1 /*
2  * Copyright (c) 2024 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 ARK_WEB_ADSBLOCK_MANAGER_WRAPPER_H_
17 #define ARK_WEB_ADSBLOCK_MANAGER_WRAPPER_H_
18 #pragma once
19 
20 #include "include/nweb_adsblock_manager.h"
21 #include "ohos_nweb/include/ark_web_adsblock_manager.h"
22 
23 namespace OHOS::ArkWeb {
24 
25 class ArkWebAdsBlockManagerWrapper : public OHOS::NWeb::NWebAdsBlockManager {
26 public:
27     ArkWebAdsBlockManagerWrapper(ArkWebRefPtr<ArkWebAdsBlockManager> ark_web_adsblock_manager);
28     ~ArkWebAdsBlockManagerWrapper() = default;
29 
30     /**
31      * @brief Set Ads Block ruleset file, containing easylist rules.
32      *
33      * @param rulesFile absolute easylist file path contains app customized ads block rules.
34      * @param replace replace internal rules or not;
35      */
36     void SetAdsBlockRules(const std::string& rulesFile, bool replace) override;
37 
38     /**
39      * @brief Add items to Ads Block Disallowed list.
40      *
41      * @param domainSuffix list of domains suffix. if web page url matches someone in the list,
42      * Ads Block will be disallowed for the web page.
43      */
44     void AddAdsBlockDisallowedList(const std::vector<std::string>& domainSuffixes) override;
45 
46     /**
47      * @brief Remove items from Ads Block disallowed list.
48      *
49      * @param domainSuffix : list of domains suffix needed be removed from disallow list
50      */
51     void RemoveAdsBlockDisallowedList(const std::vector<std::string>& domainSuffixes) override;
52 
53     /**
54      * @brief Clear Ads Block disallowed list.
55      *
56      */
57     void ClearAdsBlockDisallowedList() override;
58 
59     /**
60      * @brief Add items to Ads Block Allowed list.
61      * By default, ads block is allowed for all pages unless they are added to the
62      * disallow list. The priority of allowlist is higher than the disallowlist. It is
63      * used to re-enable ads block on the page that matches disallow list.
64      *
65      * @param domainSuffix list of domains suffix, if web page url matches someone in the list,
66      * Ads Block will be allowed for the web page.
67      */
68     void AddAdsBlockAllowedList(const std::vector<std::string>& domainSuffixes) override;
69 
70     /**
71      * @brief Remove items from Ads Block allowed list.
72      *
73      * @param domainSuffix : list of domains suffix needed be removed from allow list
74      */
75     void RemoveAdsBlockAllowedList(const std::vector<std::string>& domainSuffixes) override;
76 
77     /**
78      * @brief Clear Ads Block allow list.
79      *
80      */
81     void ClearAdsBlockAllowedList() override;
82 
83 private:
84     ArkWebRefPtr<ArkWebAdsBlockManager> ark_web_adsblock_manager_;
85 };
86 
87 } // namespace OHOS::ArkWeb
88 
89 #endif // ARK_WEB_ADSBLOCK_MANAGER_WRAPPER_H_
90