| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "grit/generated_resources.h" | 7 #include "grit/generated_resources.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/http/http_response_headers.h" | 9 #include "net/http/http_response_headers.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 bool SecurityFilterPeer::OnReceivedRedirect( | 68 bool SecurityFilterPeer::OnReceivedRedirect( |
| 69 const GURL& new_url, | 69 const GURL& new_url, |
| 70 const webkit_glue::ResourceResponseInfo& info, | 70 const webkit_glue::ResourceResponseInfo& info, |
| 71 bool* has_new_first_party_for_cookies, | 71 bool* has_new_first_party_for_cookies, |
| 72 GURL* new_first_party_for_cookies) { | 72 GURL* new_first_party_for_cookies) { |
| 73 NOTREACHED(); | 73 NOTREACHED(); |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void SecurityFilterPeer::OnReceivedResponse( | 77 void SecurityFilterPeer::OnReceivedResponse( |
| 78 const webkit_glue::ResourceResponseInfo& info, | 78 const webkit_glue::ResourceResponseInfo& info) { |
| 79 bool content_filtered) { | |
| 80 NOTREACHED(); | 79 NOTREACHED(); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void SecurityFilterPeer::OnReceivedData(const char* data, int len) { | 82 void SecurityFilterPeer::OnReceivedData(const char* data, int len) { |
| 84 NOTREACHED(); | 83 NOTREACHED(); |
| 85 } | 84 } |
| 86 | 85 |
| 87 void SecurityFilterPeer::OnCompletedRequest(const net::URLRequestStatus& status, | 86 void SecurityFilterPeer::OnCompletedRequest(const net::URLRequestStatus& status, |
| 88 const std::string& security_info, | 87 const std::string& security_info, |
| 89 const base::Time& completion_time) { | 88 const base::Time& completion_time) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 webkit_glue::ResourceLoaderBridge::Peer* peer, | 126 webkit_glue::ResourceLoaderBridge::Peer* peer, |
| 128 const std::string& mime_type) | 127 const std::string& mime_type) |
| 129 : SecurityFilterPeer(resource_loader_bridge, peer), | 128 : SecurityFilterPeer(resource_loader_bridge, peer), |
| 130 mime_type_(mime_type) { | 129 mime_type_(mime_type) { |
| 131 } | 130 } |
| 132 | 131 |
| 133 BufferedPeer::~BufferedPeer() { | 132 BufferedPeer::~BufferedPeer() { |
| 134 } | 133 } |
| 135 | 134 |
| 136 void BufferedPeer::OnReceivedResponse( | 135 void BufferedPeer::OnReceivedResponse( |
| 137 const webkit_glue::ResourceResponseInfo& info, | 136 const webkit_glue::ResourceResponseInfo& info) { |
| 138 bool response_filtered) { | |
| 139 ProcessResponseInfo(info, &response_info_, mime_type_); | 137 ProcessResponseInfo(info, &response_info_, mime_type_); |
| 140 } | 138 } |
| 141 | 139 |
| 142 void BufferedPeer::OnReceivedData(const char* data, int len) { | 140 void BufferedPeer::OnReceivedData(const char* data, int len) { |
| 143 data_.append(data, len); | 141 data_.append(data, len); |
| 144 } | 142 } |
| 145 | 143 |
| 146 void BufferedPeer::OnCompletedRequest(const net::URLRequestStatus& status, | 144 void BufferedPeer::OnCompletedRequest(const net::URLRequestStatus& status, |
| 147 const std::string& security_info, | 145 const std::string& security_info, |
| 148 const base::Time& completion_time) { | 146 const base::Time& completion_time) { |
| 149 // Make sure we delete ourselves at the end of this call. | 147 // Make sure we delete ourselves at the end of this call. |
| 150 scoped_ptr<BufferedPeer> this_deleter(this); | 148 scoped_ptr<BufferedPeer> this_deleter(this); |
| 151 | 149 |
| 152 // Give sub-classes a chance at altering the data. | 150 // Give sub-classes a chance at altering the data. |
| 153 if (status.status() != net::URLRequestStatus::SUCCESS || !DataReady()) { | 151 if (status.status() != net::URLRequestStatus::SUCCESS || !DataReady()) { |
| 154 // Pretend we failed to load the resource. | 152 // Pretend we failed to load the resource. |
| 155 original_peer_->OnReceivedResponse(response_info_, true); | 153 original_peer_->OnReceivedResponse(response_info_); |
| 156 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, | 154 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, |
| 157 net::ERR_ABORTED); | 155 net::ERR_ABORTED); |
| 158 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 156 original_peer_->OnCompletedRequest(status, security_info, completion_time); |
| 159 return; | 157 return; |
| 160 } | 158 } |
| 161 | 159 |
| 162 original_peer_->OnReceivedResponse(response_info_, true); | 160 original_peer_->OnReceivedResponse(response_info_); |
| 163 if (!data_.empty()) | 161 if (!data_.empty()) |
| 164 original_peer_->OnReceivedData(data_.data(), | 162 original_peer_->OnReceivedData(data_.data(), |
| 165 static_cast<int>(data_.size())); | 163 static_cast<int>(data_.size())); |
| 166 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 164 original_peer_->OnCompletedRequest(status, security_info, completion_time); |
| 167 } | 165 } |
| 168 | 166 |
| 169 //////////////////////////////////////////////////////////////////////////////// | 167 //////////////////////////////////////////////////////////////////////////////// |
| 170 // ReplaceContentPeer | 168 // ReplaceContentPeer |
| 171 | 169 |
| 172 ReplaceContentPeer::ReplaceContentPeer( | 170 ReplaceContentPeer::ReplaceContentPeer( |
| 173 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, | 171 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| 174 webkit_glue::ResourceLoaderBridge::Peer* peer, | 172 webkit_glue::ResourceLoaderBridge::Peer* peer, |
| 175 const std::string& mime_type, | 173 const std::string& mime_type, |
| 176 const std::string& data) | 174 const std::string& data) |
| 177 : SecurityFilterPeer(resource_loader_bridge, peer), | 175 : SecurityFilterPeer(resource_loader_bridge, peer), |
| 178 mime_type_(mime_type), | 176 mime_type_(mime_type), |
| 179 data_(data) { | 177 data_(data) { |
| 180 } | 178 } |
| 181 | 179 |
| 182 ReplaceContentPeer::~ReplaceContentPeer() { | 180 ReplaceContentPeer::~ReplaceContentPeer() { |
| 183 } | 181 } |
| 184 | 182 |
| 185 void ReplaceContentPeer::OnReceivedResponse( | 183 void ReplaceContentPeer::OnReceivedResponse( |
| 186 const webkit_glue::ResourceResponseInfo& info, | 184 const webkit_glue::ResourceResponseInfo& info) { |
| 187 bool content_filtered) { | |
| 188 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 185 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 189 } | 186 } |
| 190 | 187 |
| 191 void ReplaceContentPeer::OnReceivedData(const char* data, int len) { | 188 void ReplaceContentPeer::OnReceivedData(const char* data, int len) { |
| 192 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 189 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 193 } | 190 } |
| 194 | 191 |
| 195 void ReplaceContentPeer::OnCompletedRequest( | 192 void ReplaceContentPeer::OnCompletedRequest( |
| 196 const net::URLRequestStatus& status, | 193 const net::URLRequestStatus& status, |
| 197 const std::string& security_info, | 194 const std::string& security_info, |
| 198 const base::Time& completion_time) { | 195 const base::Time& completion_time) { |
| 199 webkit_glue::ResourceResponseInfo info; | 196 webkit_glue::ResourceResponseInfo info; |
| 200 ProcessResponseInfo(info, &info, mime_type_); | 197 ProcessResponseInfo(info, &info, mime_type_); |
| 201 info.security_info = security_info; | 198 info.security_info = security_info; |
| 202 info.content_length = static_cast<int>(data_.size()); | 199 info.content_length = static_cast<int>(data_.size()); |
| 203 original_peer_->OnReceivedResponse(info, true); | 200 original_peer_->OnReceivedResponse(info); |
| 204 if (!data_.empty()) | 201 if (!data_.empty()) |
| 205 original_peer_->OnReceivedData(data_.data(), | 202 original_peer_->OnReceivedData(data_.data(), |
| 206 static_cast<int>(data_.size())); | 203 static_cast<int>(data_.size())); |
| 207 original_peer_->OnCompletedRequest(net::URLRequestStatus(), | 204 original_peer_->OnCompletedRequest(net::URLRequestStatus(), |
| 208 security_info, | 205 security_info, |
| 209 completion_time); | 206 completion_time); |
| 210 | 207 |
| 211 // The request processing is complete, we must delete ourselves. | 208 // The request processing is complete, we must delete ourselves. |
| 212 delete this; | 209 delete this; |
| 213 } | 210 } |
| OLD | NEW |