OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/captive_portal_window_proxy.h" | 5 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/login/captive_portal_view.h" | 7 #include "chrome/browser/chromeos/login/captive_portal_view.h" |
8 #include "chrome/browser/chromeos/login/helper.h" | 8 #include "chrome/browser/chromeos/login/helper.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 } | 24 } |
25 | 25 |
26 CaptivePortalWindowProxy::~CaptivePortalWindowProxy() { | 26 CaptivePortalWindowProxy::~CaptivePortalWindowProxy() { |
27 if (widget_) { | 27 if (widget_) { |
28 widget_->RemoveObserver(this); | 28 widget_->RemoveObserver(this); |
29 widget_->Close(); | 29 widget_->Close(); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 void CaptivePortalWindowProxy::ShowIfRedirected() { | 33 void CaptivePortalWindowProxy::ShowIfRedirected() { |
| 34 // Dialog is already shown, no need to reload. |
| 35 if (widget_ && !captive_portal_view_.get()) |
| 36 return; |
| 37 |
| 38 // Dialog is not initialized yet. |
| 39 // Create view. |
34 if (!widget_ && !captive_portal_view_.get()) { | 40 if (!widget_ && !captive_portal_view_.get()) { |
35 captive_portal_view_.reset( | 41 captive_portal_view_.reset( |
36 new CaptivePortalView(ProfileManager::GetDefaultProfile(), this)); | 42 new CaptivePortalView(ProfileManager::GetDefaultProfile(), this)); |
37 captive_portal_view_->StartLoad(); | |
38 } | 43 } |
| 44 |
| 45 // Dialog has been already initialized (this call or previously), |
| 46 // force reload. |
| 47 captive_portal_view_->StartLoad(); |
39 } | 48 } |
40 | 49 |
41 void CaptivePortalWindowProxy::Close() { | 50 void CaptivePortalWindowProxy::Show() { |
42 if (widget_) { | |
43 widget_->Close(); | |
44 } else { | |
45 captive_portal_view_.reset(); | |
46 } | |
47 } | |
48 | |
49 void CaptivePortalWindowProxy::OnRedirected() { | |
50 if (!captive_portal_view_.get() || widget_) { | 51 if (!captive_portal_view_.get() || widget_) { |
51 NOTREACHED(); | 52 // Dialog already shown, do nothing. |
52 return; | 53 return; |
53 } | 54 } |
54 CaptivePortalView* captive_portal_view = captive_portal_view_.release(); | 55 CaptivePortalView* captive_portal_view = captive_portal_view_.release(); |
55 widget_ = views::Widget::CreateWindowWithParent( | 56 widget_ = views::Widget::CreateWindowWithParent( |
56 captive_portal_view, | 57 captive_portal_view, |
57 parent_); | 58 parent_); |
58 captive_portal_view->Init(); | 59 captive_portal_view->Init(); |
59 | 60 |
60 gfx::Rect bounds(CalculateScreenBounds(gfx::Size())); | 61 gfx::Rect bounds(CalculateScreenBounds(gfx::Size())); |
61 bounds.Inset(kMargin, kMargin); | 62 bounds.Inset(kMargin, kMargin); |
62 widget_->SetBounds(bounds); | 63 widget_->SetBounds(bounds); |
63 | 64 |
64 widget_->AddObserver(this); | 65 widget_->AddObserver(this); |
65 widget_->Show(); | 66 widget_->Show(); |
| 67 } |
| 68 |
| 69 void CaptivePortalWindowProxy::Close() { |
| 70 if (widget_) { |
| 71 widget_->Close(); |
| 72 } else { |
| 73 captive_portal_view_.reset(); |
| 74 } |
| 75 } |
| 76 |
| 77 void CaptivePortalWindowProxy::OnRedirected() { |
| 78 Show(); |
66 delegate_->OnPortalDetected(); | 79 delegate_->OnPortalDetected(); |
67 } | 80 } |
68 | 81 |
69 void CaptivePortalWindowProxy::OnOriginalURLLoaded() { | 82 void CaptivePortalWindowProxy::OnOriginalURLLoaded() { |
70 Close(); | 83 Close(); |
71 } | 84 } |
72 | 85 |
73 void CaptivePortalWindowProxy::OnWidgetClosing(views::Widget* widget) { | 86 void CaptivePortalWindowProxy::OnWidgetClosing(views::Widget* widget) { |
74 DCHECK(widget == widget_); | 87 DCHECK(widget == widget_); |
75 DCHECK(captive_portal_view_.get() == NULL); | 88 DCHECK(captive_portal_view_.get() == NULL); |
76 widget->RemoveObserver(this); | 89 widget->RemoveObserver(this); |
77 widget_ = NULL; | 90 widget_ = NULL; |
78 } | 91 } |
79 | 92 |
80 } // namespace chromeos | 93 } // namespace chromeos |
OLD | NEW |