Added histograms for default search provider protection. Removed protection
[chromium-blink-merge.git] / chrome_frame / plugin_url_request.h
blob879620c043842ecd55dac1b348a8ae6a3b51acad
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_FRAME_PLUGIN_URL_REQUEST_H_
6 #define CHROME_FRAME_PLUGIN_URL_REQUEST_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "base/time.h"
13 #include "base/win/scoped_comptr.h"
14 #include "chrome_frame/chrome_frame_delegate.h"
15 #include "chrome_frame/urlmon_upload_data_stream.h"
16 #include "ipc/ipc_message.h"
17 #include "net/base/host_port_pair.h"
18 #include "net/base/upload_data.h"
19 #include "net/url_request/url_request_status.h"
20 #include "webkit/glue/resource_type.h"
22 class PluginUrlRequest;
23 class PluginUrlRequestDelegate;
24 class PluginUrlRequestManager;
26 class DECLSPEC_NOVTABLE PluginUrlRequestDelegate { // NOLINT
27 public:
28 virtual void OnResponseStarted(int request_id, const char* mime_type,
29 const char* headers, int size, base::Time last_modified,
30 const std::string& redirect_url, int redirect_status,
31 const net::HostPortPair& socket_address) = 0;
32 virtual void OnReadComplete(int request_id, const std::string& data) = 0;
33 virtual void OnResponseEnd(int request_id,
34 const net::URLRequestStatus& status) = 0;
35 virtual void AddPrivacyDataForUrl(const std::string& url,
36 const std::string& policy_ref,
37 int32 flags) {}
38 virtual void OnCookiesRetrieved(bool success, const GURL& url,
39 const std::string& cookie_string,
40 int cookie_id) = 0;
41 protected:
42 PluginUrlRequestDelegate() {}
43 ~PluginUrlRequestDelegate() {}
46 class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT
47 public:
48 PluginUrlRequestManager() : delegate_(NULL), enable_frame_busting_(true) {}
49 virtual ~PluginUrlRequestManager() {}
51 void set_frame_busting(bool enable) {
52 enable_frame_busting_ = enable;
55 virtual void set_delegate(PluginUrlRequestDelegate* delegate) {
56 delegate_ = delegate;
59 enum ThreadSafeFlags {
60 NOT_THREADSAFE = 0x00,
61 START_REQUEST_THREADSAFE = 0x01,
62 STOP_REQUEST_THREADSAFE = 0x02,
63 READ_REQUEST_THREADSAFE = 0x04,
64 DOWNLOAD_REQUEST_THREADSAFE = 0x08,
65 COOKIE_REQUEST_THREADSAFE = 0x10
67 virtual ThreadSafeFlags GetThreadSafeFlags() = 0;
69 // These are called directly from Automation Client when network related
70 // automation messages are received from Chrome.
71 // Strip 'tab' handle and forward to the virtual methods implemented by
72 // derived classes.
73 void StartUrlRequest(int request_id,
74 const AutomationURLRequest& request_info) {
75 StartRequest(request_id, request_info);
78 void ReadUrlRequest(int request_id, int bytes_to_read) {
79 ReadRequest(request_id, bytes_to_read);
82 void EndUrlRequest(int request_id, const net::URLRequestStatus& s) {
83 EndRequest(request_id);
86 void DownloadUrlRequestInHost(int request_id) {
87 DownloadRequestInHost(request_id);
90 void StopAllRequests() {
91 StopAll();
94 void GetCookiesFromHost(const GURL& url, int cookie_id) {
95 GetCookiesForUrl(url, cookie_id);
98 void SetCookiesInHost(const GURL& url, const std::string& cookie) {
99 SetCookiesForUrl(url, cookie);
102 protected:
103 PluginUrlRequestDelegate* delegate_;
104 bool enable_frame_busting_;
106 private:
107 virtual void StartRequest(
108 int request_id, const AutomationURLRequest& request_info) = 0;
109 virtual void ReadRequest(int request_id, int bytes_to_read) = 0;
110 virtual void EndRequest(int request_id) = 0;
111 virtual void DownloadRequestInHost(int request_id) = 0;
112 virtual void StopAll() = 0;
113 virtual void GetCookiesForUrl(const GURL& url, int cookie_id) = 0;
114 virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie) = 0;
117 // Used as base class. Holds Url request properties (url, method, referrer..)
118 class PluginUrlRequest {
119 public:
120 PluginUrlRequest();
121 ~PluginUrlRequest();
123 bool Initialize(PluginUrlRequestDelegate* delegate,
124 int remote_request_id, const std::string& url, const std::string& method,
125 const std::string& referrer, const std::string& extra_headers,
126 net::UploadData* upload_data, ResourceType::Type resource_type,
127 bool enable_frame_busting_, int load_flags);
129 // Accessors.
130 int id() const {
131 return remote_request_id_;
134 const std::string& url() const {
135 return url_;
138 const std::string& method() const {
139 return method_;
142 const std::string& referrer() const {
143 return referrer_;
146 const std::string& extra_headers() const {
147 return extra_headers_;
150 uint64 post_data_len() const {
151 return post_data_len_;
154 bool is_chunked_upload() const {
155 return is_chunked_upload_;
158 protected:
159 HRESULT get_upload_data(IStream** ret) {
160 DCHECK(ret);
161 if (!upload_data_.get())
162 return S_FALSE;
163 *ret = upload_data_.get();
164 (*ret)->AddRef();
165 return S_OK;
168 void set_url(const std::string& url) {
169 url_ = url;
172 void ClearPostData() {
173 upload_data_.Release();
174 post_data_len_ = 0;
177 void SendData();
178 bool enable_frame_busting_;
180 PluginUrlRequestDelegate* delegate_;
181 int remote_request_id_;
182 uint64 post_data_len_;
183 std::string url_;
184 std::string method_;
185 std::string referrer_;
186 std::string extra_headers_;
187 ResourceType::Type resource_type_;
188 int load_flags_;
189 base::win::ScopedComPtr<IStream> upload_data_;
190 bool is_chunked_upload_;
191 // Contains the ip address and port of the destination host.
192 net::HostPortPair socket_address_;
195 #endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_