Chromium Code Reviews| 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_crx_util.h" | 7 #include "chrome/browser/download/download_crx_util.h" |
| 8 | 8 |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/crx_installer.h" | 10 #include "chrome/browser/extensions/crx_installer.h" |
| 11 #include "chrome/browser/extensions/extension_install_prompt.h" | 11 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 12 #include "chrome/browser/extensions/extension_management.h" | 12 #include "chrome/browser/extensions/extension_management.h" |
| 13 #include "chrome/browser/extensions/webstore_installer.h" | 13 #include "chrome/browser/extensions/webstore_installer.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "content/public/browser/download_item.h" | 17 #include "content/public/browser/download_item.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
| 20 #include "extensions/common/user_script.h" | 20 #include "extensions/common/user_script.h" |
| 21 | 21 |
| 22 using content::BrowserThread; | 22 using content::BrowserThread; |
| 23 using content::DownloadItem; | 23 using content::DownloadItem; |
| 24 using extensions::WebstoreInstaller; | 24 using extensions::WebstoreInstaller; |
| 25 | 25 |
| 26 namespace download_crx_util { | 26 namespace download_crx_util { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 bool g_allow_offstore_install_for_testing = false; | |
| 31 | |
| 30 // Hold a mock ExtensionInstallPrompt object that will be used when the | 32 // Hold a mock ExtensionInstallPrompt object that will be used when the |
| 31 // download system opens a CRX. | 33 // download system opens a CRX. |
| 32 ExtensionInstallPrompt* mock_install_prompt_for_testing = NULL; | 34 ExtensionInstallPrompt* mock_install_prompt_for_testing = NULL; |
| 33 | 35 |
| 34 // Called to get an extension install UI object. In tests, will return | 36 // Called to get an extension install UI object. In tests, will return |
| 35 // a mock if the test calls download_util::SetMockInstallPromptForTesting() | 37 // a mock if the test calls download_util::SetMockInstallPromptForTesting() |
| 36 // to set one. | 38 // to set one. |
| 37 std::unique_ptr<ExtensionInstallPrompt> CreateExtensionInstallPrompt( | 39 std::unique_ptr<ExtensionInstallPrompt> CreateExtensionInstallPrompt( |
| 38 Profile* profile, | 40 Profile* profile, |
| 39 const DownloadItem& download_item) { | 41 const DownloadItem& download_item) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 return true; | 126 return true; |
| 125 } else { | 127 } else { |
| 126 return false; | 128 return false; |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 | 131 |
| 130 bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& item) { | 132 bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& item) { |
| 131 // TODO(aa): RefererURL is cleared in some cases, for example when going | 133 // TODO(aa): RefererURL is cleared in some cases, for example when going |
| 132 // between secure and non-secure URLs. It would be better if DownloadItem | 134 // between secure and non-secure URLs. It would be better if DownloadItem |
| 133 // tracked the initiating page explicitly. | 135 // tracked the initiating page explicitly. |
| 134 return extensions::ExtensionManagementFactory::GetForBrowserContext(profile) | 136 return g_allow_offstore_install_for_testing || |
|
Devlin
2017/02/01 17:17:42
pastarmovj@: I'd rather just have tests set the pr
Devlin
2017/02/06 17:22:33
Since this is still better than the current comple
pastarmovj
2017/02/07 06:49:06
Hey sorry I somehow missed this request. You can c
| |
| 135 ->IsOffstoreInstallAllowed(item.GetURL(), item.GetReferrerUrl()); | 137 extensions::ExtensionManagementFactory::GetForBrowserContext(profile) |
| 138 ->IsOffstoreInstallAllowed(item.GetURL(), item.GetReferrerUrl()); | |
| 139 } | |
| 140 | |
| 141 std::unique_ptr<base::AutoReset<bool>> OverrideOffstoreInstallAllowedForTesting( | |
| 142 bool allowed) { | |
| 143 return base::MakeUnique<base::AutoReset<bool>>( | |
| 144 &g_allow_offstore_install_for_testing, allowed); | |
| 136 } | 145 } |
| 137 | 146 |
| 138 } // namespace download_crx_util | 147 } // namespace download_crx_util |
| OLD | NEW |