• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "paste_data.h"
20 
21 namespace OHOS {
22 namespace MiscServices {
23 
24 class API_EXPORT PasteboardWebController : public RefBase {
25 public:
26     PasteboardWebController() = default;
27     virtual ~PasteboardWebController() = default;
28 
29     static PasteboardWebController &GetInstance();
30     bool SplitWebviewPasteData(PasteData &pasteData);
31     void SetWebviewPasteData(PasteData &pasteData, const std::string &bundleName);
32     void CheckAppUriPermission(PasteData &pasteData);
33     void RetainUri(PasteData &pasteData);
34     void RebuildWebviewPasteData(PasteData &pasteData, const std::string &targetBundle = "");
35 
36 private:
37     void RefreshUri(std::shared_ptr<PasteDataRecord> &record, const std::string &targetBundle);
38     std::shared_ptr<std::string> RebuildHtml(std::shared_ptr<PasteData> pasteData) noexcept;
39     std::vector<std::shared_ptr<PasteDataRecord>> SplitHtml2Records(const std::shared_ptr<std::string> &html,
40         uint32_t recordId) noexcept;
41     void MergeExtraUris2Html(PasteData &data);
42     std::vector<std::pair<std::string, uint32_t>> SplitHtmlWithImgLabel(
43         const std::shared_ptr<std::string> html) noexcept;
44     std::map<std::string, std::vector<uint8_t>> SplitHtmlWithImgSrcLabel(
45         const std::vector<std::pair<std::string, uint32_t>> &matchVec) noexcept;
46     std::vector<std::shared_ptr<PasteDataRecord>> BuildPasteDataRecords(const std::map<std::string,
47         std::vector<uint8_t>> &imgSrcMap, uint32_t recordId) noexcept;
48 
49     void RemoveAllRecord(std::shared_ptr<PasteData> pasteData) noexcept;
50     void RemoveRecordById(PasteData &pasteData, uint32_t recordId) noexcept;
51     bool IsLocalURI(std::string &uri) noexcept;
52     std::map<std::uint32_t, std::vector<std::shared_ptr<PasteDataRecord>>> GroupRecordWithFrom(PasteData &data);
53 
54     void RemoveExtraUris(PasteData &data);
55     void ReplaceHtmlRecordContentByExtraUris(std::vector<std::shared_ptr<PasteDataRecord>> &records);
56     void UpdateHtmlRecord(std::shared_ptr<PasteDataRecord> &htmlRecord, std::shared_ptr<std::string> &htmlData);
57 };
58 } // namespace MiscServices
59 } // namespace OHOS
60 
61 #endif // WEB_CLIPBORD_CONTROLLER_H
62