1 /*
2  * Copyright (c) 2023 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 FOUNDATION_ACE_ADAPTER_OHOS_OSAL_PAGE_URL_CHECKER_OHOS_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_PAGE_URL_CHECKER_OHOS_H
18 
19 #include "frameworks/core/common/page_url_checker.h"
20 
21 #include "bundlemgr/bundle_mgr_interface.h"
22 #include "interfaces/inner_api/ace/ui_content.h"
23 
24 namespace OHOS::Ace {
25 class PageUrlCheckerOhos : public PageUrlChecker {
DECLARE_ACE_TYPE(PageUrlCheckerOhos,PageUrlChecker)26     DECLARE_ACE_TYPE(PageUrlCheckerOhos, PageUrlChecker)
27 
28 public:
29     explicit PageUrlCheckerOhos(
30         const std::shared_ptr<OHOS::AbilityRuntime::Context>& context) : context_(context) {}
PageUrlCheckerOhos(const std::shared_ptr<OHOS::AbilityRuntime::Context> & context,const std::shared_ptr<OHOS::AppExecFwk::AbilityInfo> & abilityInfo)31     PageUrlCheckerOhos(
32         const std::shared_ptr<OHOS::AbilityRuntime::Context>& context,
33         const std::shared_ptr<OHOS::AppExecFwk::AbilityInfo>& abilityInfo)
34         : context_(context), abilityInfo_(abilityInfo) {}
35     ~PageUrlCheckerOhos() = default;
36     void LoadPageUrl(const std::string& url, const std::function<void()>& callback,
37         const std::function<void(int32_t, const std::string&)>& silentInstallErrorCallBack) override;
38     void CheckPreload(const std::string& url) override;
39 
40     void NotifyPageShow(const std::string& pageName) override;
41     void NotifyPageHide(const std::string& pageName) override;
42     void SetModuleNameCallback(std::function<std::string(const std::string&)>&& callback) override;
43 
44 private:
45     sptr<AppExecFwk::IBundleMgr> GetBundleManager();
46     std::shared_ptr<OHOS::AbilityRuntime::Context> context_;
47     std::shared_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo_;
48     std::function<std::string(const std::string&)> moduleNameCallback_;
49     void GetTargetPageInfo(const std::string& pageName, std::string& targetBundleName,
50         std::string& targetModuleName) const;
51 };
52 } // namespace OHOS::Ace
53 
54 #endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_PAGE_URL_CHECKER_OHOS_H