mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 06:15:43 +00:00
Bug 1464374 part 9 - Turn JS_SetCompartmentPrincipals into JS::SetRealmPrincipals. r=bz
This commit is contained in:
parent
ad9d1f408f
commit
3721ae615a
@ -2364,9 +2364,9 @@ nsIDocument::ResetToURI(nsIURI* aURI,
|
||||
mFontFaceSet->RefreshStandardFontLoadPrincipal();
|
||||
}
|
||||
|
||||
// Refresh the principal on the compartment.
|
||||
// Refresh the principal on the realm.
|
||||
if (nsPIDOMWindowInner* win = GetInnerWindow()) {
|
||||
nsGlobalWindowInner::Cast(win)->RefreshCompartmentPrincipal();
|
||||
nsGlobalWindowInner::Cast(win)->RefreshRealmPrincipal();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3632,10 +3632,10 @@ nsGlobalWindowInner::GetChildWindow(const nsAString& aName)
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindowInner::RefreshCompartmentPrincipal()
|
||||
nsGlobalWindowInner::RefreshRealmPrincipal()
|
||||
{
|
||||
JS_SetCompartmentPrincipals(js::GetObjectCompartment(GetWrapperPreserveColor()),
|
||||
nsJSPrincipals::get(mDoc->NodePrincipal()));
|
||||
JS::SetRealmPrincipals(js::GetNonCCWObjectRealm(GetWrapperPreserveColor()),
|
||||
nsJSPrincipals::get(mDoc->NodePrincipal()));
|
||||
}
|
||||
|
||||
already_AddRefed<nsIWidget>
|
||||
|
@ -377,7 +377,7 @@ public:
|
||||
virtual void MaybeUpdateTouchState() override;
|
||||
|
||||
// Inner windows only.
|
||||
void RefreshCompartmentPrincipal();
|
||||
void RefreshRealmPrincipal();
|
||||
|
||||
// For accessing protected field mFullScreen
|
||||
friend class FullscreenTransitionTask;
|
||||
|
@ -1747,24 +1747,26 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument,
|
||||
}
|
||||
|
||||
// Inner windows are only reused for same-origin principals, but the principals
|
||||
// don't necessarily match exactly. Update the principal on the compartment to
|
||||
// match the new document.
|
||||
// NB: We don't just call currentInner->RefreshCompartmentPrincipals() here
|
||||
// don't necessarily match exactly. Update the principal on the realm to match
|
||||
// the new document.
|
||||
// NB: We don't just call currentInner->RefreshRealmPrincipals() here
|
||||
// because we haven't yet set its mDoc to aDocument.
|
||||
JSCompartment *compartment = js::GetObjectCompartment(newInnerGlobal);
|
||||
JS::Realm* realm = js::GetNonCCWObjectRealm(newInnerGlobal);
|
||||
#ifdef DEBUG
|
||||
bool sameOrigin = false;
|
||||
nsIPrincipal *existing =
|
||||
nsJSPrincipals::get(JS_GetCompartmentPrincipals(compartment));
|
||||
nsJSPrincipals::get(JS::GetRealmPrincipals(realm));
|
||||
aDocument->NodePrincipal()->Equals(existing, &sameOrigin);
|
||||
MOZ_ASSERT(sameOrigin);
|
||||
#endif
|
||||
|
||||
JSCompartment* compartment = JS::GetCompartmentForRealm(realm);
|
||||
MOZ_ASSERT_IF(aDocument == oldDoc,
|
||||
xpc::GetCompartmentPrincipal(compartment) ==
|
||||
aDocument->NodePrincipal());
|
||||
#endif
|
||||
if (aDocument != oldDoc) {
|
||||
JS_SetCompartmentPrincipals(compartment,
|
||||
nsJSPrincipals::get(aDocument->NodePrincipal()));
|
||||
JS::SetRealmPrincipals(realm,
|
||||
nsJSPrincipals::get(aDocument->NodePrincipal()));
|
||||
// Make sure we clear out the old content XBL scope, so the new one will
|
||||
// get created with a principal that subsumes our new principal.
|
||||
xpc::ClearContentXBLScope(newInnerGlobal);
|
||||
|
@ -7961,7 +7961,7 @@ js::NewRealm(JSContext* cx, JSPrincipals* principals, const JS::RealmOptions& op
|
||||
return nullptr;
|
||||
|
||||
// Set up the principals.
|
||||
JS_SetCompartmentPrincipals(JS::GetCompartmentForRealm(realm), principals);
|
||||
JS::SetRealmPrincipals(realm, principals);
|
||||
|
||||
JSCompartment* comp = realm->compartment();
|
||||
if (!comp->realms().append(realm)) {
|
||||
|
@ -169,10 +169,9 @@ JS::GetRealmPrincipals(JS::Realm* realm)
|
||||
}
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
JS_SetCompartmentPrincipals(JSCompartment* compartment, JSPrincipals* principals)
|
||||
JS::SetRealmPrincipals(JS::Realm* realm, JSPrincipals* principals)
|
||||
{
|
||||
// Short circuit if there's no change.
|
||||
Realm* realm = JS::GetRealmForCompartment(compartment);
|
||||
if (principals == realm->principals())
|
||||
return;
|
||||
|
||||
|
@ -190,9 +190,6 @@ JS_GetIsSecureContext(JSCompartment* compartment);
|
||||
extern JS_FRIEND_API(JSPrincipals*)
|
||||
JS_GetCompartmentPrincipals(JSCompartment* compartment);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
JS_SetCompartmentPrincipals(JSCompartment* compartment, JSPrincipals* principals);
|
||||
|
||||
extern JS_FRIEND_API(JSPrincipals*)
|
||||
JS_GetScriptPrincipals(JSScript* script);
|
||||
|
||||
@ -328,6 +325,9 @@ IsGCPoisoning();
|
||||
extern JS_FRIEND_API(JSPrincipals*)
|
||||
GetRealmPrincipals(JS::Realm* realm);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
SetRealmPrincipals(JS::Realm* realm, JSPrincipals* principals);
|
||||
|
||||
} // namespace JS
|
||||
|
||||
/**
|
||||
|
@ -753,7 +753,7 @@ CreateGlobalForOffThreadParse(JSContext* cx, const gc::AutoSuppressGC& nogc)
|
||||
|
||||
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
|
||||
|
||||
JS_SetCompartmentPrincipals(global->compartment(), currentRealm->principals());
|
||||
JS::SetRealmPrincipals(global->realm(), currentRealm->principals());
|
||||
|
||||
return global;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user