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 import { WebVTT } from "resource://gre/modules/vtt.sys.mjs";
7 export function WebVTTParserWrapper() {
11 WebVTTParserWrapper.prototype = {
13 this.parser = new WebVTT.Parser(window, new TextDecoder("utf8"));
17 // We can safely translate the string data to a Uint8Array as we are
18 // guaranteed character codes only from \u0000 => \u00ff
19 var buffer = new Uint8Array(data.length);
20 for (var i = 0; i < data.length; i++) {
21 buffer[i] = data.charCodeAt(i);
24 this.parser.parse(buffer);
32 this.parser.oncue = callback.onCue;
33 this.parser.onregion = callback.onRegion;
34 this.parser.onparsingerror = function (e) {
35 // Passing the just the error code back is enough for our needs.
36 callback.onParsingError("code" in e ? e.code : -1);
41 this.parser.oncue = null;
42 this.parser.onregion = null;
43 this.parser.onparsingerror = null;
46 convertCueToDOMTree(window, cue) {
47 return WebVTT.convertCueToDOMTree(window, cue.text);
50 processCues(window, cues, overlay, controls) {
51 WebVTT.processCues(window, cues, overlay, controls);
54 classDescription: "Wrapper for the JS WebVTT implementation (vtt.js)",
55 QueryInterface: ChromeUtils.generateQI(["nsIWebVTTParserWrapper"]),