/
ContentParent.h
1527 lines (1177 loc) · 57.8 KB
/
ContentParent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 mozilla_dom_ContentParent_h
#define mozilla_dom_ContentParent_h
#include "mozilla/dom/PContentParent.h"
#include "mozilla/dom/ipc/IdType.h"
#include "mozilla/dom/MediaSessionBinding.h"
#include "mozilla/dom/RemoteBrowser.h"
#include "mozilla/dom/JSProcessActorParent.h"
#include "mozilla/dom/ProcessActor.h"
#include "mozilla/gfx/gfxVarReceiver.h"
#include "mozilla/gfx/GPUProcessListener.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/ipc/PParentToChildStreamParent.h"
#include "mozilla/ipc/PChildToParentStreamParent.h"
#include "mozilla/Attributes.h"
#include "mozilla/DataMutex.h"
#include "mozilla/FileUtils.h"
#include "mozilla/HalTypes.h"
#include "mozilla/LinkedList.h"
#include "mozilla/MemoryReportingProcess.h"
#include "mozilla/MozPromise.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Variant.h"
#include "mozilla/UniquePtr.h"
#include "nsDataHashtable.h"
#include "nsPluginTags.h"
#include "nsFrameMessageManager.h"
#include "nsHashKeys.h"
#include "nsIContentParent.h"
#include "nsIInterfaceRequestor.h"
#include "nsIObserver.h"
#include "nsIRemoteTab.h"
#include "nsIDOMGeoPositionCallback.h"
#include "nsIDOMGeoPositionErrorCallback.h"
#include "nsRefPtrHashtable.h"
#include "PermissionMessageUtils.h"
#include "DriverCrashGuard.h"
#include "nsIReferrerInfo.h"
#define CHILD_PROCESS_SHUTDOWN_MESSAGE \
NS_LITERAL_STRING("child-process-shutdown")
// These must match the similar ones in E10SUtils.jsm and ProcInfo.h.
// Process names as reported by about:memory are defined in
// ContentChild:RecvRemoteType. Add your value there too or it will be called
// "Web Content".
#define DEFAULT_REMOTE_TYPE "web"
#define FISSION_WEB_REMOTE_TYPE "webIsolated"
#define FILE_REMOTE_TYPE "file"
#define EXTENSION_REMOTE_TYPE "extension"
#define PRIVILEGEDABOUT_REMOTE_TYPE "privilegedabout"
#define PRIVILEGEDMOZILLA_REMOTE_TYPE "privilegedmozilla"
#define WITH_COOP_COEP_REMOTE_TYPE_PREFIX "webCOOP+COEP="
// This must start with the DEFAULT_REMOTE_TYPE above.
#define LARGE_ALLOCATION_REMOTE_TYPE "webLargeAllocation"
class nsConsoleService;
class nsIContentProcessInfo;
class nsICycleCollectorLogSink;
class nsIDumpGCAndCCLogsCallback;
class nsIRemoteTab;
class nsITimer;
class ParentIdleListener;
class nsIWidget;
namespace mozilla {
class PRemoteSpellcheckEngineParent;
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
class SandboxBroker;
class SandboxBrokerPolicyFactory;
#endif
class PreallocatedProcessManagerImpl;
class BenchmarkStorageParent;
using mozilla::loader::PScriptCacheParent;
namespace embedding {
class PrintingParent;
}
namespace ipc {
class CrashReporterHost;
class PFileDescriptorSetParent;
class TestShellParent;
#ifdef FUZZING
class ProtocolFuzzerHelper;
#endif
class SharedPreferenceSerializer;
} // namespace ipc
namespace layers {
struct TextureFactoryIdentifier;
} // namespace layers
namespace dom {
class BrowsingContextGroup;
class Element;
class BrowserParent;
class ClonedMessageData;
class MemoryReport;
class TabContext;
class GetFilesHelper;
class MemoryReportRequestHost;
class RemoteWorkerManager;
struct CancelContentJSOptions;
#define NS_CONTENTPARENT_IID \
{ \
0xeeec9ebf, 0x8ecf, 0x4e38, { \
0x81, 0xda, 0xb7, 0x34, 0x13, 0x7e, 0xac, 0xf3 \
} \
}
class ContentParent final
: public PContentParent,
public nsIContentParent,
public nsIObserver,
public nsIDOMGeoPositionCallback,
public nsIDOMGeoPositionErrorCallback,
public nsIInterfaceRequestor,
public gfx::gfxVarReceiver,
public mozilla::LinkedListElement<ContentParent>,
public gfx::GPUProcessListener,
public mozilla::MemoryReportingProcess,
public mozilla::dom::ipc::MessageManagerCallback,
public mozilla::ipc::IShmemAllocator,
public mozilla::ipc::ParentToChildStreamActorManager,
public ProcessActor {
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
typedef mozilla::ipc::PFileDescriptorSetParent PFileDescriptorSetParent;
typedef mozilla::ipc::TestShellParent TestShellParent;
typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
typedef mozilla::dom::BrowsingContextGroup BrowsingContextGroup;
friend class mozilla::PreallocatedProcessManagerImpl;
friend class PContentParent;
friend class mozilla::dom::RemoteWorkerManager;
#ifdef FUZZING
friend class mozilla::ipc::ProtocolFuzzerHelper;
#endif
public:
using LaunchError = mozilla::ipc::LaunchError;
using LaunchPromise =
mozilla::MozPromise<RefPtr<ContentParent>, LaunchError, false>;
NS_DECLARE_STATIC_IID_ACCESSOR(NS_CONTENTPARENT_IID)
/**
* Create a subprocess suitable for use later as a content process.
*/
static RefPtr<LaunchPromise> PreallocateProcess();
/**
* Start up the content-process machinery. This might include
* scheduling pre-launch tasks.
*/
static void StartUp();
/** Shut down the content-process machinery. */
static void ShutDown();
static uint32_t GetPoolSize(const nsAString& aContentProcessType);
static uint32_t GetMaxProcessCount(const nsAString& aContentProcessType);
static bool IsMaxProcessCountReached(const nsAString& aContentProcessType);
static void ReleaseCachedProcesses();
/**
* Picks a random content parent from |aContentParents| with a given |aOpener|
* respecting the index limit set by |aMaxContentParents|.
* Returns null if non available.
*/
static already_AddRefed<ContentParent> MinTabSelect(
const nsTArray<ContentParent*>& aContentParents, ContentParent* aOpener,
int32_t maxContentParents);
/**
* Get or create a content process for:
* 1. browser iframe
* 2. remote xul <browser>
* 3. normal iframe
*/
static RefPtr<ContentParent::LaunchPromise> GetNewOrUsedBrowserProcessAsync(
Element* aFrameElement, const nsAString& aRemoteType,
hal::ProcessPriority aPriority =
hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
ContentParent* aOpener = nullptr, bool aPreferUsed = false);
static already_AddRefed<ContentParent> GetNewOrUsedBrowserProcess(
Element* aFrameElement, const nsAString& aRemoteType,
hal::ProcessPriority aPriority =
hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
ContentParent* aOpener = nullptr, bool aPreferUsed = false);
/**
* Get or create a content process for a JS plugin. aPluginID is the id of the
* JS plugin
* (@see nsFakePlugin::mId). There is a maximum of one process per JS plugin.
*/
static already_AddRefed<ContentParent> GetNewOrUsedJSPluginProcess(
uint32_t aPluginID, const hal::ProcessPriority& aPriority);
/**
* Get or create a content process for the given TabContext. aFrameElement
* should be the frame/iframe element with which this process will
* associated.
*/
static already_AddRefed<RemoteBrowser> CreateBrowser(
const TabContext& aContext, Element* aFrameElement,
const nsAString& aRemoteType, BrowsingContext* aBrowsingContext,
ContentParent* aOpenerContentParent);
static void GetAll(nsTArray<ContentParent*>& aArray);
static void GetAllEvenIfDead(nsTArray<ContentParent*>& aArray);
static void BroadcastStringBundle(const StringBundleDescriptor&);
static void BroadcastFontListChanged();
const nsAString& GetRemoteType() const override;
virtual void DoGetRemoteType(nsAString& aRemoteType,
ErrorResult& aError) const override {
aRemoteType = GetRemoteType();
}
enum CPIteratorPolicy { eLive, eAll };
class ContentParentIterator {
private:
ContentParent* mCurrent;
CPIteratorPolicy mPolicy;
public:
ContentParentIterator(CPIteratorPolicy aPolicy, ContentParent* aCurrent)
: mCurrent(aCurrent), mPolicy(aPolicy) {}
ContentParentIterator begin() {
// Move the cursor to the first element that matches the policy.
while (mPolicy != eAll && mCurrent && !mCurrent->IsAlive()) {
mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
}
return *this;
}
ContentParentIterator end() {
return ContentParentIterator(mPolicy, nullptr);
}
const ContentParentIterator& operator++() {
MOZ_ASSERT(mCurrent);
do {
mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
} while (mPolicy != eAll && mCurrent && !mCurrent->IsAlive());
return *this;
}
bool operator!=(const ContentParentIterator& aOther) {
MOZ_ASSERT(mPolicy == aOther.mPolicy);
return mCurrent != aOther.mCurrent;
}
ContentParent* operator*() { return mCurrent; }
};
static ContentParentIterator AllProcesses(CPIteratorPolicy aPolicy) {
ContentParent* first =
sContentParents ? sContentParents->getFirst() : nullptr;
return ContentParentIterator(aPolicy, first);
}
static bool IgnoreIPCPrincipal();
static void NotifyUpdatedDictionaries();
static void NotifyUpdatedFonts();
static void NotifyRebuildFontList();
#if defined(XP_WIN)
/**
* Windows helper for firing off an update window request to a plugin
* instance.
*
* aWidget - the eWindowType_plugin_ipc_chrome widget associated with
* this plugin window.
*/
static void SendAsyncUpdate(nsIWidget* aWidget);
#endif
// Let managees query if it is safe to send messages.
bool IsDestroyed() const { return !mIPCOpen; }
mozilla::ipc::IPCResult RecvCreateGMPService();
mozilla::ipc::IPCResult RecvLoadPlugin(
const uint32_t& aPluginId, nsresult* aRv, uint32_t* aRunID,
Endpoint<PPluginModuleParent>* aEndpoint);
mozilla::ipc::IPCResult RecvMaybeReloadPlugins();
mozilla::ipc::IPCResult RecvConnectPluginBridge(
const uint32_t& aPluginId, nsresult* aRv,
Endpoint<PPluginModuleParent>* aEndpoint);
mozilla::ipc::IPCResult RecvLaunchRDDProcess(
nsresult* aRv, Endpoint<PRemoteDecoderManagerChild>* aEndpoint);
mozilla::ipc::IPCResult RecvUngrabPointer(const uint32_t& aTime);
mozilla::ipc::IPCResult RecvRemovePermission(const IPC::Principal& aPrincipal,
const nsCString& aPermissionType,
nsresult* aRv);
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ContentParent, nsIObserver)
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSICONTENTPARENT
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMGEOPOSITIONCALLBACK
NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK
NS_DECL_NSIINTERFACEREQUESTOR
/**
* MessageManagerCallback methods that we override.
*/
virtual bool DoLoadMessageManagerScript(const nsAString& aURL,
bool aRunInGlobalScope) override;
virtual nsresult DoSendAsyncMessage(const nsAString& aMessage,
StructuredCloneData& aData) override;
/** Notify that a tab is beginning its destruction sequence. */
void NotifyTabDestroying();
/** Notify that a tab was destroyed during normal operation. */
void NotifyTabDestroyed(const TabId& aTabId, bool aNotifiedDestroying);
TestShellParent* CreateTestShell();
bool DestroyTestShell(TestShellParent* aTestShell);
TestShellParent* GetTestShellSingleton();
// This method can be called on any thread.
void RegisterRemoteWorkerActor();
// This method _must_ be called on main-thread because it can start the
// shutting down of the content process.
void UnregisterRemoveWorkerActor();
void ReportChildAlreadyBlocked();
bool RequestRunToCompletion();
void UpdateCookieStatus(nsIChannel* aChannel);
bool IsLaunching() const {
return mLifecycleState == LifecycleState::LAUNCHING;
}
bool IsAlive() const override;
bool IsDead() const { return mLifecycleState == LifecycleState::DEAD; }
bool IsForBrowser() const { return mIsForBrowser; }
bool IsForJSPlugin() const {
return mJSPluginID != nsFakePluginTag::NOT_JSPLUGIN;
}
GeckoChildProcessHost* Process() const { return mSubprocess; }
ContentParent* Opener() const { return mOpener; }
nsIContentProcessInfo* ScriptableHelper() const { return mScriptableHelper; }
mozilla::dom::ProcessMessageManager* GetMessageManager() const {
return mMessageManager;
}
bool NeedsPermissionsUpdate(const nsACString& aPermissionKey) const;
/**
* Kill our subprocess and make sure it dies. Should only be used
* in emergency situations since it bypasses the normal shutdown
* process.
*
* WARNING: aReason appears in telemetry, so any new value passed in requires
* data review.
*/
void KillHard(const char* aWhy);
ContentParentId ChildID() const { return mChildID; }
/**
* Get a user-friendly name for this ContentParent. We make no guarantees
* about this name: It might not be unique, apps can spoof special names,
* etc. So please don't use this name to make any decisions about the
* ContentParent based on the value returned here.
*/
void FriendlyName(nsAString& aName, bool aAnonymize = false);
virtual void OnChannelError() override;
mozilla::ipc::IPCResult RecvInitCrashReporter(
const NativeThreadId& aThreadId);
PNeckoParent* AllocPNeckoParent();
virtual mozilla::ipc::IPCResult RecvPNeckoConstructor(
PNeckoParent* aActor) override {
return PContentParent::RecvPNeckoConstructor(aActor);
}
PPrintingParent* AllocPPrintingParent();
bool DeallocPPrintingParent(PPrintingParent* aActor);
#if defined(NS_PRINTING)
/**
* @return the PrintingParent for this ContentParent.
*/
already_AddRefed<embedding::PrintingParent> GetPrintingParent();
#endif
mozilla::ipc::IPCResult RecvInitStreamFilter(
const uint64_t& aChannelId, const nsString& aAddonId,
InitStreamFilterResolver&& aResolver);
PChildToParentStreamParent* AllocPChildToParentStreamParent();
bool DeallocPChildToParentStreamParent(PChildToParentStreamParent* aActor);
PParentToChildStreamParent* AllocPParentToChildStreamParent();
bool DeallocPParentToChildStreamParent(PParentToChildStreamParent* aActor);
PHalParent* AllocPHalParent();
virtual mozilla::ipc::IPCResult RecvPHalConstructor(
PHalParent* aActor) override {
return PContentParent::RecvPHalConstructor(aActor);
}
PHeapSnapshotTempFileHelperParent* AllocPHeapSnapshotTempFileHelperParent();
PRemoteSpellcheckEngineParent* AllocPRemoteSpellcheckEngineParent();
mozilla::ipc::IPCResult RecvRecordingDeviceEvents(
const nsString& aRecordingStatus, const nsString& aPageURL,
const bool& aIsAudio, const bool& aIsVideo);
bool CycleCollectWithLogs(bool aDumpAllTraces,
nsICycleCollectorLogSink* aSink,
nsIDumpGCAndCCLogsCallback* aCallback);
mozilla::ipc::IPCResult RecvNotifyTabDestroying(const TabId& aTabId,
const ContentParentId& aCpId);
already_AddRefed<POfflineCacheUpdateParent> AllocPOfflineCacheUpdateParent(
nsIURI* aManifestURI, nsIURI* aDocumentURI,
const PrincipalInfo& aLoadingPrincipalInfo, const bool& aStickDocument,
const CookieJarSettingsArgs& aCookieJarSettingsArgs);
virtual mozilla::ipc::IPCResult RecvPOfflineCacheUpdateConstructor(
POfflineCacheUpdateParent* aActor, nsIURI* aManifestURI,
nsIURI* aDocumentURI, const PrincipalInfo& aLoadingPrincipal,
const bool& stickDocument,
const CookieJarSettingsArgs& aCookieJarSettingsArgs) override;
mozilla::ipc::IPCResult RecvSetOfflinePermission(
const IPC::Principal& principal);
mozilla::ipc::IPCResult RecvFinishShutdown();
void MaybeInvokeDragSession(BrowserParent* aParent);
PContentPermissionRequestParent* AllocPContentPermissionRequestParent(
const nsTArray<PermissionRequest>& aRequests,
const IPC::Principal& aPrincipal,
const IPC::Principal& aTopLevelPrincipal,
const bool& aIsHandlingUserInput,
const bool& aMaybeUnsafePermissionDelegate, const TabId& aTabId);
bool DeallocPContentPermissionRequestParent(
PContentPermissionRequestParent* actor);
virtual bool HandleWindowsMessages(const Message& aMsg) const override;
void ForkNewProcess(bool aBlocking);
mozilla::ipc::IPCResult RecvCreateWindow(
PBrowserParent* aThisBrowserParent,
const MaybeDiscarded<BrowsingContext>& aParent, PBrowserParent* aNewTab,
const uint32_t& aChromeFlags, const bool& aCalledFromJS,
const bool& aWidthSpecified, nsIURI* aURIToLoad,
const nsCString& aFeatures, const float& aFullZoom,
const IPC::Principal& aTriggeringPrincipal,
nsIContentSecurityPolicy* aCsp, nsIReferrerInfo* aReferrerInfo,
const OriginAttributes& aOriginAttributes,
CreateWindowResolver&& aResolve);
mozilla::ipc::IPCResult RecvCreateWindowInDifferentProcess(
PBrowserParent* aThisTab, const MaybeDiscarded<BrowsingContext>& aParent,
const uint32_t& aChromeFlags, const bool& aCalledFromJS,
const bool& aWidthSpecified, nsIURI* aURIToLoad,
const nsCString& aFeatures, const float& aFullZoom, const nsString& aName,
nsIPrincipal* aTriggeringPrincipal, nsIContentSecurityPolicy* aCsp,
nsIReferrerInfo* aReferrerInfo,
const OriginAttributes& aOriginAttributes);
static void BroadcastBlobURLRegistration(
const nsACString& aURI, BlobImpl* aBlobImpl, nsIPrincipal* aPrincipal,
ContentParent* aIgnoreThisCP = nullptr);
static void BroadcastBlobURLUnregistration(
const nsACString& aURI, nsIPrincipal* aPrincipal,
ContentParent* aIgnoreThisCP = nullptr);
mozilla::ipc::IPCResult RecvStoreAndBroadcastBlobURLRegistration(
const nsCString& aURI, const IPCBlob& aBlob, const Principal& aPrincipal);
mozilla::ipc::IPCResult RecvUnstoreAndBroadcastBlobURLUnregistration(
const nsCString& aURI, const Principal& aPrincipal);
mozilla::ipc::IPCResult RecvGetA11yContentId(uint32_t* aContentId);
mozilla::ipc::IPCResult RecvA11yHandlerControl(
const uint32_t& aPid, const IHandlerControlHolder& aHandlerControl);
virtual int32_t Pid() const override;
// PURLClassifierParent.
PURLClassifierParent* AllocPURLClassifierParent(const Principal& aPrincipal,
bool* aSuccess);
virtual mozilla::ipc::IPCResult RecvPURLClassifierConstructor(
PURLClassifierParent* aActor, const Principal& aPrincipal,
bool* aSuccess) override;
// PURLClassifierLocalParent.
PURLClassifierLocalParent* AllocPURLClassifierLocalParent(
nsIURI* aURI, const nsTArray<IPCURLClassifierFeature>& aFeatures);
virtual mozilla::ipc::IPCResult RecvPURLClassifierLocalConstructor(
PURLClassifierLocalParent* aActor, nsIURI* aURI,
nsTArray<IPCURLClassifierFeature>&& aFeatures) override;
PLoginReputationParent* AllocPLoginReputationParent(nsIURI* aURI);
virtual mozilla::ipc::IPCResult RecvPLoginReputationConstructor(
PLoginReputationParent* aActor, nsIURI* aURI) override;
bool DeallocPLoginReputationParent(PLoginReputationParent* aActor);
PSessionStorageObserverParent* AllocPSessionStorageObserverParent();
virtual mozilla::ipc::IPCResult RecvPSessionStorageObserverConstructor(
PSessionStorageObserverParent* aActor) override;
bool DeallocPSessionStorageObserverParent(
PSessionStorageObserverParent* aActor);
bool DeallocPURLClassifierLocalParent(PURLClassifierLocalParent* aActor);
bool DeallocPURLClassifierParent(PURLClassifierParent* aActor);
// Use the PHangMonitor channel to ask the child to repaint a tab.
void PaintTabWhileInterruptingJS(BrowserParent* aBrowserParent,
const layers::LayersObserverEpoch& aEpoch);
void CancelContentJSExecutionIfRunning(
BrowserParent* aBrowserParent,
nsIRemoteTab::NavigationType aNavigationType,
const CancelContentJSOptions& aCancelContentJSOptions);
// This function is called when we are about to load a document from an
// HTTP(S) or FTP channel for a content process. It is a useful place
// to start to kick off work as early as possible in response to such
// document loads.
nsresult AboutToLoadHttpFtpDocumentForChild(nsIChannel* aChannel);
// Send Blob URLs for this aPrincipal if they are not already known to this
// content process and mark the process to receive any new/revoked Blob URLs
// to this content process forever.
void TransmitBlobURLsForPrincipal(nsIPrincipal* aPrincipal);
nsresult TransmitPermissionsForPrincipal(nsIPrincipal* aPrincipal);
// This function is called in BrowsingContext immediately before IPC call to
// load a URI. If aURI is a BlobURL, this method transmits all BlobURLs for
// aPrincipal that were previously not transmitted. This allows for opening a
// locally created BlobURL in a new tab.
//
// The reason all previously untransmitted Blobs are transmitted is that the
// current BlobURL could contain html code, referring to another untransmitted
// BlobURL.
//
// Should eventually be made obsolete by broader design changes that only
// store BlobURLs in the parent process.
void TransmitBlobDataIfBlobURL(nsIURI* aURI, nsIPrincipal* aPrincipal);
void OnCompositorDeviceReset() override;
static hal::ProcessPriority GetInitialProcessPriority(Element* aFrameElement);
// Control the priority of the IPC messages for input events.
void SetInputPriorityEventEnabled(bool aEnabled);
bool IsInputPriorityEventEnabled() { return mIsInputPriorityEventEnabled; }
static bool IsInputEventQueueSupported();
mozilla::ipc::IPCResult RecvCreateBrowsingContext(
uint64_t aGroupId, BrowsingContext::IPCInitializer&& aInit);
mozilla::ipc::IPCResult RecvDiscardBrowsingContext(
const MaybeDiscarded<BrowsingContext>& aContext,
DiscardBrowsingContextResolver&& aResolve);
mozilla::ipc::IPCResult RecvWindowClose(
const MaybeDiscarded<BrowsingContext>& aContext, bool aTrustedCaller);
mozilla::ipc::IPCResult RecvWindowFocus(
const MaybeDiscarded<BrowsingContext>& aContext, CallerType aCallerType);
mozilla::ipc::IPCResult RecvWindowBlur(
const MaybeDiscarded<BrowsingContext>& aContext);
mozilla::ipc::IPCResult RecvRaiseWindow(
const MaybeDiscarded<BrowsingContext>& aContext, CallerType aCallerType);
mozilla::ipc::IPCResult RecvAdjustWindowFocus(
const MaybeDiscarded<BrowsingContext>& aContext, bool aCheckPermission,
bool aIsVisible);
mozilla::ipc::IPCResult RecvClearFocus(
const MaybeDiscarded<BrowsingContext>& aContext);
mozilla::ipc::IPCResult RecvSetFocusedBrowsingContext(
const MaybeDiscarded<BrowsingContext>& aContext);
mozilla::ipc::IPCResult RecvSetActiveBrowsingContext(
const MaybeDiscarded<BrowsingContext>& aContext);
mozilla::ipc::IPCResult RecvUnsetActiveBrowsingContext(
const MaybeDiscarded<BrowsingContext>& aContext);
mozilla::ipc::IPCResult RecvSetFocusedElement(
const MaybeDiscarded<BrowsingContext>& aContext, bool aNeedsFocus);
mozilla::ipc::IPCResult RecvBlurToParent(
const MaybeDiscarded<BrowsingContext>& aFocusedBrowsingContext,
const MaybeDiscarded<BrowsingContext>& aBrowsingContextToClear,
const MaybeDiscarded<BrowsingContext>& aAncestorBrowsingContextToFocus,
bool aIsLeavingDocument, bool aAdjustWidget,
bool aBrowsingContextToClearHandled,
bool aAncestorBrowsingContextToFocusHandled);
mozilla::ipc::IPCResult RecvMaybeExitFullscreen(
const MaybeDiscarded<BrowsingContext>& aContext);
mozilla::ipc::IPCResult RecvWindowPostMessage(
const MaybeDiscarded<BrowsingContext>& aContext,
const ClonedOrErrorMessageData& aMessage, const PostMessageData& aData);
FORWARD_SHMEM_ALLOCATOR_TO(PContentParent)
PParentToChildStreamParent* SendPParentToChildStreamConstructor(
PParentToChildStreamParent* aActor) override;
PFileDescriptorSetParent* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) override;
protected:
bool CheckBrowsingContextEmbedder(CanonicalBrowsingContext* aBC,
const char* aOperation) const;
void OnChannelConnected(int32_t pid) override;
void ActorDestroy(ActorDestroyReason why) override;
void ActorDealloc() override;
bool ShouldContinueFromReplyTimeout() override;
void OnVarChanged(const GfxVarUpdate& aVar) override;
void OnCompositorUnexpectedShutdown() override;
private:
/**
* A map of the remote content process type to a list of content parents
* currently available to host *new* tabs/frames of that type.
*
* If a content process is identified as troubled or dead, it will be
* removed from this list, but will still be in the sContentParents list for
* the GetAll/GetAllEvenIfDead APIs.
*/
static nsClassHashtable<nsStringHashKey, nsTArray<ContentParent*>>*
sBrowserContentParents;
static nsTArray<ContentParent*>* sPrivateContent;
static nsDataHashtable<nsUint32HashKey, ContentParent*>*
sJSPluginContentParents;
static StaticAutoPtr<LinkedList<ContentParent>> sContentParents;
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
// Cached Mac sandbox params used when launching content processes.
static StaticAutoPtr<std::vector<std::string>> sMacSandboxParams;
#endif
// Set aLoadUri to true to load aURIToLoad and to false to only create the
// window. aURIToLoad should always be provided, if available, to ensure
// compatibility with GeckoView.
mozilla::ipc::IPCResult CommonCreateWindow(
PBrowserParent* aThisTab, BrowsingContext* aParent, bool aSetOpener,
const uint32_t& aChromeFlags, const bool& aCalledFromJS,
const bool& aWidthSpecified, nsIURI* aURIToLoad,
const nsCString& aFeatures, const float& aFullZoom,
BrowserParent* aNextRemoteBrowser, const nsString& aName,
nsresult& aResult, nsCOMPtr<nsIRemoteTab>& aNewRemoteTab,
bool* aWindowIsNew, int32_t& aOpenLocation,
nsIPrincipal* aTriggeringPrincipal, nsIReferrerInfo* aReferrerInfo,
bool aLoadUri, nsIContentSecurityPolicy* aCsp,
const OriginAttributes& aOriginAttributes);
explicit ContentParent(int32_t aPluginID)
: ContentParent(nullptr, EmptyString(), aPluginID) {}
ContentParent(ContentParent* aOpener, const nsAString& aRemoteType)
: ContentParent(aOpener, aRemoteType, nsFakePluginTag::NOT_JSPLUGIN) {}
ContentParent(ContentParent* aOpener, const nsAString& aRemoteType,
int32_t aPluginID);
// Launch the subprocess and associated initialization.
// Returns false if the process fails to start.
// Deprecated in favor of LaunchSubprocessAsync.
bool LaunchSubprocessSync(hal::ProcessPriority aInitialPriority);
// Launch the subprocess and associated initialization;
// returns a promise and signals failure by rejecting.
// OS-level launching work is dispatched to another thread, but some
// initialization (creating IPDL actors, etc.; see Init()) is run on
// the main thread.
RefPtr<LaunchPromise> LaunchSubprocessAsync(
hal::ProcessPriority aInitialPriority);
// Common implementation of LaunchSubprocess{Sync,Async}.
// Return `true` in case of success, `false` if launch was
// aborted because of shutdown.
bool BeginSubprocessLaunch(bool aIsSync, ProcessPriority aPriority);
void LaunchSubprocessReject();
bool LaunchSubprocessResolve(bool aIsSync, ProcessPriority aPriority);
// Return `nullptr` in case of error.
// Return a `ContentParent` in case of success. This `ContentParent`
// may either be ready and initialized or in the process of initializing
// asynchronously. In the latter case, the caller is responsible for
// finishing initialization.
static already_AddRefed<ContentParent> GetNewOrUsedBrowserProcessInternal(
Element* aFrameElement, const nsAString& aRemoteType,
ProcessPriority aPriority, ContentParent* aOpener, bool aPreferUsed,
bool aIsSync);
// Common initialization after sub process launch.
bool InitInternal(ProcessPriority aPriority);
// Generate a minidump for the child process and one for the main process
void GeneratePairedMinidump(const char* aReason);
void HandleOrphanedMinidump(nsString* aDumpId);
virtual ~ContentParent();
void Init();
// Some information could be sent to content very early, it
// should be send from this function. This function should only be
// called after the process has been transformed to browser.
void ForwardKnownInfo();
/**
* We might want to reuse barely used content processes if certain criteria
* are met.
*/
bool TryToRecycle();
/**
* Removing it from the static array so it won't be returned for new tabs in
* GetNewOrUsedBrowserProcess.
*/
void RemoveFromList();
/**
* Decide whether the process should be kept alive even when it would normally
* be shut down, for example when all its tabs are closed.
*/
bool ShouldKeepProcessAlive();
/**
* Mark this ContentParent as "troubled". This means that it is still alive,
* but it won't be returned for new tabs in GetNewOrUsedBrowserProcess.
*/
void MarkAsTroubled();
/**
* Mark this ContentParent as dead for the purposes of Get*().
* This method is idempotent.
*/
void MarkAsDead();
/**
* How we will shut down this ContentParent and its subprocess.
*/
enum ShutDownMethod {
// Send a shutdown message and wait for FinishShutdown call back.
SEND_SHUTDOWN_MESSAGE,
// Close the channel ourselves and let the subprocess clean up itself.
CLOSE_CHANNEL,
// Close the channel with error and let the subprocess clean up itself.
CLOSE_CHANNEL_WITH_ERROR,
};
void MaybeAsyncSendShutDownMessage();
/**
* Exit the subprocess and vamoose. After this call IsAlive()
* will return false and this ContentParent will not be returned
* by the Get*() funtions. However, the shutdown sequence itself
* may be asynchronous.
*
* If aMethod is CLOSE_CHANNEL_WITH_ERROR and this is the first call
* to ShutDownProcess, then we'll close our channel using CloseWithError()
* rather than vanilla Close(). CloseWithError() indicates to IPC that this
* is an abnormal shutdown (e.g. a crash).
*/
void ShutDownProcess(ShutDownMethod aMethod);
// Perform any steps necesssary to gracefully shtudown the message
// manager and null out mMessageManager.
void ShutDownMessageManager();
// Start the force-kill timer on shutdown.
void StartForceKillTimer();
// Ensure that the permissions for the giben Permission key are set in the
// content process.
//
// See nsIPermissionManager::GetPermissionsForKey for more information on
// these keys.
void EnsurePermissionsByKey(const nsCString& aKey, const nsCString& aOrigin);
static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure);
bool CanOpenBrowser(const IPCTabContext& aContext);
/**
* Get or create the corresponding content parent array to
* |aContentProcessType|.
*/
static nsTArray<ContentParent*>& GetOrCreatePool(
const nsAString& aContentProcessType);
mozilla::ipc::IPCResult RecvInitBackground(
Endpoint<mozilla::ipc::PBackgroundParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport);
mozilla::ipc::IPCResult RecvFinishMemoryReport(const uint32_t& aGeneration);
mozilla::ipc::IPCResult RecvAddPerformanceMetrics(
const nsID& aID, nsTArray<PerformanceInfo>&& aMetrics);
bool DeallocPRemoteSpellcheckEngineParent(PRemoteSpellcheckEngineParent*);
mozilla::ipc::IPCResult RecvConstructPopupBrowser(
ManagedEndpoint<PBrowserParent>&& actor,
ManagedEndpoint<PWindowGlobalParent>&& windowEp, const TabId& tabId,
const IPCTabContext& context, const WindowGlobalInit& initialWindowInit,
const uint32_t& chromeFlags);
mozilla::ipc::IPCResult RecvIsSecureURI(
const uint32_t& aType, nsIURI* aURI, const uint32_t& aFlags,
const OriginAttributes& aOriginAttributes, bool* aIsSecureURI);
mozilla::ipc::IPCResult RecvAccumulateMixedContentHSTS(
nsIURI* aURI, const bool& aActive,
const OriginAttributes& aOriginAttributes);
bool DeallocPHalParent(PHalParent*);
bool DeallocPHeapSnapshotTempFileHelperParent(
PHeapSnapshotTempFileHelperParent*);
PCycleCollectWithLogsParent* AllocPCycleCollectWithLogsParent(
const bool& aDumpAllTraces, const FileDescriptor& aGCLog,
const FileDescriptor& aCCLog);
bool DeallocPCycleCollectWithLogsParent(PCycleCollectWithLogsParent* aActor);
PTestShellParent* AllocPTestShellParent();
bool DeallocPTestShellParent(PTestShellParent* shell);
PScriptCacheParent* AllocPScriptCacheParent(const FileDescOrError& cacheFile,
const bool& wantCacheData);
bool DeallocPScriptCacheParent(PScriptCacheParent* shell);
bool DeallocPNeckoParent(PNeckoParent* necko);
already_AddRefed<PExternalHelperAppParent> AllocPExternalHelperAppParent(
nsIURI* aUri, const Maybe<mozilla::net::LoadInfoArgs>& aLoadInfoArgs,
const nsCString& aMimeContentType, const nsCString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsString& aContentDispositionFilename, const bool& aForceSave,
const int64_t& aContentLength, const bool& aWasFileChannel,
nsIURI* aReferrer, const MaybeDiscarded<BrowsingContext>& aContext,
const bool& aShouldCloseWindow);
mozilla::ipc::IPCResult RecvPExternalHelperAppConstructor(
PExternalHelperAppParent* actor, nsIURI* uri,
const Maybe<LoadInfoArgs>& loadInfoArgs,
const nsCString& aMimeContentType, const nsCString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsString& aContentDispositionFilename, const bool& aForceSave,
const int64_t& aContentLength, const bool& aWasFileChannel,
nsIURI* aReferrer, const MaybeDiscarded<BrowsingContext>& aContext,
const bool& aShouldCloseWindow) override;
already_AddRefed<PHandlerServiceParent> AllocPHandlerServiceParent();
PMediaParent* AllocPMediaParent();
bool DeallocPMediaParent(PMediaParent* aActor);
PBenchmarkStorageParent* AllocPBenchmarkStorageParent();
bool DeallocPBenchmarkStorageParent(PBenchmarkStorageParent* aActor);
PPresentationParent* AllocPPresentationParent();
bool DeallocPPresentationParent(PPresentationParent* aActor);
virtual mozilla::ipc::IPCResult RecvPPresentationConstructor(
PPresentationParent* aActor) override;
#ifdef MOZ_WEBSPEECH
PSpeechSynthesisParent* AllocPSpeechSynthesisParent();
bool DeallocPSpeechSynthesisParent(PSpeechSynthesisParent* aActor);
virtual mozilla::ipc::IPCResult RecvPSpeechSynthesisConstructor(
PSpeechSynthesisParent* aActor) override;
#endif
PWebBrowserPersistDocumentParent* AllocPWebBrowserPersistDocumentParent(
PBrowserParent* aBrowser,
const MaybeDiscarded<BrowsingContext>& aContext);
bool DeallocPWebBrowserPersistDocumentParent(
PWebBrowserPersistDocumentParent* aActor);
mozilla::ipc::IPCResult RecvGetGfxVars(nsTArray<GfxVarUpdate>* aVars);
mozilla::ipc::IPCResult RecvSetClipboard(
const IPCDataTransfer& aDataTransfer, const bool& aIsPrivateData,
const IPC::Principal& aRequestingPrincipal,
const uint32_t& aContentPolicyType, const int32_t& aWhichClipboard);
mozilla::ipc::IPCResult RecvGetClipboard(nsTArray<nsCString>&& aTypes,
const int32_t& aWhichClipboard,
IPCDataTransfer* aDataTransfer);
mozilla::ipc::IPCResult RecvEmptyClipboard(const int32_t& aWhichClipboard);
mozilla::ipc::IPCResult RecvClipboardHasType(nsTArray<nsCString>&& aTypes,
const int32_t& aWhichClipboard,
bool* aHasType);
mozilla::ipc::IPCResult RecvGetExternalClipboardFormats(
const int32_t& aWhichClipboard, const bool& aPlainTextOnly,
nsTArray<nsCString>* aTypes);
mozilla::ipc::IPCResult RecvPlaySound(nsIURI* aURI);
mozilla::ipc::IPCResult RecvBeep();
mozilla::ipc::IPCResult RecvPlayEventSound(const uint32_t& aEventId);
mozilla::ipc::IPCResult RecvGetIconForExtension(const nsCString& aFileExt,
const uint32_t& aIconSize,
nsTArray<uint8_t>* bits);
mozilla::ipc::IPCResult RecvStartVisitedQueries(
const nsTArray<RefPtr<nsIURI>>&);
mozilla::ipc::IPCResult RecvSetURITitle(nsIURI* uri, const nsString& title);
bool HasNotificationPermission(const IPC::Principal& aPrincipal);
mozilla::ipc::IPCResult RecvShowAlert(nsIAlertNotification* aAlert);
mozilla::ipc::IPCResult RecvCloseAlert(const nsString& aName,
const IPC::Principal& aPrincipal);
mozilla::ipc::IPCResult RecvDisableNotifications(
const IPC::Principal& aPrincipal);
mozilla::ipc::IPCResult RecvOpenNotificationSettings(