OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extensions/unpacked_installer.h" | 5 #include "chrome/browser/extensions/unpacked_installer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "extensions/browser/extension_prefs.h" | 22 #include "extensions/browser/extension_prefs.h" |
23 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
24 #include "extensions/browser/install_flag.h" | 24 #include "extensions/browser/install_flag.h" |
25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "extensions/common/extension_l10n_util.h" | 26 #include "extensions/common/extension_l10n_util.h" |
27 #include "extensions/common/file_util.h" | 27 #include "extensions/common/file_util.h" |
28 #include "extensions/common/id_util.h" | 28 #include "extensions/common/id_util.h" |
29 #include "extensions/common/manifest.h" | 29 #include "extensions/common/manifest.h" |
30 #include "sync/api/string_ordinal.h" | 30 #include "sync/api/string_ordinal.h" |
31 #include "third_party/zlib/google/zip.h" | |
31 | 32 |
32 using content::BrowserThread; | 33 using content::BrowserThread; |
33 using extensions::Extension; | 34 using extensions::Extension; |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 const char kUnpackedExtensionsBlacklistedError[] = | 38 const char kUnpackedExtensionsBlacklistedError[] = |
38 "Loading of unpacked extensions is disabled by the administrator."; | 39 "Loading of unpacked extensions is disabled by the administrator."; |
40 const char kUnpackedInstallerTempDirError[] = | |
41 "Could not create temporary directory for zipped extension."; | |
42 const char kUnpackedInstallerUnzipError[] = | |
43 "Could not unzip extension for install."; | |
39 | 44 |
40 // Manages an ExtensionInstallPrompt for a particular extension. | 45 // Manages an ExtensionInstallPrompt for a particular extension. |
41 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { | 46 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { |
42 public: | 47 public: |
43 SimpleExtensionLoadPrompt(const Extension* extension, | 48 SimpleExtensionLoadPrompt(const Extension* extension, |
44 Profile* profile, | 49 Profile* profile, |
45 const base::Closure& callback); | 50 const base::Closure& callback); |
46 virtual ~SimpleExtensionLoadPrompt(); | 51 virtual ~SimpleExtensionLoadPrompt(); |
47 | 52 |
48 void ShowPrompt(); | 53 void ShowPrompt(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 ReportExtensionLoadError(error); | 166 ReportExtensionLoadError(error); |
162 return false; | 167 return false; |
163 } | 168 } |
164 | 169 |
165 ShowInstallPrompt(); | 170 ShowInstallPrompt(); |
166 | 171 |
167 *extension_id = extension()->id(); | 172 *extension_id = extension()->id(); |
168 return true; | 173 return true; |
169 } | 174 } |
170 | 175 |
176 void UnpackedInstaller::LoadFromZipFile(const base::FilePath& zip_path) { | |
177 BrowserThread::PostTask( | |
178 BrowserThread::FILE, | |
179 FROM_HERE, | |
180 base::Bind(&UnpackedInstaller::UnpackZipFileAndLoad, this, zip_path)); | |
181 } | |
182 | |
183 void UnpackedInstaller::UnpackZipFileAndLoad(const base::FilePath& zip_path) { | |
184 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
185 base::FilePath temp_path; | |
186 if (!base::CreateTemporaryDirInDir( | |
elijahtaylor1
2014/07/18 23:47:43
I didn't know of a great way to notify the user/de
asargent_no_longer_on_chrome
2014/07/22 22:51:01
I wonder if it would be better to unzip into a new
elijahtaylor1
2014/07/23 00:19:07
It's probably better to do in a temp dir, but it c
| |
187 zip_path.DirName(), | |
188 zip_path.RemoveExtension().BaseName().value() + | |
189 FILE_PATH_LITERAL("_"), | |
190 &temp_path)) { | |
191 // Set extension_path_ so a meaningful error is displayed, it would normally | |
192 // be set by UnpackedInstaller::Load | |
193 extension_path_ = zip_path; | |
194 BrowserThread::PostTask( | |
195 BrowserThread::UI, | |
196 FROM_HERE, | |
197 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, | |
198 this, | |
199 kUnpackedInstallerTempDirError)); | |
200 return; | |
201 } | |
202 if (!zip::Unzip(zip_path, temp_path)) { | |
asargent_no_longer_on_chrome
2014/07/22 22:51:01
For regular extension installation, we do the unzi
elijahtaylor1
2014/07/23 00:19:07
Yeah, I first tried to use the sandboxed unpacker,
meacer
2014/07/23 00:32:15
I agree with Antony, it's best to do this in the s
| |
203 // Set extension_path_ so a meaningful error is displayed, it would normally | |
204 // be set by UnpackedInstaller::Load | |
205 extension_path_ = zip_path; | |
206 BrowserThread::PostTask( | |
207 BrowserThread::UI, | |
208 FROM_HERE, | |
209 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, | |
210 this, | |
211 kUnpackedInstallerUnzipError)); | |
212 return; | |
213 } | |
214 Load(temp_path); | |
215 } | |
216 | |
171 void UnpackedInstaller::ShowInstallPrompt() { | 217 void UnpackedInstaller::ShowInstallPrompt() { |
172 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 218 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
173 if (!service_weak_.get()) | 219 if (!service_weak_.get()) |
174 return; | 220 return; |
175 | 221 |
176 const ExtensionSet& disabled_extensions = | 222 const ExtensionSet& disabled_extensions = |
177 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions(); | 223 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions(); |
178 if (service_weak_->show_extensions_prompts() && prompt_for_plugins_ && | 224 if (service_weak_->show_extensions_prompts() && prompt_for_plugins_ && |
179 PluginInfo::HasPlugins(extension()) && | 225 PluginInfo::HasPlugins(extension()) && |
180 !disabled_extensions.Contains(extension()->id())) { | 226 !disabled_extensions.Contains(extension()->id())) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 359 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
314 | 360 |
315 PermissionsUpdater perms_updater(service_weak_->profile()); | 361 PermissionsUpdater perms_updater(service_weak_->profile()); |
316 perms_updater.GrantActivePermissions(extension()); | 362 perms_updater.GrantActivePermissions(extension()); |
317 | 363 |
318 service_weak_->OnExtensionInstalled( | 364 service_weak_->OnExtensionInstalled( |
319 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); | 365 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); |
320 } | 366 } |
321 | 367 |
322 } // namespace extensions | 368 } // namespace extensions |
OLD | NEW |