Skip to content

Commit

Permalink
Bug 1650163 - Part 1: Switch native remoteType values to nsCString, r…
Browse files Browse the repository at this point in the history
…=farre,geckoview-reviewers,agi

Differential Revision: https://phabricator.services.mozilla.com/D82104
  • Loading branch information
mystor committed Jul 8, 2020
1 parent 15605ac commit 6dcce80
Show file tree
Hide file tree
Showing 79 changed files with 323 additions and 372 deletions.
2 changes: 1 addition & 1 deletion browser/components/about/AboutRedirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ AboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo,
// startup cache.
if (XRE_IsContentProcess() && path.EqualsLiteral("home")) {
auto& remoteType = dom::ContentChild::GetSingleton()->GetRemoteType();
if (remoteType.EqualsLiteral(PRIVILEGEDABOUT_REMOTE_TYPE)) {
if (remoteType == PRIVILEGEDABOUT_REMOTE_TYPE) {
nsCOMPtr<nsIAboutNewTabService> aboutNewTabService =
do_GetService("@mozilla.org/browser/aboutnewtab-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
Expand Down
2 changes: 1 addition & 1 deletion caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ nsresult nsScriptSecurityManager::CheckLoadURIFlags(
}

auto& remoteType = dom::ContentChild::GetSingleton()->GetRemoteType();
if (remoteType.EqualsLiteral(PRIVILEGEDABOUT_REMOTE_TYPE)) {
if (remoteType == PRIVILEGEDABOUT_REMOTE_TYPE) {
return NS_OK;
}
}
Expand Down
5 changes: 2 additions & 3 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,9 +1047,8 @@ bool BrowsingContext::CrossOriginIsolated() {
nsILoadInfo::
OPENER_POLICY_SAME_ORIGIN_EMBEDDER_POLICY_REQUIRE_CORP &&
XRE_IsContentProcess() &&
StringBeginsWith(
ContentChild::GetSingleton()->GetRemoteType(),
NS_LITERAL_STRING_FROM_CSTRING(WITH_COOP_COEP_REMOTE_TYPE_PREFIX));
StringBeginsWith(ContentChild::GetSingleton()->GetRemoteType(),
WITH_COOP_COEP_REMOTE_TYPE_PREFIX);
}

BrowsingContext::~BrowsingContext() {
Expand Down
6 changes: 3 additions & 3 deletions docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ ContentParent* CanonicalBrowsingContext::GetContentParent() const {
return cpm->GetContentProcessById(ContentParentId(mProcessId));
}

void CanonicalBrowsingContext::GetCurrentRemoteType(nsAString& aRemoteType,
void CanonicalBrowsingContext::GetCurrentRemoteType(nsACString& aRemoteType,
ErrorResult& aRv) const {
// If we're in the parent process, dump out the void string.
if (mProcessId == 0) {
aRemoteType.Assign(VoidString());
aRemoteType.Assign(VoidCString());
return;
}

Expand Down Expand Up @@ -822,7 +822,7 @@ CanonicalBrowsingContext::PendingRemotenessChange::~PendingRemotenessChange() {
}

RefPtr<CanonicalBrowsingContext::RemotenessPromise>
CanonicalBrowsingContext::ChangeRemoteness(const nsAString& aRemoteType,
CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
uint64_t aPendingSwitchId,
bool aReplaceBrowsingContext,
uint64_t aSpecificGroupId) {
Expand Down
6 changes: 3 additions & 3 deletions docshell/base/CanonicalBrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
uint64_t EmbedderProcessId() const { return mEmbedderProcessId; }
ContentParent* GetContentParent() const;

void GetCurrentRemoteType(nsAString& aRemoteType, ErrorResult& aRv) const;
void GetCurrentRemoteType(nsACString& aRemoteType, ErrorResult& aRv) const;

void SetOwnerProcessId(uint64_t aProcessId);

Expand Down Expand Up @@ -150,10 +150,10 @@ class CanonicalBrowsingContext final : public BrowsingContext {
// Internal method to change which process a BrowsingContext is being loaded
// in. The returned promise will resolve when the process switch is completed.
//
// A VoidString() aRemoteType argument will perform a process switch into the
// A VoidCString() aRemoteType argument will perform a process switch into the
// parent process, and the method will resolve with a null BrowserParent.
using RemotenessPromise = MozPromise<RefPtr<BrowserParent>, nsresult, false>;
RefPtr<RemotenessPromise> ChangeRemoteness(const nsAString& aRemoteType,
RefPtr<RemotenessPromise> ChangeRemoteness(const nsACString& aRemoteType,
uint64_t aPendingSwitchId,
bool aReplaceBrowsingContext,
uint64_t aSpecificGroupId);
Expand Down
40 changes: 16 additions & 24 deletions dom/base/ChromeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
global->EventTargetFor(TaskCategory::Performance);

// Getting the parent proc info
mozilla::GetProcInfo(parentPid, 0, mozilla::ProcType::Browser, u""_ns)
mozilla::GetProcInfo(parentPid, 0, mozilla::ProcType::Browser, ""_ns)
->Then(
target, __func__,
[target, domPromise, parentPid](ProcInfo aParentInfo) {
Expand All @@ -809,7 +809,7 @@ already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
if (!aGeckoProcess->GetChildProcessHandle()) {
return;
}
nsAutoString origin;
nsAutoCString origin;
base::ProcessId childPid =
base::GetProcId(aGeckoProcess->GetChildProcessHandle());
int32_t childId = 0;
Expand All @@ -832,50 +832,42 @@ already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
// Converting the remoteType into a ProcType.
// Ideally, the remoteType should be strongly typed
// upstream, this would make the conversion less brittle.
nsAutoString remoteType(contentParent->GetRemoteType());
nsAutoCString remoteType(contentParent->GetRemoteType());
if (StringBeginsWith(remoteType,
NS_LITERAL_STRING_FROM_CSTRING(
FISSION_WEB_REMOTE_TYPE))) {
FISSION_WEB_REMOTE_TYPE)) {
// WARNING: Do not change the order, as
// `DEFAULT_REMOTE_TYPE` is a prefix of
// `FISSION_WEB_REMOTE_TYPE`.
type = mozilla::ProcType::WebIsolated;
} else if (StringBeginsWith(
remoteType, NS_LITERAL_STRING_FROM_CSTRING(
DEFAULT_REMOTE_TYPE))) {
} else if (StringBeginsWith(remoteType,
DEFAULT_REMOTE_TYPE)) {
type = mozilla::ProcType::Web;
} else if (remoteType.EqualsLiteral(FILE_REMOTE_TYPE)) {
} else if (remoteType == FILE_REMOTE_TYPE) {
type = mozilla::ProcType::File;
} else if (remoteType.EqualsLiteral(
EXTENSION_REMOTE_TYPE)) {
} else if (remoteType == EXTENSION_REMOTE_TYPE) {
type = mozilla::ProcType::Extension;
} else if (remoteType.EqualsLiteral(
PRIVILEGEDABOUT_REMOTE_TYPE)) {
} else if (remoteType == PRIVILEGEDABOUT_REMOTE_TYPE) {
type = mozilla::ProcType::PrivilegedAbout;
} else if (remoteType.EqualsLiteral(
PRIVILEGEDMOZILLA_REMOTE_TYPE)) {
} else if (remoteType == PRIVILEGEDMOZILLA_REMOTE_TYPE) {
type = mozilla::ProcType::PrivilegedMozilla;
} else if (StringBeginsWith(
remoteType,
NS_LITERAL_STRING_FROM_CSTRING(
WITH_COOP_COEP_REMOTE_TYPE_PREFIX))) {
WITH_COOP_COEP_REMOTE_TYPE_PREFIX)) {
type = mozilla::ProcType::WebCOOPCOEP;
} else if (remoteType.EqualsLiteral(
LARGE_ALLOCATION_REMOTE_TYPE)) {
} else if (remoteType == LARGE_ALLOCATION_REMOTE_TYPE) {
type = mozilla::ProcType::WebLargeAllocation;
} else if (remoteType.EqualsLiteral(
PREALLOC_REMOTE_TYPE)) {
} else if (remoteType == PREALLOC_REMOTE_TYPE) {
type = mozilla::ProcType::Preallocated;
} else {
MOZ_CRASH("Unknown remoteType");
}

// By convention, everything after '=' is the origin.
nsAString::const_iterator cursor;
nsAString::const_iterator end;
nsACString::const_iterator cursor;
nsACString::const_iterator end;
remoteType.BeginReading(cursor);
remoteType.EndReading(end);
if (FindCharInReadable(u'=', cursor, end)) {
if (FindCharInReadable('=', cursor, end)) {
origin = Substring(++cursor, end);
}
childId = contentParent->ChildID();
Expand Down
2 changes: 1 addition & 1 deletion dom/base/MessageManagerGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MessageManagerGlobal {
return mMessageManager->GetProcessMessageManager(aError);
}

void GetRemoteType(nsAString& aRemoteType, mozilla::ErrorResult& aError) {
void GetRemoteType(nsACString& aRemoteType, mozilla::ErrorResult& aError) {
if (!mMessageManager) {
aError.Throw(NS_ERROR_NOT_INITIALIZED);
return;
Expand Down
15 changes: 9 additions & 6 deletions dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ nsFrameLoader::nsFrameLoader(Element* aOwner, BrowsingContext* aBrowsingContext,
mDetachedSubdocFrame(nullptr),
mPendingSwitchID(0),
mChildID(0),
mRemoteType(VoidString()),
mRemoteType(VoidCString()),
mDepthTooGreat(false),
mIsTopLevelContent(false),
mDestroyCalled(false),
Expand Down Expand Up @@ -351,17 +351,20 @@ static bool InitialLoadIsRemote(Element* aOwner) {
}

static void GetInitialRemoteTypeAndProcess(Element* aOwner,
nsAString& aRemoteType,
nsACString& aRemoteType,
uint64_t* aChildID) {
MOZ_ASSERT(XRE_IsParentProcess());
*aChildID = 0;

// Check if there is an explicit `remoteType` attribute which we should use.
nsAutoString remoteType;
bool hasRemoteType =
aOwner->GetAttr(kNameSpaceID_None, nsGkAtoms::RemoteType, aRemoteType);
if (!hasRemoteType || aRemoteType.IsEmpty()) {
aOwner->GetAttr(kNameSpaceID_None, nsGkAtoms::RemoteType, remoteType);
if (!hasRemoteType || remoteType.IsEmpty()) {
hasRemoteType = false;
aRemoteType.AssignLiteral(DEFAULT_REMOTE_TYPE);
aRemoteType = DEFAULT_REMOTE_TYPE;
} else {
aRemoteType = NS_ConvertUTF16toUTF8(remoteType);
}

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

void nsFrameLoader::ConfigRemoteProcess(const nsAString& aRemoteType,
void nsFrameLoader::ConfigRemoteProcess(const nsACString& aRemoteType,
ContentParent* aContentParent) {
MOZ_DIAGNOSTIC_ASSERT(IsRemoteFrame(), "Must be a remote frame");
MOZ_DIAGNOSTIC_ASSERT(!mRemoteBrowser, "Must not have a browser yet");
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsFrameLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class nsFrameLoader final : public nsStubMutationObserver,
// `TryRemoteBrowser`, and a script blocker must be on the stack.
//
// |aContentParent|, if set, must have the remote type |aRemoteType|.
void ConfigRemoteProcess(const nsAString& aRemoteType,
void ConfigRemoteProcess(const nsACString& aRemoteType,
mozilla::dom::ContentParent* aContentParent);

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

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

nsString mRemoteType;
nsCString mRemoteType;

bool mDepthTooGreat : 1;
bool mIsTopLevelContent : 1;
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsFrameMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameMessageManager)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameMessageManager)

void MessageManagerCallback::DoGetRemoteType(nsAString& aRemoteType,
void MessageManagerCallback::DoGetRemoteType(nsACString& aRemoteType,
ErrorResult& aError) const {
aRemoteType.Truncate();
mozilla::dom::ProcessMessageManager* parent = GetProcessMessageManager();
Expand Down Expand Up @@ -917,7 +917,7 @@ nsFrameMessageManager::GetProcessMessageManager(ErrorResult& aError) {
return pmm.forget();
}

void nsFrameMessageManager::GetRemoteType(nsAString& aRemoteType,
void nsFrameMessageManager::GetRemoteType(nsACString& aRemoteType,
ErrorResult& aError) const {
aRemoteType.Truncate();
if (mCallback) {
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsFrameMessageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class MessageManagerCallback {
return nullptr;
}

virtual void DoGetRemoteType(nsAString& aRemoteType,
virtual void DoGetRemoteType(nsACString& aRemoteType,
ErrorResult& aError) const;

protected:
Expand Down Expand Up @@ -178,7 +178,7 @@ class nsFrameMessageManager : public nsIMessageSender {
}
already_AddRefed<mozilla::dom::ProcessMessageManager>
GetProcessMessageManager(mozilla::ErrorResult& aError);
void GetRemoteType(nsAString& aRemoteType,
void GetRemoteType(nsACString& aRemoteType,
mozilla::ErrorResult& aError) const;

// SyncMessageSender
Expand Down
2 changes: 1 addition & 1 deletion dom/chrome-webidl/BrowsingContext.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ interface CanonicalBrowsingContext : BrowsingContext {
// synchronously create WindowGlobalParent. It can throw if somehow the
// content process has died.
[Throws]
readonly attribute DOMString? currentRemoteType;
readonly attribute UTF8String? currentRemoteType;

readonly attribute WindowGlobalParent? embedderWindowGlobal;

Expand Down
2 changes: 1 addition & 1 deletion dom/chrome-webidl/ChromeUtils.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ dictionary ChildProcInfoDictionary {
sequence<ThreadInfoDictionary> threads = [];
// Firefox info
unsigned long long ChildID = 0;
DOMString origin = "";
UTF8String origin = "";
WebIDLProcType type = "web";
};

Expand Down
2 changes: 1 addition & 1 deletion dom/chrome-webidl/JSProcessActor.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dictionary ProcessActorOptions {
* can prefix match remote type either `web` or `webIsolated`. If not passed,
* all content processes are allowed to instantiate the actor.
*/
sequence<DOMString> remoteTypes;
sequence<UTF8String> remoteTypes;

/** This fields are used for configuring individual sides of the actor. */
ProcessActorSidedOptions parent;
Expand Down
2 changes: 1 addition & 1 deletion dom/chrome-webidl/JSWindowActor.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ dictionary WindowActorOptions {
* can prefix match remote type either `web` or `webIsolated`. If not passed,
* all content processes are allowed to instantiate the actor.
*/
sequence<DOMString> remoteTypes;
sequence<UTF8String> remoteTypes;

/**
* An array of MessageManagerGroup values which restrict which type
Expand Down
2 changes: 1 addition & 1 deletion dom/chrome-webidl/MessageManager.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ interface mixin MessageSenderMixin {
* Otherwise, it is empty.
*/
[Throws]
readonly attribute DOMString remoteType;
readonly attribute UTF8String remoteType;
};

[ChromeOnly, Exposed=Window]
Expand Down
2 changes: 1 addition & 1 deletion dom/interfaces/base/nsIContentProcess.idl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface nsIContentProcessProvider : nsISupports
* nsIContentProcessProvider.NEW_PROCESS to ask the caller to create a new
* content process.
*/
int32_t provideProcess(in AString aType,
int32_t provideProcess(in AUTF8String aType,
in Array<nsIContentProcessInfo> aAliveProcesses,
in uint32_t aMaxCount);
};
32 changes: 15 additions & 17 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ mozilla::ipc::IPCResult ContentChild::RecvSetProcessSandbox(
// Use the prefix to avoid URIs from Fission isolated processes.
auto remoteTypePrefix = RemoteTypePrefix(GetRemoteType());
CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::RemoteType,
NS_ConvertUTF16toUTF8(remoteTypePrefix));
remoteTypePrefix);
#endif /* MOZ_SANDBOX */

return IPC_OK();
Expand Down Expand Up @@ -2568,38 +2568,36 @@ mozilla::ipc::IPCResult ContentChild::RecvAppInfo(
}

mozilla::ipc::IPCResult ContentChild::RecvRemoteType(
const nsString& aRemoteType) {
if (!DOMStringIsNull(mRemoteType)) {
const nsCString& aRemoteType) {
if (!mRemoteType.IsVoid()) {
// Preallocated processes are type PREALLOC_REMOTE_TYPE; they can become
// anything except a File: process.
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
("Changing remoteType of process %d from %s to %s", getpid(),
NS_ConvertUTF16toUTF8(mRemoteType).get(),
NS_ConvertUTF16toUTF8(aRemoteType).get()));
mRemoteType.get(), aRemoteType.get()));
// prealloc->anything (but file) or web->web allowed
MOZ_RELEASE_ASSERT(!aRemoteType.EqualsLiteral(FILE_REMOTE_TYPE) &&
(mRemoteType.EqualsLiteral(PREALLOC_REMOTE_TYPE) ||
(mRemoteType.EqualsLiteral(DEFAULT_REMOTE_TYPE) &&
aRemoteType.EqualsLiteral(DEFAULT_REMOTE_TYPE))));
MOZ_RELEASE_ASSERT(aRemoteType != FILE_REMOTE_TYPE &&
(mRemoteType == PREALLOC_REMOTE_TYPE ||
(mRemoteType == DEFAULT_REMOTE_TYPE &&
aRemoteType == DEFAULT_REMOTE_TYPE)));
} else {
// Initial setting of remote type. Either to 'prealloc' or the actual
// final type (if we didn't use a preallocated process)
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
("Setting remoteType of process %d to %s", getpid(),
NS_ConvertUTF16toUTF8(aRemoteType).get()));
aRemoteType.get()));
}

// Update the process name so about:memory's process names are more obvious.
if (aRemoteType.EqualsLiteral(FILE_REMOTE_TYPE)) {
if (aRemoteType == FILE_REMOTE_TYPE) {
SetProcessName(u"file:// Content"_ns);
} else if (aRemoteType.EqualsLiteral(EXTENSION_REMOTE_TYPE)) {
} else if (aRemoteType == EXTENSION_REMOTE_TYPE) {
SetProcessName(u"WebExtensions"_ns);
} else if (aRemoteType.EqualsLiteral(PRIVILEGEDABOUT_REMOTE_TYPE)) {
} else if (aRemoteType == PRIVILEGEDABOUT_REMOTE_TYPE) {
SetProcessName(u"Privileged Content"_ns);
} else if (aRemoteType.EqualsLiteral(LARGE_ALLOCATION_REMOTE_TYPE)) {
} else if (aRemoteType == LARGE_ALLOCATION_REMOTE_TYPE) {
SetProcessName(u"Large Allocation Web Content"_ns);
} else if (RemoteTypePrefix(aRemoteType)
.EqualsLiteral(FISSION_WEB_REMOTE_TYPE)) {
} else if (RemoteTypePrefix(aRemoteType) == FISSION_WEB_REMOTE_TYPE) {
SetProcessName(u"Isolated Web Content"_ns);
}
// else "prealloc", "web" or "webCOOP+COEP" type -> "Web Content" already set
Expand All @@ -2611,7 +2609,7 @@ mozilla::ipc::IPCResult ContentChild::RecvRemoteType(

// Call RemoteTypePrefix() on the result to remove URIs if you want to use this
// for telemetry.
const nsAString& ContentChild::GetRemoteType() const { return mRemoteType; }
const nsACString& ContentChild::GetRemoteType() const { return mRemoteType; }

mozilla::ipc::IPCResult ContentChild::RecvInitServiceWorkers(
const ServiceWorkerConfiguration& aConfig) {
Expand Down
Loading

0 comments on commit 6dcce80

Please sign in to comment.