mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1000305 - Part 1 - Add a getIcon() method. r=fabrice r=ehsan
This commit is contained in:
parent
646544ea00
commit
3852ba3695
@ -831,6 +831,7 @@ WebappsApplicationMgmt.prototype = {
|
||||
"Webapps:Uninstall:Return:KO",
|
||||
"Webapps:Install:Return:OK",
|
||||
"Webapps:GetNotInstalled:Return:OK",
|
||||
"Webapps:GetIcon:Return",
|
||||
"Webapps:Import:Return",
|
||||
"Webapps:ExtractManifest:Return",
|
||||
"Webapps:SetEnabled:Return"]);
|
||||
@ -896,6 +897,21 @@ WebappsApplicationMgmt.prototype = {
|
||||
return request;
|
||||
},
|
||||
|
||||
getIcon: function(aApp, aIconID, aEntryPoint) {
|
||||
return this.createPromise(function(aResolve, aReject) {
|
||||
cpmm.sendAsyncMessage("Webapps:GetIcon", {
|
||||
oid: this._id,
|
||||
manifestURL: aApp.manifestURL,
|
||||
iconID: aIconID,
|
||||
entryPoint: aEntryPoint,
|
||||
requestID: this.getPromiseResolverId({
|
||||
resolve: aResolve,
|
||||
reject: aReject
|
||||
})
|
||||
});
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
getNotInstalled: function() {
|
||||
let request = this.createRequest();
|
||||
let principal = this._window.document.nodePrincipal;
|
||||
@ -970,7 +986,8 @@ WebappsApplicationMgmt.prototype = {
|
||||
let msg = aMessage.data;
|
||||
let req;
|
||||
|
||||
if (["Webapps:Import:Return",
|
||||
if (["Webapps:GetIcon:Return",
|
||||
"Webapps:Import:Return",
|
||||
"Webapps:ExtractManifest:Return"]
|
||||
.indexOf(aMessage.name) != -1) {
|
||||
req = this.takePromiseResolver(msg.requestID);
|
||||
@ -1036,7 +1053,18 @@ WebappsApplicationMgmt.prototype = {
|
||||
this.__DOM_IMPL__.dispatchEvent(event);
|
||||
}
|
||||
break;
|
||||
case "Webapps:GetIcon:Return":
|
||||
if (msg.blob) {
|
||||
req.resolve(Cu.cloneInto(msg.blob, this._window));
|
||||
} else if (msg.error && msg.error == "NETWORK_ERROR"
|
||||
&& !this._window.navigator.onLine) {
|
||||
req.reject(new this._window.DOMError("NETWORK_OFFLINE"));
|
||||
} else {
|
||||
req.reject(new this._window.DOMError(msg.error || ""));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (aMessage.name !== "Webapps:Uninstall:Broadcast:Return:OK") {
|
||||
this.removeRequest(msg.requestID);
|
||||
}
|
||||
|
@ -224,6 +224,7 @@ this.DOMApplicationRegistry = {
|
||||
"Webapps:RegisterBEP",
|
||||
"Webapps:Export",
|
||||
"Webapps:Import",
|
||||
"Webapps:GetIcon",
|
||||
"Webapps:ExtractManifest",
|
||||
"Webapps:SetEnabled",
|
||||
"child-process-shutdown"];
|
||||
@ -1428,6 +1429,9 @@ this.DOMApplicationRegistry = {
|
||||
case "Webapps:RegisterBEP":
|
||||
this.registerBrowserElementParentForApp(msg, mm);
|
||||
break;
|
||||
case "Webapps:GetIcon":
|
||||
this.getIcon(msg, mm);
|
||||
break;
|
||||
case "Webapps:Export":
|
||||
this.doExport(msg, mm);
|
||||
break;
|
||||
@ -4282,6 +4286,74 @@ this.DOMApplicationRegistry = {
|
||||
});
|
||||
},
|
||||
|
||||
getIcon: function(aData, aMm) {
|
||||
function sendError(aError) {
|
||||
debug("getIcon error: " + aError);
|
||||
aData.error = aError;
|
||||
aMm.sendAsyncMessage("Webapps:GetIcon:Return", aData);
|
||||
}
|
||||
|
||||
let app = this.getAppByManifestURL(aData.manifestURL);
|
||||
if (!app) {
|
||||
sendError("NO_APP");
|
||||
return;
|
||||
}
|
||||
|
||||
function loadIcon(aUrl) {
|
||||
let fallbackMimeType = aUrl.indexOf('.') >= 0 ?
|
||||
"image/" + aUrl.split(".").reverse()[0] : "";
|
||||
// Set up an xhr to download a blob.
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||
.createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.mozBackgroundRequest = true;
|
||||
xhr.open("GET", aUrl, true);
|
||||
xhr.responseType = "blob";
|
||||
xhr.addEventListener("load", function() {
|
||||
debug("Got http status=" + xhr.status + " for " + aUrl);
|
||||
if (xhr.status == 200) {
|
||||
let blob = xhr.response;
|
||||
// Reusing aData with sendAsyncMessage() leads to an empty blob in
|
||||
// the child.
|
||||
let payload = {
|
||||
"oid": aData.oid,
|
||||
"requestID": aData.requestID,
|
||||
"blob": blob,
|
||||
"type": xhr.getResponseHeader("Content-Type") || fallbackMimeType
|
||||
};
|
||||
aMm.sendAsyncMessage("Webapps:GetIcon:Return", payload);
|
||||
} else if (xhr.status === 0) {
|
||||
sendError("NETWORK_ERROR");
|
||||
} else {
|
||||
sendError("FETCH_ICON_FAILED");
|
||||
}
|
||||
});
|
||||
xhr.addEventListener("error", function() {
|
||||
sendError("FETCH_ICON_FAILED");
|
||||
});
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
// Get the manifest, to find the icon url in the current locale.
|
||||
this.getManifestFor(aData.manifestURL, aData.entryPoint)
|
||||
.then((aManifest) => {
|
||||
if (!aManifest) {
|
||||
sendError("FETCH_ICON_FAILED");
|
||||
return;
|
||||
}
|
||||
|
||||
let manifest = new ManifestHelper(aManifest, app.origin, app.manifestURL);
|
||||
let url = manifest.iconURLForSize(aData.iconID);
|
||||
if (!url) {
|
||||
sendError("NO_ICON");
|
||||
return;
|
||||
}
|
||||
loadIcon(url);
|
||||
}).catch(() => {
|
||||
sendError("FETCH_ICON_FAILED");
|
||||
return;
|
||||
});
|
||||
},
|
||||
|
||||
getAll: function(aCallback) {
|
||||
debug("getAll");
|
||||
let apps = [];
|
||||
@ -4515,7 +4587,7 @@ this.DOMApplicationRegistry = {
|
||||
});
|
||||
},
|
||||
|
||||
getManifestFor: function(aManifestURL) {
|
||||
getManifestFor: function(aManifestURL, aEntryPoint) {
|
||||
let id = this._appIdForManifestURL(aManifestURL);
|
||||
let app = this.webapps[id];
|
||||
if (!id || (app.installState == "pending" && !app.retryingDownload)) {
|
||||
@ -4523,7 +4595,11 @@ this.DOMApplicationRegistry = {
|
||||
}
|
||||
|
||||
return this._readManifests([{ id: id }]).then((aResult) => {
|
||||
return aResult[0].manifest;
|
||||
if (aEntryPoint) {
|
||||
return aResult[0].manifest.entry_points[aEntryPoint];
|
||||
} else {
|
||||
return aResult[0].manifest;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -121,6 +121,8 @@ interface DOMApplicationsManager : EventTarget {
|
||||
Promise<any> extractManifest(Blob blob);
|
||||
|
||||
void setEnabled(DOMApplication app, boolean state);
|
||||
Promise<Blob> getIcon(DOMApplication app, DOMString iconID,
|
||||
optional DOMString entryPoint);
|
||||
|
||||
attribute EventHandler oninstall;
|
||||
attribute EventHandler onuninstall;
|
||||
|
Loading…
Reference in New Issue
Block a user