Bug 753981 - 'XHR in Web Workers bypasses Offline AppCache'. r=smaug.

This commit is contained in:
Ben Turner 2012-11-01 20:37:55 -07:00
parent b51b4ca7f7
commit 038e0fa5f4
2 changed files with 18 additions and 2 deletions

View File

@ -465,6 +465,8 @@ nsXMLHttpRequest::Init(nsIPrincipal* aPrincipal,
nsPIDOMWindow* aOwnerWindow,
nsIURI* aBaseURI)
{
NS_ASSERTION(!aOwnerWindow || aOwnerWindow->IsOuterWindow(),
"Expecting an outer window here!");
NS_ENSURE_ARG_POINTER(aPrincipal);
Construct(aPrincipal,
aOwnerWindow ? aOwnerWindow->GetCurrentInnerWindow() : nullptr,

View File

@ -154,12 +154,26 @@ public:
NS_ASSERTION(mWorkerPrivate, "Must have a worker here!");
if (!mXHR) {
nsPIDOMWindow* ownerWindow = mWorkerPrivate->GetWindow();
if (ownerWindow) {
ownerWindow = ownerWindow->GetOuterWindow();
if (!ownerWindow) {
NS_ERROR("No outer window?!");
return false;
}
nsPIDOMWindow* innerWindow = ownerWindow->GetCurrentInnerWindow();
if (mWorkerPrivate->GetWindow() != innerWindow) {
NS_WARNING("Window has navigated, cannot create XHR here.");
return false;
}
}
mXHR = new nsXMLHttpRequest();
if (NS_FAILED(mXHR->Init(mWorkerPrivate->GetPrincipal(),
mWorkerPrivate->GetScriptContext(),
mWorkerPrivate->GetWindow(),
mWorkerPrivate->GetBaseURI()))) {
ownerWindow, mWorkerPrivate->GetBaseURI()))) {
mXHR = nullptr;
return false;
}