OLD | NEW |
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 #include "chrome/browser/ui/views/profiles/user_manager_view.h" | 5 #include "chrome/browser/ui/views/profiles/user_manager_view.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/lifetime/application_lifetime.h" | 8 #include "chrome/browser/lifetime/application_lifetime.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/profiles/profile_metrics.h" | 10 #include "chrome/browser/profiles/profile_metrics.h" |
11 #include "chrome/browser/profiles/profile_window.h" | 11 #include "chrome/browser/profiles/profile_window.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_dialogs.h" | 13 #include "chrome/browser/ui/browser_dialogs.h" |
14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/views/auto_keep_alive.h" | 15 #include "chrome/browser/ui/views/auto_keep_alive.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/views/controls/webview/webview.h" | 19 #include "ui/views/controls/webview/webview.h" |
20 #include "ui/views/layout/fill_layout.h" | 20 #include "ui/views/layout/fill_layout.h" |
21 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 23 #include "ui/views/window/dialog_client_view.h" |
23 | 24 |
24 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
25 #include "chrome/browser/shell_integration.h" | 26 #include "chrome/browser/shell_integration.h" |
26 #include "ui/base/win/shell.h" | 27 #include "ui/base/win/shell.h" |
27 #include "ui/views/win/hwnd_util.h" | 28 #include "ui/views/win/hwnd_util.h" |
28 #endif | 29 #endif |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 // Default window size. | 33 // Default window size. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 void UserManagerView::OnGuestProfileCreated( | 99 void UserManagerView::OnGuestProfileCreated( |
99 scoped_ptr<UserManagerView> instance, | 100 scoped_ptr<UserManagerView> instance, |
100 Profile* guest_profile, | 101 Profile* guest_profile, |
101 const std::string& url) { | 102 const std::string& url) { |
102 instance_ = instance.release(); // |instance_| takes over ownership. | 103 instance_ = instance.release(); // |instance_| takes over ownership. |
103 instance_->Init(guest_profile, GURL(url)); | 104 instance_->Init(guest_profile, GURL(url)); |
104 } | 105 } |
105 | 106 |
106 void UserManagerView::Init(Profile* guest_profile, const GURL& url) { | 107 void UserManagerView::Init(Profile* guest_profile, const GURL& url) { |
107 web_view_ = new views::WebView(guest_profile); | 108 web_view_ = new views::WebView(guest_profile); |
| 109 web_view_->set_allow_accelerators(true); |
| 110 AddChildView(web_view_); |
108 SetLayoutManager(new views::FillLayout); | 111 SetLayoutManager(new views::FillLayout); |
109 AddChildView(web_view_); | 112 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN)); |
110 | 113 |
111 DialogDelegate::CreateDialogWidget(this, NULL, NULL); | 114 DialogDelegate::CreateDialogWidget(this, NULL, NULL); |
| 115 // Since the User Manager can be the only top level window, we don't |
| 116 // want to accidentally quit all of Chrome if the user is just trying to |
| 117 // unfocus the selected pod in the WebView. |
| 118 GetDialogClientView()->RemoveAccelerator( |
| 119 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
112 | 120 |
113 #if defined(OS_WIN) | 121 #if defined(OS_WIN) |
114 // Set the app id for the task manager to the app id of its parent | 122 // Set the app id for the task manager to the app id of its parent |
115 ui::win::SetAppIdForWindow( | 123 ui::win::SetAppIdForWindow( |
116 ShellIntegration::GetChromiumModelIdForProfile( | 124 ShellIntegration::GetChromiumModelIdForProfile( |
117 guest_profile->GetPath()), | 125 guest_profile->GetPath()), |
118 views::HWNDForWidget(GetWidget())); | 126 views::HWNDForWidget(GetWidget())); |
119 #endif | 127 #endif |
120 GetWidget()->Show(); | 128 GetWidget()->Show(); |
121 | 129 |
122 web_view_->LoadInitialURL(url); | 130 web_view_->LoadInitialURL(url); |
123 web_view_->RequestFocus(); | 131 web_view_->RequestFocus(); |
124 } | 132 } |
125 | 133 |
| 134 bool UserManagerView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 135 DCHECK_EQ(ui::VKEY_W, accelerator.key_code()); |
| 136 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers()); |
| 137 GetWidget()->Close(); |
| 138 return true; |
| 139 } |
| 140 |
126 gfx::Size UserManagerView::GetPreferredSize() const { | 141 gfx::Size UserManagerView::GetPreferredSize() const { |
127 return gfx::Size(kWindowWidth, kWindowHeight); | 142 return gfx::Size(kWindowWidth, kWindowHeight); |
128 } | 143 } |
129 | 144 |
130 bool UserManagerView::CanResize() const { | 145 bool UserManagerView::CanResize() const { |
131 return true; | 146 return true; |
132 } | 147 } |
133 | 148 |
134 bool UserManagerView::CanMaximize() const { | 149 bool UserManagerView::CanMaximize() const { |
135 return true; | 150 return true; |
(...skipping 11 matching lines...) Expand all Loading... |
147 // Now that the window is closed, we can allow a new one to be opened. | 162 // Now that the window is closed, we can allow a new one to be opened. |
148 // (WindowClosing comes in asynchronously from the call to Close() and we | 163 // (WindowClosing comes in asynchronously from the call to Close() and we |
149 // may have already opened a new instance). | 164 // may have already opened a new instance). |
150 if (instance_ == this) | 165 if (instance_ == this) |
151 instance_ = NULL; | 166 instance_ = NULL; |
152 } | 167 } |
153 | 168 |
154 bool UserManagerView::UseNewStyleForThisDialog() const { | 169 bool UserManagerView::UseNewStyleForThisDialog() const { |
155 return false; | 170 return false; |
156 } | 171 } |
OLD | NEW |