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; | 202 int flags = Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) ? |
| 203 Extension::ALLOW_FILE_ACCESS : Extension::NO_FLAGS; |
203 if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD)) | 204 if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD)) |
204 flags |= Extension::STRICT_ERROR_CHECKS; | 205 flags |= Extension::STRICT_ERROR_CHECKS; |
205 std::string error; | 206 std::string error; |
206 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( | 207 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
207 extension_path, | 208 extension_path, |
208 Extension::LOAD, | 209 Extension::LOAD, |
209 flags, | 210 flags, |
210 &error)); | 211 &error)); |
211 | 212 |
212 if (!extension) { | 213 if (!extension) { |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 // UI thread because reloads should be very rare, and the complexity | 792 // UI thread because reloads should be very rare, and the complexity |
792 // added by delaying the time when the extensions service knows about | 793 // added by delaying the time when the extensions service knows about |
793 // all extensions is significant. See crbug.com/37548 for details. | 794 // all extensions is significant. See crbug.com/37548 for details. |
794 // |allow_io| disables tests that file operations run on the file | 795 // |allow_io| disables tests that file operations run on the file |
795 // thread. | 796 // thread. |
796 base::ThreadRestrictions::ScopedAllowIO allow_io; | 797 base::ThreadRestrictions::ScopedAllowIO allow_io; |
797 | 798 |
798 int flags = Extension::NO_FLAGS; | 799 int flags = Extension::NO_FLAGS; |
799 if (Extension::ShouldDoStrictErrorChecking(info->extension_location)) | 800 if (Extension::ShouldDoStrictErrorChecking(info->extension_location)) |
800 flags |= Extension::STRICT_ERROR_CHECKS; | 801 flags |= Extension::STRICT_ERROR_CHECKS; |
| 802 if (extension_prefs_->AllowFileAccess(info->extension_id)) |
| 803 flags |= Extension::ALLOW_FILE_ACCESS; |
801 std::string error; | 804 std::string error; |
802 scoped_refptr<const Extension> extension( | 805 scoped_refptr<const Extension> extension( |
803 extension_file_util::LoadExtension( | 806 extension_file_util::LoadExtension( |
804 info->extension_path, | 807 info->extension_path, |
805 info->extension_location, | 808 info->extension_location, |
806 flags, | 809 flags, |
807 &error)); | 810 &error)); |
808 | 811 |
809 if (extension.get()) { | 812 if (extension.get()) { |
810 extensions_info->at(i)->extension_manifest.reset( | 813 extensions_info->at(i)->extension_manifest.reset( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 std::string error; | 918 std::string error; |
916 scoped_refptr<const Extension> extension(NULL); | 919 scoped_refptr<const Extension> extension(NULL); |
917 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { | 920 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { |
918 error = errors::kDisabledByPolicy; | 921 error = errors::kDisabledByPolicy; |
919 } else if (info.extension_manifest.get()) { | 922 } else if (info.extension_manifest.get()) { |
920 int flags = Extension::NO_FLAGS; | 923 int flags = Extension::NO_FLAGS; |
921 if (info.extension_location != Extension::LOAD) | 924 if (info.extension_location != Extension::LOAD) |
922 flags |= Extension::REQUIRE_KEY; | 925 flags |= Extension::REQUIRE_KEY; |
923 if (Extension::ShouldDoStrictErrorChecking(info.extension_location)) | 926 if (Extension::ShouldDoStrictErrorChecking(info.extension_location)) |
924 flags |= Extension::STRICT_ERROR_CHECKS; | 927 flags |= Extension::STRICT_ERROR_CHECKS; |
| 928 if (extension_prefs_->AllowFileAccess(info.extension_id)) |
| 929 flags |= Extension::ALLOW_FILE_ACCESS; |
925 extension = Extension::Create( | 930 extension = Extension::Create( |
926 info.extension_path, | 931 info.extension_path, |
927 info.extension_location, | 932 info.extension_location, |
928 *info.extension_manifest, | 933 *info.extension_manifest, |
929 flags, | 934 flags, |
930 &error); | 935 &error); |
931 } else { | 936 } else { |
932 error = errors::kManifestUnreadable; | 937 error = errors::kManifestUnreadable; |
933 } | 938 } |
934 | 939 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 return IsIncognitoEnabled(extension) && !extension->incognito_split_mode(); | 1087 return IsIncognitoEnabled(extension) && !extension->incognito_split_mode(); |
1083 } | 1088 } |
1084 | 1089 |
1085 bool ExtensionService::AllowFileAccess(const Extension* extension) { | 1090 bool ExtensionService::AllowFileAccess(const Extension* extension) { |
1086 return (CommandLine::ForCurrentProcess()->HasSwitch( | 1091 return (CommandLine::ForCurrentProcess()->HasSwitch( |
1087 switches::kDisableExtensionsFileAccessCheck) || | 1092 switches::kDisableExtensionsFileAccessCheck) || |
1088 extension_prefs_->AllowFileAccess(extension->id())); | 1093 extension_prefs_->AllowFileAccess(extension->id())); |
1089 } | 1094 } |
1090 | 1095 |
1091 void ExtensionService::SetAllowFileAccess(const Extension* extension, | 1096 void ExtensionService::SetAllowFileAccess(const Extension* extension, |
1092 bool allow) { | 1097 bool allow) { |
| 1098 // Reload to update browser state. Only bother if the value changed and the |
| 1099 // extension is actually enabled, since there is no UI otherwise. |
| 1100 bool old_allow = AllowFileAccess(extension); |
| 1101 if (allow == old_allow) |
| 1102 return; |
| 1103 |
1093 extension_prefs_->SetAllowFileAccess(extension->id(), allow); | 1104 extension_prefs_->SetAllowFileAccess(extension->id(), allow); |
1094 NotificationService::current()->Notify( | 1105 |
1095 NotificationType::EXTENSION_USER_SCRIPTS_UPDATED, | 1106 bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(), |
1096 Source<Profile>(profile_), | 1107 extension) != extensions_.end(); |
1097 Details<const Extension>(extension)); | 1108 if (extension_is_enabled) |
| 1109 ReloadExtension(extension->id()); |
1098 } | 1110 } |
1099 | 1111 |
1100 bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) { | 1112 bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) { |
1101 return extension_prefs_->GetBrowserActionVisibility(extension); | 1113 return extension_prefs_->GetBrowserActionVisibility(extension); |
1102 } | 1114 } |
1103 | 1115 |
1104 void ExtensionService::SetBrowserActionVisibility(const Extension* extension, | 1116 void ExtensionService::SetBrowserActionVisibility(const Extension* extension, |
1105 bool visible) { | 1117 bool visible) { |
1106 extension_prefs_->SetBrowserActionVisibility(extension, visible); | 1118 extension_prefs_->SetBrowserActionVisibility(extension, visible); |
1107 } | 1119 } |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 initial_enable_incognito = | 1499 initial_enable_incognito = |
1488 extension_prefs_->IsIncognitoEnabled(extension->id()); | 1500 extension_prefs_->IsIncognitoEnabled(extension->id()); |
1489 } | 1501 } |
1490 | 1502 |
1491 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", | 1503 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
1492 extension->GetType(), 100); | 1504 extension->GetType(), 100); |
1493 ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); | 1505 ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); |
1494 extension_prefs_->OnExtensionInstalled( | 1506 extension_prefs_->OnExtensionInstalled( |
1495 extension, initial_state, initial_enable_incognito); | 1507 extension, initial_state, initial_enable_incognito); |
1496 | 1508 |
1497 // Unpacked extensions start off with file access since they are a developer | 1509 if (Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD)) |
1498 // feature. | |
1499 if (extension->location() == Extension::LOAD) | |
1500 extension_prefs_->SetAllowFileAccess(extension->id(), true); | 1510 extension_prefs_->SetAllowFileAccess(extension->id(), true); |
1501 | 1511 |
1502 // If the extension is a theme, tell the profile (and therefore ThemeProvider) | 1512 // If the extension is a theme, tell the profile (and therefore ThemeProvider) |
1503 // to apply it. | 1513 // to apply it. |
1504 if (extension->is_theme()) { | 1514 if (extension->is_theme()) { |
1505 NotificationService::current()->Notify( | 1515 NotificationService::current()->Notify( |
1506 NotificationType::THEME_INSTALLED, | 1516 NotificationType::THEME_INSTALLED, |
1507 Source<Profile>(profile_), | 1517 Source<Profile>(profile_), |
1508 Details<const Extension>(extension)); | 1518 Details<const Extension>(extension)); |
1509 } else { | 1519 } else { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1764 } | 1774 } |
1765 | 1775 |
1766 void ExtensionService::SetBeingUpgraded(const Extension* extension, | 1776 void ExtensionService::SetBeingUpgraded(const Extension* extension, |
1767 bool value) { | 1777 bool value) { |
1768 extension_runtime_data_[extension->id()].being_upgraded = value; | 1778 extension_runtime_data_[extension->id()].being_upgraded = value; |
1769 } | 1779 } |
1770 | 1780 |
1771 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { | 1781 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { |
1772 return &extension_runtime_data_[extension->id()].property_bag; | 1782 return &extension_runtime_data_[extension->id()].property_bag; |
1773 } | 1783 } |
OLD | NEW |