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