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 #include "cj_router_ffi.h"
17
18 #include "bridge/cj_frontend/frontend/cj_frontend_abstract.h"
19 #include "bridge/cj_frontend/frontend/cj_page_router_abstract.h"
20 #include "bridge/cj_frontend/interfaces/cj_ffi/utils.h"
21 #include "core/common/container.h"
22 #include "core/components/page/page_target.h"
23
24 using namespace OHOS::Ace;
25 using namespace OHOS::Ace::Framework;
26
27 extern "C" {
FfiOHOSAceFrameworkRouterPush(const char * url,const char * param)28 void FfiOHOSAceFrameworkRouterPush(const char* url, const char* param)
29 {
30 if (Container::CurrentId() < 0) {
31 LOGE("RouterPush fail, no current container");
32 return;
33 }
34 auto frontend = Utils::GetCurrentFrontend();
35 if (!frontend) {
36 LOGE("can not get frontend.");
37 return;
38 }
39 frontend->PushPage(url, param);
40 }
41
FfiOHOSAceFrameworkRouterBack(const char * url,const char * param)42 void FfiOHOSAceFrameworkRouterBack(const char* url, const char* param)
43 {
44 if (Container::CurrentId() < 0) {
45 LOGE("RouterBack fail, no current container");
46 return;
47 }
48 auto frontend = AceType::DynamicCast<CJFrontendAbstract>(Utils::GetCurrentFrontend());
49 if (!frontend) {
50 LOGE("can not get frontend.");
51 return;
52 }
53 frontend->Back(url, param);
54 }
55
FfiOHOSAceFrameworkRouterGetParams()56 ExternalString FfiOHOSAceFrameworkRouterGetParams()
57 {
58 if (Container::CurrentId() < 0) {
59 LOGE("RouterGetParams fail, no current container");
60 return {};
61 }
62
63 auto frontend = AceType::DynamicCast<CJFrontendAbstract>(Utils::GetCurrentFrontend());
64 if (!frontend) {
65 LOGE("can not get frontend.");
66 return {};
67 }
68
69 return Utils::MallocCString(frontend->GetParams());
70 }
71 }
72