• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 FOUNDATION_ACE_INTERFACE_INNERKITS_INSPECTOR_H
16 #define FOUNDATION_ACE_INTERFACE_INNERKITS_INSPECTOR_H
17 
18 #include "napi/native_api.h"
19 #include "napi/native_common.h"
20 #include "napi/native_node_api.h"
21 
22 #include "bridge/common/utils/engine_helper.h"
23 #include "bridge/js_frontend/engine/common/js_engine.h"
24 
25 namespace OHOS::Ace::Napi { // namespace
26 using namespace OHOS::Ace::Framework;
27 
28 enum class CalloutType {
29     LAYOUTCALLOUT = 0,
30     DRAWCALLOUT,
31     DRAWCHILDRENCALLOUT,
32     UNKNOW,
33 };
34 
35 class ComponentObserver {
36 public:
ComponentObserver(const std::string & componentId)37     explicit ComponentObserver(const std::string& componentId) : componentId_(componentId) {}
~ComponentObserver()38     ~ComponentObserver() {}
39 
40     void Initialize(napi_env env, napi_value thisVar);
41     void callUserFunction(napi_env env, std::list<napi_ref>& cbList);
42     std::list<napi_ref>::iterator FindCbList(napi_env env, napi_value cb, CalloutType calloutType);
43     void NapiSerializer(napi_env& env, napi_value& result);
44     void AddCallbackToList(
45         napi_value cb, std::list<napi_ref>& cbList, CalloutType calloutType, napi_env env, napi_handle_scope scope);
46     void DeleteCallbackFromList(
47         size_t argc, std::list<napi_ref>& cbList, CalloutType calloutType, napi_value cb, napi_env env);
48     void Destroy(napi_env env);
49 
50     RefPtr<InspectorEvent> layoutEvent_;
51     RefPtr<InspectorEvent> drawEvent_;
52     RefPtr<InspectorEvent> drawChildrenEvent_;
53     std::string componentId_;
54     std::list<napi_ref> cbLayoutList_;
55     std::list<napi_ref> cbDrawList_;
56     std::list<napi_ref> cbDrawChildrenList_;
SetEngine(const RefPtr<Framework::JsEngine> & engine)57     void SetEngine(const RefPtr<Framework::JsEngine>& engine)
58     {
59         weakEngine_ = engine;
60     }
61 
62 private:
63     void FunctionOn(napi_env& env, napi_value result, const char* funName);
64     void FunctionOff(napi_env& env, napi_value result, const char* funName);
65     WeakPtr<Framework::JsEngine> weakEngine_;
66 };
67 } // namespace OHOS::Ace::Napi
68 #endif
69