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

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

Issue 10542048: Add a group policy controlling which sites can install extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | chrome/browser/extensions/crx_installer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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_prompt.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/extension_system.h"
11 #include "chrome/browser/extensions/webstore_installer.h" 12 #include "chrome/browser/extensions/webstore_installer.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/extensions/extension_switch_utils.h" 15 #include "chrome/common/extensions/extension_switch_utils.h"
15 #include "content/public/browser/download_item.h" 16 #include "content/public/browser/download_item.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 18
18 using content::BrowserThread; 19 using content::BrowserThread;
19 using content::DownloadItem; 20 using content::DownloadItem;
20 21
(...skipping 15 matching lines...) Expand all
36 if (mock_install_prompt_for_testing) { 37 if (mock_install_prompt_for_testing) {
37 result = mock_install_prompt_for_testing; 38 result = mock_install_prompt_for_testing;
38 mock_install_prompt_for_testing = NULL; 39 mock_install_prompt_for_testing = NULL;
39 } else { 40 } else {
40 result = new ExtensionInstallPrompt(profile); 41 result = new ExtensionInstallPrompt(profile);
41 } 42 }
42 43
43 return result; 44 return result;
44 } 45 }
45 46
47 bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& item) {
48 ExtensionPrefs* prefs =
49 ExtensionSystem::Get(profile)->extension_service()->extension_prefs();
50 CHECK(prefs);
51
52 URLPatternSet url_patterns = prefs->GetAllowedInstallSites();
53
54 // TODO(aa): RefererURL is cleared in some cases, for example when going
55 // between secure and non-secure URLs. It would be better if DownloadItem
56 // tracked the initiating page explicitly.
57 return url_patterns.MatchesURL(item.GetURL()) &&
58 url_patterns.MatchesURL(item.GetReferrerUrl());
59 }
60
46 } // namespace 61 } // namespace
47 62
48 // Tests can call this method to inject a mock ExtensionInstallPrompt 63 // Tests can call this method to inject a mock ExtensionInstallPrompt
49 // to be used to confirm permissions on a downloaded CRX. 64 // to be used to confirm permissions on a downloaded CRX.
50 void SetMockInstallPromptForTesting(ExtensionInstallPrompt* mock_prompt) { 65 void SetMockInstallPromptForTesting(ExtensionInstallPrompt* mock_prompt) {
51 mock_install_prompt_for_testing = mock_prompt; 66 mock_install_prompt_for_testing = mock_prompt;
52 } 67 }
53 68
54 scoped_refptr<CrxInstaller> OpenChromeExtension( 69 scoped_refptr<CrxInstaller> OpenChromeExtension(
55 Profile* profile, 70 Profile* profile,
56 const DownloadItem& download_item) { 71 const DownloadItem& download_item) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
58 73
59 ExtensionService* service = profile->GetExtensionService(); 74 ExtensionService* service = profile->GetExtensionService();
60 CHECK(service); 75 CHECK(service);
61 76
62 scoped_refptr<CrxInstaller> installer( 77 scoped_refptr<CrxInstaller> installer(
63 CrxInstaller::Create( 78 CrxInstaller::Create(
64 service, 79 service,
65 CreateExtensionInstallPrompt(profile), 80 CreateExtensionInstallPrompt(profile),
66 WebstoreInstaller::GetAssociatedApproval(download_item))); 81 WebstoreInstaller::GetAssociatedApproval(download_item)));
67 82
68 installer->set_delete_source(true); 83 installer->set_delete_source(true);
69 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); 84 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD);
70 85
86 if (OffStoreInstallAllowedByPrefs(profile, download_item)) {
87 installer->set_off_store_install_allow_reason(
88 CrxInstaller::OffStoreInstallAllowedBecausePref);
89 }
90
71 if (UserScript::IsURLUserScript(download_item.GetURL(), 91 if (UserScript::IsURLUserScript(download_item.GetURL(),
72 download_item.GetMimeType())) { 92 download_item.GetMimeType())) {
73 installer->InstallUserScript(download_item.GetFullPath(), 93 installer->InstallUserScript(download_item.GetFullPath(),
74 download_item.GetURL()); 94 download_item.GetURL());
75 } else { 95 } else {
76 bool is_gallery_download = 96 bool is_gallery_download =
77 WebstoreInstaller::GetAssociatedApproval(download_item) != NULL; 97 WebstoreInstaller::GetAssociatedApproval(download_item) != NULL;
78 installer->set_original_mime_type(download_item.GetOriginalMimeType()); 98 installer->set_original_mime_type(download_item.GetOriginalMimeType());
79 installer->set_apps_require_extension_mime_type(true); 99 installer->set_apps_require_extension_mime_type(true);
80 installer->set_download_url(download_item.GetURL()); 100 installer->set_download_url(download_item.GetURL());
(...skipping 15 matching lines...) Expand all
96 if (download_item.GetMimeType() == extensions::Extension::kMimeType || 116 if (download_item.GetMimeType() == extensions::Extension::kMimeType ||
97 UserScript::IsURLUserScript(download_item.GetURL(), 117 UserScript::IsURLUserScript(download_item.GetURL(),
98 download_item.GetMimeType())) { 118 download_item.GetMimeType())) {
99 return true; 119 return true;
100 } else { 120 } else {
101 return false; 121 return false;
102 } 122 }
103 } 123 }
104 124
105 } // namespace download_crx_util 125 } // namespace download_crx_util
OLDNEW
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | chrome/browser/extensions/crx_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698