| 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/common/security_filter_peer.h" | 5 #include "chrome/common/security_filter_peer.h" |
| 6 | 6 |
| 7 #include "base/gfx/png_encoder.h" | 7 #include "base/gfx/png_encoder.h" |
| 8 #include "base/gfx/size.h" | 8 #include "base/gfx/size.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void SecurityFilterPeer::OnReceivedResponse( | 107 void SecurityFilterPeer::OnReceivedResponse( |
| 108 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, | 108 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, |
| 109 bool content_filtered) { | 109 bool content_filtered) { |
| 110 NOTREACHED(); | 110 NOTREACHED(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void SecurityFilterPeer::OnReceivedData(const char* data, int len) { | 113 void SecurityFilterPeer::OnReceivedData(const char* data, int len) { |
| 114 NOTREACHED(); | 114 NOTREACHED(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void SecurityFilterPeer::OnCompletedRequest(const URLRequestStatus& status) { | 117 void SecurityFilterPeer::OnCompletedRequest(const URLRequestStatus& status, |
| 118 const std::string& security_info) { |
| 118 NOTREACHED(); | 119 NOTREACHED(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 std::string SecurityFilterPeer::GetURLForDebugging() { | 122 std::string SecurityFilterPeer::GetURLForDebugging() { |
| 122 return original_peer_->GetURLForDebugging(); | 123 return original_peer_->GetURLForDebugging(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 // static | 126 // static |
| 126 void ProcessResponseInfo( | 127 void ProcessResponseInfo( |
| 127 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info_in, | 128 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info_in, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 void BufferedPeer::OnReceivedResponse( | 169 void BufferedPeer::OnReceivedResponse( |
| 169 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, | 170 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, |
| 170 bool response_filtered) { | 171 bool response_filtered) { |
| 171 ProcessResponseInfo(info, &response_info_, mime_type_); | 172 ProcessResponseInfo(info, &response_info_, mime_type_); |
| 172 } | 173 } |
| 173 | 174 |
| 174 void BufferedPeer::OnReceivedData(const char* data, int len) { | 175 void BufferedPeer::OnReceivedData(const char* data, int len) { |
| 175 data_.append(data, len); | 176 data_.append(data, len); |
| 176 } | 177 } |
| 177 | 178 |
| 178 void BufferedPeer::OnCompletedRequest(const URLRequestStatus& status) { | 179 void BufferedPeer::OnCompletedRequest(const URLRequestStatus& status, |
| 180 const std::string& security_info) { |
| 179 // Make sure we delete ourselves at the end of this call. | 181 // Make sure we delete ourselves at the end of this call. |
| 180 scoped_ptr<BufferedPeer> this_deleter(this); | 182 scoped_ptr<BufferedPeer> this_deleter(this); |
| 181 | 183 |
| 182 // Give sub-classes a chance at altering the data. | 184 // Give sub-classes a chance at altering the data. |
| 183 if (status.status() != URLRequestStatus::SUCCESS || !DataReady()) { | 185 if (status.status() != URLRequestStatus::SUCCESS || !DataReady()) { |
| 184 // Pretend we failed to load the resource. | 186 // Pretend we failed to load the resource. |
| 185 original_peer_->OnReceivedResponse(response_info_, true); | 187 original_peer_->OnReceivedResponse(response_info_, true); |
| 186 URLRequestStatus status(URLRequestStatus::CANCELED, 0); | 188 URLRequestStatus status(URLRequestStatus::CANCELED, 0); |
| 187 original_peer_->OnCompletedRequest(status); | 189 original_peer_->OnCompletedRequest(status, security_info); |
| 188 return; | 190 return; |
| 189 } | 191 } |
| 190 | 192 |
| 191 original_peer_->OnReceivedResponse(response_info_, true); | 193 original_peer_->OnReceivedResponse(response_info_, true); |
| 192 if (!data_.empty()) | 194 if (!data_.empty()) |
| 193 original_peer_->OnReceivedData(data_.data(), | 195 original_peer_->OnReceivedData(data_.data(), |
| 194 static_cast<int>(data_.size())); | 196 static_cast<int>(data_.size())); |
| 195 original_peer_->OnCompletedRequest(status); | 197 original_peer_->OnCompletedRequest(status, security_info); |
| 196 } | 198 } |
| 197 | 199 |
| 198 //////////////////////////////////////////////////////////////////////////////// | 200 //////////////////////////////////////////////////////////////////////////////// |
| 199 // ReplaceContentPeer | 201 // ReplaceContentPeer |
| 200 | 202 |
| 201 ReplaceContentPeer::ReplaceContentPeer( | 203 ReplaceContentPeer::ReplaceContentPeer( |
| 202 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, | 204 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| 203 webkit_glue::ResourceLoaderBridge::Peer* peer, | 205 webkit_glue::ResourceLoaderBridge::Peer* peer, |
| 204 const std::string& mime_type, | 206 const std::string& mime_type, |
| 205 const std::string& data) | 207 const std::string& data) |
| 206 : SecurityFilterPeer(resource_loader_bridge, peer), | 208 : SecurityFilterPeer(resource_loader_bridge, peer), |
| 207 mime_type_(mime_type), | 209 mime_type_(mime_type), |
| 208 data_(data) { | 210 data_(data) { |
| 209 } | 211 } |
| 210 | 212 |
| 211 ReplaceContentPeer::~ReplaceContentPeer() { | 213 ReplaceContentPeer::~ReplaceContentPeer() { |
| 212 } | 214 } |
| 213 | 215 |
| 214 void ReplaceContentPeer::OnReceivedResponse( | 216 void ReplaceContentPeer::OnReceivedResponse( |
| 215 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, | 217 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, |
| 216 bool content_filtered) { | 218 bool content_filtered) { |
| 217 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 219 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 218 } | 220 } |
| 219 | 221 |
| 220 void ReplaceContentPeer::OnReceivedData(const char* data, int len) { | 222 void ReplaceContentPeer::OnReceivedData(const char* data, int len) { |
| 221 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 223 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 222 } | 224 } |
| 223 | 225 |
| 224 void ReplaceContentPeer::OnCompletedRequest(const URLRequestStatus& status) { | 226 void ReplaceContentPeer::OnCompletedRequest(const URLRequestStatus& status, |
| 227 const std::string& security_info) { |
| 225 webkit_glue::ResourceLoaderBridge::ResponseInfo info; | 228 webkit_glue::ResourceLoaderBridge::ResponseInfo info; |
| 226 ProcessResponseInfo(info, &info, mime_type_); | 229 ProcessResponseInfo(info, &info, mime_type_); |
| 230 info.security_info = security_info; |
| 227 info.content_length = static_cast<int>(data_.size()); | 231 info.content_length = static_cast<int>(data_.size()); |
| 228 original_peer_->OnReceivedResponse(info, true); | 232 original_peer_->OnReceivedResponse(info, true); |
| 229 if (!data_.empty()) | 233 if (!data_.empty()) |
| 230 original_peer_->OnReceivedData(data_.data(), | 234 original_peer_->OnReceivedData(data_.data(), |
| 231 static_cast<int>(data_.size())); | 235 static_cast<int>(data_.size())); |
| 232 original_peer_->OnCompletedRequest(URLRequestStatus()); | 236 original_peer_->OnCompletedRequest(URLRequestStatus(), security_info); |
| 233 | 237 |
| 234 // The request processing is complete, we must delete ourselves. | 238 // The request processing is complete, we must delete ourselves. |
| 235 delete this; | 239 delete this; |
| 236 } | 240 } |
| 237 | 241 |
| 238 //////////////////////////////////////////////////////////////////////////////// | 242 //////////////////////////////////////////////////////////////////////////////// |
| 239 // ImageFilterPeer | 243 // ImageFilterPeer |
| 240 | 244 |
| 241 ImageFilterPeer::ImageFilterPeer( | 245 ImageFilterPeer::ImageFilterPeer( |
| 242 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, | 246 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 309 } |
| 306 | 310 |
| 307 // Copy the vector content to data_ which is a string. | 311 // Copy the vector content to data_ which is a string. |
| 308 data_.clear(); | 312 data_.clear(); |
| 309 data_.resize(output.size()); | 313 data_.resize(output.size()); |
| 310 std::copy(output.begin(), output.end(), data_.begin()); | 314 std::copy(output.begin(), output.end(), data_.begin()); |
| 311 | 315 |
| 312 return true; | 316 return true; |
| 313 } | 317 } |
| 314 | 318 |
| OLD | NEW |