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

Side by Side Diff: chrome/browser/chromeos/net/network_portal_notification_controller.cc

Issue 750153002: ChromeOS: bypass proxy for captive portal authorization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore comment. Created 6 years 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
OLDNEW
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/net/network_portal_notification_controller.h" 5 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/system_notifier.h" 8 #include "ash/system/system_notifier.h"
9 #include "ash/system/tray/system_tray_notifier.h" 9 #include "ash/system/tray/system_tray_notifier.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/chromeos/mobile/mobile_activator.h" 18 #include "chrome/browser/chromeos/mobile/mobile_activator.h"
19 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h"
20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/ui/browser_dialogs.h"
20 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 23 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
21 #include "chrome/browser/ui/singleton_tabs.h" 24 #include "chrome/browser/ui/singleton_tabs.h"
22 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
23 #include "chrome/grit/theme_resources.h" 26 #include "chrome/grit/theme_resources.h"
24 #include "chromeos/chromeos_switches.h" 27 #include "chromeos/chromeos_switches.h"
25 #include "chromeos/network/network_state.h" 28 #include "chromeos/network/network_state.h"
26 #include "components/captive_portal/captive_portal_detector.h" 29 #include "components/captive_portal/captive_portal_detector.h"
27 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/message_center/message_center.h" 32 #include "ui/message_center/message_center.h"
30 #include "ui/message_center/notification.h" 33 #include "ui/message_center/notification.h"
31 #include "ui/message_center/notification_types.h" 34 #include "ui/message_center/notification_types.h"
32 #include "ui/message_center/notifier_settings.h" 35 #include "ui/message_center/notifier_settings.h"
36 #include "ui/views/widget/widget.h"
33 37
34 using message_center::Notification; 38 using message_center::Notification;
35 39
36 namespace chromeos { 40 namespace chromeos {
37 41
38 namespace { 42 namespace {
39 43
40 bool IsPortalNotificationEnabled() { 44 bool IsPortalNotificationEnabled() {
41 return !CommandLine::ForCurrentProcess()->HasSwitch( 45 return !CommandLine::ForCurrentProcess()->HasSwitch(
42 switches::kDisableNetworkPortalNotification); 46 switches::kDisableNetworkPortalNotification);
43 } 47 }
44 48
45 49
46 void CloseNotification() { 50 void CloseNotification() {
47 message_center::MessageCenter::Get()->RemoveNotification( 51 message_center::MessageCenter::Get()->RemoveNotification(
48 NetworkPortalNotificationController::kNotificationId, false); 52 NetworkPortalNotificationController::kNotificationId, false);
49 } 53 }
50 54
51 class NetworkPortalNotificationControllerDelegate 55 class NetworkPortalNotificationControllerDelegate
52 : public message_center::NotificationDelegate { 56 : public message_center::NotificationDelegate {
53 public: 57 public:
54 NetworkPortalNotificationControllerDelegate(): clicked_(false) {} 58 explicit NetworkPortalNotificationControllerDelegate(
59 base::WeakPtr<NetworkPortalNotificationController> controller)
60 : clicked_(false), controller_(controller) {}
55 61
56 // Overridden from message_center::NotificationDelegate: 62 // Overridden from message_center::NotificationDelegate:
57 virtual void Display() override; 63 virtual void Display() override;
58 virtual void Close(bool by_user) override; 64 virtual void Close(bool by_user) override;
59 virtual void Click() override; 65 virtual void Click() override;
60 66
61 private: 67 private:
62 virtual ~NetworkPortalNotificationControllerDelegate() {} 68 virtual ~NetworkPortalNotificationControllerDelegate() {}
63 69
64 bool clicked_; 70 bool clicked_;
65 71
72 base::WeakPtr<NetworkPortalNotificationController> controller_;
73
66 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationControllerDelegate); 74 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationControllerDelegate);
67 }; 75 };
68 76
69 void NetworkPortalNotificationControllerDelegate::Display() { 77 void NetworkPortalNotificationControllerDelegate::Display() {
70 UMA_HISTOGRAM_ENUMERATION( 78 UMA_HISTOGRAM_ENUMERATION(
71 NetworkPortalNotificationController::kNotificationMetric, 79 NetworkPortalNotificationController::kNotificationMetric,
72 NetworkPortalNotificationController::NOTIFICATION_METRIC_DISPLAYED, 80 NetworkPortalNotificationController::NOTIFICATION_METRIC_DISPLAYED,
73 NetworkPortalNotificationController::NOTIFICATION_METRIC_COUNT); 81 NetworkPortalNotificationController::NOTIFICATION_METRIC_COUNT);
74 } 82 }
75 83
(...skipping 10 matching lines...) Expand all
86 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); 94 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT);
87 } 95 }
88 96
89 void NetworkPortalNotificationControllerDelegate::Click() { 97 void NetworkPortalNotificationControllerDelegate::Click() {
90 clicked_ = true; 98 clicked_ = true;
91 UMA_HISTOGRAM_ENUMERATION( 99 UMA_HISTOGRAM_ENUMERATION(
92 NetworkPortalNotificationController::kUserActionMetric, 100 NetworkPortalNotificationController::kUserActionMetric,
93 NetworkPortalNotificationController::USER_ACTION_METRIC_CLICKED, 101 NetworkPortalNotificationController::USER_ACTION_METRIC_CLICKED,
94 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); 102 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT);
95 103
104 if (CommandLine::ForCurrentProcess()->HasSwitch(
105 chromeos::switches::kEnableCaptivePortalBypassProxy)) {
106 if (controller_)
107 controller_->ShowDialog();
108
109 CloseNotification();
110 return;
111 }
112
96 Profile* profile = ProfileManager::GetActiveUserProfile(); 113 Profile* profile = ProfileManager::GetActiveUserProfile();
97 if (!profile) 114 if (!profile)
98 return; 115 return;
116
99 chrome::ScopedTabbedBrowserDisplayer displayer(profile, 117 chrome::ScopedTabbedBrowserDisplayer displayer(profile,
100 chrome::HOST_DESKTOP_TYPE_ASH); 118 chrome::HOST_DESKTOP_TYPE_ASH);
101 GURL url(captive_portal::CaptivePortalDetector::kDefaultURL); 119 GURL url(captive_portal::CaptivePortalDetector::kDefaultURL);
102 chrome::ShowSingletonTab(displayer.browser(), url); 120 chrome::ShowSingletonTab(displayer.browser(), url);
103
104 CloseNotification();
105 } 121 }
106 122
107 } // namespace 123 } // namespace
108 124
109 // static 125 // static
110 const char NetworkPortalNotificationController::kNotificationId[] = 126 const char NetworkPortalNotificationController::kNotificationId[] =
111 "chrome://net/network_portal_detector"; 127 "chrome://net/network_portal_detector";
112 128
113 // static 129 // static
114 const char NetworkPortalNotificationController::kNotificationMetric[] = 130 const char NetworkPortalNotificationController::kNotificationMetric[] =
115 "CaptivePortal.Notification.Status"; 131 "CaptivePortal.Notification.Status";
116 132
117 // static 133 // static
118 const char NetworkPortalNotificationController::kUserActionMetric[] = 134 const char NetworkPortalNotificationController::kUserActionMetric[] =
119 "CaptivePortal.Notification.UserAction"; 135 "CaptivePortal.Notification.UserAction";
120 136
121 NetworkPortalNotificationController::NetworkPortalNotificationController() {} 137 NetworkPortalNotificationController::NetworkPortalNotificationController()
138 : dialog_(nullptr) {
139 }
122 140
123 NetworkPortalNotificationController::~NetworkPortalNotificationController() {} 141 NetworkPortalNotificationController::~NetworkPortalNotificationController() {}
124 142
125 void NetworkPortalNotificationController::OnPortalDetectionCompleted( 143 void NetworkPortalNotificationController::OnPortalDetectionCompleted(
126 const NetworkState* network, 144 const NetworkState* network,
127 const NetworkPortalDetector::CaptivePortalState& state) { 145 const NetworkPortalDetector::CaptivePortalState& state) {
128 if (!IsPortalNotificationEnabled()) 146 if (!IsPortalNotificationEnabled())
129 return; 147 return;
130 148
131 if (!network || 149 if (!network ||
132 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) { 150 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) {
133 last_network_path_.clear(); 151 last_network_path_.clear();
152
153 if (dialog_)
154 dialog_->Close();
155
134 CloseNotification(); 156 CloseNotification();
135 return; 157 return;
136 } 158 }
137 159
138 // Don't do anything if we're currently activating the device. 160 // Don't do anything if we're currently activating the device.
139 if (MobileActivator::GetInstance()->RunningActivation()) 161 if (MobileActivator::GetInstance()->RunningActivation())
140 return; 162 return;
141 163
142 // Don't do anything if notification for |network| already was 164 // Don't do anything if notification for |network| already was
143 // displayed. 165 // displayed.
144 if (network->path() == last_network_path_) 166 if (network->path() == last_network_path_)
145 return; 167 return;
146 last_network_path_ = network->path(); 168 last_network_path_ = network->path();
147 169
148 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 170 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
149 gfx::Image& icon = bundle.GetImageNamed(IDR_PORTAL_DETECTION_ALERT); 171 gfx::Image& icon = bundle.GetImageNamed(IDR_PORTAL_DETECTION_ALERT);
150 message_center::NotifierId notifier_id( 172 message_center::NotifierId notifier_id(
151 message_center::NotifierId::SYSTEM_COMPONENT, 173 message_center::NotifierId::SYSTEM_COMPONENT,
152 ash::system_notifier::kNotifierNetworkPortalDetector); 174 ash::system_notifier::kNotifierNetworkPortalDetector);
153 175
154 scoped_ptr<Notification> notification(new Notification( 176 scoped_ptr<Notification> notification(new Notification(
155 message_center::NOTIFICATION_TYPE_SIMPLE, 177 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId,
156 kNotificationId,
157 l10n_util::GetStringUTF16(IDS_PORTAL_DETECTION_NOTIFICATION_TITLE), 178 l10n_util::GetStringUTF16(IDS_PORTAL_DETECTION_NOTIFICATION_TITLE),
158 l10n_util::GetStringFUTF16(IDS_PORTAL_DETECTION_NOTIFICATION_MESSAGE, 179 l10n_util::GetStringFUTF16(IDS_PORTAL_DETECTION_NOTIFICATION_MESSAGE,
159 base::UTF8ToUTF16(network->name())), 180 base::UTF8ToUTF16(network->name())),
160 icon, 181 icon, base::string16() /* display_source */, notifier_id,
161 base::string16() /* display_source */,
162 notifier_id,
163 message_center::RichNotificationData(), 182 message_center::RichNotificationData(),
164 new NetworkPortalNotificationControllerDelegate())); 183 new NetworkPortalNotificationControllerDelegate(AsWeakPtr())));
165 notification->SetSystemPriority(); 184 notification->SetSystemPriority();
166 185
167 if (ash::Shell::HasInstance()) { 186 if (ash::Shell::HasInstance()) {
168 ash::Shell::GetInstance() 187 ash::Shell::GetInstance()
169 ->system_tray_notifier() 188 ->system_tray_notifier()
170 ->NotifyOnCaptivePortalDetected(network->path()); 189 ->NotifyOnCaptivePortalDetected(network->path());
171 } 190 }
172 191
173 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); 192 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
174 } 193 }
175 194
195 void NetworkPortalNotificationController::ShowDialog() {
196 if (dialog_)
197 return;
198
199 Profile* signin_profile = ProfileHelper::GetSigninProfile();
200 dialog_ = new NetworkPortalWebDialog(AsWeakPtr());
201 dialog_->SetWidget(views::Widget::GetWidgetForNativeWindow(
202 chrome::ShowWebDialog(NULL, signin_profile, dialog_)));
203 }
204
205 void NetworkPortalNotificationController::OnDialogDestroyed(
206 const NetworkPortalWebDialog* dialog) {
207 if (dialog == dialog_) {
208 dialog_ = NULL;
209 ProfileHelper::Get()->ClearSigninProfile(base::Closure());
210 }
211 }
212
176 } // namespace chromeos 213 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698