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

Side by Side Diff: chrome/browser/extensions/crx_installer.cc

Issue 2830017: Disallow apps with the wrong content type header. (Closed)
Patch Set: Rebase for checkin. Created 10 years, 5 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
« no previous file with comments | « chrome/browser/extensions/crx_installer.h ('k') | chrome/browser/history/download_types.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 28 matching lines...) Expand all
39 CrxInstaller::CrxInstaller(const FilePath& install_directory, 39 CrxInstaller::CrxInstaller(const FilePath& install_directory,
40 ExtensionsService* frontend, 40 ExtensionsService* frontend,
41 ExtensionInstallUI* client) 41 ExtensionInstallUI* client)
42 : install_directory_(install_directory), 42 : install_directory_(install_directory),
43 install_source_(Extension::INTERNAL), 43 install_source_(Extension::INTERNAL),
44 delete_source_(false), 44 delete_source_(false),
45 allow_privilege_increase_(false), 45 allow_privilege_increase_(false),
46 limit_web_extent_to_download_host_(false), 46 limit_web_extent_to_download_host_(false),
47 create_app_shortcut_(false), 47 create_app_shortcut_(false),
48 frontend_(frontend), 48 frontend_(frontend),
49 client_(client) { 49 client_(client),
50 apps_require_extension_mime_type_(false) {
50 extensions_enabled_ = frontend_->extensions_enabled(); 51 extensions_enabled_ = frontend_->extensions_enabled();
51 } 52 }
52 53
53 CrxInstaller::~CrxInstaller() { 54 CrxInstaller::~CrxInstaller() {
54 // Delete the temp directory and crx file as necessary. Note that the 55 // Delete the temp directory and crx file as necessary. Note that the
55 // destructor might be called on any thread, so we post a task to the file 56 // destructor might be called on any thread, so we post a task to the file
56 // thread to make sure the delete happens there. 57 // thread to make sure the delete happens there.
57 if (!temp_dir_.value().empty()) { 58 if (!temp_dir_.value().empty()) {
58 ChromeThread::PostTask( 59 ChromeThread::PostTask(
59 ChromeThread::FILE, FROM_HERE, 60 ChromeThread::FILE, FROM_HERE,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 122
122 void CrxInstaller::OnUnpackSuccess(const FilePath& temp_dir, 123 void CrxInstaller::OnUnpackSuccess(const FilePath& temp_dir,
123 const FilePath& extension_dir, 124 const FilePath& extension_dir,
124 Extension* extension) { 125 Extension* extension) {
125 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); 126 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
126 127
127 // Note: We take ownership of |extension| and |temp_dir|. 128 // Note: We take ownership of |extension| and |temp_dir|.
128 extension_.reset(extension); 129 extension_.reset(extension);
129 temp_dir_ = temp_dir; 130 temp_dir_ = temp_dir;
130 131
132 // If the extension was downloaded, apps_require_extension_mime_type_
133 // will be set. In this case, check that if the extension is an app,
134 // it was served with the right mime type. Make an exception for file
135 // URLs, which come from the users computer and have no headers.
136 if (extension->is_app() &&
137 !original_url_.SchemeIsFile() &&
138 apps_require_extension_mime_type_ &&
139 original_mime_type_ != Extension::kMimeType) {
140 ReportFailureFromFileThread(StringPrintf(
141 "Applications must be served with content type %s.",
142 Extension::kMimeType));
143 return;
144 }
145
131 // The unpack dir we don't have to delete explicity since it is a child of 146 // The unpack dir we don't have to delete explicity since it is a child of
132 // the temp dir. 147 // the temp dir.
133 unpacked_extension_root_ = extension_dir; 148 unpacked_extension_root_ = extension_dir;
134 149
135 // Only allow extensions with a gallery update url to be installed after 150 // Only allow extensions with a gallery update url to be installed after
136 // having been directly downloaded from the gallery. 151 // having been directly downloaded from the gallery.
137 if (extension->update_url() == GURL(extension_urls::kGalleryUpdateURL) && 152 if (extension->update_url() == GURL(extension_urls::kGalleryUpdateURL) &&
138 !ExtensionsService::IsGalleryDownloadURL(original_url_)) { 153 !ExtensionsService::IsGalleryDownloadURL(original_url_)) {
139 ReportFailureFromFileThread(l10n_util::GetStringFUTF8( 154 ReportFailureFromFileThread(l10n_util::GetStringFUTF8(
140 IDS_EXTENSION_DISALLOW_NON_DOWNLOADED_GALLERY_INSTALLS, 155 IDS_EXTENSION_DISALLOW_NON_DOWNLOADED_GALLERY_INSTALLS,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 client_->OnInstallSuccess(extension_.get()); 357 client_->OnInstallSuccess(extension_.get());
343 358
344 // Tell the frontend about the installation and hand off ownership of 359 // Tell the frontend about the installation and hand off ownership of
345 // extension_ to it. 360 // extension_ to it.
346 frontend_->OnExtensionInstalled(extension_.release(), 361 frontend_->OnExtensionInstalled(extension_.release(),
347 allow_privilege_increase_); 362 allow_privilege_increase_);
348 363
349 // We're done. We don't post any more tasks to ourselves so we are deleted 364 // We're done. We don't post any more tasks to ourselves so we are deleted
350 // soon. 365 // soon.
351 } 366 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.h ('k') | chrome/browser/history/download_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698