Chromium Code Reviews| 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 "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/prefs/pref_service.h" | |
| 16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/browser/browser_process.h" | |
| 20 #include "chrome/browser/browser_process_platform_part.h" | |
| 18 #include "chrome/browser/chromeos/mobile/mobile_activator.h" | 21 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
| 19 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h" | 22 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h" |
| 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 24 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 25 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "chrome/browser/ui/browser_dialogs.h" | 27 #include "chrome/browser/ui/browser_dialogs.h" |
| 23 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 28 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 24 #include "chrome/browser/ui/singleton_tabs.h" | 29 #include "chrome/browser/ui/singleton_tabs.h" |
| 30 #include "chrome/common/pref_names.h" | |
| 25 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
| 26 #include "chrome/grit/theme_resources.h" | 32 #include "chrome/grit/theme_resources.h" |
| 27 #include "chromeos/chromeos_switches.h" | 33 #include "chromeos/chromeos_switches.h" |
| 28 #include "chromeos/network/network_state.h" | 34 #include "chromeos/network/network_state.h" |
| 29 #include "components/captive_portal/captive_portal_detector.h" | 35 #include "components/captive_portal/captive_portal_detector.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/message_center/message_center.h" | 38 #include "ui/message_center/message_center.h" |
| 33 #include "ui/message_center/notification.h" | 39 #include "ui/message_center/notification.h" |
| 34 #include "ui/message_center/notification_types.h" | 40 #include "ui/message_center/notification_types.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); | 100 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); |
| 95 } | 101 } |
| 96 | 102 |
| 97 void NetworkPortalNotificationControllerDelegate::Click() { | 103 void NetworkPortalNotificationControllerDelegate::Click() { |
| 98 clicked_ = true; | 104 clicked_ = true; |
| 99 UMA_HISTOGRAM_ENUMERATION( | 105 UMA_HISTOGRAM_ENUMERATION( |
| 100 NetworkPortalNotificationController::kUserActionMetric, | 106 NetworkPortalNotificationController::kUserActionMetric, |
| 101 NetworkPortalNotificationController::USER_ACTION_METRIC_CLICKED, | 107 NetworkPortalNotificationController::USER_ACTION_METRIC_CLICKED, |
| 102 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); | 108 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); |
| 103 | 109 |
| 104 if (CommandLine::ForCurrentProcess()->HasSwitch( | 110 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 105 chromeos::switches::kEnableCaptivePortalBypassProxy)) { | 111 |
| 112 const bool bypass_proxy_switch_present = | |
| 113 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 114 chromeos::switches::kEnableCaptivePortalBypassProxy); | |
| 115 const bool use_incognito_profile = | |
| 116 bypass_proxy_switch_present | |
| 117 ? (profile && | |
| 118 profile->GetPrefs()->GetBoolean( | |
|
bartfab (slow)
2015/01/07 17:38:42
Nit: #include "base/prefs/pref_service.h"
Alexander Alekseev
2015/01/12 18:41:09
Done.
| |
| 119 prefs::kCaptivePortalAuthenticationIgnoresProxy)) | |
|
bartfab (slow)
2015/01/07 17:38:42
Nit: #include "chrome/common/pref_names.h"
Alexander Alekseev
2015/01/12 18:41:09
Done.
| |
| 120 : false; | |
| 121 | |
| 122 if (use_incognito_profile) { | |
| 106 if (controller_) | 123 if (controller_) |
| 107 controller_->ShowDialog(); | 124 controller_->ShowDialog(); |
| 108 } else { | 125 } else { |
| 109 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 110 if (!profile) | 126 if (!profile) |
| 111 return; | 127 return; |
| 112 chrome::ScopedTabbedBrowserDisplayer displayer( | 128 chrome::ScopedTabbedBrowserDisplayer displayer( |
| 113 profile, chrome::HOST_DESKTOP_TYPE_ASH); | 129 profile, chrome::HOST_DESKTOP_TYPE_ASH); |
| 114 GURL url(captive_portal::CaptivePortalDetector::kDefaultURL); | 130 GURL url(captive_portal::CaptivePortalDetector::kDefaultURL); |
| 115 chrome::ShowSingletonTab(displayer.browser(), url); | 131 chrome::ShowSingletonTab(displayer.browser(), url); |
| 116 } | 132 } |
| 117 CloseNotification(); | 133 CloseNotification(); |
| 118 } | 134 } |
| 119 | 135 |
| 120 } // namespace | 136 } // namespace |
| 121 | 137 |
| 122 // static | 138 // static |
| 123 const char NetworkPortalNotificationController::kNotificationId[] = | 139 const char NetworkPortalNotificationController::kNotificationId[] = |
| 124 "chrome://net/network_portal_detector"; | 140 "chrome://net/network_portal_detector"; |
| 125 | 141 |
| 126 // static | 142 // static |
| 127 const char NetworkPortalNotificationController::kNotificationMetric[] = | 143 const char NetworkPortalNotificationController::kNotificationMetric[] = |
| 128 "CaptivePortal.Notification.Status"; | 144 "CaptivePortal.Notification.Status"; |
| 129 | 145 |
| 130 // static | 146 // static |
| 131 const char NetworkPortalNotificationController::kUserActionMetric[] = | 147 const char NetworkPortalNotificationController::kUserActionMetric[] = |
| 132 "CaptivePortal.Notification.UserAction"; | 148 "CaptivePortal.Notification.UserAction"; |
| 133 | 149 |
| 134 NetworkPortalNotificationController::NetworkPortalNotificationController() | 150 NetworkPortalNotificationController::NetworkPortalNotificationController() |
| 135 : dialog_(nullptr) { | 151 : dialog_(nullptr), ignore_no_network_for_testing_(false) { |
| 136 } | 152 } |
| 137 | 153 |
| 138 NetworkPortalNotificationController::~NetworkPortalNotificationController() {} | 154 NetworkPortalNotificationController::~NetworkPortalNotificationController() {} |
| 139 | 155 |
| 140 void NetworkPortalNotificationController::OnPortalDetectionCompleted( | 156 void NetworkPortalNotificationController::OnPortalDetectionCompleted( |
| 141 const NetworkState* network, | 157 const NetworkState* network, |
| 142 const NetworkPortalDetector::CaptivePortalState& state) { | 158 const NetworkPortalDetector::CaptivePortalState& state) { |
| 143 if (!IsPortalNotificationEnabled()) | 159 if (!IsPortalNotificationEnabled()) |
| 144 return; | 160 return; |
| 145 | 161 |
| 146 if (!network || | 162 if (!network || |
| 147 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) { | 163 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) { |
| 148 last_network_path_.clear(); | 164 last_network_path_.clear(); |
| 149 | 165 |
| 150 if (dialog_) | 166 // Do not close dialog in browser tests on "no network" errors. |
| 167 if (dialog_ && | |
| 168 (!ignore_no_network_for_testing_ || | |
|
bartfab (slow)
2015/01/07 17:38:42
This conditional makes |ignore_no_network_for_test
Alexander Alekseev
2015/01/12 18:41:09
This is intentional.
bartfab (slow)
2015/01/14 11:00:07
It does not seem to match the comment though.
Alexander Alekseev
2015/01/16 22:51:48
Done.
(The comment was really outdated, sorry.)
| |
| 169 state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE)) { | |
|
bartfab (slow)
2015/01/07 17:38:42
If |ignore_no_network_for_testing_| is false (the
Alexander Alekseev
2015/01/12 18:41:09
Yes.
In browser_tests we have very strange conditi
| |
| 151 dialog_->Close(); | 170 dialog_->Close(); |
| 171 } | |
| 152 | 172 |
| 153 CloseNotification(); | 173 CloseNotification(); |
| 154 return; | 174 return; |
| 155 } | 175 } |
| 156 | 176 |
| 157 // Don't do anything if we're currently activating the device. | 177 // Don't do anything if we're currently activating the device. |
| 158 if (MobileActivator::GetInstance()->RunningActivation()) | 178 if (MobileActivator::GetInstance()->RunningActivation()) |
| 159 return; | 179 return; |
| 160 | 180 |
| 161 // Don't do anything if notification for |network| already was | 181 // Don't do anything if notification for |network| already was |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 220 } |
| 201 | 221 |
| 202 void NetworkPortalNotificationController::OnDialogDestroyed( | 222 void NetworkPortalNotificationController::OnDialogDestroyed( |
| 203 const NetworkPortalWebDialog* dialog) { | 223 const NetworkPortalWebDialog* dialog) { |
| 204 if (dialog == dialog_) { | 224 if (dialog == dialog_) { |
| 205 dialog_ = nullptr; | 225 dialog_ = nullptr; |
| 206 ProfileHelper::Get()->ClearSigninProfile(base::Closure()); | 226 ProfileHelper::Get()->ClearSigninProfile(base::Closure()); |
| 207 } | 227 } |
| 208 } | 228 } |
| 209 | 229 |
| 230 void NetworkPortalNotificationController::SetIgnoreNoNetworkForTesting() { | |
| 231 ignore_no_network_for_testing_ = true; | |
| 232 } | |
| 233 | |
| 234 const NetworkPortalWebDialog* | |
| 235 NetworkPortalNotificationController::GetDialogForTesting() const { | |
| 236 return dialog_; | |
| 237 } | |
| 238 | |
| 210 } // namespace chromeos | 239 } // namespace chromeos |
| OLD | NEW |