Commit de8bf97e authored by scheib@chromium.org's avatar scheib@chromium.org

fullscreen in apps v2 ShellWindow via app.window.create.

This allows packaged applications to launch windows
already into a fullscreen, maximized, or minimized state.

Design doc: https://docs.google.com/a/google.com/document/d/1__SPIxd_sFVYFNdP55CouE-p61uLOWEL-X-2TEOJFdY/edit

BUG=163626

TEST=Manual testing is appropriate as this functionality is tightly coupled with operating system functionality and related automated tests have always been disabled flaky. Please use the window-state sample: https://github.com/GoogleChrome/chrome-app-samples/tree/master/window-state.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192952 0039d316-1c4b-4281-b951-d872f2087c98
parent bbb92cdb
......@@ -51,21 +51,27 @@ bool AppCurrentWindowInternalFocusFunction::RunWithWindow(ShellWindow* window) {
return true;
}
bool AppCurrentWindowInternalFullscreenFunction::RunWithWindow(
ShellWindow* window) {
window->Fullscreen();
return true;
}
bool AppCurrentWindowInternalMaximizeFunction::RunWithWindow(
ShellWindow* window) {
window->GetBaseWindow()->Maximize();
window->Maximize();
return true;
}
bool AppCurrentWindowInternalMinimizeFunction::RunWithWindow(
ShellWindow* window) {
window->GetBaseWindow()->Minimize();
window->Minimize();
return true;
}
bool AppCurrentWindowInternalRestoreFunction::RunWithWindow(
ShellWindow* window) {
window->GetBaseWindow()->Restore();
window->Restore();
return true;
}
......
......@@ -33,6 +33,17 @@ class AppCurrentWindowInternalFocusFunction
virtual bool RunWithWindow(ShellWindow* window) OVERRIDE;
};
class AppCurrentWindowInternalFullscreenFunction
: public AppCurrentWindowInternalExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("app.currentWindowInternal.fullscreen",
APP_CURRENTWINDOWINTERNAL_FULLSCREEN)
protected:
virtual ~AppCurrentWindowInternalFullscreenFunction() {}
virtual bool RunWithWindow(ShellWindow* window) OVERRIDE;
};
class AppCurrentWindowInternalMaximizeFunction
: public AppCurrentWindowInternalExtensionFunction {
public:
......
......@@ -211,6 +211,23 @@ bool AppWindowCreateFunction::RunImpl() {
if (options->resizable.get())
create_params.resizable = *options->resizable.get();
if (options->type != extensions::api::app_window::WINDOW_TYPE_PANEL) {
switch (options->state) {
case extensions::api::app_window::STATE_NONE:
case extensions::api::app_window::STATE_NORMAL:
break;
case extensions::api::app_window::STATE_FULLSCREEN:
create_params.state = ShellWindow::CreateParams::STATE_FULLSCREEN;
break;
case extensions::api::app_window::STATE_MAXIMIZED:
create_params.state = ShellWindow::CreateParams::STATE_MAXIMIZED;
break;
case extensions::api::app_window::STATE_MINIMIZED:
create_params.state = ShellWindow::CreateParams::STATE_MINIMIZED;
break;
}
}
}
create_params.creator_process_id =
......@@ -220,7 +237,7 @@ bool AppWindowCreateFunction::RunImpl() {
ShellWindow::Create(profile(), GetExtension(), url, create_params);
if (chrome::ShouldForceFullscreenApp())
shell_window->GetBaseWindow()->SetFullscreen(true);
shell_window->Fullscreen();
content::RenderViewHost* created_view =
shell_window->web_contents()->GetRenderViewHost();
......
......@@ -500,6 +500,7 @@ enum HistogramValue {
WALLPAPERPRIVATE_RESETWALLPAPER,
DEVELOPERPRIVATE_PERMISSIONS,
WEBSTOREPRIVATE_ENABLEAPPLAUNCHER,
APP_CURRENTWINDOWINTERNAL_FULLSCREEN,
ENUM_BOUNDARY // Last entry: Add new entries above.
};
......
......@@ -73,7 +73,11 @@ ShellWindow::CreateParams::CreateParams()
frame(ShellWindow::FRAME_CHROME),
transparent_background(false),
bounds(INT_MIN, INT_MIN, 0, 0),
creator_process_id(0), hidden(false), resizable(true), focused(true) {
creator_process_id(0),
state(STATE_NORMAL),
hidden(false),
resizable(true),
focused(true) {
}
ShellWindow::CreateParams::~CreateParams() {
......@@ -95,7 +99,9 @@ ShellWindow::ShellWindow(Profile* profile,
: profile_(profile),
extension_(extension),
window_type_(WINDOW_TYPE_DEFAULT),
ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_ptr_factory_(this)) {
ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_ptr_factory_(this)),
fullscreen_for_window_api_(false),
fullscreen_for_tab_(false) {
}
void ShellWindow::Init(const GURL& url,
......@@ -165,6 +171,20 @@ void ShellWindow::Init(const GURL& url,
native_app_window_.reset(NativeAppWindow::Create(this, new_params));
OnNativeWindowChanged();
switch (params.state) {
case CreateParams::STATE_NORMAL:
break;
case CreateParams::STATE_FULLSCREEN:
Fullscreen();
break;
case CreateParams::STATE_MAXIMIZED:
Maximize();
break;
case CreateParams::STATE_MINIMIZED:
Minimize();
break;
}
if (!params.hidden) {
if (window_type_is_panel())
GetBaseWindow()->ShowInactive(); // Panels are not activated by default.
......@@ -382,6 +402,29 @@ void ShellWindow::UpdateAppIcon(const gfx::Image& image) {
extensions::ShellWindowRegistry::Get(profile_)->ShellWindowIconChanged(this);
}
void ShellWindow::Fullscreen() {
fullscreen_for_window_api_ = true;
GetBaseWindow()->SetFullscreen(true);
}
void ShellWindow::Maximize() {
GetBaseWindow()->Maximize();
}
void ShellWindow::Minimize() {
GetBaseWindow()->Minimize();
}
void ShellWindow::Restore() {
fullscreen_for_window_api_ = false;
fullscreen_for_tab_ = false;
if (GetBaseWindow()->IsFullscreenOrPending()) {
GetBaseWindow()->SetFullscreen(false);
} else {
GetBaseWindow()->Restore();
}
}
//------------------------------------------------------------------------------
// Private methods
......@@ -455,18 +498,25 @@ void ShellWindow::NavigationStateChanged(
void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source,
bool enter_fullscreen) {
bool has_permission = IsExtensionWithPermissionOrSuggestInConsole(
if (!IsExtensionWithPermissionOrSuggestInConsole(
APIPermission::kFullscreen,
extension_,
source->GetRenderViewHost());
source->GetRenderViewHost())) {
return;
}
if (has_permission)
native_app_window_->SetFullscreen(enter_fullscreen);
fullscreen_for_tab_ = enter_fullscreen;
if (enter_fullscreen) {
native_app_window_->SetFullscreen(true);
} else if (!fullscreen_for_window_api_) {
native_app_window_->SetFullscreen(false);
}
}
bool ShellWindow::IsFullscreenForTabOrPending(
const content::WebContents* source) const {
return native_app_window_->IsFullscreenOrPending();
return fullscreen_for_tab_;
}
void ShellWindow::Observe(int type,
......
......@@ -102,6 +102,16 @@ class ShellWindow : public content::NotificationObserver,
// The process ID of the process that requested the create.
int32 creator_process_id;
enum State {
STATE_NORMAL,
STATE_FULLSCREEN,
STATE_MAXIMIZED,
STATE_MINIMIZED
};
// Initial state of the window.
State state;
// If true, don't show the window after creation.
bool hidden;
......@@ -181,6 +191,13 @@ class ShellWindow : public content::NotificationObserver,
// callback. Also called externally for v1 apps using Ash Panels.
void UpdateAppIcon(const gfx::Image& image);
// Transitions window into fullscreen, maximized, minimized or restores based
// on chrome.app.window API.
void Fullscreen();
void Maximize();
void Minimize();
void Restore();
ShellWindowContents* shell_window_contents_for_test() {
return shell_window_contents_.get();
}
......@@ -285,6 +302,11 @@ class ShellWindow : public content::NotificationObserver,
base::WeakPtrFactory<ShellWindow> image_loader_ptr_factory_;
// Fullscreen entered by app.window api.
bool fullscreen_for_window_api_;
// Fullscreen entered by HTML requestFullscreen.
bool fullscreen_for_tab_;
DISALLOW_COPY_AND_ASSIGN(ShellWindow);
};
......
......@@ -19,6 +19,7 @@
interface Functions {
static void focus();
static void fullscreen();
static void minimize();
static void maximize();
static void restore();
......
......@@ -10,6 +10,9 @@ namespace app.window {
long? height;
};
// State of a window: normal, fullscreen, maximized, minimized.
enum State { normal, fullscreen, maximized, minimized };
// 'shell' is the default window type. 'panel' is managed by the OS
// (Currently experimental, Ash only).
[nodoc] enum WindowType { shell, panel };
......@@ -75,6 +78,10 @@ namespace app.window {
// Only supported in ash. Requires experimental API permission.
boolean? transparentBackground;
// The initial state of the window, allowing it to be created already
// fullscreen, maximized, or minimized. Defaults to 'normal'.
State? state;
// If true, the window will be created in a hidden state. Call show() on
// the window to show it once it has been created. Defaults to false.
boolean? hidden;
......@@ -97,6 +104,9 @@ namespace app.window {
// Focus the window.
static void focus();
// Fullscreens the window.
static void fullscreen();
// Is the window fullscreen?
static boolean isFullscreen();
......@@ -112,7 +122,7 @@ namespace app.window {
// Is the window maximized?
static boolean isMaximized();
// Restore the window, exiting a maximized or minimized state.
// Restore the window, exiting a maximized, minimized, or fullscreen state.
static void restore();
// Move the window to the position (|left|, |top|).
......
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