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

Unified Diff: components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc

Issue 2762403002: Wire up the ThrottleManager using the existing page activation logic (Closed)
Patch Set: engedy review Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc
diff --git a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc
index 410b37382d6f5b76f56cd82d171adc47089cce45..97f23d1ab8fb7b4476f417638f42d31d412578d5 100644
--- a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc
+++ b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc
@@ -13,8 +13,10 @@
#include "components/subresource_filter/content/common/subresource_filter_messages.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h"
#include "components/subresource_filter/core/common/activation_list.h"
+#include "components/subresource_filter/core/common/activation_state.h"
#include "components/subresource_filter/core/common/time_measurements.h"
#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "ipc/ipc_message_macros.h"
@@ -90,6 +92,11 @@ ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory(
std::unique_ptr<SubresourceFilterClient> client)
: content::WebContentsObserver(web_contents),
client_(std::move(client)),
+ throttle_manager_(
+ base::MakeUnique<ContentSubresourceFilterThrottleManager>(
+ this,
+ client_->GetRulesetDealer(),
+ web_contents)),
activation_level_(ActivationLevel::DISABLED),
activation_decision_(ActivationDecision::UNKNOWN),
measure_performance_(false) {}
@@ -97,14 +104,6 @@ ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory(
ContentSubresourceFilterDriverFactory::
~ContentSubresourceFilterDriverFactory() {}
-void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() {
- if (ShouldSuppressNotifications())
- return;
-
- client_->ToggleNotificationVisibility(activation_level_ ==
- ActivationLevel::ENABLED);
-}
-
void ContentSubresourceFilterDriverFactory::OnDocumentLoadStatistics(
const DocumentLoadStatistics& statistics) {
// Note: Chances of overflow are negligible.
@@ -184,17 +183,6 @@ ContentSubresourceFilterDriverFactory::ComputeActivationDecisionForMainFrameURL(
}
}
-void ContentSubresourceFilterDriverFactory::ActivateForFrameHostIfNeeded(
- content::RenderFrameHost* render_frame_host,
- const GURL& url) {
- if (activation_level_ != ActivationLevel::DISABLED) {
- render_frame_host->Send(
- new SubresourceFilterMsg_ActivateForNextCommittedLoad(
- render_frame_host->GetRoutingID(), activation_level_,
- measure_performance_));
- }
-}
-
void ContentSubresourceFilterDriverFactory::OnReloadRequested() {
UMA_HISTOGRAM_BOOLEAN("SubresourceFilter.Prompt.NumReloads", true);
const GURL& whitelist_url = web_contents()->GetLastCommittedURL();
@@ -211,6 +199,56 @@ void ContentSubresourceFilterDriverFactory::OnReloadRequested() {
web_contents()->GetController().Reload(content::ReloadType::NORMAL, true);
}
+void ContentSubresourceFilterDriverFactory::WillProcessResponse(
+ content::NavigationHandle* navigation_handle) {
+ DCHECK(!navigation_handle->IsSameDocument());
+ if (!navigation_handle->IsInMainFrame() ||
+ navigation_handle->GetNetErrorCode() != net::OK) {
+ return;
+ }
+
+ const GURL& url = navigation_handle->GetURL();
+ const content::Referrer& referrer = navigation_handle->GetReferrer();
+ ui::PageTransition transition = navigation_handle->GetPageTransition();
+
+ RecordRedirectChainMatchPattern();
+
+ if (ShouldWhitelistSiteOnReload() &&
+ NavigationIsPageReload(url, referrer, transition)) {
+ // Whitelist this host for the current as well as subsequent navigations.
+ AddHostOfURLToWhitelistSet(url);
+ }
+
+ activation_decision_ = ComputeActivationDecisionForMainFrameURL(url);
+ DCHECK(activation_decision_ != ActivationDecision::UNKNOWN);
+ if (activation_decision_ != ActivationDecision::ACTIVATED) {
+ ResetActivationState();
+ return;
+ }
+
+ activation_level_ = GetMaximumActivationLevel();
+ measure_performance_ = activation_level_ != ActivationLevel::DISABLED &&
+ ShouldMeasurePerformanceForPageLoad();
+ ActivationState state = ActivationState(activation_level_);
+ state.measure_performance = measure_performance_;
+ throttle_manager_->NotifyPageActivationComputed(navigation_handle, state);
+}
+
+void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() {
+ if (ShouldSuppressNotifications())
+ return;
+
+ client_->ToggleNotificationVisibility(activation_level_ ==
+ ActivationLevel::ENABLED);
+}
+
+bool ContentSubresourceFilterDriverFactory::ShouldSuppressActivation(
+ content::NavigationHandle* navigation_handle) {
+ // Never suppress subframe navigations.
+ return navigation_handle->IsInMainFrame() &&
+ IsWhitelisted(navigation_handle->GetURL());
+}
+
void ContentSubresourceFilterDriverFactory::ResetActivationState() {
navigation_chain_.clear();
activation_list_matches_.clear();
@@ -237,25 +275,6 @@ void ContentSubresourceFilterDriverFactory::DidRedirectNavigation(
navigation_chain_.push_back(navigation_handle->GetURL());
}
-void ContentSubresourceFilterDriverFactory::ReadyToCommitNavigation(
- content::NavigationHandle* navigation_handle) {
- DCHECK(!navigation_handle->IsSameDocument());
-
- // ReadyToCommitNavigation with browser-side navigation disabled is not called
- // in production code for failed navigations (e.g. network errors). We don't
- // want to activate on these pages, so we bail early to guarantee consistent
- // behavior regardless of whether browser-side navigation is enabled.
- if (navigation_handle->GetNetErrorCode() != net::OK)
- return;
-
- content::RenderFrameHost* render_frame_host =
- navigation_handle->GetRenderFrameHost();
- GURL url = navigation_handle->GetURL();
- const content::Referrer& referrer = navigation_handle->GetReferrer();
- ui::PageTransition transition = navigation_handle->GetPageTransition();
- ReadyToCommitNavigationInternal(render_frame_host, url, referrer, transition);
-}
-
void ContentSubresourceFilterDriverFactory::DidFinishLoad(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url) {
@@ -302,8 +321,6 @@ bool ContentSubresourceFilterDriverFactory::OnMessageReceived(
content::RenderFrameHost* render_frame_host) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ContentSubresourceFilterDriverFactory, message)
- IPC_MESSAGE_HANDLER(SubresourceFilterHostMsg_DidDisallowFirstSubresource,
- OnFirstSubresourceLoadDisallowed)
IPC_MESSAGE_HANDLER(SubresourceFilterHostMsg_DocumentLoadStatistics,
OnDocumentLoadStatistics)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -311,37 +328,6 @@ bool ContentSubresourceFilterDriverFactory::OnMessageReceived(
return handled;
}
-void ContentSubresourceFilterDriverFactory::ReadyToCommitNavigationInternal(
- content::RenderFrameHost* render_frame_host,
- const GURL& url,
- const content::Referrer& referrer,
- ui::PageTransition transition) {
- if (render_frame_host->GetParent()) {
- ActivateForFrameHostIfNeeded(render_frame_host, url);
- return;
- }
-
- RecordRedirectChainMatchPattern();
-
- if (ShouldWhitelistSiteOnReload() &&
- NavigationIsPageReload(url, referrer, transition)) {
- // Whitelist this host for the current as well as subsequent navigations.
- AddHostOfURLToWhitelistSet(url);
- }
-
- activation_decision_ = ComputeActivationDecisionForMainFrameURL(url);
- DCHECK(activation_decision_ != ActivationDecision::UNKNOWN);
- if (activation_decision_ != ActivationDecision::ACTIVATED) {
- ResetActivationState();
- return;
- }
-
- activation_level_ = GetMaximumActivationLevel();
- measure_performance_ = activation_level_ != ActivationLevel::DISABLED &&
- ShouldMeasurePerformanceForPageLoad();
- ActivateForFrameHostIfNeeded(render_frame_host, url);
-}
-
bool ContentSubresourceFilterDriverFactory::DidURLMatchActivationList(
const GURL& url,
ActivationList activation_list) const {

Powered by Google App Engine
This is Rietveld 408576698