1 /*
2  * Copyright (C) 2023-2023 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 WEB_CLIPBORD_CONTROLLER_H
17 #define WEB_CLIPBORD_CONTROLLER_H
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 
25 #include "paste_data.h"
26 #include "paste_data_record.h"
27 #include "refbase.h"
28 
29 namespace OHOS {
30 namespace MiscServices {
31 
32 class API_EXPORT PasteboardWebController : public RefBase {
33 public:
PasteboardWebController()34     PasteboardWebController() {};
~PasteboardWebController()35     ~PasteboardWebController() {};
36 
37     static PasteboardWebController& GetInstance();
38 
39     std::shared_ptr<std::string> RebuildHtml(std::shared_ptr<PasteData> pasteData) noexcept;
40     std::vector<std::shared_ptr<PasteDataRecord>> SplitHtml2Records(const std::shared_ptr<std::string> &html,
41         uint32_t recordId) noexcept;
42     void MergeExtraUris2Html(PasteData &data);
43 
44 private:
45     std::vector<std::pair<std::string, uint32_t>> SplitHtmlWithImgLabel(
46         const std::shared_ptr<std::string> html) noexcept;
47     std::map<std::string, std::vector<uint8_t>> SplitHtmlWithImgSrcLabel(
48         const std::vector<std::pair<std::string, uint32_t>> &matchVec) noexcept;
49     std::vector<std::shared_ptr<PasteDataRecord>> BuildPasteDataRecords(const std::map<std::string,
50         std::vector<uint8_t>> &imgSrcMap, uint32_t recordId) noexcept;
51 
52     void RemoveAllRecord(std::shared_ptr<PasteData> pasteData) noexcept;
53     void RemoveRecordById(PasteData &pasteData, uint32_t recordId) noexcept;
54     bool IsLocalURI(std::string &uri) noexcept;
55     std::map<std::uint32_t, std::vector<std::shared_ptr<PasteDataRecord>>> GroupRecordWithFrom(PasteData &data);
56 
57     void RemoveExtraUris(PasteData &data);
58     void ReplaceHtmlRecordContentByExtraUris(std::vector<std::shared_ptr<PasteDataRecord>> &records);
59 };
60 } // namespace MiscServices
61 } // namespace OHOS
62 
63 #endif // WEB_CLIPBORD_CONTROLLER_H
64