OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/browser/shell_network_delegate.h" | 5 #include "content/shell/browser/shell_network_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/base/static_cookie_policy.h" | 11 #include "net/base/static_cookie_policy.h" |
12 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 namespace { | 16 namespace { |
17 bool g_accept_all_cookies = true; | 17 bool g_block_third_party_cookies = false; |
18 } | 18 } |
19 | 19 |
20 ShellNetworkDelegate::ShellNetworkDelegate() { | 20 ShellNetworkDelegate::ShellNetworkDelegate() { |
21 } | 21 } |
22 | 22 |
23 ShellNetworkDelegate::~ShellNetworkDelegate() { | 23 ShellNetworkDelegate::~ShellNetworkDelegate() { |
24 } | 24 } |
25 | 25 |
26 void ShellNetworkDelegate::SetAcceptAllCookies(bool accept) { | 26 void ShellNetworkDelegate::SetBlockThirdPartyCookies(bool block) { |
27 g_accept_all_cookies = accept; | 27 g_block_third_party_cookies = block; |
28 } | 28 } |
29 | 29 |
30 int ShellNetworkDelegate::OnBeforeURLRequest( | 30 int ShellNetworkDelegate::OnBeforeURLRequest( |
31 net::URLRequest* request, | 31 net::URLRequest* request, |
32 const net::CompletionCallback& callback, | 32 const net::CompletionCallback& callback, |
33 GURL* new_url) { | 33 GURL* new_url) { |
34 return net::OK; | 34 return net::OK; |
35 } | 35 } |
36 | 36 |
37 int ShellNetworkDelegate::OnBeforeStartTransaction( | 37 int ShellNetworkDelegate::OnBeforeStartTransaction( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 ShellNetworkDelegate::AuthRequiredResponse ShellNetworkDelegate::OnAuthRequired( | 74 ShellNetworkDelegate::AuthRequiredResponse ShellNetworkDelegate::OnAuthRequired( |
75 net::URLRequest* request, | 75 net::URLRequest* request, |
76 const net::AuthChallengeInfo& auth_info, | 76 const net::AuthChallengeInfo& auth_info, |
77 const AuthCallback& callback, | 77 const AuthCallback& callback, |
78 net::AuthCredentials* credentials) { | 78 net::AuthCredentials* credentials) { |
79 return AUTH_REQUIRED_RESPONSE_NO_ACTION; | 79 return AUTH_REQUIRED_RESPONSE_NO_ACTION; |
80 } | 80 } |
81 | 81 |
82 bool ShellNetworkDelegate::OnCanGetCookies(const net::URLRequest& request, | 82 bool ShellNetworkDelegate::OnCanGetCookies(const net::URLRequest& request, |
83 const net::CookieList& cookie_list) { | 83 const net::CookieList& cookie_list) { |
84 net::StaticCookiePolicy::Type policy_type = g_accept_all_cookies ? | 84 net::StaticCookiePolicy::Type policy_type = g_block_third_party_cookies ? |
85 net::StaticCookiePolicy::ALLOW_ALL_COOKIES : | 85 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : |
86 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES; | 86 net::StaticCookiePolicy::ALLOW_ALL_COOKIES; |
87 net::StaticCookiePolicy policy(policy_type); | 87 net::StaticCookiePolicy policy(policy_type); |
88 int rv = policy.CanGetCookies( | 88 int rv = policy.CanGetCookies( |
89 request.url(), request.first_party_for_cookies()); | 89 request.url(), request.first_party_for_cookies()); |
90 return rv == net::OK; | 90 return rv == net::OK; |
91 } | 91 } |
92 | 92 |
93 bool ShellNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, | 93 bool ShellNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, |
94 const std::string& cookie_line, | 94 const std::string& cookie_line, |
95 net::CookieOptions* options) { | 95 net::CookieOptions* options) { |
96 net::StaticCookiePolicy::Type policy_type = g_accept_all_cookies ? | 96 net::StaticCookiePolicy::Type policy_type = g_block_third_party_cookies ? |
97 net::StaticCookiePolicy::ALLOW_ALL_COOKIES : | 97 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : |
98 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES; | 98 net::StaticCookiePolicy::ALLOW_ALL_COOKIES; |
99 net::StaticCookiePolicy policy(policy_type); | 99 net::StaticCookiePolicy policy(policy_type); |
100 int rv = policy.CanSetCookie( | 100 int rv = policy.CanSetCookie( |
101 request.url(), request.first_party_for_cookies()); | 101 request.url(), request.first_party_for_cookies()); |
102 return rv == net::OK; | 102 return rv == net::OK; |
103 } | 103 } |
104 | 104 |
105 bool ShellNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, | 105 bool ShellNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, |
106 const base::FilePath& path) const { | 106 const base::FilePath& path) const { |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 bool ShellNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const { | 110 bool ShellNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const { |
111 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 111 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
112 switches::kEnableExperimentalWebPlatformFeatures); | 112 switches::kEnableExperimentalWebPlatformFeatures); |
113 } | 113 } |
114 | 114 |
115 bool ShellNetworkDelegate::OnAreStrictSecureCookiesEnabled() const { | 115 bool ShellNetworkDelegate::OnAreStrictSecureCookiesEnabled() const { |
116 return OnAreExperimentalCookieFeaturesEnabled(); | 116 return OnAreExperimentalCookieFeaturesEnabled(); |
117 } | 117 } |
118 | 118 |
119 } // namespace content | 119 } // namespace content |
OLD | NEW |