Bug 1523638 - Part 2: Store and expose URI and Principal on WindowGlobalChild, r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D37649

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nika Layzell 2019-07-16 18:47:37 +00:00
Родитель 77dc463d33
Коммит 418bf22463
4 изменённых файлов: 35 добавлений и 20 удалений

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

@ -3370,9 +3370,8 @@ void Document::SetDocumentURI(nsIURI* aURI) {
// Tell our WindowGlobalParent that the document's URI has been changed.
nsPIDOMWindowInner* inner = GetInnerWindow();
WindowGlobalChild* wgc = inner ? inner->GetWindowGlobalChild() : nullptr;
if (wgc) {
Unused << wgc->SendUpdateDocumentURI(mDocumentURI);
if (inner && inner->GetWindowGlobalChild()) {
inner->GetWindowGlobalChild()->SetDocumentURI(mDocumentURI);
}
}

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

@ -2215,9 +2215,9 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
// Tell the WindowGlobalParent that it should become the current window global
// for our BrowsingContext if it isn't already.
mInnerWindow->GetWindowGlobalChild()->SendUpdateDocumentURI(
aDocument->GetDocumentURI());
mInnerWindow->GetWindowGlobalChild()->SendBecomeCurrentWindowGlobal();
WindowGlobalChild* wgc = mInnerWindow->GetWindowGlobalChild();
wgc->SetDocumentURI(aDocument->GetDocumentURI());
wgc->SendBecomeCurrentWindowGlobal();
// We no longer need the old inner window. Start its destruction if
// its not being reused and clear our reference.

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

@ -40,13 +40,21 @@ namespace dom {
typedef nsRefPtrHashtable<nsUint64HashKey, WindowGlobalChild> WGCByIdMap;
static StaticAutoPtr<WGCByIdMap> gWindowGlobalChildById;
WindowGlobalChild::WindowGlobalChild(nsGlobalWindowInner* aWindow,
dom::BrowsingContext* aBrowsingContext)
WindowGlobalChild::WindowGlobalChild(const WindowGlobalInit& aInit,
nsGlobalWindowInner* aWindow)
: mWindowGlobal(aWindow),
mBrowsingContext(aBrowsingContext),
mInnerWindowId(aWindow->WindowID()),
mOuterWindowId(aWindow->GetOuterWindow()->WindowID()),
mBeforeUnloadListeners(0) {}
mBrowsingContext(aInit.browsingContext()),
mDocumentPrincipal(aInit.principal()),
mDocumentURI(aInit.documentURI()),
mInnerWindowId(aInit.innerWindowId()),
mOuterWindowId(aInit.outerWindowId()),
mBeforeUnloadListeners(0) {
MOZ_DIAGNOSTIC_ASSERT(mBrowsingContext);
MOZ_DIAGNOSTIC_ASSERT(mDocumentPrincipal);
MOZ_ASSERT(mInnerWindowId == aWindow->WindowID());
MOZ_ASSERT(mOuterWindowId == aWindow->GetOuterWindow()->WindowID());
}
already_AddRefed<WindowGlobalChild> WindowGlobalChild::Create(
nsGlobalWindowInner* aWindow) {
@ -69,7 +77,11 @@ already_AddRefed<WindowGlobalChild> WindowGlobalChild::Create(
bc->SetOpenerPolicy(policy);
}
RefPtr<WindowGlobalChild> wgc = new WindowGlobalChild(aWindow, bc);
WindowGlobalInit init(principal, aWindow->GetDocumentURI(), bc,
aWindow->WindowID(),
aWindow->GetOuterWindow()->WindowID());
auto wgc = MakeRefPtr<WindowGlobalChild>(init, aWindow);
// If we have already closed our browsing context, return a pre-destroyed
// WindowGlobalChild actor.
@ -78,9 +90,6 @@ already_AddRefed<WindowGlobalChild> WindowGlobalChild::Create(
return wgc.forget();
}
WindowGlobalInit init(principal, aWindow->GetDocumentURI(), bc,
wgc->mInnerWindowId, wgc->mOuterWindowId);
// Send the link constructor over PInProcessChild or PBrowser.
if (XRE_IsParentProcess()) {
InProcessChild* ipc = InProcessChild::Singleton();
@ -337,8 +346,9 @@ void WindowGlobalChild::ReceiveRawMessage(const JSWindowActorMessageMeta& aMeta,
}
}
nsIURI* WindowGlobalChild::GetDocumentURI() {
return mWindowGlobal->GetDocumentURI();
void WindowGlobalChild::SetDocumentURI(nsIURI* aDocumentURI) {
mDocumentURI = aDocumentURI;
SendUpdateDocumentURI(aDocumentURI);
}
const nsAString& WindowGlobalChild::GetRemoteType() {

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

@ -57,6 +57,9 @@ class WindowGlobalChild final : public WindowGlobalActor,
// in the chrome process.
bool IsInProcess() { return XRE_IsParentProcess(); }
nsIURI* GetDocumentURI() override { return mDocumentURI; }
void SetDocumentURI(nsIURI* aDocumentURI);
// The Window ID for this WindowGlobal
uint64_t InnerWindowId() { return mInnerWindowId; }
uint64_t OuterWindowId() { return mOuterWindowId; }
@ -90,10 +93,12 @@ class WindowGlobalChild final : public WindowGlobalActor,
static already_AddRefed<WindowGlobalChild> Create(
nsGlobalWindowInner* aWindow);
WindowGlobalChild(const WindowGlobalInit& aInit,
nsGlobalWindowInner* aWindow);
nsISupports* GetParentObject();
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
nsIURI* GetDocumentURI() override;
protected:
const nsAString& GetRemoteType() override;
@ -118,12 +123,13 @@ class WindowGlobalChild final : public WindowGlobalActor,
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
private:
WindowGlobalChild(nsGlobalWindowInner* aWindow, dom::BrowsingContext* aBc);
~WindowGlobalChild();
RefPtr<nsGlobalWindowInner> mWindowGlobal;
RefPtr<dom::BrowsingContext> mBrowsingContext;
nsRefPtrHashtable<nsStringHashKey, JSWindowActorChild> mWindowActors;
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
nsCOMPtr<nsIURI> mDocumentURI;
uint64_t mInnerWindowId;
uint64_t mOuterWindowId;
int64_t mBeforeUnloadListeners;