1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "android_webview/browser/aw_cookie_access_policy.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "content/public/browser/browser_thread.h"
10
11 using base::AutoLock;
12 using content::BrowserThread;
13
14 namespace android_webview {
15
16 namespace {
17 base::LazyInstance<AwCookieAccessPolicy>::Leaky g_lazy_instance;
18 } // namespace
19
~AwCookieAccessPolicy()20 AwCookieAccessPolicy::~AwCookieAccessPolicy() {
21 }
22
AwCookieAccessPolicy()23 AwCookieAccessPolicy::AwCookieAccessPolicy()
24 : allow_access_(true) {
25 }
26
GetInstance()27 AwCookieAccessPolicy* AwCookieAccessPolicy::GetInstance() {
28 return g_lazy_instance.Pointer();
29 }
30
GetGlobalAllowAccess()31 bool AwCookieAccessPolicy::GetGlobalAllowAccess() {
32 AutoLock lock(lock_);
33 return allow_access_;
34 }
35
SetGlobalAllowAccess(bool allow)36 void AwCookieAccessPolicy::SetGlobalAllowAccess(bool allow) {
37 AutoLock lock(lock_);
38 allow_access_ = allow;
39 }
40
OnCanGetCookies(const net::URLRequest & request,const net::CookieList & cookie_list)41 bool AwCookieAccessPolicy::OnCanGetCookies(const net::URLRequest& request,
42 const net::CookieList& cookie_list) {
43 return GetGlobalAllowAccess();
44 }
45
OnCanSetCookie(const net::URLRequest & request,const std::string & cookie_line,net::CookieOptions * options)46 bool AwCookieAccessPolicy::OnCanSetCookie(const net::URLRequest& request,
47 const std::string& cookie_line,
48 net::CookieOptions* options) {
49 return GetGlobalAllowAccess();
50 }
51
AllowGetCookie(const GURL & url,const GURL & first_party,const net::CookieList & cookie_list,content::ResourceContext * context,int render_process_id,int render_view_id)52 bool AwCookieAccessPolicy::AllowGetCookie(const GURL& url,
53 const GURL& first_party,
54 const net::CookieList& cookie_list,
55 content::ResourceContext* context,
56 int render_process_id,
57 int render_view_id) {
58 return GetGlobalAllowAccess();
59 }
60
AllowSetCookie(const GURL & url,const GURL & first_party,const std::string & cookie_line,content::ResourceContext * context,int render_process_id,int render_view_id,net::CookieOptions * options)61 bool AwCookieAccessPolicy::AllowSetCookie(const GURL& url,
62 const GURL& first_party,
63 const std::string& cookie_line,
64 content::ResourceContext* context,
65 int render_process_id,
66 int render_view_id,
67 net::CookieOptions* options) {
68 return GetGlobalAllowAccess();
69 }
70
71 } // namespace android_webview
72