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/chromeos/login/ui/webui_login_view.h" | 5 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
6 | 6 |
7 #include "ash/common/focus_cycler.h" | 7 #include "ash/common/focus_cycler.h" |
| 8 #include "ash/common/system/status_area_widget_delegate.h" |
8 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
9 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
(...skipping 28 matching lines...) Expand all Loading... |
46 #include "content/public/browser/render_widget_host.h" | 47 #include "content/public/browser/render_widget_host.h" |
47 #include "content/public/browser/render_widget_host_view.h" | 48 #include "content/public/browser/render_widget_host_view.h" |
48 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
49 #include "content/public/browser/web_ui.h" | 50 #include "content/public/browser/web_ui.h" |
50 #include "content/public/common/renderer_preferences.h" | 51 #include "content/public/common/renderer_preferences.h" |
51 #include "extensions/browser/view_type_utils.h" | 52 #include "extensions/browser/view_type_utils.h" |
52 #include "third_party/WebKit/public/web/WebInputEvent.h" | 53 #include "third_party/WebKit/public/web/WebInputEvent.h" |
53 #include "ui/gfx/geometry/rect.h" | 54 #include "ui/gfx/geometry/rect.h" |
54 #include "ui/gfx/geometry/size.h" | 55 #include "ui/gfx/geometry/size.h" |
55 #include "ui/views/controls/webview/webview.h" | 56 #include "ui/views/controls/webview/webview.h" |
| 57 #include "ui/views/focus/focus_manager.h" |
| 58 #include "ui/views/focus/focus_search.h" |
56 #include "ui/views/widget/widget.h" | 59 #include "ui/views/widget/widget.h" |
57 | 60 |
58 using content::NativeWebKeyboardEvent; | 61 using content::NativeWebKeyboardEvent; |
59 using content::RenderViewHost; | 62 using content::RenderViewHost; |
60 using content::WebContents; | 63 using content::WebContents; |
61 using web_modal::WebContentsModalDialogManager; | 64 using web_modal::WebContentsModalDialogManager; |
62 | 65 |
63 namespace { | 66 namespace { |
64 | 67 |
65 // These strings must be kept in sync with handleAccelerator() | 68 // These strings must be kept in sync with handleAccelerator() |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 }; | 100 }; |
98 | 101 |
99 } // namespace | 102 } // namespace |
100 | 103 |
101 namespace chromeos { | 104 namespace chromeos { |
102 | 105 |
103 // static | 106 // static |
104 const char WebUILoginView::kViewClassName[] = | 107 const char WebUILoginView::kViewClassName[] = |
105 "browser/chromeos/login/WebUILoginView"; | 108 "browser/chromeos/login/WebUILoginView"; |
106 | 109 |
| 110 // WebUILoginView::CycleFocusTraversable --------------------------------------- |
| 111 class WebUILoginView::CycleFocusTraversable : public views::FocusTraversable { |
| 112 public: |
| 113 explicit CycleFocusTraversable(WebUILoginView* webui_login_view) |
| 114 : cycle_focus_search_(webui_login_view, true, false) {} |
| 115 ~CycleFocusTraversable() override {} |
| 116 |
| 117 // views::FocusTraversable |
| 118 views::FocusSearch* GetFocusSearch() override { return &cycle_focus_search_; } |
| 119 |
| 120 views::FocusTraversable* GetFocusTraversableParent() override { |
| 121 return nullptr; |
| 122 } |
| 123 |
| 124 views::View* GetFocusTraversableParentView() override { return nullptr; } |
| 125 |
| 126 private: |
| 127 views::FocusSearch cycle_focus_search_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(CycleFocusTraversable); |
| 130 }; |
| 131 |
| 132 // WebUILoginView::StatusAreaFocusTraversable ---------------------------------- |
| 133 class WebUILoginView::StatusAreaFocusTraversable |
| 134 : public views::FocusTraversable { |
| 135 public: |
| 136 StatusAreaFocusTraversable( |
| 137 ash::StatusAreaWidgetDelegate* status_area_widget_delegate, |
| 138 WebUILoginView* webui_login_view) |
| 139 : webui_login_view_(webui_login_view), |
| 140 status_area_focus_search_(status_area_widget_delegate, false, false) {} |
| 141 ~StatusAreaFocusTraversable() override {} |
| 142 |
| 143 // views::FocusTraversable |
| 144 views::FocusSearch* GetFocusSearch() override { |
| 145 return &status_area_focus_search_; |
| 146 } |
| 147 |
| 148 views::FocusTraversable* GetFocusTraversableParent() override { |
| 149 return webui_login_view_->cycle_focus_traversable_.get(); |
| 150 } |
| 151 |
| 152 views::View* GetFocusTraversableParentView() override { |
| 153 return webui_login_view_->status_area_widget_host_; |
| 154 } |
| 155 |
| 156 private: |
| 157 WebUILoginView* const webui_login_view_; |
| 158 views::FocusSearch status_area_focus_search_; |
| 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(StatusAreaFocusTraversable); |
| 161 }; |
| 162 |
107 // WebUILoginView public: ------------------------------------------------------ | 163 // WebUILoginView public: ------------------------------------------------------ |
108 | 164 |
109 WebUILoginView::WebUILoginView() | 165 WebUILoginView::WebUILoginView() |
110 : webui_login_(NULL), | 166 : webui_login_(NULL), |
111 is_hidden_(false), | 167 is_hidden_(false), |
112 webui_visible_(false), | 168 webui_visible_(false), |
113 should_emit_login_prompt_visible_(true), | 169 should_emit_login_prompt_visible_(true), |
114 forward_keyboard_event_(true) { | 170 forward_keyboard_event_(true) { |
115 registrar_.Add(this, | 171 registrar_.Add(this, |
116 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 172 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 AddAccelerator(i->first); | 218 AddAccelerator(i->first); |
163 } | 219 } |
164 | 220 |
165 WebUILoginView::~WebUILoginView() { | 221 WebUILoginView::~WebUILoginView() { |
166 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | 222 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, |
167 observer_list_, | 223 observer_list_, |
168 OnHostDestroying()); | 224 OnHostDestroying()); |
169 | 225 |
170 if (!chrome::IsRunningInMash() && | 226 if (!chrome::IsRunningInMash() && |
171 ash::Shell::GetInstance()->HasPrimaryStatusArea()) { | 227 ash::Shell::GetInstance()->HasPrimaryStatusArea()) { |
172 ash::Shell::GetInstance()->GetPrimarySystemTray()-> | 228 views::Widget* tray_widget = |
173 SetNextFocusableView(NULL); | 229 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget(); |
| 230 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = |
| 231 static_cast<ash::StatusAreaWidgetDelegate*>( |
| 232 tray_widget->GetContentsView()); |
| 233 status_area_widget_delegate->set_custom_focus_traversable(nullptr); |
| 234 status_area_widget_delegate->set_default_last_focusable_child(false); |
174 } else { | 235 } else { |
175 NOTIMPLEMENTED(); | 236 NOTIMPLEMENTED(); |
176 } | 237 } |
177 } | 238 } |
178 | 239 |
179 void WebUILoginView::Init() { | 240 void WebUILoginView::Init() { |
180 Profile* signin_profile = ProfileHelper::GetSigninProfile(); | 241 Profile* signin_profile = ProfileHelper::GetSigninProfile(); |
181 webui_login_ = new views::WebView(signin_profile); | 242 webui_login_ = new views::WebView(signin_profile); |
182 webui_login_->set_allow_accelerators(true); | 243 webui_login_->set_allow_accelerators(true); |
183 AddChildView(webui_login_); | 244 AddChildView(webui_login_); |
(...skipping 15 matching lines...) Expand all Loading... |
199 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 260 WebContentsModalDialogManager::FromWebContents(web_contents)-> |
200 SetDelegate(this); | 261 SetDelegate(this); |
201 | 262 |
202 web_contents->SetDelegate(this); | 263 web_contents->SetDelegate(this); |
203 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT); | 264 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT); |
204 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 265 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
205 web_contents); | 266 web_contents); |
206 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); | 267 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); |
207 renderer_preferences_util::UpdateFromSystemSettings( | 268 renderer_preferences_util::UpdateFromSystemSettings( |
208 prefs, signin_profile, web_contents); | 269 prefs, signin_profile, web_contents); |
| 270 |
| 271 status_area_widget_host_ = new views::View; |
| 272 AddChildView(status_area_widget_host_); |
209 } | 273 } |
210 | 274 |
211 const char* WebUILoginView::GetClassName() const { | 275 const char* WebUILoginView::GetClassName() const { |
212 return kViewClassName; | 276 return kViewClassName; |
213 } | 277 } |
214 | 278 |
215 void WebUILoginView::RequestFocus() { | 279 void WebUILoginView::RequestFocus() { |
216 webui_login_->RequestFocus(); | 280 webui_login_->RequestFocus(); |
217 } | 281 } |
218 | 282 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 webui_login_->LoadInitialURL(url); | 338 webui_login_->LoadInitialURL(url); |
275 webui_login_->RequestFocus(); | 339 webui_login_->RequestFocus(); |
276 | 340 |
277 // TODO(nkostylev): Use WebContentsObserver::RenderViewCreated to track | 341 // TODO(nkostylev): Use WebContentsObserver::RenderViewCreated to track |
278 // when RenderView is created. | 342 // when RenderView is created. |
279 GetWebContents() | 343 GetWebContents() |
280 ->GetRenderViewHost() | 344 ->GetRenderViewHost() |
281 ->GetWidget() | 345 ->GetWidget() |
282 ->GetView() | 346 ->GetView() |
283 ->SetBackgroundColor(SK_ColorTRANSPARENT); | 347 ->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 348 |
| 349 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = |
| 350 GetStatusAreaWidgetDelegate(); |
| 351 DCHECK(status_area_widget_delegate); |
| 352 cycle_focus_traversable_.reset(new CycleFocusTraversable(this)); |
| 353 status_area_focus_traversable_.reset( |
| 354 new StatusAreaFocusTraversable(status_area_widget_delegate, this)); |
| 355 status_area_widget_delegate->set_custom_focus_traversable( |
| 356 status_area_focus_traversable_.get()); |
284 } | 357 } |
285 | 358 |
286 content::WebUI* WebUILoginView::GetWebUI() { | 359 content::WebUI* WebUILoginView::GetWebUI() { |
287 return webui_login_->web_contents()->GetWebUI(); | 360 return webui_login_->web_contents()->GetWebUI(); |
288 } | 361 } |
289 | 362 |
290 content::WebContents* WebUILoginView::GetWebContents() { | 363 content::WebContents* WebUILoginView::GetWebContents() { |
291 return webui_login_->web_contents(); | 364 return webui_login_->web_contents(); |
292 } | 365 } |
293 | 366 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 // In case of blocked UI (ex.: sign in is in progress) | 501 // In case of blocked UI (ex.: sign in is in progress) |
429 // we should not process focus change events. | 502 // we should not process focus change events. |
430 if (!forward_keyboard_event_) | 503 if (!forward_keyboard_event_) |
431 return false; | 504 return false; |
432 | 505 |
433 // Focus is accepted, but the Ash system tray is not available in Mash, so | 506 // Focus is accepted, but the Ash system tray is not available in Mash, so |
434 // exit early. | 507 // exit early. |
435 if (chrome::IsRunningInMash()) | 508 if (chrome::IsRunningInMash()) |
436 return true; | 509 return true; |
437 | 510 |
438 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | 511 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = |
439 if (tray && tray->GetWidget()->IsVisible()) { | 512 GetStatusAreaWidgetDelegate(); |
440 tray->SetNextFocusableView(this); | 513 if (status_area_widget_delegate && status_area_widget_delegate->visible()) { |
| 514 status_area_widget_delegate->set_default_last_focusable_child(reverse); |
441 ash::WmShell::Get()->focus_cycler()->RotateFocus( | 515 ash::WmShell::Get()->focus_cycler()->RotateFocus( |
442 reverse ? ash::FocusCycler::BACKWARD : ash::FocusCycler::FORWARD); | 516 reverse ? ash::FocusCycler::BACKWARD : ash::FocusCycler::FORWARD); |
443 } | 517 } |
444 | 518 |
445 return true; | 519 return true; |
446 } | 520 } |
447 | 521 |
448 void WebUILoginView::RequestMediaAccessPermission( | 522 void WebUILoginView::RequestMediaAccessPermission( |
449 WebContents* web_contents, | 523 WebContents* web_contents, |
450 const content::MediaStreamRequest& request, | 524 const content::MediaStreamRequest& request, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 TRACE_EVENT0("chromeos", "WebUILoginView::OnLoginPromoptVisible"); | 591 TRACE_EVENT0("chromeos", "WebUILoginView::OnLoginPromoptVisible"); |
518 if (should_emit_login_prompt_visible_) { | 592 if (should_emit_login_prompt_visible_) { |
519 VLOG(1) << "Login WebUI >> login-prompt-visible"; | 593 VLOG(1) << "Login WebUI >> login-prompt-visible"; |
520 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> | 594 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
521 EmitLoginPromptVisible(); | 595 EmitLoginPromptVisible(); |
522 } | 596 } |
523 | 597 |
524 webui_visible_ = true; | 598 webui_visible_ = true; |
525 } | 599 } |
526 | 600 |
| 601 ash::StatusAreaWidgetDelegate* WebUILoginView::GetStatusAreaWidgetDelegate() { |
| 602 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); |
| 603 return tray ? static_cast<ash::StatusAreaWidgetDelegate*>( |
| 604 tray->GetWidget()->GetContentsView()) |
| 605 : nullptr; |
| 606 } |
| 607 |
527 } // namespace chromeos | 608 } // namespace chromeos |
OLD | NEW |