Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: chrome/browser/chromeos/login/captive_portal_window_proxy.cc

Issue 15780006: Added bowser test for Captive Portal Window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/login/captive_portal_window_proxy.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/chromeos/login/proxy_settings_dialog.h" 9 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h"
10 #include "chrome/browser/chromeos/profiles/profile_helper.h" 10 #include "chrome/browser/chromeos/profiles/profile_helper.h"
11 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
12 12
13 namespace { 13 namespace {
14 14
15 int kMargin = 50; 15 int kMargin = 50;
16 16
17 } // namespace 17 } // namespace
18 18
19 namespace chromeos { 19 namespace chromeos {
20 20
21 CaptivePortalWindowProxy::CaptivePortalWindowProxy(Delegate* delegate, 21 CaptivePortalWindowProxy::CaptivePortalWindowProxy(Delegate* delegate,
22 gfx::NativeWindow parent) 22 gfx::NativeWindow parent)
23 : delegate_(delegate), 23 : delegate_(delegate),
24 widget_(NULL), 24 widget_(NULL),
25 parent_(parent) { 25 parent_(parent) {
26 DCHECK(GetState() == STATE_IDLE);
26 } 27 }
27 28
28 CaptivePortalWindowProxy::~CaptivePortalWindowProxy() { 29 CaptivePortalWindowProxy::~CaptivePortalWindowProxy() {
29 if (widget_) { 30 if (!widget_)
30 widget_->RemoveObserver(this); 31 return;
31 widget_->Close(); 32 DCHECK(GetState() == STATE_DISPLAYED);
32 } 33 widget_->RemoveObserver(this);
34 widget_->Close();
33 } 35 }
34 36
35 void CaptivePortalWindowProxy::ShowIfRedirected() { 37 void CaptivePortalWindowProxy::ShowIfRedirected() {
36 if (widget_) { 38 if (GetState() != STATE_IDLE)
37 // Invalid state as when widget is created (Show())
38 // CaptivePortalView ownership is transferred to it.
39 if (captive_portal_view_.get()) {
40 NOTREACHED();
41 }
42 // Dialog is already shown, no need to reload.
43 return; 39 return;
44 } 40 InitCaptivePortalView();
45 41 DCHECK(GetState() == STATE_WAITING_FOR_REDIRECTION);
46 // Dialog is not initialized yet.
47 if (!captive_portal_view_.get()) {
48 captive_portal_view_.reset(
49 new CaptivePortalView(ProfileHelper::GetSigninProfile(), this));
50 }
51
52 // If dialog has been created (but not shown) previously, force reload.
53 captive_portal_view_->StartLoad();
54 } 42 }
55 43
56 void CaptivePortalWindowProxy::Show() { 44 void CaptivePortalWindowProxy::Show() {
57 if (ProxySettingsDialog::IsShown()) { 45 if (ProxySettingsDialog::IsShown()) {
58 // ProxySettingsDialog is being shown, don't cover it. 46 // ProxySettingsDialog is being shown, don't cover it.
59 Close(); 47 Close();
60 return; 48 return;
61 } 49 }
62 50
63 if (!captive_portal_view_.get() || widget_) { 51 if (GetState() == STATE_DISPLAYED) // Dialog is already shown, do nothing.
64 // Dialog is already shown, do nothing.
65 return; 52 return;
66 } 53
54 InitCaptivePortalView();
67 55
68 CaptivePortalView* captive_portal_view = captive_portal_view_.release(); 56 CaptivePortalView* captive_portal_view = captive_portal_view_.release();
69 widget_ = views::Widget::CreateWindowWithParent( 57 widget_ = views::Widget::CreateWindowWithParent(
70 captive_portal_view, 58 captive_portal_view,
71 parent_); 59 parent_);
72 captive_portal_view->Init(); 60 captive_portal_view->Init();
73 61
74 gfx::Rect bounds(CalculateScreenBounds(gfx::Size())); 62 gfx::Rect bounds(CalculateScreenBounds(gfx::Size()));
75 bounds.Inset(kMargin, kMargin); 63 bounds.Inset(kMargin, kMargin);
76 widget_->SetBounds(bounds); 64 widget_->SetBounds(bounds);
77 65
78 widget_->AddObserver(this); 66 widget_->AddObserver(this);
79 widget_->Show(); 67 widget_->Show();
68 DCHECK(GetState() == STATE_DISPLAYED);
80 } 69 }
81 70
82 void CaptivePortalWindowProxy::Close() { 71 void CaptivePortalWindowProxy::Close() {
83 if (widget_) { 72 if (GetState() == STATE_DISPLAYED)
84 widget_->Close(); 73 widget_->Close();
85 } else { 74 captive_portal_view_.reset();
86 captive_portal_view_.reset();
87 }
88 } 75 }
89 76
90 void CaptivePortalWindowProxy::OnRedirected() { 77 void CaptivePortalWindowProxy::OnRedirected() {
91 Show(); 78 if (GetState() == STATE_WAITING_FOR_REDIRECTION)
79 Show();
92 delegate_->OnPortalDetected(); 80 delegate_->OnPortalDetected();
93 } 81 }
94 82
95 void CaptivePortalWindowProxy::OnOriginalURLLoaded() { 83 void CaptivePortalWindowProxy::OnOriginalURLLoaded() {
96 Close(); 84 Close();
97 } 85 }
98 86
99 void CaptivePortalWindowProxy::OnWidgetDestroying(views::Widget* widget) { 87 void CaptivePortalWindowProxy::OnWidgetClosing(views::Widget* widget) {
88 DCHECK(GetState() == STATE_DISPLAYED);
100 DCHECK(widget == widget_); 89 DCHECK(widget == widget_);
101 DCHECK(captive_portal_view_.get() == NULL); 90
102 widget->RemoveObserver(this); 91 widget->RemoveObserver(this);
103 widget_ = NULL; 92 widget_ = NULL;
93
94 DCHECK(GetState() == STATE_IDLE);
95 }
96
97 void CaptivePortalWindowProxy::InitCaptivePortalView() {
98 DCHECK(GetState() == STATE_IDLE ||
99 GetState() == STATE_WAITING_FOR_REDIRECTION);
100 if (!captive_portal_view_.get()) {
101 captive_portal_view_.reset(
102 new CaptivePortalView(ProfileHelper::GetSigninProfile(), this));
103 }
104 captive_portal_view_->StartLoad();
105 }
106
107 CaptivePortalWindowProxy::State CaptivePortalWindowProxy::GetState() const {
108 if (widget_ == NULL) {
109 if (captive_portal_view_.get() == NULL)
110 return STATE_IDLE;
111 else
112 return STATE_WAITING_FOR_REDIRECTION;
113 } else {
114 if (captive_portal_view_.get() == NULL)
115 return STATE_DISPLAYED;
116 else
117 NOTREACHED();
118 }
119 return STATE_UNKNOWN;
104 } 120 }
105 121
106 } // namespace chromeos 122 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/captive_portal_window_proxy.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698