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 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/crx_installer.h" | 12 #include "chrome/browser/extensions/crx_installer.h" |
11 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/unpacked_installer.h" | 15 #include "chrome/browser/extensions/unpacked_installer.h" |
14 #include "chrome/browser/extensions/zipfile_installer.h" | 16 #include "chrome/browser/extensions/zipfile_installer.h" |
15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 Profile* profile = Profile::FromBrowserContext( | 101 Profile* profile = Profile::FromBrowserContext( |
100 web_ui()->GetWebContents()->GetBrowserContext()); | 102 web_ui()->GetWebContents()->GetBrowserContext()); |
101 | 103 |
102 if (file_display_name_.MatchesExtension(FILE_PATH_LITERAL(".zip"))) { | 104 if (file_display_name_.MatchesExtension(FILE_PATH_LITERAL(".zip"))) { |
103 ZipFileInstaller::Create(ExtensionSystem::Get(profile)->extension_service()) | 105 ZipFileInstaller::Create(ExtensionSystem::Get(profile)->extension_service()) |
104 ->LoadFromZipFile(file_to_install_); | 106 ->LoadFromZipFile(file_to_install_); |
105 } else { | 107 } else { |
106 scoped_ptr<ExtensionInstallPrompt> prompt( | 108 scoped_ptr<ExtensionInstallPrompt> prompt( |
107 new ExtensionInstallPrompt(web_ui()->GetWebContents())); | 109 new ExtensionInstallPrompt(web_ui()->GetWebContents())); |
108 scoped_refptr<CrxInstaller> crx_installer(CrxInstaller::Create( | 110 scoped_refptr<CrxInstaller> crx_installer(CrxInstaller::Create( |
109 ExtensionSystem::Get(profile)->extension_service(), prompt.Pass())); | 111 ExtensionSystem::Get(profile)->extension_service(), std::move(prompt))); |
110 crx_installer->set_error_on_unsupported_requirements(true); | 112 crx_installer->set_error_on_unsupported_requirements(true); |
111 crx_installer->set_off_store_install_allow_reason( | 113 crx_installer->set_off_store_install_allow_reason( |
112 CrxInstaller::OffStoreInstallAllowedFromSettingsPage); | 114 CrxInstaller::OffStoreInstallAllowedFromSettingsPage); |
113 crx_installer->set_install_immediately(true); | 115 crx_installer->set_install_immediately(true); |
114 | 116 |
115 if (file_display_name_.MatchesExtension(FILE_PATH_LITERAL(".user.js"))) { | 117 if (file_display_name_.MatchesExtension(FILE_PATH_LITERAL(".user.js"))) { |
116 crx_installer->InstallUserScript( | 118 crx_installer->InstallUserScript( |
117 file_to_install_, net::FilePathToFileURL(file_to_install_)); | 119 file_to_install_, net::FilePathToFileURL(file_to_install_)); |
118 } else if (file_display_name_.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { | 120 } else if (file_display_name_.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { |
119 crx_installer->InstallCrx(file_to_install_); | 121 crx_installer->InstallCrx(file_to_install_); |
120 } else { | 122 } else { |
121 CHECK(false); | 123 CHECK(false); |
122 } | 124 } |
123 } | 125 } |
124 | 126 |
125 file_to_install_.clear(); | 127 file_to_install_.clear(); |
126 file_display_name_.clear(); | 128 file_display_name_.clear(); |
127 } | 129 } |
128 | 130 |
129 void InstallExtensionHandler::HandleInstallDirectoryMessage( | 131 void InstallExtensionHandler::HandleInstallDirectoryMessage( |
130 const base::ListValue* args) { | 132 const base::ListValue* args) { |
131 Profile* profile = Profile::FromBrowserContext( | 133 Profile* profile = Profile::FromBrowserContext( |
132 web_ui()->GetWebContents()->GetBrowserContext()); | 134 web_ui()->GetWebContents()->GetBrowserContext()); |
133 UnpackedInstaller::Create( | 135 UnpackedInstaller::Create( |
134 ExtensionSystem::Get(profile)-> | 136 ExtensionSystem::Get(profile)-> |
135 extension_service())->Load(file_to_install_); | 137 extension_service())->Load(file_to_install_); |
136 } | 138 } |
137 | 139 |
138 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |