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/renderer/security_filter_peer.h" | 5 #include "chrome/renderer/security_filter_peer.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 | 85 |
86 void SecurityFilterPeer::OnReceivedData(const char* data, | 86 void SecurityFilterPeer::OnReceivedData(const char* data, |
87 int data_length, | 87 int data_length, |
88 int encoded_data_length) { | 88 int encoded_data_length) { |
89 NOTREACHED(); | 89 NOTREACHED(); |
90 } | 90 } |
91 | 91 |
92 void SecurityFilterPeer::OnCompletedRequest( | 92 void SecurityFilterPeer::OnCompletedRequest( |
93 const net::URLRequestStatus& status, | 93 const net::URLRequestStatus& status, |
| 94 bool handled_externally, |
94 const std::string& security_info, | 95 const std::string& security_info, |
95 const base::TimeTicks& completion_time) { | 96 const base::TimeTicks& completion_time) { |
96 NOTREACHED(); | 97 NOTREACHED(); |
97 } | 98 } |
98 | 99 |
99 // static | 100 // static |
100 void ProcessResponseInfo( | 101 void ProcessResponseInfo( |
101 const webkit_glue::ResourceResponseInfo& info_in, | 102 const webkit_glue::ResourceResponseInfo& info_in, |
102 webkit_glue::ResourceResponseInfo* info_out, | 103 webkit_glue::ResourceResponseInfo* info_out, |
103 const std::string& mime_type) { | 104 const std::string& mime_type) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 ProcessResponseInfo(info, &response_info_, mime_type_); | 145 ProcessResponseInfo(info, &response_info_, mime_type_); |
145 } | 146 } |
146 | 147 |
147 void BufferedPeer::OnReceivedData(const char* data, | 148 void BufferedPeer::OnReceivedData(const char* data, |
148 int data_length, | 149 int data_length, |
149 int encoded_data_length) { | 150 int encoded_data_length) { |
150 data_.append(data, data_length); | 151 data_.append(data, data_length); |
151 } | 152 } |
152 | 153 |
153 void BufferedPeer::OnCompletedRequest(const net::URLRequestStatus& status, | 154 void BufferedPeer::OnCompletedRequest(const net::URLRequestStatus& status, |
| 155 bool handled_externally, |
154 const std::string& security_info, | 156 const std::string& security_info, |
155 const base::TimeTicks& completion_time) { | 157 const base::TimeTicks& completion_time) { |
156 // Make sure we delete ourselves at the end of this call. | 158 // Make sure we delete ourselves at the end of this call. |
157 scoped_ptr<BufferedPeer> this_deleter(this); | 159 scoped_ptr<BufferedPeer> this_deleter(this); |
158 | 160 |
159 // Give sub-classes a chance at altering the data. | 161 // Give sub-classes a chance at altering the data. |
160 if (status.status() != net::URLRequestStatus::SUCCESS || !DataReady()) { | 162 if (status.status() != net::URLRequestStatus::SUCCESS || !DataReady()) { |
161 // Pretend we failed to load the resource. | 163 // Pretend we failed to load the resource. |
162 original_peer_->OnReceivedResponse(response_info_); | 164 original_peer_->OnReceivedResponse(response_info_); |
163 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, | 165 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, |
164 net::ERR_ABORTED); | 166 net::ERR_ABORTED); |
165 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 167 original_peer_->OnCompletedRequest(status, handled_externally, |
| 168 security_info, completion_time); |
166 return; | 169 return; |
167 } | 170 } |
168 | 171 |
169 original_peer_->OnReceivedResponse(response_info_); | 172 original_peer_->OnReceivedResponse(response_info_); |
170 if (!data_.empty()) | 173 if (!data_.empty()) |
171 original_peer_->OnReceivedData(data_.data(), | 174 original_peer_->OnReceivedData(data_.data(), |
172 static_cast<int>(data_.size()), | 175 static_cast<int>(data_.size()), |
173 -1); | 176 -1); |
174 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 177 original_peer_->OnCompletedRequest(status, handled_externally, |
| 178 security_info, completion_time); |
175 } | 179 } |
176 | 180 |
177 //////////////////////////////////////////////////////////////////////////////// | 181 //////////////////////////////////////////////////////////////////////////////// |
178 // ReplaceContentPeer | 182 // ReplaceContentPeer |
179 | 183 |
180 ReplaceContentPeer::ReplaceContentPeer( | 184 ReplaceContentPeer::ReplaceContentPeer( |
181 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, | 185 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
182 webkit_glue::ResourceLoaderBridge::Peer* peer, | 186 webkit_glue::ResourceLoaderBridge::Peer* peer, |
183 const std::string& mime_type, | 187 const std::string& mime_type, |
184 const std::string& data) | 188 const std::string& data) |
(...skipping 11 matching lines...) Expand all Loading... |
196 } | 200 } |
197 | 201 |
198 void ReplaceContentPeer::OnReceivedData(const char* data, | 202 void ReplaceContentPeer::OnReceivedData(const char* data, |
199 int data_length, | 203 int data_length, |
200 int encoded_data_length) { | 204 int encoded_data_length) { |
201 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 205 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
202 } | 206 } |
203 | 207 |
204 void ReplaceContentPeer::OnCompletedRequest( | 208 void ReplaceContentPeer::OnCompletedRequest( |
205 const net::URLRequestStatus& status, | 209 const net::URLRequestStatus& status, |
| 210 bool handled_externally, |
206 const std::string& security_info, | 211 const std::string& security_info, |
207 const base::TimeTicks& completion_time) { | 212 const base::TimeTicks& completion_time) { |
208 webkit_glue::ResourceResponseInfo info; | 213 webkit_glue::ResourceResponseInfo info; |
209 ProcessResponseInfo(info, &info, mime_type_); | 214 ProcessResponseInfo(info, &info, mime_type_); |
210 info.security_info = security_info; | 215 info.security_info = security_info; |
211 info.content_length = static_cast<int>(data_.size()); | 216 info.content_length = static_cast<int>(data_.size()); |
212 original_peer_->OnReceivedResponse(info); | 217 original_peer_->OnReceivedResponse(info); |
213 if (!data_.empty()) | 218 if (!data_.empty()) |
214 original_peer_->OnReceivedData(data_.data(), | 219 original_peer_->OnReceivedData(data_.data(), |
215 static_cast<int>(data_.size()), | 220 static_cast<int>(data_.size()), |
216 -1); | 221 -1); |
217 original_peer_->OnCompletedRequest(net::URLRequestStatus(), | 222 original_peer_->OnCompletedRequest(net::URLRequestStatus(), |
| 223 handled_externally, |
218 security_info, | 224 security_info, |
219 completion_time); | 225 completion_time); |
220 | 226 |
221 // The request processing is complete, we must delete ourselves. | 227 // The request processing is complete, we must delete ourselves. |
222 delete this; | 228 delete this; |
223 } | 229 } |
OLD | NEW |