• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "webview_function.h"
17 #include "cj_lambda.h"
18 
19 #include "nweb.h"
20 #include "nweb_helper.h"
21 #include "nweb_log.h"
22 #include "web_errors.h"
23 
24 namespace OHOS {
25 namespace NWeb {
26 using namespace NWebError;
27 
28 std::unordered_map<std::string, std::function<void(std::function<void(void)>)>> onceType = {
29     {"webInited", RegisterWebInitedCallback},
30 };
31 
FfiOnce(char * cType,void (* callbackRef)(void))32 int32_t FfiOnce(char* cType, void (*callbackRef)(void))
33 {
34     std::string type = std::string(cType);
35     if (onceType.find(type) == onceType.end()) {
36         return PARAM_CHECK_ERROR;
37     }
38     std::function<void(void)> callback = CJLambda::Create(callbackRef);
39     onceType.find(type)->second(callback);
40     return NO_ERROR;
41 }
42 
RegisterWebInitedCallback(std::function<void (void)> callback)43 void RegisterWebInitedCallback(std::function<void(void)> callback)
44 {
45     WebRunInitedCallback *runWebInitedCallbackObj = new (std::nothrow) WebRunInitedCallbackImpl(callback);
46     if (runWebInitedCallbackObj == nullptr) {
47         return;
48     }
49     OhosAdapterHelper::GetInstance().GetInitWebAdapter()->SetRunWebInitedCallback(std::move(runWebInitedCallbackObj));
50 }
51 
RunInitedCallback()52 void WebRunInitedCallbackImpl::RunInitedCallback()
53 {
54     callbackRef_();
55 }
56 } // namespace NWeb
57 } // namespace OHOS
58