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

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

Issue 10388252: Refactoring ExtenionInstallUI to abstract the Browser references. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced + mac fix 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
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_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 67
68 installer->set_delete_source(true); 68 installer->set_delete_source(true);
69 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); 69 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD);
70 70
71 if (UserScript::IsURLUserScript(download_item.GetURL(), 71 if (UserScript::IsURLUserScript(download_item.GetURL(),
72 download_item.GetMimeType())) { 72 download_item.GetMimeType())) {
73 installer->InstallUserScript(download_item.GetFullPath(), 73 installer->InstallUserScript(download_item.GetFullPath(),
74 download_item.GetURL()); 74 download_item.GetURL());
75 } else { 75 } else {
(...skipping 20 matching lines...) Expand all
96 if (download_item.GetMimeType() == extensions::Extension::kMimeType || 96 if (download_item.GetMimeType() == extensions::Extension::kMimeType ||
97 UserScript::IsURLUserScript(download_item.GetURL(), 97 UserScript::IsURLUserScript(download_item.GetURL(),
98 download_item.GetMimeType())) { 98 download_item.GetMimeType())) {
99 return true; 99 return true;
100 } else { 100 } else {
101 return false; 101 return false;
102 } 102 }
103 } 103 }
104 104
105 } // namespace download_crx_util 105 } // namespace download_crx_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_crx_util.h ('k') | chrome/browser/extensions/api/permissions/permissions_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698