1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * vim: sw=2 ts=2 et :
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "PDFiumProcessParent.h"
8 #include "nsIRunnable.h"
9 #if defined(XP_WIN) && defined(MOZ_SANDBOX)
10 #include "WinUtils.h"
11 #endif
12 #include "nsDeviceContextSpecWin.h"
13 #include "PDFiumParent.h"
14 
15 using mozilla::ipc::GeckoChildProcessHost;
16 
17 namespace mozilla {
18 namespace widget {
19 
PDFiumProcessParent()20 PDFiumProcessParent::PDFiumProcessParent()
21     : GeckoChildProcessHost(GeckoProcessType_PDFium) {
22   MOZ_COUNT_CTOR(PDFiumProcessParent);
23 }
24 
~PDFiumProcessParent()25 PDFiumProcessParent::~PDFiumProcessParent() {
26   MOZ_COUNT_DTOR(PDFiumProcessParent);
27 }
28 
Launch(PrintTargetEMF * aTarget)29 bool PDFiumProcessParent::Launch(PrintTargetEMF* aTarget) {
30   mLaunchThread = NS_GetCurrentThread();
31 
32   if (!SyncLaunch()) {
33     return false;
34   }
35 
36   // Open the top level protocol for PDFium process.
37   MOZ_ASSERT(!mPDFiumParentActor);
38   mPDFiumParentActor = new PDFiumParent(aTarget);
39   return mPDFiumParentActor->Init(GetChannel(),
40                                   base::GetProcId(GetChildProcessHandle()));
41 }
42 
Delete()43 void PDFiumProcessParent::Delete() {
44   // Make sure we do close the IPC channel on the same thread with the one
45   // that we create the channel.
46   if (!mLaunchThread || mLaunchThread == NS_GetCurrentThread()) {
47     if (mPDFiumParentActor) {
48       mPDFiumParentActor->EndConversion();
49       mPDFiumParentActor->Close();
50     }
51 
52     delete this;
53     return;
54   }
55 
56   mLaunchThread->Dispatch(NewNonOwningRunnableMethod(
57       "PDFiumProcessParent::Delete", this, &PDFiumProcessParent::Delete));
58 }
59 
60 }  // namespace widget
61 }  // namespace mozilla
62