Better fullscreen handling for Chrome OS Video Player

This is a revival of https://chromiumcodereview.appspot.com/9288062/ which was abandoned in favor of https://chromiumcodereview.appspot.com/9298009/.

Turns out that webkitRequestFullscreen is not suitable for Chrome OS File Browser because it gives us a different kind of fullscreen mode than the one we get when pressing the dedicated Chromebook key (see the bug for details).

BUG=chromium-os:26003
TEST=

Review URL: https://chromiumcodereview.appspot.com/9565008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124631 0039d316-1c4b-4281-b951-d872f2087c98
parent 6e84d357
......@@ -28,6 +28,7 @@
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/select_file_dialog_extension.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/common/chrome_switches.h"
......@@ -1610,6 +1611,22 @@ void GetVolumeMetadataFunction::GetLocalPathsResponseOnUIThread(
SendResponse(true);
}
bool ToggleFullscreenFunction::RunImpl() {
Browser* browser = GetCurrentBrowser();
if (browser) {
browser->ToggleFullscreenModeWithExtension(
file_manager_util::GetFileBrowserExtensionUrl());
}
return true;
}
bool IsFullscreenFunction::RunImpl() {
Browser* browser = GetCurrentBrowser();
result_.reset(Value::CreateBooleanValue(
browser && browser->window() && browser->window()->IsFullscreen()));
return true;
}
bool FileDialogStringsFunction::RunImpl() {
result_.reset(new DictionaryValue());
DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get());
......
......@@ -352,6 +352,22 @@ class GetVolumeMetadataFunction
DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getVolumeMetadata");
};
// Toggles fullscreen mode for the browser.
class ToggleFullscreenFunction : public SyncExtensionFunction {
protected:
virtual bool RunImpl() OVERRIDE;
private:
DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.toggleFullscreen");
};
// Checks if the browser is in fullscreen mode.
class IsFullscreenFunction : public SyncExtensionFunction {
protected:
virtual bool RunImpl() OVERRIDE;
private:
DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.isFullscreen");
};
// File Dialog Strings.
class FileDialogStringsFunction : public SyncExtensionFunction {
public:
......
......@@ -410,6 +410,8 @@ void FactoryRegistry::ResetFunctions() {
RegisterFunction<GetSizeStatsFunction>();
RegisterFunction<FormatDeviceFunction>();
RegisterFunction<ViewFilesFunction>();
RegisterFunction<ToggleFullscreenFunction>();
RegisterFunction<IsFullscreenFunction>();
// Mediaplayer
RegisterFunction<PlayMediaplayerFunction>();
......
......@@ -229,6 +229,10 @@ Gallery.prototype.initDom_ = function(shareActions) {
} else {
this.shareMode_ = null;
}
Gallery.getFileBrowserPrivate().isFullscreen(function(fullscreen) {
this.originalFullscreen_ = fullscreen;
}.bind(this));
};
Gallery.blobToURL_ = function(blob) {
......@@ -437,24 +441,32 @@ Gallery.prototype.isRenaming_ = function() {
return this.container_.hasAttribute('renaming');
};
Gallery.getFileBrowserPrivate = function() {
return chrome.fileBrowserPrivate || window.top.chrome.fileBrowserPrivate;
};
Gallery.prototype.toggleFullscreen_ = function() {
if (this.document_.webkitIsFullScreen) {
this.document_.webkitCancelFullScreen();
} else {
this.document_.body.webkitRequestFullScreen();
}
Gallery.getFileBrowserPrivate().toggleFullscreen();
};
/**
* Close the Gallery.
*/
Gallery.prototype.close_ = function() {
Gallery.getFileBrowserPrivate().isFullscreen(function(fullscreen) {
if (this.originalFullscreen_ != fullscreen) {
Gallery.getFileBrowserPrivate().toggleFullscreen();
}
this.closeCallback_();
}.bind(this));
};
/**
* Handle user's 'Close' action (Escape or a click on the X icon).
*/
Gallery.prototype.onClose_ = function() {
if (this.document_.webkitIsFullScreen) {
// Closing the Gallery iframe while in full screen will crash the tab.
this.document_.addEventListener(
'webkitfullscreenchange', this.onClose_.bind(this));
this.document_.webkitCancelFullScreen();
return;
}
// TODO: handle write errors gracefully (suggest retry or saving elsewhere).
this.saveChanges_(this.closeCallback_);
this.saveChanges_(this.close_.bind(this));
};
Gallery.prototype.prefetchImage = function(id, content, metadata) {
......
......@@ -259,6 +259,17 @@ chrome.fileBrowserPrivate = {
callback(metadata);
},
toggleFullscreen: function() {
if (document.webkitIsFullScreen)
document.webkitCancelFullScreen();
else
document.body.webkitRequestFullScreen();
},
isFullscreen: function(callback) {
setTimeout(callback, 0, document.webkitIsFullScreen);
},
/**
* Return localized strings.
*/
......
......@@ -536,6 +536,29 @@
"description": "Device's mount path."
}
]
},
{
"name": "toggleFullscreen",
"description": "Switches fullscreen mode on/off for the File Browser.",
"parameters": []
},
{
"name": "isFullscreen",
"description": "Checks if the browser is in fullscreen mode.",
"parameters": [
{
"name": "callback",
"type": "function",
"optional": false,
"parameters": [
{
"name" : "result",
"type": "boolean",
"description": "Whether the browser is in fullscreen mode."
}
]
}
]
}
],
"events": [
......
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