1 /* 2 * Copyright (c) 2023-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 OHOS_ABILITY_RUNTIME_JS_AUTO_SAVE_REQUEST_CALLBACK_H 17 #define OHOS_ABILITY_RUNTIME_JS_AUTO_SAVE_REQUEST_CALLBACK_H 18 19 #include "save_request_callback_interface.h" 20 #include "native_engine/native_value.h" 21 22 class NativeReference; 23 namespace OHOS { 24 namespace AbilityRuntime { 25 using AutoFillManagerFunc = std::function<void(int32_t)>; 26 class JsAutoSaveRequestCallback : public ISaveRequestCallback, 27 public std::enable_shared_from_this<JsAutoSaveRequestCallback> { 28 public: 29 JsAutoSaveRequestCallback(napi_env env, int32_t instanceId, AutoFillManagerFunc autoFillManagerFunc); 30 virtual ~JsAutoSaveRequestCallback(); 31 32 void Register(napi_value value); 33 void OnSaveRequestSuccess() override; 34 void OnSaveRequestFailed() override; 35 36 private: 37 void JSCallFunction(const std::string &methodName); 38 void JSCallFunctionWorker(const std::string &methodName); 39 bool IsJsCallbackEquals(std::shared_ptr<NativeReference> callback, napi_value value); 40 41 napi_env env_ = nullptr; 42 std::shared_ptr<NativeReference> callback_; 43 int32_t instanceId_ = -1; 44 AutoFillManagerFunc autoFillManagerFunc_ = nullptr; 45 }; 46 } // namespace AbilityRuntime 47 } // namespace OHOS 48 #endif // OHOS_ABILITY_RUNTIME_JS_AUTO_SAVE_REQUEST_CALLBACK_H 49