| 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/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 Loading... |
| 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 if (profile_->HasOffTheRecordProfile() && | 1007 if (profile_->HasOffTheRecordProfile() && |
| 1007 !profile_->IsOffTheRecord()) { | 1008 !profile_->IsOffTheRecord()) { |
| 1008 DispatchEventInternal( | 1009 DispatchEventInternal( |
| 1009 profile_->GetOffTheRecordProfile(), | 1010 profile_->GetOffTheRecordProfile(), |
| 1010 event_name, | 1011 event_name, |
| 1011 json_args, | 1012 json_args, |
| 1012 scoped_ptr<base::ListValue>(args->DeepCopy())); | 1013 scoped_ptr<base::ListValue>(args->DeepCopy())); |
| 1013 } | 1014 } |
| 1014 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); | 1015 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); |
| 1015 } | 1016 } |
| OLD | NEW |