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

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

Issue 381553002: Update the CrxInstaller and UnpackedInstaller to use the ExtensionInstallChecker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved include to correct file Created 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
14 #include "chrome/browser/extensions/extension_error_reporter.h" 13 #include "chrome/browser/extensions/extension_error_reporter.h"
15 #include "chrome/browser/extensions/extension_install_prompt.h" 14 #include "chrome/browser/extensions/extension_install_prompt.h"
16 #include "chrome/browser/extensions/extension_install_ui.h" 15 #include "chrome/browser/extensions/extension_install_ui.h"
17 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/permissions_updater.h" 17 #include "chrome/browser/extensions/permissions_updater.h"
19 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 20 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
22 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DCHECK(extension_service); 107 DCHECK(extension_service);
109 return scoped_refptr<UnpackedInstaller>( 108 return scoped_refptr<UnpackedInstaller>(
110 new UnpackedInstaller(extension_service)); 109 new UnpackedInstaller(extension_service));
111 } 110 }
112 111
113 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service) 112 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service)
114 : service_weak_(extension_service->AsWeakPtr()), 113 : service_weak_(extension_service->AsWeakPtr()),
115 prompt_for_plugins_(true), 114 prompt_for_plugins_(true),
116 require_modern_manifest_version_(true), 115 require_modern_manifest_version_(true),
117 be_noisy_on_failure_(true), 116 be_noisy_on_failure_(true),
118 installer_(extension_service->profile()) { 117 install_checker_(extension_service->profile()) {
119 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 118 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
120 } 119 }
121 120
122 UnpackedInstaller::~UnpackedInstaller() { 121 UnpackedInstaller::~UnpackedInstaller() {
123 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 122 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
124 BrowserThread::CurrentlyOn(BrowserThread::FILE)); 123 BrowserThread::CurrentlyOn(BrowserThread::FILE));
125 } 124 }
126 125
127 void UnpackedInstaller::Load(const base::FilePath& path_in) { 126 void UnpackedInstaller::Load(const base::FilePath& path_in) {
128 DCHECK(extension_path_.empty()); 127 DCHECK(extension_path_.empty());
(...skipping 16 matching lines...) Expand all
145 base::ThreadRestrictions::ScopedAllowIO allow_io; 144 base::ThreadRestrictions::ScopedAllowIO allow_io;
146 145
147 extension_path_ = base::MakeAbsoluteFilePath(path_in); 146 extension_path_ = base::MakeAbsoluteFilePath(path_in);
148 147
149 if (!IsLoadingUnpackedAllowed()) { 148 if (!IsLoadingUnpackedAllowed()) {
150 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); 149 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError);
151 return false; 150 return false;
152 } 151 }
153 152
154 std::string error; 153 std::string error;
155 installer_.set_extension( 154 install_checker_.set_extension(
156 file_util::LoadExtension( 155 file_util::LoadExtension(
157 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get()); 156 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get());
158 157
159 if (!installer_.extension().get() || 158 if (!extension() ||
160 !extension_l10n_util::ValidateExtensionLocales( 159 !extension_l10n_util::ValidateExtensionLocales(
161 extension_path_, 160 extension_path_, extension()->manifest()->value(), &error)) {
162 installer_.extension()->manifest()->value(),
163 &error)) {
164 ReportExtensionLoadError(error); 161 ReportExtensionLoadError(error);
165 return false; 162 return false;
166 } 163 }
167 164
168 ShowInstallPrompt(); 165 ShowInstallPrompt();
169 166
170 *extension_id = installer_.extension()->id(); 167 *extension_id = extension()->id();
171 return true; 168 return true;
172 } 169 }
173 170
174 void UnpackedInstaller::ShowInstallPrompt() { 171 void UnpackedInstaller::ShowInstallPrompt() {
175 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 172 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
176 if (!service_weak_.get()) 173 if (!service_weak_.get())
177 return; 174 return;
178 175
179 const ExtensionSet& disabled_extensions = 176 const ExtensionSet& disabled_extensions =
180 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions(); 177 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions();
181 if (service_weak_->show_extensions_prompts() && prompt_for_plugins_ && 178 if (service_weak_->show_extensions_prompts() && prompt_for_plugins_ &&
182 PluginInfo::HasPlugins(installer_.extension().get()) && 179 PluginInfo::HasPlugins(extension()) &&
183 !disabled_extensions.Contains(installer_.extension()->id())) { 180 !disabled_extensions.Contains(extension()->id())) {
184 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( 181 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
185 installer_.extension().get(), 182 extension(),
186 installer_.profile(), 183 install_checker_.profile(),
187 base::Bind(&UnpackedInstaller::CallCheckRequirements, this)); 184 base::Bind(&UnpackedInstaller::StartInstallChecks, this));
188 prompt->ShowPrompt(); 185 prompt->ShowPrompt();
189 return; 186 return;
190 } 187 }
191 CallCheckRequirements(); 188 StartInstallChecks();
192 } 189 }
193 190
194 void UnpackedInstaller::CallCheckRequirements() { 191 void UnpackedInstaller::StartInstallChecks() {
195 installer_.CheckRequirements( 192 install_checker_.Start(
196 base::Bind(&UnpackedInstaller::OnRequirementsChecked, this)); 193 ExtensionInstallChecker::CHECK_REQUIREMENTS |
194 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY,
195 true /* fail fast */,
196 base::Bind(&UnpackedInstaller::OnInstallChecksComplete, this));
197 } 197 }
198 198
199 void UnpackedInstaller::OnRequirementsChecked( 199 void UnpackedInstaller::OnInstallChecksComplete(int failed_checks) {
200 std::vector<std::string> requirement_errors) {
201 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 200 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
202 201
203 if (!requirement_errors.empty()) { 202 if (!install_checker_.policy_error().empty()) {
204 ReportExtensionLoadError(JoinString(requirement_errors, ' ')); 203 ReportExtensionLoadError(install_checker_.policy_error());
205 return; 204 return;
206 } 205 }
207 206
208 ConfirmInstall(); 207 if (!install_checker_.requirement_errors().empty()) {
208 ReportExtensionLoadError(
209 JoinString(install_checker_.requirement_errors(), ' '));
210 return;
211 }
212
213 InstallExtension();
209 } 214 }
210 215
211 int UnpackedInstaller::GetFlags() { 216 int UnpackedInstaller::GetFlags() {
212 std::string id = id_util::GenerateIdForPath(extension_path_); 217 std::string id = id_util::GenerateIdForPath(extension_path_);
213 bool allow_file_access = 218 bool allow_file_access =
214 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED); 219 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED);
215 ExtensionPrefs* prefs = ExtensionPrefs::Get(service_weak_->profile()); 220 ExtensionPrefs* prefs = ExtensionPrefs::Get(service_weak_->profile());
216 if (prefs->HasAllowFileAccessSetting(id)) 221 if (prefs->HasAllowFileAccessSetting(id))
217 allow_file_access = prefs->AllowFileAccess(id); 222 allow_file_access = prefs->AllowFileAccess(id);
218 223
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 BrowserThread::PostTask( 270 BrowserThread::PostTask(
266 BrowserThread::FILE, 271 BrowserThread::FILE,
267 FROM_HERE, 272 FROM_HERE,
268 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); 273 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags()));
269 } 274 }
270 275
271 void UnpackedInstaller::LoadWithFileAccess(int flags) { 276 void UnpackedInstaller::LoadWithFileAccess(int flags) {
272 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 277 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
273 278
274 std::string error; 279 std::string error;
275 installer_.set_extension( 280 install_checker_.set_extension(
276 file_util::LoadExtension( 281 file_util::LoadExtension(
277 extension_path_, Manifest::UNPACKED, flags, &error).get()); 282 extension_path_, Manifest::UNPACKED, flags, &error).get());
278 283
279 if (!installer_.extension().get() || 284 if (!extension() ||
280 !extension_l10n_util::ValidateExtensionLocales( 285 !extension_l10n_util::ValidateExtensionLocales(
281 extension_path_, 286 extension_path_, extension()->manifest()->value(), &error)) {
282 installer_.extension()->manifest()->value(),
283 &error)) {
284 BrowserThread::PostTask( 287 BrowserThread::PostTask(
285 BrowserThread::UI, 288 BrowserThread::UI,
286 FROM_HERE, 289 FROM_HERE,
287 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); 290 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error));
288 return; 291 return;
289 } 292 }
290 293
291 BrowserThread::PostTask( 294 BrowserThread::PostTask(
292 BrowserThread::UI, 295 BrowserThread::UI,
293 FROM_HERE, 296 FROM_HERE,
294 base::Bind(&UnpackedInstaller::ShowInstallPrompt, this)); 297 base::Bind(&UnpackedInstaller::ShowInstallPrompt, this));
295 } 298 }
296 299
297 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) { 300 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) {
298 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 301 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
299 if (!on_failure_callback_.is_null()) 302 if (!on_failure_callback_.is_null())
300 on_failure_callback_.Run(extension_path_, error); 303 on_failure_callback_.Run(extension_path_, error);
301 304
302 if (service_weak_.get()) { 305 if (service_weak_.get()) {
303 ExtensionErrorReporter::GetInstance()->ReportLoadError( 306 ExtensionErrorReporter::GetInstance()->ReportLoadError(
304 extension_path_, 307 extension_path_,
305 error, 308 error,
306 service_weak_->profile(), 309 service_weak_->profile(),
307 be_noisy_on_failure_); 310 be_noisy_on_failure_);
308 } 311 }
309 } 312 }
310 313
311 void UnpackedInstaller::ConfirmInstall() { 314 void UnpackedInstaller::InstallExtension() {
312 DCHECK_CURRENTLY_ON(BrowserThread::UI); 315 DCHECK_CURRENTLY_ON(BrowserThread::UI);
313 base::string16 error = installer_.CheckManagementPolicy();
314 if (!error.empty()) {
315 ReportExtensionLoadError(base::UTF16ToUTF8(error));
316 return;
317 }
318 316
319 PermissionsUpdater perms_updater(service_weak_->profile()); 317 PermissionsUpdater perms_updater(service_weak_->profile());
320 perms_updater.GrantActivePermissions(installer_.extension().get()); 318 perms_updater.GrantActivePermissions(extension());
321 319
322 service_weak_->OnExtensionInstalled(installer_.extension().get(), 320 service_weak_->OnExtensionInstalled(
323 syncer::StringOrdinal(), 321 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately);
324 kInstallFlagInstallImmediately);
325 } 322 }
326 323
327 } // namespace extensions 324 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/unpacked_installer.h ('k') | chrome/browser/supervised_user/supervised_user_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698