1 /* 2 * Copyright (c) 2022 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 #ifndef NWEB_WEBVIEW_HAS_IMAGE_CALLBACK_H 16 #define NWEB_WEBVIEW_HAS_IMAGE_CALLBACK_H 17 18 #include <uv.h> 19 #include "napi/native_api.h" 20 #include "napi/native_node_api.h" 21 #include "nweb_value_callback.h" 22 23 namespace OHOS::NWeb { 24 class WebviewHasImageCallback : public OHOS::NWeb::NWebValueCallback<bool> { 25 public: WebviewHasImageCallback(napi_env env,napi_ref callbackRef,napi_deferred deferred)26 explicit WebviewHasImageCallback(napi_env env, napi_ref callbackRef, napi_deferred deferred) 27 : env_(env), callbackRef_(callbackRef), deferred_(deferred) {} 28 ~WebviewHasImageCallback() = default; 29 void OnReceiveValue(bool result) override; 30 31 private: 32 struct HasImageParam { 33 napi_env env_; 34 napi_ref callbackRef_; 35 napi_deferred deferred_; 36 bool result_; 37 }; 38 39 napi_env env_ = nullptr; 40 napi_ref callbackRef_ = nullptr; 41 napi_deferred deferred_ = nullptr; 42 43 static void UvAfterWorkCb(uv_work_t* work, int status); 44 static void UvAfterWorkCbAsync(napi_env env, napi_ref callbackRef, bool result); 45 static void UvAfterWorkCbPromise(napi_env env, napi_deferred deferred, bool result); 46 }; 47 48 } 49 #endif 50