• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_IMPL_H_
17 #define ARK_WEB_ADSBLOCK_MANAGER_IMPL_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 ArkWebAdsBlockManagerImpl : public ArkWebAdsBlockManager {
26   IMPLEMENT_REFCOUNTING(ArkWebAdsBlockManagerImpl);
27 
28 public:
29   ArkWebAdsBlockManagerImpl(std::shared_ptr<OHOS::NWeb::NWebAdsBlockManager> nweb_adsblock_manager);
30   ~ArkWebAdsBlockManagerImpl() = default;
31 
32   /**
33    * @brief Set Ads Block ruleset file, containing easylist rules.
34    *
35    * @param rulesFile absolute easylist file path contains app customized ads
36    * block rules.
37    * @param replace replace internal rules or not;
38    */
39   void SetAdsBlockRules(const ArkWebString &url, bool replace) override;
40 
41   /**
42    * @brief Add items to Ads Block Disallowed list.
43    *
44    * @param domainSuffix list of domains suffix. if web page url matches someone
45    * in the list, Ads Block will be disallowed for the web page.
46    */
47   void AddAdsBlockDisallowedList(const ArkWebStringVector &domainSuffixes) override;
48 
49   /**
50    * @brief Remove items from Ads Block disallowed list.
51    *
52    * @param domainSuffix : list of domains suffix needed be removed from
53    * disallow list
54    */
55   void RemoveAdsBlockDisallowedList(const ArkWebStringVector &domainSuffixes) override;
56 
57   /**
58    * @brief Clear Ads Block disallowed list.
59    *
60    */
61   void ClearAdsBlockDisallowedList() override;
62 
63   /**
64    * @brief Add items to Ads Block Allowed list.
65    * By default, ads block is allowed for all pages unless they are added to the
66    * disallow list. The priority of allowlist is higher than the disallowlist.
67    * It is used to re-enable ads block on the page that matches disallow list.
68    *
69    * @param domainSuffix list of domains suffix, if web page url matches someone
70    * in the list, Ads Block will be allowed for the web page.
71    */
72   void AddAdsBlockAllowedList(const ArkWebStringVector &domainSuffixes) override;
73 
74   /**
75    * @brief Remove items from Ads Block allowed list.
76    *
77    * @param domainSuffix : list of domains suffix needed be removed from allow
78    * list
79    */
80   void RemoveAdsBlockAllowedList(const ArkWebStringVector &domainSuffixes) override;
81 
82   /**
83    * @brief Clear Ads Block allow list.
84    *
85    */
86   void ClearAdsBlockAllowedList() override;
87 
88 private:
89   std::shared_ptr<OHOS::NWeb::NWebAdsBlockManager> nweb_adsblock_manager_;
90 };
91 
92 } // namespace OHOS::ArkWeb
93 
94 #endif // ARK_WEB_ADSBLOCK_MANAGER_IMPL_H_
95