Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/renderer/security_filter_peer.cc

Issue 1103813002: Make WebURLLoader capable of retaining received buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string>
8
7 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
9 #include "chrome/grit/generated_resources.h" 11 #include "chrome/grit/generated_resources.h"
10 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
11 #include "net/http/http_response_headers.h" 13 #include "net/http/http_response_headers.h"
12 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
13 15
14 SecurityFilterPeer::SecurityFilterPeer(content::RequestPeer* peer) 16 SecurityFilterPeer::SecurityFilterPeer(content::RequestPeer* peer)
15 : original_peer_(peer) { 17 : original_peer_(peer) {
16 } 18 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const content::ResourceResponseInfo& info) { 75 const content::ResourceResponseInfo& info) {
74 NOTREACHED(); 76 NOTREACHED();
75 return false; 77 return false;
76 } 78 }
77 79
78 void SecurityFilterPeer::OnReceivedResponse( 80 void SecurityFilterPeer::OnReceivedResponse(
79 const content::ResourceResponseInfo& info) { 81 const content::ResourceResponseInfo& info) {
80 NOTREACHED(); 82 NOTREACHED();
81 } 83 }
82 84
83 void SecurityFilterPeer::OnReceivedData(const char* data, 85 void SecurityFilterPeer::OnReceivedData(scoped_ptr<ReceivedData> data) {
84 int data_length,
85 int encoded_data_length) {
86 NOTREACHED(); 86 NOTREACHED();
87 } 87 }
88 88
89 void SecurityFilterPeer::OnCompletedRequest( 89 void SecurityFilterPeer::OnCompletedRequest(
90 int error_code, 90 int error_code,
91 bool was_ignored_by_handler, 91 bool was_ignored_by_handler,
92 bool stale_copy_in_cache, 92 bool stale_copy_in_cache,
93 const std::string& security_info, 93 const std::string& security_info,
94 const base::TimeTicks& completion_time, 94 const base::TimeTicks& completion_time,
95 int64 total_transfer_size) { 95 int64 total_transfer_size) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 : SecurityFilterPeer(peer), mime_type_(mime_type) {} 132 : SecurityFilterPeer(peer), mime_type_(mime_type) {}
133 133
134 BufferedPeer::~BufferedPeer() { 134 BufferedPeer::~BufferedPeer() {
135 } 135 }
136 136
137 void BufferedPeer::OnReceivedResponse( 137 void BufferedPeer::OnReceivedResponse(
138 const content::ResourceResponseInfo& info) { 138 const content::ResourceResponseInfo& info) {
139 ProcessResponseInfo(info, &response_info_, mime_type_); 139 ProcessResponseInfo(info, &response_info_, mime_type_);
140 } 140 }
141 141
142 void BufferedPeer::OnReceivedData(const char* data, 142 void BufferedPeer::OnReceivedData(scoped_ptr<ReceivedData> data) {
143 int data_length, 143 data_.append(data->payload(), data->length());
144 int encoded_data_length) {
145 data_.append(data, data_length);
146 } 144 }
147 145
148 void BufferedPeer::OnCompletedRequest(int error_code, 146 void BufferedPeer::OnCompletedRequest(int error_code,
149 bool was_ignored_by_handler, 147 bool was_ignored_by_handler,
150 bool stale_copy_in_cache, 148 bool stale_copy_in_cache,
151 const std::string& security_info, 149 const std::string& security_info,
152 const base::TimeTicks& completion_time, 150 const base::TimeTicks& completion_time,
153 int64 total_transfer_size) { 151 int64 total_transfer_size) {
154 // Make sure we delete ourselves at the end of this call. 152 // Make sure we delete ourselves at the end of this call.
155 scoped_ptr<BufferedPeer> this_deleter(this); 153 scoped_ptr<BufferedPeer> this_deleter(this);
156 154
157 // Give sub-classes a chance at altering the data. 155 // Give sub-classes a chance at altering the data.
158 if (error_code != net::OK || !DataReady()) { 156 if (error_code != net::OK || !DataReady()) {
159 // Pretend we failed to load the resource. 157 // Pretend we failed to load the resource.
160 original_peer_->OnReceivedResponse(response_info_); 158 original_peer_->OnReceivedResponse(response_info_);
161 original_peer_->OnCompletedRequest(net::ERR_ABORTED, false, 159 original_peer_->OnCompletedRequest(net::ERR_ABORTED, false,
162 stale_copy_in_cache, 160 stale_copy_in_cache,
163 security_info, completion_time, 161 security_info, completion_time,
164 total_transfer_size); 162 total_transfer_size);
165 return; 163 return;
166 } 164 }
167 165
168 original_peer_->OnReceivedResponse(response_info_); 166 original_peer_->OnReceivedResponse(response_info_);
169 if (!data_.empty()) 167 if (!data_.empty())
170 original_peer_->OnReceivedData(data_.data(), 168 original_peer_->OnReceivedData(make_scoped_ptr(
171 static_cast<int>(data_.size()), 169 new RequestPeer::FixedReceivedData(data_.data(), data_.size(), -1)));
172 -1);
173 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, 170 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler,
174 stale_copy_in_cache, security_info, 171 stale_copy_in_cache, security_info,
175 completion_time, total_transfer_size); 172 completion_time, total_transfer_size);
176 } 173 }
177 174
178 //////////////////////////////////////////////////////////////////////////////// 175 ////////////////////////////////////////////////////////////////////////////////
179 // ReplaceContentPeer 176 // ReplaceContentPeer
180 177
181 ReplaceContentPeer::ReplaceContentPeer(content::RequestPeer* peer, 178 ReplaceContentPeer::ReplaceContentPeer(content::RequestPeer* peer,
182 const std::string& mime_type, 179 const std::string& mime_type,
183 const std::string& data) 180 const std::string& data)
184 : SecurityFilterPeer(peer), 181 : SecurityFilterPeer(peer),
185 mime_type_(mime_type), 182 mime_type_(mime_type),
186 data_(data) {} 183 data_(data) {}
187 184
188 ReplaceContentPeer::~ReplaceContentPeer() { 185 ReplaceContentPeer::~ReplaceContentPeer() {
189 } 186 }
190 187
191 void ReplaceContentPeer::OnReceivedResponse( 188 void ReplaceContentPeer::OnReceivedResponse(
192 const content::ResourceResponseInfo& info) { 189 const content::ResourceResponseInfo& info) {
193 // Ignore this, we'll serve some alternate content in OnCompletedRequest. 190 // Ignore this, we'll serve some alternate content in OnCompletedRequest.
194 } 191 }
195 192
196 void ReplaceContentPeer::OnReceivedData(const char* data, 193 void ReplaceContentPeer::OnReceivedData(scoped_ptr<ReceivedData> data) {
197 int data_length,
198 int encoded_data_length) {
199 // Ignore this, we'll serve some alternate content in OnCompletedRequest. 194 // Ignore this, we'll serve some alternate content in OnCompletedRequest.
200 } 195 }
201 196
202 void ReplaceContentPeer::OnCompletedRequest( 197 void ReplaceContentPeer::OnCompletedRequest(
203 int error_code, 198 int error_code,
204 bool was_ignored_by_handler, 199 bool was_ignored_by_handler,
205 bool stale_copy_in_cache, 200 bool stale_copy_in_cache,
206 const std::string& security_info, 201 const std::string& security_info,
207 const base::TimeTicks& completion_time, 202 const base::TimeTicks& completion_time,
208 int64 total_transfer_size) { 203 int64 total_transfer_size) {
209 content::ResourceResponseInfo info; 204 content::ResourceResponseInfo info;
210 ProcessResponseInfo(info, &info, mime_type_); 205 ProcessResponseInfo(info, &info, mime_type_);
211 info.security_info = security_info; 206 info.security_info = security_info;
212 info.content_length = static_cast<int>(data_.size()); 207 info.content_length = static_cast<int>(data_.size());
213 original_peer_->OnReceivedResponse(info); 208 original_peer_->OnReceivedResponse(info);
214 if (!data_.empty()) 209 if (!data_.empty())
215 original_peer_->OnReceivedData(data_.data(), 210 original_peer_->OnReceivedData(make_scoped_ptr(
216 static_cast<int>(data_.size()), 211 new RequestPeer::FixedReceivedData(data_.data(), data_.size(), -1)));
217 -1);
218 original_peer_->OnCompletedRequest(net::OK, 212 original_peer_->OnCompletedRequest(net::OK,
219 false, 213 false,
220 stale_copy_in_cache, 214 stale_copy_in_cache,
221 security_info, 215 security_info,
222 completion_time, 216 completion_time,
223 total_transfer_size); 217 total_transfer_size);
224 218
225 // The request processing is complete, we must delete ourselves. 219 // The request processing is complete, we must delete ourselves.
226 delete this; 220 delete this;
227 } 221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698