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
3 // found in the LICENSE file.
5 #include "content/shell/browser/shell_network_delegate.h"
7 #include "base/command_line.h"
8 #include "content/public/common/content_switches.h"
9 #include "net/base/net_errors.h"
10 #include "net/base/static_cookie_policy.h"
11 #include "net/url_request/url_request.h"
16 bool g_accept_all_cookies
= true;
19 ShellNetworkDelegate::ShellNetworkDelegate() {
22 ShellNetworkDelegate::~ShellNetworkDelegate() {
25 void ShellNetworkDelegate::SetAcceptAllCookies(bool accept
) {
26 g_accept_all_cookies
= accept
;
29 int ShellNetworkDelegate::OnBeforeURLRequest(
30 net::URLRequest
* request
,
31 const net::CompletionCallback
& callback
,
36 int ShellNetworkDelegate::OnBeforeSendHeaders(
37 net::URLRequest
* request
,
38 const net::CompletionCallback
& callback
,
39 net::HttpRequestHeaders
* headers
) {
43 void ShellNetworkDelegate::OnSendHeaders(
44 net::URLRequest
* request
,
45 const net::HttpRequestHeaders
& headers
) {
48 int ShellNetworkDelegate::OnHeadersReceived(
49 net::URLRequest
* request
,
50 const net::CompletionCallback
& callback
,
51 const net::HttpResponseHeaders
* original_response_headers
,
52 scoped_refptr
<net::HttpResponseHeaders
>* override_response_headers
,
53 GURL
* allowed_unsafe_redirect_url
) {
57 void ShellNetworkDelegate::OnBeforeRedirect(net::URLRequest
* request
,
58 const GURL
& new_location
) {
61 void ShellNetworkDelegate::OnResponseStarted(net::URLRequest
* request
) {
64 void ShellNetworkDelegate::OnRawBytesRead(const net::URLRequest
& request
,
68 void ShellNetworkDelegate::OnCompleted(net::URLRequest
* request
, bool started
) {
71 void ShellNetworkDelegate::OnURLRequestDestroyed(net::URLRequest
* request
) {
74 void ShellNetworkDelegate::OnPACScriptError(int line_number
,
75 const base::string16
& error
) {
78 ShellNetworkDelegate::AuthRequiredResponse
ShellNetworkDelegate::OnAuthRequired(
79 net::URLRequest
* request
,
80 const net::AuthChallengeInfo
& auth_info
,
81 const AuthCallback
& callback
,
82 net::AuthCredentials
* credentials
) {
83 return AUTH_REQUIRED_RESPONSE_NO_ACTION
;
86 bool ShellNetworkDelegate::OnCanGetCookies(const net::URLRequest
& request
,
87 const net::CookieList
& cookie_list
) {
88 net::StaticCookiePolicy::Type policy_type
= g_accept_all_cookies
?
89 net::StaticCookiePolicy::ALLOW_ALL_COOKIES
:
90 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES
;
91 net::StaticCookiePolicy
policy(policy_type
);
92 int rv
= policy
.CanGetCookies(
93 request
.url(), request
.first_party_for_cookies());
97 bool ShellNetworkDelegate::OnCanSetCookie(const net::URLRequest
& request
,
98 const std::string
& cookie_line
,
99 net::CookieOptions
* options
) {
100 net::StaticCookiePolicy::Type policy_type
= g_accept_all_cookies
?
101 net::StaticCookiePolicy::ALLOW_ALL_COOKIES
:
102 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES
;
103 net::StaticCookiePolicy
policy(policy_type
);
104 int rv
= policy
.CanSetCookie(
105 request
.url(), request
.first_party_for_cookies());
106 return rv
== net::OK
;
109 bool ShellNetworkDelegate::OnCanAccessFile(const net::URLRequest
& request
,
110 const base::FilePath
& path
) const {
114 bool ShellNetworkDelegate::OnFirstPartyOnlyCookieExperimentEnabled() const {
115 return base::CommandLine::ForCurrentProcess()->HasSwitch(
116 switches::kEnableExperimentalWebPlatformFeatures
);
119 } // namespace content