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 16 #ifndef NWEB_NAPI_WEB_ASYNC_CONTROLLER_H 17 #define NWEB_NAPI_WEB_ASYNC_CONTROLLER_H 18 19 #include "hilog/log.h" 20 #include "napi/native_api.h" 21 #include "napi/native_common.h" 22 #include "napi/native_node_api.h" 23 24 namespace OHOS { 25 namespace NWeb { 26 // The asynchronous interface of NWeb is implemented through this interface. 27 class NapiWebAsyncController { 28 public: 29 NapiWebAsyncController(napi_env env, napi_value thisVar, int32_t nwebId); 30 ~NapiWebAsyncController() = default; 31 32 static napi_value Init(napi_env env, napi_value exports); 33 34 private: 35 static napi_value JS_NapiWebAsyncController(napi_env env, napi_callback_info info); 36 static napi_value JS_StoreWebArchive(napi_env env, napi_callback_info cbinfo); 37 38 static napi_value StoreWebArchiveInternal(napi_env env, napi_callback_info cbinfo, const std::string &baseName, 39 bool autoName); 40 41 // Saves the current view as a web archive by way of callback. 42 void StoreWebArchiveCallback(const std::string &baseName, bool autoName, napi_env env, napi_ref jsCallback); 43 // Saves the current view as a web archive by way of promise. 44 void StoreWebArchivePromise(const std::string &baseName, bool autoName, napi_env env, napi_deferred deferred); 45 46 int32_t nwebId_ { -1 }; 47 }; 48 } // namespace NWeb 49 } // namespace OHOS 50 51 #endif // NWEB_NAPI_WEB_ASYNC_CONTROLLER_H 52