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/net/network_portal_notification_controller.h" | 5 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/system/system_notifier.h" | 10 #include "ash/system/system_notifier.h" |
11 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/prefs/pref_service.h" |
19 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/browser_process_platform_part.h" |
23 #include "chrome/browser/chromeos/mobile/mobile_activator.h" | 25 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
24 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h" | 26 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h" |
25 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 27 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
26 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | 28 #include "chrome/browser/chromeos/policy/consumer_management_service.h" |
27 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 29 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
28 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
29 #include "chrome/browser/ui/browser_dialogs.h" | 31 #include "chrome/browser/ui/browser_dialogs.h" |
30 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 32 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
31 #include "chrome/browser/ui/singleton_tabs.h" | 33 #include "chrome/browser/ui/singleton_tabs.h" |
| 34 #include "chrome/common/pref_names.h" |
32 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
33 #include "chrome/grit/theme_resources.h" | 36 #include "chrome/grit/theme_resources.h" |
34 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
35 #include "chromeos/network/network_state.h" | 38 #include "chromeos/network/network_state.h" |
36 #include "chromeos/network/network_type_pattern.h" | 39 #include "chromeos/network/network_type_pattern.h" |
37 #include "components/captive_portal/captive_portal_detector.h" | 40 #include "components/captive_portal/captive_portal_detector.h" |
38 #include "components/user_manager/user_manager.h" | 41 #include "components/user_manager/user_manager.h" |
39 #include "extensions/browser/api/networking_config/networking_config_service.h" | 42 #include "extensions/browser/api/networking_config/networking_config_service.h" |
40 #include "extensions/browser/api/networking_config/networking_config_service_fac
tory.h" | 43 #include "extensions/browser/api/networking_config/networking_config_service_fac
tory.h" |
41 #include "third_party/cros_system_api/dbus/service_constants.h" | 44 #include "third_party/cros_system_api/dbus/service_constants.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); | 158 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); |
156 } | 159 } |
157 | 160 |
158 void NetworkPortalNotificationControllerDelegate::Click() { | 161 void NetworkPortalNotificationControllerDelegate::Click() { |
159 clicked_ = true; | 162 clicked_ = true; |
160 UMA_HISTOGRAM_ENUMERATION( | 163 UMA_HISTOGRAM_ENUMERATION( |
161 NetworkPortalNotificationController::kUserActionMetric, | 164 NetworkPortalNotificationController::kUserActionMetric, |
162 NetworkPortalNotificationController::USER_ACTION_METRIC_CLICKED, | 165 NetworkPortalNotificationController::USER_ACTION_METRIC_CLICKED, |
163 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); | 166 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); |
164 | 167 |
165 // ConsumerManagementService may not exist in tests. | 168 Profile* profile = ProfileManager::GetActiveUserProfile(); |
166 const policy::ConsumerManagementService* consumer_management_service = | |
167 g_browser_process->platform_part() | |
168 ->browser_policy_connector_chromeos() | |
169 ->GetConsumerManagementService(); | |
170 const bool enrolled = consumer_management_service && | |
171 consumer_management_service->GetStatus() == | |
172 policy::ConsumerManagementService::STATUS_ENROLLED; | |
173 | 169 |
174 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 170 const bool bypass_proxy_switch_present = |
175 chromeos::switches::kEnableCaptivePortalBypassProxy) && | 171 base::CommandLine::ForCurrentProcess()->HasSwitch( |
176 !enrolled) { | 172 chromeos::switches::kEnableCaptivePortalBypassProxyOption); |
| 173 const bool use_incognito_profile = |
| 174 bypass_proxy_switch_present |
| 175 ? (profile && |
| 176 profile->GetPrefs()->GetBoolean( |
| 177 prefs::kCaptivePortalAuthenticationIgnoresProxy)) |
| 178 : false; |
| 179 |
| 180 if (use_incognito_profile) { |
177 if (controller_) | 181 if (controller_) |
178 controller_->ShowDialog(); | 182 controller_->ShowDialog(); |
179 } else { | 183 } else { |
180 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
181 if (!profile) | 184 if (!profile) |
182 return; | 185 return; |
183 chrome::ScopedTabbedBrowserDisplayer displayer( | 186 chrome::ScopedTabbedBrowserDisplayer displayer( |
184 profile, chrome::HOST_DESKTOP_TYPE_ASH); | 187 profile, chrome::HOST_DESKTOP_TYPE_ASH); |
185 GURL url(captive_portal::CaptivePortalDetector::kDefaultURL); | 188 GURL url(captive_portal::CaptivePortalDetector::kDefaultURL); |
186 chrome::ShowSingletonTab(displayer.browser(), url); | 189 chrome::ShowSingletonTab(displayer.browser(), url); |
187 } | 190 } |
188 CloseNotification(); | 191 CloseNotification(); |
189 } | 192 } |
190 | 193 |
(...skipping 22 matching lines...) Expand all Loading... |
213 | 216 |
214 // static | 217 // static |
215 const char NetworkPortalNotificationController::kNotificationMetric[] = | 218 const char NetworkPortalNotificationController::kNotificationMetric[] = |
216 "CaptivePortal.Notification.Status"; | 219 "CaptivePortal.Notification.Status"; |
217 | 220 |
218 // static | 221 // static |
219 const char NetworkPortalNotificationController::kUserActionMetric[] = | 222 const char NetworkPortalNotificationController::kUserActionMetric[] = |
220 "CaptivePortal.Notification.UserAction"; | 223 "CaptivePortal.Notification.UserAction"; |
221 | 224 |
222 NetworkPortalNotificationController::NetworkPortalNotificationController() | 225 NetworkPortalNotificationController::NetworkPortalNotificationController() |
223 : dialog_(nullptr) { | 226 : dialog_(nullptr), ignore_no_network_for_testing_(false) { |
224 } | 227 } |
225 | 228 |
226 NetworkPortalNotificationController::~NetworkPortalNotificationController() { | 229 NetworkPortalNotificationController::~NetworkPortalNotificationController() { |
227 } | 230 } |
228 | 231 |
229 void NetworkPortalNotificationController::DefaultNetworkChanged( | 232 void NetworkPortalNotificationController::DefaultNetworkChanged( |
230 const NetworkState* network) { | 233 const NetworkState* network) { |
231 if (!network) | 234 if (!network) |
232 return; | 235 return; |
233 Profile* profile = GetProfileForPrimaryUser(); | 236 Profile* profile = GetProfileForPrimaryUser(); |
(...skipping 10 matching lines...) Expand all Loading... |
244 void NetworkPortalNotificationController::OnPortalDetectionCompleted( | 247 void NetworkPortalNotificationController::OnPortalDetectionCompleted( |
245 const NetworkState* network, | 248 const NetworkState* network, |
246 const NetworkPortalDetector::CaptivePortalState& state) { | 249 const NetworkPortalDetector::CaptivePortalState& state) { |
247 if (!IsPortalNotificationEnabled()) | 250 if (!IsPortalNotificationEnabled()) |
248 return; | 251 return; |
249 | 252 |
250 if (!network || | 253 if (!network || |
251 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) { | 254 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) { |
252 last_network_path_.clear(); | 255 last_network_path_.clear(); |
253 | 256 |
254 if (dialog_) | 257 // In browser tests we initiate fake network portal detection, but network |
| 258 // state usually stays connected. This way, after dialog is shown, it is |
| 259 // immediately closed. The testing check below prevents dialog from closing. |
| 260 if (dialog_ && |
| 261 (!ignore_no_network_for_testing_ || |
| 262 state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE)) { |
255 dialog_->Close(); | 263 dialog_->Close(); |
| 264 } |
256 | 265 |
257 CloseNotification(); | 266 CloseNotification(); |
258 return; | 267 return; |
259 } | 268 } |
260 | 269 |
261 // Don't do anything if we're currently activating the device. | 270 // Don't do anything if we're currently activating the device. |
262 if (MobileActivator::GetInstance()->RunningActivation()) | 271 if (MobileActivator::GetInstance()->RunningActivation()) |
263 return; | 272 return; |
264 | 273 |
265 // Don't do anything if notification for |network| already was | 274 // Don't do anything if notification for |network| already was |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 network->raw_ssid()); | 396 network->raw_ssid()); |
388 } | 397 } |
389 if (extension) { | 398 if (extension) { |
390 return CreateCaptivePortalNotificationForExtension( | 399 return CreateCaptivePortalNotificationForExtension( |
391 network, networking_config_service, extension); | 400 network, networking_config_service, extension); |
392 } else { | 401 } else { |
393 return CreateDefaultCaptivePortalNotification(network); | 402 return CreateDefaultCaptivePortalNotification(network); |
394 } | 403 } |
395 } | 404 } |
396 | 405 |
| 406 void NetworkPortalNotificationController::SetIgnoreNoNetworkForTesting() { |
| 407 ignore_no_network_for_testing_ = true; |
| 408 } |
| 409 |
| 410 void NetworkPortalNotificationController::CloseDialog() { |
| 411 if (dialog_) |
| 412 dialog_->Close(); |
| 413 } |
| 414 |
| 415 const NetworkPortalWebDialog* |
| 416 NetworkPortalNotificationController::GetDialogForTesting() const { |
| 417 return dialog_; |
| 418 } |
| 419 |
397 } // namespace chromeos | 420 } // namespace chromeos |
OLD | NEW |