Reland "Non-SFI mode: Switch to newlib. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / chrome / renderer / security_filter_peer.h
blobef3bc3b6b3c97955097035a05f9b868874830c1e
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
3 // found in the LICENSE file.
5 #ifndef CHROME_RENDERER_SECURITY_FILTER_PEER_H_
6 #define CHROME_RENDERER_SECURITY_FILTER_PEER_H_
8 #include <string>
10 #include "content/public/child/request_peer.h"
11 #include "content/public/common/resource_response_info.h"
12 #include "content/public/common/resource_type.h"
14 // The SecurityFilterPeer is a proxy to a
15 // content::RequestPeer instance. It is used to pre-process
16 // unsafe resources (such as mixed-content resource).
17 // Call the factory method CreateSecurityFilterPeer() to obtain an instance of
18 // SecurityFilterPeer based on the original Peer.
19 // NOTE: subclasses should ensure they delete themselves at the end of the
20 // OnReceiveComplete call.
21 class SecurityFilterPeer : public content::RequestPeer {
22 public:
23 ~SecurityFilterPeer() override;
25 static SecurityFilterPeer* CreateSecurityFilterPeerForDeniedRequest(
26 content::ResourceType resource_type,
27 content::RequestPeer* peer,
28 int os_error);
30 static SecurityFilterPeer* CreateSecurityFilterPeerForFrame(
31 content::RequestPeer* peer,
32 int os_error);
34 // content::RequestPeer methods.
35 void OnUploadProgress(uint64 position, uint64 size) override;
36 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info,
37 const content::ResourceResponseInfo& info) override;
38 void OnReceivedResponse(const content::ResourceResponseInfo& info) override;
39 void OnDownloadedData(int len, int encoded_data_length) override {}
40 void OnReceivedData(scoped_ptr<ReceivedData> data) override;
41 void OnCompletedRequest(int error_code,
42 bool was_ignored_by_handler,
43 bool stale_copy_in_cache,
44 const std::string& security_info,
45 const base::TimeTicks& completion_time,
46 int64 total_transfer_size) override;
48 protected:
49 explicit SecurityFilterPeer(content::RequestPeer* peer);
51 content::RequestPeer* original_peer_;
53 private:
54 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer);
57 // The BufferedPeer reads all the data of the request into an internal buffer.
58 // Subclasses should implement DataReady() to process the data as necessary.
59 class BufferedPeer : public SecurityFilterPeer {
60 public:
61 BufferedPeer(content::RequestPeer* peer, const std::string& mime_type);
62 ~BufferedPeer() override;
64 // content::RequestPeer Implementation.
65 void OnReceivedResponse(const content::ResourceResponseInfo& info) override;
66 void OnReceivedData(scoped_ptr<ReceivedData> data) override;
67 void OnCompletedRequest(int error_code,
68 bool was_ignored_by_handler,
69 bool stale_copy_in_cache,
70 const std::string& security_info,
71 const base::TimeTicks& completion_time,
72 int64 total_transfer_size) override;
74 protected:
75 // Invoked when the entire request has been processed before the data is sent
76 // to the original peer, giving an opportunity to subclasses to process the
77 // data in data_. If this method returns true, the data is fed to the
78 // original peer, if it returns false, an error is sent instead.
79 virtual bool DataReady() = 0;
81 content::ResourceResponseInfo response_info_;
82 std::string data_;
84 private:
85 std::string mime_type_;
87 DISALLOW_COPY_AND_ASSIGN(BufferedPeer);
90 // The ReplaceContentPeer cancels the request and serves the provided data as
91 // content instead.
92 // TODO(jcampan): For now the resource is still being fetched, but ignored, as
93 // once we have provided the replacement content, the associated pending request
94 // in ResourceDispatcher is removed and further OnReceived* notifications are
95 // ignored.
96 class ReplaceContentPeer : public SecurityFilterPeer {
97 public:
98 ReplaceContentPeer(content::RequestPeer* peer,
99 const std::string& mime_type,
100 const std::string& data);
101 ~ReplaceContentPeer() override;
103 // content::RequestPeer Implementation.
104 void OnReceivedResponse(const content::ResourceResponseInfo& info) override;
105 void OnReceivedData(scoped_ptr<ReceivedData> data) override;
106 void OnCompletedRequest(int error_code,
107 bool was_ignored_by_handler,
108 bool stale_copy_in_cache,
109 const std::string& security_info,
110 const base::TimeTicks& completion_time,
111 int64 total_transfer_size) override;
113 private:
114 content::ResourceResponseInfo response_info_;
115 std::string mime_type_;
116 std::string data_;
118 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer);
121 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_