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

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

Issue 2894813003: [subresource_filter] Add observer interface for page activation (Closed)
Patch Set: use another method Created 3 years, 7 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_throttle_manager.cc
diff --git a/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.cc b/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.cc
index 6b57efe16887a80688b7642f60bcaca6b9c30edf..1ad008c981863cd84ca2fcea8eaf614b23d1388c 100644
--- a/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.cc
+++ b/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.cc
@@ -4,6 +4,8 @@
#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
+#include <utility>
+
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
@@ -11,6 +13,7 @@
#include "components/subresource_filter/content/browser/async_document_subresource_filter.h"
#include "components/subresource_filter/content/browser/page_load_statistics.h"
#include "components/subresource_filter/content/browser/subframe_navigation_filtering_throttle.h"
+#include "components/subresource_filter/content/browser/subresource_filter_observer_manager.h"
#include "components/subresource_filter/content/common/subresource_filter_messages.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/navigation_throttle.h"
@@ -26,23 +29,22 @@ ContentSubresourceFilterThrottleManager::
VerifiedRulesetDealer::Handle* dealer_handle,
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
+ scoped_observer_(this),
dealer_handle_(dealer_handle),
delegate_(delegate),
- weak_ptr_factory_(this) {}
+ weak_ptr_factory_(this) {
+ SubresourceFilterObserverManager::CreateForWebContents(web_contents);
+ scoped_observer_.Add(
+ SubresourceFilterObserverManager::FromWebContents(web_contents));
+}
ContentSubresourceFilterThrottleManager::
~ContentSubresourceFilterThrottleManager() {}
-void ContentSubresourceFilterThrottleManager::NotifyPageActivationComputed(
- content::NavigationHandle* navigation_handle,
- const ActivationState& activation_state) {
- DCHECK(navigation_handle->IsInMainFrame());
- DCHECK(!navigation_handle->HasCommitted());
- auto it = ongoing_activation_throttles_.find(navigation_handle);
- if (it != ongoing_activation_throttles_.end()) {
- it->second->NotifyPageActivationWithRuleset(EnsureRulesetHandle(),
- activation_state);
- }
+void ContentSubresourceFilterThrottleManager::OnSubresourceFilterGoingAway() {
+ // Stop observing here because the observer manager could be destroyed by the
+ // time this class is destroyed.
+ scoped_observer_.RemoveAll();
}
void ContentSubresourceFilterThrottleManager::RenderFrameDeleted(
@@ -139,6 +141,26 @@ bool ContentSubresourceFilterThrottleManager::OnMessageReceived(
return handled;
}
+// Sets the desired page-level |activation_state| for the currently ongoing
+// page load, identified by its main-frame |navigation_handle|. If this method
+// is not called for a main-frame navigation, the default behavior is no
+// activation for that page load.
+void ContentSubresourceFilterThrottleManager::OnPageActivationComputed(
+ content::NavigationHandle* navigation_handle,
+ ActivationDecision activation_decision,
+ const ActivationState& activation_state) {
+ DCHECK(navigation_handle->IsInMainFrame());
+ DCHECK(!navigation_handle->HasCommitted());
+ // Do not notify the throttle if activation is disabled.
+ if (activation_state.activation_level == ActivationLevel::DISABLED)
+ return;
+ auto it = ongoing_activation_throttles_.find(navigation_handle);
+ if (it != ongoing_activation_throttles_.end()) {
+ it->second->NotifyPageActivationWithRuleset(EnsureRulesetHandle(),
+ activation_state);
+ }
+}
+
void ContentSubresourceFilterThrottleManager::MaybeAppendNavigationThrottles(
content::NavigationHandle* navigation_handle,
std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {

Powered by Google App Engine
This is Rietveld 408576698