From 0dd746c9477ad16242368f6cbe52c7fe645bad61 Mon Sep 17 00:00:00 2001 From: Mike de Boer Date: Fri, 30 Aug 2013 18:20:22 +0200 Subject: [PATCH 1/6] Bug 900865: Make about:home call nsISearchEngine.getSubmission for all searches. r=gavin --- browser/base/content/abouthome/aboutHome.js | 55 ++++--------------- browser/base/content/content.js | 14 ++--- .../base/content/test/browser_aboutHome.js | 7 ++- browser/modules/AboutHome.jsm | 30 ++++------ .../base/public/nsIBrowserSearchService.idl | 8 +-- toolkit/components/search/nsSearchService.js | 15 ++--- 6 files changed, 36 insertions(+), 93 deletions(-) diff --git a/browser/base/content/abouthome/aboutHome.js b/browser/base/content/abouthome/aboutHome.js index fa0691d16baa..738fe27ab045 100644 --- a/browser/base/content/abouthome/aboutHome.js +++ b/browser/base/content/abouthome/aboutHome.js @@ -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 == "searchEngineURL") { + if (mutation.attributeName == "searchEngineName") { setupSearchEngine(); if (!gInitialized) { ensureSnippetsMapThen(loadSnippets); @@ -295,52 +295,17 @@ function ensureSnippetsMapThen(aCallback) function onSearchSubmit(aEvent) { let searchTerms = document.getElementById("searchText").value; - let searchURL = document.documentElement.getAttribute("searchEngineURL"); + let engineName = document.documentElement.getAttribute("searchEngineName"); - 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}); + 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}); 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 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(); diff --git a/browser/base/content/content.js b/browser/base/content/content.js index 824b29a2ac4d..e734f4b18672 100644 --- a/browser/base/content/content.js +++ b/browser/base/content/content.js @@ -90,19 +90,13 @@ let AboutHomeListener = { // Inject search engine and snippets URL. let docElt = doc.documentElement; - // set the following attributes BEFORE searchEngineURL, which triggers to + // set the following attributes BEFORE searchEngineName, 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); + docElt.setAttribute("searchEngineName", Services.search.defaultEngine.name); }, onPageLoad: function() { @@ -135,7 +129,7 @@ let AboutHomeListener = { sendAsyncMessage("AboutHome:RequestUpdate"); doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) { - sendAsyncMessage("AboutHome:Search", { engineName: e.detail }); + sendAsyncMessage("AboutHome:Search", { searchData: e.detail }); }, true, true); }, @@ -280,4 +274,4 @@ let ClickEventHandler = { return [href ? makeURLAbsolute(baseURI, href) : null, null]; } }; -ClickEventHandler.init(); \ No newline at end of file +ClickEventHandler.init(); diff --git a/browser/base/content/test/browser_aboutHome.js b/browser/base/content/test/browser_aboutHome.js index 7afe2bae5329..430b137b8ce6 100644 --- a/browser/base/content/test/browser_aboutHome.js +++ b/browser/base/content/test/browser_aboutHome.js @@ -107,7 +107,8 @@ let gTests = [ let engineName = doc.documentElement.getAttribute("searchEngineName"); doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) { - is(e.detail, engineName, "Detail is search engine name"); + let data = JSON.parse(e.detail); + is(data.engineName, 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 @@ -287,7 +288,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 == "searchEngineURL") { + if (mutation.attributeName == "searchEngineName") { searchText.value = needle; searchText.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); @@ -445,7 +446,7 @@ function promiseBrowserAttributes(aTab) } // Now we just have to wait for the last attribute. - if (mutation.attributeName == "searchEngineURL") { + if (mutation.attributeName == "searchEngineName") { info("Remove attributes observer"); observer.disconnect(); // Must be sure to continue after the page mutation observer. diff --git a/browser/modules/AboutHome.jsm b/browser/modules/AboutHome.jsm index bad0ad6f6719..bdf61bf90bba 100644 --- a/browser/modules/AboutHome.jsm +++ b/browser/modules/AboutHome.jsm @@ -25,21 +25,6 @@ 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 @@ -173,9 +158,19 @@ 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(aMessage.data.engineName, "abouthome"); + window.BrowserSearch.recordSearchInHealthReport(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; } }, @@ -189,8 +184,7 @@ let AboutHome = { showRestoreLastSession: ss.canRestoreLastSession, snippetsURL: AboutHomeUtils.snippetsURL, showKnowYourRights: AboutHomeUtils.showKnowYourRights, - snippetsVersion: AboutHomeUtils.snippetsVersion, - defaultSearchEngine: AboutHomeUtils.defaultSearchEngine + snippetsVersion: AboutHomeUtils.snippetsVersion }; if (AboutHomeUtils.showKnowYourRights) { diff --git a/netwerk/base/public/nsIBrowserSearchService.idl b/netwerk/base/public/nsIBrowserSearchService.idl index d8182fd81f83..c15e1298bfd3 100644 --- a/netwerk/base/public/nsIBrowserSearchService.idl +++ b/netwerk/base/public/nsIBrowserSearchService.idl @@ -7,7 +7,7 @@ interface nsIURI; interface nsIInputStream; -[scriptable, uuid(82ec6ee8-68b5-49ef-87b7-0d5240f8a183)] +[scriptable, uuid(5799251f-5b55-4df7-a9e7-0c27812c469a)] interface nsISearchSubmission : nsISupports { /** @@ -16,12 +16,6 @@ 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. */ diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/nsSearchService.js index 4bbf533eb316..15f96eb09702 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -931,7 +931,6 @@ 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... @@ -939,8 +938,8 @@ EngineURL.prototype = { url += "?"; url += dataString; } else if (this.method == "POST") { - // For POST requests, specify the data as a MIME stream as well as a string. - postDataString = dataString; + // POST method requests must wrap the encoded text in a MIME + // stream and supply that as POSTDATA. var stringStream = Cc["@mozilla.org/io/string-input-stream;1"]. createInstance(Ci.nsIStringInputStream); stringStream.data = dataString; @@ -952,7 +951,7 @@ EngineURL.prototype = { postData.setData(stringStream); } - return new Submission(makeURI(url), postData, postDataString); + return new Submission(makeURI(url), postData); }, _hasRelation: function SRC_EURL__hasRelation(aRel) @@ -2544,7 +2543,7 @@ Engine.prototype = { if (!aData) { // Return a dummy submission object with our searchForm attribute - return new Submission(makeURI(this.searchForm)); + return new Submission(makeURI(this.searchForm), null); } LOG("getSubmission: In data: \"" + aData + "\"; Purpose: \"" + aPurpose + "\""); @@ -2581,10 +2580,9 @@ Engine.prototype = { }; // nsISearchSubmission -function Submission(aURI, aPostData = null, aPostDataString = null) { +function Submission(aURI, aPostData = null) { this._uri = aURI; this._postData = aPostData; - this._postDataString = aPostDataString; } Submission.prototype = { get uri() { @@ -2593,9 +2591,6 @@ 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)) From d3026d9dad4c68d17eb07e3ffdcf4295ad444767 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Fri, 30 Aug 2013 09:30:00 -0700 Subject: [PATCH 2/6] bug 910741 fix opening tabs from clicked links in share panel, r=felipe --- browser/base/content/browser-social.js | 7 +++++-- browser/base/content/test/social/browser_social_flyout.js | 8 +++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/browser/base/content/browser-social.js b/browser/base/content/browser-social.js index f831f0a9cc2b..1a6de8739c12 100644 --- a/browser/base/content/browser-social.js +++ b/browser/base/content/browser-social.js @@ -322,7 +322,10 @@ SocialUI = { let containerParent = container.parentNode; if (containerParent.classList.contains("social-panel") && containerParent instanceof Ci.nsIDOMXULPopupElement) { - containerParent.hidePopup(); + // allow the link traversal to finish before closing the panel + setTimeout(() => { + containerParent.hidePopup(); + }, 0); } }, @@ -693,7 +696,7 @@ SocialShare = { onHidden: function() { this.shareButton.removeAttribute("open"); - this.iframe.setAttribute("src", "data:text/plain;charset=utf8,") + this.iframe.setAttribute("src", "data:text/plain;charset=utf8,"); this.currentShare = null; }, diff --git a/browser/base/content/test/social/browser_social_flyout.js b/browser/base/content/test/social/browser_social_flyout.js index b710a3444e56..b8642e33854d 100644 --- a/browser/base/content/test/social/browser_social_flyout.js +++ b/browser/base/content/test/social/browser_social_flyout.js @@ -133,12 +133,10 @@ var tests = { function onTabOpen(event) { gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); - is(panel.state, "closed", "flyout should be closed"); - ok(true, "Link should open a new tab"); - executeSoon(function(){ + waitForCondition(function() { return panel.state == "closed" }, function() { gBrowser.removeTab(event.target); next(); - }); + }, "panel should close after tab open"); } let panel = document.getElementById("social-flyout-panel"); @@ -154,7 +152,7 @@ var tests = { if (e.data.result == "shown") { // click on our test link is(panel.state, "open", "flyout should be open"); - gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true); + gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true); let iframe = panel.firstChild; iframe.contentDocument.getElementById('traversal').click(); } From 3af357b6783dca460f288a9909d8a1e88c722c28 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Fri, 30 Aug 2013 11:11:20 -0700 Subject: [PATCH 3/6] bug 906212 fix socialapi ui startup regressions, r=markh --- browser/base/content/browser-sets.inc | 2 +- browser/base/content/browser-social.js | 6 +- .../test/social/browser_social_window.js | 67 ++++++++++--------- browser/base/content/test/social/head.js | 10 +++ browser/modules/Social.jsm | 5 +- toolkit/components/social/SocialService.jsm | 10 +++ 6 files changed, 63 insertions(+), 37 deletions(-) diff --git a/browser/base/content/browser-sets.inc b/browser/base/content/browser-sets.inc index 57d0356c0e4e..1acfbbc3c3dc 100644 --- a/browser/base/content/browser-sets.inc +++ b/browser/base/content/browser-sets.inc @@ -111,7 +111,7 @@ - +