blob: 1445c1c5ece49567909eb59c2d8a8bb08db4682f [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#import "ios/web/web_state/ui/wk_web_view_configuration_provider_observer.h"
@class WKContentRuleList;
@class WKUserContentController;
namespace web {
class BrowserState;
enum class CookieBlockingMode;
// A provider class that handles compiling and configuring Content Blocker
// rules.
class WKContentRuleListProvider {
explicit WKContentRuleListProvider(BrowserState* browser_state);
// Sets the WKUserContentController that this provider will install its rules
// on.
void SetUserContentController(
WKUserContentController* user_content_controller);
// Updates and re-installs the Content Blocker rules using any new state.
// This may be asynchronous if a rule list hasn't been compiled yet, so
// |callback| will be called after the mode is set. It will be called with
// true if the update is successful and false otherwise (most likely because
// rules were updated again before the first set of rules was fully
// installed).
void UpdateContentRuleLists(base::OnceCallback<void(bool)> callback);
WKContentRuleListProvider(const WKContentRuleListProvider&) = delete;
WKContentRuleListProvider& operator=(const WKContentRuleListProvider&) =
// Installs the content rule list that should be installed given the current
// block setting.
void InstallContentRuleLists();
// Uninstalls all content rule lists installed by this provider.
void UninstallContentRuleLists();
BrowserState* browser_state_;
__weak WKUserContentController* user_content_controller_;
WKContentRuleList* block_content_rule_list_;
WKContentRuleList* block_third_party_content_rule_list_;
WKContentRuleList* block_local_rule_list_;
base::OnceCallback<void(bool)> update_callback_;
base::WeakPtrFactory<WKContentRuleListProvider> weak_ptr_factory_;
} // namespace web