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

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

Issue 818433003: ChromeOS: Implement CaptivePortalAuthenticationIgnoresProxy policy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years, 12 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
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/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"
22 #include "chrome/browser/chromeos/net/captive_portal_ignore_proxy_policy_values. h"
19 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h" 23 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h"
24 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
25 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" 26 #include "chrome/browser/chromeos/profiles/profile_helper.h"
21 #include "chrome/browser/profiles/profile_manager.h" 27 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/ui/browser_dialogs.h" 28 #include "chrome/browser/ui/browser_dialogs.h"
23 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 29 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
24 #include "chrome/browser/ui/singleton_tabs.h" 30 #include "chrome/browser/ui/singleton_tabs.h"
31 #include "chrome/common/pref_names.h"
25 #include "chrome/grit/generated_resources.h" 32 #include "chrome/grit/generated_resources.h"
26 #include "chrome/grit/theme_resources.h" 33 #include "chrome/grit/theme_resources.h"
27 #include "chromeos/chromeos_switches.h" 34 #include "chromeos/chromeos_switches.h"
28 #include "chromeos/network/network_state.h" 35 #include "chromeos/network/network_state.h"
29 #include "components/captive_portal/captive_portal_detector.h" 36 #include "components/captive_portal/captive_portal_detector.h"
30 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/message_center/message_center.h" 39 #include "ui/message_center/message_center.h"
33 #include "ui/message_center/notification.h" 40 #include "ui/message_center/notification.h"
34 #include "ui/message_center/notification_types.h" 41 #include "ui/message_center/notification_types.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); 101 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT);
95 } 102 }
96 103
97 void NetworkPortalNotificationControllerDelegate::Click() { 104 void NetworkPortalNotificationControllerDelegate::Click() {
98 clicked_ = true; 105 clicked_ = true;
99 UMA_HISTOGRAM_ENUMERATION( 106 UMA_HISTOGRAM_ENUMERATION(
100 NetworkPortalNotificationController::kUserActionMetric, 107 NetworkPortalNotificationController::kUserActionMetric,
101 NetworkPortalNotificationController::USER_ACTION_METRIC_CLICKED, 108 NetworkPortalNotificationController::USER_ACTION_METRIC_CLICKED,
102 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT); 109 NetworkPortalNotificationController::USER_ACTION_METRIC_COUNT);
103 110
104 if (CommandLine::ForCurrentProcess()->HasSwitch( 111 Profile* profile = ProfileManager::GetActiveUserProfile();
105 chromeos::switches::kEnableCaptivePortalBypassProxy)) { 112
113 const bool command_line_switch_present =
ygorshenin1 2014/12/25 18:07:15 It's not clear from the name of the variable what
Alexander Alekseev 2015/01/05 20:53:03 Done.
114 CommandLine::ForCurrentProcess()->HasSwitch(
115 chromeos::switches::kEnableCaptivePortalBypassProxy);
116 bool use_incognito_profile = command_line_switch_present;
117
118 // Check if CaptivePortalAuthenticationIgnoresProxy policy is applied.
119 if (profile &&
120 !profile->GetPrefs()
121 ->FindPreference(prefs::kCaptivePortalAuthenticationIgnoresProxy)
122 ->IsDefaultValue()) {
123 const int policy = profile->GetPrefs()->GetInteger(
124 prefs::kCaptivePortalAuthenticationIgnoresProxy);
125 switch (policy) {
126 case CAPTIVE_PORTAL_AUTH_IGNORE_PROXY_TRUE:
127 use_incognito_profile = true;
128 break;
129 case CAPTIVE_PORTAL_AUTH_IGNORE_PROXY_FALSE:
130 use_incognito_profile = false;
131 break;
132 case CAPTIVE_PORTAL_AUTH_IGNORE_PROXY_USER_CONFIGURABLE:
Mattias Nissler (ping if slow) 2015/01/05 11:33:29 This is not how policy is designed to work. user-c
Alexander Alekseev 2015/01/05 20:53:03 Done.
133 break;
134 default:
135 NOTREACHED();
136 }
137 // ConsumerManagementService() might be undefined in tests.
138 } else if (g_browser_process->platform_part()
ygorshenin1 2014/12/25 18:07:15 Could you please create a local variable for a res
Alexander Alekseev 2015/01/05 20:53:03 Done.
139 ->browser_policy_connector_chromeos()
140 ->GetConsumerManagementService() &&
141 g_browser_process->platform_part()
142 ->browser_policy_connector_chromeos()
143 ->GetConsumerManagementService()
144 ->GetStatus() ==
145 policy::ConsumerManagementService::STATUS_ENROLLED) {
146 // Enrolled device defaults to
147 // "CaptivePortalAuthenticationIgnoresProxy=false".
148 use_incognito_profile = false;
Mattias Nissler (ping if slow) 2015/01/05 11:33:29 Why do we need this code branch for consumer-enrol
Alexander Alekseev 2015/01/05 20:53:03 Done.
149 }
150
151 if (use_incognito_profile) {
106 if (controller_) 152 if (controller_)
107 controller_->ShowDialog(); 153 controller_->ShowDialog();
108 } else { 154 } else {
109 Profile* profile = ProfileManager::GetActiveUserProfile();
110 if (!profile) 155 if (!profile)
111 return; 156 return;
112 chrome::ScopedTabbedBrowserDisplayer displayer( 157 chrome::ScopedTabbedBrowserDisplayer displayer(
113 profile, chrome::HOST_DESKTOP_TYPE_ASH); 158 profile, chrome::HOST_DESKTOP_TYPE_ASH);
114 GURL url(captive_portal::CaptivePortalDetector::kDefaultURL); 159 GURL url(captive_portal::CaptivePortalDetector::kDefaultURL);
115 chrome::ShowSingletonTab(displayer.browser(), url); 160 chrome::ShowSingletonTab(displayer.browser(), url);
116 } 161 }
117 CloseNotification(); 162 CloseNotification();
118 } 163 }
119 164
120 } // namespace 165 } // namespace
121 166
122 // static 167 // static
123 const char NetworkPortalNotificationController::kNotificationId[] = 168 const char NetworkPortalNotificationController::kNotificationId[] =
124 "chrome://net/network_portal_detector"; 169 "chrome://net/network_portal_detector";
125 170
126 // static 171 // static
127 const char NetworkPortalNotificationController::kNotificationMetric[] = 172 const char NetworkPortalNotificationController::kNotificationMetric[] =
128 "CaptivePortal.Notification.Status"; 173 "CaptivePortal.Notification.Status";
129 174
130 // static 175 // static
131 const char NetworkPortalNotificationController::kUserActionMetric[] = 176 const char NetworkPortalNotificationController::kUserActionMetric[] =
132 "CaptivePortal.Notification.UserAction"; 177 "CaptivePortal.Notification.UserAction";
133 178
134 NetworkPortalNotificationController::NetworkPortalNotificationController() 179 NetworkPortalNotificationController::NetworkPortalNotificationController()
135 : dialog_(nullptr) { 180 : dialog_(nullptr), ignore_no_network_for_testing_(false) {
136 } 181 }
137 182
138 NetworkPortalNotificationController::~NetworkPortalNotificationController() {} 183 NetworkPortalNotificationController::~NetworkPortalNotificationController() {}
139 184
140 void NetworkPortalNotificationController::OnPortalDetectionCompleted( 185 void NetworkPortalNotificationController::OnPortalDetectionCompleted(
141 const NetworkState* network, 186 const NetworkState* network,
142 const NetworkPortalDetector::CaptivePortalState& state) { 187 const NetworkPortalDetector::CaptivePortalState& state) {
143 if (!IsPortalNotificationEnabled()) 188 if (!IsPortalNotificationEnabled())
144 return; 189 return;
145 190
146 if (!network || 191 if (!network ||
147 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) { 192 state.status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) {
148 last_network_path_.clear(); 193 last_network_path_.clear();
149 194
150 if (dialog_) 195 // Do not close dialog in browser tests on "no network" errors.
196 if (dialog_ &&
197 (!ignore_no_network_for_testing_ ||
198 state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE))
151 dialog_->Close(); 199 dialog_->Close();
ygorshenin1 2014/12/25 18:07:15 Could you please wrap branch in curly braces?
Alexander Alekseev 2015/01/05 20:53:02 Done.
152 200
153 CloseNotification(); 201 CloseNotification();
154 return; 202 return;
155 } 203 }
156 204
157 // Don't do anything if we're currently activating the device. 205 // Don't do anything if we're currently activating the device.
158 if (MobileActivator::GetInstance()->RunningActivation()) 206 if (MobileActivator::GetInstance()->RunningActivation())
159 return; 207 return;
160 208
161 // Don't do anything if notification for |network| already was 209 // Don't do anything if notification for |network| already was
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 248 }
201 249
202 void NetworkPortalNotificationController::OnDialogDestroyed( 250 void NetworkPortalNotificationController::OnDialogDestroyed(
203 const NetworkPortalWebDialog* dialog) { 251 const NetworkPortalWebDialog* dialog) {
204 if (dialog == dialog_) { 252 if (dialog == dialog_) {
205 dialog_ = nullptr; 253 dialog_ = nullptr;
206 ProfileHelper::Get()->ClearSigninProfile(base::Closure()); 254 ProfileHelper::Get()->ClearSigninProfile(base::Closure());
207 } 255 }
208 } 256 }
209 257
258 void NetworkPortalNotificationController::SetIgnoreNoNetworkForTesting() {
259 ignore_no_network_for_testing_ = true;
260 }
261
262 const NetworkPortalWebDialog*
263 NetworkPortalNotificationController::GetDialogForTesting() const {
264 return dialog_;
265 }
266
210 } // namespace chromeos 267 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698