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

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

Issue 10683003: Moved CrxInstaller and CrxInstallerError into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest-er master Created 8 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
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 #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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "content/public/browser/user_metrics.h" 45 #include "content/public/browser/user_metrics.h"
46 #include "grit/chromium_strings.h" 46 #include "grit/chromium_strings.h"
47 #include "grit/generated_resources.h" 47 #include "grit/generated_resources.h"
48 #include "grit/theme_resources.h" 48 #include "grit/theme_resources.h"
49 #include "third_party/skia/include/core/SkBitmap.h" 49 #include "third_party/skia/include/core/SkBitmap.h"
50 #include "ui/base/l10n/l10n_util.h" 50 #include "ui/base/l10n/l10n_util.h"
51 #include "ui/base/resource/resource_bundle.h" 51 #include "ui/base/resource/resource_bundle.h"
52 52
53 using content::BrowserThread; 53 using content::BrowserThread;
54 using content::UserMetricsAction; 54 using content::UserMetricsAction;
55 using extensions::Extension; 55
56 using extensions::PermissionsUpdater; 56 namespace extensions {
57 57
58 namespace { 58 namespace {
59 59
60 // Used in histograms; do not change order. 60 // Used in histograms; do not change order.
61 enum OffStoreInstallDecision { 61 enum OffStoreInstallDecision {
62 OnStoreInstall, 62 OnStoreInstall,
63 OffStoreInstallAllowed, 63 OffStoreInstallAllowed,
64 OffStoreInstallDisallowed, 64 OffStoreInstallDisallowed,
65 NumOffStoreInstallDecision 65 NumOffStoreInstallDecision
66 }; 66 };
67 67
68 } // namespace 68 } // namespace
69 69
70 // static 70 // static
71 scoped_refptr<CrxInstaller> CrxInstaller::Create( 71 scoped_refptr<CrxInstaller> CrxInstaller::Create(
72 ExtensionService* frontend, 72 ExtensionService* frontend,
73 ExtensionInstallPrompt* client) { 73 ExtensionInstallPrompt* client) {
74 return new CrxInstaller(frontend->AsWeakPtr(), client, NULL); 74 return new CrxInstaller(frontend->AsWeakPtr(), client, NULL);
75 } 75 }
76 76
77 // static 77 // static
78 scoped_refptr<CrxInstaller> CrxInstaller::Create( 78 scoped_refptr<CrxInstaller> CrxInstaller::Create(
79 ExtensionService* frontend, 79 ExtensionService* frontend,
80 ExtensionInstallPrompt* client, 80 ExtensionInstallPrompt* client,
81 const extensions::WebstoreInstaller::Approval* approval) { 81 const WebstoreInstaller::Approval* approval) {
82 return new CrxInstaller(frontend->AsWeakPtr(), client, approval); 82 return new CrxInstaller(frontend->AsWeakPtr(), client, approval);
83 } 83 }
84 84
85 CrxInstaller::CrxInstaller( 85 CrxInstaller::CrxInstaller(
86 base::WeakPtr<ExtensionService> frontend_weak, 86 base::WeakPtr<ExtensionService> frontend_weak,
87 ExtensionInstallPrompt* client, 87 ExtensionInstallPrompt* client,
88 const extensions::WebstoreInstaller::Approval* approval) 88 const WebstoreInstaller::Approval* approval)
89 : install_directory_(frontend_weak->install_directory()), 89 : install_directory_(frontend_weak->install_directory()),
90 install_source_(Extension::INTERNAL), 90 install_source_(Extension::INTERNAL),
91 approved_(false), 91 approved_(false),
92 extensions_enabled_(frontend_weak->extensions_enabled()), 92 extensions_enabled_(frontend_weak->extensions_enabled()),
93 delete_source_(false), 93 delete_source_(false),
94 create_app_shortcut_(false), 94 create_app_shortcut_(false),
95 frontend_weak_(frontend_weak), 95 frontend_weak_(frontend_weak),
96 profile_(frontend_weak->profile()), 96 profile_(frontend_weak->profile()),
97 client_(client), 97 client_(client),
98 apps_require_extension_mime_type_(false), 98 apps_require_extension_mime_type_(false),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 base::Bind(&extension_file_util::DeleteFile, source_file_, false)); 135 base::Bind(&extension_file_util::DeleteFile, source_file_, false));
136 } 136 }
137 // Make sure the UI is deleted on the ui thread. 137 // Make sure the UI is deleted on the ui thread.
138 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, client_); 138 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, client_);
139 client_ = NULL; 139 client_ = NULL;
140 } 140 }
141 141
142 void CrxInstaller::InstallCrx(const FilePath& source_file) { 142 void CrxInstaller::InstallCrx(const FilePath& source_file) {
143 source_file_ = source_file; 143 source_file_ = source_file;
144 144
145 scoped_refptr<extensions::SandboxedUnpacker> unpacker( 145 scoped_refptr<SandboxedUnpacker> unpacker(
146 new extensions::SandboxedUnpacker( 146 new SandboxedUnpacker(
147 source_file, 147 source_file,
148 content::ResourceDispatcherHost::Get() != NULL, 148 content::ResourceDispatcherHost::Get() != NULL,
149 install_source_, 149 install_source_,
150 creation_flags_, 150 creation_flags_,
151 this)); 151 this));
152 152
153 if (!BrowserThread::PostTask( 153 if (!BrowserThread::PostTask(
154 BrowserThread::FILE, FROM_HERE, 154 BrowserThread::FILE, FROM_HERE,
155 base::Bind( 155 base::Bind(&SandboxedUnpacker::Start, unpacker.get())))
156 &extensions::SandboxedUnpacker::Start, unpacker.get())))
157 NOTREACHED(); 156 NOTREACHED();
158 } 157 }
159 158
160 void CrxInstaller::InstallUserScript(const FilePath& source_file, 159 void CrxInstaller::InstallUserScript(const FilePath& source_file,
161 const GURL& download_url) { 160 const GURL& download_url) {
162 DCHECK(!download_url.is_empty()); 161 DCHECK(!download_url.is_empty());
163 162
164 source_file_ = source_file; 163 source_file_ = source_file;
165 download_url_ = download_url; 164 download_url_ = download_url;
166 165
167 if (!BrowserThread::PostTask( 166 if (!BrowserThread::PostTask(
168 BrowserThread::FILE, FROM_HERE, 167 BrowserThread::FILE, FROM_HERE,
169 base::Bind(&CrxInstaller::ConvertUserScriptOnFileThread, this))) 168 base::Bind(&CrxInstaller::ConvertUserScriptOnFileThread, this)))
170 NOTREACHED(); 169 NOTREACHED();
171 } 170 }
172 171
173 void CrxInstaller::ConvertUserScriptOnFileThread() { 172 void CrxInstaller::ConvertUserScriptOnFileThread() {
174 string16 error; 173 string16 error;
175 scoped_refptr<Extension> extension = extensions::ConvertUserScriptToExtension( 174 scoped_refptr<Extension> extension = ConvertUserScriptToExtension(
176 source_file_, download_url_, &error); 175 source_file_, download_url_, &error);
177 if (!extension) { 176 if (!extension) {
178 ReportFailureFromFileThread(CrxInstallerError(error)); 177 ReportFailureFromFileThread(CrxInstallerError(error));
179 return; 178 return;
180 } 179 }
181 180
182 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension); 181 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension);
183 } 182 }
184 183
185 void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) { 184 void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // SandboxedUnpacker sets extension->location. 240 // SandboxedUnpacker sets extension->location.
242 if (extension->is_theme() || Extension::IsExternalLocation(install_source_)) 241 if (extension->is_theme() || Extension::IsExternalLocation(install_source_))
243 return CrxInstallerError(); 242 return CrxInstallerError();
244 243
245 if (!extensions_enabled_) { 244 if (!extensions_enabled_) {
246 return CrxInstallerError( 245 return CrxInstallerError(
247 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_NOT_ENABLED)); 246 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_NOT_ENABLED));
248 } 247 }
249 248
250 if (install_cause_ == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) { 249 if (install_cause_ == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) {
251 if (extensions::switch_utils::IsEasyOffStoreInstallEnabled()) { 250 if (switch_utils::IsEasyOffStoreInstallEnabled()) {
252 const char* kHistogramName = "Extensions.OffStoreInstallDecisionEasy"; 251 const char* kHistogramName = "Extensions.OffStoreInstallDecisionEasy";
253 if (is_gallery_install()) { 252 if (is_gallery_install()) {
254 UMA_HISTOGRAM_ENUMERATION(kHistogramName, OnStoreInstall, 253 UMA_HISTOGRAM_ENUMERATION(kHistogramName, OnStoreInstall,
255 NumOffStoreInstallDecision); 254 NumOffStoreInstallDecision);
256 } else { 255 } else {
257 UMA_HISTOGRAM_ENUMERATION(kHistogramName, OffStoreInstallAllowed, 256 UMA_HISTOGRAM_ENUMERATION(kHistogramName, OffStoreInstallAllowed,
258 NumOffStoreInstallDecision); 257 NumOffStoreInstallDecision);
259 } 258 }
260 } else { 259 } else {
261 const char* kHistogramName = "Extensions.OffStoreInstallDecisionHard"; 260 const char* kHistogramName = "Extensions.OffStoreInstallDecisionHard";
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 if (extension->UpdatesFromGallery()) { 307 if (extension->UpdatesFromGallery()) {
309 return CrxInstallerError( 308 return CrxInstallerError(
310 l10n_util::GetStringFUTF16( 309 l10n_util::GetStringFUTF16(
311 IDS_EXTENSION_DISALLOW_NON_DOWNLOADED_GALLERY_INSTALLS, 310 IDS_EXTENSION_DISALLOW_NON_DOWNLOADED_GALLERY_INSTALLS,
312 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE))); 311 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)));
313 } 312 }
314 313
315 // For self-hosted apps, verify that the entire extent is on the same 314 // For self-hosted apps, verify that the entire extent is on the same
316 // host (or a subdomain of the host) the download happened from. There's 315 // host (or a subdomain of the host) the download happened from. There's
317 // no way for us to verify that the app controls any other hosts. 316 // no way for us to verify that the app controls any other hosts.
318 URLPattern pattern(extensions::UserScript::kValidUserScriptSchemes); 317 URLPattern pattern(UserScript::kValidUserScriptSchemes);
319 pattern.SetHost(download_url_.host()); 318 pattern.SetHost(download_url_.host());
320 pattern.SetMatchSubdomains(true); 319 pattern.SetMatchSubdomains(true);
321 320
322 URLPatternSet patterns = extension_->web_extent(); 321 URLPatternSet patterns = extension_->web_extent();
323 for (URLPatternSet::const_iterator i = patterns.begin(); 322 for (URLPatternSet::const_iterator i = patterns.begin();
324 i != patterns.end(); ++i) { 323 i != patterns.end(); ++i) {
325 if (!pattern.MatchesHost(i->host())) { 324 if (!pattern.MatchesHost(i->host())) {
326 return CrxInstallerError( 325 return CrxInstallerError(
327 l10n_util::GetStringUTF16( 326 l10n_util::GetStringUTF16(
328 IDS_EXTENSION_INSTALL_INCORRECT_INSTALL_HOST)); 327 IDS_EXTENSION_INSTALL_INCORRECT_INSTALL_HOST));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 ->IsExtensionBlacklisted(extension_->id())) { 399 ->IsExtensionBlacklisted(extension_->id())) {
401 VLOG(1) << "This extension: " << extension_->id() 400 VLOG(1) << "This extension: " << extension_->id()
402 << " is blacklisted. Install failed."; 401 << " is blacklisted. Install failed.";
403 ReportFailureFromUIThread( 402 ReportFailureFromUIThread(
404 CrxInstallerError( 403 CrxInstallerError(
405 l10n_util::GetStringUTF16(IDS_EXTENSION_CANT_INSTALL_BLACKLISTED))); 404 l10n_util::GetStringUTF16(IDS_EXTENSION_CANT_INSTALL_BLACKLISTED)));
406 return; 405 return;
407 } 406 }
408 407
409 string16 error; 408 string16 error;
410 if (!extensions::ExtensionSystem::Get(profile_)->management_policy()-> 409 if (!ExtensionSystem::Get(profile_)->management_policy()->
411 UserMayLoad(extension_, &error)) { 410 UserMayLoad(extension_, &error)) {
412 ReportFailureFromUIThread(CrxInstallerError(error)); 411 ReportFailureFromUIThread(CrxInstallerError(error));
413 return; 412 return;
414 } 413 }
415 414
416 GURL overlapping_url; 415 GURL overlapping_url;
417 const Extension* overlapping_extension = 416 const Extension* overlapping_extension =
418 frontend_weak_->extensions()-> 417 frontend_weak_->extensions()->
419 GetHostedAppByOverlappingWebExtent(extension_->web_extent()); 418 GetHostedAppByOverlappingWebExtent(extension_->web_extent());
420 if (overlapping_extension && 419 if (overlapping_extension &&
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 // Some users (such as the download shelf) need to know when a 617 // Some users (such as the download shelf) need to know when a
619 // CRXInstaller is done. Listening for the EXTENSION_* events 618 // CRXInstaller is done. Listening for the EXTENSION_* events
620 // is problematic because they don't know anything about the 619 // is problematic because they don't know anything about the
621 // extension before it is unpacked, so they cannot filter based 620 // extension before it is unpacked, so they cannot filter based
622 // on the extension. 621 // on the extension.
623 content::NotificationService::current()->Notify( 622 content::NotificationService::current()->Notify(
624 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 623 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
625 content::Source<CrxInstaller>(this), 624 content::Source<CrxInstaller>(this),
626 content::Details<const Extension>(extension)); 625 content::Details<const Extension>(extension));
627 } 626 }
627
628 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.h ('k') | chrome/browser/extensions/crx_installer_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698