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.
5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_
6 #define ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_
8 #include "base/basictypes.h"
9 #include "base/lazy_instance.h"
10 #include "base/synchronization/lock.h"
11 #include "net/base/static_cookie_policy.h"
12 #include "net/cookies/canonical_cookie.h"
13 #include "net/url_request/url_request.h"
16 class ResourceContext;
25 namespace android_webview {
27 // Manages the cookie access (both setting and getting) policy for WebView.
28 class AwCookieAccessPolicy {
30 static AwCookieAccessPolicy* GetInstance();
32 // These manage the global access state shared across requests regardless of
33 // source (i.e. network or JavaScript).
34 bool GetGlobalAllowAccess();
35 void SetGlobalAllowAccess(bool allow);
37 // These allow more fine grained control over requests depending on whether
38 // the cookie is third party or not.
39 bool GetThirdPartyAllowAccess();
40 void SetThirdPartyAllowAccess(bool allow);
42 // These are the functions called when operating over cookies from the
43 // network. See NetworkDelegate for further descriptions.
44 bool OnCanGetCookies(const net::URLRequest& request,
45 const net::CookieList& cookie_list);
46 bool OnCanSetCookie(const net::URLRequest& request,
47 const std::string& cookie_line,
48 net::CookieOptions* options);
50 // These are the functions called when operating over cookies from the
51 // renderer. See ContentBrowserClient for further descriptions.
52 bool AllowGetCookie(const GURL& url,
53 const GURL& first_party,
54 const net::CookieList& cookie_list,
55 content::ResourceContext* context,
56 int render_process_id,
58 bool AllowSetCookie(const GURL& url,
59 const GURL& first_party,
60 const std::string& cookie_line,
61 content::ResourceContext* context,
62 int render_process_id,
64 net::CookieOptions* options);
67 friend struct base::DefaultLazyInstanceTraits<AwCookieAccessPolicy>;
69 AwCookieAccessPolicy();
70 ~AwCookieAccessPolicy();
72 bool allow_third_party_access_;
75 // We have two bits of state but only three different cases:
76 // If !GlobalAllowAccess then reject all cookies.
77 // If GlobalAllowAccess and !ThirdPartyAllowAccess then reject third party.
78 // If GlobalAllowAccess and ThirdPartyAllowAccess then allow all cookies.
79 net::StaticCookiePolicy::Type GetPolicy(void);
81 bool AllowGet(const GURL& url, const GURL& first_party);
82 bool AllowSet(const GURL& url, const GURL& first_party);
84 DISALLOW_COPY_AND_ASSIGN(AwCookieAccessPolicy);
87 } // namespace android_webview
89 #endif // ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_