mobile/android/modules/WebappManagerWorker.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 importScripts("resource://gre/modules/osfile.jsm");
     7 function log(message) {
     8   dump("WebManagerWorker " + message + "\n");
     9 }
    11 onmessage = function(event) {
    12   let { url, path } = event.data;
    14   let file = OS.File.open(path, { truncate: true });
    15   let request = new XMLHttpRequest({ mozSystem: true });
    17   request.open("GET", url, true);
    18   request.responseType = "moz-chunked-arraybuffer";
    20   request.onprogress = function(event) {
    21     log("onprogress: received " + request.response.byteLength + " bytes");
    22     let bytesWritten = file.write(new Uint8Array(request.response));
    23     log("onprogress: wrote " + bytesWritten + " bytes");
    24   };
    26   request.onreadystatechange = function(event) {
    27     log("onreadystatechange: " + request.readyState);
    29     if (request.readyState !== 4) {
    30       return;
    31     }
    33     file.close();
    35     if (request.status === 200) {
    36       postMessage({ type: "success" });
    37     } else {
    38       try {
    39         OS.File.remove(path);
    40       } catch(ex) {
    41         log("error removing " + path + ": " + ex);
    42       }
    43       let statusMessage = request.status + " - " + request.statusText;
    44       postMessage({ type: "failure", message: statusMessage });
    45     }
    46   };
    48   request.send(null);
    49 }

mercurial