content/media/webvtt/WebVTTParserWrapper.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
     6 Components.utils.import("resource://gre/modules/vtt.jsm");
     8 var Ci = Components.interfaces;
    10 var WEBVTTPARSERWRAPPER_CID = "{acf6e493-0092-4b26-b172-241e375c57ab}";
    11 var WEBVTTPARSERWRAPPER_CONTRACTID = "@mozilla.org/webvttParserWrapper;1";
    13 function WebVTTParserWrapper()
    14 {
    15   // Nothing
    16 }
    18 WebVTTParserWrapper.prototype =
    19 {
    20   loadParser: function(window)
    21   {
    22     this.parser = new WebVTT.Parser(window,  new TextDecoder("utf8"));
    23   },
    25   parse: function(data)
    26   {
    27     // We can safely translate the string data to a Uint8Array as we are
    28     // guaranteed character codes only from \u0000 => \u00ff
    29     var buffer = new Uint8Array(data.length);
    30     for (var i = 0; i < data.length; i++) {
    31       buffer[i] = data.charCodeAt(i);
    32     }
    34     this.parser.parse(buffer);
    35   },
    37   flush: function()
    38   {
    39     this.parser.flush();
    40   },
    42   watch: function(callback)
    43   {
    44     this.parser.oncue = callback.onCue;
    45     this.parser.onregion = callback.onRegion;
    46     this.parser.onparsingerror = function(e) {
    47       // Passing the just the error code back is enough for our needs.
    48       callback.onParsingError(("code" in e) ? e.code : -1);
    49     };
    50   },
    52   convertCueToDOMTree: function(window, cue)
    53   {
    54     return WebVTT.convertCueToDOMTree(window, cue.text);
    55   },
    57   processCues: function(window, cues, overlay)
    58   {
    59     WebVTT.processCues(window, cues, overlay);
    60   },
    62   classDescription: "Wrapper for the JS WebVTT implementation (vtt.js)",
    63   classID: Components.ID(WEBVTTPARSERWRAPPER_CID),
    64   QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebVTTParserWrapper]),
    65   classInfo: XPCOMUtils.generateCI({
    66     classID:    WEBVTTPARSERWRAPPER_CID,
    67     contractID: WEBVTTPARSERWRAPPER_CONTRACTID,
    68     interfaces: [Ci.nsIWebVTTParserWrapper]
    69   })
    70 };
    72 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebVTTParserWrapper]);

mercurial