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