Commit 99d36903 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

VideoPlayer initialization: await DOMContentLoaded

Make the initialization promise await DOMContentLoaded and then apply
i18n transforms to the video player DOM [1].

Minor: correct commentary, add commentary. Add assertions re document
readyState when the i18n template strings are applied.

[1] Applying i18n strings to an incomplete (readyState === 'loading')
DOM document makes no sense at all.

Test: browser_tests --gtest_filter="VideoPlayerBrowserTest*"
Bug: 884963
Change-Id: Ie5a25763c54c56e949edde40c7e06b8eaad230c4
Reviewed-on: https://chromium-review.googlesource.com/1233394
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592690}
parent da130715
......@@ -790,33 +790,51 @@ VideoPlayer.prototype.updateInactivityWatcherState_ = function() {
var player = new VideoPlayer();
/**
* Initializes the strings.
* @param {function()} callback Called when the sting data is ready.
* Initializes the load time data.
* @param {function()} callback Called when the load time data is ready.
*/
function initStrings(callback) {
chrome.fileManagerPrivate.getStrings(function(strings) {
loadTimeData.data = strings;
i18nTemplate.process(document, loadTimeData);
callback();
}.wrap(null));
}
/**
* Initializes the volume manager.
* @param {function()} callback Called when the volume manager is ready.
*/
function initVolumeManager(callback) {
var volumeManager = new FilteredVolumeManager(AllowedPaths.ANY_PATH, false);
volumeManager.ensureInitialized(callback);
}
var initPromise = Promise.all(
[new Promise(initStrings.wrap(null)),
/**
* Promise to initialize both the volume manager and the load time data.
* @type {!Promise}
*/
const initPromise = Promise.all([
new Promise(initStrings.wrap(null)),
new Promise(initVolumeManager.wrap(null)),
new Promise(util.addPageLoadHandler.wrap(null))]);
]);
initPromise.then(function(unused) {
/**
* Initialize the video player.
*/
initPromise.then(function() {
if (document.readyState !== 'loading')
return;
return new Promise(function(fulfill, reject) {
document.addEventListener('DOMContentLoaded', fulfill);
}.wrap());
}.wrap()).then(function() {
const isReady = document.readyState !== 'loading';
assert(isReady, 'VideoPlayer DOM document is still loading');
i18nTemplate.process(document, loadTimeData);
return new Promise(function(fulfill, reject) {
util.URLsToEntries(window.appState.items, function(entries) {
metrics.recordOpenVideoPlayerAction();
metrics.recordNumberOfOpenedFiles(entries.length);
player.prepare(entries);
player.playFirstVideo(player, fulfill);
}.wrap());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment