| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/managed_mode/managed_user_service.h" | 5 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | |
| 15 #include "chrome/browser/managed_mode/managed_mode_site_list.h" | 14 #include "chrome/browser/managed_mode/managed_mode_site_list.h" |
| 16 #include "chrome/browser/managed_mode/managed_user_registration_service.h" | 15 #include "chrome/browser/managed_mode/managed_user_registration_service.h" |
| 17 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 16 #include "chrome/browser/policy/managed_mode_policy_provider.h" |
| 18 #include "chrome/browser/policy/profile_policy_connector.h" | 17 #include "chrome/browser/policy/profile_policy_connector.h" |
| 19 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 18 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/signin/token_service.h" | 21 #include "chrome/browser/signin/token_service.h" |
| 23 #include "chrome/browser/signin/token_service_factory.h" | 22 #include "chrome/browser/signin/token_service_factory.h" |
| 24 #include "chrome/browser/sync/glue/session_model_associator.h" | 23 #include "chrome/browser/sync/glue/session_model_associator.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 131 |
| 133 bool ManagedUserService::ProfileIsManaged() const { | 132 bool ManagedUserService::ProfileIsManaged() const { |
| 134 return ProfileIsManaged(profile_); | 133 return ProfileIsManaged(profile_); |
| 135 } | 134 } |
| 136 | 135 |
| 137 // static | 136 // static |
| 138 bool ManagedUserService::ProfileIsManaged(Profile* profile) { | 137 bool ManagedUserService::ProfileIsManaged(Profile* profile) { |
| 139 return profile->GetPrefs()->GetBoolean(prefs::kProfileIsManaged); | 138 return profile->GetPrefs()->GetBoolean(prefs::kProfileIsManaged); |
| 140 } | 139 } |
| 141 | 140 |
| 142 bool ManagedUserService::IsElevatedForWebContents( | |
| 143 const content::WebContents* web_contents) const { | |
| 144 const ManagedModeNavigationObserver* observer = | |
| 145 ManagedModeNavigationObserver::FromWebContents(web_contents); | |
| 146 return observer ? observer->is_elevated() : false; | |
| 147 } | |
| 148 | |
| 149 bool ManagedUserService::IsPassphraseEmpty() const { | |
| 150 PrefService* pref_service = profile_->GetPrefs(); | |
| 151 return pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty(); | |
| 152 } | |
| 153 | |
| 154 bool ManagedUserService::CanSkipPassphraseDialog( | |
| 155 const content::WebContents* web_contents) const { | |
| 156 #if defined(OS_CHROMEOS) | |
| 157 NOTREACHED(); | |
| 158 #endif | |
| 159 return IsElevatedForWebContents(web_contents) || | |
| 160 IsPassphraseEmpty(); | |
| 161 } | |
| 162 | |
| 163 void ManagedUserService::RequestAuthorization( | |
| 164 content::WebContents* web_contents, | |
| 165 const PassphraseCheckedCallback& callback) { | |
| 166 #if defined(OS_CHROMEOS) | |
| 167 NOTREACHED(); | |
| 168 #endif | |
| 169 | |
| 170 if (CanSkipPassphraseDialog(web_contents)) { | |
| 171 callback.Run(true); | |
| 172 return; | |
| 173 } | |
| 174 | |
| 175 // Is deleted automatically when the dialog is closed. | |
| 176 new ManagedUserPassphraseDialog(web_contents, callback); | |
| 177 } | |
| 178 | |
| 179 // static | 141 // static |
| 180 void ManagedUserService::RegisterUserPrefs( | 142 void ManagedUserService::RegisterUserPrefs( |
| 181 user_prefs::PrefRegistrySyncable* registry) { | 143 user_prefs::PrefRegistrySyncable* registry) { |
| 182 registry->RegisterDictionaryPref( | 144 registry->RegisterDictionaryPref( |
| 183 prefs::kManagedModeManualHosts, | 145 prefs::kManagedModeManualHosts, |
| 184 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 146 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 185 registry->RegisterDictionaryPref( | 147 registry->RegisterDictionaryPref( |
| 186 prefs::kManagedModeManualURLs, | 148 prefs::kManagedModeManualURLs, |
| 187 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 149 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 188 registry->RegisterIntegerPref( | 150 registry->RegisterIntegerPref( |
| 189 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, | 151 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, |
| 190 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 152 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 191 registry->RegisterStringPref( | |
| 192 prefs::kManagedModeLocalPassphrase, std::string(), | |
| 193 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 194 registry->RegisterStringPref( | |
| 195 prefs::kManagedModeLocalSalt, std::string(), | |
| 196 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 197 } | 153 } |
| 198 | 154 |
| 199 scoped_refptr<const ManagedModeURLFilter> | 155 scoped_refptr<const ManagedModeURLFilter> |
| 200 ManagedUserService::GetURLFilterForIOThread() { | 156 ManagedUserService::GetURLFilterForIOThread() { |
| 201 return url_filter_context_.io_url_filter(); | 157 return url_filter_context_.io_url_filter(); |
| 202 } | 158 } |
| 203 | 159 |
| 204 ManagedModeURLFilter* ManagedUserService::GetURLFilterForUIThread() { | 160 ManagedModeURLFilter* ManagedUserService::GetURLFilterForUIThread() { |
| 205 return url_filter_context_.ui_url_filter(); | 161 return url_filter_context_.ui_url_filter(); |
| 206 } | 162 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 268 |
| 313 bool ManagedUserService::ExtensionManagementPolicyImpl( | 269 bool ManagedUserService::ExtensionManagementPolicyImpl( |
| 314 const std::string& extension_id, | 270 const std::string& extension_id, |
| 315 string16* error) const { | 271 string16* error) const { |
| 316 if (!ProfileIsManaged()) | 272 if (!ProfileIsManaged()) |
| 317 return true; | 273 return true; |
| 318 | 274 |
| 319 if (elevated_for_testing_) | 275 if (elevated_for_testing_) |
| 320 return true; | 276 return true; |
| 321 | 277 |
| 322 if (elevated_for_extensions_.count(extension_id)) | |
| 323 return true; | |
| 324 | |
| 325 if (error) | 278 if (error) |
| 326 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_MODE); | 279 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_MODE); |
| 327 return false; | 280 return false; |
| 328 } | 281 } |
| 329 | 282 |
| 330 ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() { | 283 ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() { |
| 331 ScopedVector<ManagedModeSiteList> site_lists; | 284 ScopedVector<ManagedModeSiteList> site_lists; |
| 332 ExtensionService* extension_service = | 285 ExtensionService* extension_service = |
| 333 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 286 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 334 // Can be NULL in unit tests. | 287 // Can be NULL in unit tests. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 517 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
| 565 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 518 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
| 566 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 519 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 567 bool allow = false; | 520 bool allow = false; |
| 568 bool result = it.value().GetAsBoolean(&allow); | 521 bool result = it.value().GetAsBoolean(&allow); |
| 569 DCHECK(result); | 522 DCHECK(result); |
| 570 (*url_map)[GURL(it.key())] = allow; | 523 (*url_map)[GURL(it.key())] = allow; |
| 571 } | 524 } |
| 572 url_filter_context_.SetManualURLs(url_map.Pass()); | 525 url_filter_context_.SetManualURLs(url_map.Pass()); |
| 573 } | 526 } |
| OLD | NEW |