Skip to content

Commit

Permalink
[embedlite-components] Add each Services.embedlite.sendAsyncMessage b…
Browse files Browse the repository at this point in the history
…ehind try-catch. Fixes JB#53592
  • Loading branch information
rainemak committed Mar 19, 2021
1 parent f71f88c commit 0dc580e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 52 deletions.
14 changes: 9 additions & 5 deletions jscomps/ContentPermissionPrompt.js
Expand Up @@ -117,11 +117,15 @@ ContentPermissionPrompt.prototype = {
let entityName = kEntities[perm.type];

Services.embedlite.addMessageListener("embedui:permissions", this);
var winId = Services.embedlite.getIDByWindow(request.window);
Services.embedlite.sendAsyncMessage(winId, "embed:permissions",
JSON.stringify({title: entityName,
host: request.principal.URI.host,
id: reqkey}));
try {
var winId = Services.embedlite.getIDByWindow(request.window);
Services.embedlite.sendAsyncMessage(winId, "embed:permissions",
JSON.stringify({title: entityName,
host: request.principal.URI.host,
id: reqkey}));
} catch (e) {
Logger.warn("ContentPermissionPrompt: sending async message failed", e)
}
}
};

Expand Down
24 changes: 16 additions & 8 deletions jscomps/EmbedLiteFaviconService.js
Expand Up @@ -49,13 +49,17 @@ var gProgressListener = {
return;
}
let iconPath = domDoc.documentURIObject.prePath + "/favicon.ico";
let winId = Services.embedlite.getIDByWindow(aWebProgress.DOMWindow);
NetUtil.asyncFetch(iconPath, function(aInputStream, aStatusCode, aRequest) {
if (!Components.isSuccessCode(aStatusCode) || aRequest.contentType == "text/html") {
return;
}
Services.embedlite.sendAsyncMessage(winId, "embed:faviconURL", JSON.stringify({url: resolveGeckoURI(iconPath)}));
});
try {
let winId = Services.embedlite.getIDByWindow(aWebProgress.DOMWindow);
NetUtil.asyncFetch(iconPath, function(aInputStream, aStatusCode, aRequest) {
if (!Components.isSuccessCode(aStatusCode) || aRequest.contentType == "text/html") {
return;
}
Services.embedlite.sendAsyncMessage(winId, "embed:faviconURL", JSON.stringify({url: resolveGeckoURI(iconPath)}));
});
} catch (e) {
Logger.warn("EmbedLiteFaviconService: sending async message failed", e)
}
},
onSecurityChange: function() { },
onProgressChange: function() { },
Expand Down Expand Up @@ -100,7 +104,11 @@ EventLinkListener.prototype = {
if (list.indexOf("[icon]") == -1)
return;

Services.embedlite.sendAsyncMessage(this._winId, "embed:faviconURL", JSON.stringify({url: resolveGeckoURI(target.href)}));
try {
Services.embedlite.sendAsyncMessage(this._winId, "embed:faviconURL", JSON.stringify({url: resolveGeckoURI(target.href)}));
} catch (e) {
Logger.warn("EmbedLiteFaviconService: sending async message failed", e)
}
break;
}
},
Expand Down
41 changes: 26 additions & 15 deletions jscomps/EmbedLiteWebAppInstall.js
Expand Up @@ -118,10 +118,13 @@ var WebappsUI = {
}).bind(this));
break;
case "webapps-sync-uninstall":
let winId = Services.embedlite.getIDByWindow(Services.ww.activeWindow);
Services.embedlite.sendAsyncMessage(winId, "WebApps:Uninstall", JSON.stringify({
origin: data.origin
}));
try {
let winId = Services.embedlite.getIDByWindow(Services.ww.activeWindow);
Services.embedlite.sendAsyncMessage(winId, "WebApps:Uninstall",
JSON.stringify({ origin: data.origin }));
} catch (e) {
Logger.warn("EmbedLiteWebAppInstall: sending async message failed", e)
}
break;
}
},
Expand Down Expand Up @@ -211,12 +214,16 @@ var WebappsUI = {
let source = Services.io.newURI(fullsizeIcon, "UTF8", null);
persist.saveURI(source, null, null, null, null, iconFile, null);

Services.embedlite.sendAsyncMessage(winId, "WebApps:PostInstall", JSON.stringify({
name: manifest.name,
manifestURL: aData.app.manifestURL,
origin: aData.app.origin,
iconURL: fullsizeIcon
}));
try {
Services.embedlite.sendAsyncMessage(winId, "WebApps:PostInstall", JSON.stringify({
name: manifest.name,
manifestURL: aData.app.manifestURL,
origin: aData.app.origin,
iconURL: fullsizeIcon
}));
} catch (e) {
Logger.warn("EmbedLiteWebAppInstall: sending async message failed", e)
}
if (!!aData.isPackage) {
// For packaged apps, put a notification in the notification bar.
let message = Strings.browser.GetStringFromName("webapps.alertSuccess");
Expand Down Expand Up @@ -259,11 +266,15 @@ var WebappsUI = {
},

openURL: function openURL(aManifestURL, aOrigin) {
let winId = Services.embedlite.getIDByWindow(Services.ww.activeWindow);
Services.embedlite.sendAsyncMessage(winId, "WebApps:Open", JSON.stringify({
manifestURL: aManifestURL,
origin: aOrigin
}));
try {
let winId = Services.embedlite.getIDByWindow(Services.ww.activeWindow);
Services.embedlite.sendAsyncMessage(winId, "WebApps:Open", JSON.stringify({
manifestURL: aManifestURL,
origin: aOrigin
}));
} catch (e) {
Logger.warn("EmbedLiteWebAppInstall: sending async message failed", e)
}
},

get iconSize() {
Expand Down
6 changes: 5 additions & 1 deletion jscomps/FilePicker.js
Expand Up @@ -227,7 +227,11 @@ FilePicker.prototype = {
},

sendMessageToEmbed: function(aMsg) {
Services.embedlite.sendAsyncMessage(aMsg.winId, aMsg.type, JSON.stringify(aMsg));
try {
Services.embedlite.sendAsyncMessage(aMsg.winId, aMsg.type, JSON.stringify(aMsg));
} catch (e) {
Logger.warn("FilePicker: sending async message failed", e)
}
Services.embedlite.addMessageListener("filepickerresponse", this);
},

Expand Down
26 changes: 15 additions & 11 deletions jscomps/nsLoginManagerPrompter.js
Expand Up @@ -799,17 +799,21 @@ LoginManagerPrompter.prototype = {
}

Services.embedlite.addMessageListener("embedui:login", this);
var winid = Services.embedlite.getIDByWindow(notifyWin);
let uniqueid = this._getRandomId();
Services.embedlite.sendAsyncMessage(winid, "embed:login",
JSON.stringify({
name: aName,
buttons: aButtons,
options: logoptions,
id: uniqueid,
formdata: aFormData
}));
this._pendingRequests[uniqueid] = aButtons;
try {
var winid = Services.embedlite.getIDByWindow(notifyWin);
let uniqueid = this._getRandomId();
Services.embedlite.sendAsyncMessage(winid, "embed:login",
JSON.stringify({
name: aName,
buttons: aButtons,
options: logoptions,
id: uniqueid,
formdata: aFormData
}));
this._pendingRequests[uniqueid] = aButtons;
} catch (e) {
Logger.warn("nsLoginManagerPrompter: sending async message failed", e)
}
},

/**
Expand Down
6 changes: 5 additions & 1 deletion jsscripts/Prompt.jsm
Expand Up @@ -216,7 +216,11 @@ Prompt.prototype = {

_innerShow: function() {
Services.embedlite.addMessageListener(this.getResponseName(), this);
Services.embedlite.sendAsyncMessage(this.msg.winId, this.getMessageName(), JSON.stringify(this.msg));
try {
Services.embedlite.sendAsyncMessage(this.msg.winId, this.getMessageName(), JSON.stringify(this.msg));
} catch (e) {
Logger.warn("Prompt: sending async message failed", e)
}
},

_setListItems: function(aItems) {
Expand Down
30 changes: 19 additions & 11 deletions jsscripts/embedhelper.js
Expand Up @@ -204,11 +204,15 @@ EmbedHelper.prototype = {
} else {
let uri = this._getLinkURI(this._touchElement);
if (uri && (uri instanceof Ci.nsIURI)) {
let winId = Services.embedlite.getIDByWindow(content);
Services.embedlite.sendAsyncMessage(winId, "embed:linkclicked",
JSON.stringify({
"uri": uri.asciiSpec
}));
try {
let winId = Services.embedlite.getIDByWindow(content);
Services.embedlite.sendAsyncMessage(winId, "embed:linkclicked",
JSON.stringify({
"uri": uri.asciiSpec
}));
} catch (e) {
Logger.warn("embedhelper: sending async message failed", e)
}
}
this._touchElement = null;
}
Expand Down Expand Up @@ -594,12 +598,16 @@ EmbedHelper.prototype = {

_handleFullScreenChanged: function(aEvent) {
let window = aEvent.target.defaultView;
let winId = Services.embedlite.getIDByWindow(window);
this.inFullScreen = aEvent.target.mozFullScreen;
Services.embedlite.sendAsyncMessage(winId, "embed:fullscreenchanged",
JSON.stringify({
"fullscreen": aEvent.target.mozFullScreen
}));
try {
let winId = Services.embedlite.getIDByWindow(window);
this.inFullScreen = aEvent.target.mozFullScreen;
Services.embedlite.sendAsyncMessage(winId, "embed:fullscreenchanged",
JSON.stringify({
"fullscreen": aEvent.target.mozFullScreen
}));
} catch (e) {
Logger.warn("emhedhelper: sending async message failed", e)
}
},

_handleTouchMove: function(aEvent) {
Expand Down

0 comments on commit 0dc580e

Please sign in to comment.