| 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/strings/stringprintf.h" | 8 #include "base/strings/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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return new ReplaceContentPeer(peer, "text/html", html); | 64 return new ReplaceContentPeer(peer, "text/html", html); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void SecurityFilterPeer::OnUploadProgress(uint64 position, uint64 size) { | 67 void SecurityFilterPeer::OnUploadProgress(uint64 position, uint64 size) { |
| 68 original_peer_->OnUploadProgress(position, size); | 68 original_peer_->OnUploadProgress(position, size); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool SecurityFilterPeer::OnReceivedRedirect( | 71 bool SecurityFilterPeer::OnReceivedRedirect( |
| 72 const GURL& new_url, | 72 const GURL& new_url, |
| 73 const GURL& new_first_party_for_cookies, | 73 const GURL& new_first_party_for_cookies, |
| 74 const webkit_glue::ResourceResponseInfo& info) { | 74 const content::ResourceResponseInfo& info) { |
| 75 NOTREACHED(); | 75 NOTREACHED(); |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SecurityFilterPeer::OnReceivedResponse( | 79 void SecurityFilterPeer::OnReceivedResponse( |
| 80 const webkit_glue::ResourceResponseInfo& info) { | 80 const content::ResourceResponseInfo& info) { |
| 81 NOTREACHED(); | 81 NOTREACHED(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void SecurityFilterPeer::OnReceivedData(const char* data, | 84 void SecurityFilterPeer::OnReceivedData(const char* data, |
| 85 int data_length, | 85 int data_length, |
| 86 int encoded_data_length) { | 86 int encoded_data_length) { |
| 87 NOTREACHED(); | 87 NOTREACHED(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SecurityFilterPeer::OnCompletedRequest( | 90 void SecurityFilterPeer::OnCompletedRequest( |
| 91 int error_code, | 91 int error_code, |
| 92 bool was_ignored_by_handler, | 92 bool was_ignored_by_handler, |
| 93 bool stale_copy_in_cache, | 93 bool stale_copy_in_cache, |
| 94 const std::string& security_info, | 94 const std::string& security_info, |
| 95 const base::TimeTicks& completion_time, | 95 const base::TimeTicks& completion_time, |
| 96 int64 total_transfer_size) { | 96 int64 total_transfer_size) { |
| 97 NOTREACHED(); | 97 NOTREACHED(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 void ProcessResponseInfo( | 101 void ProcessResponseInfo(const content::ResourceResponseInfo& info_in, |
| 102 const webkit_glue::ResourceResponseInfo& info_in, | 102 content::ResourceResponseInfo* info_out, |
| 103 webkit_glue::ResourceResponseInfo* info_out, | 103 const std::string& mime_type) { |
| 104 const std::string& mime_type) { | |
| 105 DCHECK(info_out); | 104 DCHECK(info_out); |
| 106 *info_out = info_in; | 105 *info_out = info_in; |
| 107 info_out->mime_type = mime_type; | 106 info_out->mime_type = mime_type; |
| 108 // Let's create our own HTTP headers. | 107 // Let's create our own HTTP headers. |
| 109 std::string raw_headers; | 108 std::string raw_headers; |
| 110 raw_headers.append("HTTP/1.1 200 OK"); | 109 raw_headers.append("HTTP/1.1 200 OK"); |
| 111 raw_headers.push_back('\0'); | 110 raw_headers.push_back('\0'); |
| 112 // Don't cache the data we are serving, it is not the real data for that URL | 111 // Don't cache the data we are serving, it is not the real data for that URL |
| 113 // (if the filtered resource were to make it into the WebCore cache, then the | 112 // (if the filtered resource were to make it into the WebCore cache, then the |
| 114 // same URL loaded in a safe scenario would still return the filtered | 113 // same URL loaded in a safe scenario would still return the filtered |
| (...skipping 15 matching lines...) Expand all Loading... |
| 130 // BufferedPeer | 129 // BufferedPeer |
| 131 | 130 |
| 132 BufferedPeer::BufferedPeer(content::RequestPeer* peer, | 131 BufferedPeer::BufferedPeer(content::RequestPeer* peer, |
| 133 const std::string& mime_type) | 132 const std::string& mime_type) |
| 134 : SecurityFilterPeer(peer), mime_type_(mime_type) {} | 133 : SecurityFilterPeer(peer), mime_type_(mime_type) {} |
| 135 | 134 |
| 136 BufferedPeer::~BufferedPeer() { | 135 BufferedPeer::~BufferedPeer() { |
| 137 } | 136 } |
| 138 | 137 |
| 139 void BufferedPeer::OnReceivedResponse( | 138 void BufferedPeer::OnReceivedResponse( |
| 140 const webkit_glue::ResourceResponseInfo& info) { | 139 const content::ResourceResponseInfo& info) { |
| 141 ProcessResponseInfo(info, &response_info_, mime_type_); | 140 ProcessResponseInfo(info, &response_info_, mime_type_); |
| 142 } | 141 } |
| 143 | 142 |
| 144 void BufferedPeer::OnReceivedData(const char* data, | 143 void BufferedPeer::OnReceivedData(const char* data, |
| 145 int data_length, | 144 int data_length, |
| 146 int encoded_data_length) { | 145 int encoded_data_length) { |
| 147 data_.append(data, data_length); | 146 data_.append(data, data_length); |
| 148 } | 147 } |
| 149 | 148 |
| 150 void BufferedPeer::OnCompletedRequest(int error_code, | 149 void BufferedPeer::OnCompletedRequest(int error_code, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 const std::string& mime_type, | 183 const std::string& mime_type, |
| 185 const std::string& data) | 184 const std::string& data) |
| 186 : SecurityFilterPeer(peer), | 185 : SecurityFilterPeer(peer), |
| 187 mime_type_(mime_type), | 186 mime_type_(mime_type), |
| 188 data_(data) {} | 187 data_(data) {} |
| 189 | 188 |
| 190 ReplaceContentPeer::~ReplaceContentPeer() { | 189 ReplaceContentPeer::~ReplaceContentPeer() { |
| 191 } | 190 } |
| 192 | 191 |
| 193 void ReplaceContentPeer::OnReceivedResponse( | 192 void ReplaceContentPeer::OnReceivedResponse( |
| 194 const webkit_glue::ResourceResponseInfo& info) { | 193 const content::ResourceResponseInfo& info) { |
| 195 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 194 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 196 } | 195 } |
| 197 | 196 |
| 198 void ReplaceContentPeer::OnReceivedData(const char* data, | 197 void ReplaceContentPeer::OnReceivedData(const char* data, |
| 199 int data_length, | 198 int data_length, |
| 200 int encoded_data_length) { | 199 int encoded_data_length) { |
| 201 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 200 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 202 } | 201 } |
| 203 | 202 |
| 204 void ReplaceContentPeer::OnCompletedRequest( | 203 void ReplaceContentPeer::OnCompletedRequest( |
| 205 int error_code, | 204 int error_code, |
| 206 bool was_ignored_by_handler, | 205 bool was_ignored_by_handler, |
| 207 bool stale_copy_in_cache, | 206 bool stale_copy_in_cache, |
| 208 const std::string& security_info, | 207 const std::string& security_info, |
| 209 const base::TimeTicks& completion_time, | 208 const base::TimeTicks& completion_time, |
| 210 int64 total_transfer_size) { | 209 int64 total_transfer_size) { |
| 211 webkit_glue::ResourceResponseInfo info; | 210 content::ResourceResponseInfo info; |
| 212 ProcessResponseInfo(info, &info, mime_type_); | 211 ProcessResponseInfo(info, &info, mime_type_); |
| 213 info.security_info = security_info; | 212 info.security_info = security_info; |
| 214 info.content_length = static_cast<int>(data_.size()); | 213 info.content_length = static_cast<int>(data_.size()); |
| 215 original_peer_->OnReceivedResponse(info); | 214 original_peer_->OnReceivedResponse(info); |
| 216 if (!data_.empty()) | 215 if (!data_.empty()) |
| 217 original_peer_->OnReceivedData(data_.data(), | 216 original_peer_->OnReceivedData(data_.data(), |
| 218 static_cast<int>(data_.size()), | 217 static_cast<int>(data_.size()), |
| 219 -1); | 218 -1); |
| 220 original_peer_->OnCompletedRequest(net::OK, | 219 original_peer_->OnCompletedRequest(net::OK, |
| 221 false, | 220 false, |
| 222 stale_copy_in_cache, | 221 stale_copy_in_cache, |
| 223 security_info, | 222 security_info, |
| 224 completion_time, | 223 completion_time, |
| 225 total_transfer_size); | 224 total_transfer_size); |
| 226 | 225 |
| 227 // The request processing is complete, we must delete ourselves. | 226 // The request processing is complete, we must delete ourselves. |
| 228 delete this; | 227 delete this; |
| 229 } | 228 } |
| OLD | NEW |