| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | // Copyright (c) 2012 The Chromium Authors. All rights reserved.
 | 
					
						
							|  |  |  | // Use of this source code is governed by a BSD-style license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE-CHROMIUM file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-18 15:58:12 -07:00
										 |  |  | #include "brightray/browser/network_delegate.h"
 | 
					
						
							| 
									
										
										
										
											2013-11-17 18:09:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 16:03:43 +08:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "base/command_line.h"
 | 
					
						
							|  |  |  | #include "base/strings/string_split.h"
 | 
					
						
							|  |  |  | #include "net/base/load_flags.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | #include "net/base/net_errors.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-16 16:03:43 +08:00
										 |  |  | #include "net/url_request/url_request.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace brightray { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 16:03:43 +08:00
										 |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Ignore the limit of 6 connections per host.
 | 
					
						
							|  |  |  | const char kIgnoreConnectionsLimit[] = "ignore-connections-limit"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | NetworkDelegate::NetworkDelegate() { | 
					
						
							| 
									
										
										
										
											2018-04-17 15:41:47 -07:00
										 |  |  |   auto* command_line = base::CommandLine::ForCurrentProcess(); | 
					
						
							| 
									
										
										
										
											2015-06-16 16:03:43 +08:00
										 |  |  |   if (command_line->HasSwitch(kIgnoreConnectionsLimit)) { | 
					
						
							| 
									
										
										
										
											2017-03-23 15:47:30 -07:00
										 |  |  |     std::string value = | 
					
						
							|  |  |  |         command_line->GetSwitchValueASCII(kIgnoreConnectionsLimit); | 
					
						
							| 
									
										
										
										
											2015-12-07 19:55:01 +08:00
										 |  |  |     ignore_connections_limit_domains_ = base::SplitString( | 
					
						
							|  |  |  |         value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 
					
						
							| 
									
										
										
										
											2015-06-16 16:03:43 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | NetworkDelegate::~NetworkDelegate() {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | int NetworkDelegate::OnBeforeURLRequest(net::URLRequest* request, | 
					
						
							|  |  |  |                                         const net::CompletionCallback& callback, | 
					
						
							|  |  |  |                                         GURL* new_url) { | 
					
						
							| 
									
										
										
										
											2015-06-16 16:03:43 +08:00
										 |  |  |   for (const auto& domain : ignore_connections_limit_domains_) { | 
					
						
							| 
									
										
										
										
											2015-12-07 19:55:01 +08:00
										 |  |  |     if (request->url().DomainIs(domain)) { | 
					
						
							| 
									
										
										
										
											2015-06-16 16:03:43 +08:00
										 |  |  |       // Allow unlimited concurrent connections.
 | 
					
						
							|  |  |  |       request->SetPriority(net::MAXIMUM_PRIORITY); | 
					
						
							|  |  |  |       request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  |   return net::OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-06 17:22:52 +09:00
										 |  |  | int NetworkDelegate::OnBeforeStartTransaction( | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  |     net::URLRequest* request, | 
					
						
							|  |  |  |     const net::CompletionCallback& callback, | 
					
						
							|  |  |  |     net::HttpRequestHeaders* headers) { | 
					
						
							|  |  |  |   return net::OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-06 17:22:52 +09:00
										 |  |  | void NetworkDelegate::OnStartTransaction( | 
					
						
							|  |  |  |     net::URLRequest* request, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  |     const net::HttpRequestHeaders& headers) {} | 
					
						
							| 
									
										
										
										
											2015-03-08 19:47:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-06 17:22:52 +09:00
										 |  |  | void NetworkDelegate::OnBeforeSendHeaders( | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  |     net::URLRequest* request, | 
					
						
							| 
									
										
										
										
											2016-09-06 17:22:52 +09:00
										 |  |  |     const net::ProxyInfo& proxy_info, | 
					
						
							|  |  |  |     const net::ProxyRetryInfoMap& proxy_retry_info, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  |     net::HttpRequestHeaders* headers) {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | int NetworkDelegate::OnHeadersReceived( | 
					
						
							|  |  |  |     net::URLRequest* request, | 
					
						
							|  |  |  |     const net::CompletionCallback& callback, | 
					
						
							|  |  |  |     const net::HttpResponseHeaders* original_response_headers, | 
					
						
							| 
									
										
										
										
											2014-06-26 16:33:11 -04:00
										 |  |  |     scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 
					
						
							|  |  |  |     GURL* allowed_unsafe_redirect_url) { | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  |   return net::OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NetworkDelegate::OnBeforeRedirect(net::URLRequest* request, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  |                                        const GURL& new_location) {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | void NetworkDelegate::OnResponseStarted(net::URLRequest* request) {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-07 21:59:14 -08:00
										 |  |  | void NetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  |                                              int64_t bytes_read) {} | 
					
						
							| 
									
										
										
										
											2015-12-07 19:55:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-07 21:59:14 -08:00
										 |  |  | void NetworkDelegate::OnNetworkBytesSent(net::URLRequest* request, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  |                                          int64_t bytes_sent) {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | void NetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | void NetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | void NetworkDelegate::OnPACScriptError(int line_number, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  |                                        const base::string16& error) {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired( | 
					
						
							|  |  |  |     net::URLRequest* request, | 
					
						
							|  |  |  |     const net::AuthChallengeInfo& auth_info, | 
					
						
							|  |  |  |     const AuthCallback& callback, | 
					
						
							|  |  |  |     net::AuthCredentials* credentials) { | 
					
						
							|  |  |  |   return AUTH_REQUIRED_RESPONSE_NO_ACTION; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NetworkDelegate::OnCanGetCookies(const net::URLRequest& request, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  |                                       const net::CookieList& cookie_list) { | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NetworkDelegate::OnCanSetCookie(const net::URLRequest& request, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  |                                      const std::string& cookie_line, | 
					
						
							|  |  |  |                                      net::CookieOptions* options) { | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-21 00:25:49 +03:00
										 |  |  | bool NetworkDelegate::OnCanAccessFile( | 
					
						
							|  |  |  |     const net::URLRequest& request, | 
					
						
							|  |  |  |     const base::FilePath& original_path, | 
					
						
							|  |  |  |     const base::FilePath& absolute_path) const { | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-08 19:47:12 -07:00
										 |  |  | bool NetworkDelegate::OnCanEnablePrivacyMode( | 
					
						
							|  |  |  |     const GURL& url, | 
					
						
							|  |  |  |     const GURL& first_party_for_cookies) const { | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 20:04:08 +09:00
										 |  |  | bool NetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const { | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-08 19:47:12 -07:00
										 |  |  | bool NetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( | 
					
						
							|  |  |  |     const net::URLRequest& request, | 
					
						
							|  |  |  |     const GURL& target_url, | 
					
						
							|  |  |  |     const GURL& referrer_url) const { | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 00:50:08 +03:00
										 |  |  | // TODO(deepak1556) : Enable after hooking into the reporting service
 | 
					
						
							|  |  |  | // https://crbug.com/704259
 | 
					
						
							|  |  |  | bool NetworkDelegate::OnCanQueueReportingReport( | 
					
						
							|  |  |  |     const url::Origin& origin) const { | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NetworkDelegate::OnCanSendReportingReport( | 
					
						
							|  |  |  |     const url::Origin& origin) const { | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | bool NetworkDelegate::OnCanSetReportingClient(const url::Origin& origin, | 
					
						
							|  |  |  |                                               const GURL& endpoint) const { | 
					
						
							| 
									
										
										
										
											2017-08-24 00:50:08 +03:00
										 |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | bool NetworkDelegate::OnCanUseReportingClient(const url::Origin& origin, | 
					
						
							|  |  |  |                                               const GURL& endpoint) const { | 
					
						
							| 
									
										
										
										
											2017-08-24 00:50:08 +03:00
										 |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-17 18:09:21 -05:00
										 |  |  | }  // namespace brightray
 |