Upstream version 6.34.113.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / xwalk_cookie_access_policy.h
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 #ifndef XWALK_RUNTIME_BROWSER_ANDROID_XWALK_COOKIE_ACCESS_POLICY_H_
6 #define XWALK_RUNTIME_BROWSER_ANDROID_XWALK_COOKIE_ACCESS_POLICY_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/lazy_instance.h"
12 #include "base/synchronization/lock.h"
13 #include "net/cookies/canonical_cookie.h"
14
15 namespace content {
16 class ResourceContext;
17 }
18
19 namespace net {
20 class CookieOptions;
21 class URLRequest;
22 }
23
24 class GURL;
25
26 namespace xwalk {
27
28 // Manages the cookie access (both setting and getting) policy for WebView.
29 class XWalkCookieAccessPolicy {
30  public:
31   static XWalkCookieAccessPolicy* GetInstance();
32
33   // These manage the global access state shared across requests regardless of
34   // source (i.e. network or JavaScript).
35   bool GetGlobalAllowAccess();
36   void SetGlobalAllowAccess(bool allow);
37
38   // These are the functions called when operating over cookies from the
39   // network. See NetworkDelegate for further descriptions.
40   bool OnCanGetCookies(const net::URLRequest& request,
41                        const net::CookieList& cookie_list);
42   bool OnCanSetCookie(const net::URLRequest& request,
43                       const std::string& cookie_line,
44                       net::CookieOptions* options);
45
46   // These are the functions called when operating over cookies from the
47   // renderer. See ContentBrowserClient for further descriptions.
48   bool AllowGetCookie(const GURL& url,
49                       const GURL& first_party,
50                       const net::CookieList& cookie_list,
51                       content::ResourceContext* context,
52                       int render_process_id,
53                       int render_frame_id);
54   bool AllowSetCookie(const GURL& url,
55                       const GURL& first_party,
56                       const std::string& cookie_line,
57                       content::ResourceContext* context,
58                       int render_process_id,
59                       int render_frame_id,
60                       net::CookieOptions* options);
61
62  private:
63   friend struct base::DefaultLazyInstanceTraits<XWalkCookieAccessPolicy>;
64
65   XWalkCookieAccessPolicy();
66   ~XWalkCookieAccessPolicy();
67   bool allow_access_;
68   base::Lock lock_;
69
70   DISALLOW_COPY_AND_ASSIGN(XWalkCookieAccessPolicy);
71 };
72
73 }  // namespace xwalk
74
75 #endif  // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_COOKIE_ACCESS_POLICY_H_