Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: chrome/browser/download/download_crx_util.cc

Issue 226023003: Create CrxInstaller directly in WebstoreInstaller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Android compilation fix (again). Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 } // namespace 63 } // namespace
64 64
65 // Tests can call this method to inject a mock ExtensionInstallPrompt 65 // Tests can call this method to inject a mock ExtensionInstallPrompt
66 // to be used to confirm permissions on a downloaded CRX. 66 // to be used to confirm permissions on a downloaded CRX.
67 void SetMockInstallPromptForTesting( 67 void SetMockInstallPromptForTesting(
68 scoped_ptr<ExtensionInstallPrompt> mock_prompt) { 68 scoped_ptr<ExtensionInstallPrompt> mock_prompt) {
69 mock_install_prompt_for_testing = mock_prompt.release(); 69 mock_install_prompt_for_testing = mock_prompt.release();
70 } 70 }
71 71
72 scoped_refptr<extensions::CrxInstaller> OpenChromeExtension( 72 scoped_refptr<extensions::CrxInstaller> CreateCrxInstaller(
73 Profile* profile, 73 Profile* profile,
74 const DownloadItem& download_item) { 74 const content::DownloadItem& download_item) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76
77 ExtensionService* service = extensions::ExtensionSystem::Get(profile)-> 75 ExtensionService* service = extensions::ExtensionSystem::Get(profile)->
78 extension_service(); 76 extension_service();
79 CHECK(service); 77 CHECK(service);
80 78
81 scoped_refptr<extensions::CrxInstaller> installer( 79 scoped_refptr<extensions::CrxInstaller> installer(
82 extensions::CrxInstaller::Create( 80 extensions::CrxInstaller::Create(
83 service, 81 service,
84 CreateExtensionInstallPrompt(profile, download_item), 82 CreateExtensionInstallPrompt(profile, download_item),
85 WebstoreInstaller::GetAssociatedApproval(download_item))); 83 WebstoreInstaller::GetAssociatedApproval(download_item)));
86 84
87 installer->set_error_on_unsupported_requirements(true); 85 installer->set_error_on_unsupported_requirements(true);
88 installer->set_delete_source(true); 86 installer->set_delete_source(true);
89 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); 87 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD);
88 installer->set_original_mime_type(download_item.GetOriginalMimeType());
89 installer->set_apps_require_extension_mime_type(true);
90
91 return installer;
92 }
93
94 scoped_refptr<extensions::CrxInstaller> OpenChromeExtension(
95 Profile* profile,
96 const DownloadItem& download_item) {
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
98
99 scoped_refptr<extensions::CrxInstaller> installer(
100 CreateCrxInstaller(profile, download_item));
90 101
91 if (OffStoreInstallAllowedByPrefs(profile, download_item)) { 102 if (OffStoreInstallAllowedByPrefs(profile, download_item)) {
92 installer->set_off_store_install_allow_reason( 103 installer->set_off_store_install_allow_reason(
93 extensions::CrxInstaller::OffStoreInstallAllowedBecausePref); 104 extensions::CrxInstaller::OffStoreInstallAllowedBecausePref);
94 } 105 }
95 106
96 if (extensions::UserScript::IsURLUserScript(download_item.GetURL(), 107 if (extensions::UserScript::IsURLUserScript(download_item.GetURL(),
97 download_item.GetMimeType())) { 108 download_item.GetMimeType())) {
98 installer->InstallUserScript(download_item.GetFullPath(), 109 installer->InstallUserScript(download_item.GetFullPath(),
99 download_item.GetURL()); 110 download_item.GetURL());
100 } else { 111 } else {
101 bool is_gallery_download = 112 DCHECK(!WebstoreInstaller::GetAssociatedApproval(download_item));
102 WebstoreInstaller::GetAssociatedApproval(download_item) != NULL;
103 installer->set_original_mime_type(download_item.GetOriginalMimeType());
104 installer->set_apps_require_extension_mime_type(true);
105 installer->set_download_url(download_item.GetURL());
106 installer->set_is_gallery_install(is_gallery_download);
107 if (is_gallery_download)
108 installer->set_original_download_url(download_item.GetOriginalUrl());
109 installer->set_allow_silent_install(is_gallery_download);
110 installer->InstallCrx(download_item.GetFullPath()); 113 installer->InstallCrx(download_item.GetFullPath());
111 } 114 }
112 115
113 return installer; 116 return installer;
114 } 117 }
115 118
116 bool IsExtensionDownload(const DownloadItem& download_item) { 119 bool IsExtensionDownload(const DownloadItem& download_item) {
117 if (download_item.GetTargetDisposition() == 120 if (download_item.GetTargetDisposition() ==
118 DownloadItem::TARGET_DISPOSITION_PROMPT) 121 DownloadItem::TARGET_DISPOSITION_PROMPT)
119 return false; 122 return false;
(...skipping 19 matching lines...) Expand all
139 // The referrer URL must also be whitelisted, unless the URL has the file 142 // The referrer URL must also be whitelisted, unless the URL has the file
140 // scheme (there's no referrer for those URLs). 143 // scheme (there's no referrer for those URLs).
141 // TODO(aa): RefererURL is cleared in some cases, for example when going 144 // TODO(aa): RefererURL is cleared in some cases, for example when going
142 // between secure and non-secure URLs. It would be better if DownloadItem 145 // between secure and non-secure URLs. It would be better if DownloadItem
143 // tracked the initiating page explicitly. 146 // tracked the initiating page explicitly.
144 return url_patterns.MatchesURL(item.GetReferrerUrl()) || 147 return url_patterns.MatchesURL(item.GetReferrerUrl()) ||
145 item.GetURL().SchemeIsFile(); 148 item.GetURL().SchemeIsFile();
146 } 149 }
147 150
148 } // namespace download_crx_util 151 } // namespace download_crx_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_crx_util.h ('k') | chrome/browser/download/download_crx_util_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698