Chromium Code Reviews| 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 | 419 |
| 420 DownloadQuery query_out; | 420 DownloadQuery query_out; |
| 421 | 421 |
| 422 if (query_in.limit.get()) { | 422 if (query_in.limit.get()) { |
| 423 if (*query_in.limit.get() < 0) { | 423 if (*query_in.limit.get() < 0) { |
| 424 *error = download_extension_errors::kInvalidQueryLimit; | 424 *error = download_extension_errors::kInvalidQueryLimit; |
| 425 return; | 425 return; |
| 426 } | 426 } |
| 427 query_out.Limit(*query_in.limit.get()); | 427 query_out.Limit(*query_in.limit.get()); |
| 428 } | 428 } |
| 429 if (query_in.state.get()) { | 429 std::string state_string; |
| 430 DownloadItem::DownloadState state = StateEnumFromString( | 430 scoped_ptr<base::Value> state_value( |
| 431 *query_in.state.get()); | 431 extensions::api::downloads::CreateEnumValue(query_in.state)); |
| 432 if (state_value.get()) { | |
| 433 state_value->GetAsString(&state_string); | |
| 434 DownloadItem::DownloadState state = StateEnumFromString(state_string); | |
|
not at google - send to devlin
2012/09/14 01:44:51
if you generate a ToString as I suggested, this wo
cduvall
2012/09/17 22:07:46
Done.
| |
| 432 if (state == DownloadItem::MAX_DOWNLOAD_STATE) { | 435 if (state == DownloadItem::MAX_DOWNLOAD_STATE) { |
| 433 *error = download_extension_errors::kInvalidStateError; | 436 *error = download_extension_errors::kInvalidStateError; |
| 434 return; | 437 return; |
| 435 } | 438 } |
| 436 query_out.AddFilter(state); | 439 query_out.AddFilter(state); |
| 437 } | 440 } |
| 438 if (query_in.danger.get()) { | 441 std::string danger_string; |
| 439 content::DownloadDangerType danger_type = | 442 scoped_ptr<base::Value> danger_value( |
| 440 DangerEnumFromString(*query_in.danger.get()); | 443 extensions::api::downloads::CreateEnumValue(query_in.danger)); |
| 444 if (danger_value.get()) { | |
| 445 danger_value->GetAsString(&danger_string); | |
| 446 content::DownloadDangerType danger_type = DangerEnumFromString( | |
| 447 danger_string); | |
|
not at google - send to devlin
2012/09/14 01:44:51
etc
cduvall
2012/09/17 22:07:46
Done.
| |
| 441 if (danger_type == content::DOWNLOAD_DANGER_TYPE_MAX) { | 448 if (danger_type == content::DOWNLOAD_DANGER_TYPE_MAX) { |
| 442 *error = download_extension_errors::kInvalidDangerTypeError; | 449 *error = download_extension_errors::kInvalidDangerTypeError; |
| 443 return; | 450 return; |
| 444 } | 451 } |
| 445 query_out.AddFilter(danger_type); | 452 query_out.AddFilter(danger_type); |
| 446 } | 453 } |
| 447 if (query_in.order_by.get()) { | 454 if (query_in.order_by.get()) { |
| 448 CompileDownloadQueryOrderBy(*query_in.order_by.get(), error, &query_out); | 455 CompileDownloadQueryOrderBy(*query_in.order_by.get(), error, &query_out); |
| 449 if (!error->empty()) | 456 if (!error->empty()) |
| 450 return; | 457 return; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 ++iter) { | 572 ++iter) { |
| 566 const HeaderNameValuePair& name_value = **iter; | 573 const HeaderNameValuePair& name_value = **iter; |
| 567 if (!net::HttpUtil::IsSafeHeader(name_value.name)) { | 574 if (!net::HttpUtil::IsSafeHeader(name_value.name)) { |
| 568 error_ = download_extension_errors::kGenericError; | 575 error_ = download_extension_errors::kGenericError; |
| 569 return false; | 576 return false; |
| 570 } | 577 } |
| 571 download_params->add_request_header(name_value.name, name_value.value); | 578 download_params->add_request_header(name_value.name, name_value.value); |
| 572 } | 579 } |
| 573 } | 580 } |
| 574 | 581 |
| 575 if (options.method.get()) | 582 if (options.method != extensions::api::downloads::HTTPMETHOD_NONE) { |
| 576 download_params->set_method(*options.method.get()); | 583 std::string method; |
| 584 extensions::api::downloads::CreateEnumValue(options.method)->GetAsString( | |
| 585 &method); | |
| 586 download_params->set_method(method); | |
| 587 } | |
|
not at google - send to devlin
2012/09/14 01:44:51
etc
cduvall
2012/09/17 22:07:46
Done.
| |
| 577 if (options.body.get()) | 588 if (options.body.get()) |
| 578 download_params->set_post_body(*options.body.get()); | 589 download_params->set_post_body(*options.body); |
|
benjhayden
2012/09/14 13:17:48
Why remove the .get()? I think it's more explicit
cduvall
2012/09/17 22:07:46
Done.
| |
| 579 download_params->set_callback(base::Bind( | 590 download_params->set_callback(base::Bind( |
| 580 &DownloadsDownloadFunction::OnStarted, this)); | 591 &DownloadsDownloadFunction::OnStarted, this)); |
| 581 // Prevent login prompts for 401/407 responses. | 592 // Prevent login prompts for 401/407 responses. |
| 582 download_params->set_load_flags(net::LOAD_DO_NOT_PROMPT_FOR_LOGIN); | 593 download_params->set_load_flags(net::LOAD_DO_NOT_PROMPT_FOR_LOGIN); |
| 583 | 594 |
| 584 DownloadManager* manager = BrowserContext::GetDownloadManager( | 595 DownloadManager* manager = BrowserContext::GetDownloadManager( |
| 585 current_profile); | 596 current_profile); |
| 586 manager->DownloadUrl(download_params.Pass()); | 597 manager->DownloadUrl(download_params.Pass()); |
| 587 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); | 598 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); |
| 588 return true; | 599 return true; |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 if (profile_->HasOffTheRecordProfile() && | 997 if (profile_->HasOffTheRecordProfile() && |
| 987 !profile_->IsOffTheRecord()) { | 998 !profile_->IsOffTheRecord()) { |
| 988 DispatchEventInternal( | 999 DispatchEventInternal( |
| 989 profile_->GetOffTheRecordProfile(), | 1000 profile_->GetOffTheRecordProfile(), |
| 990 event_name, | 1001 event_name, |
| 991 json_args, | 1002 json_args, |
| 992 scoped_ptr<base::ListValue>(args->DeepCopy())); | 1003 scoped_ptr<base::ListValue>(args->DeepCopy())); |
| 993 } | 1004 } |
| 994 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); | 1005 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); |
| 995 } | 1006 } |
| OLD | NEW |