Bug 1177237 - Implement OS query parsing and user search choice. r=jaws

This commit is contained in:
Justin Dolske 2015-07-06 18:11:05 -07:00
parent eb48e9f038
commit f5edb410f0
5 changed files with 56 additions and 2 deletions

View File

@ -422,6 +422,12 @@ pref("browser.search.showOneOffButtons", true);
// comma seperated list of of engines to hide in the search panel.
pref("browser.search.hiddenOneOffs", "");
#ifdef XP_WIN
pref("browser.search.redirectWindowsSearch", true);
#else
pref("browser.search.redirectWindowsSearch", false);
#endif
pref("browser.sessionhistory.max_entries", 50);
// Built-in default permissions.

View File

@ -2,6 +2,8 @@
* 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/. */
Components.utils.importGlobalProperties(["URLSearchParams"]);
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/AppConstants.jsm");
@ -727,10 +729,42 @@ nsDefaultCommandLineHandler.prototype = {
}
}
let redirectWinSearch = false;
if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
redirectWinSearch = Services.prefs.getBoolPref("browser.search.redirectWindowsSearch");
}
try {
var ar;
while ((ar = cmdLine.handleFlagWithParam("url", false))) {
var uri = resolveURIInternal(cmdLine, ar);
// Searches in the Windows 10 task bar searchbox simply open the default browser
// with a URL for a search on Bing. Here we extract the search term and use the
// user's default search engine instead.
if (redirectWinSearch && uri.spec.startsWith("https://www.bing.com/search")) {
try {
var url = uri.QueryInterface(Components.interfaces.nsIURL);
var params = new URLSearchParams(url.query);
// We don't want to rewrite all Bing URLs coming from external apps. Look
// for the magic URL parm that's present in searches from the task bar.
// (Typed searches use "form=WNSGPH", Cortana voice searches use "FORM=WNSBOX")
var formParam = params.get("form");
if (!formParam) {
formParam = params.get("FORM");
}
if (formParam == "WNSGPH" || formParam == "WNSBOX") {
var term = params.get("q");
var ss = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(nsIBrowserSearchService);
var submission = ss.defaultEngine.getSubmission(term, null, "searchbar");
uri = submission.uri;
}
} catch (e) {
Components.utils.reportError("Couldn't redirect Windows search: " + e);
}
}
urilist.push(uri);
}
}

View File

@ -3,6 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
"resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
@ -11,6 +13,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
const ENGINE_FLAVOR = "text/x-moz-search-engine";
document.addEventListener("Initialized", () => {
if (!AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
document.getElementById("redirectSearchCheckbox").hidden = true;
}
if (Services.prefs.getBoolPref("browser.search.showOneOffButtons"))
return;

View File

@ -1,15 +1,17 @@
<preferences id="searchPreferences" hidden="true" data-category="paneSearch">
<!-- Suggest -->
<preference id="browser.search.suggest.enabled"
name="browser.search.suggest.enabled"
type="bool"/>
<!-- One off providers -->
<preference id="browser.search.hiddenOneOffs"
name="browser.search.hiddenOneOffs"
type="unichar"/>
<preference id="browser.search.redirectWindowsSearch"
name="browser.search.redirectWindowsSearch"
type="bool"/>
</preferences>
<script type="application/javascript"
@ -35,6 +37,10 @@
label="&provideSearchSuggestions.label;"
accesskey="&provideSearchSuggestions.accesskey;"
preference="browser.search.suggest.enabled"/>
<checkbox id="redirectSearchCheckbox"
label="&redirectWindowsSearch.label;"
accesskey="&redirectWindowsSearch.accesskey;"
preference="browser.search.redirectWindowsSearch"/>
</groupbox>
<groupbox id="oneClickSearchProvidersGroup" data-category="paneSearch">

View File

@ -9,6 +9,8 @@
<!ENTITY provideSearchSuggestions.label "Provide search suggestions">
<!ENTITY provideSearchSuggestions.accesskey "s">
<!ENTITY redirectWindowsSearch.label "Use this search engine for searches from Windows">
<!ENTITY redirectWindowsSearch.accesskey "W">
<!ENTITY oneClickSearchEngines.label "One-click search engines">