| 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/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 LoadAllExtensions(); | 137 LoadAllExtensions(); |
| 138 | 138 |
| 139 // TODO(erikkay) this should probably be deferred to a future point | 139 // TODO(erikkay) this should probably be deferred to a future point |
| 140 // rather than running immediately at startup. | 140 // rather than running immediately at startup. |
| 141 CheckForExternalUpdates(); | 141 CheckForExternalUpdates(); |
| 142 | 142 |
| 143 // TODO(erikkay) this should probably be deferred as well. | 143 // TODO(erikkay) this should probably be deferred as well. |
| 144 GarbageCollectExtensions(); | 144 GarbageCollectExtensions(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 std::vector<PageAction*> ExtensionsService::GetPageActions() const { | 147 std::vector<ContextualAction*> ExtensionsService::GetPageActions() const { |
| 148 std::vector<PageAction*> result; | 148 return GetContextualActions(ContextualAction::PAGE_ACTION); |
| 149 } |
| 149 | 150 |
| 150 // TODO(finnur): Sort the page icons in some meaningful way. | 151 std::vector<ContextualAction*> ExtensionsService::GetBrowserActions() const { |
| 151 for (ExtensionList::const_iterator iter = extensions_.begin(); | 152 return GetContextualActions(ContextualAction::BROWSER_ACTION); |
| 152 iter != extensions_.end(); ++iter) { | |
| 153 const PageActionMap& page_actions = (*iter)->page_actions(); | |
| 154 for (PageActionMap::const_iterator i(page_actions.begin()); | |
| 155 i != page_actions.end(); ++i) { | |
| 156 result.push_back(i->second); | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 return result; | |
| 161 } | 153 } |
| 162 | 154 |
| 163 void ExtensionsService::InstallExtension(const FilePath& extension_path) { | 155 void ExtensionsService::InstallExtension(const FilePath& extension_path) { |
| 164 CrxInstaller::Start(extension_path, install_directory_, Extension::INTERNAL, | 156 CrxInstaller::Start(extension_path, install_directory_, Extension::INTERNAL, |
| 165 "", // no expected id | 157 "", // no expected id |
| 166 false, // don't delete crx when complete | 158 false, // don't delete crx when complete |
| 167 true, // allow privilege increase | 159 true, // allow privilege increase |
| 168 backend_loop_, | 160 backend_loop_, |
| 169 this, | 161 this, |
| 170 NULL); // no client (silent install) | 162 NULL); // no client (silent install) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 OnExtensionLoaded(extension, true); | 317 OnExtensionLoaded(extension, true); |
| 326 | 318 |
| 327 if (location == Extension::EXTERNAL_PREF || | 319 if (location == Extension::EXTERNAL_PREF || |
| 328 location == Extension::EXTERNAL_REGISTRY) { | 320 location == Extension::EXTERNAL_REGISTRY) { |
| 329 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), | 321 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), |
| 330 &ExtensionsServiceBackend::CheckExternalUninstall, | 322 &ExtensionsServiceBackend::CheckExternalUninstall, |
| 331 scoped_refptr<ExtensionsService>(this), id, location)); | 323 scoped_refptr<ExtensionsService>(this), id, location)); |
| 332 } | 324 } |
| 333 } | 325 } |
| 334 | 326 |
| 327 std::vector<ContextualAction*> ExtensionsService::GetContextualActions( |
| 328 ContextualAction::ContextualActionType action_type) const { |
| 329 std::vector<ContextualAction*> result; |
| 330 |
| 331 // TODO(finnur): Sort the icons in some meaningful way. |
| 332 for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 333 iter != extensions_.end(); ++iter) { |
| 334 if (action_type == ContextualAction::PAGE_ACTION) { |
| 335 const ContextualActionMap* page_actions = &(*iter)->page_actions(); |
| 336 for (ContextualActionMap::const_iterator i(page_actions->begin()); |
| 337 i != page_actions->end(); ++i) { |
| 338 result.push_back(i->second); |
| 339 } |
| 340 } else { |
| 341 ContextualAction* browser_action = (*iter)->browser_action(); |
| 342 if (browser_action) |
| 343 result.push_back(browser_action); |
| 344 } |
| 345 } |
| 346 |
| 347 return result; |
| 348 } |
| 349 |
| 335 void ExtensionsService::UpdateExtensionBlacklist( | 350 void ExtensionsService::UpdateExtensionBlacklist( |
| 336 const std::vector<std::string>& blacklist) { | 351 const std::vector<std::string>& blacklist) { |
| 337 // Use this set to indicate if an extension in the blacklist has been used. | 352 // Use this set to indicate if an extension in the blacklist has been used. |
| 338 std::set<std::string> blacklist_set; | 353 std::set<std::string> blacklist_set; |
| 339 for (unsigned int i = 0; i < blacklist.size(); ++i) { | 354 for (unsigned int i = 0; i < blacklist.size(); ++i) { |
| 340 if (Extension::IdIsValid(blacklist[i])) { | 355 if (Extension::IdIsValid(blacklist[i])) { |
| 341 blacklist_set.insert(blacklist[i]); | 356 blacklist_set.insert(blacklist[i]); |
| 342 } | 357 } |
| 343 } | 358 } |
| 344 extension_prefs_->UpdateBlacklist(blacklist_set); | 359 extension_prefs_->UpdateBlacklist(blacklist_set); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 linked_ptr<ExternalExtensionProvider>(test_provider); | 767 linked_ptr<ExternalExtensionProvider>(test_provider); |
| 753 } | 768 } |
| 754 | 769 |
| 755 void ExtensionsServiceBackend::OnExternalExtensionFound( | 770 void ExtensionsServiceBackend::OnExternalExtensionFound( |
| 756 const std::string& id, const Version* version, const FilePath& path, | 771 const std::string& id, const Version* version, const FilePath& path, |
| 757 Extension::Location location) { | 772 Extension::Location location) { |
| 758 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_, | 773 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_, |
| 759 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(), | 774 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(), |
| 760 path, location)); | 775 path, location)); |
| 761 } | 776 } |
| OLD | NEW |