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