| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 raw_headers.append(mime_type); | 109 raw_headers.append(mime_type); |
| 110 raw_headers.push_back('\0'); | 110 raw_headers.push_back('\0'); |
| 111 } | 111 } |
| 112 raw_headers.push_back('\0'); | 112 raw_headers.push_back('\0'); |
| 113 net::HttpResponseHeaders* new_headers = | 113 net::HttpResponseHeaders* new_headers = |
| 114 new net::HttpResponseHeaders(raw_headers); | 114 new net::HttpResponseHeaders(raw_headers); |
| 115 info_out->headers = new_headers; | 115 info_out->headers = new_headers; |
| 116 } | 116 } |
| 117 | 117 |
| 118 //////////////////////////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////////////////////////// |
| 119 // BufferedPeer | |
| 120 | |
| 121 BufferedPeer::BufferedPeer(std::unique_ptr<content::RequestPeer> peer, | |
| 122 const std::string& mime_type) | |
| 123 : SecurityFilterPeer(std::move(peer)), mime_type_(mime_type) {} | |
| 124 | |
| 125 BufferedPeer::~BufferedPeer() { | |
| 126 } | |
| 127 | |
| 128 void BufferedPeer::OnReceivedResponse( | |
| 129 const content::ResourceResponseInfo& info) { | |
| 130 ProcessResponseInfo(info, &response_info_, mime_type_); | |
| 131 } | |
| 132 | |
| 133 void BufferedPeer::OnReceivedData(std::unique_ptr<ReceivedData> data) { | |
| 134 data_.append(data->payload(), data->length()); | |
| 135 } | |
| 136 | |
| 137 void BufferedPeer::OnCompletedRequest(int error_code, | |
| 138 bool was_ignored_by_handler, | |
| 139 bool stale_copy_in_cache, | |
| 140 const base::TimeTicks& completion_time, | |
| 141 int64_t total_transfer_size, | |
| 142 int64_t encoded_body_size) { | |
| 143 // Give sub-classes a chance at altering the data. | |
| 144 if (error_code != net::OK || !DataReady()) { | |
| 145 // Pretend we failed to load the resource. | |
| 146 original_peer_->OnReceivedResponse(response_info_); | |
| 147 original_peer_->OnCompletedRequest(net::ERR_ABORTED, false, | |
| 148 stale_copy_in_cache, completion_time, | |
| 149 total_transfer_size, encoded_body_size); | |
| 150 return; | |
| 151 } | |
| 152 | |
| 153 original_peer_->OnReceivedResponse(response_info_); | |
| 154 if (!data_.empty()) { | |
| 155 original_peer_->OnReceivedData(base::MakeUnique<content::FixedReceivedData>( | |
| 156 data_.data(), data_.size())); | |
| 157 } | |
| 158 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, | |
| 159 stale_copy_in_cache, completion_time, | |
| 160 total_transfer_size, encoded_body_size); | |
| 161 } | |
| 162 | |
| 163 //////////////////////////////////////////////////////////////////////////////// | |
| 164 // ReplaceContentPeer | 119 // ReplaceContentPeer |
| 165 | 120 |
| 166 ReplaceContentPeer::ReplaceContentPeer( | 121 ReplaceContentPeer::ReplaceContentPeer( |
| 167 std::unique_ptr<content::RequestPeer> peer, | 122 std::unique_ptr<content::RequestPeer> peer, |
| 168 const std::string& mime_type, | 123 const std::string& mime_type, |
| 169 const std::string& data) | 124 const std::string& data) |
| 170 : SecurityFilterPeer(std::move(peer)), mime_type_(mime_type), data_(data) {} | 125 : SecurityFilterPeer(std::move(peer)), mime_type_(mime_type), data_(data) {} |
| 171 | 126 |
| 172 ReplaceContentPeer::~ReplaceContentPeer() { | 127 ReplaceContentPeer::~ReplaceContentPeer() { |
| 173 } | 128 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 193 info.content_length = static_cast<int>(data_.size()); | 148 info.content_length = static_cast<int>(data_.size()); |
| 194 original_peer_->OnReceivedResponse(info); | 149 original_peer_->OnReceivedResponse(info); |
| 195 if (!data_.empty()) { | 150 if (!data_.empty()) { |
| 196 original_peer_->OnReceivedData(base::MakeUnique<content::FixedReceivedData>( | 151 original_peer_->OnReceivedData(base::MakeUnique<content::FixedReceivedData>( |
| 197 data_.data(), data_.size())); | 152 data_.data(), data_.size())); |
| 198 } | 153 } |
| 199 original_peer_->OnCompletedRequest(net::OK, false, stale_copy_in_cache, | 154 original_peer_->OnCompletedRequest(net::OK, false, stale_copy_in_cache, |
| 200 completion_time, total_transfer_size, | 155 completion_time, total_transfer_size, |
| 201 encoded_body_size); | 156 encoded_body_size); |
| 202 } | 157 } |
| OLD | NEW |