зеркало из https://github.com/mozilla/gecko-dev.git
Bug 615761 - Promise chain AddSearchProvider window actor calls to prevent IPC flooding. r=johannh,Standard8
Differential Revision: https://phabricator.services.mozilla.com/D70870
This commit is contained in:
Родитель
efff5156a0
Коммит
3ecb060dd3
|
@ -27,12 +27,13 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
|||
class SidebarSearchParent extends JSWindowActorParent {
|
||||
receiveMessage(msg) {
|
||||
if (msg.name == "Search:AddEngine") {
|
||||
this.addSearchEngine(msg.data);
|
||||
return this.addSearchEngine(msg.data);
|
||||
}
|
||||
return Promise.reject("Unsupported message");
|
||||
}
|
||||
|
||||
// Called when a webpage calls window.external.AddSearchProvider
|
||||
addSearchEngine({ pageURL, engineURL }) {
|
||||
async addSearchEngine({ pageURL, engineURL }) {
|
||||
pageURL = NetUtil.newURI(pageURL);
|
||||
engineURL = NetUtil.newURI(engineURL, null, pageURL);
|
||||
|
||||
|
@ -79,16 +80,16 @@ class SidebarSearchParent extends JSWindowActorParent {
|
|||
brandName,
|
||||
engineURL.spec,
|
||||
]);
|
||||
Services.prompt.asyncAlert(
|
||||
await Services.prompt.asyncAlert(
|
||||
this.browsingContext,
|
||||
promptModalType,
|
||||
title,
|
||||
msg
|
||||
);
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Services.search
|
||||
return Services.search
|
||||
.addEngine(
|
||||
engineURL.spec,
|
||||
iconURL ? iconURL.spec : null,
|
||||
|
|
|
@ -1106,9 +1106,7 @@ SearchEngine.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
function promptError(strings = {}, error = undefined) {
|
||||
onError(error);
|
||||
|
||||
async function promptError(strings = {}, error = undefined) {
|
||||
if (engine._engineToUpdate) {
|
||||
// We're in an update, so just fail quietly
|
||||
SearchUtils.log("updating " + engine._engineToUpdate.name + " failed");
|
||||
|
@ -1126,12 +1124,13 @@ SearchEngine.prototype = {
|
|||
engine._location,
|
||||
]);
|
||||
|
||||
Services.prompt.asyncAlert(
|
||||
await Services.prompt.asyncAlert(
|
||||
engine._reqContext,
|
||||
promptModalType,
|
||||
title,
|
||||
text
|
||||
);
|
||||
onError(error);
|
||||
}
|
||||
|
||||
if (!bytes) {
|
||||
|
|
|
@ -8,6 +8,8 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|||
function nsSidebar() {}
|
||||
|
||||
nsSidebar.prototype = {
|
||||
pendingAddSearchProvider: Promise.resolve(),
|
||||
|
||||
init(window) {
|
||||
this.window = window;
|
||||
},
|
||||
|
@ -34,10 +36,14 @@ nsSidebar.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
sidebarActor.sendAsyncMessage("Search:AddEngine", {
|
||||
pageURL: this.window.document.documentURIObject.spec,
|
||||
engineURL,
|
||||
});
|
||||
this.pendingAddSearchProvider = this.pendingAddSearchProvider.finally(
|
||||
() => {
|
||||
return sidebarActor.sendQuery("Search:AddEngine", {
|
||||
pageURL: this.window.document.documentURIObject.spec,
|
||||
engineURL,
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
// This function exists to implement window.external.IsSearchProviderInstalled(),
|
||||
|
|
Загрузка…
Ссылка в новой задаче