• 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 PASTEBOARD_WEB_CONTROLLER_H
17 #define PASTEBOARD_WEB_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::pair<std::string, int32_t> &bundleIndex);
32     void CheckAppUriPermission(PasteData &pasteData);
33     void RetainUri(PasteData &pasteData);
34     void RebuildWebviewPasteData(PasteData &pasteData, const std::string &targetBundle = "",
35         int32_t appIndex = 0);
36 
37 private:
38     void RefreshUri(std::shared_ptr<PasteDataRecord> &record, const std::string &targetBundle, int32_t appInedx);
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     std::vector<std::pair<std::string, uint32_t>> SplitHtmlWithImgLabel(
44         const std::shared_ptr<std::string> html) noexcept;
45     std::map<std::string, std::vector<uint8_t>> SplitHtmlWithImgSrcLabel(
46         const std::vector<std::pair<std::string, uint32_t>> &matchVec) noexcept;
47     std::vector<std::shared_ptr<PasteDataRecord>> BuildPasteDataRecords(const std::map<std::string,
48         std::vector<uint8_t>> &imgSrcMap, uint32_t recordId) noexcept;
49 
50     void RemoveAllRecord(std::shared_ptr<PasteData> pasteData) noexcept;
51     void RemoveRecordById(PasteData &pasteData, uint32_t recordId) noexcept;
52     bool IsLocalURI(std::string &uri) noexcept;
53     std::map<std::uint32_t, std::vector<std::shared_ptr<PasteDataRecord>>> GroupRecordWithFrom(PasteData &data);
54 
55     void RemoveExtraUris(PasteData &data);
56     void ReplaceHtmlRecordContentByExtraUris(std::vector<std::shared_ptr<PasteDataRecord>> &records);
57     void UpdateHtmlRecord(std::shared_ptr<PasteDataRecord> &htmlRecord, std::shared_ptr<std::string> &htmlData);
58 };
59 } // namespace MiscServices
60 } // namespace OHOS
61 
62 #endif // PASTEBOARD_WEB_CONTROLLER_H
63