| 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 424 |
| 425 DownloadQuery query_out; | 425 DownloadQuery query_out; |
| 426 | 426 |
| 427 if (query_in.limit.get()) { | 427 if (query_in.limit.get()) { |
| 428 if (*query_in.limit.get() < 0) { | 428 if (*query_in.limit.get() < 0) { |
| 429 *error = download_extension_errors::kInvalidQueryLimit; | 429 *error = download_extension_errors::kInvalidQueryLimit; |
| 430 return; | 430 return; |
| 431 } | 431 } |
| 432 query_out.Limit(*query_in.limit.get()); | 432 query_out.Limit(*query_in.limit.get()); |
| 433 } | 433 } |
| 434 if (query_in.state.get()) { | 434 std::string state_string = |
| 435 DownloadItem::DownloadState state = StateEnumFromString( | 435 extensions::api::downloads::ToString(query_in.state); |
| 436 *query_in.state.get()); | 436 if (!state_string.empty()) { |
| 437 DownloadItem::DownloadState state = StateEnumFromString(state_string); |
| 437 if (state == DownloadItem::MAX_DOWNLOAD_STATE) { | 438 if (state == DownloadItem::MAX_DOWNLOAD_STATE) { |
| 438 *error = download_extension_errors::kInvalidStateError; | 439 *error = download_extension_errors::kInvalidStateError; |
| 439 return; | 440 return; |
| 440 } | 441 } |
| 441 query_out.AddFilter(state); | 442 query_out.AddFilter(state); |
| 442 } | 443 } |
| 443 if (query_in.danger.get()) { | 444 std::string danger_string = |
| 444 content::DownloadDangerType danger_type = | 445 extensions::api::downloads::ToString(query_in.danger); |
| 445 DangerEnumFromString(*query_in.danger.get()); | 446 if (!danger_string.empty()) { |
| 447 content::DownloadDangerType danger_type = DangerEnumFromString( |
| 448 danger_string); |
| 446 if (danger_type == content::DOWNLOAD_DANGER_TYPE_MAX) { | 449 if (danger_type == content::DOWNLOAD_DANGER_TYPE_MAX) { |
| 447 *error = download_extension_errors::kInvalidDangerTypeError; | 450 *error = download_extension_errors::kInvalidDangerTypeError; |
| 448 return; | 451 return; |
| 449 } | 452 } |
| 450 query_out.AddFilter(danger_type); | 453 query_out.AddFilter(danger_type); |
| 451 } | 454 } |
| 452 if (query_in.order_by.get()) { | 455 if (query_in.order_by.get()) { |
| 453 CompileDownloadQueryOrderBy(*query_in.order_by.get(), error, &query_out); | 456 CompileDownloadQueryOrderBy(*query_in.order_by.get(), error, &query_out); |
| 454 if (!error->empty()) | 457 if (!error->empty()) |
| 455 return; | 458 return; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 ++iter) { | 620 ++iter) { |
| 618 const HeaderNameValuePair& name_value = **iter; | 621 const HeaderNameValuePair& name_value = **iter; |
| 619 if (!net::HttpUtil::IsSafeHeader(name_value.name)) { | 622 if (!net::HttpUtil::IsSafeHeader(name_value.name)) { |
| 620 error_ = download_extension_errors::kGenericError; | 623 error_ = download_extension_errors::kGenericError; |
| 621 return false; | 624 return false; |
| 622 } | 625 } |
| 623 download_params->add_request_header(name_value.name, name_value.value); | 626 download_params->add_request_header(name_value.name, name_value.value); |
| 624 } | 627 } |
| 625 } | 628 } |
| 626 | 629 |
| 627 if (options.method.get()) | 630 std::string method_string = |
| 628 download_params->set_method(*options.method.get()); | 631 extensions::api::downloads::ToString(options.method); |
| 632 if (!method_string.empty()) |
| 633 download_params->set_method(method_string); |
| 629 if (options.body.get()) | 634 if (options.body.get()) |
| 630 download_params->set_post_body(*options.body.get()); | 635 download_params->set_post_body(*options.body.get()); |
| 631 download_params->set_callback(base::Bind( | 636 download_params->set_callback(base::Bind( |
| 632 &DownloadsDownloadFunction::OnStarted, this)); | 637 &DownloadsDownloadFunction::OnStarted, this)); |
| 633 // Prevent login prompts for 401/407 responses. | 638 // Prevent login prompts for 401/407 responses. |
| 634 download_params->set_load_flags(net::LOAD_DO_NOT_PROMPT_FOR_LOGIN); | 639 download_params->set_load_flags(net::LOAD_DO_NOT_PROMPT_FOR_LOGIN); |
| 635 | 640 |
| 636 DownloadManager* manager = BrowserContext::GetDownloadManager( | 641 DownloadManager* manager = BrowserContext::GetDownloadManager( |
| 637 current_profile); | 642 current_profile); |
| 638 manager->DownloadUrl(download_params.Pass()); | 643 manager->DownloadUrl(download_params.Pass()); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 if (profile_->HasOffTheRecordProfile() && | 1007 if (profile_->HasOffTheRecordProfile() && |
| 1003 !profile_->IsOffTheRecord()) { | 1008 !profile_->IsOffTheRecord()) { |
| 1004 DispatchEventInternal( | 1009 DispatchEventInternal( |
| 1005 profile_->GetOffTheRecordProfile(), | 1010 profile_->GetOffTheRecordProfile(), |
| 1006 event_name, | 1011 event_name, |
| 1007 json_args, | 1012 json_args, |
| 1008 scoped_ptr<base::ListValue>(args->DeepCopy())); | 1013 scoped_ptr<base::ListValue>(args->DeepCopy())); |
| 1009 } | 1014 } |
| 1010 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); | 1015 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); |
| 1011 } | 1016 } |
| OLD | NEW |