diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 19:19:15 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 19:19:15 +0000 |
commit | c7a90eab2f4a045fee103dbfa18710918b368476 (patch) | |
tree | e12ebddacb41a61bb804deff42a504b0361f5544 /chrome/browser/automation | |
parent | 97cdd4667b961cf865047d0bc764764a7c199ce7 (diff) | |
download | chromium_src-c7a90eab2f4a045fee103dbfa18710918b368476.zip chromium_src-c7a90eab2f4a045fee103dbfa18710918b368476.tar.gz chromium_src-c7a90eab2f4a045fee103dbfa18710918b368476.tar.bz2 |
Modify CookiePolicy to work asynchronously
This change will enable us to prompt the user before setting a cookie. While we only need to prompt before setting, we actually need to make both CanSetCookie and CanGetCookies asynchronous. This is necessary in order to preserve FIFO ordering since the value returned by GetCookies depends on the changes made to the cookie DB by SetCookie.
This change also includes some simplification of CookieStore. Instead of N virtual functions, I distilled it down to only 4. The remaining functions are instead expressed in terms of those.
While studying all the places where we currently use CookiePolicy, I found that some of them were not appropriate. After discussing with Amit, I decided to remove the policy checks in URLRequestAutomationJob. See the comments in the code regarding this.
I changed the signature of CookieMonster::GetRawCookies to GetAllCookiesForURL to better match GetAllCookies. I also filed a bug about making it even closer in functionality. Related to this change webkit/glue/webcookie.h grows a constructor that takes a CanonicalCookie to help clean up some code.
On the Chrome side, ChromeURLRequestContext now has a ChromeCookiePolicy object. That object is thread-safe ref counted because it is passed between the UI and IO threads. It is responsible for implementing the queuing logic described above. It will also in the future trigger the Chrome UI code to actually show the set-cookie prompt.
Please review the state machinery changes in URLRequestHttpJob carefully.
R=eroman
BUG=34331
TEST=no tests yet for prompting.
Review URL: http://codereview.chromium.org/567015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37998 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r-- | chrome/browser/automation/automation_profile_impl.cc | 42 | ||||
-rw-r--r-- | chrome/browser/automation/url_request_automation_job.cc | 29 |
2 files changed, 18 insertions, 53 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.cc b/chrome/browser/automation/automation_profile_impl.cc index 3a1387d..d09b036 100644 --- a/chrome/browser/automation/automation_profile_impl.cc +++ b/chrome/browser/automation/automation_profile_impl.cc @@ -58,8 +58,12 @@ class AutomationCookieStore : public net::CookieStore { } // CookieStore implementation. - virtual bool SetCookie(const GURL& url, const std::string& cookie_line) { - bool cookie_set = original_cookie_store_->SetCookie(url, cookie_line); + virtual bool SetCookieWithOptions(const GURL& url, + const std::string& cookie_line, + const net::CookieOptions& options) { + bool cookie_set = + original_cookie_store_->SetCookieWithOptions(url, cookie_line, + options); if (cookie_set) { // TODO(eroman): Should NOT be accessing the profile from here, as this // is running on the IO thread. @@ -68,48 +72,14 @@ class AutomationCookieStore : public net::CookieStore { } return cookie_set; } - virtual bool SetCookieWithOptions(const GURL& url, - const std::string& cookie_line, - const net::CookieOptions& options) { - return original_cookie_store_->SetCookieWithOptions(url, cookie_line, - options); - } - virtual bool SetCookieWithCreationTime(const GURL& url, - const std::string& cookie_line, - const base::Time& creation_time) { - return original_cookie_store_->SetCookieWithCreationTime(url, cookie_line, - creation_time); - } - virtual bool SetCookieWithCreationTimeWithOptions( - const GURL& url, - const std::string& cookie_line, - const base::Time& creation_time, - const net::CookieOptions& options) { - return original_cookie_store_->SetCookieWithCreationTimeWithOptions(url, - cookie_line, creation_time, options); - } - virtual void SetCookies(const GURL& url, - const std::vector<std::string>& cookies) { - original_cookie_store_->SetCookies(url, cookies); - } - virtual void SetCookiesWithOptions(const GURL& url, - const std::vector<std::string>& cookies, - const net::CookieOptions& options) { - original_cookie_store_->SetCookiesWithOptions(url, cookies, options); - } - virtual std::string GetCookies(const GURL& url) { - return original_cookie_store_->GetCookies(url); - } virtual std::string GetCookiesWithOptions(const GURL& url, const net::CookieOptions& options) { 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); } - virtual net::CookieMonster* GetCookieMonster() { return original_cookie_store_->GetCookieMonster(); } diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc index 319b976..77e927f 100644 --- a/chrome/browser/automation/url_request_automation_job.cc +++ b/chrome/browser/automation/url_request_automation_job.cc @@ -13,7 +13,6 @@ #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/cookie_policy.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/http/http_util.h" @@ -298,6 +297,9 @@ void URLRequestAutomationJob::OnRequestStarted(int tab, int id, URLRequestContext* ctx = request_->context(); std::vector<std::string> response_cookies; + // NOTE: We ignore Chrome's cookie policy to allow the automation to + // decide what cookies should be set. + if (!response.headers.empty()) { headers_ = new net::HttpResponseHeaders( net::HttpUtil::AssembleRawHeaders(response.headers.data(), @@ -312,30 +314,23 @@ void URLRequestAutomationJob::OnRequestStarted(int tab, int id, response_cookies.push_back(value); } - if (response_cookies.size()) { - if (ctx && ctx->cookie_store() && (!ctx->cookie_policy() || - ctx->cookie_policy()->CanSetCookie( - url_for_cookies, request_->first_party_for_cookies()))) { - net::CookieOptions options; - options.set_include_httponly(); - ctx->cookie_store()->SetCookiesWithOptions(url_for_cookies, - response_cookies, - options); - } + if (response_cookies.size() && ctx && ctx->cookie_store()) { + net::CookieOptions options; + options.set_include_httponly(); + ctx->cookie_store()->SetCookiesWithOptions(url_for_cookies, + response_cookies, + options); } } - if (!response.persistent_cookies.empty() && ctx && ctx->cookie_store() && - (!ctx->cookie_policy() || ctx->cookie_policy()->CanSetCookie( - url_for_cookies, request_->first_party_for_cookies()))) { + if (!response.persistent_cookies.empty() && ctx && ctx->cookie_store()) { StringTokenizer cookie_parser(response.persistent_cookies, ";"); net::CookieMonster::CookieList existing_cookies; net::CookieMonster* monster = ctx->cookie_store()->GetCookieMonster(); DCHECK(monster); - if (monster) { - existing_cookies = monster->GetRawCookies(url_for_cookies); - } + if (monster) + existing_cookies = monster->GetAllCookiesForURL(url_for_cookies); while (cookie_parser.GetNext()) { std::string cookie_string = cookie_parser.token(); |