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

Side by Side Diff: chrome/browser/download/download_extension_api.cc

Issue 9460010: test http auth-basic handling and implement headers.binaryValue for downloads.download() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: include load_flags.h Created 8 years, 9 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/downloads/test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/download/download_extension_api.h" 5 #include "chrome/browser/download/download_extension_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 26 matching lines...) Expand all
37 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 37 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
38 #include "chrome/browser/ui/browser_list.h" 38 #include "chrome/browser/ui/browser_list.h"
39 #include "chrome/browser/ui/webui/web_ui_util.h" 39 #include "chrome/browser/ui/webui/web_ui_util.h"
40 #include "content/browser/download/download_state_info.h" 40 #include "content/browser/download/download_state_info.h"
41 #include "content/browser/download/download_types.h" 41 #include "content/browser/download/download_types.h"
42 #include "content/browser/download/interrupt_reasons.h" 42 #include "content/browser/download/interrupt_reasons.h"
43 #include "content/browser/renderer_host/render_view_host.h" 43 #include "content/browser/renderer_host/render_view_host.h"
44 #include "content/browser/renderer_host/resource_dispatcher_host.h" 44 #include "content/browser/renderer_host/resource_dispatcher_host.h"
45 #include "content/public/browser/download_item.h" 45 #include "content/public/browser/download_item.h"
46 #include "content/public/browser/render_process_host.h" 46 #include "content/public/browser/render_process_host.h"
47 #include "net/base/load_flags.h"
47 #include "net/http/http_util.h" 48 #include "net/http/http_util.h"
48 #include "net/url_request/url_request.h" 49 #include "net/url_request/url_request.h"
49 50
50 using content::BrowserThread; 51 using content::BrowserThread;
51 using content::DownloadId; 52 using content::DownloadId;
52 using content::DownloadItem; 53 using content::DownloadItem;
53 using content::DownloadManager; 54 using content::DownloadManager;
54 55
55 namespace download_extension_errors { 56 namespace download_extension_errors {
56 57
(...skipping 25 matching lines...) Expand all
82 const char kDangerKey[] = "danger"; 83 const char kDangerKey[] = "danger";
83 const char kDangerSafe[] = "safe"; 84 const char kDangerSafe[] = "safe";
84 const char kDangerUrl[] = "url"; 85 const char kDangerUrl[] = "url";
85 const char kEndTimeKey[] = "endTime"; 86 const char kEndTimeKey[] = "endTime";
86 const char kErrorKey[] = "error"; 87 const char kErrorKey[] = "error";
87 const char kFileSizeKey[] = "fileSize"; 88 const char kFileSizeKey[] = "fileSize";
88 const char kFilenameKey[] = "filename"; 89 const char kFilenameKey[] = "filename";
89 const char kFilenameRegexKey[] = "filenameRegex"; 90 const char kFilenameRegexKey[] = "filenameRegex";
90 const char kHeaderNameKey[] = "name"; 91 const char kHeaderNameKey[] = "name";
91 const char kHeaderValueKey[] = "value"; 92 const char kHeaderValueKey[] = "value";
93 const char kHeaderBinaryValueKey[] = "binaryValue";
92 const char kHeadersKey[] = "headers"; 94 const char kHeadersKey[] = "headers";
93 const char kIdKey[] = "id"; 95 const char kIdKey[] = "id";
94 const char kLimitKey[] = "limit"; 96 const char kLimitKey[] = "limit";
95 const char kMethodKey[] = "method"; 97 const char kMethodKey[] = "method";
96 const char kMimeKey[] = "mime"; 98 const char kMimeKey[] = "mime";
97 const char kOrderByKey[] = "orderBy"; 99 const char kOrderByKey[] = "orderBy";
98 const char kPausedKey[] = "paused"; 100 const char kPausedKey[] = "paused";
99 const char kQueryKey[] = "query"; 101 const char kQueryKey[] = "query";
100 const char kSaveAsKey[] = "saveAs"; 102 const char kSaveAsKey[] = "saveAs";
101 const char kSizeKey[] = "size"; 103 const char kSizeKey[] = "size";
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 399 }
398 400
399 if (options->HasKey(kBodyKey)) { 401 if (options->HasKey(kBodyKey)) {
400 EXTENSION_FUNCTION_VALIDATE(options->GetString( 402 EXTENSION_FUNCTION_VALIDATE(options->GetString(
401 kBodyKey, &iodata_->post_body)); 403 kBodyKey, &iodata_->post_body));
402 } 404 }
403 405
404 if (iodata_->extra_headers != NULL) { 406 if (iodata_->extra_headers != NULL) {
405 for (size_t index = 0; index < iodata_->extra_headers->GetSize(); ++index) { 407 for (size_t index = 0; index < iodata_->extra_headers->GetSize(); ++index) {
406 base::DictionaryValue* header = NULL; 408 base::DictionaryValue* header = NULL;
407 std::string name, value; 409 std::string name;
408 EXTENSION_FUNCTION_VALIDATE(iodata_->extra_headers->GetDictionary( 410 EXTENSION_FUNCTION_VALIDATE(iodata_->extra_headers->GetDictionary(
409 index, &header)); 411 index, &header));
410 EXTENSION_FUNCTION_VALIDATE(header->GetString( 412 EXTENSION_FUNCTION_VALIDATE(header->GetString(
411 kHeaderNameKey, &name)); 413 kHeaderNameKey, &name));
412 EXTENSION_FUNCTION_VALIDATE(header->GetString( 414 if (header->HasKey(kHeaderBinaryValueKey)) {
413 kHeaderValueKey, &value)); 415 base::ListValue* binary_value = NULL;
416 EXTENSION_FUNCTION_VALIDATE(header->GetList(
417 kHeaderBinaryValueKey, &binary_value));
418 for (size_t char_i = 0; char_i < binary_value->GetSize(); ++char_i) {
419 int char_value = 0;
420 EXTENSION_FUNCTION_VALIDATE(binary_value->GetInteger(
421 char_i, &char_value));
422 }
423 } else if (header->HasKey(kHeaderValueKey)) {
424 std::string value;
425 EXTENSION_FUNCTION_VALIDATE(header->GetString(
426 kHeaderValueKey, &value));
427 }
414 if (!net::HttpUtil::IsSafeHeader(name)) { 428 if (!net::HttpUtil::IsSafeHeader(name)) {
415 error_ = download_extension_errors::kGenericError; 429 error_ = download_extension_errors::kGenericError;
416 return false; 430 return false;
417 } 431 }
418 } 432 }
419 } 433 }
420 iodata_->rdh = ResourceDispatcherHost::Get(); 434 iodata_->rdh = ResourceDispatcherHost::Get();
421 iodata_->resource_context = profile()->GetResourceContext(); 435 iodata_->resource_context = profile()->GetResourceContext();
422 iodata_->render_process_host_id = render_view_host()->process()->GetID(); 436 iodata_->render_process_host_id = render_view_host()->process()->GetID();
423 iodata_->render_view_host_routing_id = render_view_host()->routing_id(); 437 iodata_->render_view_host_routing_id = render_view_host()->routing_id();
(...skipping 20 matching lines...) Expand all
444 save_info.prompt_for_save_location = iodata_->save_as; 458 save_info.prompt_for_save_location = iodata_->save_as;
445 459
446 scoped_ptr<net::URLRequest> request( 460 scoped_ptr<net::URLRequest> request(
447 new net::URLRequest(iodata_->url, iodata_->rdh)); 461 new net::URLRequest(iodata_->url, iodata_->rdh));
448 request->set_method(iodata_->method); 462 request->set_method(iodata_->method);
449 if (iodata_->extra_headers != NULL) { 463 if (iodata_->extra_headers != NULL) {
450 for (size_t index = 0; index < iodata_->extra_headers->GetSize(); ++index) { 464 for (size_t index = 0; index < iodata_->extra_headers->GetSize(); ++index) {
451 base::DictionaryValue* header = NULL; 465 base::DictionaryValue* header = NULL;
452 std::string name, value; 466 std::string name, value;
453 CHECK(iodata_->extra_headers->GetDictionary(index, &header)); 467 CHECK(iodata_->extra_headers->GetDictionary(index, &header));
454 CHECK(header->GetString("name", &name)); 468 CHECK(header->GetString(kHeaderNameKey, &name));
455 CHECK(header->GetString("value", &value)); 469 if (header->HasKey(kHeaderBinaryValueKey)) {
470 base::ListValue* binary_value = NULL;
471 CHECK(header->GetList(kHeaderBinaryValueKey, &binary_value));
472 for (size_t char_i = 0; char_i < binary_value->GetSize(); ++char_i) {
473 int char_value = 0;
474 CHECK(binary_value->GetInteger(char_i, &char_value));
475 if ((0 <= char_value) &&
476 (char_value <= 0xff)) {
477 value.push_back(char_value);
478 }
479 }
480 } else if (header->HasKey(kHeaderValueKey)) {
481 CHECK(header->GetString(kHeaderValueKey, &value));
482 }
456 request->SetExtraRequestHeaderByName(name, value, false/*overwrite*/); 483 request->SetExtraRequestHeaderByName(name, value, false/*overwrite*/);
457 } 484 }
458 } 485 }
459 if (!iodata_->post_body.empty()) { 486 if (!iodata_->post_body.empty()) {
460 request->AppendBytesToUpload(iodata_->post_body.data(), 487 request->AppendBytesToUpload(iodata_->post_body.data(),
461 iodata_->post_body.size()); 488 iodata_->post_body.size());
462 } 489 }
490
491 // Prevent login prompts for 401/407 responses.
492 request->set_load_flags(request->load_flags() |
493 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN);
494
463 net::Error error = iodata_->rdh->BeginDownload( 495 net::Error error = iodata_->rdh->BeginDownload(
464 request.Pass(), 496 request.Pass(),
465 false, // prefer_cache 497 false, // prefer_cache
466 save_info, 498 save_info,
467 base::Bind(&DownloadsDownloadFunction::OnStarted, this), 499 base::Bind(&DownloadsDownloadFunction::OnStarted, this),
468 iodata_->render_process_host_id, 500 iodata_->render_process_host_id,
469 iodata_->render_view_host_routing_id, 501 iodata_->render_view_host_routing_id,
470 iodata_->resource_context); 502 iodata_->resource_context);
471 iodata_.reset(); 503 iodata_.reset();
472 504
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 ListValue args; 1066 ListValue args;
1035 args.Append(arg); 1067 args.Append(arg);
1036 std::string json_args; 1068 std::string json_args;
1037 base::JSONWriter::Write(&args, false, &json_args); 1069 base::JSONWriter::Write(&args, false, &json_args);
1038 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( 1070 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
1039 event_name, 1071 event_name,
1040 json_args, 1072 json_args,
1041 profile_, 1073 profile_,
1042 GURL()); 1074 GURL());
1043 } 1075 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/downloads/test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698