OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" | 5 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" |
6 | 6 |
7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "components/subresource_filter/content/browser/content_activation_list_
utils.h" | 12 #include "components/subresource_filter/content/browser/content_activation_list_
utils.h" |
13 #include "components/subresource_filter/content/browser/subresource_filter_clien
t.h" | 13 #include "components/subresource_filter/content/browser/subresource_filter_clien
t.h" |
14 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" | 14 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
15 #include "components/subresource_filter/core/common/activation_list.h" | 15 #include "components/subresource_filter/core/common/activation_list.h" |
16 #include "components/subresource_filter/core/common/activation_state.h" | 16 #include "components/subresource_filter/core/common/activation_state.h" |
17 #include "content/public/browser/navigation_handle.h" | 17 #include "content/public/browser/navigation_handle.h" |
18 #include "content/public/browser/navigation_throttle.h" | 18 #include "content/public/browser/navigation_throttle.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
| 23 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 24 subresource_filter::ContentSubresourceFilterDriverFactory); |
| 25 |
23 namespace subresource_filter { | 26 namespace subresource_filter { |
24 | 27 |
25 namespace { | 28 namespace { |
26 | 29 |
27 const char kWebContentsUserDataKey[] = | |
28 "web_contents_subresource_filter_driver_factory"; | |
29 | |
30 std::string DistillURLToHostAndPath(const GURL& url) { | 30 std::string DistillURLToHostAndPath(const GURL& url) { |
31 return url.host() + url.path(); | 31 return url.host() + url.path(); |
32 } | 32 } |
33 | 33 |
34 // Returns true with a probability given by |performance_measurement_rate| if | 34 // Returns true with a probability given by |performance_measurement_rate| if |
35 // ThreadTicks is supported, otherwise returns false. | 35 // ThreadTicks is supported, otherwise returns false. |
36 bool ShouldMeasurePerformanceForPageLoad(double performance_measurement_rate) { | 36 bool ShouldMeasurePerformanceForPageLoad(double performance_measurement_rate) { |
37 if (!base::ThreadTicks::IsSupported()) | 37 if (!base::ThreadTicks::IsSupported()) |
38 return false; | 38 return false; |
39 return performance_measurement_rate == 1 || | 39 return performance_measurement_rate == 1 || |
(...skipping 10 matching lines...) Expand all Loading... |
50 hits_pattern, 0x10); \ | 50 hits_pattern, 0x10); \ |
51 UMA_HISTOGRAM_COUNTS( \ | 51 UMA_HISTOGRAM_COUNTS( \ |
52 "SubresourceFilter.PageLoad.RedirectChainLength." suffix, chain_size); \ | 52 "SubresourceFilter.PageLoad.RedirectChainLength." suffix, chain_size); \ |
53 } while (0) | 53 } while (0) |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 // static | 57 // static |
58 void ContentSubresourceFilterDriverFactory::CreateForWebContents( | 58 void ContentSubresourceFilterDriverFactory::CreateForWebContents( |
59 content::WebContents* web_contents, | 59 content::WebContents* web_contents, |
60 std::unique_ptr<SubresourceFilterClient> client) { | 60 SubresourceFilterClient* client) { |
61 if (FromWebContents(web_contents)) | 61 if (FromWebContents(web_contents)) |
62 return; | 62 return; |
63 web_contents->SetUserData( | 63 web_contents->SetUserData( |
64 kWebContentsUserDataKey, | 64 UserDataKey(), base::MakeUnique<ContentSubresourceFilterDriverFactory>( |
65 base::MakeUnique<ContentSubresourceFilterDriverFactory>( | 65 web_contents, client)); |
66 web_contents, std::move(client))); | |
67 } | 66 } |
68 | 67 |
69 // static | 68 // static |
70 ContentSubresourceFilterDriverFactory* | |
71 ContentSubresourceFilterDriverFactory::FromWebContents( | |
72 content::WebContents* web_contents) { | |
73 return static_cast<ContentSubresourceFilterDriverFactory*>( | |
74 web_contents->GetUserData(kWebContentsUserDataKey)); | |
75 } | |
76 | |
77 // static | |
78 bool ContentSubresourceFilterDriverFactory::NavigationIsPageReload( | 69 bool ContentSubresourceFilterDriverFactory::NavigationIsPageReload( |
79 const GURL& url, | 70 const GURL& url, |
80 const content::Referrer& referrer, | 71 const content::Referrer& referrer, |
81 ui::PageTransition transition) { | 72 ui::PageTransition transition) { |
82 return ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) || | 73 return ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) || |
83 // Some pages 'reload' from JavaScript by navigating to themselves. | 74 // Some pages 'reload' from JavaScript by navigating to themselves. |
84 url == referrer.url; | 75 url == referrer.url; |
85 } | 76 } |
86 | 77 |
87 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( | 78 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( |
88 content::WebContents* web_contents, | 79 content::WebContents* web_contents, |
89 std::unique_ptr<SubresourceFilterClient> client) | 80 SubresourceFilterClient* client) |
90 : content::WebContentsObserver(web_contents), | 81 : content::WebContentsObserver(web_contents), |
91 client_(std::move(client)), | 82 client_(client), |
92 throttle_manager_( | 83 throttle_manager_( |
93 base::MakeUnique<ContentSubresourceFilterThrottleManager>( | 84 base::MakeUnique<ContentSubresourceFilterThrottleManager>( |
94 this, | 85 this, |
95 client_->GetRulesetDealer(), | 86 client_->GetRulesetDealer(), |
96 web_contents)), | 87 web_contents)), |
97 activation_level_(ActivationLevel::DISABLED), | 88 activation_level_(ActivationLevel::DISABLED), |
98 activation_decision_(ActivationDecision::UNKNOWN), | 89 activation_decision_(ActivationDecision::UNKNOWN), |
99 measure_performance_(false) {} | 90 measure_performance_(false) {} |
100 | 91 |
101 ContentSubresourceFilterDriverFactory:: | 92 ContentSubresourceFilterDriverFactory:: |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern, | 321 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern, |
331 chain_size); | 322 chain_size); |
332 break; | 323 break; |
333 default: | 324 default: |
334 NOTREACHED(); | 325 NOTREACHED(); |
335 break; | 326 break; |
336 } | 327 } |
337 } | 328 } |
338 | 329 |
339 } // namespace subresource_filter | 330 } // namespace subresource_filter |
OLD | NEW |