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 "webkit/child/resource_loader_bridge.h"
10 // The SecurityFilterPeer is a proxy to a
11 // webkit_glue::ResourceLoaderBridge::Peer instance. It is used to pre-process
12 // unsafe resources (such as mixed-content resource).
13 // Call the factory method CreateSecurityFilterPeer() to obtain an instance of
14 // SecurityFilterPeer based on the original Peer.
15 // NOTE: subclasses should insure they delete themselves at the end of the
16 // OnReceiveComplete call.
17 class SecurityFilterPeer
: public webkit_glue::ResourceLoaderBridge::Peer
{
19 virtual ~SecurityFilterPeer();
21 static SecurityFilterPeer
* CreateSecurityFilterPeerForDeniedRequest(
22 ResourceType::Type resource_type
,
23 webkit_glue::ResourceLoaderBridge::Peer
* peer
,
26 static SecurityFilterPeer
* CreateSecurityFilterPeerForFrame(
27 webkit_glue::ResourceLoaderBridge::Peer
* peer
,
30 // ResourceLoaderBridge::Peer methods.
31 virtual void OnUploadProgress(uint64 position
, uint64 size
) OVERRIDE
;
32 virtual bool OnReceivedRedirect(
34 const webkit_glue::ResourceResponseInfo
& info
,
35 bool* has_new_first_party_for_cookies
,
36 GURL
* new_first_party_for_cookies
) OVERRIDE
;
37 virtual void OnReceivedResponse(
38 const webkit_glue::ResourceResponseInfo
& info
) OVERRIDE
;
39 virtual void OnDownloadedData(int len
, int encoded_data_length
) OVERRIDE
{}
40 virtual void OnReceivedData(const char* data
,
42 int encoded_data_length
) OVERRIDE
;
43 virtual void OnCompletedRequest(
45 bool was_ignored_by_handler
,
46 bool stale_copy_in_cache
,
47 const std::string
& security_info
,
48 const base::TimeTicks
& completion_time
,
49 int64 total_transfer_size
) OVERRIDE
;
52 SecurityFilterPeer(webkit_glue::ResourceLoaderBridge
* resource_loader_bridge
,
53 webkit_glue::ResourceLoaderBridge::Peer
* peer
);
55 webkit_glue::ResourceLoaderBridge::Peer
* original_peer_
;
56 webkit_glue::ResourceLoaderBridge
* resource_loader_bridge_
;
59 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer
);
62 // The BufferedPeer reads all the data of the request into an internal buffer.
63 // Subclasses should implement DataReady() to process the data as necessary.
64 class BufferedPeer
: public SecurityFilterPeer
{
66 BufferedPeer(webkit_glue::ResourceLoaderBridge
* resource_loader_bridge
,
67 webkit_glue::ResourceLoaderBridge::Peer
* peer
,
68 const std::string
& mime_type
);
69 virtual ~BufferedPeer();
71 // ResourceLoaderBridge::Peer Implementation.
72 virtual void OnReceivedResponse(
73 const webkit_glue::ResourceResponseInfo
& info
) OVERRIDE
;
74 virtual void OnReceivedData(const char* data
,
76 int encoded_data_length
) OVERRIDE
;
77 virtual void OnCompletedRequest(
79 bool was_ignored_by_handler
,
80 bool stale_copy_in_cache
,
81 const std::string
& security_info
,
82 const base::TimeTicks
& completion_time
,
83 int64 total_transfer_size
) OVERRIDE
;
86 // Invoked when the entire request has been processed before the data is sent
87 // to the original peer, giving an opportunity to subclasses to process the
88 // data in data_. If this method returns true, the data is fed to the
89 // original peer, if it returns false, an error is sent instead.
90 virtual bool DataReady() = 0;
92 webkit_glue::ResourceResponseInfo response_info_
;
96 std::string mime_type_
;
98 DISALLOW_COPY_AND_ASSIGN(BufferedPeer
);
101 // The ReplaceContentPeer cancels the request and serves the provided data as
103 // TODO(jcampan): we do not as of now cancel the request, as we do not have
104 // access to the resource_loader_bridge in the SecurityFilterPeer factory
105 // method. For now the resource is still being fetched, but ignored, as once
106 // we have provided the replacement content, the associated pending request
107 // in ResourceDispatcher is removed and further OnReceived* notifications are
109 class ReplaceContentPeer
: public SecurityFilterPeer
{
111 ReplaceContentPeer(webkit_glue::ResourceLoaderBridge
* resource_loader_bridge
,
112 webkit_glue::ResourceLoaderBridge::Peer
* peer
,
113 const std::string
& mime_type
,
114 const std::string
& data
);
115 virtual ~ReplaceContentPeer();
117 // ResourceLoaderBridge::Peer Implementation.
118 virtual void OnReceivedResponse(
119 const webkit_glue::ResourceResponseInfo
& info
) OVERRIDE
;
120 virtual void OnReceivedData(const char* data
,
122 int encoded_data_length
) OVERRIDE
;
123 virtual void OnCompletedRequest(
125 bool was_ignored_by_handler
,
126 bool stale_copy_in_cache
,
127 const std::string
& security_info
,
128 const base::TimeTicks
& completion_time
,
129 int64 total_transfer_size
) OVERRIDE
;
132 webkit_glue::ResourceResponseInfo response_info_
;
133 std::string mime_type_
;
136 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer
);
139 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_