Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* The core XPConnect public interfaces. */ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsISupports.idl" |
michael@0 | 10 | |
michael@0 | 11 | %{ C++ |
michael@0 | 12 | #include "jspubtd.h" |
michael@0 | 13 | #include "js/TypeDecls.h" |
michael@0 | 14 | |
michael@0 | 15 | struct JSFreeOp; |
michael@0 | 16 | |
michael@0 | 17 | class nsWrapperCache; |
michael@0 | 18 | class nsAXPCNativeCallContext; |
michael@0 | 19 | %} |
michael@0 | 20 | |
michael@0 | 21 | /***************************************************************************/ |
michael@0 | 22 | |
michael@0 | 23 | // NB: jsval and jsid are declared in nsrootidl.idl |
michael@0 | 24 | |
michael@0 | 25 | [ptr] native JSContextPtr(JSContext); |
michael@0 | 26 | [ptr] native JSClassPtr(JSClass); |
michael@0 | 27 | [ptr] native JSFreeOpPtr(JSFreeOp); |
michael@0 | 28 | [ptr] native JSObjectPtr(JSObject); |
michael@0 | 29 | [ptr] native JSValConstPtr(const JS::Value); |
michael@0 | 30 | native JSPropertyOp(JSPropertyOp); |
michael@0 | 31 | native JSEqualityOp(JSEqualityOp); |
michael@0 | 32 | [ptr] native JSScriptPtr(JSScript); |
michael@0 | 33 | [ptr] native voidPtrPtr(void*); |
michael@0 | 34 | [ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext); |
michael@0 | 35 | [ptr] native nsWrapperCachePtr(nsWrapperCache); |
michael@0 | 36 | [ref] native JSCompartmentOptions(JS::CompartmentOptions); |
michael@0 | 37 | [ref] native JSCallArgsRef(const JS::CallArgs); |
michael@0 | 38 | native JSHandleId(JS::Handle<jsid>); |
michael@0 | 39 | |
michael@0 | 40 | /***************************************************************************/ |
michael@0 | 41 | |
michael@0 | 42 | // forward declarations... |
michael@0 | 43 | interface nsIXPCScriptable; |
michael@0 | 44 | interface nsIXPConnect; |
michael@0 | 45 | interface nsIXPConnectWrappedNative; |
michael@0 | 46 | interface nsIInterfaceInfo; |
michael@0 | 47 | interface nsIXPCSecurityManager; |
michael@0 | 48 | interface nsIPrincipal; |
michael@0 | 49 | interface nsIClassInfo; |
michael@0 | 50 | interface nsIVariant; |
michael@0 | 51 | interface nsIStackFrame; |
michael@0 | 52 | interface nsIObjectInputStream; |
michael@0 | 53 | interface nsIObjectOutputStream; |
michael@0 | 54 | |
michael@0 | 55 | /***************************************************************************/ |
michael@0 | 56 | [uuid(909e8641-7c54-4dff-9b94-ba631f057b33)] |
michael@0 | 57 | interface nsIXPConnectJSObjectHolder : nsISupports |
michael@0 | 58 | { |
michael@0 | 59 | [notxpcom, nostdcall] JSObjectPtr GetJSObject(); |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | [uuid(675b01ba-397b-472a-9b80-5716376a2ec6)] |
michael@0 | 63 | interface nsIXPConnectWrappedNative : nsIXPConnectJSObjectHolder |
michael@0 | 64 | { |
michael@0 | 65 | /* attribute 'JSObject' inherited from nsIXPConnectJSObjectHolder */ |
michael@0 | 66 | readonly attribute nsISupports Native; |
michael@0 | 67 | readonly attribute JSObjectPtr JSObjectPrototype; |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * These are here as an aid to nsIXPCScriptable implementors |
michael@0 | 71 | */ |
michael@0 | 72 | |
michael@0 | 73 | nsIInterfaceInfo FindInterfaceWithMember(in JSHandleId nameID); |
michael@0 | 74 | nsIInterfaceInfo FindInterfaceWithName(in JSHandleId nameID); |
michael@0 | 75 | [notxpcom] bool HasNativeMember(in JSHandleId name); |
michael@0 | 76 | |
michael@0 | 77 | void debugDump(in short depth); |
michael@0 | 78 | |
michael@0 | 79 | /* |
michael@0 | 80 | * This finishes initializing a wrapped global, doing the parts that we |
michael@0 | 81 | * couldn't do while the global and window were being simultaneously |
michael@0 | 82 | * bootstrapped. This should be called exactly once, and only for wrapped |
michael@0 | 83 | * globals. |
michael@0 | 84 | */ |
michael@0 | 85 | void finishInitForWrappedGlobal(); |
michael@0 | 86 | |
michael@0 | 87 | /* |
michael@0 | 88 | * NOTE: Add new IDL methods _before_ the C++ block below if you |
michael@0 | 89 | * add them. Otherwise the vtable won't be what xpidl thinks it |
michael@0 | 90 | * is, since GetObjectPrincipal() is virtual. |
michael@0 | 91 | */ |
michael@0 | 92 | |
michael@0 | 93 | %{C++ |
michael@0 | 94 | /** |
michael@0 | 95 | * Faster access to the native object from C++. Will never return null. |
michael@0 | 96 | */ |
michael@0 | 97 | nsISupports* Native() const { return mIdentity; } |
michael@0 | 98 | |
michael@0 | 99 | protected: |
michael@0 | 100 | nsISupports *mIdentity; |
michael@0 | 101 | public: |
michael@0 | 102 | %} |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | %{C++ |
michael@0 | 106 | #include "nsCOMPtr.h" |
michael@0 | 107 | |
michael@0 | 108 | inline |
michael@0 | 109 | const nsQueryInterface |
michael@0 | 110 | do_QueryWrappedNative(nsIXPConnectWrappedNative *aWrappedNative) |
michael@0 | 111 | { |
michael@0 | 112 | return nsQueryInterface(aWrappedNative->Native()); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | inline |
michael@0 | 116 | const nsQueryInterfaceWithError |
michael@0 | 117 | do_QueryWrappedNative(nsIXPConnectWrappedNative *aWrappedNative, |
michael@0 | 118 | nsresult *aError) |
michael@0 | 119 | |
michael@0 | 120 | { |
michael@0 | 121 | return nsQueryInterfaceWithError(aWrappedNative->Native(), aError); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | %} |
michael@0 | 125 | |
michael@0 | 126 | [uuid(BED52030-BCA6-11d2-BA79-00805F8A5DD7)] |
michael@0 | 127 | interface nsIXPConnectWrappedJS : nsIXPConnectJSObjectHolder |
michael@0 | 128 | { |
michael@0 | 129 | /* attribute 'JSObject' inherited from nsIXPConnectJSObjectHolder */ |
michael@0 | 130 | readonly attribute nsIInterfaceInfo InterfaceInfo; |
michael@0 | 131 | readonly attribute nsIIDPtr InterfaceIID; |
michael@0 | 132 | |
michael@0 | 133 | void debugDump(in short depth); |
michael@0 | 134 | |
michael@0 | 135 | void aggregatedQueryInterface(in nsIIDRef uuid, |
michael@0 | 136 | [iid_is(uuid),retval] out nsQIResult result); |
michael@0 | 137 | |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | /***************************************************************************/ |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * This is a sort of a placeholder interface. It is not intended to be |
michael@0 | 144 | * implemented. It exists to give the nsIXPCSecurityManager an iid on |
michael@0 | 145 | * which to gate a specific activity in XPConnect. |
michael@0 | 146 | * |
michael@0 | 147 | * That activity is... |
michael@0 | 148 | * |
michael@0 | 149 | * When JavaScript code uses a component that is itself implemented in |
michael@0 | 150 | * JavaScript then XPConnect will build a wrapper rather than directly |
michael@0 | 151 | * expose the JSObject of the component. This allows components implemented |
michael@0 | 152 | * in JavaScript to 'look' just like any other xpcom component (from the |
michael@0 | 153 | * perspective of the JavaScript caller). This insulates the component from |
michael@0 | 154 | * the caller and hides any properties or methods that are not part of the |
michael@0 | 155 | * interface as declared in xpidl. Usually this is a good thing. |
michael@0 | 156 | * |
michael@0 | 157 | * However, in some cases it is useful to allow the JS caller access to the |
michael@0 | 158 | * JS component's underlying implementation. In order to facilitate this |
michael@0 | 159 | * XPConnect supports the 'wrappedJSObject' property. The caller code can do: |
michael@0 | 160 | * |
michael@0 | 161 | * // 'foo' is some xpcom component (that might be implemented in JS). |
michael@0 | 162 | * try { |
michael@0 | 163 | * var bar = foo.wrappedJSObject; |
michael@0 | 164 | * if(bar) { |
michael@0 | 165 | * // bar is the underlying JSObject. Do stuff with it here. |
michael@0 | 166 | * } |
michael@0 | 167 | * } catch(e) { |
michael@0 | 168 | * // security exception? |
michael@0 | 169 | * } |
michael@0 | 170 | * |
michael@0 | 171 | * Recall that 'foo' above is an XPConnect wrapper, not the underlying JS |
michael@0 | 172 | * object. The property get "foo.wrappedJSObject" will only succeed if three |
michael@0 | 173 | * conditions are met: |
michael@0 | 174 | * |
michael@0 | 175 | * 1) 'foo' really is an XPConnect wrapper around a JSObject. |
michael@0 | 176 | * 2) The underlying JSObject actually implements a "wrappedJSObject" |
michael@0 | 177 | * property that returns a JSObject. This is called by XPConnect. This |
michael@0 | 178 | * restriction allows wrapped objects to only allow access to the underlying |
michael@0 | 179 | * JSObject if they choose to do so. Ususally this just means that 'foo' |
michael@0 | 180 | * would have a property tht looks like: |
michael@0 | 181 | * this.wrappedJSObject = this. |
michael@0 | 182 | * 3) The implemementation of nsIXPCSecurityManager (if installed) allows |
michael@0 | 183 | * a property get on the interface below. Although the JSObject need not |
michael@0 | 184 | * implement 'nsIXPCWrappedJSObjectGetter', XPConnect will ask the |
michael@0 | 185 | * security manager if it is OK for the caller to access the only method |
michael@0 | 186 | * in nsIXPCWrappedJSObjectGetter before allowing the activity. This fits |
michael@0 | 187 | * in with the security manager paradigm and makes control over accessing |
michael@0 | 188 | * the property on this interface the control factor for getting the |
michael@0 | 189 | * underlying wrapped JSObject of a JS component from JS code. |
michael@0 | 190 | * |
michael@0 | 191 | * Notes: |
michael@0 | 192 | * |
michael@0 | 193 | * a) If 'foo' above were the underlying JSObject and not a wrapper at all, |
michael@0 | 194 | * then this all just works and XPConnect is not part of the picture at all. |
michael@0 | 195 | * b) One might ask why 'foo' should not just implement an interface through |
michael@0 | 196 | * which callers might get at the underlying object. There are three reasons: |
michael@0 | 197 | * i) XPConnect would still have to do magic since JSObject is not a |
michael@0 | 198 | * scriptable type. |
michael@0 | 199 | * ii) JS Components might use aggregation (like C++ objects) and have |
michael@0 | 200 | * different JSObjects for different interfaces 'within' an aggregate |
michael@0 | 201 | * object. But, using an additional interface only allows returning one |
michael@0 | 202 | * underlying JSObject. However, this allows for the possibility that |
michael@0 | 203 | * each of the aggregte JSObjects could return something different. |
michael@0 | 204 | * Note that one might do: this.wrappedJSObject = someOtherObject; |
michael@0 | 205 | * iii) Avoiding the explicit interface makes it easier for both the caller |
michael@0 | 206 | * and the component. |
michael@0 | 207 | * |
michael@0 | 208 | * Anyway, some future implementation of nsIXPCSecurityManager might want |
michael@0 | 209 | * do special processing on 'nsIXPCSecurityManager::CanGetProperty' when |
michael@0 | 210 | * the interface id is that of nsIXPCWrappedJSObjectGetter. |
michael@0 | 211 | */ |
michael@0 | 212 | |
michael@0 | 213 | [scriptable, uuid(254bb2e0-6439-11d4-8fe0-0010a4e73d9a)] |
michael@0 | 214 | interface nsIXPCWrappedJSObjectGetter : nsISupports |
michael@0 | 215 | { |
michael@0 | 216 | readonly attribute nsISupports neverCalled; |
michael@0 | 217 | }; |
michael@0 | 218 | |
michael@0 | 219 | /***************************************************************************/ |
michael@0 | 220 | |
michael@0 | 221 | /* |
michael@0 | 222 | * This interface is implemented by outside code and registered with xpconnect |
michael@0 | 223 | * via nsIXPConnect::setFunctionThisTranslator. |
michael@0 | 224 | * |
michael@0 | 225 | * The reason this exists is to support calls to JavaScript event callbacks |
michael@0 | 226 | * needed by the DOM via xpconnect from C++ code. |
michael@0 | 227 | * |
michael@0 | 228 | * We've added support for wrapping JS function objects as xpcom interfaces |
michael@0 | 229 | * by declaring the given interface as a [function] interface. However, to |
michael@0 | 230 | * support the requirements of JS event callbacks we need to call the JS |
michael@0 | 231 | * function with the 'this' set as the JSObject for which the event is being |
michael@0 | 232 | * fired; e.g. a form node. |
michael@0 | 233 | * |
michael@0 | 234 | * We've decided that for all cases we care about the appropriate 'this' object |
michael@0 | 235 | * can be derived from the first param in the call to the callback. In the |
michael@0 | 236 | * event handler case the first param is an event object. |
michael@0 | 237 | * |
michael@0 | 238 | * Though we can't change all the JS code so that it would setup its own 'this', |
michael@0 | 239 | * we can add plugin 'helper' support to xpconnect. And that is what we have |
michael@0 | 240 | * here. |
michael@0 | 241 | * |
michael@0 | 242 | * The idea is that at startup time some code that cares about this issue |
michael@0 | 243 | * (e.g. the DOM helper code) can register a nsIXPCFunctionThisTranslator |
michael@0 | 244 | * object with xpconnect to handle calls to [function] interfaces of a given |
michael@0 | 245 | * iid. When xpconnect goes to invoke a method on a wrapped JSObject for |
michael@0 | 246 | * an interface marked as [function], xpconnect will check if the first param |
michael@0 | 247 | * of the method is an xpcom object pointer and if so it will check to see if a |
michael@0 | 248 | * nsIXPCFunctionThisTranslator has been registered for the given iid of the |
michael@0 | 249 | * interface being called. If so it will call the translator and get an |
michael@0 | 250 | * interface pointer to use as the 'this' for the call. If the translator |
michael@0 | 251 | * returns a non-null interface pointer (which it should then have addref'd |
michael@0 | 252 | * since it is being returned as an out param), xpconnect will attempt to build |
michael@0 | 253 | * a wrapper around the pointer and get a JSObject from that wrapper to use |
michael@0 | 254 | * as the 'this' for the call. |
michael@0 | 255 | * |
michael@0 | 256 | * If a null interface pointer is returned then xpconnect will use the default |
michael@0 | 257 | * 'this' - the same JSObject as the function object it is calling. |
michael@0 | 258 | */ |
michael@0 | 259 | |
michael@0 | 260 | [uuid(f5f84b70-92eb-41f1-a1dd-2eaac0ed564c)] |
michael@0 | 261 | interface nsIXPCFunctionThisTranslator : nsISupports |
michael@0 | 262 | { |
michael@0 | 263 | nsISupports TranslateThis(in nsISupports aInitialThis); |
michael@0 | 264 | }; |
michael@0 | 265 | |
michael@0 | 266 | /***************************************************************************/ |
michael@0 | 267 | |
michael@0 | 268 | |
michael@0 | 269 | %{ C++ |
michael@0 | 270 | // For use with the service manager |
michael@0 | 271 | // {CB6593E0-F9B2-11d2-BDD6-000064657374} |
michael@0 | 272 | #define NS_XPCONNECT_CID \ |
michael@0 | 273 | { 0xcb6593e0, 0xf9b2, 0x11d2, \ |
michael@0 | 274 | { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } |
michael@0 | 275 | %} |
michael@0 | 276 | |
michael@0 | 277 | [noscript, uuid(3d5a6320-8764-11e3-baa7-0800200c9a66)] |
michael@0 | 278 | interface nsIXPConnect : nsISupports |
michael@0 | 279 | { |
michael@0 | 280 | %{ C++ |
michael@0 | 281 | NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCONNECT_CID) |
michael@0 | 282 | %} |
michael@0 | 283 | |
michael@0 | 284 | /** |
michael@0 | 285 | * Initializes classes on a global object that has already been created. |
michael@0 | 286 | */ |
michael@0 | 287 | void |
michael@0 | 288 | initClasses(in JSContextPtr aJSContext, |
michael@0 | 289 | in JSObjectPtr aGlobalJSObj); |
michael@0 | 290 | |
michael@0 | 291 | /** |
michael@0 | 292 | * Creates a new global object using the given aCOMObj as the global |
michael@0 | 293 | * object. The object will be set up according to the flags (defined |
michael@0 | 294 | * below). If you do not pass INIT_JS_STANDARD_CLASSES, then aCOMObj |
michael@0 | 295 | * must implement nsIXPCScriptable so it can resolve the standard |
michael@0 | 296 | * classes when asked by the JS engine. |
michael@0 | 297 | * |
michael@0 | 298 | * @param aJSContext the context to use while creating the global object. |
michael@0 | 299 | * @param aCOMObj the native object that represents the global object. |
michael@0 | 300 | * @param aPrincipal the principal of the code that will run in this |
michael@0 | 301 | * compartment. Can be null if not on the main thread. |
michael@0 | 302 | * @param aFlags one of the flags below specifying what options this |
michael@0 | 303 | * global object wants. |
michael@0 | 304 | * @param aOptions JSAPI-specific options for the new compartment. |
michael@0 | 305 | */ |
michael@0 | 306 | nsIXPConnectJSObjectHolder |
michael@0 | 307 | initClassesWithNewWrappedGlobal( |
michael@0 | 308 | in JSContextPtr aJSContext, |
michael@0 | 309 | in nsISupports aCOMObj, |
michael@0 | 310 | in nsIPrincipal aPrincipal, |
michael@0 | 311 | in uint32_t aFlags, |
michael@0 | 312 | in JSCompartmentOptions aOptions); |
michael@0 | 313 | |
michael@0 | 314 | const uint32_t INIT_JS_STANDARD_CLASSES = 1 << 0; |
michael@0 | 315 | const uint32_t DONT_FIRE_ONNEWGLOBALHOOK = 1 << 1; |
michael@0 | 316 | const uint32_t OMIT_COMPONENTS_OBJECT = 1 << 2; |
michael@0 | 317 | |
michael@0 | 318 | /** |
michael@0 | 319 | * wrapNative will create a new JSObject or return an existing one. |
michael@0 | 320 | * |
michael@0 | 321 | * The JSObject is returned inside a refcounted nsIXPConnectJSObjectHolder. |
michael@0 | 322 | * As long as this holder is held the JSObject will be protected from |
michael@0 | 323 | * collection by JavaScript's garbage collector. It is a good idea to |
michael@0 | 324 | * transfer the JSObject to some equally protected place before releasing |
michael@0 | 325 | * the holder (i.e. use JS_SetProperty to make this object a property of |
michael@0 | 326 | * some other JSObject). |
michael@0 | 327 | * |
michael@0 | 328 | * This method now correctly deals with cases where the passed in xpcom |
michael@0 | 329 | * object already has an associated JSObject for the cases: |
michael@0 | 330 | * 1) The xpcom object has already been wrapped for use in the same scope |
michael@0 | 331 | * as an nsIXPConnectWrappedNative. |
michael@0 | 332 | * 2) The xpcom object is in fact a nsIXPConnectWrappedJS and thus already |
michael@0 | 333 | * has an underlying JSObject. |
michael@0 | 334 | * |
michael@0 | 335 | * It *might* be possible to QueryInterface the nsIXPConnectJSObjectHolder |
michael@0 | 336 | * returned by the method into a nsIXPConnectWrappedNative or a |
michael@0 | 337 | * nsIXPConnectWrappedJS. |
michael@0 | 338 | * |
michael@0 | 339 | * This method will never wrap the JSObject involved in an |
michael@0 | 340 | * XPCNativeWrapper before returning. |
michael@0 | 341 | * |
michael@0 | 342 | * Returns: |
michael@0 | 343 | * success: |
michael@0 | 344 | * NS_OK |
michael@0 | 345 | * failure: |
michael@0 | 346 | * NS_ERROR_XPC_BAD_CONVERT_NATIVE |
michael@0 | 347 | * NS_ERROR_XPC_CANT_GET_JSOBJECT_OF_DOM_OBJECT |
michael@0 | 348 | * NS_ERROR_FAILURE |
michael@0 | 349 | */ |
michael@0 | 350 | nsIXPConnectJSObjectHolder |
michael@0 | 351 | wrapNative(in JSContextPtr aJSContext, |
michael@0 | 352 | in JSObjectPtr aScope, |
michael@0 | 353 | in nsISupports aCOMObj, |
michael@0 | 354 | in nsIIDRef aIID); |
michael@0 | 355 | |
michael@0 | 356 | /** |
michael@0 | 357 | * Same as wrapNative, but it returns the JSObject in aVal. C++ callers |
michael@0 | 358 | * must ensure that aVal is rooted. |
michael@0 | 359 | * aIID may be null, it means the same as passing in |
michael@0 | 360 | * &NS_GET_IID(nsISupports) but when passing in null certain shortcuts |
michael@0 | 361 | * can be taken because we know without comparing IIDs that the caller is |
michael@0 | 362 | * asking for an nsISupports wrapper. |
michael@0 | 363 | * If aAllowWrapper, then the returned value will be wrapped in the proper |
michael@0 | 364 | * type of security wrapper on top of the XPCWrappedNative (if needed). |
michael@0 | 365 | * This method doesn't push aJSContext on the context stack, so the caller |
michael@0 | 366 | * is required to push it if the top of the context stack is not equal to |
michael@0 | 367 | * aJSContext. |
michael@0 | 368 | */ |
michael@0 | 369 | void |
michael@0 | 370 | wrapNativeToJSVal(in JSContextPtr aJSContext, |
michael@0 | 371 | in JSObjectPtr aScope, |
michael@0 | 372 | in nsISupports aCOMObj, |
michael@0 | 373 | in nsWrapperCachePtr aCache, |
michael@0 | 374 | in nsIIDPtr aIID, |
michael@0 | 375 | in boolean aAllowWrapper, |
michael@0 | 376 | out jsval aVal); |
michael@0 | 377 | |
michael@0 | 378 | /** |
michael@0 | 379 | * wrapJS will yield a new or previously existing xpcom interface pointer |
michael@0 | 380 | * to represent the JSObject passed in. |
michael@0 | 381 | * |
michael@0 | 382 | * This method now correctly deals with cases where the passed in JSObject |
michael@0 | 383 | * already has an associated xpcom interface for the cases: |
michael@0 | 384 | * 1) The JSObject has already been wrapped as a nsIXPConnectWrappedJS. |
michael@0 | 385 | * 2) The JSObject is in fact a nsIXPConnectWrappedNative and thus already |
michael@0 | 386 | * has an underlying xpcom object. |
michael@0 | 387 | * 3) The JSObject is of a jsclass which supports getting the nsISupports |
michael@0 | 388 | * from the JSObject directly. This is used for idlc style objects |
michael@0 | 389 | * (e.g. DOM objects). |
michael@0 | 390 | * |
michael@0 | 391 | * It *might* be possible to QueryInterface the resulting interface pointer |
michael@0 | 392 | * to nsIXPConnectWrappedJS. |
michael@0 | 393 | * |
michael@0 | 394 | * Returns: |
michael@0 | 395 | * success: |
michael@0 | 396 | * NS_OK |
michael@0 | 397 | * failure: |
michael@0 | 398 | * NS_ERROR_XPC_BAD_CONVERT_JS |
michael@0 | 399 | * NS_ERROR_FAILURE |
michael@0 | 400 | */ |
michael@0 | 401 | void |
michael@0 | 402 | wrapJS(in JSContextPtr aJSContext, |
michael@0 | 403 | in JSObjectPtr aJSObj, |
michael@0 | 404 | in nsIIDRef aIID, |
michael@0 | 405 | [iid_is(aIID),retval] out nsQIResult result); |
michael@0 | 406 | |
michael@0 | 407 | /** |
michael@0 | 408 | * Wraps the given jsval in a nsIVariant and returns the new variant. |
michael@0 | 409 | */ |
michael@0 | 410 | nsIVariant |
michael@0 | 411 | jSValToVariant(in JSContextPtr cx, in jsval aJSVal); |
michael@0 | 412 | |
michael@0 | 413 | /** |
michael@0 | 414 | * This only succeeds if the JSObject is a nsIXPConnectWrappedNative. |
michael@0 | 415 | * A new wrapper is *never* constructed. |
michael@0 | 416 | */ |
michael@0 | 417 | nsIXPConnectWrappedNative |
michael@0 | 418 | getWrappedNativeOfJSObject(in JSContextPtr aJSContext, |
michael@0 | 419 | in JSObjectPtr aJSObj); |
michael@0 | 420 | |
michael@0 | 421 | [noscript, notxpcom] nsISupports |
michael@0 | 422 | getNativeOfWrapper(in JSContextPtr aJSContext, |
michael@0 | 423 | in JSObjectPtr aJSObj); |
michael@0 | 424 | |
michael@0 | 425 | /** |
michael@0 | 426 | * The security manager to use when the current JSContext has no security |
michael@0 | 427 | * manager. |
michael@0 | 428 | */ |
michael@0 | 429 | void setDefaultSecurityManager(in nsIXPCSecurityManager aManager); |
michael@0 | 430 | |
michael@0 | 431 | nsIStackFrame |
michael@0 | 432 | createStackFrameLocation(in uint32_t aLanguage, |
michael@0 | 433 | in string aFilename, |
michael@0 | 434 | in string aFunctionName, |
michael@0 | 435 | in int32_t aLineNumber, |
michael@0 | 436 | in nsIStackFrame aCaller); |
michael@0 | 437 | |
michael@0 | 438 | |
michael@0 | 439 | [noscript,notxpcom,nostdcall] JSContextPtr getCurrentJSContext(); |
michael@0 | 440 | [noscript,notxpcom,nostdcall] JSContextPtr initSafeJSContext(); |
michael@0 | 441 | [noscript,notxpcom,nostdcall] JSContextPtr getSafeJSContext(); |
michael@0 | 442 | |
michael@0 | 443 | readonly attribute nsIStackFrame CurrentJSStack; |
michael@0 | 444 | readonly attribute nsAXPCNativeCallContextPtr CurrentNativeCallContext; |
michael@0 | 445 | |
michael@0 | 446 | void debugDump(in short depth); |
michael@0 | 447 | void debugDumpObject(in nsISupports aCOMObj, in short depth); |
michael@0 | 448 | void debugDumpJSStack(in boolean showArgs, |
michael@0 | 449 | in boolean showLocals, |
michael@0 | 450 | in boolean showThisProps); |
michael@0 | 451 | void debugDumpEvalInJSStackFrame(in uint32_t aFrameNumber, |
michael@0 | 452 | in string aSourceText); |
michael@0 | 453 | |
michael@0 | 454 | /** |
michael@0 | 455 | * wrapJSAggregatedToNative is just like wrapJS except it is used in cases |
michael@0 | 456 | * where the JSObject is also aggregated to some native xpcom Object. |
michael@0 | 457 | * At present XBL is the only system that might want to do this. |
michael@0 | 458 | * |
michael@0 | 459 | * XXX write more! |
michael@0 | 460 | * |
michael@0 | 461 | * Returns: |
michael@0 | 462 | * success: |
michael@0 | 463 | * NS_OK |
michael@0 | 464 | * failure: |
michael@0 | 465 | * NS_ERROR_XPC_BAD_CONVERT_JS |
michael@0 | 466 | * NS_ERROR_FAILURE |
michael@0 | 467 | */ |
michael@0 | 468 | void |
michael@0 | 469 | wrapJSAggregatedToNative(in nsISupports aOuter, |
michael@0 | 470 | in JSContextPtr aJSContext, |
michael@0 | 471 | in JSObjectPtr aJSObj, |
michael@0 | 472 | in nsIIDRef aIID, |
michael@0 | 473 | [iid_is(aIID),retval] out nsQIResult result); |
michael@0 | 474 | |
michael@0 | 475 | // Methods added since mozilla 0.6.... |
michael@0 | 476 | |
michael@0 | 477 | /** |
michael@0 | 478 | * This only succeeds if the native object is already wrapped by xpconnect. |
michael@0 | 479 | * A new wrapper is *never* constructed. |
michael@0 | 480 | */ |
michael@0 | 481 | nsIXPConnectWrappedNative |
michael@0 | 482 | getWrappedNativeOfNativeObject(in JSContextPtr aJSContext, |
michael@0 | 483 | in JSObjectPtr aScope, |
michael@0 | 484 | in nsISupports aCOMObj, |
michael@0 | 485 | in nsIIDRef aIID); |
michael@0 | 486 | |
michael@0 | 487 | void |
michael@0 | 488 | setFunctionThisTranslator(in nsIIDRef aIID, |
michael@0 | 489 | in nsIXPCFunctionThisTranslator aTranslator); |
michael@0 | 490 | |
michael@0 | 491 | void |
michael@0 | 492 | reparentWrappedNativeIfFound(in JSContextPtr aJSContext, |
michael@0 | 493 | in JSObjectPtr aScope, |
michael@0 | 494 | in JSObjectPtr aNewParent, |
michael@0 | 495 | in nsISupports aCOMObj); |
michael@0 | 496 | void |
michael@0 | 497 | rescueOrphansInScope(in JSContextPtr aJSContext, in JSObjectPtr aScope); |
michael@0 | 498 | |
michael@0 | 499 | nsIXPConnectJSObjectHolder |
michael@0 | 500 | getWrappedNativePrototype(in JSContextPtr aJSContext, |
michael@0 | 501 | in JSObjectPtr aScope, |
michael@0 | 502 | in nsIClassInfo aClassInfo); |
michael@0 | 503 | |
michael@0 | 504 | jsval variantToJS(in JSContextPtr ctx, in JSObjectPtr scope, in nsIVariant value); |
michael@0 | 505 | nsIVariant JSToVariant(in JSContextPtr ctx, in jsval value); |
michael@0 | 506 | |
michael@0 | 507 | /** |
michael@0 | 508 | * Create a sandbox for evaluating code in isolation using |
michael@0 | 509 | * evalInSandboxObject(). |
michael@0 | 510 | * |
michael@0 | 511 | * @param cx A context to use when creating the sandbox object. |
michael@0 | 512 | * @param principal The principal (or NULL to use the null principal) |
michael@0 | 513 | * to use when evaluating code in this sandbox. |
michael@0 | 514 | */ |
michael@0 | 515 | [noscript] nsIXPConnectJSObjectHolder createSandbox(in JSContextPtr cx, |
michael@0 | 516 | in nsIPrincipal principal); |
michael@0 | 517 | |
michael@0 | 518 | /** |
michael@0 | 519 | * Evaluate script in a sandbox, completely isolated from all |
michael@0 | 520 | * other running scripts. |
michael@0 | 521 | * |
michael@0 | 522 | * @param source The source of the script to evaluate. |
michael@0 | 523 | * @param filename The filename of the script. May be null. |
michael@0 | 524 | * @param cx The context to use when setting up the evaluation of |
michael@0 | 525 | * the script. The actual evaluation will happen on a new |
michael@0 | 526 | * temporary context. |
michael@0 | 527 | * @param sandbox The sandbox object to evaluate the script in. |
michael@0 | 528 | * @param returnStringOnly The only results to come out of the |
michael@0 | 529 | * computation (including exceptions) will |
michael@0 | 530 | * be coerced into strings created in the |
michael@0 | 531 | * sandbox. |
michael@0 | 532 | * @return The result of the evaluation as a jsval. If the caller |
michael@0 | 533 | * intends to use the return value from this call the caller |
michael@0 | 534 | * is responsible for rooting the jsval before making a call |
michael@0 | 535 | * to this method. |
michael@0 | 536 | */ |
michael@0 | 537 | [noscript] jsval evalInSandboxObject(in AString source, in string filename, |
michael@0 | 538 | in JSContextPtr cx, |
michael@0 | 539 | in JSObjectPtr sandbox, |
michael@0 | 540 | in boolean returnStringOnly); |
michael@0 | 541 | |
michael@0 | 542 | /** |
michael@0 | 543 | * Whether or not XPConnect should report all JS exceptions when returning |
michael@0 | 544 | * from JS into C++. False by default, although any value set in the |
michael@0 | 545 | * MOZ_REPORT_ALL_JS_EXCEPTIONS environment variable will override the value |
michael@0 | 546 | * passed here. |
michael@0 | 547 | */ |
michael@0 | 548 | void setReportAllJSExceptions(in boolean reportAllJSExceptions); |
michael@0 | 549 | |
michael@0 | 550 | /** |
michael@0 | 551 | * Trigger a JS garbage collection. |
michael@0 | 552 | * Use a js::gcreason::Reason from jsfriendapi.h for the kind. |
michael@0 | 553 | */ |
michael@0 | 554 | void GarbageCollect(in uint32_t reason); |
michael@0 | 555 | |
michael@0 | 556 | /** |
michael@0 | 557 | * Signals a good place to do an incremental GC slice, because the |
michael@0 | 558 | * browser is drawing a frame. |
michael@0 | 559 | */ |
michael@0 | 560 | void NotifyDidPaint(); |
michael@0 | 561 | |
michael@0 | 562 | %{C++ |
michael@0 | 563 | /** |
michael@0 | 564 | * Get the object principal for this wrapper. Note that this may well end |
michael@0 | 565 | * up being null; in that case one should seek principals elsewhere. Null |
michael@0 | 566 | * here does NOT indicate system principal or no principals at all, just |
michael@0 | 567 | * that this wrapper doesn't have an intrinsic one. |
michael@0 | 568 | */ |
michael@0 | 569 | virtual nsIPrincipal* GetPrincipal(JSObject* obj, |
michael@0 | 570 | bool allowShortCircuit) const = 0; |
michael@0 | 571 | virtual char* DebugPrintJSStack(bool showArgs, |
michael@0 | 572 | bool showLocals, |
michael@0 | 573 | bool showThisProps) = 0; |
michael@0 | 574 | %} |
michael@0 | 575 | |
michael@0 | 576 | /** |
michael@0 | 577 | * Creates a JS object holder around aObject that will hold the object |
michael@0 | 578 | * alive for as long as the holder stays alive. |
michael@0 | 579 | */ |
michael@0 | 580 | nsIXPConnectJSObjectHolder holdObject(in JSContextPtr aJSContext, |
michael@0 | 581 | in JSObjectPtr aObject); |
michael@0 | 582 | |
michael@0 | 583 | /** |
michael@0 | 584 | * When we place the browser in JS debug mode, there can't be any |
michael@0 | 585 | * JS on the stack. This is because we currently activate debugMode |
michael@0 | 586 | * on all scripts in the JSRuntime when the debugger is activated. |
michael@0 | 587 | * This method will turn debug mode on or off when the context |
michael@0 | 588 | * stack reaches zero length. |
michael@0 | 589 | */ |
michael@0 | 590 | [noscript] void setDebugModeWhenPossible(in boolean mode, |
michael@0 | 591 | in boolean allowSyncDisable); |
michael@0 | 592 | |
michael@0 | 593 | [noscript] void writeScript(in nsIObjectOutputStream aStream, |
michael@0 | 594 | in JSContextPtr aJSContext, |
michael@0 | 595 | in JSScriptPtr aJSScript); |
michael@0 | 596 | |
michael@0 | 597 | [noscript] JSScriptPtr readScript(in nsIObjectInputStream aStream, |
michael@0 | 598 | in JSContextPtr aJSContext); |
michael@0 | 599 | |
michael@0 | 600 | [noscript] void writeFunction(in nsIObjectOutputStream aStream, |
michael@0 | 601 | in JSContextPtr aJSContext, |
michael@0 | 602 | in JSObjectPtr aJSObject); |
michael@0 | 603 | |
michael@0 | 604 | [noscript] JSObjectPtr readFunction(in nsIObjectInputStream aStream, |
michael@0 | 605 | in JSContextPtr aJSContext); |
michael@0 | 606 | |
michael@0 | 607 | /** |
michael@0 | 608 | * This function should be called in JavaScript error reporters |
michael@0 | 609 | * to signal that they are ignoring the error. In this case, |
michael@0 | 610 | * XPConnect can print a warning to the console. |
michael@0 | 611 | */ |
michael@0 | 612 | [noscript] void markErrorUnreported(in JSContextPtr aJSContext); |
michael@0 | 613 | }; |