OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // The version number. | 30 // The version number. |
31 const wchar_t kPrefVersion[] = L"manifest.version"; | 31 const wchar_t kPrefVersion[] = L"manifest.version"; |
32 | 32 |
33 // Indicates if an extension is blacklisted: | 33 // Indicates if an extension is blacklisted: |
34 const wchar_t kPrefBlacklist[] = L"blacklist"; | 34 const wchar_t kPrefBlacklist[] = L"blacklist"; |
35 | 35 |
36 // A preference that tracks extension shelf configuration. This is a list | 36 // A preference that tracks extension shelf configuration. This is a list |
37 // object read from the Preferences file, containing a list of toolstrip URLs. | 37 // object read from the Preferences file, containing a list of toolstrip URLs. |
38 const wchar_t kExtensionShelf[] = L"extensions.shelf"; | 38 const wchar_t kExtensionShelf[] = L"extensions.shelf"; |
| 39 |
| 40 // A preference that tracks browser action toolbar configuration. This is a list |
| 41 // object stored in the Preferences file. The extensions are stored by ID. |
| 42 const wchar_t kExtensionToolbar[] = L"extensions.toolbar"; |
| 43 |
39 } | 44 } |
40 | 45 |
41 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
42 | 47 |
43 InstalledExtensions::InstalledExtensions(ExtensionPrefs* prefs) { | 48 InstalledExtensions::InstalledExtensions(ExtensionPrefs* prefs) { |
44 extension_data_.reset(prefs->CopyCurrentExtensions()); | 49 extension_data_.reset(prefs->CopyCurrentExtensions()); |
45 } | 50 } |
46 | 51 |
47 InstalledExtensions::~InstalledExtensions() { | 52 InstalledExtensions::~InstalledExtensions() { |
48 } | 53 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 103 |
99 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
100 | 105 |
101 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) | 106 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) |
102 : prefs_(prefs), | 107 : prefs_(prefs), |
103 install_directory_(root_dir) { | 108 install_directory_(root_dir) { |
104 if (!prefs_->FindPreference(kExtensionsPref)) | 109 if (!prefs_->FindPreference(kExtensionsPref)) |
105 prefs_->RegisterDictionaryPref(kExtensionsPref); | 110 prefs_->RegisterDictionaryPref(kExtensionsPref); |
106 if (!prefs->FindPreference(kExtensionShelf)) | 111 if (!prefs->FindPreference(kExtensionShelf)) |
107 prefs->RegisterListPref(kExtensionShelf); | 112 prefs->RegisterListPref(kExtensionShelf); |
| 113 if (!prefs->FindPreference(kExtensionToolbar)) |
| 114 prefs->RegisterListPref(kExtensionToolbar); |
108 MakePathsRelative(); | 115 MakePathsRelative(); |
109 } | 116 } |
110 | 117 |
111 static FilePath::StringType MakePathRelative(const FilePath& parent, | 118 static FilePath::StringType MakePathRelative(const FilePath& parent, |
112 const FilePath& child, | 119 const FilePath& child, |
113 bool *dirty) { | 120 bool *dirty) { |
114 if (!parent.IsParent(child)) | 121 if (!parent.IsParent(child)) |
115 return child.value(); | 122 return child.value(); |
116 | 123 |
117 if (dirty) | 124 if (dirty) |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 void ExtensionPrefs::SetShelfToolstripOrder(const URLList& urls) { | 314 void ExtensionPrefs::SetShelfToolstripOrder(const URLList& urls) { |
308 ListValue* toolstrip_urls = prefs_->GetMutableList(kExtensionShelf); | 315 ListValue* toolstrip_urls = prefs_->GetMutableList(kExtensionShelf); |
309 toolstrip_urls->Clear(); | 316 toolstrip_urls->Clear(); |
310 for (size_t i = 0; i < urls.size(); ++i) { | 317 for (size_t i = 0; i < urls.size(); ++i) { |
311 GURL url = urls[i]; | 318 GURL url = urls[i]; |
312 toolstrip_urls->Append(new StringValue(url.spec())); | 319 toolstrip_urls->Append(new StringValue(url.spec())); |
313 } | 320 } |
314 prefs_->ScheduleSavePersistentPrefs(); | 321 prefs_->ScheduleSavePersistentPrefs(); |
315 } | 322 } |
316 | 323 |
| 324 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { |
| 325 std::vector<std::string> extension_ids; |
| 326 const ListValue* toolbar_order = prefs_->GetList(kExtensionToolbar); |
| 327 if (toolbar_order) { |
| 328 for (size_t i = 0; i < toolbar_order->GetSize(); ++i) { |
| 329 std::string extension_id; |
| 330 if (toolbar_order->GetString(i, &extension_id)) |
| 331 extension_ids.push_back(extension_id); |
| 332 } |
| 333 } |
| 334 return extension_ids; |
| 335 } |
| 336 |
| 337 void ExtensionPrefs::SetToolbarOrder( |
| 338 const std::vector<std::string>& extension_ids) { |
| 339 ListValue* toolbar_order = prefs_->GetMutableList(kExtensionToolbar); |
| 340 toolbar_order->Clear(); |
| 341 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); |
| 342 iter != extension_ids.end(); ++iter) { |
| 343 toolbar_order->Append(new StringValue(*iter)); |
| 344 } |
| 345 prefs_->ScheduleSavePersistentPrefs(); |
| 346 } |
| 347 |
317 void ExtensionPrefs::OnExtensionInstalled(Extension* extension) { | 348 void ExtensionPrefs::OnExtensionInstalled(Extension* extension) { |
318 const std::string& id = extension->id(); | 349 const std::string& id = extension->id(); |
319 // Make sure we don't enable a disabled extension. | 350 // Make sure we don't enable a disabled extension. |
320 if (GetExtensionState(extension->id()) != Extension::DISABLED) { | 351 if (GetExtensionState(extension->id()) != Extension::DISABLED) { |
321 UpdateExtensionPref(id, kPrefState, | 352 UpdateExtensionPref(id, kPrefState, |
322 Value::CreateIntegerValue(Extension::ENABLED)); | 353 Value::CreateIntegerValue(Extension::ENABLED)); |
323 } | 354 } |
324 UpdateExtensionPref(id, kPrefLocation, | 355 UpdateExtensionPref(id, kPrefLocation, |
325 Value::CreateIntegerValue(extension->location())); | 356 Value::CreateIntegerValue(extension->location())); |
326 FilePath::StringType path = MakePathRelative(install_directory_, | 357 FilePath::StringType path = MakePathRelative(install_directory_, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 } | 464 } |
434 | 465 |
435 DictionaryValue* ExtensionPrefs::GetExtensionPref( | 466 DictionaryValue* ExtensionPrefs::GetExtensionPref( |
436 const std::string& extension_id) { | 467 const std::string& extension_id) { |
437 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); | 468 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); |
438 DictionaryValue* extension = NULL; | 469 DictionaryValue* extension = NULL; |
439 std::wstring id = ASCIIToWide(extension_id); | 470 std::wstring id = ASCIIToWide(extension_id); |
440 dict->GetDictionary(id, &extension); | 471 dict->GetDictionary(id, &extension); |
441 return extension; | 472 return extension; |
442 } | 473 } |
OLD | NEW |