• 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 #include "paste_data_impl.h"
16 #include "pasteboard_hilog.h"
17 
18 using namespace OHOS::MiscServices;
19 
20 namespace OHOS {
21 namespace MiscServicesCj {
22 
GetClassType()23 OHOS::FFI::RuntimeType *PasteDataImpl::GetClassType()
24 {
25     static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("PasteDataImpl");
26     return &runtimeType;
27 }
28 
CreateCjPasteDataObject(std::string mimeType,CJValueType value)29 int64_t CreateCjPasteDataObject(std::string mimeType, CJValueType value)
30 {
31     auto pasteDataImpl = FFI::FFIData::Create<PasteDataImpl>(mimeType, value);
32     PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(pasteDataImpl != nullptr, ERR_INVALID_VALUE, PASTEBOARD_MODULE_SERVICE,
33         "create cj paste data failed");
34     return pasteDataImpl->GetID();
35 }
36 
PasteDataImpl()37 PasteDataImpl::PasteDataImpl()
38 {
39     value_ = std::make_shared<PasteData>();
40 }
41 
PasteDataImpl(std::shared_ptr<MiscServices::PasteData> pasteData)42 PasteDataImpl::PasteDataImpl(std::shared_ptr<MiscServices::PasteData> pasteData)
43 {
44     value_ = pasteData;
45 }
46 
PasteDataImpl(std::string mimeType,const CJValueType & value)47 PasteDataImpl::PasteDataImpl(std::string mimeType, const CJValueType &value)
48 {
49     if (mimeType == "text/html") {
50         CreateHtmlData(mimeType, value);
51     } else if (mimeType == "text/plain") {
52         CreatePlainTextData(mimeType, value);
53     } else if (mimeType == "text/uri") {
54         CreateUriData(mimeType, value);
55     } else if (mimeType == "pixelMap") {
56         CreatePixelMapData(mimeType, value);
57     } else if (mimeType == "text/want") {
58         CreateWantData(mimeType, value);
59     } else {
60         std::vector<uint8_t> arrayBuf(reinterpret_cast<uint8_t *>(value.arrayBufferData),
61             reinterpret_cast<uint8_t *>(value.arrayBufferData) + value.arrayBufferSize);
62         value_ = PasteboardClient::GetInstance()->CreateKvData(mimeType, arrayBuf);
63     }
64 }
65 
GetRealPasteData()66 std::shared_ptr<MiscServices::PasteData> PasteDataImpl::GetRealPasteData()
67 {
68     return value_;
69 }
70 
CreateHtmlData(std::string mimeType,const CJValueType & value)71 void PasteDataImpl::CreateHtmlData(std::string mimeType, const CJValueType &value)
72 {
73     value_ = PasteboardClient::GetInstance()->CreateHtmlData(value.stringValue);
74 }
75 
CreatePlainTextData(std::string mimeType,const CJValueType & value)76 void PasteDataImpl::CreatePlainTextData(std::string mimeType, const CJValueType &value)
77 {
78     value_ = PasteboardClient::GetInstance()->CreatePlainTextData(value.stringValue);
79 }
80 
CreateUriData(std::string mimeType,const CJValueType & value)81 void PasteDataImpl::CreateUriData(std::string mimeType, const CJValueType &value)
82 {
83     value_ = PasteboardClient::GetInstance()->CreateUriData(OHOS::Uri(value.stringValue));
84 }
85 
CreatePixelMapData(std::string mimeType,const CJValueType & value)86 void PasteDataImpl::CreatePixelMapData(std::string mimeType, const CJValueType &value)
87 {
88     value_ = PasteboardClient::GetInstance()->CreatePixelMapData(value.pixelMap);
89 }
90 
CreateWantData(std::string mimeType,CJValueType value)91 void PasteDataImpl::CreateWantData(std::string mimeType, CJValueType value) {}
92 
93 } // namespace MiscServicesCj
94 }