Bug 1554280 - Part 1: Expose the ContentParentId of a WindowGlobalActor, r=mconley
authorNika Layzell <nika@thelayzells.com>
Mon, 27 May 2019 18:42:35 +0000
changeset 475766 9b03e3640b09713ea027467bca40ebeac9ec2775
parent 475765 eee6d44b303084e435c512901a41cca2f5476907
child 475767 14c9835bfca5c478fd9d822f0621f4054b7facb5
push id86470
push usernlayzell@mozilla.com
push dateMon, 27 May 2019 20:34:30 +0000
treeherderautoland@14c9835bfca5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1554280
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1554280 - Part 1: Expose the ContentParentId of a WindowGlobalActor, r=mconley Differential Revision: https://phabricator.services.mozilla.com/D32515
dom/chrome-webidl/WindowGlobalActors.webidl
dom/ipc/WindowGlobalChild.cpp
dom/ipc/WindowGlobalChild.h
dom/ipc/WindowGlobalParent.cpp
dom/ipc/WindowGlobalParent.h
--- a/dom/chrome-webidl/WindowGlobalActors.webidl
+++ b/dom/chrome-webidl/WindowGlobalActors.webidl
@@ -13,16 +13,17 @@ interface WindowGlobalParent {
   readonly attribute boolean isClosed;
   readonly attribute boolean isInProcess;
   readonly attribute CanonicalBrowsingContext browsingContext;
 
   readonly attribute boolean isCurrentGlobal;
 
   readonly attribute unsigned long long innerWindowId;
   readonly attribute unsigned long long outerWindowId;
+  readonly attribute unsigned long long contentParentId;
 
   readonly attribute FrameLoader? rootFrameLoader; // Embedded (browser) only
 
   readonly attribute WindowGlobalChild? childActor; // in-process only
 
   // Information about the currently loaded document.
   readonly attribute Principal documentPrincipal;
   readonly attribute URI? documentURI;
@@ -43,16 +44,17 @@ interface WindowGlobalChild {
   readonly attribute boolean isClosed;
   readonly attribute boolean isInProcess;
   readonly attribute BrowsingContext browsingContext;
 
   readonly attribute boolean isCurrentGlobal;
 
   readonly attribute unsigned long long innerWindowId;
   readonly attribute unsigned long long outerWindowId;
+  readonly attribute unsigned long long contentParentId;
 
   readonly attribute WindowGlobalParent? parentActor; // in-process only
 
   static WindowGlobalChild? getByInnerWindowId(unsigned long long innerWIndowId);
 
   [Throws]
   JSWindowActorChild getActor(DOMString name);
 };
--- a/dom/ipc/WindowGlobalChild.cpp
+++ b/dom/ipc/WindowGlobalChild.cpp
@@ -133,16 +133,23 @@ already_AddRefed<WindowGlobalParent> Win
 
 already_AddRefed<BrowserChild> WindowGlobalChild::GetBrowserChild() {
   if (IsInProcess() || mIPCClosed) {
     return nullptr;
   }
   return do_AddRef(static_cast<BrowserChild*>(Manager()));
 }
 
+uint64_t WindowGlobalChild::ContentParentId() {
+  if (XRE_IsParentProcess()) {
+    return 0;
+  }
+  return ContentChild::GetSingleton()->GetID();
+}
+
 void WindowGlobalChild::Destroy() {
   // Perform async IPC shutdown unless we're not in-process, and our
   // BrowserChild is in the process of being destroyed, which will destroy us as
   // well.
   RefPtr<BrowserChild> browserChild = GetBrowserChild();
   if (!browserChild || !browserChild->IsDestroyed()) {
     // Make a copy so that we can avoid potential iterator invalidation when
     // calling the user-provided Destroy() methods.
--- a/dom/ipc/WindowGlobalChild.h
+++ b/dom/ipc/WindowGlobalChild.h
@@ -56,16 +56,18 @@ class WindowGlobalChild final : public W
   // Check if this actor is managed by PInProcess, as-in the document is loaded
   // in the chrome process.
   bool IsInProcess() { return XRE_IsParentProcess(); }
 
   // The Window ID for this WindowGlobal
   uint64_t InnerWindowId() { return mInnerWindowId; }
   uint64_t OuterWindowId() { return mOuterWindowId; }
 
+  uint64_t ContentParentId();
+
   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();
 
   // Get this actor's manager if it is not an in-process actor. Returns
   // |nullptr| if the actor has been torn down, or is in-process.
--- a/dom/ipc/WindowGlobalParent.cpp
+++ b/dom/ipc/WindowGlobalParent.cpp
@@ -70,17 +70,17 @@ void WindowGlobalParent::Init(const Wind
     gWindowGlobalParentsById = new WGPByIdMap();
     ClearOnShutdown(&gWindowGlobalParentsById);
   }
   auto entry = gWindowGlobalParentsById->LookupForAdd(mInnerWindowId);
   MOZ_RELEASE_ASSERT(!entry, "Duplicate WindowGlobalParent entry for ID!");
   entry.OrInsert([&] { return this; });
 
   // Determine which content process the window global is coming from.
-  ContentParentId processId(0);
+  dom::ContentParentId processId(0);
   if (!mInProcess) {
     processId = static_cast<ContentParent*>(Manager()->Manager())->ChildID();
   }
 
   mBrowsingContext = CanonicalBrowsingContext::Cast(aInit.browsingContext());
   MOZ_ASSERT(mBrowsingContext);
 
   // Attach ourself to the browsing context.
@@ -146,16 +146,21 @@ already_AddRefed<WindowGlobalChild> Wind
 
 already_AddRefed<BrowserParent> WindowGlobalParent::GetBrowserParent() {
   if (IsInProcess() || mIPCClosed) {
     return nullptr;
   }
   return do_AddRef(static_cast<BrowserParent*>(Manager()));
 }
 
+uint64_t WindowGlobalParent::ContentParentId() {
+  RefPtr<BrowserParent> browserParent = GetBrowserParent();
+  return browserParent ? browserParent->Manager()->ChildID() : 0;
+}
+
 IPCResult WindowGlobalParent::RecvUpdateDocumentURI(nsIURI* aURI) {
   // XXX(nika): Assert that the URI change was one which makes sense (either
   // about:blank -> a real URI, or a legal push/popstate URI change?)
   mDocumentURI = aURI;
   return IPC_OK();
 }
 
 IPCResult WindowGlobalParent::RecvBecomeCurrentWindowGlobal() {
--- a/dom/ipc/WindowGlobalParent.h
+++ b/dom/ipc/WindowGlobalParent.h
@@ -87,16 +87,18 @@ class WindowGlobalParent final : public 
 
   // The current URI which loaded in the document.
   nsIURI* GetDocumentURI() override { return mDocumentURI; }
 
   // Window IDs for inner/outer windows.
   uint64_t OuterWindowId() { return mOuterWindowId; }
   uint64_t InnerWindowId() { return mInnerWindowId; }
 
+  uint64_t ContentParentId();
+
   bool IsCurrentGlobal();
 
   already_AddRefed<Promise> ChangeFrameRemoteness(dom::BrowsingContext* aBc,
                                                   const nsAString& aRemoteType,
                                                   uint64_t aPendingSwitchId,
                                                   ErrorResult& aRv);
 
   // Create a WindowGlobalParent from over IPC. This method should not be called