--- a/toolkit/components/search/moz.build
+++ b/toolkit/components/search/moz.build
@@ -2,37 +2,32 @@
# vim: set filetype=python:
# 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/.
XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
EXTRA_COMPONENTS += [
+ 'nsSearchService.js',
'nsSearchSuggestions.js',
]
if CONFIG['MOZ_BUILD_APP'] in ['browser', 'mobile/android', 'xulrunner']:
DEFINES['HAVE_SIDEBAR'] = True
EXTRA_COMPONENTS += [
'nsSidebar.js',
]
EXTRA_JS_MODULES += [
'SearchSuggestionController.jsm',
]
EXTRA_PP_COMPONENTS += [
- 'nsSearchService.js',
'toolkitsearch.manifest',
]
EXTRA_JS_MODULES += [
'SearchStaticData.jsm',
]
-DEFINES['MOZ_DISTRIBUTION_ID'] = CONFIG['MOZ_DISTRIBUTION_ID']
-
-if CONFIG['MOZ_BUILD_APP'] == 'mobile/android':
- DEFINES['MOZ_FENNEC'] = True
-
with Files('**'):
BUG_COMPONENT = ('Firefox', 'Search')
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -1,20 +1,22 @@
-# 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/.
+/* 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/. */
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
const Cu = Components.utils;
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/Promise.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Promise.jsm");
+Cu.import("resource://gre/modules/debug.js");
+Cu.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AsyncShutdown",
"resource://gre/modules/AsyncShutdown.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask",
"resource://gre/modules/DeferredTask.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
@@ -136,22 +138,17 @@ const URLTYPE_SEARCH_HTML = "text/html"
const URLTYPE_OPENSEARCH = "application/opensearchdescription+xml";
const BROWSER_SEARCH_PREF = "browser.search.";
const LOCALE_PREF = "general.useragent.locale";
const USER_DEFINED = "{searchTerms}";
// Custom search parameters
-#ifdef MOZ_OFFICIAL_BRANDING
-const MOZ_OFFICIAL = "official";
-#else
-const MOZ_OFFICIAL = "unofficial";
-#endif
-#expand const MOZ_DISTRIBUTION_ID = __MOZ_DISTRIBUTION_ID__;
+const MOZ_OFFICIAL = AppConstants.MOZ_OFFICIAL_BRANDING ? "official" : "unofficial";
const MOZ_PARAM_LOCALE = /\{moz:locale\}/g;
const MOZ_PARAM_DIST_ID = /\{moz:distributionID\}/g;
const MOZ_PARAM_OFFICIAL = /\{moz:official\}/g;
// Supported OpenSearch parameters
// See http://opensearch.a9.com/spec/1.1/querysyntax/#core
const OS_PARAM_USER_DEFINED = /\{searchTerms\??\}/g;
@@ -224,36 +221,31 @@ const SEARCH_LOG_PREFIX = "*** Search: "
/**
* Outputs aText to the JavaScript console as well as to stdout.
*/
function DO_LOG(aText) {
dump(SEARCH_LOG_PREFIX + aText + "\n");
Services.console.logStringMessage(aText);
}
-#ifdef DEBUG
/**
* In debug builds, use a live, pref-based (browser.search.log) LOG function
- * to allow enabling/disabling without a restart.
- */
-function PREF_LOG(aText) {
- if (getBoolPref(BROWSER_SEARCH_PREF + "log", false))
- DO_LOG(aText);
-}
-var LOG = PREF_LOG;
-
-#else
-
-/**
- * Otherwise, don't log at all by default. This can be overridden at startup
- * by the pref, see SearchService's _init method.
+ * to allow enabling/disabling without a restart. Otherwise, don't log at all by
+ * default. This can be overridden at startup by the pref, see SearchService's
+ * _init method.
*/
var LOG = function(){};
-#endif
+if (AppConstants.DEBUG) {
+ LOG = function (aText) {
+ if (getBoolPref(BROWSER_SEARCH_PREF + "log", false)) {
+ DO_LOG(aText);
+ }
+ };
+}
/**
* Presents an assertion dialog in non-release builds and throws.
* @param message
* A message to display
* @param resultCode
* The NS_ERROR_* value to throw.
* @throws resultCode
@@ -1015,17 +1007,17 @@ function QueryParameter(aName, aValue, a
* @param aEngine
* The engine which owns the string being acted on.
*
* @see http://opensearch.a9.com/spec/1.1/querysyntax/#core
*/
function ParamSubstitution(aParamValue, aSearchTerms, aEngine) {
var value = aParamValue;
- var distributionID = MOZ_DISTRIBUTION_ID;
+ var distributionID = Services.appinfo.distributionID;
try {
distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID");
}
catch (ex) { }
var official = MOZ_OFFICIAL;
try {
if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official"))
official = "official";
@@ -2230,33 +2222,33 @@ Engine.prototype = {
}
let scheme = uri.scheme;
let packageName = "";
if (scheme == "chrome") {
packageName = uri.hostPort;
uri = gChromeReg.convertChromeURL(uri);
}
-#ifdef ANDROID
- // On Android the omni.ja file isn't at the same path as the binary
- // used to start the process. We tweak the path here so that the code
- // shared with Desktop will correctly identify files from the omni.ja
- // file as coming from the [app] folder.
- let appPath = Services.io.getProtocolHandler("resource")
- .QueryInterface(Ci.nsIResProtocolHandler)
- .getSubstitution("android");
- if (appPath) {
- appPath = appPath.spec;
- let spec = uri.spec;
- if (spec.includes(appPath)) {
- let appURI = Services.io.newFileURI(getDir(knownDirs["app"]));
- uri = NetUtil.newURI(spec.replace(appPath, appURI.spec));
+ if (AppConstants.platform == "android") {
+ // On Android the omni.ja file isn't at the same path as the binary
+ // used to start the process. We tweak the path here so that the code
+ // shared with Desktop will correctly identify files from the omni.ja
+ // file as coming from the [app] folder.
+ let appPath = Services.io.getProtocolHandler("resource")
+ .QueryInterface(Ci.nsIResProtocolHandler)
+ .getSubstitution("android");
+ if (appPath) {
+ appPath = appPath.spec;
+ let spec = uri.spec;
+ if (spec.includes(appPath)) {
+ let appURI = Services.io.newFileURI(getDir(knownDirs["app"]));
+ uri = NetUtil.newURI(spec.replace(appPath, appURI.spec));
+ }
}
}
-#endif
if (uri instanceof Ci.nsINestedURI) {
prefix = "jar:";
suffix = "!" + packageName + "/" + leafName;
uri = uri.innermostURI;
}
if (uri instanceof Ci.nsIFileURL) {
file = uri.file;
@@ -2386,34 +2378,32 @@ Engine.prototype = {
var url = this._getURLOfType(aResponseType);
if (!url)
FAIL("Engine object has no URL for response type " + aResponseType,
Cr.NS_ERROR_FAILURE);
url.addParam(aName, aValue);
},
-#ifdef ANDROID
get _defaultMobileResponseType() {
let type = URLTYPE_SEARCH_HTML;
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
let isTablet = sysInfo.get("tablet");
if (isTablet && this.supportsResponseType("application/x-moz-tabletsearch")) {
// Check for a tablet-specific search URL override
type = "application/x-moz-tabletsearch";
} else if (!isTablet && this.supportsResponseType("application/x-moz-phonesearch")) {
// Check for a phone-specific search URL override
type = "application/x-moz-phonesearch";
}
delete this._defaultMobileResponseType;
return this._defaultMobileResponseType = type;
},
-#endif
get _isWhiteListed() {
let url = this._getURLOfType(URLTYPE_SEARCH_HTML).template;
let hostname = makeURI(url).host;
let whitelist = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF)
.getCharPref("reset.whitelist")
.split(",");
if (whitelist.includes(hostname)) {
@@ -2422,23 +2412,19 @@ Engine.prototype = {
return true;
}
return false;
},
// from nsISearchEngine
getSubmission: function SRCH_ENG_getSubmission(aData, aResponseType, aPurpose) {
-#ifdef ANDROID
if (!aResponseType) {
- aResponseType = this._defaultMobileResponseType;
- }
-#endif
- if (!aResponseType) {
- aResponseType = URLTYPE_SEARCH_HTML;
+ aResponseType = AppConstants.platform == "android" ? this._defaultMobileResponseType :
+ URLTYPE_SEARCH_HTML;
}
if (aResponseType == URLTYPE_SEARCH_HTML &&
Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF).getBoolPref("reset.enabled") &&
this.name == Services.search.currentEngine.name &&
!this._isDefault &&
this.name != Services.search.originalDefaultEngine.name &&
(!this.getAttr("loadPathHash") ||
@@ -2479,42 +2465,35 @@ Engine.prototype = {
// from nsISearchEngine
supportsResponseType: function SRCH_ENG_supportsResponseType(type) {
return (this._getURLOfType(type) != null);
},
// from nsISearchEngine
getResultDomain: function SRCH_ENG_getResultDomain(aResponseType) {
-#ifdef ANDROID
if (!aResponseType) {
- aResponseType = this._defaultMobileResponseType;
- }
-#endif
- if (!aResponseType) {
- aResponseType = URLTYPE_SEARCH_HTML;
+ aResponseType = AppConstants.platform == "android" ? this._defaultMobileResponseType :
+ URLTYPE_SEARCH_HTML;
}
LOG("getResultDomain: responseType: \"" + aResponseType + "\"");
let url = this._getURLOfType(aResponseType);
if (url)
return url.resultDomain;
return "";
},
/**
* Returns URL parsing properties used by _buildParseSubmissionMap.
*/
getURLParsingInfo: function () {
-#ifdef ANDROID
- let responseType = this._defaultMobileResponseType;
-#else
- let responseType = URLTYPE_SEARCH_HTML;
-#endif
+ let responseType = AppConstants.platform == "android" ? this._defaultMobileResponseType :
+ URLTYPE_SEARCH_HTML;
LOG("getURLParsingInfo: responseType: \"" + responseType + "\"");
let url = this._getURLOfType(responseType);
if (!url || url.method != "GET") {
return null;
}
@@ -4698,19 +4677,19 @@ SearchService.prototype = {
// initialization for which we try to register the observers twice.
return;
}
this._observersAdded = true;
Services.obs.addObserver(this, SEARCH_ENGINE_TOPIC, false);
Services.obs.addObserver(this, QUIT_APPLICATION_TOPIC, false);
-#ifdef MOZ_FENNEC
- Services.prefs.addObserver(LOCALE_PREF, this, false);
-#endif
+ if (AppConstants.MOZ_BUILD_APP == "mobile/android") {
+ Services.prefs.addObserver(LOCALE_PREF, this, false);
+ }
// The current stage of shutdown. Used to help analyze crash
// signatures in case of shutdown timeout.
let shutdownState = {
step: "Not started",
latestError: {
message: undefined,
stack: undefined
@@ -4743,19 +4722,19 @@ SearchService.prototype = {
);
},
_observersAdded: false,
_removeObservers: function SRCH_SVC_removeObservers() {
Services.obs.removeObserver(this, SEARCH_ENGINE_TOPIC);
Services.obs.removeObserver(this, QUIT_APPLICATION_TOPIC);
-#ifdef MOZ_FENNEC
- Services.prefs.removeObserver(LOCALE_PREF, this);
-#endif
+ if (AppConstants.MOZ_BUILD_APP == "mobile/android") {
+ Services.prefs.removeObserver(LOCALE_PREF, this);
+ }
},
QueryInterface: function SRCH_SVC_QI(aIID) {
if (aIID.equals(Ci.nsIBrowserSearchService) ||
aIID.equals(Ci.nsIObserver) ||
aIID.equals(Ci.nsITimerCallback) ||
aIID.equals(Ci.nsISupports))
return this;
@@ -4812,10 +4791,8 @@ var engineUpdateService = {
// If we're updating the engine too, use the new engine object,
// otherwise use the existing engine object.
(testEngine || engine)._setIcon(engine._iconUpdateURL, true);
}
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SearchService]);
-
-#include ../../../toolkit/modules/debug.js