• 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 #include "interfaces/inner_api/ui_session/ui_content_stub.h"
17 
18 #include "interfaces/inner_api/ui_session/ui_session_manager.h"
19 #include "ui_content_errors.h"
20 
21 #include "adapter/ohos/entrance/ui_session/include/ui_service_hilog.h"
22 
23 namespace OHOS::Ace {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int32_t UiContentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
25 {
26     if (data.ReadInterfaceToken() != GetDescriptor()) {
27         LOGW("ui_session InterfaceToken check failed");
28         return -1;
29     }
30     switch (code) {
31         case UI_CONTENT_SERVICE_GET_TREE: {
32             GetInspectorTreeInner(data, reply, option);
33             break;
34         }
35         case UI_CONTENT_CONNECT: {
36             ConnectInner(data, reply, option);
37             break;
38         }
39         case REGISTER_CLICK_EVENT: {
40             RegisterClickEventCallbackInner(data, reply, option);
41             break;
42         }
43         case REGISTER_SEARCH_EVENT: {
44             RegisterSearchEventCallbackInner(data, reply, option);
45             break;
46         }
47         case REGISTER_ROUTER_CHANGE_EVENT: {
48             RegisterRouterChangeEventCallbackInner(data, reply, option);
49             break;
50         }
51         case REGISTER_COMPONENT_EVENT: {
52             RegisterComponentChangeEventCallbackInner(data, reply, option);
53             break;
54         }
55         case UNREGISTER_CLICK_EVENT: {
56             UnregisterClickEventCallbackInner(data, reply, option);
57             break;
58         }
59         case UNREGISTER_SEARCH_EVENT: {
60             UnregisterSearchEventCallbackInner(data, reply, option);
61             break;
62         }
63         case UNREGISTER_ROUTER_CHANGE_EVENT: {
64             UnregisterRouterChangeEventCallbackInner(data, reply, option);
65             break;
66         }
67         case UNREGISTER_COMPONENT_EVENT: {
68             UnregisterComponentChangeEventCallbackInner(data, reply, option);
69             break;
70         }
71         case UNREGISTER_WEB_UNFOCUS_EVENT: {
72             UnregisterWebUnfocusEventCallbackInner(data, reply, option);
73             break;
74         }
75         case RESET_ALL_TEXT: {
76             ResetTranslateTextAllInner(data, reply, option);
77             break;
78         }
79         case RESET_TEXT_BY_ID: {
80             ResetTranslateTextInner(data, reply, option);
81             break;
82         }
83         case GET_WEB_VIEW_LANGUAGE: {
84             GetWebViewCurrentLanguageInner(data, reply, option);
85             break;
86         }
87         case GET_WEB_TRANSLATE_TEXT: {
88             GetWebViewTranslateTextInner(data, reply, option);
89             break;
90         }
91         case CONTINUE_GET_WEB_TEXT: {
92             StartWebViewTranslateInner(data, reply, option);
93             break;
94         }
95         case SEND_TRANSLATE_RESULT: {
96             SendTranslateResultInner(data, reply, option);
97             break;
98         }
99         case END_WEB_TRANSLATE: {
100             EndWebViewTranslateInner(data, reply, option);
101             break;
102         }
103         case SEND_TRANSLATE_RESULT_STR: {
104             SendTranslateResultStrInner(data, reply, option);
105             break;
106         }
107         case GET_CURRENT_PAGE_NAME: {
108             GetCurrentPageNameInner(data, reply, option);
109             break;
110         }
111         case GET_CURRENT_SHOWING_IMAGE: {
112             GetCurrentImagesShowingInner(data, reply, option);
113             break;
114         }
115         case GET_VISIBLE_TREE: {
116             GetVisibleInspectorTreeInner(data, reply, option);
117             break;
118         }
119         default: {
120             LOGI("ui_session unknown transaction code %{public}d", code);
121             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
122         }
123     }
124     return 0;
125 }
126 
GetInspectorTreeInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)127 int32_t UiContentStub::GetInspectorTreeInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
128 {
129     GetInspectorTree(nullptr);
130     return NO_ERROR;
131 }
132 
ConnectInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)133 int32_t UiContentStub::ConnectInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
134 {
135     sptr<IRemoteObject> report = data.ReadRemoteObject();
136     if (report == nullptr) {
137         LOGW("read reportStub object is nullptr,connect failed");
138         return FAILED;
139     }
140     int32_t processId = data.ReadInt32();
141     UiSessionManager::GetInstance()->SaveReportStub(report, processId);
142     UiSessionManager::GetInstance()->SendBaseInfo(processId);
143     return NO_ERROR;
144 }
145 
RegisterClickEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)146 int32_t UiContentStub::RegisterClickEventCallbackInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
147 {
148     reply.WriteInt32(RegisterClickEventCallback(nullptr));
149     return NO_ERROR;
150 }
151 
RegisterRouterChangeEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)152 int32_t UiContentStub::RegisterRouterChangeEventCallbackInner(
153     MessageParcel& data, MessageParcel& reply, MessageOption& option)
154 {
155     reply.WriteInt32(RegisterRouterChangeEventCallback(nullptr));
156     return NO_ERROR;
157 }
158 
RegisterSearchEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)159 int32_t UiContentStub::RegisterSearchEventCallbackInner(
160     MessageParcel& data, MessageParcel& reply, MessageOption& option)
161 {
162     reply.WriteInt32(RegisterSearchEventCallback(nullptr));
163     return NO_ERROR;
164 }
165 
RegisterComponentChangeEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)166 int32_t UiContentStub::RegisterComponentChangeEventCallbackInner(
167     MessageParcel& data, MessageParcel& reply, MessageOption& option)
168 {
169     reply.WriteInt32(RegisterComponentChangeEventCallback(nullptr));
170     return NO_ERROR;
171 }
172 
RegisterWebUnfocusEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)173 int32_t UiContentStub::RegisterWebUnfocusEventCallbackInner(
174     MessageParcel& data, MessageParcel& reply, MessageOption& option)
175 {
176     reply.WriteInt32(RegisterWebUnfocusEventCallback(nullptr));
177     return NO_ERROR;
178 }
179 
UnregisterClickEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)180 int32_t UiContentStub::UnregisterClickEventCallbackInner(
181     MessageParcel& data, MessageParcel& reply, MessageOption& option)
182 {
183     reply.WriteInt32(UnregisterClickEventCallback());
184     return NO_ERROR;
185 }
186 
UnregisterSearchEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)187 int32_t UiContentStub::UnregisterSearchEventCallbackInner(
188     MessageParcel& data, MessageParcel& reply, MessageOption& option)
189 {
190     reply.WriteInt32(UnregisterSearchEventCallback());
191     return NO_ERROR;
192 }
193 
UnregisterRouterChangeEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)194 int32_t UiContentStub::UnregisterRouterChangeEventCallbackInner(
195     MessageParcel& data, MessageParcel& reply, MessageOption& option)
196 {
197     reply.WriteInt32(UnregisterRouterChangeEventCallback());
198     return NO_ERROR;
199 }
200 
UnregisterComponentChangeEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)201 int32_t UiContentStub::UnregisterComponentChangeEventCallbackInner(
202     MessageParcel& data, MessageParcel& reply, MessageOption& option)
203 {
204     reply.WriteInt32(UnregisterComponentChangeEventCallback());
205     return NO_ERROR;
206 }
207 
UnregisterWebUnfocusEventCallbackInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)208 int32_t UiContentStub::UnregisterWebUnfocusEventCallbackInner(
209     MessageParcel& data, MessageParcel& reply, MessageOption& option)
210 {
211     reply.WriteInt32(UnregisterWebUnfocusEventCallback());
212     return NO_ERROR;
213 }
214 
ResetTranslateTextAllInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)215 int32_t UiContentStub::ResetTranslateTextAllInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
216 {
217     reply.WriteInt32(ResetTranslateTextAll());
218     return NO_ERROR;
219 }
220 
ResetTranslateTextInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)221 int32_t UiContentStub::ResetTranslateTextInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
222 {
223     int32_t nodeId = data.ReadInt32();
224     reply.WriteInt32(ResetTranslateText(nodeId));
225     return NO_ERROR;
226 }
227 
GetWebViewCurrentLanguageInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)228 int32_t UiContentStub::GetWebViewCurrentLanguageInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
229 {
230     int32_t processId = data.ReadInt32();
231     UiSessionManager::GetInstance()->SaveProcessId("translate", processId);
232     reply.WriteInt32(GetWebViewCurrentLanguage(nullptr));
233     return NO_ERROR;
234 }
235 
GetWebViewTranslateTextInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)236 int32_t UiContentStub::GetWebViewTranslateTextInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
237 {
238     std::string extraData = data.ReadString();
239     reply.WriteInt32(GetWebViewTranslateText(extraData, nullptr));
240     return NO_ERROR;
241 }
242 
StartWebViewTranslateInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)243 int32_t UiContentStub::StartWebViewTranslateInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
244 {
245     std::string extraData = data.ReadString();
246     int32_t processId = data.ReadInt32();
247     UiSessionManager::GetInstance()->SaveProcessId("translate", processId);
248     reply.WriteInt32(StartWebViewTranslate(extraData, nullptr));
249     return NO_ERROR;
250 }
251 
SendTranslateResultInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)252 int32_t UiContentStub::SendTranslateResultInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
253 {
254     int32_t nodeId = data.ReadInt32();
255     std::vector<std::string> results;
256     data.ReadStringVector(&results);
257     std::vector<int32_t> ids;
258     data.ReadInt32Vector(&ids);
259     reply.WriteInt32(SendTranslateResult(nodeId, results, ids));
260     return NO_ERROR;
261 }
EndWebViewTranslateInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)262 int32_t UiContentStub::EndWebViewTranslateInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
263 {
264     reply.WriteInt32(EndWebViewTranslate());
265     return NO_ERROR;
266 }
267 
SendTranslateResultStrInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)268 int32_t UiContentStub::SendTranslateResultStrInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
269 {
270     int32_t nodeId = data.ReadInt32();
271     std::string result = data.ReadString();
272     reply.WriteInt32(SendTranslateResult(nodeId, result));
273     return NO_ERROR;
274 }
275 
GetCurrentPageNameInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)276 int32_t UiContentStub::GetCurrentPageNameInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
277 {
278     reply.WriteInt32(GetCurrentPageName(nullptr));
279     return NO_ERROR;
280 }
281 
GetCurrentImagesShowingInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)282 int32_t UiContentStub::GetCurrentImagesShowingInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
283 {
284     int32_t processId = data.ReadInt32();
285     UiSessionManager::GetInstance()->SaveProcessId("pixel", processId);
286     reply.WriteInt32(GetCurrentImagesShowing(nullptr));
287     return NO_ERROR;
288 }
289 
GetVisibleInspectorTreeInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)290 int32_t UiContentStub::GetVisibleInspectorTreeInner(MessageParcel& data, MessageParcel& reply, MessageOption& option)
291 {
292     GetVisibleInspectorTree(nullptr);
293     return NO_ERROR;
294 }
295 } // namespace OHOS::Ace
296