Skip to content

Commit

Permalink
Issue #2653 - Part 1: Initial cleanup of AppId and isolated mozbrowser.
Browse files Browse the repository at this point in the history
This removes a lot of the plumbing for having the platform embed itself
through IPC which was required for B2G running the browser as both
shell and browser application.
  • Loading branch information
wolfbeast committed Nov 17, 2024
1 parent b2cab55 commit 01a1a85
Show file tree
Hide file tree
Showing 77 changed files with 295 additions and 1,799 deletions.
4 changes: 2 additions & 2 deletions accessible/jsat/AccessFu.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ this.AccessFu = { // jshint ignore:line
case 'remote-browser-shown':
case 'inprocess-browser-shown':
{
// Ignore notifications that aren't from a BrowserOrApp
// Ignore notifications that aren't from a Browser
let frameLoader = aSubject.QueryInterface(Ci.nsIFrameLoader);
if (!frameLoader.ownerIsMozBrowserOrAppFrame) {
if (!frameLoader.ownerIsMozBrowserFrame) {
return;
}
this._handleMessageManager(frameLoader.messageManager);
Expand Down
9 changes: 0 additions & 9 deletions caps/nsIPrincipal.idl
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,6 @@ interface nsIPrincipal : nsISerializable
*/
[infallible] readonly attribute unsigned long privateBrowsingId;

/**
* Returns true iff the principal is inside an isolated mozbrowser element.
* <iframe mozbrowser mozapp> and <xul:browser> are not considered to be
* mozbrowser elements. <iframe mozbrowser noisolation> does not count as
* isolated since isolation is disabled. Isolation can only be disabled if
* the containing document is chrome.
*/
[infallible] readonly attribute boolean isInIsolatedMozBrowserElement;

/**
* Returns true if this principal has an unknown appId. This shouldn't
* generally be used. We only expose it due to not providing the correct
Expand Down
58 changes: 1 addition & 57 deletions caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,63 +243,7 @@ nsScriptSecurityManager::SecurityHashURI(nsIURI* aURI)
uint16_t
nsScriptSecurityManager::AppStatusForPrincipal(nsIPrincipal *aPrin)
{
uint32_t appId = aPrin->GetAppId();

// After bug 1238160, the principal no longer knows how to answer "is this a
// browser element", which is really what this code path wants. Currently,
// desktop is the only platform where we intend to disable isolation on a
// browser frame, so non-desktop should be able to assume that
// inIsolatedMozBrowser is true for all mozbrowser frames. Additionally,
// apps are no longer used on desktop, so appId is always NO_APP_ID. We use
// a release assertion in nsFrameLoader::OwnerIsIsolatedMozBrowserFrame so
// that platforms with apps can assume inIsolatedMozBrowser is true for all
// mozbrowser frames.
bool inIsolatedMozBrowser = aPrin->GetIsInIsolatedMozBrowserElement();

NS_WARNING_ASSERTION(
appId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
"Asking for app status on a principal with an unknown app id");

// Installed apps have a valid app id (not NO_APP_ID or UNKNOWN_APP_ID)
// and they are not inside a mozbrowser.
if (appId == nsIScriptSecurityManager::NO_APP_ID ||
appId == nsIScriptSecurityManager::UNKNOWN_APP_ID ||
inIsolatedMozBrowser)
{
return nsIPrincipal::APP_STATUS_NOT_INSTALLED;
}

nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(appsService, nsIPrincipal::APP_STATUS_NOT_INSTALLED);

nsCOMPtr<mozIApplication> app;
appsService->GetAppByLocalId(appId, getter_AddRefs(app));
NS_ENSURE_TRUE(app, nsIPrincipal::APP_STATUS_NOT_INSTALLED);

uint16_t status = nsIPrincipal::APP_STATUS_INSTALLED;
NS_ENSURE_SUCCESS(app->GetAppStatus(&status),
nsIPrincipal::APP_STATUS_NOT_INSTALLED);

nsString appOrigin;
NS_ENSURE_SUCCESS(app->GetOrigin(appOrigin),
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
nsCOMPtr<nsIURI> appURI;
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(appURI), appOrigin),
nsIPrincipal::APP_STATUS_NOT_INSTALLED);

// The app could contain a cross-origin iframe - make sure that the content
// is actually same-origin with the app.
MOZ_ASSERT(inIsolatedMozBrowser == false, "Checked this above");
nsAutoCString suffix;
PrincipalOriginAttributes attrs;
NS_ENSURE_TRUE(attrs.PopulateFromOrigin(NS_ConvertUTF16toUTF8(appOrigin), suffix),
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
attrs.mAppId = appId;
attrs.mInIsolatedMozBrowser = false;
nsCOMPtr<nsIPrincipal> appPrin = BasePrincipal::CreateCodebasePrincipal(appURI, attrs);
NS_ENSURE_TRUE(appPrin, nsIPrincipal::APP_STATUS_NOT_INSTALLED);
return aPrin->Equals(appPrin) ? status
: nsIPrincipal::APP_STATUS_NOT_INSTALLED;
return nsIPrincipal::APP_STATUS_NOT_INSTALLED;
}

/*
Expand Down
8 changes: 3 additions & 5 deletions devtools/server/actors/webconsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,9 @@ WebConsoleActor.prototype =

let startedListeners = [];
let window = !this.parentActor.isRootActor ? this.window : null;
let appId = null;
let messageManager = null;

if (this._parentIsContentActor) {
appId = this.parentActor.docShell.appId;
messageManager = this.parentActor.messageManager;
}

Expand Down Expand Up @@ -604,16 +602,16 @@ WebConsoleActor.prototype =
// Create a StackTraceCollector that's going to be shared both by the
// NetworkMonitorChild (getting messages about requests from parent) and
// by the NetworkMonitor that directly watches service workers requests.
this.stackTraceCollector = new StackTraceCollector({ window, appId });
this.stackTraceCollector = new StackTraceCollector({ window });
this.stackTraceCollector.init();

let processBoundary = Services.appinfo.processType !=
Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
if ((appId || messageManager) && processBoundary) {
if (messageManager && processBoundary) {
// Start a network monitor in the parent process to listen to
// most requests than happen in parent
this.networkMonitor =
new NetworkMonitorChild(appId, this.parentActor.outerWindowID,
new NetworkMonitorChild(this.parentActor.outerWindowID,
messageManager, this.conn, this);
this.networkMonitor.init();
// Spawn also one in the child to listen to service workers
Expand Down
8 changes: 4 additions & 4 deletions devtools/shared/layout/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ function getTopWindow(win) {
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);

if (!docShell.isMozBrowserOrApp) {
if (!docShell.isMozBrowser) {
return win.top;
}

let topDocShell =
docShell.getSameTypeRootTreeItemIgnoreBrowserAndAppBoundaries();
docShell.getSameTypeRootTreeItemIgnoreBrowserBoundaries();

return topDocShell
? topDocShell.contentViewer.DOMDocument.defaultView
Expand Down Expand Up @@ -98,12 +98,12 @@ function getParentWindow(win) {
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);

if (!docShell.isMozBrowserOrApp) {
if (!docShell.isMozBrowser) {
return win.parent;
}

let parentDocShell =
docShell.getSameTypeParentIgnoreBrowserAndAppBoundaries();
docShell.getSameTypeParentIgnoreBrowserBoundaries();

return parentDocShell
? parentDocShell.contentViewer.DOMDocument.defaultView
Expand Down
7 changes: 1 addition & 6 deletions devtools/shared/webconsole/network-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1551,8 +1551,6 @@ NetworkMonitor.prototype = {
* data to the WebConsoleActor or to a NetworkEventActor.
*
* @constructor
* @param number appId
* The web appId of the child process.
* @param number outerWindowID
* The outerWindowID of the TabActor's main window.
* @param nsIMessageManager messageManager
Expand All @@ -1562,8 +1560,7 @@ NetworkMonitor.prototype = {
* @param object owner
* The WebConsoleActor that is listening for the network requests.
*/
function NetworkMonitorChild(appId, outerWindowID, messageManager, conn, owner) {
this.appId = appId;
function NetworkMonitorChild(outerWindowID, messageManager, conn, owner) {
this.outerWindowID = outerWindowID;
this.conn = conn;
this.owner = owner;
Expand All @@ -1577,7 +1574,6 @@ function NetworkMonitorChild(appId, outerWindowID, messageManager, conn, owner)
exports.NetworkMonitorChild = NetworkMonitorChild;

NetworkMonitorChild.prototype = {
appId: null,
owner: null,
_netEvents: null,
_saveRequestAndResponseBodies: true,
Expand Down Expand Up @@ -1623,7 +1619,6 @@ NetworkMonitorChild.prototype = {
mm.addMessageListener(`${this._msgName}:newEvent`, this._onNewEvent);
mm.addMessageListener(`${this._msgName}:updateEvent`, this._onUpdateEvent);
mm.sendAsyncMessage(this._msgName, {
appId: this.appId,
outerWindowID: this.outerWindowID,
action: "start",
});
Expand Down
22 changes: 0 additions & 22 deletions docshell/base/LoadContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,6 @@ LoadContext::SetRemoteTabs(bool aUseRemoteTabs)
return NS_ERROR_UNEXPECTED;
}

NS_IMETHODIMP
LoadContext::GetIsInIsolatedMozBrowserElement(bool* aIsInIsolatedMozBrowserElement)
{
MOZ_ASSERT(mIsNotNull);

NS_ENSURE_ARG_POINTER(aIsInIsolatedMozBrowserElement);

*aIsInIsolatedMozBrowserElement = mOriginAttributes.mInIsolatedMozBrowser;
return NS_OK;
}

NS_IMETHODIMP
LoadContext::GetAppId(uint32_t* aAppId)
{
MOZ_ASSERT(mIsNotNull);

NS_ENSURE_ARG_POINTER(aAppId);

*aAppId = mOriginAttributes.mAppId;
return NS_OK;
}

NS_IMETHODIMP
LoadContext::GetOriginAttributes(JS::MutableHandleValue aAttrs)
{
Expand Down
4 changes: 0 additions & 4 deletions docshell/base/LoadContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class LoadContext final
NS_DECL_NSILOADCONTEXT
NS_DECL_NSIINTERFACEREQUESTOR

// appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
// provided by child process.
LoadContext(const IPC::SerializedLoadContext& aToCopy,
dom::Element* aTopFrameElement,
DocShellOriginAttributes& aAttrs)
Expand All @@ -54,8 +52,6 @@ class LoadContext final
{
}

// appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
// provided by child process.
LoadContext(const IPC::SerializedLoadContext& aToCopy,
uint64_t aNestedFrameId,
DocShellOriginAttributes& aAttrs)
Expand Down
2 changes: 1 addition & 1 deletion docshell/base/nsDSURIContentListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ nsDSURIContentListener::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
curDocShellItem->GetParent(getter_AddRefs(parentDocShellItem))) &&
parentDocShellItem) {
nsCOMPtr<nsIDocShell> curDocShell = do_QueryInterface(curDocShellItem);
if (curDocShell && curDocShell->GetIsMozBrowserOrApp()) {
if (curDocShell && curDocShell->GetIsMozBrowser()) {
break;
}

Expand Down
Loading

0 comments on commit 01a1a85

Please sign in to comment.