Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/ContentParent.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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
#ifndef mozilla_dom_ContentParent_h
8
#define mozilla_dom_ContentParent_h
9
10
#include "mozilla/dom/PContentParent.h"
11
#include "mozilla/dom/nsIContentParent.h"
12
#include "mozilla/gfx/gfxVarReceiver.h"
13
#include "mozilla/gfx/GPUProcessListener.h"
14
#include "mozilla/Attributes.h"
15
#include "mozilla/FileUtils.h"
16
#include "mozilla/HalTypes.h"
17
#include "mozilla/LinkedList.h"
18
#include "mozilla/MemoryReportingProcess.h"
19
#include "mozilla/StaticPtr.h"
20
#include "mozilla/TimeStamp.h"
21
#include "mozilla/UniquePtr.h"
22
23
#include "ContentProcessHost.h"
24
#include "nsDataHashtable.h"
25
#include "nsPluginTags.h"
26
#include "nsFrameMessageManager.h"
27
#include "nsHashKeys.h"
28
#include "nsIInterfaceRequestor.h"
29
#include "nsIObserver.h"
30
#include "nsIThreadInternal.h"
31
#include "nsIDOMGeoPositionCallback.h"
32
#include "nsIDOMGeoPositionErrorCallback.h"
33
#include "nsRefPtrHashtable.h"
34
#include "PermissionMessageUtils.h"
35
#include "DriverCrashGuard.h"
36
37
0
#define CHILD_PROCESS_SHUTDOWN_MESSAGE NS_LITERAL_STRING("child-process-shutdown")
38
39
// These must match the similar ones in E10SUtils.jsm.
40
// Process names as reported by about:memory are defined in
41
// ContentChild:RecvRemoteType.  Add your value there too or it will be called
42
// "Web Content".
43
0
#define DEFAULT_REMOTE_TYPE "web"
44
0
#define FILE_REMOTE_TYPE "file"
45
0
#define EXTENSION_REMOTE_TYPE "extension"
46
0
#define PRIVILEGED_REMOTE_TYPE "privileged"
47
48
// This must start with the DEFAULT_REMOTE_TYPE above.
49
0
#define LARGE_ALLOCATION_REMOTE_TYPE "webLargeAllocation"
50
51
class nsConsoleService;
52
class nsIContentProcessInfo;
53
class nsICycleCollectorLogSink;
54
class nsIDumpGCAndCCLogsCallback;
55
class nsITabParent;
56
class nsITimer;
57
class ParentIdleListener;
58
class nsIWidget;
59
60
namespace mozilla {
61
class PRemoteSpellcheckEngineParent;
62
63
#if defined(XP_LINUX) && defined(MOZ_CONTENT_SANDBOX)
64
class SandboxBroker;
65
class SandboxBrokerPolicyFactory;
66
#endif
67
68
class PreallocatedProcessManagerImpl;
69
70
using mozilla::loader::PScriptCacheParent;
71
72
namespace embedding {
73
class PrintingParent;
74
}
75
76
namespace ipc {
77
class CrashReporterHost;
78
class OptionalURIParams;
79
class PFileDescriptorSetParent;
80
class URIParams;
81
class TestShellParent;
82
#ifdef FUZZING
83
class ProtocolFuzzerHelper;
84
#endif
85
} // namespace ipc
86
87
namespace jsipc {
88
class PJavaScriptParent;
89
} // namespace jsipc
90
91
namespace layers {
92
struct TextureFactoryIdentifier;
93
} // namespace layers
94
95
namespace layout {
96
class PRenderFrameParent;
97
} // namespace layout
98
99
namespace dom {
100
101
class Element;
102
class TabParent;
103
class ClonedMessageData;
104
class MemoryReport;
105
class TabContext;
106
class ContentBridgeParent;
107
class GetFilesHelper;
108
class MemoryReportRequestHost;
109
110
class ContentParent final : public PContentParent
111
                          , public nsIContentParent
112
                          , public nsIObserver
113
                          , public nsIDOMGeoPositionCallback
114
                          , public nsIDOMGeoPositionErrorCallback
115
                          , public nsIInterfaceRequestor
116
                          , public gfx::gfxVarReceiver
117
                          , public mozilla::LinkedListElement<ContentParent>
118
                          , public gfx::GPUProcessListener
119
                          , public mozilla::MemoryReportingProcess
120
{
121
  typedef mozilla::ipc::OptionalURIParams OptionalURIParams;
122
  typedef mozilla::ipc::PFileDescriptorSetParent PFileDescriptorSetParent;
123
  typedef mozilla::ipc::TestShellParent TestShellParent;
124
  typedef mozilla::ipc::URIParams URIParams;
125
  typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
126
  typedef mozilla::dom::ClonedMessageData ClonedMessageData;
127
128
  friend class ContentProcessHost;
129
  friend class mozilla::PreallocatedProcessManagerImpl;
130
#ifdef FUZZING
131
  friend class mozilla::ipc::ProtocolFuzzerHelper;
132
#endif
133
134
public:
135
136
0
  virtual bool IsContentParent() const override { return true; }
137
138
  /**
139
   * Create a subprocess suitable for use later as a content process.
140
   */
141
  static already_AddRefed<ContentParent> PreallocateProcess();
142
143
  /**
144
   * Start up the content-process machinery.  This might include
145
   * scheduling pre-launch tasks.
146
   */
147
  static void StartUp();
148
149
  /** Shut down the content-process machinery. */
150
  static void ShutDown();
151
152
  static uint32_t GetPoolSize(const nsAString& aContentProcessType);
153
154
  static uint32_t GetMaxProcessCount(const nsAString& aContentProcessType);
155
156
  static bool IsMaxProcessCountReached(const nsAString& aContentProcessType);
157
158
  static void ReleaseCachedProcesses();
159
160
  /**
161
   * Picks a random content parent from |aContentParents| with a given |aOpener|
162
   * respecting the index limit set by |aMaxContentParents|.
163
   * Returns null if non available.
164
   */
165
  static already_AddRefed<ContentParent>
166
  MinTabSelect(const nsTArray<ContentParent*>& aContentParents,
167
               ContentParent* aOpener,
168
               int32_t maxContentParents);
169
170
  /**
171
   * Get or create a content process for:
172
   * 1. browser iframe
173
   * 2. remote xul <browser>
174
   * 3. normal iframe
175
   */
176
  static already_AddRefed<ContentParent>
177
  GetNewOrUsedBrowserProcess(Element* aFrameElement,
178
                             const nsAString& aRemoteType,
179
                             hal::ProcessPriority aPriority =
180
                             hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
181
                             ContentParent* aOpener = nullptr,
182
                             bool aPreferUsed = false);
183
184
  /**
185
   * Get or create a content process for a JS plugin. aPluginID is the id of the JS plugin
186
   * (@see nsFakePlugin::mId). There is a maximum of one process per JS plugin.
187
   */
188
  static already_AddRefed<ContentParent>
189
  GetNewOrUsedJSPluginProcess(uint32_t aPluginID,
190
                              const hal::ProcessPriority& aPriority);
191
192
  /**
193
   * Get or create a content process for the given TabContext.  aFrameElement
194
   * should be the frame/iframe element with which this process will
195
   * associated.
196
   */
197
  static TabParent*
198
  CreateBrowser(const TabContext& aContext,
199
                Element* aFrameElement,
200
                ContentParent* aOpenerContentParent,
201
                TabParent* aSameTabGroupAs,
202
                uint64_t aNextTabParentId);
203
204
  static void GetAll(nsTArray<ContentParent*>& aArray);
205
206
  static void GetAllEvenIfDead(nsTArray<ContentParent*>& aArray);
207
208
  static void BroadcastStringBundle(const StringBundleDescriptor&);
209
210
  const nsAString& GetRemoteType() const;
211
212
  virtual void DoGetRemoteType(nsAString& aRemoteType, ErrorResult& aError) const override
213
0
  {
214
0
    aRemoteType = GetRemoteType();
215
0
  }
216
217
  enum CPIteratorPolicy {
218
    eLive,
219
    eAll
220
  };
221
222
  class ContentParentIterator {
223
  private:
224
    ContentParent* mCurrent;
225
    CPIteratorPolicy mPolicy;
226
227
  public:
228
    ContentParentIterator(CPIteratorPolicy aPolicy, ContentParent* aCurrent)
229
      : mCurrent(aCurrent),
230
        mPolicy(aPolicy)
231
264
    {
232
264
    }
233
234
    ContentParentIterator begin()
235
132
    {
236
132
      // Move the cursor to the first element that matches the policy.
237
132
      while (mPolicy != eAll && mCurrent && !mCurrent->mIsAlive) {
238
0
        mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
239
0
      }
240
132
241
132
      return *this;
242
132
    }
243
    ContentParentIterator end()
244
132
    {
245
132
      return ContentParentIterator(mPolicy, nullptr);
246
132
    }
247
248
    const ContentParentIterator& operator++()
249
0
    {
250
0
      MOZ_ASSERT(mCurrent);
251
0
      do {
252
0
        mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
253
0
      } while (mPolicy != eAll && mCurrent && !mCurrent->mIsAlive);
254
0
255
0
      return *this;
256
0
    }
257
258
    bool operator!=(const ContentParentIterator& aOther)
259
132
    {
260
132
      MOZ_ASSERT(mPolicy == aOther.mPolicy);
261
132
      return mCurrent != aOther.mCurrent;
262
132
    }
263
264
    ContentParent* operator*()
265
0
    {
266
0
      return mCurrent;
267
0
    }
268
  };
269
270
  static ContentParentIterator AllProcesses(CPIteratorPolicy aPolicy)
271
132
  {
272
132
    ContentParent* first =
273
132
      sContentParents ? sContentParents->getFirst() : nullptr;
274
132
    return ContentParentIterator(aPolicy, first);
275
132
  }
276
277
  static bool IgnoreIPCPrincipal();
278
279
  static void NotifyUpdatedDictionaries();
280
281
  static void NotifyUpdatedFonts();
282
283
#if defined(XP_WIN)
284
  /**
285
   * Windows helper for firing off an update window request to a plugin
286
   * instance.
287
   *
288
   * aWidget - the eWindowType_plugin_ipc_chrome widget associated with
289
   *           this plugin window.
290
   */
291
  static void SendAsyncUpdate(nsIWidget* aWidget);
292
#endif
293
294
  // Let managees query if it is safe to send messages.
295
0
  bool IsDestroyed() const { return !mIPCOpen; }
296
297
  virtual mozilla::ipc::IPCResult RecvCreateChildProcess(const IPCTabContext& aContext,
298
                                                         const hal::ProcessPriority& aPriority,
299
                                                         const TabId& aOpenerTabId,
300
                                                         const TabId& aTabId,
301
                                                         ContentParentId* aCpId,
302
                                                         bool* aIsForBrowser) override;
303
304
  virtual mozilla::ipc::IPCResult RecvBridgeToChildProcess(const ContentParentId& aCpId,
305
                                                           Endpoint<PContentBridgeParent>* aEndpoint) override;
306
307
  virtual mozilla::ipc::IPCResult RecvOpenRecordReplayChannel(const uint32_t& channelId,
308
                                                              FileDescriptor* connection) override;
309
  virtual mozilla::ipc::IPCResult RecvCreateReplayingProcess(const uint32_t& aChannelId) override;
310
  virtual mozilla::ipc::IPCResult RecvTerminateReplayingProcess(const uint32_t& aChannelId) override;
311
312
  virtual mozilla::ipc::IPCResult RecvCreateGMPService() override;
313
314
  virtual mozilla::ipc::IPCResult RecvLoadPlugin(const uint32_t& aPluginId, nsresult* aRv,
315
                                                 uint32_t* aRunID,
316
                                                 Endpoint<PPluginModuleParent>* aEndpoint) override;
317
318
  virtual mozilla::ipc::IPCResult RecvMaybeReloadPlugins() override;
319
320
  virtual mozilla::ipc::IPCResult RecvConnectPluginBridge(const uint32_t& aPluginId,
321
                                                          nsresult* aRv,
322
                                                          Endpoint<PPluginModuleParent>* aEndpoint) override;
323
324
  virtual mozilla::ipc::IPCResult RecvUngrabPointer(const uint32_t& aTime) override;
325
326
  virtual mozilla::ipc::IPCResult RecvRemovePermission(const IPC::Principal& aPrincipal,
327
                                                       const nsCString& aPermissionType,
328
                                                       nsresult* aRv) override;
329
330
  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ContentParent, nsIObserver)
331
332
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
333
  NS_DECL_NSIOBSERVER
334
  NS_DECL_NSIDOMGEOPOSITIONCALLBACK
335
  NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK
336
  NS_DECL_NSIINTERFACEREQUESTOR
337
338
  /**
339
   * MessageManagerCallback methods that we override.
340
   */
341
  virtual bool DoLoadMessageManagerScript(const nsAString& aURL,
342
                                          bool aRunInGlobalScope) override;
343
344
  virtual nsresult DoSendAsyncMessage(JSContext* aCx,
345
                                      const nsAString& aMessage,
346
                                      StructuredCloneData& aData,
347
                                      JS::Handle<JSObject *> aCpows,
348
                                      nsIPrincipal* aPrincipal) override;
349
350
  /** Notify that a tab is beginning its destruction sequence. */
351
  static void NotifyTabDestroying(const TabId& aTabId,
352
                                  const ContentParentId& aCpId);
353
354
  /** Notify that a tab was destroyed during normal operation. */
355
  void NotifyTabDestroyed(const TabId& aTabId,
356
                          bool aNotifiedDestroying);
357
358
  TestShellParent* CreateTestShell();
359
360
  bool DestroyTestShell(TestShellParent* aTestShell);
361
362
  TestShellParent* GetTestShellSingleton();
363
364
  jsipc::CPOWManager* GetCPOWManager() override;
365
366
  static void
367
  UnregisterRemoteFrame(const TabId& aTabId,
368
                        const ContentParentId& aCpId,
369
                        bool aMarkedDestroying);
370
371
  void ReportChildAlreadyBlocked();
372
373
  bool RequestRunToCompletion();
374
375
  void UpdateCookieStatus(nsIChannel *aChannel);
376
377
  bool IsAvailable() const
378
0
  {
379
0
    return mIsAvailable;
380
0
  }
381
  bool IsAlive() const override;
382
383
  virtual bool IsForBrowser() const override
384
0
  {
385
0
    return mIsForBrowser;
386
0
  }
387
  virtual bool IsForJSPlugin() const override
388
0
  {
389
0
    return mJSPluginID != nsFakePluginTag::NOT_JSPLUGIN;
390
0
  }
391
392
  ContentProcessHost* Process() const
393
0
  {
394
0
    return mSubprocess;
395
0
  }
396
397
  ContentParent* Opener() const
398
0
  {
399
0
    return mOpener;
400
0
  }
401
  nsIContentProcessInfo* ScriptableHelper() const
402
0
  {
403
0
    return mScriptableHelper;
404
0
  }
405
406
  bool NeedsPermissionsUpdate(const nsACString& aPermissionKey) const;
407
408
  /**
409
   * Kill our subprocess and make sure it dies.  Should only be used
410
   * in emergency situations since it bypasses the normal shutdown
411
   * process.
412
   *
413
   * WARNING: aReason appears in telemetry, so any new value passed in requires
414
   * data review.
415
   */
416
  void KillHard(const char* aWhy);
417
418
0
  ContentParentId ChildID() const override { return mChildID; }
419
420
  /**
421
   * Get a user-friendly name for this ContentParent.  We make no guarantees
422
   * about this name: It might not be unique, apps can spoof special names,
423
   * etc.  So please don't use this name to make any decisions about the
424
   * ContentParent based on the value returned here.
425
   */
426
  void FriendlyName(nsAString& aName, bool aAnonymize = false);
427
428
  virtual void OnChannelError() override;
429
430
  virtual mozilla::ipc::IPCResult
431
  RecvInitCrashReporter(Shmem&& aShmem, const NativeThreadId& aThreadId) override;
432
433
  virtual PNeckoParent* AllocPNeckoParent() override;
434
435
  virtual mozilla::ipc::IPCResult RecvPNeckoConstructor(PNeckoParent* aActor) override
436
0
  {
437
0
    return PContentParent::RecvPNeckoConstructor(aActor);
438
0
  }
439
440
  virtual PPrintingParent* AllocPPrintingParent() override;
441
442
  virtual bool DeallocPPrintingParent(PPrintingParent* aActor) override;
443
444
#if defined(NS_PRINTING)
445
  /**
446
   * @return the PrintingParent for this ContentParent.
447
   */
448
  already_AddRefed<embedding::PrintingParent> GetPrintingParent();
449
#endif
450
451
  virtual mozilla::ipc::IPCResult
452
  RecvInitStreamFilter(const uint64_t& aChannelId,
453
                       const nsString& aAddonId,
454
                       InitStreamFilterResolver&& aResolver) override;
455
456
  virtual PChildToParentStreamParent* AllocPChildToParentStreamParent() override;
457
  virtual bool
458
  DeallocPChildToParentStreamParent(PChildToParentStreamParent* aActor) override;
459
460
  virtual PParentToChildStreamParent*
461
  SendPParentToChildStreamConstructor(PParentToChildStreamParent*) override;
462
463
  virtual PFileDescriptorSetParent*
464
  SendPFileDescriptorSetConstructor(const FileDescriptor&) override;
465
466
  virtual PParentToChildStreamParent* AllocPParentToChildStreamParent() override;
467
  virtual bool
468
  DeallocPParentToChildStreamParent(PParentToChildStreamParent* aActor) override;
469
470
  virtual PHalParent* AllocPHalParent() override;
471
472
  virtual mozilla::ipc::IPCResult RecvPHalConstructor(PHalParent* aActor) override
473
0
  {
474
0
    return PContentParent::RecvPHalConstructor(aActor);
475
0
  }
476
477
  virtual PHeapSnapshotTempFileHelperParent*
478
  AllocPHeapSnapshotTempFileHelperParent() override;
479
480
  virtual PJavaScriptParent*
481
  AllocPJavaScriptParent() override;
482
483
  virtual mozilla::ipc::IPCResult
484
  RecvPJavaScriptConstructor(PJavaScriptParent* aActor) override
485
0
  {
486
0
    return PContentParent::RecvPJavaScriptConstructor(aActor);
487
0
  }
488
489
  virtual PRemoteSpellcheckEngineParent* AllocPRemoteSpellcheckEngineParent() override;
490
491
  virtual mozilla::ipc::IPCResult RecvRecordingDeviceEvents(const nsString& aRecordingStatus,
492
                                                            const nsString& aPageURL,
493
                                                            const bool& aIsAudio,
494
                                                            const bool& aIsVideo) override;
495
496
  bool CycleCollectWithLogs(bool aDumpAllTraces,
497
                            nsICycleCollectorLogSink* aSink,
498
                            nsIDumpGCAndCCLogsCallback* aCallback);
499
500
  virtual mozilla::ipc::IPCResult RecvUnregisterRemoteFrame(const TabId& aTabId,
501
                                                            const ContentParentId& aCpId,
502
                                                            const bool& aMarkedDestroying) override;
503
504
  virtual mozilla::ipc::IPCResult RecvNotifyTabDestroying(const TabId& aTabId,
505
                                                          const ContentParentId& aCpId) override;
506
507
  nsTArray<TabContext> GetManagedTabContext();
508
509
  virtual POfflineCacheUpdateParent*
510
  AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI,
511
                                 const URIParams& aDocumentURI,
512
                                 const PrincipalInfo& aLoadingPrincipalInfo,
513
                                 const bool& aStickDocument) override;
514
515
  virtual mozilla::ipc::IPCResult
516
  RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor,
517
                                     const URIParams& aManifestURI,
518
                                     const URIParams& aDocumentURI,
519
                                     const PrincipalInfo& aLoadingPrincipal,
520
                                     const bool& stickDocument) override;
521
522
  virtual bool
523
  DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor) override;
524
525
  virtual mozilla::ipc::IPCResult RecvSetOfflinePermission(const IPC::Principal& principal) override;
526
527
  virtual mozilla::ipc::IPCResult RecvFinishShutdown() override;
528
529
  void MaybeInvokeDragSession(TabParent* aParent);
530
531
  virtual PContentPermissionRequestParent*
532
  AllocPContentPermissionRequestParent(const InfallibleTArray<PermissionRequest>& aRequests,
533
                                       const IPC::Principal& aPrincipal,
534
                                       const bool& aIsTrusted,
535
                                       const TabId& aTabId) override;
536
537
  virtual bool
538
  DeallocPContentPermissionRequestParent(PContentPermissionRequestParent* actor) override;
539
540
  virtual bool HandleWindowsMessages(const Message& aMsg) const override;
541
542
  void ForkNewProcess(bool aBlocking);
543
544
  virtual mozilla::ipc::IPCResult
545
  RecvCreateWindow(PBrowserParent* aThisTabParent,
546
                   PBrowserParent* aNewTab,
547
                   layout::PRenderFrameParent* aRenderFrame,
548
                   const uint32_t& aChromeFlags,
549
                   const bool& aCalledFromJS,
550
                   const bool& aPositionSpecified,
551
                   const bool& aSizeSpecified,
552
                   const OptionalURIParams& aURIToLoad,
553
                   const nsCString& aFeatures,
554
                   const nsCString& aBaseURI,
555
                   const float& aFullZoom,
556
                   const IPC::Principal& aTriggeringPrincipal,
557
                   const uint32_t& aReferrerPolicy,
558
                   CreateWindowResolver&& aResolve) override;
559
560
  virtual mozilla::ipc::IPCResult RecvCreateWindowInDifferentProcess(
561
    PBrowserParent* aThisTab,
562
    const uint32_t& aChromeFlags,
563
    const bool& aCalledFromJS,
564
    const bool& aPositionSpecified,
565
    const bool& aSizeSpecified,
566
    const OptionalURIParams& aURIToLoad,
567
    const nsCString& aFeatures,
568
    const nsCString& aBaseURI,
569
    const float& aFullZoom,
570
    const nsString& aName,
571
    const IPC::Principal& aTriggeringPrincipal,
572
    const uint32_t& aReferrerPolicy) override;
573
574
  static bool AllocateLayerTreeId(TabParent* aTabParent, layers::LayersId* aId);
575
576
  static void
577
  BroadcastBlobURLRegistration(const nsACString& aURI,
578
                               BlobImpl* aBlobImpl,
579
                               nsIPrincipal* aPrincipal,
580
                               ContentParent* aIgnoreThisCP = nullptr);
581
582
  static void
583
  BroadcastBlobURLUnregistration(const nsACString& aURI,
584
                                 ContentParent* aIgnoreThisCP = nullptr);
585
586
  virtual mozilla::ipc::IPCResult
587
  RecvStoreAndBroadcastBlobURLRegistration(const nsCString& aURI,
588
                                           const IPCBlob& aBlob,
589
                                           const Principal& aPrincipal) override;
590
591
  virtual mozilla::ipc::IPCResult
592
  RecvUnstoreAndBroadcastBlobURLUnregistration(const nsCString& aURI) override;
593
594
  virtual mozilla::ipc::IPCResult
595
  RecvGetA11yContentId(uint32_t* aContentId) override;
596
597
  virtual mozilla::ipc::IPCResult
598
  RecvA11yHandlerControl(const uint32_t& aPid,
599
                         const IHandlerControlHolder& aHandlerControl) override;
600
601
  virtual int32_t Pid() const override;
602
603
  // PURLClassifierParent.
604
  virtual PURLClassifierParent*
605
  AllocPURLClassifierParent(const Principal& aPrincipal,
606
                            const bool& aUseTrackingProtection,
607
                            bool* aSuccess) override;
608
  virtual mozilla::ipc::IPCResult
609
  RecvPURLClassifierConstructor(PURLClassifierParent* aActor,
610
                                const Principal& aPrincipal,
611
                                const bool& aUseTrackingProtection,
612
                                bool* aSuccess) override;
613
614
  // PURLClassifierLocalParent.
615
  virtual PURLClassifierLocalParent*
616
  AllocPURLClassifierLocalParent(const URIParams& aURI,
617
                                 const nsCString& aTables) override;
618
  virtual mozilla::ipc::IPCResult
619
  RecvPURLClassifierLocalConstructor(PURLClassifierLocalParent* aActor,
620
                                     const URIParams& aURI,
621
                                     const nsCString& aTables) override;
622
623
  virtual PLoginReputationParent*
624
  AllocPLoginReputationParent(const URIParams& aURI) override;
625
626
  virtual mozilla::ipc::IPCResult
627
  RecvPLoginReputationConstructor(PLoginReputationParent* aActor,
628
                                  const URIParams& aURI) override;
629
630
  virtual bool
631
  DeallocPLoginReputationParent(PLoginReputationParent* aActor) override;
632
633
  virtual bool SendActivate(PBrowserParent* aTab) override
634
0
  {
635
0
    return PContentParent::SendActivate(aTab);
636
0
  }
637
638
  virtual bool SendDeactivate(PBrowserParent* aTab) override
639
0
  {
640
0
    return PContentParent::SendDeactivate(aTab);
641
0
  }
642
643
  virtual bool
644
  DeallocPURLClassifierLocalParent(PURLClassifierLocalParent* aActor) override;
645
646
  virtual bool
647
  DeallocPURLClassifierParent(PURLClassifierParent* aActor) override;
648
649
  virtual mozilla::ipc::IPCResult
650
  RecvClassifyLocal(const URIParams& aURI,
651
                    const nsCString& aTables,
652
                    nsresult* aRv,
653
                    nsTArray<nsCString>* aResults) override;
654
655
  // Use the PHangMonitor channel to ask the child to repaint a tab.
656
  void PaintTabWhileInterruptingJS(TabParent* aTabParent,
657
                                   bool aForceRepaint,
658
                                   const layers::LayersObserverEpoch& aEpoch);
659
660
  // This function is called when we are about to load a document from an
661
  // HTTP(S), FTP or wyciwyg channel for a content process.  It is a useful
662
  // place to start to kick off work as early as possible in response to such
663
  // document loads.
664
  nsresult AboutToLoadHttpFtpWyciwygDocumentForChild(nsIChannel* aChannel);
665
666
  nsresult TransmitPermissionsForPrincipal(nsIPrincipal* aPrincipal);
667
668
  void OnCompositorDeviceReset() override;
669
670
  virtual PClientOpenWindowOpParent*
671
  AllocPClientOpenWindowOpParent(const ClientOpenWindowArgs& aArgs) override;
672
673
  virtual bool
674
  DeallocPClientOpenWindowOpParent(PClientOpenWindowOpParent* aActor) override;
675
676
  static hal::ProcessPriority GetInitialProcessPriority(Element* aFrameElement);
677
678
  // Control the priority of the IPC messages for input events.
679
  void SetInputPriorityEventEnabled(bool aEnabled);
680
  bool IsInputPriorityEventEnabled()
681
0
  {
682
0
    return mIsInputPriorityEventEnabled;
683
0
  }
684
685
  static bool IsInputEventQueueSupported();
686
687
  virtual mozilla::ipc::IPCResult RecvAttachBrowsingContext(
688
    const BrowsingContextId& aParentContextId,
689
    const BrowsingContextId& aContextId,
690
    const nsString& aName) override;
691
692
  virtual mozilla::ipc::IPCResult RecvDetachBrowsingContext(
693
    const BrowsingContextId& aContextId,
694
    const bool& aMoveToBFCache) override;
695
696
protected:
697
  void OnChannelConnected(int32_t pid) override;
698
699
  virtual void ActorDestroy(ActorDestroyReason why) override;
700
701
  bool ShouldContinueFromReplyTimeout() override;
702
703
  void OnVarChanged(const GfxVarUpdate& aVar) override;
704
  void OnCompositorUnexpectedShutdown() override;
705
706
private:
707
  /**
708
   * A map of the remote content process type to a list of content parents
709
   * currently available to host *new* tabs/frames of that type.
710
   *
711
   * If a content process is identified as troubled or dead, it will be
712
   * removed from this list, but will still be in the sContentParents list for
713
   * the GetAll/GetAllEvenIfDead APIs.
714
   */
715
  static nsClassHashtable<nsStringHashKey, nsTArray<ContentParent*>>* sBrowserContentParents;
716
  static nsTArray<ContentParent*>* sPrivateContent;
717
  static nsDataHashtable<nsUint32HashKey, ContentParent*> *sJSPluginContentParents;
718
  static StaticAutoPtr<LinkedList<ContentParent> > sContentParents;
719
720
  static ContentBridgeParent* CreateContentBridgeParent(const TabContext& aContext,
721
                                                        const hal::ProcessPriority& aPriority,
722
                                                        const TabId& aOpenerTabId,
723
                                                        const TabId& aTabId);
724
725
  // Hide the raw constructor methods since we don't want client code
726
  // using them.
727
  virtual PBrowserParent* SendPBrowserConstructor(
728
      PBrowserParent* actor,
729
      const TabId& aTabId,
730
      const TabId& aSameTabGroupsAs,
731
      const IPCTabContext& context,
732
      const uint32_t& chromeFlags,
733
      const ContentParentId& aCpId,
734
      const bool& aIsForBrowser) override;
735
  using PContentParent::SendPTestShellConstructor;
736
737
  // Set aLoadUri to true to load aURIToLoad and to false to only create the
738
  // window. aURIToLoad should always be provided, if available, to ensure
739
  // compatibility with GeckoView.
740
  mozilla::ipc::IPCResult
741
  CommonCreateWindow(PBrowserParent* aThisTab,
742
                     bool aSetOpener,
743
                     const uint32_t& aChromeFlags,
744
                     const bool& aCalledFromJS,
745
                     const bool& aPositionSpecified,
746
                     const bool& aSizeSpecified,
747
                     nsIURI* aURIToLoad,
748
                     const nsCString& aFeatures,
749
                     const nsCString& aBaseURI,
750
                     const float& aFullZoom,
751
                     uint64_t aNextTabParentId,
752
                     const nsString& aName,
753
                     nsresult& aResult,
754
                     nsCOMPtr<nsITabParent>& aNewTabParent,
755
                     bool* aWindowIsNew,
756
                     int32_t& aOpenLocation,
757
                     nsIPrincipal* aTriggeringPrincipal,
758
                     uint32_t aReferrerPolicy,
759
                     bool aLoadUri);
760
761
  FORWARD_SHMEM_ALLOCATOR_TO(PContentParent)
762
763
  enum RecordReplayState
764
  {
765
    eNotRecordingOrReplaying,
766
    eRecording,
767
    eReplaying
768
  };
769
770
  explicit ContentParent(int32_t aPluginID)
771
    : ContentParent(nullptr, EmptyString(), eNotRecordingOrReplaying, EmptyString(), aPluginID)
772
0
  {}
773
  ContentParent(ContentParent* aOpener,
774
                const nsAString& aRemoteType,
775
                RecordReplayState aRecordReplayState = eNotRecordingOrReplaying,
776
                const nsAString& aRecordingFile = EmptyString())
777
    : ContentParent(aOpener, aRemoteType, aRecordReplayState, aRecordingFile,
778
                    nsFakePluginTag::NOT_JSPLUGIN)
779
0
  {}
780
781
  ContentParent(ContentParent* aOpener,
782
                const nsAString& aRemoteType,
783
                RecordReplayState aRecordReplayState,
784
                const nsAString& aRecordingFile,
785
                int32_t aPluginID);
786
787
  // Launch the subprocess and associated initialization.
788
  // Returns false if the process fails to start.
789
  bool LaunchSubprocess(hal::ProcessPriority aInitialPriority = hal::PROCESS_PRIORITY_FOREGROUND);
790
791
  // Common initialization after sub process launch.
792
  void InitInternal(ProcessPriority aPriority);
793
794
  virtual ~ContentParent();
795
796
  void Init();
797
798
  // Some information could be sent to content very early, it
799
  // should be send from this function. This function should only be
800
  // called after the process has been transformed to browser.
801
  void ForwardKnownInfo();
802
803
  /**
804
   * We might want to reuse barely used content processes if certain criteria are met.
805
   */
806
  bool TryToRecycle();
807
808
  /**
809
   * Removing it from the static array so it won't be returned for new tabs in
810
   * GetNewOrUsedBrowserProcess.
811
   */
812
  void RemoveFromList();
813
814
  /**
815
   * Decide whether the process should be kept alive even when it would normally
816
   * be shut down, for example when all its tabs are closed.
817
   */
818
  bool ShouldKeepProcessAlive() const;
819
820
  /**
821
   * Mark this ContentParent as "troubled". This means that it is still alive,
822
   * but it won't be returned for new tabs in GetNewOrUsedBrowserProcess.
823
   */
824
  void MarkAsTroubled();
825
826
  /**
827
   * Mark this ContentParent as dead for the purposes of Get*().
828
   * This method is idempotent.
829
   */
830
  void MarkAsDead();
831
832
  /**
833
   * How we will shut down this ContentParent and its subprocess.
834
   */
835
  enum ShutDownMethod
836
  {
837
    // Send a shutdown message and wait for FinishShutdown call back.
838
    SEND_SHUTDOWN_MESSAGE,
839
    // Close the channel ourselves and let the subprocess clean up itself.
840
    CLOSE_CHANNEL,
841
    // Close the channel with error and let the subprocess clean up itself.
842
    CLOSE_CHANNEL_WITH_ERROR,
843
  };
844
845
  /**
846
   * Exit the subprocess and vamoose.  After this call IsAlive()
847
   * will return false and this ContentParent will not be returned
848
   * by the Get*() funtions.  However, the shutdown sequence itself
849
   * may be asynchronous.
850
   *
851
   * If aMethod is CLOSE_CHANNEL_WITH_ERROR and this is the first call
852
   * to ShutDownProcess, then we'll close our channel using CloseWithError()
853
   * rather than vanilla Close().  CloseWithError() indicates to IPC that this
854
   * is an abnormal shutdown (e.g. a crash).
855
   */
856
  void ShutDownProcess(ShutDownMethod aMethod);
857
858
  // Perform any steps necesssary to gracefully shtudown the message
859
  // manager and null out mMessageManager.
860
  void ShutDownMessageManager();
861
862
  // Start the force-kill timer on shutdown.
863
  void StartForceKillTimer();
864
865
  // Ensure that the permissions for the giben Permission key are set in the
866
  // content process.
867
  //
868
  // See nsIPermissionManager::GetPermissionsForKey for more information on
869
  // these keys.
870
  void EnsurePermissionsByKey(const nsCString& aKey);
871
872
  static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure);
873
874
  static bool AllocateLayerTreeId(ContentParent* aContent,
875
                                  TabParent* aTopLevel, const TabId& aTabId,
876
                                  layers::LayersId* aId);
877
878
  /**
879
   * Get or create the corresponding content parent array to |aContentProcessType|.
880
   */
881
  static nsTArray<ContentParent*>& GetOrCreatePool(const nsAString& aContentProcessType);
882
883
  virtual mozilla::ipc::IPCResult RecvInitBackground(Endpoint<mozilla::ipc::PBackgroundParent>&& aEndpoint) override;
884
885
  mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport) override;
886
  mozilla::ipc::IPCResult RecvFinishMemoryReport(const uint32_t& aGeneration) override;
887
  mozilla::ipc::IPCResult RecvAddPerformanceMetrics(const nsID& aID, nsTArray<PerformanceInfo>&& aMetrics) override;
888
889
  virtual bool
890
  DeallocPJavaScriptParent(mozilla::jsipc::PJavaScriptParent*) override;
891
892
  virtual bool
893
  DeallocPRemoteSpellcheckEngineParent(PRemoteSpellcheckEngineParent*) override;
894
895
  virtual PBrowserParent* AllocPBrowserParent(const TabId& aTabId,
896
                                              const TabId& aSameTabGroupAs,
897
                                              const IPCTabContext& aContext,
898
                                              const uint32_t& aChromeFlags,
899
                                              const ContentParentId& aCpId,
900
                                              const bool& aIsForBrowser) override;
901
902
  virtual bool DeallocPBrowserParent(PBrowserParent* frame) override;
903
904
  virtual mozilla::ipc::IPCResult
905
  RecvPBrowserConstructor(PBrowserParent* actor,
906
                          const TabId& tabId,
907
                          const TabId& sameTabGroupAs,
908
                          const IPCTabContext& context,
909
                          const uint32_t& chromeFlags,
910
                          const ContentParentId& cpId,
911
                          const bool& isForBrowser) override;
912
913
  virtual PIPCBlobInputStreamParent*
914
  SendPIPCBlobInputStreamConstructor(PIPCBlobInputStreamParent* aActor,
915
                                     const nsID& aID,
916
                                     const uint64_t& aSize) override;
917
918
  virtual PIPCBlobInputStreamParent*
919
  AllocPIPCBlobInputStreamParent(const nsID& aID,
920
                                 const uint64_t& aSize) override;
921
922
  virtual bool
923
  DeallocPIPCBlobInputStreamParent(PIPCBlobInputStreamParent* aActor) override;
924
925
  virtual mozilla::ipc::IPCResult RecvIsSecureURI(const uint32_t& aType, const URIParams& aURI,
926
                                                  const uint32_t& aFlags,
927
                                                  const OriginAttributes& aOriginAttributes,
928
                                                  bool* aIsSecureURI) override;
929
930
  virtual mozilla::ipc::IPCResult RecvAccumulateMixedContentHSTS(const URIParams& aURI,
931
                                                                 const bool& aActive,
932
                                                                 const OriginAttributes& aOriginAttributes) override;
933
934
  virtual bool DeallocPHalParent(PHalParent*) override;
935
936
  virtual bool
937
  DeallocPHeapSnapshotTempFileHelperParent(PHeapSnapshotTempFileHelperParent*) override;
938
939
  virtual PCycleCollectWithLogsParent*
940
  AllocPCycleCollectWithLogsParent(const bool& aDumpAllTraces,
941
                                   const FileDescriptor& aGCLog,
942
                                   const FileDescriptor& aCCLog) override;
943
944
  virtual bool
945
  DeallocPCycleCollectWithLogsParent(PCycleCollectWithLogsParent* aActor) override;
946
947
  virtual PTestShellParent* AllocPTestShellParent() override;
948
949
  virtual bool DeallocPTestShellParent(PTestShellParent* shell) override;
950
951
  virtual PScriptCacheParent*
952
  AllocPScriptCacheParent(const FileDescOrError& cacheFile,
953
                          const bool& wantCacheData) override;
954
955
  virtual bool DeallocPScriptCacheParent(PScriptCacheParent* shell) override;
956
957
  virtual bool DeallocPNeckoParent(PNeckoParent* necko) override;
958
959
  virtual PPSMContentDownloaderParent*
960
  AllocPPSMContentDownloaderParent(const uint32_t& aCertType) override;
961
962
  virtual bool
963
  DeallocPPSMContentDownloaderParent(PPSMContentDownloaderParent* aDownloader) override;
964
965
  virtual PExternalHelperAppParent*
966
  AllocPExternalHelperAppParent(const OptionalURIParams& aUri,
967
                                const nsCString& aMimeContentType,
968
                                const nsCString& aContentDisposition,
969
                                const uint32_t& aContentDispositionHint,
970
                                const nsString& aContentDispositionFilename,
971
                                const bool& aForceSave,
972
                                const int64_t& aContentLength,
973
                                const bool& aWasFileChannel,
974
                                const OptionalURIParams& aReferrer,
975
                                PBrowserParent* aBrowser) override;
976
977
  virtual bool
978
  DeallocPExternalHelperAppParent(PExternalHelperAppParent* aService) override;
979
980
  virtual PHandlerServiceParent* AllocPHandlerServiceParent() override;
981
982
  virtual bool DeallocPHandlerServiceParent(PHandlerServiceParent*) override;
983
984
  virtual PMediaParent* AllocPMediaParent() override;
985
986
  virtual bool DeallocPMediaParent(PMediaParent* aActor) override;
987
988
  virtual PPresentationParent* AllocPPresentationParent() override;
989
990
  virtual bool DeallocPPresentationParent(PPresentationParent* aActor) override;
991
992
  virtual mozilla::ipc::IPCResult RecvPPresentationConstructor(PPresentationParent* aActor) override;
993
994
  virtual PSpeechSynthesisParent* AllocPSpeechSynthesisParent() override;
995
996
  virtual bool
997
  DeallocPSpeechSynthesisParent(PSpeechSynthesisParent* aActor) override;
998
999
  virtual mozilla::ipc::IPCResult
1000
  RecvPSpeechSynthesisConstructor(PSpeechSynthesisParent* aActor) override;
1001
1002
  virtual PWebBrowserPersistDocumentParent*
1003
  AllocPWebBrowserPersistDocumentParent(PBrowserParent* aBrowser,
1004
                                        const uint64_t& aOuterWindowID) override;
1005
1006
  virtual bool
1007
  DeallocPWebBrowserPersistDocumentParent(PWebBrowserPersistDocumentParent* aActor) override;
1008
1009
  virtual mozilla::ipc::IPCResult RecvGetGfxVars(InfallibleTArray<GfxVarUpdate>* aVars) override;
1010
1011
  virtual mozilla::ipc::IPCResult RecvReadFontList(InfallibleTArray<FontListEntry>* retValue) override;
1012
1013
  virtual mozilla::ipc::IPCResult RecvSetClipboard(const IPCDataTransfer& aDataTransfer,
1014
                                                   const bool& aIsPrivateData,
1015
                                                   const IPC::Principal& aRequestingPrincipal,
1016
                                                   const uint32_t& aContentPolicyType,
1017
                                                   const int32_t& aWhichClipboard) override;
1018
1019
  virtual mozilla::ipc::IPCResult RecvGetClipboard(nsTArray<nsCString>&& aTypes,
1020
                                                   const int32_t& aWhichClipboard,
1021
                                                   IPCDataTransfer* aDataTransfer) override;
1022
1023
  virtual mozilla::ipc::IPCResult RecvEmptyClipboard(const int32_t& aWhichClipboard) override;
1024
1025
  virtual mozilla::ipc::IPCResult RecvClipboardHasType(nsTArray<nsCString>&& aTypes,
1026
                                                       const int32_t& aWhichClipboard,
1027
                                                       bool* aHasType) override;
1028
1029
  virtual mozilla::ipc::IPCResult RecvGetExternalClipboardFormats(const int32_t& aWhichClipboard,
1030
                                                                  const bool& aPlainTextOnly,
1031
                                                                  nsTArray<nsCString>* aTypes) override;
1032
1033
  virtual mozilla::ipc::IPCResult RecvPlaySound(const URIParams& aURI) override;
1034
  virtual mozilla::ipc::IPCResult RecvBeep() override;
1035
  virtual mozilla::ipc::IPCResult RecvPlayEventSound(const uint32_t& aEventId) override;
1036
1037
  virtual mozilla::ipc::IPCResult RecvGetSystemColors(const uint32_t& colorsCount,
1038
                                                      InfallibleTArray<uint32_t>* colors) override;
1039
1040
  virtual mozilla::ipc::IPCResult RecvGetIconForExtension(const nsCString& aFileExt,
1041
                                                          const uint32_t& aIconSize,
1042
                                                          InfallibleTArray<uint8_t>* bits) override;
1043
1044
  virtual mozilla::ipc::IPCResult RecvGetShowPasswordSetting(bool* showPassword) override;
1045
1046
  virtual mozilla::ipc::IPCResult RecvStartVisitedQuery(const URIParams& uri) override;
1047
1048
  virtual mozilla::ipc::IPCResult RecvVisitURI(const URIParams& uri,
1049
                                               const OptionalURIParams& referrer,
1050
                                               const uint32_t& flags) override;
1051
1052
  virtual mozilla::ipc::IPCResult RecvSetURITitle(const URIParams& uri,
1053
                                                  const nsString& title) override;
1054
1055
  bool HasNotificationPermission(const IPC::Principal& aPrincipal);
1056
1057
  virtual mozilla::ipc::IPCResult RecvShowAlert(nsIAlertNotification* aAlert) override;
1058
1059
  virtual mozilla::ipc::IPCResult RecvCloseAlert(const nsString& aName,
1060
                                                 const IPC::Principal& aPrincipal) override;
1061
1062
  virtual mozilla::ipc::IPCResult RecvDisableNotifications(const IPC::Principal& aPrincipal) override;
1063
1064
  virtual mozilla::ipc::IPCResult RecvOpenNotificationSettings(const IPC::Principal& aPrincipal) override;
1065
1066
  virtual mozilla::ipc::IPCResult RecvLoadURIExternal(const URIParams& uri,
1067
                                                      PBrowserParent* windowContext) override;
1068
  virtual mozilla::ipc::IPCResult RecvExtProtocolChannelConnectParent(const uint32_t& registrarId) override;
1069
1070
  virtual mozilla::ipc::IPCResult RecvSyncMessage(const nsString& aMsg,
1071
                                                  const ClonedMessageData& aData,
1072
                                                  InfallibleTArray<CpowEntry>&& aCpows,
1073
                                                  const IPC::Principal& aPrincipal,
1074
                                                  nsTArray<StructuredCloneData>* aRetvals) override;
1075
1076
  virtual mozilla::ipc::IPCResult RecvRpcMessage(const nsString& aMsg,
1077
                                                 const ClonedMessageData& aData,
1078
                                                 InfallibleTArray<CpowEntry>&& aCpows,
1079
                                                 const IPC::Principal& aPrincipal,
1080
                                                 nsTArray<StructuredCloneData>* aRetvals) override;
1081
1082
  virtual mozilla::ipc::IPCResult RecvAsyncMessage(const nsString& aMsg,
1083
                                                   InfallibleTArray<CpowEntry>&& aCpows,
1084
                                                   const IPC::Principal& aPrincipal,
1085
                                                   const ClonedMessageData& aData) override;
1086
1087
  virtual mozilla::ipc::IPCResult RecvAddGeolocationListener(const IPC::Principal& aPrincipal,
1088
                                                             const bool& aHighAccuracy) override;
1089
  virtual mozilla::ipc::IPCResult RecvRemoveGeolocationListener() override;
1090
1091
  virtual mozilla::ipc::IPCResult RecvSetGeolocationHigherAccuracy(const bool& aEnable) override;
1092
1093
  virtual mozilla::ipc::IPCResult RecvConsoleMessage(const nsString& aMessage) override;
1094
1095
  virtual mozilla::ipc::IPCResult RecvScriptError(const nsString& aMessage,
1096
                                                  const nsString& aSourceName,
1097
                                                  const nsString& aSourceLine,
1098
                                                  const uint32_t& aLineNumber,
1099
                                                  const uint32_t& aColNumber,
1100
                                                  const uint32_t& aFlags,
1101
                                                  const nsCString& aCategory,
1102
                                                  const bool& aIsFromPrivateWindow) override;
1103
1104
  virtual mozilla::ipc::IPCResult RecvScriptErrorWithStack(const nsString& aMessage,
1105
                                                           const nsString& aSourceName,
1106
                                                           const nsString& aSourceLine,
1107
                                                           const uint32_t& aLineNumber,
1108
                                                           const uint32_t& aColNumber,
1109
                                                           const uint32_t& aFlags,
1110
                                                           const nsCString& aCategory,
1111
                                                           const bool& aIsFromPrivateWindow,
1112
                                                           const ClonedMessageData& aStack) override;
1113
1114
private:
1115
  mozilla::ipc::IPCResult RecvScriptErrorInternal(const nsString& aMessage,
1116
                                                  const nsString& aSourceName,
1117
                                                  const nsString& aSourceLine,
1118
                                                  const uint32_t& aLineNumber,
1119
                                                  const uint32_t& aColNumber,
1120
                                                  const uint32_t& aFlags,
1121
                                                  const nsCString& aCategory,
1122
                                                  const bool& aIsFromPrivateWindow,
1123
                                                  const ClonedMessageData* aStack = nullptr);
1124
1125
public:
1126
  virtual mozilla::ipc::IPCResult RecvPrivateDocShellsExist(const bool& aExist) override;
1127
1128
  virtual mozilla::ipc::IPCResult RecvFirstIdle() override;
1129
1130
  virtual mozilla::ipc::IPCResult RecvDeviceReset() override;
1131
1132
  virtual mozilla::ipc::IPCResult RecvKeywordToURI(const nsCString& aKeyword,
1133
                                                   nsString* aProviderName,
1134
                                                   RefPtr<nsIInputStream>* aPostData,
1135
                                                   OptionalURIParams* aURI) override;
1136
1137
  virtual mozilla::ipc::IPCResult RecvNotifyKeywordSearchLoading(const nsString &aProvider,
1138
                                                                 const nsString &aKeyword) override;
1139
1140
  virtual mozilla::ipc::IPCResult RecvCopyFavicon(const URIParams& aOldURI,
1141
                                                  const URIParams& aNewURI,
1142
                                                  const IPC::Principal& aLoadingPrincipal,
1143
                                                  const bool& aInPrivateBrowsing) override;
1144
1145
  virtual void ProcessingError(Result aCode, const char* aMsgName) override;
1146
1147
  virtual mozilla::ipc::IPCResult RecvAllocateLayerTreeId(const ContentParentId& aCpId,
1148
                                                          const TabId& aTabId,
1149
                                                          layers::LayersId* aId) override;
1150
1151
  virtual mozilla::ipc::IPCResult RecvDeallocateLayerTreeId(const ContentParentId& aCpId,
1152
                                                            const layers::LayersId& aId) override;
1153
1154
  virtual mozilla::ipc::IPCResult RecvGraphicsError(const nsCString& aError) override;
1155
1156
  virtual mozilla::ipc::IPCResult
1157
  RecvBeginDriverCrashGuard(const uint32_t& aGuardType,
1158
                            bool* aOutCrashed) override;
1159
1160
  virtual mozilla::ipc::IPCResult RecvEndDriverCrashGuard(const uint32_t& aGuardType) override;
1161
1162
  virtual mozilla::ipc::IPCResult RecvAddIdleObserver(const uint64_t& observerId,
1163
                                                      const uint32_t& aIdleTimeInS) override;
1164
1165
  virtual mozilla::ipc::IPCResult RecvRemoveIdleObserver(const uint64_t& observerId,
1166
                                                         const uint32_t& aIdleTimeInS) override;
1167
1168
  virtual mozilla::ipc::IPCResult
1169
  RecvBackUpXResources(const FileDescriptor& aXSocketFd) override;
1170
1171
  virtual mozilla::ipc::IPCResult
1172
  RecvRequestAnonymousTemporaryFile(const uint64_t& aID) override;
1173
1174
  virtual mozilla::ipc::IPCResult
1175
  RecvCreateAudioIPCConnection(CreateAudioIPCConnectionResolver&& aResolver) override;
1176
1177
  virtual mozilla::ipc::IPCResult
1178
  RecvKeygenProcessValue(const nsString& oldValue, const nsString& challenge,
1179
                         const nsString& keytype, const nsString& keyparams,
1180
                         nsString* newValue) override;
1181
1182
  virtual mozilla::ipc::IPCResult
1183
  RecvKeygenProvideContent(nsString* aAttribute,
1184
                           nsTArray<nsString>* aContent) override;
1185
1186
  virtual PFileDescriptorSetParent*
1187
  AllocPFileDescriptorSetParent(const mozilla::ipc::FileDescriptor&) override;
1188
1189
  virtual bool
1190
  DeallocPFileDescriptorSetParent(PFileDescriptorSetParent*) override;
1191
1192
  virtual PWebrtcGlobalParent* AllocPWebrtcGlobalParent() override;
1193
  virtual bool DeallocPWebrtcGlobalParent(PWebrtcGlobalParent *aActor) override;
1194
1195
1196
  virtual mozilla::ipc::IPCResult RecvUpdateDropEffect(const uint32_t& aDragAction,
1197
                                                       const uint32_t& aDropEffect) override;
1198
1199
  virtual mozilla::ipc::IPCResult RecvShutdownProfile(const nsCString& aProfile) override;
1200
1201
  virtual mozilla::ipc::IPCResult RecvGetGraphicsDeviceInitData(ContentDeviceData* aOut) override;
1202
1203
  virtual mozilla::ipc::IPCResult RecvGetAndroidSystemInfo(AndroidSystemInfo* aInfo) override;
1204
1205
  virtual mozilla::ipc::IPCResult RecvNotifyBenchmarkResult(const nsString& aCodecName,
1206
                                                            const uint32_t& aDecodeFPS) override;
1207
1208
  virtual mozilla::ipc::IPCResult RecvNotifyPushObservers(const nsCString& aScope,
1209
                                                          const IPC::Principal& aPrincipal,
1210
                                                          const nsString& aMessageId) override;
1211
1212
  virtual mozilla::ipc::IPCResult RecvNotifyPushObserversWithData(const nsCString& aScope,
1213
                                                                  const IPC::Principal& aPrincipal,
1214
                                                                  const nsString& aMessageId,
1215
                                                                  InfallibleTArray<uint8_t>&& aData) override;
1216
1217
  virtual mozilla::ipc::IPCResult RecvNotifyPushSubscriptionChangeObservers(const nsCString& aScope,
1218
                                                                            const IPC::Principal& aPrincipal) override;
1219
1220
  virtual mozilla::ipc::IPCResult RecvNotifyPushSubscriptionModifiedObservers(const nsCString& aScope,
1221
                                                                              const IPC::Principal& aPrincipal) override;
1222
1223
  virtual mozilla::ipc::IPCResult RecvGetFilesRequest(const nsID& aID,
1224
                                                      const nsString& aDirectoryPath,
1225
                                                      const bool& aRecursiveFlag) override;
1226
1227
  virtual mozilla::ipc::IPCResult RecvDeleteGetFilesRequest(const nsID& aID) override;
1228
1229
  virtual mozilla::ipc::IPCResult
1230
  RecvFileCreationRequest(const nsID& aID, const nsString& aFullPath,
1231
                          const nsString& aType, const nsString& aName,
1232
                          const bool& aLastModifiedPassed,
1233
                          const int64_t& aLastModified,
1234
                          const bool& aExistenceCheck,
1235
                          const bool& aIsFromNsIFile) override;
1236
1237
  virtual mozilla::ipc::IPCResult RecvAccumulateChildHistograms(
1238
    InfallibleTArray<HistogramAccumulation>&& aAccumulations) override;
1239
  virtual mozilla::ipc::IPCResult RecvAccumulateChildKeyedHistograms(
1240
    InfallibleTArray<KeyedHistogramAccumulation>&& aAccumulations) override;
1241
  virtual mozilla::ipc::IPCResult RecvUpdateChildScalars(
1242
    InfallibleTArray<ScalarAction>&& aScalarActions) override;
1243
  virtual mozilla::ipc::IPCResult RecvUpdateChildKeyedScalars(
1244
    InfallibleTArray<KeyedScalarAction>&& aScalarActions) override;
1245
  virtual mozilla::ipc::IPCResult RecvRecordChildEvents(
1246
    nsTArray<ChildEventData>&& events) override;
1247
  virtual mozilla::ipc::IPCResult RecvRecordDiscardedData(
1248
    const DiscardedData& aDiscardedData) override;
1249
1250
  virtual mozilla::ipc::IPCResult RecvBHRThreadHang(
1251
    const HangDetails& aHangDetails) override;
1252
1253
  virtual mozilla::ipc::IPCResult
1254
  RecvFirstPartyStorageAccessGrantedForOrigin(const Principal& aParentPrincipal,
1255
                                              const nsCString& aTrackingOrigin,
1256
                                              const nsCString& aGrantedOrigin,
1257
                                              FirstPartyStorageAccessGrantedForOriginResolver&& aResolver) override;
1258
1259
  virtual mozilla::ipc::IPCResult
1260
  RecvStoreUserInteractionAsPermission(const Principal& aPrincipal) override;
1261
1262
  // Notify the ContentChild to enable the input event prioritization when
1263
  // initializing.
1264
  void MaybeEnableRemoteInputEventQueue();
1265
1266
public:
1267
  void SendGetFilesResponseAndForget(const nsID& aID,
1268
                                     const GetFilesResponseResult& aResult);
1269
1270
  bool SendRequestMemoryReport(const uint32_t& aGeneration,
1271
                               const bool& aAnonymize,
1272
                               const bool& aMinimizeMemoryUsage,
1273
                               const MaybeFileDesc& aDMDFile) override;
1274
1275
  bool CanCommunicateWith(ContentParentId aOtherProcess);
1276
1277
  nsresult SaveRecording(nsIFile* aFile, bool* aRetval);
1278
1279
0
  bool IsRecordingOrReplaying() const {
1280
0
    return mRecordReplayState != eNotRecordingOrReplaying;
1281
0
  }
1282
1283
private:
1284
1285
  // If you add strong pointers to cycle collected objects here, be sure to
1286
  // release these objects in ShutDownProcess.  See the comment there for more
1287
  // details.
1288
1289
  ContentProcessHost* mSubprocess;
1290
  const TimeStamp mLaunchTS; // used to calculate time to start content process
1291
  TimeStamp mActivateTS;
1292
  ContentParent* mOpener;
1293
1294
  nsString mRemoteType;
1295
1296
  ContentParentId mChildID;
1297
  int32_t mGeolocationWatchID;
1298
1299
  // This contains the id for the JS plugin (@see nsFakePluginTag) if this is the
1300
  // ContentParent for a process containing iframes for that JS plugin.
1301
  // If this is not a ContentParent for a JS plugin then it contains the value
1302
  // nsFakePluginTag::NOT_JSPLUGIN.
1303
  int32_t mJSPluginID;
1304
1305
  nsCString mKillHardAnnotation;
1306
1307
  // After we initiate shutdown, we also start a timer to ensure
1308
  // that even content processes that are 100% blocked (say from
1309
  // SIGSTOP), are still killed eventually.  This task enforces that
1310
  // timer.
1311
  nsCOMPtr<nsITimer> mForceKillTimer;
1312
  // How many tabs we're waiting to finish their destruction
1313
  // sequence.  Precisely, how many TabParents have called
1314
  // NotifyTabDestroying() but not called NotifyTabDestroyed().
1315
  int32_t mNumDestroyingTabs;
1316
  // True only while this process is in "good health" and may be used for
1317
  // new remote tabs.
1318
  bool mIsAvailable;
1319
  // True only while remote content is being actively used from this process.
1320
  // After mIsAlive goes to false, some previously scheduled IPC traffic may
1321
  // still pass through.
1322
  bool mIsAlive;
1323
1324
  bool mIsForBrowser;
1325
1326
  // Whether this process is recording or replaying its execution, and any
1327
  // associated recording file.
1328
  RecordReplayState mRecordReplayState;
1329
  nsString mRecordingFile;
1330
1331
  // When recording or replaying, the child process is a middleman. This vector
1332
  // stores any replaying children we have spawned on behalf of that middleman,
1333
  // indexed by their record/replay channel ID.
1334
  Vector<mozilla::ipc::GeckoChildProcessHost*> mReplayingChildren;
1335
1336
  // These variables track whether we've called Close() and KillHard() on our
1337
  // channel.
1338
  bool mCalledClose;
1339
  bool mCalledKillHard;
1340
  bool mCreatedPairedMinidumps;
1341
  bool mShutdownPending;
1342
  bool mIPCOpen;
1343
1344
  // True if the input event queue on the main thread of the content process is
1345
  // enabled.
1346
  bool mIsRemoteInputEventQueueEnabled;
1347
1348
  // True if we send input events with input priority. Otherwise, we send input
1349
  // events with normal priority.
1350
  bool mIsInputPriorityEventEnabled;
1351
1352
  RefPtr<nsConsoleService>  mConsoleService;
1353
  nsConsoleService* GetConsoleService();
1354
  nsCOMPtr<nsIContentProcessInfo> mScriptableHelper;
1355
1356
  nsTArray<nsCOMPtr<nsIObserver>> mIdleListeners;
1357
1358
#ifdef MOZ_X11
1359
  // Dup of child's X socket, used to scope its resources to this
1360
  // object instead of the child process's lifetime.
1361
  ScopedClose mChildXSocketFdDup;
1362
#endif
1363
1364
  PProcessHangMonitorParent* mHangMonitorActor;
1365
1366
  UniquePtr<gfx::DriverCrashGuard> mDriverCrashGuard;
1367
  UniquePtr<MemoryReportRequestHost> mMemoryReportRequest;
1368
1369
#if defined(XP_LINUX) && defined(MOZ_CONTENT_SANDBOX)
1370
  mozilla::UniquePtr<SandboxBroker> mSandboxBroker;
1371
  static mozilla::UniquePtr<SandboxBrokerPolicyFactory>
1372
      sSandboxBrokerPolicyFactory;
1373
#endif
1374
1375
#ifdef NS_PRINTING
1376
  RefPtr<embedding::PrintingParent> mPrintingParent;
1377
#endif
1378
1379
  // This hashtable is used to run GetFilesHelper objects in the parent process.
1380
  // GetFilesHelper can be aborted by receiving RecvDeleteGetFilesRequest.
1381
  nsRefPtrHashtable<nsIDHashKey, GetFilesHelper> mGetFilesPendingRequests;
1382
1383
  nsTHashtable<nsCStringHashKey> mActivePermissionKeys;
1384
1385
  nsTArray<nsCString> mBlobURLs;
1386
1387
  UniquePtr<mozilla::ipc::CrashReporterHost> mCrashReporter;
1388
1389
  static uint64_t sNextTabParentId;
1390
  static nsDataHashtable<nsUint64HashKey, TabParent*> sNextTabParents;
1391
};
1392
1393
} // namespace dom
1394
} // namespace mozilla
1395
1396
class ParentIdleListener : public nsIObserver
1397
{
1398
  friend class mozilla::dom::ContentParent;
1399
1400
public:
1401
  NS_DECL_ISUPPORTS
1402
  NS_DECL_NSIOBSERVER
1403
1404
  ParentIdleListener(mozilla::dom::ContentParent* aParent,
1405
                     uint64_t aObserver, uint32_t aTime)
1406
    : mParent(aParent), mObserver(aObserver), mTime(aTime)
1407
0
  {}
1408
1409
private:
1410
0
  virtual ~ParentIdleListener() {}
1411
1412
  RefPtr<mozilla::dom::ContentParent> mParent;
1413
  uint64_t mObserver;
1414
  uint32_t mTime;
1415
};
1416
1417
#endif // mozilla_dom_ContentParent_h