chromium/components/subresource_filter/content/browser/content_subresource_filter_web_contents_helper.h

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER_WEB_CONTENTS_HELPER_H_
#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER_WEB_CONTENTS_HELPER_H_

#include <set>

#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/scoped_observation.h"
#include "components/subresource_filter/content/browser/subresource_filter_observer.h"
#include "components/subresource_filter/content/browser/subresource_filter_observer_manager.h"
#include "components/subresource_filter/core/browser/verified_ruleset_dealer.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"

namespace content {
class NavigationHandle;
class Page;
class RenderFrameHost;
class WebContents;
}  // namespace content

namespace safe_browsing {
class SafeBrowsingDatabaseManager;
}  // namespace safe_browsing

namespace subresource_filter {

class ContentSubresourceFilterThrottleManager;
class SubresourceFilterProfileContext;

// This class manages the lifetime and storage of
// ContentSubresourceFilterThrottleManager instances. This helper is attached
// to each WebContents and listens to navigations to ensure certain Page(s) in
// the WebContents have an associated throttle manager. A throttle manager is
// created for outermost pages. Fenced frames are treated as subframes and don't
// create a throttle manager; they use the throttle manager of their embedding
// page.
//
// This class also listens to events occurring in the WebContents and
// SubresourceFilter and, based on their context, routes the event to the
// throttle manager of the target page.
// TODO(bokan): This seems like a common pattern for a feature to want to
// observe events and track state on a per-Page basis. The WebContentsHelper
// pattern or something like it should be wrapped up into a common and reusable
// //content API. See:
// https://docs.google.com/document/d/1p-IXk8hI5ucWRf5vJEi9K_YvJXsTr8kbvzGrjMcALDE/edit?usp=sharing
class ContentSubresourceFilterWebContentsHelper
    : public content::WebContentsUserData<
          ContentSubresourceFilterWebContentsHelper>,
      public content::WebContentsObserver,
      public SubresourceFilterObserver {};

}  // namespace subresource_filter

#endif  // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER_WEB_CONTENTS_HELPER_H_