Skip to content

Commit 22a65a2

Browse files
committed
Bug 1650163 - Part 1: Switch native remoteType values to nsCString, r=farre,geckoview-reviewers,agi
Differential Revision: https://phabricator.services.mozilla.com/D82104
1 parent 0877db2 commit 22a65a2

File tree

79 files changed

+323
-372
lines changed

Some content is hidden

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

79 files changed

+323
-372
lines changed

browser/components/about/AboutRedirector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ AboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo,
156156
// startup cache.
157157
if (XRE_IsContentProcess() && path.EqualsLiteral("home")) {
158158
auto& remoteType = dom::ContentChild::GetSingleton()->GetRemoteType();
159-
if (remoteType.EqualsLiteral(PRIVILEGEDABOUT_REMOTE_TYPE)) {
159+
if (remoteType == PRIVILEGEDABOUT_REMOTE_TYPE) {
160160
nsCOMPtr<nsIAboutNewTabService> aboutNewTabService =
161161
do_GetService("@mozilla.org/browser/aboutnewtab-service;1", &rv);
162162
NS_ENSURE_SUCCESS(rv, rv);

caps/nsScriptSecurityManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ nsresult nsScriptSecurityManager::CheckLoadURIFlags(
938938
}
939939

940940
auto& remoteType = dom::ContentChild::GetSingleton()->GetRemoteType();
941-
if (remoteType.EqualsLiteral(PRIVILEGEDABOUT_REMOTE_TYPE)) {
941+
if (remoteType == PRIVILEGEDABOUT_REMOTE_TYPE) {
942942
return NS_OK;
943943
}
944944
}

docshell/base/BrowsingContext.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,9 +1047,8 @@ bool BrowsingContext::CrossOriginIsolated() {
10471047
nsILoadInfo::
10481048
OPENER_POLICY_SAME_ORIGIN_EMBEDDER_POLICY_REQUIRE_CORP &&
10491049
XRE_IsContentProcess() &&
1050-
StringBeginsWith(
1051-
ContentChild::GetSingleton()->GetRemoteType(),
1052-
NS_LITERAL_STRING_FROM_CSTRING(WITH_COOP_COEP_REMOTE_TYPE_PREFIX));
1050+
StringBeginsWith(ContentChild::GetSingleton()->GetRemoteType(),
1051+
WITH_COOP_COEP_REMOTE_TYPE_PREFIX);
10531052
}
10541053

10551054
BrowsingContext::~BrowsingContext() {

docshell/base/CanonicalBrowsingContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ ContentParent* CanonicalBrowsingContext::GetContentParent() const {
9494
return cpm->GetContentProcessById(ContentParentId(mProcessId));
9595
}
9696

97-
void CanonicalBrowsingContext::GetCurrentRemoteType(nsAString& aRemoteType,
97+
void CanonicalBrowsingContext::GetCurrentRemoteType(nsACString& aRemoteType,
9898
ErrorResult& aRv) const {
9999
// If we're in the parent process, dump out the void string.
100100
if (mProcessId == 0) {
101-
aRemoteType.Assign(VoidString());
101+
aRemoteType.Assign(VoidCString());
102102
return;
103103
}
104104

@@ -822,7 +822,7 @@ CanonicalBrowsingContext::PendingRemotenessChange::~PendingRemotenessChange() {
822822
}
823823

824824
RefPtr<CanonicalBrowsingContext::RemotenessPromise>
825-
CanonicalBrowsingContext::ChangeRemoteness(const nsAString& aRemoteType,
825+
CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
826826
uint64_t aPendingSwitchId,
827827
bool aReplaceBrowsingContext,
828828
uint64_t aSpecificGroupId) {

docshell/base/CanonicalBrowsingContext.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
5959
uint64_t EmbedderProcessId() const { return mEmbedderProcessId; }
6060
ContentParent* GetContentParent() const;
6161

62-
void GetCurrentRemoteType(nsAString& aRemoteType, ErrorResult& aRv) const;
62+
void GetCurrentRemoteType(nsACString& aRemoteType, ErrorResult& aRv) const;
6363

6464
void SetOwnerProcessId(uint64_t aProcessId);
6565

@@ -150,10 +150,10 @@ class CanonicalBrowsingContext final : public BrowsingContext {
150150
// Internal method to change which process a BrowsingContext is being loaded
151151
// in. The returned promise will resolve when the process switch is completed.
152152
//
153-
// A VoidString() aRemoteType argument will perform a process switch into the
153+
// A VoidCString() aRemoteType argument will perform a process switch into the
154154
// parent process, and the method will resolve with a null BrowserParent.
155155
using RemotenessPromise = MozPromise<RefPtr<BrowserParent>, nsresult, false>;
156-
RefPtr<RemotenessPromise> ChangeRemoteness(const nsAString& aRemoteType,
156+
RefPtr<RemotenessPromise> ChangeRemoteness(const nsACString& aRemoteType,
157157
uint64_t aPendingSwitchId,
158158
bool aReplaceBrowsingContext,
159159
uint64_t aSpecificGroupId);

dom/base/ChromeUtils.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
795795
global->EventTargetFor(TaskCategory::Performance);
796796

797797
// Getting the parent proc info
798-
mozilla::GetProcInfo(parentPid, 0, mozilla::ProcType::Browser, u""_ns)
798+
mozilla::GetProcInfo(parentPid, 0, mozilla::ProcType::Browser, ""_ns)
799799
->Then(
800800
target, __func__,
801801
[target, domPromise, parentPid](ProcInfo aParentInfo) {
@@ -809,7 +809,7 @@ already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
809809
if (!aGeckoProcess->GetChildProcessHandle()) {
810810
return;
811811
}
812-
nsAutoString origin;
812+
nsAutoCString origin;
813813
base::ProcessId childPid =
814814
base::GetProcId(aGeckoProcess->GetChildProcessHandle());
815815
int32_t childId = 0;
@@ -832,50 +832,42 @@ already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
832832
// Converting the remoteType into a ProcType.
833833
// Ideally, the remoteType should be strongly typed
834834
// upstream, this would make the conversion less brittle.
835-
nsAutoString remoteType(contentParent->GetRemoteType());
835+
nsAutoCString remoteType(contentParent->GetRemoteType());
836836
if (StringBeginsWith(remoteType,
837-
NS_LITERAL_STRING_FROM_CSTRING(
838-
FISSION_WEB_REMOTE_TYPE))) {
837+
FISSION_WEB_REMOTE_TYPE)) {
839838
// WARNING: Do not change the order, as
840839
// `DEFAULT_REMOTE_TYPE` is a prefix of
841840
// `FISSION_WEB_REMOTE_TYPE`.
842841
type = mozilla::ProcType::WebIsolated;
843-
} else if (StringBeginsWith(
844-
remoteType, NS_LITERAL_STRING_FROM_CSTRING(
845-
DEFAULT_REMOTE_TYPE))) {
842+
} else if (StringBeginsWith(remoteType,
843+
DEFAULT_REMOTE_TYPE)) {
846844
type = mozilla::ProcType::Web;
847-
} else if (remoteType.EqualsLiteral(FILE_REMOTE_TYPE)) {
845+
} else if (remoteType == FILE_REMOTE_TYPE) {
848846
type = mozilla::ProcType::File;
849-
} else if (remoteType.EqualsLiteral(
850-
EXTENSION_REMOTE_TYPE)) {
847+
} else if (remoteType == EXTENSION_REMOTE_TYPE) {
851848
type = mozilla::ProcType::Extension;
852-
} else if (remoteType.EqualsLiteral(
853-
PRIVILEGEDABOUT_REMOTE_TYPE)) {
849+
} else if (remoteType == PRIVILEGEDABOUT_REMOTE_TYPE) {
854850
type = mozilla::ProcType::PrivilegedAbout;
855-
} else if (remoteType.EqualsLiteral(
856-
PRIVILEGEDMOZILLA_REMOTE_TYPE)) {
851+
} else if (remoteType == PRIVILEGEDMOZILLA_REMOTE_TYPE) {
857852
type = mozilla::ProcType::PrivilegedMozilla;
858853
} else if (StringBeginsWith(
859854
remoteType,
860-
NS_LITERAL_STRING_FROM_CSTRING(
861-
WITH_COOP_COEP_REMOTE_TYPE_PREFIX))) {
855+
WITH_COOP_COEP_REMOTE_TYPE_PREFIX)) {
862856
type = mozilla::ProcType::WebCOOPCOEP;
863-
} else if (remoteType.EqualsLiteral(
864-
LARGE_ALLOCATION_REMOTE_TYPE)) {
857+
} else if (remoteType == LARGE_ALLOCATION_REMOTE_TYPE) {
865858
type = mozilla::ProcType::WebLargeAllocation;
866-
} else if (remoteType.EqualsLiteral(
867-
PREALLOC_REMOTE_TYPE)) {
859+
} else if (remoteType == PREALLOC_REMOTE_TYPE) {
868860
type = mozilla::ProcType::Preallocated;
869861
} else {
870862
MOZ_CRASH("Unknown remoteType");
871863
}
872864

873865
// By convention, everything after '=' is the origin.
874-
nsAString::const_iterator cursor;
875-
nsAString::const_iterator end;
866+
nsACString::const_iterator cursor;
867+
nsACString::const_iterator end;
876868
remoteType.BeginReading(cursor);
877869
remoteType.EndReading(end);
878-
if (FindCharInReadable(u'=', cursor, end)) {
870+
if (FindCharInReadable('=', cursor, end)) {
879871
origin = Substring(++cursor, end);
880872
}
881873
childId = contentParent->ChildID();

dom/base/MessageManagerGlobal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class MessageManagerGlobal {
7575
return mMessageManager->GetProcessMessageManager(aError);
7676
}
7777

78-
void GetRemoteType(nsAString& aRemoteType, mozilla::ErrorResult& aError) {
78+
void GetRemoteType(nsACString& aRemoteType, mozilla::ErrorResult& aError) {
7979
if (!mMessageManager) {
8080
aError.Throw(NS_ERROR_NOT_INITIALIZED);
8181
return;

dom/base/nsFrameLoader.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ nsFrameLoader::nsFrameLoader(Element* aOwner, BrowsingContext* aBrowsingContext,
169169
mDetachedSubdocFrame(nullptr),
170170
mPendingSwitchID(0),
171171
mChildID(0),
172-
mRemoteType(VoidString()),
172+
mRemoteType(VoidCString()),
173173
mDepthTooGreat(false),
174174
mIsTopLevelContent(false),
175175
mDestroyCalled(false),
@@ -351,17 +351,20 @@ static bool InitialLoadIsRemote(Element* aOwner) {
351351
}
352352

353353
static void GetInitialRemoteTypeAndProcess(Element* aOwner,
354-
nsAString& aRemoteType,
354+
nsACString& aRemoteType,
355355
uint64_t* aChildID) {
356356
MOZ_ASSERT(XRE_IsParentProcess());
357357
*aChildID = 0;
358358

359359
// Check if there is an explicit `remoteType` attribute which we should use.
360+
nsAutoString remoteType;
360361
bool hasRemoteType =
361-
aOwner->GetAttr(kNameSpaceID_None, nsGkAtoms::RemoteType, aRemoteType);
362-
if (!hasRemoteType || aRemoteType.IsEmpty()) {
362+
aOwner->GetAttr(kNameSpaceID_None, nsGkAtoms::RemoteType, remoteType);
363+
if (!hasRemoteType || remoteType.IsEmpty()) {
363364
hasRemoteType = false;
364-
aRemoteType.AssignLiteral(DEFAULT_REMOTE_TYPE);
365+
aRemoteType = DEFAULT_REMOTE_TYPE;
366+
} else {
367+
aRemoteType = NS_ConvertUTF16toUTF8(remoteType);
365368
}
366369

367370
// Check if `sameProcessAsFrameLoader` was used to override the process.
@@ -528,7 +531,7 @@ void nsFrameLoader::LoadFrame(bool aOriginalSrc) {
528531
}
529532
}
530533

531-
void nsFrameLoader::ConfigRemoteProcess(const nsAString& aRemoteType,
534+
void nsFrameLoader::ConfigRemoteProcess(const nsACString& aRemoteType,
532535
ContentParent* aContentParent) {
533536
MOZ_DIAGNOSTIC_ASSERT(IsRemoteFrame(), "Must be a remote frame");
534537
MOZ_DIAGNOSTIC_ASSERT(!mRemoteBrowser, "Must not have a browser yet");

dom/base/nsFrameLoader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class nsFrameLoader final : public nsStubMutationObserver,
398398
// `TryRemoteBrowser`, and a script blocker must be on the stack.
399399
//
400400
// |aContentParent|, if set, must have the remote type |aRemoteType|.
401-
void ConfigRemoteProcess(const nsAString& aRemoteType,
401+
void ConfigRemoteProcess(const nsACString& aRemoteType,
402402
mozilla::dom::ContentParent* aContentParent);
403403

404404
void MaybeNotifyCrashed(mozilla::dom::BrowsingContext* aBrowsingContext,
@@ -515,7 +515,7 @@ class nsFrameLoader final : public nsStubMutationObserver,
515515

516516
RefPtr<mozilla::dom::TabListener> mSessionStoreListener;
517517

518-
nsString mRemoteType;
518+
nsCString mRemoteType;
519519

520520
bool mDepthTooGreat : 1;
521521
bool mIsTopLevelContent : 1;

dom/base/nsFrameMessageManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ NS_INTERFACE_MAP_END
152152
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameMessageManager)
153153
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameMessageManager)
154154

155-
void MessageManagerCallback::DoGetRemoteType(nsAString& aRemoteType,
155+
void MessageManagerCallback::DoGetRemoteType(nsACString& aRemoteType,
156156
ErrorResult& aError) const {
157157
aRemoteType.Truncate();
158158
mozilla::dom::ProcessMessageManager* parent = GetProcessMessageManager();
@@ -917,7 +917,7 @@ nsFrameMessageManager::GetProcessMessageManager(ErrorResult& aError) {
917917
return pmm.forget();
918918
}
919919

920-
void nsFrameMessageManager::GetRemoteType(nsAString& aRemoteType,
920+
void nsFrameMessageManager::GetRemoteType(nsACString& aRemoteType,
921921
ErrorResult& aError) const {
922922
aRemoteType.Truncate();
923923
if (mCallback) {

0 commit comments

Comments
 (0)