Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: chrome_frame/plugin_url_request.h

Issue 545093: Refactor host network (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/npapi_url_request.cc ('k') | chrome_frame/plugin_url_request.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_FRAME_PLUGIN_URL_REQUEST_H_ 5 #ifndef CHROME_FRAME_PLUGIN_URL_REQUEST_H_
6 #define CHROME_FRAME_PLUGIN_URL_REQUEST_H_ 6 #define CHROME_FRAME_PLUGIN_URL_REQUEST_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "base/scoped_comptr_win.h" 12 #include "base/scoped_comptr_win.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome_frame/chrome_frame_delegate.h" 14 #include "chrome_frame/chrome_frame_delegate.h"
15 #include "chrome_frame/urlmon_upload_data_stream.h" 15 #include "chrome_frame/urlmon_upload_data_stream.h"
16 #include "ipc/ipc_message.h" 16 #include "ipc/ipc_message.h"
17 #include "net/base/upload_data.h" 17 #include "net/base/upload_data.h"
18 #include "net/url_request/url_request_status.h" 18 #include "net/url_request/url_request_status.h"
19 19
20 class PluginUrlRequest; 20 class PluginUrlRequest;
21 class PluginUrlRequestDelegate;
22 class PluginUrlRequestManager;
21 23
22 // Interface for a class that keeps a collection of outstanding 24 class DECLSPEC_NOVTABLE PluginUrlRequestDelegate {
23 // reqeusts and offers an outgoing channel.
24 class PluginRequestHandler
25 : public IPC::Message::Sender,
26 public base::RefCountedThreadSafe<PluginRequestHandler> {
27 public: 25 public:
28 virtual bool AddRequest(PluginUrlRequest* request) = 0;
29 virtual void RemoveRequest(PluginUrlRequest* request) = 0;
30 };
31
32 // A reference counting solution whose method's are compatible with
33 // scoped_refptr and COM's IUnknown. Don't cast this object directly over to
34 // IUnknown though since IUnknown's first method is QueryInterface.
35 class UrlRequestReference {
36 public:
37 virtual unsigned long API_CALL AddRef() = 0; // NOLINT
38 virtual unsigned long API_CALL Release() = 0; // NOLINT
39 };
40
41 class PluginUrlRequest : public UrlRequestReference {
42 public:
43 PluginUrlRequest();
44 ~PluginUrlRequest();
45
46 bool Initialize(PluginRequestHandler* handler, int tab,
47 int remote_request_id, const std::string& url,
48 const std::string& method, const std::string& referrer,
49 const std::string& extra_headers,
50 net::UploadData* upload_data,
51 bool intercept_frame_options);
52
53 // Called in response to automation IPCs
54 virtual bool Start() = 0;
55 virtual void Stop() = 0;
56 virtual bool Read(int bytes_to_read) = 0;
57
58 // Persistent cookies are read from the host browser and passed off to Chrome 26 // Persistent cookies are read from the host browser and passed off to Chrome
59 // These cookies are sent when we receive a response for every URL request 27 // These cookies are sent when we receive a response for every URL request
60 // initiated by Chrome. Ideally we should only send cookies for the top level 28 // initiated by Chrome. Ideally we should only send cookies for the top level
61 // URL and any subframes. However we don't receive information from Chrome 29 // URL and any subframes. However we don't receive information from Chrome
62 // about the context for a URL, i.e. whether it is a subframe, etc. 30 // about the context for a URL, i.e. whether it is a subframe, etc.
63 // Additionally cookies for a URL should be sent once for the page. This 31 // Additionally cookies for a URL should be sent once for the page. This
64 // is not done now as it is difficult to track URLs, specifically if they 32 // is not done now as it is difficult to track URLs, specifically if they
65 // are redirected, etc. 33 // are redirected, etc.
66 void OnResponseStarted(const char* mime_type, const char* headers, int size, 34 virtual void OnResponseStarted(int request_id, const char* mime_type,
67 base::Time last_modified, const std::string& peristent_cookies, 35 const char* headers, int size, base::Time last_modified,
68 const std::string& redirect_url, int redirect_status); 36 const std::string& peristent_cookies, const std::string& redirect_url,
37 int redirect_status) = 0;
38 virtual void OnReadComplete(int request_id, const void* buffer, int len) = 0;
39 virtual void OnResponseEnd(int request_id, const URLRequestStatus& status) = 0 ;
40 protected:
41 PluginUrlRequestDelegate() {}
42 ~PluginUrlRequestDelegate() {}
43 };
69 44
70 void OnReadComplete(const void* buffer, int len); 45 class DECLSPEC_NOVTABLE PluginUrlRequestManager {
71 void OnResponseEnd(const URLRequestStatus& status); 46 public:
47 PluginUrlRequestManager() : delegate_(NULL), enable_frame_busting_(true) {}
48 virtual ~PluginUrlRequestManager() {}
72 49
73 PluginRequestHandler* request_handler() const { 50 void set_frame_busting(bool enable) {
74 return request_handler_; 51 enable_frame_busting_ = enable;
75 } 52 }
76 53
54 virtual void set_delegate(PluginUrlRequestDelegate* delegate) {
55 delegate_ = delegate;
56 }
57
58 virtual bool IsThreadSafe() = 0;
59
60 // These are called directly from Automation Client when network related
61 // automation messages are received from Chrome.
62 // Strip 'tab' handle and forward to the virtual methods implemented by
63 // derived classes.
64 void StartUrlRequest(int tab, int request_id,
65 const IPC::AutomationURLRequest& request_info) {
66 StartRequest(request_id, request_info);
67 }
68
69 void ReadUrlRequest(int tab, int request_id, int bytes_to_read) {
70 ReadRequest(request_id, bytes_to_read);
71 }
72
73 void EndUrlRequest(int tab, int request_id, const URLRequestStatus& s) {
74 EndRequest(request_id);
75 }
76
77 void StopAllRequests() {
78 StopAll();
79 }
80
81 protected:
82 PluginUrlRequestDelegate* delegate_;
83 bool enable_frame_busting_;
84
85 private:
86 virtual void StartRequest(int request_id,
87 const IPC::AutomationURLRequest& request_info) = 0;
88 virtual void ReadRequest(int request_id, int bytes_to_read) = 0;
89 virtual void EndRequest(int request_id) = 0;
90 virtual void StopAll() = 0;
91 };
92
93 // Used as base class. Holds Url request properties (url, method, referrer..)
94 class PluginUrlRequest {
95 public:
96 PluginUrlRequest();
97 ~PluginUrlRequest();
98
99 bool Initialize(PluginUrlRequestDelegate* delegate,
100 int remote_request_id, const std::string& url, const std::string& method,
101 const std::string& referrer, const std::string& extra_headers,
102 net::UploadData* upload_data, bool enable_frame_busting_);
103
104 // Accessors.
77 int id() const { 105 int id() const {
78 return remote_request_id_; 106 return remote_request_id_;
79 } 107 }
80 108
81 const std::string& url() const { 109 const std::string& url() const {
82 return url_; 110 return url_;
83 } 111 }
84 112
85 const std::string& method() const { 113 const std::string& method() const {
86 return method_; 114 return method_;
87 } 115 }
88 116
89 void set_method(const std::string& new_method) {
90 method_ = new_method;
91 }
92
93 const std::string& referrer() const { 117 const std::string& referrer() const {
94 return referrer_; 118 return referrer_;
95 } 119 }
96 120
97 const std::string& extra_headers() const { 121 const std::string& extra_headers() const {
98 return extra_headers_; 122 return extra_headers_;
99 } 123 }
100 124
101 uint64 post_data_len() const { 125 uint64 post_data_len() const {
102 return post_data_len_; 126 return post_data_len_;
103 } 127 }
104 128
129 protected:
105 HRESULT get_upload_data(IStream** ret) { 130 HRESULT get_upload_data(IStream** ret) {
106 DCHECK(ret); 131 DCHECK(ret);
107 if (!upload_data_.get()) 132 if (!upload_data_.get())
108 return S_FALSE; 133 return S_FALSE;
109 *ret = upload_data_.get(); 134 *ret = upload_data_.get();
110 (*ret)->AddRef(); 135 (*ret)->AddRef();
111 return S_OK; 136 return S_OK;
112 } 137 }
113 138
139 void set_url(const std::string& url) {
140 url_ = url;
141 }
142
114 void ClearPostData() { 143 void ClearPostData() {
115 upload_data_.Release(); 144 upload_data_.Release();
116 post_data_len_ = 0; 145 post_data_len_ = 0;
117 } 146 }
118 147
119 bool is_done() const { 148 void SendData();
120 return (URLRequestStatus::IO_PENDING != status_); 149 bool enable_frame_busting_;
121 }
122 150
123 void set_url(const std::string& url) { 151 PluginUrlRequestDelegate* delegate_;
124 url_ = url;
125 }
126
127 protected:
128 void SendData();
129 bool frame_busting_enabled_;
130
131 private:
132 scoped_refptr<PluginRequestHandler> request_handler_;
133 int tab_;
134 int remote_request_id_; 152 int remote_request_id_;
135 uint64 post_data_len_; 153 uint64 post_data_len_;
136 std::string url_; 154 std::string url_;
137 std::string method_; 155 std::string method_;
138 std::string referrer_; 156 std::string referrer_;
139 std::string extra_headers_; 157 std::string extra_headers_;
140 ScopedComPtr<IStream> upload_data_; 158 ScopedComPtr<IStream> upload_data_;
141 URLRequestStatus::Status status_;
142 }; 159 };
143 160
144 #endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_ 161 #endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_
OLDNEW
« no previous file with comments | « chrome_frame/npapi_url_request.cc ('k') | chrome_frame/plugin_url_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698