• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_ABILITY_RUNTIME_UISERVICE_UIEXT_CONNECTION_H
16 #define OHOS_ABILITY_RUNTIME_UISERVICE_UIEXT_CONNECTION_H
17 
18 #include "js_ui_extension_context.h"
19 
20 #include "ui_service_host_stub.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
24 namespace UIServiceConnection {
25 void AddUIServiceExtensionConnection(AAFwk::Want& want, sptr<JSUIServiceUIExtConnection>& connection);
26 void RemoveUIServiceExtensionConnection(const int64_t& connectId);
27 void FindUIServiceExtensionConnection(const int64_t& connectId, AAFwk::Want& want,
28     sptr<JSUIServiceUIExtConnection>& connection);
29 void FindUIServiceExtensionConnection(napi_env env, AAFwk::Want& want, napi_value callback,
30     sptr<JSUIServiceUIExtConnection>& connection);
31 }
32 
33 class UIExtensionServiceHostStubImpl;
34 class JSUIServiceUIExtConnection : public JSUIExtensionConnection {
35 public:
36     JSUIServiceUIExtConnection(napi_env env);
37     ~JSUIServiceUIExtConnection();
38     virtual void HandleOnAbilityConnectDone(
39         const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
40     virtual void HandleOnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
GetServiceHostStub()41     sptr<UIExtensionServiceHostStubImpl> GetServiceHostStub() { return serviceHostStub_; }
42     void SetProxyObject(napi_value proxy);
43     napi_value GetProxyObject();
44     void SetNapiAsyncTask(std::shared_ptr<NapiAsyncTask>& task);
45     void AddDuplicatedPendingTask(std::unique_ptr<NapiAsyncTask>& task);
46     void ResolveDuplicatedPendingTask(napi_env env, napi_value proxy);
47     void RejectDuplicatedPendingTask(napi_env env, napi_value error);
48     int32_t OnSendData(OHOS::AAFwk::WantParams &data);
49     void HandleOnSendData(const OHOS::AAFwk::WantParams &data);
50     void CallJsOnDisconnect();
51     static bool IsJsCallbackObjectEquals(napi_env env, std::unique_ptr<NativeReference>& callback, napi_value value);
52 
53 private:
54     sptr<UIExtensionServiceHostStubImpl> serviceHostStub_;
55     std::unique_ptr<NativeReference> serviceProxyObject_;
56     std::shared_ptr<NapiAsyncTask> napiAsyncTask_;
57     std::vector<std::unique_ptr<NapiAsyncTask>> duplicatedPendingTaskList_;
58 };
59 
60 }
61 }
62 #endif
63