Bug 1149420 - Make the IndexedDB permissions prompt work in e10s. r=bent/mfinkle

This commit is contained in:
Blake Kaplan 2015-04-10 18:10:00 +02:00
parent d3044dc4a3
commit dbef115db9
8 changed files with 43 additions and 46 deletions

View File

@ -6181,20 +6181,13 @@ var IndexedDBPromptHelper = {
var requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor); var requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor);
var contentWindow = requestor.getInterface(Ci.nsIDOMWindow); var browser = requestor.getInterface(Ci.nsIDOMNode);
var contentDocument = contentWindow.document; if (browser.ownerDocument.defaultView != window) {
var browserWindow = // Only listen for notifications for browsers in our chrome window.
OfflineApps._getBrowserWindowForContentWindow(contentWindow);
if (browserWindow != window) {
// Must belong to some other window.
return; return;
} }
var browser = var host = browser.currentURI.asciiHost;
OfflineApps._getBrowserForContentWindow(browserWindow, contentWindow);
var host = contentDocument.documentURIObject.asciiHost;
var message; var message;
var responseTopic; var responseTopic;

View File

@ -19,6 +19,7 @@
#include "mozilla/BasicEvents.h" #include "mozilla/BasicEvents.h"
#include "mozilla/Maybe.h" #include "mozilla/Maybe.h"
#include "mozilla/TypeTraits.h" #include "mozilla/TypeTraits.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/TabChild.h" #include "mozilla/dom/TabChild.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileChild.h" #include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileChild.h"
@ -528,9 +529,9 @@ class PermissionRequestMainProcessHelper final
public: public:
PermissionRequestMainProcessHelper(BackgroundFactoryRequestChild* aActor, PermissionRequestMainProcessHelper(BackgroundFactoryRequestChild* aActor,
IDBFactory* aFactory, IDBFactory* aFactory,
nsPIDOMWindow* aWindow, Element* aOwnerElement,
nsIPrincipal* aPrincipal) nsIPrincipal* aPrincipal)
: PermissionRequestBase(aWindow, aPrincipal) : PermissionRequestBase(aOwnerElement, aPrincipal)
, mActor(aActor) , mActor(aActor)
, mFactory(aFactory) , mFactory(aFactory)
{ {
@ -1129,8 +1130,14 @@ BackgroundFactoryRequestChild::RecvPermissionChallenge(
nsCOMPtr<nsPIDOMWindow> window = mFactory->GetParentObject(); nsCOMPtr<nsPIDOMWindow> window = mFactory->GetParentObject();
MOZ_ASSERT(window); MOZ_ASSERT(window);
nsCOMPtr<Element> ownerElement =
do_QueryInterface(window->GetChromeEventHandler());
if (NS_WARN_IF(!ownerElement)) {
return false;
}
nsRefPtr<PermissionRequestMainProcessHelper> helper = nsRefPtr<PermissionRequestMainProcessHelper> helper =
new PermissionRequestMainProcessHelper(this, mFactory, window, principal); new PermissionRequestMainProcessHelper(this, mFactory, ownerElement, principal);
PermissionRequestBase::PermissionValue permission; PermissionRequestBase::PermissionValue permission;
if (NS_WARN_IF(NS_FAILED(helper->PromptIfNeeded(&permission)))) { if (NS_WARN_IF(NS_FAILED(helper->PromptIfNeeded(&permission)))) {

View File

@ -7489,9 +7489,9 @@ class PermissionRequestHelper final
bool mActorDestroyed; bool mActorDestroyed;
public: public:
PermissionRequestHelper(nsPIDOMWindow* aWindow, PermissionRequestHelper(Element* aOwnerElement,
nsIPrincipal* aPrincipal) nsIPrincipal* aPrincipal)
: PermissionRequestBase(aWindow, aPrincipal) : PermissionRequestBase(aOwnerElement, aPrincipal)
, mActorDestroyed(false) , mActorDestroyed(false)
{ } { }
@ -8161,13 +8161,13 @@ DeallocPBackgroundIDBFactoryParent(PBackgroundIDBFactoryParent* aActor)
} }
PIndexedDBPermissionRequestParent* PIndexedDBPermissionRequestParent*
AllocPIndexedDBPermissionRequestParent(nsPIDOMWindow* aWindow, AllocPIndexedDBPermissionRequestParent(Element* aOwnerElement,
nsIPrincipal* aPrincipal) nsIPrincipal* aPrincipal)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<PermissionRequestHelper> actor = nsRefPtr<PermissionRequestHelper> actor =
new PermissionRequestHelper(aWindow, aPrincipal); new PermissionRequestHelper(aOwnerElement, aPrincipal);
return actor.forget().take(); return actor.forget().take();
} }

View File

@ -14,6 +14,7 @@ class nsPIDOMWindow;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class Element;
class TabParent; class TabParent;
namespace quota { namespace quota {
@ -39,7 +40,7 @@ bool
DeallocPBackgroundIDBFactoryParent(PBackgroundIDBFactoryParent* aActor); DeallocPBackgroundIDBFactoryParent(PBackgroundIDBFactoryParent* aActor);
PIndexedDBPermissionRequestParent* PIndexedDBPermissionRequestParent*
AllocPIndexedDBPermissionRequestParent(nsPIDOMWindow* aWindow, AllocPIndexedDBPermissionRequestParent(Element* aOwnerElement,
nsIPrincipal* aPrincipal); nsIPrincipal* aPrincipal);
bool bool

View File

@ -7,6 +7,7 @@
#include "MainThreadUtils.h" #include "MainThreadUtils.h"
#include "mozilla/Assertions.h" #include "mozilla/Assertions.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/dom/Element.h"
#include "nsIDOMWindow.h" #include "nsIDOMWindow.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
@ -46,13 +47,13 @@ AssertSanity()
} // anonymous namespace } // anonymous namespace
PermissionRequestBase::PermissionRequestBase(nsPIDOMWindow* aWindow, PermissionRequestBase::PermissionRequestBase(Element* aOwnerElement,
nsIPrincipal* aPrincipal) nsIPrincipal* aPrincipal)
: mWindow(aWindow) : mOwnerElement(aOwnerElement)
, mPrincipal(aPrincipal) , mPrincipal(aPrincipal)
{ {
AssertSanity(); AssertSanity();
MOZ_ASSERT(aWindow); MOZ_ASSERT(aOwnerElement);
MOZ_ASSERT(aPrincipal); MOZ_ASSERT(aPrincipal);
} }
@ -125,8 +126,8 @@ PermissionRequestBase::PromptIfNeeded(PermissionValue* aCurrentValue)
// Tricky, we want to release the window and principal in all cases except // Tricky, we want to release the window and principal in all cases except
// when we successfully prompt. // when we successfully prompt.
nsCOMPtr<nsPIDOMWindow> window; nsCOMPtr<Element> element;
mWindow.swap(window); mOwnerElement.swap(element);
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
mPrincipal.swap(principal); mPrincipal.swap(principal);
@ -146,7 +147,7 @@ PermissionRequestBase::PromptIfNeeded(PermissionValue* aCurrentValue)
} }
// We're about to prompt so swap the members back. // We're about to prompt so swap the members back.
window.swap(mWindow); element.swap(mOwnerElement);
principal.swap(mPrincipal); principal.swap(mPrincipal);
rv = obsSvc->NotifyObservers(static_cast<nsIObserver*>(this), rv = obsSvc->NotifyObservers(static_cast<nsIObserver*>(this),
@ -154,7 +155,7 @@ PermissionRequestBase::PromptIfNeeded(PermissionValue* aCurrentValue)
nullptr); nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
// Finally release if we failed the prompt. // Finally release if we failed the prompt.
mWindow = nullptr; mOwnerElement = nullptr;
mPrincipal = nullptr; mPrincipal = nullptr;
return rv; return rv;
} }
@ -200,8 +201,8 @@ PermissionRequestBase::GetInterface(const nsIID& aIID,
return QueryInterface(aIID, aResult); return QueryInterface(aIID, aResult);
} }
if (aIID.Equals(NS_GET_IID(nsIDOMWindow)) && mWindow) { if (aIID.Equals(NS_GET_IID(nsIDOMNode)) && mOwnerElement) {
return mWindow->QueryInterface(aIID, aResult); return mOwnerElement->QueryInterface(aIID, aResult);
} }
*aResult = nullptr; *aResult = nullptr;
@ -215,11 +216,11 @@ PermissionRequestBase::Observe(nsISupports* aSubject,
{ {
AssertSanity(); AssertSanity();
MOZ_ASSERT(!strcmp(aTopic, kPermissionResponseTopic)); MOZ_ASSERT(!strcmp(aTopic, kPermissionResponseTopic));
MOZ_ASSERT(mWindow); MOZ_ASSERT(mOwnerElement);
MOZ_ASSERT(mPrincipal); MOZ_ASSERT(mPrincipal);
nsCOMPtr<nsPIDOMWindow> window; nsCOMPtr<Element> element;
mWindow.swap(window); element.swap(mOwnerElement);
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
mPrincipal.swap(principal); mPrincipal.swap(principal);

View File

@ -18,13 +18,16 @@ class nsPIDOMWindow;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class Element;
namespace indexedDB { namespace indexedDB {
class PermissionRequestBase class PermissionRequestBase
: public nsIObserver : public nsIObserver
, public nsIInterfaceRequestor , public nsIInterfaceRequestor
{ {
nsCOMPtr<nsPIDOMWindow> mWindow; nsCOMPtr<Element> mOwnerElement;
nsCOMPtr<nsIPrincipal> mPrincipal; nsCOMPtr<nsIPrincipal> mPrincipal;
public: public:
@ -51,7 +54,7 @@ public:
PromptIfNeeded(PermissionValue* aCurrentValue); PromptIfNeeded(PermissionValue* aCurrentValue);
protected: protected:
PermissionRequestBase(nsPIDOMWindow* aWindow, PermissionRequestBase(Element* aOwnerElement,
nsIPrincipal* aPrincipal); nsIPrincipal* aPrincipal);
// Reference counted. // Reference counted.

View File

@ -1121,19 +1121,12 @@ TabParent::AllocPIndexedDBPermissionRequestParent(const Principal& aPrincipal)
MOZ_CRASH("Figure out security checks for bridged content!"); MOZ_CRASH("Figure out security checks for bridged content!");
} }
nsCOMPtr<nsPIDOMWindow> window; if (NS_WARN_IF(!mFrameElement)) {
nsCOMPtr<nsIContent> frame = do_QueryInterface(mFrameElement);
if (frame) {
MOZ_ASSERT(frame->OwnerDoc());
window = do_QueryInterface(frame->OwnerDoc()->GetWindow());
}
if (!window) {
return nullptr; return nullptr;
} }
return return
mozilla::dom::indexedDB::AllocPIndexedDBPermissionRequestParent(window, mozilla::dom::indexedDB::AllocPIndexedDBPermissionRequestParent(mFrameElement,
principal); principal);
} }

View File

@ -6670,13 +6670,12 @@ var IndexedDB = {
let requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor); let requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor);
let contentWindow = requestor.getInterface(Ci.nsIDOMWindow); let browser = requestor.getInterface(Ci.nsIDOMNode);
let contentDocument = contentWindow.document; let tab = BrowserApp.getTabForBrowser(browser);
let tab = BrowserApp.getTabForWindow(contentWindow);
if (!tab) if (!tab)
return; return;
let host = contentDocument.documentURIObject.asciiHost; let host = browser.currentURI.asciiHost;
let strings = Strings.browser; let strings = Strings.browser;