cros: Show terminated/disabled app in launcher bar.
[chromium-blink-merge.git] / chrome / renderer / security_filter_peer.h
blobb4dd6371f74aa56339c339b582a1a3ea393ffc30
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/glue/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 {
18 public:
19 virtual ~SecurityFilterPeer();
21 static SecurityFilterPeer* CreateSecurityFilterPeerForDeniedRequest(
22 ResourceType::Type resource_type,
23 webkit_glue::ResourceLoaderBridge::Peer* peer,
24 int os_error);
26 static SecurityFilterPeer* CreateSecurityFilterPeerForFrame(
27 webkit_glue::ResourceLoaderBridge::Peer* peer,
28 int os_error);
30 // ResourceLoaderBridge::Peer methods.
31 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE;
32 virtual bool OnReceivedRedirect(
33 const GURL& new_url,
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) OVERRIDE {}
40 virtual void OnReceivedData(const char* data,
41 int data_length,
42 int encoded_data_length) OVERRIDE;
43 virtual void OnCompletedRequest(
44 int error_code,
45 bool was_ignored_by_handler,
46 const std::string& security_info,
47 const base::TimeTicks& completion_time) OVERRIDE;
49 protected:
50 SecurityFilterPeer(webkit_glue::ResourceLoaderBridge* resource_loader_bridge,
51 webkit_glue::ResourceLoaderBridge::Peer* peer);
53 webkit_glue::ResourceLoaderBridge::Peer* original_peer_;
54 webkit_glue::ResourceLoaderBridge* resource_loader_bridge_;
56 private:
57 DISALLOW_COPY_AND_ASSIGN(SecurityFilterPeer);
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.
62 class BufferedPeer : public SecurityFilterPeer {
63 public:
64 BufferedPeer(webkit_glue::ResourceLoaderBridge* resource_loader_bridge,
65 webkit_glue::ResourceLoaderBridge::Peer* peer,
66 const std::string& mime_type);
67 virtual ~BufferedPeer();
69 // ResourceLoaderBridge::Peer Implementation.
70 virtual void OnReceivedResponse(
71 const webkit_glue::ResourceResponseInfo& info) OVERRIDE;
72 virtual void OnReceivedData(const char* data,
73 int data_length,
74 int encoded_data_length) OVERRIDE;
75 virtual void OnCompletedRequest(
76 int error_code,
77 bool was_ignored_by_handler,
78 const std::string& security_info,
79 const base::TimeTicks& completion_time) OVERRIDE;
81 protected:
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
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.
86 virtual bool DataReady() = 0;
88 webkit_glue::ResourceResponseInfo response_info_;
89 std::string data_;
91 private:
92 std::string mime_type_;
94 DISALLOW_COPY_AND_ASSIGN(BufferedPeer);
97 // The ReplaceContentPeer cancels the request and serves the provided data as
98 // content instead.
99 // TODO(jcampan): we do not as of now cancel the request, as we do not have
100 // access to the resource_loader_bridge in the SecurityFilterPeer factory
101 // method. For now the resource is still being fetched, but ignored, as once
102 // we have provided the replacement content, the associated pending request
103 // in ResourceDispatcher is removed and further OnReceived* notifications are
104 // ignored.
105 class ReplaceContentPeer : public SecurityFilterPeer {
106 public:
107 ReplaceContentPeer(webkit_glue::ResourceLoaderBridge* resource_loader_bridge,
108 webkit_glue::ResourceLoaderBridge::Peer* peer,
109 const std::string& mime_type,
110 const std::string& data);
111 virtual ~ReplaceContentPeer();
113 // ResourceLoaderBridge::Peer Implementation.
114 virtual void OnReceivedResponse(
115 const webkit_glue::ResourceResponseInfo& info) OVERRIDE;
116 virtual void OnReceivedData(const char* data,
117 int data_length,
118 int encoded_data_length) OVERRIDE;
119 virtual void OnCompletedRequest(
120 int error_code,
121 bool was_ignored_by_handler,
122 const std::string& security_info,
123 const base::TimeTicks& completion_time) OVERRIDE;
125 private:
126 webkit_glue::ResourceResponseInfo response_info_;
127 std::string mime_type_;
128 std::string data_;
130 DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer);
133 #endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_