Bug 1510460 - Record the current WindowGlobal on ChromeBrowsingContext, r=farre

Differential Revision: https://phabricator.services.mozilla.com/D13156
This commit is contained in:
Nika Layzell 2018-11-27 15:03:05 -05:00
Родитель c82214c322
Коммит 614b663032
10 изменённых файлов: 59 добавлений и 0 удалений

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

@ -74,6 +74,20 @@ void ChromeBrowsingContext::UnregisterWindowGlobal(
WindowGlobalParent* aGlobal) {
MOZ_ASSERT(mWindowGlobals.Contains(aGlobal), "Global not registered!");
mWindowGlobals.RemoveEntry(aGlobal);
// Our current window global should be in our mWindowGlobals set. If it's not
// anymore, clear that reference.
if (aGlobal == mCurrentWindowGlobal) {
mCurrentWindowGlobal = nullptr;
}
}
void ChromeBrowsingContext::SetCurrentWindowGlobal(
WindowGlobalParent* aGlobal) {
MOZ_ASSERT(mWindowGlobals.Contains(aGlobal), "Global not registered!");
// TODO: This should probably assert that the processes match.
mCurrentWindowGlobal = aGlobal;
}
JSObject* ChromeBrowsingContext::WrapObject(JSContext* aCx,

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

@ -41,6 +41,12 @@ class ChromeBrowsingContext final : public BrowsingContext {
void RegisterWindowGlobal(WindowGlobalParent* aGlobal);
void UnregisterWindowGlobal(WindowGlobalParent* aGlobal);
// The current active WindowGlobal.
WindowGlobalParent* GetCurrentWindowGlobal() const {
return mCurrentWindowGlobal;
}
void SetCurrentWindowGlobal(WindowGlobalParent* aGlobal);
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
@ -62,6 +68,7 @@ class ChromeBrowsingContext final : public BrowsingContext {
// All live window globals within this browsing context.
nsTHashtable<nsRefPtrHashKey<WindowGlobalParent>> mWindowGlobals;
RefPtr<WindowGlobalParent> mCurrentWindowGlobal;
};
} // namespace dom

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

@ -68,6 +68,7 @@
#include "mozilla/intl/LocaleService.h"
#include "WindowDestroyedEvent.h"
#include "nsDocShellLoadState.h"
#include "mozilla/dom/WindowGlobalChild.h"
// Helper Classes
#include "nsJSUtils.h"
@ -1962,6 +1963,10 @@ nsresult nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument,
newInnerWindow->MigrateStateForDocumentOpen(currentInner);
}
// Tell the WindowGlobalParent that it should become the current window global
// for our BrowsingContext if it isn't already.
mInnerWindow->GetWindowGlobalChild()->SendBecomeCurrentWindowGlobal();
// We no longer need the old inner window. Start its destruction if
// its not being reused and clear our reference.
if (doomCurrentInner) {

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

@ -21,4 +21,6 @@ interface BrowsingContext {
[Exposed=Window, ChromeOnly]
interface ChromeBrowsingContext : BrowsingContext {
sequence<WindowGlobalParent> getWindowGlobals();
readonly attribute WindowGlobalParent? currentWindowGlobal;
};

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

@ -13,6 +13,8 @@ interface WindowGlobalParent {
readonly attribute boolean isInProcess;
readonly attribute ChromeBrowsingContext browsingContext;
readonly attribute boolean isCurrentGlobal;
readonly attribute unsigned long long innerWindowId;
readonly attribute unsigned long long outerWindowId;
@ -33,6 +35,8 @@ interface WindowGlobalChild {
readonly attribute boolean isInProcess;
readonly attribute BrowsingContext browsingContext;
readonly attribute boolean isCurrentGlobal;
readonly attribute unsigned long long innerWindowId;
readonly attribute unsigned long long outerWindowId;

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

@ -28,6 +28,9 @@ parent:
/// Update the URI of the document in this WindowGlobal.
async UpdateDocumentURI(nsIURI aUri);
/// Notify the parent that this PWindowGlobal is now the current global.
async BecomeCurrentWindowGlobal();
async __delete__();
};

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

@ -82,6 +82,12 @@ WindowGlobalChild::GetByInnerWindowId(uint64_t aInnerWindowId)
return gWindowGlobalChildById->Get(aInnerWindowId);
}
bool
WindowGlobalChild::IsCurrentGlobal()
{
return !mIPCClosed && mWindowGlobal->IsCurrentInnerWindow();
}
already_AddRefed<WindowGlobalParent>
WindowGlobalChild::GetParentActor()
{

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

@ -53,6 +53,8 @@ public:
uint64_t InnerWindowId() { return mInnerWindowId; }
uint64_t OuterWindowId() { return mOuterWindowId; }
bool IsCurrentGlobal();
// Get the other side of this actor if it is an in-process actor. Returns
// |nullptr| if the actor has been torn down, or is not in-process.
already_AddRefed<WindowGlobalParent> GetParentActor();

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

@ -124,6 +124,19 @@ WindowGlobalParent::RecvUpdateDocumentURI(nsIURI* aURI)
return IPC_OK();
}
IPCResult
WindowGlobalParent::RecvBecomeCurrentWindowGlobal()
{
mBrowsingContext->SetCurrentWindowGlobal(this);
return IPC_OK();
}
bool
WindowGlobalParent::IsCurrentGlobal()
{
return !mIPCClosed && mBrowsingContext->GetCurrentWindowGlobal() == this;
}
void
WindowGlobalParent::ActorDestroy(ActorDestroyReason aWhy)
{

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

@ -71,6 +71,8 @@ public:
uint64_t OuterWindowId() { return mOuterWindowId; }
uint64_t InnerWindowId() { return mInnerWindowId; }
bool IsCurrentGlobal();
// Create a WindowGlobalParent from over IPC. This method should not be called
// from outside of the IPC constructors.
WindowGlobalParent(const WindowGlobalInit& aInit, bool aInProcess);
@ -86,6 +88,7 @@ public:
protected:
// IPC messages
mozilla::ipc::IPCResult RecvUpdateDocumentURI(nsIURI* aURI) override;
mozilla::ipc::IPCResult RecvBecomeCurrentWindowGlobal() override;
void ActorDestroy(ActorDestroyReason aWhy) override;