• 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 OHOS_ABILITY_RUNTIME_JS_EXTENSION_COMMON_H
17 #define OHOS_ABILITY_RUNTIME_JS_EXTENSION_COMMON_H
18 
19 #include "configuration.h"
20 #include "service_extension.h"
21 
22 class NativeReference;
23 class NativeValue;
24 class NativeObject;
25 
26 namespace OHOS {
27 namespace AbilityRuntime {
28 class ServiceExtension;
29 class JsRuntime;
30 /**
31  * @brief Basic js extension common components.
32  */
33 class JsExtensionCommon : public ExtensionCommon,
34                             public std::enable_shared_from_this<JsExtensionCommon> {
35 public:
36     JsExtensionCommon(JsRuntime &jsRuntime, NativeReference &jsObj,
37         const std::shared_ptr<NativeReference> &shellContextRef);
38 
39     virtual ~JsExtensionCommon() override;
40 
41     /**
42      * @brief Create JsServiceExtension.
43      *
44      * @param jsRuntime The runtime.
45      * @param jsObj The js object instance.
46      * @return The JsServiceExtension instance.
47      */
48     static std::shared_ptr<JsExtensionCommon> Create(JsRuntime &jsRuntime, NativeReference &jsObj,
49         const std::shared_ptr<NativeReference> &shellContextRef);
50 
51     /**
52      * @brief Called when the system configuration is updated.
53      *
54      * @param configuration Indicates the updated configuration information.
55      */
56     void OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration> &fullConfig) override;
57 
58     /**
59      * @brief Notify current memory level.
60      *
61      * @param level Current memory level.
62      */
63     virtual void OnMemoryLevel(int level) override;
64 
65 private:
66     NativeValue* CallObjectMethod(const char* name, NativeValue* const * argv, size_t argc);
67 
68 private:
69     JsRuntime& jsRuntime_;
70     NativeReference& jsObj_;
71     std::shared_ptr<NativeReference> shellContextRef_ = nullptr;
72 };
73 }  // namespace AbilityRuntime
74 }  // namespace OHOS
75 #endif  // OHOS_ABILITY_RUNTIME_JS_EXTENSION_COMMON_H
76