From 2680a1d8e9e0c94255060d3c97195a4c3473c130 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 13 Oct 2016 23:51:14 -0400 Subject: [PATCH 01/13] Bug 1310097 - Remove MessageBroadcaster.jsm; r=myk --- dom/apps/MessageBroadcaster.jsm | 132 -------------------------------- dom/apps/moz.build | 1 - 2 files changed, 133 deletions(-) delete mode 100644 dom/apps/MessageBroadcaster.jsm diff --git a/dom/apps/MessageBroadcaster.jsm b/dom/apps/MessageBroadcaster.jsm deleted file mode 100644 index fe253d422c88..000000000000 --- a/dom/apps/MessageBroadcaster.jsm +++ /dev/null @@ -1,132 +0,0 @@ -/* 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/. */ - -"use strict"; - -// Manages registration of message managers from child processes and -// broadcasting messages to them. - -this.EXPORTED_SYMBOLS = ["MessageBroadcaster"]; - -this.MessageBroadcaster = { - appGetter: null, - children: [], - - init: function(aAppGetter) { - if (!aAppGetter || typeof aAppGetter !== "function") { - throw "MessageBroadcaster.init needs a function parameter"; - } - this.appGetter = aAppGetter; - }, - - // We manage refcounting of listeners per message manager. - addMessageListener: function(aMsgNames, aApp, aMm) { - aMsgNames.forEach(aMsgName => { - let manifestURL = aApp && aApp.manifestURL; - if (!(aMsgName in this.children)) { - this.children[aMsgName] = []; - } - - let mmFound = this.children[aMsgName].some(mmRef => { - if (mmRef.mm === aMm) { - mmRef.refCount++; - return true; - } - return false; - }); - - if (!mmFound) { - this.children[aMsgName].push({ - mm: aMm, - refCount: 1 - }); - } - - // If the state reported by the registration is outdated, update it now. - if (manifestURL && ((aMsgName === 'Webapps:FireEvent') || - (aMsgName === 'Webapps:UpdateState'))) { - let app = this.appGetter(aApp.manifestURL); - if (app && ((aApp.installState !== app.installState) || - (aApp.downloading !== app.downloading))) { - debug("Got a registration from an outdated app: " + - manifestURL); - let aEvent ={ - type: app.installState, - app: app, - manifestURL: app.manifestURL, - manifest: app.manifest - }; - aMm.sendAsyncMessage(aMsgName, aEvent); - } - } - }); - }, - - removeMessageListener: function(aMsgNames, aMm) { - if (aMsgNames.length === 1 && - aMsgNames[0] === "Webapps:Internal:AllMessages") { - for (let msgName in this.children) { - let msg = this.children[msgName]; - - for (let mmI = msg.length - 1; mmI >= 0; mmI -= 1) { - let mmRef = msg[mmI]; - if (mmRef.mm === aMm) { - msg.splice(mmI, 1); - } - } - - if (msg.length === 0) { - delete this.children[msgName]; - } - } - return; - } - - aMsgNames.forEach(aMsgName => { - if (!(aMsgName in this.children)) { - return; - } - - let removeIndex; - this.children[aMsgName].some((mmRef, index) => { - if (mmRef.mm === aMm) { - mmRef.refCount--; - if (mmRef.refCount === 0) { - removeIndex = index; - } - return true; - } - return false; - }); - - if (removeIndex) { - this.children[aMsgName].splice(removeIndex, 1); - } - }); - }, - - // Some messages can be listened by several content processes: - // Webapps:AddApp - // Webapps:RemoveApp - // Webapps:Install:Return:OK - // Webapps:Uninstall:Return:OK - // Webapps:Uninstall:Broadcast:Return:OK - // Webapps:FireEvent - // Webapps:checkForUpdate:Return:OK - // Webapps:UpdateState - broadcastMessage: function(aMsgName, aContent) { - if (!(aMsgName in this.children)) { - return; - } - this.children[aMsgName].forEach((mmRef) => { - mmRef.mm.sendAsyncMessage(aMsgName, this.formatMessage(aContent)); - }); - }, - - formatMessage: function(aData) { - let msg = aData; - delete msg["mm"]; - return msg; - }, -} diff --git a/dom/apps/moz.build b/dom/apps/moz.build index 9fdb7ac0eb48..a8150d6dbf27 100644 --- a/dom/apps/moz.build +++ b/dom/apps/moz.build @@ -17,7 +17,6 @@ EXTRA_COMPONENTS += [ EXTRA_JS_MODULES += [ 'AppsServiceChild.jsm', - 'MessageBroadcaster.jsm', 'PermissionsInstaller.jsm', 'PermissionsTable.jsm', 'UserCustomizations.jsm', From e2fdfd7548631f8a540b3e87e1c780a18b8ddff5 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 14 Oct 2016 19:29:35 -0400 Subject: [PATCH 02/13] Bug 1310366 - Remove support for app redirects; r=baku --- docshell/base/nsDocShell.cpp | 34 --------------------- docshell/base/nsDocShell.h | 6 ---- dom/apps/AppsService.js | 9 ------ dom/apps/AppsUtils.jsm | 1 - dom/apps/tests/unit/test_moziapplication.js | 1 - dom/interfaces/apps/nsIAppsService.idl | 6 ---- 6 files changed, 57 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 50f9a234b2d3..8d5fdd98845a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1253,10 +1253,6 @@ nsDocShell::LoadURI(nsIURI* aURI, return NS_OK; // JS may not handle returning of an error code } - if (DoAppRedirectIfNeeded(aURI, aLoadInfo, aFirstParty)) { - return NS_OK; - } - nsCOMPtr referrer; nsCOMPtr originalURI; bool loadReplace = false; @@ -6729,32 +6725,6 @@ nsDocShell::ForceRefreshURIFromTimer(nsIURI* aURI, return ForceRefreshURI(aURI, aDelay, aMetaRefresh); } -bool -nsDocShell::DoAppRedirectIfNeeded(nsIURI* aURI, - nsIDocShellLoadInfo* aLoadInfo, - bool aFirstParty) -{ - uint32_t appId = nsIDocShell::GetAppId(); - - if (appId != nsIScriptSecurityManager::NO_APP_ID && - appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) { - nsCOMPtr appsService = - do_GetService(APPS_SERVICE_CONTRACTID); - NS_ASSERTION(appsService, "No AppsService available"); - nsCOMPtr redirect; - nsresult rv = appsService->GetRedirect(appId, aURI, getter_AddRefs(redirect)); - if (NS_SUCCEEDED(rv) && redirect) { - rv = LoadURI(redirect, aLoadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, - aFirstParty); - if (NS_SUCCEEDED(rv)) { - return true; - } - } - } - - return false; -} - NS_IMETHODIMP nsDocShell::ForceRefreshURI(nsIURI* aURI, int32_t aDelay, bool aMetaRefresh) { @@ -7460,10 +7430,6 @@ nsDocShell::OnRedirectStateChange(nsIChannel* aOldChannel, return; } - if (DoAppRedirectIfNeeded(newURI, nullptr, false)) { - return; - } - // Below a URI visit is saved (see AddURIVisit method doc). // The visit chain looks something like: // ... diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index c83774ab05a8..ff57c5a95fb6 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -727,12 +727,6 @@ protected: // Convenience method for getting our parent docshell. Can return null already_AddRefed GetParentDocshell(); - // Check if we have an app redirect registered for the URI and redirect if - // needed. Returns true if a redirect happened, false otherwise. - bool DoAppRedirectIfNeeded(nsIURI* aURI, - nsIDocShellLoadInfo* aLoadInfo, - bool aFirstParty); - // Check if aURI is about:newtab. bool IsAboutNewtab(nsIURI* aURI); diff --git a/dom/apps/AppsService.js b/dom/apps/AppsService.js index 4d0c98a6185e..dde910923018 100644 --- a/dom/apps/AppsService.js +++ b/dom/apps/AppsService.js @@ -116,15 +116,6 @@ AppsService.prototype = { throw Cr.NS_ERROR_NOT_IMPLEMENTED; }, - getRedirect: function getRedirect(aLocalId, aURI) { - debug("getRedirect for " + aLocalId + " " + aURI.spec); - if (this.isInvalidId(aLocalId)) { - return null; - } - - throw Cr.NS_ERROR_NOT_IMPLEMENTED; - }, - getScopeByLocalId: function(aLocalId) { debug("getScopeByLocalId( " + aLocalId + " )"); if (this.isInvalidId(aLocalId)) { diff --git a/dom/apps/AppsUtils.jsm b/dom/apps/AppsUtils.jsm index b373fae55b3b..73e58e5bebd2 100644 --- a/dom/apps/AppsUtils.jsm +++ b/dom/apps/AppsUtils.jsm @@ -122,7 +122,6 @@ function _setAppProperties(aObj, aApp) { aObj.storeId = aApp.storeId || ""; aObj.storeVersion = aApp.storeVersion || 0; aObj.role = aApp.role || ""; - aObj.redirects = aApp.redirects; aObj.widgetPages = aApp.widgetPages || []; aObj.kind = aApp.kind; aObj.enabled = aApp.enabled !== undefined ? aApp.enabled : true; diff --git a/dom/apps/tests/unit/test_moziapplication.js b/dom/apps/tests/unit/test_moziapplication.js index cff329018b7f..dbcf2372a375 100644 --- a/dom/apps/tests/unit/test_moziapplication.js +++ b/dom/apps/tests/unit/test_moziapplication.js @@ -34,7 +34,6 @@ add_test(() => { storeId: "aStoreId", storeVersion: 1, role: "aRole", - redirects: "aRedirects", kind: "aKind", enabled: true, sideloaded: false diff --git a/dom/interfaces/apps/nsIAppsService.idl b/dom/interfaces/apps/nsIAppsService.idl index 3bb2af73ed0b..6b6b757679bd 100644 --- a/dom/interfaces/apps/nsIAppsService.idl +++ b/dom/interfaces/apps/nsIAppsService.idl @@ -73,12 +73,6 @@ interface nsIAppsService : nsISupports jsval getAppInfo(in DOMString appId); - /** - * Returns a URI to redirect to when we get a redirection to 'uri'. - * Returns null if no redirection is declared for this uri. - */ - nsIURI getRedirect(in unsigned long localId, in nsIURI uri); - /** * Returns the localId if the app was installed from a store */ From 4a51ebacfaf1fe8007ad636df29d119dd9fb13c9 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 14 Oct 2016 20:38:21 -0400 Subject: [PATCH 03/13] Bug 1310378 - Remove support for mozwidget; r=baku --- caps/nsPrincipal.cpp | 1 - docshell/base/nsDocShell.cpp | 30 ------- dom/apps/AppsUtils.jsm | 14 ---- dom/apps/PermissionsTable.jsm | 5 -- .../tests/unit/test_has_widget_criterion.js | 66 --------------- dom/apps/tests/unit/xpcshell.ini | 1 - dom/base/nsFrameLoader.cpp | 16 ---- dom/base/nsFrameLoader.h | 6 -- dom/base/nsGkAtomList.h | 1 - dom/base/nsIFrameLoader.idl | 6 -- .../BrowserElementChildPreload.js | 4 - dom/browser-element/BrowserElementParent.cpp | 7 -- dom/browser-element/BrowserElementParent.js | 11 +-- dom/html/nsBrowserElement.cpp | 34 -------- dom/html/nsBrowserElement.h | 4 +- dom/html/nsGenericHTMLFrameElement.cpp | 81 +++---------------- dom/html/nsGenericHTMLFrameElement.h | 2 +- dom/interfaces/apps/mozIApplication.idl | 6 -- dom/interfaces/html/nsIMozBrowserFrame.idl | 20 +---- modules/libpref/init/all.js | 2 +- 20 files changed, 18 insertions(+), 299 deletions(-) delete mode 100644 dom/apps/tests/unit/test_has_widget_criterion.js diff --git a/caps/nsPrincipal.cpp b/caps/nsPrincipal.cpp index 492cb674aed1..60885ab548b1 100644 --- a/caps/nsPrincipal.cpp +++ b/caps/nsPrincipal.cpp @@ -31,7 +31,6 @@ #include "mozilla/HashFunctions.h" #include "nsIAppsService.h" -#include "mozIApplication.h" using namespace mozilla; diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 8d5fdd98845a..3a736518caba 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -43,7 +43,6 @@ #include "nsIDOMStorage.h" #include "nsIContentViewer.h" #include "nsIDocumentLoaderFactory.h" -#include "nsIMozBrowserFrame.h" #include "nsCURILoader.h" #include "nsDocShellCID.h" #include "nsDOMCID.h" @@ -10774,35 +10773,6 @@ nsDocShell::DoURILoad(nsIURI* aURI, "DoURILoad thinks this is a document and InternalLoad does not"); } - - // For mozWidget, display a load error if we navigate to a page which is not - // claimed in |widgetPages|. - // When we go to display a load error for an invalid mozWidget page, we will - // try to load an about:neterror page, which is also an invalid mozWidget - // page. To avoid recursion, we skip this check if aURI's scheme is "about". - - // The goal is to prevent leaking sensitive information of an invalid page of - // an app, so allowing about:blank would not be conflict to the goal. - bool isAbout = false; - rv = aURI->SchemeIs("about", &isAbout); - if (NS_SUCCEEDED(rv) && !isAbout && - nsIDocShell::GetIsApp()) { - nsCOMPtr frameElement = mScriptGlobal->AsOuter()->GetFrameElementInternal(); - if (frameElement) { - nsCOMPtr browserFrame = do_QueryInterface(frameElement); - // |GetReallyIsApp| indicates the browser frame is a valid app or widget. - // Here we prevent navigating to an app or widget which loses its validity - // by loading invalid page or other way. - if (browserFrame && !browserFrame->GetReallyIsApp()) { - nsCOMPtr serv = services::GetObserverService(); - if (serv) { - serv->NotifyObservers(GetDocument(), "invalid-widget", nullptr); - } - return NS_ERROR_MALFORMED_URI; - } - } - } - // open a channel for the url nsCOMPtr channel; diff --git a/dom/apps/AppsUtils.jsm b/dom/apps/AppsUtils.jsm index 73e58e5bebd2..6df9bbc84a0e 100644 --- a/dom/apps/AppsUtils.jsm +++ b/dom/apps/AppsUtils.jsm @@ -53,15 +53,6 @@ mozIApplication.prototype = { return (perm === Ci.nsIPermissionManager.ALLOW_ACTION); }, - hasWidgetPage: function(aPageURL) { - let uri = Services.io.newURI(aPageURL, null, null); - let filepath = AppsUtils.getFilePath(uri.path); - let eliminatedUri = Services.io.newURI(uri.prePath + filepath, null, null); - let equalCriterion = aUrl => Services.io.newURI(aUrl, null, null) - .equals(eliminatedUri); - return this.widgetPages.find(equalCriterion) !== undefined; - }, - get principal() { if (this._principal) { return this._principal; @@ -122,7 +113,6 @@ function _setAppProperties(aObj, aApp) { aObj.storeId = aApp.storeId || ""; aObj.storeVersion = aApp.storeVersion || 0; aObj.role = aApp.role || ""; - aObj.widgetPages = aApp.widgetPages || []; aObj.kind = aApp.kind; aObj.enabled = aApp.enabled !== undefined ? aApp.enabled : true; aObj.sideloaded = aApp.sideloaded; @@ -854,10 +844,6 @@ ManifestHelper.prototype = { return this._localeProp("package_path"); }, - get widgetPages() { - return this._localeProp("widgetPages"); - }, - get size() { return this._manifest["size"] || 0; }, diff --git a/dom/apps/PermissionsTable.jsm b/dom/apps/PermissionsTable.jsm index 13bd21871db8..8430c76567ed 100644 --- a/dom/apps/PermissionsTable.jsm +++ b/dom/apps/PermissionsTable.jsm @@ -268,11 +268,6 @@ this.PermissionsTable = { geolocation: { privileged: DENY_ACTION, certified: ALLOW_ACTION }, - "embed-widgets": { - app: DENY_ACTION, - privileged: ALLOW_ACTION, - certified: ALLOW_ACTION - }, "background-sensors": { app: DENY_ACTION, privileged: DENY_ACTION, diff --git a/dom/apps/tests/unit/test_has_widget_criterion.js b/dom/apps/tests/unit/test_has_widget_criterion.js deleted file mode 100644 index 31ef90e90630..000000000000 --- a/dom/apps/tests/unit/test_has_widget_criterion.js +++ /dev/null @@ -1,66 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -var {classes: Cc, interfaces: Ci, utils: Cu} = Components; - -Cu.import("resource:///modules/AppsUtils.jsm"); -Cu.import("resource:///modules/Services.jsm"); - -add_test(function test_has_widget_criterion() { - - // follow the logic |_saveWidgetsFullPath| - let baseUri = Services.io.newURI('http://example.com', null, null); - let resolve = (aPage)=>{ - let filepath = AppsUtils.getFilePath(aPage); - - return baseUri.resolve(filepath); - }; - - let widgetPages = ['/widget.html', - '/foo/bar.html']; - let resolvedWidgetPages = widgetPages.map(resolve); - - let app = new mozIApplication({widgetPages:resolvedWidgetPages}); - - let widgetPageCheck = aPage => app.hasWidgetPage(baseUri.resolve(aPage)); - - Assert.ok(widgetPageCheck('/widget.html'), 'should pass for identical path'); - Assert.ok(widgetPageCheck('/foo/bar.html'), 'should pass for identical path'); - - Assert.ok(!widgetPageCheck('/wrong.html'), 'should not pass for wrong path'); - Assert.ok(!widgetPageCheck('/WIDGET.html'), 'should be case _sensitive_ for path'); - Assert.ok(!widgetPageCheck('/widget.HTML'), 'should be case _sensitive_ for file extension'); - - Assert.ok(widgetPageCheck('/widget.html?aQuery'), 'should be query insensitive'); - Assert.ok(widgetPageCheck('/widget.html#aHash'), 'should be hash insensitive'); - Assert.ok(widgetPageCheck('/widget.html?aQuery=aquery#aHash'), - 'should be hash/query insensitive'); - - Assert.ok(widgetPageCheck('HTTP://example.com/widget.html'), - 'should be case insensitive for protocol'); - Assert.ok(widgetPageCheck('http://EXAMPLE.COM/widget.html'), - 'should be case insensitive for domain'); - Assert.ok(widgetPageCheck('http://example.com:80/widget.html'), - 'should pass for default port'); - - Assert.ok(widgetPageCheck('HTTP://EXAMPLE.COM:80/widget.html?QueryA=queryA&QueryB=queryB#aHash'), - 'should pass for a really mess one'); - - Assert.ok(!widgetPageCheck('foo://example.com/widget.html'), - 'should not pass for wrong protocol'); - Assert.ok(!widgetPageCheck('https://example.com/widget.html'), - 'should not pass for wrong protocol'); - Assert.ok(!widgetPageCheck('/wrong/widget.html'), - 'should not pass for additional path'); - Assert.ok(!widgetPageCheck('/bar.html'), - 'should not pass for reduced path'); - Assert.ok(!widgetPageCheck('http://username:password@example.com/widget.html'), - 'should not pass for userinfo'); - Assert.ok(!widgetPageCheck('http://example.com:8080/widget.html'), - 'should not pass non-default port'); - run_next_test(); -}); - -function run_test() { - run_next_test(); -} diff --git a/dom/apps/tests/unit/xpcshell.ini b/dom/apps/tests/unit/xpcshell.ini index aa2af155cae4..9745b198f254 100644 --- a/dom/apps/tests/unit/xpcshell.ini +++ b/dom/apps/tests/unit/xpcshell.ini @@ -1,6 +1,5 @@ [DEFAULT] -[test_has_widget_criterion.js] [test_manifestSanitizer.js] [test_manifestHelper.js] [test_moziapplication.js] diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index 307a78e60308..b1a44e7905fe 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -1765,22 +1765,6 @@ nsFrameLoader::GetOwnerIsMozBrowserOrAppFrame(bool* aResult) return NS_OK; } -bool -nsFrameLoader::OwnerIsWidget() -{ - nsCOMPtr browserFrame = do_QueryInterface(mOwnerContent); - return browserFrame ? browserFrame->GetReallyIsWidget() : false; -} - - -// The xpcom getter version -NS_IMETHODIMP -nsFrameLoader::GetOwnerIsWidget(bool* aResult) -{ - *aResult = OwnerIsWidget(); - return NS_OK; -} - bool nsFrameLoader::OwnerIsAppFrame() { diff --git a/dom/base/nsFrameLoader.h b/dom/base/nsFrameLoader.h index fb820d734e52..6f9f14548e08 100644 --- a/dom/base/nsFrameLoader.h +++ b/dom/base/nsFrameLoader.h @@ -248,12 +248,6 @@ private: */ bool OwnerIsMozBrowserOrAppFrame(); - /** - * Is this a frameloader for a bona fide