зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 41729438f597 (bug 900865) for Windows mochitest-bc crashes.
This commit is contained in:
Родитель
5b03824427
Коммит
dfe10b3ffb
|
@ -153,7 +153,7 @@ const SNIPPETS_OBJECTSTORE_NAME = "snippets";
|
|||
let gInitialized = false;
|
||||
let gObserver = new MutationObserver(function (mutations) {
|
||||
for (let mutation of mutations) {
|
||||
if (mutation.attributeName == "searchEngineName") {
|
||||
if (mutation.attributeName == "searchEngineURL") {
|
||||
setupSearchEngine();
|
||||
if (!gInitialized) {
|
||||
ensureSnippetsMapThen(loadSnippets);
|
||||
|
@ -295,17 +295,52 @@ function ensureSnippetsMapThen(aCallback)
|
|||
function onSearchSubmit(aEvent)
|
||||
{
|
||||
let searchTerms = document.getElementById("searchText").value;
|
||||
let engineName = document.documentElement.getAttribute("searchEngineName");
|
||||
let searchURL = document.documentElement.getAttribute("searchEngineURL");
|
||||
|
||||
if (engineName && searchTerms.length > 0) {
|
||||
// Send an event that will perform a search and Firefox Health Report will
|
||||
// record that a search from about:home has occurred.
|
||||
let eventData = JSON.stringify({
|
||||
engineName: engineName,
|
||||
searchTerms: searchTerms
|
||||
});
|
||||
let event = new CustomEvent("AboutHomeSearchEvent", {detail: eventData});
|
||||
if (searchURL && searchTerms.length > 0) {
|
||||
// Send an event that a search was performed. This was originally
|
||||
// added so Firefox Health Report could record that a search from
|
||||
// about:home had occurred.
|
||||
let engineName = document.documentElement.getAttribute("searchEngineName");
|
||||
let event = new CustomEvent("AboutHomeSearchEvent", {detail: engineName});
|
||||
document.dispatchEvent(event);
|
||||
|
||||
const SEARCH_TOKEN = "_searchTerms_";
|
||||
let searchPostData = document.documentElement.getAttribute("searchEnginePostData");
|
||||
if (searchPostData) {
|
||||
// Check if a post form already exists. If so, remove it.
|
||||
const POST_FORM_NAME = "searchFormPost";
|
||||
let form = document.forms[POST_FORM_NAME];
|
||||
if (form) {
|
||||
form.parentNode.removeChild(form);
|
||||
}
|
||||
|
||||
// Create a new post form.
|
||||
form = document.body.appendChild(document.createElement("form"));
|
||||
form.setAttribute("name", POST_FORM_NAME);
|
||||
// Set the URL to submit the form to.
|
||||
form.setAttribute("action", searchURL.replace(SEARCH_TOKEN, searchTerms));
|
||||
form.setAttribute("method", "post");
|
||||
|
||||
// Create new <input type=hidden> elements for search param.
|
||||
searchPostData = searchPostData.split("&");
|
||||
for (let postVar of searchPostData) {
|
||||
let [name, value] = postVar.split("=");
|
||||
if (value == SEARCH_TOKEN) {
|
||||
value = searchTerms;
|
||||
}
|
||||
let input = document.createElement("input");
|
||||
input.setAttribute("type", "hidden");
|
||||
input.setAttribute("name", name);
|
||||
input.setAttribute("value", value);
|
||||
form.appendChild(input);
|
||||
}
|
||||
// Submit the form.
|
||||
form.submit();
|
||||
} else {
|
||||
searchURL = searchURL.replace(SEARCH_TOKEN, encodeURIComponent(searchTerms));
|
||||
window.location.href = searchURL;
|
||||
}
|
||||
}
|
||||
|
||||
aEvent.preventDefault();
|
||||
|
|
|
@ -90,13 +90,19 @@ let AboutHomeListener = {
|
|||
|
||||
// Inject search engine and snippets URL.
|
||||
let docElt = doc.documentElement;
|
||||
// set the following attributes BEFORE searchEngineName, which triggers to
|
||||
// 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);
|
||||
docElt.setAttribute("searchEngineName", Services.search.defaultEngine.name);
|
||||
|
||||
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() {
|
||||
|
@ -129,7 +135,7 @@ let AboutHomeListener = {
|
|||
sendAsyncMessage("AboutHome:RequestUpdate");
|
||||
|
||||
doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) {
|
||||
sendAsyncMessage("AboutHome:Search", { searchData: e.detail });
|
||||
sendAsyncMessage("AboutHome:Search", { engineName: e.detail });
|
||||
}, true, true);
|
||||
},
|
||||
|
||||
|
@ -274,4 +280,4 @@ let ClickEventHandler = {
|
|||
return [href ? makeURLAbsolute(baseURI, href) : null, null];
|
||||
}
|
||||
};
|
||||
ClickEventHandler.init();
|
||||
ClickEventHandler.init();
|
|
@ -107,8 +107,7 @@ let gTests = [
|
|||
let engineName = doc.documentElement.getAttribute("searchEngineName");
|
||||
|
||||
doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) {
|
||||
let data = JSON.parse(e.detail);
|
||||
is(data.engineName, engineName, "Detail is search engine name");
|
||||
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
|
||||
|
@ -288,7 +287,7 @@ let gTests = [
|
|||
// 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 == "searchEngineName") {
|
||||
if (mutation.attributeName == "searchEngineURL") {
|
||||
searchText.value = needle;
|
||||
searchText.focus();
|
||||
EventUtils.synthesizeKey("VK_RETURN", {});
|
||||
|
@ -446,7 +445,7 @@ function promiseBrowserAttributes(aTab)
|
|||
}
|
||||
|
||||
// Now we just have to wait for the last attribute.
|
||||
if (mutation.attributeName == "searchEngineName") {
|
||||
if (mutation.attributeName == "searchEngineURL") {
|
||||
info("Remove attributes observer");
|
||||
observer.disconnect();
|
||||
// Must be sure to continue after the page mutation observer.
|
||||
|
|
|
@ -25,6 +25,21 @@ 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
|
||||
|
@ -158,19 +173,9 @@ let AboutHome = {
|
|||
break;
|
||||
|
||||
case "AboutHome:Search":
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(aMessage.data.searchData);
|
||||
} catch(ex) {
|
||||
Cu.reportError(ex);
|
||||
break;
|
||||
}
|
||||
#ifdef MOZ_SERVICES_HEALTHREPORT
|
||||
window.BrowserSearch.recordSearchInHealthReport(data.engineName, "abouthome");
|
||||
window.BrowserSearch.recordSearchInHealthReport(aMessage.data.engineName, "abouthome");
|
||||
#endif
|
||||
// Trigger a search through nsISearchEngine.getSubmission()
|
||||
let submission = Services.search.currentEngine.getSubmission(data.searchTerms);
|
||||
window.loadURI(submission.uri.spec, null, submission.postData);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
@ -184,7 +189,8 @@ let AboutHome = {
|
|||
showRestoreLastSession: ss.canRestoreLastSession,
|
||||
snippetsURL: AboutHomeUtils.snippetsURL,
|
||||
showKnowYourRights: AboutHomeUtils.showKnowYourRights,
|
||||
snippetsVersion: AboutHomeUtils.snippetsVersion
|
||||
snippetsVersion: AboutHomeUtils.snippetsVersion,
|
||||
defaultSearchEngine: AboutHomeUtils.defaultSearchEngine
|
||||
};
|
||||
|
||||
if (AboutHomeUtils.showKnowYourRights) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
interface nsIURI;
|
||||
interface nsIInputStream;
|
||||
|
||||
[scriptable, uuid(58e4f602-a7c8-4cd1-9dca-716705e826ef)]
|
||||
[scriptable, uuid(82ec6ee8-68b5-49ef-87b7-0d5240f8a183)]
|
||||
interface nsISearchSubmission : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -16,6 +16,12 @@ interface nsISearchSubmission : nsISupports
|
|||
*/
|
||||
readonly attribute nsIInputStream postData;
|
||||
|
||||
/**
|
||||
* The POST data associated with a search submission as an
|
||||
* application/x-www-form-urlencoded string. May be null.
|
||||
*/
|
||||
readonly attribute AString postDataString;
|
||||
|
||||
/**
|
||||
* The URI to submit a search to.
|
||||
*/
|
||||
|
|
|
@ -931,6 +931,7 @@ EngineURL.prototype = {
|
|||
}
|
||||
|
||||
var postData = null;
|
||||
let postDataString = null;
|
||||
if (this.method == "GET") {
|
||||
// GET method requests have no post data, and append the encoded
|
||||
// query string to the url...
|
||||
|
@ -938,8 +939,8 @@ EngineURL.prototype = {
|
|||
url += "?";
|
||||
url += dataString;
|
||||
} else if (this.method == "POST") {
|
||||
// POST method requests must wrap the encoded text in a MIME
|
||||
// stream and supply that as POSTDATA.
|
||||
// For POST requests, specify the data as a MIME stream as well as a string.
|
||||
postDataString = dataString;
|
||||
var stringStream = Cc["@mozilla.org/io/string-input-stream;1"].
|
||||
createInstance(Ci.nsIStringInputStream);
|
||||
stringStream.data = dataString;
|
||||
|
@ -951,7 +952,7 @@ EngineURL.prototype = {
|
|||
postData.setData(stringStream);
|
||||
}
|
||||
|
||||
return new Submission(makeURI(url), postData);
|
||||
return new Submission(makeURI(url), postData, postDataString);
|
||||
},
|
||||
|
||||
_hasRelation: function SRC_EURL__hasRelation(aRel)
|
||||
|
@ -2543,7 +2544,7 @@ Engine.prototype = {
|
|||
|
||||
if (!aData) {
|
||||
// Return a dummy submission object with our searchForm attribute
|
||||
return new Submission(makeURI(this.searchForm), null);
|
||||
return new Submission(makeURI(this.searchForm));
|
||||
}
|
||||
|
||||
LOG("getSubmission: In data: \"" + aData + "\"; Purpose: \"" + aPurpose + "\"");
|
||||
|
@ -2580,9 +2581,10 @@ Engine.prototype = {
|
|||
};
|
||||
|
||||
// nsISearchSubmission
|
||||
function Submission(aURI, aPostData = null) {
|
||||
function Submission(aURI, aPostData = null, aPostDataString = null) {
|
||||
this._uri = aURI;
|
||||
this._postData = aPostData;
|
||||
this._postDataString = aPostDataString;
|
||||
}
|
||||
Submission.prototype = {
|
||||
get uri() {
|
||||
|
@ -2591,6 +2593,9 @@ Submission.prototype = {
|
|||
get postData() {
|
||||
return this._postData;
|
||||
},
|
||||
get postDataString() {
|
||||
return this._postDataString;
|
||||
},
|
||||
QueryInterface: function SRCH_SUBM_QI(aIID) {
|
||||
if (aIID.equals(Ci.nsISearchSubmission) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
|
|
Загрузка…
Ссылка в новой задаче