Bug 1203524 - search.xml should use Services.jsm, r=Mossop.

This commit is contained in:
Florian Quèze 2015-09-11 14:18:15 +02:00
parent db5607b8f3
commit aba5768e58

View File

@ -68,14 +68,11 @@
// Make sure we rebuild the popup in onpopupshowing
this._needToBuildPopup = true;
var os =
Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(this, "browser-search-engine-modified", false);
Services.obs.addObserver(this, "browser-search-engine-modified", false);
this._initialized = true;
this.searchService.init((function search_init_cb(aStatus) {
Services.search.init((function search_init_cb(aStatus) {
// Bail out if the binding's been destroyed
if (!this._initialized)
return;
@ -98,9 +95,7 @@
if (this._initialized) {
this._initialized = false;
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.removeObserver(this, "browser-search-engine-modified");
Services.obs.removeObserver(this, "browser-search-engine-modified");
}
// Make sure to break the cycle from _textbox to us. Otherwise we leak
@ -120,7 +115,6 @@
<field name="_textboxInitialized">false</field>
<field name="_textbox">document.getAnonymousElementByAttribute(this,
"anonid", "searchbar-textbox");</field>
<field name="_ss">null</field>
<field name="_engines">null</field>
<field name="FormHistory" readonly="true">
(Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory;
@ -132,19 +126,19 @@
<property name="engines" readonly="true">
<getter><![CDATA[
if (!this._engines)
this._engines = this.searchService.getVisibleEngines();
this._engines = Services.search.getVisibleEngines();
return this._engines;
]]></getter>
</property>
<property name="currentEngine">
<setter><![CDATA[
let ss = this.searchService;
let ss = Services.search;
ss.defaultEngine = ss.currentEngine = val;
return val;
]]></setter>
<getter><![CDATA[
var currentEngine = this.searchService.currentEngine;
var currentEngine = Services.search.currentEngine;
// Return a dummy engine if there is no currentEngine
return currentEngine || {name: "", uri: null};
]]></getter>
@ -155,18 +149,6 @@
<property name="textbox" readonly="true"
onget="return this._textbox;"/>
<property name="searchService" readonly="true">
<getter><![CDATA[
if (!this._ss) {
const nsIBSS = Components.interfaces.nsIBrowserSearchService;
this._ss =
Components.classes["@mozilla.org/browser/search-service;1"]
.getService(nsIBSS);
}
return this._ss;
]]></getter>
</property>
<property name="value" onget="return this._textbox.value;"
onset="return this._textbox.value = val;"/>
@ -366,7 +348,7 @@
where = whereToOpenLink(aEvent, false, true);
}
else {
var newTabPref = textBox._prefBranch.getBoolPref("browser.search.openintab");
var newTabPref = Services.prefs.getBoolPref("browser.search.openintab");
if (((aEvent instanceof KeyboardEvent) && aEvent.altKey) ^ newTabPref)
where = "tab";
if ((aEvent instanceof MouseEvent) &&
@ -456,18 +438,15 @@
if (target.engine) {
this.currentEngine = target.engine;
} else if (target.classList.contains("addengine-item")) {
var searchService =
Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
// We only detect OpenSearch files
var type = Components.interfaces.nsISearchEngine.DATA_XML;
var type = Ci.nsISearchEngine.DATA_XML;
// Select the installed engine if the installation succeeds
var installCallback = {
onSuccess: engine => this.currentEngine = engine
}
searchService.addEngine(target.getAttribute("uri"), type,
target.getAttribute("src"), false,
installCallback);
Services.search.addEngine(target.getAttribute("uri"), type,
target.getAttribute("src"), false,
installCallback);
}
else
return;
@ -559,13 +538,10 @@
// Initialize fields
this._stringBundle = document.getBindingParent(this)._stringBundle;
this._prefBranch =
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
this._suggestEnabled =
this._prefBranch.getBoolPref("browser.search.suggest.enabled");
Services.prefs.getBoolPref("browser.search.suggest.enabled");
if (this._prefBranch.getBoolPref("browser.urlbar.clickSelectsAll"))
if (Services.prefs.getBoolPref("browser.urlbar.clickSelectsAll"))
this.setAttribute("clickSelectsAll", true);
// Add items to context menu and attach controller to handle them
@ -637,15 +613,11 @@
document.getBindingParent(this)._textboxInitialized = true;
// Add observer for suggest preference
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.addObserver("browser.search.suggest.enabled", this, false);
Services.prefs.addObserver("browser.search.suggest.enabled", this, false);
]]></constructor>
<destructor><![CDATA[
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.removeObserver("browser.search.suggest.enabled", this);
Services.prefs.removeObserver("browser.search.suggest.enabled", this);
// Because XBL and the customize toolbar code interacts poorly,
// there may not be anything to remove here
@ -655,7 +627,6 @@
]]></destructor>
<field name="_stringBundle"/>
<field name="_prefBranch"/>
<field name="_suggestMenuItem"/>
<field name="_suggestEnabled"/>
@ -698,7 +669,7 @@
}
popup.mInput = this;
popup.view = this.controller.QueryInterface(Components.interfaces.nsITreeView);
popup.view = this.controller.QueryInterface(Ci.nsITreeView);
popup.invalidate();
popup.showCommentColumn = this.showCommentColumn;
@ -730,7 +701,7 @@
<body><![CDATA[
if (aTopic == "nsPref:changed") {
this._suggestEnabled =
this._prefBranch.getBoolPref("browser.search.suggest.enabled");
Services.prefs.getBoolPref("browser.search.suggest.enabled");
this._suggestMenuItem.setAttribute("checked", this._suggestEnabled);
}
]]></body>
@ -974,8 +945,8 @@
case "cmd_togglesuggest":
// The pref observer will update _suggestEnabled and the menu
// checkmark.
this._self._prefBranch.setBoolPref("browser.search.suggest.enabled",
!this._self._suggestEnabled);
Services.prefs.setBoolPref("browser.search.suggest.enabled",
!this._self._suggestEnabled);
break;
default:
// do nothing with unrecognized command