Bug 1399787 - Part 5. Implement the PDFium process. r=jwatt
☠☠ backed out by 2e0485d0998d ☠ ☠
authorcku <cku@mozilla.com>
Mon, 16 Oct 2017 16:22:07 +0800
changeset 395692 c186893ce0fcbef7462683ba7affc02b6fb473f7
parent 395691 323da3bddaaaed876e113b07e794d2e73309af24
child 395693 ef21f295db3f2184eaaf13e6369f52d8fd9e3395
push id33054
push userrgurzau@mozilla.com
push dateFri, 08 Dec 2017 21:57:23 +0000
treeherdermozilla-central@6e2181b6137c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1399787
milestone59.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 1399787 - Part 5. Implement the PDFium process. r=jwatt MozReview-Commit-ID: 502jB9DAeIC
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
widget/windows/PDFiumProcessChild.cpp
widget/windows/PDFiumProcessChild.h
widget/windows/PDFiumProcessParent.cpp
widget/windows/PDFiumProcessParent.h
widget/windows/moz.build
xpcom/build/nsXULAppAPI.h
xpcom/system/nsIXULRuntime.idl
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -897,19 +897,20 @@ nsXULAppInfo::GetWidgetToolkit(nsACStrin
                 "GeckoProcessType in nsXULAppAPI.h not synchronized with nsIXULRuntime.idl");
 
 SYNC_ENUMS(DEFAULT, Default)
 SYNC_ENUMS(PLUGIN, Plugin)
 SYNC_ENUMS(CONTENT, Content)
 SYNC_ENUMS(IPDLUNITTEST, IPDLUnitTest)
 SYNC_ENUMS(GMPLUGIN, GMPlugin)
 SYNC_ENUMS(GPU, GPU)
+SYNC_ENUMS(PDFIUM, PDFium)
 
 // .. and ensure that that is all of them:
-static_assert(GeckoProcessType_GPU + 1 == GeckoProcessType_End,
+static_assert(GeckoProcessType_PDFium + 1 == GeckoProcessType_End,
               "Did not find the final GeckoProcessType");
 
 NS_IMETHODIMP
 nsXULAppInfo::GetProcessType(uint32_t* aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = XRE_GetProcessType();
   return NS_OK;
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -111,16 +111,20 @@
 
 using mozilla::_ipdltest::IPDLUnitTestProcessChild;
 #endif  // ifdef MOZ_IPDL_TESTS
 
 #ifdef MOZ_JPROF
 #include "jprof.h"
 #endif
 
+#if defined(XP_WIN) && defined(MOZ_ENABLE_SKIA_PDF)
+#include "mozilla/widget/PDFiumProcessChild.h"
+#endif
+
 using namespace mozilla;
 
 using mozilla::ipc::BrowserProcessSubThread;
 using mozilla::ipc::GeckoChildProcessHost;
 using mozilla::ipc::IOThreadChild;
 using mozilla::ipc::ProcessChild;
 using mozilla::ipc::ScopedXREEmbed;
 
@@ -600,16 +604,17 @@ XRE_InitChildProcess(int aArgc,
   MessageLoop::Type uiLoopType;
   switch (XRE_GetProcessType()) {
   case GeckoProcessType_Content:
   case GeckoProcessType_GPU:
       // Content processes need the XPCOM/chromium frankenventloop
       uiLoopType = MessageLoop::TYPE_MOZILLA_CHILD;
       break;
   case GeckoProcessType_GMPlugin:
+  case GeckoProcessType_PDFium:
       uiLoopType = MessageLoop::TYPE_DEFAULT;
       break;
   default:
       uiLoopType = MessageLoop::TYPE_UI;
       break;
   }
 
   {
@@ -647,16 +652,21 @@ XRE_InitChildProcess(int aArgc,
         MOZ_CRASH("rebuild with --enable-ipdl-tests");
 #endif
         break;
 
       case GeckoProcessType_GMPlugin:
         process = new gmp::GMPProcessChild(parentPID);
         break;
 
+#if defined(XP_WIN) && defined(MOZ_ENABLE_SKIA_PDF)
+      case GeckoProcessType_PDFium:
+        process = new widget::PDFiumProcessChild(parentPID);
+        break;
+#endif
       case GeckoProcessType_GPU:
         process = new gfx::GPUProcessImpl(parentPID);
         break;
 
       default:
         MOZ_CRASH("Unknown main thread class");
       }
 
new file mode 100644
--- /dev/null
+++ b/widget/windows/PDFiumProcessChild.cpp
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; 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/. */
+
+#include "PDFiumProcessChild.h"
+
+#include "mozilla/ipc/IOThreadChild.h"
+#include "mozilla/BackgroundHangMonitor.h"
+#include "mozilla/dom/ContentChild.h"
+#include "mozilla/dom/ContentParent.h"
+
+using mozilla::ipc::IOThreadChild;
+
+namespace mozilla {
+namespace widget {
+
+PDFiumProcessChild::PDFiumProcessChild(ProcessId aParentPid)
+  : ProcessChild(aParentPid)
+{
+}
+
+PDFiumProcessChild::~PDFiumProcessChild()
+{
+}
+
+bool
+PDFiumProcessChild::Init(int aArgc, char* aArgv[])
+{
+  BackgroundHangMonitor::Startup();
+  mPDFiumActor.Init(ParentPid(),IOThreadChild::message_loop(),
+                    IOThreadChild::channel());
+
+  return true;
+}
+
+void
+PDFiumProcessChild::CleanUp()
+{
+  BackgroundHangMonitor::Shutdown();
+}
+
+} // namespace widget
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/widget/windows/PDFiumProcessChild.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; 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/. */
+
+#ifndef PDFIUMPROCESSCHILD_H_
+#define PDFIUMPROCESSCHILD_H_
+
+#include "mozilla/ipc/ProcessChild.h"
+#include "PDFiumChild.h"
+
+namespace mozilla {
+namespace widget {
+
+/**
+ * Contains the PDFiumChild object that facilitates IPC communication to/from
+ * the instance of the PDFium library that is run in this process.
+ */
+class PDFiumProcessChild final : public mozilla::ipc::ProcessChild
+{
+protected:
+  typedef mozilla::ipc::ProcessChild ProcessChild;
+
+public:
+  explicit PDFiumProcessChild(ProcessId aParentPid);
+  ~PDFiumProcessChild();
+
+  // ProcessChild functions.
+  bool Init(int aArgc, char* aArgv[]) override;
+  void CleanUp() override;
+
+private:
+  DISALLOW_COPY_AND_ASSIGN(PDFiumProcessChild);
+
+  PDFiumChild mPDFiumActor;
+};
+
+} // namespace widget
+} // namespace mozilla
+
+#endif // PDFIUMPROCESSCHILD_H_
new file mode 100644
--- /dev/null
+++ b/widget/windows/PDFiumProcessParent.cpp
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 et :
+ * 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/. */
+
+#include "PDFiumProcessParent.h"
+#include "nsIRunnable.h"
+#if defined(XP_WIN) && defined(MOZ_SANDBOX)
+#include "WinUtils.h"
+#endif
+#include "nsDeviceContextSpecWin.h"
+#include "PDFiumParent.h"
+
+using mozilla::ipc::GeckoChildProcessHost;
+
+namespace mozilla {
+namespace widget {
+
+PDFiumProcessParent::PDFiumProcessParent()
+  : GeckoChildProcessHost(GeckoProcessType_PDFium)
+{
+  MOZ_COUNT_CTOR(PDFiumProcessParent);
+}
+
+PDFiumProcessParent::~PDFiumProcessParent()
+{
+  MOZ_COUNT_DTOR(PDFiumProcessParent);
+}
+
+bool
+PDFiumProcessParent::Launch()
+{
+  return SyncLaunch();
+}
+
+void
+PDFiumProcessParent::Delete()
+{
+}
+
+} // namespace widget
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/widget/windows/PDFiumProcessParent.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: sw=4 ts=4 et :
+ * 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/. */
+
+#ifndef PDFIUMPROCESSPARENT_H
+#define PDFIUMPROCESSPARENT_H
+
+#include "chrome/common/child_process_host.h"
+#include "mozilla/ipc/GeckoChildProcessHost.h"
+
+class nsIRunnable;
+
+namespace mozilla {
+namespace widget {
+
+class PDFiumProcessParent final : public mozilla::ipc::GeckoChildProcessHost
+{
+public:
+  PDFiumProcessParent();
+  ~PDFiumProcessParent();
+
+  bool Launch();
+
+  void Delete();
+
+  bool CanShutdown() override { return true; }
+
+private:
+
+  DISALLOW_COPY_AND_ASSIGN(PDFiumProcessParent);
+};
+
+} // namespace widget
+} // namespace mozilla
+
+#endif // ifndef PDFIUMPROCESSPARENT_H
--- a/widget/windows/moz.build
+++ b/widget/windows/moz.build
@@ -21,16 +21,17 @@ EXPORTS += [
 EXPORTS.mozilla.widget += [
     'AudioSession.h',
     'CompositorWidgetChild.h',
     'CompositorWidgetParent.h',
     'InProcessWinCompositorWidget.h',
     'PDFiumChild.h',
     'PDFiumEngineShim.h',
     'PDFiumParent.h',
+    'PDFiumProcessChild.h',
     'PDFViaEMFPrintHelper.h',
     'WinCompositorWidget.h',
     'WinMessages.h',
     'WinModifierKeyState.h',
     'WinNativeEventData.h',
 ]
 
 UNIFIED_SOURCES += [
@@ -103,16 +104,18 @@ if CONFIG['MOZ_ENABLE_SKIA_PDF']:
     DIRS += ['/modules/pdfium']
     IPDL_SOURCES += [
         'PPDFium.ipdl',
     ]
     UNIFIED_SOURCES += [
         'PDFiumChild.cpp',
         'PDFiumEngineShim.cpp',
         'PDFiumParent.cpp',
+        'PDFiumProcessChild.cpp',
+        'PDFiumProcessParent.cpp',
         'PDFViaEMFPrintHelper.cpp',
         'WindowsEMF.cpp',
     ]
 
 if CONFIG['NS_ENABLE_TSF']:
     SOURCES += [
         'TSFTextStore.cpp',
     ]
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -369,28 +369,29 @@ enum GeckoProcessType
   GeckoProcessType_Plugin,
   GeckoProcessType_Content,
 
   GeckoProcessType_IPDLUnitTest,
 
   GeckoProcessType_GMPlugin, // Gecko Media Plugin
 
   GeckoProcessType_GPU,      // GPU and compositor process
-
+  GeckoProcessType_PDFium,   // Gecko PDFium process
   GeckoProcessType_End,
   GeckoProcessType_Invalid = GeckoProcessType_End
 };
 
 static const char* const kGeckoProcessTypeString[] = {
   "default",
   "plugin",
   "tab",
   "ipdlunittest",
   "geckomediaplugin",
-  "gpu"
+  "gpu",
+  "pdfium"
 };
 
 static_assert(MOZ_ARRAY_LENGTH(kGeckoProcessTypeString) ==
               GeckoProcessType_End,
               "Array length mismatch");
 
 XRE_API(const char*,
         XRE_ChildProcessTypeToString, (GeckoProcessType aProcessType))
--- a/xpcom/system/nsIXULRuntime.idl
+++ b/xpcom/system/nsIXULRuntime.idl
@@ -71,16 +71,17 @@ interface nsIXULRuntime : nsISupports
    * The legal values of processType.
    */
   const unsigned long PROCESS_TYPE_DEFAULT = 0;
   const unsigned long PROCESS_TYPE_PLUGIN = 1;
   const unsigned long PROCESS_TYPE_CONTENT = 2;
   const unsigned long PROCESS_TYPE_IPDLUNITTEST = 3;
   const unsigned long PROCESS_TYPE_GMPLUGIN = 4;
   const unsigned long PROCESS_TYPE_GPU = 5;
+  const unsigned long PROCESS_TYPE_PDFIUM = 6;
 
   /**
    * The type of the caller's process.  Returns one of the values above.
    */
   readonly attribute unsigned long processType;
 
   /**
    * The system process ID of the caller's process.