| 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_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 192 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 193 | 193 |
| 194 frontend_ = frontend; | 194 frontend_ = frontend; |
| 195 | 195 |
| 196 // Explicit UI loads are always noisy. | 196 // Explicit UI loads are always noisy. |
| 197 alert_on_error_ = true; | 197 alert_on_error_ = true; |
| 198 | 198 |
| 199 FilePath extension_path = path_in; | 199 FilePath extension_path = path_in; |
| 200 file_util::AbsolutePath(&extension_path); | 200 file_util::AbsolutePath(&extension_path); |
| 201 | 201 |
| 202 int flags = Extension::NO_FLAGS; |
| 203 if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD)) |
| 204 flags |= Extension::STRICT_ERROR_CHECKS; |
| 202 std::string error; | 205 std::string error; |
| 203 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( | 206 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
| 204 extension_path, | 207 extension_path, |
| 205 Extension::LOAD, | 208 Extension::LOAD, |
| 206 false, // Don't require id | 209 flags, |
| 207 Extension::ShouldDoStrictErrorChecking(Extension::LOAD), | |
| 208 &error)); | 210 &error)); |
| 209 | 211 |
| 210 if (!extension) { | 212 if (!extension) { |
| 211 ReportExtensionLoadError(extension_path, error); | 213 ReportExtensionLoadError(extension_path, error); |
| 212 return; | 214 return; |
| 213 } | 215 } |
| 214 | 216 |
| 215 // Report this as an installed extension so that it gets remembered in the | 217 // Report this as an installed extension so that it gets remembered in the |
| 216 // prefs. | 218 // prefs. |
| 217 BrowserThread::PostTask( | 219 BrowserThread::PostTask( |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 739 |
| 738 void ExtensionService::LoadComponentExtension( | 740 void ExtensionService::LoadComponentExtension( |
| 739 const ComponentExtensionInfo &info) { | 741 const ComponentExtensionInfo &info) { |
| 740 JSONStringValueSerializer serializer(info.manifest); | 742 JSONStringValueSerializer serializer(info.manifest); |
| 741 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); | 743 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
| 742 if (!manifest.get()) { | 744 if (!manifest.get()) { |
| 743 DLOG(ERROR) << "Failed to parse manifest for extension"; | 745 DLOG(ERROR) << "Failed to parse manifest for extension"; |
| 744 return; | 746 return; |
| 745 } | 747 } |
| 746 | 748 |
| 749 int flags = Extension::REQUIRE_KEY; |
| 750 if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT)) |
| 751 flags |= Extension::STRICT_ERROR_CHECKS; |
| 747 std::string error; | 752 std::string error; |
| 748 scoped_refptr<const Extension> extension(Extension::Create( | 753 scoped_refptr<const Extension> extension(Extension::Create( |
| 749 info.root_directory, | 754 info.root_directory, |
| 750 Extension::COMPONENT, | 755 Extension::COMPONENT, |
| 751 *static_cast<DictionaryValue*>(manifest.get()), | 756 *static_cast<DictionaryValue*>(manifest.get()), |
| 752 true, // Require key | 757 flags, |
| 753 Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT), | |
| 754 &error)); | 758 &error)); |
| 755 if (!extension.get()) { | 759 if (!extension.get()) { |
| 756 NOTREACHED() << error; | 760 NOTREACHED() << error; |
| 757 return; | 761 return; |
| 758 } | 762 } |
| 759 AddExtension(extension); | 763 AddExtension(extension); |
| 760 } | 764 } |
| 761 | 765 |
| 762 void ExtensionService::LoadAllExtensions() { | 766 void ExtensionService::LoadAllExtensions() { |
| 763 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 767 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 784 | 788 |
| 785 if (reload_reason != NOT_NEEDED) { | 789 if (reload_reason != NOT_NEEDED) { |
| 786 // Reloading and extension reads files from disk. We do this on the | 790 // Reloading and extension reads files from disk. We do this on the |
| 787 // UI thread because reloads should be very rare, and the complexity | 791 // UI thread because reloads should be very rare, and the complexity |
| 788 // added by delaying the time when the extensions service knows about | 792 // added by delaying the time when the extensions service knows about |
| 789 // all extensions is significant. See crbug.com/37548 for details. | 793 // all extensions is significant. See crbug.com/37548 for details. |
| 790 // |allow_io| disables tests that file operations run on the file | 794 // |allow_io| disables tests that file operations run on the file |
| 791 // thread. | 795 // thread. |
| 792 base::ThreadRestrictions::ScopedAllowIO allow_io; | 796 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 793 | 797 |
| 798 int flags = Extension::NO_FLAGS; |
| 799 if (Extension::ShouldDoStrictErrorChecking(info->extension_location)) |
| 800 flags |= Extension::STRICT_ERROR_CHECKS; |
| 794 std::string error; | 801 std::string error; |
| 795 scoped_refptr<const Extension> extension( | 802 scoped_refptr<const Extension> extension( |
| 796 extension_file_util::LoadExtension( | 803 extension_file_util::LoadExtension( |
| 797 info->extension_path, | 804 info->extension_path, |
| 798 info->extension_location, | 805 info->extension_location, |
| 799 false, // Don't require key | 806 flags, |
| 800 Extension::ShouldDoStrictErrorChecking(info->extension_location), | |
| 801 &error)); | 807 &error)); |
| 802 | 808 |
| 803 if (extension.get()) { | 809 if (extension.get()) { |
| 804 extensions_info->at(i)->extension_manifest.reset( | 810 extensions_info->at(i)->extension_manifest.reset( |
| 805 static_cast<DictionaryValue*>( | 811 static_cast<DictionaryValue*>( |
| 806 extension->manifest_value()->DeepCopy())); | 812 extension->manifest_value()->DeepCopy())); |
| 807 should_write_prefs = true; | 813 should_write_prefs = true; |
| 808 } | 814 } |
| 809 } | 815 } |
| 810 } | 816 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 browser_action_count); | 910 browser_action_count); |
| 905 } | 911 } |
| 906 | 912 |
| 907 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, | 913 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, |
| 908 bool write_to_prefs) { | 914 bool write_to_prefs) { |
| 909 std::string error; | 915 std::string error; |
| 910 scoped_refptr<const Extension> extension(NULL); | 916 scoped_refptr<const Extension> extension(NULL); |
| 911 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { | 917 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { |
| 912 error = errors::kDisabledByPolicy; | 918 error = errors::kDisabledByPolicy; |
| 913 } else if (info.extension_manifest.get()) { | 919 } else if (info.extension_manifest.get()) { |
| 914 bool require_key = info.extension_location != Extension::LOAD; | 920 int flags = Extension::NO_FLAGS; |
| 921 if (info.extension_location != Extension::LOAD) |
| 922 flags |= Extension::REQUIRE_KEY; |
| 923 if (Extension::ShouldDoStrictErrorChecking(info.extension_location)) |
| 924 flags |= Extension::STRICT_ERROR_CHECKS; |
| 915 extension = Extension::Create( | 925 extension = Extension::Create( |
| 916 info.extension_path, | 926 info.extension_path, |
| 917 info.extension_location, | 927 info.extension_location, |
| 918 *info.extension_manifest, | 928 *info.extension_manifest, |
| 919 require_key, | 929 flags, |
| 920 Extension::ShouldDoStrictErrorChecking(info.extension_location), | |
| 921 &error); | 930 &error); |
| 922 } else { | 931 } else { |
| 923 error = errors::kManifestUnreadable; | 932 error = errors::kManifestUnreadable; |
| 924 } | 933 } |
| 925 | 934 |
| 926 if (!extension) { | 935 if (!extension) { |
| 927 ReportExtensionLoadError(info.extension_path, | 936 ReportExtensionLoadError(info.extension_path, |
| 928 error, | 937 error, |
| 929 NotificationType::EXTENSION_INSTALL_ERROR, | 938 NotificationType::EXTENSION_INSTALL_ERROR, |
| 930 false); | 939 false); |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1755 } | 1764 } |
| 1756 | 1765 |
| 1757 void ExtensionService::SetBeingUpgraded(const Extension* extension, | 1766 void ExtensionService::SetBeingUpgraded(const Extension* extension, |
| 1758 bool value) { | 1767 bool value) { |
| 1759 extension_runtime_data_[extension->id()].being_upgraded = value; | 1768 extension_runtime_data_[extension->id()].being_upgraded = value; |
| 1760 } | 1769 } |
| 1761 | 1770 |
| 1762 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { | 1771 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { |
| 1763 return &extension_runtime_data_[extension->id()].property_bag; | 1772 return &extension_runtime_data_[extension->id()].property_bag; |
| 1764 } | 1773 } |
| OLD | NEW |