Skip to content

Commit

Permalink
[embedlite-component] Report to chrome when a search engine is added.…
Browse files Browse the repository at this point in the history
… Contributes to JB#32815

Register to observe "profile-after-change" after "app-startup"
instead of using custom "embedliteInitialized".
  • Loading branch information
rainemak committed Jun 21, 2016
1 parent 8538f6a commit e358ecf
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions jscomps/EmbedLiteSearchEngine.js
Expand Up @@ -19,21 +19,42 @@ EmbedLiteSearchEngine.prototype = {
classID: Components.ID("{924fe7ba-afa1-11e2-9d4f-533572064b73}"),

observe: function (aSubject, aTopic, aData) {
let searchCallback = {
onSuccess: function (engine) {
var message = {
"msg": "search-engine-added",
"engine": (engine && engine.name) || "",
"errorCode": 0,
}
Services.obs.notifyObservers(null, "embed:search", JSON.stringify(message));
},
onError: function (errorCode) {
// Checked possible failures from nsIBrowserSearchService.idl
var message = {
"msg": "search-engine-added",
"engine": "",
"errorCode": errorCode
}
Services.obs.notifyObservers(null, "embed:search", JSON.stringify(message));
}
}

switch(aTopic) {
// Engine DownloadManager notifications
case "app-startup": {
Services.obs.addObserver(this, "xpcom-shutdown", true);
Services.obs.addObserver(this, "embedui:search", true);
Services.obs.addObserver(this, "embedliteInitialized", true);
Services.obs.addObserver(this, "profile-after-change", false);
break;
}
case "embedliteInitialized": {
Services.obs.removeObserver(this, "embedliteInitialized");
case "profile-after-change": {
Services.obs.removeObserver(this, "profile-after-change");
Services.search.init(function addEngine_cb(rv) {
let engines = Services.search.getEngines({});
let engineNames = engines.map(function (element) {
return element.name;
});

let enginesAvailable = (engines && engines.length > 0);
var messg = {
msg: "init",
Expand All @@ -49,7 +70,7 @@ EmbedLiteSearchEngine.prototype = {
var data = JSON.parse(aData);
switch (data.msg) {
case "loadxml": {
Services.search.addEngine(data.uri, Ci.nsISearchEngine.DATA_XML, null, data.confirm);
Services.search.addEngine(data.uri, Ci.nsISearchEngine.DATA_XML, null, data.confirm, searchCallback);
break;
}
case "restoreDefault": {
Expand Down

0 comments on commit e358ecf

Please sign in to comment.