gecko/mobile/android/modules/WebappManagerWorker.js
Myk Melez 8bea8e6d63 bug 934756 - implement install/launch/uninstall flows for webapps on Android using synthetic APKs; r=wesj, fabrice
--HG--
extra : rebase_source : d97be65ec4c033f5eca37bc0b6f94979398fcf02
2014-01-09 10:18:55 -08:00

42 lines
1.2 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
importScripts("resource://gre/modules/osfile.jsm");
function log(message) {
dump("WebManagerWorker " + message + "\n");
}
onmessage = function(event) {
let { url, path } = event.data;
let file = OS.File.open(path, { truncate: true });
let request = new XMLHttpRequest({ mozSystem: true });
request.open("GET", url, true);
request.responseType = "moz-chunked-arraybuffer";
request.onprogress = function(event) {
log("onprogress: received " + request.response.byteLength + " bytes");
let bytesWritten = file.write(new Uint8Array(request.response));
log("onprogress: wrote " + bytesWritten + " bytes");
};
request.onreadystatechange = function(event) {
log("onreadystatechange: " + request.readyState);
if (request.readyState == 4) {
file.close();
if (request.status == 200 || request.status == 0) {
postMessage({ type: "success" });
} else {
postMessage({ type: "failure", message: request.statusText });
}
}
};
request.send(null);
}