Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: components/subresource_filter/content/common/document_subresource_filter.cc

Issue 2683413003: Introduce AsyncDocumentSubresourceFilter. (Closed)
Patch Set: Fix fix blink test build. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/document_subresource_filt er.h" 5 #include "components/subresource_filter/content/common/document_subresource_filt er.h"
6 6
7 #include <climits> 7 #include <climits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 ruleset_matcher_(ruleset_->data(), ruleset_->length()), 148 ruleset_matcher_(ruleset_->data(), ruleset_->length()),
149 first_disallowed_load_callback_( 149 first_disallowed_load_callback_(
150 std::move(first_disallowed_load_callback)) { 150 std::move(first_disallowed_load_callback)) {
151 DCHECK_NE(activation_state_.activation_level, ActivationLevel::DISABLED); 151 DCHECK_NE(activation_state_.activation_level, ActivationLevel::DISABLED);
152 if (!activation_state_.filtering_disabled_for_document) 152 if (!activation_state_.filtering_disabled_for_document)
153 document_origin_.reset(new FirstPartyOrigin(std::move(document_origin))); 153 document_origin_.reset(new FirstPartyOrigin(std::move(document_origin)));
154 } 154 }
155 155
156 DocumentSubresourceFilter::~DocumentSubresourceFilter() = default; 156 DocumentSubresourceFilter::~DocumentSubresourceFilter() = default;
157 157
158 blink::WebDocumentSubresourceFilter::LoadPolicy 158 DocumentSubresourceFilter::LoadPolicy DocumentSubresourceFilter::getLoadPolicy(
159 DocumentSubresourceFilter::getLoadPolicy(
160 const blink::WebURL& resourceUrl, 159 const blink::WebURL& resourceUrl,
161 blink::WebURLRequest::RequestContext request_context) { 160 blink::WebURLRequest::RequestContext request_context) {
162 ++statistics_.num_loads_total; 161 ++statistics_.num_loads_total;
163 162
164 if (activation_state_.filtering_disabled_for_document) 163 if (activation_state_.filtering_disabled_for_document)
165 return Allow; 164 return LoadPolicy::Allow;
166 if (resourceUrl.protocolIs(url::kDataScheme)) 165 if (resourceUrl.protocolIs(url::kDataScheme))
167 return Allow; 166 return LoadPolicy::Allow;
168 167
169 // TODO(pkalinnikov): Would be good to avoid converting to GURL. 168 // TODO(pkalinnikov): Would be good to avoid converting to GURL.
170 return EvaluateLoadPolicy(GURL(resourceUrl), ToElementType(request_context)); 169 return EvaluateLoadPolicy(GURL(resourceUrl), ToElementType(request_context));
171 } 170 }
172 171
173 blink::WebDocumentSubresourceFilter::LoadPolicy 172 DocumentSubresourceFilter::LoadPolicy
174 DocumentSubresourceFilter::GetLoadPolicyForSubdocument( 173 DocumentSubresourceFilter::GetLoadPolicyForSubdocument(
175 const GURL& subdocument_url) { 174 const GURL& subdocument_url) {
176 ++statistics_.num_loads_total; 175 ++statistics_.num_loads_total;
177 176
178 if (activation_state_.filtering_disabled_for_document) 177 if (activation_state_.filtering_disabled_for_document)
179 return Allow; 178 return LoadPolicy::Allow;
180 if (subdocument_url.SchemeIs(url::kDataScheme)) 179 if (subdocument_url.SchemeIs(url::kDataScheme))
181 return Allow; 180 return LoadPolicy::Allow;
182 return EvaluateLoadPolicy(subdocument_url, proto::ELEMENT_TYPE_SUBDOCUMENT); 181 return EvaluateLoadPolicy(subdocument_url, proto::ELEMENT_TYPE_SUBDOCUMENT);
183 } 182 }
184 183
185 void DocumentSubresourceFilter::reportDisallowedLoad() { 184 void DocumentSubresourceFilter::reportDisallowedLoad() {
186 if (first_disallowed_load_callback_.is_null()) 185 if (first_disallowed_load_callback_.is_null())
187 return; 186 return;
188 std::move(first_disallowed_load_callback_).Run(); 187 std::move(first_disallowed_load_callback_).Run();
189 } 188 }
190 189
191 blink::WebDocumentSubresourceFilter::LoadPolicy 190 DocumentSubresourceFilter::LoadPolicy
192 DocumentSubresourceFilter::EvaluateLoadPolicy(const GURL& resource_url, 191 DocumentSubresourceFilter::EvaluateLoadPolicy(const GURL& resource_url,
193 proto::ElementType element_type) { 192 proto::ElementType element_type) {
194 TRACE_EVENT1("loader", "DocumentSubresourceFilter::EvaluateLoadPolicy", "url", 193 TRACE_EVENT1("loader", "DocumentSubresourceFilter::EvaluateLoadPolicy", "url",
195 resource_url.spec()); 194 resource_url.spec());
196 195
197 auto wall_duration_timer = ScopedTimers::StartIf( 196 auto wall_duration_timer = ScopedTimers::StartIf(
198 activation_state_.measure_performance && 197 activation_state_.measure_performance &&
199 ScopedThreadTimers::IsSupported(), 198 ScopedThreadTimers::IsSupported(),
200 [this](base::TimeDelta delta) { 199 [this](base::TimeDelta delta) {
201 statistics_.evaluation_total_wall_duration += delta; 200 statistics_.evaluation_total_wall_duration += delta;
202 UMA_HISTOGRAM_MICRO_TIMES( 201 UMA_HISTOGRAM_MICRO_TIMES(
203 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration", delta); 202 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration", delta);
204 }); 203 });
205 auto cpu_duration_timer = ScopedThreadTimers::StartIf( 204 auto cpu_duration_timer = ScopedThreadTimers::StartIf(
206 activation_state_.measure_performance, [this](base::TimeDelta delta) { 205 activation_state_.measure_performance, [this](base::TimeDelta delta) {
207 statistics_.evaluation_total_cpu_duration += delta; 206 statistics_.evaluation_total_cpu_duration += delta;
208 UMA_HISTOGRAM_MICRO_TIMES( 207 UMA_HISTOGRAM_MICRO_TIMES(
209 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration", delta); 208 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration", delta);
210 }); 209 });
211 210
212 ++statistics_.num_loads_evaluated; 211 ++statistics_.num_loads_evaluated;
213 DCHECK(document_origin_); 212 DCHECK(document_origin_);
214 if (ruleset_matcher_.ShouldDisallowResourceLoad( 213 if (ruleset_matcher_.ShouldDisallowResourceLoad(
215 resource_url, *document_origin_, element_type, 214 resource_url, *document_origin_, element_type,
216 activation_state_.generic_blocking_rules_disabled)) { 215 activation_state_.generic_blocking_rules_disabled)) {
217 ++statistics_.num_loads_matching_rules; 216 ++statistics_.num_loads_matching_rules;
218 if (activation_state_.activation_level == ActivationLevel::ENABLED) { 217 if (activation_state_.activation_level == ActivationLevel::ENABLED) {
219 ++statistics_.num_loads_disallowed; 218 ++statistics_.num_loads_disallowed;
220 return Disallow; 219 return LoadPolicy::Disallow;
221 } else if (activation_state_.activation_level == ActivationLevel::DRYRUN) { 220 } else if (activation_state_.activation_level == ActivationLevel::DRYRUN) {
222 return WouldDisallow; 221 return LoadPolicy::WouldDisallow;
223 } 222 }
224 } 223 }
225 return Allow; 224 return LoadPolicy::Allow;
226 } 225 }
227 226
228 } // namespace subresource_filter 227 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698