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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 11028131: Shift passage of FileStream in downloads system to be by scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Al's comments. Created 8 years, 2 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 | Annotate | Revision Log
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/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 const extensions::api::downloads::DownloadOptions& options = params->options; 571 const extensions::api::downloads::DownloadOptions& options = params->options;
572 GURL download_url(options.url); 572 GURL download_url(options.url);
573 if (!download_url.is_valid() || 573 if (!download_url.is_valid() ||
574 (!download_url.SchemeIs("data") && 574 (!download_url.SchemeIs("data") &&
575 download_url.GetOrigin() != GetExtension()->url().GetOrigin() && 575 download_url.GetOrigin() != GetExtension()->url().GetOrigin() &&
576 !GetExtension()->HasHostPermission(download_url))) { 576 !GetExtension()->HasHostPermission(download_url))) {
577 error_ = download_extension_errors::kInvalidURLError; 577 error_ = download_extension_errors::kInvalidURLError;
578 return false; 578 return false;
579 } 579 }
580 580
581 content::DownloadSaveInfo save_info; 581 scoped_ptr<content::DownloadSaveInfo> save_info(
582 new content::DownloadSaveInfo());
582 if (options.filename.get()) { 583 if (options.filename.get()) {
583 // TODO(benjhayden): Make json_schema_compiler generate string16s instead of 584 // TODO(benjhayden): Make json_schema_compiler generate string16s instead of
584 // std::strings. Can't get filename16 from options.ToValue() because that 585 // std::strings. Can't get filename16 from options.ToValue() because that
585 // converts it from std::string. 586 // converts it from std::string.
586 base::DictionaryValue* options_value = NULL; 587 base::DictionaryValue* options_value = NULL;
587 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options_value)); 588 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options_value));
588 string16 filename16; 589 string16 filename16;
589 EXTENSION_FUNCTION_VALIDATE(options_value->GetString( 590 EXTENSION_FUNCTION_VALIDATE(options_value->GetString(
590 kFilenameKey, &filename16)); 591 kFilenameKey, &filename16));
591 if (!ValidateFilename(filename16)) { 592 if (!ValidateFilename(filename16)) {
592 error_ = download_extension_errors::kGenericError; 593 error_ = download_extension_errors::kGenericError;
593 return false; 594 return false;
594 } 595 }
595 // TODO(benjhayden) Ensure that this filename is interpreted as a path 596 // TODO(benjhayden) Ensure that this filename is interpreted as a path
596 // relative to the default downloads directory without allowing '..'. 597 // relative to the default downloads directory without allowing '..'.
597 save_info.suggested_name = filename16; 598 save_info->suggested_name = filename16;
598 } 599 }
599 600
600 if (options.save_as.get()) 601 if (options.save_as.get())
601 save_info.prompt_for_save_location = *options.save_as.get(); 602 save_info->prompt_for_save_location = *options.save_as.get();
602 603
603 Profile* current_profile = profile(); 604 Profile* current_profile = profile();
604 if (include_incognito() && profile()->HasOffTheRecordProfile()) 605 if (include_incognito() && profile()->HasOffTheRecordProfile())
605 current_profile = profile()->GetOffTheRecordProfile(); 606 current_profile = profile()->GetOffTheRecordProfile();
606 607
607 scoped_ptr<content::DownloadUrlParameters> download_params( 608 scoped_ptr<content::DownloadUrlParameters> download_params(
608 new content::DownloadUrlParameters( 609 new content::DownloadUrlParameters(
609 download_url, 610 download_url,
610 render_view_host()->GetProcess()->GetID(), 611 render_view_host()->GetProcess()->GetID(),
611 render_view_host()->GetRoutingID(), 612 render_view_host()->GetRoutingID(),
612 current_profile->GetResourceContext(), 613 current_profile->GetResourceContext(),
613 save_info)); 614 save_info.Pass()));
614 615
615 if (options.headers.get()) { 616 if (options.headers.get()) {
616 typedef extensions::api::downloads::HeaderNameValuePair HeaderNameValuePair; 617 typedef extensions::api::downloads::HeaderNameValuePair HeaderNameValuePair;
617 for (std::vector<linked_ptr<HeaderNameValuePair> >::const_iterator iter = 618 for (std::vector<linked_ptr<HeaderNameValuePair> >::const_iterator iter =
618 options.headers->begin(); 619 options.headers->begin();
619 iter != options.headers->end(); 620 iter != options.headers->end();
620 ++iter) { 621 ++iter) {
621 const HeaderNameValuePair& name_value = **iter; 622 const HeaderNameValuePair& name_value = **iter;
622 if (!net::HttpUtil::IsSafeHeader(name_value.name)) { 623 if (!net::HttpUtil::IsSafeHeader(name_value.name)) {
623 error_ = download_extension_errors::kGenericError; 624 error_ = download_extension_errors::kGenericError;
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 if (profile_->HasOffTheRecordProfile() && 1010 if (profile_->HasOffTheRecordProfile() &&
1010 !profile_->IsOffTheRecord()) { 1011 !profile_->IsOffTheRecord()) {
1011 DispatchEventInternal( 1012 DispatchEventInternal(
1012 profile_->GetOffTheRecordProfile(), 1013 profile_->GetOffTheRecordProfile(),
1013 event_name, 1014 event_name,
1014 json_args, 1015 json_args,
1015 scoped_ptr<base::ListValue>(args->DeepCopy())); 1016 scoped_ptr<base::ListValue>(args->DeepCopy()));
1016 } 1017 }
1017 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); 1018 DispatchEventInternal(profile_, event_name, json_args, args.Pass());
1018 } 1019 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | chrome/browser/extensions/webstore_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698