From 032bee38ffe9a22bb9b61a96fb09e75771b76c90 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 8 Feb 2013 14:24:20 +0000 Subject: [PATCH] Bug 821850 - Check for XBL scopes in nsContentUtils::IsCallerXBL(). r=bz --- content/base/src/nsContentUtils.cpp | 8 +++++++- js/xpconnect/src/XPCJSRuntime.cpp | 10 ++++++++++ js/xpconnect/src/xpcpublic.h | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 72fcb643467..b461989c790 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -1752,7 +1752,13 @@ nsContentUtils::IsCallerXBL() { JSScript *script; JSContext *cx = GetCurrentJSContext(); - if (!cx || !JS_DescribeScriptedCaller(cx, &script, nullptr) || !script) + if (!cx) + return false; + // New Hotness. + if (xpc::IsXBLScope(js::GetContextCompartment(cx))) + return true; + // XBL scopes are behind a pref, so check the XBL bit as well. + if (!JS_DescribeScriptedCaller(cx, &script, nullptr) || !script) return false; return JS_GetScriptUserBit(script); } diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 7964133efd5..3d9a55c9d77 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -237,6 +237,16 @@ EnsureCompartmentPrivate(JSCompartment *c) return priv; } +bool +IsXBLScope(JSCompartment *compartment) +{ + // We always eagerly create compartment privates for XBL scopes. + CompartmentPrivate *priv = GetCompartmentPrivate(compartment); + if (!priv || !priv->scope) + return false; + return priv->scope->IsXBLScope(); +} + bool IsUniversalXPConnectEnabled(JSCompartment *compartment) { diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index 17b6a9bd691..e5c3e5f81cd 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -333,6 +333,8 @@ bool StringToJsval(JSContext* cx, mozilla::dom::DOMString& str, nsIPrincipal *GetCompartmentPrincipal(JSCompartment *compartment); +bool IsXBLScope(JSCompartment *compartment); + void DumpJSHeap(FILE* file); void SetLocationForGlobal(JSObject *global, const nsACString& location);