Bug 1525833 - nsISearchService::addEngine does not support using a callback anymore, instead it returns a Promise. Update the searchbar's usage to reflect this. r=florian

This also officially gets rid of the nsIBrowserSearchInitObserver and nsISearchInstallCallback
from nsISearchService.idl, even though they're not used for anything anymore.

Differential Revision: https://phabricator.services.mozilla.com/D18993

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike de Boer 2019-02-07 16:17:54 +00:00
Родитель 43661cfaf5
Коммит 4e948732c1
6 изменённых файлов: 16 добавлений и 59 удалений

Просмотреть файл

@ -1194,7 +1194,7 @@ BrowserPageActions.addSearchEngine = {
showBrowserPageActionFeedback(this.action);
},
errorCode => {
if (errorCode != Ci.nsISearchInstallCallback.ERROR_DUPLICATE_ENGINE) {
if (errorCode != Ci.nsISearchService.ERROR_DUPLICATE_ENGINE) {
// Download error is shown by the search service
return;
}

Просмотреть файл

@ -1176,12 +1176,12 @@ class SearchOneOffs {
if (target.classList.contains("addengine-item")) {
// On success, hide the panel and tell event listeners to reshow it to
// show the new engine.
let installCallback = {
onSuccess: engine => {
Services.search.addEngine(target.getAttribute("uri"), target.getAttribute("image"))
.then(engine => {
this._rebuild();
},
onError(errorCode) {
if (errorCode != Ci.nsISearchInstallCallback.ERROR_DUPLICATE_ENGINE) {
})
.catch(errorCode => {
if (errorCode != Ci.nsISearchService.ERROR_DUPLICATE_ENGINE) {
// Download error is shown by the search service
return;
}
@ -1206,11 +1206,7 @@ class SearchOneOffs {
prompt.QueryInterface(Ci.nsIWritablePropertyBag2);
prompt.setPropertyAsBool("allowTabModal", true);
prompt.alert(title, text);
},
};
Services.search.addEngine(target.getAttribute("uri"),
target.getAttribute("image"), false,
installCallback);
});
}
if (target.classList.contains("search-one-offs-context-open-in-new-tab")) {

Просмотреть файл

@ -385,13 +385,9 @@ class MozSearchbar extends MozXULElement {
if (target.engine) {
this.currentEngine = target.engine;
} else if (target.classList.contains("addengine-item")) {
// Select the installed engine if the installation succeeds
let installCallback = {
onSuccess: engine => this.currentEngine = engine,
};
// Select the installed engine if the installation succeeds.
Services.search.addEngine(target.getAttribute("uri"), null,
target.getAttribute("src"), false,
installCallback);
target.getAttribute("src"), false).then(engine => this.currentEngine = engine);
} else
return;

Просмотреть файл

@ -198,47 +198,12 @@ interface nsISearchParseSubmissionResult : nsISupports
readonly attribute long termsLength;
};
[scriptable, uuid(9fc39136-f08b-46d3-b232-96f4b7b0e235)]
interface nsISearchInstallCallback : nsISupports
[scriptable, uuid(0301834b-2630-440e-8b98-db8dc55f34b9)]
interface nsISearchService : nsISupports
{
const unsigned long ERROR_UNKNOWN_FAILURE = 0x1;
const unsigned long ERROR_DUPLICATE_ENGINE = 0x2;
/**
* Called to indicate that the engine addition process succeeded.
*
* @param engine
* The nsISearchEngine object that was added (will not be null).
*/
void onSuccess(in nsISearchEngine engine);
/**
* Called to indicate that the engine addition process failed.
*
* @param errorCode
* One of the ERROR_* values described above indicating the cause of
* the failure.
*/
void onError(in unsigned long errorCode);
};
/**
* Callback for asynchronous initialization of nsIBrowserSearchService
*/
[scriptable, function, uuid(02256156-16e4-47f1-9979-76ff98ceb590)]
interface nsIBrowserSearchInitObserver : nsISupports
{
/**
* Called once initialization of the browser search service is complete.
*
* @param aStatus The status of that service.
*/
void onInitComplete(in nsresult aStatus);
};
[scriptable, uuid(0301834b-2630-440e-8b98-db8dc55f34b9)]
interface nsISearchService : nsISupports
{
/**
* Start asynchronous initialization.
*

Просмотреть файл

@ -1438,7 +1438,7 @@ Engine.prototype = {
* Handle an error during the load of an engine by notifying the engine's
* error callback, if any.
*/
function onError(errorCode = Ci.nsISearchInstallCallback.ERROR_UNKNOWN_FAILURE) {
function onError(errorCode = Ci.nsISearchService.ERROR_UNKNOWN_FAILURE) {
// Notify the callback of the failure
if (aEngine._installCallback) {
aEngine._installCallback(errorCode);
@ -1519,9 +1519,9 @@ Engine.prototype = {
if (aEngine._confirm) {
promptError({ error: "error_duplicate_engine_msg",
title: "error_invalid_engine_title",
}, Ci.nsISearchInstallCallback.ERROR_DUPLICATE_ENGINE);
}, Ci.nsISearchService.ERROR_DUPLICATE_ENGINE);
} else {
onError(Ci.nsISearchInstallCallback.ERROR_DUPLICATE_ENGINE);
onError(Ci.nsISearchService.ERROR_DUPLICATE_ENGINE);
}
LOG("_onLoad: duplicate engine found, bailing");
return;

Просмотреть файл

@ -48,7 +48,7 @@ add_task(async function duplicate_failure_test() {
} catch (ex) {
let errorCode = ex.result;
Assert.ok(!!errorCode);
Assert.equal(errorCode, Ci.nsISearchInstallCallback.ERROR_DUPLICATE_ENGINE);
Assert.equal(errorCode, Ci.nsISearchService.ERROR_DUPLICATE_ENGINE);
} finally {
Assert.ok(!engine);
}
@ -63,7 +63,7 @@ add_task(async function load_failure_test() {
} catch (ex) {
let errorCode = ex.result;
Assert.ok(!!errorCode);
Assert.equal(errorCode, Ci.nsISearchInstallCallback.ERROR_UNKNOWN_FAILURE);
Assert.equal(errorCode, Ci.nsISearchService.ERROR_UNKNOWN_FAILURE);
} finally {
Assert.ok(!engine);
}