Return Windows error code when create-process fails.
[chromium-blink-merge.git] / chrome / renderer / security_filter_peer.h
blobd26b5897dd6966ad4ef9e0f038b8fc9ae4338e65
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 OnDownloadedData(int len, int encoded_data_length) override {}
39 protected:
40 explicit SecurityFilterPeer(content::RequestPeer* peer);
42 content::RequestPeer* original_peer_;
44 private:
45 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer);
48 // The BufferedPeer reads all the data of the request into an internal buffer.
49 // Subclasses should implement DataReady() to process the data as necessary.
50 class BufferedPeer : public SecurityFilterPeer {
51 public:
52 BufferedPeer(content::RequestPeer* peer, const std::string& mime_type);
53 ~BufferedPeer() override;
55 // content::RequestPeer Implementation.
56 void OnReceivedResponse(const content::ResourceResponseInfo& info) override;
57 void OnReceivedData(scoped_ptr<ReceivedData> data) override;
58 void OnCompletedRequest(int error_code,
59 bool was_ignored_by_handler,
60 bool stale_copy_in_cache,
61 const std::string& security_info,
62 const base::TimeTicks& completion_time,
63 int64 total_transfer_size) override;
64 void OnReceivedCompletedResponse(const content::ResourceResponseInfo& info,
65 scoped_ptr<ReceivedData> data,
66 int error_code,
67 bool was_ignored_by_handler,
68 bool stale_copy_in_cache,
69 const std::string& security_info,
70 const base::TimeTicks& completion_time,
71 int64 total_transfer_size) override;
73 protected:
74 // Invoked when the entire request has been processed before the data is sent
75 // to the original peer, giving an opportunity to subclasses to process the
76 // data in data_. If this method returns true, the data is fed to the
77 // original peer, if it returns false, an error is sent instead.
78 virtual bool DataReady() = 0;
80 content::ResourceResponseInfo response_info_;
81 std::string data_;
83 private:
84 std::string mime_type_;
86 DISALLOW_COPY_AND_ASSIGN(BufferedPeer);
89 // The ReplaceContentPeer cancels the request and serves the provided data as
90 // content instead.
91 // TODO(jcampan): For now the resource is still being fetched, but ignored, as
92 // once we have provided the replacement content, the associated pending request
93 // in ResourceDispatcher is removed and further OnReceived* notifications are
94 // ignored.
95 class ReplaceContentPeer : public SecurityFilterPeer {
96 public:
97 ReplaceContentPeer(content::RequestPeer* peer,
98 const std::string& mime_type,
99 const std::string& data);
100 ~ReplaceContentPeer() override;
102 // content::RequestPeer Implementation.
103 void OnReceivedResponse(const content::ResourceResponseInfo& info) override;
104 void OnReceivedData(scoped_ptr<ReceivedData> data) override;
105 void OnCompletedRequest(int error_code,
106 bool was_ignored_by_handler,
107 bool stale_copy_in_cache,
108 const std::string& security_info,
109 const base::TimeTicks& completion_time,
110 int64 total_transfer_size) override;
111 void OnReceivedCompletedResponse(const content::ResourceResponseInfo& info,
112 scoped_ptr<ReceivedData> data,
113 int error_code,
114 bool was_ignored_by_handler,
115 bool stale_copy_in_cache,
116 const std::string& security_info,
117 const base::TimeTicks& completion_time,
118 int64 total_transfer_size) override;
120 private:
121 content::ResourceResponseInfo response_info_;
122 std::string mime_type_;
123 std::string data_;
125 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer);
128 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_