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 #include "navigation_controller_helper.h"
17 
18 #include "ui_content_impl.h"
19 
20 namespace OHOS {
21 namespace Ace {
OHOS_ACE_GetNavigationController( UIContent* uiContent, const char* navigationId)22 extern "C" ACE_FORCE_EXPORT void* OHOS_ACE_GetNavigationController(
23     UIContent* uiContent, const char* navigationId)
24 {
25     return NavigationControllerHelper::GetNavigationController(uiContent, navigationId);
26 }
27 
GetNavigationController( UIContent* uiContent, const std::string& navigationId)28 NavigationController* NavigationControllerHelper::GetNavigationController(
29     UIContent* uiContent, const std::string& navigationId)
30 {
31     if (navigationId.empty()) {
32         TAG_LOGW(AceLogTag::ACE_NAVIGATION, "navigationId is empty");
33         return nullptr;
34     }
35 
36     OHOS::Ace::UIContentImpl* uiContentImpl = reinterpret_cast<OHOS::Ace::UIContentImpl*>(uiContent);
37     if (uiContentImpl == nullptr) {
38         TAG_LOGW(AceLogTag::ACE_NAVIGATION, "uiContentImpl is null");
39         return nullptr;
40     }
41 
42     int32_t instanceId = uiContentImpl->GetInstanceId();
43     auto container = Platform::AceContainer::GetContainer(instanceId);
44     if (!container) {
45         TAG_LOGW(AceLogTag::ACE_NAVIGATION, "container is nullptr, instanceId is %{public}d", instanceId);
46         return nullptr;
47     }
48 
49     return container->GetNavigationController(navigationId).get();
50 }
51 } // namespace Ace
52 } // namespace OHOS
53