Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / browser_frame_ash.cc
blob22f2a99747e97210997fafd42e9af4196c9caabd
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/frame/browser_frame_ash.h"
7 #include "ash/shell.h"
8 #include "ash/wm/window_properties.h"
9 #include "ash/wm/window_state.h"
10 #include "ash/wm/window_state_delegate.h"
11 #include "ash/wm/window_util.h"
12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/views/frame/browser_shutdown.h"
15 #include "chrome/browser/ui/views/frame/browser_view.h"
16 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_observer.h"
19 #include "ui/views/view.h"
21 namespace {
23 // BrowserWindowStateDelegate class handles a user's fullscreen
24 // request (Shift+F4/F4).
25 class BrowserWindowStateDelegate : public ash::wm::WindowStateDelegate {
26 public:
27 explicit BrowserWindowStateDelegate(Browser* browser)
28 : browser_(browser) {
29 DCHECK(browser_);
31 ~BrowserWindowStateDelegate() override {}
33 // Overridden from ash::wm::WindowStateDelegate.
34 bool ToggleFullscreen(ash::wm::WindowState* window_state) override {
35 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize());
36 // Windows which cannot be maximized should not be fullscreened.
37 if (!window_state->IsFullscreen() && !window_state->CanMaximize())
38 return true;
39 chrome::ToggleFullscreenMode(browser_);
40 return true;
42 private:
43 Browser* browser_; // not owned.
45 DISALLOW_COPY_AND_ASSIGN(BrowserWindowStateDelegate);
48 } // namespace
50 ///////////////////////////////////////////////////////////////////////////////
51 // BrowserFrameAsh, public:
53 // static
54 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh";
56 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame,
57 BrowserView* browser_view)
58 : views::NativeWidgetAura(browser_frame),
59 browser_view_(browser_view) {
60 GetNativeWindow()->SetName(kWindowName);
61 Browser* browser = browser_view->browser();
62 ash::wm::WindowState* window_state =
63 ash::wm::GetWindowState(GetNativeWindow());
64 window_state->SetDelegate(
65 scoped_ptr<ash::wm::WindowStateDelegate>(
66 new BrowserWindowStateDelegate(browser)).Pass());
68 // Turn on auto window management if we don't need an explicit bounds.
69 // This way the requested bounds are honored.
70 if (!browser->bounds_overridden() && !browser->is_session_restore())
71 SetWindowAutoManaged();
72 #if defined(OS_CHROMEOS)
73 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys
74 // like brightness, volume, etc. Otherwise these keys are handled by the
75 // Ash window manager.
76 window_state->set_can_consume_system_keys(browser->is_app());
77 #endif // defined(OS_CHROMEOS)
80 ///////////////////////////////////////////////////////////////////////////////
81 // BrowserFrameAsh, views::NativeWidgetAura overrides:
83 void BrowserFrameAsh::OnWindowDestroying(aura::Window* window) {
84 // Destroy any remaining WebContents early on. Doing so may result in
85 // calling back to one of the Views/LayoutManagers or supporting classes of
86 // BrowserView. By destroying here we ensure all said classes are valid.
87 DestroyBrowserWebContents(browser_view_->browser());
88 NativeWidgetAura::OnWindowDestroying(window);
91 void BrowserFrameAsh::OnWindowTargetVisibilityChanged(bool visible) {
92 if (visible) {
93 // Once the window has been shown we know the requested bounds
94 // (if provided) have been honored and we can switch on window management.
95 SetWindowAutoManaged();
97 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible);
100 bool BrowserFrameAsh::ShouldSaveWindowPlacement() const {
101 return nullptr == GetWidget()->GetNativeWindow()->GetProperty(
102 ash::kRestoreBoundsOverrideKey);
105 void BrowserFrameAsh::GetWindowPlacement(
106 gfx::Rect* bounds,
107 ui::WindowShowState* show_state) const {
108 gfx::Rect* override_bounds = GetWidget()->GetNativeWindow()->GetProperty(
109 ash::kRestoreBoundsOverrideKey);
110 if (override_bounds && !override_bounds->IsEmpty()) {
111 *bounds = *override_bounds;
112 *show_state = GetWidget()->GetNativeWindow()->GetProperty(
113 ash::kRestoreShowStateOverrideKey);
114 } else {
115 *bounds = GetWidget()->GetRestoredBounds();
116 *show_state = GetWidget()->GetNativeWindow()->GetProperty(
117 aura::client::kShowStateKey);
120 if (*show_state != ui::SHOW_STATE_MAXIMIZED &&
121 *show_state != ui::SHOW_STATE_MINIMIZED) {
122 *show_state = ui::SHOW_STATE_NORMAL;
125 if (ash::wm::GetWindowState(GetNativeWindow())->IsDocked()) {
126 if (browser_view_->browser()->is_app()) {
127 // Only web app windows (not tabbed browser windows) persist docked state.
128 *show_state = ui::SHOW_STATE_DOCKED;
129 } else {
130 // Restore original restore bounds for tabbed browser windows ignoring
131 // the docked origin.
132 gfx::Rect* restore_bounds = GetWidget()->GetNativeWindow()->GetProperty(
133 aura::client::kRestoreBoundsKey);
134 if (restore_bounds)
135 *bounds = *restore_bounds;
140 ////////////////////////////////////////////////////////////////////////////////
141 // BrowserFrameAsh, NativeBrowserFrame implementation:
143 views::Widget::InitParams BrowserFrameAsh::GetWidgetParams() {
144 views::Widget::InitParams params;
145 params.native_widget = this;
147 params.context = ash::Shell::GetPrimaryRootWindow();
148 #if defined(OS_WIN)
149 // If this window is under ASH on Windows, we need it to be translucent.
150 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
151 #endif
153 return params;
156 bool BrowserFrameAsh::UseCustomFrame() const {
157 return true;
160 bool BrowserFrameAsh::UsesNativeSystemMenu() const {
161 return false;
164 int BrowserFrameAsh::GetMinimizeButtonOffset() const {
165 return 0;
168 BrowserFrameAsh::~BrowserFrameAsh() {
171 ///////////////////////////////////////////////////////////////////////////////
172 // BrowserFrameAsh, private:
174 void BrowserFrameAsh::SetWindowAutoManaged() {
175 if (!browser_view_->browser()->is_type_popup() ||
176 browser_view_->browser()->is_app()) {
177 ash::wm::GetWindowState(GetNativeWindow())->
178 set_window_position_managed(true);