Bug 653065 - Make the lightweight theme web installer ready for e10s. r=mconley

This commit is contained in:
Jimmy Wang 2015-07-14 11:42:02 -07:00
Родитель c18e1226b8
Коммит ba032ec59b
5 изменённых файлов: 143 добавлений и 87 удалений

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

@ -397,58 +397,73 @@ const gXPInstallObserver = {
};
var LightWeightThemeWebInstaller = {
init: function () {
let mm = window.messageManager;
mm.addMessageListener("LightWeightThemeWebInstaller:Install", this);
mm.addMessageListener("LightWeightThemeWebInstaller:Preview", this);
mm.addMessageListener("LightWeightThemeWebInstaller:ResetPreview", this);
},
receiveMessage: function (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.baseURI);
break;
}
case "LightWeightThemeWebInstaller:Preview": {
this._preview(data.themeData, data.baseURI);
break;
}
case "LightWeightThemeWebInstaller:ResetPreview": {
this._resetPreview(data && data.baseURI);
break;
}
}
},
handleEvent: function (event) {
switch (event.type) {
case "InstallBrowserTheme":
case "PreviewBrowserTheme":
case "ResetBrowserThemePreview":
// ignore requests from background tabs
if (event.target.ownerDocument.defaultView.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":
case "TabSelect": {
this._resetPreview();
break;
}
}
},
get _manager () {
var temp = {};
let temp = {};
Cu.import("resource://gre/modules/LightweightThemeManager.jsm", temp);
delete this._manager;
return this._manager = temp.LightweightThemeManager;
},
_installRequest: function (event) {
var node = event.target;
var data = this._getThemeFromNode(node);
if (!data)
return;
_installRequest: function (dataString, baseURI) {
let data = this._manager.parseTheme(dataString, baseURI);
if (this._isAllowed(node)) {
if (!data) {
return;
}
if (this._isAllowed(baseURI)) {
this._install(data);
return;
}
var allowButtonText =
let allowButtonText =
gNavigatorBundle.getString("lwthemeInstallRequest.allowButton");
var allowButtonAccesskey =
let allowButtonAccesskey =
gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey");
var message =
let message =
gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message",
[node.ownerDocument.location.host]);
var buttons = [{
[makeURI(baseURI).host]);
let buttons = [{
label: allowButtonText,
accessKey: allowButtonAccesskey,
callback: function () {
@ -458,8 +473,8 @@ var LightWeightThemeWebInstaller = {
this._removePreviousNotifications();
var notificationBox = gBrowser.getNotificationBox();
var notificationBar =
let notificationBox = gBrowser.getNotificationBox();
let notificationBar =
notificationBox.appendNotification(message, "lwtheme-install-request", "",
notificationBox.PRIORITY_INFO_MEDIUM,
buttons);
@ -467,12 +482,13 @@ var LightWeightThemeWebInstaller = {
},
_install: function (newLWTheme) {
var previousLWTheme = this._manager.currentTheme;
let previousLWTheme = this._manager.currentTheme;
var listener = {
let listener = {
onEnabling: function(aAddon, aRequiresRestart) {
if (!aRequiresRestart)
if (!aRequiresRestart) {
return;
}
let messageString = gNavigatorBundle.getFormattedString("lwthemeNeedsRestart.message",
[aAddon.name], 1);
@ -509,7 +525,7 @@ var LightWeightThemeWebInstaller = {
return gNavigatorBundle.getString("lwthemePostInstallNotification." + id);
}
var buttons = [{
let buttons = [{
label: text("undoButton"),
accessKey: text("undoButton.accesskey"),
callback: function () {
@ -526,8 +542,8 @@ var LightWeightThemeWebInstaller = {
this._removePreviousNotifications();
var notificationBox = gBrowser.getNotificationBox();
var notificationBar =
let notificationBox = gBrowser.getNotificationBox();
let notificationBar =
notificationBox.appendNotification(text("message"),
"lwtheme-install-notification", "",
notificationBox.PRIORITY_INFO_MEDIUM,
@ -537,62 +553,54 @@ var LightWeightThemeWebInstaller = {
},
_removePreviousNotifications: function () {
var box = gBrowser.getNotificationBox();
let box = gBrowser.getNotificationBox();
["lwtheme-install-request",
"lwtheme-install-notification"].forEach(function (value) {
var notification = box.getNotificationWithValue(value);
let notification = box.getNotificationWithValue(value);
if (notification)
box.removeNotification(notification);
});
},
_previewWindow: null,
_preview: function (event) {
if (!this._isAllowed(event.target))
_preview: function (dataString, baseURI) {
if (!this._isAllowed(baseURI))
return;
var data = this._getThemeFromNode(event.target);
let data = this._manager.parseTheme(dataString, baseURI);
if (!data)
return;
this._resetPreview();
this._previewWindow = event.target.ownerDocument.defaultView;
this._previewWindow.addEventListener("pagehide", this, true);
gBrowser.tabContainer.addEventListener("TabSelect", this, false);
this._manager.previewTheme(data);
},
_resetPreview: function (event) {
if (!this._previewWindow ||
event && !this._isAllowed(event.target))
_resetPreview: function (baseURI) {
if (baseURI && !this._isAllowed(baseURI))
return;
this._previewWindow.removeEventListener("pagehide", this, true);
this._previewWindow = null;
gBrowser.tabContainer.removeEventListener("TabSelect", this, false);
this._manager.resetPreview();
},
_isAllowed: function (node) {
var pm = Services.perms;
var uri = node.ownerDocument.documentURIObject;
if (!uri.schemeIs("https"))
_isAllowed: function (srcURIString) {
let uri;
try {
uri = makeURI(srcURIString);
}
catch(e) {
//makeURI fails if srcURIString is a nonsense URI
return false;
}
if (!uri.schemeIs("https")) {
return false;
}
let pm = Services.perms;
return pm.testPermission(uri, "install") == pm.ALLOW_ACTION;
},
_getThemeFromNode: function (node) {
return this._manager.parseTheme(node.getAttribute("data-browsertheme"),
node.baseURI);
}
}
};
/*
* Listen for Lightweight Theme styling changes and update the browser's theme accordingly.

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

@ -1372,9 +1372,7 @@ var gBrowserInit = {
placesContext.addEventListener("popuphiding", updateEditUIVisibility, false);
#endif
gBrowser.mPanelContainer.addEventListener("InstallBrowserTheme", LightWeightThemeWebInstaller, false, true);
gBrowser.mPanelContainer.addEventListener("PreviewBrowserTheme", LightWeightThemeWebInstaller, false, true);
gBrowser.mPanelContainer.addEventListener("ResetBrowserThemePreview", LightWeightThemeWebInstaller, false, true);
LightWeightThemeWebInstaller.init();
if (Win7Features)
Win7Features.onOpenWindow();

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

@ -717,6 +717,57 @@ addMessageListener("ContextMenu:SearchFieldBookmarkData", (message) => {
{ spec, title, description, postData, charset });
});
let LightWeightThemeWebInstallListener = {
_previewWindow: null,
init: function() {
addEventListener("InstallBrowserTheme", this, false, true);
addEventListener("PreviewBrowserTheme", this, false, true);
addEventListener("ResetBrowserThemePreview", this, false, true);
},
handleEvent: function (event) {
switch (event.type) {
case "InstallBrowserTheme": {
sendAsyncMessage("LightWeightThemeWebInstaller:Install", {
baseURI: event.target.baseURI,
themeData: event.target.getAttribute("data-browsertheme"),
});
break;
}
case "PreviewBrowserTheme": {
sendAsyncMessage("LightWeightThemeWebInstaller:Preview", {
baseURI: event.target.baseURI,
themeData: event.target.getAttribute("data-browsertheme"),
});
this._previewWindow = event.target.ownerDocument.defaultView;
this._previewWindow.addEventListener("pagehide", this, true);
break;
}
case "pagehide": {
sendAsyncMessage("LightWeightThemeWebInstaller:ResetPreview");
this._resetPreviewWindow();
break;
}
case "ResetBrowserThemePreview": {
if (this._previewWindow) {
sendAsyncMessage("LightWeightThemeWebInstaller:ResetPreview",
{baseURI: event.target.baseURI});
this._resetPreviewWindow();
}
break;
}
}
},
_resetPreviewWindow: function () {
this._previewWindow.removeEventListener("pagehide", this, true);
this._previewWindow = null;
}
};
LightWeightThemeWebInstallListener.init();
function disableSetDesktopBackground(aTarget) {
// Disable the Set as Desktop Background menu item if we're still trying
// to load the image or the load failed.

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

@ -227,7 +227,6 @@ skip-if = toolkit != "cocoa"
[browser_bug585830.js]
[browser_bug590206.js]
[browser_bug592338.js]
skip-if = e10s # Bug 653065 - Make the lightweight theme web installer ready for e10s
[browser_bug594131.js]
[browser_bug595507.js]
[browser_bug596687.js]

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

@ -30,8 +30,7 @@ function test_install_http() {
gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
executeSoon(function() {
var link = gBrowser.contentDocument.getElementById("theme-install");
EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow);
BrowserTestUtils.synthesizeMouse("#theme-install", 2, 2, {}, gBrowser.selectedBrowser);
is(LightweightThemeManager.currentTheme, null, "Should not have installed the test theme");
@ -57,19 +56,21 @@ function test_install_lwtheme() {
gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
executeSoon(function() {
var link = gBrowser.contentDocument.getElementById("theme-install");
EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow);
BrowserTestUtils.synthesizeMouse("#theme-install", 2, 2, {}, gBrowser.selectedBrowser);
let notification;
let notificationBox = gBrowser.getNotificationBox(gBrowser.selectedBrowser);
waitForCondition(
() => (notification = notificationBox.getNotificationWithValue("lwtheme-install-notification")),
() => {
is(LightweightThemeManager.currentTheme.id, "test", "Should have installed the test theme");
is(LightweightThemeManager.currentTheme.id, "test", "Should have installed the test theme");
LightweightThemeManager.currentTheme = null;
gBrowser.removeTab(gBrowser.selectedTab);
Services.perms.remove(makeURI("http://example.com/"), "install");
LightweightThemeManager.currentTheme = null;
gBrowser.removeTab(gBrowser.selectedTab);
Services.perms.remove(makeURI("http://example.com/"), "install");
runNextTest();
});
runNextTest();
}
);
}, false);
},
@ -92,7 +93,6 @@ function test_lwtheme_switch_theme() {
gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
executeSoon(function() {
var link = gBrowser.contentDocument.getElementById("theme-install");
wait_for_notification(function(aPanel) {
is(LightweightThemeManager.currentTheme, null, "Should not have installed the test lwtheme");
ok(aAddon.isActive, "Test theme should still be active");
@ -110,7 +110,7 @@ function test_lwtheme_switch_theme() {
runNextTest();
});
EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow);
BrowserTestUtils.synthesizeMouse("#theme-install", 2, 2, {}, gBrowser.selectedBrowser);
});
}, false);
});