• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_NWEB_NATIVE_COMMON_WEB_MESSAGE_PORT_H
17 #define OHOS_NWEB_NATIVE_COMMON_WEB_MESSAGE_PORT_H
18 #include "nweb.h"
19 #include "web_errors.h"
20 #include "nweb_helper.h"
21 #include "nweb_log.h"
22 #include "transfer_referenced_count.h"
23 
24 namespace OHOS {
25 namespace NWeb {
26 
27 class WebMessagePort : public TransferReferencedCount {
28 public:
29     WebMessagePort(int32_t nwebId, std::string& port, bool isExtentionType);
30 
31     ~WebMessagePort() = default;
32 
33     ErrCode ClosePort();
34 
35     ErrCode PostPortMessage(std::shared_ptr<NWebMessage> data, std::shared_ptr<NWebRomValue> value);
36 
37     ErrCode SetPortMessageCallback(std::shared_ptr<NWebMessageValueCallback> callback);
38 
39     std::string GetPortHandle() const;
40 
IsExtentionType()41     bool IsExtentionType()
42     {
43         return isExtentionType_;
44     }
45 
46 private:
47     int32_t nwebId_ = -1;
48     std::string portHandle_;
49     bool isExtentionType_;
50 };
51 
52 } // namespace NWeb
53 } // namespace OHOS
54 #endif // OHOS_NWEB_NATIVE_COMMON_WEB_MESSAGE_PORT_H