| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // TODO(jcampan): use a different message when getting a phishing/malware | 60 // TODO(jcampan): use a different message when getting a phishing/malware |
| 61 // error. | 61 // error. |
| 62 std::string html = base::StringPrintf( | 62 std::string html = base::StringPrintf( |
| 63 "<html><meta charset='UTF-8'>" | 63 "<html><meta charset='UTF-8'>" |
| 64 "<body style='background-color:#990000;color:white;'>" | 64 "<body style='background-color:#990000;color:white;'>" |
| 65 "%s</body></html>", | 65 "%s</body></html>", |
| 66 l10n_util::GetStringUTF8(IDS_UNSAFE_FRAME_MESSAGE).c_str()); | 66 l10n_util::GetStringUTF8(IDS_UNSAFE_FRAME_MESSAGE).c_str()); |
| 67 return new ReplaceContentPeer(peer, "text/html", html); | 67 return new ReplaceContentPeer(peer, "text/html", html); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SecurityFilterPeer::OnUploadProgress(uint64 position, uint64 size) { | 70 void SecurityFilterPeer::OnUploadProgress(uint64_t position, uint64_t size) { |
| 71 original_peer_->OnUploadProgress(position, size); | 71 original_peer_->OnUploadProgress(position, size); |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool SecurityFilterPeer::OnReceivedRedirect( | 74 bool SecurityFilterPeer::OnReceivedRedirect( |
| 75 const net::RedirectInfo& redirect_info, | 75 const net::RedirectInfo& redirect_info, |
| 76 const content::ResourceResponseInfo& info) { | 76 const content::ResourceResponseInfo& info) { |
| 77 NOTREACHED(); | 77 NOTREACHED(); |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 | 80 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 void BufferedPeer::OnReceivedData(scoped_ptr<ReceivedData> data) { | 124 void BufferedPeer::OnReceivedData(scoped_ptr<ReceivedData> data) { |
| 125 data_.append(data->payload(), data->length()); | 125 data_.append(data->payload(), data->length()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void BufferedPeer::OnCompletedRequest(int error_code, | 128 void BufferedPeer::OnCompletedRequest(int error_code, |
| 129 bool was_ignored_by_handler, | 129 bool was_ignored_by_handler, |
| 130 bool stale_copy_in_cache, | 130 bool stale_copy_in_cache, |
| 131 const std::string& security_info, | 131 const std::string& security_info, |
| 132 const base::TimeTicks& completion_time, | 132 const base::TimeTicks& completion_time, |
| 133 int64 total_transfer_size) { | 133 int64_t total_transfer_size) { |
| 134 // Make sure we delete ourselves at the end of this call. | 134 // Make sure we delete ourselves at the end of this call. |
| 135 scoped_ptr<BufferedPeer> this_deleter(this); | 135 scoped_ptr<BufferedPeer> this_deleter(this); |
| 136 | 136 |
| 137 // Give sub-classes a chance at altering the data. | 137 // Give sub-classes a chance at altering the data. |
| 138 if (error_code != net::OK || !DataReady()) { | 138 if (error_code != net::OK || !DataReady()) { |
| 139 // Pretend we failed to load the resource. | 139 // Pretend we failed to load the resource. |
| 140 original_peer_->OnReceivedCompletedResponse( | 140 original_peer_->OnReceivedCompletedResponse( |
| 141 response_info_, nullptr, net::ERR_ABORTED, false, stale_copy_in_cache, | 141 response_info_, nullptr, net::ERR_ABORTED, false, stale_copy_in_cache, |
| 142 security_info, completion_time, total_transfer_size); | 142 security_info, completion_time, total_transfer_size); |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 | 145 |
| 146 scoped_ptr<content::FixedReceivedData> data_to_pass( | 146 scoped_ptr<content::FixedReceivedData> data_to_pass( |
| 147 data_.empty() ? nullptr : new content::FixedReceivedData( | 147 data_.empty() ? nullptr : new content::FixedReceivedData( |
| 148 data_.data(), data_.size(), -1)); | 148 data_.data(), data_.size(), -1)); |
| 149 original_peer_->OnReceivedCompletedResponse( | 149 original_peer_->OnReceivedCompletedResponse( |
| 150 response_info_, data_to_pass.Pass(), error_code, was_ignored_by_handler, | 150 response_info_, data_to_pass.Pass(), error_code, was_ignored_by_handler, |
| 151 stale_copy_in_cache, security_info, completion_time, total_transfer_size); | 151 stale_copy_in_cache, security_info, completion_time, total_transfer_size); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void BufferedPeer::OnReceivedCompletedResponse( | 154 void BufferedPeer::OnReceivedCompletedResponse( |
| 155 const content::ResourceResponseInfo& info, | 155 const content::ResourceResponseInfo& info, |
| 156 scoped_ptr<ReceivedData> data, | 156 scoped_ptr<ReceivedData> data, |
| 157 int error_code, | 157 int error_code, |
| 158 bool was_ignored_by_handler, | 158 bool was_ignored_by_handler, |
| 159 bool stale_copy_in_cache, | 159 bool stale_copy_in_cache, |
| 160 const std::string& security_info, | 160 const std::string& security_info, |
| 161 const base::TimeTicks& completion_time, | 161 const base::TimeTicks& completion_time, |
| 162 int64 total_transfer_size) { | 162 int64_t total_transfer_size) { |
| 163 // Make sure we delete ourselves at the end of this call. | 163 // Make sure we delete ourselves at the end of this call. |
| 164 scoped_ptr<BufferedPeer> this_deleter(this); | 164 scoped_ptr<BufferedPeer> this_deleter(this); |
| 165 original_peer_->OnReceivedCompletedResponse( | 165 original_peer_->OnReceivedCompletedResponse( |
| 166 info, data.Pass(), error_code, was_ignored_by_handler, | 166 info, data.Pass(), error_code, was_ignored_by_handler, |
| 167 stale_copy_in_cache, security_info, completion_time, total_transfer_size); | 167 stale_copy_in_cache, security_info, completion_time, total_transfer_size); |
| 168 } | 168 } |
| 169 | 169 |
| 170 //////////////////////////////////////////////////////////////////////////////// | 170 //////////////////////////////////////////////////////////////////////////////// |
| 171 // ReplaceContentPeer | 171 // ReplaceContentPeer |
| 172 | 172 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 188 void ReplaceContentPeer::OnReceivedData(scoped_ptr<ReceivedData> data) { | 188 void ReplaceContentPeer::OnReceivedData(scoped_ptr<ReceivedData> data) { |
| 189 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 189 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 190 } | 190 } |
| 191 | 191 |
| 192 void ReplaceContentPeer::OnCompletedRequest( | 192 void ReplaceContentPeer::OnCompletedRequest( |
| 193 int error_code, | 193 int error_code, |
| 194 bool was_ignored_by_handler, | 194 bool was_ignored_by_handler, |
| 195 bool stale_copy_in_cache, | 195 bool stale_copy_in_cache, |
| 196 const std::string& security_info, | 196 const std::string& security_info, |
| 197 const base::TimeTicks& completion_time, | 197 const base::TimeTicks& completion_time, |
| 198 int64 total_transfer_size) { | 198 int64_t total_transfer_size) { |
| 199 // Make sure we delete ourselves at the end of this call. | 199 // Make sure we delete ourselves at the end of this call. |
| 200 scoped_ptr<ReplaceContentPeer> this_deleter(this); | 200 scoped_ptr<ReplaceContentPeer> this_deleter(this); |
| 201 | 201 |
| 202 content::ResourceResponseInfo info; | 202 content::ResourceResponseInfo info; |
| 203 ProcessResponseInfo(info, &info, mime_type_); | 203 ProcessResponseInfo(info, &info, mime_type_); |
| 204 info.security_info = security_info; | 204 info.security_info = security_info; |
| 205 info.content_length = static_cast<int>(data_.size()); | 205 info.content_length = static_cast<int>(data_.size()); |
| 206 | 206 |
| 207 scoped_ptr<content::FixedReceivedData> data_to_pass( | 207 scoped_ptr<content::FixedReceivedData> data_to_pass( |
| 208 data_.empty() ? nullptr : new content::FixedReceivedData( | 208 data_.empty() ? nullptr : new content::FixedReceivedData( |
| 209 data_.data(), data_.size(), -1)); | 209 data_.data(), data_.size(), -1)); |
| 210 original_peer_->OnReceivedCompletedResponse( | 210 original_peer_->OnReceivedCompletedResponse( |
| 211 response_info_, data_to_pass.Pass(), net::OK, false, stale_copy_in_cache, | 211 response_info_, data_to_pass.Pass(), net::OK, false, stale_copy_in_cache, |
| 212 security_info, completion_time, total_transfer_size); | 212 security_info, completion_time, total_transfer_size); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void ReplaceContentPeer::OnReceivedCompletedResponse( | 215 void ReplaceContentPeer::OnReceivedCompletedResponse( |
| 216 const content::ResourceResponseInfo& info, | 216 const content::ResourceResponseInfo& info, |
| 217 scoped_ptr<ReceivedData> data, | 217 scoped_ptr<ReceivedData> data, |
| 218 int error_code, | 218 int error_code, |
| 219 bool was_ignored_by_handler, | 219 bool was_ignored_by_handler, |
| 220 bool stale_copy_in_cache, | 220 bool stale_copy_in_cache, |
| 221 const std::string& security_info, | 221 const std::string& security_info, |
| 222 const base::TimeTicks& completion_time, | 222 const base::TimeTicks& completion_time, |
| 223 int64 total_transfer_size) { | 223 int64_t total_transfer_size) { |
| 224 // Make sure we delete ourselves at the end of this call. | 224 // Make sure we delete ourselves at the end of this call. |
| 225 scoped_ptr<ReplaceContentPeer> this_deleter(this); | 225 scoped_ptr<ReplaceContentPeer> this_deleter(this); |
| 226 | 226 |
| 227 original_peer_->OnReceivedCompletedResponse( | 227 original_peer_->OnReceivedCompletedResponse( |
| 228 info, data.Pass(), error_code, was_ignored_by_handler, | 228 info, data.Pass(), error_code, was_ignored_by_handler, |
| 229 stale_copy_in_cache, security_info, completion_time, total_transfer_size); | 229 stale_copy_in_cache, security_info, completion_time, total_transfer_size); |
| 230 } | 230 } |
| OLD | NEW |