Skip to content

Commit 258ad59

Browse files
committed
Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj
1 parent 6ee48e8 commit 258ad59

File tree

202 files changed

+509
-582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+509
-582
lines changed

accessible/base/nsAccessibilityService.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ nsAccessibilityService::Init()
12651265
logging::CheckEnv();
12661266
#endif
12671267

1268-
if (XRE_GetProcessType() == GeckoProcessType_Default)
1268+
if (XRE_IsParentProcess())
12691269
gApplicationAccessible = new ApplicationAccessibleWrap();
12701270
else
12711271
gApplicationAccessible = new ApplicationAccessible();
@@ -1286,7 +1286,7 @@ nsAccessibilityService::Init()
12861286
gIsShutdown = false;
12871287

12881288
// Now its safe to start platform accessibility.
1289-
if (XRE_GetProcessType() == GeckoProcessType_Default)
1289+
if (XRE_IsParentProcess())
12901290
PlatformInit();
12911291

12921292
return true;
@@ -1329,7 +1329,7 @@ nsAccessibilityService::Shutdown()
13291329

13301330
gIsShutdown = true;
13311331

1332-
if (XRE_GetProcessType() == GeckoProcessType_Default)
1332+
if (XRE_IsParentProcess())
13331333
PlatformShutdown();
13341334

13351335
gApplicationAccessible->Shutdown();

accessible/base/nsAccessibilityService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ IPCAccessibilityActive()
282282
#ifdef MOZ_B2G
283283
return false;
284284
#else
285-
return XRE_GetProcessType() == GeckoProcessType_Content &&
285+
return XRE_IsContentProcess() &&
286286
mozilla::Preferences::GetBool("accessibility.ipc_architecture.enabled", true);
287287
#endif
288288
}

accessible/base/nsCoreUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ nsCoreUtils::IsTabDocument(nsIDocument* aDocumentNode)
425425
treeItem->GetParent(getter_AddRefs(parentTreeItem));
426426

427427
// Tab document running in own process doesn't have parent.
428-
if (XRE_GetProcessType() == GeckoProcessType_Content)
428+
if (XRE_IsContentProcess())
429429
return !parentTreeItem;
430430

431431
// Parent of docshell for tab document running in chrome process is root.

accessible/windows/msaa/nsWinUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ nsWinUtils::MaybeStartWindowEmulation()
6464

6565
if (Compatibility::IsJAWS() || Compatibility::IsWE() ||
6666
Compatibility::IsDolphin() ||
67-
XRE_GetProcessType() == GeckoProcessType_Content) {
67+
XRE_IsContentProcess()) {
6868
RegisterNativeWindow(kClassNameTabContent);
6969
sHWNDCache = new nsRefPtrHashtable<nsPtrHashKey<void>, DocAccessible>(2);
7070
return true;

caps/DomainPolicy.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static nsresult
2222
BroadcastDomainSetChange(DomainSetType aSetType, DomainSetChangeType aChangeType,
2323
nsIURI* aDomain = nullptr)
2424
{
25-
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default,
25+
MOZ_ASSERT(XRE_IsParentProcess(),
2626
"DomainPolicy should only be exposed to the chrome process.");
2727

2828
nsTArray<ContentParent*> parents;
@@ -45,7 +45,7 @@ DomainPolicy::DomainPolicy() : mBlacklist(new DomainSet(BLACKLIST))
4545
, mWhitelist(new DomainSet(WHITELIST))
4646
, mSuperWhitelist(new DomainSet(SUPER_WHITELIST))
4747
{
48-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
48+
if (XRE_IsParentProcess()) {
4949
BroadcastDomainSetChange(NO_TYPE, ACTIVATE_POLICY);
5050
}
5151
}
@@ -112,7 +112,7 @@ DomainPolicy::Deactivate()
112112
if (ssm) {
113113
ssm->DeactivateDomainPolicy();
114114
}
115-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
115+
if (XRE_IsParentProcess()) {
116116
BroadcastDomainSetChange(NO_TYPE, DEACTIVATE_POLICY);
117117
}
118118
return NS_OK;
@@ -170,7 +170,7 @@ DomainSet::Add(nsIURI* aDomain)
170170
nsCOMPtr<nsIURI> clone = GetCanonicalClone(aDomain);
171171
NS_ENSURE_TRUE(clone, NS_ERROR_FAILURE);
172172
mHashTable.PutEntry(clone);
173-
if (XRE_GetProcessType() == GeckoProcessType_Default)
173+
if (XRE_IsParentProcess())
174174
return BroadcastDomainSetChange(mType, ADD_DOMAIN, aDomain);
175175

176176
return NS_OK;
@@ -182,7 +182,7 @@ DomainSet::Remove(nsIURI* aDomain)
182182
nsCOMPtr<nsIURI> clone = GetCanonicalClone(aDomain);
183183
NS_ENSURE_TRUE(clone, NS_ERROR_FAILURE);
184184
mHashTable.RemoveEntry(clone);
185-
if (XRE_GetProcessType() == GeckoProcessType_Default)
185+
if (XRE_IsParentProcess())
186186
return BroadcastDomainSetChange(mType, REMOVE_DOMAIN, aDomain);
187187

188188
return NS_OK;
@@ -192,7 +192,7 @@ NS_IMETHODIMP
192192
DomainSet::Clear()
193193
{
194194
mHashTable.Clear();
195-
if (XRE_GetProcessType() == GeckoProcessType_Default)
195+
if (XRE_IsParentProcess())
196196
return BroadcastDomainSetChange(mType, CLEAR_DOMAINS);
197197

198198
return NS_OK;

caps/nsScriptSecurityManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ nsScriptSecurityManager::~nsScriptSecurityManager(void)
12831283
// ContentChild might hold a reference to the domain policy,
12841284
// and it might release it only after the security manager is
12851285
// gone. But we can still assert this for the main process.
1286-
MOZ_ASSERT_IF(XRE_GetProcessType() == GeckoProcessType_Default,
1286+
MOZ_ASSERT_IF(XRE_IsParentProcess(),
12871287
!mDomainPolicy);
12881288
}
12891289

@@ -1500,7 +1500,7 @@ nsScriptSecurityManager::GetDomainPolicyActive(bool *aRv)
15001500
NS_IMETHODIMP
15011501
nsScriptSecurityManager::ActivateDomainPolicy(nsIDomainPolicy** aRv)
15021502
{
1503-
if (XRE_GetProcessType() != GeckoProcessType_Default) {
1503+
if (!XRE_IsParentProcess()) {
15041504
return NS_ERROR_SERVICE_NOT_AVAILABLE;
15051505
}
15061506

docshell/base/nsDefaultURIFixup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword,
416416
}
417417
keyword.Trim(" ");
418418

419-
if (XRE_GetProcessType() == GeckoProcessType_Content) {
419+
if (XRE_IsContentProcess()) {
420420
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
421421
if (!contentChild) {
422422
return NS_ERROR_NOT_AVAILABLE;

docshell/base/nsDocShell.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ IncreasePrivateDocShellCount()
824824
{
825825
gNumberOfPrivateDocShells++;
826826
if (gNumberOfPrivateDocShells > 1 ||
827-
XRE_GetProcessType() != GeckoProcessType_Content) {
827+
!XRE_IsContentProcess()) {
828828
return;
829829
}
830830

@@ -838,7 +838,7 @@ DecreasePrivateDocShellCount()
838838
MOZ_ASSERT(gNumberOfPrivateDocShells > 0);
839839
gNumberOfPrivateDocShells--;
840840
if (!gNumberOfPrivateDocShells) {
841-
if (XRE_GetProcessType() == GeckoProcessType_Content) {
841+
if (XRE_IsContentProcess()) {
842842
dom::ContentChild* cc = dom::ContentChild::GetSingleton();
843843
cc->SendPrivateDocShellsExist(false);
844844
return;
@@ -5020,7 +5020,7 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
50205020
mInPrivateBrowsing ? nsISocketProvider::NO_PERMANENT_STORAGE : 0;
50215021
bool isStsHost = false;
50225022
bool isPinnedHost = false;
5023-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
5023+
if (XRE_IsParentProcess()) {
50245024
nsCOMPtr<nsISiteSecurityService> sss =
50255025
do_GetService(NS_SSSERVICE_CONTRACTID, &rv);
50265026
NS_ENSURE_SUCCESS(rv, rv);
@@ -9448,7 +9448,7 @@ nsDocShell::CopyFavicon(nsIURI* aOldURI,
94489448
nsIURI* aNewURI,
94499449
bool aInPrivateBrowsing)
94509450
{
9451-
if (XRE_GetProcessType() == GeckoProcessType_Content) {
9451+
if (XRE_IsContentProcess()) {
94529452
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
94539453
if (contentChild) {
94549454
mozilla::ipc::URIParams oldURI, newURI;
@@ -13991,7 +13991,7 @@ nsDocShell::MaybeNotifyKeywordSearchLoading(const nsString& aProvider,
1399113991
return;
1399213992
}
1399313993

13994-
if (XRE_GetProcessType() == GeckoProcessType_Content) {
13994+
if (XRE_IsContentProcess()) {
1399513995
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
1399613996
if (contentChild) {
1399713997
contentChild->SendNotifyKeywordSearchLoading(aProvider, aKeyword);

dom/asmjscache/AsmJSCache.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ namespace asmjscache {
5757

5858
namespace {
5959

60-
bool
61-
IsMainProcess()
62-
{
63-
return XRE_GetProcessType() == GeckoProcessType_Default;
64-
}
65-
6660
// Anything smaller should compile fast enough that caching will just add
6761
// overhead.
6862
static const size_t sMinCachedModuleLength = 10000;
@@ -504,7 +498,7 @@ class MainProcessRunnable
504498
mIsApp(false),
505499
mEnforcingQuota(true)
506500
{
507-
MOZ_ASSERT(IsMainProcess());
501+
MOZ_ASSERT(XRE_IsParentProcess());
508502
}
509503

510504
virtual ~MainProcessRunnable()
@@ -1147,7 +1141,7 @@ class SingleProcessRunnable final : public File,
11471141
: MainProcessRunnable(aPrincipal, aOpenMode, aWriteParams),
11481142
mReadParams(aReadParams)
11491143
{
1150-
MOZ_ASSERT(IsMainProcess());
1144+
MOZ_ASSERT(XRE_IsParentProcess());
11511145
MOZ_ASSERT(!NS_IsMainThread());
11521146
MOZ_COUNT_CTOR(SingleProcessRunnable);
11531147
}
@@ -1229,7 +1223,7 @@ class ParentProcessRunnable final : public PAsmJSCacheEntryParent,
12291223
mOpened(false),
12301224
mFinished(false)
12311225
{
1232-
MOZ_ASSERT(IsMainProcess());
1226+
MOZ_ASSERT(XRE_IsParentProcess());
12331227
MOZ_ASSERT(NS_IsMainThread());
12341228
MOZ_COUNT_CTOR(ParentProcessRunnable);
12351229
}
@@ -1408,7 +1402,7 @@ class ChildProcessRunnable final : public File,
14081402
mActorDestroyed(false),
14091403
mState(eInitial)
14101404
{
1411-
MOZ_ASSERT(!IsMainProcess());
1405+
MOZ_ASSERT(!XRE_IsParentProcess());
14121406
MOZ_ASSERT(!NS_IsMainThread());
14131407
MOZ_COUNT_CTOR(ChildProcessRunnable);
14141408
}
@@ -1604,7 +1598,7 @@ OpenFile(nsIPrincipal* aPrincipal,
16041598
// parent process to open the file and interact with the QuotaManager. The
16051599
// child can then map the file into its address space to perform I/O.
16061600
nsRefPtr<File> file;
1607-
if (IsMainProcess()) {
1601+
if (XRE_IsParentProcess()) {
16081602
file = new SingleProcessRunnable(aPrincipal, aOpenMode, aWriteParams,
16091603
aReadParams);
16101604
} else {

dom/audiochannel/AudioChannelService.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ AudioChannelService::GetAudioChannelService()
7070
{
7171
MOZ_ASSERT(NS_IsMainThread());
7272

73-
if (XRE_GetProcessType() != GeckoProcessType_Default) {
73+
if (!XRE_IsParentProcess()) {
7474
return AudioChannelServiceChild::GetAudioChannelService();
7575
}
7676

@@ -84,7 +84,7 @@ AudioChannelService::GetOrCreateAudioChannelService()
8484
{
8585
MOZ_ASSERT(NS_IsMainThread());
8686

87-
if (XRE_GetProcessType() != GeckoProcessType_Default) {
87+
if (!XRE_IsParentProcess()) {
8888
return AudioChannelServiceChild::GetOrCreateAudioChannelService();
8989
}
9090

@@ -104,7 +104,7 @@ AudioChannelService::GetOrCreateAudioChannelService()
104104
void
105105
AudioChannelService::Shutdown()
106106
{
107-
if (XRE_GetProcessType() != GeckoProcessType_Default) {
107+
if (!XRE_IsParentProcess()) {
108108
return AudioChannelServiceChild::Shutdown();
109109
}
110110

@@ -122,7 +122,7 @@ AudioChannelService::AudioChannelService()
122122
, mDisabled(false)
123123
, mDefChannelChildID(CONTENT_PROCESS_ID_UNKNOWN)
124124
{
125-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
125+
if (XRE_IsParentProcess()) {
126126
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
127127
if (obs) {
128128
obs->AddObserver(this, "ipc:content-shutdown", false);
@@ -180,7 +180,7 @@ AudioChannelService::RegisterType(AudioChannel aChannel, uint64_t aChildID,
180180
AudioChannelInternalType type = GetInternalType(aChannel, true);
181181
mChannelCounters[type].AppendElement(aChildID);
182182

183-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
183+
if (XRE_IsParentProcess()) {
184184

185185
// We must keep the childIds in order to decide which app is allowed to play
186186
// with then telephony channel.
@@ -272,7 +272,7 @@ AudioChannelService::UnregisterType(AudioChannel aChannel,
272272
// There are two reasons to defer the decrease of telephony channel.
273273
// 1. User can have time to remove device from his ear before music resuming.
274274
// 2. Give BT SCO to be disconnected before starting to connect A2DP.
275-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
275+
if (XRE_IsParentProcess()) {
276276

277277
if (aChannel == AudioChannel::Telephony) {
278278
UnregisterTelephonyChild(aChildID);
@@ -306,7 +306,7 @@ AudioChannelService::UnregisterTypeInternal(AudioChannel aChannel,
306306

307307
// In order to avoid race conditions, it's safer to notify any existing
308308
// agent any time a new one is registered.
309-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
309+
if (XRE_IsParentProcess()) {
310310
// No hidden content channel is playable if the original playable hidden
311311
// process does not need to play audio from background anymore.
312312
if (aChannel == AudioChannel::Content &&
@@ -547,7 +547,7 @@ AudioChannelService::SetDefaultVolumeControlChannelInternal(int32_t aChannel,
547547
bool aVisible,
548548
uint64_t aChildID)
549549
{
550-
if (XRE_GetProcessType() != GeckoProcessType_Default) {
550+
if (!XRE_IsParentProcess()) {
551551
return;
552552
}
553553

@@ -590,7 +590,7 @@ AudioChannelService::SetDefaultVolumeControlChannelInternal(int32_t aChannel,
590590
void
591591
AudioChannelService::SendAudioChannelChangedNotification(uint64_t aChildID)
592592
{
593-
if (XRE_GetProcessType() != GeckoProcessType_Default) {
593+
if (!XRE_IsParentProcess()) {
594594
return;
595595
}
596596

dom/base/Crypto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
9191

9292
uint8_t* data = aArray.Data();
9393

94-
if (XRE_GetProcessType() != GeckoProcessType_Default) {
94+
if (!XRE_IsParentProcess()) {
9595
InfallibleTArray<uint8_t> randomValues;
9696
// Tell the parent process to generate random values via PContent
9797
ContentChild* cc = ContentChild::GetSingleton();

dom/base/Navigator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ Navigator::GetFeature(const nsAString& aName, ErrorResult& aRv)
14811481
#if defined(XP_LINUX)
14821482
if (aName.EqualsLiteral("hardware.memory")) {
14831483
// with seccomp enabled, fopen() should be in a non-sandboxed process
1484-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
1484+
if (XRE_IsParentProcess()) {
14851485
uint32_t memLevel = mozilla::hal::GetTotalSystemMemoryLevel();
14861486
if (memLevel == 0) {
14871487
p->MaybeReject(NS_ERROR_NOT_AVAILABLE);
@@ -2549,7 +2549,7 @@ Navigator::HasTVSupport(JSContext* aCx, JSObject* aGlobal)
25492549
bool
25502550
Navigator::IsE10sEnabled(JSContext* aCx, JSObject* aGlobal)
25512551
{
2552-
return XRE_GetProcessType() == GeckoProcessType_Content;
2552+
return XRE_IsContentProcess();
25532553
}
25542554

25552555
bool

dom/base/nsCCUncollectableMarker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void
141141
MarkMessageManagers()
142142
{
143143
// The global message manager only exists in the root process.
144-
if (XRE_GetProcessType() != GeckoProcessType_Default) {
144+
if (!XRE_IsParentProcess()) {
145145
return;
146146
}
147147
nsCOMPtr<nsIMessageBroadcaster> strongGlobalMM =

dom/base/nsContentPermissionHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ nsContentPermissionUtils::AskPermission(nsIContentPermissionRequest* aRequest, n
336336
NS_ENSURE_STATE(aWindow && aWindow->IsCurrentInnerWindow());
337337

338338
// for content process
339-
if (XRE_GetProcessType() == GeckoProcessType_Content) {
339+
if (XRE_IsContentProcess()) {
340340

341341
nsRefPtr<RemotePermissionRequest> req =
342342
new RemotePermissionRequest(aRequest, aWindow);

dom/base/nsDocument.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10658,7 +10658,7 @@ PLDHashOperator UnlockEnumerator(imgIRequest* aKey,
1065810658
nsresult
1065910659
nsDocument::SetImageLockingState(bool aLocked)
1066010660
{
10661-
if (XRE_GetProcessType() == GeckoProcessType_Content &&
10661+
if (XRE_IsContentProcess() &&
1066210662
!Preferences::GetBool("image.mem.allow_locking_in_content_processes", true)) {
1066310663
return NS_OK;
1066410664
}

dom/base/nsFocusManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ nsFocusManager::WindowRaised(nsIDOMWindow* aWindow)
697697
// If this is a parent or single process window, send the activate event.
698698
// Events for child process windows will be sent when ParentActivated
699699
// is called.
700-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
700+
if (XRE_IsParentProcess()) {
701701
ActivateOrDeactivate(window, true);
702702
}
703703

@@ -760,7 +760,7 @@ nsFocusManager::WindowLowered(nsIDOMWindow* aWindow)
760760
// If this is a parent or single process window, send the deactivate event.
761761
// Events for child process windows will be sent when ParentActivated
762762
// is called.
763-
if (XRE_GetProcessType() == GeckoProcessType_Default) {
763+
if (XRE_IsParentProcess()) {
764764
ActivateOrDeactivate(window, false);
765765
}
766766

0 commit comments

Comments
 (0)