OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This job type handles Chrome plugin network interception. When a plugin | 5 // This job type handles Chrome plugin network interception. When a plugin |
6 // wants to intercept a request, a job of this type is created. The intercept | 6 // wants to intercept a request, a job of this type is created. The intercept |
7 // job communicates with the plugin to retrieve the response headers and data. | 7 // job communicates with the plugin to retrieve the response headers and data. |
8 | 8 |
9 #include "chrome/common/net/url_request_intercept_job.h" | 9 #include "chrome/common/net/url_request_intercept_job.h" |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 int rv = plugin_->functions().request_funcs->read(cprequest_.get(), | 84 int rv = plugin_->functions().request_funcs->read(cprequest_.get(), |
85 dest->data(), dest_size); | 85 dest->data(), dest_size); |
86 if (rv >= 0) { | 86 if (rv >= 0) { |
87 *bytes_read = rv; | 87 *bytes_read = rv; |
88 return true; | 88 return true; |
89 } | 89 } |
90 | 90 |
91 if (rv == CPERR_IO_PENDING) { | 91 if (rv == CPERR_IO_PENDING) { |
92 read_buffer_ = dest; | 92 read_buffer_ = dest; |
93 read_buffer_size_ = dest_size; | 93 read_buffer_size_ = dest_size; |
94 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 94 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
95 } else { | 95 } else { |
96 // TODO(mpcomplete): better error code | 96 // TODO(mpcomplete): better error code |
97 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, net::ERR_FAILED)); | 97 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 98 net::ERR_FAILED)); |
98 } | 99 } |
99 | 100 |
100 return false; | 101 return false; |
101 } | 102 } |
102 | 103 |
103 bool URLRequestInterceptJob::GetMimeType(std::string* mime_type) const { | 104 bool URLRequestInterceptJob::GetMimeType(std::string* mime_type) const { |
104 return request_->response_headers()->GetMimeType(mime_type); | 105 return request_->response_headers()->GetMimeType(mime_type); |
105 } | 106 } |
106 | 107 |
107 bool URLRequestInterceptJob::GetCharset(std::string* charset) { | 108 bool URLRequestInterceptJob::GetCharset(std::string* charset) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (!request_ || !plugin_) | 202 if (!request_ || !plugin_) |
202 return; | 203 return; |
203 | 204 |
204 int rv = plugin_->functions().request_funcs->start_request(cprequest_.get()); | 205 int rv = plugin_->functions().request_funcs->start_request(cprequest_.get()); |
205 if (rv != CPERR_IO_PENDING) | 206 if (rv != CPERR_IO_PENDING) |
206 OnStartCompleted(rv); | 207 OnStartCompleted(rv); |
207 } | 208 } |
208 | 209 |
209 void URLRequestInterceptJob::OnStartCompleted(int result) { | 210 void URLRequestInterceptJob::OnStartCompleted(int result) { |
210 if (result != CPERR_SUCCESS) { | 211 if (result != CPERR_SUCCESS) { |
211 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 212 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
212 net::ERR_CONNECTION_FAILED)); | 213 net::ERR_CONNECTION_FAILED)); |
213 return; | 214 return; |
214 } | 215 } |
215 | 216 |
216 NotifyHeadersComplete(); | 217 NotifyHeadersComplete(); |
217 } | 218 } |
218 | 219 |
219 void URLRequestInterceptJob::OnReadCompleted(int bytes_read) { | 220 void URLRequestInterceptJob::OnReadCompleted(int bytes_read) { |
220 if (bytes_read < 0) { | 221 if (bytes_read < 0) { |
221 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, net::ERR_FAILED)); | 222 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 223 net::ERR_FAILED)); |
222 return; | 224 return; |
223 } | 225 } |
224 | 226 |
225 SetStatus(URLRequestStatus()); // clear the async flag | 227 SetStatus(net::URLRequestStatus()); // clear the async flag |
226 NotifyReadComplete(bytes_read); | 228 NotifyReadComplete(bytes_read); |
227 } | 229 } |
228 | 230 |
229 void URLRequestInterceptJob::Observe(NotificationType type, | 231 void URLRequestInterceptJob::Observe(NotificationType type, |
230 const NotificationSource& source, | 232 const NotificationSource& source, |
231 const NotificationDetails& details) { | 233 const NotificationDetails& details) { |
232 DCHECK(type == NotificationType::CHROME_PLUGIN_UNLOADED); | 234 DCHECK(type == NotificationType::CHROME_PLUGIN_UNLOADED); |
233 DCHECK(plugin_ == Source<ChromePluginLib>(source).ptr()); | 235 DCHECK(plugin_ == Source<ChromePluginLib>(source).ptr()); |
234 DetachPlugin(); | 236 DetachPlugin(); |
235 } | 237 } |
OLD | NEW |