summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authoramit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 13:28:11 +0000
committeramit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 13:28:11 +0000
commit5f450e5c6fc98a762cebb38cd080731bedd61ae3 (patch)
treede1e6a257709c220222a6ab9defac23aade6e45c /net/base
parent60147f3b071444f0abfb320e62a0c9f2b666d443 (diff)
downloadchromium_src-5f450e5c6fc98a762cebb38cd080731bedd61ae3.zip
chromium_src-5f450e5c6fc98a762cebb38cd080731bedd61ae3.tar.gz
chromium_src-5f450e5c6fc98a762cebb38cd080731bedd61ae3.tar.bz2
Navigation and cookies for Automation
Give Automation better visibility and control over navigations. Also, make it possible for automation to implement a dummy cookie store to go with dummy request serving over automation. BUG=none TEST=none Review URL: http://codereview.chromium.org/159189 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21836 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/cookie_monster.h68
-rw-r--r--net/base/cookie_monster_unittest.cc4
-rw-r--r--net/base/cookie_options.h27
-rw-r--r--net/base/cookie_policy.h6
-rw-r--r--net/base/cookie_policy_unittest.cc6
-rw-r--r--net/base/cookie_store.h64
6 files changed, 128 insertions, 47 deletions
diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h
index 24db893..638a8ed 100644
--- a/net/base/cookie_monster.h
+++ b/net/base/cookie_monster.h
@@ -15,6 +15,7 @@
#include "base/basictypes.h"
#include "base/lock.h"
#include "base/time.h"
+#include "net/base/cookie_store.h"
class GURL;
@@ -30,7 +31,7 @@ namespace net {
//
// TODO(deanm) Implement CookieMonster, the cookie database.
// - Verify that our domain enforcement and non-dotted handling is correct
-class CookieMonster {
+class CookieMonster : public CookieStore {
public:
class ParsedCookie;
class CanonicalCookie;
@@ -49,18 +50,6 @@ class CookieMonster {
typedef std::pair<std::string, CanonicalCookie> CookieListPair;
typedef std::vector<CookieListPair> CookieList;
- class CookieOptions {
- public:
- // Default is to exclude httponly, which means:
- // - reading operations will not return httponly cookies.
- // - writing operations will not write httponly cookies.
- CookieOptions() : exclude_httponly_(true) {}
- void set_exclude_httponly() { exclude_httponly_ = true; }
- void set_include_httponly() { exclude_httponly_ = false; }
- bool exclude_httponly() const { return exclude_httponly_; }
- private:
- bool exclude_httponly_;
- };
CookieMonster();
@@ -85,35 +74,32 @@ class CookieMonster {
// Parse the string with the cookie time (very forgivingly).
static base::Time ParseCookieTime(const std::string& time_string);
- // Set a single cookie. Expects a cookie line, like "a=1; domain=b.com".
- bool SetCookie(const GURL& url, const std::string& cookie_line);
- bool SetCookieWithOptions(const GURL& url,
- const std::string& cookie_line,
- const CookieOptions& options);
- // Sets a single cookie with a specific creation date. To set a cookie with
- // a creation date of Now() use SetCookie() instead (it calls this function
- // internally).
- bool SetCookieWithCreationTime(const GURL& url,
- const std::string& cookie_line,
- const base::Time& creation_time);
- bool SetCookieWithCreationTimeWithOptions(
- const GURL& url,
- const std::string& cookie_line,
- const base::Time& creation_time,
- const CookieOptions& options);
- // Set a vector of response cookie values for the same URL.
- void SetCookies(const GURL& url, const std::vector<std::string>& cookies);
- void SetCookiesWithOptions(const GURL& url,
- const std::vector<std::string>& cookies,
- const CookieOptions& options);
-
- // TODO what if the total size of all the cookies >4k, can we have a header
- // that big or do we need multiple Cookie: headers?
- // Simple interface, get a cookie string "a=b; c=d" for the given URL.
- // It will _not_ return httponly cookies, see CookieOptions.
- std::string GetCookies(const GURL& url);
- std::string GetCookiesWithOptions(const GURL& url,
+ // CookieStore implementation.
+ virtual bool SetCookie(const GURL& url, const std::string& cookie_line);
+ virtual bool SetCookieWithOptions(const GURL& url,
+ const std::string& cookie_line,
const CookieOptions& options);
+ virtual bool SetCookieWithCreationTime(const GURL& url,
+ const std::string& cookie_line,
+ const base::Time& creation_time);
+ virtual bool SetCookieWithCreationTimeWithOptions(
+ const GURL& url,
+ const std::string& cookie_line,
+ const base::Time& creation_time,
+ const CookieOptions& options);
+ virtual void SetCookies(const GURL& url,
+ const std::vector<std::string>& cookies);
+ virtual void SetCookiesWithOptions(const GURL& url,
+ const std::vector<std::string>& cookies,
+ const CookieOptions& options);
+ virtual std::string GetCookies(const GURL& url);
+ virtual std::string GetCookiesWithOptions(const GURL& url,
+ const CookieOptions& options);
+
+ virtual CookieMonster* GetCookieMonster() {
+ return this;
+ }
+
// Returns all the cookies, for use in management UI, etc. This does not mark
// the cookies as having been accessed.
CookieList GetAllCookies();
diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc
index d650d0f..bb36585 100644
--- a/net/base/cookie_monster_unittest.cc
+++ b/net/base/cookie_monster_unittest.cc
@@ -528,7 +528,7 @@ TEST(CookieMonsterTest, PathTest) {
TEST(CookieMonsterTest, HttpOnlyTest) {
GURL url_google(kUrlGoogle);
net::CookieMonster cm;
- net::CookieMonster::CookieOptions options;
+ net::CookieOptions options;
options.set_include_httponly();
// Create a httponly cookie.
@@ -693,7 +693,7 @@ TEST(CookieMonsterTest, TestCookieDeletion) {
TEST(CookieMonsterTest, TestCookieDeleteAll) {
GURL url_google(kUrlGoogle);
net::CookieMonster cm;
- net::CookieMonster::CookieOptions options;
+ net::CookieOptions options;
options.set_include_httponly();
EXPECT_TRUE(cm.SetCookie(url_google, kValidCookieLine));
diff --git a/net/base/cookie_options.h b/net/base/cookie_options.h
new file mode 100644
index 0000000..e9301fe
--- /dev/null
+++ b/net/base/cookie_options.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Brought to you by number 42.
+
+#ifndef NET_BASE_COOKIE_OPTIONS_H_
+#define NET_BASE_COOKIE_OPTIONS_H_
+
+namespace net {
+
+class CookieOptions {
+ public:
+ // Default is to exclude httponly, which means:
+ // - reading operations will not return httponly cookies.
+ // - writing operations will not write httponly cookies.
+ CookieOptions() : exclude_httponly_(true) {}
+ void set_exclude_httponly() { exclude_httponly_ = true; }
+ void set_include_httponly() { exclude_httponly_ = false; }
+ bool exclude_httponly() const { return exclude_httponly_; }
+ private:
+ bool exclude_httponly_;
+};
+} // namespace net
+
+#endif // NET_BASE_COOKIE_OPTIONS_H_
+
diff --git a/net/base/cookie_policy.h b/net/base/cookie_policy.h
index 4c01705..8efe998 100644
--- a/net/base/cookie_policy.h
+++ b/net/base/cookie_policy.h
@@ -38,7 +38,11 @@ class CookiePolicy {
// Sets the current policy to enforce. This should be called when the user's
// preferences change.
- void SetType(Type type) { type_ = type; }
+ void set_type(Type type) { type_ = type; }
+
+ Type type() const {
+ return type_;
+ }
CookiePolicy();
diff --git a/net/base/cookie_policy_unittest.cc b/net/base/cookie_policy_unittest.cc
index 982b250..22cf59e 100644
--- a/net/base/cookie_policy_unittest.cc
+++ b/net/base/cookie_policy_unittest.cc
@@ -37,7 +37,7 @@ TEST_F(CookiePolicyTest, DefaultPolicyTest) {
TEST_F(CookiePolicyTest, AllowAllCookiesTest) {
net::CookiePolicy cp;
- cp.SetType(net::CookiePolicy::ALLOW_ALL_COOKIES);
+ cp.set_type(net::CookiePolicy::ALLOW_ALL_COOKIES);
EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_));
EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_secure_));
@@ -54,7 +54,7 @@ TEST_F(CookiePolicyTest, AllowAllCookiesTest) {
TEST_F(CookiePolicyTest, BlockThirdPartyCookiesTest) {
net::CookiePolicy cp;
- cp.SetType(net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
+ cp.set_type(net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_));
EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_secure_));
@@ -71,7 +71,7 @@ TEST_F(CookiePolicyTest, BlockThirdPartyCookiesTest) {
TEST_F(CookiePolicyTest, BlockAllCookiesTest) {
net::CookiePolicy cp;
- cp.SetType(net::CookiePolicy::BLOCK_ALL_COOKIES);
+ cp.set_type(net::CookiePolicy::BLOCK_ALL_COOKIES);
EXPECT_FALSE(cp.CanGetCookies(url_google_, url_google_));
EXPECT_FALSE(cp.CanGetCookies(url_google_, url_google_secure_));
diff --git a/net/base/cookie_store.h b/net/base/cookie_store.h
new file mode 100644
index 0000000..3fa33b9
--- /dev/null
+++ b/net/base/cookie_store.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Brought to you by number 42.
+
+#ifndef NET_BASE_COOKIE_STORE_H_
+#define NET_BASE_COOKIE_STORE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/time.h"
+#include "net/base/cookie_options.h"
+
+class GURL;
+
+namespace net {
+
+class CookieMonster;
+
+// An interface for storing and retrieving cookies. Implementations need to
+// be therad safe as its methods can be accessed from IO as well as UI threads.
+class CookieStore {
+ public:
+ // Set a single cookie. Expects a cookie line, like "a=1; domain=b.com".
+ virtual bool SetCookie(const GURL& url, const std::string& cookie_line) = 0;
+ virtual bool SetCookieWithOptions(const GURL& url,
+ const std::string& cookie_line,
+ const CookieOptions& options) = 0;
+ // Sets a single cookie with a specific creation date. To set a cookie with
+ // a creation date of Now() use SetCookie() instead (it calls this function
+ // internally).
+ virtual bool SetCookieWithCreationTime(const GURL& url,
+ const std::string& cookie_line,
+ const base::Time& creation_time) = 0;
+ virtual bool SetCookieWithCreationTimeWithOptions(
+ const GURL& url,
+ const std::string& cookie_line,
+ const base::Time& creation_time,
+ const CookieOptions& options) = 0;
+ // Set a vector of response cookie values for the same URL.
+ virtual void SetCookies(const GURL& url,
+ const std::vector<std::string>& cookies) = 0;
+ virtual void SetCookiesWithOptions(const GURL& url,
+ const std::vector<std::string>& cookies,
+ const CookieOptions& options) = 0;
+
+ // TODO what if the total size of all the cookies >4k, can we have a header
+ // that big or do we need multiple Cookie: headers?
+ // Simple interface, get a cookie string "a=b; c=d" for the given URL.
+ // It will _not_ return httponly cookies, see CookieOptions.
+ virtual std::string GetCookies(const GURL& url) = 0;
+ virtual std::string GetCookiesWithOptions(const GURL& url,
+ const CookieOptions& options) = 0;
+
+ virtual CookieMonster* GetCookieMonster() {
+ return NULL;
+ };
+};
+
+} // namespace net
+
+#endif // NET_BASE_COOKIE_STORE_H_