OLD | NEW |
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 #include "chrome_frame/plugin_url_request.h" | 5 #include "chrome_frame/plugin_url_request.h" |
6 | 6 |
7 #include "chrome/test/automation/automation_messages.h" | 7 #include "chrome/test/automation/automation_messages.h" |
8 #include "chrome_frame/np_browser_functions.h" | 8 #include "chrome_frame/np_browser_functions.h" |
9 | 9 |
10 PluginUrlRequest::PluginUrlRequest() | 10 PluginUrlRequest::PluginUrlRequest() |
11 : request_handler_(NULL), | 11 : delegate_(NULL), |
12 tab_(0), | |
13 remote_request_id_(-1), | 12 remote_request_id_(-1), |
14 post_data_len_(0), | 13 post_data_len_(0), |
15 status_(URLRequestStatus::IO_PENDING), | 14 enable_frame_busting_(false) { |
16 frame_busting_enabled_(false) { | |
17 } | 15 } |
18 | 16 |
19 PluginUrlRequest::~PluginUrlRequest() { | 17 PluginUrlRequest::~PluginUrlRequest() { |
20 } | 18 } |
21 | 19 |
22 bool PluginUrlRequest::Initialize(PluginRequestHandler* request_handler, | 20 bool PluginUrlRequest::Initialize(PluginUrlRequestDelegate* delegate, |
23 int tab, int remote_request_id, const std::string& url, | 21 int remote_request_id, const std::string& url, const std::string& method, |
24 const std::string& method, const std::string& referrer, | 22 const std::string& referrer, const std::string& extra_headers, |
25 const std::string& extra_headers, net::UploadData* upload_data, | 23 net::UploadData* upload_data, bool enable_frame_busting) { |
26 bool enable_frame_busting) { | 24 delegate_ = delegate; |
27 request_handler_ = request_handler; | |
28 tab_ = tab; | |
29 remote_request_id_ = remote_request_id; | 25 remote_request_id_ = remote_request_id; |
30 url_ = url; | 26 url_ = url; |
31 method_ = method; | 27 method_ = method; |
32 referrer_ = referrer; | 28 referrer_ = referrer; |
33 extra_headers_ = extra_headers; | 29 extra_headers_ = extra_headers; |
34 | 30 |
35 if (upload_data) { | 31 if (upload_data) { |
36 // We store a pointer to UrlmonUploadDataStream and not net::UploadData | 32 // We store a pointer to UrlmonUploadDataStream and not net::UploadData |
37 // since UrlmonUploadDataStream implements thread safe ref counting and | 33 // since UrlmonUploadDataStream implements thread safe ref counting and |
38 // UploadData does not. | 34 // UploadData does not. |
39 CComObject<UrlmonUploadDataStream>* upload_stream = NULL; | 35 CComObject<UrlmonUploadDataStream>* upload_stream = NULL; |
40 HRESULT hr = CComObject<UrlmonUploadDataStream>::CreateInstance( | 36 HRESULT hr = CComObject<UrlmonUploadDataStream>::CreateInstance( |
41 &upload_stream); | 37 &upload_stream); |
42 if (FAILED(hr)) { | 38 if (FAILED(hr)) { |
43 NOTREACHED(); | 39 NOTREACHED(); |
44 } else { | 40 } else { |
45 post_data_len_ = upload_data->GetContentLength(); | 41 post_data_len_ = upload_data->GetContentLength(); |
46 upload_stream->AddRef(); | 42 upload_stream->AddRef(); |
47 upload_stream->Initialize(upload_data); | 43 upload_stream->Initialize(upload_data); |
48 upload_data_.Attach(upload_stream); | 44 upload_data_.Attach(upload_stream); |
49 } | 45 } |
50 } | 46 } |
51 | 47 |
52 frame_busting_enabled_ = enable_frame_busting; | 48 enable_frame_busting_ = enable_frame_busting; |
53 | 49 |
54 return true; | 50 return true; |
55 } | 51 } |
56 | |
57 void PluginUrlRequest::OnResponseStarted(const char* mime_type, | |
58 const char* headers, int size, base::Time last_modified, | |
59 const std::string& persistent_cookies, | |
60 const std::string& redirect_url, int redirect_status) { | |
61 const IPC::AutomationURLResponse response = { | |
62 mime_type, | |
63 headers ? headers : "", | |
64 size, | |
65 last_modified, | |
66 persistent_cookies, | |
67 redirect_url, | |
68 redirect_status | |
69 }; | |
70 request_handler_->Send(new AutomationMsg_RequestStarted(0, tab_, | |
71 remote_request_id_, response)); | |
72 } | |
73 | |
74 void PluginUrlRequest::OnResponseEnd(const URLRequestStatus& status) { | |
75 DCHECK(!status.is_io_pending()); | |
76 DCHECK(status.is_success() || status.os_error()); | |
77 request_handler_->Send(new AutomationMsg_RequestEnd(0, tab_, | |
78 remote_request_id_, status)); | |
79 } | |
80 | |
81 void PluginUrlRequest::OnReadComplete(const void* buffer, int len) { | |
82 std::string data(reinterpret_cast<const char*>(buffer), len); | |
83 request_handler_->Send(new AutomationMsg_RequestData(0, tab_, | |
84 remote_request_id_, data)); | |
85 } | |
86 | |
OLD | NEW |