Upstream version 6.34.113.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / xwalk_cookie_access_policy.cc
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 "xwalk/runtime/browser/android/xwalk_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 xwalk {
15
16 namespace {
17 base::LazyInstance<XWalkCookieAccessPolicy>::Leaky g_lazy_instance;
18 }  // namespace
19
20 XWalkCookieAccessPolicy::~XWalkCookieAccessPolicy() {
21 }
22
23 XWalkCookieAccessPolicy::XWalkCookieAccessPolicy()
24     : allow_access_(true) {
25 }
26
27 XWalkCookieAccessPolicy* XWalkCookieAccessPolicy::GetInstance() {
28   return g_lazy_instance.Pointer();
29 }
30
31 bool XWalkCookieAccessPolicy::GetGlobalAllowAccess() {
32   AutoLock lock(lock_);
33   return allow_access_;
34 }
35
36 void XWalkCookieAccessPolicy::SetGlobalAllowAccess(bool allow) {
37   AutoLock lock(lock_);
38   allow_access_ = allow;
39 }
40
41 bool XWalkCookieAccessPolicy::OnCanGetCookies(
42     const net::URLRequest& request,
43     const net::CookieList& cookie_list) {
44   return GetGlobalAllowAccess();
45 }
46
47 bool XWalkCookieAccessPolicy::OnCanSetCookie(
48     const net::URLRequest& request,
49     const std::string& cookie_line,
50     net::CookieOptions* options) {
51   return GetGlobalAllowAccess();
52 }
53
54 bool XWalkCookieAccessPolicy::AllowGetCookie(
55     const GURL& url,
56     const GURL& first_party,
57     const net::CookieList& cookie_list,
58     content::ResourceContext* context,
59     int render_process_id,
60     int render_frame_id) {
61   return GetGlobalAllowAccess();
62 }
63
64 bool XWalkCookieAccessPolicy::AllowSetCookie(
65     const GURL& url,
66     const GURL& first_party,
67     const std::string& cookie_line,
68     content::ResourceContext* context,
69     int render_process_id,
70     int render_frame_id,
71     net::CookieOptions* options) {
72   return GetGlobalAllowAccess();
73 }
74
75 }  // namespace xwalk