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/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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 kHeaderNameKey, &name)); | 411 kHeaderNameKey, &name)); |
412 EXTENSION_FUNCTION_VALIDATE(header->GetString( | 412 EXTENSION_FUNCTION_VALIDATE(header->GetString( |
413 kHeaderValueKey, &value)); | 413 kHeaderValueKey, &value)); |
414 if (!net::HttpUtil::IsSafeHeader(name)) { | 414 if (!net::HttpUtil::IsSafeHeader(name)) { |
415 error_ = download_extension_errors::kGenericError; | 415 error_ = download_extension_errors::kGenericError; |
416 return false; | 416 return false; |
417 } | 417 } |
418 } | 418 } |
419 } | 419 } |
420 iodata_->rdh = ResourceDispatcherHost::Get(); | 420 iodata_->rdh = ResourceDispatcherHost::Get(); |
421 iodata_->resource_context = &profile()->GetResourceContext(); | 421 iodata_->resource_context = profile()->GetResourceContext(); |
422 iodata_->render_process_host_id = render_view_host()->process()->GetID(); | 422 iodata_->render_process_host_id = render_view_host()->process()->GetID(); |
423 iodata_->render_view_host_routing_id = render_view_host()->routing_id(); | 423 iodata_->render_view_host_routing_id = render_view_host()->routing_id(); |
424 return true; | 424 return true; |
425 } | 425 } |
426 | 426 |
427 bool DownloadsDownloadFunction::RunInternal() { | 427 bool DownloadsDownloadFunction::RunInternal() { |
428 VLOG(1) << __FUNCTION__ << " " << iodata_->url.spec(); | 428 VLOG(1) << __FUNCTION__ << " " << iodata_->url.spec(); |
429 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 429 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
430 &DownloadsDownloadFunction::BeginDownloadOnIOThread, this))) { | 430 &DownloadsDownloadFunction::BeginDownloadOnIOThread, this))) { |
431 error_ = download_extension_errors::kGenericError; | 431 error_ = download_extension_errors::kGenericError; |
(...skipping 28 matching lines...) Expand all Loading... |
460 request->AppendBytesToUpload(iodata_->post_body.data(), | 460 request->AppendBytesToUpload(iodata_->post_body.data(), |
461 iodata_->post_body.size()); | 461 iodata_->post_body.size()); |
462 } | 462 } |
463 net::Error error = iodata_->rdh->BeginDownload( | 463 net::Error error = iodata_->rdh->BeginDownload( |
464 request.Pass(), | 464 request.Pass(), |
465 false, // prefer_cache | 465 false, // prefer_cache |
466 save_info, | 466 save_info, |
467 base::Bind(&DownloadsDownloadFunction::OnStarted, this), | 467 base::Bind(&DownloadsDownloadFunction::OnStarted, this), |
468 iodata_->render_process_host_id, | 468 iodata_->render_process_host_id, |
469 iodata_->render_view_host_routing_id, | 469 iodata_->render_view_host_routing_id, |
470 *(iodata_->resource_context)); | 470 iodata_->resource_context); |
471 iodata_.reset(); | 471 iodata_.reset(); |
472 | 472 |
473 if (error != net::OK) { | 473 if (error != net::OK) { |
474 BrowserThread::PostTask( | 474 BrowserThread::PostTask( |
475 BrowserThread::UI, FROM_HERE, | 475 BrowserThread::UI, FROM_HERE, |
476 base::Bind(&DownloadsDownloadFunction::OnStarted, this, | 476 base::Bind(&DownloadsDownloadFunction::OnStarted, this, |
477 DownloadId::Invalid(), error)); | 477 DownloadId::Invalid(), error)); |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 ListValue args; | 939 ListValue args; |
940 args.Append(arg); | 940 args.Append(arg); |
941 std::string json_args; | 941 std::string json_args; |
942 base::JSONWriter::Write(&args, false, &json_args); | 942 base::JSONWriter::Write(&args, false, &json_args); |
943 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 943 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
944 event_name, | 944 event_name, |
945 json_args, | 945 json_args, |
946 profile_, | 946 profile_, |
947 GURL()); | 947 GURL()); |
948 } | 948 } |
OLD | NEW |