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