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

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

Issue 10382149: Refactor the various ways to control what users can do to extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/installed_loader.h" 5 #include "chrome/browser/extensions/installed_loader.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_file_util.h" 17 #include "chrome/common/extensions/extension_file_util.h"
17 #include "chrome/common/extensions/extension_l10n_util.h" 18 #include "chrome/common/extensions/extension_l10n_util.h"
18 #include "chrome/common/extensions/extension_manifest_constants.h" 19 #include "chrome/common/extensions/extension_manifest_constants.h"
19 #include "chrome/common/extensions/manifest.h" 20 #include "chrome/common/extensions/manifest.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/user_metrics.h" 23 #include "content/public/browser/user_metrics.h"
23 24
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 : extension_service_(extension_service), 62 : extension_service_(extension_service),
62 extension_prefs_(extension_service->extension_prefs()) { 63 extension_prefs_(extension_service->extension_prefs()) {
63 } 64 }
64 65
65 InstalledLoader::~InstalledLoader() { 66 InstalledLoader::~InstalledLoader() {
66 } 67 }
67 68
68 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) { 69 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) {
69 std::string error; 70 std::string error;
70 scoped_refptr<const Extension> extension(NULL); 71 scoped_refptr<const Extension> extension(NULL);
71 // An explicit check against policy is required to behave correctly during 72 if (info.extension_manifest.get()) {
72 // startup. This is because extensions that were previously OK might have
73 // been blacklisted in policy while Chrome was not running.
74 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id,
75 info.extension_location)) {
76 error = errors::kDisabledByPolicy;
77 } else if (info.extension_manifest.get()) {
78 extension = Extension::Create( 73 extension = Extension::Create(
79 info.extension_path, 74 info.extension_path,
80 info.extension_location, 75 info.extension_location,
81 *info.extension_manifest, 76 *info.extension_manifest,
82 GetCreationFlags(&info), 77 GetCreationFlags(&info),
83 &error); 78 &error);
84 } else { 79 } else {
85 error = errors::kManifestUnreadable; 80 error = errors::kManifestUnreadable;
86 } 81 }
87 82
88 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by 83 // Once installed, non-unpacked extensions cannot change their IDs (e.g., by
89 // updating the 'key' field in their manifest). 84 // updating the 'key' field in their manifest).
90 // TODO(jstritar): migrate preferences when unpacked extensions change IDs. 85 // TODO(jstritar): migrate preferences when unpacked extensions change IDs.
91 if (extension && 86 if (extension &&
92 extension->location() != Extension::LOAD && 87 extension->location() != Extension::LOAD &&
93 info.extension_id != extension->id()) { 88 info.extension_id != extension->id()) {
94 error = errors::kCannotChangeExtensionID; 89 error = errors::kCannotChangeExtensionID;
95 extension = NULL; 90 extension = NULL;
96 content::RecordAction(UserMetricsAction("Extensions.IDChangedError")); 91 content::RecordAction(UserMetricsAction("Extensions.IDChangedError"));
97 } 92 }
98 93
94 // Check policy on every load in case an extension was blacklisted while
95 // Chrome was not running.
96 const ManagementPolicy* policy = ExtensionSystem::Get(
97 extension_service_->profile())->management_policy();
98 if (extension &&
99 !policy->UserMayLoad(extension, NULL)) {
100 // The error message from UserMayInstall() often contains the extension ID
101 // and is therefore not well suited to this UI.
102 error = errors::kDisabledByPolicy;
103 extension = NULL;
104 }
105
99 if (!extension) { 106 if (!extension) {
100 extension_service_-> 107 extension_service_->
101 ReportExtensionLoadError(info.extension_path, error, false); 108 ReportExtensionLoadError(info.extension_path, error, false);
102 return; 109 return;
103 } 110 }
104 111
105 if (write_to_prefs) 112 if (write_to_prefs)
106 extension_prefs_->UpdateManifest(extension); 113 extension_prefs_->UpdateManifest(extension);
107 114
108 extension_service_->AddExtension(extension); 115 extension_service_->AddExtension(extension);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 if (extension_prefs_->AllowFileAccess(info->extension_id)) 302 if (extension_prefs_->AllowFileAccess(info->extension_id))
296 flags |= Extension::ALLOW_FILE_ACCESS; 303 flags |= Extension::ALLOW_FILE_ACCESS;
297 if (extension_prefs_->IsFromWebStore(info->extension_id)) 304 if (extension_prefs_->IsFromWebStore(info->extension_id))
298 flags |= Extension::FROM_WEBSTORE; 305 flags |= Extension::FROM_WEBSTORE;
299 if (extension_prefs_->IsFromBookmark(info->extension_id)) 306 if (extension_prefs_->IsFromBookmark(info->extension_id))
300 flags |= Extension::FROM_BOOKMARK; 307 flags |= Extension::FROM_BOOKMARK;
301 return flags; 308 return flags;
302 } 309 }
303 310
304 } // namespace extensions 311 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_system.cc ('k') | chrome/browser/extensions/management_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698