mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Update to Chromium revision 149431.
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@730 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -4,7 +4,9 @@
|
||||
|
||||
#include "libcef/browser/cookie_manager_impl.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "libcef/browser/browser_context.h"
|
||||
#include "libcef/browser/context.h"
|
||||
@ -20,6 +22,7 @@
|
||||
#include "chrome/browser/net/sqlite_persistent_cookie_store.h"
|
||||
#include "googleurl/src/gurl.h"
|
||||
#include "net/cookies/cookie_util.h"
|
||||
#include "net/cookies/parsed_cookie.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
|
||||
namespace {
|
||||
@ -41,7 +44,7 @@ class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
|
||||
net::CookieList::const_iterator it = list.begin();
|
||||
for (; it != list.end(); ++it, ++count) {
|
||||
CefCookie cookie;
|
||||
const net::CookieMonster::CanonicalCookie& cc = *(it);
|
||||
const net::CanonicalCookie& cc = *(it);
|
||||
CefCookieManagerImpl::GetCefCookie(cc, cookie);
|
||||
|
||||
bool deleteCookie = false;
|
||||
@ -65,7 +68,7 @@ class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
|
||||
|
||||
// Determine the cookie domain to use for setting the specified cookie.
|
||||
bool GetCookieDomain(const GURL& url,
|
||||
const net::CookieMonster::ParsedCookie& pc,
|
||||
const net::ParsedCookie& pc,
|
||||
std::string* result) {
|
||||
std::string domain_string;
|
||||
if (pc.HasDomain())
|
||||
@ -74,66 +77,6 @@ bool GetCookieDomain(const GURL& url,
|
||||
result);
|
||||
}
|
||||
|
||||
std::string CanonPathWithString(const GURL& url,
|
||||
const std::string& path_string) {
|
||||
// The RFC says the path should be a prefix of the current URL path.
|
||||
// However, Mozilla allows you to set any path for compatibility with
|
||||
// broken websites. We unfortunately will mimic this behavior. We try
|
||||
// to be generous and accept cookies with an invalid path attribute, and
|
||||
// default the path to something reasonable.
|
||||
|
||||
// The path was supplied in the cookie, we'll take it.
|
||||
if (!path_string.empty() && path_string[0] == '/')
|
||||
return path_string;
|
||||
|
||||
// The path was not supplied in the cookie or invalid, we will default
|
||||
// to the current URL path.
|
||||
// """Defaults to the path of the request URL that generated the
|
||||
// Set-Cookie response, up to, but not including, the
|
||||
// right-most /."""
|
||||
// How would this work for a cookie on /? We will include it then.
|
||||
const std::string& url_path = url.path();
|
||||
|
||||
size_t idx = url_path.find_last_of('/');
|
||||
|
||||
// The cookie path was invalid or a single '/'.
|
||||
if (idx == 0 || idx == std::string::npos)
|
||||
return std::string("/");
|
||||
|
||||
// Return up to the rightmost '/'.
|
||||
return url_path.substr(0, idx);
|
||||
}
|
||||
|
||||
std::string CanonPath(const GURL& url,
|
||||
const net::CookieMonster::ParsedCookie& pc) {
|
||||
std::string path_string;
|
||||
if (pc.HasPath())
|
||||
path_string = pc.Path();
|
||||
return CanonPathWithString(url, path_string);
|
||||
}
|
||||
|
||||
base::Time CanonExpiration(const net::CookieMonster::ParsedCookie& pc,
|
||||
const base::Time& current) {
|
||||
// First, try the Max-Age attribute.
|
||||
uint64 max_age = 0;
|
||||
if (pc.HasMaxAge() &&
|
||||
#ifdef COMPILER_MSVC
|
||||
sscanf_s(
|
||||
#else
|
||||
sscanf(
|
||||
#endif
|
||||
pc.MaxAge().c_str(), " %" PRIu64, &max_age) == 1) {
|
||||
return current + base::TimeDelta::FromSeconds(max_age);
|
||||
}
|
||||
|
||||
// Try the Expires attribute.
|
||||
if (pc.HasExpires())
|
||||
return net::CookieMonster::ParseCookieTime(pc.Expires());
|
||||
|
||||
// Invalid or no expiration, persistent cookie.
|
||||
return base::Time();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@ -318,7 +261,7 @@ bool CefCookieManagerImpl::SetStoragePath(const CefString& path) {
|
||||
GetCookieMonster();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (cookie_monster_ && ((storage_path_.empty() && path.empty()) ||
|
||||
storage_path_ == new_path)) {
|
||||
// The path has not changed so don't do anything.
|
||||
@ -373,9 +316,8 @@ void CefCookieManagerImpl::SetGlobal() {
|
||||
}
|
||||
|
||||
// static
|
||||
bool CefCookieManagerImpl::GetCefCookie(
|
||||
const net::CookieMonster::CanonicalCookie& cc,
|
||||
CefCookie& cookie) {
|
||||
bool CefCookieManagerImpl::GetCefCookie(const net::CanonicalCookie& cc,
|
||||
CefCookie& cookie) {
|
||||
CefString(&cookie.name).FromString(cc.Name());
|
||||
CefString(&cookie.value).FromString(cc.Value());
|
||||
CefString(&cookie.domain).FromString(cc.Domain());
|
||||
@ -384,7 +326,7 @@ bool CefCookieManagerImpl::GetCefCookie(
|
||||
cookie.httponly = cc.IsHttpOnly();
|
||||
cef_time_from_basetime(cc.CreationDate(), cookie.creation);
|
||||
cef_time_from_basetime(cc.LastAccessDate(), cookie.last_access);
|
||||
cookie.has_expires = cc.DoesExpire();
|
||||
cookie.has_expires = cc.IsPersistent();
|
||||
if (cookie.has_expires)
|
||||
cef_time_from_basetime(cc.ExpiryDate(), cookie.expires);
|
||||
|
||||
@ -396,7 +338,7 @@ bool CefCookieManagerImpl::GetCefCookie(const GURL& url,
|
||||
const std::string& cookie_line,
|
||||
CefCookie& cookie) {
|
||||
// Parse the cookie.
|
||||
net::CookieMonster::ParsedCookie pc(cookie_line);
|
||||
net::ParsedCookie pc(cookie_line);
|
||||
if (!pc.IsValid())
|
||||
return false;
|
||||
|
||||
@ -404,9 +346,10 @@ bool CefCookieManagerImpl::GetCefCookie(const GURL& url,
|
||||
if (!GetCookieDomain(url, pc, &cookie_domain))
|
||||
return false;
|
||||
|
||||
std::string cookie_path = CanonPath(url, pc);
|
||||
std::string cookie_path = net::CanonicalCookie::CanonPath(url, pc);
|
||||
base::Time creation_time = base::Time::Now();
|
||||
base::Time cookie_expires = CanonExpiration(pc, creation_time);
|
||||
base::Time cookie_expires =
|
||||
net::CanonicalCookie::CanonExpiration(pc, creation_time, creation_time);
|
||||
|
||||
CefString(&cookie.name).FromString(pc.Name());
|
||||
CefString(&cookie.value).FromString(pc.Value());
|
||||
|
Reference in New Issue
Block a user