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 
16 #ifndef AAFWK_BROWSER_HOST_IMPL_H
17 #define AAFWK_BROWSER_HOST_IMPL_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <map>
22 
23 #include "aafwk_browser_host_adapter.h"
24 #include <functional>
25 #include "iremote_object.h"
26 #include "iremote_stub.h"
27 #include "iconsumer_surface.h"
28 #include "nocopyable.h"
29 #include "ibrowser.h"
30 #include "res_sched_client_adapter.h"
31 
32 namespace OHOS::NWeb {
33 class BrowserHost : public IRemoteStub<IBrowser> {
34 public:
35     BrowserHost();
36 
37     virtual ~BrowserHost();
38 
39     virtual int OnRemoteRequest(
40         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
41 private:
42     int32_t HandleQueryRenderSurface(MessageParcel &data, MessageParcel &reply);
43 
44     int32_t HandleReportThread(MessageParcel &data, MessageParcel &reply);
45 
46     int32_t HandlePassSurface(MessageParcel &data, MessageParcel &reply);
47 
48     int32_t HandleDestroyRenderSurface(MessageParcel &data, MessageParcel &reply);
49 
50     using BrowserHostFunc = std::function<int32_t(BrowserHost*, MessageParcel &data, MessageParcel &reply)>;
51 
52     std::map<uint32_t, BrowserHostFunc> memberFuncMap_;
53 
54     DISALLOW_COPY_AND_MOVE(BrowserHost);
55 };
56 
57 class AafwkBrowserHostImpl : public BrowserHost {
58 public:
59     explicit AafwkBrowserHostImpl(std::shared_ptr<AafwkBrowserHostAdapter> adapter);
60 
61     ~AafwkBrowserHostImpl() override = default;
62 
63     sptr<IRemoteObject> QueryRenderSurface(int32_t surface_id) override;
64 
65     void ReportThread(int32_t status, int32_t process_id, int32_t thread_id, int32_t role) override;
66 
67     void PassSurface(sptr<Surface> surface, int64_t surface_id) override;
68 
69     void DestroyRenderSurface(int32_t surface_id) override;
70 private:
71     std::map<int64_t, sptr<Surface>> surface_map_;
72     std::shared_ptr<AafwkBrowserHostAdapter> browserHostAdapter_;
73 };
74 } //namespace content
75 
76 #endif // AAFWK_BROWSER_HOST_IMPL_H