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 // 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_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 #include "chrome/browser/extensions/crx_installer.h" | 8 #include "chrome/browser/extensions/crx_installer.h" |
9 #include "chrome/browser/extensions/extension_install_ui.h" | 9 #include "chrome/browser/extensions/extension_install_prompt.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/webstore_installer.h" | 11 #include "chrome/browser/extensions/webstore_installer.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 "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/extensions/extension_switch_utils.h" | 14 #include "chrome/common/extensions/extension_switch_utils.h" |
15 #include "content/public/browser/download_item.h" | 15 #include "content/public/browser/download_item.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 | 17 |
18 using content::BrowserThread; | 18 using content::BrowserThread; |
19 using content::DownloadItem; | 19 using content::DownloadItem; |
20 | 20 |
21 namespace download_crx_util { | 21 namespace download_crx_util { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Hold a mock ExtensionInstallUI object that will be used when the | 25 // Hold a mock ExtensionInstallPrompt object that will be used when the |
26 // download system opens a CRX. | 26 // download system opens a CRX. |
27 ExtensionInstallUI* mock_install_ui_for_testing = NULL; | 27 ExtensionInstallPrompt* mock_install_prompt_for_testing = NULL; |
28 | 28 |
29 // Called to get an extension install UI object. In tests, will return | 29 // Called to get an extension install UI object. In tests, will return |
30 // a mock if the test calls download_util::SetMockInstallUIForTesting() | 30 // a mock if the test calls download_util::SetMockInstallUIForTesting() |
31 // to set one. | 31 // to set one. |
32 ExtensionInstallUI* CreateExtensionInstallUI(Profile* profile) { | 32 ExtensionInstallPrompt* CreateExtensionInstallPrompt(Profile* profile) { |
33 // Use a mock if one is present. Otherwise, create a real extensions | 33 // Use a mock if one is present. Otherwise, create a real extensions |
34 // install UI. | 34 // install UI. |
35 ExtensionInstallUI* result = NULL; | 35 ExtensionInstallPrompt* result = NULL; |
36 if (mock_install_ui_for_testing) { | 36 if (mock_install_prompt_for_testing) { |
37 result = mock_install_ui_for_testing; | 37 result = mock_install_prompt_for_testing; |
38 mock_install_ui_for_testing = NULL; | 38 mock_install_prompt_for_testing = NULL; |
39 } else { | 39 } else { |
40 result = new ExtensionInstallUI(profile); | 40 result = new ExtensionInstallPrompt(profile); |
41 } | 41 } |
42 | 42 |
43 return result; | 43 return result; |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 // Tests can call this method to inject a mock ExtensionInstallUI | 48 // Tests can call this method to inject a mock ExtensionInstallPrompt |
49 // to be used to confirm permissions on a downloaded CRX. | 49 // to be used to confirm permissions on a downloaded CRX. |
50 void SetMockInstallUIForTesting(ExtensionInstallUI* mock_ui) { | 50 void SetMockInstallPromptForTesting(ExtensionInstallPrompt* mock_prompt) { |
51 mock_install_ui_for_testing = mock_ui; | 51 mock_install_prompt_for_testing = mock_prompt; |
52 } | 52 } |
53 | 53 |
54 scoped_refptr<CrxInstaller> OpenChromeExtension( | 54 scoped_refptr<CrxInstaller> OpenChromeExtension( |
55 Profile* profile, | 55 Profile* profile, |
56 const DownloadItem& download_item) { | 56 const DownloadItem& download_item) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 | 58 |
59 ExtensionService* service = profile->GetExtensionService(); | 59 ExtensionService* service = profile->GetExtensionService(); |
60 CHECK(service); | 60 CHECK(service); |
61 | 61 |
62 scoped_refptr<CrxInstaller> installer( | 62 scoped_refptr<CrxInstaller> installer( |
63 CrxInstaller::Create( | 63 CrxInstaller::Create( |
64 service, | 64 service, |
65 CreateExtensionInstallUI(profile), | 65 CreateExtensionInstallPrompt(profile), |
66 WebstoreInstaller::GetAssociatedApproval(download_item))); | 66 WebstoreInstaller::GetAssociatedApproval(download_item))); |
67 installer->set_delete_source(true); | 67 installer->set_delete_source(true); |
68 | 68 |
69 if (UserScript::IsURLUserScript(download_item.GetURL(), | 69 if (UserScript::IsURLUserScript(download_item.GetURL(), |
70 download_item.GetMimeType())) { | 70 download_item.GetMimeType())) { |
71 installer->InstallUserScript(download_item.GetFullPath(), | 71 installer->InstallUserScript(download_item.GetFullPath(), |
72 download_item.GetURL()); | 72 download_item.GetURL()); |
73 } else { | 73 } else { |
74 bool is_gallery_download = | 74 bool is_gallery_download = |
75 WebstoreInstaller::GetAssociatedApproval(download_item) != NULL; | 75 WebstoreInstaller::GetAssociatedApproval(download_item) != NULL; |
76 installer->set_original_mime_type(download_item.GetOriginalMimeType()); | 76 installer->set_original_mime_type(download_item.GetOriginalMimeType()); |
77 installer->set_apps_require_extension_mime_type(true); | 77 installer->set_apps_require_extension_mime_type(true); |
78 installer->set_download_url(download_item.GetURL()); | 78 installer->set_download_url(download_item.GetURL()); |
79 installer->set_is_gallery_install(is_gallery_download); | 79 installer->set_is_gallery_install(is_gallery_download); |
80 if (is_gallery_download) | 80 if (is_gallery_download) |
81 installer->set_original_download_url(download_item.GetOriginalUrl()); | 81 installer->set_original_download_url(download_item.GetOriginalUrl()); |
82 installer->set_allow_silent_install(is_gallery_download); | 82 installer->set_allow_silent_install(is_gallery_download); |
83 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); | 83 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); |
84 installer->InstallCrx(download_item.GetFullPath()); | 84 installer->InstallCrx(download_item.GetFullPath()); |
85 } | 85 } |
86 | 86 |
87 return installer; | 87 return installer; |
88 } | 88 } |
89 | 89 |
90 } // namespace download_crx_util | 90 } // namespace download_crx_util |
OLD | NEW |