Bug 655649 - Recompute cross-compartment wrappers when setting document.domain. r=mrbkap

This commit is contained in:
Bobby Holley 2012-07-12 10:10:15 +02:00
Родитель 8a10e6848c
Коммит 9ecc2d4946
1 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@ -22,6 +22,8 @@
#include "nsIClassInfoImpl.h"
#include "nsDOMError.h"
#include "nsIContentSecurityPolicy.h"
#include "nsContentUtils.h"
#include "jswrapper.h"
#include "nsPrincipal.h"
@ -963,6 +965,18 @@ nsPrincipal::SetDomain(nsIURI* aDomain)
// Domain has changed, forget cached security policy
SetSecurityPolicy(nsnull);
// Recompute all wrappers between compartments using this principal and other
// non-chrome compartments.
JSContext *cx = nsContentUtils::GetSafeJSContext();
NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
JSPrincipals *principals = nsJSPrincipals::get(static_cast<nsIPrincipal*>(this));
bool success = js::RecomputeWrappers(cx, js::ContentCompartmentsOnly(),
js::CompartmentsWithPrincipals(principals));
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
success = js::RecomputeWrappers(cx, js::CompartmentsWithPrincipals(principals),
js::ContentCompartmentsOnly());
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
return NS_OK;
}