Commit 308d2b20 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Video Player: Supports bound arguments of wrap() util function

And with this patch, the error detail is shown in case of error.

BUG=355545
TEST=manually tested
R=hirono@chromium.org

Review URL: https://codereview.chromium.org/315103004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275328 0039d316-1c4b-4281-b951-d872f2087c98
parent db160b7d
...@@ -22,19 +22,26 @@ window.onerror = function() { window.JSErrorCount++; }; ...@@ -22,19 +22,26 @@ window.onerror = function() { window.JSErrorCount++; };
* - Bind this object * - Bind this object
* *
* @param {Object} thisObject Object to be used as this. * @param {Object} thisObject Object to be used as this.
* @param {...} var_args Arguments to be bound with the wrapped function.
* @return {function} Wrapped function. * @return {function} Wrapped function.
*/ */
Function.prototype.wrap = function(thisObject) { Function.prototype.wrap = function(thisObject, var_args) {
var func = this; var func = this;
var liveStack = (new Error('Stack trace before async call')).stack; var liveStack = (new Error('Stack trace before async call')).stack;
if (thisObject === undefined) if (thisObject === undefined)
thisObject = null; thisObject = null;
var boundArguments = Array.prototype.slice.call(arguments, 1);
return function wrappedCallback() { return function wrappedCallback(var_args) {
try { try {
return func.apply(thisObject, arguments); var args = boundArguments.concat(Array.prototype.slice.call(arguments));
return func.apply(thisObject, args);
} catch (e) { } catch (e) {
console.error('Exception happens in callback.', liveStack); // Some async funcrtion doesn't handle exception correctly. So outputing
// the exception message and stack trace just in case.
// The message will show twice if the caller handles exception correctly.
console.error(e.stack);
console.info('Exception above happened in callback.', liveStack);
window.JSErrorCount++; window.JSErrorCount++;
throw e; throw e;
......
...@@ -51,7 +51,7 @@ function FullWindowVideoControls( ...@@ -51,7 +51,7 @@ function FullWindowVideoControls(
this.inactivityWatcher_ = new MouseInactivityWatcher(playerContainer); this.inactivityWatcher_ = new MouseInactivityWatcher(playerContainer);
this.__defineGetter__('inactivityWatcher', function() { this.__defineGetter__('inactivityWatcher', function() {
return this.inactivityWatcher_; return this.inactivityWatcher_;
}); }.wrap(this));
this.inactivityWatcher_.check(); this.inactivityWatcher_.check();
} }
...@@ -126,11 +126,11 @@ VideoPlayer.prototype = { ...@@ -126,11 +126,11 @@ VideoPlayer.prototype = {
* @param {Array.<Object.<string, Object>>} videos List of videos. * @param {Array.<Object.<string, Object>>} videos List of videos.
*/ */
VideoPlayer.prototype.prepare = function(videos) { VideoPlayer.prototype.prepare = function(videos) {
document.ondragstart = function(e) { e.preventDefault() };
this.videos_ = videos; this.videos_ = videos;
var preventDefault = function(event) { event.preventDefault(); }; var preventDefault = function(event) { event.preventDefault(); }.wrap(null);
document.ondragstart = preventDefault;
var maximizeButton = document.querySelector('.maximize-button'); var maximizeButton = document.querySelector('.maximize-button');
maximizeButton.addEventListener( maximizeButton.addEventListener(
...@@ -141,7 +141,7 @@ VideoPlayer.prototype.prepare = function(videos) { ...@@ -141,7 +141,7 @@ VideoPlayer.prototype.prepare = function(videos) {
appWindow.restore(); appWindow.restore();
else else
appWindow.maximize(); appWindow.maximize();
}); }.wrap(null));
maximizeButton.addEventListener('mousedown', preventDefault); maximizeButton.addEventListener('mousedown', preventDefault);
var minimizeButton = document.querySelector('.minimize-button'); var minimizeButton = document.querySelector('.minimize-button');
...@@ -149,13 +149,13 @@ VideoPlayer.prototype.prepare = function(videos) { ...@@ -149,13 +149,13 @@ VideoPlayer.prototype.prepare = function(videos) {
'click', 'click',
function() { function() {
chrome.app.window.current().minimize() chrome.app.window.current().minimize()
}); }.wrap(null));
minimizeButton.addEventListener('mousedown', preventDefault); minimizeButton.addEventListener('mousedown', preventDefault);
var closeButton = document.querySelector('.close-button'); var closeButton = document.querySelector('.close-button');
closeButton.addEventListener( closeButton.addEventListener(
'click', 'click',
function() { close(); }); function() { close(); }.wrap(null));
closeButton.addEventListener('mousedown', preventDefault); closeButton.addEventListener('mousedown', preventDefault);
this.controls_ = new FullWindowVideoControls( this.controls_ = new FullWindowVideoControls(
...@@ -302,7 +302,7 @@ function initVideos(callback) { ...@@ -302,7 +302,7 @@ function initVideos(callback) {
var videos = window.videos; var videos = window.videos;
window.videos = null; window.videos = null;
callback(videos); callback(videos);
}); }.wrap(null));
} }
var player = new VideoPlayer(); var player = new VideoPlayer();
...@@ -315,7 +315,7 @@ function initStrings(callback) { ...@@ -315,7 +315,7 @@ function initStrings(callback) {
chrome.fileBrowserPrivate.getStrings(function(strings) { chrome.fileBrowserPrivate.getStrings(function(strings) {
loadTimeData.data = strings; loadTimeData.data = strings;
callback(); callback();
}); }.wrap(null));
} }
var initPromise = Promise.all( var initPromise = Promise.all(
...@@ -327,4 +327,4 @@ initPromise.then(function(results) { ...@@ -327,4 +327,4 @@ initPromise.then(function(results) {
var videos = results[0]; var videos = results[0];
player.prepare(videos); player.prepare(videos);
return new Promise(player.playVideo.wrap(player)); return new Promise(player.playVideo.wrap(player));
}); }.wrap(null));
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