1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_FRAME_PLUGIN_URL_REQUEST_H_
#define CHROME_FRAME_PLUGIN_URL_REQUEST_H_
#include <string>
#include <vector>
#include "base/ref_counted.h"
#include "base/scoped_comptr_win.h"
#include "base/time.h"
#include "chrome_frame/chrome_frame_delegate.h"
#include "chrome_frame/urlmon_upload_data_stream.h"
#include "ipc/ipc_message.h"
#include "net/base/upload_data.h"
#include "net/url_request/url_request_status.h"
class PluginUrlRequest;
class PluginUrlRequestDelegate;
class PluginUrlRequestManager;
class DECLSPEC_NOVTABLE PluginUrlRequestDelegate {
public:
// Persistent cookies are read from the host browser and passed off to Chrome
// These cookies are sent when we receive a response for every URL request
// initiated by Chrome. Ideally we should only send cookies for the top level
// URL and any subframes. However we don't receive information from Chrome
// about the context for a URL, i.e. whether it is a subframe, etc.
// Additionally cookies for a URL should be sent once for the page. This
// is not done now as it is difficult to track URLs, specifically if they
// are redirected, etc.
virtual void OnResponseStarted(int request_id, const char* mime_type,
const char* headers, int size, base::Time last_modified,
const std::string& peristent_cookies, const std::string& redirect_url,
int redirect_status) = 0;
virtual void OnReadComplete(int request_id, const void* buffer, int len) = 0;
virtual void OnResponseEnd(int request_id, const URLRequestStatus& status) = 0;
protected:
PluginUrlRequestDelegate() {}
~PluginUrlRequestDelegate() {}
};
class DECLSPEC_NOVTABLE PluginUrlRequestManager {
public:
PluginUrlRequestManager() : delegate_(NULL), enable_frame_busting_(true) {}
virtual ~PluginUrlRequestManager() {}
void set_frame_busting(bool enable) {
enable_frame_busting_ = enable;
}
virtual void set_delegate(PluginUrlRequestDelegate* delegate) {
delegate_ = delegate;
}
virtual bool IsThreadSafe() = 0;
// These are called directly from Automation Client when network related
// automation messages are received from Chrome.
// Strip 'tab' handle and forward to the virtual methods implemented by
// derived classes.
void StartUrlRequest(int tab, int request_id,
const IPC::AutomationURLRequest& request_info) {
StartRequest(request_id, request_info);
}
void ReadUrlRequest(int tab, int request_id, int bytes_to_read) {
ReadRequest(request_id, bytes_to_read);
}
void EndUrlRequest(int tab, int request_id, const URLRequestStatus& s) {
EndRequest(request_id);
}
void StopAllRequests() {
StopAll();
}
protected:
PluginUrlRequestDelegate* delegate_;
bool enable_frame_busting_;
private:
virtual void StartRequest(int request_id,
const IPC::AutomationURLRequest& request_info) = 0;
virtual void ReadRequest(int request_id, int bytes_to_read) = 0;
virtual void EndRequest(int request_id) = 0;
virtual void StopAll() = 0;
};
// Used as base class. Holds Url request properties (url, method, referrer..)
class PluginUrlRequest {
public:
PluginUrlRequest();
~PluginUrlRequest();
bool Initialize(PluginUrlRequestDelegate* delegate,
int remote_request_id, const std::string& url, const std::string& method,
const std::string& referrer, const std::string& extra_headers,
net::UploadData* upload_data, bool enable_frame_busting_);
// Accessors.
int id() const {
return remote_request_id_;
}
const std::string& url() const {
return url_;
}
const std::string& method() const {
return method_;
}
const std::string& referrer() const {
return referrer_;
}
const std::string& extra_headers() const {
return extra_headers_;
}
uint64 post_data_len() const {
return post_data_len_;
}
protected:
HRESULT get_upload_data(IStream** ret) {
DCHECK(ret);
if (!upload_data_.get())
return S_FALSE;
*ret = upload_data_.get();
(*ret)->AddRef();
return S_OK;
}
void set_url(const std::string& url) {
url_ = url;
}
void ClearPostData() {
upload_data_.Release();
post_data_len_ = 0;
}
void SendData();
bool enable_frame_busting_;
PluginUrlRequestDelegate* delegate_;
int remote_request_id_;
uint64 post_data_len_;
std::string url_;
std::string method_;
std::string referrer_;
std::string extra_headers_;
ScopedComPtr<IStream> upload_data_;
};
#endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_
|