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