| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_RENDERER_SECURITY_FILTER_PEER_H_ | 5 #ifndef CHROME_RENDERER_SECURITY_FILTER_PEER_H_ |
| 6 #define CHROME_RENDERER_SECURITY_FILTER_PEER_H_ | 6 #define CHROME_RENDERER_SECURITY_FILTER_PEER_H_ |
| 7 | 7 |
| 8 #include "content/public/child/request_peer.h" | 8 #include "content/public/child/request_peer.h" |
| 9 #include "webkit/common/resource_response_info.h" | 9 #include "webkit/common/resource_response_info.h" |
| 10 #include "webkit/common/resource_type.h" | 10 #include "webkit/common/resource_type.h" |
| 11 | 11 |
| 12 namespace webkit_glue { |
| 13 class ResourceLoaderBridge; |
| 14 } |
| 15 |
| 12 // The SecurityFilterPeer is a proxy to a | 16 // The SecurityFilterPeer is a proxy to a |
| 13 // content::RequestPeer instance. It is used to pre-process | 17 // content::RequestPeer instance. It is used to pre-process |
| 14 // unsafe resources (such as mixed-content resource). | 18 // unsafe resources (such as mixed-content resource). |
| 15 // Call the factory method CreateSecurityFilterPeer() to obtain an instance of | 19 // Call the factory method CreateSecurityFilterPeer() to obtain an instance of |
| 16 // SecurityFilterPeer based on the original Peer. | 20 // SecurityFilterPeer based on the original Peer. |
| 17 // NOTE: subclasses should insure they delete themselves at the end of the | 21 // NOTE: subclasses should insure they delete themselves at the end of the |
| 18 // OnReceiveComplete call. | 22 // OnReceiveComplete call. |
| 19 class SecurityFilterPeer : public content::RequestPeer { | 23 class SecurityFilterPeer : public content::RequestPeer { |
| 20 public: | 24 public: |
| 21 virtual ~SecurityFilterPeer(); | 25 virtual ~SecurityFilterPeer(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 int data_length, | 46 int data_length, |
| 43 int encoded_data_length) OVERRIDE; | 47 int encoded_data_length) OVERRIDE; |
| 44 virtual void OnCompletedRequest(int error_code, | 48 virtual void OnCompletedRequest(int error_code, |
| 45 bool was_ignored_by_handler, | 49 bool was_ignored_by_handler, |
| 46 bool stale_copy_in_cache, | 50 bool stale_copy_in_cache, |
| 47 const std::string& security_info, | 51 const std::string& security_info, |
| 48 const base::TimeTicks& completion_time, | 52 const base::TimeTicks& completion_time, |
| 49 int64 total_transfer_size) OVERRIDE; | 53 int64 total_transfer_size) OVERRIDE; |
| 50 | 54 |
| 51 protected: | 55 protected: |
| 52 explicit SecurityFilterPeer(content::RequestPeer* peer); | 56 SecurityFilterPeer(webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| 57 content::RequestPeer* peer); |
| 53 | 58 |
| 54 content::RequestPeer* original_peer_; | 59 content::RequestPeer* original_peer_; |
| 60 webkit_glue::ResourceLoaderBridge* resource_loader_bridge_; |
| 55 | 61 |
| 56 private: | 62 private: |
| 57 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer); | 63 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer); |
| 58 }; | 64 }; |
| 59 | 65 |
| 60 // The BufferedPeer reads all the data of the request into an internal buffer. | 66 // The BufferedPeer reads all the data of the request into an internal buffer. |
| 61 // Subclasses should implement DataReady() to process the data as necessary. | 67 // Subclasses should implement DataReady() to process the data as necessary. |
| 62 class BufferedPeer : public SecurityFilterPeer { | 68 class BufferedPeer : public SecurityFilterPeer { |
| 63 public: | 69 public: |
| 64 BufferedPeer(content::RequestPeer* peer, const std::string& mime_type); | 70 BufferedPeer(webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| 71 content::RequestPeer* peer, |
| 72 const std::string& mime_type); |
| 65 virtual ~BufferedPeer(); | 73 virtual ~BufferedPeer(); |
| 66 | 74 |
| 67 // content::RequestPeer Implementation. | 75 // content::RequestPeer Implementation. |
| 68 virtual void OnReceivedResponse( | 76 virtual void OnReceivedResponse( |
| 69 const webkit_glue::ResourceResponseInfo& info) OVERRIDE; | 77 const webkit_glue::ResourceResponseInfo& info) OVERRIDE; |
| 70 virtual void OnReceivedData(const char* data, | 78 virtual void OnReceivedData(const char* data, |
| 71 int data_length, | 79 int data_length, |
| 72 int encoded_data_length) OVERRIDE; | 80 int encoded_data_length) OVERRIDE; |
| 73 virtual void OnCompletedRequest( | 81 virtual void OnCompletedRequest( |
| 74 int error_code, | 82 int error_code, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 89 std::string data_; | 97 std::string data_; |
| 90 | 98 |
| 91 private: | 99 private: |
| 92 std::string mime_type_; | 100 std::string mime_type_; |
| 93 | 101 |
| 94 DISALLOW_COPY_AND_ASSIGN(BufferedPeer); | 102 DISALLOW_COPY_AND_ASSIGN(BufferedPeer); |
| 95 }; | 103 }; |
| 96 | 104 |
| 97 // The ReplaceContentPeer cancels the request and serves the provided data as | 105 // The ReplaceContentPeer cancels the request and serves the provided data as |
| 98 // content instead. | 106 // content instead. |
| 99 // TODO(jcampan): For now the resource is still being fetched, but ignored, as | 107 // TODO(jcampan): we do not as of now cancel the request, as we do not have |
| 100 // once we have provided the replacement content, the associated pending request | 108 // access to the resource_loader_bridge in the SecurityFilterPeer factory |
| 109 // method. For now the resource is still being fetched, but ignored, as once |
| 110 // we have provided the replacement content, the associated pending request |
| 101 // in ResourceDispatcher is removed and further OnReceived* notifications are | 111 // in ResourceDispatcher is removed and further OnReceived* notifications are |
| 102 // ignored. | 112 // ignored. |
| 103 class ReplaceContentPeer : public SecurityFilterPeer { | 113 class ReplaceContentPeer : public SecurityFilterPeer { |
| 104 public: | 114 public: |
| 105 ReplaceContentPeer(content::RequestPeer* peer, | 115 ReplaceContentPeer(webkit_glue::ResourceLoaderBridge* resource_loader_bridge, |
| 116 content::RequestPeer* peer, |
| 106 const std::string& mime_type, | 117 const std::string& mime_type, |
| 107 const std::string& data); | 118 const std::string& data); |
| 108 virtual ~ReplaceContentPeer(); | 119 virtual ~ReplaceContentPeer(); |
| 109 | 120 |
| 110 // content::RequestPeer Implementation. | 121 // content::RequestPeer Implementation. |
| 111 virtual void OnReceivedResponse( | 122 virtual void OnReceivedResponse( |
| 112 const webkit_glue::ResourceResponseInfo& info) OVERRIDE; | 123 const webkit_glue::ResourceResponseInfo& info) OVERRIDE; |
| 113 virtual void OnReceivedData(const char* data, | 124 virtual void OnReceivedData(const char* data, |
| 114 int data_length, | 125 int data_length, |
| 115 int encoded_data_length) OVERRIDE; | 126 int encoded_data_length) OVERRIDE; |
| 116 virtual void OnCompletedRequest(int error_code, | 127 virtual void OnCompletedRequest( |
| 117 bool was_ignored_by_handler, | 128 int error_code, |
| 118 bool stale_copy_in_cache, | 129 bool was_ignored_by_handler, |
| 119 const std::string& security_info, | 130 bool stale_copy_in_cache, |
| 120 const base::TimeTicks& completion_time, | 131 const std::string& security_info, |
| 121 int64 total_transfer_size) OVERRIDE; | 132 const base::TimeTicks& completion_time, |
| 133 int64 total_transfer_size) OVERRIDE; |
| 122 | 134 |
| 123 private: | 135 private: |
| 124 webkit_glue::ResourceResponseInfo response_info_; | 136 webkit_glue::ResourceResponseInfo response_info_; |
| 125 std::string mime_type_; | 137 std::string mime_type_; |
| 126 std::string data_; | 138 std::string data_; |
| 127 | 139 |
| 128 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer); | 140 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer); |
| 129 }; | 141 }; |
| 130 | 142 |
| 131 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_ | 143 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_ |
| OLD | NEW |