Chromium Code Reviews| 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 views::Widget* tray_widget = | |
| 350 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget(); | |
| 351 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = | |
| 352 static_cast<ash::StatusAreaWidgetDelegate*>( | |
| 353 tray_widget->GetContentsView()); | |
|
xiyuan
2016/09/13 18:00:57
nit: Let's create a helper function to get this St
Qiang(Joe) Xu
2016/09/13 21:44:56
Done.
| |
| 354 cycle_focus_traversable_.reset(new CycleFocusTraversable(this)); | |
| 355 status_area_focus_traversable_.reset( | |
| 356 new StatusAreaFocusTraversable(status_area_widget_delegate, this)); | |
| 357 status_area_widget_delegate->set_custom_focus_traversable( | |
| 358 status_area_focus_traversable_.get()); | |
| 284 } | 359 } |
| 285 | 360 |
| 286 content::WebUI* WebUILoginView::GetWebUI() { | 361 content::WebUI* WebUILoginView::GetWebUI() { |
| 287 return webui_login_->web_contents()->GetWebUI(); | 362 return webui_login_->web_contents()->GetWebUI(); |
| 288 } | 363 } |
| 289 | 364 |
| 290 content::WebContents* WebUILoginView::GetWebContents() { | 365 content::WebContents* WebUILoginView::GetWebContents() { |
| 291 return webui_login_->web_contents(); | 366 return webui_login_->web_contents(); |
| 292 } | 367 } |
| 293 | 368 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 if (!forward_keyboard_event_) | 505 if (!forward_keyboard_event_) |
| 431 return false; | 506 return false; |
| 432 | 507 |
| 433 // Focus is accepted, but the Ash system tray is not available in Mash, so | 508 // Focus is accepted, but the Ash system tray is not available in Mash, so |
| 434 // exit early. | 509 // exit early. |
| 435 if (chrome::IsRunningInMash()) | 510 if (chrome::IsRunningInMash()) |
| 436 return true; | 511 return true; |
| 437 | 512 |
| 438 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | 513 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); |
| 439 if (tray && tray->GetWidget()->IsVisible()) { | 514 if (tray && tray->GetWidget()->IsVisible()) { |
| 440 tray->SetNextFocusableView(this); | 515 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = |
| 516 static_cast<ash::StatusAreaWidgetDelegate*>( | |
| 517 tray->GetWidget()->GetContentsView()); | |
| 518 status_area_widget_delegate->set_default_last_focusable_child(reverse); | |
| 441 ash::WmShell::Get()->focus_cycler()->RotateFocus( | 519 ash::WmShell::Get()->focus_cycler()->RotateFocus( |
| 442 reverse ? ash::FocusCycler::BACKWARD : ash::FocusCycler::FORWARD); | 520 reverse ? ash::FocusCycler::BACKWARD : ash::FocusCycler::FORWARD); |
| 443 } | 521 } |
| 444 | 522 |
| 445 return true; | 523 return true; |
| 446 } | 524 } |
| 447 | 525 |
| 448 void WebUILoginView::RequestMediaAccessPermission( | 526 void WebUILoginView::RequestMediaAccessPermission( |
| 449 WebContents* web_contents, | 527 WebContents* web_contents, |
| 450 const content::MediaStreamRequest& request, | 528 const content::MediaStreamRequest& request, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 if (should_emit_login_prompt_visible_) { | 596 if (should_emit_login_prompt_visible_) { |
| 519 VLOG(1) << "Login WebUI >> login-prompt-visible"; | 597 VLOG(1) << "Login WebUI >> login-prompt-visible"; |
| 520 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> | 598 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 521 EmitLoginPromptVisible(); | 599 EmitLoginPromptVisible(); |
| 522 } | 600 } |
| 523 | 601 |
| 524 webui_visible_ = true; | 602 webui_visible_ = true; |
| 525 } | 603 } |
| 526 | 604 |
| 527 } // namespace chromeos | 605 } // namespace chromeos |
| OLD | NEW |