blob: bd14655181eb2a217ddbf38d958c6e7185a14b93 [file] [log] [blame]
[email protected]27a112c2011-01-06 04:19:301// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]f7817822009-09-24 05:11:582// 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]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
[email protected]f7817822009-09-24 05:11:5812#include "base/time.h"
[email protected]8ee65ba2011-04-12 20:53:2313#include "base/win/scoped_comptr.h"
[email protected]c5a83282009-10-29 03:57:2314#include "chrome_frame/chrome_frame_delegate.h"
[email protected]4736610c2011-03-04 06:43:3515#include "chrome_frame/urlmon_upload_data_stream.h"
[email protected]f7817822009-09-24 05:11:5816#include "ipc/ipc_message.h"
[email protected]0d282c2e2011-02-24 20:42:5117#include "net/base/host_port_pair.h"
[email protected]f7817822009-09-24 05:11:5818#include "net/base/upload_data.h"
19#include "net/url_request/url_request_status.h"
[email protected]60633402010-10-01 16:33:3720#include "webkit/glue/resource_type.h"
[email protected]f7817822009-09-24 05:11:5821
22class PluginUrlRequest;
[email protected]3eb07da2010-02-01 19:48:3623class PluginUrlRequestDelegate;
24class PluginUrlRequestManager;
[email protected]f7817822009-09-24 05:11:5825
[email protected]7ae80742010-03-25 22:02:2726class DECLSPEC_NOVTABLE PluginUrlRequestDelegate { // NOLINT
[email protected]f7817822009-09-24 05:11:5827 public:
[email protected]7335ab02012-08-30 22:30:4228 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;
[email protected]0ce46402010-04-08 16:53:5733 virtual void OnReadComplete(int request_id, const std::string& data) = 0;
[email protected]80b5a8d2010-03-19 16:50:4334 virtual void OnResponseEnd(int request_id,
[email protected]27a112c2011-01-06 04:19:3035 const net::URLRequestStatus& status) = 0;
[email protected]80b5a8d2010-03-19 16:50:4336 virtual void AddPrivacyDataForUrl(const std::string& url,
37 const std::string& policy_ref,
38 int32 flags) {}
[email protected]27ad98352010-04-13 17:10:5139 virtual void OnCookiesRetrieved(bool success, const GURL& url,
40 const std::string& cookie_string,
41 int cookie_id) = 0;
[email protected]3eb07da2010-02-01 19:48:3642 protected:
43 PluginUrlRequestDelegate() {}
44 ~PluginUrlRequestDelegate() {}
45};
[email protected]f7817822009-09-24 05:11:5846
[email protected]7ae80742010-03-25 22:02:2747class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT
[email protected]3eb07da2010-02-01 19:48:3648 public:
49 PluginUrlRequestManager() : delegate_(NULL), enable_frame_busting_(true) {}
50 virtual ~PluginUrlRequestManager() {}
[email protected]f7817822009-09-24 05:11:5851
[email protected]3eb07da2010-02-01 19:48:3652 void set_frame_busting(bool enable) {
53 enable_frame_busting_ = enable;
[email protected]f7817822009-09-24 05:11:5854 }
[email protected]c5a83282009-10-29 03:57:2355
[email protected]3eb07da2010-02-01 19:48:3656 virtual void set_delegate(PluginUrlRequestDelegate* delegate) {
57 delegate_ = delegate;
58 }
59
[email protected]27ad98352010-04-13 17:10:5160 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
67 };
68 virtual ThreadSafeFlags GetThreadSafeFlags() = 0;
[email protected]3eb07da2010-02-01 19:48:3669
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.
[email protected]f5494d42010-12-23 22:15:3474 void StartUrlRequest(int request_id,
75 const AutomationURLRequest& request_info) {
[email protected]0ce46402010-04-08 16:53:5776 StartRequest(request_id, request_info);
[email protected]3eb07da2010-02-01 19:48:3677 }
78
[email protected]f5494d42010-12-23 22:15:3479 void ReadUrlRequest(int request_id, int bytes_to_read) {
[email protected]3eb07da2010-02-01 19:48:3680 ReadRequest(request_id, bytes_to_read);
81 }
82
[email protected]27a112c2011-01-06 04:19:3083 void EndUrlRequest(int request_id, const net::URLRequestStatus& s) {
[email protected]3eb07da2010-02-01 19:48:3684 EndRequest(request_id);
85 }
86
[email protected]f5494d42010-12-23 22:15:3487 void DownloadUrlRequestInHost(int request_id) {
[email protected]7ae80742010-03-25 22:02:2788 DownloadRequestInHost(request_id);
89 }
90
[email protected]3eb07da2010-02-01 19:48:3691 void StopAllRequests() {
92 StopAll();
93 }
94
[email protected]f5494d42010-12-23 22:15:3495 void GetCookiesFromHost(const GURL& url, int cookie_id) {
[email protected]27ad98352010-04-13 17:10:5196 GetCookiesForUrl(url, cookie_id);
[email protected]c82d09a22010-03-26 23:28:4097 }
98
[email protected]f5494d42010-12-23 22:15:3499 void SetCookiesInHost(const GURL& url, const std::string& cookie) {
[email protected]27ad98352010-04-13 17:10:51100 SetCookiesForUrl(url, cookie);
[email protected]c82d09a22010-03-26 23:28:40101 }
102
[email protected]3eb07da2010-02-01 19:48:36103 protected:
104 PluginUrlRequestDelegate* delegate_;
105 bool enable_frame_busting_;
106
107 private:
[email protected]f5494d42010-12-23 22:15:34108 virtual void StartRequest(
109 int request_id, const AutomationURLRequest& request_info) = 0;
[email protected]3eb07da2010-02-01 19:48:36110 virtual void ReadRequest(int request_id, int bytes_to_read) = 0;
111 virtual void EndRequest(int request_id) = 0;
[email protected]7ae80742010-03-25 22:02:27112 virtual void DownloadRequestInHost(int request_id) = 0;
[email protected]3eb07da2010-02-01 19:48:36113 virtual void StopAll() = 0;
[email protected]27ad98352010-04-13 17:10:51114 virtual void GetCookiesForUrl(const GURL& url, int cookie_id) = 0;
115 virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie) = 0;
[email protected]3eb07da2010-02-01 19:48:36116};
117
118// Used as base class. Holds Url request properties (url, method, referrer..)
119class PluginUrlRequest {
120 public:
121 PluginUrlRequest();
122 ~PluginUrlRequest();
123
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,
[email protected]60633402010-10-01 16:33:37127 net::UploadData* upload_data, ResourceType::Type resource_type,
[email protected]d9ffd552010-10-21 18:45:33128 bool enable_frame_busting_, int load_flags);
[email protected]3eb07da2010-02-01 19:48:36129
130 // Accessors.
[email protected]f7817822009-09-24 05:11:58131 int id() const {
132 return remote_request_id_;
133 }
[email protected]c5a83282009-10-29 03:57:23134
[email protected]f7817822009-09-24 05:11:58135 const std::string& url() const {
136 return url_;
137 }
[email protected]c5a83282009-10-29 03:57:23138
[email protected]f7817822009-09-24 05:11:58139 const std::string& method() const {
140 return method_;
141 }
[email protected]885362ca2009-10-27 21:50:07142
[email protected]f7817822009-09-24 05:11:58143 const std::string& referrer() const {
144 return referrer_;
145 }
[email protected]c5a83282009-10-29 03:57:23146
[email protected]f7817822009-09-24 05:11:58147 const std::string& extra_headers() const {
148 return extra_headers_;
149 }
[email protected]c5a83282009-10-29 03:57:23150
151 uint64 post_data_len() const {
152 return post_data_len_;
153 }
154
[email protected]8f170162011-01-26 23:42:42155 bool is_chunked_upload() const {
156 return is_chunked_upload_;
157 }
158
[email protected]3eb07da2010-02-01 19:48:36159 protected:
[email protected]4736610c2011-03-04 06:43:35160 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;
167 }
168
[email protected]3eb07da2010-02-01 19:48:36169 void set_url(const std::string& url) {
170 url_ = url;
171 }
172
[email protected]f7817822009-09-24 05:11:58173 void SendData();
[email protected]3eb07da2010-02-01 19:48:36174 bool enable_frame_busting_;
[email protected]f7817822009-09-24 05:11:58175
[email protected]3eb07da2010-02-01 19:48:36176 PluginUrlRequestDelegate* delegate_;
[email protected]f7817822009-09-24 05:11:58177 int remote_request_id_;
[email protected]c5a83282009-10-29 03:57:23178 uint64 post_data_len_;
[email protected]f7817822009-09-24 05:11:58179 std::string url_;
180 std::string method_;
181 std::string referrer_;
182 std::string extra_headers_;
[email protected]60633402010-10-01 16:33:37183 ResourceType::Type resource_type_;
[email protected]d9ffd552010-10-21 18:45:33184 int load_flags_;
[email protected]8ee65ba2011-04-12 20:53:23185 base::win::ScopedComPtr<IStream> upload_data_;
[email protected]8f170162011-01-26 23:42:42186 bool is_chunked_upload_;
[email protected]0d282c2e2011-02-24 20:42:51187 // Contains the ip address and port of the destination host.
188 net::HostPortPair socket_address_;
[email protected]f7817822009-09-24 05:11:58189};
190
[email protected]f7817822009-09-24 05:11:58191#endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_