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

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

Issue 11054006: Make application shortcuts point to app_host.exe, install App Host during app installation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Changed AppHostInstaller interface; handled thread compilcation in AppHostInstaller; added error me… Created 8 years, 2 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 "base/string_util.h"
11 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
12 #include "chrome/browser/extensions/app_host_installer.h"
12 #include "chrome/browser/extensions/extension_install_prompt.h" 13 #include "chrome/browser/extensions/extension_install_prompt.h"
13 #include "chrome/browser/extensions/extension_install_ui.h" 14 #include "chrome/browser/extensions/extension_install_ui.h"
14 #include "chrome/browser/extensions/extension_prefs.h" 15 #include "chrome/browser/extensions/extension_prefs.h"
15 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/permissions_updater.h" 17 #include "chrome/browser/extensions/permissions_updater.h"
17 #include "chrome/browser/extensions/requirements_checker.h" 18 #include "chrome/browser/extensions/requirements_checker.h"
18 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_file_util.h" 20 #include "chrome/common/extensions/extension_file_util.h"
21 #include "grit/generated_resources.h"
20 #include "sync/api/string_ordinal.h" 22 #include "sync/api/string_ordinal.h"
23 #include "ui/base/l10n/l10n_util.h"
21 24
22 using content::BrowserThread; 25 using content::BrowserThread;
23 using extensions::Extension; 26 using extensions::Extension;
24 27
25 namespace { 28 namespace {
26 29
27 const char kUnpackedExtensionsBlacklistedError[] = 30 const char kUnpackedExtensionsBlacklistedError[] =
28 "Loading of unpacked extensions is disabled by the administrator."; 31 "Loading of unpacked extensions is disabled by the administrator.";
29 32
30 // Manages an ExtensionInstallPrompt for a particular extension. 33 // Manages an ExtensionInstallPrompt for a particular extension.
31 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { 34 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate {
32 public: 35 public:
33 SimpleExtensionLoadPrompt(Profile* profile, 36 SimpleExtensionLoadPrompt(Profile* profile,
34 base::WeakPtr<ExtensionService> extension_service, 37 base::WeakPtr<ExtensionService> extension_service,
35 const Extension* extension); 38 const Extension* extension,
39 const base::Closure& callback);
36 ~SimpleExtensionLoadPrompt(); 40 ~SimpleExtensionLoadPrompt();
37 41
38 void ShowPrompt(); 42 void ShowPrompt();
39 43
40 // ExtensionInstallUI::Delegate 44 // ExtensionInstallUI::Delegate
41 virtual void InstallUIProceed() OVERRIDE; 45 virtual void InstallUIProceed() OVERRIDE;
42 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; 46 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
43 47
44 private: 48 private:
45 base::WeakPtr<ExtensionService> service_weak_; 49 base::WeakPtr<ExtensionService> service_weak_;
46 scoped_ptr<ExtensionInstallPrompt> install_ui_; 50 scoped_ptr<ExtensionInstallPrompt> install_ui_;
47 scoped_refptr<const Extension> extension_; 51 scoped_refptr<const Extension> extension_;
52 const base::Closure& callback_;
48 }; 53 };
49 54
50 SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( 55 SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt(
51 Profile* profile, 56 Profile* profile,
52 base::WeakPtr<ExtensionService> extension_service, 57 base::WeakPtr<ExtensionService> extension_service,
53 const Extension* extension) 58 const Extension* extension,
59 const base::Closure& callback)
54 : service_weak_(extension_service), 60 : service_weak_(extension_service),
55 extension_(extension) { 61 extension_(extension),
62 callback_(callback) {
56 install_ui_.reset( 63 install_ui_.reset(
57 ExtensionInstallUI::CreateInstallPromptWithProfile(profile)); 64 ExtensionInstallUI::CreateInstallPromptWithProfile(profile));
58 } 65 }
59 66
60 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { 67 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() {
61 } 68 }
62 69
63 void SimpleExtensionLoadPrompt::ShowPrompt() { 70 void SimpleExtensionLoadPrompt::ShowPrompt() {
64 install_ui_->ConfirmInstall(this, extension_); 71 install_ui_->ConfirmInstall(this, extension_);
65 } 72 }
66 73
67 void SimpleExtensionLoadPrompt::InstallUIProceed() { 74 void SimpleExtensionLoadPrompt::InstallUIProceed() {
68 if (service_weak_.get()) { 75 if (service_weak_.get()) {
69 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); 76 callback_.Run();
70 perms_updater.GrantActivePermissions(extension_, false);
71 service_weak_->OnExtensionInstalled(
72 extension_,
73 false, // Not from web store.
74 syncer::StringOrdinal(),
75 false /* no requirement errors */);
76 } 77 }
77 delete this; 78 delete this;
78 } 79 }
79 80
80 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { 81 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) {
81 delete this; 82 delete this;
82 } 83 }
83 84
84 } // namespace 85 } // namespace
85 86
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return; 248 return;
248 const ExtensionSet* disabled_extensions = 249 const ExtensionSet* disabled_extensions =
249 service_weak_->disabled_extensions(); 250 service_weak_->disabled_extensions();
250 if (service_weak_->show_extensions_prompts() && 251 if (service_weak_->show_extensions_prompts() &&
251 prompt_for_plugins_ && 252 prompt_for_plugins_ &&
252 !extension_->plugins().empty() && 253 !extension_->plugins().empty() &&
253 !disabled_extensions->Contains(extension_->id())) { 254 !disabled_extensions->Contains(extension_->id())) {
254 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( 255 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
255 service_weak_->profile(), 256 service_weak_->profile(),
256 service_weak_, 257 service_weak_,
257 extension_); 258 extension_,
259 base::Bind(&UnpackedInstaller::BeginInstall, this));
258 prompt->ShowPrompt(); 260 prompt->ShowPrompt();
259 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* 261 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt*
260 } 262 }
263 BeginInstall();
264 }
261 265
266 void UnpackedInstaller::BeginInstall() {
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
268 app_host_installer_.InstallAppHostIfNecessaryThenCall(
269 *extension_,
270 base::Bind(&UnpackedInstaller::OnAppHostInstallation, this));
271 }
272
273 void UnpackedInstaller::OnAppHostInstallation(bool success) {
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
275 if (!success) {
276 UnpackedInstaller::ReportExtensionLoadError(
277 l10n_util::GetStringUTF8(IDS_EXTENSION_APP_HOST_INSTALL_ERROR));
278 return;
279 }
280 CompleteInstall();
281 }
282
283 void UnpackedInstaller::CompleteInstall() {
284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
262 PermissionsUpdater perms_updater(service_weak_->profile()); 285 PermissionsUpdater perms_updater(service_weak_->profile());
263 perms_updater.GrantActivePermissions(extension_, false); 286 perms_updater.GrantActivePermissions(extension_, false);
264 service_weak_->OnExtensionInstalled(extension_, 287 service_weak_->OnExtensionInstalled(extension_,
265 false, // Not from web store. 288 false, // Not from web store.
266 syncer::StringOrdinal(), 289 syncer::StringOrdinal(),
267 false /* no requirement errors */); 290 false /* no requirement errors */);
268 } 291 }
269 292
270 } // namespace extensions 293 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698