summaryrefslogtreecommitdiffstats
path: root/android_webview/browser/aw_cookie_access_policy.cc
diff options
context:
space:
mode:
Diffstat (limited to 'android_webview/browser/aw_cookie_access_policy.cc')
-rw-r--r--android_webview/browser/aw_cookie_access_policy.cc84
1 files changed, 59 insertions, 25 deletions
diff --git a/android_webview/browser/aw_cookie_access_policy.cc b/android_webview/browser/aw_cookie_access_policy.cc
index 06e30605..e07db11 100644
--- a/android_webview/browser/aw_cookie_access_policy.cc
+++ b/android_webview/browser/aw_cookie_access_policy.cc
@@ -4,13 +4,17 @@
#include "android_webview/browser/aw_cookie_access_policy.h"
+#include "android_webview/browser/aw_contents_io_thread_client.h"
+
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/resource_request_info.h"
#include "net/base/net_errors.h"
using base::AutoLock;
using content::BrowserThread;
+using content::ResourceRequestInfo;
using net::StaticCookiePolicy;
namespace android_webview {
@@ -23,43 +27,59 @@ AwCookieAccessPolicy::~AwCookieAccessPolicy() {
}
AwCookieAccessPolicy::AwCookieAccessPolicy()
- : allow_access_(true),
- allow_third_party_access_(true) {
+ : accept_cookies_(true) {
}
AwCookieAccessPolicy* AwCookieAccessPolicy::GetInstance() {
return g_lazy_instance.Pointer();
}
-bool AwCookieAccessPolicy::GetGlobalAllowAccess() {
+bool AwCookieAccessPolicy::GetShouldAcceptCookies() {
AutoLock lock(lock_);
- return allow_access_;
+ return accept_cookies_;
}
-void AwCookieAccessPolicy::SetGlobalAllowAccess(bool allow) {
+void AwCookieAccessPolicy::SetShouldAcceptCookies(bool allow) {
AutoLock lock(lock_);
- allow_access_ = allow;
+ accept_cookies_ = allow;
}
-bool AwCookieAccessPolicy::GetThirdPartyAllowAccess() {
- AutoLock lock(lock_);
- return allow_third_party_access_;
+bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies(
+ int render_process_id,
+ int render_frame_id) {
+ scoped_ptr<AwContentsIoThreadClient> io_thread_client =
+ AwContentsIoThreadClient::FromID(render_process_id, render_frame_id);
+ if (!io_thread_client) {
+ return false;
+ }
+ return io_thread_client->ShouldAcceptThirdPartyCookies();
}
-void AwCookieAccessPolicy::SetThirdPartyAllowAccess(bool allow) {
- AutoLock lock(lock_);
- allow_third_party_access_ = allow;
+bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies(
+ const net::URLRequest& request) {
+ const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
+ if (!info) {
+ return false;
+ }
+ return GetShouldAcceptThirdPartyCookies(info->GetChildID(),
+ info->GetRenderFrameID());
}
bool AwCookieAccessPolicy::OnCanGetCookies(const net::URLRequest& request,
const net::CookieList& cookie_list) {
- return AllowGet(request.url(), request.first_party_for_cookies());
+ bool global = GetShouldAcceptCookies();
+ bool thirdParty = GetShouldAcceptThirdPartyCookies(request);
+ return AwStaticCookiePolicy(global, thirdParty)
+ .AllowGet(request.url(), request.first_party_for_cookies());
}
bool AwCookieAccessPolicy::OnCanSetCookie(const net::URLRequest& request,
const std::string& cookie_line,
net::CookieOptions* options) {
- return AllowSet(request.url(), request.first_party_for_cookies());
+ bool global = GetShouldAcceptCookies();
+ bool thirdParty = GetShouldAcceptThirdPartyCookies(request);
+ return AwStaticCookiePolicy(global, thirdParty)
+ .AllowSet(request.url(), request.first_party_for_cookies());
}
bool AwCookieAccessPolicy::AllowGetCookie(const GURL& url,
@@ -68,7 +88,10 @@ bool AwCookieAccessPolicy::AllowGetCookie(const GURL& url,
content::ResourceContext* context,
int render_process_id,
int render_frame_id) {
- return AllowGet(url, first_party);
+ bool global = GetShouldAcceptCookies();
+ bool thirdParty =
+ GetShouldAcceptThirdPartyCookies(render_process_id, render_frame_id);
+ return AwStaticCookiePolicy(global, thirdParty).AllowGet(url, first_party);
}
bool AwCookieAccessPolicy::AllowSetCookie(const GURL& url,
@@ -78,26 +101,37 @@ bool AwCookieAccessPolicy::AllowSetCookie(const GURL& url,
int render_process_id,
int render_frame_id,
net::CookieOptions* options) {
- return AllowSet(url, first_party);
+ bool global = GetShouldAcceptCookies();
+ bool thirdParty =
+ GetShouldAcceptThirdPartyCookies(render_process_id, render_frame_id);
+ return AwStaticCookiePolicy(global, thirdParty).AllowSet(url, first_party);
+}
+
+AwStaticCookiePolicy::AwStaticCookiePolicy(bool accept_cookies,
+ bool accept_third_party_cookies)
+ : accept_cookies_(accept_cookies),
+ accept_third_party_cookies_(accept_third_party_cookies) {
}
-StaticCookiePolicy::Type AwCookieAccessPolicy::GetPolicy() {
- if (!GetGlobalAllowAccess()) {
+StaticCookiePolicy::Type AwStaticCookiePolicy::GetPolicy() const {
+ if (!accept_cookies()) {
return StaticCookiePolicy::BLOCK_ALL_COOKIES;
- } else if (!GetThirdPartyAllowAccess()) {
+ } else if (!accept_third_party_cookies()) {
return StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES;
}
return StaticCookiePolicy::ALLOW_ALL_COOKIES;
}
-bool AwCookieAccessPolicy::AllowSet(const GURL& url, const GURL& first_party) {
- return StaticCookiePolicy(GetPolicy()).CanSetCookie(url, first_party)
- == net::OK;
+bool AwStaticCookiePolicy::AllowSet(const GURL& url,
+ const GURL& first_party) const {
+ return StaticCookiePolicy(GetPolicy()).CanSetCookie(url, first_party) ==
+ net::OK;
}
-bool AwCookieAccessPolicy::AllowGet(const GURL& url, const GURL& first_party) {
- return StaticCookiePolicy(GetPolicy()).CanGetCookies(url, first_party)
- == net::OK;
+bool AwStaticCookiePolicy::AllowGet(const GURL& url,
+ const GURL& first_party) const {
+ return StaticCookiePolicy(GetPolicy()).CanGetCookies(url, first_party) ==
+ net::OK;
}
} // namespace android_webview