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/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "base/version.h" | 22 #include "base/version.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/extensions/convert_user_script.h" | 24 #include "chrome/browser/extensions/convert_user_script.h" |
25 #include "chrome/browser/extensions/convert_web_app.h" | 25 #include "chrome/browser/extensions/convert_web_app.h" |
26 #include "chrome/browser/extensions/default_apps_trial.h" | 26 #include "chrome/browser/extensions/default_apps_trial.h" |
27 #include "chrome/browser/extensions/extension_error_reporter.h" | 27 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 28 #include "chrome/browser/extensions/extension_install_ui.h" |
28 #include "chrome/browser/extensions/extension_service.h" | 29 #include "chrome/browser/extensions/extension_service.h" |
29 #include "chrome/browser/extensions/permissions_updater.h" | 30 #include "chrome/browser/extensions/permissions_updater.h" |
30 #include "chrome/browser/extensions/webstore_installer.h" | 31 #include "chrome/browser/extensions/webstore_installer.h" |
31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/shell_integration.h" | 33 #include "chrome/browser/shell_integration.h" |
33 #include "chrome/browser/web_applications/web_app.h" | 34 #include "chrome/browser/web_applications/web_app.h" |
34 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
36 #include "chrome/common/extensions/extension_constants.h" | 37 #include "chrome/common/extensions/extension_constants.h" |
37 #include "chrome/common/extensions/extension_file_util.h" | 38 #include "chrome/common/extensions/extension_file_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
48 #include "ui/base/resource/resource_bundle.h" | 49 #include "ui/base/resource/resource_bundle.h" |
49 | 50 |
50 using content::BrowserThread; | 51 using content::BrowserThread; |
51 using content::UserMetricsAction; | 52 using content::UserMetricsAction; |
52 using extensions::Extension; | 53 using extensions::Extension; |
53 using extensions::PermissionsUpdater; | 54 using extensions::PermissionsUpdater; |
54 | 55 |
55 // static | 56 // static |
56 scoped_refptr<CrxInstaller> CrxInstaller::Create( | 57 scoped_refptr<CrxInstaller> CrxInstaller::Create( |
57 ExtensionService* frontend, | 58 ExtensionService* frontend, |
58 ExtensionInstallUI* client) { | 59 ExtensionInstallPrompt* client) { |
59 return new CrxInstaller(frontend->AsWeakPtr(), client, NULL); | 60 return new CrxInstaller(frontend->AsWeakPtr(), client, NULL); |
60 } | 61 } |
61 | 62 |
62 // static | 63 // static |
63 scoped_refptr<CrxInstaller> CrxInstaller::Create( | 64 scoped_refptr<CrxInstaller> CrxInstaller::Create( |
64 ExtensionService* frontend, | 65 ExtensionService* frontend, |
65 ExtensionInstallUI* client, | 66 ExtensionInstallPrompt* client, |
66 const WebstoreInstaller::Approval* approval) { | 67 const WebstoreInstaller::Approval* approval) { |
67 return new CrxInstaller(frontend->AsWeakPtr(), client, approval); | 68 return new CrxInstaller(frontend->AsWeakPtr(), client, approval); |
68 } | 69 } |
69 | 70 |
70 CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, | 71 CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, |
71 ExtensionInstallUI* client, | 72 ExtensionInstallPrompt* client, |
72 const WebstoreInstaller::Approval* approval) | 73 const WebstoreInstaller::Approval* approval) |
73 : install_directory_(frontend_weak->install_directory()), | 74 : install_directory_(frontend_weak->install_directory()), |
74 install_source_(Extension::INTERNAL), | 75 install_source_(Extension::INTERNAL), |
75 approved_(false), | 76 approved_(false), |
76 extensions_enabled_(frontend_weak->extensions_enabled()), | 77 extensions_enabled_(frontend_weak->extensions_enabled()), |
77 delete_source_(false), | 78 delete_source_(false), |
78 create_app_shortcut_(false), | 79 create_app_shortcut_(false), |
79 frontend_weak_(frontend_weak), | 80 frontend_weak_(frontend_weak), |
80 profile_(frontend_weak->profile()), | 81 profile_(frontend_weak->profile()), |
81 client_(client), | 82 client_(client), |
82 apps_require_extension_mime_type_(false), | 83 apps_require_extension_mime_type_(false), |
83 allow_silent_install_(false), | 84 allow_silent_install_(false), |
84 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), | 85 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), |
85 creation_flags_(Extension::NO_FLAGS) { | 86 creation_flags_(Extension::NO_FLAGS) { |
86 if (!approval) | 87 if (!approval) |
87 return; | 88 return; |
88 | 89 |
89 CHECK(profile_->IsSameProfile(approval->profile)); | 90 CHECK(profile_->IsSameProfile(approval->profile)); |
90 client_->set_use_app_installed_bubble(approval->use_app_installed_bubble); | 91 client_->set_use_app_installed_bubble(approval->use_app_installed_bubble); |
91 client_->set_skip_post_install_ui(approval->skip_post_install_ui); | 92 client_->SetSkipPostInstallUI(approval->skip_post_install_ui); |
92 | 93 |
93 if (approval->skip_install_dialog) { | 94 if (approval->skip_install_dialog) { |
94 // Mark the extension as approved, but save the expected manifest and ID | 95 // Mark the extension as approved, but save the expected manifest and ID |
95 // so we can check that they match the CRX's. | 96 // so we can check that they match the CRX's. |
96 approved_ = true; | 97 approved_ = true; |
97 expected_manifest_.reset(approval->parsed_manifest->DeepCopy()); | 98 expected_manifest_.reset(approval->parsed_manifest->DeepCopy()); |
98 expected_id_ = approval->extension_id; | 99 expected_id_ = approval->extension_id; |
99 } | 100 } |
100 } | 101 } |
101 | 102 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 content::Details<const string16>(&error)); | 482 content::Details<const string16>(&error)); |
482 | 483 |
483 // This isn't really necessary, it is only used because unit tests expect to | 484 // This isn't really necessary, it is only used because unit tests expect to |
484 // see errors get reported via this interface. | 485 // see errors get reported via this interface. |
485 // | 486 // |
486 // TODO(aa): Need to go through unit tests and clean them up too, probably get | 487 // TODO(aa): Need to go through unit tests and clean them up too, probably get |
487 // rid of this line. | 488 // rid of this line. |
488 ExtensionErrorReporter::GetInstance()->ReportError(error, false); // quiet | 489 ExtensionErrorReporter::GetInstance()->ReportError(error, false); // quiet |
489 | 490 |
490 if (client_) | 491 if (client_) |
491 client_->OnInstallFailure(error); | 492 client_->install_ui()->OnInstallFailure(error); |
492 | 493 |
493 NotifyCrxInstallComplete(NULL); | 494 NotifyCrxInstallComplete(NULL); |
494 } | 495 } |
495 | 496 |
496 void CrxInstaller::ReportSuccessFromFileThread() { | 497 void CrxInstaller::ReportSuccessFromFileThread() { |
497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
498 | 499 |
499 // Tracking number of extensions installed by users | 500 // Tracking number of extensions installed by users |
500 if (install_cause() == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) { | 501 if (install_cause() == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) { |
501 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionInstalled", 1, 2); | 502 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionInstalled", 1, 2); |
(...skipping 14 matching lines...) Expand all Loading... |
516 NOTREACHED(); | 517 NOTREACHED(); |
517 } | 518 } |
518 | 519 |
519 void CrxInstaller::ReportSuccessFromUIThread() { | 520 void CrxInstaller::ReportSuccessFromUIThread() { |
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
521 | 522 |
522 if (!frontend_weak_.get()) | 523 if (!frontend_weak_.get()) |
523 return; | 524 return; |
524 | 525 |
525 // If there is a client, tell the client about installation. | 526 // If there is a client, tell the client about installation. |
526 if (client_) | 527 if (client_) { |
527 client_->OnInstallSuccess(extension_.get(), install_icon_.get()); | 528 client_->install_ui()->OnInstallSuccess( |
| 529 extension_.get(), install_icon_.get()); |
| 530 } |
528 | 531 |
529 // We update the extension's granted permissions if the user already approved | 532 // We update the extension's granted permissions if the user already approved |
530 // the install (client_ is non NULL), or we are allowed to install this | 533 // the install (client_ is non NULL), or we are allowed to install this |
531 // silently. | 534 // silently. |
532 if (client_ || allow_silent_install_) { | 535 if (client_ || allow_silent_install_) { |
533 PermissionsUpdater perms_updater(profile()); | 536 PermissionsUpdater perms_updater(profile()); |
534 perms_updater.GrantActivePermissions(extension_); | 537 perms_updater.GrantActivePermissions(extension_); |
535 } | 538 } |
536 | 539 |
537 // Tell the frontend about the installation and hand off ownership of | 540 // Tell the frontend about the installation and hand off ownership of |
(...skipping 13 matching lines...) Expand all Loading... |
551 // Some users (such as the download shelf) need to know when a | 554 // Some users (such as the download shelf) need to know when a |
552 // CRXInstaller is done. Listening for the EXTENSION_* events | 555 // CRXInstaller is done. Listening for the EXTENSION_* events |
553 // is problematic because they don't know anything about the | 556 // is problematic because they don't know anything about the |
554 // extension before it is unpacked, so they cannot filter based | 557 // extension before it is unpacked, so they cannot filter based |
555 // on the extension. | 558 // on the extension. |
556 content::NotificationService::current()->Notify( | 559 content::NotificationService::current()->Notify( |
557 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 560 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
558 content::Source<CrxInstaller>(this), | 561 content::Source<CrxInstaller>(this), |
559 content::Details<const Extension>(extension)); | 562 content::Details<const Extension>(extension)); |
560 } | 563 } |
OLD | NEW |