| 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 { |
| 119 return &cycle_focus_search_; |
| 120 } |
| 121 |
| 122 views::FocusTraversable* GetFocusTraversableParent() override { |
| 123 return nullptr; |
| 124 } |
| 125 |
| 126 views::View* GetFocusTraversableParentView() override { |
| 127 return nullptr; |
| 128 } |
| 129 |
| 130 private: |
| 131 views::FocusSearch cycle_focus_search_; |
| 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(CycleFocusTraversable); |
| 134 }; |
| 135 |
| 136 // WebUILoginView::StatusAreaFocusTraversable ---------------------------------- |
| 137 class WebUILoginView::StatusAreaFocusTraversable |
| 138 : public views::FocusTraversable { |
| 139 public: |
| 140 StatusAreaFocusTraversable( |
| 141 ash::StatusAreaWidgetDelegate* status_area_widget_delgate, |
| 142 WebUILoginView* webui_login_view) |
| 143 : webui_login_view_(webui_login_view), |
| 144 status_area_focus_search_(status_area_widget_delgate, false, false) {} |
| 145 ~StatusAreaFocusTraversable() override {} |
| 146 |
| 147 // views::FocusTraversable |
| 148 views::FocusSearch* GetFocusSearch() override { |
| 149 return &status_area_focus_search_; |
| 150 } |
| 151 |
| 152 views::FocusTraversable* GetFocusTraversableParent() override { |
| 153 return webui_login_view_->cycle_focus_traversable_.get(); |
| 154 } |
| 155 |
| 156 views::View* GetFocusTraversableParentView() override { |
| 157 return webui_login_view_->status_area_widget_host_; |
| 158 } |
| 159 |
| 160 private: |
| 161 WebUILoginView* const webui_login_view_; |
| 162 views::FocusSearch status_area_focus_search_; |
| 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(StatusAreaFocusTraversable); |
| 165 }; |
| 166 |
| 107 // WebUILoginView public: ------------------------------------------------------ | 167 // WebUILoginView public: ------------------------------------------------------ |
| 108 | 168 |
| 109 WebUILoginView::WebUILoginView() | 169 WebUILoginView::WebUILoginView() |
| 110 : webui_login_(NULL), | 170 : webui_login_(NULL), |
| 111 is_hidden_(false), | 171 is_hidden_(false), |
| 112 webui_visible_(false), | 172 webui_visible_(false), |
| 113 should_emit_login_prompt_visible_(true), | 173 should_emit_login_prompt_visible_(true), |
| 114 forward_keyboard_event_(true) { | 174 forward_keyboard_event_(true) { |
| 115 registrar_.Add(this, | 175 registrar_.Add(this, |
| 116 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 176 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 AddAccelerator(i->first); | 222 AddAccelerator(i->first); |
| 163 } | 223 } |
| 164 | 224 |
| 165 WebUILoginView::~WebUILoginView() { | 225 WebUILoginView::~WebUILoginView() { |
| 166 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | 226 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, |
| 167 observer_list_, | 227 observer_list_, |
| 168 OnHostDestroying()); | 228 OnHostDestroying()); |
| 169 | 229 |
| 170 if (!chrome::IsRunningInMash() && | 230 if (!chrome::IsRunningInMash() && |
| 171 ash::Shell::GetInstance()->HasPrimaryStatusArea()) { | 231 ash::Shell::GetInstance()->HasPrimaryStatusArea()) { |
| 172 ash::Shell::GetInstance()->GetPrimarySystemTray()-> | 232 views::Widget* tray_widget = |
| 173 SetNextFocusableView(NULL); | 233 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget(); |
| 234 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = |
| 235 static_cast<ash::StatusAreaWidgetDelegate*>( |
| 236 tray_widget->GetContentsView()); |
| 237 status_area_widget_delegate->set_custom_focus_traversable(nullptr); |
| 174 } else { | 238 } else { |
| 175 NOTIMPLEMENTED(); | 239 NOTIMPLEMENTED(); |
| 176 } | 240 } |
| 177 } | 241 } |
| 178 | 242 |
| 179 void WebUILoginView::Init() { | 243 void WebUILoginView::Init() { |
| 180 Profile* signin_profile = ProfileHelper::GetSigninProfile(); | 244 Profile* signin_profile = ProfileHelper::GetSigninProfile(); |
| 181 webui_login_ = new views::WebView(signin_profile); | 245 webui_login_ = new views::WebView(signin_profile); |
| 182 webui_login_->set_allow_accelerators(true); | 246 webui_login_->set_allow_accelerators(true); |
| 183 AddChildView(webui_login_); | 247 AddChildView(webui_login_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 199 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 263 WebContentsModalDialogManager::FromWebContents(web_contents)-> |
| 200 SetDelegate(this); | 264 SetDelegate(this); |
| 201 | 265 |
| 202 web_contents->SetDelegate(this); | 266 web_contents->SetDelegate(this); |
| 203 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT); | 267 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT); |
| 204 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 268 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| 205 web_contents); | 269 web_contents); |
| 206 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); | 270 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); |
| 207 renderer_preferences_util::UpdateFromSystemSettings( | 271 renderer_preferences_util::UpdateFromSystemSettings( |
| 208 prefs, signin_profile, web_contents); | 272 prefs, signin_profile, web_contents); |
| 273 |
| 274 status_area_widget_host_ = new views::View; |
| 275 AddChildView(status_area_widget_host_); |
| 209 } | 276 } |
| 210 | 277 |
| 211 const char* WebUILoginView::GetClassName() const { | 278 const char* WebUILoginView::GetClassName() const { |
| 212 return kViewClassName; | 279 return kViewClassName; |
| 213 } | 280 } |
| 214 | 281 |
| 215 void WebUILoginView::RequestFocus() { | 282 void WebUILoginView::RequestFocus() { |
| 216 webui_login_->RequestFocus(); | 283 webui_login_->RequestFocus(); |
| 217 } | 284 } |
| 218 | 285 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 webui_login_->LoadInitialURL(url); | 341 webui_login_->LoadInitialURL(url); |
| 275 webui_login_->RequestFocus(); | 342 webui_login_->RequestFocus(); |
| 276 | 343 |
| 277 // TODO(nkostylev): Use WebContentsObserver::RenderViewCreated to track | 344 // TODO(nkostylev): Use WebContentsObserver::RenderViewCreated to track |
| 278 // when RenderView is created. | 345 // when RenderView is created. |
| 279 GetWebContents() | 346 GetWebContents() |
| 280 ->GetRenderViewHost() | 347 ->GetRenderViewHost() |
| 281 ->GetWidget() | 348 ->GetWidget() |
| 282 ->GetView() | 349 ->GetView() |
| 283 ->SetBackgroundColor(SK_ColorTRANSPARENT); | 350 ->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 351 |
| 352 views::Widget* tray_widget = |
| 353 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget(); |
| 354 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = |
| 355 static_cast<ash::StatusAreaWidgetDelegate*>( |
| 356 tray_widget->GetContentsView()); |
| 357 cycle_focus_traversable_.reset(new CycleFocusTraversable(this)); |
| 358 status_area_focus_traversable_.reset( |
| 359 new StatusAreaFocusTraversable(status_area_widget_delegate, this)); |
| 360 status_area_widget_delegate->set_custom_focus_traversable( |
| 361 status_area_focus_traversable_.get()); |
| 284 } | 362 } |
| 285 | 363 |
| 286 content::WebUI* WebUILoginView::GetWebUI() { | 364 content::WebUI* WebUILoginView::GetWebUI() { |
| 287 return webui_login_->web_contents()->GetWebUI(); | 365 return webui_login_->web_contents()->GetWebUI(); |
| 288 } | 366 } |
| 289 | 367 |
| 290 content::WebContents* WebUILoginView::GetWebContents() { | 368 content::WebContents* WebUILoginView::GetWebContents() { |
| 291 return webui_login_->web_contents(); | 369 return webui_login_->web_contents(); |
| 292 } | 370 } |
| 293 | 371 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 if (!forward_keyboard_event_) | 508 if (!forward_keyboard_event_) |
| 431 return false; | 509 return false; |
| 432 | 510 |
| 433 // Focus is accepted, but the Ash system tray is not available in Mash, so | 511 // Focus is accepted, but the Ash system tray is not available in Mash, so |
| 434 // exit early. | 512 // exit early. |
| 435 if (chrome::IsRunningInMash()) | 513 if (chrome::IsRunningInMash()) |
| 436 return true; | 514 return true; |
| 437 | 515 |
| 438 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | 516 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); |
| 439 if (tray && tray->GetWidget()->IsVisible()) { | 517 if (tray && tray->GetWidget()->IsVisible()) { |
| 440 tray->SetNextFocusableView(this); | |
| 441 ash::WmShell::Get()->focus_cycler()->RotateFocus( | 518 ash::WmShell::Get()->focus_cycler()->RotateFocus( |
| 442 reverse ? ash::FocusCycler::BACKWARD : ash::FocusCycler::FORWARD); | 519 reverse ? ash::FocusCycler::BACKWARD : ash::FocusCycler::FORWARD); |
| 443 } | 520 } |
| 444 | 521 |
| 445 return true; | 522 return true; |
| 446 } | 523 } |
| 447 | 524 |
| 448 void WebUILoginView::RequestMediaAccessPermission( | 525 void WebUILoginView::RequestMediaAccessPermission( |
| 449 WebContents* web_contents, | 526 WebContents* web_contents, |
| 450 const content::MediaStreamRequest& request, | 527 const content::MediaStreamRequest& request, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 if (should_emit_login_prompt_visible_) { | 595 if (should_emit_login_prompt_visible_) { |
| 519 VLOG(1) << "Login WebUI >> login-prompt-visible"; | 596 VLOG(1) << "Login WebUI >> login-prompt-visible"; |
| 520 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> | 597 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 521 EmitLoginPromptVisible(); | 598 EmitLoginPromptVisible(); |
| 522 } | 599 } |
| 523 | 600 |
| 524 webui_visible_ = true; | 601 webui_visible_ = true; |
| 525 } | 602 } |
| 526 | 603 |
| 527 } // namespace chromeos | 604 } // namespace chromeos |
| OLD | NEW |