OLD | NEW |
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" |
20 #include "sync/api/string_ordinal.h" | 21 #include "sync/api/string_ordinal.h" |
21 | 22 |
(...skipping 12 matching lines...) Expand all Loading... |
34 base::WeakPtr<ExtensionService> extension_service, | 35 base::WeakPtr<ExtensionService> extension_service, |
35 const Extension* extension); | 36 const Extension* extension); |
36 ~SimpleExtensionLoadPrompt(); | 37 ~SimpleExtensionLoadPrompt(); |
37 | 38 |
38 void ShowPrompt(); | 39 void ShowPrompt(); |
39 | 40 |
40 // ExtensionInstallUI::Delegate | 41 // ExtensionInstallUI::Delegate |
41 virtual void InstallUIProceed() OVERRIDE; | 42 virtual void InstallUIProceed() OVERRIDE; |
42 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 43 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
43 | 44 |
| 45 void OnAppHostInstallation(bool success); |
| 46 void CompleteInstall(); |
| 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 extensions::AppHostInstaller app_host_installer_; |
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) |
54 : service_weak_(extension_service), | 59 : service_weak_(extension_service), |
55 extension_(extension) { | 60 extension_(extension) { |
56 install_ui_.reset( | 61 install_ui_.reset( |
57 ExtensionInstallUI::CreateInstallPromptWithProfile(profile)); | 62 ExtensionInstallUI::CreateInstallPromptWithProfile(profile)); |
58 } | 63 } |
59 | 64 |
60 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { | 65 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { |
61 } | 66 } |
62 | 67 |
63 void SimpleExtensionLoadPrompt::ShowPrompt() { | 68 void SimpleExtensionLoadPrompt::ShowPrompt() { |
64 install_ui_->ConfirmInstall(this, extension_); | 69 install_ui_->ConfirmInstall(this, extension_); |
65 } | 70 } |
66 | 71 |
67 void SimpleExtensionLoadPrompt::InstallUIProceed() { | 72 void SimpleExtensionLoadPrompt::InstallUIProceed() { |
68 if (service_weak_.get()) { | 73 if (service_weak_.get()) { |
69 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); | 74 if (extensions::AppHostInstaller::IsAppHostInstallRequired(*extension_)) { |
70 perms_updater.GrantActivePermissions(extension_, false); | 75 // TODO(huangs): Should this be Unretained, or not? |
71 service_weak_->OnExtensionInstalled( | 76 app_host_installer_.InstallAppHost( |
72 extension_, | 77 base::Bind(&SimpleExtensionLoadPrompt::OnAppHostInstallation, |
73 false, // Not from web store. | 78 base::Unretained(this))); |
74 syncer::StringOrdinal(), | 79 } else { |
75 false /* no requirement errors */); | 80 CompleteInstall(); |
| 81 } |
| 82 } else { |
| 83 delete this; |
76 } | 84 } |
| 85 } |
| 86 |
| 87 void SimpleExtensionLoadPrompt::OnAppHostInstallation(bool success) { |
| 88 if (success) { |
| 89 CompleteInstall(); |
| 90 } else { |
| 91 // TODO(huangs): Error message. |
| 92 delete this; |
| 93 } |
| 94 } |
| 95 |
| 96 void SimpleExtensionLoadPrompt::CompleteInstall() { |
| 97 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); |
| 98 perms_updater.GrantActivePermissions(extension_, false); |
| 99 service_weak_->OnExtensionInstalled( |
| 100 extension_, |
| 101 false, // Not from web store. |
| 102 syncer::StringOrdinal(), |
| 103 false /* no requirement errors */); |
77 delete this; | 104 delete this; |
78 } | 105 } |
79 | 106 |
80 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { | 107 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { |
81 delete this; | 108 delete this; |
82 } | 109 } |
83 | 110 |
84 } // namespace | 111 } // namespace |
85 | 112 |
86 namespace extensions { | 113 namespace extensions { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 !extension_->plugins().empty() && | 279 !extension_->plugins().empty() && |
253 !disabled_extensions->Contains(extension_->id())) { | 280 !disabled_extensions->Contains(extension_->id())) { |
254 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( | 281 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( |
255 service_weak_->profile(), | 282 service_weak_->profile(), |
256 service_weak_, | 283 service_weak_, |
257 extension_); | 284 extension_); |
258 prompt->ShowPrompt(); | 285 prompt->ShowPrompt(); |
259 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* | 286 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* |
260 } | 287 } |
261 | 288 |
| 289 if (AppHostInstaller::IsAppHostInstallRequired(*extension_)) { |
| 290 // Calls CompleteInstall() after. |
| 291 app_host_installer_.InstallAppHost( |
| 292 base::Bind(&UnpackedInstaller::OnAppHostInstallation, this)); |
| 293 } else { |
| 294 CompleteInstall(); |
| 295 } |
| 296 } |
| 297 |
| 298 void UnpackedInstaller::OnAppHostInstallation(bool success) { |
| 299 if (success) { |
| 300 CompleteInstall(); |
| 301 } else { |
| 302 // TODO(huangs): Error message. |
| 303 std::string error = "Some random error message"; |
| 304 UnpackedInstaller::ReportExtensionLoadError(error); |
| 305 } |
| 306 } |
| 307 |
| 308 void UnpackedInstaller::CompleteInstall() { |
| 309 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
262 PermissionsUpdater perms_updater(service_weak_->profile()); | 310 PermissionsUpdater perms_updater(service_weak_->profile()); |
263 perms_updater.GrantActivePermissions(extension_, false); | 311 perms_updater.GrantActivePermissions(extension_, false); |
264 service_weak_->OnExtensionInstalled(extension_, | 312 service_weak_->OnExtensionInstalled(extension_, |
265 false, // Not from web store. | 313 false, // Not from web store. |
266 syncer::StringOrdinal(), | 314 syncer::StringOrdinal(), |
267 false /* no requirement errors */); | 315 false /* no requirement errors */); |
268 } | 316 } |
269 | 317 |
270 } // namespace extensions | 318 } // namespace extensions |
OLD | NEW |