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