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 "content/public/common/resource_response_info.h" | 9 #include "content/public/common/resource_response_info.h" |
10 #include "content/public/common/resource_type.h" | 10 #include "content/public/common/resource_type.h" |
11 | 11 |
12 // The SecurityFilterPeer is a proxy to a | 12 // The SecurityFilterPeer is a proxy to a |
13 // content::RequestPeer instance. It is used to pre-process | 13 // content::RequestPeer instance. It is used to pre-process |
14 // unsafe resources (such as mixed-content resource). | 14 // unsafe resources (such as mixed-content resource). |
15 // Call the factory method CreateSecurityFilterPeer() to obtain an instance of | 15 // Call the factory method CreateSecurityFilterPeer() to obtain an instance of |
16 // SecurityFilterPeer based on the original Peer. | 16 // SecurityFilterPeer based on the original Peer. |
17 // NOTE: subclasses should ensure they delete themselves at the end of the | 17 // NOTE: subclasses should ensure they delete themselves at the end of the |
18 // OnReceiveComplete call. | 18 // OnReceiveComplete call. |
19 class SecurityFilterPeer : public content::RequestPeer { | 19 class SecurityFilterPeer : public content::RequestPeer { |
20 public: | 20 public: |
21 virtual ~SecurityFilterPeer(); | 21 ~SecurityFilterPeer() override; |
22 | 22 |
23 static SecurityFilterPeer* CreateSecurityFilterPeerForDeniedRequest( | 23 static SecurityFilterPeer* CreateSecurityFilterPeerForDeniedRequest( |
24 content::ResourceType resource_type, | 24 content::ResourceType resource_type, |
25 content::RequestPeer* peer, | 25 content::RequestPeer* peer, |
26 int os_error); | 26 int os_error); |
27 | 27 |
28 static SecurityFilterPeer* CreateSecurityFilterPeerForFrame( | 28 static SecurityFilterPeer* CreateSecurityFilterPeerForFrame( |
29 content::RequestPeer* peer, | 29 content::RequestPeer* peer, |
30 int os_error); | 30 int os_error); |
31 | 31 |
32 // content::RequestPeer methods. | 32 // content::RequestPeer methods. |
33 virtual void OnUploadProgress(uint64 position, uint64 size) override; | 33 void OnUploadProgress(uint64 position, uint64 size) override; |
34 virtual bool OnReceivedRedirect( | 34 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, |
35 const net::RedirectInfo& redirect_info, | 35 const content::ResourceResponseInfo& info) override; |
36 const content::ResourceResponseInfo& info) override; | 36 void OnReceivedResponse(const content::ResourceResponseInfo& info) override; |
37 virtual void OnReceivedResponse( | 37 void OnDownloadedData(int len, int encoded_data_length) override {} |
38 const content::ResourceResponseInfo& info) override; | 38 void OnReceivedData(const char* data, |
39 virtual void OnDownloadedData(int len, int encoded_data_length) override {} | 39 int data_length, |
40 virtual void OnReceivedData(const char* data, | 40 int encoded_data_length) override; |
41 int data_length, | 41 void OnCompletedRequest(int error_code, |
42 int encoded_data_length) override; | 42 bool was_ignored_by_handler, |
43 virtual void OnCompletedRequest(int error_code, | 43 bool stale_copy_in_cache, |
44 bool was_ignored_by_handler, | 44 const std::string& security_info, |
45 bool stale_copy_in_cache, | 45 const base::TimeTicks& completion_time, |
46 const std::string& security_info, | 46 int64 total_transfer_size) override; |
47 const base::TimeTicks& completion_time, | |
48 int64 total_transfer_size) override; | |
49 | 47 |
50 protected: | 48 protected: |
51 explicit SecurityFilterPeer(content::RequestPeer* peer); | 49 explicit SecurityFilterPeer(content::RequestPeer* peer); |
52 | 50 |
53 content::RequestPeer* original_peer_; | 51 content::RequestPeer* original_peer_; |
54 | 52 |
55 private: | 53 private: |
56 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer); | 54 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer); |
57 }; | 55 }; |
58 | 56 |
59 // The BufferedPeer reads all the data of the request into an internal buffer. | 57 // The BufferedPeer reads all the data of the request into an internal buffer. |
60 // Subclasses should implement DataReady() to process the data as necessary. | 58 // Subclasses should implement DataReady() to process the data as necessary. |
61 class BufferedPeer : public SecurityFilterPeer { | 59 class BufferedPeer : public SecurityFilterPeer { |
62 public: | 60 public: |
63 BufferedPeer(content::RequestPeer* peer, const std::string& mime_type); | 61 BufferedPeer(content::RequestPeer* peer, const std::string& mime_type); |
64 virtual ~BufferedPeer(); | 62 ~BufferedPeer() override; |
65 | 63 |
66 // content::RequestPeer Implementation. | 64 // content::RequestPeer Implementation. |
67 virtual void OnReceivedResponse( | 65 void OnReceivedResponse(const content::ResourceResponseInfo& info) override; |
68 const content::ResourceResponseInfo& info) override; | 66 void OnReceivedData(const char* data, |
69 virtual void OnReceivedData(const char* data, | 67 int data_length, |
70 int data_length, | 68 int encoded_data_length) override; |
71 int encoded_data_length) override; | 69 void OnCompletedRequest(int error_code, |
72 virtual void OnCompletedRequest( | 70 bool was_ignored_by_handler, |
73 int error_code, | 71 bool stale_copy_in_cache, |
74 bool was_ignored_by_handler, | 72 const std::string& security_info, |
75 bool stale_copy_in_cache, | 73 const base::TimeTicks& completion_time, |
76 const std::string& security_info, | 74 int64 total_transfer_size) override; |
77 const base::TimeTicks& completion_time, | |
78 int64 total_transfer_size) override; | |
79 | 75 |
80 protected: | 76 protected: |
81 // Invoked when the entire request has been processed before the data is sent | 77 // Invoked when the entire request has been processed before the data is sent |
82 // to the original peer, giving an opportunity to subclasses to process the | 78 // to the original peer, giving an opportunity to subclasses to process the |
83 // data in data_. If this method returns true, the data is fed to the | 79 // data in data_. If this method returns true, the data is fed to the |
84 // original peer, if it returns false, an error is sent instead. | 80 // original peer, if it returns false, an error is sent instead. |
85 virtual bool DataReady() = 0; | 81 virtual bool DataReady() = 0; |
86 | 82 |
87 content::ResourceResponseInfo response_info_; | 83 content::ResourceResponseInfo response_info_; |
88 std::string data_; | 84 std::string data_; |
89 | 85 |
90 private: | 86 private: |
91 std::string mime_type_; | 87 std::string mime_type_; |
92 | 88 |
93 DISALLOW_COPY_AND_ASSIGN(BufferedPeer); | 89 DISALLOW_COPY_AND_ASSIGN(BufferedPeer); |
94 }; | 90 }; |
95 | 91 |
96 // The ReplaceContentPeer cancels the request and serves the provided data as | 92 // The ReplaceContentPeer cancels the request and serves the provided data as |
97 // content instead. | 93 // content instead. |
98 // TODO(jcampan): For now the resource is still being fetched, but ignored, as | 94 // TODO(jcampan): For now the resource is still being fetched, but ignored, as |
99 // once we have provided the replacement content, the associated pending request | 95 // once we have provided the replacement content, the associated pending request |
100 // in ResourceDispatcher is removed and further OnReceived* notifications are | 96 // in ResourceDispatcher is removed and further OnReceived* notifications are |
101 // ignored. | 97 // ignored. |
102 class ReplaceContentPeer : public SecurityFilterPeer { | 98 class ReplaceContentPeer : public SecurityFilterPeer { |
103 public: | 99 public: |
104 ReplaceContentPeer(content::RequestPeer* peer, | 100 ReplaceContentPeer(content::RequestPeer* peer, |
105 const std::string& mime_type, | 101 const std::string& mime_type, |
106 const std::string& data); | 102 const std::string& data); |
107 virtual ~ReplaceContentPeer(); | 103 ~ReplaceContentPeer() override; |
108 | 104 |
109 // content::RequestPeer Implementation. | 105 // content::RequestPeer Implementation. |
110 virtual void OnReceivedResponse( | 106 void OnReceivedResponse(const content::ResourceResponseInfo& info) override; |
111 const content::ResourceResponseInfo& info) override; | 107 void OnReceivedData(const char* data, |
112 virtual void OnReceivedData(const char* data, | 108 int data_length, |
113 int data_length, | 109 int encoded_data_length) override; |
114 int encoded_data_length) override; | 110 void OnCompletedRequest(int error_code, |
115 virtual void OnCompletedRequest( | 111 bool was_ignored_by_handler, |
116 int error_code, | 112 bool stale_copy_in_cache, |
117 bool was_ignored_by_handler, | 113 const std::string& security_info, |
118 bool stale_copy_in_cache, | 114 const base::TimeTicks& completion_time, |
119 const std::string& security_info, | 115 int64 total_transfer_size) override; |
120 const base::TimeTicks& completion_time, | |
121 int64 total_transfer_size) override; | |
122 | 116 |
123 private: | 117 private: |
124 content::ResourceResponseInfo response_info_; | 118 content::ResourceResponseInfo response_info_; |
125 std::string mime_type_; | 119 std::string mime_type_; |
126 std::string data_; | 120 std::string data_; |
127 | 121 |
128 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer); | 122 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer); |
129 }; | 123 }; |
130 | 124 |
131 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_ | 125 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_ |
OLD | NEW |