Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/policy/configuration_policy_handler.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/stl_util.h" | |
| 13 #include "base/string16.h" | |
| 14 #include "base/string_number_conversions.h" | |
| 15 #include "base/string_util.h" | |
| 16 #include "base/utf_string_conversions.h" | |
| 17 #include "base/values.h" | |
| 18 #include "chrome/browser/download/download_util.h" | |
| 19 #include "chrome/browser/policy/configuration_policy_pref_store.h" | |
| 20 #include "chrome/browser/policy/policy_error_map.h" | |
| 21 #include "chrome/browser/policy/policy_map.h" | |
| 22 #include "chrome/browser/policy/policy_path_parser.h" | |
| 23 #include "chrome/browser/prefs/incognito_mode_prefs.h" | |
| 24 #include "chrome/browser/prefs/pref_value_map.h" | |
| 25 #include "chrome/browser/prefs/proxy_config_dictionary.h" | |
| 26 #include "chrome/browser/prefs/proxy_prefs.h" | |
| 27 #include "chrome/browser/search_engines/search_terms_data.h" | |
| 28 #include "chrome/browser/search_engines/template_url.h" | |
| 29 #include "chrome/common/pref_names.h" | |
| 30 #include "grit/generated_resources.h" | |
| 31 #include "policy/configuration_policy_type.h" | |
| 32 | |
| 33 namespace policy { | |
| 34 | |
| 35 namespace { | |
| 36 | |
| 37 | |
|
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
remove some extra white space?
Joao da Silva
2011/10/11 15:09:23
Done.
| |
| 38 // Implementations of ConfigurationPolicyHandler ------------------------------- | |
| 39 | |
| 40 | |
| 41 // Abstract class derived from ConfigurationPolicyHandler that should be | |
| 42 // subclassed to handle a single policy (not a combination of policies). | |
| 43 class TypeCheckingPolicyHandler : public ConfigurationPolicyHandler { | |
| 44 public: | |
| 45 TypeCheckingPolicyHandler(ConfigurationPolicyType policy_type, | |
| 46 base::Value::Type value_type); | |
| 47 | |
| 48 // ConfigurationPolicyHandler methods: | |
| 49 virtual bool CheckPolicySettings(const PolicyMap* policies, | |
| 50 PolicyErrorMap* errors) OVERRIDE; | |
| 51 | |
| 52 protected: | |
| 53 virtual ~TypeCheckingPolicyHandler(); | |
| 54 | |
| 55 ConfigurationPolicyType policy_type() const; | |
| 56 | |
| 57 private: | |
| 58 // The ConfigurationPolicyType of the policy. | |
| 59 ConfigurationPolicyType policy_type_; | |
| 60 | |
| 61 // The type the value of the policy should have. | |
| 62 base::Value::Type value_type_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler); | |
| 65 }; | |
| 66 | |
|
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
nit: remove extra blank line? also below.
Joao da Silva
2011/10/11 15:09:23
Done.
| |
| 67 | |
| 68 // ConfigurationPolicyHandler for policies that map directly to a preference. | |
| 69 class SimplePolicyHandler : public TypeCheckingPolicyHandler { | |
| 70 public: | |
| 71 SimplePolicyHandler(ConfigurationPolicyType policy_type, | |
| 72 base::Value::Type value_type, | |
| 73 const char* pref_path); | |
| 74 virtual ~SimplePolicyHandler(); | |
| 75 | |
| 76 // ConfigurationPolicyHandler methods: | |
| 77 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 78 PrefValueMap* prefs) OVERRIDE; | |
| 79 | |
| 80 private: | |
| 81 // The DictionaryValue path of the preference the policy maps to. | |
| 82 const char* pref_path_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); | |
| 85 }; | |
| 86 | |
| 87 | |
| 88 // ConfigurationPolicyHandler for the SyncDisabled policy. | |
| 89 class SyncPolicyHandler : public TypeCheckingPolicyHandler { | |
| 90 public: | |
| 91 SyncPolicyHandler(); | |
| 92 virtual ~SyncPolicyHandler(); | |
| 93 | |
| 94 // ConfigurationPolicyHandler methods: | |
| 95 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 96 PrefValueMap* prefs) OVERRIDE; | |
| 97 | |
| 98 private: | |
| 99 DISALLOW_COPY_AND_ASSIGN(SyncPolicyHandler); | |
| 100 }; | |
| 101 | |
| 102 | |
| 103 // ConfigurationPolicyHandler for the AutofillEnabled policy. | |
| 104 class AutofillPolicyHandler : public TypeCheckingPolicyHandler { | |
| 105 public: | |
| 106 AutofillPolicyHandler(); | |
| 107 virtual ~AutofillPolicyHandler(); | |
| 108 | |
| 109 // ConfigurationPolicyHandler methods: | |
| 110 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 111 PrefValueMap* prefs) OVERRIDE; | |
| 112 | |
| 113 private: | |
| 114 DISALLOW_COPY_AND_ASSIGN(AutofillPolicyHandler); | |
| 115 }; | |
| 116 | |
| 117 | |
| 118 // ConfigurationPolicyHandler for the DownloadDirectory policy. | |
| 119 class DownloadDirPolicyHandler : public TypeCheckingPolicyHandler { | |
| 120 public: | |
| 121 DownloadDirPolicyHandler(); | |
| 122 virtual ~DownloadDirPolicyHandler(); | |
| 123 | |
| 124 // ConfigurationPolicyHandler methods: | |
| 125 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 126 PrefValueMap* prefs) OVERRIDE; | |
| 127 | |
| 128 private: | |
| 129 DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler); | |
| 130 }; | |
| 131 | |
| 132 | |
| 133 // ConfigurationPolicyHandler for the DiskCacheDir policy. | |
| 134 class DiskCacheDirPolicyHandler : public TypeCheckingPolicyHandler { | |
| 135 public: | |
| 136 explicit DiskCacheDirPolicyHandler(); | |
| 137 virtual ~DiskCacheDirPolicyHandler(); | |
| 138 | |
| 139 // ConfigurationPolicyHandler methods: | |
| 140 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 141 PrefValueMap* prefs) OVERRIDE; | |
| 142 | |
| 143 private: | |
| 144 DISALLOW_COPY_AND_ASSIGN(DiskCacheDirPolicyHandler); | |
| 145 }; | |
| 146 | |
| 147 | |
| 148 // ConfigurationPolicyHandler for the FileSelectionDialogsHandler policy. | |
| 149 class FileSelectionDialogsHandler : public TypeCheckingPolicyHandler { | |
| 150 public: | |
| 151 FileSelectionDialogsHandler(); | |
| 152 virtual ~FileSelectionDialogsHandler(); | |
| 153 | |
| 154 // ConfigurationPolicyHandler methods: | |
| 155 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 156 PrefValueMap* prefs) OVERRIDE; | |
| 157 | |
| 158 private: | |
| 159 DISALLOW_COPY_AND_ASSIGN(FileSelectionDialogsHandler); | |
| 160 }; | |
| 161 | |
| 162 | |
| 163 // ConfigurationPolicyHandler for the incognito mode policies. | |
| 164 class IncognitoModePolicyHandler : public ConfigurationPolicyHandler { | |
| 165 public: | |
| 166 IncognitoModePolicyHandler(); | |
| 167 virtual ~IncognitoModePolicyHandler(); | |
| 168 | |
| 169 // ConfigurationPolicyHandler methods: | |
| 170 virtual bool CheckPolicySettings(const PolicyMap* policies, | |
| 171 PolicyErrorMap* errors) OVERRIDE; | |
| 172 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 173 PrefValueMap* prefs) OVERRIDE; | |
| 174 | |
| 175 private: | |
| 176 IncognitoModePrefs::Availability GetAvailabilityValueAsEnum( | |
| 177 const Value* availability); | |
| 178 | |
| 179 DISALLOW_COPY_AND_ASSIGN(IncognitoModePolicyHandler); | |
| 180 }; | |
| 181 | |
| 182 | |
| 183 // ConfigurationPolicyHandler for the DefaultSearchEncodings policy. | |
| 184 class DefaultSearchEncodingsPolicyHandler : public TypeCheckingPolicyHandler { | |
| 185 public: | |
| 186 DefaultSearchEncodingsPolicyHandler(); | |
| 187 virtual ~DefaultSearchEncodingsPolicyHandler(); | |
| 188 | |
| 189 // ConfigurationPolicyHandler methods: | |
| 190 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 191 PrefValueMap* prefs) OVERRIDE; | |
| 192 | |
| 193 private: | |
| 194 DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler); | |
| 195 }; | |
| 196 | |
| 197 | |
| 198 // ConfigurationPolicyHandler for the default search policies. | |
| 199 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler { | |
| 200 public: | |
| 201 DefaultSearchPolicyHandler(); | |
| 202 virtual ~DefaultSearchPolicyHandler(); | |
| 203 | |
| 204 // ConfigurationPolicyHandler methods: | |
| 205 virtual bool CheckPolicySettings(const PolicyMap* policies, | |
| 206 PolicyErrorMap* errors) OVERRIDE; | |
| 207 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 208 PrefValueMap* prefs) OVERRIDE; | |
| 209 | |
| 210 private: | |
| 211 // Calls |CheckPolicySettings()| on each of the handlers in |handlers_| | |
| 212 // and returns true if all of the calls return true and false otherwise. | |
| 213 bool CheckIndividualPolicies(const PolicyMap* policies, | |
| 214 PolicyErrorMap* errors); | |
| 215 | |
| 216 // Returns true if there is a value for |policy_type| in |policies| and false | |
| 217 // otherwise. | |
| 218 bool HasDefaultSearchPolicy(const PolicyMap* policies, | |
| 219 ConfigurationPolicyType policy_type); | |
| 220 | |
| 221 // Returns true if any default search policies are specified in |policies| and | |
| 222 // false otherwise. | |
| 223 bool AnyDefaultSearchPoliciesSpecified(const PolicyMap* policies); | |
| 224 | |
| 225 // Returns true if the default search provider is disabled and false | |
| 226 // otherwise. | |
| 227 bool DefaultSearchProviderIsDisabled(const PolicyMap* policies); | |
| 228 | |
| 229 // Returns true if the default search URL was set and is valid and false | |
| 230 // otherwise. | |
| 231 bool DefaultSearchURLIsValid(const PolicyMap* policies); | |
| 232 | |
| 233 // Make sure that the |path| if present in |prefs_|. If not, set it to | |
| 234 // a blank string. | |
| 235 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); | |
| 236 | |
| 237 // The ConfigurationPolicyHandler handlers for each default search policy. | |
| 238 HandlerList handlers_; | |
| 239 | |
| 240 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); | |
| 241 }; | |
| 242 | |
| 243 | |
| 244 // ConfigurationPolicyHandler for the proxy policies. | |
| 245 class ProxyPolicyHandler : public ConfigurationPolicyHandler { | |
| 246 public: | |
| 247 ProxyPolicyHandler(); | |
| 248 virtual ~ProxyPolicyHandler(); | |
| 249 | |
| 250 // ConfigurationPolicyHandler methods: | |
| 251 virtual bool CheckPolicySettings(const PolicyMap* policies, | |
| 252 PolicyErrorMap* errors) OVERRIDE; | |
| 253 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
| 254 PrefValueMap* prefs) OVERRIDE; | |
| 255 | |
| 256 private: | |
| 257 const Value* GetProxyPolicyValue(const PolicyMap* policies, | |
| 258 ConfigurationPolicyType policy); | |
| 259 | |
| 260 // Converts the deprecated ProxyServerMode policy value to a ProxyMode value | |
| 261 // and places the result in |mode_value|. Returns true if the conversion | |
| 262 // succeeded and false otherwise. | |
| 263 bool CheckProxyModeAndServerMode(const PolicyMap* policies, | |
| 264 PolicyErrorMap* errors, | |
| 265 std::string* mode_value); | |
| 266 | |
| 267 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler); | |
| 268 }; | |
| 269 | |
| 270 | |
| 271 // Helper classes -------------------------------------------------------------- | |
| 272 | |
| 273 | |
| 274 // Implementation of SearchTermsData just for validation. | |
| 275 class SearchTermsDataForValidation : public SearchTermsData { | |
| 276 public: | |
| 277 SearchTermsDataForValidation() {} | |
| 278 | |
| 279 // Implementation of SearchTermsData. | |
| 280 virtual std::string GoogleBaseURLValue() const { | |
| 281 return "http://www.google.com/"; | |
| 282 } | |
| 283 virtual std::string GetApplicationLocale() const { | |
| 284 return "en"; | |
| 285 } | |
| 286 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | |
| 287 virtual string16 GetRlzParameterValue() const { | |
| 288 return string16(); | |
| 289 } | |
| 290 #endif | |
| 291 private: | |
| 292 DISALLOW_COPY_AND_ASSIGN(SearchTermsDataForValidation); | |
| 293 }; | |
| 294 | |
| 295 | |
| 296 // This is used to check whether for a given ProxyMode value, the ProxyPacUrl, | |
| 297 // the ProxyBypassList and the ProxyServer policies are allowed to be specified. | |
| 298 // |error_message_id| is the message id of the localized error message to show | |
| 299 // when the policies are not specified as allowed. Each value of ProxyMode | |
| 300 // has a ProxyModeValidationEntry in the |kProxyModeValidationMap| below. | |
| 301 struct ProxyModeValidationEntry { | |
| 302 const char* mode_value; | |
| 303 bool pac_url_allowed; | |
| 304 bool bypass_list_allowed; | |
| 305 bool server_allowed; | |
| 306 int error_message_id; | |
| 307 }; | |
| 308 | |
| 309 | |
| 310 // Maps a policy type to a preference path, and to the expected value type. | |
| 311 // This is the entry type of |kSimplePolicyMap| below. | |
| 312 struct PolicyToPreferenceMapEntry { | |
| 313 base::Value::Type value_type; | |
| 314 ConfigurationPolicyType policy_type; | |
| 315 const char* preference_path; | |
| 316 }; | |
| 317 | |
| 318 | |
| 319 // Static data ----------------------------------------------------------------- | |
| 320 | |
| 321 | |
| 322 // List of policy types to preference names. This is used for simple policies | |
| 323 // that directly map to a single preference. | |
| 324 const PolicyToPreferenceMapEntry kSimplePolicyMap[] = { | |
| 325 { Value::TYPE_STRING, kPolicyHomepageLocation, prefs::kHomePage }, | |
| 326 { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage, | |
| 327 prefs::kHomePageIsNewTabPage }, | |
| 328 { Value::TYPE_INTEGER, kPolicyRestoreOnStartup, | |
| 329 prefs::kRestoreOnStartup}, | |
| 330 { Value::TYPE_LIST, kPolicyRestoreOnStartupURLs, | |
| 331 prefs::kURLsToRestoreOnStartup }, | |
| 332 { Value::TYPE_BOOLEAN, kPolicyAlternateErrorPagesEnabled, | |
| 333 prefs::kAlternateErrorPagesEnabled }, | |
| 334 { Value::TYPE_BOOLEAN, kPolicySearchSuggestEnabled, | |
| 335 prefs::kSearchSuggestEnabled }, | |
| 336 { Value::TYPE_BOOLEAN, kPolicyDnsPrefetchingEnabled, | |
| 337 prefs::kNetworkPredictionEnabled }, | |
| 338 { Value::TYPE_BOOLEAN, kPolicyDisableSpdy, | |
| 339 prefs::kDisableSpdy }, | |
| 340 { Value::TYPE_LIST, kPolicyDisabledSchemes, | |
| 341 prefs::kDisabledSchemes }, | |
| 342 { Value::TYPE_BOOLEAN, kPolicySafeBrowsingEnabled, | |
| 343 prefs::kSafeBrowsingEnabled }, | |
| 344 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerEnabled, | |
| 345 prefs::kPasswordManagerEnabled }, | |
| 346 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerAllowShowPasswords, | |
| 347 prefs::kPasswordManagerAllowShowPasswords }, | |
| 348 { Value::TYPE_BOOLEAN, kPolicyPrintingEnabled, | |
| 349 prefs::kPrintingEnabled }, | |
| 350 { Value::TYPE_BOOLEAN, kPolicyMetricsReportingEnabled, | |
| 351 prefs::kMetricsReportingEnabled }, | |
| 352 { Value::TYPE_STRING, kPolicyApplicationLocaleValue, | |
| 353 prefs::kApplicationLocale}, | |
| 354 { Value::TYPE_LIST, kPolicyExtensionInstallWhitelist, | |
| 355 prefs::kExtensionInstallAllowList}, | |
| 356 { Value::TYPE_LIST, kPolicyExtensionInstallBlacklist, | |
| 357 prefs::kExtensionInstallDenyList}, | |
| 358 { Value::TYPE_LIST, kPolicyExtensionInstallForcelist, | |
| 359 prefs::kExtensionInstallForceList}, | |
| 360 { Value::TYPE_LIST, kPolicyDisabledPlugins, | |
| 361 prefs::kPluginsDisabledPlugins}, | |
| 362 { Value::TYPE_LIST, kPolicyDisabledPluginsExceptions, | |
| 363 prefs::kPluginsDisabledPluginsExceptions}, | |
| 364 { Value::TYPE_LIST, kPolicyEnabledPlugins, | |
| 365 prefs::kPluginsEnabledPlugins}, | |
| 366 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton, | |
| 367 prefs::kShowHomeButton }, | |
| 368 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled, | |
| 369 prefs::kWebKitJavascriptEnabled }, | |
| 370 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, | |
| 371 prefs::kSavingBrowserHistoryDisabled }, | |
| 372 { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit, | |
| 373 prefs::kClearSiteDataOnExit }, | |
| 374 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled, | |
| 375 prefs::kDevToolsDisabled }, | |
| 376 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies, | |
| 377 prefs::kBlockThirdPartyCookies }, | |
| 378 { Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting, | |
| 379 prefs::kManagedDefaultCookiesSetting }, | |
| 380 { Value::TYPE_INTEGER, kPolicyDefaultImagesSetting, | |
| 381 prefs::kManagedDefaultImagesSetting }, | |
| 382 { Value::TYPE_INTEGER, kPolicyDefaultJavaScriptSetting, | |
| 383 prefs::kManagedDefaultJavaScriptSetting }, | |
| 384 { Value::TYPE_INTEGER, kPolicyDefaultPluginsSetting, | |
| 385 prefs::kManagedDefaultPluginsSetting }, | |
| 386 { Value::TYPE_INTEGER, kPolicyDefaultPopupsSetting, | |
| 387 prefs::kManagedDefaultPopupsSetting }, | |
| 388 { Value::TYPE_LIST, kPolicyAutoSelectCertificateForUrls, | |
| 389 prefs::kManagedAutoSelectCertificateForUrls}, | |
| 390 { Value::TYPE_LIST, kPolicyCookiesAllowedForUrls, | |
| 391 prefs::kManagedCookiesAllowedForUrls }, | |
| 392 { Value::TYPE_LIST, kPolicyCookiesBlockedForUrls, | |
| 393 prefs::kManagedCookiesBlockedForUrls }, | |
| 394 { Value::TYPE_LIST, kPolicyCookiesSessionOnlyForUrls, | |
| 395 prefs::kManagedCookiesSessionOnlyForUrls }, | |
| 396 { Value::TYPE_LIST, kPolicyImagesAllowedForUrls, | |
| 397 prefs::kManagedImagesAllowedForUrls }, | |
| 398 { Value::TYPE_LIST, kPolicyImagesBlockedForUrls, | |
| 399 prefs::kManagedImagesBlockedForUrls }, | |
| 400 { Value::TYPE_LIST, kPolicyJavaScriptAllowedForUrls, | |
| 401 prefs::kManagedJavaScriptAllowedForUrls }, | |
| 402 { Value::TYPE_LIST, kPolicyJavaScriptBlockedForUrls, | |
| 403 prefs::kManagedJavaScriptBlockedForUrls }, | |
| 404 { Value::TYPE_LIST, kPolicyPluginsAllowedForUrls, | |
| 405 prefs::kManagedPluginsAllowedForUrls }, | |
| 406 { Value::TYPE_LIST, kPolicyPluginsBlockedForUrls, | |
| 407 prefs::kManagedPluginsBlockedForUrls }, | |
| 408 { Value::TYPE_LIST, kPolicyPopupsAllowedForUrls, | |
| 409 prefs::kManagedPopupsAllowedForUrls }, | |
| 410 { Value::TYPE_LIST, kPolicyPopupsBlockedForUrls, | |
| 411 prefs::kManagedPopupsBlockedForUrls }, | |
| 412 { Value::TYPE_LIST, kPolicyNotificationsAllowedForUrls, | |
| 413 prefs::kManagedNotificationsAllowedForUrls }, | |
| 414 { Value::TYPE_LIST, kPolicyNotificationsBlockedForUrls, | |
| 415 prefs::kManagedNotificationsBlockedForUrls }, | |
| 416 { Value::TYPE_INTEGER, kPolicyDefaultNotificationsSetting, | |
| 417 prefs::kManagedDefaultNotificationsSetting }, | |
| 418 { Value::TYPE_INTEGER, kPolicyDefaultGeolocationSetting, | |
| 419 prefs::kManagedDefaultGeolocationSetting }, | |
| 420 { Value::TYPE_STRING, kPolicyAuthSchemes, | |
| 421 prefs::kAuthSchemes }, | |
| 422 { Value::TYPE_BOOLEAN, kPolicyDisableAuthNegotiateCnameLookup, | |
| 423 prefs::kDisableAuthNegotiateCnameLookup }, | |
| 424 { Value::TYPE_BOOLEAN, kPolicyEnableAuthNegotiatePort, | |
| 425 prefs::kEnableAuthNegotiatePort }, | |
| 426 { Value::TYPE_STRING, kPolicyAuthServerWhitelist, | |
| 427 prefs::kAuthServerWhitelist }, | |
| 428 { Value::TYPE_STRING, kPolicyAuthNegotiateDelegateWhitelist, | |
| 429 prefs::kAuthNegotiateDelegateWhitelist }, | |
| 430 { Value::TYPE_STRING, kPolicyGSSAPILibraryName, | |
| 431 prefs::kGSSAPILibraryName }, | |
| 432 { Value::TYPE_BOOLEAN, kPolicyAllowCrossOriginAuthPrompt, | |
| 433 prefs::kAllowCrossOriginAuthPrompt }, | |
| 434 { Value::TYPE_BOOLEAN, kPolicyDisable3DAPIs, | |
| 435 prefs::kDisable3DAPIs }, | |
| 436 { Value::TYPE_BOOLEAN, kPolicyDisablePluginFinder, | |
| 437 prefs::kDisablePluginFinder }, | |
| 438 { Value::TYPE_INTEGER, kPolicyPolicyRefreshRate, | |
| 439 prefs::kUserPolicyRefreshRate }, | |
| 440 { Value::TYPE_INTEGER, kPolicyDevicePolicyRefreshRate, | |
| 441 prefs::kDevicePolicyRefreshRate }, | |
| 442 { Value::TYPE_BOOLEAN, kPolicyInstantEnabled, prefs::kInstantEnabled }, | |
| 443 { Value::TYPE_BOOLEAN, kPolicyDefaultBrowserSettingEnabled, | |
| 444 prefs::kDefaultBrowserSettingEnabled }, | |
| 445 { Value::TYPE_BOOLEAN, kPolicyRemoteAccessClientFirewallTraversal, | |
| 446 prefs::kRemoteAccessClientFirewallTraversal }, | |
| 447 { Value::TYPE_BOOLEAN, kPolicyRemoteAccessHostFirewallTraversal, | |
| 448 prefs::kRemoteAccessHostFirewallTraversal }, | |
| 449 { Value::TYPE_BOOLEAN, kPolicyCloudPrintProxyEnabled, | |
| 450 prefs::kCloudPrintProxyEnabled }, | |
| 451 { Value::TYPE_BOOLEAN, kPolicyTranslateEnabled, prefs::kEnableTranslate }, | |
| 452 { Value::TYPE_BOOLEAN, kPolicyAllowOutdatedPlugins, | |
| 453 prefs::kPluginsAllowOutdated }, | |
| 454 { Value::TYPE_BOOLEAN, kPolicyAlwaysAuthorizePlugins, | |
| 455 prefs::kPluginsAlwaysAuthorize }, | |
| 456 { Value::TYPE_BOOLEAN, kPolicyBookmarkBarEnabled, | |
| 457 prefs::kShowBookmarkBar }, | |
| 458 { Value::TYPE_BOOLEAN, kPolicyEditBookmarksEnabled, | |
| 459 prefs::kEditBookmarksEnabled }, | |
| 460 { Value::TYPE_BOOLEAN, kPolicyAllowFileSelectionDialogs, | |
| 461 prefs::kAllowFileSelectionDialogs }, | |
| 462 { Value::TYPE_BOOLEAN, kPolicyImportBookmarks, | |
| 463 prefs::kImportBookmarks}, | |
| 464 { Value::TYPE_BOOLEAN, kPolicyImportHistory, | |
| 465 prefs::kImportHistory}, | |
| 466 { Value::TYPE_BOOLEAN, kPolicyImportHomepage, | |
| 467 prefs::kImportHomepage}, | |
| 468 { Value::TYPE_BOOLEAN, kPolicyImportSearchEngine, | |
| 469 prefs::kImportSearchEngine }, | |
| 470 { Value::TYPE_BOOLEAN, kPolicyImportSavedPasswords, | |
| 471 prefs::kImportSavedPasswords }, | |
| 472 { Value::TYPE_INTEGER, kPolicyMaxConnectionsPerProxy, | |
| 473 prefs::kMaxConnectionsPerProxy }, | |
| 474 { Value::TYPE_BOOLEAN, kPolicyHideWebStorePromo, | |
| 475 prefs::kNTPHideWebStorePromo }, | |
| 476 { Value::TYPE_LIST, kPolicyURLBlacklist, | |
| 477 prefs::kUrlBlacklist }, | |
| 478 { Value::TYPE_LIST, kPolicyURLWhitelist, | |
| 479 prefs::kUrlWhitelist }, | |
| 480 | |
| 481 #if defined(OS_CHROMEOS) | |
| 482 { Value::TYPE_BOOLEAN, kPolicyChromeOsLockOnIdleSuspend, | |
| 483 prefs::kEnableScreenLock }, | |
| 484 { Value::TYPE_STRING, kPolicyChromeOsReleaseChannel, | |
| 485 prefs::kChromeOsReleaseChannel }, | |
| 486 #endif | |
| 487 }; | |
| 488 | |
| 489 // List of policy types to preference names, for policies affecting the default | |
| 490 // search provider. | |
| 491 const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[] = { | |
| 492 { Value::TYPE_BOOLEAN, kPolicyDefaultSearchProviderEnabled, | |
| 493 prefs::kDefaultSearchProviderEnabled }, | |
| 494 { Value::TYPE_STRING, kPolicyDefaultSearchProviderName, | |
| 495 prefs::kDefaultSearchProviderName }, | |
| 496 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword, | |
| 497 prefs::kDefaultSearchProviderKeyword }, | |
| 498 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL, | |
| 499 prefs::kDefaultSearchProviderSearchURL }, | |
| 500 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL, | |
| 501 prefs::kDefaultSearchProviderSuggestURL }, | |
| 502 { Value::TYPE_STRING, kPolicyDefaultSearchProviderInstantURL, | |
| 503 prefs::kDefaultSearchProviderInstantURL }, | |
| 504 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL, | |
| 505 prefs::kDefaultSearchProviderIconURL }, | |
| 506 { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings, | |
| 507 prefs::kDefaultSearchProviderEncodings }, | |
| 508 }; | |
| 509 | |
| 510 // List of entries determining which proxy policies can be specified, depending | |
| 511 // on the ProxyMode. | |
| 512 const ProxyModeValidationEntry kProxyModeValidationMap[] = { | |
| 513 { ProxyPrefs::kDirectProxyModeName, | |
| 514 false, false, false, IDS_POLICY_PROXY_MODE_DISABLED_ERROR }, | |
| 515 { ProxyPrefs::kAutoDetectProxyModeName, | |
| 516 false, false, false, IDS_POLICY_PROXY_MODE_AUTO_DETECT_ERROR }, | |
| 517 { ProxyPrefs::kPacScriptProxyModeName, | |
| 518 true, false, false, IDS_POLICY_PROXY_MODE_PAC_URL_ERROR }, | |
| 519 { ProxyPrefs::kFixedServersProxyModeName, | |
| 520 false, true, true, IDS_POLICY_PROXY_MODE_FIXED_SERVERS_ERROR }, | |
| 521 { ProxyPrefs::kSystemProxyModeName, | |
| 522 false, false, false, IDS_POLICY_PROXY_MODE_SYSTEM_ERROR }, | |
| 523 }; | |
| 524 | |
| 525 | |
| 526 // Helper functions ------------------------------------------------------------ | |
| 527 | |
| 528 | |
| 529 std::string ValueTypeToString(Value::Type type) { | |
| 530 static const char* strings[] = { | |
| 531 "null", | |
| 532 "boolean", | |
| 533 "integer", | |
| 534 "double", | |
| 535 "string", | |
| 536 "binary", | |
| 537 "dictionary", | |
| 538 "list" | |
| 539 }; | |
| 540 DCHECK(static_cast<size_t>(type) < arraysize(strings)); | |
| 541 return std::string(strings[type]); | |
| 542 } | |
| 543 | |
| 544 | |
| 545 // TypeCheckingPolicyHandler implementation ------------------------------------ | |
| 546 | |
| 547 | |
| 548 TypeCheckingPolicyHandler::TypeCheckingPolicyHandler( | |
| 549 ConfigurationPolicyType policy_type, | |
| 550 Value::Type value_type) | |
| 551 : policy_type_(policy_type), | |
| 552 value_type_(value_type) { | |
| 553 } | |
| 554 | |
| 555 TypeCheckingPolicyHandler::~TypeCheckingPolicyHandler() { | |
| 556 } | |
| 557 | |
| 558 ConfigurationPolicyType TypeCheckingPolicyHandler::policy_type() const { | |
| 559 return policy_type_; | |
| 560 } | |
| 561 | |
| 562 bool TypeCheckingPolicyHandler::CheckPolicySettings(const PolicyMap* policies, | |
| 563 PolicyErrorMap* errors) { | |
| 564 const Value* value = policies->Get(policy_type_); | |
| 565 if (value && value_type_ != value->GetType()) { | |
| 566 errors->AddError(policy_type_, | |
| 567 IDS_POLICY_TYPE_ERROR, ValueTypeToString(value_type_)); | |
| 568 return false; | |
| 569 } | |
| 570 return true; | |
| 571 } | |
| 572 | |
| 573 | |
| 574 // SimplePolicyHandler implementation ------------------------------------------ | |
| 575 | |
| 576 | |
| 577 SimplePolicyHandler::SimplePolicyHandler( | |
| 578 ConfigurationPolicyType policy_type, | |
| 579 Value::Type value_type, | |
| 580 const char* pref_path) | |
| 581 : TypeCheckingPolicyHandler(policy_type, value_type), | |
| 582 pref_path_(pref_path) { | |
| 583 } | |
| 584 | |
| 585 SimplePolicyHandler::~SimplePolicyHandler() { | |
| 586 } | |
| 587 | |
| 588 void SimplePolicyHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 589 PrefValueMap* prefs) { | |
| 590 const Value* value = policies->Get(policy_type()); | |
| 591 if (value) | |
| 592 prefs->SetValue(pref_path_, value->DeepCopy()); | |
| 593 } | |
| 594 | |
| 595 | |
| 596 // SyncPolicyHandler implementation -------------------------------------------- | |
| 597 | |
| 598 | |
| 599 SyncPolicyHandler::SyncPolicyHandler() | |
| 600 : TypeCheckingPolicyHandler(kPolicySyncDisabled, | |
| 601 Value::TYPE_BOOLEAN) { | |
| 602 } | |
| 603 | |
| 604 SyncPolicyHandler::~SyncPolicyHandler() { | |
| 605 } | |
| 606 | |
| 607 void SyncPolicyHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 608 PrefValueMap* prefs) { | |
| 609 const Value* value = policies->Get(policy_type()); | |
| 610 bool disable_sync; | |
| 611 if (value && value->GetAsBoolean(&disable_sync) && disable_sync) | |
| 612 prefs->SetValue(prefs::kSyncManaged, value->DeepCopy()); | |
| 613 } | |
| 614 | |
| 615 | |
| 616 // AutofillPolicyHandler implementation ---------------------------------------- | |
| 617 | |
| 618 | |
| 619 AutofillPolicyHandler::AutofillPolicyHandler() | |
| 620 : TypeCheckingPolicyHandler(kPolicyAutoFillEnabled, | |
| 621 Value::TYPE_BOOLEAN) { | |
| 622 } | |
| 623 | |
| 624 AutofillPolicyHandler::~AutofillPolicyHandler() { | |
| 625 } | |
| 626 | |
| 627 void AutofillPolicyHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 628 PrefValueMap* prefs) { | |
| 629 const Value* value = policies->Get(policy_type()); | |
| 630 bool auto_fill_enabled; | |
| 631 if (value && value->GetAsBoolean(&auto_fill_enabled) && !auto_fill_enabled) { | |
| 632 prefs->SetValue(prefs::kAutofillEnabled, | |
| 633 Value::CreateBooleanValue(false)); | |
| 634 } | |
| 635 } | |
| 636 | |
| 637 | |
| 638 // DownloadDirPolicyHandler implementation ------------------------------------- | |
| 639 | |
| 640 | |
| 641 DownloadDirPolicyHandler::DownloadDirPolicyHandler() | |
| 642 : TypeCheckingPolicyHandler(kPolicyDownloadDirectory, | |
| 643 Value::TYPE_STRING) { | |
| 644 } | |
| 645 | |
| 646 DownloadDirPolicyHandler::~DownloadDirPolicyHandler() { | |
| 647 } | |
| 648 | |
| 649 void DownloadDirPolicyHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 650 PrefValueMap* prefs) { | |
| 651 const Value* value = policies->Get(policy_type()); | |
| 652 FilePath::StringType string_value; | |
| 653 if (!value || !value->GetAsString(&string_value)) | |
| 654 return; | |
| 655 | |
| 656 FilePath::StringType expanded_value = | |
| 657 policy::path_parser::ExpandPathVariables(string_value); | |
| 658 // Make sure the path isn't empty, since that will point to an undefined | |
| 659 // location; the default location is used instead in that case. | |
| 660 // This is checked after path expansion because a non-empty policy value can | |
| 661 // lead to an empty path value after expansion (e.g. "\"\""). | |
| 662 if (expanded_value.empty()) | |
| 663 expanded_value = download_util::GetDefaultDownloadDirectory().value(); | |
| 664 prefs->SetValue(prefs::kDownloadDefaultDirectory, | |
| 665 Value::CreateStringValue(expanded_value)); | |
| 666 prefs->SetValue(prefs::kPromptForDownload, | |
| 667 Value::CreateBooleanValue(false)); | |
| 668 } | |
| 669 | |
| 670 | |
| 671 // DiskCacheDirPolicyHandler implementation ------------------------------------ | |
| 672 | |
| 673 | |
| 674 DiskCacheDirPolicyHandler::DiskCacheDirPolicyHandler() | |
| 675 : TypeCheckingPolicyHandler(kPolicyDiskCacheDir, | |
| 676 Value::TYPE_STRING) { | |
| 677 } | |
| 678 | |
| 679 DiskCacheDirPolicyHandler::~DiskCacheDirPolicyHandler() { | |
| 680 } | |
| 681 | |
| 682 void DiskCacheDirPolicyHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 683 PrefValueMap* prefs) { | |
| 684 const Value* value = policies->Get(policy_type()); | |
| 685 FilePath::StringType string_value; | |
| 686 if (value && value->GetAsString(&string_value)) { | |
| 687 FilePath::StringType expanded_value = | |
| 688 policy::path_parser::ExpandPathVariables(string_value); | |
| 689 prefs->SetValue(prefs::kDiskCacheDir, | |
| 690 Value::CreateStringValue(expanded_value)); | |
| 691 } | |
| 692 } | |
| 693 | |
| 694 | |
| 695 // FileSelectionDialogsHandler implementation ---------------------------------- | |
| 696 | |
| 697 | |
| 698 FileSelectionDialogsHandler::FileSelectionDialogsHandler() | |
| 699 : TypeCheckingPolicyHandler(kPolicyAllowFileSelectionDialogs, | |
| 700 Value::TYPE_BOOLEAN) { | |
| 701 } | |
| 702 | |
| 703 FileSelectionDialogsHandler::~FileSelectionDialogsHandler() { | |
| 704 } | |
| 705 | |
| 706 void FileSelectionDialogsHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 707 PrefValueMap* prefs) { | |
| 708 bool allow_dialogs; | |
| 709 const Value* value = policies->Get(policy_type()); | |
| 710 if (value && value->GetAsBoolean(&allow_dialogs)) { | |
| 711 prefs->SetValue(prefs::kAllowFileSelectionDialogs, | |
| 712 Value::CreateBooleanValue(allow_dialogs)); | |
| 713 // Disallow selecting the download location if file dialogs are disabled. | |
| 714 if (!allow_dialogs) { | |
| 715 prefs->SetValue(prefs::kPromptForDownload, | |
| 716 Value::CreateBooleanValue(false)); | |
| 717 } | |
| 718 } | |
| 719 } | |
| 720 | |
| 721 | |
| 722 // IncognitoModePolicyHandler implementation ----------------------------------- | |
| 723 | |
| 724 | |
| 725 IncognitoModePolicyHandler::IncognitoModePolicyHandler() { | |
| 726 } | |
| 727 | |
| 728 IncognitoModePolicyHandler::~IncognitoModePolicyHandler() { | |
| 729 } | |
| 730 | |
| 731 bool IncognitoModePolicyHandler::CheckPolicySettings(const PolicyMap* policies, | |
| 732 PolicyErrorMap* errors) { | |
| 733 int int_value = IncognitoModePrefs::ENABLED; | |
| 734 const Value* availability = policies->Get(kPolicyIncognitoModeAvailability); | |
| 735 | |
| 736 if (availability) { | |
| 737 if (availability->GetAsInteger(&int_value)) { | |
| 738 IncognitoModePrefs::Availability availability_enum_value; | |
| 739 if (!IncognitoModePrefs::IntToAvailability(int_value, | |
| 740 &availability_enum_value)) { | |
| 741 errors->AddError(kPolicyIncognitoModeAvailability, | |
| 742 IDS_POLICY_OUT_OF_RANGE_ERROR, | |
| 743 base::IntToString(int_value)); | |
| 744 return false; | |
| 745 } | |
| 746 } else { | |
| 747 errors->AddError(kPolicyIncognitoModeAvailability, | |
| 748 IDS_POLICY_TYPE_ERROR, | |
| 749 ValueTypeToString(Value::TYPE_INTEGER)); | |
| 750 return false; | |
| 751 } | |
| 752 } else { | |
| 753 const Value* deprecated_enabled = policies->Get(kPolicyIncognitoEnabled); | |
| 754 if (deprecated_enabled && | |
| 755 !deprecated_enabled->IsType(Value::TYPE_BOOLEAN)) { | |
| 756 errors->AddError(kPolicyIncognitoEnabled, | |
| 757 IDS_POLICY_TYPE_ERROR, | |
| 758 ValueTypeToString(Value::TYPE_BOOLEAN)); | |
| 759 return false; | |
| 760 } | |
| 761 } | |
| 762 return true; | |
| 763 } | |
| 764 | |
| 765 void IncognitoModePolicyHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 766 PrefValueMap* prefs) { | |
| 767 const Value* availability = policies->Get(kPolicyIncognitoModeAvailability); | |
| 768 const Value* deprecated_enabled = policies->Get(kPolicyIncognitoEnabled); | |
| 769 if (availability) { | |
| 770 int int_value = IncognitoModePrefs::ENABLED; | |
| 771 IncognitoModePrefs::Availability availability_enum_value; | |
| 772 if (availability->GetAsInteger(&int_value) && | |
| 773 IncognitoModePrefs::IntToAvailability(int_value, | |
| 774 &availability_enum_value)) { | |
| 775 prefs->SetValue(prefs::kIncognitoModeAvailability, | |
| 776 Value::CreateIntegerValue(availability_enum_value)); | |
| 777 } else { | |
| 778 NOTREACHED(); | |
| 779 } | |
| 780 } else if (deprecated_enabled) { | |
| 781 // If kPolicyIncognitoModeAvailability is not specified, check the obsolete | |
| 782 // kPolicyIncognitoEnabled. | |
| 783 bool enabled = true; | |
| 784 if (deprecated_enabled->GetAsBoolean(&enabled)) { | |
| 785 prefs->SetInteger(prefs::kIncognitoModeAvailability, | |
| 786 enabled ? IncognitoModePrefs::ENABLED : | |
| 787 IncognitoModePrefs::DISABLED); | |
| 788 } else { | |
| 789 NOTREACHED(); | |
| 790 } | |
| 791 } | |
| 792 } | |
| 793 | |
| 794 | |
| 795 // DefaultSearchEncodingsPolicyHandler implementation -------------------------- | |
| 796 | |
| 797 | |
| 798 DefaultSearchEncodingsPolicyHandler::DefaultSearchEncodingsPolicyHandler() | |
| 799 : TypeCheckingPolicyHandler(kPolicyDefaultSearchProviderEncodings, | |
| 800 Value::TYPE_LIST) { | |
| 801 } | |
| 802 | |
| 803 DefaultSearchEncodingsPolicyHandler::~DefaultSearchEncodingsPolicyHandler() { | |
| 804 } | |
| 805 | |
| 806 void DefaultSearchEncodingsPolicyHandler::ApplyPolicySettings( | |
| 807 const PolicyMap* policies, PrefValueMap* prefs) { | |
| 808 // The DefaultSearchProviderEncodings policy has type list, but the related | |
| 809 // preference has type string. Convert one into the other here, using | |
| 810 // ';' as a separator. | |
| 811 const Value* value = policies->Get(policy_type()); | |
| 812 const ListValue* list; | |
| 813 if (!value || !value->GetAsList(&list)) | |
| 814 return; | |
| 815 | |
| 816 ListValue::const_iterator iter(list->begin()); | |
| 817 ListValue::const_iterator end(list->end()); | |
| 818 std::vector<std::string> string_parts; | |
| 819 for (; iter != end; ++iter) { | |
| 820 std::string s; | |
| 821 if ((*iter)->GetAsString(&s)) { | |
| 822 string_parts.push_back(s); | |
| 823 } | |
| 824 } | |
| 825 std::string encodings = JoinString(string_parts, ';'); | |
| 826 prefs->SetValue(prefs::kDefaultSearchProviderEncodings, | |
| 827 Value::CreateStringValue(encodings)); | |
| 828 } | |
| 829 | |
| 830 | |
| 831 // DefaultSearchPolicyHandler implementation ----------------------------------- | |
| 832 | |
| 833 | |
| 834 DefaultSearchPolicyHandler::DefaultSearchPolicyHandler() { | |
| 835 for (size_t i = 0; i < arraysize(kDefaultSearchPolicyMap); ++i) { | |
| 836 ConfigurationPolicyType policy_type = | |
| 837 kDefaultSearchPolicyMap[i].policy_type; | |
| 838 if (policy_type == kPolicyDefaultSearchProviderEncodings) { | |
| 839 handlers_.push_back(new DefaultSearchEncodingsPolicyHandler()); | |
| 840 } else { | |
| 841 handlers_.push_back( | |
| 842 new SimplePolicyHandler(policy_type, | |
| 843 kDefaultSearchPolicyMap[i].value_type, | |
| 844 kDefaultSearchPolicyMap[i].preference_path)); | |
| 845 } | |
| 846 } | |
| 847 } | |
| 848 | |
| 849 DefaultSearchPolicyHandler::~DefaultSearchPolicyHandler() { | |
| 850 STLDeleteElements(&handlers_); | |
| 851 } | |
| 852 | |
| 853 bool DefaultSearchPolicyHandler::CheckPolicySettings(const PolicyMap* policies, | |
| 854 PolicyErrorMap* errors) { | |
| 855 if (!CheckIndividualPolicies(policies, errors)) | |
| 856 return false; | |
| 857 | |
| 858 if (DefaultSearchProviderIsDisabled(policies)) { | |
| 859 // Add an error for all specified default search policies except | |
| 860 // DefaultSearchProviderEnabled. | |
| 861 for (size_t i = 0; i < arraysize(kDefaultSearchPolicyMap); ++i) { | |
| 862 ConfigurationPolicyType policy_type = | |
| 863 kDefaultSearchPolicyMap[i].policy_type; | |
| 864 if (policy_type != kPolicyDefaultSearchProviderEnabled && | |
| 865 HasDefaultSearchPolicy(policies, policy_type)) { | |
| 866 errors->AddError(policy_type, IDS_POLICY_DEFAULT_SEARCH_DISABLED); | |
| 867 } | |
| 868 } | |
| 869 return true; | |
| 870 } | |
| 871 | |
| 872 const Value* search_url = | |
| 873 policies->Get(kPolicyDefaultSearchProviderSearchURL); | |
| 874 if (!search_url && AnyDefaultSearchPoliciesSpecified(policies)) { | |
| 875 errors->AddError(kPolicyDefaultSearchProviderSearchURL, | |
| 876 IDS_POLICY_NOT_SPECIFIED_ERROR); | |
| 877 return false; | |
| 878 } | |
| 879 | |
| 880 if (search_url && !DefaultSearchURLIsValid(policies)) { | |
| 881 errors->AddError(kPolicyDefaultSearchProviderSearchURL, | |
| 882 IDS_POLICY_INVALID_SEARCH_URL_ERROR); | |
| 883 return false; | |
| 884 } | |
| 885 return true; | |
| 886 } | |
| 887 | |
| 888 void DefaultSearchPolicyHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 889 PrefValueMap* prefs) { | |
| 890 if (DefaultSearchProviderIsDisabled(policies)) { | |
| 891 // If default search is disabled, the other fields are ignored. | |
| 892 prefs->SetString(prefs::kDefaultSearchProviderName, std::string()); | |
| 893 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); | |
| 894 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); | |
| 895 prefs->SetString(prefs::kDefaultSearchProviderIconURL, std::string()); | |
| 896 prefs->SetString(prefs::kDefaultSearchProviderEncodings, std::string()); | |
| 897 prefs->SetString(prefs::kDefaultSearchProviderKeyword, std::string()); | |
| 898 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, std::string()); | |
| 899 return; | |
| 900 } | |
| 901 | |
| 902 const Value* search_url = | |
| 903 policies->Get(kPolicyDefaultSearchProviderSearchURL); | |
| 904 // The search URL is required. | |
| 905 if (!search_url) | |
| 906 return; | |
| 907 | |
| 908 // The other entries are optional. Just make sure that they are all | |
| 909 // specified via policy, so that the regular prefs aren't used. | |
| 910 if (DefaultSearchURLIsValid(policies)) { | |
| 911 PrefValueMap tmp_prefs; | |
|
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
Since we don't bail out here, we can just fill in
Joao da Silva
2011/10/11 15:09:23
Done.
| |
| 912 HandlerList::const_iterator handler = handlers_.begin(); | |
| 913 for ( ; handler != handlers_.end(); ++handler) | |
| 914 (*handler)->ApplyPolicySettings(policies, &tmp_prefs); | |
| 915 | |
| 916 EnsureStringPrefExists(&tmp_prefs, prefs::kDefaultSearchProviderSuggestURL); | |
| 917 EnsureStringPrefExists(&tmp_prefs, prefs::kDefaultSearchProviderIconURL); | |
| 918 EnsureStringPrefExists(&tmp_prefs, prefs::kDefaultSearchProviderEncodings); | |
| 919 EnsureStringPrefExists(&tmp_prefs, prefs::kDefaultSearchProviderKeyword); | |
| 920 EnsureStringPrefExists(&tmp_prefs, prefs::kDefaultSearchProviderInstantURL); | |
| 921 | |
| 922 // For the name, default to the host if not specified. | |
| 923 std::string name; | |
| 924 if (!tmp_prefs.GetString(prefs::kDefaultSearchProviderName, &name) || | |
| 925 name.empty()) { | |
| 926 std::string search_url_string; | |
| 927 if (search_url->GetAsString(&search_url_string)) { | |
| 928 tmp_prefs.SetString(prefs::kDefaultSearchProviderName, | |
| 929 GURL(search_url_string).host()); | |
| 930 } | |
| 931 } | |
| 932 | |
| 933 // And clear the IDs since these are not specified via policy. | |
| 934 tmp_prefs.SetString(prefs::kDefaultSearchProviderID, std::string()); | |
| 935 tmp_prefs.SetString(prefs::kDefaultSearchProviderPrepopulateID, | |
| 936 std::string()); | |
|
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
indentation.
Joao da Silva
2011/10/11 15:09:23
Done.
| |
| 937 prefs->MergeFrom(&tmp_prefs); | |
| 938 } | |
| 939 } | |
| 940 | |
| 941 bool DefaultSearchPolicyHandler::CheckIndividualPolicies( | |
| 942 const PolicyMap* policies, PolicyErrorMap* errors) { | |
|
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
break after comma.
Joao da Silva
2011/10/11 15:09:23
Done.
| |
| 943 HandlerList::const_iterator handler = handlers_.begin(); | |
| 944 for ( ; handler != handlers_.end(); ++handler) { | |
| 945 if (!(*handler)->CheckPolicySettings(policies, errors)) | |
| 946 return false; | |
| 947 } | |
| 948 return true; | |
| 949 } | |
| 950 | |
| 951 bool DefaultSearchPolicyHandler::HasDefaultSearchPolicy( | |
| 952 const PolicyMap* policies, ConfigurationPolicyType policy_type) { | |
|
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
break after comma
Joao da Silva
2011/10/11 15:09:23
Done.
| |
| 953 return policies->Get(policy_type) != NULL; | |
| 954 } | |
| 955 | |
| 956 bool DefaultSearchPolicyHandler::AnyDefaultSearchPoliciesSpecified( | |
| 957 const PolicyMap* policies) { | |
| 958 for (size_t i = 0; i < arraysize(kDefaultSearchPolicyMap); ++i) { | |
| 959 if (policies->Get(kDefaultSearchPolicyMap[i].policy_type)) | |
| 960 return true; | |
| 961 } | |
| 962 return false; | |
| 963 } | |
| 964 | |
| 965 bool DefaultSearchPolicyHandler::DefaultSearchProviderIsDisabled( | |
| 966 const PolicyMap* policies) { | |
| 967 const Value* provider_enabled = | |
| 968 policies->Get(kPolicyDefaultSearchProviderEnabled); | |
| 969 bool enabled = true; | |
| 970 return provider_enabled && | |
| 971 provider_enabled->GetAsBoolean(&enabled) && | |
| 972 !enabled; | |
| 973 } | |
| 974 | |
| 975 bool DefaultSearchPolicyHandler::DefaultSearchURLIsValid( | |
| 976 const PolicyMap* policies) { | |
| 977 const Value* search_url = | |
| 978 policies->Get(kPolicyDefaultSearchProviderSearchURL); | |
| 979 if (!search_url) | |
| 980 return false; | |
| 981 | |
| 982 std::string search_url_string; | |
| 983 if (search_url->GetAsString(&search_url_string)) { | |
| 984 SearchTermsDataForValidation search_terms_data; | |
| 985 const TemplateURLRef search_url_ref(search_url_string, 0, 0); | |
| 986 // It must support replacement (which implies it is valid). | |
| 987 return search_url_ref.SupportsReplacementUsingTermsData(search_terms_data); | |
| 988 } | |
| 989 return false; | |
| 990 } | |
| 991 | |
| 992 void DefaultSearchPolicyHandler::EnsureStringPrefExists( | |
| 993 PrefValueMap* prefs, const std::string& path) { | |
|
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
break after comma
Joao da Silva
2011/10/11 15:09:23
Done.
| |
| 994 std::string value; | |
| 995 if (!prefs->GetString(path, &value)) | |
| 996 prefs->SetString(path, value); | |
| 997 } | |
| 998 | |
| 999 | |
| 1000 // ProxyPolicyHandler implementation ------------------------------------------- | |
| 1001 | |
| 1002 | |
| 1003 ProxyPolicyHandler::ProxyPolicyHandler() { | |
| 1004 } | |
| 1005 | |
| 1006 ProxyPolicyHandler::~ProxyPolicyHandler() { | |
| 1007 } | |
| 1008 | |
| 1009 bool ProxyPolicyHandler::CheckPolicySettings(const PolicyMap* policies, | |
| 1010 PolicyErrorMap* errors) { | |
| 1011 const Value* mode = GetProxyPolicyValue(policies, kPolicyProxyMode); | |
| 1012 const Value* server = GetProxyPolicyValue(policies, kPolicyProxyServer); | |
| 1013 const Value* server_mode = | |
| 1014 GetProxyPolicyValue(policies, kPolicyProxyServerMode); | |
| 1015 const Value* pac_url = GetProxyPolicyValue(policies, kPolicyProxyPacUrl); | |
| 1016 const Value* bypass_list = | |
| 1017 GetProxyPolicyValue(policies, kPolicyProxyBypassList); | |
| 1018 | |
| 1019 if ((server || pac_url || bypass_list) && !(mode || server_mode)) { | |
| 1020 errors->AddError(kPolicyProxyMode, | |
| 1021 IDS_POLICY_NOT_SPECIFIED_ERROR); | |
| 1022 return false; | |
| 1023 } | |
| 1024 | |
| 1025 std::string mode_value; | |
| 1026 if (!CheckProxyModeAndServerMode(policies, errors, &mode_value)) | |
| 1027 return false; | |
| 1028 | |
| 1029 // If neither ProxyMode nor ProxyServerMode are specified, mode_value will be | |
| 1030 // empty and the proxy shouldn't be configured at all. | |
|
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
Maybe we should check other proxy policies and add
Joao da Silva
2011/10/11 15:09:23
Line 1019 above checks and reports that.
Mattias Nissler (ping if slow)
2011/10/12 17:10:00
I see.
| |
| 1031 if (mode_value.empty()) | |
| 1032 return true; | |
| 1033 | |
| 1034 bool is_valid_mode = false; | |
| 1035 for (size_t i = 0; i != arraysize(kProxyModeValidationMap); ++i) { | |
| 1036 const ProxyModeValidationEntry& entry = kProxyModeValidationMap[i]; | |
| 1037 if (entry.mode_value != mode_value) | |
| 1038 continue; | |
| 1039 | |
| 1040 is_valid_mode = true; | |
| 1041 | |
| 1042 if (!entry.pac_url_allowed && pac_url) | |
| 1043 errors->AddError(kPolicyProxyPacUrl, entry.error_message_id); | |
| 1044 if (!entry.bypass_list_allowed && bypass_list) | |
| 1045 errors->AddError(kPolicyProxyPacUrl, entry.error_message_id); | |
| 1046 if (!entry.server_allowed && server) | |
| 1047 errors->AddError(kPolicyProxyPacUrl, entry.error_message_id); | |
| 1048 | |
| 1049 if ((!entry.pac_url_allowed && pac_url) || | |
| 1050 (!entry.bypass_list_allowed && bypass_list) || | |
| 1051 (!entry.server_allowed && server)) { | |
| 1052 return false; | |
| 1053 } | |
| 1054 } | |
| 1055 | |
| 1056 if (!is_valid_mode) { | |
| 1057 errors->AddError(mode ? kPolicyProxyMode : kPolicyProxyServerMode, | |
| 1058 IDS_POLICY_OUT_OF_RANGE_ERROR, mode_value); | |
| 1059 return false; | |
| 1060 } | |
| 1061 return true; | |
| 1062 } | |
| 1063 | |
| 1064 void ProxyPolicyHandler::ApplyPolicySettings(const PolicyMap* policies, | |
| 1065 PrefValueMap* prefs) { | |
| 1066 const Value* mode = GetProxyPolicyValue(policies, kPolicyProxyMode); | |
| 1067 const Value* server = GetProxyPolicyValue(policies, kPolicyProxyServer); | |
| 1068 const Value* server_mode = | |
| 1069 GetProxyPolicyValue(policies, kPolicyProxyServerMode); | |
| 1070 const Value* pac_url = GetProxyPolicyValue(policies, kPolicyProxyPacUrl); | |
| 1071 const Value* bypass_list = | |
| 1072 GetProxyPolicyValue(policies, kPolicyProxyBypassList); | |
| 1073 | |
| 1074 ProxyPrefs::ProxyMode proxy_mode; | |
| 1075 if (mode) { | |
| 1076 std::string string_mode; | |
| 1077 CHECK(mode->GetAsString(&string_mode)); | |
| 1078 CHECK(ProxyPrefs::StringToProxyMode(string_mode, &proxy_mode)); | |
| 1079 } else if (server_mode) { | |
| 1080 int int_mode = 0; | |
| 1081 CHECK(server_mode->GetAsInteger(&int_mode)); | |
| 1082 | |
| 1083 switch (int_mode) { | |
| 1084 case kPolicyNoProxyServerMode: | |
| 1085 proxy_mode = ProxyPrefs::MODE_DIRECT; | |
| 1086 break; | |
| 1087 case kPolicyAutoDetectProxyServerMode: | |
| 1088 proxy_mode = ProxyPrefs::MODE_AUTO_DETECT; | |
| 1089 break; | |
| 1090 case kPolicyManuallyConfiguredProxyServerMode: | |
| 1091 proxy_mode = ProxyPrefs::MODE_FIXED_SERVERS; | |
| 1092 if (pac_url) | |
| 1093 proxy_mode = ProxyPrefs::MODE_PAC_SCRIPT; | |
| 1094 break; | |
| 1095 case kPolicyUseSystemProxyServerMode: | |
| 1096 proxy_mode = ProxyPrefs::MODE_SYSTEM; | |
| 1097 break; | |
| 1098 default: | |
| 1099 proxy_mode = ProxyPrefs::MODE_DIRECT; | |
| 1100 NOTREACHED(); | |
| 1101 } | |
| 1102 } else { | |
| 1103 return; | |
| 1104 } | |
| 1105 | |
| 1106 switch (proxy_mode) { | |
| 1107 case ProxyPrefs::MODE_DIRECT: | |
| 1108 prefs->SetValue(prefs::kProxy, ProxyConfigDictionary::CreateDirect()); | |
| 1109 break; | |
| 1110 case ProxyPrefs::MODE_AUTO_DETECT: | |
| 1111 prefs->SetValue(prefs::kProxy, ProxyConfigDictionary::CreateAutoDetect()); | |
| 1112 break; | |
| 1113 case ProxyPrefs::MODE_PAC_SCRIPT: { | |
| 1114 std::string pac_url_string; | |
| 1115 if (pac_url->GetAsString(&pac_url_string)) { | |
| 1116 prefs->SetValue(prefs::kProxy, | |
| 1117 ProxyConfigDictionary::CreatePacScript(pac_url_string, false)); | |
| 1118 } else { | |
| 1119 NOTREACHED(); | |
| 1120 } | |
| 1121 break; | |
| 1122 } | |
| 1123 case ProxyPrefs::MODE_FIXED_SERVERS: { | |
| 1124 std::string proxy_server; | |
| 1125 std::string bypass_list_string; | |
| 1126 if (server->GetAsString(&proxy_server)) { | |
| 1127 if (bypass_list) | |
| 1128 bypass_list->GetAsString(&bypass_list_string); | |
| 1129 prefs->SetValue(prefs::kProxy, | |
| 1130 ProxyConfigDictionary::CreateFixedServers( | |
| 1131 proxy_server, bypass_list_string)); | |
| 1132 } | |
| 1133 break; | |
| 1134 } | |
| 1135 case ProxyPrefs::MODE_SYSTEM: | |
| 1136 prefs->SetValue(prefs::kProxy, | |
| 1137 ProxyConfigDictionary::CreateSystem()); | |
| 1138 break; | |
| 1139 case ProxyPrefs::kModeCount: | |
| 1140 NOTREACHED(); | |
| 1141 } | |
| 1142 } | |
| 1143 | |
| 1144 const Value* ProxyPolicyHandler::GetProxyPolicyValue( | |
| 1145 const PolicyMap* policies, ConfigurationPolicyType policy) { | |
| 1146 const Value* value = policies->Get(policy); | |
| 1147 std::string tmp; | |
| 1148 if (!value || | |
| 1149 value->IsType(Value::TYPE_NULL) || | |
| 1150 (value->IsType(Value::TYPE_STRING) && | |
| 1151 value->GetAsString(&tmp) && | |
| 1152 tmp.empty())) { | |
| 1153 return NULL; | |
| 1154 } | |
| 1155 return value; | |
| 1156 } | |
| 1157 | |
| 1158 bool ProxyPolicyHandler::CheckProxyModeAndServerMode(const PolicyMap* policies, | |
| 1159 PolicyErrorMap* errors, | |
| 1160 std::string* mode_value) { | |
| 1161 const Value* mode = GetProxyPolicyValue(policies, kPolicyProxyMode); | |
| 1162 const Value* server = GetProxyPolicyValue(policies, kPolicyProxyServer); | |
| 1163 const Value* server_mode = | |
| 1164 GetProxyPolicyValue(policies, kPolicyProxyServerMode); | |
| 1165 const Value* pac_url = GetProxyPolicyValue(policies, kPolicyProxyPacUrl); | |
| 1166 | |
| 1167 // If there's a server mode, convert it into a mode. | |
| 1168 // When both are specified, the mode takes precedence. | |
| 1169 if (mode) { | |
| 1170 if (server_mode) { | |
| 1171 errors->AddError(kPolicyProxyServerMode, | |
| 1172 IDS_POLICY_PROXY_SERVER_MODE_IGNORED); | |
| 1173 } | |
| 1174 if (!mode->GetAsString(mode_value)) { | |
| 1175 errors->AddError(kPolicyProxyMode, IDS_POLICY_TYPE_ERROR, | |
| 1176 ValueTypeToString(Value::TYPE_BOOLEAN)); | |
| 1177 return false; | |
| 1178 } | |
| 1179 | |
| 1180 ProxyPrefs::ProxyMode mode; | |
| 1181 if (!ProxyPrefs::StringToProxyMode(*mode_value, &mode)) { | |
| 1182 errors->AddError(kPolicyProxyMode, IDS_POLICY_INVALID_PROXY_MODE_ERROR); | |
| 1183 return false; | |
| 1184 } | |
| 1185 | |
| 1186 if (mode == ProxyPrefs::MODE_PAC_SCRIPT && !pac_url) { | |
| 1187 errors->AddError(kPolicyProxyPacUrl, IDS_POLICY_NOT_SPECIFIED_ERROR); | |
| 1188 return false; | |
| 1189 } else if (mode == ProxyPrefs::MODE_FIXED_SERVERS && !server) { | |
| 1190 errors->AddError(kPolicyProxyServer, IDS_POLICY_NOT_SPECIFIED_ERROR); | |
| 1191 return false; | |
| 1192 } | |
| 1193 } else if (server_mode) { | |
| 1194 int server_mode_value; | |
| 1195 if (!server_mode->GetAsInteger(&server_mode_value)) { | |
| 1196 errors->AddError(kPolicyProxyServerMode, IDS_POLICY_TYPE_ERROR, | |
| 1197 ValueTypeToString(Value::TYPE_INTEGER)); | |
| 1198 return false; | |
| 1199 } | |
| 1200 | |
| 1201 switch (server_mode_value) { | |
| 1202 case kPolicyNoProxyServerMode: | |
| 1203 *mode_value = ProxyPrefs::kDirectProxyModeName; | |
| 1204 break; | |
| 1205 case kPolicyAutoDetectProxyServerMode: | |
| 1206 *mode_value = ProxyPrefs::kAutoDetectProxyModeName; | |
| 1207 break; | |
| 1208 case kPolicyManuallyConfiguredProxyServerMode: | |
| 1209 if (server && pac_url) { | |
| 1210 int message_id = IDS_POLICY_PROXY_BOTH_SPECIFIED_ERROR; | |
| 1211 errors->AddError(kPolicyProxyServer, message_id); | |
| 1212 errors->AddError(kPolicyProxyPacUrl, message_id); | |
| 1213 return false; | |
| 1214 } | |
| 1215 if (!server && !pac_url) { | |
| 1216 int message_id = IDS_POLICY_PROXY_NEITHER_SPECIFIED_ERROR; | |
| 1217 errors->AddError(kPolicyProxyServer, message_id); | |
| 1218 errors->AddError(kPolicyProxyPacUrl, message_id); | |
| 1219 return false; | |
| 1220 } | |
| 1221 if (pac_url) | |
| 1222 *mode_value = ProxyPrefs::kPacScriptProxyModeName; | |
| 1223 else | |
| 1224 *mode_value = ProxyPrefs::kFixedServersProxyModeName; | |
| 1225 break; | |
| 1226 case kPolicyUseSystemProxyServerMode: | |
| 1227 *mode_value = ProxyPrefs::kSystemProxyModeName; | |
| 1228 break; | |
| 1229 default: | |
| 1230 errors->AddError(kPolicyProxyServerMode, IDS_POLICY_OUT_OF_RANGE_ERROR, | |
| 1231 base::IntToString(server_mode_value)); | |
| 1232 return false; | |
| 1233 } | |
| 1234 } | |
| 1235 return true; | |
| 1236 } | |
| 1237 | |
| 1238 | |
| 1239 } // namespace | |
| 1240 | |
| 1241 | |
| 1242 // ConfigurationPolicyHandler implementation ----------------------------------- | |
| 1243 | |
| 1244 | |
| 1245 // static | |
| 1246 ConfigurationPolicyHandler::HandlerList* | |
| 1247 ConfigurationPolicyHandler::CreateHandlerList() { | |
| 1248 HandlerList* list = new HandlerList; | |
| 1249 | |
| 1250 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) { | |
| 1251 list->push_back( | |
| 1252 new SimplePolicyHandler(kSimplePolicyMap[i].policy_type, | |
| 1253 kSimplePolicyMap[i].value_type, | |
| 1254 kSimplePolicyMap[i].preference_path)); | |
| 1255 } | |
| 1256 list->push_back(new SyncPolicyHandler()); | |
| 1257 list->push_back(new AutofillPolicyHandler()); | |
| 1258 | |
| 1259 #if !defined(OS_CHROMEOS) | |
| 1260 list->push_back(new DownloadDirPolicyHandler()); | |
| 1261 #endif // !defined(OS_CHROME0S) | |
| 1262 | |
| 1263 list->push_back(new DiskCacheDirPolicyHandler()); | |
| 1264 list->push_back(new FileSelectionDialogsHandler()); | |
| 1265 list->push_back(new ProxyPolicyHandler()); | |
| 1266 list->push_back(new IncognitoModePolicyHandler()); | |
| 1267 list->push_back(new DefaultSearchPolicyHandler()); | |
| 1268 | |
| 1269 return list; | |
| 1270 } | |
| 1271 | |
| 1272 } // namespace policy | |
| OLD | NEW |