| 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/captive_portal_window_proxy.h" | 5 #include "chrome/browser/chromeos/login/ui/captive_portal_window_proxy.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/login/ui/captive_portal_view.h" | 7 #include "chrome/browser/chromeos/login/ui/captive_portal_view.h" |
| 8 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h" | 8 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h" |
| 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 10 #include "components/web_modal/popup_manager.h" | 10 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 11 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 12 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 11 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | |
| 15 // The captive portal dialog is system-modal, but uses the web-content-modal | 16 // The captive portal dialog is system-modal, but uses the web-content-modal |
| 16 // dialog manager (odd) and requires this atypical dialog widget initialization. | 17 // dialog manager (odd) and requires this atypical dialog widget initialization. |
| 17 views::Widget* CreateWindowAsFramelessChild(views::WidgetDelegate* delegate, | 18 views::Widget* CreateWindowAsFramelessChild(views::WidgetDelegate* delegate, |
| 18 gfx::NativeView parent) { | 19 gfx::NativeView parent) { |
| 19 views::Widget* widget = new views::Widget; | 20 views::Widget* widget = new views::Widget; |
| 20 | 21 |
| 21 views::Widget::InitParams params; | 22 views::Widget::InitParams params; |
| 22 params.delegate = delegate; | 23 params.delegate = delegate; |
| 23 params.child = true; | 24 params.child = true; |
| 24 params.parent = parent; | 25 params.parent = parent; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 Close(); | 65 Close(); |
| 65 return; | 66 return; |
| 66 } | 67 } |
| 67 | 68 |
| 68 if (GetState() == STATE_DISPLAYED) // Dialog is already shown, do nothing. | 69 if (GetState() == STATE_DISPLAYED) // Dialog is already shown, do nothing. |
| 69 return; | 70 return; |
| 70 | 71 |
| 71 InitCaptivePortalView(); | 72 InitCaptivePortalView(); |
| 72 | 73 |
| 73 CaptivePortalView* portal = captive_portal_view_.release(); | 74 CaptivePortalView* portal = captive_portal_view_.release(); |
| 74 web_modal::PopupManager* popup_manager = | 75 web_modal::WebContentsModalDialogManager* manager = |
| 75 web_modal::PopupManager::FromWebContents(web_contents_); | 76 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 76 if (popup_manager) { | 77 const gfx::NativeWindow parent = |
| 77 widget_ = | 78 manager->delegate()->GetWebContentsModalDialogHost()->GetHostView(); |
| 78 CreateWindowAsFramelessChild(portal, popup_manager->GetHostView()); | 79 widget_ = CreateWindowAsFramelessChild(portal, parent); |
| 79 portal->Init(); | 80 portal->Init(); |
| 80 widget_->AddObserver(this); | 81 |
| 81 popup_manager->ShowModalDialog(widget_->GetNativeView(), web_contents_); | 82 widget_->AddObserver(this); |
| 82 } | 83 manager->ShowModalDialog(widget_->GetNativeView()); |
| 84 DCHECK(GetState() == STATE_DISPLAYED); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void CaptivePortalWindowProxy::Close() { | 87 void CaptivePortalWindowProxy::Close() { |
| 86 if (GetState() == STATE_DISPLAYED) | 88 if (GetState() == STATE_DISPLAYED) |
| 87 widget_->Close(); | 89 widget_->Close(); |
| 88 captive_portal_view_.reset(); | 90 captive_portal_view_.reset(); |
| 89 captive_portal_view_for_testing_ = NULL; | 91 captive_portal_view_for_testing_ = NULL; |
| 90 } | 92 } |
| 91 | 93 |
| 92 void CaptivePortalWindowProxy::OnRedirected() { | 94 void CaptivePortalWindowProxy::OnRedirected() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 145 } |
| 144 | 146 |
| 145 void CaptivePortalWindowProxy::DetachFromWidget(views::Widget* widget) { | 147 void CaptivePortalWindowProxy::DetachFromWidget(views::Widget* widget) { |
| 146 if (!widget_ || widget_ != widget) | 148 if (!widget_ || widget_ != widget) |
| 147 return; | 149 return; |
| 148 widget_->RemoveObserver(this); | 150 widget_->RemoveObserver(this); |
| 149 widget_ = NULL; | 151 widget_ = NULL; |
| 150 } | 152 } |
| 151 | 153 |
| 152 } // namespace chromeos | 154 } // namespace chromeos |
| OLD | NEW |