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

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

Issue 10689097: Enforce the 'requirements' field in manifests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Conforming to the doc Created 8 years, 5 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
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/unpacked_installer.h" 5 #include "chrome/browser/extensions/unpacked_installer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/string_util.h"
10 #include "chrome/browser/extensions/extension_install_prompt.h" 11 #include "chrome/browser/extensions/extension_install_prompt.h"
11 #include "chrome/browser/extensions/extension_install_ui.h" 12 #include "chrome/browser/extensions/extension_install_ui.h"
12 #include "chrome/browser/extensions/extension_prefs.h" 13 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/permissions_updater.h" 15 #include "chrome/browser/extensions/permissions_updater.h"
16 #include "chrome/browser/extensions/requirements_checker.h"
15 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_file_util.h" 18 #include "chrome/common/extensions/extension_file_util.h"
17 #include "chrome/common/string_ordinal.h" 19 #include "chrome/common/string_ordinal.h"
18 20
19 using content::BrowserThread; 21 using content::BrowserThread;
20 using extensions::Extension; 22 using extensions::Extension;
21 23
22 namespace { 24 namespace {
23 25
24 const char kUnpackedExtensionsBlacklistedError[] = 26 const char kUnpackedExtensionsBlacklistedError[] =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 61
60 void SimpleExtensionLoadPrompt::ShowPrompt() { 62 void SimpleExtensionLoadPrompt::ShowPrompt() {
61 install_ui_->ConfirmInstall(this, extension_); 63 install_ui_->ConfirmInstall(this, extension_);
62 } 64 }
63 65
64 void SimpleExtensionLoadPrompt::InstallUIProceed() { 66 void SimpleExtensionLoadPrompt::InstallUIProceed() {
65 if (service_weak_.get()) { 67 if (service_weak_.get()) {
66 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); 68 extensions::PermissionsUpdater perms_updater(service_weak_->profile());
67 perms_updater.GrantActivePermissions(extension_, false); 69 perms_updater.GrantActivePermissions(extension_, false);
68 service_weak_->OnExtensionInstalled( 70 service_weak_->OnExtensionInstalled(
69 extension_, false, StringOrdinal()); // Not from web store. 71 extension_,
72 false, // Not from web store.
73 StringOrdinal(),
74 std::vector<std::string>());
70 } 75 }
71 delete this; 76 delete this;
72 } 77 }
73 78
74 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { 79 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) {
75 delete this; 80 delete this;
76 } 81 }
77 82
78 } // namespace 83 } // namespace
79 84
80 namespace extensions { 85 namespace extensions {
81 86
82 // static 87 // static
83 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( 88 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create(
84 ExtensionService* extension_service) { 89 ExtensionService* extension_service) {
85 return scoped_refptr<UnpackedInstaller>( 90 return scoped_refptr<UnpackedInstaller>(
86 new UnpackedInstaller(extension_service)); 91 new UnpackedInstaller(extension_service));
87 } 92 }
88 93
89 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service) 94 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service)
90 : service_weak_(extension_service->AsWeakPtr()), 95 : service_weak_(extension_service->AsWeakPtr()),
91 prompt_for_plugins_(true) { 96 prompt_for_plugins_(true),
97 requirements_checker_(new RequirementsChecker()) {
92 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 98 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
93 } 99 }
94 100
95 UnpackedInstaller::~UnpackedInstaller() { 101 UnpackedInstaller::~UnpackedInstaller() {
96 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 102 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
97 BrowserThread::CurrentlyOn(BrowserThread::FILE)); 103 BrowserThread::CurrentlyOn(BrowserThread::FILE));
98 } 104 }
99 105
100 void UnpackedInstaller::Load(const FilePath& path_in) { 106 void UnpackedInstaller::Load(const FilePath& path_in) {
101 extension_path_ = path_in; 107 extension_path_ = path_in;
102 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 108 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
103 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); 109 base::Bind(&UnpackedInstaller::GetAbsolutePath, this));
104 } 110 }
105 111
106 void UnpackedInstaller::LoadFromCommandLine(const FilePath& path_in) { 112 void UnpackedInstaller::LoadFromCommandLine(const FilePath& path_in) {
113 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
114
107 if (!service_weak_.get()) 115 if (!service_weak_.get())
108 return; 116 return;
109 // Load extensions from the command line synchronously to avoid a race 117 // Load extensions from the command line synchronously to avoid a race
110 // between extension loading and loading an URL from the command line. 118 // between extension loading and loading an URL from the command line.
111 base::ThreadRestrictions::ScopedAllowIO allow_io; 119 base::ThreadRestrictions::ScopedAllowIO allow_io;
112 120
113 extension_path_ = path_in; 121 extension_path_ = path_in;
114 file_util::AbsolutePath(&extension_path_); 122 file_util::AbsolutePath(&extension_path_);
115 123
116 if (!IsLoadingUnpackedAllowed()) { 124 if (!IsLoadingUnpackedAllowed()) {
117 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); 125 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError);
118 return; 126 return;
119 } 127 }
120 128
121 std::string id = Extension::GenerateIdForPath(extension_path_); 129 std::string id = Extension::GenerateIdForPath(extension_path_);
122 bool allow_file_access = 130 bool allow_file_access =
123 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD); 131 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD);
124 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id)) 132 if (service_weak_->extension_prefs()->HasAllowFileAccessSetting(id))
125 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id); 133 allow_file_access = service_weak_->extension_prefs()->AllowFileAccess(id);
126 134
127 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION; 135 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION;
128 if (allow_file_access) 136 if (allow_file_access)
129 flags |= Extension::ALLOW_FILE_ACCESS; 137 flags |= Extension::ALLOW_FILE_ACCESS;
130 138
131 std::string error; 139 std::string error;
132 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( 140 extension_ = extension_file_util::LoadExtension(
133 extension_path_, 141 extension_path_,
134 Extension::LOAD, 142 Extension::LOAD,
135 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE, 143 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE,
136 &error)); 144 &error);
137 145
138 if (!extension) { 146 if (!extension_.get()) {
139 ReportExtensionLoadError(error); 147 ReportExtensionLoadError(error);
140 return; 148 return;
141 } 149 }
142 150
143 OnLoaded(extension); 151 requirements_checker_->Check(
152 extension_,
153 base::Bind(&UnpackedInstaller::RequirementsChecked, this),
154 BrowserThread::UI);
155 }
156
157 void UnpackedInstaller::RequirementsChecked(std::vector<std::string> errors) {
158 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
159
160 if (!errors.empty()) {
161 ReportExtensionLoadError(JoinString(errors, ' '));
162 return;
163 }
164
165 OnLoaded();
144 } 166 }
145 167
146 bool UnpackedInstaller::IsLoadingUnpackedAllowed() const { 168 bool UnpackedInstaller::IsLoadingUnpackedAllowed() const {
147 if (!service_weak_) 169 if (!service_weak_)
148 return true; 170 return true;
149 // If there is a "*" in the extension blacklist, then no extensions should be 171 // If there is a "*" in the extension blacklist, then no extensions should be
150 // allowed at all (except explicitly whitelisted extensions). 172 // allowed at all (except explicitly whitelisted extensions).
151 return !service_weak_->extension_prefs()->ExtensionsBlacklistedByDefault(); 173 return !service_weak_->extension_prefs()->ExtensionsBlacklistedByDefault();
152 } 174 }
153 175
(...skipping 29 matching lines...) Expand all
183 &UnpackedInstaller::LoadWithFileAccess, 205 &UnpackedInstaller::LoadWithFileAccess,
184 this, allow_file_access)); 206 this, allow_file_access));
185 } 207 }
186 208
187 void UnpackedInstaller::LoadWithFileAccess(bool allow_file_access) { 209 void UnpackedInstaller::LoadWithFileAccess(bool allow_file_access) {
188 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 210 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
189 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION; 211 int flags = Extension::REQUIRE_MODERN_MANIFEST_VERSION;
190 if (allow_file_access) 212 if (allow_file_access)
191 flags |= Extension::ALLOW_FILE_ACCESS; 213 flags |= Extension::ALLOW_FILE_ACCESS;
192 std::string error; 214 std::string error;
193 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( 215 extension_ = extension_file_util::LoadExtension(
194 extension_path_, 216 extension_path_,
195 Extension::LOAD, 217 Extension::LOAD,
196 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE, 218 flags | Extension::FOLLOW_SYMLINKS_ANYWHERE,
197 &error)); 219 &error);
198 220
199 if (!extension) { 221 if (!extension_.get()) {
200 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 222 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
201 base::Bind( 223 base::Bind(
202 &UnpackedInstaller::ReportExtensionLoadError, 224 &UnpackedInstaller::ReportExtensionLoadError,
203 this, error)); 225 this, error));
204 return; 226 return;
205 } 227 }
206 228
207 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 229 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
208 base::Bind( 230 base::Bind(&RequirementsChecker::Check,
209 &UnpackedInstaller::OnLoaded, 231 base::Unretained(requirements_checker_.get()),
210 this, extension)); 232 extension_,
233 base::Bind(&UnpackedInstaller::RequirementsChecked, this),
234 BrowserThread::UI));
211 } 235 }
212 236
213 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) { 237 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) {
214 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 238 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215 if (!service_weak_.get()) 239 if (!service_weak_.get())
216 return; 240 return;
217 service_weak_->ReportExtensionLoadError(extension_path_, error, true); 241 service_weak_->ReportExtensionLoadError(extension_path_, error, true);
218 } 242 }
219 243
220 void UnpackedInstaller::OnLoaded( 244 void UnpackedInstaller::OnLoaded() {
221 const scoped_refptr<const Extension>& extension) {
222 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 245 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 if (!service_weak_.get()) 246 if (!service_weak_.get())
224 return; 247 return;
225 const ExtensionSet* disabled_extensions = 248 const ExtensionSet* disabled_extensions =
226 service_weak_->disabled_extensions(); 249 service_weak_->disabled_extensions();
227 if (service_weak_->show_extensions_prompts() && 250 if (service_weak_->show_extensions_prompts() &&
228 prompt_for_plugins_ && 251 prompt_for_plugins_ &&
229 !extension->plugins().empty() && 252 !extension_->plugins().empty() &&
230 !disabled_extensions->Contains(extension->id())) { 253 !disabled_extensions->Contains(extension_->id())) {
231 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( 254 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
232 service_weak_->profile(), 255 service_weak_->profile(),
233 service_weak_, 256 service_weak_,
234 extension); 257 extension_);
235 prompt->ShowPrompt(); 258 prompt->ShowPrompt();
236 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* 259 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt*
237 } 260 }
238 261
239 PermissionsUpdater perms_updater(service_weak_->profile()); 262 PermissionsUpdater perms_updater(service_weak_->profile());
240 perms_updater.GrantActivePermissions(extension, false); 263 perms_updater.GrantActivePermissions(extension_, false);
241 service_weak_->OnExtensionInstalled(extension, 264 service_weak_->OnExtensionInstalled(extension_,
242 false, // Not from web store. 265 false, // Not from web store.
243 StringOrdinal()); 266 StringOrdinal(),
267 std::vector<std::string>());
244 } 268 }
245 269
246 } // namespace extensions 270 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698