Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsIScriptContext_h__
7 #define nsIScriptContext_h__
9 #include "nscore.h"
10 #include "nsStringGlue.h"
11 #include "nsISupports.h"
12 #include "nsCOMPtr.h"
13 #include "nsIProgrammingLanguage.h"
14 #include "jspubtd.h"
15 #include "js/GCAPI.h"
17 class nsIScriptGlobalObject;
18 class nsIScriptSecurityManager;
19 class nsIPrincipal;
20 class nsIAtom;
21 class nsIArray;
22 class nsIVariant;
23 class nsIObjectInputStream;
24 class nsIObjectOutputStream;
25 class nsIScriptObjectPrincipal;
26 class nsIDOMWindow;
27 class nsIURI;
29 #define NS_ISCRIPTCONTEXT_IID \
30 { 0x274840b6, 0x7349, 0x4798, \
31 { 0xbe, 0x24, 0xbd, 0x75, 0xa6, 0x46, 0x99, 0xb7 } }
33 /* This MUST match JSVERSION_DEFAULT. This version stuff if we don't
34 know what language we have is a little silly... */
35 #define SCRIPTVERSION_DEFAULT JSVERSION_DEFAULT
37 class nsIOffThreadScriptReceiver;
39 /**
40 * It is used by the application to initialize a runtime and run scripts.
41 * A script runtime would implement this interface.
42 */
43 class nsIScriptContext : public nsISupports
44 {
45 public:
46 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID)
48 /**
49 * Return the global object.
50 *
51 **/
52 virtual nsIScriptGlobalObject *GetGlobalObject() = 0;
54 /**
55 * Return the native script context
56 *
57 **/
58 virtual JSContext* GetNativeContext() = 0;
60 /**
61 * Initialize the context generally. Does not create a global object.
62 **/
63 virtual nsresult InitContext() = 0;
65 /**
66 * Check to see if context is as yet intialized. Used to prevent
67 * reentrancy issues during the initialization process.
68 *
69 * @return true if initialized, false if not
70 *
71 */
72 virtual bool IsContextInitialized() = 0;
74 /**
75 * For garbage collected systems, do a synchronous collection pass.
76 * May be a no-op on other systems
77 *
78 * @return NS_OK if the method is successful
79 */
80 virtual void GC(JS::gcreason::Reason aReason) = 0;
82 // SetProperty is suspect and jst believes should not be needed. Currenly
83 // used only for "arguments".
84 virtual nsresult SetProperty(JS::Handle<JSObject*> aTarget,
85 const char* aPropName, nsISupports* aVal) = 0;
86 /**
87 * Called to set/get information if the script context is
88 * currently processing a script tag
89 */
90 virtual bool GetProcessingScriptTag() = 0;
91 virtual void SetProcessingScriptTag(bool aResult) = 0;
93 /**
94 * Initialize DOM classes on aGlobalObj, always call
95 * WillInitializeContext() before calling InitContext(), and always
96 * call DidInitializeContext() when a context is fully
97 * (successfully) initialized.
98 */
99 virtual nsresult InitClasses(JS::Handle<JSObject*> aGlobalObj) = 0;
101 /**
102 * Tell the context we're about to be reinitialize it.
103 */
104 virtual void WillInitializeContext() = 0;
106 /**
107 * Tell the context we're done reinitializing it.
108 */
109 virtual void DidInitializeContext() = 0;
111 /**
112 * Access the Window Proxy. The setter should only be called by nsGlobalWindow.
113 */
114 virtual void SetWindowProxy(JS::Handle<JSObject*> aWindowProxy) = 0;
115 virtual JSObject* GetWindowProxy() = 0;
116 virtual JSObject* GetWindowProxyPreserveColor() = 0;
117 };
119 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContext, NS_ISCRIPTCONTEXT_IID)
121 #define NS_IOFFTHREADSCRIPTRECEIVER_IID \
122 {0x3a980010, 0x878d, 0x46a9, \
123 {0x93, 0xad, 0xbc, 0xfd, 0xd3, 0x8e, 0xa0, 0xc2}}
125 class nsIOffThreadScriptReceiver : public nsISupports
126 {
127 public:
128 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IOFFTHREADSCRIPTRECEIVER_IID)
130 /**
131 * Notify this object that a previous CompileScript call specifying this as
132 * aOffThreadReceiver has completed. The script being passed in must be
133 * rooted before any call which could trigger GC.
134 */
135 NS_IMETHOD OnScriptCompileComplete(JSScript* aScript, nsresult aStatus) = 0;
136 };
138 NS_DEFINE_STATIC_IID_ACCESSOR(nsIOffThreadScriptReceiver, NS_IOFFTHREADSCRIPTRECEIVER_IID)
140 #endif // nsIScriptContext_h__