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