mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 02:57:38 +00:00
Backout a933e3c0ec0f (bug 749477) for causing a new random failure in m-oth
This commit is contained in:
parent
1886002408
commit
db05fdca4d
@ -112,38 +112,28 @@ const DEFAULT_SNIPPETS_URLS = [
|
||||
|
||||
const SNIPPETS_UPDATE_INTERVAL_MS = 86400000; // 1 Day.
|
||||
|
||||
let gObserver = new MutationObserver(function (mutations) {
|
||||
for (let mutation of mutations) {
|
||||
if (mutation.attributeName == "searchEngineURL") {
|
||||
gObserver.disconnect();
|
||||
setupSearchEngine();
|
||||
loadSnippets();
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
let gSearchEngine;
|
||||
|
||||
window.addEventListener("load", function () {
|
||||
// Delay search engine setup, cause browser.js::BrowserOnAboutPageLoad runs
|
||||
// later and may use asynchronous getters.
|
||||
window.gObserver.observe(document.documentElement, { attributes: true });
|
||||
fitToWidth();
|
||||
document.addEventListener("DOMContentLoaded", function init() {
|
||||
setupSearchEngine();
|
||||
loadSnippets();
|
||||
});
|
||||
window.addEventListener("load", fitToWidth);
|
||||
window.addEventListener("resize", fitToWidth);
|
||||
|
||||
|
||||
function onSearchSubmit(aEvent)
|
||||
{
|
||||
let searchTerms = document.getElementById("searchText").value;
|
||||
let searchURL = document.documentElement.getAttribute("searchEngineURL");
|
||||
if (searchURL && searchTerms.length > 0) {
|
||||
if (gSearchEngine && searchTerms.length > 0) {
|
||||
const SEARCH_TOKENS = {
|
||||
"_searchTerms_": encodeURIComponent(searchTerms)
|
||||
}
|
||||
let url = gSearchEngine.searchUrl;
|
||||
for (let key in SEARCH_TOKENS) {
|
||||
searchURL = searchURL.replace(key, SEARCH_TOKENS[key]);
|
||||
url = url.replace(key, SEARCH_TOKENS[key]);
|
||||
}
|
||||
window.location.href = searchURL;
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
aEvent.preventDefault();
|
||||
@ -152,24 +142,27 @@ function onSearchSubmit(aEvent)
|
||||
|
||||
function setupSearchEngine()
|
||||
{
|
||||
let searchEngineName = document.documentElement.getAttribute("searchEngineName");
|
||||
let searchEngineInfo = SEARCH_ENGINES[searchEngineName];
|
||||
if (!searchEngineInfo) {
|
||||
gSearchEngine = JSON.parse(localStorage["search-engine"]);
|
||||
|
||||
if (!gSearchEngine)
|
||||
return;
|
||||
|
||||
// Look for extended information, like logo and links.
|
||||
let searchEngineInfo = SEARCH_ENGINES[gSearchEngine.name];
|
||||
if (searchEngineInfo) {
|
||||
for (let prop in searchEngineInfo)
|
||||
gSearchEngine[prop] = searchEngineInfo[prop];
|
||||
}
|
||||
|
||||
// Enqueue additional params if required by the engine definition.
|
||||
if (searchEngineInfo.params) {
|
||||
let searchEngineURL = document.documentElement.getAttribute("searchEngineURL");
|
||||
searchEngineURL += "&" + searchEngineInfo.params;
|
||||
document.documentElement.setAttribute("searchEngineURL", searchEngineURL);
|
||||
}
|
||||
if (gSearchEngine.params)
|
||||
gSearchEngine.searchUrl += "&" + gSearchEngine.params;
|
||||
|
||||
// Add search engine logo.
|
||||
if (searchEngineInfo.image) {
|
||||
if (gSearchEngine.image) {
|
||||
let logoElt = document.getElementById("searchEngineLogo");
|
||||
logoElt.src = searchEngineInfo.image;
|
||||
logoElt.alt = searchEngineInfo.name;
|
||||
logoElt.src = gSearchEngine.image;
|
||||
logoElt.alt = gSearchEngine.name;
|
||||
}
|
||||
|
||||
// The "autofocus" attribute doesn't focus the form element
|
||||
@ -187,7 +180,7 @@ function loadSnippets()
|
||||
{
|
||||
// Check last snippets update.
|
||||
let lastUpdate = localStorage["snippets-last-update"];
|
||||
let updateURL = document.documentElement.getAttribute("snippetsURL");
|
||||
let updateURL = localStorage["snippets-update-url"];
|
||||
if (updateURL && (!lastUpdate ||
|
||||
Date.now() - lastUpdate > SNIPPETS_UPDATE_INTERVAL_MS)) {
|
||||
// Try to update from network.
|
||||
|
@ -90,9 +90,6 @@ __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.defineLazyGetter(this, "Weave", function() {
|
||||
let tmp = {};
|
||||
@ -2498,19 +2495,10 @@ function BrowserOnAboutPageLoad(document) {
|
||||
// the hidden attribute set on the apps button in aboutHome.xhtml
|
||||
if (getBoolPref("browser.aboutHome.apps", false))
|
||||
document.getElementById("apps").removeAttribute("hidden");
|
||||
|
||||
let ss = Components.classes["@mozilla.org/browser/sessionstore;1"].
|
||||
getService(Components.interfaces.nsISessionStore);
|
||||
if (!ss.canRestoreLastSession)
|
||||
document.getElementById("launcher").removeAttribute("session");
|
||||
|
||||
// Inject search engine and snippets URL.
|
||||
let docElt = document.documentElement;
|
||||
docElt.setAttribute("snippetsURL", AboutHomeUtils.snippetsURL);
|
||||
docElt.setAttribute("searchEngineName",
|
||||
AboutHomeUtils.defaultSearchEngine.name);
|
||||
docElt.setAttribute("searchEngineURL",
|
||||
AboutHomeUtils.defaultSearchEngine.searchURL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4490,14 +4478,9 @@ var TabsProgressListener = {
|
||||
// We can't look for this during onLocationChange since at that point the
|
||||
// document URI is not yet the about:-uri of the error page.
|
||||
|
||||
let document = aWebProgress.DOMWindow.document;
|
||||
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
|
||||
Components.isSuccessCode(aStatus) &&
|
||||
/^about:/.test(document.documentURI) &&
|
||||
!document.documentElement.hasAttribute("hasBrowserHandlers")) {
|
||||
// STATE_STOP may be received twice for documents, thus store an
|
||||
// attribute to ensure handling it just once.
|
||||
document.documentElement.setAttribute("hasBrowserHandlers", "true");
|
||||
/^about:/.test(aWebProgress.DOMWindow.document.documentURI)) {
|
||||
aBrowser.addEventListener("click", BrowserOnClick, true);
|
||||
aBrowser.addEventListener("pagehide", function onPageHide(event) {
|
||||
if (event.target.defaultView.frameElement)
|
||||
@ -4507,7 +4490,7 @@ var TabsProgressListener = {
|
||||
}, true);
|
||||
|
||||
// We also want to make changes to page UI for unprivileged about pages.
|
||||
BrowserOnAboutPageLoad(document);
|
||||
BrowserOnAboutPageLoad(aWebProgress.DOMWindow.document);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -15,17 +15,64 @@ registerCleanupFunction(function() {
|
||||
let gTests = [
|
||||
|
||||
{
|
||||
desc: "Check that clearing cookies does not clear storage",
|
||||
desc: "Check that rejecting cookies does not prevent page from working",
|
||||
setup: function ()
|
||||
{
|
||||
Cc["@mozilla.org/dom/storagemanager;1"]
|
||||
.getService(Ci.nsIObserver)
|
||||
.observe(null, "cookie-changed", "cleared");
|
||||
Services.prefs.setIntPref("network.cookies.cookieBehavior", 2);
|
||||
},
|
||||
run: function ()
|
||||
{
|
||||
let storage = getStorage();
|
||||
isnot(storage.getItem("snippets-last-update"), null);
|
||||
isnot(storage.getItem("search-engine"), null);
|
||||
try {
|
||||
Services.prefs.clearUserPref("network.cookies.cookieBehavior");
|
||||
} catch (ex) {}
|
||||
executeSoon(runNextTest);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
desc: "Check that asking for cookies does not prevent page from working",
|
||||
setup: function ()
|
||||
{
|
||||
Services.prefs.setIntPref("network.cookie.lifetimePolicy", 1);
|
||||
},
|
||||
run: function ()
|
||||
{
|
||||
let storage = getStorage();
|
||||
isnot(storage.getItem("search-engine"), null);
|
||||
try {
|
||||
Services.prefs.clearUserPref("network.cookie.lifetimePolicy");
|
||||
} catch (ex) {}
|
||||
executeSoon(runNextTest);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
desc: "Check that clearing cookies does not prevent page from working",
|
||||
setup: function ()
|
||||
{
|
||||
Components.classes["@mozilla.org/dom/storagemanager;1"].
|
||||
getService(Components.interfaces.nsIObserver).
|
||||
observe(null, "cookie-changed", "cleared");
|
||||
},
|
||||
run: function ()
|
||||
{
|
||||
let storage = getStorage();
|
||||
isnot(storage.getItem("search-engine"), null);
|
||||
executeSoon(runNextTest);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
desc: "Check normal status is working",
|
||||
setup: function ()
|
||||
{
|
||||
},
|
||||
run: function ()
|
||||
{
|
||||
let storage = getStorage();
|
||||
isnot(storage.getItem("search-engine"), null);
|
||||
executeSoon(runNextTest);
|
||||
}
|
||||
},
|
||||
@ -73,6 +120,14 @@ function test()
|
||||
{
|
||||
waitForExplicitFinish();
|
||||
|
||||
// browser-chrome test harness inits browser specifying an hardcoded page
|
||||
// and this causes nsIBrowserHandler.defaultArgs to not be evaluated since
|
||||
// there is a predefined argument.
|
||||
// About:home localStorage is populated with overridden homepage, that is
|
||||
// setup in the defaultArgs getter.
|
||||
// Thus to populate about:home we need to get defaultArgs manually.
|
||||
Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler).defaultArgs;
|
||||
|
||||
// Ensure that by default we don't try to check for remote snippets since that
|
||||
// could be tricky due to network bustages or slowness.
|
||||
let storage = getStorage();
|
||||
@ -93,20 +148,10 @@ function runNextTest()
|
||||
info(test.desc);
|
||||
test.setup();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab("about:home");
|
||||
tab.linkedBrowser.addEventListener("load", function load(event) {
|
||||
tab.linkedBrowser.removeEventListener("load", load, true);
|
||||
|
||||
let observer = new MutationObserver(function (mutations) {
|
||||
for (let mutation of mutations) {
|
||||
if (mutation.attributeName == "searchEngineURL") {
|
||||
observer.disconnect();
|
||||
executeSoon(test.run);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
let docElt = tab.linkedBrowser.contentDocument.documentElement;
|
||||
observer.observe(docElt, { attributes: true });
|
||||
tab.linkedBrowser.addEventListener("load", function (event) {
|
||||
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
||||
// Some part of the page is populated on load, so enqueue on it.
|
||||
executeSoon(test.run);
|
||||
}, true);
|
||||
}
|
||||
else {
|
||||
|
@ -577,6 +577,10 @@ nsBrowserContentHandler.prototype = {
|
||||
} catch (ex) {}
|
||||
let override = needHomepageOverride(prefb);
|
||||
if (override != OVERRIDE_NONE) {
|
||||
// Setup the default search engine to about:home page.
|
||||
AboutHomeUtils.loadDefaultSearchEngine();
|
||||
AboutHomeUtils.loadSnippetsURL();
|
||||
|
||||
switch (override) {
|
||||
case OVERRIDE_NEW_PROFILE:
|
||||
// New profile.
|
||||
@ -599,6 +603,13 @@ nsBrowserContentHandler.prototype = {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// No need to override homepage, but update snippets url if the pref has
|
||||
// been manually changed.
|
||||
if (Services.prefs.prefHasUserValue(AboutHomeUtils.SNIPPETS_URL_PREF)) {
|
||||
AboutHomeUtils.loadSnippetsURL();
|
||||
}
|
||||
}
|
||||
} catch (ex) {}
|
||||
|
||||
// formatURLPref might return "about:blank" if getting the pref fails
|
||||
@ -824,5 +835,41 @@ nsDefaultCommandLineHandler.prototype = {
|
||||
helpInfo : "",
|
||||
};
|
||||
|
||||
let AboutHomeUtils = {
|
||||
SNIPPETS_URL_PREF: "browser.aboutHomeSnippets.updateUrl",
|
||||
get _storage() {
|
||||
let aboutHomeURI = Services.io.newURI("moz-safe-about:home", null, null);
|
||||
let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"].
|
||||
getService(Components.interfaces.nsIScriptSecurityManager).
|
||||
getNoAppCodebasePrincipal(aboutHomeURI);
|
||||
let dsm = Components.classes["@mozilla.org/dom/storagemanager;1"].
|
||||
getService(Components.interfaces.nsIDOMStorageManager);
|
||||
return dsm.getLocalStorageForPrincipal(principal, "");
|
||||
},
|
||||
|
||||
loadDefaultSearchEngine: function AHU_loadDefaultSearchEngine()
|
||||
{
|
||||
let defaultEngine = Services.search.originalDefaultEngine;
|
||||
let submission = defaultEngine.getSubmission("_searchTerms_");
|
||||
if (submission.postData)
|
||||
throw new Error("Home page does not support POST search engines.");
|
||||
let engine = {
|
||||
name: defaultEngine.name
|
||||
, searchUrl: submission.uri.spec
|
||||
}
|
||||
this._storage.setItem("search-engine", JSON.stringify(engine));
|
||||
},
|
||||
|
||||
loadSnippetsURL: function AHU_loadSnippetsURL()
|
||||
{
|
||||
const STARTPAGE_VERSION = 3;
|
||||
let updateURL = Services.prefs
|
||||
.getCharPref(this.SNIPPETS_URL_PREF)
|
||||
.replace("%STARTPAGE_VERSION%", STARTPAGE_VERSION);
|
||||
updateURL = Services.urlFormatter.formatURL(updateURL);
|
||||
this._storage.setItem("snippets-update-url", updateURL);
|
||||
},
|
||||
};
|
||||
|
||||
var components = [nsBrowserContentHandler, nsDefaultCommandLineHandler];
|
||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|
||||
|
@ -1,45 +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";
|
||||
|
||||
const 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 = 3;
|
||||
|
||||
let AboutHomeUtils = new Object();
|
||||
|
||||
/**
|
||||
* Returns an object containing the name and searchURL of the original default
|
||||
* search engine.
|
||||
*/
|
||||
XPCOMUtils.defineLazyGetter(AboutHomeUtils, "defaultSearchEngine", function() {
|
||||
let defaultEngine = Services.search.originalDefaultEngine;
|
||||
let submission = defaultEngine.getSubmission("_searchTerms_");
|
||||
if (submission.postData) {
|
||||
throw new Error("Home page does not support POST search engines.");
|
||||
}
|
||||
|
||||
return Object.freeze({
|
||||
name: defaultEngine.name,
|
||||
searchURL: submission.uri.spec
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 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);
|
||||
});
|
@ -14,7 +14,6 @@ include $(topsrcdir)/config/config.mk
|
||||
TEST_DIRS += test
|
||||
|
||||
EXTRA_JS_MODULES = \
|
||||
AboutHomeUtils.jsm \
|
||||
BrowserNewTabPreloader.jsm \
|
||||
openLocationLastURL.jsm \
|
||||
NetworkPrioritizer.jsm \
|
||||
|
Loading…
Reference in New Issue
Block a user