blob: 0026ade80bfa3e323e096aa7d28e352945551ba2 [file] [log] [blame]
[email protected]f7817822009-09-24 05:11:581// Copyright (c) 2009 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.
4
5#ifndef CHROME_FRAME_PLUGIN_URL_REQUEST_H_
6#define CHROME_FRAME_PLUGIN_URL_REQUEST_H_
7
8#include <string>
9#include <vector>
10
[email protected]c5a83282009-10-29 03:57:2311#include "base/ref_counted.h"
12#include "base/scoped_comptr_win.h"
[email protected]f7817822009-09-24 05:11:5813#include "base/time.h"
[email protected]c5a83282009-10-29 03:57:2314#include "chrome_frame/chrome_frame_delegate.h"
15#include "chrome_frame/urlmon_upload_data_stream.h"
[email protected]f7817822009-09-24 05:11:5816#include "ipc/ipc_message.h"
17#include "net/base/upload_data.h"
18#include "net/url_request/url_request_status.h"
[email protected]60633402010-10-01 16:33:3719#include "webkit/glue/resource_type.h"
[email protected]f7817822009-09-24 05:11:5820
21class PluginUrlRequest;
[email protected]3eb07da2010-02-01 19:48:3622class PluginUrlRequestDelegate;
23class PluginUrlRequestManager;
[email protected]f7817822009-09-24 05:11:5824
[email protected]7ae80742010-03-25 22:02:2725class DECLSPEC_NOVTABLE PluginUrlRequestDelegate { // NOLINT
[email protected]f7817822009-09-24 05:11:5826 public:
[email protected]3eb07da2010-02-01 19:48:3627 virtual void OnResponseStarted(int request_id, const char* mime_type,
28 const char* headers, int size, base::Time last_modified,
[email protected]70daf0b2010-03-02 19:13:0029 const std::string& redirect_url, int redirect_status) = 0;
[email protected]0ce46402010-04-08 16:53:5730 virtual void OnReadComplete(int request_id, const std::string& data) = 0;
[email protected]80b5a8d2010-03-19 16:50:4331 virtual void OnResponseEnd(int request_id,
32 const URLRequestStatus& status) = 0;
33 virtual void AddPrivacyDataForUrl(const std::string& url,
34 const std::string& policy_ref,
35 int32 flags) {}
[email protected]27ad98352010-04-13 17:10:5136 virtual void OnCookiesRetrieved(bool success, const GURL& url,
37 const std::string& cookie_string,
38 int cookie_id) = 0;
[email protected]3eb07da2010-02-01 19:48:3639 protected:
40 PluginUrlRequestDelegate() {}
41 ~PluginUrlRequestDelegate() {}
42};
[email protected]f7817822009-09-24 05:11:5843
[email protected]7ae80742010-03-25 22:02:2744class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT
[email protected]3eb07da2010-02-01 19:48:3645 public:
46 PluginUrlRequestManager() : delegate_(NULL), enable_frame_busting_(true) {}
47 virtual ~PluginUrlRequestManager() {}
[email protected]f7817822009-09-24 05:11:5848
[email protected]3eb07da2010-02-01 19:48:3649 void set_frame_busting(bool enable) {
50 enable_frame_busting_ = enable;
[email protected]f7817822009-09-24 05:11:5851 }
[email protected]c5a83282009-10-29 03:57:2352
[email protected]3eb07da2010-02-01 19:48:3653 virtual void set_delegate(PluginUrlRequestDelegate* delegate) {
54 delegate_ = delegate;
55 }
56
[email protected]27ad98352010-04-13 17:10:5157 enum ThreadSafeFlags {
58 NOT_THREADSAFE = 0x00,
59 START_REQUEST_THREADSAFE = 0x01,
60 STOP_REQUEST_THREADSAFE = 0x02,
61 READ_REQUEST_THREADSAFE = 0x04,
62 DOWNLOAD_REQUEST_THREADSAFE = 0x08,
63 COOKIE_REQUEST_THREADSAFE = 0x10
64 };
65 virtual ThreadSafeFlags GetThreadSafeFlags() = 0;
[email protected]3eb07da2010-02-01 19:48:3666
67 // These are called directly from Automation Client when network related
68 // automation messages are received from Chrome.
69 // Strip 'tab' handle and forward to the virtual methods implemented by
70 // derived classes.
71 void StartUrlRequest(int tab, int request_id,
72 const IPC::AutomationURLRequest& request_info) {
[email protected]0ce46402010-04-08 16:53:5773 StartRequest(request_id, request_info);
[email protected]3eb07da2010-02-01 19:48:3674 }
75
76 void ReadUrlRequest(int tab, int request_id, int bytes_to_read) {
77 ReadRequest(request_id, bytes_to_read);
78 }
79
80 void EndUrlRequest(int tab, int request_id, const URLRequestStatus& s) {
81 EndRequest(request_id);
82 }
83
[email protected]7ae80742010-03-25 22:02:2784 void DownloadUrlRequestInHost(int tab, int request_id) {
85 DownloadRequestInHost(request_id);
86 }
87
[email protected]3eb07da2010-02-01 19:48:3688 void StopAllRequests() {
89 StopAll();
90 }
91
[email protected]27ad98352010-04-13 17:10:5192 void GetCookiesFromHost(int tab_handle, const GURL& url, int cookie_id) {
93 GetCookiesForUrl(url, cookie_id);
[email protected]c82d09a22010-03-26 23:28:4094 }
95
[email protected]27ad98352010-04-13 17:10:5196 void SetCookiesInHost(int tab_handle, const GURL& url,
[email protected]c82d09a22010-03-26 23:28:4097 const std::string& cookie) {
[email protected]27ad98352010-04-13 17:10:5198 SetCookiesForUrl(url, cookie);
[email protected]c82d09a22010-03-26 23:28:4099 }
100
[email protected]3eb07da2010-02-01 19:48:36101 protected:
102 PluginUrlRequestDelegate* delegate_;
103 bool enable_frame_busting_;
104
105 private:
106 virtual void StartRequest(int request_id,
[email protected]0ce46402010-04-08 16:53:57107 const IPC::AutomationURLRequest& request_info) = 0;
[email protected]3eb07da2010-02-01 19:48:36108 virtual void ReadRequest(int request_id, int bytes_to_read) = 0;
109 virtual void EndRequest(int request_id) = 0;
[email protected]7ae80742010-03-25 22:02:27110 virtual void DownloadRequestInHost(int request_id) = 0;
[email protected]3eb07da2010-02-01 19:48:36111 virtual void StopAll() = 0;
[email protected]27ad98352010-04-13 17:10:51112 virtual void GetCookiesForUrl(const GURL& url, int cookie_id) = 0;
113 virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie) = 0;
[email protected]3eb07da2010-02-01 19:48:36114};
115
116// Used as base class. Holds Url request properties (url, method, referrer..)
117class PluginUrlRequest {
118 public:
119 PluginUrlRequest();
120 ~PluginUrlRequest();
121
122 bool Initialize(PluginUrlRequestDelegate* delegate,
123 int remote_request_id, const std::string& url, const std::string& method,
124 const std::string& referrer, const std::string& extra_headers,
[email protected]60633402010-10-01 16:33:37125 net::UploadData* upload_data, ResourceType::Type resource_type,
126 bool enable_frame_busting_);
[email protected]3eb07da2010-02-01 19:48:36127
128 // Accessors.
[email protected]f7817822009-09-24 05:11:58129 int id() const {
130 return remote_request_id_;
131 }
[email protected]c5a83282009-10-29 03:57:23132
[email protected]f7817822009-09-24 05:11:58133 const std::string& url() const {
134 return url_;
135 }
[email protected]c5a83282009-10-29 03:57:23136
[email protected]f7817822009-09-24 05:11:58137 const std::string& method() const {
138 return method_;
139 }
[email protected]885362ca2009-10-27 21:50:07140
[email protected]f7817822009-09-24 05:11:58141 const std::string& referrer() const {
142 return referrer_;
143 }
[email protected]c5a83282009-10-29 03:57:23144
[email protected]f7817822009-09-24 05:11:58145 const std::string& extra_headers() const {
146 return extra_headers_;
147 }
[email protected]c5a83282009-10-29 03:57:23148
149 uint64 post_data_len() const {
150 return post_data_len_;
151 }
152
[email protected]3eb07da2010-02-01 19:48:36153 protected:
[email protected]c5a83282009-10-29 03:57:23154 HRESULT get_upload_data(IStream** ret) {
155 DCHECK(ret);
156 if (!upload_data_.get())
157 return S_FALSE;
158 *ret = upload_data_.get();
159 (*ret)->AddRef();
160 return S_OK;
161 }
162
[email protected]3eb07da2010-02-01 19:48:36163 void set_url(const std::string& url) {
164 url_ = url;
165 }
166
[email protected]c5a83282009-10-29 03:57:23167 void ClearPostData() {
168 upload_data_.Release();
169 post_data_len_ = 0;
[email protected]f7817822009-09-24 05:11:58170 }
171
[email protected]f7817822009-09-24 05:11:58172 void SendData();
[email protected]3eb07da2010-02-01 19:48:36173 bool enable_frame_busting_;
[email protected]f7817822009-09-24 05:11:58174
[email protected]3eb07da2010-02-01 19:48:36175 PluginUrlRequestDelegate* delegate_;
[email protected]f7817822009-09-24 05:11:58176 int remote_request_id_;
[email protected]c5a83282009-10-29 03:57:23177 uint64 post_data_len_;
[email protected]f7817822009-09-24 05:11:58178 std::string url_;
179 std::string method_;
180 std::string referrer_;
181 std::string extra_headers_;
[email protected]60633402010-10-01 16:33:37182 ResourceType::Type resource_type_;
[email protected]c5a83282009-10-29 03:57:23183 ScopedComPtr<IStream> upload_data_;
[email protected]f7817822009-09-24 05:11:58184};
185
[email protected]f7817822009-09-24 05:11:58186#endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_