Bug 1644795 - Expose all nsIDOMProcessParent via ChromeUtils.getAllDOMProcesses(). r=nika
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 01 Jul 2020 09:09:44 +0000
changeset 538165 7cc7ff20205ef335a54cea79690cb76181102cea
parent 538164 f53cf203cbf5aec0797b17748ad096e56eb9c6ef
child 538166 9cf50d4ea19fb05de3b0822f7e3aab36c96c4e63
push id37559
push userrmaries@mozilla.com
push dateWed, 01 Jul 2020 21:32:12 +0000
treeherdermozilla-central@597ca7dea687 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1644795
milestone80.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 1644795 - Expose all nsIDOMProcessParent via ChromeUtils.getAllDOMProcesses(). r=nika Differential Revision: https://phabricator.services.mozilla.com/D81121
dom/base/ChromeUtils.cpp
dom/base/ChromeUtils.h
dom/chrome-webidl/ChromeUtils.webidl
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -21,16 +21,17 @@
 #include "mozilla/ProcInfo.h"
 #include "mozilla/RDDProcessManager.h"
 #include "mozilla/ResultExtensions.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/dom/BrowsingContext.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/IdleDeadline.h"
+#include "mozilla/dom/InProcessParent.h"
 #include "mozilla/dom/InProcessChild.h"
 #include "mozilla/dom/JSActorService.h"
 #include "mozilla/dom/MediaControlUtils.h"
 #include "mozilla/dom/MediaControlService.h"
 #include "mozilla/dom/MediaMetadata.h"
 #include "mozilla/dom/MediaSessionBinding.h"
 #include "mozilla/dom/Performance.h"
 #include "mozilla/dom/Promise.h"
@@ -1306,16 +1307,35 @@ void ChromeUtils::GenerateMediaControlKe
 nsIDOMProcessChild* ChromeUtils::GetDomProcessChild(const GlobalObject&) {
   if (XRE_IsParentProcess()) {
     return InProcessChild::Singleton();
   }
   return ContentChild::GetSingleton();
 }
 
 /* static */
+void ChromeUtils::GetAllDOMProcesses(
+    GlobalObject& aGlobal, nsTArray<RefPtr<nsIDOMProcessParent>>& aParents,
+    ErrorResult& aRv) {
+  if (!XRE_IsParentProcess()) {
+    aRv.ThrowNotAllowedError(
+        "getAllDOMProcesses() may only be called in the parent process");
+    return;
+  }
+  aParents.Clear();
+  // Always add the parent process nsIDOMProcessParent first
+  aParents.AppendElement(InProcessParent::Singleton());
+
+  // Before adding nsIDOMProcessParent for all the content processes
+  for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
+    aParents.AppendElement(cp);
+  }
+}
+
+/* static */
 void ChromeUtils::GetCurrentActiveMediaMetadata(const GlobalObject& aGlobal,
                                                 MediaMetadataInit& aMetadata) {
   if (RefPtr<MediaControlService> service = MediaControlService::GetService()) {
     MediaMetadataBase metadata = service->GetMainControllerMediaMetadata();
     aMetadata.mTitle = metadata.mTitle;
     aMetadata.mArtist = metadata.mArtist;
     aMetadata.mAlbum = metadata.mAlbum;
     for (const auto& artwork : metadata.mArtwork) {
--- a/dom/base/ChromeUtils.h
+++ b/dom/base/ChromeUtils.h
@@ -8,16 +8,17 @@
 #define mozilla_dom_ChromeUtils__
 
 #include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/ChromeUtilsBinding.h"
 #include "mozilla/ErrorResult.h"
 #include "nsDOMNavigationTiming.h"  // for DOMHighResTimeStamp
 #include "nsIDOMProcessChild.h"
+#include "nsIDOMProcessParent.h"
 
 namespace mozilla {
 
 namespace devtools {
 class HeapSnapshot;
 }  // namespace devtools
 
 namespace dom {
@@ -215,16 +216,20 @@ class ChromeUtils {
   static void PrivateNoteIntentionalCrash(const GlobalObject& aGlobal,
                                           ErrorResult& aError);
 
   static void GenerateMediaControlKey(const GlobalObject& aGlobal,
                                       MediaControlKey aKey);
 
   static nsIDOMProcessChild* GetDomProcessChild(const GlobalObject&);
 
+  static void GetAllDOMProcesses(
+      GlobalObject& aGlobal, nsTArray<RefPtr<nsIDOMProcessParent>>& aParents,
+      ErrorResult& aRv);
+
   // This function would only be used for testing.
   static void GetCurrentActiveMediaMetadata(const GlobalObject& aGlobal,
                                             MediaMetadataInit& aMetadata);
 
   // This function would only be used for testing.
   static MediaSessionPlaybackTestState GetCurrentMediaSessionPlaybackState(
       GlobalObject& aGlobal);
 };
--- a/dom/chrome-webidl/ChromeUtils.webidl
+++ b/dom/chrome-webidl/ChromeUtils.webidl
@@ -1,15 +1,16 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 interface nsIDOMProcessChild;
+interface nsIDOMProcessParent;
 
 /**
  * An optimized QueryInterface method, generated by generateQI.
  *
  * For JS callers, this behaves like a normal QueryInterface function. When
  * called with a supported interface, it returns its `this` object. When
  * called with an unsupported interface, it throws NS_ERROR_NO_INTERFACE.
  *
@@ -477,16 +478,25 @@ partial namespace ChromeUtils {
   void generateMediaControlKey(MediaControlKey aKey);
 
   /**
    * nsIDOMProcessChild for the current process.
    */
   [ChromeOnly]
   readonly attribute nsIDOMProcessChild? domProcessChild;
 
+  /**
+   * nsIDOMProcessParent for all processes.
+   *
+   * The first is for the parent process and all the next are for the content
+   * processes.
+   */
+  [Throws, ChromeOnly]
+  sequence<nsIDOMProcessParent> getAllDOMProcesses();
+
   // This is used to get the media metadata from the current main controller in
   // testing.
   [ChromeOnly]
   MediaMetadataInit getCurrentActiveMediaMetadata();
 
   // This is used to get the actual media playback state from the current main
   // controller in testing.
   [ChromeOnly]