OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Download code which handles CRX files (extensions, themes, apps, ...). | 5 // Download code which handles CRX files (extensions, themes, apps, ...). |
6 | 6 |
7 #include "chrome/browser/download/download_item.h" | 7 #include "chrome/browser/download/download_item.h" |
8 #include "chrome/browser/download/download_util.h" | 8 #include "chrome/browser/download/download_util.h" |
9 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
10 #include "chrome/browser/extensions/extension_install_ui.h" | 10 #include "chrome/browser/extensions/extension_install_ui.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/chrome_notification_types.h" |
13 #include "content/common/notification_service.h" | 14 #include "content/common/notification_service.h" |
14 | 15 |
15 namespace download_crx_util { | 16 namespace download_crx_util { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Hold a mock ExtensionInstallUI object that will be used when the | 20 // Hold a mock ExtensionInstallUI object that will be used when the |
20 // download system opens a CRX. | 21 // download system opens a CRX. |
21 ExtensionInstallUI* mock_install_ui_for_testing = NULL; | 22 ExtensionInstallUI* mock_install_ui_for_testing = NULL; |
22 | 23 |
(...skipping 25 matching lines...) Expand all Loading... |
48 scoped_refptr<CrxInstaller> OpenChromeExtension( | 49 scoped_refptr<CrxInstaller> OpenChromeExtension( |
49 Profile* profile, | 50 Profile* profile, |
50 const DownloadItem& download_item) { | 51 const DownloadItem& download_item) { |
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
52 DCHECK(download_item.is_extension_install()); | 53 DCHECK(download_item.is_extension_install()); |
53 | 54 |
54 ExtensionService* service = profile->GetExtensionService(); | 55 ExtensionService* service = profile->GetExtensionService(); |
55 CHECK(service); | 56 CHECK(service); |
56 NotificationService* nservice = NotificationService::current(); | 57 NotificationService* nservice = NotificationService::current(); |
57 GURL nonconst_download_url = download_item.GetURL(); | 58 GURL nonconst_download_url = download_item.GetURL(); |
58 nservice->Notify(NotificationType::EXTENSION_READY_FOR_INSTALL, | 59 nservice->Notify(chrome::NOTIFICATION_EXTENSION_READY_FOR_INSTALL, |
59 Source<DownloadManager>(profile->GetDownloadManager()), | 60 Source<DownloadManager>(profile->GetDownloadManager()), |
60 Details<GURL>(&nonconst_download_url)); | 61 Details<GURL>(&nonconst_download_url)); |
61 | 62 |
62 scoped_refptr<CrxInstaller> installer( | 63 scoped_refptr<CrxInstaller> installer( |
63 service->MakeCrxInstaller(CreateExtensionInstallUI(profile))); | 64 service->MakeCrxInstaller(CreateExtensionInstallUI(profile))); |
64 installer->set_delete_source(true); | 65 installer->set_delete_source(true); |
65 | 66 |
66 if (UserScript::IsURLUserScript(download_item.GetURL(), | 67 if (UserScript::IsURLUserScript(download_item.GetURL(), |
67 download_item.mime_type())) { | 68 download_item.mime_type())) { |
68 installer->InstallUserScript(download_item.full_path(), | 69 installer->InstallUserScript(download_item.full_path(), |
69 download_item.GetURL()); | 70 download_item.GetURL()); |
70 } else { | 71 } else { |
71 bool is_gallery_download = service->IsDownloadFromGallery( | 72 bool is_gallery_download = service->IsDownloadFromGallery( |
72 download_item.GetURL(), download_item.referrer_url()); | 73 download_item.GetURL(), download_item.referrer_url()); |
73 installer->set_original_mime_type(download_item.original_mime_type()); | 74 installer->set_original_mime_type(download_item.original_mime_type()); |
74 installer->set_apps_require_extension_mime_type(true); | 75 installer->set_apps_require_extension_mime_type(true); |
75 installer->set_original_url(download_item.GetURL()); | 76 installer->set_original_url(download_item.GetURL()); |
76 installer->set_is_gallery_install(is_gallery_download); | 77 installer->set_is_gallery_install(is_gallery_download); |
77 installer->set_allow_silent_install(is_gallery_download); | 78 installer->set_allow_silent_install(is_gallery_download); |
78 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); | 79 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); |
79 installer->InstallCrx(download_item.full_path()); | 80 installer->InstallCrx(download_item.full_path()); |
80 } | 81 } |
81 | 82 |
82 return installer; | 83 return installer; |
83 } | 84 } |
84 | 85 |
85 } // namespace download_crx_util | 86 } // namespace download_crx_util |
OLD | NEW |