Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/ui/webui/options/managed_user_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/managed_user_settings_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/first_run/first_run.h" | |
| 17 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | 16 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" |
| 18 #include "chrome/browser/managed_mode/managed_user_service.h" | 17 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 19 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 18 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 23 #include "content/public/browser/user_metrics.h" | 22 #include "content/public/browser/user_metrics.h" |
| 24 #include "content/public/browser/web_ui.h" | 23 #include "content/public/browser/web_ui.h" |
| 25 #include "googleurl/src/url_canon.h" | 24 #include "googleurl/src/url_canon.h" |
| 26 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 DCHECK(result); | 84 DCHECK(result); |
| 86 entries->Append( | 85 entries->Append( |
| 87 GetEntryForPattern(it.key(), allow ? "allow" : "block")); | 86 GetEntryForPattern(it.key(), allow ? "allow" : "block")); |
| 88 } | 87 } |
| 89 } | 88 } |
| 90 | 89 |
| 91 } // namespace | 90 } // namespace |
| 92 | 91 |
| 93 namespace options { | 92 namespace options { |
| 94 | 93 |
| 95 ManagedUserSettingsHandler::ManagedUserSettingsHandler() { | 94 ManagedUserSettingsHandler::ManagedUserSettingsHandler() |
| 95 : has_seen_settings_dialog_(true) { | |
| 96 } | 96 } |
| 97 | 97 |
| 98 ManagedUserSettingsHandler::~ManagedUserSettingsHandler() { | 98 ManagedUserSettingsHandler::~ManagedUserSettingsHandler() { |
| 99 } | 99 } |
| 100 | 100 |
| 101 void ManagedUserSettingsHandler::InitializeHandler() { | 101 void ManagedUserSettingsHandler::InitializeHandler() { |
| 102 pref_change_registrar_.Init(Profile::FromWebUI(web_ui())->GetPrefs()); | 102 pref_change_registrar_.Init(Profile::FromWebUI(web_ui())->GetPrefs()); |
| 103 pref_change_registrar_.Add( | 103 pref_change_registrar_.Add( |
| 104 prefs::kManagedModeLocalPassphrase, | 104 prefs::kManagedModeLocalPassphrase, |
| 105 base::Bind(&ManagedUserSettingsHandler::OnLocalPassphraseChanged, | 105 base::Bind(&ManagedUserSettingsHandler::OnLocalPassphraseChanged, |
| 106 base::Unretained(this))); | 106 base::Unretained(this))); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void ManagedUserSettingsHandler::InitializePage() { | 109 void ManagedUserSettingsHandler::InitializePage() { |
| 110 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 110 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 111 switches::kEnableManagedUsers)) { | 111 switches::kEnableManagedUsers)) { |
| 112 return; | 112 return; |
| 113 } | 113 } |
| 114 | |
| 114 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 115 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 115 base::FundamentalValue is_passphrase_set(!pref_service->GetString( | 116 bool passphrase_empty = |
| 116 prefs::kManagedModeLocalPassphrase).empty()); | 117 pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty(); |
| 118 base::FundamentalValue is_passphrase_set(!passphrase_empty); | |
| 117 web_ui()->CallJavascriptFunction( | 119 web_ui()->CallJavascriptFunction( |
| 118 "ManagedUserSettings.passphraseChanged", | 120 "ManagedUserSettings.passphraseChanged", |
| 119 is_passphrase_set); | 121 is_passphrase_set); |
| 120 if ((first_run::IsChromeFirstRun() && | |
| 121 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoFirstRun)) || | |
| 122 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 123 switches::kResetLocalPassphrase)) { | |
| 124 ManagedModeNavigationObserver::FromWebContents( | |
| 125 web_ui()->GetWebContents())->set_elevated(true); | |
| 126 } | |
| 127 | 122 |
| 128 // Populate the list. | 123 // Populate the list. |
| 129 UpdateViewFromModel(); | 124 UpdateViewFromModel(); |
| 130 } | 125 } |
| 131 | 126 |
| 132 void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) { | 127 void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) { |
| 133 start_time_ = base::TimeTicks::Now(); | 128 start_time_ = base::TimeTicks::Now(); |
| 134 content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings")); | 129 content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings")); |
| 135 if (ManagedModeNavigationObserver::FromWebContents( | 130 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( |
| 136 web_ui()->GetWebContents())->is_elevated()) { | 131 Profile::FromWebUI(web_ui())); |
| 132 ManagedModeNavigationObserver* observer = | |
| 133 ManagedModeNavigationObserver::FromWebContents( | |
| 134 web_ui()->GetWebContents()); | |
| 135 | |
| 136 // Check if we need to give initial elevation for startup of a new profile. | |
| 137 if (service->startup_elevation()) { | |
| 138 service->set_startup_elevation(false); | |
| 139 observer->set_elevated(true); | |
| 140 has_seen_settings_dialog_ = false; | |
|
Bernhard Bauer
2013/04/10 12:26:17
Hmm... I'm wondering if it would make more sense t
Adrian Kuegel
2013/04/10 12:34:55
Yes, SGTM. I changed it like that.
| |
| 141 } | |
| 142 | |
| 143 if (observer->is_elevated()) { | |
| 137 web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated", | 144 web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated", |
| 138 base::FundamentalValue(true)); | 145 base::FundamentalValue(true)); |
| 139 } | 146 } |
| 140 } | 147 } |
| 141 | 148 |
| 142 void ManagedUserSettingsHandler::GetLocalizedValues( | 149 void ManagedUserSettingsHandler::GetLocalizedValues( |
| 143 base::DictionaryValue* localized_strings) { | 150 base::DictionaryValue* localized_strings) { |
| 144 DCHECK(localized_strings); | 151 DCHECK(localized_strings); |
| 145 | 152 |
| 146 static OptionsStringResource resources[] = { | 153 static OptionsStringResource resources[] = { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 web_ui()->RegisterMessageCallback("setManualException", | 207 web_ui()->RegisterMessageCallback("setManualException", |
| 201 base::Bind(&ManagedUserSettingsHandler::SetManualException, | 208 base::Bind(&ManagedUserSettingsHandler::SetManualException, |
| 202 base::Unretained(this))); | 209 base::Unretained(this))); |
| 203 web_ui()->RegisterMessageCallback("checkManualExceptionValidity", | 210 web_ui()->RegisterMessageCallback("checkManualExceptionValidity", |
| 204 base::Bind( | 211 base::Bind( |
| 205 &ManagedUserSettingsHandler::CheckManualExceptionValidity, | 212 &ManagedUserSettingsHandler::CheckManualExceptionValidity, |
| 206 base::Unretained(this))); | 213 base::Unretained(this))); |
| 207 } | 214 } |
| 208 | 215 |
| 209 void ManagedUserSettingsHandler::SaveMetrics(const ListValue* args) { | 216 void ManagedUserSettingsHandler::SaveMetrics(const ListValue* args) { |
| 210 if (first_run::IsChromeFirstRun()) { | 217 if (!has_seen_settings_dialog_) { |
| 218 has_seen_settings_dialog_ = true; | |
| 211 UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsFirstRunTime", | 219 UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsFirstRunTime", |
| 212 base::TimeTicks::Now() - start_time_); | 220 base::TimeTicks::Now() - start_time_); |
| 213 } else { | 221 } else { |
| 214 UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsModifyTime", | 222 UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsModifyTime", |
| 215 base::TimeTicks::Now() - start_time_); | 223 base::TimeTicks::Now() - start_time_); |
| 216 } | 224 } |
| 217 } | 225 } |
| 218 | 226 |
| 219 void ManagedUserSettingsHandler::OnLocalPassphraseChanged() { | 227 void ManagedUserSettingsHandler::OnLocalPassphraseChanged() { |
| 220 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 228 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 void ManagedUserSettingsHandler::UpdateViewFromModel() { | 318 void ManagedUserSettingsHandler::UpdateViewFromModel() { |
| 311 ListValue entries; | 319 ListValue entries; |
| 312 AddCurrentURLEntries(web_ui(), &entries); | 320 AddCurrentURLEntries(web_ui(), &entries); |
| 313 | 321 |
| 314 web_ui()->CallJavascriptFunction( | 322 web_ui()->CallJavascriptFunction( |
| 315 "ManagedUserSettings.setManualExceptions", | 323 "ManagedUserSettings.setManualExceptions", |
| 316 entries); | 324 entries); |
| 317 } | 325 } |
| 318 | 326 |
| 319 } // namespace options | 327 } // namespace options |
| OLD | NEW |