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 #include "net/base/static_cookie_policy.h"
7 #include "base/logging.h"
8 #include "net/base/net_errors.h"
9 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
14 int StaticCookiePolicy::CanGetCookies(
16 const GURL
& first_party_for_cookies
) const {
18 case StaticCookiePolicy::ALLOW_ALL_COOKIES
:
20 case StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES
:
21 if (first_party_for_cookies
.is_empty())
22 return OK
; // Empty first-party URL indicates a first-party request.
23 return registry_controlled_domains::SameDomainOrHost(
25 first_party_for_cookies
,
26 registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES
) ?
27 OK
: ERR_ACCESS_DENIED
;
28 case StaticCookiePolicy::BLOCK_ALL_COOKIES
:
29 return ERR_ACCESS_DENIED
;
32 return ERR_ACCESS_DENIED
;
36 int StaticCookiePolicy::CanSetCookie(
38 const GURL
& first_party_for_cookies
) const {
40 case StaticCookiePolicy::ALLOW_ALL_COOKIES
:
42 case StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES
:
43 if (first_party_for_cookies
.is_empty())
44 return OK
; // Empty first-party URL indicates a first-party request.
45 return registry_controlled_domains::SameDomainOrHost(
47 first_party_for_cookies
,
48 registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES
) ?
49 OK
: ERR_ACCESS_DENIED
;
50 case StaticCookiePolicy::BLOCK_ALL_COOKIES
:
51 return ERR_ACCESS_DENIED
;
54 return ERR_ACCESS_DENIED
;