Bug 1346700 - When rendering, verify timestamp node is valid or not. r=alwu
MozReview-Commit-ID: HqW8HxILK0o
--- a/dom/media/webvtt/WebVTTParserWrapper.js
+++ b/dom/media/webvtt/WebVTTParserWrapper.js
@@ -46,17 +46,17 @@ WebVTTParserWrapper.prototype =
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);
};
},
convertCueToDOMTree: function(window, cue)
{
- return WebVTT.convertCueToDOMTree(window, cue.text);
+ return WebVTT.convertCueToDOMTree(window, cue);
},
processCues: function(window, cues, overlay, controls)
{
WebVTT.processCues(window, cues, overlay, controls);
},
classDescription: "Wrapper for the JS WebVTT implementation (vtt.js)",
--- a/dom/media/webvtt/vtt.jsm
+++ b/dom/media/webvtt/vtt.jsm
@@ -298,17 +298,19 @@ Cu.import('resource://gre/modules/Servic
lang: "lang"
};
var NEEDS_PARENT = {
rt: "ruby"
};
// Parse content into a document fragment.
- function parseContent(window, input, bReturnFrag) {
+ function parseContent(window, cue, bReturnFrag) {
+ var input = cue.text;
+ var validTimeRange = {start: cue.startTime, end: cue.endTime};
function nextToken() {
// Check for end-of-string.
if (!input) {
return null;
}
// Consume 'n' characters from the input.
function consume(result) {
@@ -377,16 +379,27 @@ Cu.import('resource://gre/modules/Servic
if (f[1]) {
f = f[1].slice(0, 3).padEnd(3, "0");
} else {
f = "000";
}
return hours + ':' + minutes + ':' + seconds + '.' + f;
}
+ // Check the input ts against to validTimeRange[] and also update
+ // validTimeRange.
+ function isValidTimestamp(ts) {
+ dump(validTimeRange["start"] +" " +ts+ " "+validTimeRange["end"] +"\n");
+ if (validTimeRange["start"] <= ts && ts <= validTimeRange["end"]) {
+ validTimeRange["start"] = ts;
+ return true;
+ }
+ return false;
+ }
+
var root;
if (bReturnFrag) {
root = window.document.createDocumentFragment();
} else {
root = window.document.createElement("div");
}
var current = root,
t,
@@ -401,18 +414,22 @@ Cu.import('resource://gre/modules/Servic
tagStack.pop();
current = current.parentNode;
}
// Otherwise just ignore the end tag.
continue;
}
var ts = collectTimeStamp(t.substr(1, t.length - 1));
var node;
+ // Timestamps are lead nodes as well.
if (ts) {
- // Timestamps are lead nodes as well.
+ if (!bReturnFrag && !isValidTimestamp(ts)) {
+ // rendering and the ts is invalid
+ continue;
+ }
node = window.document.createProcessingInstruction("timestamp", normalizedTimeStamp(ts));
current.appendChild(node);
continue;
}
var m = t.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/);
// If we can't parse the tag, skip to the next tag.
if (!m) {
continue;
@@ -477,17 +494,17 @@ Cu.import('resource://gre/modules/Servic
backgroundColor = "rgb(0, 0, 0)";
}
StyleBox.call(this);
this.cue = cue;
// Parse our cue's text into a DOM tree rooted at 'cueDiv'. This div will
// have inline positioning and will function as the cue background box.
- this.cueDiv = parseContent(window, cue.text, false);
+ this.cueDiv = parseContent(window, cue, false);
var styles = {
color: color,
backgroundColor: backgroundColor,
position: "relative",
left: 0,
right: 0,
top: 0,
bottom: 0,
@@ -865,21 +882,21 @@ Cu.import('resource://gre/modules/Servic
if (typeof data !== "string") {
throw new Error("Error - expected string data.");
}
return decodeURIComponent(encodeURIComponent(data));
}
};
};
- WebVTT.convertCueToDOMTree = function(window, cuetext) {
+ WebVTT.convertCueToDOMTree = function(window, cue) {
if (!window) {
return null;
}
- return parseContent(window, cuetext, true);
+ return parseContent(window, cue, true);
};
var FONT_SIZE_PERCENT = 0.05;
var FONT_STYLE = "sans-serif";
var CUE_BACKGROUND_PADDING = "1.5%";
// Runs the processing model over the cues and regions passed to it.
// @param overlay A block level element (usually a div) that the computed cues