From dbef115db9ca4847e96e9dc5095b85f20b6e4c6e Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Fri, 10 Apr 2015 18:10:00 +0200 Subject: [PATCH] Bug 1149420 - Make the IndexedDB permissions prompt work in e10s. r=bent/mfinkle --- browser/base/content/browser.js | 15 ++++---------- dom/indexedDB/ActorsChild.cpp | 13 +++++++++--- dom/indexedDB/ActorsParent.cpp | 8 ++++---- dom/indexedDB/ActorsParent.h | 3 ++- dom/indexedDB/PermissionRequestBase.cpp | 25 ++++++++++++------------ dom/indexedDB/PermissionRequestBase.h | 7 +++++-- dom/ipc/TabParent.cpp | 11 ++--------- mobile/android/chrome/content/browser.js | 7 +++---- 8 files changed, 43 insertions(+), 46 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 6875397f373..fcc5156ce51 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -6181,20 +6181,13 @@ var IndexedDBPromptHelper = { var requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor); - var contentWindow = requestor.getInterface(Ci.nsIDOMWindow); - var contentDocument = contentWindow.document; - var browserWindow = - OfflineApps._getBrowserWindowForContentWindow(contentWindow); - - if (browserWindow != window) { - // Must belong to some other window. + var browser = requestor.getInterface(Ci.nsIDOMNode); + if (browser.ownerDocument.defaultView != window) { + // Only listen for notifications for browsers in our chrome window. return; } - var browser = - OfflineApps._getBrowserForContentWindow(browserWindow, contentWindow); - - var host = contentDocument.documentURIObject.asciiHost; + var host = browser.currentURI.asciiHost; var message; var responseTopic; diff --git a/dom/indexedDB/ActorsChild.cpp b/dom/indexedDB/ActorsChild.cpp index ee31c2b27d5..1009dc47d5b 100644 --- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -19,6 +19,7 @@ #include "mozilla/BasicEvents.h" #include "mozilla/Maybe.h" #include "mozilla/TypeTraits.h" +#include "mozilla/dom/Element.h" #include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/TabChild.h" #include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileChild.h" @@ -528,9 +529,9 @@ class PermissionRequestMainProcessHelper final public: PermissionRequestMainProcessHelper(BackgroundFactoryRequestChild* aActor, IDBFactory* aFactory, - nsPIDOMWindow* aWindow, + Element* aOwnerElement, nsIPrincipal* aPrincipal) - : PermissionRequestBase(aWindow, aPrincipal) + : PermissionRequestBase(aOwnerElement, aPrincipal) , mActor(aActor) , mFactory(aFactory) { @@ -1129,8 +1130,14 @@ BackgroundFactoryRequestChild::RecvPermissionChallenge( nsCOMPtr window = mFactory->GetParentObject(); MOZ_ASSERT(window); + nsCOMPtr ownerElement = + do_QueryInterface(window->GetChromeEventHandler()); + if (NS_WARN_IF(!ownerElement)) { + return false; + } + nsRefPtr helper = - new PermissionRequestMainProcessHelper(this, mFactory, window, principal); + new PermissionRequestMainProcessHelper(this, mFactory, ownerElement, principal); PermissionRequestBase::PermissionValue permission; if (NS_WARN_IF(NS_FAILED(helper->PromptIfNeeded(&permission)))) { diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 7c726a98e9d..0b88b75ab22 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -7489,9 +7489,9 @@ class PermissionRequestHelper final bool mActorDestroyed; public: - PermissionRequestHelper(nsPIDOMWindow* aWindow, + PermissionRequestHelper(Element* aOwnerElement, nsIPrincipal* aPrincipal) - : PermissionRequestBase(aWindow, aPrincipal) + : PermissionRequestBase(aOwnerElement, aPrincipal) , mActorDestroyed(false) { } @@ -8161,13 +8161,13 @@ DeallocPBackgroundIDBFactoryParent(PBackgroundIDBFactoryParent* aActor) } PIndexedDBPermissionRequestParent* -AllocPIndexedDBPermissionRequestParent(nsPIDOMWindow* aWindow, +AllocPIndexedDBPermissionRequestParent(Element* aOwnerElement, nsIPrincipal* aPrincipal) { MOZ_ASSERT(NS_IsMainThread()); nsRefPtr actor = - new PermissionRequestHelper(aWindow, aPrincipal); + new PermissionRequestHelper(aOwnerElement, aPrincipal); return actor.forget().take(); } diff --git a/dom/indexedDB/ActorsParent.h b/dom/indexedDB/ActorsParent.h index ad42be4ee93..02dc7e70182 100644 --- a/dom/indexedDB/ActorsParent.h +++ b/dom/indexedDB/ActorsParent.h @@ -14,6 +14,7 @@ class nsPIDOMWindow; namespace mozilla { namespace dom { +class Element; class TabParent; namespace quota { @@ -39,7 +40,7 @@ bool DeallocPBackgroundIDBFactoryParent(PBackgroundIDBFactoryParent* aActor); PIndexedDBPermissionRequestParent* -AllocPIndexedDBPermissionRequestParent(nsPIDOMWindow* aWindow, +AllocPIndexedDBPermissionRequestParent(Element* aOwnerElement, nsIPrincipal* aPrincipal); bool diff --git a/dom/indexedDB/PermissionRequestBase.cpp b/dom/indexedDB/PermissionRequestBase.cpp index d7f9c0ebe7b..9dd556694d9 100644 --- a/dom/indexedDB/PermissionRequestBase.cpp +++ b/dom/indexedDB/PermissionRequestBase.cpp @@ -7,6 +7,7 @@ #include "MainThreadUtils.h" #include "mozilla/Assertions.h" #include "mozilla/Services.h" +#include "mozilla/dom/Element.h" #include "nsIDOMWindow.h" #include "nsIObserverService.h" #include "nsIPrincipal.h" @@ -46,13 +47,13 @@ AssertSanity() } // anonymous namespace -PermissionRequestBase::PermissionRequestBase(nsPIDOMWindow* aWindow, +PermissionRequestBase::PermissionRequestBase(Element* aOwnerElement, nsIPrincipal* aPrincipal) - : mWindow(aWindow) + : mOwnerElement(aOwnerElement) , mPrincipal(aPrincipal) { AssertSanity(); - MOZ_ASSERT(aWindow); + MOZ_ASSERT(aOwnerElement); MOZ_ASSERT(aPrincipal); } @@ -125,8 +126,8 @@ PermissionRequestBase::PromptIfNeeded(PermissionValue* aCurrentValue) // Tricky, we want to release the window and principal in all cases except // when we successfully prompt. - nsCOMPtr window; - mWindow.swap(window); + nsCOMPtr element; + mOwnerElement.swap(element); nsCOMPtr principal; mPrincipal.swap(principal); @@ -146,7 +147,7 @@ PermissionRequestBase::PromptIfNeeded(PermissionValue* aCurrentValue) } // We're about to prompt so swap the members back. - window.swap(mWindow); + element.swap(mOwnerElement); principal.swap(mPrincipal); rv = obsSvc->NotifyObservers(static_cast(this), @@ -154,7 +155,7 @@ PermissionRequestBase::PromptIfNeeded(PermissionValue* aCurrentValue) nullptr); if (NS_WARN_IF(NS_FAILED(rv))) { // Finally release if we failed the prompt. - mWindow = nullptr; + mOwnerElement = nullptr; mPrincipal = nullptr; return rv; } @@ -200,8 +201,8 @@ PermissionRequestBase::GetInterface(const nsIID& aIID, return QueryInterface(aIID, aResult); } - if (aIID.Equals(NS_GET_IID(nsIDOMWindow)) && mWindow) { - return mWindow->QueryInterface(aIID, aResult); + if (aIID.Equals(NS_GET_IID(nsIDOMNode)) && mOwnerElement) { + return mOwnerElement->QueryInterface(aIID, aResult); } *aResult = nullptr; @@ -215,11 +216,11 @@ PermissionRequestBase::Observe(nsISupports* aSubject, { AssertSanity(); MOZ_ASSERT(!strcmp(aTopic, kPermissionResponseTopic)); - MOZ_ASSERT(mWindow); + MOZ_ASSERT(mOwnerElement); MOZ_ASSERT(mPrincipal); - nsCOMPtr window; - mWindow.swap(window); + nsCOMPtr element; + element.swap(mOwnerElement); nsCOMPtr principal; mPrincipal.swap(principal); diff --git a/dom/indexedDB/PermissionRequestBase.h b/dom/indexedDB/PermissionRequestBase.h index 3ebf9b81f55..80ffda1dd5c 100644 --- a/dom/indexedDB/PermissionRequestBase.h +++ b/dom/indexedDB/PermissionRequestBase.h @@ -18,13 +18,16 @@ class nsPIDOMWindow; namespace mozilla { namespace dom { + +class Element; + namespace indexedDB { class PermissionRequestBase : public nsIObserver , public nsIInterfaceRequestor { - nsCOMPtr mWindow; + nsCOMPtr mOwnerElement; nsCOMPtr mPrincipal; public: @@ -51,7 +54,7 @@ public: PromptIfNeeded(PermissionValue* aCurrentValue); protected: - PermissionRequestBase(nsPIDOMWindow* aWindow, + PermissionRequestBase(Element* aOwnerElement, nsIPrincipal* aPrincipal); // Reference counted. diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index aacbc7c6c13..4751cd7c93e 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1121,19 +1121,12 @@ TabParent::AllocPIndexedDBPermissionRequestParent(const Principal& aPrincipal) MOZ_CRASH("Figure out security checks for bridged content!"); } - nsCOMPtr window; - nsCOMPtr frame = do_QueryInterface(mFrameElement); - if (frame) { - MOZ_ASSERT(frame->OwnerDoc()); - window = do_QueryInterface(frame->OwnerDoc()->GetWindow()); - } - - if (!window) { + if (NS_WARN_IF(!mFrameElement)) { return nullptr; } return - mozilla::dom::indexedDB::AllocPIndexedDBPermissionRequestParent(window, + mozilla::dom::indexedDB::AllocPIndexedDBPermissionRequestParent(mFrameElement, principal); } diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index e29936eb509..5c69e8ea9ee 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -6670,13 +6670,12 @@ var IndexedDB = { let requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor); - let contentWindow = requestor.getInterface(Ci.nsIDOMWindow); - let contentDocument = contentWindow.document; - let tab = BrowserApp.getTabForWindow(contentWindow); + let browser = requestor.getInterface(Ci.nsIDOMNode); + let tab = BrowserApp.getTabForBrowser(browser); if (!tab) return; - let host = contentDocument.documentURIObject.asciiHost; + let host = browser.currentURI.asciiHost; let strings = Strings.browser;