mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Back out bug 899222 because of bug 903208.
--HG-- rename : browser/modules/AboutHome.jsm => browser/modules/AboutHomeUtils.jsm
This commit is contained in:
parent
b47a41208b
commit
7fa594f564
@ -84,6 +84,9 @@ this.__defineSetter__("PluralForm", function (val) {
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
|
||||
"resource://gre/modules/TelemetryStopwatch.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AboutHomeUtils",
|
||||
"resource:///modules/AboutHomeUtils.jsm");
|
||||
|
||||
#ifdef MOZ_SERVICES_SYNC
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Weave",
|
||||
"resource://services-sync/main.js");
|
||||
@ -2312,6 +2315,64 @@ function PageProxyClickHandler(aEvent)
|
||||
middleMousePaste(aEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle load of some pages (about:*) so that we can make modifications
|
||||
* to the DOM for unprivileged pages.
|
||||
*/
|
||||
function BrowserOnAboutPageLoad(doc) {
|
||||
if (doc.documentURI.toLowerCase() == "about:home") {
|
||||
// XXX bug 738646 - when Marketplace is launched, remove this statement and
|
||||
// the hidden attribute set on the apps button in aboutHome.xhtml
|
||||
if (getBoolPref("browser.aboutHome.apps", false))
|
||||
doc.getElementById("apps").removeAttribute("hidden");
|
||||
|
||||
let ss = Components.classes["@mozilla.org/browser/sessionstore;1"].
|
||||
getService(Components.interfaces.nsISessionStore);
|
||||
if (ss.canRestoreLastSession &&
|
||||
!PrivateBrowsingUtils.isWindowPrivate(window))
|
||||
doc.getElementById("launcher").setAttribute("session", "true");
|
||||
|
||||
// Inject search engine and snippets URL.
|
||||
let docElt = doc.documentElement;
|
||||
// set the following attributes BEFORE searchEngineURL, which triggers to
|
||||
// show the snippets when it's set.
|
||||
docElt.setAttribute("snippetsURL", AboutHomeUtils.snippetsURL);
|
||||
if (AboutHomeUtils.showKnowYourRights) {
|
||||
docElt.setAttribute("showKnowYourRights", "true");
|
||||
// Set pref to indicate we've shown the notification.
|
||||
let currentVersion = Services.prefs.getIntPref("browser.rights.version");
|
||||
Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
|
||||
}
|
||||
docElt.setAttribute("snippetsVersion", AboutHomeUtils.snippetsVersion);
|
||||
|
||||
let updateSearchEngine = function() {
|
||||
let engine = AboutHomeUtils.defaultSearchEngine;
|
||||
docElt.setAttribute("searchEngineName", engine.name);
|
||||
docElt.setAttribute("searchEnginePostData", engine.postDataString || "");
|
||||
// Again, keep the searchEngineURL as the last attribute, because the
|
||||
// mutation observer in aboutHome.js is counting on that.
|
||||
docElt.setAttribute("searchEngineURL", engine.searchURL);
|
||||
};
|
||||
updateSearchEngine();
|
||||
|
||||
// Listen for the event that's triggered when the user changes search engine.
|
||||
// At this point we simply reload about:home to reflect the change.
|
||||
Services.obs.addObserver(updateSearchEngine, "browser-search-engine-modified", false);
|
||||
|
||||
// Remove the observer when the page is reloaded or closed.
|
||||
doc.defaultView.addEventListener("pagehide", function removeObserver() {
|
||||
doc.defaultView.removeEventListener("pagehide", removeObserver);
|
||||
Services.obs.removeObserver(updateSearchEngine, "browser-search-engine-modified");
|
||||
}, false);
|
||||
|
||||
#ifdef MOZ_SERVICES_HEALTHREPORT
|
||||
doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) {
|
||||
BrowserSearch.recordSearchInHealthReport(e.detail, "abouthome");
|
||||
}, true, true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle command events bubbling up from error page content
|
||||
*/
|
||||
@ -2336,6 +2397,9 @@ let BrowserOnClick = {
|
||||
else if (ownerDoc.documentURI.startsWith("about:neterror")) {
|
||||
this.onAboutNetError(originalTarget, ownerDoc);
|
||||
}
|
||||
else if (ownerDoc.documentURI.toLowerCase() == "about:home") {
|
||||
this.onAboutHome(originalTarget, ownerDoc);
|
||||
}
|
||||
},
|
||||
|
||||
onAboutCertError: function BrowserOnClick_onAboutCertError(aTargetElm, aOwnerDoc) {
|
||||
@ -2512,6 +2576,49 @@ let BrowserOnClick = {
|
||||
return;
|
||||
Services.io.offline = false;
|
||||
},
|
||||
|
||||
onAboutHome: function BrowserOnClick_onAboutHome(aTargetElm, aOwnerDoc) {
|
||||
let elmId = aTargetElm.getAttribute("id");
|
||||
|
||||
switch (elmId) {
|
||||
case "restorePreviousSession":
|
||||
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
|
||||
getService(Ci.nsISessionStore);
|
||||
if (ss.canRestoreLastSession) {
|
||||
ss.restoreLastSession();
|
||||
}
|
||||
aOwnerDoc.getElementById("launcher").removeAttribute("session");
|
||||
break;
|
||||
|
||||
case "downloads":
|
||||
BrowserDownloadsUI();
|
||||
break;
|
||||
|
||||
case "bookmarks":
|
||||
PlacesCommandHook.showPlacesOrganizer("AllBookmarks");
|
||||
break;
|
||||
|
||||
case "history":
|
||||
PlacesCommandHook.showPlacesOrganizer("History");
|
||||
break;
|
||||
|
||||
case "apps":
|
||||
openUILinkIn("https://marketplace.mozilla.org/", "tab");
|
||||
break;
|
||||
|
||||
case "addons":
|
||||
BrowserOpenAddonsMgr();
|
||||
break;
|
||||
|
||||
case "sync":
|
||||
openPreferences("paneSync");
|
||||
break;
|
||||
|
||||
case "settings":
|
||||
openPreferences();
|
||||
break;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@ -4191,7 +4298,6 @@ var TabsProgressListener = {
|
||||
Components.isSuccessCode(aStatus) &&
|
||||
doc.documentURI.startsWith("about:") &&
|
||||
!doc.documentURI.toLowerCase().startsWith("about:blank") &&
|
||||
!doc.documentURI.toLowerCase().startsWith("about:home") &&
|
||||
!doc.documentElement.hasAttribute("hasBrowserHandlers")) {
|
||||
// STATE_STOP may be received twice for documents, thus store an
|
||||
// attribute to ensure handling it just once.
|
||||
@ -4205,6 +4311,9 @@ var TabsProgressListener = {
|
||||
if (event.target.documentElement)
|
||||
event.target.documentElement.removeAttribute("hasBrowserHandlers");
|
||||
}, true);
|
||||
|
||||
// We also want to make changes to page UI for unprivileged about pages.
|
||||
BrowserOnAboutPageLoad(doc);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -13,8 +13,6 @@ XPCOMUtils.defineLazyModuleGetter(this,
|
||||
"LoginManagerContent", "resource://gre/modules/LoginManagerContent.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this,
|
||||
"InsecurePasswordUtils", "resource://gre/modules/InsecurePasswordUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||
|
||||
// Bug 671101 - directly using webNavigation in this context
|
||||
// causes docshells to leak
|
||||
@ -57,144 +55,6 @@ if (Services.prefs.getBoolPref("browser.tabs.remote")) {
|
||||
});
|
||||
}
|
||||
|
||||
let AboutHomeListener = {
|
||||
init: function() {
|
||||
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebProgress);
|
||||
webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_WINDOW);
|
||||
|
||||
addMessageListener("AboutHome:Update", this);
|
||||
},
|
||||
|
||||
receiveMessage: function(aMessage) {
|
||||
switch (aMessage.name) {
|
||||
case "AboutHome:Update":
|
||||
this.onUpdate(aMessage.data);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
onUpdate: function(aData) {
|
||||
let doc = content.document;
|
||||
if (doc.documentURI.toLowerCase() != "about:home")
|
||||
return;
|
||||
|
||||
if (aData.showRestoreLastSession && !PrivateBrowsingUtils.isWindowPrivate(content))
|
||||
doc.getElementById("launcher").setAttribute("session", "true");
|
||||
|
||||
// Inject search engine and snippets URL.
|
||||
let docElt = doc.documentElement;
|
||||
// set the following attributes BEFORE searchEngineURL, which triggers to
|
||||
// show the snippets when it's set.
|
||||
docElt.setAttribute("snippetsURL", aData.snippetsURL);
|
||||
if (aData.showKnowYourRights)
|
||||
docElt.setAttribute("showKnowYourRights", "true");
|
||||
docElt.setAttribute("snippetsVersion", aData.snippetsVersion);
|
||||
|
||||
let engine = aData.defaultSearchEngine;
|
||||
docElt.setAttribute("searchEngineName", engine.name);
|
||||
docElt.setAttribute("searchEnginePostData", engine.postDataString || "");
|
||||
// Again, keep the searchEngineURL as the last attribute, because the
|
||||
// mutation observer in aboutHome.js is counting on that.
|
||||
docElt.setAttribute("searchEngineURL", engine.searchURL);
|
||||
},
|
||||
|
||||
onPageLoad: function(aDocument) {
|
||||
// XXX bug 738646 - when Marketplace is launched, remove this statement and
|
||||
// the hidden attribute set on the apps button in aboutHome.xhtml
|
||||
if (Services.prefs.getPrefType("browser.aboutHome.apps") == Services.prefs.PREF_BOOL &&
|
||||
Services.prefs.getBoolPref("browser.aboutHome.apps"))
|
||||
doc.getElementById("apps").removeAttribute("hidden");
|
||||
|
||||
sendAsyncMessage("AboutHome:RequestUpdate");
|
||||
|
||||
aDocument.addEventListener("AboutHomeSearchEvent", function onSearch(e) {
|
||||
sendAsyncMessage("AboutHome:Search", { engineName: e.detail });
|
||||
}, true, true);
|
||||
},
|
||||
|
||||
onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
|
||||
let doc = aWebProgress.DOMWindow.document;
|
||||
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
|
||||
aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW &&
|
||||
Components.isSuccessCode(aStatus) &&
|
||||
doc.documentURI.toLowerCase() == "about:home" &&
|
||||
!doc.documentElement.hasAttribute("hasBrowserHandlers")) {
|
||||
// STATE_STOP may be received twice for documents, thus store an
|
||||
// attribute to ensure handling it just once.
|
||||
doc.documentElement.setAttribute("hasBrowserHandlers", "true");
|
||||
addEventListener("click", this.onClick, true);
|
||||
addEventListener("pagehide", function onPageHide(event) {
|
||||
if (event.target.defaultView.frameElement)
|
||||
return;
|
||||
removeEventListener("click", this.onClick, true);
|
||||
removeEventListener("pagehide", onPageHide, true);
|
||||
if (event.target.documentElement)
|
||||
event.target.documentElement.removeAttribute("hasBrowserHandlers");
|
||||
}, true);
|
||||
|
||||
// We also want to make changes to page UI for unprivileged about pages.
|
||||
this.onPageLoad(doc);
|
||||
}
|
||||
},
|
||||
|
||||
onClick: function(aEvent) {
|
||||
if (!aEvent.isTrusted || // Don't trust synthetic events
|
||||
aEvent.button == 2 || aEvent.target.localName != "button") {
|
||||
return;
|
||||
}
|
||||
|
||||
let originalTarget = aEvent.originalTarget;
|
||||
let ownerDoc = originalTarget.ownerDocument;
|
||||
let elmId = originalTarget.getAttribute("id");
|
||||
|
||||
switch (elmId) {
|
||||
case "restorePreviousSession":
|
||||
sendAsyncMessage("AboutHome:RestorePreviousSession");
|
||||
ownerDoc.getElementById("launcher").removeAttribute("session");
|
||||
break;
|
||||
|
||||
case "downloads":
|
||||
sendAsyncMessage("AboutHome:Downloads");
|
||||
break;
|
||||
|
||||
case "bookmarks":
|
||||
sendAsyncMessage("AboutHome:Bookmarks");
|
||||
break;
|
||||
|
||||
case "history":
|
||||
sendAsyncMessage("AboutHome:History");
|
||||
break;
|
||||
|
||||
case "apps":
|
||||
sendAsyncMessage("AboutHome:Apps");
|
||||
break;
|
||||
|
||||
case "addons":
|
||||
sendAsyncMessage("AboutHome:Addons");
|
||||
break;
|
||||
|
||||
case "sync":
|
||||
sendAsyncMessage("AboutHome:Sync");
|
||||
break;
|
||||
|
||||
case "settings":
|
||||
sendAsyncMessage("AboutHome:Settings");
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
QueryInterface: function QueryInterface(aIID) {
|
||||
if (aIID.equals(Ci.nsIWebProgressListener) ||
|
||||
aIID.equals(Ci.nsISupportsWeakReference) ||
|
||||
aIID.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
AboutHomeListener.init();
|
||||
|
||||
var global = this;
|
||||
|
||||
@ -288,4 +148,4 @@ let ClickEventHandler = {
|
||||
return [href ? makeURLAbsolute(baseURI, href) : null, null];
|
||||
}
|
||||
};
|
||||
ClickEventHandler.init();
|
||||
ClickEventHandler.init();
|
@ -7,7 +7,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AboutHomeUtils",
|
||||
"resource:///modules/AboutHome.jsm");
|
||||
"resource:///modules/AboutHomeUtils.jsm");
|
||||
|
||||
let gRightsVersion = Services.prefs.getIntPref("browser.rights.version");
|
||||
|
||||
@ -106,17 +106,14 @@ let gTests = [
|
||||
let doc = gBrowser.contentDocument;
|
||||
let engineName = doc.documentElement.getAttribute("searchEngineName");
|
||||
|
||||
// We rely on the listener in browser.js being installed and fired before
|
||||
// this one. If this ever changes, we should add an executeSoon() or similar.
|
||||
doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) {
|
||||
is(e.detail, engineName, "Detail is search engine name");
|
||||
|
||||
// We use executeSoon() to ensure that this code runs after the
|
||||
// count has been updated in browser.js, since it uses the same
|
||||
// event.
|
||||
executeSoon(function () {
|
||||
getNumberOfSearches(engineName).then(num => {
|
||||
is(num, numSearchesBefore + 1, "One more search recorded.");
|
||||
deferred.resolve();
|
||||
});
|
||||
getNumberOfSearches(engineName).then(num => {
|
||||
is(num, numSearchesBefore + 1, "One more search recorded.");
|
||||
deferred.resolve();
|
||||
});
|
||||
}, true, true);
|
||||
|
||||
@ -278,35 +275,19 @@ let gTests = [
|
||||
if (engine.name != "POST Search")
|
||||
return;
|
||||
|
||||
// Ready to execute the tests!
|
||||
let needle = "Search for something awesome.";
|
||||
let document = gBrowser.selectedTab.linkedBrowser.contentDocument;
|
||||
let searchText = document.getElementById("searchText");
|
||||
|
||||
// We're about to change the search engine. Once the change has
|
||||
// propagated to the about:home content, we want to perform a search.
|
||||
let mutationObserver = new MutationObserver(function (mutations) {
|
||||
for (let mutation of mutations) {
|
||||
if (mutation.attributeName == "searchEngineURL") {
|
||||
searchText.value = needle;
|
||||
searchText.focus();
|
||||
EventUtils.synthesizeKey("VK_RETURN", {});
|
||||
}
|
||||
}
|
||||
});
|
||||
mutationObserver.observe(document.documentElement, { attributes: true });
|
||||
|
||||
// Change the search engine, triggering the observer above.
|
||||
Services.search.defaultEngine = engine;
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
mutationObserver.disconnect();
|
||||
Services.search.removeEngine(engine);
|
||||
Services.search.defaultEngine = currEngine;
|
||||
});
|
||||
|
||||
|
||||
// When the search results load, check them for correctness.
|
||||
// Ready to execute the tests!
|
||||
let needle = "Search for something awesome.";
|
||||
let document = gBrowser.selectedTab.linkedBrowser.contentDocument;
|
||||
let searchText = document.getElementById("searchText");
|
||||
|
||||
waitForLoad(function() {
|
||||
let loadedText = gBrowser.contentDocument.body.textContent;
|
||||
ok(loadedText, "search page loaded");
|
||||
@ -314,6 +295,10 @@ let gTests = [
|
||||
"Search text should arrive correctly");
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
searchText.value = needle;
|
||||
searchText.focus();
|
||||
EventUtils.synthesizeKey("VK_RETURN", {});
|
||||
};
|
||||
Services.obs.addObserver(searchObserver, "browser-search-engine-modified", false);
|
||||
registerCleanupFunction(function () {
|
||||
|
@ -14,9 +14,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource:///modules/SignInToWebsite.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AboutHome",
|
||||
"resource:///modules/AboutHome.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
|
||||
"resource://gre/modules/AddonManager.jsm");
|
||||
|
||||
@ -468,7 +465,6 @@ BrowserGlue.prototype = {
|
||||
SignInToWebsiteUX.init();
|
||||
PdfJs.init();
|
||||
webrtcUI.init();
|
||||
AboutHome.init();
|
||||
|
||||
if (Services.prefs.getBoolPref("browser.tabs.remote"))
|
||||
ContentClick.init();
|
||||
|
@ -1,209 +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";
|
||||
|
||||
let Cc = Components.classes;
|
||||
let Ci = Components.interfaces;
|
||||
let Cu = Components.utils;
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ "AboutHomeUtils", "AboutHome" ];
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||
|
||||
// Url to fetch snippets, in the urlFormatter service format.
|
||||
const SNIPPETS_URL_PREF = "browser.aboutHomeSnippets.updateUrl";
|
||||
|
||||
// Should be bumped up if the snippets content format changes.
|
||||
const STARTPAGE_VERSION = 4;
|
||||
|
||||
this.AboutHomeUtils = {
|
||||
get snippetsVersion() STARTPAGE_VERSION,
|
||||
|
||||
/**
|
||||
* Returns an object containing the name and searchURL of the original default
|
||||
* search engine.
|
||||
*/
|
||||
get defaultSearchEngine() {
|
||||
let defaultEngine = Services.search.defaultEngine;
|
||||
let submission = defaultEngine.getSubmission("_searchTerms_", null, "homepage");
|
||||
|
||||
return Object.freeze({
|
||||
name: defaultEngine.name,
|
||||
searchURL: submission.uri.spec,
|
||||
postDataString: submission.postDataString
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
* showKnowYourRights - Determines if the user should be shown the
|
||||
* about:rights notification. The notification should *not* be shown if
|
||||
* we've already shown the current version, or if the override pref says to
|
||||
* never show it. The notification *should* be shown if it's never been seen
|
||||
* before, if a newer version is available, or if the override pref says to
|
||||
* always show it.
|
||||
*/
|
||||
get showKnowYourRights() {
|
||||
// Look for an unconditional override pref. If set, do what it says.
|
||||
// (true --> never show, false --> always show)
|
||||
try {
|
||||
return !Services.prefs.getBoolPref("browser.rights.override");
|
||||
} catch (e) { }
|
||||
// Ditto, for the legacy EULA pref.
|
||||
try {
|
||||
return !Services.prefs.getBoolPref("browser.EULA.override");
|
||||
} catch (e) { }
|
||||
|
||||
#ifndef MOZILLA_OFFICIAL
|
||||
// Non-official builds shouldn't show the notification.
|
||||
return false;
|
||||
#endif
|
||||
|
||||
// Look to see if the user has seen the current version or not.
|
||||
var currentVersion = Services.prefs.getIntPref("browser.rights.version");
|
||||
try {
|
||||
return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
|
||||
} catch (e) { }
|
||||
|
||||
// Legacy: If the user accepted a EULA, we won't annoy them with the
|
||||
// equivalent about:rights page until the version changes.
|
||||
try {
|
||||
return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted");
|
||||
} catch (e) { }
|
||||
|
||||
// We haven't shown the notification before, so do so now.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the URL to fetch snippets from, in the urlFormatter service format.
|
||||
*/
|
||||
XPCOMUtils.defineLazyGetter(AboutHomeUtils, "snippetsURL", function() {
|
||||
let updateURL = Services.prefs
|
||||
.getCharPref(SNIPPETS_URL_PREF)
|
||||
.replace("%STARTPAGE_VERSION%", STARTPAGE_VERSION);
|
||||
return Services.urlFormatter.formatURL(updateURL);
|
||||
});
|
||||
|
||||
/**
|
||||
* This code provides services to the about:home page. Whenever
|
||||
* about:home needs to do something chrome-privileged, it sends a
|
||||
* message that's handled here.
|
||||
*/
|
||||
let AboutHome = {
|
||||
MESSAGES: [
|
||||
"AboutHome:RestorePreviousSession",
|
||||
"AboutHome:Downloads",
|
||||
"AboutHome:Bookmarks",
|
||||
"AboutHome:History",
|
||||
"AboutHome:Apps",
|
||||
"AboutHome:Addons",
|
||||
"AboutHome:Sync",
|
||||
"AboutHome:Settings",
|
||||
"AboutHome:RequestUpdate",
|
||||
"AboutHome:Search",
|
||||
],
|
||||
|
||||
init: function() {
|
||||
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
|
||||
|
||||
for (let msg of this.MESSAGES) {
|
||||
mm.addMessageListener(msg, this);
|
||||
}
|
||||
|
||||
Services.obs.addObserver(this, "browser-search-engine-modified", false);
|
||||
},
|
||||
|
||||
observe: function(aEngine, aTopic, aVerb) {
|
||||
switch (aTopic) {
|
||||
case "browser-search-engine-modified":
|
||||
this.sendAboutHomeData(null);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
receiveMessage: function(aMessage) {
|
||||
let window = aMessage.target.ownerDocument.defaultView;
|
||||
|
||||
switch (aMessage.name) {
|
||||
case "AboutHome:RestorePreviousSession":
|
||||
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
|
||||
getService(Ci.nsISessionStore);
|
||||
if (ss.canRestoreLastSession) {
|
||||
ss.restoreLastSession();
|
||||
}
|
||||
break;
|
||||
|
||||
case "AboutHome:Downloads":
|
||||
window.BrowserDownloadsUI();
|
||||
break;
|
||||
|
||||
case "AboutHome:Bookmarks":
|
||||
window.PlacesCommandHook.showPlacesOrganizer("AllBookmarks");
|
||||
break;
|
||||
|
||||
case "AboutHome:History":
|
||||
window.PlacesCommandHook.showPlacesOrganizer("History");
|
||||
break;
|
||||
|
||||
case "AboutHome:Apps":
|
||||
window.openUILinkIn("https://marketplace.mozilla.org/", "tab");
|
||||
break;
|
||||
|
||||
case "AboutHome:Addons":
|
||||
window.BrowserOpenAddonsMgr();
|
||||
break;
|
||||
|
||||
case "AboutHome:Sync":
|
||||
window.openPreferences("paneSync");
|
||||
break;
|
||||
|
||||
case "AboutHome:Settings":
|
||||
window.openPreferences();
|
||||
break;
|
||||
|
||||
case "AboutHome:RequestUpdate":
|
||||
this.sendAboutHomeData(aMessage.target);
|
||||
break;
|
||||
|
||||
case "AboutHome:Search":
|
||||
#ifdef MOZ_SERVICES_HEALTHREPORT
|
||||
window.BrowserSearch.recordSearchInHealthReport(aMessage.data.engineName, "abouthome");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// Send all the chrome-privileged data needed by about:home. This
|
||||
// gets re-sent when the search engine changes.
|
||||
sendAboutHomeData: function(target) {
|
||||
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
|
||||
getService(Ci.nsISessionStore);
|
||||
let data = {
|
||||
showRestoreLastSession: ss.canRestoreLastSession,
|
||||
snippetsURL: AboutHomeUtils.snippetsURL,
|
||||
showKnowYourRights: AboutHomeUtils.showKnowYourRights,
|
||||
snippetsVersion: AboutHomeUtils.snippetsVersion,
|
||||
defaultSearchEngine: AboutHomeUtils.defaultSearchEngine
|
||||
};
|
||||
|
||||
if (AboutHomeUtils.showKnowYourRights) {
|
||||
// Set pref to indicate we've shown the notification.
|
||||
let currentVersion = Services.prefs.getIntPref("browser.rights.version");
|
||||
Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
|
||||
}
|
||||
|
||||
if (target) {
|
||||
target.messageManager.sendAsyncMessage("AboutHome:Update", data);
|
||||
} else {
|
||||
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
|
||||
mm.broadcastAsyncMessage("AboutHome:Update", data);
|
||||
}
|
||||
},
|
||||
};
|
85
browser/modules/AboutHomeUtils.jsm
Normal file
85
browser/modules/AboutHomeUtils.jsm
Normal file
@ -0,0 +1,85 @@
|
||||
/* 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";
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ "AboutHomeUtils" ];
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Url to fetch snippets, in the urlFormatter service format.
|
||||
const SNIPPETS_URL_PREF = "browser.aboutHomeSnippets.updateUrl";
|
||||
|
||||
// Should be bumped up if the snippets content format changes.
|
||||
const STARTPAGE_VERSION = 4;
|
||||
|
||||
this.AboutHomeUtils = {
|
||||
get snippetsVersion() STARTPAGE_VERSION,
|
||||
|
||||
/**
|
||||
* Returns an object containing the name and searchURL of the original default
|
||||
* search engine.
|
||||
*/
|
||||
get defaultSearchEngine() {
|
||||
let defaultEngine = Services.search.defaultEngine;
|
||||
let submission = defaultEngine.getSubmission("_searchTerms_", null, "homepage");
|
||||
|
||||
return Object.freeze({
|
||||
name: defaultEngine.name,
|
||||
searchURL: submission.uri.spec,
|
||||
postDataString: submission.postDataString
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
* showKnowYourRights - Determines if the user should be shown the
|
||||
* about:rights notification. The notification should *not* be shown if
|
||||
* we've already shown the current version, or if the override pref says to
|
||||
* never show it. The notification *should* be shown if it's never been seen
|
||||
* before, if a newer version is available, or if the override pref says to
|
||||
* always show it.
|
||||
*/
|
||||
get showKnowYourRights() {
|
||||
// Look for an unconditional override pref. If set, do what it says.
|
||||
// (true --> never show, false --> always show)
|
||||
try {
|
||||
return !Services.prefs.getBoolPref("browser.rights.override");
|
||||
} catch (e) { }
|
||||
// Ditto, for the legacy EULA pref.
|
||||
try {
|
||||
return !Services.prefs.getBoolPref("browser.EULA.override");
|
||||
} catch (e) { }
|
||||
|
||||
#ifndef MOZILLA_OFFICIAL
|
||||
// Non-official builds shouldn't show the notification.
|
||||
return false;
|
||||
#endif
|
||||
|
||||
// Look to see if the user has seen the current version or not.
|
||||
var currentVersion = Services.prefs.getIntPref("browser.rights.version");
|
||||
try {
|
||||
return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
|
||||
} catch (e) { }
|
||||
|
||||
// Legacy: If the user accepted a EULA, we won't annoy them with the
|
||||
// equivalent about:rights page until the version changes.
|
||||
try {
|
||||
return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted");
|
||||
} catch (e) { }
|
||||
|
||||
// We haven't shown the notification before, so do so now.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the URL to fetch snippets from, in the urlFormatter service format.
|
||||
*/
|
||||
XPCOMUtils.defineLazyGetter(AboutHomeUtils, "snippetsURL", function() {
|
||||
let updateURL = Services.prefs
|
||||
.getCharPref(SNIPPETS_URL_PREF)
|
||||
.replace("%STARTPAGE_VERSION%", STARTPAGE_VERSION);
|
||||
return Services.urlFormatter.formatURL(updateURL);
|
||||
});
|
@ -27,7 +27,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
|
||||
]
|
||||
|
||||
EXTRA_PP_JS_MODULES += [
|
||||
'AboutHome.jsm',
|
||||
'AboutHomeUtils.jsm',
|
||||
'RecentWindow.jsm',
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user