1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NWEB_ADSBLOCK_MANAGER_H
17 #define NWEB_ADSBLOCK_MANAGER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "nweb_export.h"
23 
24 namespace OHOS::NWeb {
25 class OHOS_NWEB_EXPORT NWebAdsBlockManager {
26 public:
27     NWebAdsBlockManager() = default;
28 
29     virtual ~NWebAdsBlockManager() = default;
30 
31     /**
32      * @brief Set Ads Block ruleset file, containing easylist rules.
33      *
34      * @param rulesFile absolute easylist file path contains app customized ads block rules.
35      * @param replace replace internal rules or not;
36      */
37     virtual void SetAdsBlockRules(const std::string& rulesFile, bool replace) = 0;
38 
39     /**
40      * @brief Add items to Ads Block Disallowed list.
41      *
42      * @param domainSuffix list of domains suffix. if web page url matches someone in the list,
43      * Ads Block will be disallowed for the web page.
44      */
45     virtual void AddAdsBlockDisallowedList(const std::vector<std::string>& domainSuffixes) = 0;
46 
47     /**
48      * @brief Remove items from Ads Block disallowed list.
49      *
50      * @param domainSuffix : list of domains suffix needed be removed from disallow list
51      */
52     virtual void RemoveAdsBlockDisallowedList(const std::vector<std::string>& domainSuffixes) = 0;
53 
54     /**
55      * @brief Clear Ads Block disallowed list.
56      *
57      */
58     virtual void ClearAdsBlockDisallowedList() = 0;
59 
60     /**
61      * @brief Add items to Ads Block Allowed list.
62      * By default, ads block is allowed for all pages unless they are added to the
63      * disallow list. The priority of allowlist is higher than the disallowlist. It is
64      * used to re-enable ads block on the page that matches disallow list.
65      *
66      * @param domainSuffix list of domains suffix, if web page url matches someone in the list,
67      * Ads Block will be allowed for the web page.
68      */
69     virtual void AddAdsBlockAllowedList(const std::vector<std::string>& domainSuffixes) = 0;
70 
71     /**
72      * @brief Remove items from Ads Block allowed list.
73      *
74      * @param domainSuffix : list of domains suffix needed be removed from allow list
75      */
76     virtual void RemoveAdsBlockAllowedList(const std::vector<std::string>& domainSuffixes) = 0;
77 
78     /**
79      * @brief Clear Ads Block allow list.
80      *
81      */
82     virtual void ClearAdsBlockAllowedList() = 0;
83 };
84 
85 } // namespace OHOS::NWeb
86 
87 #endif // NWEB_ADSBLOCK_MANAGER_H
88