diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-29 16:07:21 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-29 16:07:21 +0000 |
commit | 971713ef6b3cb00c871a3420b890c0feeb80d605 (patch) | |
tree | 0df6925f83f162737a2b7813a5e19e7a6b8f228a | |
parent | 2add77b802f0f5cab795a0a4d9ecb48003447d51 (diff) | |
download | chromium_src-971713ef6b3cb00c871a3420b890c0feeb80d605.zip chromium_src-971713ef6b3cb00c871a3420b890c0feeb80d605.tar.gz chromium_src-971713ef6b3cb00c871a3420b890c0feeb80d605.tar.bz2 |
DevTools: Implement raw cookies access for inspector.
Review URL: http://codereview.chromium.org/294025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30457 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/child_process_security_policy.cc | 48 | ||||
-rw-r--r-- | chrome/browser/child_process_security_policy.h | 13 | ||||
-rw-r--r-- | chrome/browser/debugger/devtools_manager.cc | 51 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 50 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 9 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 31 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 12 | ||||
-rw-r--r-- | chrome/renderer/renderer_webkitclient_impl.cc | 36 | ||||
-rw-r--r-- | chrome/renderer/renderer_webkitclient_impl.h | 5 | ||||
-rw-r--r-- | net/base/cookie_monster.cc | 32 | ||||
-rw-r--r-- | net/base/cookie_monster.h | 3 | ||||
-rw-r--r-- | webkit/api/public/WebCookie.h | 77 | ||||
-rw-r--r-- | webkit/api/public/WebKitClient.h | 4 | ||||
-rw-r--r-- | webkit/glue/webcookie.h | 66 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 18 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.h | 5 | ||||
-rw-r--r-- | webkit/webkit.gyp | 2 |
17 files changed, 435 insertions, 27 deletions
diff --git a/chrome/browser/child_process_security_policy.cc b/chrome/browser/child_process_security_policy.cc index 7f009e9..635e0cf 100644 --- a/chrome/browser/child_process_security_policy.cc +++ b/chrome/browser/child_process_security_policy.cc @@ -17,7 +17,9 @@ // information. class ChildProcessSecurityPolicy::SecurityState { public: - SecurityState() : enabled_bindings_(0) { } + SecurityState() + : enabled_bindings_(0), + can_read_raw_cookies_(false) { } ~SecurityState() { scheme_policy_.clear(); } @@ -41,6 +43,14 @@ class ChildProcessSecurityPolicy::SecurityState { enabled_bindings_ |= bindings; } + void GrantReadRawCookies() { + can_read_raw_cookies_ = true; + } + + void RevokeReadRawCookies() { + can_read_raw_cookies_ = false; + } + // Determine whether permission has been granted to request url. // Schemes that have not been granted default to being denied. bool CanRequestURL(const GURL& url) { @@ -66,6 +76,10 @@ class ChildProcessSecurityPolicy::SecurityState { return BindingsPolicy::is_extension_enabled(enabled_bindings_); } + bool can_read_raw_cookies() const { + return can_read_raw_cookies_; + } + private: typedef std::map<std::string, bool> SchemeMap; typedef std::set<FilePath> FileSet; @@ -82,6 +96,8 @@ class ChildProcessSecurityPolicy::SecurityState { int enabled_bindings_; + bool can_read_raw_cookies_; + DISALLOW_COPY_AND_ASSIGN(SecurityState); }; @@ -252,6 +268,26 @@ void ChildProcessSecurityPolicy::GrantExtensionBindings(int renderer_id) { state->second->GrantBindings(BindingsPolicy::EXTENSION); } +void ChildProcessSecurityPolicy::GrantReadRawCookies(int renderer_id) { + AutoLock lock(lock_); + + SecurityStateMap::iterator state = security_state_.find(renderer_id); + if (state == security_state_.end()) + return; + + state->second->GrantReadRawCookies(); +} + +void ChildProcessSecurityPolicy::RevokeReadRawCookies(int renderer_id) { + AutoLock lock(lock_); + + SecurityStateMap::iterator state = security_state_.find(renderer_id); + if (state == security_state_.end()) + return; + + state->second->RevokeReadRawCookies(); +} + bool ChildProcessSecurityPolicy::CanRequestURL( int renderer_id, const GURL& url) { if (!url.is_valid()) @@ -325,3 +361,13 @@ bool ChildProcessSecurityPolicy::HasExtensionBindings(int renderer_id) { return state->second->has_extension_bindings(); } + +bool ChildProcessSecurityPolicy::CanReadRawCookies(int renderer_id) { + AutoLock lock(lock_); + + SecurityStateMap::iterator state = security_state_.find(renderer_id); + if (state == security_state_.end()) + return false; + + return state->second->can_read_raw_cookies(); +} diff --git a/chrome/browser/child_process_security_policy.h b/chrome/browser/child_process_security_policy.h index 402cd1b..9cde10a 100644 --- a/chrome/browser/child_process_security_policy.h +++ b/chrome/browser/child_process_security_policy.h @@ -80,6 +80,12 @@ class ChildProcessSecurityPolicy { // Grant this renderer the ability to use extension Bindings. void GrantExtensionBindings(int renderer_id); + // Grant this renderer the ability to read raw cookies. + void GrantReadRawCookies(int renderer_id); + + // Revoke read raw cookies permission. + void RevokeReadRawCookies(int renderer_id); + // Before servicing a renderer's request for a URL, the browser should call // this method to determine whether the renderer has the capability to // request the URL. @@ -90,16 +96,19 @@ class ChildProcessSecurityPolicy { // capability to upload the requested file. bool CanUploadFile(int renderer_id, const FilePath& file); - // Returns true of the specified renderer_id has been granted DOMUIBindings. + // Returns true if the specified renderer_id has been granted DOMUIBindings. // The browser should check this property before assuming the renderer is // allowed to use DOMUIBindings. bool HasDOMUIBindings(int renderer_id); - // Returns true of the specified renderer_id has been granted DOMUIBindings. + // Returns true if the specified renderer_id has been granted DOMUIBindings. // The browser should check this property before assuming the renderer is // allowed to use extension bindings. bool HasExtensionBindings(int renderer_id); + // Returns true if the specified renderer_id has been granted ReadRawCookies. + bool CanReadRawCookies(int renderer_id); + private: friend class ChildProcessSecurityPolicyInProcessBrowserTest; FRIEND_TEST(ChildProcessSecurityPolicyInProcessBrowserTest, NoLeak); diff --git a/chrome/browser/debugger/devtools_manager.cc b/chrome/browser/debugger/devtools_manager.cc index bff379c..cc8cb22 100644 --- a/chrome/browser/debugger/devtools_manager.cc +++ b/chrome/browser/debugger/devtools_manager.cc @@ -7,6 +7,7 @@ #include "base/message_loop.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browsing_instance.h" +#include "chrome/browser/child_process_security_policy.h" #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/debugger/devtools_client_host.h" #include "chrome/browser/profile.h" @@ -42,9 +43,8 @@ DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( RenderViewHost* inspected_rvh) { InspectedRvhToClientHostMap::iterator it = inspected_rvh_to_client_host_.find(inspected_rvh); - if (it != inspected_rvh_to_client_host_.end()) { + if (it != inspected_rvh_to_client_host_.end()) return it->second; - } return NULL; } @@ -64,9 +64,8 @@ void DevToolsManager::ForwardToDevToolsAgent( RenderViewHost* client_rvh, const IPC::Message& message) { DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); - if (client_host) { + if (client_host) ForwardToDevToolsAgent(client_host, message); - } } void DevToolsManager::ForwardToDevToolsAgent(DevToolsClientHost* from, @@ -96,9 +95,9 @@ void DevToolsManager::ForwardToDevToolsClient(RenderViewHost* inspected_rvh, void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); - if (!client_host) { + if (!client_host) return; - } + DevToolsWindow* window = client_host->AsDevToolsWindow(); DCHECK(window); window->Activate(); @@ -106,9 +105,8 @@ void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { void DevToolsManager::CloseWindow(RenderViewHost* client_rvh) { DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); - if (client_host) { + if (client_host) CloseWindow(client_host); - } } void DevToolsManager::DockWindow(RenderViewHost* client_rvh) { @@ -147,9 +145,8 @@ void DevToolsManager::InspectElement(RenderViewHost* inspected_rvh, void DevToolsManager::ClientHostClosing(DevToolsClientHost* host) { RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(host); - if (!inspected_rvh) { + if (!inspected_rvh) return; - } SendDetachToAgent(inspected_rvh); inspected_rvh_to_client_host_.erase(inspected_rvh); @@ -160,26 +157,34 @@ RenderViewHost* DevToolsManager::GetInspectedRenderViewHost( DevToolsClientHost* client_host) { ClientHostToInspectedRvhMap::iterator it = client_host_to_inspected_rvh_.find(client_host); - if (it != client_host_to_inspected_rvh_.end()) { + if (it != client_host_to_inspected_rvh_.end()) return it->second; - } return NULL; } void DevToolsManager::UnregisterDevToolsClientHostFor( RenderViewHost* inspected_rvh) { DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); - if (!host) { + if (!host) return; - } inspected_rvh_to_client_host_.erase(inspected_rvh); client_host_to_inspected_rvh_.erase(host); - if (inspected_rvh_for_reopen_ == inspected_rvh) { + if (inspected_rvh_for_reopen_ == inspected_rvh) inspected_rvh_for_reopen_ = NULL; - } // Issue tab closing event post unbound. host->InspectedTabClosing(); + + int process_id = inspected_rvh->process()->id(); + for (InspectedRvhToClientHostMap::iterator it = + inspected_rvh_to_client_host_.begin(); + it != inspected_rvh_to_client_host_.end(); + ++it) { + if (it->first->process()->id() == process_id) + return; + } + // We've disconnected from the last renderer -> revoke cookie permissions. + ChildProcessSecurityPolicy::GetInstance()->RevokeReadRawCookies(process_id); } void DevToolsManager::OnNavigatingToPendingEntry(RenderViewHost* rvh, @@ -219,6 +224,8 @@ void DevToolsManager::OnNavigatingToPendingEntry(RenderViewHost* rvh, void DevToolsManager::SendAttachToAgent(RenderViewHost* inspected_rvh) { if (inspected_rvh) { + ChildProcessSecurityPolicy::GetInstance()->GrantReadRawCookies( + inspected_rvh->process()->id()); IPC::Message* m = new DevToolsAgentMsg_Attach(); m->set_routing_id(inspected_rvh->routing_id()); inspected_rvh->Send(m); @@ -249,21 +256,18 @@ DevToolsClientHost* DevToolsManager::FindOnwerDevToolsClientHost( it != inspected_rvh_to_client_host_.end(); ++it) { DevToolsWindow* win = it->second->AsDevToolsWindow(); - if (!win) { + if (!win) continue; - } - if (client_rvh == win->GetRenderViewHost()) { + if (client_rvh == win->GetRenderViewHost()) return it->second; - } } return NULL; } void DevToolsManager::ReopenWindow(RenderViewHost* client_rvh, bool docked) { DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); - if (!client_host) { + if (!client_host) return; - } RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); DCHECK(inspected_rvh); inspected_rvh->process()->profile()->GetPrefs()->SetBoolean( @@ -294,9 +298,8 @@ void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh, do_open = true; } DevToolsWindow* window = host->AsDevToolsWindow(); - if (!window) { + if (!window) return; - } // If window is docked and visible, we hide it on toggle. If window is // undocked, we show (activate) it. diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 046ea92..4d0d451 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -47,6 +47,7 @@ #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "chrome/common/worker_messages.h" +#include "net/base/cookie_monster.h" #include "net/base/keygen_handler.h" #include "net/base/mime_util.h" #include "net/base/load_flags.h" @@ -295,6 +296,8 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget) IPC_MESSAGE_HANDLER(ViewHostMsg_SetCookie, OnSetCookie) IPC_MESSAGE_HANDLER(ViewHostMsg_GetCookies, OnGetCookies) + IPC_MESSAGE_HANDLER(ViewHostMsg_GetRawCookies, OnGetRawCookies) + IPC_MESSAGE_HANDLER(ViewHostMsg_DeleteCookie, OnDeleteCookie) #if defined(OS_WIN) // This hack is Windows-specific. IPC_MESSAGE_HANDLER(ViewHostMsg_LoadFont, OnLoadFont) #endif @@ -502,6 +505,53 @@ void ResourceMessageFilter::OnGetCookies(const GURL& url, *cookies = context->cookie_store()->GetCookies(url); } +void ResourceMessageFilter::OnGetRawCookies( + const GURL& url, + const GURL& first_party_for_cookies, + std::vector<webkit_glue::WebCookie>* raw_cookies) { + raw_cookies->clear(); + + URLRequestContext* context = GetRequestContextForURL(url); + net::CookieMonster* cookie_monster = context->cookie_store()-> + GetCookieMonster(); + if (!cookie_monster) { + NOTREACHED(); + return; + } + + if (!context->cookie_policy()->CanGetCookies(url, first_party_for_cookies)) + return; + + typedef std::vector<net::CookieMonster::CanonicalCookie> CanonicalCookieList; + CanonicalCookieList cookies; + cookie_monster->GetRawCookies(url, &cookies); + for (CanonicalCookieList::iterator it = cookies.begin(); + it != cookies.end(); ++it) { + raw_cookies->push_back( + webkit_glue::WebCookie( + it->Name(), + it->Value(), + url.host(), + it->Path(), + it->ExpiryDate().ToDoubleT() * 1000, + it->IsHttpOnly(), + it->IsSecure(), + !it->IsPersistent())); + } +} + +void ResourceMessageFilter::OnDeleteCookie(const GURL& url, + const std::string& cookie_name) +{ + URLRequestContext* context = GetRequestContextForURL(url); + net::CookieMonster* cookie_monster = context->cookie_store()-> + GetCookieMonster(); + if (!cookie_monster) + return; + + cookie_monster->DeleteCookie(url, cookie_name); +} + #if defined(OS_WIN) // This hack is Windows-specific. void ResourceMessageFilter::OnLoadFont(LOGFONT font) { // If renderer is running in a sandbox, GetTextMetrics diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 0134c37..1a91466 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -50,6 +50,10 @@ class PrinterQuery; class PrintJobManager; } +namespace webkit_glue { +struct WebCookie; +} + namespace WebKit { struct WebScreenInfo; } @@ -124,6 +128,11 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnGetCookies(const GURL& url, const GURL& first_party_for_cookies, std::string* cookies); + void OnGetRawCookies(const GURL& url, + const GURL& first_party_for_cookies, + std::vector<webkit_glue::WebCookie>* raw_cookies); + void OnDeleteCookie(const GURL& url, + const std::string& cookieName); void OnPluginFileDialog(const IPC::Message& msg, bool multiple_files, const std::wstring& title, diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 3a12c49..5ce13c5 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -43,6 +43,7 @@ #include "webkit/glue/password_form_dom_manager.h" #include "webkit/glue/resource_loader_bridge.h" #include "webkit/glue/webaccessibility.h" +#include "webkit/glue/webcookie.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webmenuitem.h" #include "webkit/glue/webplugin.h" @@ -2124,6 +2125,36 @@ struct ParamTraits<DOMStorageType> { } }; +// Traits for WebCookie +template <> +struct ParamTraits<webkit_glue::WebCookie> { + typedef webkit_glue::WebCookie param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, p.name); + WriteParam(m, p.value); + WriteParam(m, p.domain); + WriteParam(m, p.path); + WriteParam(m, p.expires); + WriteParam(m, p.http_only); + WriteParam(m, p.secure); + WriteParam(m, p.session); + } + static bool Read(const Message* m, void** iter, param_type* p) { + return + ReadParam(m, iter, &p->name) && + ReadParam(m, iter, &p->value) && + ReadParam(m, iter, &p->domain) && + ReadParam(m, iter, &p->path) && + ReadParam(m, iter, &p->expires) && + ReadParam(m, iter, &p->http_only) && + ReadParam(m, iter, &p->secure) && + ReadParam(m, iter, &p->session); + } + static void Log(const param_type& p, std::wstring* l) { + l->append(L"<WebCookie>"); + } +}; + } // namespace IPC diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index ceebdea..cecc9fc6 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1048,6 +1048,18 @@ IPC_BEGIN_MESSAGES(ViewHost) GURL /* first_party_for_cookies */, std::string /* cookies */) + // Used to get raw cookie information for the given URL + IPC_SYNC_MESSAGE_CONTROL2_1(ViewHostMsg_GetRawCookies, + GURL /* url */, + GURL /* first_party_for_cookies */, + std::vector<webkit_glue::WebCookie> + /* raw_cookies */) + + // Used to delete cookie for the given URL and name + IPC_SYNC_MESSAGE_CONTROL2_0(ViewHostMsg_DeleteCookie, + GURL /* url */, + std::string /* cookie_name */) + // Used to get the list of plugins IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetPlugins, bool /* refresh*/, diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc index 1f95c1ff..9affc08 100644 --- a/chrome/renderer/renderer_webkitclient_impl.cc +++ b/chrome/renderer/renderer_webkitclient_impl.cc @@ -24,8 +24,10 @@ #include "chrome/renderer/renderer_webstoragenamespace_impl.h" #include "chrome/renderer/visitedlink_slave.h" #include "googleurl/src/gurl.h" +#include "webkit/api/public/WebCookie.h" #include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURL.h" +#include "webkit/api/public/WebVector.h" #include "webkit/appcache/web_application_cache_host_impl.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/webkit_glue.h" @@ -40,11 +42,13 @@ using WebKit::WebApplicationCacheHost; using WebKit::WebApplicationCacheHostClient; +using WebKit::WebCookie; using WebKit::WebKitClient; using WebKit::WebStorageArea; using WebKit::WebStorageNamespace; using WebKit::WebString; using WebKit::WebURL; +using WebKit::WebVector; //------------------------------------------------------------------------------ @@ -120,6 +124,38 @@ WebString RendererWebKitClientImpl::cookies( return WebString::fromUTF8(value_utf8); } +bool RendererWebKitClientImpl::rawCookies( + const WebURL& url, + const WebURL& first_party_for_cookies, + WebVector<WebKit::WebCookie>* raw_cookies) { + std::vector<webkit_glue::WebCookie> cookies; + RenderThread::current()->Send( + new ViewHostMsg_GetRawCookies(url, first_party_for_cookies, &cookies)); + + WebVector<WebKit::WebCookie> result(cookies.size()); + int i = 0; + for (std::vector<webkit_glue::WebCookie>::iterator it = cookies.begin(); + it != cookies.end(); ++it) + result[i++] = WebKit::WebCookie(WebString::fromUTF8(it->name), + WebString::fromUTF8(it->value), + WebString::fromUTF8(it->domain), + WebString::fromUTF8(it->path), + it->expires, + it->http_only, + it->secure, + it->session); + raw_cookies->assign(result); + return true; +} + +void RendererWebKitClientImpl::deleteCookie(const WebURL& url, + const WebString& cookie_name) { + std::string cookie_name_utf8; + UTF16ToUTF8(cookie_name.data(), cookie_name.length(), &cookie_name_utf8); + RenderThread::current()->Send( + new ViewHostMsg_DeleteCookie(url, cookie_name_utf8)); +} + void RendererWebKitClientImpl::prefetchHostName(const WebString& hostname) { if (!hostname.isEmpty()) { std::string hostname_utf8; diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h index c5ac687..79e56fc 100644 --- a/chrome/renderer/renderer_webkitclient_impl.h +++ b/chrome/renderer/renderer_webkitclient_impl.h @@ -38,6 +38,11 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { const WebKit::WebString&); virtual WebKit::WebString cookies( const WebKit::WebURL& url, const WebKit::WebURL& first_party_for_cookies); + virtual bool rawCookies(const WebKit::WebURL& url, + const WebKit::WebURL& first_party_for_cookies, + WebKit::WebVector<WebKit::WebCookie>* raw_cookies); + virtual void deleteCookie(const WebKit::WebURL& url, + const WebKit::WebString& cookie_name); virtual void prefetchHostName(const WebKit::WebString&); virtual WebKit::WebString defaultLocale(); virtual void suddenTerminationChanged(bool enabled); diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index e20c03d..2c2f21d 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -769,6 +769,38 @@ std::string CookieMonster::GetCookiesWithOptions(const GURL& url, return cookie_line; } +void CookieMonster::GetRawCookies(const GURL& url, + std::vector<CanonicalCookie>* raw_cookies) { + raw_cookies->clear(); + if (!HasCookieableScheme(url)) + return; + + CookieOptions options; + options.set_include_httponly(); + // Get the cookies for this host and its domain(s). + std::vector<CanonicalCookie*> cookies; + FindCookiesForHostAndDomain(url, options, &cookies); + std::sort(cookies.begin(), cookies.end(), CookieSorter); + + for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); + it != cookies.end(); ++it) + raw_cookies->push_back(*(*it)); +} + +void CookieMonster::DeleteCookie(const GURL& url, + const std::string& cookie_name) { + if (!HasCookieableScheme(url)) + return; + + for (CookieMapItPair its = cookies_.equal_range(url.host()); + its.first != its.second; ++its.first) { + if (its.first->second->Name() == cookie_name) { + InternalDeleteCookie(its.first, true); + return; + } + } +} + CookieMonster::CookieList CookieMonster::GetAllCookies() { AutoLock autolock(lock_); InitIfNecessary(); diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index f388fef..7b8362d 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -95,6 +95,9 @@ class CookieMonster : public CookieStore { virtual std::string GetCookies(const GURL& url); virtual std::string GetCookiesWithOptions(const GURL& url, const CookieOptions& options); + virtual void GetRawCookies(const GURL& url, + std::vector<CanonicalCookie>* raw_cookies); + virtual void DeleteCookie(const GURL& url, const std::string& cookie_name); virtual CookieMonster* GetCookieMonster() { return this; diff --git a/webkit/api/public/WebCookie.h b/webkit/api/public/WebCookie.h new file mode 100644 index 0000000..02cbdde1 --- /dev/null +++ b/webkit/api/public/WebCookie.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebCookie_h +#define WebCookie_h + +#include "WebCommon.h" +#include "WebString.h" + +namespace WebKit { + + class WebString; + + // A cookie. + // + struct WebCookie { + WebCookie() + : expires(0) + , httpOnly(false) + , secure(false) + , session(false) + { + } + + WebCookie(const WebString& name, const WebString& value, const WebString& domain, + const WebString& path, double expires, bool httpOnly, bool secure, bool session) + : name(name) + , value(value) + , domain(domain) + , path(path) + , expires(expires) + , httpOnly(httpOnly) + , secure(secure) + , session(session) + { + } + + WebString name; + WebString value; + WebString domain; + WebString path; + double expires; + bool httpOnly; + bool secure; + bool session; + }; + +} // namespace WebKit + +#endif diff --git a/webkit/api/public/WebKitClient.h b/webkit/api/public/WebKitClient.h index 9d742a3..a3076a4 100644 --- a/webkit/api/public/WebKitClient.h +++ b/webkit/api/public/WebKitClient.h @@ -35,6 +35,7 @@ #include "WebCommon.h" #include "WebLocalizedString.h" +#include "WebVector.h" #include "webkit/api/src/TemporaryGlue.h" #ifdef WIN32 @@ -56,6 +57,7 @@ namespace WebKit { class WebThemeEngine; class WebURL; class WebURLLoader; + struct WebCookie; struct WebPluginInfo; template <typename T> class WebVector; @@ -169,6 +171,8 @@ namespace WebKit { virtual void setCookies( const WebURL& url, const WebURL& policyURL, const WebString& cookies) = 0; virtual WebString cookies(const WebURL& url, const WebURL& policyURL) = 0; + virtual bool rawCookies(const WebURL& url, const WebURL& policyURL, WebVector<WebCookie>*) = 0; + virtual void deleteCookie(const WebURL& url, const WebString& cookieName) = 0; // A suggestion to prefetch IP information for the given hostname. virtual void prefetchHostName(const WebString&) = 0; diff --git a/webkit/glue/webcookie.h b/webkit/glue/webcookie.h new file mode 100644 index 0000000..4966c442 --- /dev/null +++ b/webkit/glue/webcookie.h @@ -0,0 +1,66 @@ +// Copyright (c) 2006-2008 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. +// +// A struct for managing data being dropped on a webview. This represents a +// union of all the types of data that can be dropped in a platform neutral +// way. + +#ifndef WEBKIT_GLUE_WEBCOOKIE_H_ +#define WEBKIT_GLUE_WEBCOOKIE_H_ + +#include <string> + +namespace webkit_glue { + +struct WebCookie { + + WebCookie(const std::string& name, const std::string& value, + const std::string& domain, const std::string& path, double expires, + bool http_only, bool secure, bool session) + : name(name), + value(value), + domain(domain), + path(path), + expires(expires), + http_only(http_only), + secure(secure), + session(session) { + } + + // For default constructions. + WebCookie() : + expires(0), + http_only(false), + secure(false), + session(false) { + } + + // Cookie name. + std::string name; + + // Cookie value. + std::string value; + + // Cookie domain. + std::string domain; + + // Cookie path. + std::string path; + + // Cookie expires param if any. + double expires; + + // Cookie HTTPOnly param. + bool http_only; + + // Cookie secure param. + bool secure; + + // Session cookie flag. + bool session; +}; + +} // namespace webkit_glue + +#endif // WEBKIT_GLUE_WEBCOOKIE_H_ diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index 2d2e27f..e3fd73f 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -22,12 +22,15 @@ #include "grit/webkit_resources.h" #include "grit/webkit_strings.h" #include "net/base/net_util.h" +#include "webkit/api/public/WebCookie.h" #include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebData.h" #include "webkit/api/public/WebFrameClient.h" #include "webkit/api/public/WebPluginListBuilder.h" #include "webkit/api/public/WebScreenInfo.h" #include "webkit/api/public/WebString.h" +#include "webkit/api/public/WebVector.h" +#include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebViewClient.h" #include "webkit/api/src/ChromeClientImpl.h" #include "webkit/glue/glue_util.h" @@ -42,6 +45,7 @@ using WebKit::ChromeClientImpl; using WebKit::WebApplicationCacheHost; using WebKit::WebApplicationCacheHostClient; +using WebKit::WebCookie; using WebKit::WebCursorInfo; using WebKit::WebData; using WebKit::WebLocalizedString; @@ -50,7 +54,9 @@ using WebKit::WebStorageNamespace; using WebKit::WebString; using WebKit::WebSocketStreamHandle; using WebKit::WebThemeEngine; +using WebKit::WebURL; using WebKit::WebURLLoader; +using WebKit::WebVector; using WebKit::WebWidgetClient; namespace { @@ -153,6 +159,18 @@ WebThemeEngine* WebKitClientImpl::themeEngine() { #endif } +bool WebKitClientImpl::rawCookies(const WebURL& url, + const WebURL& policy_url, + WebVector<WebCookie>* raw_cookies) { + NOTREACHED(); + return false; +} + +void WebKitClientImpl::deleteCookie(const WebURL& url, + const WebString& cookie_name) { + NOTREACHED(); +} + WebURLLoader* WebKitClientImpl::createURLLoader() { return new WebURLLoaderImpl(); } diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h index e6f5c42..284d6d3 100644 --- a/webkit/glue/webkitclient_impl.h +++ b/webkit/glue/webkitclient_impl.h @@ -22,6 +22,11 @@ class WebKitClientImpl : public WebKit::WebKitClient { // WebKitClient methods (partial implementation): virtual WebKit::WebThemeEngine* themeEngine(); + virtual bool rawCookies(const WebKit::WebURL& url, + const WebKit::WebURL& policy_url, + WebKit::WebVector<WebKit::WebCookie>*); + virtual void deleteCookie(const WebKit::WebURL& url, + const WebKit::WebString& cookie_name); virtual WebKit::WebURLLoader* createURLLoader(); virtual WebKit::WebSocketStreamHandle* createSocketStreamHandle(); virtual void getPluginList(bool refresh, WebKit::WebPluginListBuilder*); diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index aa22025..bea1e1c 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -89,6 +89,7 @@ 'api/public/WebCompositionCommand.h', 'api/public/WebConsoleMessage.h', 'api/public/WebContextMenuData.h', + 'api/public/WebCookie.h', 'api/public/WebCrossOriginPreflightResultCache.h', 'api/public/WebCString.h', 'api/public/WebCursorInfo.h', @@ -626,6 +627,7 @@ 'glue/webaccessibilitymanager_impl.h', 'glue/webclipboard_impl.cc', 'glue/webclipboard_impl.h', + 'glue/webcookie.h', 'glue/webcursor.cc', 'glue/webcursor.h', 'glue/webcursor_gtk.cc', |