| 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/extensions/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/extension_pref_store.h" | 10 #include "chrome/browser/extensions/extension_pref_store.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 // A preference that contains extension-set content settings. | 168 // A preference that contains extension-set content settings. |
| 169 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; | 169 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; |
| 170 | 170 |
| 171 // Provider of write access to a dictionary storing extension prefs. | 171 // Provider of write access to a dictionary storing extension prefs. |
| 172 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 172 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
| 173 public: | 173 public: |
| 174 ScopedExtensionPrefUpdate(PrefService* service, | 174 ScopedExtensionPrefUpdate(PrefService* service, |
| 175 const std::string& extension_id) : | 175 const std::string& extension_id) : |
| 176 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), | 176 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), |
| 177 prefs_(service), | |
| 178 extension_id_(extension_id) {} | 177 extension_id_(extension_id) {} |
| 179 | 178 |
| 180 virtual ~ScopedExtensionPrefUpdate() { | 179 virtual ~ScopedExtensionPrefUpdate() { |
| 181 prefs_->ScheduleSavePersistentPrefs(); | |
| 182 } | 180 } |
| 183 | 181 |
| 184 virtual DictionaryValue* Get() { | 182 virtual DictionaryValue* Get() { |
| 185 DictionaryValue* dict = DictionaryPrefUpdate::Get(); | 183 DictionaryValue* dict = DictionaryPrefUpdate::Get(); |
| 186 DictionaryValue* extension = NULL; | 184 DictionaryValue* extension = NULL; |
| 187 if (!dict->GetDictionary(extension_id_, &extension)) { | 185 if (!dict->GetDictionary(extension_id_, &extension)) { |
| 188 // Extension pref does not exist, create it. | 186 // Extension pref does not exist, create it. |
| 189 extension = new DictionaryValue(); | 187 extension = new DictionaryValue(); |
| 190 dict->Set(extension_id_, extension); | 188 dict->Set(extension_id_, extension); |
| 191 } | 189 } |
| 192 return extension; | 190 return extension; |
| 193 } | 191 } |
| 194 | 192 |
| 195 private: | 193 private: |
| 196 PrefService* prefs_; | |
| 197 const std::string extension_id_; | 194 const std::string extension_id_; |
| 198 | 195 |
| 199 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionPrefUpdate); | 196 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionPrefUpdate); |
| 200 }; | 197 }; |
| 201 | 198 |
| 202 // Provider of write access to a dictionary storing extension controlled prefs. | 199 // Provider of write access to a dictionary storing extension controlled prefs. |
| 203 class ScopedExtensionControlledPrefUpdate : public DictionaryPrefUpdate { | 200 class ScopedExtensionControlledPrefUpdate : public DictionaryPrefUpdate { |
| 204 public: | 201 public: |
| 205 // |incognito_or_regular_path| indicates the sub-path where the | 202 // |incognito_or_regular_path| indicates the sub-path where the |
| 206 // extension controlled preferences are stored. This has to be either | 203 // extension controlled preferences are stored. This has to be either |
| 207 // kPrefPreferences or kPrefIncognitoPreferences. | 204 // kPrefPreferences or kPrefIncognitoPreferences. |
| 208 ScopedExtensionControlledPrefUpdate( | 205 ScopedExtensionControlledPrefUpdate( |
| 209 PrefService* service, | 206 PrefService* service, |
| 210 const std::string& extension_id, | 207 const std::string& extension_id, |
| 211 const std::string& incognito_or_regular_path) : | 208 const std::string& incognito_or_regular_path) : |
| 212 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), | 209 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), |
| 213 prefs_(service), | |
| 214 extension_id_(extension_id), | 210 extension_id_(extension_id), |
| 215 incognito_or_regular_path_(incognito_or_regular_path) {} | 211 incognito_or_regular_path_(incognito_or_regular_path) {} |
| 216 | 212 |
| 217 virtual ~ScopedExtensionControlledPrefUpdate() { | 213 virtual ~ScopedExtensionControlledPrefUpdate() { |
| 218 prefs_->ScheduleSavePersistentPrefs(); | |
| 219 } | 214 } |
| 220 | 215 |
| 221 virtual DictionaryValue* Get() { | 216 virtual DictionaryValue* Get() { |
| 222 DictionaryValue* dict = DictionaryPrefUpdate::Get(); | 217 DictionaryValue* dict = DictionaryPrefUpdate::Get(); |
| 223 DictionaryValue* preferences = NULL; | 218 DictionaryValue* preferences = NULL; |
| 224 std::string key = | 219 std::string key = |
| 225 extension_id_ + std::string(".") + incognito_or_regular_path_; | 220 extension_id_ + std::string(".") + incognito_or_regular_path_; |
| 226 if (!dict->GetDictionary(key, &preferences)) { | 221 if (!dict->GetDictionary(key, &preferences)) { |
| 227 preferences = new DictionaryValue; | 222 preferences = new DictionaryValue; |
| 228 dict->Set(key, preferences); | 223 dict->Set(key, preferences); |
| 229 } | 224 } |
| 230 return preferences; | 225 return preferences; |
| 231 } | 226 } |
| 232 | 227 |
| 233 private: | 228 private: |
| 234 PrefService* prefs_; | |
| 235 const std::string extension_id_; | 229 const std::string extension_id_; |
| 236 const std::string incognito_or_regular_path_; | 230 const std::string incognito_or_regular_path_; |
| 237 | 231 |
| 238 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionControlledPrefUpdate); | 232 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionControlledPrefUpdate); |
| 239 }; | 233 }; |
| 240 | 234 |
| 241 std::string JoinPrefs(const std::string& parent, const char* child) { | 235 std::string JoinPrefs(const std::string& parent, const char* child) { |
| 242 return parent + "." + child; | 236 return parent + "." + child; |
| 243 } | 237 } |
| 244 | 238 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 if (!update_dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { | 312 if (!update_dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { |
| 319 NOTREACHED() << "Control should never reach here for extension " << *i; | 313 NOTREACHED() << "Control should never reach here for extension " << *i; |
| 320 continue; | 314 continue; |
| 321 } | 315 } |
| 322 FilePath::StringType path_string; | 316 FilePath::StringType path_string; |
| 323 extension_dict->GetString(kPrefPath, &path_string); | 317 extension_dict->GetString(kPrefPath, &path_string); |
| 324 FilePath path(path_string); | 318 FilePath path(path_string); |
| 325 extension_dict->SetString(kPrefPath, | 319 extension_dict->SetString(kPrefPath, |
| 326 MakePathRelative(install_directory_, path)); | 320 MakePathRelative(install_directory_, path)); |
| 327 } | 321 } |
| 328 SavePrefs(); | |
| 329 } | 322 } |
| 330 | 323 |
| 331 void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) { | 324 void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) { |
| 332 if (!dict || dict->empty()) | 325 if (!dict || dict->empty()) |
| 333 return; | 326 return; |
| 334 | 327 |
| 335 for (DictionaryValue::key_iterator i = dict->begin_keys(); | 328 for (DictionaryValue::key_iterator i = dict->begin_keys(); |
| 336 i != dict->end_keys(); ++i) { | 329 i != dict->end_keys(); ++i) { |
| 337 DictionaryValue* extension_dict = NULL; | 330 DictionaryValue* extension_dict = NULL; |
| 338 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { | 331 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 } | 528 } |
| 536 | 529 |
| 537 // Set the scriptable host permissions. | 530 // Set the scriptable host permissions. |
| 538 if (!new_value->scriptable_hosts().is_empty()) { | 531 if (!new_value->scriptable_hosts().is_empty()) { |
| 539 SetExtensionPrefURLPatternSet(extension_id, | 532 SetExtensionPrefURLPatternSet(extension_id, |
| 540 JoinPrefs(pref_key, kPrefScriptableHosts), | 533 JoinPrefs(pref_key, kPrefScriptableHosts), |
| 541 new_value->scriptable_hosts()); | 534 new_value->scriptable_hosts()); |
| 542 } | 535 } |
| 543 } | 536 } |
| 544 | 537 |
| 545 void ExtensionPrefs::SavePrefs() { | |
| 546 prefs_->ScheduleSavePersistentPrefs(); | |
| 547 } | |
| 548 | |
| 549 // static | 538 // static |
| 550 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { | 539 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { |
| 551 return ReadBooleanFromPref(ext, kPrefBlacklist); | 540 return ReadBooleanFromPref(ext, kPrefBlacklist); |
| 552 } | 541 } |
| 553 | 542 |
| 554 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { | 543 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { |
| 555 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); | 544 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); |
| 556 } | 545 } |
| 557 | 546 |
| 558 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { | 547 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 | 1160 |
| 1172 void ExtensionPrefs::SetToolbarOrder( | 1161 void ExtensionPrefs::SetToolbarOrder( |
| 1173 const std::vector<std::string>& extension_ids) { | 1162 const std::vector<std::string>& extension_ids) { |
| 1174 ListPrefUpdate update(prefs_, kExtensionToolbar); | 1163 ListPrefUpdate update(prefs_, kExtensionToolbar); |
| 1175 ListValue* toolbar_order = update.Get(); | 1164 ListValue* toolbar_order = update.Get(); |
| 1176 toolbar_order->Clear(); | 1165 toolbar_order->Clear(); |
| 1177 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); | 1166 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); |
| 1178 iter != extension_ids.end(); ++iter) { | 1167 iter != extension_ids.end(); ++iter) { |
| 1179 toolbar_order->Append(new StringValue(*iter)); | 1168 toolbar_order->Append(new StringValue(*iter)); |
| 1180 } | 1169 } |
| 1181 SavePrefs(); | |
| 1182 } | 1170 } |
| 1183 | 1171 |
| 1184 void ExtensionPrefs::OnExtensionInstalled( | 1172 void ExtensionPrefs::OnExtensionInstalled( |
| 1185 const Extension* extension, | 1173 const Extension* extension, |
| 1186 Extension::State initial_state, | 1174 Extension::State initial_state, |
| 1187 bool from_webstore, | 1175 bool from_webstore, |
| 1188 const StringOrdinal& page_ordinal) { | 1176 const StringOrdinal& page_ordinal) { |
| 1189 const std::string& id = extension->id(); | 1177 const std::string& id = extension->id(); |
| 1190 CHECK(Extension::IdIsValid(id)); | 1178 CHECK(Extension::IdIsValid(id)); |
| 1191 ScopedExtensionPrefUpdate update(prefs_, id); | 1179 ScopedExtensionPrefUpdate update(prefs_, id); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 update->Set(key, data_value); | 1353 update->Set(key, data_value); |
| 1366 else | 1354 else |
| 1367 update->Remove(key, NULL); | 1355 update->Remove(key, NULL); |
| 1368 } | 1356 } |
| 1369 | 1357 |
| 1370 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { | 1358 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { |
| 1371 extension_pref_value_map_->UnregisterExtension(extension_id); | 1359 extension_pref_value_map_->UnregisterExtension(extension_id); |
| 1372 content_settings_store_->UnregisterExtension(extension_id); | 1360 content_settings_store_->UnregisterExtension(extension_id); |
| 1373 DictionaryPrefUpdate update(prefs_, kExtensionsPref); | 1361 DictionaryPrefUpdate update(prefs_, kExtensionsPref); |
| 1374 DictionaryValue* dict = update.Get(); | 1362 DictionaryValue* dict = update.Get(); |
| 1375 if (dict->HasKey(extension_id)) { | 1363 dict->Remove(extension_id, NULL); |
| 1376 dict->Remove(extension_id, NULL); | |
| 1377 SavePrefs(); | |
| 1378 } | |
| 1379 } | 1364 } |
| 1380 | 1365 |
| 1381 const DictionaryValue* ExtensionPrefs::GetExtensionPref( | 1366 const DictionaryValue* ExtensionPrefs::GetExtensionPref( |
| 1382 const std::string& extension_id) const { | 1367 const std::string& extension_id) const { |
| 1383 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); | 1368 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); |
| 1384 if (!dict) | 1369 if (!dict) |
| 1385 return NULL; | 1370 return NULL; |
| 1386 DictionaryValue* extension = NULL; | 1371 DictionaryValue* extension = NULL; |
| 1387 dict->GetDictionary(extension_id, &extension); | 1372 dict->GetDictionary(extension_id, &extension); |
| 1388 return extension; | 1373 return extension; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 bool ExtensionPrefs::GetWebStoreLogin(std::string* result) { | 1560 bool ExtensionPrefs::GetWebStoreLogin(std::string* result) { |
| 1576 if (prefs_->HasPrefPath(kWebStoreLogin)) { | 1561 if (prefs_->HasPrefPath(kWebStoreLogin)) { |
| 1577 *result = prefs_->GetString(kWebStoreLogin); | 1562 *result = prefs_->GetString(kWebStoreLogin); |
| 1578 return true; | 1563 return true; |
| 1579 } | 1564 } |
| 1580 return false; | 1565 return false; |
| 1581 } | 1566 } |
| 1582 | 1567 |
| 1583 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) { | 1568 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) { |
| 1584 prefs_->SetString(kWebStoreLogin, login); | 1569 prefs_->SetString(kWebStoreLogin, login); |
| 1585 SavePrefs(); | |
| 1586 } | 1570 } |
| 1587 | 1571 |
| 1588 StringOrdinal ExtensionPrefs::GetMinOrMaxAppLaunchOrdinalsOnPage( | 1572 StringOrdinal ExtensionPrefs::GetMinOrMaxAppLaunchOrdinalsOnPage( |
| 1589 const StringOrdinal& target_page_ordinal, | 1573 const StringOrdinal& target_page_ordinal, |
| 1590 AppLaunchOrdinalReturn return_type) const { | 1574 AppLaunchOrdinalReturn return_type) const { |
| 1591 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 1575 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
| 1592 CHECK(extensions); | 1576 CHECK(extensions); |
| 1593 CHECK(target_page_ordinal.IsValid()); | 1577 CHECK(target_page_ordinal.IsValid()); |
| 1594 | 1578 |
| 1595 StringOrdinal return_value; | 1579 StringOrdinal return_value; |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 2062 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
| 2079 PrefService::UNSYNCABLE_PREF); | 2063 PrefService::UNSYNCABLE_PREF); |
| 2080 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 2064 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
| 2081 PrefService::UNSYNCABLE_PREF); | 2065 PrefService::UNSYNCABLE_PREF); |
| 2082 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 2066 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
| 2083 PrefService::UNSYNCABLE_PREF); | 2067 PrefService::UNSYNCABLE_PREF); |
| 2084 prefs->RegisterStringPref(kWebStoreLogin, | 2068 prefs->RegisterStringPref(kWebStoreLogin, |
| 2085 std::string() /* default_value */, | 2069 std::string() /* default_value */, |
| 2086 PrefService::UNSYNCABLE_PREF); | 2070 PrefService::UNSYNCABLE_PREF); |
| 2087 } | 2071 } |
| OLD | NEW |