OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/renderer_host/download_resource_handler.h" | 5 #include "chrome/browser/renderer_host/download_resource_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
12 #include "chrome/browser/download/download_item.h" | 12 #include "chrome/browser/download/download_item.h" |
13 #include "chrome/browser/download/download_file_manager.h" | 13 #include "chrome/browser/download/download_file_manager.h" |
14 #include "chrome/browser/history/download_create_info.h" | 14 #include "chrome/browser/history/download_create_info.h" |
15 #include "chrome/browser/renderer_host/global_request_id.h" | 15 #include "chrome/browser/renderer_host/global_request_id.h" |
16 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 16 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 17 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
17 #include "chrome/common/resource_response.h" | 18 #include "chrome/common/resource_response.h" |
18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
20 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
21 | 22 |
22 DownloadResourceHandler::DownloadResourceHandler( | 23 DownloadResourceHandler::DownloadResourceHandler( |
23 ResourceDispatcherHost* rdh, | 24 ResourceDispatcherHost* rdh, |
24 int render_process_host_id, | 25 int render_process_host_id, |
25 int render_view_id, | 26 int render_view_id, |
26 int request_id, | 27 int request_id, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 bool DownloadResourceHandler::OnResponseStarted(int request_id, | 63 bool DownloadResourceHandler::OnResponseStarted(int request_id, |
63 ResourceResponse* response) { | 64 ResourceResponse* response) { |
64 VLOG(20) << __FUNCTION__ << "()" << DebugString() | 65 VLOG(20) << __FUNCTION__ << "()" << DebugString() |
65 << " request_id = " << request_id; | 66 << " request_id = " << request_id; |
66 std::string content_disposition; | 67 std::string content_disposition; |
67 request_->GetResponseHeaderByName("content-disposition", | 68 request_->GetResponseHeaderByName("content-disposition", |
68 &content_disposition); | 69 &content_disposition); |
69 set_content_disposition(content_disposition); | 70 set_content_disposition(content_disposition); |
70 set_content_length(response->response_head.content_length); | 71 set_content_length(response->response_head.content_length); |
71 | 72 |
| 73 const ResourceDispatcherHostRequestInfo* request_info = |
| 74 ResourceDispatcherHost::InfoForRequest(request_); |
| 75 |
72 download_id_ = download_file_manager_->GetNextId(); | 76 download_id_ = download_file_manager_->GetNextId(); |
73 // |download_file_manager_| consumes (deletes): | 77 // |download_file_manager_| consumes (deletes): |
74 DownloadCreateInfo* info = new DownloadCreateInfo; | 78 DownloadCreateInfo* info = new DownloadCreateInfo; |
75 info->url = url_; | 79 info->url = url_; |
76 info->referrer_url = GURL(request_->referrer()); | 80 info->referrer_url = GURL(request_->referrer()); |
77 info->start_time = base::Time::Now(); | 81 info->start_time = base::Time::Now(); |
78 info->received_bytes = 0; | 82 info->received_bytes = 0; |
79 info->total_bytes = content_length_; | 83 info->total_bytes = content_length_; |
80 info->state = DownloadItem::IN_PROGRESS; | 84 info->state = DownloadItem::IN_PROGRESS; |
81 info->download_id = download_id_; | 85 info->download_id = download_id_; |
| 86 info->has_user_gesture = request_info->has_user_gesture(); |
82 info->child_id = global_id_.child_id; | 87 info->child_id = global_id_.child_id; |
83 info->render_view_id = render_view_id_; | 88 info->render_view_id = render_view_id_; |
84 info->request_id = global_id_.request_id; | 89 info->request_id = global_id_.request_id; |
85 info->content_disposition = content_disposition_; | 90 info->content_disposition = content_disposition_; |
86 info->mime_type = response->response_head.mime_type; | 91 info->mime_type = response->response_head.mime_type; |
87 | 92 |
88 std::string content_type_header; | 93 std::string content_type_header; |
89 if (!response->response_head.headers || | 94 if (!response->response_head.headers || |
90 !response->response_head.headers->GetMimeType(&content_type_header)) | 95 !response->response_head.headers->GetMimeType(&content_type_header)) |
91 content_type_header = ""; | 96 content_type_header = ""; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 " render_view_id_ = " "%d" | 242 " render_view_id_ = " "%d" |
238 " save_info_.file_path = " "\"%s\"" | 243 " save_info_.file_path = " "\"%s\"" |
239 " }", | 244 " }", |
240 url_.spec().c_str(), | 245 url_.spec().c_str(), |
241 download_id_, | 246 download_id_, |
242 global_id_.child_id, | 247 global_id_.child_id, |
243 global_id_.request_id, | 248 global_id_.request_id, |
244 render_view_id_, | 249 render_view_id_, |
245 save_info_.file_path.value().c_str()); | 250 save_info_.file_path.value().c_str()); |
246 } | 251 } |
OLD | NEW |