Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: ui/file_manager/video_player/js/video_player.js

Issue 571453002: Correct indentation, JSDoc, etc... to comply with closure linter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made it more strict. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @param {Element} playerContainer Main container. 8 * @param {Element} playerContainer Main container.
9 * @param {Element} videoContainer Container for the video element. 9 * @param {Element} videoContainer Container for the video element.
10 * @param {Element} controlsContainer Container for video controls. 10 * @param {Element} controlsContainer Container for video controls.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 */ 182 */
183 VideoPlayer.prototype.prepare = function(videos) { 183 VideoPlayer.prototype.prepare = function(videos) {
184 this.videos_ = videos; 184 this.videos_ = videos;
185 185
186 var preventDefault = function(event) { event.preventDefault(); }.wrap(null); 186 var preventDefault = function(event) { event.preventDefault(); }.wrap(null);
187 187
188 document.ondragstart = preventDefault; 188 document.ondragstart = preventDefault;
189 189
190 var maximizeButton = document.querySelector('.maximize-button'); 190 var maximizeButton = document.querySelector('.maximize-button');
191 maximizeButton.addEventListener( 191 maximizeButton.addEventListener(
192 'click', 192 'click',
193 function(event) { 193 function(event) {
194 var appWindow = chrome.app.window.current(); 194 var appWindow = chrome.app.window.current();
195 if (appWindow.isMaximized()) 195 if (appWindow.isMaximized())
196 appWindow.restore(); 196 appWindow.restore();
197 else 197 else
198 appWindow.maximize(); 198 appWindow.maximize();
199 event.stopPropagation(); 199 event.stopPropagation();
200 }.wrap(null)); 200 }.wrap(null));
201 maximizeButton.addEventListener('mousedown', preventDefault); 201 maximizeButton.addEventListener('mousedown', preventDefault);
202 202
203 var minimizeButton = document.querySelector('.minimize-button'); 203 var minimizeButton = document.querySelector('.minimize-button');
204 minimizeButton.addEventListener( 204 minimizeButton.addEventListener(
205 'click', 205 'click',
206 function(event) { 206 function(event) {
207 chrome.app.window.current().minimize() 207 chrome.app.window.current().minimize();
208 event.stopPropagation(); 208 event.stopPropagation();
209 }.wrap(null)); 209 }.wrap(null));
210 minimizeButton.addEventListener('mousedown', preventDefault); 210 minimizeButton.addEventListener('mousedown', preventDefault);
211 211
212 var closeButton = document.querySelector('.close-button'); 212 var closeButton = document.querySelector('.close-button');
213 closeButton.addEventListener( 213 closeButton.addEventListener(
214 'click', 214 'click',
215 function(event) { 215 function(event) {
216 close(); 216 close();
217 event.stopPropagation(); 217 event.stopPropagation();
218 }.wrap(null)); 218 }.wrap(null));
219 closeButton.addEventListener('mousedown', preventDefault); 219 closeButton.addEventListener('mousedown', preventDefault);
220 220
221 var castButton = document.querySelector('.cast-button'); 221 var castButton = document.querySelector('.cast-button');
222 cr.ui.decorate(castButton, cr.ui.MenuButton); 222 cr.ui.decorate(castButton, cr.ui.MenuButton);
223 castButton.addEventListener( 223 castButton.addEventListener(
224 'click', 224 'click',
225 function(event) { 225 function(event) {
226 event.stopPropagation(); 226 event.stopPropagation();
227 }.wrap(null)); 227 }.wrap(null));
228 castButton.addEventListener('mousedown', preventDefault); 228 castButton.addEventListener('mousedown', preventDefault);
229 229
230 var menu = document.querySelector('#cast-menu'); 230 var menu = document.querySelector('#cast-menu');
231 cr.ui.decorate(menu, cr.ui.Menu); 231 cr.ui.decorate(menu, cr.ui.Menu);
232 232
233 this.controls_ = new FullWindowVideoControls( 233 this.controls_ = new FullWindowVideoControls(
234 document.querySelector('#video-player'), 234 document.querySelector('#video-player'),
235 document.querySelector('#video-container'), 235 document.querySelector('#video-container'),
236 document.querySelector('#controls')); 236 document.querySelector('#controls'));
237 237
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 document.querySelector('#video-player').removeAttribute('disabled'); 308 document.querySelector('#video-player').removeAttribute('disabled');
309 document.querySelector('#error').removeAttribute('visible'); 309 document.querySelector('#error').removeAttribute('visible');
310 this.controls.inactivityWatcher.disabled = true; 310 this.controls.inactivityWatcher.disabled = true;
311 this.controls.decodeErrorOccured = false; 311 this.controls.decodeErrorOccured = false;
312 this.controls.casting = !!this.currentCast_; 312 this.controls.casting = !!this.currentCast_;
313 313
314 videoPlayerElement.setAttribute('loading', true); 314 videoPlayerElement.setAttribute('loading', true);
315 315
316 var media = new MediaManager(video.entry); 316 var media = new MediaManager(video.entry);
317 317
318 Promise.all([media.getThumbnail(), media.getToken()]).then( 318 Promise.all([media.getThumbnail(), media.getToken()])
319 function(results) { 319 .then(function(results) {
320 var url = results[0]; 320 var url = results[0];
321 var token = results[1]; 321 var token = results[1];
322 document.querySelector('#thumbnail').style.backgroundImage = 322 document.querySelector('#thumbnail').style.backgroundImage =
323 'url(' + url + '&access_token=' + token + ')'; 323 'url(' + url + '&access_token=' + token + ')';
324 }).catch(function() { 324 })
325 .catch(function() {
325 // Shows no image on error. 326 // Shows no image on error.
326 document.querySelector('#thumbnail').style.backgroundImage = ''; 327 document.querySelector('#thumbnail').style.backgroundImage = '';
327 }); 328 });
328 329
329 var videoElementInitializePromise; 330 var videoElementInitializePromise;
330 if (this.currentCast_) { 331 if (this.currentCast_) {
331 videoPlayerElement.setAttribute('casting', true); 332 videoPlayerElement.setAttribute('casting', true);
332 333
333 document.querySelector('#cast-name-label').textContent = 334 document.querySelector('#cast-name-label').textContent =
334 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON'); 335 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON');
335 document.querySelector('#cast-name').textContent = 336 document.querySelector('#cast-name').textContent =
336 this.currentCast_.friendlyName; 337 this.currentCast_.friendlyName;
337 338
338 videoPlayerElement.setAttribute('castable', true); 339 videoPlayerElement.setAttribute('castable', true);
339 340
340 videoElementInitializePromise = 341 videoElementInitializePromise = media.isAvailableForCast()
341 media.isAvailableForCast().then(function(result) { 342 .then(function(result) {
342 if (!result) 343 if (!result)
343 return Promise.reject('No casts are available.'); 344 return Promise.reject('No casts are available.');
344 345
345 return new Promise(function(fulfill, reject) { 346 return new Promise(function(fulfill, reject) {
346 chrome.cast.requestSession( 347 chrome.cast.requestSession(
347 fulfill, reject, undefined, this.currentCast_.label); 348 fulfill, reject, undefined, this.currentCast_.label);
348 }.bind(this)).then(function(session) { 349 }.bind(this)).then(function(session) {
349 session.addUpdateListener(this.onCastSessionUpdateBound_); 350 session.addUpdateListener(this.onCastSessionUpdateBound_);
350 351
351 this.currentSession_ = session; 352 this.currentSession_ = session;
(...skipping 16 matching lines...) Expand all
368 videoPlayerElement.setAttribute('castable', true); 369 videoPlayerElement.setAttribute('castable', true);
369 else 370 else
370 videoPlayerElement.removeAttribute('castable'); 371 videoPlayerElement.removeAttribute('castable');
371 }).catch(function() { 372 }).catch(function() {
372 videoPlayerElement.setAttribute('castable', true); 373 videoPlayerElement.setAttribute('castable', true);
373 }); 374 });
374 375
375 videoElementInitializePromise = Promise.resolve(); 376 videoElementInitializePromise = Promise.resolve();
376 } 377 }
377 378
378 videoElementInitializePromise. 379 videoElementInitializePromise
379 then(function() { 380 .then(function() {
380 var handler = function(currentPos) { 381 var handler = function(currentPos) {
381 if (currentPos === this.currentPos_) { 382 if (currentPos === this.currentPos_) {
382 if (opt_callback) 383 if (opt_callback)
383 opt_callback(); 384 opt_callback();
384 videoPlayerElement.removeAttribute('loading'); 385 videoPlayerElement.removeAttribute('loading');
385 this.controls.inactivityWatcher.disabled = false; 386 this.controls.inactivityWatcher.disabled = false;
386 } 387 }
387 388
388 this.videoElement_.removeEventListener('loadedmetadata', handler); 389 this.videoElement_.removeEventListener('loadedmetadata', handler);
389 }.wrap(this, this.currentPos_); 390 }.wrap(this, this.currentPos_);
390 391
391 this.videoElement_.addEventListener('loadedmetadata', handler); 392 this.videoElement_.addEventListener('loadedmetadata', handler);
392 393
393 this.videoElement_.addEventListener('play', function() { 394 this.videoElement_.addEventListener('play', function() {
394 chrome.power.requestKeepAwake('display'); 395 chrome.power.requestKeepAwake('display');
395 }.wrap()); 396 }.wrap());
396 this.videoElement_.addEventListener('pause', function() { 397 this.videoElement_.addEventListener('pause', function() {
397 chrome.power.releaseKeepAwake(); 398 chrome.power.releaseKeepAwake();
398 }.wrap()); 399 }.wrap());
399 400
400 this.videoElement_.load(); 401 this.videoElement_.load();
401 callback(); 402 callback();
402 }.bind(this)). 403 }.bind(this))
403 // In case of error. 404 // In case of error.
404 catch(function(error) { 405 .catch(function(error) {
405 videoPlayerElement.removeAttribute('loading'); 406 videoPlayerElement.removeAttribute('loading');
406 console.error('Failed to initialize the video element.', 407 console.error('Failed to initialize the video element.',
407 error.stack || error); 408 error.stack || error);
408 this.controls_.showErrorMessage('GALLERY_VIDEO_ERROR'); 409 this.controls_.showErrorMessage('GALLERY_VIDEO_ERROR');
409 callback(); 410 callback();
410 }.bind(this)); 411 }.bind(this));
411 }.wrap(this)); 412 }.wrap(this));
412 }; 413 };
413 414
414 /** 415 /**
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 * @param {function()=} opt_callback Completion callback. 514 * @param {function()=} opt_callback Completion callback.
514 */ 515 */
515 VideoPlayer.prototype.reloadCurrentVideo = function(opt_callback) { 516 VideoPlayer.prototype.reloadCurrentVideo = function(opt_callback) {
516 var currentVideo = this.videos_[this.currentPos_]; 517 var currentVideo = this.videos_[this.currentPos_];
517 this.loadVideo_(currentVideo, opt_callback); 518 this.loadVideo_(currentVideo, opt_callback);
518 }; 519 };
519 520
520 /** 521 /**
521 * Invokes when a menuitem in the cast menu is selected. 522 * Invokes when a menuitem in the cast menu is selected.
522 * @param {Object} cast Selected element in the list of casts. 523 * @param {Object} cast Selected element in the list of casts.
524 * @private
523 */ 525 */
524 VideoPlayer.prototype.onCastSelected_ = function(cast) { 526 VideoPlayer.prototype.onCastSelected_ = function(cast) {
525 // If the selected item is same as the current item, do nothing. 527 // If the selected item is same as the current item, do nothing.
526 if ((this.currentCast_ && this.currentCast_.label) === (cast && cast.label)) 528 if ((this.currentCast_ && this.currentCast_.label) === (cast && cast.label))
527 return; 529 return;
528 530
529 this.unloadVideo(false); 531 this.unloadVideo(false);
530 532
531 // Waits for unloading video. 533 // Waits for unloading video.
532 this.loadQueue_.run(function(callback) { 534 this.loadQueue_.run(function(callback) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 var initPromise = Promise.all( 670 var initPromise = Promise.all(
669 [new Promise(initVideos.wrap(null)), 671 [new Promise(initVideos.wrap(null)),
670 new Promise(initStrings.wrap(null)), 672 new Promise(initStrings.wrap(null)),
671 new Promise(util.addPageLoadHandler.wrap(null))]); 673 new Promise(util.addPageLoadHandler.wrap(null))]);
672 674
673 initPromise.then(function(results) { 675 initPromise.then(function(results) {
674 var videos = results[0]; 676 var videos = results[0];
675 player.prepare(videos); 677 player.prepare(videos);
676 return new Promise(player.playFirstVideo.wrap(player)); 678 return new Promise(player.playFirstVideo.wrap(player));
677 }.wrap(null)); 679 }.wrap(null));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698