diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index 54b93cd29d64..96d7b5b71b2a 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -128,6 +128,19 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(JSContext *cx, // Attach ourselves to the compartment private. CompartmentPrivate *priv = EnsureCompartmentPrivate(aGlobal); priv->scope = this; + + // Determine whether to use an XBL scope or not. + mUseXBLScope = XPCJSRuntime::Get()->XBLScopesEnabled(); + if (mUseXBLScope) { + js::Class *clasp = js::GetObjectClass(mGlobalJSObject); + mUseXBLScope = !strcmp(clasp->name, "Window") || + !strcmp(clasp->name, "ChromeWindow") || + !strcmp(clasp->name, "ModalContentWindow"); + } + if (mUseXBLScope) { + nsIPrincipal *principal = GetPrincipal(); + mUseXBLScope = principal && !nsContentUtils::IsSystemPrincipal(principal); + } } // static @@ -180,21 +193,8 @@ XPCWrappedNativeScope::EnsureXBLScope(JSContext *cx) if (mXBLScope) return mXBLScope; - // We should only be applying XBL bindings in DOM scopes. - MOZ_ASSERT(!strcmp(js::GetObjectClass(mGlobalJSObject)->name, "Window") || - !strcmp(js::GetObjectClass(mGlobalJSObject)->name, "ChromeWindow") || - !strcmp(js::GetObjectClass(mGlobalJSObject)->name, "ModalContentWindow")); - - // Get the scope principal. If it's system, there's no reason to make - // a separate XBL scope. - nsIPrincipal *principal = GetPrincipal(); - if (!principal) - return nullptr; - if (nsContentUtils::IsSystemPrincipal(principal)) - return global; - - // Check the pref. If XBL scopes are disabled, just return the global. - if (!XPCJSRuntime::Get()->XBLScopesEnabled()) + // If this scope doesn't need an XBL scope, just return the global. + if (!mUseXBLScope) return global; // Set up the sandbox options. Note that we use the DOM global as the @@ -212,6 +212,7 @@ XPCWrappedNativeScope::EnsureXBLScope(JSContext *cx) options.proto = global; // Use an nsExpandedPrincipal to create asymmetric security. + nsIPrincipal *principal = GetPrincipal(); nsCOMPtr ep; MOZ_ASSERT(!(ep = do_QueryInterface(principal))); nsTArray< nsCOMPtr > principalAsArray(1); diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 922992ceadf7..4142c4431322 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -1760,6 +1760,7 @@ private: JSBool mExperimentalBindingsEnabled; bool mIsXBLScope; + bool mUseXBLScope; }; /***************************************************************************/