OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h " | 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h " |
36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" | 37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" |
38 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h" | 38 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h" |
39 #include "components/domain_reliability/monitor.h" | 39 #include "components/domain_reliability/monitor.h" |
40 #include "components/google/core/browser/google_util.h" | 40 #include "components/google/core/browser/google_util.h" |
41 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
42 #include "content/public/browser/render_frame_host.h" | 42 #include "content/public/browser/render_frame_host.h" |
43 #include "content/public/browser/render_view_host.h" | 43 #include "content/public/browser/render_view_host.h" |
44 #include "content/public/browser/resource_request_info.h" | 44 #include "content/public/browser/resource_request_info.h" |
45 #include "extensions/common/constants.h" | |
46 #include "net/base/host_port_pair.h" | 45 #include "net/base/host_port_pair.h" |
47 #include "net/base/net_errors.h" | 46 #include "net/base/net_errors.h" |
48 #include "net/base/net_log.h" | 47 #include "net/base/net_log.h" |
49 #include "net/cookies/canonical_cookie.h" | 48 #include "net/cookies/canonical_cookie.h" |
50 #include "net/cookies/cookie_options.h" | 49 #include "net/cookies/cookie_options.h" |
51 #include "net/http/http_request_headers.h" | 50 #include "net/http/http_request_headers.h" |
52 #include "net/http/http_response_headers.h" | 51 #include "net/http/http_response_headers.h" |
53 #include "net/proxy/proxy_info.h" | 52 #include "net/proxy/proxy_info.h" |
54 #include "net/proxy/proxy_server.h" | 53 #include "net/proxy/proxy_server.h" |
55 #include "net/socket_stream/socket_stream.h" | 54 #include "net/socket_stream/socket_stream.h" |
56 #include "net/url_request/url_request.h" | 55 #include "net/url_request/url_request.h" |
57 #include "net/url_request/url_request_context.h" | 56 #include "net/url_request/url_request_context.h" |
58 | 57 |
59 #if defined(OS_ANDROID) | 58 #if defined(OS_ANDROID) |
60 #include "chrome/browser/io_thread.h" | 59 #include "chrome/browser/io_thread.h" |
61 #include "components/precache/content/precache_manager.h" | 60 #include "components/precache/content/precache_manager.h" |
62 #include "components/precache/content/precache_manager_factory.h" | 61 #include "components/precache/content/precache_manager_factory.h" |
63 #endif | 62 #endif |
64 | 63 |
65 #if defined(OS_CHROMEOS) | 64 #if defined(OS_CHROMEOS) |
66 #include "base/command_line.h" | 65 #include "base/command_line.h" |
67 #include "base/sys_info.h" | 66 #include "base/sys_info.h" |
68 #include "chrome/common/chrome_switches.h" | 67 #include "chrome/common/chrome_switches.h" |
69 #endif | 68 #endif |
70 | 69 |
71 #if defined(ENABLE_CONFIGURATION_POLICY) | 70 #if defined(ENABLE_CONFIGURATION_POLICY) |
72 #include "components/policy/core/browser/url_blacklist_manager.h" | 71 #include "components/policy/core/browser/url_blacklist_manager.h" |
73 #endif | 72 #endif |
74 | 73 |
74 #if defined(ENABLE_EXTENSIONS) | |
75 #include "extensions/common/constants.h" | |
76 #endif | |
77 | |
75 using content::BrowserThread; | 78 using content::BrowserThread; |
76 using content::RenderViewHost; | 79 using content::RenderViewHost; |
77 using content::ResourceRequestInfo; | 80 using content::ResourceRequestInfo; |
78 using content::ResourceType; | 81 using content::ResourceType; |
79 | 82 |
80 // By default we don't allow access to all file:// urls on ChromeOS and | 83 // By default we don't allow access to all file:// urls on ChromeOS and |
81 // Android. | 84 // Android. |
82 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 85 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
83 bool ChromeNetworkDelegate::g_allow_file_access_ = false; | 86 bool ChromeNetworkDelegate::g_allow_file_access_ = false; |
84 #else | 87 #else |
85 bool ChromeNetworkDelegate::g_allow_file_access_ = true; | 88 bool ChromeNetworkDelegate::g_allow_file_access_ = true; |
86 #endif | 89 #endif |
87 | 90 |
91 #if defined(ENABLE_EXTENSIONS) | |
88 // This remains false unless the --disable-extensions-http-throttling | 92 // This remains false unless the --disable-extensions-http-throttling |
89 // flag is passed to the browser. | 93 // flag is passed to the browser. |
90 bool ChromeNetworkDelegate::g_never_throttle_requests_ = false; | 94 bool ChromeNetworkDelegate::g_never_throttle_requests_ = false; |
95 #endif | |
91 | 96 |
92 namespace { | 97 namespace { |
93 | 98 |
94 const char kDNTHeader[] = "DNT"; | 99 const char kDNTHeader[] = "DNT"; |
95 | 100 |
96 // Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the | 101 // Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the |
97 // same key as the the |second_parameter| (e.g. foo=baz). Both parameters | 102 // same key as the the |second_parameter| (e.g. foo=baz). Both parameters |
98 // must be in key=value form. | 103 // must be in key=value form. |
99 bool HasSameParameterKey(const std::string& first_parameter, | 104 bool HasSameParameterKey(const std::string& first_parameter, |
100 const std::string& second_parameter) { | 105 const std::string& second_parameter) { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 connect_interceptor_.reset( | 336 connect_interceptor_.reset( |
332 new chrome_browser_net::ConnectInterceptor(predictor)); | 337 new chrome_browser_net::ConnectInterceptor(predictor)); |
333 } | 338 } |
334 | 339 |
335 void ChromeNetworkDelegate::SetEnableClientHints() { | 340 void ChromeNetworkDelegate::SetEnableClientHints() { |
336 client_hints_.reset(new ClientHints()); | 341 client_hints_.reset(new ClientHints()); |
337 client_hints_->Init(); | 342 client_hints_->Init(); |
338 } | 343 } |
339 | 344 |
340 // static | 345 // static |
346 #if defined(ENABLE_EXTENSIONS) | |
341 void ChromeNetworkDelegate::NeverThrottleRequests() { | 347 void ChromeNetworkDelegate::NeverThrottleRequests() { |
342 g_never_throttle_requests_ = true; | 348 g_never_throttle_requests_ = true; |
343 } | 349 } |
350 #endif | |
Ryan Sleevi
2014/07/16 20:23:44
Doesn't seem strictly necessary to #ifdef dance th
Lei Zhang
2014/07/18 01:34:24
All the throttle code here exists to support --dis
| |
344 | 351 |
345 // static | 352 // static |
346 void ChromeNetworkDelegate::InitializePrefsOnUIThread( | 353 void ChromeNetworkDelegate::InitializePrefsOnUIThread( |
347 BooleanPrefMember* enable_referrers, | 354 BooleanPrefMember* enable_referrers, |
348 BooleanPrefMember* enable_do_not_track, | 355 BooleanPrefMember* enable_do_not_track, |
349 BooleanPrefMember* force_google_safe_search, | 356 BooleanPrefMember* force_google_safe_search, |
350 PrefService* pref_service) { | 357 PrefService* pref_service) { |
351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
352 enable_referrers->Init(prefs::kEnableReferrers, pref_service); | 359 enable_referrers->Init(prefs::kEnableReferrers, pref_service); |
353 enable_referrers->MoveToThread( | 360 enable_referrers->MoveToThread( |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
782 } | 789 } |
783 } | 790 } |
784 | 791 |
785 DVLOG(1) << "File access denied - " << path.value().c_str(); | 792 DVLOG(1) << "File access denied - " << path.value().c_str(); |
786 return false; | 793 return false; |
787 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 794 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
788 } | 795 } |
789 | 796 |
790 bool ChromeNetworkDelegate::OnCanThrottleRequest( | 797 bool ChromeNetworkDelegate::OnCanThrottleRequest( |
791 const net::URLRequest& request) const { | 798 const net::URLRequest& request) const { |
799 #if defined(ENABLE_EXTENSIONS) | |
792 if (g_never_throttle_requests_) | 800 if (g_never_throttle_requests_) |
793 return false; | 801 return false; |
794 return request.first_party_for_cookies().scheme() == | 802 return request.first_party_for_cookies().scheme() == |
795 extensions::kExtensionScheme; | 803 extensions::kExtensionScheme; |
804 #else | |
805 return false; | |
806 #endif | |
796 } | 807 } |
797 | 808 |
798 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( | 809 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( |
799 const GURL& url, | 810 const GURL& url, |
800 const GURL& first_party_for_cookies) const { | 811 const GURL& first_party_for_cookies) const { |
801 // NULL during tests, or when we're running in the system context. | 812 // NULL during tests, or when we're running in the system context. |
802 if (!cookie_settings_.get()) | 813 if (!cookie_settings_.get()) |
803 return false; | 814 return false; |
804 | 815 |
805 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( | 816 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( |
(...skipping 27 matching lines...) Expand all Loading... | |
833 data_reduction_proxy::DataReductionProxyRequestType request_type) { | 844 data_reduction_proxy::DataReductionProxyRequestType request_type) { |
834 DCHECK_GE(received_content_length, 0); | 845 DCHECK_GE(received_content_length, 0); |
835 DCHECK_GE(original_content_length, 0); | 846 DCHECK_GE(original_content_length, 0); |
836 StoreAccumulatedContentLength(received_content_length, | 847 StoreAccumulatedContentLength(received_content_length, |
837 original_content_length, | 848 original_content_length, |
838 request_type, | 849 request_type, |
839 reinterpret_cast<Profile*>(profile_)); | 850 reinterpret_cast<Profile*>(profile_)); |
840 received_content_length_ += received_content_length; | 851 received_content_length_ += received_content_length; |
841 original_content_length_ += original_content_length; | 852 original_content_length_ += original_content_length; |
842 } | 853 } |
OLD | NEW |