network_delegate.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Copyright (c) 2012 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-CHROMIUM file.
  4. #include "brightray/browser/network_delegate.h"
  5. #include <string>
  6. #include <vector>
  7. #include "base/command_line.h"
  8. #include "base/strings/string_split.h"
  9. #include "net/base/load_flags.h"
  10. #include "net/base/net_errors.h"
  11. #include "net/url_request/url_request.h"
  12. namespace brightray {
  13. namespace {
  14. // Ignore the limit of 6 connections per host.
  15. const char kIgnoreConnectionsLimit[] = "ignore-connections-limit";
  16. } // namespace
  17. NetworkDelegate::NetworkDelegate() {
  18. auto* command_line = base::CommandLine::ForCurrentProcess();
  19. if (command_line->HasSwitch(kIgnoreConnectionsLimit)) {
  20. std::string value =
  21. command_line->GetSwitchValueASCII(kIgnoreConnectionsLimit);
  22. ignore_connections_limit_domains_ = base::SplitString(
  23. value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
  24. }
  25. }
  26. NetworkDelegate::~NetworkDelegate() {}
  27. int NetworkDelegate::OnBeforeURLRequest(net::URLRequest* request,
  28. const net::CompletionCallback& callback,
  29. GURL* new_url) {
  30. for (const auto& domain : ignore_connections_limit_domains_) {
  31. if (request->url().DomainIs(domain)) {
  32. // Allow unlimited concurrent connections.
  33. request->SetPriority(net::MAXIMUM_PRIORITY);
  34. request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS);
  35. break;
  36. }
  37. }
  38. return net::OK;
  39. }
  40. int NetworkDelegate::OnBeforeStartTransaction(
  41. net::URLRequest* request,
  42. const net::CompletionCallback& callback,
  43. net::HttpRequestHeaders* headers) {
  44. return net::OK;
  45. }
  46. void NetworkDelegate::OnStartTransaction(
  47. net::URLRequest* request,
  48. const net::HttpRequestHeaders& headers) {}
  49. void NetworkDelegate::OnBeforeSendHeaders(
  50. net::URLRequest* request,
  51. const net::ProxyInfo& proxy_info,
  52. const net::ProxyRetryInfoMap& proxy_retry_info,
  53. net::HttpRequestHeaders* headers) {}
  54. int NetworkDelegate::OnHeadersReceived(
  55. net::URLRequest* request,
  56. const net::CompletionCallback& callback,
  57. const net::HttpResponseHeaders* original_response_headers,
  58. scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
  59. GURL* allowed_unsafe_redirect_url) {
  60. return net::OK;
  61. }
  62. void NetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
  63. const GURL& new_location) {}
  64. void NetworkDelegate::OnResponseStarted(net::URLRequest* request) {}
  65. void NetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request,
  66. int64_t bytes_read) {}
  67. void NetworkDelegate::OnNetworkBytesSent(net::URLRequest* request,
  68. int64_t bytes_sent) {}
  69. void NetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {}
  70. void NetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {}
  71. void NetworkDelegate::OnPACScriptError(int line_number,
  72. const base::string16& error) {}
  73. NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
  74. net::URLRequest* request,
  75. const net::AuthChallengeInfo& auth_info,
  76. const AuthCallback& callback,
  77. net::AuthCredentials* credentials) {
  78. return AUTH_REQUIRED_RESPONSE_NO_ACTION;
  79. }
  80. bool NetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
  81. const net::CookieList& cookie_list) {
  82. return true;
  83. }
  84. bool NetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
  85. const std::string& cookie_line,
  86. net::CookieOptions* options) {
  87. return true;
  88. }
  89. bool NetworkDelegate::OnCanAccessFile(
  90. const net::URLRequest& request,
  91. const base::FilePath& original_path,
  92. const base::FilePath& absolute_path) const {
  93. return true;
  94. }
  95. bool NetworkDelegate::OnCanEnablePrivacyMode(
  96. const GURL& url,
  97. const GURL& first_party_for_cookies) const {
  98. return false;
  99. }
  100. bool NetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const {
  101. return true;
  102. }
  103. bool NetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
  104. const net::URLRequest& request,
  105. const GURL& target_url,
  106. const GURL& referrer_url) const {
  107. return false;
  108. }
  109. // TODO(deepak1556) : Enable after hooking into the reporting service
  110. // https://crbug.com/704259
  111. bool NetworkDelegate::OnCanQueueReportingReport(
  112. const url::Origin& origin) const {
  113. return false;
  114. }
  115. bool NetworkDelegate::OnCanSendReportingReport(
  116. const url::Origin& origin) const {
  117. return false;
  118. }
  119. bool NetworkDelegate::OnCanSetReportingClient(const url::Origin& origin,
  120. const GURL& endpoint) const {
  121. return false;
  122. }
  123. bool NetworkDelegate::OnCanUseReportingClient(const url::Origin& origin,
  124. const GURL& endpoint) const {
  125. return false;
  126. }
  127. } // namespace brightray