| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ProcessResponseInfo(info, &response_info_, mime_type_); | 126 ProcessResponseInfo(info, &response_info_, mime_type_); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void BufferedPeer::OnReceivedData(std::unique_ptr<ReceivedData> data) { | 129 void BufferedPeer::OnReceivedData(std::unique_ptr<ReceivedData> data) { |
| 130 data_.append(data->payload(), data->length()); | 130 data_.append(data->payload(), data->length()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void BufferedPeer::OnCompletedRequest(int error_code, | 133 void BufferedPeer::OnCompletedRequest(int error_code, |
| 134 bool was_ignored_by_handler, | 134 bool was_ignored_by_handler, |
| 135 bool stale_copy_in_cache, | 135 bool stale_copy_in_cache, |
| 136 const std::string& security_info, | |
| 137 const base::TimeTicks& completion_time, | 136 const base::TimeTicks& completion_time, |
| 138 int64_t total_transfer_size) { | 137 int64_t total_transfer_size) { |
| 139 // Give sub-classes a chance at altering the data. | 138 // Give sub-classes a chance at altering the data. |
| 140 if (error_code != net::OK || !DataReady()) { | 139 if (error_code != net::OK || !DataReady()) { |
| 141 // Pretend we failed to load the resource. | 140 // Pretend we failed to load the resource. |
| 142 original_peer_->OnReceivedResponse(response_info_); | 141 original_peer_->OnReceivedResponse(response_info_); |
| 143 original_peer_->OnCompletedRequest(net::ERR_ABORTED, false, | 142 original_peer_->OnCompletedRequest(net::ERR_ABORTED, false, |
| 144 stale_copy_in_cache, security_info, | 143 stale_copy_in_cache, completion_time, |
| 145 completion_time, total_transfer_size); | 144 total_transfer_size); |
| 146 return; | 145 return; |
| 147 } | 146 } |
| 148 | 147 |
| 149 original_peer_->OnReceivedResponse(response_info_); | 148 original_peer_->OnReceivedResponse(response_info_); |
| 150 if (!data_.empty()) { | 149 if (!data_.empty()) { |
| 151 original_peer_->OnReceivedData(base::WrapUnique( | 150 original_peer_->OnReceivedData(base::WrapUnique( |
| 152 new content::FixedReceivedData(data_.data(), data_.size(), -1, 0))); | 151 new content::FixedReceivedData(data_.data(), data_.size(), -1, 0))); |
| 153 } | 152 } |
| 154 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, | 153 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, |
| 155 stale_copy_in_cache, security_info, | 154 stale_copy_in_cache, completion_time, |
| 156 completion_time, total_transfer_size); | 155 total_transfer_size); |
| 157 } | 156 } |
| 158 | 157 |
| 159 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
| 160 // ReplaceContentPeer | 159 // ReplaceContentPeer |
| 161 | 160 |
| 162 ReplaceContentPeer::ReplaceContentPeer( | 161 ReplaceContentPeer::ReplaceContentPeer( |
| 163 std::unique_ptr<content::RequestPeer> peer, | 162 std::unique_ptr<content::RequestPeer> peer, |
| 164 const std::string& mime_type, | 163 const std::string& mime_type, |
| 165 const std::string& data) | 164 const std::string& data) |
| 166 : SecurityFilterPeer(std::move(peer)), mime_type_(mime_type), data_(data) {} | 165 : SecurityFilterPeer(std::move(peer)), mime_type_(mime_type), data_(data) {} |
| 167 | 166 |
| 168 ReplaceContentPeer::~ReplaceContentPeer() { | 167 ReplaceContentPeer::~ReplaceContentPeer() { |
| 169 } | 168 } |
| 170 | 169 |
| 171 void ReplaceContentPeer::OnReceivedResponse( | 170 void ReplaceContentPeer::OnReceivedResponse( |
| 172 const content::ResourceResponseInfo& info) { | 171 const content::ResourceResponseInfo& info) { |
| 173 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 172 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 174 } | 173 } |
| 175 | 174 |
| 176 void ReplaceContentPeer::OnReceivedData(std::unique_ptr<ReceivedData> data) { | 175 void ReplaceContentPeer::OnReceivedData(std::unique_ptr<ReceivedData> data) { |
| 177 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 176 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 178 } | 177 } |
| 179 | 178 |
| 180 void ReplaceContentPeer::OnCompletedRequest( | 179 void ReplaceContentPeer::OnCompletedRequest( |
| 181 int error_code, | 180 int error_code, |
| 182 bool was_ignored_by_handler, | 181 bool was_ignored_by_handler, |
| 183 bool stale_copy_in_cache, | 182 bool stale_copy_in_cache, |
| 184 const std::string& security_info, | |
| 185 const base::TimeTicks& completion_time, | 183 const base::TimeTicks& completion_time, |
| 186 int64_t total_transfer_size) { | 184 int64_t total_transfer_size) { |
| 187 content::ResourceResponseInfo info; | 185 content::ResourceResponseInfo info; |
| 188 ProcessResponseInfo(info, &info, mime_type_); | 186 ProcessResponseInfo(info, &info, mime_type_); |
| 189 info.security_info = security_info; | |
| 190 info.content_length = static_cast<int>(data_.size()); | 187 info.content_length = static_cast<int>(data_.size()); |
| 191 original_peer_->OnReceivedResponse(info); | 188 original_peer_->OnReceivedResponse(info); |
| 192 if (!data_.empty()) { | 189 if (!data_.empty()) { |
| 193 original_peer_->OnReceivedData(base::WrapUnique( | 190 original_peer_->OnReceivedData(base::WrapUnique( |
| 194 new content::FixedReceivedData(data_.data(), data_.size(), -1, 0))); | 191 new content::FixedReceivedData(data_.data(), data_.size(), -1, 0))); |
| 195 } | 192 } |
| 196 original_peer_->OnCompletedRequest(net::OK, false, stale_copy_in_cache, | 193 original_peer_->OnCompletedRequest(net::OK, false, stale_copy_in_cache, |
| 197 security_info, completion_time, | 194 completion_time, total_transfer_size); |
| 198 total_transfer_size); | |
| 199 } | 195 } |
| OLD | NEW |