Use Histogram algorithm to calculate DNS timeout.
[chromium-blink-merge.git] / chrome_frame / plugin_url_request.h
blob718741b7f1503f7e2d25118706982b1598b93074
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/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(
29 int request_id, const char* mime_type, const char* headers, int size,
30 base::Time last_modified, const std::string& redirect_url,
31 int redirect_status, const net::HostPortPair& socket_address,
32 uint64 upload_size) = 0;
33 virtual void OnReadComplete(int request_id, const std::string& data) = 0;
34 virtual void OnResponseEnd(int request_id,
35 const net::URLRequestStatus& status) = 0;
36 virtual void AddPrivacyDataForUrl(const std::string& url,
37 const std::string& policy_ref,
38 int32 flags) {}
39 virtual void OnCookiesRetrieved(bool success, const GURL& url,
40 const std::string& cookie_string,
41 int cookie_id) = 0;
42 protected:
43 PluginUrlRequestDelegate() {}
44 ~PluginUrlRequestDelegate() {}
47 class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT
48 public:
49 PluginUrlRequestManager() : delegate_(NULL), enable_frame_busting_(true) {}
50 virtual ~PluginUrlRequestManager() {}
52 void set_frame_busting(bool enable) {
53 enable_frame_busting_ = enable;
56 virtual void set_delegate(PluginUrlRequestDelegate* delegate) {
57 delegate_ = delegate;
60 enum ThreadSafeFlags {
61 NOT_THREADSAFE = 0x00,
62 START_REQUEST_THREADSAFE = 0x01,
63 STOP_REQUEST_THREADSAFE = 0x02,
64 READ_REQUEST_THREADSAFE = 0x04,
65 DOWNLOAD_REQUEST_THREADSAFE = 0x08,
66 COOKIE_REQUEST_THREADSAFE = 0x10
68 virtual ThreadSafeFlags GetThreadSafeFlags() = 0;
70 // These are called directly from Automation Client when network related
71 // automation messages are received from Chrome.
72 // Strip 'tab' handle and forward to the virtual methods implemented by
73 // derived classes.
74 void StartUrlRequest(int request_id,
75 const AutomationURLRequest& request_info) {
76 StartRequest(request_id, request_info);
79 void ReadUrlRequest(int request_id, int bytes_to_read) {
80 ReadRequest(request_id, bytes_to_read);
83 void EndUrlRequest(int request_id, const net::URLRequestStatus& s) {
84 EndRequest(request_id);
87 void DownloadUrlRequestInHost(int request_id) {
88 DownloadRequestInHost(request_id);
91 void StopAllRequests() {
92 StopAll();
95 void GetCookiesFromHost(const GURL& url, int cookie_id) {
96 GetCookiesForUrl(url, cookie_id);
99 void SetCookiesInHost(const GURL& url, const std::string& cookie) {
100 SetCookiesForUrl(url, cookie);
103 protected:
104 PluginUrlRequestDelegate* delegate_;
105 bool enable_frame_busting_;
107 private:
108 virtual void StartRequest(
109 int request_id, const AutomationURLRequest& request_info) = 0;
110 virtual void ReadRequest(int request_id, int bytes_to_read) = 0;
111 virtual void EndRequest(int request_id) = 0;
112 virtual void DownloadRequestInHost(int request_id) = 0;
113 virtual void StopAll() = 0;
114 virtual void GetCookiesForUrl(const GURL& url, int cookie_id) = 0;
115 virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie) = 0;
118 // Used as base class. Holds Url request properties (url, method, referrer..)
119 class PluginUrlRequest {
120 public:
121 PluginUrlRequest();
122 ~PluginUrlRequest();
124 bool Initialize(PluginUrlRequestDelegate* delegate,
125 int remote_request_id, const std::string& url, const std::string& method,
126 const std::string& referrer, const std::string& extra_headers,
127 net::UploadData* upload_data, ResourceType::Type resource_type,
128 bool enable_frame_busting_, int load_flags);
130 // Accessors.
131 int id() const {
132 return remote_request_id_;
135 const std::string& url() const {
136 return url_;
139 const std::string& method() const {
140 return method_;
143 const std::string& referrer() const {
144 return referrer_;
147 const std::string& extra_headers() const {
148 return extra_headers_;
151 uint64 post_data_len() const {
152 return post_data_len_;
155 bool is_chunked_upload() const {
156 return is_chunked_upload_;
159 protected:
160 HRESULT get_upload_data(IStream** ret) {
161 DCHECK(ret);
162 if (!upload_data_.get())
163 return S_FALSE;
164 *ret = upload_data_.get();
165 (*ret)->AddRef();
166 return S_OK;
169 void set_url(const std::string& url) {
170 url_ = url;
173 void SendData();
174 bool enable_frame_busting_;
176 PluginUrlRequestDelegate* delegate_;
177 int remote_request_id_;
178 uint64 post_data_len_;
179 std::string url_;
180 std::string method_;
181 std::string referrer_;
182 std::string extra_headers_;
183 ResourceType::Type resource_type_;
184 int load_flags_;
185 base::win::ScopedComPtr<IStream> upload_data_;
186 bool is_chunked_upload_;
187 // Contains the ip address and port of the destination host.
188 net::HostPortPair socket_address_;
191 #endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_