|
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/. */ |
|
5 |
|
6 #ifndef nsIScriptContext_h__ |
|
7 #define nsIScriptContext_h__ |
|
8 |
|
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" |
|
16 |
|
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; |
|
28 |
|
29 #define NS_ISCRIPTCONTEXT_IID \ |
|
30 { 0x274840b6, 0x7349, 0x4798, \ |
|
31 { 0xbe, 0x24, 0xbd, 0x75, 0xa6, 0x46, 0x99, 0xb7 } } |
|
32 |
|
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 |
|
36 |
|
37 class nsIOffThreadScriptReceiver; |
|
38 |
|
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) |
|
47 |
|
48 /** |
|
49 * Return the global object. |
|
50 * |
|
51 **/ |
|
52 virtual nsIScriptGlobalObject *GetGlobalObject() = 0; |
|
53 |
|
54 /** |
|
55 * Return the native script context |
|
56 * |
|
57 **/ |
|
58 virtual JSContext* GetNativeContext() = 0; |
|
59 |
|
60 /** |
|
61 * Initialize the context generally. Does not create a global object. |
|
62 **/ |
|
63 virtual nsresult InitContext() = 0; |
|
64 |
|
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; |
|
73 |
|
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; |
|
81 |
|
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; |
|
92 |
|
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; |
|
100 |
|
101 /** |
|
102 * Tell the context we're about to be reinitialize it. |
|
103 */ |
|
104 virtual void WillInitializeContext() = 0; |
|
105 |
|
106 /** |
|
107 * Tell the context we're done reinitializing it. |
|
108 */ |
|
109 virtual void DidInitializeContext() = 0; |
|
110 |
|
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 }; |
|
118 |
|
119 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContext, NS_ISCRIPTCONTEXT_IID) |
|
120 |
|
121 #define NS_IOFFTHREADSCRIPTRECEIVER_IID \ |
|
122 {0x3a980010, 0x878d, 0x46a9, \ |
|
123 {0x93, 0xad, 0xbc, 0xfd, 0xd3, 0x8e, 0xa0, 0xc2}} |
|
124 |
|
125 class nsIOffThreadScriptReceiver : public nsISupports |
|
126 { |
|
127 public: |
|
128 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IOFFTHREADSCRIPTRECEIVER_IID) |
|
129 |
|
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 }; |
|
137 |
|
138 NS_DEFINE_STATIC_IID_ACCESSOR(nsIOffThreadScriptReceiver, NS_IOFFTHREADSCRIPTRECEIVER_IID) |
|
139 |
|
140 #endif // nsIScriptContext_h__ |
|
141 |