| 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/extensions/webstore_installer.h" | 5 #include "chrome/browser/extensions/webstore_installer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 WebstoreInstaller::Approval::Approval() | 242 WebstoreInstaller::Approval::Approval() |
| 243 : profile(NULL), | 243 : profile(NULL), |
| 244 use_app_installed_bubble(false), | 244 use_app_installed_bubble(false), |
| 245 skip_post_install_ui(false), | 245 skip_post_install_ui(false), |
| 246 skip_install_dialog(false), | 246 skip_install_dialog(false), |
| 247 enable_launcher(false), | 247 enable_launcher(false), |
| 248 manifest_check_level(MANIFEST_CHECK_LEVEL_STRICT) { | 248 manifest_check_level(MANIFEST_CHECK_LEVEL_STRICT) { |
| 249 } | 249 } |
| 250 | 250 |
| 251 scoped_ptr<WebstoreInstaller::Approval> | 251 std::unique_ptr<WebstoreInstaller::Approval> |
| 252 WebstoreInstaller::Approval::CreateWithInstallPrompt(Profile* profile) { | 252 WebstoreInstaller::Approval::CreateWithInstallPrompt(Profile* profile) { |
| 253 scoped_ptr<Approval> result(new Approval()); | 253 std::unique_ptr<Approval> result(new Approval()); |
| 254 result->profile = profile; | 254 result->profile = profile; |
| 255 return result; | 255 return result; |
| 256 } | 256 } |
| 257 | 257 |
| 258 scoped_ptr<WebstoreInstaller::Approval> | 258 std::unique_ptr<WebstoreInstaller::Approval> |
| 259 WebstoreInstaller::Approval::CreateForSharedModule(Profile* profile) { | 259 WebstoreInstaller::Approval::CreateForSharedModule(Profile* profile) { |
| 260 scoped_ptr<Approval> result(new Approval()); | 260 std::unique_ptr<Approval> result(new Approval()); |
| 261 result->profile = profile; | 261 result->profile = profile; |
| 262 result->skip_install_dialog = true; | 262 result->skip_install_dialog = true; |
| 263 result->skip_post_install_ui = true; | 263 result->skip_post_install_ui = true; |
| 264 result->manifest_check_level = MANIFEST_CHECK_LEVEL_NONE; | 264 result->manifest_check_level = MANIFEST_CHECK_LEVEL_NONE; |
| 265 return result; | 265 return result; |
| 266 } | 266 } |
| 267 | 267 |
| 268 scoped_ptr<WebstoreInstaller::Approval> | 268 std::unique_ptr<WebstoreInstaller::Approval> |
| 269 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 269 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
| 270 Profile* profile, | 270 Profile* profile, |
| 271 const std::string& extension_id, | 271 const std::string& extension_id, |
| 272 scoped_ptr<base::DictionaryValue> parsed_manifest, | 272 std::unique_ptr<base::DictionaryValue> parsed_manifest, |
| 273 bool strict_manifest_check) { | 273 bool strict_manifest_check) { |
| 274 scoped_ptr<Approval> result(new Approval()); | 274 std::unique_ptr<Approval> result(new Approval()); |
| 275 result->extension_id = extension_id; | 275 result->extension_id = extension_id; |
| 276 result->profile = profile; | 276 result->profile = profile; |
| 277 result->manifest = scoped_ptr<Manifest>( | 277 result->manifest = std::unique_ptr<Manifest>(new Manifest( |
| 278 new Manifest(Manifest::INVALID_LOCATION, | 278 Manifest::INVALID_LOCATION, |
| 279 scoped_ptr<base::DictionaryValue>( | 279 std::unique_ptr<base::DictionaryValue>(parsed_manifest->DeepCopy()))); |
| 280 parsed_manifest->DeepCopy()))); | |
| 281 result->skip_install_dialog = true; | 280 result->skip_install_dialog = true; |
| 282 result->manifest_check_level = strict_manifest_check ? | 281 result->manifest_check_level = strict_manifest_check ? |
| 283 MANIFEST_CHECK_LEVEL_STRICT : MANIFEST_CHECK_LEVEL_LOOSE; | 282 MANIFEST_CHECK_LEVEL_STRICT : MANIFEST_CHECK_LEVEL_LOOSE; |
| 284 return result; | 283 return result; |
| 285 } | 284 } |
| 286 | 285 |
| 287 WebstoreInstaller::Approval::~Approval() {} | 286 WebstoreInstaller::Approval::~Approval() {} |
| 288 | 287 |
| 289 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval( | 288 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval( |
| 290 const DownloadItem& download) { | 289 const DownloadItem& download) { |
| 291 return static_cast<const Approval*>(download.GetUserData(kApprovalKey)); | 290 return static_cast<const Approval*>(download.GetUserData(kApprovalKey)); |
| 292 } | 291 } |
| 293 | 292 |
| 294 WebstoreInstaller::WebstoreInstaller(Profile* profile, | 293 WebstoreInstaller::WebstoreInstaller(Profile* profile, |
| 295 Delegate* delegate, | 294 Delegate* delegate, |
| 296 content::WebContents* web_contents, | 295 content::WebContents* web_contents, |
| 297 const std::string& id, | 296 const std::string& id, |
| 298 scoped_ptr<Approval> approval, | 297 std::unique_ptr<Approval> approval, |
| 299 InstallSource source) | 298 InstallSource source) |
| 300 : content::WebContentsObserver(web_contents), | 299 : content::WebContentsObserver(web_contents), |
| 301 extension_registry_observer_(this), | 300 extension_registry_observer_(this), |
| 302 profile_(profile), | 301 profile_(profile), |
| 303 delegate_(delegate), | 302 delegate_(delegate), |
| 304 id_(id), | 303 id_(id), |
| 305 install_source_(source), | 304 install_source_(source), |
| 306 download_item_(NULL), | 305 download_item_(NULL), |
| 307 approval_(approval.release()), | 306 approval_(approval.release()), |
| 308 total_modules_(0), | 307 total_modules_(0), |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 item->Remove(); | 483 item->Remove(); |
| 485 return; | 484 return; |
| 486 } | 485 } |
| 487 | 486 |
| 488 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 487 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 489 DCHECK(!pending_modules_.empty()); | 488 DCHECK(!pending_modules_.empty()); |
| 490 download_item_ = item; | 489 download_item_ = item; |
| 491 download_item_->AddObserver(this); | 490 download_item_->AddObserver(this); |
| 492 if (pending_modules_.size() > 1) { | 491 if (pending_modules_.size() > 1) { |
| 493 // We are downloading a shared module. We need create an approval for it. | 492 // We are downloading a shared module. We need create an approval for it. |
| 494 scoped_ptr<Approval> approval = Approval::CreateForSharedModule(profile_); | 493 std::unique_ptr<Approval> approval = |
| 494 Approval::CreateForSharedModule(profile_); |
| 495 const SharedModuleInfo::ImportInfo& info = pending_modules_.front(); | 495 const SharedModuleInfo::ImportInfo& info = pending_modules_.front(); |
| 496 approval->extension_id = info.extension_id; | 496 approval->extension_id = info.extension_id; |
| 497 const Version version_required(info.minimum_version); | 497 const Version version_required(info.minimum_version); |
| 498 | 498 |
| 499 if (version_required.IsValid()) { | 499 if (version_required.IsValid()) { |
| 500 approval->minimum_version.reset( | 500 approval->minimum_version.reset( |
| 501 new Version(version_required)); | 501 new Version(version_required)); |
| 502 } | 502 } |
| 503 download_item_->SetUserData(kApprovalKey, approval.release()); | 503 download_item_->SetUserData(kApprovalKey, approval.release()); |
| 504 } else { | 504 } else { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 | 660 |
| 661 // The download url for the given extension is contained in |download_url_|. | 661 // The download url for the given extension is contained in |download_url_|. |
| 662 // We will navigate the current tab to this url to start the download. The | 662 // We will navigate the current tab to this url to start the download. The |
| 663 // download system will then pass the crx to the CrxInstaller. | 663 // download system will then pass the crx to the CrxInstaller. |
| 664 RecordDownloadSource(DOWNLOAD_INITIATED_BY_WEBSTORE_INSTALLER); | 664 RecordDownloadSource(DOWNLOAD_INITIATED_BY_WEBSTORE_INSTALLER); |
| 665 int render_process_host_id = contents->GetRenderProcessHost()->GetID(); | 665 int render_process_host_id = contents->GetRenderProcessHost()->GetID(); |
| 666 int render_view_host_routing_id = | 666 int render_view_host_routing_id = |
| 667 contents->GetRenderViewHost()->GetRoutingID(); | 667 contents->GetRenderViewHost()->GetRoutingID(); |
| 668 content::ResourceContext* resource_context = | 668 content::ResourceContext* resource_context = |
| 669 controller.GetBrowserContext()->GetResourceContext(); | 669 controller.GetBrowserContext()->GetResourceContext(); |
| 670 scoped_ptr<DownloadUrlParameters> params(new DownloadUrlParameters( | 670 std::unique_ptr<DownloadUrlParameters> params(new DownloadUrlParameters( |
| 671 download_url_, | 671 download_url_, render_process_host_id, render_view_host_routing_id, |
| 672 render_process_host_id, | 672 contents->GetMainFrame()->GetRoutingID(), resource_context)); |
| 673 render_view_host_routing_id, | |
| 674 contents->GetMainFrame()->GetRoutingID(), | |
| 675 resource_context)); | |
| 676 params->set_file_path(file); | 673 params->set_file_path(file); |
| 677 if (controller.GetVisibleEntry()) | 674 if (controller.GetVisibleEntry()) |
| 678 params->set_referrer(content::Referrer::SanitizeForRequest( | 675 params->set_referrer(content::Referrer::SanitizeForRequest( |
| 679 download_url_, content::Referrer(controller.GetVisibleEntry()->GetURL(), | 676 download_url_, content::Referrer(controller.GetVisibleEntry()->GetURL(), |
| 680 blink::WebReferrerPolicyDefault))); | 677 blink::WebReferrerPolicyDefault))); |
| 681 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, | 678 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, |
| 682 this, | 679 this, |
| 683 extension_id)); | 680 extension_id)); |
| 684 download_manager->DownloadUrl(std::move(params)); | 681 download_manager->DownloadUrl(std::move(params)); |
| 685 } | 682 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 1, | 789 1, |
| 793 kMaxSizeKb, | 790 kMaxSizeKb, |
| 794 kNumBuckets); | 791 kNumBuckets); |
| 795 } | 792 } |
| 796 UMA_HISTOGRAM_BOOLEAN( | 793 UMA_HISTOGRAM_BOOLEAN( |
| 797 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", | 794 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", |
| 798 total_bytes <= 0); | 795 total_bytes <= 0); |
| 799 } | 796 } |
| 800 | 797 |
| 801 } // namespace extensions | 798 } // namespace extensions |
| OLD | NEW |