| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/npapi_url_request.h" | 5 #include "chrome_frame/npapi_url_request.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "chrome_frame/np_browser_functions.h" | 8 #include "chrome_frame/np_browser_functions.h" |
| 9 #include "chrome_frame/np_utils.h" | 9 #include "chrome_frame/np_utils.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 DISALLOW_COPY_AND_ASSIGN(NPAPIUrlRequest); | 49 DISALLOW_COPY_AND_ASSIGN(NPAPIUrlRequest); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 int NPAPIUrlRequest::instance_count_ = 0; | 52 int NPAPIUrlRequest::instance_count_ = 0; |
| 53 | 53 |
| 54 NPAPIUrlRequest::NPAPIUrlRequest(NPP instance) | 54 NPAPIUrlRequest::NPAPIUrlRequest(NPP instance) |
| 55 : ref_count_(0), instance_(instance), stream_(NULL), | 55 : ref_count_(0), instance_(instance), stream_(NULL), |
| 56 pending_read_size_(0), | 56 pending_read_size_(0), |
| 57 status_(URLRequestStatus::FAILED, net::ERR_FAILED), | 57 status_(URLRequestStatus::FAILED, net::ERR_FAILED), |
| 58 thread_(PlatformThread::CurrentId()) { | 58 thread_(PlatformThread::CurrentId()) { |
| 59 DLOG(INFO) << "Created request. Count: " << ++instance_count_; | 59 DVLOG(1) << "Created request. Count: " << ++instance_count_; |
| 60 } | 60 } |
| 61 | 61 |
| 62 NPAPIUrlRequest::~NPAPIUrlRequest() { | 62 NPAPIUrlRequest::~NPAPIUrlRequest() { |
| 63 DLOG(INFO) << "Deleted request. Count: " << --instance_count_; | 63 DVLOG(1) << "Deleted request. Count: " << --instance_count_; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // NPAPIUrlRequest member defines. | 66 // NPAPIUrlRequest member defines. |
| 67 bool NPAPIUrlRequest::Start() { | 67 bool NPAPIUrlRequest::Start() { |
| 68 NPError result = NPERR_GENERIC_ERROR; | 68 NPError result = NPERR_GENERIC_ERROR; |
| 69 DLOG(INFO) << "Starting URL request: " << url(); | 69 DVLOG(1) << "Starting URL request: " << url(); |
| 70 if (LowerCaseEqualsASCII(method(), "get")) { | 70 if (LowerCaseEqualsASCII(method(), "get")) { |
| 71 // TODO(joshia): if we have extra headers for HTTP GET, then implement | 71 // TODO(joshia): if we have extra headers for HTTP GET, then implement |
| 72 // it using XHR | 72 // it using XHR |
| 73 result = npapi::GetURLNotify(instance_, url().c_str(), NULL, this); | 73 result = npapi::GetURLNotify(instance_, url().c_str(), NULL, this); |
| 74 } else if (LowerCaseEqualsASCII(method(), "post")) { | 74 } else if (LowerCaseEqualsASCII(method(), "post")) { |
| 75 uint32 data_len = static_cast<uint32>(post_data_len()); | 75 uint32 data_len = static_cast<uint32>(post_data_len()); |
| 76 | 76 |
| 77 std::string buffer; | 77 std::string buffer; |
| 78 if (extra_headers().length() > 0) { | 78 if (extra_headers().length() > 0) { |
| 79 buffer += extra_headers(); | 79 buffer += extra_headers(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 delegate_->OnResponseEnd(id(), | 113 delegate_->OnResponseEnd(id(), |
| 114 URLRequestStatus(URLRequestStatus::FAILED, os_error)); | 114 URLRequestStatus(URLRequestStatus::FAILED, os_error)); |
| 115 return false; | 115 return false; |
| 116 } | 116 } |
| 117 | 117 |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void NPAPIUrlRequest::Stop() { | 121 void NPAPIUrlRequest::Stop() { |
| 122 DLOG(INFO) << "Finished request: Url - " << url() << " result: " | 122 DVLOG(1) << "Finished request: Url - " << url() |
| 123 << static_cast<int>(status_.status()); | 123 << " result: " << static_cast<int>(status_.status()); |
| 124 | 124 |
| 125 status_.set_status(URLRequestStatus::CANCELED); | 125 status_.set_status(URLRequestStatus::CANCELED); |
| 126 if (stream_) { | 126 if (stream_) { |
| 127 npapi::DestroyStream(instance_, stream_, NPRES_USER_BREAK); | 127 npapi::DestroyStream(instance_, stream_, NPRES_USER_BREAK); |
| 128 stream_ = NULL; | 128 stream_ = NULL; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool NPAPIUrlRequest::Read(int bytes_to_read) { | 132 bool NPAPIUrlRequest::Read(int bytes_to_read) { |
| 133 pending_read_size_ = bytes_to_read; | 133 pending_read_size_ = bytes_to_read; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 | 265 |
| 266 void NPAPIUrlRequestManager::SetCookiesForUrl(const GURL& url, | 266 void NPAPIUrlRequestManager::SetCookiesForUrl(const GURL& url, |
| 267 const std::string& cookie) { | 267 const std::string& cookie) { |
| 268 // Use the newer NPAPI way if available | 268 // Use the newer NPAPI way if available |
| 269 if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { | 269 if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { |
| 270 npapi::SetValueForURL(instance_, NPNURLVCookie, url.spec().c_str(), | 270 npapi::SetValueForURL(instance_, NPNURLVCookie, url.spec().c_str(), |
| 271 cookie.c_str(), cookie.length()); | 271 cookie.c_str(), cookie.length()); |
| 272 } else { | 272 } else { |
| 273 DLOG(INFO) << "Host does not support NPVERS_HAS_URL_AND_AUTH_INFO."; | 273 DVLOG(1) << "Host does not support NPVERS_HAS_URL_AND_AUTH_INFO. " |
| 274 DLOG(INFO) << "Attempting to set cookie using XPCOM cookie service"; | 274 "Attempting to set cookie using XPCOM cookie service"; |
| 275 if (np_utils::SetCookiesUsingXPCOMCookieService(instance_, url.spec(), | 275 if (np_utils::SetCookiesUsingXPCOMCookieService(instance_, url.spec(), |
| 276 cookie)) { | 276 cookie)) { |
| 277 DLOG(INFO) << "Successfully set cookies using XPCOM cookie service"; | 277 DVLOG(1) << "Successfully set cookies using XPCOM cookie service " |
| 278 DLOG(INFO) << cookie.c_str(); | 278 << cookie; |
| 279 } else { | 279 } else { |
| 280 NOTREACHED() << "Failed to set cookies for host"; | 280 NOTREACHED() << "Failed to set cookies for host"; |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 void NPAPIUrlRequestManager::GetCookiesForUrl(const GURL& url, int cookie_id) { | 285 void NPAPIUrlRequestManager::GetCookiesForUrl(const GURL& url, int cookie_id) { |
| 286 std::string cookie_string; | 286 std::string cookie_string; |
| 287 bool success = true; | 287 bool success = true; |
| 288 | 288 |
| 289 if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { | 289 if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { |
| 290 char* cookies = NULL; | 290 char* cookies = NULL; |
| 291 unsigned int cookie_length = 0; | 291 unsigned int cookie_length = 0; |
| 292 NPError ret = npapi::GetValueForURL(instance_, NPNURLVCookie, | 292 NPError ret = npapi::GetValueForURL(instance_, NPNURLVCookie, |
| 293 url.spec().c_str(), &cookies, | 293 url.spec().c_str(), &cookies, |
| 294 &cookie_length); | 294 &cookie_length); |
| 295 if (ret == NPERR_NO_ERROR) { | 295 if (ret == NPERR_NO_ERROR) { |
| 296 DLOG(INFO) << "Obtained cookies:" << cookies << " from host"; | 296 DVLOG(1) << "Obtained cookies:" << cookies << " from host"; |
| 297 cookie_string.append(cookies, cookie_length); | 297 cookie_string.append(cookies, cookie_length); |
| 298 npapi::MemFree(cookies); | 298 npapi::MemFree(cookies); |
| 299 } else { | 299 } else { |
| 300 success = false; | 300 success = false; |
| 301 } | 301 } |
| 302 } else { | 302 } else { |
| 303 DLOG(INFO) << "Host does not support NPVERS_HAS_URL_AND_AUTH_INFO."; | 303 DVLOG(1) << "Host does not support NPVERS_HAS_URL_AND_AUTH_INFO. " |
| 304 DLOG(INFO) << "Attempting to read cookie using XPCOM cookie service"; | 304 "Attempting to read cookie using XPCOM cookie service"; |
| 305 if (np_utils::GetCookiesUsingXPCOMCookieService(instance_, url.spec(), | 305 if (np_utils::GetCookiesUsingXPCOMCookieService(instance_, url.spec(), |
| 306 &cookie_string)) { | 306 &cookie_string)) { |
| 307 DLOG(INFO) << "Successfully read cookies using XPCOM cookie service"; | 307 DVLOG(1) << "Successfully read cookies using XPCOM cookie service " |
| 308 DLOG(INFO) << cookie_string.c_str(); | 308 << cookie_string; |
| 309 } else { | 309 } else { |
| 310 success = false; | 310 success = false; |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 if (!success) | 314 if (!success) |
| 315 DLOG(INFO) << "Failed to return cookies for url:" << url.spec().c_str(); | 315 DVLOG(1) << "Failed to return cookies for url:" << url.spec(); |
| 316 | 316 |
| 317 OnCookiesRetrieved(success, url, cookie_string, cookie_id); | 317 OnCookiesRetrieved(success, url, cookie_string, cookie_id); |
| 318 } | 318 } |
| 319 | 319 |
| 320 // PluginRequestDelegate implementation. | 320 // PluginRequestDelegate implementation. |
| 321 // Callbacks from NPAPIUrlRequest. Simply forward to the delegate. | 321 // Callbacks from NPAPIUrlRequest. Simply forward to the delegate. |
| 322 void NPAPIUrlRequestManager::OnResponseStarted(int request_id, | 322 void NPAPIUrlRequestManager::OnResponseStarted(int request_id, |
| 323 const char* mime_type, const char* headers, int size, | 323 const char* mime_type, const char* headers, int size, |
| 324 base::Time last_modified, const std::string& redirect_url, | 324 base::Time last_modified, const std::string& redirect_url, |
| 325 int redirect_status) { | 325 int redirect_status) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 | 418 |
| 419 scoped_refptr<NPAPIUrlRequest> NPAPIUrlRequestManager::LookupRequest( | 419 scoped_refptr<NPAPIUrlRequest> NPAPIUrlRequestManager::LookupRequest( |
| 420 int request_id) { | 420 int request_id) { |
| 421 RequestMap::iterator index = request_map_.find(request_id); | 421 RequestMap::iterator index = request_map_.find(request_id); |
| 422 if (index != request_map_.end()) | 422 if (index != request_map_.end()) |
| 423 return index->second; | 423 return index->second; |
| 424 return NULL; | 424 return NULL; |
| 425 } | 425 } |
| OLD | NEW |