зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1510460 - Record the current WindowGlobal on ChromeBrowsingContext, r=farre
Differential Revision: https://phabricator.services.mozilla.com/D13156
This commit is contained in:
Родитель
c82214c322
Коммит
614b663032
|
@ -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;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче