| 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" |
| 11 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 | 13 |
| 14 SecurityFilterPeer::SecurityFilterPeer(content::RequestPeer* peer) | 14 SecurityFilterPeer::SecurityFilterPeer( |
| 15 : original_peer_(peer) {} | 15 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| 16 content::RequestPeer* peer) |
| 17 : original_peer_(peer), |
| 18 resource_loader_bridge_(resource_loader_bridge) { |
| 19 } |
| 16 | 20 |
| 17 SecurityFilterPeer::~SecurityFilterPeer() { | 21 SecurityFilterPeer::~SecurityFilterPeer() { |
| 18 } | 22 } |
| 19 | 23 |
| 20 // static | 24 // static |
| 21 SecurityFilterPeer* | 25 SecurityFilterPeer* |
| 22 SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest( | 26 SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest( |
| 23 ResourceType::Type resource_type, | 27 ResourceType::Type resource_type, |
| 24 content::RequestPeer* peer, | 28 content::RequestPeer* peer, |
| 25 int os_error) { | 29 int os_error) { |
| 26 // Create a filter for SSL and CERT errors. | 30 // Create a filter for SSL and CERT errors. |
| 27 switch (os_error) { | 31 switch (os_error) { |
| 28 case net::ERR_SSL_PROTOCOL_ERROR: | 32 case net::ERR_SSL_PROTOCOL_ERROR: |
| 29 case net::ERR_CERT_COMMON_NAME_INVALID: | 33 case net::ERR_CERT_COMMON_NAME_INVALID: |
| 30 case net::ERR_CERT_DATE_INVALID: | 34 case net::ERR_CERT_DATE_INVALID: |
| 31 case net::ERR_CERT_AUTHORITY_INVALID: | 35 case net::ERR_CERT_AUTHORITY_INVALID: |
| 32 case net::ERR_CERT_CONTAINS_ERRORS: | 36 case net::ERR_CERT_CONTAINS_ERRORS: |
| 33 case net::ERR_CERT_NO_REVOCATION_MECHANISM: | 37 case net::ERR_CERT_NO_REVOCATION_MECHANISM: |
| 34 case net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION: | 38 case net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION: |
| 35 case net::ERR_CERT_REVOKED: | 39 case net::ERR_CERT_REVOKED: |
| 36 case net::ERR_CERT_INVALID: | 40 case net::ERR_CERT_INVALID: |
| 37 case net::ERR_CERT_WEAK_SIGNATURE_ALGORITHM: | 41 case net::ERR_CERT_WEAK_SIGNATURE_ALGORITHM: |
| 38 case net::ERR_CERT_WEAK_KEY: | 42 case net::ERR_CERT_WEAK_KEY: |
| 39 case net::ERR_CERT_NAME_CONSTRAINT_VIOLATION: | 43 case net::ERR_CERT_NAME_CONSTRAINT_VIOLATION: |
| 40 case net::ERR_INSECURE_RESPONSE: | 44 case net::ERR_INSECURE_RESPONSE: |
| 41 case net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN: | 45 case net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN: |
| 42 if (ResourceType::IsFrame(resource_type)) | 46 if (ResourceType::IsFrame(resource_type)) |
| 43 return CreateSecurityFilterPeerForFrame(peer, os_error); | 47 return CreateSecurityFilterPeerForFrame(peer, os_error); |
| 44 // Any other content is entirely filtered-out. | 48 // Any other content is entirely filtered-out. |
| 45 return new ReplaceContentPeer(peer, std::string(), std::string()); | 49 return new ReplaceContentPeer(NULL, peer, std::string(), std::string()); |
| 46 default: | 50 default: |
| 47 // For other errors, we use our normal error handling. | 51 // For other errors, we use our normal error handling. |
| 48 return NULL; | 52 return NULL; |
| 49 } | 53 } |
| 50 } | 54 } |
| 51 | 55 |
| 52 // static | 56 // static |
| 53 SecurityFilterPeer* SecurityFilterPeer::CreateSecurityFilterPeerForFrame( | 57 SecurityFilterPeer* SecurityFilterPeer::CreateSecurityFilterPeerForFrame( |
| 54 content::RequestPeer* peer, | 58 content::RequestPeer* peer, |
| 55 int os_error) { | 59 int os_error) { |
| 56 // TODO(jcampan): use a different message when getting a phishing/malware | 60 // TODO(jcampan): use a different message when getting a phishing/malware |
| 57 // error. | 61 // error. |
| 58 std::string html = base::StringPrintf( | 62 std::string html = base::StringPrintf( |
| 59 "<html><meta charset='UTF-8'>" | 63 "<html><meta charset='UTF-8'>" |
| 60 "<body style='background-color:#990000;color:white;'>" | 64 "<body style='background-color:#990000;color:white;'>" |
| 61 "%s</body></html>", | 65 "%s</body></html>", |
| 62 l10n_util::GetStringUTF8(IDS_UNSAFE_FRAME_MESSAGE).c_str()); | 66 l10n_util::GetStringUTF8(IDS_UNSAFE_FRAME_MESSAGE).c_str()); |
| 63 return new ReplaceContentPeer(peer, "text/html", html); | 67 return new ReplaceContentPeer(NULL, peer, "text/html", html); |
| 64 } | 68 } |
| 65 | 69 |
| 66 void SecurityFilterPeer::OnUploadProgress(uint64 position, uint64 size) { | 70 void SecurityFilterPeer::OnUploadProgress(uint64 position, uint64 size) { |
| 67 original_peer_->OnUploadProgress(position, size); | 71 original_peer_->OnUploadProgress(position, size); |
| 68 } | 72 } |
| 69 | 73 |
| 70 bool SecurityFilterPeer::OnReceivedRedirect( | 74 bool SecurityFilterPeer::OnReceivedRedirect( |
| 71 const GURL& new_url, | 75 const GURL& new_url, |
| 72 const webkit_glue::ResourceResponseInfo& info, | 76 const webkit_glue::ResourceResponseInfo& info, |
| 73 bool* has_new_first_party_for_cookies, | 77 bool* has_new_first_party_for_cookies, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 126 } |
| 123 raw_headers.push_back('\0'); | 127 raw_headers.push_back('\0'); |
| 124 net::HttpResponseHeaders* new_headers = | 128 net::HttpResponseHeaders* new_headers = |
| 125 new net::HttpResponseHeaders(raw_headers); | 129 new net::HttpResponseHeaders(raw_headers); |
| 126 info_out->headers = new_headers; | 130 info_out->headers = new_headers; |
| 127 } | 131 } |
| 128 | 132 |
| 129 //////////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////////// |
| 130 // BufferedPeer | 134 // BufferedPeer |
| 131 | 135 |
| 132 BufferedPeer::BufferedPeer(content::RequestPeer* peer, | 136 BufferedPeer::BufferedPeer( |
| 133 const std::string& mime_type) | 137 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| 134 : SecurityFilterPeer(peer), mime_type_(mime_type) {} | 138 content::RequestPeer* peer, |
| 139 const std::string& mime_type) |
| 140 : SecurityFilterPeer(resource_loader_bridge, peer), |
| 141 mime_type_(mime_type) { |
| 142 } |
| 135 | 143 |
| 136 BufferedPeer::~BufferedPeer() { | 144 BufferedPeer::~BufferedPeer() { |
| 137 } | 145 } |
| 138 | 146 |
| 139 void BufferedPeer::OnReceivedResponse( | 147 void BufferedPeer::OnReceivedResponse( |
| 140 const webkit_glue::ResourceResponseInfo& info) { | 148 const webkit_glue::ResourceResponseInfo& info) { |
| 141 ProcessResponseInfo(info, &response_info_, mime_type_); | 149 ProcessResponseInfo(info, &response_info_, mime_type_); |
| 142 } | 150 } |
| 143 | 151 |
| 144 void BufferedPeer::OnReceivedData(const char* data, | 152 void BufferedPeer::OnReceivedData(const char* data, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 173 static_cast<int>(data_.size()), | 181 static_cast<int>(data_.size()), |
| 174 -1); | 182 -1); |
| 175 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, | 183 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, |
| 176 stale_copy_in_cache, security_info, | 184 stale_copy_in_cache, security_info, |
| 177 completion_time, total_transfer_size); | 185 completion_time, total_transfer_size); |
| 178 } | 186 } |
| 179 | 187 |
| 180 //////////////////////////////////////////////////////////////////////////////// | 188 //////////////////////////////////////////////////////////////////////////////// |
| 181 // ReplaceContentPeer | 189 // ReplaceContentPeer |
| 182 | 190 |
| 183 ReplaceContentPeer::ReplaceContentPeer(content::RequestPeer* peer, | 191 ReplaceContentPeer::ReplaceContentPeer( |
| 184 const std::string& mime_type, | 192 webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| 185 const std::string& data) | 193 content::RequestPeer* peer, |
| 186 : SecurityFilterPeer(peer), | 194 const std::string& mime_type, |
| 195 const std::string& data) |
| 196 : SecurityFilterPeer(resource_loader_bridge, peer), |
| 187 mime_type_(mime_type), | 197 mime_type_(mime_type), |
| 188 data_(data) {} | 198 data_(data) { |
| 199 } |
| 189 | 200 |
| 190 ReplaceContentPeer::~ReplaceContentPeer() { | 201 ReplaceContentPeer::~ReplaceContentPeer() { |
| 191 } | 202 } |
| 192 | 203 |
| 193 void ReplaceContentPeer::OnReceivedResponse( | 204 void ReplaceContentPeer::OnReceivedResponse( |
| 194 const webkit_glue::ResourceResponseInfo& info) { | 205 const webkit_glue::ResourceResponseInfo& info) { |
| 195 // Ignore this, we'll serve some alternate content in OnCompletedRequest. | 206 // Ignore this, we'll serve some alternate content in OnCompletedRequest. |
| 196 } | 207 } |
| 197 | 208 |
| 198 void ReplaceContentPeer::OnReceivedData(const char* data, | 209 void ReplaceContentPeer::OnReceivedData(const char* data, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 220 original_peer_->OnCompletedRequest(net::OK, | 231 original_peer_->OnCompletedRequest(net::OK, |
| 221 false, | 232 false, |
| 222 stale_copy_in_cache, | 233 stale_copy_in_cache, |
| 223 security_info, | 234 security_info, |
| 224 completion_time, | 235 completion_time, |
| 225 total_transfer_size); | 236 total_transfer_size); |
| 226 | 237 |
| 227 // The request processing is complete, we must delete ourselves. | 238 // The request processing is complete, we must delete ourselves. |
| 228 delete this; | 239 delete this; |
| 229 } | 240 } |
| OLD | NEW |