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 |
22 using content::BrowserThread; | 23 using content::BrowserThread; |
23 using extensions::Extension; | 24 using extensions::Extension; |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 const char kUnpackedExtensionsBlacklistedError[] = | 28 const char kUnpackedExtensionsBlacklistedError[] = |
28 "Loading of unpacked extensions is disabled by the administrator."; | 29 "Loading of unpacked extensions is disabled by the administrator."; |
29 | 30 |
30 // Manages an ExtensionInstallPrompt for a particular extension. | 31 // Manages an ExtensionInstallPrompt for a particular extension. |
31 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { | 32 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { |
32 public: | 33 public: |
33 SimpleExtensionLoadPrompt(Profile* profile, | 34 SimpleExtensionLoadPrompt(Profile* profile, |
34 base::WeakPtr<ExtensionService> extension_service, | 35 base::WeakPtr<ExtensionService> extension_service, |
35 const Extension* extension); | 36 const Extension* extension, |
37 const base::Closure& callback); | |
36 ~SimpleExtensionLoadPrompt(); | 38 ~SimpleExtensionLoadPrompt(); |
37 | 39 |
38 void ShowPrompt(); | 40 void ShowPrompt(); |
39 | 41 |
40 // ExtensionInstallUI::Delegate | 42 // ExtensionInstallUI::Delegate |
41 virtual void InstallUIProceed() OVERRIDE; | 43 virtual void InstallUIProceed() OVERRIDE; |
42 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 44 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
43 | 45 |
46 void BeginInstall(); | |
47 void OnAppHostInstallation(bool success); | |
48 void CompleteInstall(); | |
49 | |
44 private: | 50 private: |
45 base::WeakPtr<ExtensionService> service_weak_; | 51 base::WeakPtr<ExtensionService> service_weak_; |
46 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 52 scoped_ptr<ExtensionInstallPrompt> install_ui_; |
47 scoped_refptr<const Extension> extension_; | 53 scoped_refptr<const Extension> extension_; |
54 const base::Closure& callback_; | |
48 }; | 55 }; |
49 | 56 |
50 SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( | 57 SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( |
51 Profile* profile, | 58 Profile* profile, |
52 base::WeakPtr<ExtensionService> extension_service, | 59 base::WeakPtr<ExtensionService> extension_service, |
53 const Extension* extension) | 60 const Extension* extension, |
61 const base::Closure& callback) | |
54 : service_weak_(extension_service), | 62 : service_weak_(extension_service), |
55 extension_(extension) { | 63 extension_(extension), |
64 callback_(callback) { | |
56 install_ui_.reset( | 65 install_ui_.reset( |
57 ExtensionInstallUI::CreateInstallPromptWithProfile(profile)); | 66 ExtensionInstallUI::CreateInstallPromptWithProfile(profile)); |
58 } | 67 } |
59 | 68 |
60 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { | 69 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { |
61 } | 70 } |
62 | 71 |
63 void SimpleExtensionLoadPrompt::ShowPrompt() { | 72 void SimpleExtensionLoadPrompt::ShowPrompt() { |
64 install_ui_->ConfirmInstall(this, extension_); | 73 install_ui_->ConfirmInstall(this, extension_); |
65 } | 74 } |
66 | 75 |
67 void SimpleExtensionLoadPrompt::InstallUIProceed() { | 76 void SimpleExtensionLoadPrompt::InstallUIProceed() { |
68 if (service_weak_.get()) { | 77 if (service_weak_.get()) { |
erikwright (departed)
2012/10/04 01:28:16
Remove this check, remove the extension_service me
huangs
2012/10/04 22:56:42
Keeping this the way it was, now that we changed i
| |
69 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); | 78 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 } | 79 } |
77 delete this; | 80 delete this; |
78 } | 81 } |
79 | 82 |
80 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { | 83 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { |
81 delete this; | 84 delete this; |
82 } | 85 } |
83 | 86 |
84 } // namespace | 87 } // namespace |
85 | 88 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 return; | 250 return; |
248 const ExtensionSet* disabled_extensions = | 251 const ExtensionSet* disabled_extensions = |
249 service_weak_->disabled_extensions(); | 252 service_weak_->disabled_extensions(); |
250 if (service_weak_->show_extensions_prompts() && | 253 if (service_weak_->show_extensions_prompts() && |
251 prompt_for_plugins_ && | 254 prompt_for_plugins_ && |
252 !extension_->plugins().empty() && | 255 !extension_->plugins().empty() && |
253 !disabled_extensions->Contains(extension_->id())) { | 256 !disabled_extensions->Contains(extension_->id())) { |
254 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( | 257 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( |
255 service_weak_->profile(), | 258 service_weak_->profile(), |
256 service_weak_, | 259 service_weak_, |
257 extension_); | 260 extension_, |
261 base::Bind(&UnpackedInstaller::OnPromptAccepted, this)); | |
258 prompt->ShowPrompt(); | 262 prompt->ShowPrompt(); |
259 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* | 263 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* |
260 } | 264 } |
265 OnPromptAccepted(); | |
266 } | |
261 | 267 |
268 void UnpackedInstaller::OnPromptAccepted() { | |
269 if (!BrowserThread::PostTask( | |
270 BrowserThread::FILE, FROM_HERE, | |
271 base::Bind(&UnpackedInstaller::BeginInstall, this))) | |
272 NOTREACHED(); | |
273 } | |
274 | |
275 void UnpackedInstaller::BeginInstall() { | |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
277 if (AppHostInstaller::IsAppHostInstallRequired(*extension_)) { | |
278 // Calls CompleteInstall() after. | |
279 app_host_installer_.InstallAppHost( | |
280 base::Bind(&UnpackedInstaller::OnAppHostInstallation, this)); | |
benwells
2012/10/04 07:53:01
early return and remove the else.
huangs
2012/10/04 22:56:42
Done.
| |
281 } else { | |
282 CompleteInstall(); | |
283 } | |
284 } | |
285 | |
286 void UnpackedInstaller::OnAppHostInstallation(bool success) { | |
287 if (success) { | |
288 CompleteInstall(); | |
benwells
2012/10/04 07:53:01
early return and remove the else.
huangs
2012/10/04 22:56:42
Done.
| |
289 } else { | |
290 // TODO(huangs): Error message. | |
291 std::string error = "Some random error message"; | |
292 UnpackedInstaller::ReportExtensionLoadError(error); | |
293 } | |
294 } | |
295 | |
296 void UnpackedInstaller::CompleteInstall() { | |
297 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
262 PermissionsUpdater perms_updater(service_weak_->profile()); | 298 PermissionsUpdater perms_updater(service_weak_->profile()); |
erikwright (departed)
2012/10/04 01:28:16
Do a check on service_weak_ around lines 298-303.
erikwright (departed)
2012/10/04 01:28:16
This used to all happen on the UI thread. Have you
huangs
2012/10/04 22:56:42
No check, in light of changed interface to AppHost
huangs
2012/10/04 22:56:42
Changing interface to AppHostInstaller, so still i
| |
263 perms_updater.GrantActivePermissions(extension_, false); | 299 perms_updater.GrantActivePermissions(extension_, false); |
264 service_weak_->OnExtensionInstalled(extension_, | 300 service_weak_->OnExtensionInstalled(extension_, |
265 false, // Not from web store. | 301 false, // Not from web store. |
266 syncer::StringOrdinal(), | 302 syncer::StringOrdinal(), |
267 false /* no requirement errors */); | 303 false /* no requirement errors */); |
268 } | 304 } |
269 | 305 |
270 } // namespace extensions | 306 } // namespace extensions |
OLD | NEW |