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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAVIGATION_ROUTE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAVIGATION_ROUTE_H
18 
19 #include <map>
20 #include "base/memory/ace_type.h"
21 #include "base/memory/referenced.h"
22 
23 namespace OHOS::Ace::NG {
24 using NavigationLoadPageCallback = std::function<int32_t(
25     const std::string& bundleName, const std::string& moduleName, const std::string& pageName, bool isSingleton)>;
26 // navigation map info
27 struct RouteItem {
28     std::optional<std::string> name;
29     std::optional<std::string> bundleName;
30     std::optional<std::string> moduleName;
31     std::optional<std::string> buildFunction;
32     std::optional<std::string> pageSourceFile;
33     std::map<std::string, std::string> data;
34 };
35 
36 class ACE_EXPORT NavigationRoute : public AceType {
37     DECLARE_ACE_TYPE(NavigationRoute, AceType);
38 public:
39     NavigationRoute() = default;
40     ~NavigationRoute() = default;
41 
GetRouteItem(const std::string & name,RouteItem & info)42     virtual bool GetRouteItem(const std::string& name, RouteItem& info)
43     {
44         return false;
45     }
46 
HasLoaded(const std::string & name)47     virtual bool HasLoaded(const std::string& name)
48     {
49         return false;
50     }
51 
LoadPage(const std::string & name)52     virtual int32_t LoadPage(const std::string& name)
53     {
54         return 0;
55     }
56 
SetLoadPageCallback(NavigationLoadPageCallback callback)57     void SetLoadPageCallback(NavigationLoadPageCallback callback)
58     {
59         callback_ = std::move(callback);
60     }
61 
IsNavigationItemExits(const std::string & name)62     virtual bool IsNavigationItemExits(const std::string& name)
63     {
64         return false;
65     }
66 
InitRouteMap()67     virtual void InitRouteMap() {}
68 
69 protected:
70     NavigationLoadPageCallback callback_;
71 };
72 } // namespace OHOS::Ace::NG
73 
74 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_PAGE_URL_CHECKER_H