зеркало из https://github.com/mozilla/gecko-dev.git
Bug 774633 - Assert against switching origins on a compartment. r=jst
This commit is contained in:
Родитель
38274fd965
Коммит
fb072823ff
|
@ -1884,7 +1884,15 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
|
|||
// match the new document.
|
||||
// NB: We don't just call currentInner->RefreshCompartmentPrincipals() here
|
||||
// because we haven't yet set its mDoc to aDocument.
|
||||
JS_SetCompartmentPrincipals(js::GetObjectCompartment(currentInner->mJSObject),
|
||||
JSCompartment *compartment = js::GetObjectCompartment(currentInner->mJSObject);
|
||||
#ifdef DEBUG
|
||||
bool sameOrigin = false;
|
||||
nsIPrincipal *existing =
|
||||
nsJSPrincipals::get(JS_GetCompartmentPrincipals(compartment));
|
||||
aDocument->NodePrincipal()->Equals(existing, &sameOrigin);
|
||||
MOZ_ASSERT(sameOrigin);
|
||||
#endif
|
||||
JS_SetCompartmentPrincipals(compartment,
|
||||
nsJSPrincipals::get(aDocument->NodePrincipal()));
|
||||
} else {
|
||||
if (aState) {
|
||||
|
|
|
@ -196,10 +196,20 @@ JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals
|
|||
if (principals == compartment->principals)
|
||||
return;
|
||||
|
||||
// Any compartment with the trusted principals -- and there can be
|
||||
// multiple -- is a system compartment.
|
||||
JSPrincipals *trusted = compartment->rt->trustedPrincipals();
|
||||
bool isSystem = principals && principals == trusted;
|
||||
|
||||
// Clear out the old principals, if any.
|
||||
if (compartment->principals) {
|
||||
JS_DropPrincipals(compartment->rt, compartment->principals);
|
||||
compartment->principals = NULL;
|
||||
// We'd like to assert that our new principals is always same-origin
|
||||
// with the old one, but JSPrincipals doesn't give us a way to do that.
|
||||
// But we can at least assert that we're not switching between system
|
||||
// and non-system.
|
||||
JS_ASSERT(compartment->isSystemCompartment == isSystem);
|
||||
}
|
||||
|
||||
// Set up the new principals.
|
||||
|
@ -208,10 +218,8 @@ JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals
|
|||
compartment->principals = principals;
|
||||
}
|
||||
|
||||
// Any compartment with the trusted principals -- and there can be
|
||||
// multiple -- is a system compartment.
|
||||
JSPrincipals *trusted = compartment->rt->trustedPrincipals();
|
||||
compartment->isSystemCompartment = principals && principals == trusted;
|
||||
// Update the system flag.
|
||||
compartment->isSystemCompartment = isSystem;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSBool)
|
||||
|
|
Загрузка…
Ссылка в новой задаче