Bug 1358921: Lazily load ContentSearch.jsm when first needed. r=florian
MozReview-Commit-ID: 2iN85WYKtkS
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -50,17 +50,17 @@ let initializedModules = {};
["AsyncShutdown", "resource://gre/modules/AsyncShutdown.jsm"],
["AutoCompletePopup", "resource://gre/modules/AutoCompletePopup.jsm"],
["BookmarkHTMLUtils", "resource://gre/modules/BookmarkHTMLUtils.jsm"],
["BookmarkJSONUtils", "resource://gre/modules/BookmarkJSONUtils.jsm"],
["BrowserUITelemetry", "resource:///modules/BrowserUITelemetry.jsm"],
["BrowserUsageTelemetry", "resource:///modules/BrowserUsageTelemetry.jsm"],
["ContentClick", "resource:///modules/ContentClick.jsm"],
["ContentPrefServiceParent", "resource://gre/modules/ContentPrefServiceParent.jsm"],
- ["ContentSearch", "resource:///modules/ContentSearch.jsm"],
+ ["ContentSearch", "resource:///modules/ContentSearch.jsm", "init"],
["DateTimePickerHelper", "resource://gre/modules/DateTimePickerHelper.jsm"],
["DirectoryLinksProvider", "resource:///modules/DirectoryLinksProvider.jsm"],
["ExtensionsUI", "resource:///modules/ExtensionsUI.jsm"],
["Feeds", "resource:///modules/Feeds.jsm"],
["FileUtils", "resource://gre/modules/FileUtils.jsm"],
["FormValidationHandler", "resource:///modules/FormValidationHandler.jsm"],
["Integration", "resource://gre/modules/Integration.jsm"],
["LightweightThemeManager", "resource://gre/modules/LightweightThemeManager.jsm"],
@@ -129,16 +129,17 @@ const listeners = {
ppmm: {
"webrtc:UpdateGlobalIndicators": ["webrtcUI"],
"webrtc:UpdatingIndicators": ["webrtcUI"],
},
mm: {
"AboutHome:MaybeShowAutoMigrationUndoNotification": ["AboutHome"],
"AboutHome:RequestUpdate": ["AboutHome"],
+ "ContentSearch": ["ContentSearch"],
"rtcpeer:CancelRequest": ["webrtcUI"],
"rtcpeer:Request": ["webrtcUI"],
"webrtc:CancelRequest": ["webrtcUI"],
"webrtc:Request": ["webrtcUI"],
"webrtc:StopRecording": ["webrtcUI"],
"webrtc:UpdateBrowserIndicators": ["webrtcUI"],
},
@@ -577,17 +578,16 @@ BrowserGlue.prototype = {
DirectoryLinksProvider.init();
NewTabUtils.init();
NewTabUtils.links.addProvider(DirectoryLinksProvider);
AboutNewTab.init();
SessionStore.init();
BrowserUsageTelemetry.init();
BrowserUITelemetry.init();
- ContentSearch.init();
FormValidationHandler.init();
ContentClick.init();
RemotePrompt.init();
Feeds.init();
ContentPrefServiceParent.init();
LoginManagerParent.init();
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -104,19 +104,16 @@ this.ContentSearch = {
// Resolved when we finish shutting down.
_destroyedPromise: null,
// The current controller and browser in _onMessageGetSuggestions. Allows
// fetch cancellation from _cancelSuggestions.
_currentSuggestion: null,
init() {
- Cc["@mozilla.org/globalmessagemanager;1"].
- getService(Ci.nsIMessageListenerManager).
- addMessageListener(INBOUND_MESSAGE, this);
Services.obs.addObserver(this, "browser-search-engine-modified");
Services.obs.addObserver(this, "shutdown-leaks-before-check");
Services.prefs.addObserver("browser.search.hiddenOneOffs", this);
this._stringBundle = Services.strings.createBundle("chrome://global/locale/autocomplete.properties");
},
get searchSuggestionUIStrings() {
if (this._searchSuggestionUIStrings) {
@@ -133,19 +130,16 @@ this.ContentSearch = {
return this._searchSuggestionUIStrings;
},
destroy() {
if (this._destroyedPromise) {
return this._destroyedPromise;
}
- Cc["@mozilla.org/globalmessagemanager;1"].
- getService(Ci.nsIMessageListenerManager).
- removeMessageListener(INBOUND_MESSAGE, this);
Services.obs.removeObserver(this, "browser-search-engine-modified");
Services.obs.removeObserver(this, "shutdown-leaks-before-check");
this._eventQueue.length = 0;
this._destroyedPromise = Promise.resolve(this._currentEventPromise);
return this._destroyedPromise;
},
@@ -155,16 +149,17 @@ this.ContentSearch = {
* The MessageManager object of the selected browser.
*/
focusInput(messageManager) {
messageManager.sendAsyncMessage(OUTBOUND_MESSAGE, {
type: "FocusInput"
});
},
+ // Listeners and observers are added in nsBrowserGlue.js
receiveMessage(msg) {
// Add a temporary event handler that exists only while the message is in
// the event queue. If the message's source docshell changes browsers in
// the meantime, then we need to update msg.target. event.detail will be
// the docshell's new parent <xul:browser> element.
msg.handleEvent = event => {
let browserData = this._suggestionMap.get(msg.target);
if (browserData) {