• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 JS_WINDOW_EXTENSION_H
17 #define JS_WINDOW_EXTENSION_H
18 
19 #include <js_runtime.h>
20 #include <js_runtime_utils.h>
21 
22 #include "js_window_extension_context.h"
23 #include "window.h"
24 #include "window_extension.h"
25 #include "window_extension_stub.h"
26 #include "window_extension_stub_impl.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 napi_valuetype GetType(napi_env env, napi_value value);
31 napi_value CallJsMethod(const char* name, napi_value const * argv = nullptr, size_t argc = 0,
32     napi_env env = nullptr, napi_value value = nullptr);
33 class JsWindowExtension : public WindowExtension {
34 public:
35     explicit JsWindowExtension(AbilityRuntime::JsRuntime& jsRuntime);
36     virtual ~JsWindowExtension() override;
37 
38     /**
39      * @brief Create JsAccessibilityExtension.
40      *
41      * @param runtime The runtime.
42      * @return The JsAccessibilityExtension instance.
43      */
44     static JsWindowExtension* Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime);
45 
46     /**
47      * @brief Init the extension.
48      *
49      * @param record the extension record.
50      * @param application the application info.
51      * @param handler the extension handler.
52      * @param token the remote token.
53      */
54     void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
55         const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
56         std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
57         const sptr<IRemoteObject>& token) override;
58 
59     /**
60      * @brief Called when this Accessibility extension is connected for the first time.
61      *
62      * You can override this function to implement your own processing logic.
63      *
64      * @param want Indicates the {@link Want} structure containing connection information
65      * about the Accessibility extension.
66      * @return Returns a pointer to the <b>sid</b> of the connected Accessibility extension.
67      */
68     sptr<IRemoteObject> OnConnect(const AAFwk::Want& want) override;
69 
70     /**
71      * @brief Called when all abilities connected to this Service extension are disconnected.
72      *
73      * You can override this function to implement your own processing logic.
74      *
75      */
76     void OnDisconnect(const AAFwk::Want& want) override;
77 
78     /**
79      * @brief Called when this extension is started. You must override this function if you want to perform some
80      *        initialization operations during extension startup.
81      *
82      * This function can be called only once in the entire lifecycle of an extension.
83      * @param Want Indicates the {@link Want} structure containing startup information about the extension.
84      * @param sessionInfo Indicates the {@link SessionInfo} structure containing session info about the extension.
85      */
86     virtual void OnStart(const AAFwk::Want& want, sptr<AAFwk::SessionInfo> sessionInfo) override;
87 private:
88     void GetSrcPath(std::string& srcPath) const;
89     void OnWindowCreated() const;
90     void BindContext(napi_env env, napi_value obj);
91 
92     AbilityRuntime::JsRuntime& jsRuntime_;
93     std::unique_ptr<NativeReference> jsObj_;
94     sptr<WindowExtensionStubImpl> stub_;
95     static int extensionCnt_;
96     sptr<AAFwk::SessionInfo> sessionInfo_;
97 };
98 } // namespace Rosen
99 } // namespace OHOS
100 #endif // JS_WINDOW_EXTENSION_H
101