blob: 12a12f835df8ec7a2210a03f8cd77fdbfd5018c1 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"
class GURL;
namespace net {
class URLRequest;
} // namespace net
namespace android_webview {
// Manages the cookie access (both setting and getting) policy for WebView.
// Currently we don't distinguish between sources (i.e. network vs. JavaScript)
// or between reading vs. writing cookies.
class AwCookieAccessPolicy {
static AwCookieAccessPolicy* GetInstance();
// Can we read/write any cookies? Can be called from any thread.
bool GetShouldAcceptCookies();
void SetShouldAcceptCookies(bool allow);
// Can we read/write third party cookies?
// |render_process_id| and |render_frame_id| must be valid.
// Navigation requests are not associated with a renderer process. In this
// case, |frame_tree_node_id| must be valid instead. Can only be called from
// the IO thread.
bool GetShouldAcceptThirdPartyCookies(int render_process_id,
int render_frame_id,
int frame_tree_node_id);
bool GetShouldAcceptThirdPartyCookies(const net::URLRequest& request);
// Whether or not to allow cookies to bet sent or set for |request|. Can only
// be called from the IO thread.
bool AllowCookies(const net::URLRequest& request);
// Whether or not to allow cookies for requests with these parameters.
bool AllowCookies(const GURL& url,
const GURL& first_party,
int render_process_id,
int render_frame_id);
friend struct base::LazyInstanceTraitsBase<AwCookieAccessPolicy>;
friend class AwCookieAccessPolicyTest;
bool CanAccessCookies(const GURL& url,
const GURL& site_for_cookies,
bool accept_third_party_cookies);
bool accept_cookies_;
base::Lock lock_;
} // namespace android_webview