Bug 1525511: Part 1 - Remove LWT install gunk. r=aswan

Differential Revision: https://phabricator.services.mozilla.com/D18781

--HG--
extra : rebase_source : cfd98054b2098bc4fee6eeea0736bcd42a036bcf
This commit is contained in:
Kris Maglione 2019-02-05 21:29:58 -08:00
Родитель 2b16bbc8e9
Коммит e7796b70b4
7 изменённых файлов: 13 добавлений и 337 удалений

Просмотреть файл

@ -1,51 +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/. */
var EXPORTED_SYMBOLS = ["LightWeightThemeInstallChild"];
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
class LightWeightThemeInstallChild extends ActorChild {
handleEvent(event) {
let {mm} = this;
switch (event.type) {
case "InstallBrowserTheme": {
mm.sendAsyncMessage("LightWeightThemeWebInstaller:Install", {
baseURI: event.target.baseURI,
principal: event.target.nodePrincipal,
themeData: event.target.getAttribute("data-browsertheme"),
});
break;
}
case "PreviewBrowserTheme": {
mm.sendAsyncMessage("LightWeightThemeWebInstaller:Preview", {
baseURI: event.target.baseURI,
principal: event.target.nodePrincipal,
themeData: event.target.getAttribute("data-browsertheme"),
});
this._previewWindow = event.target.ownerGlobal;
this._previewWindow.addEventListener("pagehide", this, true);
break;
}
case "pagehide": {
mm.sendAsyncMessage("LightWeightThemeWebInstaller:ResetPreview");
this._resetPreviewWindow();
break;
}
case "ResetBrowserThemePreview": {
if (this._previewWindow) {
mm.sendAsyncMessage("LightWeightThemeWebInstaller:ResetPreview",
{principal: event.target.nodePrincipal});
this._resetPreviewWindow();
}
break;
}
}
}
_resetPreviewWindow() {
this._previewWindow.removeEventListener("pagehide", this, true);
this._previewWindow = null;
}
}

Просмотреть файл

@ -10,9 +10,6 @@ with Files("**"):
with Files("LightweightThemeChild.jsm"):
BUG_COMPONENT = ("WebExtensions", "Themes")
with Files("LightWeightThemeInstallChild.jsm"):
BUG_COMPONENT = ("Firefox", "Theme")
with Files("PageInfoChild.jsm"):
BUG_COMPONENT = ("Firefox", "Page Info Window")
@ -35,7 +32,6 @@ FINAL_TARGET_FILES.actors += [
'DOMFullscreenChild.jsm',
'FormValidationChild.jsm',
'LightweightThemeChild.jsm',
'LightWeightThemeInstallChild.jsm',
'LinkHandlerChild.jsm',
'NetErrorChild.jsm',
'OfflineAppsChild.jsm',

Просмотреть файл

@ -671,156 +671,3 @@ var gExtensionsNotifications = {
}
},
};
var LightWeightThemeWebInstaller = {
init() {
let mm = window.messageManager;
mm.addMessageListener("LightWeightThemeWebInstaller:Install", this);
mm.addMessageListener("LightWeightThemeWebInstaller:Preview", this);
mm.addMessageListener("LightWeightThemeWebInstaller:ResetPreview", this);
XPCOMUtils.defineLazyPreferenceGetter(this, "_apiTesting", "extensions.webapi.testing", false);
},
receiveMessage(message) {
// ignore requests from background tabs
if (message.target != gBrowser.selectedBrowser) {
return;
}
let data = message.data;
switch (message.name) {
case "LightWeightThemeWebInstaller:Install": {
this._installRequest(data.themeData, data.principal, data.baseURI);
break;
}
case "LightWeightThemeWebInstaller:Preview": {
this._preview(data.themeData, data.principal, data.baseURI);
break;
}
case "LightWeightThemeWebInstaller:ResetPreview": {
this._resetPreview(data && data.principal);
break;
}
}
},
handleEvent(event) {
switch (event.type) {
case "TabSelect": {
this._resetPreview();
break;
}
}
},
get _manager() {
let temp = {};
ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm", temp);
delete this._manager;
return this._manager = temp.LightweightThemeManager;
},
_installRequest(dataString, principal, baseURI) {
// Don't allow installing off null principals.
if (!principal.URI) {
return;
}
let data = this._manager.parseTheme(dataString, baseURI);
if (!data) {
return;
}
// A notification bar with the option to undo is normally shown after a
// theme is installed. But the discovery pane served from the url(s)
// below has its own toggle switch for quick undos, so don't show the
// notification in that case.
let notify = this._shouldShowUndoPrompt(principal);
if (this._isAllowed(principal)) {
this._install(data, notify);
return;
}
let strings = {
header: gNavigatorBundle.getFormattedString("webextPerms.header", ["<>"]),
addonName: data.name,
text: gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message2",
[principal.URI.host]),
acceptText: gNavigatorBundle.getString("lwthemeInstallRequest.allowButton2"),
acceptKey: gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey2"),
cancelText: gNavigatorBundle.getString("webextPerms.cancel.label"),
cancelKey: gNavigatorBundle.getString("webextPerms.cancel.accessKey"),
msgs: [],
};
ExtensionsUI.showPermissionsPrompt(gBrowser.selectedBrowser, strings, null,
"installWeb").then(answer => {
if (answer) {
LightWeightThemeWebInstaller._install(data, notify);
}
});
},
_install(newLWTheme, notify) {
let listener = {
onEnabled(aAddon) {
if (notify) {
ExtensionsUI.showInstallNotification(gBrowser.selectedBrowser, newLWTheme);
}
},
};
AddonManager.addAddonListener(listener);
this._manager.currentTheme = newLWTheme;
AddonManager.removeAddonListener(listener);
},
_preview(dataString, principal, baseURI) {
if (!this._isAllowed(principal))
return;
let data = this._manager.parseTheme(dataString, baseURI);
if (!data)
return;
this._resetPreview();
gBrowser.tabContainer.addEventListener("TabSelect", this);
this._manager.previewTheme(data);
},
_resetPreview(principal) {
if (!this._isAllowed(principal))
return;
gBrowser.tabContainer.removeEventListener("TabSelect", this);
this._manager.resetPreview();
},
_isAllowed(principal) {
if (!principal || !principal.URI || !principal.URI.schemeIs("https")) {
return false;
}
let pm = Services.perms;
return pm.testPermission(principal.URI, "install") == pm.ALLOW_ACTION;
},
_shouldShowUndoPrompt(principal) {
if (!principal || !principal.URI) {
return true;
}
let prePath = principal.URI.prePath;
if (prePath == "https://discovery.addons.mozilla.org") {
return false;
}
if (this._apiTesting && (prePath == "https://discovery.addons.allizom.org" ||
prePath == "https://discovery.addons-dev.allizom.org")) {
return false;
}
return true;
},
};

Просмотреть файл

@ -2,6 +2,10 @@
* 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/. */
ChromeUtils.defineModuleGetter(
this, "LightweightThemeManager",
"resource://gre/modules/LightweightThemeManager.jsm");
/**
* Enables compacttheme.css when needed.
*/

Просмотреть файл

@ -31,7 +31,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
FormValidationHandler: "resource:///modules/FormValidationHandler.jsm",
HomePage: "resource:///modules/HomePage.jsm",
LightweightThemeConsumer: "resource://gre/modules/LightweightThemeConsumer.jsm",
LightweightThemeManager: "resource://gre/modules/LightweightThemeManager.jsm",
Log: "resource://gre/modules/Log.jsm",
LoginManagerParent: "resource://gre/modules/LoginManagerParent.jsm",
MigrationUtils: "resource:///modules/MigrationUtils.jsm",
@ -102,8 +101,7 @@ XPCOMUtils.defineLazyScriptGetter(this, "gViewSourceUtils",
"chrome://global/content/viewSourceUtils.js");
XPCOMUtils.defineLazyScriptGetter(this, "gTabsPanel",
"chrome://browser/content/browser-allTabsMenu.js");
XPCOMUtils.defineLazyScriptGetter(this, ["LightWeightThemeWebInstaller",
"gExtensionsNotifications",
XPCOMUtils.defineLazyScriptGetter(this, ["gExtensionsNotifications",
"gXPInstallObserver"],
"chrome://browser/content/browser-addons.js");
XPCOMUtils.defineLazyScriptGetter(this, "ctrlTab",
@ -1654,8 +1652,6 @@ var gBrowserInit = {
placesContext.addEventListener("popuphiding", updateEditUIVisibility);
}
LightWeightThemeWebInstaller.init();
FullScreen.init();
PointerLock.init();

Просмотреть файл

@ -132,17 +132,6 @@ let ACTORS = {
},
},
LightWeightThemeInstall: {
child: {
module: "resource:///actors/LightWeightThemeInstallChild.jsm",
events: {
"InstallBrowserTheme": {wantUntrusted: true},
"PreviewBrowserTheme": {wantUntrusted: true},
"ResetBrowserThemePreview": {wantUntrusted: true},
},
},
},
LightweightTheme: {
child: {
module: "resource:///actors/LightweightThemeChild.jsm",

Просмотреть файл

@ -532,7 +532,7 @@ var BrowserApp = {
Telemetry.addData("FENNEC_TRACKING_PROTECTION_STATE", parseInt(BrowserApp.getTrackingProtectionState()));
});
InitLater(() => LightWeightThemeWebInstaller.init());
InitLater(() => LightWeightThemeStuff.init());
InitLater(() => CastingApps.init(), window, "CastingApps");
// Bug 778855 - Perf regression if we do this here. To be addressed in bug 779008.
@ -3274,14 +3274,11 @@ ChromeUtils.defineModuleGetter(this, "PageActions",
});
});
var LightWeightThemeWebInstaller = {
var LightWeightThemeStuff = {
init: function sh_init() {
let temp = {};
ChromeUtils.import("resource://gre/modules/LightweightThemeConsumer.jsm", temp);
let theme = new temp.LightweightThemeConsumer(document);
BrowserApp.deck.addEventListener("InstallBrowserTheme", this, false, true);
BrowserApp.deck.addEventListener("PreviewBrowserTheme", this, false, true);
BrowserApp.deck.addEventListener("ResetBrowserThemePreview", this, false, true);
let {LightweightThemeConsumer} =
ChromeUtils.import("resource://gre/modules/LightweightThemeConsumer.jsm");
new LightweightThemeConsumer(document);
if (ParentalControls.parentalControlsEnabled &&
!this._manager.currentTheme &&
@ -3291,38 +3288,11 @@ var LightWeightThemeWebInstaller = {
}
},
handleEvent: function (event) {
switch (event.type) {
case "InstallBrowserTheme":
case "PreviewBrowserTheme":
case "ResetBrowserThemePreview":
// ignore requests from background tabs
if (event.target.ownerGlobal.top != content)
return;
}
switch (event.type) {
case "InstallBrowserTheme":
this._installRequest(event);
break;
case "PreviewBrowserTheme":
this._preview(event);
break;
case "ResetBrowserThemePreview":
this._resetPreview(event);
break;
case "pagehide":
case "TabSelect":
this._resetPreview();
break;
}
},
get _manager () {
let temp = {};
ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm", temp);
let {LightweightThemeManager} =
ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm");
delete this._manager;
return this._manager = temp.LightweightThemeManager;
return this._manager = LightweightThemeManager;
},
_installParentalControlsTheme: function() {
@ -3336,81 +3306,6 @@ var LightWeightThemeWebInstaller = {
mgr.addBuiltInTheme(parentalControlsTheme);
mgr.themeChanged(parentalControlsTheme);
},
_installRequest: function (event) {
let node = event.target;
let data = this._getThemeFromNode(node);
if (!data)
return;
if (this._isAllowed(node)) {
this._install(data);
return;
}
let allowButtonText = Strings.browser.GetStringFromName("lwthemeInstallRequest.allowButton");
let IDNService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
let hostname = IDNService.convertToDisplayIDN(node.ownerDocument.location.hostname, {});
let message = Strings.browser.formatStringFromName("lwthemeInstallRequest.message", [hostname], 1);
let buttons = [{
label: allowButtonText,
callback: function () {
LightWeightThemeWebInstaller._install(data);
},
positive: true
}];
NativeWindow.doorhanger.show(message, "Personas", buttons, BrowserApp.selectedTab.id);
},
_install: function (newLWTheme) {
this._manager.currentTheme = newLWTheme;
},
_previewWindow: null,
_preview: function (event) {
if (!this._isAllowed(event.target))
return;
let data = this._getThemeFromNode(event.target);
if (!data)
return;
this._resetPreview();
this._previewWindow = event.target.ownerGlobal;
this._previewWindow.addEventListener("pagehide", this, true);
BrowserApp.deck.addEventListener("TabSelect", this);
this._manager.previewTheme(data);
},
_resetPreview: function (event) {
if (!this._previewWindow ||
event && !this._isAllowed(event.target))
return;
this._previewWindow.removeEventListener("pagehide", this, true);
this._previewWindow = null;
BrowserApp.deck.removeEventListener("TabSelect", this);
this._manager.resetPreview();
},
_isAllowed: function (node) {
// Make sure the whitelist has been imported to permissions
PermissionsUtils.importFromPrefs("xpinstall.", "install");
let pm = Services.perms;
let uri = node.ownerDocument.documentURIObject;
if (!uri.schemeIs("https")) {
return false;
}
return pm.testPermission(uri, "install") == pm.ALLOW_ACTION;
},
_getThemeFromNode: function (node) {
return this._manager.parseTheme(node.getAttribute("data-browsertheme"), node.baseURI);
}
};
var DesktopUserAgent = {