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
:
19 case StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES
:
21 case StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES
:
22 if (first_party_for_cookies
.is_empty())
23 return OK
; // Empty first-party URL indicates a first-party request.
24 return registry_controlled_domains::SameDomainOrHost(
26 first_party_for_cookies
,
27 registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES
) ?
28 OK
: ERR_ACCESS_DENIED
;
29 case StaticCookiePolicy::BLOCK_ALL_COOKIES
:
30 return ERR_ACCESS_DENIED
;
33 return ERR_ACCESS_DENIED
;
37 int StaticCookiePolicy::CanSetCookie(
39 const GURL
& first_party_for_cookies
) const {
41 case StaticCookiePolicy::ALLOW_ALL_COOKIES
:
43 case StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES
:
44 case StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES
:
45 if (first_party_for_cookies
.is_empty())
46 return OK
; // Empty first-party URL indicates a first-party request.
47 return registry_controlled_domains::SameDomainOrHost(
49 first_party_for_cookies
,
50 registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES
) ?
51 OK
: ERR_ACCESS_DENIED
;
52 case StaticCookiePolicy::BLOCK_ALL_COOKIES
:
53 return ERR_ACCESS_DENIED
;
56 return ERR_ACCESS_DENIED
;