1bc03f14fSopenharmony_ci/* 2bc03f14fSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3bc03f14fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bc03f14fSopenharmony_ci * you may not use this file except in compliance with the License. 5bc03f14fSopenharmony_ci * You may obtain a copy of the License at 6bc03f14fSopenharmony_ci * 7bc03f14fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc03f14fSopenharmony_ci * 9bc03f14fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc03f14fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bc03f14fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc03f14fSopenharmony_ci * See the License for the specific language governing permissions and 13bc03f14fSopenharmony_ci * limitations under the License. 14bc03f14fSopenharmony_ci */ 15bc03f14fSopenharmony_ci 16bc03f14fSopenharmony_ci#include <memory> 17bc03f14fSopenharmony_ci#include "pasteboard_common.h" 18bc03f14fSopenharmony_ci#include "pasteboard_hilog.h" 19bc03f14fSopenharmony_ci#include "pasteboard_js_err.h" 20bc03f14fSopenharmony_ci#include "pasteboard_napi.h" 21bc03f14fSopenharmony_ci#include "systempasteboard_napi.h" 22bc03f14fSopenharmony_ci#include "uri.h" 23bc03f14fSopenharmony_ciusing namespace OHOS::MiscServices; 24bc03f14fSopenharmony_ciusing namespace OHOS::Media; 25bc03f14fSopenharmony_ci 26bc03f14fSopenharmony_cinamespace OHOS { 27bc03f14fSopenharmony_cinamespace MiscServicesNapi { 28bc03f14fSopenharmony_ciconstexpr size_t MAX_ARGS = 6; 29bc03f14fSopenharmony_ciconst size_t ARGC_TYPE_SET1 = 1; 30bc03f14fSopenharmony_ciconst size_t ARGC_TYPE_SET2 = 2; 31bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreateHtmlRecord(napi_env env, napi_value in) 32bc03f14fSopenharmony_ci{ 33bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreateHtmlRecord is called!"); 34bc03f14fSopenharmony_ci std::string value; 35bc03f14fSopenharmony_ci bool ret = GetValue(env, in, value); 36bc03f14fSopenharmony_ci if (!ret) { 37bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Failed to GetValue!"); 38bc03f14fSopenharmony_ci return nullptr; 39bc03f14fSopenharmony_ci } 40bc03f14fSopenharmony_ci napi_value instance = nullptr; 41bc03f14fSopenharmony_ci PasteDataRecordNapi::NewHtmlTextRecordInstance(env, value, instance); 42bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 43bc03f14fSopenharmony_ci return instance; 44bc03f14fSopenharmony_ci} 45bc03f14fSopenharmony_ci 46bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreatePlainTextRecord(napi_env env, napi_value in) 47bc03f14fSopenharmony_ci{ 48bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreatePlainTextRecord is called!"); 49bc03f14fSopenharmony_ci std::string value; 50bc03f14fSopenharmony_ci bool ret = GetValue(env, in, value); 51bc03f14fSopenharmony_ci if (!ret) { 52bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Failed to GetValue!"); 53bc03f14fSopenharmony_ci return nullptr; 54bc03f14fSopenharmony_ci } 55bc03f14fSopenharmony_ci napi_value instance = nullptr; 56bc03f14fSopenharmony_ci PasteDataRecordNapi::NewPlainTextRecordInstance(env, value, instance); 57bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 58bc03f14fSopenharmony_ci return instance; 59bc03f14fSopenharmony_ci} 60bc03f14fSopenharmony_ci 61bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreateUriRecord(napi_env env, napi_value in) 62bc03f14fSopenharmony_ci{ 63bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreateUriRecord is called!"); 64bc03f14fSopenharmony_ci std::string value; 65bc03f14fSopenharmony_ci bool ret = GetValue(env, in, value); 66bc03f14fSopenharmony_ci if (!ret) { 67bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Failed to GetValue!"); 68bc03f14fSopenharmony_ci return nullptr; 69bc03f14fSopenharmony_ci } 70bc03f14fSopenharmony_ci napi_value instance = nullptr; 71bc03f14fSopenharmony_ci PasteDataRecordNapi::NewUriRecordInstance(env, value, instance); 72bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 73bc03f14fSopenharmony_ci return instance; 74bc03f14fSopenharmony_ci} 75bc03f14fSopenharmony_ci 76bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreatePixelMapRecord(napi_env env, napi_value in) 77bc03f14fSopenharmony_ci{ 78bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreatePixelMapRecord is called!"); 79bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMap = PixelMapNapi::GetPixelMap(env, in); 80bc03f14fSopenharmony_ci if (pixelMap == nullptr) { 81bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Failed to get pixelMap!"); 82bc03f14fSopenharmony_ci return nullptr; 83bc03f14fSopenharmony_ci } 84bc03f14fSopenharmony_ci napi_value instance = nullptr; 85bc03f14fSopenharmony_ci PasteDataRecordNapi::NewPixelMapRecordInstance(env, pixelMap, instance); 86bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 87bc03f14fSopenharmony_ci return instance; 88bc03f14fSopenharmony_ci} 89bc03f14fSopenharmony_ci 90bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreateWantRecord(napi_env env, napi_value in) 91bc03f14fSopenharmony_ci{ 92bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreateWantRecord is called!"); 93bc03f14fSopenharmony_ci AAFwk::Want want; 94bc03f14fSopenharmony_ci bool ret = OHOS::AppExecFwk::UnwrapWant(env, in, want); 95bc03f14fSopenharmony_ci if (!ret) { 96bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Failed to unwrap want!"); 97bc03f14fSopenharmony_ci return nullptr; 98bc03f14fSopenharmony_ci } 99bc03f14fSopenharmony_ci napi_value instance = nullptr; 100bc03f14fSopenharmony_ci PasteDataRecordNapi::NewWantRecordInstance(env, std::make_shared<AAFwk::Want>(want), instance); 101bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 102bc03f14fSopenharmony_ci return instance; 103bc03f14fSopenharmony_ci} 104bc03f14fSopenharmony_ci 105bc03f14fSopenharmony_ci// common function of CreateHtmlData, CreatePlainTextData, CreateUriData 106bc03f14fSopenharmony_ciPasteDataNapi *PasteboardNapi::CreateDataCommon(napi_env env, napi_value in, std::string &str, napi_value &instance) 107bc03f14fSopenharmony_ci{ 108bc03f14fSopenharmony_ci bool ret = GetValue(env, in, str); 109bc03f14fSopenharmony_ci if (!ret) { 110bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "GetValue failed"); 111bc03f14fSopenharmony_ci return nullptr; 112bc03f14fSopenharmony_ci } 113bc03f14fSopenharmony_ci NAPI_CALL(env, PasteDataNapi::NewInstance(env, instance)); 114bc03f14fSopenharmony_ci PasteDataNapi *obj = nullptr; 115bc03f14fSopenharmony_ci napi_status status = napi_unwrap(env, instance, reinterpret_cast<void **>(&obj)); 116bc03f14fSopenharmony_ci if ((status != napi_ok) || (obj == nullptr)) { 117bc03f14fSopenharmony_ci return nullptr; 118bc03f14fSopenharmony_ci } 119bc03f14fSopenharmony_ci return obj; 120bc03f14fSopenharmony_ci} 121bc03f14fSopenharmony_ci 122bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreateHtmlData(napi_env env, napi_value in) 123bc03f14fSopenharmony_ci{ 124bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreateHtmlData is called!"); 125bc03f14fSopenharmony_ci std::string str; 126bc03f14fSopenharmony_ci napi_value instance = nullptr; 127bc03f14fSopenharmony_ci PasteDataNapi *obj = CreateDataCommon(env, in, str, instance); 128bc03f14fSopenharmony_ci if (obj == nullptr) { 129bc03f14fSopenharmony_ci return nullptr; 130bc03f14fSopenharmony_ci } 131bc03f14fSopenharmony_ci obj->value_ = PasteboardClient::GetInstance()->CreateHtmlData(str); 132bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 133bc03f14fSopenharmony_ci return instance; 134bc03f14fSopenharmony_ci} 135bc03f14fSopenharmony_ci 136bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreatePlainTextData(napi_env env, napi_value in) 137bc03f14fSopenharmony_ci{ 138bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreatePlainTextData is called!"); 139bc03f14fSopenharmony_ci std::string str; 140bc03f14fSopenharmony_ci napi_value instance = nullptr; 141bc03f14fSopenharmony_ci PasteDataNapi *obj = CreateDataCommon(env, in, str, instance); 142bc03f14fSopenharmony_ci if (obj == nullptr) { 143bc03f14fSopenharmony_ci return nullptr; 144bc03f14fSopenharmony_ci } 145bc03f14fSopenharmony_ci obj->value_ = PasteboardClient::GetInstance()->CreatePlainTextData(str); 146bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 147bc03f14fSopenharmony_ci return instance; 148bc03f14fSopenharmony_ci} 149bc03f14fSopenharmony_ci 150bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreateUriData(napi_env env, napi_value in) 151bc03f14fSopenharmony_ci{ 152bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreateUriData is called!"); 153bc03f14fSopenharmony_ci std::string str; 154bc03f14fSopenharmony_ci napi_value instance = nullptr; 155bc03f14fSopenharmony_ci PasteDataNapi *obj = CreateDataCommon(env, in, str, instance); 156bc03f14fSopenharmony_ci if (obj == nullptr) { 157bc03f14fSopenharmony_ci return nullptr; 158bc03f14fSopenharmony_ci } 159bc03f14fSopenharmony_ci obj->value_ = PasteboardClient::GetInstance()->CreateUriData(OHOS::Uri(str)); 160bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 161bc03f14fSopenharmony_ci return instance; 162bc03f14fSopenharmony_ci} 163bc03f14fSopenharmony_ci 164bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreatePixelMapData(napi_env env, napi_value in) 165bc03f14fSopenharmony_ci{ 166bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreatePixelMapData is called!"); 167bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMap = PixelMapNapi::GetPixelMap(env, in); 168bc03f14fSopenharmony_ci if (pixelMap == nullptr) { 169bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Failed to get pixelMap!"); 170bc03f14fSopenharmony_ci return nullptr; 171bc03f14fSopenharmony_ci } 172bc03f14fSopenharmony_ci napi_value instance = nullptr; 173bc03f14fSopenharmony_ci NAPI_CALL(env, PasteDataNapi::NewInstance(env, instance)); 174bc03f14fSopenharmony_ci PasteDataNapi *obj = nullptr; 175bc03f14fSopenharmony_ci napi_status status = napi_unwrap(env, instance, reinterpret_cast<void **>(&obj)); 176bc03f14fSopenharmony_ci if ((status != napi_ok) || (obj == nullptr)) { 177bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "unwrap Failed!"); 178bc03f14fSopenharmony_ci return nullptr; 179bc03f14fSopenharmony_ci } 180bc03f14fSopenharmony_ci obj->value_ = PasteboardClient::GetInstance()->CreatePixelMapData(pixelMap); 181bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 182bc03f14fSopenharmony_ci return instance; 183bc03f14fSopenharmony_ci} 184bc03f14fSopenharmony_ci 185bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreateWantData(napi_env env, napi_value in) 186bc03f14fSopenharmony_ci{ 187bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreateWantData is called!"); 188bc03f14fSopenharmony_ci AAFwk::Want want; 189bc03f14fSopenharmony_ci bool ret = OHOS::AppExecFwk::UnwrapWant(env, in, want); 190bc03f14fSopenharmony_ci if (!ret) { 191bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Failed to unwrap want!"); 192bc03f14fSopenharmony_ci return nullptr; 193bc03f14fSopenharmony_ci } 194bc03f14fSopenharmony_ci napi_value instance = nullptr; 195bc03f14fSopenharmony_ci NAPI_CALL(env, PasteDataNapi::NewInstance(env, instance)); 196bc03f14fSopenharmony_ci PasteDataNapi *obj = nullptr; 197bc03f14fSopenharmony_ci napi_status status = napi_unwrap(env, instance, reinterpret_cast<void **>(&obj)); 198bc03f14fSopenharmony_ci if ((status != napi_ok) || (obj == nullptr)) { 199bc03f14fSopenharmony_ci return nullptr; 200bc03f14fSopenharmony_ci } 201bc03f14fSopenharmony_ci obj->value_ = PasteboardClient::GetInstance()->CreateWantData(std::make_shared<AAFwk::Want>(want)); 202bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 203bc03f14fSopenharmony_ci return instance; 204bc03f14fSopenharmony_ci} 205bc03f14fSopenharmony_ci 206bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreateMultiTypeData(napi_env env, 207bc03f14fSopenharmony_ci std::shared_ptr<std::map<std::string, std::shared_ptr<EntryValue>>> typeValueMap) 208bc03f14fSopenharmony_ci{ 209bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreateMultiTypeData is called!"); 210bc03f14fSopenharmony_ci napi_value instance = nullptr; 211bc03f14fSopenharmony_ci NAPI_CALL(env, PasteDataNapi::NewInstance(env, instance)); 212bc03f14fSopenharmony_ci PasteDataNapi *obj = nullptr; 213bc03f14fSopenharmony_ci napi_status status = napi_unwrap(env, instance, reinterpret_cast<void **>(&obj)); 214bc03f14fSopenharmony_ci if ((status != napi_ok) || (obj == nullptr)) { 215bc03f14fSopenharmony_ci return nullptr; 216bc03f14fSopenharmony_ci } 217bc03f14fSopenharmony_ci obj->value_ = PasteboardClient::GetInstance()->CreateMultiTypeData(std::move(typeValueMap)); 218bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 219bc03f14fSopenharmony_ci return instance; 220bc03f14fSopenharmony_ci} 221bc03f14fSopenharmony_ci 222bc03f14fSopenharmony_cinapi_value PasteboardNapi::CreateMultiTypeDelayData(napi_env env, std::vector<std::string> mimeTypes, 223bc03f14fSopenharmony_ci std::shared_ptr<UDMF::EntryGetter> entryGetter) 224bc03f14fSopenharmony_ci{ 225bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "CreateMultiTypeDelayData is called!"); 226bc03f14fSopenharmony_ci napi_value instance = nullptr; 227bc03f14fSopenharmony_ci NAPI_CALL(env, PasteDataNapi::NewInstance(env, instance)); 228bc03f14fSopenharmony_ci PasteDataNapi *obj = nullptr; 229bc03f14fSopenharmony_ci napi_status status = napi_unwrap(env, instance, reinterpret_cast<void **>(&obj)); 230bc03f14fSopenharmony_ci if ((status != napi_ok) || (obj == nullptr)) { 231bc03f14fSopenharmony_ci return nullptr; 232bc03f14fSopenharmony_ci } 233bc03f14fSopenharmony_ci obj->value_ = PasteboardClient::GetInstance()->CreateMultiTypeDelayData(mimeTypes, entryGetter); 234bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "end."); 235bc03f14fSopenharmony_ci return instance; 236bc03f14fSopenharmony_ci} 237bc03f14fSopenharmony_ci 238bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreateHtmlTextRecord(napi_env env, napi_callback_info info) 239bc03f14fSopenharmony_ci{ 240bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreateHtmlTextRecord is called!"); 241bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 242bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 243bc03f14fSopenharmony_ci napi_value thisVar = nullptr; 244bc03f14fSopenharmony_ci 245bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); 246bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 247bc03f14fSopenharmony_ci 248bc03f14fSopenharmony_ci return CreateHtmlRecord(env, argv[0]); 249bc03f14fSopenharmony_ci} 250bc03f14fSopenharmony_ci 251bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreateWantRecord(napi_env env, napi_callback_info info) 252bc03f14fSopenharmony_ci{ 253bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreateWantRecord is called!"); 254bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 255bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 256bc03f14fSopenharmony_ci napi_value thisVar = nullptr; 257bc03f14fSopenharmony_ci 258bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); 259bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 260bc03f14fSopenharmony_ci napi_valuetype valueType = napi_undefined; 261bc03f14fSopenharmony_ci NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); 262bc03f14fSopenharmony_ci NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected."); 263bc03f14fSopenharmony_ci 264bc03f14fSopenharmony_ci return CreateWantRecord(env, argv[0]); 265bc03f14fSopenharmony_ci} 266bc03f14fSopenharmony_ci 267bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreateShareOption(napi_env env, napi_callback_info info) 268bc03f14fSopenharmony_ci{ 269bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreateShareOption is called!"); 270bc03f14fSopenharmony_ci 271bc03f14fSopenharmony_ci napi_value jsShareOption = nullptr; 272bc03f14fSopenharmony_ci napi_create_object(env, &jsShareOption); 273bc03f14fSopenharmony_ci 274bc03f14fSopenharmony_ci napi_value jsInApp = CreateNapiNumber(env, static_cast<int32_t>(ShareOption::InApp)); 275bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsShareOption, "InApp", jsInApp)); 276bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsShareOption, "INAPP", jsInApp)); 277bc03f14fSopenharmony_ci 278bc03f14fSopenharmony_ci napi_value jsLocalDevice = CreateNapiNumber(env, static_cast<int32_t>(ShareOption::LocalDevice)); 279bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsShareOption, "LocalDevice", jsLocalDevice)); 280bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsShareOption, "LOCALDEVICE", jsLocalDevice)); 281bc03f14fSopenharmony_ci 282bc03f14fSopenharmony_ci napi_value jsCrossDevice = CreateNapiNumber(env, static_cast<int32_t>(ShareOption::CrossDevice)); 283bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsShareOption, "CrossDevice", jsCrossDevice)); 284bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsShareOption, "CROSSDEVICE", jsCrossDevice)); 285bc03f14fSopenharmony_ci 286bc03f14fSopenharmony_ci return jsShareOption; 287bc03f14fSopenharmony_ci} 288bc03f14fSopenharmony_ci 289bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreatePattern(napi_env env, napi_callback_info info) 290bc03f14fSopenharmony_ci{ 291bc03f14fSopenharmony_ci napi_value jsPattern = nullptr; 292bc03f14fSopenharmony_ci napi_create_object(env, &jsPattern); 293bc03f14fSopenharmony_ci 294bc03f14fSopenharmony_ci napi_value jsURL = CreateNapiNumber(env, static_cast<uint32_t>(Pattern::URL)); 295bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsPattern, "URL", jsURL)); 296bc03f14fSopenharmony_ci 297bc03f14fSopenharmony_ci napi_value jsNumber = CreateNapiNumber(env, static_cast<uint32_t>(Pattern::Number)); 298bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsPattern, "NUMBER", jsNumber)); 299bc03f14fSopenharmony_ci 300bc03f14fSopenharmony_ci napi_value jsEmailAddress = CreateNapiNumber(env, static_cast<uint32_t>(Pattern::EmailAddress)); 301bc03f14fSopenharmony_ci NAPI_CALL(env, napi_set_named_property(env, jsPattern, "EMAIL_ADDRESS", jsEmailAddress)); 302bc03f14fSopenharmony_ci 303bc03f14fSopenharmony_ci return jsPattern; 304bc03f14fSopenharmony_ci} 305bc03f14fSopenharmony_ci 306bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreatePlainTextRecord(napi_env env, napi_callback_info info) 307bc03f14fSopenharmony_ci{ 308bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreatePlainTextRecord is called!"); 309bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 310bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 311bc03f14fSopenharmony_ci napi_value thisVar = nullptr; 312bc03f14fSopenharmony_ci 313bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); 314bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 315bc03f14fSopenharmony_ci 316bc03f14fSopenharmony_ci return CreatePlainTextRecord(env, argv[0]); 317bc03f14fSopenharmony_ci} 318bc03f14fSopenharmony_ci 319bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreatePixelMapRecord(napi_env env, napi_callback_info info) 320bc03f14fSopenharmony_ci{ 321bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreatePixelMapRecord is called!"); 322bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 323bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 324bc03f14fSopenharmony_ci napi_value thisVar = nullptr; 325bc03f14fSopenharmony_ci 326bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); 327bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 328bc03f14fSopenharmony_ci 329bc03f14fSopenharmony_ci napi_valuetype valueType = napi_undefined; 330bc03f14fSopenharmony_ci NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); 331bc03f14fSopenharmony_ci NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected."); 332bc03f14fSopenharmony_ci 333bc03f14fSopenharmony_ci return CreatePixelMapRecord(env, argv[0]); 334bc03f14fSopenharmony_ci} 335bc03f14fSopenharmony_ci 336bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreateUriRecord(napi_env env, napi_callback_info info) 337bc03f14fSopenharmony_ci{ 338bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreateUriRecord is called!"); 339bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 340bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 341bc03f14fSopenharmony_ci napi_value thisVar = nullptr; 342bc03f14fSopenharmony_ci 343bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); 344bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 345bc03f14fSopenharmony_ci 346bc03f14fSopenharmony_ci return CreateUriRecord(env, argv[0]); 347bc03f14fSopenharmony_ci} 348bc03f14fSopenharmony_ci 349bc03f14fSopenharmony_cinapi_value PasteboardNapi::JSCreateRecord(napi_env env, napi_callback_info info) 350bc03f14fSopenharmony_ci{ 351bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JSCreateRecord is called!"); 352bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 353bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 354bc03f14fSopenharmony_ci napi_value thisVar = nullptr; 355bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); 356bc03f14fSopenharmony_ci napi_valuetype type = napi_undefined; 357bc03f14fSopenharmony_ci NAPI_CALL(env, napi_typeof(env, argv[0], &type)); 358bc03f14fSopenharmony_ci if (!CheckExpression(env, argc >= ARGC_TYPE_SET2, JSErrorCode::INVALID_PARAMETERS, 359bc03f14fSopenharmony_ci "Parameter error. The number of arguments cannot be less than two.") || 360bc03f14fSopenharmony_ci !CheckExpression(env, type == napi_object || type == napi_string, JSErrorCode::INVALID_PARAMETERS, 361bc03f14fSopenharmony_ci "Parameter error. the first param should be object or string.")) { 362bc03f14fSopenharmony_ci return nullptr; 363bc03f14fSopenharmony_ci } 364bc03f14fSopenharmony_ci if (type == napi_string) { 365bc03f14fSopenharmony_ci std::string mimeType; 366bc03f14fSopenharmony_ci if (!CheckArgs(env, argv, argc, mimeType)) { 367bc03f14fSopenharmony_ci return nullptr; 368bc03f14fSopenharmony_ci } 369bc03f14fSopenharmony_ci auto it = createRecordMap_.find(mimeType); 370bc03f14fSopenharmony_ci if (it != createRecordMap_.end()) { 371bc03f14fSopenharmony_ci return (it->second)(env, argv[1]); 372bc03f14fSopenharmony_ci } 373bc03f14fSopenharmony_ci 374bc03f14fSopenharmony_ci void *data = nullptr; 375bc03f14fSopenharmony_ci size_t dataLen = 0; 376bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_arraybuffer_info(env, argv[1], &data, &dataLen)); 377bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuf(reinterpret_cast<uint8_t *>(data), reinterpret_cast<uint8_t *>(data) + dataLen); 378bc03f14fSopenharmony_ci napi_value instance = nullptr; 379bc03f14fSopenharmony_ci PasteDataRecordNapi::NewKvRecordInstance(env, mimeType, arrayBuf, instance); 380bc03f14fSopenharmony_ci return instance; 381bc03f14fSopenharmony_ci } else { 382bc03f14fSopenharmony_ci napi_ref provider = nullptr; 383bc03f14fSopenharmony_ci std::vector<std::string> mimeTypes; 384bc03f14fSopenharmony_ci if (!CheckArgsArray(env, argv[0], mimeTypes) || 385bc03f14fSopenharmony_ci !CheckArgsFunc(env, argv[1], provider)) { 386bc03f14fSopenharmony_ci return nullptr; 387bc03f14fSopenharmony_ci } 388bc03f14fSopenharmony_ci napi_value instance = nullptr; 389bc03f14fSopenharmony_ci std::shared_ptr<PastedataRecordEntryGetterInstance> entryGetter = 390bc03f14fSopenharmony_ci std::make_shared<PastedataRecordEntryGetterInstance>(env, provider); 391bc03f14fSopenharmony_ci entryGetter->GetStub()->SetEntryGetterWrapper(entryGetter); 392bc03f14fSopenharmony_ci PasteDataRecordNapi::NewEntryGetterRecordInstance(mimeTypes, entryGetter, instance); 393bc03f14fSopenharmony_ci return instance; 394bc03f14fSopenharmony_ci } 395bc03f14fSopenharmony_ci} 396bc03f14fSopenharmony_ci 397bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreateHtmlData(napi_env env, napi_callback_info info) 398bc03f14fSopenharmony_ci{ 399bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreateHtmlData is called!"); 400bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 401bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 402bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); 403bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 404bc03f14fSopenharmony_ci 405bc03f14fSopenharmony_ci return CreateHtmlData(env, argv[0]); 406bc03f14fSopenharmony_ci} 407bc03f14fSopenharmony_ci 408bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreateWantData(napi_env env, napi_callback_info info) 409bc03f14fSopenharmony_ci{ 410bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreateWantData is called!"); 411bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 412bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 413bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); 414bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 415bc03f14fSopenharmony_ci napi_valuetype valueType = napi_undefined; 416bc03f14fSopenharmony_ci NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); 417bc03f14fSopenharmony_ci NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected."); 418bc03f14fSopenharmony_ci 419bc03f14fSopenharmony_ci return CreateWantData(env, argv[0]); 420bc03f14fSopenharmony_ci} 421bc03f14fSopenharmony_ci 422bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreatePlainTextData(napi_env env, napi_callback_info info) 423bc03f14fSopenharmony_ci{ 424bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreatePlainTextData is called!"); 425bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 426bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 427bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); 428bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 429bc03f14fSopenharmony_ci 430bc03f14fSopenharmony_ci return CreatePlainTextData(env, argv[0]); 431bc03f14fSopenharmony_ci} 432bc03f14fSopenharmony_ci 433bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreatePixelMapData(napi_env env, napi_callback_info info) 434bc03f14fSopenharmony_ci{ 435bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreatePixelMapData is called!"); 436bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 437bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 438bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); 439bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 440bc03f14fSopenharmony_ci napi_valuetype valueType = napi_undefined; 441bc03f14fSopenharmony_ci NAPI_CALL(env, napi_typeof(env, argv[0], &valueType)); 442bc03f14fSopenharmony_ci NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected."); 443bc03f14fSopenharmony_ci 444bc03f14fSopenharmony_ci return CreatePixelMapData(env, argv[0]); 445bc03f14fSopenharmony_ci} 446bc03f14fSopenharmony_ci 447bc03f14fSopenharmony_cinapi_value PasteboardNapi::JScreateUriData(napi_env env, napi_callback_info info) 448bc03f14fSopenharmony_ci{ 449bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JScreateUriData is called!"); 450bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 451bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 452bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); 453bc03f14fSopenharmony_ci NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); 454bc03f14fSopenharmony_ci 455bc03f14fSopenharmony_ci return CreateUriData(env, argv[0]); 456bc03f14fSopenharmony_ci} 457bc03f14fSopenharmony_ci 458bc03f14fSopenharmony_cinapi_value PasteboardNapi::JSCreateKvData( 459bc03f14fSopenharmony_ci napi_env env, const std::string &mimeType, const std::vector<uint8_t> &arrayBuffer) 460bc03f14fSopenharmony_ci{ 461bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JSCreateKvData is called!"); 462bc03f14fSopenharmony_ci 463bc03f14fSopenharmony_ci napi_value instance = nullptr; 464bc03f14fSopenharmony_ci NAPI_CALL(env, PasteDataNapi::NewInstance(env, instance)); 465bc03f14fSopenharmony_ci PasteDataNapi *obj = nullptr; 466bc03f14fSopenharmony_ci napi_status status = napi_unwrap(env, instance, reinterpret_cast<void **>(&obj)); 467bc03f14fSopenharmony_ci if ((status != napi_ok) || (obj == nullptr)) { 468bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "unwrap failed!"); 469bc03f14fSopenharmony_ci return nullptr; 470bc03f14fSopenharmony_ci } 471bc03f14fSopenharmony_ci 472bc03f14fSopenharmony_ci obj->value_ = PasteboardClient::GetInstance()->CreateKvData(mimeType, arrayBuffer); 473bc03f14fSopenharmony_ci return instance; 474bc03f14fSopenharmony_ci} 475bc03f14fSopenharmony_ci 476bc03f14fSopenharmony_cinapi_value PasteboardNapi::JSCreateData(napi_env env, napi_callback_info info) 477bc03f14fSopenharmony_ci{ 478bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JSCreateData is called!"); 479bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 480bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 481bc03f14fSopenharmony_ci napi_value thisVar = nullptr; 482bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); 483bc03f14fSopenharmony_ci std::string mimeType; 484bc03f14fSopenharmony_ci std::shared_ptr<std::map<std::string, std::shared_ptr<EntryValue>>> typeValueMap = 485bc03f14fSopenharmony_ci std::make_shared<std::map<std::string, std::shared_ptr<MiscServices::EntryValue>>>(); 486bc03f14fSopenharmony_ci if (!CheckExpression(env, argc >= ARGC_TYPE_SET1, JSErrorCode::INVALID_PARAMETERS, 487bc03f14fSopenharmony_ci "Parameter error. The number of arguments cannot be less than one.")) { 488bc03f14fSopenharmony_ci return nullptr; 489bc03f14fSopenharmony_ci } 490bc03f14fSopenharmony_ci if (argc == ARGC_TYPE_SET1) { 491bc03f14fSopenharmony_ci if (!CheckArgsMap(env, argv[0], typeValueMap)) { 492bc03f14fSopenharmony_ci return nullptr; 493bc03f14fSopenharmony_ci } 494bc03f14fSopenharmony_ci return CreateMultiTypeData(env, typeValueMap); 495bc03f14fSopenharmony_ci } 496bc03f14fSopenharmony_ci bool isArray = false; 497bc03f14fSopenharmony_ci NAPI_CALL(env, napi_is_array(env, argv[0], &isArray)); 498bc03f14fSopenharmony_ci if (isArray) { 499bc03f14fSopenharmony_ci napi_ref provider = nullptr; 500bc03f14fSopenharmony_ci std::vector<std::string> mimeTypes; 501bc03f14fSopenharmony_ci if (!CheckArgsArray(env, argv[0], mimeTypes) || !CheckArgsFunc(env, argv[1], provider)) { 502bc03f14fSopenharmony_ci return nullptr; 503bc03f14fSopenharmony_ci } 504bc03f14fSopenharmony_ci std::shared_ptr<PastedataRecordEntryGetterInstance> entryGetter = 505bc03f14fSopenharmony_ci std::make_shared<PastedataRecordEntryGetterInstance>(env, provider); 506bc03f14fSopenharmony_ci entryGetter->GetStub()->SetEntryGetterWrapper(entryGetter); 507bc03f14fSopenharmony_ci return CreateMultiTypeDelayData(env, mimeTypes, entryGetter->GetStub()); 508bc03f14fSopenharmony_ci } 509bc03f14fSopenharmony_ci if (!CheckArgs(env, argv, argc, mimeType)) { 510bc03f14fSopenharmony_ci return nullptr; 511bc03f14fSopenharmony_ci } 512bc03f14fSopenharmony_ci auto it = createDataMap_.find(mimeType); 513bc03f14fSopenharmony_ci if (it != createDataMap_.end()) { 514bc03f14fSopenharmony_ci return (it->second)(env, argv[1]); 515bc03f14fSopenharmony_ci } 516bc03f14fSopenharmony_ci 517bc03f14fSopenharmony_ci void *data = nullptr; 518bc03f14fSopenharmony_ci size_t dataLen = 0; 519bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_arraybuffer_info(env, argv[1], &data, &dataLen)); 520bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuf(reinterpret_cast<uint8_t *>(data), reinterpret_cast<uint8_t *>(data) + dataLen); 521bc03f14fSopenharmony_ci return JSCreateKvData(env, mimeType, arrayBuf); 522bc03f14fSopenharmony_ci} 523bc03f14fSopenharmony_ci 524bc03f14fSopenharmony_cinapi_value PasteboardNapi::JSgetSystemPasteboard(napi_env env, napi_callback_info info) 525bc03f14fSopenharmony_ci{ 526bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JSgetSystemPasteboard is called!"); 527bc03f14fSopenharmony_ci size_t argc = MAX_ARGS; 528bc03f14fSopenharmony_ci napi_value argv[MAX_ARGS] = { 0 }; 529bc03f14fSopenharmony_ci napi_value thisVar = nullptr; 530bc03f14fSopenharmony_ci 531bc03f14fSopenharmony_ci NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); 532bc03f14fSopenharmony_ci napi_value instance = nullptr; 533bc03f14fSopenharmony_ci napi_status status = SystemPasteboardNapi::NewInstance(env, instance); // 0 arguments 534bc03f14fSopenharmony_ci if (status != napi_ok) { 535bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "JSgetSystemPasteboard create instance failed"); 536bc03f14fSopenharmony_ci return NapiGetNull(env); 537bc03f14fSopenharmony_ci } 538bc03f14fSopenharmony_ci 539bc03f14fSopenharmony_ci return instance; 540bc03f14fSopenharmony_ci} 541bc03f14fSopenharmony_ci 542bc03f14fSopenharmony_cinapi_value PasteboardNapi::PasteBoardInit(napi_env env, napi_value exports) 543bc03f14fSopenharmony_ci{ 544bc03f14fSopenharmony_ci napi_property_descriptor desc[] = { DECLARE_NAPI_FUNCTION("createHtmlData", JScreateHtmlData), 545bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createWantData", JScreateWantData), 546bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createPlainTextData", JScreatePlainTextData), 547bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createPixelMapData", JScreatePixelMapData), 548bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createUriData", JScreateUriData), 549bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createData", JSCreateData), 550bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createDelayData", JSCreateData), 551bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createHtmlTextRecord", JScreateHtmlTextRecord), 552bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createWantRecord", JScreateWantRecord), 553bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createPlainTextRecord", JScreatePlainTextRecord), 554bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createPixelMapRecord", JScreatePixelMapRecord), 555bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createUriRecord", JScreateUriRecord), 556bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createRecord", JSCreateRecord), 557bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("createDelayRecord", JSCreateRecord), 558bc03f14fSopenharmony_ci DECLARE_NAPI_FUNCTION("getSystemPasteboard", JSgetSystemPasteboard), 559bc03f14fSopenharmony_ci DECLARE_NAPI_GETTER("ShareOption", JScreateShareOption), DECLARE_NAPI_GETTER("Pattern", JScreatePattern), 560bc03f14fSopenharmony_ci DECLARE_NAPI_PROPERTY("MAX_RECORD_NUM", CreateNapiNumber(env, PasteData::MAX_RECORD_NUM)), 561bc03f14fSopenharmony_ci DECLARE_NAPI_PROPERTY("MIMETYPE_PIXELMAP", CreateNapiString(env, MIMETYPE_PIXELMAP)), 562bc03f14fSopenharmony_ci DECLARE_NAPI_PROPERTY("MIMETYPE_TEXT_HTML", CreateNapiString(env, MIMETYPE_TEXT_HTML)), 563bc03f14fSopenharmony_ci DECLARE_NAPI_PROPERTY("MIMETYPE_TEXT_WANT", CreateNapiString(env, MIMETYPE_TEXT_WANT)), 564bc03f14fSopenharmony_ci DECLARE_NAPI_PROPERTY("MIMETYPE_TEXT_PLAIN", CreateNapiString(env, MIMETYPE_TEXT_PLAIN)), 565bc03f14fSopenharmony_ci DECLARE_NAPI_PROPERTY("MIMETYPE_TEXT_URI", CreateNapiString(env, MIMETYPE_TEXT_URI)) }; 566bc03f14fSopenharmony_ci 567bc03f14fSopenharmony_ci NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); 568bc03f14fSopenharmony_ci 569bc03f14fSopenharmony_ci return exports; 570bc03f14fSopenharmony_ci} 571bc03f14fSopenharmony_ci 572bc03f14fSopenharmony_cistd::unordered_map<std::string, PasteboardNapi::FUNC> PasteboardNapi::createRecordMap_ = { 573bc03f14fSopenharmony_ci { "text/html", &PasteboardNapi::CreateHtmlRecord }, { "text/plain", &PasteboardNapi::CreatePlainTextRecord }, 574bc03f14fSopenharmony_ci { "text/uri", &PasteboardNapi::CreateUriRecord }, { "pixelMap", &PasteboardNapi::CreatePixelMapRecord }, 575bc03f14fSopenharmony_ci { "text/want", &PasteboardNapi::CreateWantRecord } 576bc03f14fSopenharmony_ci}; 577bc03f14fSopenharmony_ci 578bc03f14fSopenharmony_cistd::unordered_map<std::string, PasteboardNapi::FUNC> PasteboardNapi::createDataMap_ = { 579bc03f14fSopenharmony_ci { "text/html", &PasteboardNapi::CreateHtmlData }, { "text/plain", &PasteboardNapi::CreatePlainTextData }, 580bc03f14fSopenharmony_ci { "text/uri", &PasteboardNapi::CreateUriData }, { "pixelMap", &PasteboardNapi::CreatePixelMapData }, 581bc03f14fSopenharmony_ci { "text/want", &PasteboardNapi::CreateWantData } 582bc03f14fSopenharmony_ci}; 583bc03f14fSopenharmony_ci} // namespace MiscServicesNapi 584bc03f14fSopenharmony_ci} // namespace OHOS