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() { ...@@ -790,33 +790,51 @@ VideoPlayer.prototype.updateInactivityWatcherState_ = function() {
var player = new VideoPlayer(); var player = new VideoPlayer();
/** /**
* Initializes the strings. * Initializes the load time data.
* @param {function()} callback Called when the sting data is ready. * @param {function()} callback Called when the load time data is ready.
*/ */
function initStrings(callback) { function initStrings(callback) {
chrome.fileManagerPrivate.getStrings(function(strings) { chrome.fileManagerPrivate.getStrings(function(strings) {
loadTimeData.data = strings; loadTimeData.data = strings;
i18nTemplate.process(document, loadTimeData);
callback(); callback();
}.wrap(null)); }.wrap(null));
} }
/**
* Initializes the volume manager.
* @param {function()} callback Called when the volume manager is ready.
*/
function initVolumeManager(callback) { function initVolumeManager(callback) {
var volumeManager = new FilteredVolumeManager(AllowedPaths.ANY_PATH, false); var volumeManager = new FilteredVolumeManager(AllowedPaths.ANY_PATH, false);
volumeManager.ensureInitialized(callback); volumeManager.ensureInitialized(callback);
} }
var initPromise = Promise.all( /**
[new Promise(initStrings.wrap(null)), * Promise to initialize both the volume manager and the load time data.
new Promise(initVolumeManager.wrap(null)), * @type {!Promise}
new Promise(util.addPageLoadHandler.wrap(null))]); */
const initPromise = Promise.all([
new Promise(initStrings.wrap(null)),
new Promise(initVolumeManager.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) { return new Promise(function(fulfill, reject) {
util.URLsToEntries(window.appState.items, function(entries) { util.URLsToEntries(window.appState.items, function(entries) {
metrics.recordOpenVideoPlayerAction(); metrics.recordOpenVideoPlayerAction();
metrics.recordNumberOfOpenedFiles(entries.length); metrics.recordNumberOfOpenedFiles(entries.length);
player.prepare(entries); player.prepare(entries);
player.playFirstVideo(player, fulfill); player.playFirstVideo(player, fulfill);
}.wrap()); }.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