| 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/browser/automation/url_request_automation_job.h" | 5 #include "chrome/browser/automation/url_request_automation_job.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "chrome/browser/automation/automation_resource_message_filter.h" | 9 #include "chrome/browser/automation/automation_resource_message_filter.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 int URLRequestAutomationJob::instance_count_ = 0; | 44 int URLRequestAutomationJob::instance_count_ = 0; |
| 45 bool URLRequestAutomationJob::is_protocol_factory_registered_ = false; | 45 bool URLRequestAutomationJob::is_protocol_factory_registered_ = false; |
| 46 | 46 |
| 47 URLRequest::ProtocolFactory* URLRequestAutomationJob::old_http_factory_ | 47 URLRequest::ProtocolFactory* URLRequestAutomationJob::old_http_factory_ |
| 48 = NULL; | 48 = NULL; |
| 49 URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ | 49 URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ |
| 50 = NULL; | 50 = NULL; |
| 51 | 51 |
| 52 namespace { |
| 53 |
| 54 // Returns true if the cookie passed in exists in the list of cookies |
| 55 // parsed from the HTTP response header. |
| 56 bool IsParsedCookiePresentInCookieHeader( |
| 57 const net::CookieMonster::ParsedCookie& parsed_cookie, |
| 58 const std::vector<std::string>& header_cookies) { |
| 59 for (size_t i = 0; i < header_cookies.size(); ++i) { |
| 60 net::CookieMonster::ParsedCookie parsed_header_cookie(header_cookies[i]); |
| 61 if (parsed_header_cookie.Name() == parsed_cookie.Name()) |
| 62 return true; |
| 63 } |
| 64 |
| 65 return false; |
| 66 } |
| 67 |
| 68 } // end namespace |
| 69 |
| 52 URLRequestAutomationJob::URLRequestAutomationJob(URLRequest* request, int tab, | 70 URLRequestAutomationJob::URLRequestAutomationJob(URLRequest* request, int tab, |
| 53 int request_id, AutomationResourceMessageFilter* filter) | 71 int request_id, AutomationResourceMessageFilter* filter) |
| 54 : URLRequestJob(request), | 72 : URLRequestJob(request), |
| 55 tab_(tab), | 73 tab_(tab), |
| 56 message_filter_(filter), | 74 message_filter_(filter), |
| 57 pending_buf_size_(0), | 75 pending_buf_size_(0), |
| 58 redirect_status_(0), | 76 redirect_status_(0), |
| 59 request_id_(request_id) { | 77 request_id_(request_id) { |
| 60 DLOG(INFO) << "URLRequestAutomationJob create. Count: " << ++instance_count_; | 78 DLOG(INFO) << "URLRequestAutomationJob create. Count: " << ++instance_count_; |
| 61 DCHECK(message_filter_ != NULL); | 79 DCHECK(message_filter_ != NULL); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 options); | 302 options); |
| 285 } | 303 } |
| 286 } | 304 } |
| 287 } | 305 } |
| 288 | 306 |
| 289 if (ctx && ctx->cookie_store() && !response.persistent_cookies.empty() && | 307 if (ctx && ctx->cookie_store() && !response.persistent_cookies.empty() && |
| 290 ctx->cookie_policy()->CanSetCookie( | 308 ctx->cookie_policy()->CanSetCookie( |
| 291 url_for_cookies, request_->first_party_for_cookies())) { | 309 url_for_cookies, request_->first_party_for_cookies())) { |
| 292 StringTokenizer cookie_parser(response.persistent_cookies, ";"); | 310 StringTokenizer cookie_parser(response.persistent_cookies, ";"); |
| 293 | 311 |
| 312 std::vector<net::CookieMonster::CanonicalCookie> existing_cookies; |
| 313 net::CookieMonster* monster = ctx->cookie_store()->GetCookieMonster(); |
| 314 DCHECK(monster); |
| 315 if (monster) { |
| 316 monster->GetRawCookies(url_for_cookies, &existing_cookies); |
| 317 } |
| 318 |
| 294 while (cookie_parser.GetNext()) { | 319 while (cookie_parser.GetNext()) { |
| 295 std::string cookie_string = cookie_parser.token(); | 320 std::string cookie_string = cookie_parser.token(); |
| 296 // Only allow cookies with valid name value pairs. | 321 // Only allow cookies with valid name value pairs. |
| 297 if (cookie_string.find('=') != std::string::npos) { | 322 if (cookie_string.find('=') != std::string::npos) { |
| 298 TrimWhitespace(cookie_string, TRIM_ALL, &cookie_string); | 323 TrimWhitespace(cookie_string, TRIM_ALL, &cookie_string); |
| 299 // Ignore duplicate cookies, i.e. cookies passed in from the host | 324 // Ignore duplicate cookies, i.e. cookies passed in from the host |
| 300 // browser which also exist in the response header. | 325 // browser which also exist in the response header. |
| 301 if (!IsCookiePresentInCookieHeader(cookie_string, | 326 net::CookieMonster::ParsedCookie parsed_cookie(cookie_string); |
| 302 response_cookies)) { | 327 std::vector<net::CookieMonster::CanonicalCookie>::const_iterator i; |
| 303 net::CookieOptions options; | 328 for (i = existing_cookies.begin(); i != existing_cookies.end(); ++i) { |
| 304 ctx->cookie_store()->SetCookieWithOptions(url_for_cookies, | 329 if ((*i).Name() == parsed_cookie.Name()) |
| 305 cookie_string, | 330 break; |
| 306 options); | 331 } |
| 332 |
| 333 if (i == existing_cookies.end() && |
| 334 !IsParsedCookiePresentInCookieHeader(parsed_cookie, |
| 335 response_cookies)) { |
| 336 net::CookieOptions options; |
| 337 ctx->cookie_store()->SetCookieWithOptions(url_for_cookies, |
| 338 cookie_string, |
| 339 options); |
| 307 } | 340 } |
| 308 } | 341 } |
| 309 } | 342 } |
| 310 } | 343 } |
| 311 | 344 |
| 312 NotifyHeadersComplete(); | 345 NotifyHeadersComplete(); |
| 313 } | 346 } |
| 314 | 347 |
| 315 void URLRequestAutomationJob::OnDataAvailable( | 348 void URLRequestAutomationJob::OnDataAvailable( |
| 316 int tab, int id, const std::string& bytes) { | 349 int tab, int id, const std::string& bytes) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } | 475 } |
| 443 | 476 |
| 444 void URLRequestAutomationJob::DisconnectFromMessageFilter() { | 477 void URLRequestAutomationJob::DisconnectFromMessageFilter() { |
| 445 if (message_filter_) { | 478 if (message_filter_) { |
| 446 message_filter_->UnRegisterRequest(this); | 479 message_filter_->UnRegisterRequest(this); |
| 447 message_filter_ = NULL; | 480 message_filter_ = NULL; |
| 448 } | 481 } |
| 449 } | 482 } |
| 450 | 483 |
| 451 bool URLRequestAutomationJob::IsCookiePresentInCookieHeader( | 484 bool URLRequestAutomationJob::IsCookiePresentInCookieHeader( |
| 452 const std::string& cookie_line, | 485 const std::string& cookie_name, |
| 453 const std::vector<std::string>& header_cookies) { | 486 const std::vector<std::string>& header_cookies) { |
| 454 net::CookieMonster::ParsedCookie parsed_current_cookie(cookie_line); | 487 net::CookieMonster::ParsedCookie parsed_cookie(cookie_name); |
| 455 for (size_t index = 0; index < header_cookies.size(); index++) { | 488 return IsParsedCookiePresentInCookieHeader(parsed_cookie, header_cookies); |
| 456 net::CookieMonster::ParsedCookie parsed_header_cookie( | |
| 457 header_cookies[index]); | |
| 458 | |
| 459 if (parsed_header_cookie.Name() == parsed_current_cookie.Name()) | |
| 460 return true; | |
| 461 } | |
| 462 | |
| 463 return false; | |
| 464 } | 489 } |
| 465 | |
| OLD | NEW |