Bug 738818 part 3: Make changing currentEngine also change defaultEngine, including for about:home. r=fryn ui-r=limi sr=gavin

This commit is contained in:
Mike de Boer 2013-04-09 17:12:27 -07:00
parent 9961d20654
commit 17035d928b
4 changed files with 46 additions and 33 deletions

View File

@ -256,19 +256,6 @@ function onSearchSubmit(aEvent)
function setupSearchEngine()
{
let searchEngineName = document.documentElement.getAttribute("searchEngineName");
let searchEngineInfo = SEARCH_ENGINES[searchEngineName];
if (!searchEngineInfo) {
return;
}
// Add search engine logo.
if (searchEngineInfo.image) {
let logoElt = document.getElementById("searchEngineLogo");
logoElt.src = searchEngineInfo.image;
logoElt.alt = searchEngineName;
}
// The "autofocus" attribute doesn't focus the form element
// immediately when the element is first drawn, so the
// attribute is also used for styling when the page first loads.
@ -277,6 +264,26 @@ function setupSearchEngine()
searchText.removeEventListener("blur", searchText_onBlur);
searchText.removeAttribute("autofocus");
});
let searchEngineName = document.documentElement.getAttribute("searchEngineName");
let searchEngineInfo = SEARCH_ENGINES[searchEngineName];
let logoElt = document.getElementById("searchEngineLogo");
// Add search engine logo.
if (searchEngineInfo && searchEngineInfo.image) {
logoElt.parentNode.hidden = false;
logoElt.src = searchEngineInfo.image;
#ifdef XP_MACOSX
if (searchEngineInfo.imageHD && !window.matchMedia("(max-resolution: 1dppx)").matches)
logoElt.src = searchEngineInfo.imageHD;
#endif
logoElt.alt = searchEngineName;
searchText.placeholder = "";
}
else {
logoElt.parentNode.hidden = true;
searchText.placeholder = searchEngineName;
}
}

View File

@ -45,6 +45,7 @@ var gEngineManagerDialog = {
break;
case "engine-removed":
case "engine-current":
case "engine-default":
// Not relevant
break;
}

View File

@ -121,8 +121,12 @@
<field name="searchButton">document.getAnonymousElementByAttribute(this,
"anonid", "searchbar-engine-button");</field>
<property name="currentEngine"
onset="this.searchService.currentEngine = val; return val;">
<property name="currentEngine">
<setter><![CDATA[
let ss = this.searchService;
ss.defaultEngine = ss.currentEngine = val;
return val;
]]></setter>
<getter><![CDATA[
var currentEngine = this.searchService.currentEngine;
// Return a dummy engine if there is no currentEngine
@ -422,8 +426,9 @@
var newIndex = this.engines.indexOf(this.currentEngine);
newIndex += isNextEngine ? 1 : -1;
if (newIndex >= 0 && newIndex < this.engines.length)
if (newIndex >= 0 && newIndex < this.engines.length) {
this.currentEngine = this.engines[newIndex];
}
aEvent.preventDefault();
aEvent.stopPropagation();

View File

@ -18,6 +18,23 @@ 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");
if (submission.postData) {
throw new Error("Home page does not support POST search engines.");
}
return Object.freeze({
name: defaultEngine.name,
searchURL: submission.uri.spec
});
},
/*
* showKnowYourRights - Determines if the user should be shown the
* about:rights notification. The notification should *not* be shown if
@ -59,23 +76,6 @@ this.AboutHomeUtils = {
}
};
/**
* Returns an object containing the name and searchURL of the original default
* search engine.
*/
XPCOMUtils.defineLazyGetter(AboutHomeUtils, "defaultSearchEngine", function() {
let defaultEngine = Services.search.defaultEngine;
let submission = defaultEngine.getSubmission("_searchTerms_", null, "homepage");
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.
*/