summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 05:55:50 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 05:55:50 +0000
commitaeb9efc09906da4c32ec2eaccfb9dfd44f1b4c10 (patch)
treefe41260e4361e23166033b33fed519c63b991357 /chrome/browser/automation
parent799149e6934057e03c11038e39c7875a5eb71fbe (diff)
downloadchromium_src-aeb9efc09906da4c32ec2eaccfb9dfd44f1b4c10.zip
chromium_src-aeb9efc09906da4c32ec2eaccfb9dfd44f1b4c10.tar.gz
chromium_src-aeb9efc09906da4c32ec2eaccfb9dfd44f1b4c10.tar.bz2
Attempt 2 at landing this.
Deleting cookies by setting the expires attribute on them with an empty value would not work in ChromeFrame with the host network stack enabled. When we receive a response in the host browser (IE) we send over the response headers which include the Set-Cookie header and a list of cookies retreived via the InternetGetCookie API. We call this API to retrieve the persistent cookies and send them over to Chrome. However this API returns session cookies as well as persistent cookies. There is no documented way to return only persistent cookies from IE. As a result we would end up setting duplicate cookies in Chrome, which caused this issu.e. To workaround this issue when we receive the response in the url request automation job which handles ChromeFrame network requests, we strip out duplicate cookies sent via InternetGetCookie. When a script deletes a cookie we now handle it correctly in IE and set the data to an empty string. However this does not delete the cookie. When such cookies show up in Chrome, we strip them out as well. Fixes bug http://code.google.com/p/chromium/issues/detail?id=30786 The changes to chrome_frame_npapi.cc/.h are to move the NPAPI functions to the chrome_frame namespace as they conflict with similar functions in NACL. Added the DeleteCookie function to the CookieStore interface, which I think missed out by oversight. Bug=30786 Test=Covered by ChromeFrame unit tests. I also added a unit test to test the newly added URLRequestAutomationJob::IsCookiePresentInCookieHeader function TBR=amit Review URL: http://codereview.chromium.org/521072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35778 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_profile_impl.cc5
-rw-r--r--chrome/browser/automation/url_request_automation_job.cc37
-rw-r--r--chrome/browser/automation/url_request_automation_job.h7
3 files changed, 44 insertions, 5 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.cc b/chrome/browser/automation/automation_profile_impl.cc
index 0acd37d..b8685be 100644
--- a/chrome/browser/automation/automation_profile_impl.cc
+++ b/chrome/browser/automation/automation_profile_impl.cc
@@ -105,6 +105,11 @@ class AutomationCookieStore : public net::CookieStore {
return original_cookie_store_->GetCookiesWithOptions(url, options);
}
+ virtual void DeleteCookie(const GURL& url,
+ const std::string& cookie_name) {
+ return original_cookie_store_->DeleteCookie(url, cookie_name);
+ }
+
protected:
void SendIPCMessageOnIOThread(IPC::Message* m) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc
index 5433ca7..576743e 100644
--- a/chrome/browser/automation/url_request_automation_job.cc
+++ b/chrome/browser/automation/url_request_automation_job.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "chrome/test/automation/automation_messages.h"
+#include "net/base/cookie_monster.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/http/http_util.h"
@@ -256,6 +257,7 @@ void URLRequestAutomationJob::OnRequestStarted(int tab, int id,
redirect_url_.c_str());
URLRequestContext* ctx = request_->context();
+ std::vector<std::string> response_cookies;
if (!response.headers.empty()) {
headers_ = new net::HttpResponseHeaders(
@@ -264,7 +266,6 @@ void URLRequestAutomationJob::OnRequestStarted(int tab, int id,
// Parse and set HTTP cookies.
const std::string name = "Set-Cookie";
std::string value;
- std::vector<std::string> response_cookies;
void* iter = NULL;
while (headers_->EnumerateHeader(&iter, name, &value)) {
@@ -291,10 +292,20 @@ void URLRequestAutomationJob::OnRequestStarted(int tab, int id,
StringTokenizer cookie_parser(response.persistent_cookies, ";");
while (cookie_parser.GetNext()) {
- net::CookieOptions options;
- ctx->cookie_store()->SetCookieWithOptions(url_for_cookies,
- cookie_parser.token(),
- options);
+ std::string cookie_string = cookie_parser.token();
+ // Only allow cookies with valid name value pairs.
+ if (cookie_string.find('=') != std::string::npos) {
+ TrimWhitespace(cookie_string, TRIM_ALL, &cookie_string);
+ // Ignore duplicate cookies, i.e. cookies passed in from the host
+ // browser which also exist in the response header.
+ if (!IsCookiePresentInCookieHeader(cookie_string,
+ response_cookies)) {
+ net::CookieOptions options;
+ ctx->cookie_store()->SetCookieWithOptions(url_for_cookies,
+ cookie_string,
+ options);
+ }
+ }
}
}
@@ -436,3 +447,19 @@ void URLRequestAutomationJob::DisconnectFromMessageFilter() {
message_filter_ = NULL;
}
}
+
+bool URLRequestAutomationJob::IsCookiePresentInCookieHeader(
+ const std::string& cookie_line,
+ const std::vector<std::string>& header_cookies) {
+ net::CookieMonster::ParsedCookie parsed_current_cookie(cookie_line);
+ for (size_t index = 0; index < header_cookies.size(); index++) {
+ net::CookieMonster::ParsedCookie parsed_header_cookie(
+ header_cookies[index]);
+
+ if (parsed_header_cookie.Name() == parsed_current_cookie.Name())
+ return true;
+ }
+
+ return false;
+}
+
diff --git a/chrome/browser/automation/url_request_automation_job.h b/chrome/browser/automation/url_request_automation_job.h
index 824b80c..0b6a2f1 100644
--- a/chrome/browser/automation/url_request_automation_job.h
+++ b/chrome/browser/automation/url_request_automation_job.h
@@ -6,6 +6,7 @@
#ifndef CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_
#define CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_
+#include <vector>
#include "chrome/common/ref_counted_util.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
@@ -51,6 +52,12 @@ class URLRequestAutomationJob : public URLRequestJob {
return request_id_;
}
+ // Returns true if the cookie passed in exists in the list of cookies
+ // parsed from the HTTP response header.
+ static bool IsCookiePresentInCookieHeader(
+ const std::string& cookie_name,
+ const std::vector<std::string>& header_cookies);
+
protected:
// Protected URLRequestJob override.
virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);