diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index 1cf3055a6b63..c2b71876c8fb 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -266,6 +266,15 @@ XPCWrappedNativeScope::EnsureXBLScope(JSContext *cx) return mXBLScope; } +bool +XPCWrappedNativeScope::AllowXBLScope() +{ + // We only disallow XBL scopes in remote XUL situations. + MOZ_ASSERT_IF(!mAllowXBLScope, + nsContentUtils::AllowXULXBLForPrincipal(GetPrincipal())); + return mAllowXBLScope; +} + namespace xpc { JSObject *GetXBLScope(JSContext *cx, JSObject *contentScopeArg) { diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 61ea9fb7fda2..3c4dde7eb329 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -1710,9 +1710,15 @@ bool IsChromeOrXBL(JSContext* cx, JSObject* /* unused */) { MOZ_ASSERT(NS_IsMainThread()); - JSCompartment* compartment = js::GetContextCompartment(cx); - return AccessCheck::isChrome(compartment) || - IsXBLScope(compartment); + JSCompartment* c = js::GetContextCompartment(cx); + + // For remote XUL, we run XBL in the XUL scope. Given that we care about + // compat and not security for remote XUL, we just always claim to be XBL. + // + // Note that, for performance, we don't check AllowXULXBLForPrincipal here, + // and instead rely on the fact that AllowXBLScope() only returns false in + // remote XUL situations. + return AccessCheck::isChrome(c) || IsXBLScope(c) || !AllowXBLScope(c); } } // namespace dom diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 340471159634..ee4a2ef7c242 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -1413,7 +1413,7 @@ public: nsAutoPtr mWaiverWrapperMap; bool IsXBLScope() { return mIsXBLScope; } - bool AllowXBLScope() { return mAllowXBLScope; } + bool AllowXBLScope(); protected: virtual ~XPCWrappedNativeScope(); @@ -1449,20 +1449,17 @@ private: bool mIsXBLScope; - // There are certain cases where we explicitly disallow XBL scopes: they - // can be prefed off, or we might be running in a remote XUL domain where - // we want to run all XBL in content to maintain compat. We separately + // For remote XUL domains, we run all XBL in the content scope for compat + // reasons (though we sometimes pref this off for automation). We separately // track the result of this decision (mAllowXBLScope), from the decision // of whether to actually _use_ an XBL scope (mUseXBLScope), which depends // on the type of global and whether the compartment is system principal // or not. // - // This distinction is useful primarily because it tells us whether we - // can infer the XBL-ness of a caller by checking that the caller is - // running in an XBL scope, or whether we need to check the XBL bit on the - // script. The XBL bit is nasty, so we want to consult it only if we - // absolutely have to, which should generally happen only in unsupported - // pref configurations. + // This distinction is useful primarily because, if true, we know that we + // have no way of distinguishing XBL script from content script for the + // given scope. In these (unsupported) situations, we just always claim to + // be XBL. bool mAllowXBLScope; bool mUseXBLScope; };