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