Bug 1017310 - Rename *XBLScope to *ContentXBLScope in xpconnect (r=bholley)

This commit is contained in:
Bill McCloskey 2014-06-02 18:04:21 -07:00
parent 1d1a56c87a
commit 9157c8fd4d
19 changed files with 85 additions and 82 deletions

View File

@ -1039,7 +1039,7 @@ nsScriptSecurityManager::CanCreateWrapper(JSContext *cx,
}
// We give remote-XUL whitelisted domains a free pass here. See bug 932906.
if (!xpc::AllowXBLScope(js::GetContextCompartment(cx)))
if (!xpc::AllowContentXBLScope(js::GetContextCompartment(cx)))
{
return NS_OK;
}

View File

@ -188,7 +188,7 @@ public:
static bool IsCallerChrome();
static bool ThreadsafeIsCallerChrome();
static bool IsCallerXBL();
static bool IsCallerContentXBL();
static bool IsImageSrcSetDisabled();

View File

@ -1714,7 +1714,7 @@ nsContentUtils::ThreadsafeIsCallerChrome()
}
bool
nsContentUtils::IsCallerXBL()
nsContentUtils::IsCallerContentXBL()
{
JSContext *cx = GetCurrentJSContext();
if (!cx)
@ -1724,12 +1724,12 @@ nsContentUtils::IsCallerXBL()
// For remote XUL, we run XBL in the XUL scope. Given that we care about
// compat and not security for remote XUL, just always claim to be XBL.
if (!xpc::AllowXBLScope(c)) {
if (!xpc::AllowContentXBLScope(c)) {
MOZ_ASSERT(nsContentUtils::AllowXULXBLForPrincipal(xpc::GetCompartmentPrincipal(c)));
return true;
}
return xpc::IsXBLScope(c);
return xpc::IsContentXBLScope(c);
}
@ -5585,7 +5585,7 @@ nsContentTypeParser::GetParameter(const char* aParameterName, nsAString& aResult
bool
nsContentUtils::CanAccessNativeAnon()
{
return IsCallerChrome() || IsCallerXBL();
return IsCallerChrome() || IsCallerContentXBL();
}
/* static */ nsresult

View File

@ -2660,7 +2660,7 @@ nsINode::WrapObject(JSContext *aCx)
JS::Rooted<JSObject*> obj(aCx, WrapNode(aCx));
MOZ_ASSERT_IF(ChromeOnlyAccess(),
xpc::IsInXBLScope(obj) || !xpc::UseXBLScope(js::GetObjectCompartment(obj)));
xpc::IsInContentXBLScope(obj) || !xpc::UseContentXBLScope(js::GetObjectCompartment(obj)));
return obj;
}

View File

@ -2650,7 +2650,7 @@ nsObjectLoadingContent::ScriptRequestPluginInstance(JSContext* aCx,
MOZ_ASSERT_IF(nsContentUtils::GetCurrentJSContext(),
aCx == nsContentUtils::GetCurrentJSContext());
bool callerIsContentJS = (!nsContentUtils::IsCallerChrome() &&
!nsContentUtils::IsCallerXBL() &&
!nsContentUtils::IsCallerContentXBL() &&
js::IsContextRunningJS(aCx));
nsCOMPtr<nsIContent> thisContent =

View File

@ -1405,7 +1405,7 @@ WrapNativeParent(JSContext* cx, T* p, nsWrapperCache* cache,
// If useXBLScope is true, it means that the canonical reflector for this
// native object should live in the XBL scope.
if (xpc::IsInXBLScope(parent)) {
if (xpc::IsInContentXBLScope(parent)) {
return parent;
}
JS::Rooted<JSObject*> rootedParent(cx, parent);

View File

@ -104,7 +104,7 @@ static const JSClass gPrototypeJSClass = {
// Constructors/Destructors
nsXBLBinding::nsXBLBinding(nsXBLPrototypeBinding* aBinding)
: mMarkedForDeath(false)
, mUsingXBLScope(false)
, mUsingContentXBLScope(false)
, mPrototypeBinding(aBinding)
{
NS_ASSERTION(mPrototypeBinding, "Must have a prototype binding!");
@ -115,7 +115,7 @@ nsXBLBinding::nsXBLBinding(nsXBLPrototypeBinding* aBinding)
// Constructor used by web components.
nsXBLBinding::nsXBLBinding(ShadowRoot* aShadowRoot, nsXBLPrototypeBinding* aBinding)
: mMarkedForDeath(false),
mUsingXBLScope(false),
mUsingContentXBLScope(false),
mPrototypeBinding(aBinding),
mContent(aShadowRoot)
{
@ -278,7 +278,7 @@ nsXBLBinding::SetBoundElement(nsIContent* aElement)
// is not given in the handler declaration.
nsCOMPtr<nsIGlobalObject> go = mBoundElement->OwnerDoc()->GetScopeObject();
NS_ENSURE_TRUE_VOID(go && go->GetGlobalJSObject());
mUsingXBLScope = xpc::UseXBLScope(js::GetObjectCompartment(go->GetGlobalJSObject()));
mUsingContentXBLScope = xpc::UseContentXBLScope(js::GetObjectCompartment(go->GetGlobalJSObject()));
}
bool
@ -512,7 +512,7 @@ nsXBLBinding::InstallEventHandlers()
bool hasAllowUntrustedAttr = curr->HasAllowUntrustedAttr();
if ((hasAllowUntrustedAttr && curr->AllowUntrustedEvents()) ||
(!hasAllowUntrustedAttr && !isChromeDoc && !mUsingXBLScope)) {
(!hasAllowUntrustedAttr && !isChromeDoc && !mUsingContentXBLScope)) {
flags.mAllowUntrustedEvents = true;
}
@ -528,7 +528,7 @@ nsXBLBinding::InstallEventHandlers()
for (i = 0; i < keyHandlers->Count(); ++i) {
nsXBLKeyEventHandler* handler = keyHandlers->ObjectAt(i);
handler->SetIsBoundToChrome(isChromeDoc);
handler->SetUsingXBLScope(mUsingXBLScope);
handler->SetUsingContentXBLScope(mUsingContentXBLScope);
nsAutoString type;
handler->GetEventName(type);
@ -920,8 +920,8 @@ GetOrCreateMapEntryForPrototype(JSContext *cx, JS::Handle<JSObject*> proto)
// So we define two maps - one class objects that live in content (prototyped
// to content prototypes), and the other for class objects that live in the
// XBL scope (prototyped to cross-compartment-wrapped content prototypes).
const char* name = xpc::IsInXBLScope(proto) ? "__ContentClassObjectMap__"
: "__XBLClassObjectMap__";
const char* name = xpc::IsInContentXBLScope(proto) ? "__ContentClassObjectMap__"
: "__XBLClassObjectMap__";
// Now, enter the XBL scope, since that's where we need to operate, and wrap
// the proto accordingly.
@ -1116,7 +1116,7 @@ nsXBLBinding::LookupMember(JSContext* aCx, JS::Handle<jsid> aId,
// We do a release-mode assertion here to be extra safe.
JS::Rooted<JSObject*> boundScope(aCx,
js::GetGlobalForObjectCrossCompartment(mBoundElement->GetWrapper()));
MOZ_RELEASE_ASSERT(!xpc::IsInXBLScope(boundScope));
MOZ_RELEASE_ASSERT(!xpc::IsInContentXBLScope(boundScope));
JS::Rooted<JSObject*> xblScope(aCx, xpc::GetXBLScope(aCx, boundScope));
NS_ENSURE_TRUE(xblScope, false);
MOZ_ASSERT(boundScope != xblScope);

View File

@ -160,7 +160,7 @@ public:
protected:
bool mMarkedForDeath;
bool mUsingXBLScope;
bool mUsingContentXBLScope;
nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.

View File

@ -71,7 +71,7 @@ nsXBLKeyEventHandler::nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase,
mPhase(aPhase),
mType(aType),
mIsBoundToChrome(false),
mUsingXBLScope(false)
mUsingContentXBLScope(false)
{
}
@ -97,7 +97,7 @@ nsXBLKeyEventHandler::ExecuteMatchedHandlers(nsIDOMKeyEvent* aKeyEvent,
bool hasAllowUntrustedAttr = handler->HasAllowUntrustedAttr();
if ((trustedEvent ||
(hasAllowUntrustedAttr && handler->AllowUntrustedEvents()) ||
(!hasAllowUntrustedAttr && !mIsBoundToChrome && !mUsingXBLScope)) &&
(!hasAllowUntrustedAttr && !mIsBoundToChrome && !mUsingContentXBLScope)) &&
handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreShiftKey)) {
handler->ExecuteHandler(target, aKeyEvent);
executed = true;

View File

@ -86,9 +86,9 @@ public:
mIsBoundToChrome = aIsBoundToChrome;
}
void SetUsingXBLScope(bool aUsingXBLScope)
void SetUsingContentXBLScope(bool aUsingContentXBLScope)
{
mUsingXBLScope = aUsingXBLScope;
mUsingContentXBLScope = aUsingContentXBLScope;
}
private:
@ -101,7 +101,7 @@ private:
uint8_t mPhase;
uint8_t mType;
bool mIsBoundToChrome;
bool mUsingXBLScope;
bool mUsingContentXBLScope;
};
nsresult

View File

@ -104,7 +104,7 @@ nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
MOZ_ASSERT(xpc::IsInXBLScope(globalObject) ||
MOZ_ASSERT(xpc::IsInContentXBLScope(globalObject) ||
globalObject == xpc::GetXBLScope(aCx, globalObject));
JS::Rooted<JSObject*> jsMethodObject(aCx, GetCompiledMethod());

View File

@ -129,7 +129,7 @@ nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
MOZ_ASSERT(mGetter.IsCompiled() && mSetter.IsCompiled());
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
MOZ_ASSERT(xpc::IsInXBLScope(globalObject) ||
MOZ_ASSERT(xpc::IsInContentXBLScope(globalObject) ||
globalObject == xpc::GetXBLScope(aCx, globalObject));
JS::Rooted<JSObject*> getter(aCx, mGetter.GetJSFunction());

View File

@ -503,19 +503,19 @@ Scriptability::Get(JSObject *aScope)
}
bool
IsXBLScope(JSCompartment *compartment)
IsContentXBLScope(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();
return priv->scope->IsContentXBLScope();
}
bool
IsInXBLScope(JSObject *obj)
IsInContentXBLScope(JSObject *obj)
{
return IsXBLScope(js::GetObjectCompartment(obj));
return IsContentXBLScope(js::GetObjectCompartment(obj));
}
bool

View File

@ -73,7 +73,7 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(JSContext *cx,
mComponents(nullptr),
mNext(nullptr),
mGlobalJSObject(aGlobal),
mIsXBLScope(false)
mIsContentXBLScope(false)
{
// add ourselves to the scopes list
{
@ -101,18 +101,18 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(JSContext *cx,
// In addition to being pref-controlled, we also disable XBL scopes for
// remote XUL domains, _except_ if we have an additional pref override set.
nsIPrincipal *principal = GetPrincipal();
mAllowXBLScope = !RemoteXULForbidsXBLScope(principal, aGlobal);
mAllowContentXBLScope = !RemoteXULForbidsXBLScope(principal, aGlobal);
// Determine whether to use an XBL scope.
mUseXBLScope = mAllowXBLScope;
if (mUseXBLScope) {
mUseContentXBLScope = mAllowContentXBLScope;
if (mUseContentXBLScope) {
const js::Class *clasp = js::GetObjectClass(mGlobalJSObject);
mUseXBLScope = !strcmp(clasp->name, "Window") ||
!strcmp(clasp->name, "ChromeWindow") ||
!strcmp(clasp->name, "ModalContentWindow");
mUseContentXBLScope = !strcmp(clasp->name, "Window") ||
!strcmp(clasp->name, "ChromeWindow") ||
!strcmp(clasp->name, "ModalContentWindow");
}
if (mUseXBLScope) {
mUseXBLScope = principal && !nsContentUtils::IsSystemPrincipal(principal);
if (mUseContentXBLScope) {
mUseContentXBLScope = principal && !nsContentUtils::IsSystemPrincipal(principal);
}
}
@ -186,20 +186,20 @@ XPCWrappedNativeScope::AttachComponentsObject(JSContext* aCx)
}
JSObject*
XPCWrappedNativeScope::EnsureXBLScope(JSContext *cx)
XPCWrappedNativeScope::EnsureContentXBLScope(JSContext *cx)
{
JS::RootedObject global(cx, GetGlobalJSObject());
MOZ_ASSERT(js::IsObjectInContextCompartment(global, cx));
MOZ_ASSERT(!mIsXBLScope);
MOZ_ASSERT(!mIsContentXBLScope);
MOZ_ASSERT(strcmp(js::GetObjectClass(global)->name,
"nsXBLPrototypeScript compilation scope"));
// If we already have a special XBL scope object, we know what to use.
if (mXBLScope)
return mXBLScope;
if (mContentXBLScope)
return mContentXBLScope;
// If this scope doesn't need an XBL scope, just return the global.
if (!mUseXBLScope)
if (!mUseContentXBLScope)
return global;
// Set up the sandbox options. Note that we use the DOM global as the
@ -228,22 +228,22 @@ XPCWrappedNativeScope::EnsureXBLScope(JSContext *cx)
RootedValue v(cx);
nsresult rv = CreateSandboxObject(cx, &v, ep, options);
NS_ENSURE_SUCCESS(rv, nullptr);
mXBLScope = &v.toObject();
mContentXBLScope = &v.toObject();
// Tag it.
EnsureCompartmentPrivate(js::UncheckedUnwrap(mXBLScope))->scope->mIsXBLScope = true;
EnsureCompartmentPrivate(js::UncheckedUnwrap(mContentXBLScope))->scope->mIsContentXBLScope = true;
// Good to go!
return mXBLScope;
return mContentXBLScope;
}
bool
XPCWrappedNativeScope::AllowXBLScope()
XPCWrappedNativeScope::AllowContentXBLScope()
{
// We only disallow XBL scopes in remote XUL situations.
MOZ_ASSERT_IF(!mAllowXBLScope,
MOZ_ASSERT_IF(!mAllowContentXBLScope,
nsContentUtils::AllowXULXBLForPrincipal(GetPrincipal()));
return mAllowXBLScope;
return mAllowContentXBLScope;
}
namespace xpc {
@ -251,23 +251,25 @@ JSObject *GetXBLScope(JSContext *cx, JSObject *contentScopeArg)
{
JS::RootedObject contentScope(cx, contentScopeArg);
JSAutoCompartment ac(cx, contentScope);
JSObject *scope = EnsureCompartmentPrivate(contentScope)->scope->EnsureXBLScope(cx);
JSObject *scope = EnsureCompartmentPrivate(contentScope)->scope->EnsureContentXBLScope(cx);
NS_ENSURE_TRUE(scope, nullptr); // See bug 858642.
scope = js::UncheckedUnwrap(scope);
JS::ExposeObjectToActiveJS(scope);
return scope;
}
bool AllowXBLScope(JSCompartment *c)
bool
AllowContentXBLScope(JSCompartment *c)
{
XPCWrappedNativeScope *scope = EnsureCompartmentPrivate(c)->scope;
return scope && scope->AllowXBLScope();
return scope && scope->AllowContentXBLScope();
}
bool UseXBLScope(JSCompartment *c)
bool
UseContentXBLScope(JSCompartment *c)
{
XPCWrappedNativeScope *scope = EnsureCompartmentPrivate(c)->scope;
return scope && scope->UseXBLScope();
return scope && scope->UseContentXBLScope();
}
} /* namespace xpc */
@ -301,7 +303,7 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
mXrayExpandos.destroy();
JSRuntime *rt = XPCJSRuntime::Get()->Runtime();
mXBLScope.finalize(rt);
mContentXBLScope.finalize(rt);
mGlobalJSObject.finalize(rt);
}

View File

@ -1577,9 +1577,9 @@ IsChromeOrXBL(JSContext* cx, JSObject* /* unused */)
// 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
// and instead rely on the fact that AllowContentXBLScope() only returns false in
// remote XUL situations.
return AccessCheck::isChrome(c) || IsXBLScope(c) || !AllowXBLScope(c);
return AccessCheck::isChrome(c) || IsContentXBLScope(c) || !AllowContentXBLScope(c);
}
} // namespace dom

View File

@ -1020,8 +1020,8 @@ public:
void TraceSelf(JSTracer *trc) {
MOZ_ASSERT(mGlobalJSObject);
mGlobalJSObject.trace(trc, "XPCWrappedNativeScope::mGlobalJSObject");
if (mXBLScope)
mXBLScope.trace(trc, "XPCWrappedNativeScope::mXBLScope");
if (mContentXBLScope)
mContentXBLScope.trace(trc, "XPCWrappedNativeScope::mXBLScope");
if (mXrayExpandos.initialized())
mXrayExpandos.trace(trc);
}
@ -1097,15 +1097,15 @@ public:
// Gets the appropriate scope object for XBL in this scope. The context
// must be same-compartment with the global upon entering, and the scope
// object is wrapped into the compartment of the global.
JSObject *EnsureXBLScope(JSContext *cx);
JSObject *EnsureContentXBLScope(JSContext *cx);
XPCWrappedNativeScope(JSContext *cx, JS::HandleObject aGlobal);
nsAutoPtr<JSObject2JSObjectMap> mWaiverWrapperMap;
bool IsXBLScope() { return mIsXBLScope; }
bool AllowXBLScope();
bool UseXBLScope() { return mUseXBLScope; }
bool IsContentXBLScope() { return mIsContentXBLScope; }
bool AllowContentXBLScope();
bool UseContentXBLScope() { return mUseContentXBLScope; }
protected:
virtual ~XPCWrappedNativeScope();
@ -1130,20 +1130,20 @@ private:
JS::ObjectPtr mGlobalJSObject;
// XBL Scope. This is is a lazily-created sandbox for non-system scopes.
// EnsureXBLScope() decides whether it needs to be created or not.
// EnsureContentXBLScope() decides whether it needs to be created or not.
// This reference is wrapped into the compartment of mGlobalJSObject.
JS::ObjectPtr mXBLScope;
JS::ObjectPtr mContentXBLScope;
nsAutoPtr<DOMExpandoSet> mDOMExpandoSet;
JS::WeakMapPtr<JSObject*, JSObject*> mXrayExpandos;
bool mIsXBLScope;
bool mIsContentXBLScope;
// 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
// track the result of this decision (mAllowContentXBLScope), from the decision
// of whether to actually _use_ an XBL scope (mUseContentXBLScope), which depends
// on the type of global and whether the compartment is system principal
// or not.
//
@ -1151,8 +1151,8 @@ private:
// 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;
bool mAllowContentXBLScope;
bool mUseContentXBLScope;
};
/***************************************************************************/

View File

@ -70,8 +70,8 @@ private:
JSObject *
TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target);
bool IsXBLScope(JSCompartment *compartment);
bool IsInXBLScope(JSObject *obj);
bool IsContentXBLScope(JSCompartment *compartment);
bool IsInContentXBLScope(JSObject *obj);
// Return a raw XBL scope object corresponding to contentScope, which must
// be an object whose global is a DOM window.
@ -90,23 +90,24 @@ JSObject *
GetXBLScope(JSContext *cx, JSObject *contentScope);
inline JSObject *
GetXBLScopeOrGlobal(JSContext *cx, JSObject *obj) {
if (IsInXBLScope(obj))
GetXBLScopeOrGlobal(JSContext *cx, JSObject *obj)
{
if (IsInContentXBLScope(obj))
return js::GetGlobalForObjectCrossCompartment(obj);
return GetXBLScope(cx, obj);
}
// Returns whether XBL scopes have been explicitly disabled for code running
// in this compartment. See the comment around mAllowXBLScope.
// in this compartment. See the comment around mAllowContentXBLScope.
bool
AllowXBLScope(JSCompartment *c);
AllowContentXBLScope(JSCompartment *c);
// Returns whether we will use an XBL scope for this compartment. This is
// semantically equivalent to comparing global != GetXBLScope(global), but it
// does not have the side-effect of eagerly creating the XBL scope if it does
// not already exist.
bool
UseXBLScope(JSCompartment *c);
UseContentXBLScope(JSCompartment *c);
bool
IsSandboxPrototypeProxy(JSObject *obj);

View File

@ -431,7 +431,7 @@ WrapperFactory::Rewrap(JSContext *cx, HandleObject existing, HandleObject obj,
// See bug 843829.
else if (targetSubsumesOrigin && !originSubsumesTarget &&
!waiveXrayFlag && xrayType == NotXray &&
IsXBLScope(target))
IsContentXBLScope(target))
{
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper, GentlyOpaque>::singleton;
}
@ -462,10 +462,10 @@ WrapperFactory::Rewrap(JSContext *cx, HandleObject existing, HandleObject obj,
// We have slightly different behavior for the case when the object
// being wrapped is in an XBL scope.
bool originIsXBLScope = IsXBLScope(origin);
bool originIsContentXBLScope = IsContentXBLScope(origin);
wrapper = SelectWrapper(securityWrapper, wantXrays, xrayType, waiveXrays,
originIsXBLScope);
originIsContentXBLScope);
}
if (!targetSubsumesOrigin) {

View File

@ -1775,7 +1775,7 @@ DEBUG_CheckXBLCallable(JSContext *cx, JSObject *obj)
// has been adopted into another compartment, those prototypes will now point
// to a different XBL scope (which is ok).
MOZ_ASSERT_IF(js::IsCrossCompartmentWrapper(obj),
xpc::IsXBLScope(js::GetObjectCompartment(js::UncheckedUnwrap(obj))));
xpc::IsContentXBLScope(js::GetObjectCompartment(js::UncheckedUnwrap(obj))));
MOZ_ASSERT(JS_ObjectIsCallable(cx, obj));
}
@ -1930,7 +1930,7 @@ XrayWrapper<Base, Traits>::getPropertyDescriptor(JSContext *cx, HandleObject wra
// Make sure to assert this.
nsCOMPtr<nsIContent> content;
if (!desc.object() &&
EnsureCompartmentPrivate(wrapper)->scope->IsXBLScope() &&
EnsureCompartmentPrivate(wrapper)->scope->IsContentXBLScope() &&
(content = do_QueryInterfaceNative(cx, wrapper)))
{
if (!nsContentUtils::LookupBindingMember(cx, content, id, desc))