Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 6772022: Make <all_urls> and file:///* in permissions trigger "Allow file access" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for landing Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 // UI thread because reloads should be very rare, and the complexity 810 // UI thread because reloads should be very rare, and the complexity
810 // added by delaying the time when the extensions service knows about 811 // added by delaying the time when the extensions service knows about
811 // all extensions is significant. See crbug.com/37548 for details. 812 // all extensions is significant. See crbug.com/37548 for details.
812 // |allow_io| disables tests that file operations run on the file 813 // |allow_io| disables tests that file operations run on the file
813 // thread. 814 // thread.
814 base::ThreadRestrictions::ScopedAllowIO allow_io; 815 base::ThreadRestrictions::ScopedAllowIO allow_io;
815 816
816 int flags = Extension::NO_FLAGS; 817 int flags = Extension::NO_FLAGS;
817 if (Extension::ShouldDoStrictErrorChecking(info->extension_location)) 818 if (Extension::ShouldDoStrictErrorChecking(info->extension_location))
818 flags |= Extension::STRICT_ERROR_CHECKS; 819 flags |= Extension::STRICT_ERROR_CHECKS;
820 if (extension_prefs_->AllowFileAccess(info->extension_id))
821 flags |= Extension::ALLOW_FILE_ACCESS;
819 std::string error; 822 std::string error;
820 scoped_refptr<const Extension> extension( 823 scoped_refptr<const Extension> extension(
821 extension_file_util::LoadExtension( 824 extension_file_util::LoadExtension(
822 info->extension_path, 825 info->extension_path,
823 info->extension_location, 826 info->extension_location,
824 flags, 827 flags,
825 &error)); 828 &error));
826 829
827 if (extension.get()) { 830 if (extension.get()) {
828 extensions_info->at(i)->extension_manifest.reset( 831 extensions_info->at(i)->extension_manifest.reset(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 std::string error; 936 std::string error;
934 scoped_refptr<const Extension> extension(NULL); 937 scoped_refptr<const Extension> extension(NULL);
935 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { 938 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) {
936 error = errors::kDisabledByPolicy; 939 error = errors::kDisabledByPolicy;
937 } else if (info.extension_manifest.get()) { 940 } else if (info.extension_manifest.get()) {
938 int flags = Extension::NO_FLAGS; 941 int flags = Extension::NO_FLAGS;
939 if (info.extension_location != Extension::LOAD) 942 if (info.extension_location != Extension::LOAD)
940 flags |= Extension::REQUIRE_KEY; 943 flags |= Extension::REQUIRE_KEY;
941 if (Extension::ShouldDoStrictErrorChecking(info.extension_location)) 944 if (Extension::ShouldDoStrictErrorChecking(info.extension_location))
942 flags |= Extension::STRICT_ERROR_CHECKS; 945 flags |= Extension::STRICT_ERROR_CHECKS;
946 if (extension_prefs_->AllowFileAccess(info.extension_id))
947 flags |= Extension::ALLOW_FILE_ACCESS;
943 extension = Extension::Create( 948 extension = Extension::Create(
944 info.extension_path, 949 info.extension_path,
945 info.extension_location, 950 info.extension_location,
946 *info.extension_manifest, 951 *info.extension_manifest,
947 flags, 952 flags,
948 &error); 953 &error);
949 } else { 954 } else {
950 error = errors::kManifestUnreadable; 955 error = errors::kManifestUnreadable;
951 } 956 }
952 957
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 return IsIncognitoEnabled(extension) && !extension->incognito_split_mode(); 1105 return IsIncognitoEnabled(extension) && !extension->incognito_split_mode();
1101 } 1106 }
1102 1107
1103 bool ExtensionService::AllowFileAccess(const Extension* extension) { 1108 bool ExtensionService::AllowFileAccess(const Extension* extension) {
1104 return (CommandLine::ForCurrentProcess()->HasSwitch( 1109 return (CommandLine::ForCurrentProcess()->HasSwitch(
1105 switches::kDisableExtensionsFileAccessCheck) || 1110 switches::kDisableExtensionsFileAccessCheck) ||
1106 extension_prefs_->AllowFileAccess(extension->id())); 1111 extension_prefs_->AllowFileAccess(extension->id()));
1107 } 1112 }
1108 1113
1109 void ExtensionService::SetAllowFileAccess(const Extension* extension, 1114 void ExtensionService::SetAllowFileAccess(const Extension* extension,
1110 bool allow) { 1115 bool allow) {
1116 // Reload to update browser state. Only bother if the value changed and the
1117 // extension is actually enabled, since there is no UI otherwise.
1118 bool old_allow = AllowFileAccess(extension);
1119 if (allow == old_allow)
1120 return;
1121
1111 extension_prefs_->SetAllowFileAccess(extension->id(), allow); 1122 extension_prefs_->SetAllowFileAccess(extension->id(), allow);
1112 NotificationService::current()->Notify( 1123
1113 NotificationType::EXTENSION_USER_SCRIPTS_UPDATED, 1124 bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
1114 Source<Profile>(profile_), 1125 extension) != extensions_.end();
1115 Details<const Extension>(extension)); 1126 if (extension_is_enabled)
1127 ReloadExtension(extension->id());
1116 } 1128 }
1117 1129
1118 bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) { 1130 bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) {
1119 return extension_prefs_->GetBrowserActionVisibility(extension); 1131 return extension_prefs_->GetBrowserActionVisibility(extension);
1120 } 1132 }
1121 1133
1122 void ExtensionService::SetBrowserActionVisibility(const Extension* extension, 1134 void ExtensionService::SetBrowserActionVisibility(const Extension* extension,
1123 bool visible) { 1135 bool visible) {
1124 extension_prefs_->SetBrowserActionVisibility(extension, visible); 1136 extension_prefs_->SetBrowserActionVisibility(extension, visible);
1125 } 1137 }
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 initial_enable_incognito = 1517 initial_enable_incognito =
1506 extension_prefs_->IsIncognitoEnabled(extension->id()); 1518 extension_prefs_->IsIncognitoEnabled(extension->id());
1507 } 1519 }
1508 1520
1509 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", 1521 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1510 extension->GetType(), 100); 1522 extension->GetType(), 100);
1511 ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); 1523 ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension);
1512 extension_prefs_->OnExtensionInstalled( 1524 extension_prefs_->OnExtensionInstalled(
1513 extension, initial_state, initial_enable_incognito); 1525 extension, initial_state, initial_enable_incognito);
1514 1526
1515 // Unpacked extensions start off with file access since they are a developer 1527 // Unpacked extensions default to allowing file access, but if that has been
1516 // feature. 1528 // overridden, don't reset the value.
1517 if (extension->location() == Extension::LOAD) 1529 if (Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) &&
1530 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1518 extension_prefs_->SetAllowFileAccess(extension->id(), true); 1531 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1532 }
1519 1533
1520 // If the extension is a theme, tell the profile (and therefore ThemeProvider) 1534 // If the extension is a theme, tell the profile (and therefore ThemeProvider)
1521 // to apply it. 1535 // to apply it.
1522 if (extension->is_theme()) { 1536 if (extension->is_theme()) {
1523 NotificationService::current()->Notify( 1537 NotificationService::current()->Notify(
1524 NotificationType::THEME_INSTALLED, 1538 NotificationType::THEME_INSTALLED,
1525 Source<Profile>(profile_), 1539 Source<Profile>(profile_),
1526 Details<const Extension>(extension)); 1540 Details<const Extension>(extension));
1527 } else { 1541 } else {
1528 NotificationService::current()->Notify( 1542 NotificationService::current()->Notify(
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 } 1796 }
1783 1797
1784 void ExtensionService::SetBeingUpgraded(const Extension* extension, 1798 void ExtensionService::SetBeingUpgraded(const Extension* extension,
1785 bool value) { 1799 bool value) {
1786 extension_runtime_data_[extension->id()].being_upgraded = value; 1800 extension_runtime_data_[extension->id()].being_upgraded = value;
1787 } 1801 }
1788 1802
1789 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { 1803 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) {
1790 return &extension_runtime_data_[extension->id()].property_bag; 1804 return &extension_runtime_data_[extension->id()].property_bag;
1791 } 1805 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extensions_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698