| 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 if (!widget_ && !captive_portal_view_.get()) { | 34 if (widget_) { |
| 35 // Invalid state as when widget is created (Show()) |
| 36 // CaptivePortalView ownership is transferred to it. |
| 37 if (captive_portal_view_.get()) { |
| 38 NOTREACHED(); |
| 39 } |
| 40 // Dialog is already shown, no need to reload. |
| 41 return; |
| 42 } |
| 43 |
| 44 // Dialog is not initialized yet. |
| 45 if (!captive_portal_view_.get()) { |
| 35 captive_portal_view_.reset( | 46 captive_portal_view_.reset( |
| 36 new CaptivePortalView(ProfileManager::GetDefaultProfile(), this)); | 47 new CaptivePortalView(ProfileManager::GetDefaultProfile(), this)); |
| 37 captive_portal_view_->StartLoad(); | |
| 38 } | 48 } |
| 49 |
| 50 // If dialog has been created (but not shown) previously, force reload. |
| 51 captive_portal_view_->StartLoad(); |
| 39 } | 52 } |
| 40 | 53 |
| 41 void CaptivePortalWindowProxy::Close() { | 54 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_) { | 55 if (!captive_portal_view_.get() || widget_) { |
| 51 NOTREACHED(); | 56 // Dialog is already shown, do nothing. |
| 52 return; | 57 return; |
| 53 } | 58 } |
| 54 CaptivePortalView* captive_portal_view = captive_portal_view_.release(); | 59 CaptivePortalView* captive_portal_view = captive_portal_view_.release(); |
| 55 widget_ = views::Widget::CreateWindowWithParent( | 60 widget_ = views::Widget::CreateWindowWithParent( |
| 56 captive_portal_view, | 61 captive_portal_view, |
| 57 parent_); | 62 parent_); |
| 58 captive_portal_view->Init(); | 63 captive_portal_view->Init(); |
| 59 | 64 |
| 60 gfx::Rect bounds(CalculateScreenBounds(gfx::Size())); | 65 gfx::Rect bounds(CalculateScreenBounds(gfx::Size())); |
| 61 bounds.Inset(kMargin, kMargin); | 66 bounds.Inset(kMargin, kMargin); |
| 62 widget_->SetBounds(bounds); | 67 widget_->SetBounds(bounds); |
| 63 | 68 |
| 64 widget_->AddObserver(this); | 69 widget_->AddObserver(this); |
| 65 widget_->Show(); | 70 widget_->Show(); |
| 71 } |
| 72 |
| 73 void CaptivePortalWindowProxy::Close() { |
| 74 if (widget_) { |
| 75 widget_->Close(); |
| 76 } else { |
| 77 captive_portal_view_.reset(); |
| 78 } |
| 79 } |
| 80 |
| 81 void CaptivePortalWindowProxy::OnRedirected() { |
| 82 Show(); |
| 66 delegate_->OnPortalDetected(); | 83 delegate_->OnPortalDetected(); |
| 67 } | 84 } |
| 68 | 85 |
| 69 void CaptivePortalWindowProxy::OnOriginalURLLoaded() { | 86 void CaptivePortalWindowProxy::OnOriginalURLLoaded() { |
| 70 Close(); | 87 Close(); |
| 71 } | 88 } |
| 72 | 89 |
| 73 void CaptivePortalWindowProxy::OnWidgetClosing(views::Widget* widget) { | 90 void CaptivePortalWindowProxy::OnWidgetClosing(views::Widget* widget) { |
| 74 DCHECK(widget == widget_); | 91 DCHECK(widget == widget_); |
| 75 DCHECK(captive_portal_view_.get() == NULL); | 92 DCHECK(captive_portal_view_.get() == NULL); |
| 76 widget->RemoveObserver(this); | 93 widget->RemoveObserver(this); |
| 77 widget_ = NULL; | 94 widget_ = NULL; |
| 78 } | 95 } |
| 79 | 96 |
| 80 } // namespace chromeos | 97 } // namespace chromeos |
| OLD | NEW |