OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/renderer_host/sync_resource_handler.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "chrome/browser/debugger/devtools_netlog_observer.h" | |
9 #include "chrome/browser/net/load_timing_observer.h" | |
10 #include "chrome/browser/renderer_host/global_request_id.h" | |
11 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | |
12 #include "chrome/browser/renderer_host/resource_message_filter.h" | |
13 #include "chrome/common/render_messages.h" | |
14 #include "net/base/io_buffer.h" | |
15 #include "net/http/http_response_headers.h" | |
16 | |
17 SyncResourceHandler::SyncResourceHandler( | |
18 ResourceMessageFilter* filter, | |
19 const GURL& url, | |
20 IPC::Message* result_message, | |
21 ResourceDispatcherHost* resource_dispatcher_host) | |
22 : read_buffer_(new net::IOBuffer(kReadBufSize)), | |
23 filter_(filter), | |
24 result_message_(result_message), | |
25 rdh_(resource_dispatcher_host) { | |
26 result_.final_url = url; | |
27 } | |
28 | |
29 SyncResourceHandler::~SyncResourceHandler() { | |
30 } | |
31 | |
32 bool SyncResourceHandler::OnUploadProgress(int request_id, | |
33 uint64 position, | |
34 uint64 size) { | |
35 return true; | |
36 } | |
37 | |
38 bool SyncResourceHandler::OnRequestRedirected(int request_id, | |
39 const GURL& new_url, | |
40 ResourceResponse* response, | |
41 bool* defer) { | |
42 net::URLRequest* request = rdh_->GetURLRequest( | |
43 GlobalRequestID(filter_->child_id(), request_id)); | |
44 LoadTimingObserver::PopulateTimingInfo(request, response); | |
45 DevToolsNetLogObserver::PopulateResponseInfo(request, response); | |
46 // TODO(darin): It would be much better if this could live in WebCore, but | |
47 // doing so requires API changes at all levels. Similar code exists in | |
48 // WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-( | |
49 if (new_url.GetOrigin() != result_.final_url.GetOrigin()) { | |
50 LOG(ERROR) << "Cross origin redirect denied"; | |
51 return false; | |
52 } | |
53 result_.final_url = new_url; | |
54 return true; | |
55 } | |
56 | |
57 bool SyncResourceHandler::OnResponseStarted(int request_id, | |
58 ResourceResponse* response) { | |
59 net::URLRequest* request = rdh_->GetURLRequest( | |
60 GlobalRequestID(filter_->child_id(), request_id)); | |
61 LoadTimingObserver::PopulateTimingInfo(request, response); | |
62 DevToolsNetLogObserver::PopulateResponseInfo(request, response); | |
63 | |
64 // We don't care about copying the status here. | |
65 result_.headers = response->response_head.headers; | |
66 result_.mime_type = response->response_head.mime_type; | |
67 result_.charset = response->response_head.charset; | |
68 result_.download_file_path = response->response_head.download_file_path; | |
69 result_.request_time = response->response_head.request_time; | |
70 result_.response_time = response->response_head.response_time; | |
71 result_.connection_id = response->response_head.connection_id; | |
72 result_.connection_reused = response->response_head.connection_reused; | |
73 result_.load_timing = response->response_head.load_timing; | |
74 result_.devtools_info = response->response_head.devtools_info; | |
75 return true; | |
76 } | |
77 | |
78 bool SyncResourceHandler::OnWillStart(int request_id, | |
79 const GURL& url, | |
80 bool* defer) { | |
81 return true; | |
82 } | |
83 | |
84 bool SyncResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, | |
85 int* buf_size, int min_size) { | |
86 DCHECK(min_size == -1); | |
87 *buf = read_buffer_.get(); | |
88 *buf_size = kReadBufSize; | |
89 return true; | |
90 } | |
91 | |
92 bool SyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { | |
93 if (!*bytes_read) | |
94 return true; | |
95 result_.data.append(read_buffer_->data(), *bytes_read); | |
96 return true; | |
97 } | |
98 | |
99 bool SyncResourceHandler::OnResponseCompleted( | |
100 int request_id, | |
101 const net::URLRequestStatus& status, | |
102 const std::string& security_info) { | |
103 result_.status = status; | |
104 | |
105 ViewHostMsg_SyncLoad::WriteReplyParams(result_message_, result_); | |
106 filter_->Send(result_message_); | |
107 result_message_ = NULL; | |
108 return true; | |
109 } | |
110 | |
111 void SyncResourceHandler::OnRequestClosed() { | |
112 if (!result_message_) | |
113 return; | |
114 | |
115 result_message_->set_reply_error(); | |
116 filter_->Send(result_message_); | |
117 } | |
OLD | NEW |