OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 return false; | 115 return false; |
116 } | 116 } |
117 | 117 |
118 CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, | 118 CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, |
119 ExtensionInstallUI* client) | 119 ExtensionInstallUI* client) |
120 : install_directory_(frontend_weak->install_directory()), | 120 : install_directory_(frontend_weak->install_directory()), |
121 install_source_(Extension::INTERNAL), | 121 install_source_(Extension::INTERNAL), |
122 extensions_enabled_(frontend_weak->extensions_enabled()), | 122 extensions_enabled_(frontend_weak->extensions_enabled()), |
123 delete_source_(false), | 123 delete_source_(false), |
124 is_gallery_install_(false), | |
125 create_app_shortcut_(false), | 124 create_app_shortcut_(false), |
126 page_index_(-1), | 125 page_index_(-1), |
127 frontend_weak_(frontend_weak), | 126 frontend_weak_(frontend_weak), |
128 profile_(frontend_weak->profile()), | 127 profile_(frontend_weak->profile()), |
129 client_(client), | 128 client_(client), |
130 apps_require_extension_mime_type_(false), | 129 apps_require_extension_mime_type_(false), |
131 allow_silent_install_(false), | 130 allow_silent_install_(false), |
132 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), | 131 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), |
133 creation_flags_(Extension::NO_FLAGS) { | 132 creation_flags_(Extension::NO_FLAGS) { |
134 } | 133 } |
(...skipping 23 matching lines...) Expand all Loading... |
158 client_ = NULL; | 157 client_ = NULL; |
159 } | 158 } |
160 | 159 |
161 void CrxInstaller::InstallCrx(const FilePath& source_file) { | 160 void CrxInstaller::InstallCrx(const FilePath& source_file) { |
162 source_file_ = source_file; | 161 source_file_ = source_file; |
163 | 162 |
164 scoped_refptr<SandboxedExtensionUnpacker> unpacker( | 163 scoped_refptr<SandboxedExtensionUnpacker> unpacker( |
165 new SandboxedExtensionUnpacker( | 164 new SandboxedExtensionUnpacker( |
166 source_file, | 165 source_file, |
167 g_browser_process->resource_dispatcher_host(), | 166 g_browser_process->resource_dispatcher_host(), |
| 167 install_source_, |
168 creation_flags_, | 168 creation_flags_, |
169 this)); | 169 this)); |
170 | 170 |
171 if (!BrowserThread::PostTask( | 171 if (!BrowserThread::PostTask( |
172 BrowserThread::FILE, FROM_HERE, | 172 BrowserThread::FILE, FROM_HERE, |
173 base::Bind( | 173 base::Bind( |
174 &SandboxedExtensionUnpacker::Start, unpacker.get()))) | 174 &SandboxedExtensionUnpacker::Start, unpacker.get()))) |
175 NOTREACHED(); | 175 NOTREACHED(); |
176 } | 176 } |
177 | 177 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 original_mime_type_ != Extension::kMimeType) { | 267 original_mime_type_ != Extension::kMimeType) { |
268 *error = base::StringPrintf( | 268 *error = base::StringPrintf( |
269 "Apps must be served with content type %s.", | 269 "Apps must be served with content type %s.", |
270 Extension::kMimeType); | 270 Extension::kMimeType); |
271 return false; | 271 return false; |
272 } | 272 } |
273 | 273 |
274 // If the client_ is NULL, then the app is either being installed via | 274 // If the client_ is NULL, then the app is either being installed via |
275 // an internal mechanism like sync, external_extensions, or default apps. | 275 // an internal mechanism like sync, external_extensions, or default apps. |
276 // In that case, we don't want to enforce things like the install origin. | 276 // In that case, we don't want to enforce things like the install origin. |
277 if (!is_gallery_install_ && client_) { | 277 if (!is_gallery_install() && client_) { |
278 // For apps with a gallery update URL, require that they be installed | 278 // For apps with a gallery update URL, require that they be installed |
279 // from the gallery. | 279 // from the gallery. |
280 // TODO(erikkay) Apply this rule for paid extensions and themes as well. | 280 // TODO(erikkay) Apply this rule for paid extensions and themes as well. |
281 if (extension->UpdatesFromGallery()) { | 281 if (extension->UpdatesFromGallery()) { |
282 *error = l10n_util::GetStringFUTF8( | 282 *error = l10n_util::GetStringFUTF8( |
283 IDS_EXTENSION_DISALLOW_NON_DOWNLOADED_GALLERY_INSTALLS, | 283 IDS_EXTENSION_DISALLOW_NON_DOWNLOADED_GALLERY_INSTALLS, |
284 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); | 284 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); |
285 return false; | 285 return false; |
286 } | 286 } |
287 | 287 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 current_version_ = | 399 current_version_ = |
400 frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); | 400 frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); |
401 | 401 |
402 // TODO(asargent) - remove this when we fully deprecate the old install api. | 402 // TODO(asargent) - remove this when we fully deprecate the old install api. |
403 ClearWhitelistedInstallId(extension_->id()); | 403 ClearWhitelistedInstallId(extension_->id()); |
404 | 404 |
405 bool whitelisted = false; | 405 bool whitelisted = false; |
406 scoped_ptr<CrxInstaller::WhitelistEntry> entry( | 406 scoped_ptr<CrxInstaller::WhitelistEntry> entry( |
407 RemoveWhitelistEntry(extension_->id())); | 407 RemoveWhitelistEntry(extension_->id())); |
408 if (is_gallery_install_ && entry.get() && original_manifest_.get()) { | 408 if (is_gallery_install() && entry.get() && original_manifest_.get()) { |
409 if (!(original_manifest_->Equals(entry->parsed_manifest.get()))) { | 409 if (!(original_manifest_->Equals(entry->parsed_manifest.get()))) { |
410 ReportFailureFromUIThread( | 410 ReportFailureFromUIThread( |
411 l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID)); | 411 l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID)); |
412 return; | 412 return; |
413 } | 413 } |
414 whitelisted = true; | 414 whitelisted = true; |
415 if (entry->use_app_installed_bubble) | 415 if (entry->use_app_installed_bubble) |
416 client_->set_use_app_installed_bubble(true); | 416 client_->set_use_app_installed_bubble(true); |
417 } | 417 } |
418 | 418 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 IDS_EXTENSION_MOVE_DIRECTORY_TO_PROFILE_FAILED)); | 490 IDS_EXTENSION_MOVE_DIRECTORY_TO_PROFILE_FAILED)); |
491 return; | 491 return; |
492 } | 492 } |
493 | 493 |
494 // This is lame, but we must reload the extension because absolute paths | 494 // This is lame, but we must reload the extension because absolute paths |
495 // inside the content scripts are established inside InitFromValue() and we | 495 // inside the content scripts are established inside InitFromValue() and we |
496 // just moved the extension. | 496 // just moved the extension. |
497 // TODO(aa): All paths to resources inside extensions should be created | 497 // TODO(aa): All paths to resources inside extensions should be created |
498 // lazily and based on the Extension's root path at that moment. | 498 // lazily and based on the Extension's root path at that moment. |
499 std::string error; | 499 std::string error; |
500 int flags = extension_->creation_flags() | Extension::REQUIRE_KEY; | |
501 if (is_gallery_install()) | |
502 flags |= Extension::FROM_WEBSTORE; | |
503 extension_ = extension_file_util::LoadExtension( | 500 extension_ = extension_file_util::LoadExtension( |
504 version_dir, | 501 version_dir, |
505 install_source_, | 502 install_source_, |
506 flags, | 503 extension_->creation_flags() | Extension::REQUIRE_KEY, |
507 &error); | 504 &error); |
508 CHECK(error.empty()) << error; | 505 CHECK(error.empty()) << error; |
509 | 506 |
510 ReportSuccessFromFileThread(); | 507 ReportSuccessFromFileThread(); |
511 } | 508 } |
512 | 509 |
513 void CrxInstaller::ReportFailureFromFileThread(const std::string& error) { | 510 void CrxInstaller::ReportFailureFromFileThread(const std::string& error) { |
514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
515 if (!BrowserThread::PostTask( | 512 if (!BrowserThread::PostTask( |
516 BrowserThread::UI, FROM_HERE, | 513 BrowserThread::UI, FROM_HERE, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 // Some users (such as the download shelf) need to know when a | 593 // Some users (such as the download shelf) need to know when a |
597 // CRXInstaller is done. Listening for the EXTENSION_* events | 594 // CRXInstaller is done. Listening for the EXTENSION_* events |
598 // is problematic because they don't know anything about the | 595 // is problematic because they don't know anything about the |
599 // extension before it is unpacked, so they can not filter based | 596 // extension before it is unpacked, so they can not filter based |
600 // on the extension. | 597 // on the extension. |
601 content::NotificationService::current()->Notify( | 598 content::NotificationService::current()->Notify( |
602 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 599 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
603 content::Source<CrxInstaller>(this), | 600 content::Source<CrxInstaller>(this), |
604 content::NotificationService::NoDetails()); | 601 content::NotificationService::NoDetails()); |
605 } | 602 } |
OLD | NEW |