| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 resource_type_names_incorrect_size); | 42 resource_type_names_incorrect_size); |
| 43 | 43 |
| 44 // The default setting for each content type. | 44 // The default setting for each content type. |
| 45 const ContentSetting kDefaultSettings[] = { | 45 const ContentSetting kDefaultSettings[] = { |
| 46 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES | 46 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES |
| 47 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES | 47 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES |
| 48 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT | 48 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT |
| 49 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS | 49 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS |
| 50 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS | 50 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS |
| 51 CONTENT_SETTING_ASK, // Not used for Geolocation | 51 CONTENT_SETTING_ASK, // Not used for Geolocation |
| 52 CONTENT_SETTING_ASK, // Not used for Notifications | 52 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_NOTIFICATIONS |
| 53 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PRERENDER | 53 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PRERENDER |
| 54 }; | 54 }; |
| 55 COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, | 55 COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, |
| 56 default_settings_incorrect_size); | 56 default_settings_incorrect_size); |
| 57 | 57 |
| 58 // The names of the ContentSettingsType values, for use with dictionary prefs. | 58 // The names of the ContentSettingsType values, for use with dictionary prefs. |
| 59 const char* kTypeNames[] = { | 59 const char* kTypeNames[] = { |
| 60 "cookies", | 60 "cookies", |
| 61 "images", | 61 "images", |
| 62 "javascript", | 62 "javascript", |
| 63 "plugins", | 63 "plugins", |
| 64 "popups", | 64 "popups", |
| 65 NULL, // Not used for Geolocation | 65 NULL, // Not used for Geolocation |
| 66 // TODO(markusheintz): Refactoring in progress. Content settings exceptions | 66 // TODO(markusheintz): Refactoring in progress. Content settings exceptions |
| 67 // for notifications will be added next. | 67 // for notifications will be added next. |
| 68 "notifications", // Only used for default Notifications settings. | 68 "notifications", // Only used for default Notifications settings. |
| 69 NULL, // Not used for Prerender | 69 NULL, // Not used for Prerender |
| 70 }; | 70 }; |
| 71 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, | 71 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, |
| 72 type_names_incorrect_size); | 72 type_names_incorrect_size); |
| 73 | 73 |
| 74 void SetDefaultContentSettings(DictionaryValue* default_settings) { |
| 75 default_settings->Clear(); |
| 76 |
| 77 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 78 if (kTypeNames[i] != NULL) { |
| 79 default_settings->SetInteger(kTypeNames[i], |
| 80 kDefaultSettings[i]); |
| 81 } |
| 82 } |
| 83 } |
| 84 |
| 74 } // namespace | 85 } // namespace |
| 75 | 86 |
| 76 namespace content_settings { | 87 namespace content_settings { |
| 77 | 88 |
| 78 PrefDefaultProvider::PrefDefaultProvider(Profile* profile) | 89 PrefDefaultProvider::PrefDefaultProvider(Profile* profile) |
| 79 : profile_(profile), | 90 : profile_(profile), |
| 80 is_incognito_(profile_->IsOffTheRecord()), | 91 is_incognito_(profile_->IsOffTheRecord()), |
| 81 updating_preferences_(false) { | 92 updating_preferences_(false) { |
| 82 initializing_ = true; | 93 initializing_ = true; |
| 83 PrefService* prefs = profile->GetPrefs(); | 94 PrefService* prefs = profile->GetPrefs(); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 if (prefs->HasPrefPath(prefs::kDesktopNotificationDefaultContentSetting)) { | 288 if (prefs->HasPrefPath(prefs::kDesktopNotificationDefaultContentSetting)) { |
| 278 ContentSetting setting = IntToContentSetting( | 289 ContentSetting setting = IntToContentSetting( |
| 279 prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); | 290 prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); |
| 280 UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | 291 UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); |
| 281 prefs->ClearPref(prefs::kDesktopNotificationDefaultContentSetting); | 292 prefs->ClearPref(prefs::kDesktopNotificationDefaultContentSetting); |
| 282 } | 293 } |
| 283 } | 294 } |
| 284 | 295 |
| 285 // static | 296 // static |
| 286 void PrefDefaultProvider::RegisterUserPrefs(PrefService* prefs) { | 297 void PrefDefaultProvider::RegisterUserPrefs(PrefService* prefs) { |
| 287 prefs->RegisterDictionaryPref(prefs::kDefaultContentSettings); | 298 // The registration of the preference prefs::kDefaultContentSettings should |
| 299 // also include the default values for default content settings. This allows |
| 300 // functional tests to get default content settings by reading the preference |
| 301 // prefs::kDefaultContentSettings via pyauto. |
| 302 // TODO(markusheintz): Write pyauto hooks for the content settings map as |
| 303 // content settings should be read from the host content settings map. |
| 304 DictionaryValue* default_content_settings = new DictionaryValue(); |
| 305 SetDefaultContentSettings(default_content_settings); |
| 306 prefs->RegisterDictionaryPref(prefs::kDefaultContentSettings, |
| 307 default_content_settings); |
| 288 | 308 |
| 289 // Obsolete prefs, for migrations: | 309 // Obsolete prefs, for migrations: |
| 290 prefs->RegisterIntegerPref( | 310 prefs->RegisterIntegerPref( |
| 291 prefs::kDesktopNotificationDefaultContentSetting, | 311 prefs::kDesktopNotificationDefaultContentSetting, |
| 292 kDefaultSettings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS]); | 312 kDefaultSettings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS]); |
| 293 } | 313 } |
| 294 | 314 |
| 295 // //////////////////////////////////////////////////////////////////////////// | 315 // //////////////////////////////////////////////////////////////////////////// |
| 296 // PrefProvider: | 316 // PrefProvider: |
| 297 // | 317 // |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 ContentSettingsPattern(host), | 818 ContentSettingsPattern(host), |
| 799 CONTENT_SETTINGS_TYPE_POPUPS, | 819 CONTENT_SETTINGS_TYPE_POPUPS, |
| 800 "", | 820 "", |
| 801 CONTENT_SETTING_ALLOW); | 821 CONTENT_SETTING_ALLOW); |
| 802 } | 822 } |
| 803 prefs->ClearPref(prefs::kPopupWhitelistedHosts); | 823 prefs->ClearPref(prefs::kPopupWhitelistedHosts); |
| 804 } | 824 } |
| 805 } | 825 } |
| 806 | 826 |
| 807 } // namespace content_settings | 827 } // namespace content_settings |
| OLD | NEW |