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 "frameworks/bridge/declarative_frontend/jsview/js_previewer_mock.h"
17
18 #include "base/log/ace_trace.h"
19 #include "frameworks/bridge/common/utils/utils.h"
20 #include "frameworks/bridge/declarative_frontend/jsview/models/preview_mock_model_impl.h"
21 #include "frameworks/core/components_ng/pattern/preview_mock/preview_mock_model.h"
22 #include "frameworks/core/components_ng/pattern/preview_mock/preview_mock_model_ng.h"
23
24 namespace OHOS::Ace {
25
26 std::unique_ptr<PreviewMockModel> PreviewMockModel::instance_ = nullptr;
27 std::mutex PreviewMockModel::mutex_;
28
GetInstance()29 PreviewMockModel* PreviewMockModel::GetInstance()
30 {
31 if (!instance_) {
32 std::lock_guard<std::mutex> lock(mutex_);
33 if (!instance_) {
34 if (Container::IsCurrentUseNewPipeline()) {
35 instance_.reset(new NG::PreviewMockModelNG());
36 } else {
37 instance_.reset(new Framework::PreviewMockModelImpl());
38 }
39 }
40 }
41 return instance_.get();
42 }
43
44 } // namespace OHOS::Ace
45
46 namespace OHOS::Ace::Framework {
47
CreateMockComponent(const std::string inspectorTag)48 void CreateMockComponent(const std::string inspectorTag)
49 {
50 OHOS::Ace::PreviewMockModel::GetInstance()->Create(inspectorTag);
51 }
52
Create(const JSCallbackInfo & info)53 void JSForm::Create(const JSCallbackInfo& info)
54 {
55 if (info.Length() == 0 || !info[0]->IsObject()) {
56 LOGE("form create fail due to FormComponent construct param is empty or type is not Object");
57 return;
58 }
59
60 CreateMockComponent("FormComponent");
61 }
62
Mock(const JSCallbackInfo & info)63 void JSForm::Mock(const JSCallbackInfo& info) {}
64
JSBind(BindingTarget globalObj)65 void JSForm::JSBind(BindingTarget globalObj)
66 {
67 JSClass<JSForm>::Declare("FormComponent");
68 MethodOptions opt = MethodOptions::NONE;
69 JSClass<JSForm>::StaticMethod("create", &JSForm::Create, opt);
70 JSClass<JSForm>::StaticMethod("size", &JSForm::Mock, opt);
71 JSClass<JSForm>::StaticMethod("dimension", &JSForm::Mock, opt);
72 JSClass<JSForm>::StaticMethod("allowUpdate", &JSForm::Mock, opt);
73 JSClass<JSForm>::StaticMethod("visibility", &JSForm::Mock, opt);
74 JSClass<JSForm>::StaticMethod("clip", &JSForm::Mock, opt);
75
76 JSClass<JSForm>::StaticMethod("onAcquired", &JSForm::Mock);
77 JSClass<JSForm>::StaticMethod("onError", &JSForm::Mock);
78 JSClass<JSForm>::StaticMethod("onUninstall", &JSForm::Mock);
79 JSClass<JSForm>::StaticMethod("onRouter", &JSForm::Mock);
80 JSClass<JSForm>::StaticMethod("onAppear", &JSForm::Mock);
81 JSClass<JSForm>::StaticMethod("onDisAppear", &JSForm::Mock);
82 JSClass<JSForm>::StaticMethod("onTouch", &JSForm::Mock);
83 JSClass<JSForm>::StaticMethod("onKeyEvent", &JSForm::Mock);
84 JSClass<JSForm>::StaticMethod("onDeleteEvent", &JSForm::Mock);
85 JSClass<JSForm>::StaticMethod("onClick", &JSForm::Mock);
86
87 JSClass<JSForm>::InheritAndBind<JSViewAbstract>(globalObj);
88 }
89
Create(const JSCallbackInfo & info)90 void JSRichText::Create(const JSCallbackInfo& info)
91 {
92 if (info.Length() < 1) {
93 LOGI("richtext create error, info is non-valid");
94 return;
95 }
96 CreateMockComponent("RichText");
97 }
98
Mock(const JSCallbackInfo & info)99 void JSRichText::Mock(const JSCallbackInfo& info) {}
100
JSBind(BindingTarget globalObj)101 void JSRichText::JSBind(BindingTarget globalObj)
102 {
103 JSClass<JSRichText>::Declare("RichText");
104 JSClass<JSRichText>::StaticMethod("create", &JSRichText::Create);
105 JSClass<JSRichText>::StaticMethod("onStart", &JSRichText::Mock);
106 JSClass<JSRichText>::StaticMethod("onComplete", &JSRichText::Mock);
107 JSClass<JSRichText>::InheritAndBind<JSViewAbstract>(globalObj);
108 }
109
110 class JSWebDialog : public Referenced {
111 public:
JSBind(BindingTarget globalObj)112 static void JSBind(BindingTarget globalObj)
113 {
114 JSClass<JSWebDialog>::Declare("WebDialog");
115 JSClass<JSWebDialog>::StaticMethod("handleConfirm", &JSWeb::Mock);
116 JSClass<JSWebDialog>::StaticMethod("handleCancel", &JSWeb::Mock);
117 JSClass<JSWebDialog>::StaticMethod("handlePromptConfirm", &JSWeb::Mock);
118 JSClass<JSWebDialog>::Bind(globalObj);
119 }
120 };
121
122 class JSWebHttpAuth : public Referenced {
123 public:
JSBind(BindingTarget globalObj)124 static void JSBind(BindingTarget globalObj)
125 {
126 JSClass<JSWebHttpAuth>::Declare("WebHttpAuthResult");
127 JSClass<JSWebHttpAuth>::StaticMethod("confirm", &JSWeb::Mock);
128 JSClass<JSWebHttpAuth>::StaticMethod("cancel", &JSWeb::Mock);
129 JSClass<JSWebHttpAuth>::StaticMethod("isHttpAuthInfoSaved", &JSWeb::Mock);
130 JSClass<JSWebHttpAuth>::Bind(globalObj);
131 }
132 };
133
134 class JSWebSslError : public Referenced {
135 public:
JSBind(BindingTarget globalObj)136 static void JSBind(BindingTarget globalObj)
137 {
138 JSClass<JSWebSslError>::Declare("WebSslErrorResult");
139 JSClass<JSWebSslError>::StaticMethod("handleConfirm", &JSWeb::Mock);
140 JSClass<JSWebSslError>::StaticMethod("handleCancel", &JSWeb::Mock);
141 JSClass<JSWebSslError>::Bind(globalObj);
142 }
143 };
144
145 class JSWebSslSelectCert : public Referenced {
146 public:
JSBind(BindingTarget globalObj)147 static void JSBind(BindingTarget globalObj)
148 {
149 JSClass<JSWebSslSelectCert>::Declare("WebSelectCertResult");
150 JSClass<JSWebSslSelectCert>::StaticMethod("confirm", &JSWeb::Mock);
151 JSClass<JSWebSslSelectCert>::StaticMethod("cancel", &JSWeb::Mock);
152 JSClass<JSWebSslSelectCert>::StaticMethod("ignore", &JSWeb::Mock);
153 JSClass<JSWebSslSelectCert>::Bind(globalObj);
154 }
155 };
156
157 class JSWebConsoleLog : public Referenced {
158 public:
JSBind(BindingTarget globalObj)159 static void JSBind(BindingTarget globalObj)
160 {
161 JSClass<JSWebConsoleLog>::Declare("ConsoleMessage");
162 JSClass<JSWebConsoleLog>::StaticMethod("getLineNumber", &JSWeb::Mock);
163 JSClass<JSWebConsoleLog>::StaticMethod("getMessage", &JSWeb::Mock);
164 JSClass<JSWebConsoleLog>::StaticMethod("getMessageLevel", &JSWeb::Mock);
165 JSClass<JSWebConsoleLog>::StaticMethod("getSourceId", &JSWeb::Mock);
166 JSClass<JSWebConsoleLog>::Bind(globalObj);
167 }
168 };
169
170 class JSWebGeolocation : public Referenced {
171 public:
JSBind(BindingTarget globalObj)172 static void JSBind(BindingTarget globalObj)
173 {
174 JSClass<JSWebGeolocation>::Declare("WebGeolocation");
175 JSClass<JSWebGeolocation>::StaticMethod("invoke", &JSWeb::Mock);
176 JSClass<JSWebGeolocation>::Bind(globalObj);
177 }
178 };
179
180 class JSWebResourceError : public Referenced {
181 public:
JSBind(BindingTarget globalObj)182 static void JSBind(BindingTarget globalObj)
183 {
184 JSClass<JSWebResourceError>::Declare("WebResourceError");
185 JSClass<JSWebResourceError>::StaticMethod("getErrorCode", &JSWeb::Mock);
186 JSClass<JSWebResourceError>::StaticMethod("getErrorInfo", &JSWeb::Mock);
187 JSClass<JSWebResourceError>::Bind(globalObj);
188 }
189 };
190
191 class JSWebResourceResponse : public Referenced {
192 public:
JSBind(BindingTarget globalObj)193 static void JSBind(BindingTarget globalObj)
194 {
195 JSClass<JSWebResourceResponse>::Declare("WebResourceResponse");
196 JSClass<JSWebResourceResponse>::StaticMethod("getResponseData", &JSWeb::Mock);
197 JSClass<JSWebResourceResponse>::StaticMethod("getResponseEncoding", &JSWeb::Mock);
198 JSClass<JSWebResourceResponse>::StaticMethod("getResponseMimeType", &JSWeb::Mock);
199 JSClass<JSWebResourceResponse>::StaticMethod("getReasonMessage", &JSWeb::Mock);
200 JSClass<JSWebResourceResponse>::StaticMethod("getResponseCode", &JSWeb::Mock);
201 JSClass<JSWebResourceResponse>::StaticMethod("getResponseHeader", &JSWeb::Mock);
202 JSClass<JSWebResourceResponse>::Bind(globalObj);
203 }
204 };
205
206 class JSWebResourceRequest : public Referenced {
207 public:
JSBind(BindingTarget globalObj)208 static void JSBind(BindingTarget globalObj)
209 {
210 JSClass<JSWebResourceRequest>::Declare("WebResourceRequest");
211 JSClass<JSWebResourceRequest>::StaticMethod("getRequestUrl", &JSWeb::Mock);
212 JSClass<JSWebResourceRequest>::StaticMethod("getRequestHeader", &JSWeb::Mock);
213 JSClass<JSWebResourceRequest>::StaticMethod("isRequestGesture", &JSWeb::Mock);
214 JSClass<JSWebResourceRequest>::StaticMethod("isMainFrame", &JSWeb::Mock);
215 JSClass<JSWebResourceRequest>::StaticMethod("isRedirect", &JSWeb::Mock);
216 JSClass<JSWebResourceRequest>::Bind(globalObj);
217 }
218 };
219
220 class JSFileSelectorParam : public Referenced {
221 public:
JSBind(BindingTarget globalObj)222 static void JSBind(BindingTarget globalObj)
223 {
224 JSClass<JSFileSelectorParam>::Declare("FileSelectorParam");
225 JSClass<JSFileSelectorParam>::StaticMethod("getTitle", &JSWeb::Mock);
226 JSClass<JSFileSelectorParam>::StaticMethod("getMode", &JSWeb::Mock);
227 JSClass<JSFileSelectorParam>::StaticMethod("getAcceptType", &JSWeb::Mock);
228 JSClass<JSFileSelectorParam>::StaticMethod("isCapture", &JSWeb::Mock);
229 JSClass<JSFileSelectorParam>::Bind(globalObj);
230 }
231 };
232
233 class JSFileSelectorResult : public Referenced {
234 public:
JSBind(BindingTarget globalObj)235 static void JSBind(BindingTarget globalObj)
236 {
237 JSClass<JSFileSelectorResult>::Declare("FileSelectorResult");
238 JSClass<JSFileSelectorResult>::StaticMethod("handleFileList", &JSWeb::Mock);
239 JSClass<JSFileSelectorResult>::Bind(globalObj);
240 }
241 };
242
Create(const JSCallbackInfo & info)243 void JSWeb::Create(const JSCallbackInfo& info)
244 {
245 if (info.Length() < 1 || !info[0]->IsObject()) {
246 LOGI("web create error, info is invalid");
247 return;
248 }
249
250 CreateMockComponent("Web");
251 }
252
Mock(const JSCallbackInfo & info)253 void JSWeb::Mock(const JSCallbackInfo& info) {}
254
JSBind(BindingTarget globalObj)255 void JSWeb::JSBind(BindingTarget globalObj)
256 {
257 JSClass<JSWeb>::Declare("Web");
258 JSClass<JSWeb>::StaticMethod("create", &JSWeb::Create);
259 JSClass<JSWeb>::StaticMethod("onAlert", &JSWeb::Mock);
260 JSClass<JSWeb>::StaticMethod("onBeforeUnload", &JSWeb::Mock);
261 JSClass<JSWeb>::StaticMethod("onConfirm", &JSWeb::Mock);
262 JSClass<JSWeb>::StaticMethod("onPrompt", &JSWeb::Mock);
263 JSClass<JSWeb>::StaticMethod("onConsole", &JSWeb::Mock);
264 JSClass<JSWeb>::StaticMethod("onPageBegin", &JSWeb::Mock);
265 JSClass<JSWeb>::StaticMethod("onPageEnd", &JSWeb::Mock);
266 JSClass<JSWeb>::StaticMethod("onProgressChange", &JSWeb::Mock);
267 JSClass<JSWeb>::StaticMethod("onTitleReceive", &JSWeb::Mock);
268 JSClass<JSWeb>::StaticMethod("onGeolocationHide", &JSWeb::Mock);
269 JSClass<JSWeb>::StaticMethod("onGeolocationShow", &JSWeb::Mock);
270 JSClass<JSWeb>::StaticMethod("onRequestSelected", &JSWeb::Mock);
271 JSClass<JSWeb>::StaticMethod("onShowFileSelector", &JSWeb::Mock);
272 JSClass<JSWeb>::StaticMethod("javaScriptAccess", &JSWeb::Mock);
273 JSClass<JSWeb>::StaticMethod("fileExtendAccess", &JSWeb::Mock);
274 JSClass<JSWeb>::StaticMethod("fileAccess", &JSWeb::Mock);
275 JSClass<JSWeb>::StaticMethod("onDownloadStart", &JSWeb::Mock);
276 JSClass<JSWeb>::StaticMethod("onErrorReceive", &JSWeb::Mock);
277 JSClass<JSWeb>::StaticMethod("onHttpErrorReceive", &JSWeb::Mock);
278 JSClass<JSWeb>::StaticMethod("onUrlLoadIntercept", &JSWeb::Mock);
279 JSClass<JSWeb>::StaticMethod("onlineImageAccess", &JSWeb::Mock);
280 JSClass<JSWeb>::StaticMethod("domStorageAccess", &JSWeb::Mock);
281 JSClass<JSWeb>::StaticMethod("imageAccess", &JSWeb::Mock);
282 JSClass<JSWeb>::StaticMethod("mixedMode", &JSWeb::Mock);
283 JSClass<JSWeb>::StaticMethod("zoomAccess", &JSWeb::Mock);
284 JSClass<JSWeb>::StaticMethod("geolocationAccess", &JSWeb::Mock);
285 JSClass<JSWeb>::StaticMethod("javaScriptProxy", &JSWeb::Mock);
286 JSClass<JSWeb>::StaticMethod("userAgent", &JSWeb::Mock);
287 JSClass<JSWeb>::StaticMethod("onRenderExited", &JSWeb::Mock);
288 JSClass<JSWeb>::StaticMethod("onRefreshAccessedHistory", &JSWeb::Mock);
289 JSClass<JSWeb>::StaticMethod("cacheMode", &JSWeb::Mock);
290 JSClass<JSWeb>::StaticMethod("overviewModeAccess", &JSWeb::Mock);
291 JSClass<JSWeb>::StaticMethod("fileFromUrlAccess", &JSWeb::Mock);
292 JSClass<JSWeb>::StaticMethod("databaseAccess", &JSWeb::Mock);
293 JSClass<JSWeb>::StaticMethod("textZoomAtio", &JSWeb::Mock);
294 JSClass<JSWeb>::StaticMethod("textZoomRatio", &JSWeb::Mock);
295 JSClass<JSWeb>::StaticMethod("webDebuggingAccess", &JSWeb::Mock);
296 JSClass<JSWeb>::StaticMethod("initialScale", &JSWeb::Mock);
297 JSClass<JSWeb>::StaticMethod("backgroundColor", &JSWeb::Mock);
298 JSClass<JSWeb>::StaticMethod("onKeyEvent", &JSWeb::Mock);
299 JSClass<JSWeb>::StaticMethod("onTouch", &JSWeb::Mock);
300 JSClass<JSWeb>::StaticMethod("onMouse", &JSWeb::Mock);
301 JSClass<JSWeb>::StaticMethod("onResourceLoad", &JSWeb::Mock);
302 JSClass<JSWeb>::StaticMethod("onScaleChange", &JSWeb::Mock);
303 JSClass<JSWeb>::StaticMethod("password", &JSWeb::Mock);
304 JSClass<JSWeb>::StaticMethod("tableData", &JSWeb::Mock);
305 JSClass<JSWeb>::StaticMethod("onFileSelectorShow", &JSWeb::Mock);
306 JSClass<JSWeb>::StaticMethod("onHttpAuthRequest", &JSWeb::Mock);
307 JSClass<JSWeb>::StaticMethod("onSslErrorEventReceive", &JSWeb::Mock);
308 JSClass<JSWeb>::StaticMethod("onClientAuthenticationRequest", &JSWeb::Mock);
309 JSClass<JSWeb>::InheritAndBind<JSViewAbstract>(globalObj);
310
311 JSWebDialog::JSBind(globalObj);
312 JSWebGeolocation::JSBind(globalObj);
313 JSWebResourceRequest::JSBind(globalObj);
314 JSWebResourceError::JSBind(globalObj);
315 JSWebResourceResponse::JSBind(globalObj);
316 JSWebConsoleLog::JSBind(globalObj);
317 JSFileSelectorParam::JSBind(globalObj);
318 JSFileSelectorResult::JSBind(globalObj);
319 JSWebHttpAuth::JSBind(globalObj);
320 JSWebSslError::JSBind(globalObj);
321 JSWebSslSelectCert::JSBind(globalObj);
322 }
323
324 class JSWebCookie : public Referenced {
325 public:
JSBind(BindingTarget globalObj)326 static void JSBind(BindingTarget globalObj)
327 {
328 JSClass<JSWebCookie>::Declare("WebCookie");
329 JSClass<JSWebCookie>::StaticMethod("setCookie", &JSWeb::Mock);
330 JSClass<JSWebCookie>::StaticMethod("getCookie", &JSWeb::Mock);
331 JSClass<JSWebCookie>::StaticMethod("deleteEntireCookie", &JSWeb::Mock);
332 JSClass<JSWebCookie>::StaticMethod("saveCookieSync", &JSWeb::Mock);
333 JSClass<JSWebCookie>::Bind(globalObj);
334 }
335 };
336
337 class JSHitTestValue : public Referenced {
338 public:
JSBind(BindingTarget globalObj)339 static void JSBind(BindingTarget globalObj)
340 {
341 JSClass<JSHitTestValue>::Declare("HitTestValue");
342 JSClass<JSHitTestValue>::StaticMethod("getType", &JSWeb::Mock);
343 JSClass<JSHitTestValue>::StaticMethod("getExtra", &JSWeb::Mock);
344 JSClass<JSHitTestValue>::Bind(globalObj);
345 }
346 };
347
JSBind(BindingTarget globalObj)348 void JSWebController::JSBind(BindingTarget globalObj)
349 {
350 JSClass<JSWebController>::Declare("WebController");
351 JSClass<JSWebController>::StaticMethod("loadUrl", &JSWeb::Mock);
352 JSClass<JSWebController>::StaticMethod("runJavaScript", &JSWeb::Mock);
353 JSClass<JSWebController>::StaticMethod("refresh", &JSWeb::Mock);
354 JSClass<JSWebController>::StaticMethod("stop", &JSWeb::Mock);
355 JSClass<JSWebController>::StaticMethod("getHitTest", &JSWeb::Mock);
356 JSClass<JSWebController>::StaticMethod("registerJavaScriptProxy", &JSWeb::Mock);
357 JSClass<JSWebController>::StaticMethod("deleteJavaScriptRegister", &JSWeb::Mock);
358 JSClass<JSWebController>::StaticMethod("onInactive", &JSWeb::Mock);
359 JSClass<JSWebController>::StaticMethod("onActive", &JSWeb::Mock);
360 JSClass<JSWebController>::StaticMethod("zoom", &JSWeb::Mock);
361 JSClass<JSWebController>::StaticMethod("requestFocus", &JSWeb::Mock);
362 JSClass<JSWebController>::StaticMethod("loadData", &JSWeb::Mock);
363 JSClass<JSWebController>::StaticMethod("backward", &JSWeb::Mock);
364 JSClass<JSWebController>::StaticMethod("forward", &JSWeb::Mock);
365 JSClass<JSWebController>::StaticMethod("accessStep", &JSWeb::Mock);
366 JSClass<JSWebController>::StaticMethod("accessForward", &JSWeb::Mock);
367 JSClass<JSWebController>::StaticMethod("accessBackward", &JSWeb::Mock);
368 JSClass<JSWebController>::StaticMethod("clearHistory", &JSWeb::Mock);
369 JSClass<JSWebController>::StaticMethod("clearSslCache", &JSWeb::Mock);
370 JSClass<JSWebController>::StaticMethod("clearClientAuthenticationCache", &JSWeb::Mock);
371 JSClass<JSWebController>::StaticMethod("getCookieManager", &JSWeb::Mock);
372 JSClass<JSWebController>::StaticMethod("getHitTestValue", &JSWeb::Mock);
373 JSClass<JSWebController>::StaticMethod("backOrForward", &JSWeb::Mock);
374 JSClass<JSWebController>::StaticMethod("zoomIn", &JSWeb::Mock);
375 JSClass<JSWebController>::StaticMethod("zoomOut", &JSWeb::Mock);
376 JSClass<JSWebController>::StaticMethod("getPageHeight", &JSWeb::Mock);
377 JSClass<JSWebController>::StaticMethod("getTitle", &JSWeb::Mock);
378 JSClass<JSWebController>::StaticMethod("getWebId", &JSWeb::Mock);
379 JSClass<JSWebController>::StaticMethod("getDefaultUserAgent", &JSWeb::Mock);
380 JSClass<JSWebController>::Bind(globalObj);
381 JSWebCookie::JSBind(globalObj);
382 JSHitTestValue::JSBind(globalObj);
383 }
384
Create(const JSCallbackInfo & info)385 void JSXComponent::Create(const JSCallbackInfo& info)
386 {
387 if (info.Length() < 1 || !info[0]->IsObject()) {
388 LOGI("xcomponent create error, info is invalid");
389 return;
390 }
391 CreateMockComponent("XComponent");
392 }
393
Mock(const JSCallbackInfo & info)394 void JSXComponent::Mock(const JSCallbackInfo& info) {}
395
JSBind(BindingTarget globalObj)396 void JSXComponent::JSBind(BindingTarget globalObj)
397 {
398 JSClass<JSXComponent>::Declare("XComponent");
399 JSClass<JSXComponent>::StaticMethod("create", &JSXComponent::Create);
400 JSClass<JSXComponent>::StaticMethod("onLoad", &JSXComponent::Mock);
401 JSClass<JSXComponent>::StaticMethod("onDestroy", &JSXComponent::Mock);
402 JSClass<JSXComponent>::InheritAndBind<JSViewAbstract>(globalObj);
403 }
404
JSBind(BindingTarget globalObj)405 void JSXComponentController::JSBind(BindingTarget globalObj)
406 {
407 JSClass<JSXComponentController>::Declare("XComponentController");
408 JSClass<JSXComponentController>::StaticMethod("getXComponentSurfaceId", &JSXComponentController::Mock);
409 JSClass<JSXComponentController>::StaticMethod("getXComponentContext", &JSXComponentController::Mock);
410 JSClass<JSXComponentController>::StaticMethod("setXComponentSurfaceSize", &JSXComponentController::Mock);
411 JSClass<JSXComponentController>::Bind(globalObj);
412 }
413
Mock(const JSCallbackInfo & info)414 void JSXComponentController::Mock(const JSCallbackInfo& info) {}
415
Create(const JSCallbackInfo & info)416 void JSVideo::Create(const JSCallbackInfo& info)
417 {
418 if (info.Length() <= 0 || !info[0]->IsObject()) {
419 LOGE("video create error, info is invalid.");
420 return;
421 }
422 CreateMockComponent("Video");
423 }
424
Mock(const JSCallbackInfo & info)425 void JSVideo::Mock(const JSCallbackInfo& info) {}
426
JSBind(BindingTarget globalObj)427 void JSVideo::JSBind(BindingTarget globalObj)
428 {
429 JSClass<JSVideo>::Declare("Video");
430 MethodOptions opt = MethodOptions::NONE;
431 JSClass<JSVideo>::StaticMethod("create", &JSVideo::Create, opt);
432 JSClass<JSVideo>::StaticMethod("muted", &JSVideo::Mock, opt);
433 JSClass<JSVideo>::StaticMethod("autoPlay", &JSVideo::Mock, opt);
434 JSClass<JSVideo>::StaticMethod("controls", &JSVideo::Mock, opt);
435 JSClass<JSVideo>::StaticMethod("loop", &JSVideo::Mock, opt);
436 JSClass<JSVideo>::StaticMethod("objectFit", &JSVideo::Mock, opt);
437
438 JSClass<JSVideo>::StaticMethod("onStart", &JSVideo::Mock);
439 JSClass<JSVideo>::StaticMethod("onPause", &JSVideo::Mock);
440 JSClass<JSVideo>::StaticMethod("onFinish", &JSVideo::Mock);
441 JSClass<JSVideo>::StaticMethod("onFullscreenChange", &JSVideo::Mock);
442 JSClass<JSVideo>::StaticMethod("onPrepared", &JSVideo::Mock);
443 JSClass<JSVideo>::StaticMethod("onSeeking", &JSVideo::Mock);
444 JSClass<JSVideo>::StaticMethod("onSeeked", &JSVideo::Mock);
445 JSClass<JSVideo>::StaticMethod("onUpdate", &JSVideo::Mock);
446 JSClass<JSVideo>::StaticMethod("onError", &JSVideo::Mock);
447
448 JSClass<JSVideo>::StaticMethod("onTouch", &JSVideo::Mock);
449 JSClass<JSVideo>::StaticMethod("onHover", &JSVideo::Mock);
450 JSClass<JSVideo>::StaticMethod("onKeyEvent", &JSVideo::Mock);
451 JSClass<JSVideo>::StaticMethod("onDeleteEvent", &JSVideo::Mock);
452 JSClass<JSVideo>::StaticMethod("onClick", &JSVideo::Mock);
453 JSClass<JSVideo>::StaticMethod("onAppear", &JSVideo::Mock);
454 JSClass<JSVideo>::StaticMethod("onDisAppear", &JSVideo::Mock);
455 JSClass<JSVideo>::StaticMethod("remoteMessage", &JSVideo::Mock);
456
457 // override method
458 JSClass<JSVideo>::StaticMethod("opacity", &JSVideo::Mock);
459 JSClass<JSVideo>::StaticMethod("transition", &JSVideo::Mock);
460 JSClass<JSVideo>::InheritAndBind<JSViewAbstract>(globalObj);
461 }
462
JSBind(BindingTarget globalObj)463 void JSVideoController::JSBind(BindingTarget globalObj)
464 {
465 JSClass<JSVideoController>::Declare("VideoController");
466 JSClass<JSVideoController>::StaticMethod("start", &JSVideoController::Mock);
467 JSClass<JSVideoController>::StaticMethod("pause", &JSVideoController::Mock);
468 JSClass<JSVideoController>::StaticMethod("stop", &JSVideoController::Mock);
469 JSClass<JSVideoController>::StaticMethod("setCurrentTime", &JSVideoController::Mock);
470 JSClass<JSVideoController>::StaticMethod("requestFullscreen", &JSVideoController::Mock);
471 JSClass<JSVideoController>::StaticMethod("exitFullscreen", &JSVideoController::Mock);
472 JSClass<JSVideoController>::Bind(globalObj);
473 }
474
Mock(const JSCallbackInfo & info)475 void JSVideoController::Mock(const JSCallbackInfo& info) {}
476
Create(const JSCallbackInfo & info)477 void JSPlugin::Create(const JSCallbackInfo& info)
478 {
479 if (info.Length() <= 0 || !info[0]->IsObject()) {
480 LOGE("plugin create error, info is invalid.");
481 return;
482 }
483 CreateMockComponent("PluginComponent");
484 }
485
Mock(const JSCallbackInfo & info)486 void JSPlugin::Mock(const JSCallbackInfo& info) {}
487
JSBind(BindingTarget globalObj)488 void JSPlugin::JSBind(BindingTarget globalObj)
489 {
490 JSClass<JSPlugin>::Declare("PluginComponent");
491 MethodOptions opt = MethodOptions::NONE;
492 JSClass<JSPlugin>::StaticMethod("create", &JSPlugin::Create, opt);
493 JSClass<JSPlugin>::StaticMethod("size", &JSPlugin::Mock, opt);
494 JSClass<JSPlugin>::StaticMethod("width", &JSPlugin::Mock);
495 JSClass<JSPlugin>::StaticMethod("height", &JSPlugin::Mock);
496 JSClass<JSPlugin>::StaticMethod("onComplete", &JSPlugin::Mock);
497 JSClass<JSPlugin>::StaticMethod("onError", &JSPlugin::Mock);
498 JSClass<JSPlugin>::StaticMethod("onAppear", &JSPlugin::Mock);
499 JSClass<JSPlugin>::StaticMethod("onDisAppear", &JSPlugin::Mock);
500 JSClass<JSPlugin>::StaticMethod("onTouch", &JSPlugin::Mock);
501 JSClass<JSPlugin>::StaticMethod("onKeyEvent", &JSPlugin::Mock);
502 JSClass<JSPlugin>::StaticMethod("onDeleteEvent", &JSPlugin::Mock);
503 JSClass<JSPlugin>::StaticMethod("onClick", &JSPlugin::Mock);
504
505 JSClass<JSPlugin>::InheritAndBind<JSViewAbstract>(globalObj);
506 }
507
JSBind(BindingTarget globalObj)508 void JSUIExtension::JSBind(BindingTarget globalObj)
509 {
510 JSClass<JSUIExtension>::Declare("UIExtensionComponent");
511 MethodOptions opt = MethodOptions::NONE;
512 JSClass<JSUIExtension>::StaticMethod("create", &JSUIExtension::Create, opt);
513 JSClass<JSUIExtension>::StaticMethod("onRemoteReady", &JSUIExtension::Mock);
514 JSClass<JSUIExtension>::StaticMethod("onReceive", &JSUIExtension::Mock);
515 JSClass<JSUIExtension>::StaticMethod("onResult", &JSUIExtension::Mock);
516 JSClass<JSUIExtension>::StaticMethod("onRelease", &JSUIExtension::Mock);
517 JSClass<JSUIExtension>::StaticMethod("onError", &JSUIExtension::Mock);
518 JSClass<JSUIExtension>::InheritAndBind<JSViewAbstract>(globalObj);
519 }
520
Create(const JSCallbackInfo & info)521 void JSUIExtension::Create(const JSCallbackInfo& info)
522 {
523 if (!info[0]->IsObject()) {
524 return;
525 }
526 CreateMockComponent("UIExtensionComponent");
527 }
528
Mock(const JSCallbackInfo & info)529 void JSUIExtension::Mock(const JSCallbackInfo& info) {}
530 } // namespace OHOS::Ace::Framework
531