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.
4
5 #include "content/shell/browser/shell_network_delegate.h"
6
7 #include "net/base/net_errors.h"
8 #include "net/base/static_cookie_policy.h"
9 #include "net/url_request/url_request.h"
10
11 namespace content {
12
13 namespace {
14 bool g_accept_all_cookies = true;
15 }
16
ShellNetworkDelegate()17 ShellNetworkDelegate::ShellNetworkDelegate() {
18 }
19
~ShellNetworkDelegate()20 ShellNetworkDelegate::~ShellNetworkDelegate() {
21 }
22
SetAcceptAllCookies(bool accept)23 void ShellNetworkDelegate::SetAcceptAllCookies(bool accept) {
24 g_accept_all_cookies = accept;
25 }
26
OnBeforeURLRequest(net::URLRequest * request,const net::CompletionCallback & callback,GURL * new_url)27 int ShellNetworkDelegate::OnBeforeURLRequest(
28 net::URLRequest* request,
29 const net::CompletionCallback& callback,
30 GURL* new_url) {
31 return net::OK;
32 }
33
OnBeforeSendHeaders(net::URLRequest * request,const net::CompletionCallback & callback,net::HttpRequestHeaders * headers)34 int ShellNetworkDelegate::OnBeforeSendHeaders(
35 net::URLRequest* request,
36 const net::CompletionCallback& callback,
37 net::HttpRequestHeaders* headers) {
38 return net::OK;
39 }
40
OnSendHeaders(net::URLRequest * request,const net::HttpRequestHeaders & headers)41 void ShellNetworkDelegate::OnSendHeaders(
42 net::URLRequest* request,
43 const net::HttpRequestHeaders& headers) {
44 }
45
OnHeadersReceived(net::URLRequest * request,const net::CompletionCallback & callback,const net::HttpResponseHeaders * original_response_headers,scoped_refptr<net::HttpResponseHeaders> * override_response_headers)46 int ShellNetworkDelegate::OnHeadersReceived(
47 net::URLRequest* request,
48 const net::CompletionCallback& callback,
49 const net::HttpResponseHeaders* original_response_headers,
50 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) {
51 return net::OK;
52 }
53
OnBeforeRedirect(net::URLRequest * request,const GURL & new_location)54 void ShellNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
55 const GURL& new_location) {
56 }
57
OnResponseStarted(net::URLRequest * request)58 void ShellNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
59 }
60
OnRawBytesRead(const net::URLRequest & request,int bytes_read)61 void ShellNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
62 int bytes_read) {
63 }
64
OnCompleted(net::URLRequest * request,bool started)65 void ShellNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
66 }
67
OnURLRequestDestroyed(net::URLRequest * request)68 void ShellNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
69 }
70
OnPACScriptError(int line_number,const base::string16 & error)71 void ShellNetworkDelegate::OnPACScriptError(int line_number,
72 const base::string16& error) {
73 }
74
OnAuthRequired(net::URLRequest * request,const net::AuthChallengeInfo & auth_info,const AuthCallback & callback,net::AuthCredentials * credentials)75 ShellNetworkDelegate::AuthRequiredResponse ShellNetworkDelegate::OnAuthRequired(
76 net::URLRequest* request,
77 const net::AuthChallengeInfo& auth_info,
78 const AuthCallback& callback,
79 net::AuthCredentials* credentials) {
80 return AUTH_REQUIRED_RESPONSE_NO_ACTION;
81 }
82
OnCanGetCookies(const net::URLRequest & request,const net::CookieList & cookie_list)83 bool ShellNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
84 const net::CookieList& cookie_list) {
85 net::StaticCookiePolicy::Type policy_type = g_accept_all_cookies ?
86 net::StaticCookiePolicy::ALLOW_ALL_COOKIES :
87 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES;
88 net::StaticCookiePolicy policy(policy_type);
89 int rv = policy.CanGetCookies(
90 request.url(), request.first_party_for_cookies());
91 return rv == net::OK;
92 }
93
OnCanSetCookie(const net::URLRequest & request,const std::string & cookie_line,net::CookieOptions * options)94 bool ShellNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
95 const std::string& cookie_line,
96 net::CookieOptions* options) {
97 net::StaticCookiePolicy::Type policy_type = g_accept_all_cookies ?
98 net::StaticCookiePolicy::ALLOW_ALL_COOKIES :
99 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES;
100 net::StaticCookiePolicy policy(policy_type);
101 int rv = policy.CanSetCookie(
102 request.url(), request.first_party_for_cookies());
103 return rv == net::OK;
104 }
105
OnCanAccessFile(const net::URLRequest & request,const base::FilePath & path) const106 bool ShellNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
107 const base::FilePath& path) const {
108 return true;
109 }
110
OnCanThrottleRequest(const net::URLRequest & request) const111 bool ShellNetworkDelegate::OnCanThrottleRequest(
112 const net::URLRequest& request) const {
113 return false;
114 }
115
OnBeforeSocketStreamConnect(net::SocketStream * socket,const net::CompletionCallback & callback)116 int ShellNetworkDelegate::OnBeforeSocketStreamConnect(
117 net::SocketStream* socket,
118 const net::CompletionCallback& callback) {
119 return net::OK;
120 }
121
OnRequestWaitStateChange(const net::URLRequest & request,RequestWaitState waiting)122 void ShellNetworkDelegate::OnRequestWaitStateChange(
123 const net::URLRequest& request,
124 RequestWaitState waiting) {
125 }
126
127 } // namespace content
128