[Pale-Moon] Issue #1737 - Part 1: Clean up base/content p.1

This commit is contained in:
Pale Moon 2020-03-07 12:20:40 +01:00 • committed by Roy Tam
commit 8b3b8034b9
6 changed files with 1354 additions and 1166 deletions

View file

@ -7,8 +7,9 @@ Components.utils.import("resource://gre/modules/Services.jsm");
function init(aEvent) function init(aEvent)
{ {
if (aEvent.target != document) if (aEvent.target != document) {
return; return;
}
try { try {
var distroId = Services.prefs.getCharPref("distribution.id"); var distroId = Services.prefs.getCharPref("distribution.id");
@ -22,18 +23,16 @@ function init(aEvent)
try { try {
// This is in its own try catch due to bug 895473 and bug 900925. // This is in its own try catch due to bug 895473 and bug 900925.
var distroAbout = Services.prefs.getComplexValue("distribution.about", var distroAbout = Services.prefs.getComplexValue("distribution.about",
Components.interfaces.nsISupportsString); Components.interfaces.nsISupportsString);
var distroField = document.getElementById("distribution"); var distroField = document.getElementById("distribution");
distroField.value = distroAbout; distroField.value = distroAbout;
distroField.style.display = "block"; distroField.style.display = "block";
} } catch (ex) {
catch (ex) {
// Pref is unset // Pref is unset
Components.utils.reportError(ex); Components.utils.reportError(ex);
} }
} }
} } catch (e) {
catch (e) {
// Pref is unset // Pref is unset
} }

View file

@ -17,10 +17,8 @@ var Cu = Components.utils;
// Services = object with smart getters for common XPCOM services // Services = object with smart getters for common XPCOM services
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
var browser_autoRecovery = var browser_autoRecovery = {
{
onLoad: function() { onLoad: function() {
var nsIAS = Ci.nsIAppStartup; // Application startup interface var nsIAS = Ci.nsIAppStartup; // Application startup interface
if (typeof gBrowser === "undefined") { if (typeof gBrowser === "undefined") {
@ -35,9 +33,9 @@ var browser_autoRecovery =
// gBrowser isn't defined, and we're not using a custom locale. Most likely // gBrowser isn't defined, and we're not using a custom locale. Most likely
// a user-installed add-on causes issues here, so we restart in Safe Mode. // a user-installed add-on causes issues here, so we restart in Safe Mode.
let RISM = Services.prompt.confirm(null, "Error", let RISM = Services.prompt.confirm(null, "Error",
"The Browser didn't start properly!\n"+ "The Browser didn't start properly!\n"+
"This is usually caused by an add-on or misconfiguration.\n\n"+ "This is usually caused by an add-on or misconfiguration.\n\n"+
"Restart in Safe Mode?"); "Restart in Safe Mode?");
if (RISM) { if (RISM) {
Cc["@mozilla.org/toolkit/app-startup;1"].getService(nsIAS).restartInSafeMode(nsIAS.eRestart | nsIAS.eAttemptQuit); Cc["@mozilla.org/toolkit/app-startup;1"].getService(nsIAS).restartInSafeMode(nsIAS.eRestart | nsIAS.eAttemptQuit);
} else { } else {

View file

@ -30,39 +30,40 @@ function removeNotificationOnEnd(notification, installs) {
} }
const gXPInstallObserver = { const gXPInstallObserver = {
_findChildShell: function (aDocShell, aSoughtShell) _findChildShell: function (aDocShell, aSoughtShell) {
{ if (aDocShell == aSoughtShell) {
if (aDocShell == aSoughtShell)
return aDocShell; return aDocShell;
}
var node = aDocShell.QueryInterface(Components.interfaces.nsIDocShellTreeItem); var node = aDocShell.QueryInterface(Components.interfaces.nsIDocShellTreeItem);
for (var i = 0; i < node.childCount; ++i) { for (var i = 0; i < node.childCount; ++i) {
var docShell = node.getChildAt(i); var docShell = node.getChildAt(i);
docShell = this._findChildShell(docShell, aSoughtShell); docShell = this._findChildShell(docShell, aSoughtShell);
if (docShell == aSoughtShell) if (docShell == aSoughtShell) {
return docShell; return docShell;
}
} }
return null; return null;
}, },
_getBrowser: function (aDocShell) _getBrowser: function (aDocShell) {
{
for (let browser of gBrowser.browsers) { for (let browser of gBrowser.browsers) {
if (this._findChildShell(browser.docShell, aDocShell)) if (this._findChildShell(browser.docShell, aDocShell)) {
return browser; return browser;
}
} }
return null; return null;
}, },
observe: function (aSubject, aTopic, aData) observe: function (aSubject, aTopic, aData) {
{
var brandBundle = document.getElementById("bundle_brand"); var brandBundle = document.getElementById("bundle_brand");
var installInfo = aSubject.QueryInterface(Components.interfaces.amIWebInstallInfo); var installInfo = aSubject.QueryInterface(Components.interfaces.amIWebInstallInfo);
var browser = installInfo.browser; var browser = installInfo.browser;
// Make sure the browser is still alive. // Make sure the browser is still alive.
if (!browser || gBrowser.browsers.indexOf(browser) == -1) if (!browser || gBrowser.browsers.indexOf(browser) == -1) {
return; return;
}
const anchorID = "addons-notification-icon"; const anchorID = "addons-notification-icon";
var messageString, action; var messageString, action;
@ -70,152 +71,153 @@ const gXPInstallObserver = {
var notificationID = aTopic; var notificationID = aTopic;
// Make notifications persist a minimum of 30 seconds // Make notifications persist a minimum of 30 seconds
var options = { var options = { timeout: Date.now() + 30000 };
timeout: Date.now() + 30000
};
switch (aTopic) { switch (aTopic) {
case "addon-install-disabled": case "addon-install-disabled":
notificationID = "xpinstall-disabled" notificationID = "xpinstall-disabled"
if (gPrefService.prefIsLocked("xpinstall.enabled")) { if (gPrefService.prefIsLocked("xpinstall.enabled")) {
messageString = gNavigatorBundle.getString("xpinstallDisabledMessageLocked"); messageString = gNavigatorBundle.getString("xpinstallDisabledMessageLocked");
buttons = []; buttons = [];
} } else {
else { messageString = gNavigatorBundle.getString("xpinstallDisabledMessage");
messageString = gNavigatorBundle.getString("xpinstallDisabledMessage");
action = { action = {
label: gNavigatorBundle.getString("xpinstallDisabledButton"), label: gNavigatorBundle.getString("xpinstallDisabledButton"),
accessKey: gNavigatorBundle.getString("xpinstallDisabledButton.accesskey"), accessKey: gNavigatorBundle.getString("xpinstallDisabledButton.accesskey"),
callback: function editPrefs() { callback: function editPrefs() {
gPrefService.setBoolPref("xpinstall.enabled", true); gPrefService.setBoolPref("xpinstall.enabled", true);
} }
}; };
}
PopupNotifications.show(browser, notificationID, messageString, anchorID,
action, null, options);
break;
case "addon-install-origin-blocked": {
messageString = gNavigatorBundle.getFormattedString("xpinstallPromptWarningOrigin",
[brandShortName]);
let popup = PopupNotifications.show(browser, notificationID,
messageString, anchorID,
null, null, options);
removeNotificationOnEnd(popup, installInfo.installs);
break; }
case "addon-install-blocked":
let originatingHost;
try {
originatingHost = installInfo.originatingURI.host;
} catch (ex) {
// Need to deal with missing originatingURI and with about:/data: URIs more gracefully,
// see bug 1063418 - but for now, bail:
return;
}
messageString = gNavigatorBundle.getFormattedString("xpinstallPromptWarning",
[brandShortName, originatingHost]);
action = {
label: gNavigatorBundle.getString("xpinstallPromptAllowButton"),
accessKey: gNavigatorBundle.getString("xpinstallPromptAllowButton.accesskey"),
callback: function() {
installInfo.install();
} }
};
let popup = PopupNotifications.show(browser, notificationID, messageString,
anchorID, action, null, options);
removeNotificationOnEnd(popup, installInfo.installs);
break;
case "addon-install-started":
var needsDownload = function needsDownload(aInstall) {
return aInstall.state != AddonManager.STATE_DOWNLOADED;
}
// If all installs have already been downloaded then there is no need to
// show the download progress
if (!installInfo.installs.some(needsDownload))
return;
notificationID = "addon-progress";
messageString = gNavigatorBundle.getString("addonDownloading");
messageString = PluralForm.get(installInfo.installs.length, messageString);
options.installs = installInfo.installs;
options.contentWindow = browser.contentWindow;
options.sourceURI = browser.currentURI;
options.eventCallback = function(aEvent) {
if (aEvent != "removed")
return;
options.contentWindow = null;
options.sourceURI = null;
};
PopupNotifications.show(browser, notificationID, messageString, anchorID,
null, null, options);
break;
case "addon-install-failed":
// TODO This isn't terribly ideal for the multiple failure case
for (let install of installInfo.installs) {
let host = (installInfo.originatingURI instanceof Ci.nsIStandardURL) &&
installInfo.originatingURI.host;
if (!host)
host = (install.sourceURI instanceof Ci.nsIStandardURL) &&
install.sourceURI.host;
let error = (host || install.error == 0) ? "addonError" : "addonLocalError";
if (install.error != 0)
error += install.error;
else if (install.addon.jetsdk)
error += "JetSDK";
else if (install.addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
error += "Blocklisted";
else
error += "Incompatible";
messageString = gNavigatorBundle.getString(error);
messageString = messageString.replace("#1", install.name);
if (host)
messageString = messageString.replace("#2", host);
messageString = messageString.replace("#3", brandShortName);
messageString = messageString.replace("#4", Services.appinfo.version);
PopupNotifications.show(browser, notificationID, messageString, anchorID, PopupNotifications.show(browser, notificationID, messageString, anchorID,
action, null, options); action, null, options);
} break;
break; case "addon-install-origin-blocked":
case "addon-install-complete": messageString = gNavigatorBundle.getFormattedString("xpinstallPromptWarningOrigin",
var needsRestart = installInfo.installs.some(function(i) { [brandShortName]);
return i.addon.pendingOperations != AddonManager.PENDING_NONE;
}); let popup = PopupNotifications.show(browser, notificationID,
messageString, anchorID,
null, null, options);
removeNotificationOnEnd(popup, installInfo.installs);
break;
case "addon-install-blocked":
let originatingHost;
try {
originatingHost = installInfo.originatingURI.host;
} catch(ex) {
// Need to deal with missing originatingURI and with about:/data: URIs more gracefully,
// see bug 1063418 - but for now, bail:
return;
}
messageString = gNavigatorBundle.getFormattedString("xpinstallPromptWarning",
[brandShortName, originatingHost]);
if (needsRestart) {
messageString = gNavigatorBundle.getString("addonsInstalledNeedsRestart");
action = { action = {
label: gNavigatorBundle.getString("addonInstallRestartButton"), label: gNavigatorBundle.getString("xpinstallPromptAllowButton"),
accessKey: gNavigatorBundle.getString("addonInstallRestartButton.accesskey"), accessKey: gNavigatorBundle.getString("xpinstallPromptAllowButton.accesskey"),
callback: function() { callback: function() {
Application.restart(); installInfo.install();
} }
}; };
}
else {
messageString = gNavigatorBundle.getString("addonsInstalled");
action = null;
}
messageString = PluralForm.get(installInfo.installs.length, messageString); let popup = PopupNotifications.show(browser, notificationID, messageString,
messageString = messageString.replace("#1", installInfo.installs[0].name); anchorID, action, null, options);
messageString = messageString.replace("#2", installInfo.installs.length); removeNotificationOnEnd(popup, installInfo.installs);
messageString = messageString.replace("#3", brandShortName); break;
case "addon-install-started":
var needsDownload = function needsDownload(aInstall) {
return aInstall.state != AddonManager.STATE_DOWNLOADED;
}
// If all installs have already been downloaded then there is no need to
// show the download progress
if (!installInfo.installs.some(needsDownload)) {
return;
}
notificationID = "addon-progress";
messageString = gNavigatorBundle.getString("addonDownloading");
messageString = PluralForm.get(installInfo.installs.length, messageString);
options.installs = installInfo.installs;
options.contentWindow = browser.contentWindow;
options.sourceURI = browser.currentURI;
options.eventCallback = function(aEvent) {
if (aEvent != "removed") {
return;
}
options.contentWindow = null;
options.sourceURI = null;
};
PopupNotifications.show(browser, notificationID, messageString, anchorID,
null, null, options);
break;
case "addon-install-failed":
// TODO This isn't terribly ideal for the multiple failure case
for (let install of installInfo.installs) {
let host = (installInfo.originatingURI instanceof Ci.nsIStandardURL) &&
installInfo.originatingURI.host;
if (!host) {
host = (install.sourceURI instanceof Ci.nsIStandardURL) &&
install.sourceURI.host;
}
// Remove notificaion on dismissal, since it's possible to cancel the let error = (host || install.error == 0) ? "addonError" : "addonLocalError";
// install through the addons manager UI, making the "restart" prompt if (install.error != 0) {
// irrelevant. error += install.error;
options.removeOnDismissal = true; } else if (install.addon.jetsdk) {
error += "JetSDK";
} else if (install.addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED) {
error += "Blocklisted";
} else {
error += "Incompatible";
}
PopupNotifications.show(browser, notificationID, messageString, anchorID, messageString = gNavigatorBundle.getString(error);
action, null, options); messageString = messageString.replace("#1", install.name);
break; if (host) {
messageString = messageString.replace("#2", host);
}
messageString = messageString.replace("#3", brandShortName);
messageString = messageString.replace("#4", Services.appinfo.version);
PopupNotifications.show(browser, notificationID, messageString, anchorID,
action, null, options);
}
break;
case "addon-install-complete":
var needsRestart = installInfo.installs.some(function(i) {
return i.addon.pendingOperations != AddonManager.PENDING_NONE;
});
if (needsRestart) {
messageString = gNavigatorBundle.getString("addonsInstalledNeedsRestart");
action = {
label: gNavigatorBundle.getString("addonInstallRestartButton"),
accessKey: gNavigatorBundle.getString("addonInstallRestartButton.accesskey"),
callback: function() {
Application.restart();
}
};
} else {
messageString = gNavigatorBundle.getString("addonsInstalled");
action = null;
}
messageString = PluralForm.get(installInfo.installs.length, messageString);
messageString = messageString.replace("#1", installInfo.installs[0].name);
messageString = messageString.replace("#2", installInfo.installs.length);
messageString = messageString.replace("#3", brandShortName);
// Remove notificaion on dismissal, since it's possible to cancel the
// install through the addons manager UI, making the "restart" prompt
// irrelevant.
options.removeOnDismissal = true;
PopupNotifications.show(browser, notificationID, messageString, anchorID,
action, null, options);
break;
} }
} }
}; };
@ -237,8 +239,9 @@ var AddonsMgrListener = {
.split(",") .split(",")
.concat(["separator", "spacer", "spring"]); .concat(["separator", "spacer", "spring"]);
for (let item of this.addonBar.currentSet.split(",")) { for (let item of this.addonBar.currentSet.split(",")) {
if (defaultOrNoninteractive.indexOf(item) == -1) if (defaultOrNoninteractive.indexOf(item) == -1) {
itemCount++; itemCount++;
}
} }
return itemCount; return itemCount;
@ -247,20 +250,30 @@ var AddonsMgrListener = {
this.lastAddonBarCount = this.getAddonBarItemCount(); this.lastAddonBarCount = this.getAddonBarItemCount();
}, },
onInstalled: function(aAddon) { onInstalled: function(aAddon) {
if (this.getAddonBarItemCount() > this.lastAddonBarCount) if (this.getAddonBarItemCount() > this.lastAddonBarCount) {
setToolbarVisibility(this.addonBar, true); setToolbarVisibility(this.addonBar, true);
}
}, },
onUninstalling: function(aAddon) { onUninstalling: function(aAddon) {
this.lastAddonBarCount = this.getAddonBarItemCount(); this.lastAddonBarCount = this.getAddonBarItemCount();
}, },
onUninstalled: function(aAddon) { onUninstalled: function(aAddon) {
if (this.getAddonBarItemCount() == 0) if (this.getAddonBarItemCount() == 0) {
setToolbarVisibility(this.addonBar, false); setToolbarVisibility(this.addonBar, false);
}
}, },
onEnabling: function(aAddon) this.onInstalling(), onEnabling: function(aAddon) {
onEnabled: function(aAddon) this.onInstalled(), return this.onInstalling();
onDisabling: function(aAddon) this.onUninstalling(), },
onDisabled: function(aAddon) this.onUninstalled(), onEnabled: function(aAddon) {
return this.onInstalled();
},
onDisabling: function(aAddon) {
return this.onUninstalling();
},
onDisabled: function(aAddon) {
return this.onUninstalled();
}
}; };
#ifdef MOZ_PERSONAS #ifdef MOZ_PERSONAS
@ -271,8 +284,9 @@ var LightWeightThemeWebInstaller = {
case "PreviewBrowserTheme": case "PreviewBrowserTheme":
case "ResetBrowserThemePreview": case "ResetBrowserThemePreview":
// ignore requests from background tabs // ignore requests from background tabs
if (event.target.ownerDocument.defaultView.top != content) if (event.target.ownerDocument.defaultView.top != content) {
return; return;
}
} }
switch (event.type) { switch (event.type) {
case "InstallBrowserTheme": case "InstallBrowserTheme":
@ -292,7 +306,7 @@ var LightWeightThemeWebInstaller = {
}, },
get _manager () { get _manager () {
var temp = {}; var temp = { };
Cu.import("resource://gre/modules/LightweightThemeManager.jsm", temp); Cu.import("resource://gre/modules/LightweightThemeManager.jsm", temp);
delete this._manager; delete this._manager;
return this._manager = temp.LightweightThemeManager; return this._manager = temp.LightweightThemeManager;
@ -301,21 +315,19 @@ var LightWeightThemeWebInstaller = {
_installRequest: function (event) { _installRequest: function (event) {
var node = event.target; var node = event.target;
var data = this._getThemeFromNode(node); var data = this._getThemeFromNode(node);
if (!data) if (!data) {
return; return;
}
if (this._isAllowed(node)) { if (this._isAllowed(node)) {
this._install(data); this._install(data);
return; return;
} }
var allowButtonText = var allowButtonText = gNavigatorBundle.getString("lwthemeInstallRequest.allowButton");
gNavigatorBundle.getString("lwthemeInstallRequest.allowButton"); var allowButtonAccesskey = gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey");
var allowButtonAccesskey = var message = gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message",
gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey"); [node.ownerDocument.location.host]);
var message =
gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message",
[node.ownerDocument.location.host]);
var buttons = [{ var buttons = [{
label: allowButtonText, label: allowButtonText,
accessKey: allowButtonAccesskey, accessKey: allowButtonAccesskey,
@ -339,11 +351,12 @@ var LightWeightThemeWebInstaller = {
var listener = { var listener = {
onEnabling: function(aAddon, aRequiresRestart) { onEnabling: function(aAddon, aRequiresRestart) {
if (!aRequiresRestart) if (!aRequiresRestart) {
return; return;
}
let messageString = gNavigatorBundle.getFormattedString("lwthemeNeedsRestart.message", let messageString = gNavigatorBundle.getFormattedString("lwthemeNeedsRestart.message",
[aAddon.name], 1); [aAddon.name], 1);
let action = { let action = {
label: gNavigatorBundle.getString("lwthemeNeedsRestart.button"), label: gNavigatorBundle.getString("lwthemeNeedsRestart.button"),
@ -353,9 +366,7 @@ var LightWeightThemeWebInstaller = {
} }
}; };
let options = { let options = { timeout: Date.now() + 30000 };
timeout: Date.now() + 30000
};
PopupNotifications.show(gBrowser.selectedBrowser, "addon-theme-change", PopupNotifications.show(gBrowser.selectedBrowser, "addon-theme-change",
messageString, "addons-notification-icon", messageString, "addons-notification-icon",
@ -417,12 +428,14 @@ var LightWeightThemeWebInstaller = {
_previewWindow: null, _previewWindow: null,
_preview: function (event) { _preview: function (event) {
if (!this._isAllowed(event.target)) if (!this._isAllowed(event.target)) {
return; return;
}
var data = this._getThemeFromNode(event.target); var data = this._getThemeFromNode(event.target);
if (!data) if (!data) {
return; return;
}
this._resetPreview(); this._resetPreview();
@ -435,8 +448,9 @@ var LightWeightThemeWebInstaller = {
_resetPreview: function (event) { _resetPreview: function (event) {
if (!this._previewWindow || if (!this._previewWindow ||
event && !this._isAllowed(event.target)) (event && !this._isAllowed(event.target))) {
return; return;
}
this._previewWindow.removeEventListener("pagehide", this, true); this._previewWindow.removeEventListener("pagehide", this, true);
this._previewWindow = null; this._previewWindow = null;
@ -475,8 +489,9 @@ var LightweightThemeListener = {
Services.obs.addObserver(this, "lightweight-theme-styling-update", false); Services.obs.addObserver(this, "lightweight-theme-styling-update", false);
Services.obs.addObserver(this, "lightweight-theme-optimized", false); Services.obs.addObserver(this, "lightweight-theme-optimized", false);
if (document.documentElement.hasAttribute("lwtheme")) if (document.documentElement.hasAttribute("lwtheme")) {
this.updateStyleSheet(document.documentElement.style.backgroundImage); this.updateStyleSheet(document.documentElement.style.backgroundImage);
}
}, },
uninit: function () { uninit: function () {
@ -491,8 +506,9 @@ var LightweightThemeListener = {
* @param headerImage - a string containing a CSS image for the lightweight theme header. * @param headerImage - a string containing a CSS image for the lightweight theme header.
*/ */
updateStyleSheet: function(headerImage) { updateStyleSheet: function(headerImage) {
if (!this.styleSheet) if (!this.styleSheet) {
return; return;
}
this.substituteRules(this.styleSheet.cssRules, headerImage); this.substituteRules(this.styleSheet.cssRules, headerImage);
}, },
@ -504,11 +520,13 @@ var LightweightThemeListener = {
// Add the number of modified sub-rules to the modified count // Add the number of modified sub-rules to the modified count
styleRulesModified += this.substituteRules(rule.cssRules, headerImage, existingStyleRulesModified + styleRulesModified); styleRulesModified += this.substituteRules(rule.cssRules, headerImage, existingStyleRulesModified + styleRulesModified);
} else if (rule instanceof Ci.nsIDOMCSSStyleRule) { } else if (rule instanceof Ci.nsIDOMCSSStyleRule) {
if (!rule.style.backgroundImage) if (!rule.style.backgroundImage) {
continue; continue;
}
let modifiedIndex = existingStyleRulesModified + styleRulesModified; let modifiedIndex = existingStyleRulesModified + styleRulesModified;
if (!this._modifiedStyles[modifiedIndex]) if (!this._modifiedStyles[modifiedIndex]) {
this._modifiedStyles[modifiedIndex] = { backgroundImage: rule.style.backgroundImage }; this._modifiedStyles[modifiedIndex] = { backgroundImage: rule.style.backgroundImage };
}
rule.style.backgroundImage = this._modifiedStyles[modifiedIndex].backgroundImage + ", " + headerImage; rule.style.backgroundImage = this._modifiedStyles[modifiedIndex].backgroundImage + ", " + headerImage;
styleRulesModified++; styleRulesModified++;
@ -522,15 +540,18 @@ var LightweightThemeListener = {
// nsIObserver // nsIObserver
observe: function (aSubject, aTopic, aData) { observe: function (aSubject, aTopic, aData) {
if ((aTopic != "lightweight-theme-styling-update" && aTopic != "lightweight-theme-optimized") || if ((aTopic != "lightweight-theme-styling-update" && aTopic != "lightweight-theme-optimized") ||
!this.styleSheet) !this.styleSheet) {
return; return;
}
if (aTopic == "lightweight-theme-optimized" && aSubject != window) if (aTopic == "lightweight-theme-optimized" && aSubject != window) {
return; return;
}
let themeData = JSON.parse(aData); let themeData = JSON.parse(aData);
if (!themeData) if (!themeData) {
return; return;
}
this.updateStyleSheet("url(" + themeData.headerURL + ")"); this.updateStyleSheet("url(" + themeData.headerURL + ")");
}, },
}; };

View file

@ -37,8 +37,9 @@ var FeedHandler = {
let feeds = gBrowser.selectedBrowser.feeds || []; let feeds = gBrowser.selectedBrowser.feeds || [];
// If there are multiple feeds, the menu will open, so no need to do // If there are multiple feeds, the menu will open, so no need to do
// anything. If there are no feeds, nothing to do either. // anything. If there are no feeds, nothing to do either.
if (feeds.length != 1) if (feeds.length != 1) {
return; return;
}
if (event.eventPhase == Event.AT_TARGET && if (event.eventPhase == Event.AT_TARGET &&
(event.button == 0 || event.button == 1)) { (event.button == 0 || event.button == 1)) {
@ -68,18 +69,21 @@ var FeedHandler = {
return false; return false;
} }
while (menuPopup.firstChild) while (menuPopup.firstChild) {
menuPopup.removeChild(menuPopup.firstChild); menuPopup.removeChild(menuPopup.firstChild);
}
if (feeds.length == 1) { if (feeds.length == 1) {
var feedButtonPM = document.getElementById("ub-feed-button"); var feedButtonPM = document.getElementById("ub-feed-button");
if (feedButtonPM) if (feedButtonPM) {
feedButtonPM.setAttribute("feed", feeds[0].href); feedButtonPM.setAttribute("feed", feeds[0].href);
}
return false; return false;
} }
if (feeds.length <= 1) if (feeds.length <= 1) {
return false; return false;
}
// Build the menu showing the available feed choices for viewing. // Build the menu showing the available feed choices for viewing.
for (let feedInfo of feeds) { for (let feedInfo of feeds) {
@ -112,15 +116,17 @@ var FeedHandler = {
subscribeToFeed: function(href, event) { subscribeToFeed: function(href, event) {
// Just load the feed in the content area to either subscribe or show the // Just load the feed in the content area to either subscribe or show the
// preview UI // preview UI
if (!href) if (!href) {
href = event.target.getAttribute("feed"); href = event.target.getAttribute("feed");
}
urlSecurityCheck(href, gBrowser.contentPrincipal, urlSecurityCheck(href, gBrowser.contentPrincipal,
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL); Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
var feedURI = makeURI(href, document.characterSet); var feedURI = makeURI(href, document.characterSet);
// Use the feed scheme so X-Moz-Is-Feed will be set // Use the feed scheme so X-Moz-Is-Feed will be set
// The value doesn't matter // The value doesn't matter
if (/^https?$/.test(feedURI.scheme)) if (/^https?$/.test(feedURI.scheme)) {
href = "feed:" + href; href = "feed:" + href;
}
this.loadFeed(href, event); this.loadFeed(href, event);
}, },
@ -128,8 +134,7 @@ var FeedHandler = {
var feeds = gBrowser.selectedBrowser.feeds; var feeds = gBrowser.selectedBrowser.feeds;
try { try {
openUILink(href, event, { ignoreAlt: true }); openUILink(href, event, { ignoreAlt: true });
} } finally {
finally {
// We might default to a livebookmarks modal dialog, // We might default to a livebookmarks modal dialog,
// so reset that if the user happens to click it again // so reset that if the user happens to click it again
gBrowser.selectedBrowser.feeds = feeds; gBrowser.selectedBrowser.feeds = feeds;
@ -151,8 +156,9 @@ var FeedHandler = {
* a page is loaded or the user switches tabs to a page that has feeds. * a page is loaded or the user switches tabs to a page that has feeds.
*/ */
updateFeeds: function() { updateFeeds: function() {
if (this._updateFeedTimeout) if (this._updateFeedTimeout) {
clearTimeout(this._updateFeedTimeout); clearTimeout(this._updateFeedTimeout);
}
var feeds = gBrowser.selectedBrowser.feeds; var feeds = gBrowser.selectedBrowser.feeds;
var haveFeeds = feeds && feeds.length > 0; var haveFeeds = feeds && feeds.length > 0;
@ -161,8 +167,9 @@ var FeedHandler = {
var feedButton = document.getElementById("feed-button"); var feedButton = document.getElementById("feed-button");
if (feedButton) if (feedButton) {
feedButton.disabled = !haveFeeds; feedButton.disabled = !haveFeeds;
}
if (feedButtonPM) { if (feedButtonPM) {
if (!haveFeeds) { if (!haveFeeds) {
@ -181,13 +188,15 @@ var FeedHandler = {
} }
if (feeds.length > 1) { if (feeds.length > 1) {
if (feedButtonPM) if (feedButtonPM) {
feedButtonPM.removeAttribute("feed"); feedButtonPM.removeAttribute("feed");
}
this._feedMenuitem.setAttribute("hidden", "true"); this._feedMenuitem.setAttribute("hidden", "true");
this._feedMenupopup.removeAttribute("hidden"); this._feedMenupopup.removeAttribute("hidden");
} else { } else {
if (feedButtonPM) if (feedButtonPM) {
feedButtonPM.setAttribute("feed", feeds[0].href); feedButtonPM.setAttribute("feed", feeds[0].href);
}
this._feedMenuitem.setAttribute("feed", feeds[0].href); this._feedMenuitem.setAttribute("feed", feeds[0].href);
this._feedMenuitem.removeAttribute("disabled"); this._feedMenuitem.removeAttribute("disabled");
this._feedMenuitem.removeAttribute("hidden"); this._feedMenuitem.removeAttribute("hidden");
@ -203,8 +212,9 @@ var FeedHandler = {
return; return;
} }
if (!browserForLink.feeds) if (!browserForLink.feeds) {
browserForLink.feeds = []; browserForLink.feeds = [];
}
browserForLink.feeds.push({ href: link.href, title: link.title }); browserForLink.feeds.push({ href: link.href, title: link.title });
@ -212,12 +222,14 @@ var FeedHandler = {
// background browsers, we'll update on tab switch. // background browsers, we'll update on tab switch.
if (browserForLink == gBrowser.selectedBrowser) { if (browserForLink == gBrowser.selectedBrowser) {
var feedButtonPM = document.getElementById("ub-feed-button"); var feedButtonPM = document.getElementById("ub-feed-button");
if (feedButtonPM) if (feedButtonPM) {
feedButtonPM.collapsed = !gPrefService.getBoolPref("browser.urlbar.rss"); feedButtonPM.collapsed = !gPrefService.getBoolPref("browser.urlbar.rss");
}
// Batch updates to avoid updating the UI for multiple onLinkAdded events // Batch updates to avoid updating the UI for multiple onLinkAdded events
// fired within 100ms of each other. // fired within 100ms of each other.
if (this._updateFeedTimeout) if (this._updateFeedTimeout) {
clearTimeout(this._updateFeedTimeout); clearTimeout(this._updateFeedTimeout);
}
this._updateFeedTimeout = setTimeout(this.updateFeeds.bind(this), 100); this._updateFeedTimeout = setTimeout(this.updateFeeds.bind(this), 100);
} }
} }

View file

@ -37,8 +37,7 @@ var FullScreen = {
if (enterFS && this.useLionFullScreen) { if (enterFS && this.useLionFullScreen) {
if (document.mozFullScreen) { if (document.mozFullScreen) {
this.showXULChrome("toolbar", false); this.showXULChrome("toolbar", false);
} } else {
else {
gNavToolbox.setAttribute("inFullscreen", true); gNavToolbox.setAttribute("inFullscreen", true);
document.documentElement.setAttribute("inFullscreen", true); document.documentElement.setAttribute("inFullscreen", true);
} }
@ -61,8 +60,7 @@ var FullScreen = {
// as the size of the content area would still be changing after the // as the size of the content area would still be changing after the
// mozfullscreenchange event fired, which could confuse content script. // mozfullscreenchange event fired, which could confuse content script.
this.hideNavToolbox(document.mozFullScreen); this.hideNavToolbox(document.mozFullScreen);
} } else {
else {
this.showNavToolbox(false); this.showNavToolbox(false);
// This is needed if they use the context menu to quit fullscreen // This is needed if they use the context menu to quit fullscreen
this._isPopupOpen = false; this._isPopupOpen = false;
@ -85,15 +83,17 @@ var FullScreen = {
} }
break; break;
case "transitionend": case "transitionend":
if (event.propertyName == "opacity") if (event.propertyName == "opacity") {
this.cancelWarning(); this.cancelWarning();
}
break; break;
} }
}, },
enterDomFullscreen : function(event) { enterDomFullscreen : function(event) {
if (!document.mozFullScreen) if (!document.mozFullScreen) {
return; return;
}
// However, if we receive a "MozDOMFullscreen:NewOrigin" event for a document // However, if we receive a "MozDOMFullscreen:NewOrigin" event for a document
// which is not a subdocument of a currently active (ie. visible) browser // which is not a subdocument of a currently active (ie. visible) browser
@ -117,8 +117,9 @@ var FullScreen = {
document.documentElement.setAttribute("inDOMFullscreen", true); document.documentElement.setAttribute("inDOMFullscreen", true);
if (gFindBarInitialized) if (gFindBarInitialized) {
gFindBar.close(); gFindBar.close();
}
this.showWarning(event.target); this.showWarning(event.target);
@ -151,54 +152,54 @@ var FullScreen = {
gBrowser.tabContainer.removeEventListener("TabOpen", this.exitDomFullScreen); gBrowser.tabContainer.removeEventListener("TabOpen", this.exitDomFullScreen);
gBrowser.tabContainer.removeEventListener("TabClose", this.exitDomFullScreen); gBrowser.tabContainer.removeEventListener("TabClose", this.exitDomFullScreen);
gBrowser.tabContainer.removeEventListener("TabSelect", this.exitDomFullScreen); gBrowser.tabContainer.removeEventListener("TabSelect", this.exitDomFullScreen);
if (!this.useLionFullScreen) if (!this.useLionFullScreen) {
window.removeEventListener("activate", this); window.removeEventListener("activate", this);
}
this.fullscreenDoc = null; this.fullscreenDoc = null;
} }
}, },
// Event callbacks // Event callbacks
_expandCallback: function() _expandCallback: function() {
{
FullScreen.showNavToolbox(); FullScreen.showNavToolbox();
}, },
_collapseCallback: function() _collapseCallback: function() {
{
FullScreen.hideNavToolbox(); FullScreen.hideNavToolbox();
}, },
_keyToggleCallback: function(aEvent) _keyToggleCallback: function(aEvent) {
{
// if we can use the keyboard (eg Ctrl+L or Ctrl+E) to open the toolbars, we // if we can use the keyboard (eg Ctrl+L or Ctrl+E) to open the toolbars, we
// should provide a way to collapse them too. // should provide a way to collapse them too.
if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE) { if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE) {
FullScreen.hideNavToolbox(true); FullScreen.hideNavToolbox(true);
} } else if (aEvent.keyCode == aEvent.DOM_VK_F6) {
// F6 is another shortcut to the address bar, but its not covered in OpenLocation() // F6 is another shortcut to the address bar, but its not covered in OpenLocation()
else if (aEvent.keyCode == aEvent.DOM_VK_F6)
FullScreen.showNavToolbox(); FullScreen.showNavToolbox();
}
}, },
// Checks whether we are allowed to collapse the chrome // Checks whether we are allowed to collapse the chrome
_isPopupOpen: false, _isPopupOpen: false,
_isChromeCollapsed: false, _isChromeCollapsed: false,
_safeToCollapse: function(forceHide) _safeToCollapse: function(forceHide) {
{ if (!gPrefService.getBoolPref("browser.fullscreen.autohide")) {
if (!gPrefService.getBoolPref("browser.fullscreen.autohide"))
return false; return false;
}
// a popup menu is open in chrome: don't collapse chrome // a popup menu is open in chrome: don't collapse chrome
if (!forceHide && this._isPopupOpen) if (!forceHide && this._isPopupOpen) {
return false; return false;
}
// a textbox in chrome is focused (location bar anyone?): don't collapse chrome // a textbox in chrome is focused (location bar anyone?): don't collapse chrome
if (document.commandDispatcher.focusedElement && if (document.commandDispatcher.focusedElement &&
document.commandDispatcher.focusedElement.ownerDocument == document && document.commandDispatcher.focusedElement.ownerDocument == document &&
document.commandDispatcher.focusedElement.localName == "input") { document.commandDispatcher.focusedElement.localName == "input") {
if (forceHide) if (forceHide) {
// hidden textboxes that still have focus are bad bad bad // hidden textboxes that still have focus are bad bad bad
document.commandDispatcher.focusedElement.blur(); document.commandDispatcher.focusedElement.blur();
else } else {
return false; return false;
}
} }
return true; return true;
}, },
@ -210,20 +211,19 @@ var FullScreen = {
// e.g. we wouldn't want the autoscroll icon firing this event, so when the user // e.g. we wouldn't want the autoscroll icon firing this event, so when the user
// toggles chrome when moving mouse to the top, it doesn't go away again. // toggles chrome when moving mouse to the top, it doesn't go away again.
if (aEvent.type == "popupshown" && !FullScreen._isChromeCollapsed && if (aEvent.type == "popupshown" && !FullScreen._isChromeCollapsed &&
aEvent.target.localName != "tooltip" && aEvent.target.localName != "window") aEvent.target.localName != "tooltip" && aEvent.target.localName != "window") {
FullScreen._isPopupOpen = true; FullScreen._isPopupOpen = true;
else if (aEvent.type == "popuphidden" && aEvent.target.localName != "tooltip" && } else if (aEvent.type == "popuphidden" && aEvent.target.localName != "tooltip" &&
aEvent.target.localName != "window") aEvent.target.localName != "window") {
FullScreen._isPopupOpen = false; FullScreen._isPopupOpen = false;
}
}, },
// Autohide helpers for the context menu item // Autohide helpers for the context menu item
getAutohide: function(aItem) getAutohide: function(aItem) {
{
aItem.setAttribute("checked", gPrefService.getBoolPref("browser.fullscreen.autohide")); aItem.setAttribute("checked", gPrefService.getBoolPref("browser.fullscreen.autohide"));
}, },
setAutohide: function() setAutohide: function() {
{
gPrefService.setBoolPref("browser.fullscreen.autohide", !gPrefService.getBoolPref("browser.fullscreen.autohide")); gPrefService.setBoolPref("browser.fullscreen.autohide", !gPrefService.getBoolPref("browser.fullscreen.autohide"));
}, },
@ -231,8 +231,9 @@ var FullScreen = {
_shouldAnimate: true, _shouldAnimate: true,
cancelWarning: function(event) { cancelWarning: function(event) {
if (!this.warningBox) if (!this.warningBox) {
return; return;
}
this.warningBox.removeEventListener("transitionend", this); this.warningBox.removeEventListener("transitionend", this);
if (this.warningFadeOutTimeout) { if (this.warningFadeOutTimeout) {
clearTimeout(this.warningFadeOutTimeout); clearTimeout(this.warningFadeOutTimeout);
@ -257,8 +258,9 @@ var FullScreen = {
// Shows a warning that the site has entered fullscreen for a short duration. // Shows a warning that the site has entered fullscreen for a short duration.
showWarning: function(targetDoc) { showWarning: function(targetDoc) {
let timeout = gPrefService.getIntPref("full-screen-api.warning.timeout"); let timeout = gPrefService.getIntPref("full-screen-api.warning.timeout");
if (!document.mozFullScreen || timeout <= 0) if (!document.mozFullScreen || timeout <= 0) {
return; return;
}
// Set the strings on the fullscreen warning UI. // Set the strings on the fullscreen warning UI.
this.fullscreenDoc = targetDoc; this.fullscreenDoc = targetDoc;
@ -266,11 +268,12 @@ var FullScreen = {
let host = null; let host = null;
try { try {
host = uri.host; host = uri.host;
} catch (e) { } } catch(e) {
}
let hostLabel = document.getElementById("full-screen-domain-text"); let hostLabel = document.getElementById("full-screen-domain-text");
if (host) { if (host) {
// Document's principal's URI has a host. Display a warning including the hostname. // Document's principal's URI has a host. Display a warning including the hostname.
let utils = {}; let utils = { };
Cu.import("resource://gre/modules/DownloadUtils.jsm", utils); Cu.import("resource://gre/modules/DownloadUtils.jsm", utils);
let displayHost = utils.DownloadUtils.getURIHost(uri.spec)[0]; let displayHost = utils.DownloadUtils.getURIHost(uri.spec)[0];
let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties"); let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
@ -384,16 +387,16 @@ var FullScreen = {
// Give the main nav bar and the tab bar the fullscreen context menu, // Give the main nav bar and the tab bar the fullscreen context menu,
// otherwise remove context menu to prevent breakage // otherwise remove context menu to prevent breakage
el.setAttribute("saved-context", el.getAttribute("context")); el.setAttribute("saved-context", el.getAttribute("context"));
if (el.id == "nav-bar" || el.id == "TabsToolbar") if (el.id == "nav-bar" || el.id == "TabsToolbar") {
el.setAttribute("context", "autohide-context"); el.setAttribute("context", "autohide-context");
else } else {
el.removeAttribute("context"); el.removeAttribute("context");
}
// Set the inFullscreen attribute to allow specific styling // Set the inFullscreen attribute to allow specific styling
// in fullscreen mode // in fullscreen mode
el.setAttribute("inFullscreen", true); el.setAttribute("inFullscreen", true);
} } else {
else {
var restoreAttr = function restoreAttr(attrName) { var restoreAttr = function restoreAttr(attrName) {
var savedAttr = "saved-" + attrName; var savedAttr = "saved-" + attrName;
if (el.hasAttribute(savedAttr)) { if (el.hasAttribute(savedAttr)) {
@ -411,10 +414,11 @@ var FullScreen = {
} else { } else {
// use moz-collapsed so it doesn't persist hidden/collapsed, // use moz-collapsed so it doesn't persist hidden/collapsed,
// so that new windows don't have missing toolbars // so that new windows don't have missing toolbars
if (aShow) if (aShow) {
el.removeAttribute("moz-collapsed"); el.removeAttribute("moz-collapsed");
else } else {
el.setAttribute("moz-collapsed", "true"); el.setAttribute("moz-collapsed", "true");
}
} }
} }
@ -433,13 +437,13 @@ var FullScreen = {
var fullscreenctls = document.getElementById("window-controls"); var fullscreenctls = document.getElementById("window-controls");
var navbar = document.getElementById("nav-bar"); var navbar = document.getElementById("nav-bar");
var ctlsOnTabbar = window.toolbar.visible && var ctlsOnTabbar = window.toolbar.visible &&
(navbar.collapsed || (TabsOnTop.enabled && (navbar.collapsed ||
!gPrefService.getBoolPref("browser.tabs.autoHide"))); (TabsOnTop.enabled &&
!gPrefService.getBoolPref("browser.tabs.autoHide")));
if (fullscreenctls.parentNode == navbar && ctlsOnTabbar) { if (fullscreenctls.parentNode == navbar && ctlsOnTabbar) {
fullscreenctls.removeAttribute("flex"); fullscreenctls.removeAttribute("flex");
document.getElementById("TabsToolbar").appendChild(fullscreenctls); document.getElementById("TabsToolbar").appendChild(fullscreenctls);
} } else if (fullscreenctls.parentNode.id == "TabsToolbar" && !ctlsOnTabbar) {
else if (fullscreenctls.parentNode.id == "TabsToolbar" && !ctlsOnTabbar) {
fullscreenctls.setAttribute("flex", "1"); fullscreenctls.setAttribute("flex", "1");
navbar.appendChild(fullscreenctls); navbar.appendChild(fullscreenctls);
} }

File diff suppressed because it is too large Load diff