michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Components.utils.import("resource://gre/modules/vtt.jsm"); michael@0: michael@0: var Ci = Components.interfaces; michael@0: michael@0: var WEBVTTPARSERWRAPPER_CID = "{acf6e493-0092-4b26-b172-241e375c57ab}"; michael@0: var WEBVTTPARSERWRAPPER_CONTRACTID = "@mozilla.org/webvttParserWrapper;1"; michael@0: michael@0: function WebVTTParserWrapper() michael@0: { michael@0: // Nothing michael@0: } michael@0: michael@0: WebVTTParserWrapper.prototype = michael@0: { michael@0: loadParser: function(window) michael@0: { michael@0: this.parser = new WebVTT.Parser(window, new TextDecoder("utf8")); michael@0: }, michael@0: michael@0: parse: function(data) michael@0: { michael@0: // We can safely translate the string data to a Uint8Array as we are michael@0: // guaranteed character codes only from \u0000 => \u00ff michael@0: var buffer = new Uint8Array(data.length); michael@0: for (var i = 0; i < data.length; i++) { michael@0: buffer[i] = data.charCodeAt(i); michael@0: } michael@0: michael@0: this.parser.parse(buffer); michael@0: }, michael@0: michael@0: flush: function() michael@0: { michael@0: this.parser.flush(); michael@0: }, michael@0: michael@0: watch: function(callback) michael@0: { michael@0: this.parser.oncue = callback.onCue; michael@0: this.parser.onregion = callback.onRegion; michael@0: this.parser.onparsingerror = function(e) { michael@0: // Passing the just the error code back is enough for our needs. michael@0: callback.onParsingError(("code" in e) ? e.code : -1); michael@0: }; michael@0: }, michael@0: michael@0: convertCueToDOMTree: function(window, cue) michael@0: { michael@0: return WebVTT.convertCueToDOMTree(window, cue.text); michael@0: }, michael@0: michael@0: processCues: function(window, cues, overlay) michael@0: { michael@0: WebVTT.processCues(window, cues, overlay); michael@0: }, michael@0: michael@0: classDescription: "Wrapper for the JS WebVTT implementation (vtt.js)", michael@0: classID: Components.ID(WEBVTTPARSERWRAPPER_CID), michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebVTTParserWrapper]), michael@0: classInfo: XPCOMUtils.generateCI({ michael@0: classID: WEBVTTPARSERWRAPPER_CID, michael@0: contractID: WEBVTTPARSERWRAPPER_CONTRACTID, michael@0: interfaces: [Ci.nsIWebVTTParserWrapper] michael@0: }) michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebVTTParserWrapper]);