OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "headless/lib/browser/headless_network_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/public/common/content_switches.h" | 8 #include "content/public/common/content_switches.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/static_cookie_policy.h" | 10 #include "net/base/static_cookie_policy.h" |
11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
12 | 12 |
13 namespace content { | 13 namespace headless { |
14 | 14 |
15 namespace { | 15 namespace { |
16 bool g_accept_all_cookies = true; | 16 bool g_accept_all_cookies = true; |
17 } | 17 } |
18 | 18 |
19 ShellNetworkDelegate::ShellNetworkDelegate() { | 19 HeadlessNetworkDelegate::HeadlessNetworkDelegate() { |
20 } | 20 } |
21 | 21 |
22 ShellNetworkDelegate::~ShellNetworkDelegate() { | 22 HeadlessNetworkDelegate::~HeadlessNetworkDelegate() { |
23 } | 23 } |
24 | 24 |
25 void ShellNetworkDelegate::SetAcceptAllCookies(bool accept) { | 25 void HeadlessNetworkDelegate::SetAcceptAllCookies(bool accept) { |
26 g_accept_all_cookies = accept; | 26 g_accept_all_cookies = accept; |
27 } | 27 } |
28 | 28 |
29 int ShellNetworkDelegate::OnBeforeURLRequest( | 29 int HeadlessNetworkDelegate::OnBeforeURLRequest( |
30 net::URLRequest* request, | 30 net::URLRequest* request, |
31 const net::CompletionCallback& callback, | 31 const net::CompletionCallback& callback, |
32 GURL* new_url) { | 32 GURL* new_url) { |
33 return net::OK; | 33 return net::OK; |
34 } | 34 } |
35 | 35 |
36 int ShellNetworkDelegate::OnBeforeSendHeaders( | 36 int HeadlessNetworkDelegate::OnBeforeSendHeaders( |
37 net::URLRequest* request, | 37 net::URLRequest* request, |
38 const net::CompletionCallback& callback, | 38 const net::CompletionCallback& callback, |
39 net::HttpRequestHeaders* headers) { | 39 net::HttpRequestHeaders* headers) { |
40 return net::OK; | 40 return net::OK; |
41 } | 41 } |
42 | 42 |
43 void ShellNetworkDelegate::OnSendHeaders( | 43 void HeadlessNetworkDelegate::OnSendHeaders( |
44 net::URLRequest* request, | 44 net::URLRequest* request, |
45 const net::HttpRequestHeaders& headers) { | 45 const net::HttpRequestHeaders& headers) { |
46 } | 46 } |
47 | 47 |
48 int ShellNetworkDelegate::OnHeadersReceived( | 48 int HeadlessNetworkDelegate::OnHeadersReceived( |
49 net::URLRequest* request, | 49 net::URLRequest* request, |
50 const net::CompletionCallback& callback, | 50 const net::CompletionCallback& callback, |
51 const net::HttpResponseHeaders* original_response_headers, | 51 const net::HttpResponseHeaders* original_response_headers, |
52 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 52 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
53 GURL* allowed_unsafe_redirect_url) { | 53 GURL* allowed_unsafe_redirect_url) { |
54 return net::OK; | 54 return net::OK; |
55 } | 55 } |
56 | 56 |
57 void ShellNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, | 57 void HeadlessNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, |
58 const GURL& new_location) { | 58 const GURL& new_location) { |
59 } | 59 } |
60 | 60 |
61 void ShellNetworkDelegate::OnResponseStarted(net::URLRequest* request) { | 61 void HeadlessNetworkDelegate::OnResponseStarted(net::URLRequest* request) { |
62 } | 62 } |
63 | 63 |
64 void ShellNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) { | 64 void HeadlessNetworkDelegate::OnCompleted(net::URLRequest* request, bool started
) { |
65 } | 65 } |
66 | 66 |
67 void ShellNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { | 67 void HeadlessNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { |
68 } | 68 } |
69 | 69 |
70 void ShellNetworkDelegate::OnPACScriptError(int line_number, | 70 void HeadlessNetworkDelegate::OnPACScriptError(int line_number, |
71 const base::string16& error) { | 71 const base::string16& error) { |
72 } | 72 } |
73 | 73 |
74 ShellNetworkDelegate::AuthRequiredResponse ShellNetworkDelegate::OnAuthRequired( | 74 HeadlessNetworkDelegate::AuthRequiredResponse HeadlessNetworkDelegate::OnAuthReq
uired( |
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 HeadlessNetworkDelegate::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_accept_all_cookies ? |
85 net::StaticCookiePolicy::ALLOW_ALL_COOKIES : | 85 net::StaticCookiePolicy::ALLOW_ALL_COOKIES : |
86 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES; | 86 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_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 HeadlessNetworkDelegate::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_accept_all_cookies ? |
97 net::StaticCookiePolicy::ALLOW_ALL_COOKIES : | 97 net::StaticCookiePolicy::ALLOW_ALL_COOKIES : |
98 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES; | 98 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_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 HeadlessNetworkDelegate::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 HeadlessNetworkDelegate::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 } // namespace content | 115 } // namespace headless |
OLD | NEW |