• 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 class JsWindowExtension : public WindowExtension {
31 public:
32     JsWindowExtension(AbilityRuntime::JsRuntime& jsRuntime);
33     virtual ~JsWindowExtension() override;
34 
35     /**
36      * @brief Create JsAccessibilityExtension.
37      *
38      * @param runtime The runtime.
39      * @return The JsAccessibilityExtension instance.
40      */
41     static JsWindowExtension* Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime);
42 
43     /**
44      * @brief Init the extension.
45      *
46      * @param record the extension record.
47      * @param application the application info.
48      * @param handler the extension handler.
49      * @param token the remote token.
50      */
51     void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
52         const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
53         std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
54         const sptr<IRemoteObject>& token) override;
55 
56     /**
57      * @brief Called when this Accessibility extension is connected for the first time.
58      *
59      * You can override this function to implement your own processing logic.
60      *
61      * @param want Indicates the {@link Want} structure containing connection information
62      * about the Accessibility extension.
63      * @return Returns a pointer to the <b>sid</b> of the connected Accessibility extension.
64      */
65     sptr<IRemoteObject> OnConnect(const AAFwk::Want& want) override;
66 
67     /**
68      * @brief Called when all abilities connected to this Service extension are disconnected.
69      *
70      * You can override this function to implement your own processing logic.
71      *
72      */
73     void OnDisconnect(const AAFwk::Want& want) override;
74 
75     /**
76      * @brief Called when this extension is started. You must override this function if you want to perform some
77      *        initialization operations during extension startup.
78      *
79      * This function can be called only once in the entire lifecycle of an extension.
80      * @param Want Indicates the {@link Want} structure containing startup information about the extension.
81      */
82     virtual void OnStart(const AAFwk::Want& want) override;
83 private:
84     void GetSrcPath(std::string& srcPath) const;
85     NativeValue* CallJsMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0) const;
86     void OnWindowCreated() const;
87     void BindContext(NativeEngine& engine, NativeObject* obj);
88 
89     AbilityRuntime::JsRuntime& jsRuntime_;
90     std::unique_ptr<NativeReference> jsObj_;
91     std::shared_ptr<NativeReference> shellContextRef_;
92     sptr<WindowExtensionStubImpl> stub_;
93 };
94 } // namespace Rosen
95 } // namespace OHOS
96 #endif // JS_WINDOW_EXTENSION_H