1 /*
2  * Copyright (c) 2024 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 <cstdint>
17 #include "webview_controller_impl.h"
18 #include "webview_javascript_execute_callback.h"
19 #include "webview_javascript_result_callback.h"
20 #include "native_arkweb_utils.h"
21 #include "native_interface_arkweb.h"
22 #include "cj_common_ffi.h"
23 #include "application_context.h"
24 #include "webview_log.h"
25 #include "webview_utils.h"
26 #include "nweb_store_web_archive_callback.h"
27 
28 namespace OHOS::Webview {
29     std::unordered_map<int32_t, WebviewControllerImpl*> g_webview_controller_map;
30     std::string WebviewControllerImpl::customeSchemeCmdLine_ = "";
31     bool WebviewControllerImpl::existNweb_ = false;
32     bool WebviewControllerImpl::webDebuggingAccess_ = false;
33 
WebviewControllerImpl(int32_t nwebId)34     WebviewControllerImpl::WebviewControllerImpl(int32_t nwebId) : nwebId_(nwebId)
35     {
36         if (IsInit()) {
37             std::unique_lock<std::mutex> lk(webMtx_);
38             g_webview_controller_map.emplace(nwebId, this);
39         }
40     }
41 
IsInit()42     bool WebviewControllerImpl::IsInit()
43     {
44         return NWeb::NWebHelper::Instance().GetNWeb(nwebId_) ? true : false;
45     }
46 
SetWebId(int32_t nwebId)47     void WebviewControllerImpl::SetWebId(int32_t nwebId)
48     {
49         nwebId_ = nwebId;
50         std::unique_lock<std::mutex> lk(webMtx_);
51         g_webview_controller_map.emplace(nwebId, this);
52 
53         if (webTag_.empty()) {
54             WEBVIEWLOGI("native webtag is empty, don't care because it's not a native instance");
55             return;
56         }
57 
58         auto nweb_ptr = OHOS::NWeb::NWebHelper::Instance().GetNWeb(nwebId);
59         if (nweb_ptr) {
60             OH_NativeArkWeb_BindWebTagToWebInstance(webTag_.c_str(), nweb_ptr);
61             NWeb::NWebHelper::Instance().SetWebTag(nwebId_, webTag_.c_str());
62         }
63     }
64 
InnerSetHapPath(const std::string & hapPath)65     void WebviewControllerImpl::InnerSetHapPath(const std::string &hapPath)
66     {
67         hapPath_ = hapPath;
68     }
69 
GetWebId() const70     int32_t WebviewControllerImpl::GetWebId() const
71     {
72         int32_t webId = -1;
73         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
74         if (nweb_ptr) {
75             webId = static_cast<int32_t>(nweb_ptr->GetWebId());
76         }
77         return webId;
78     }
79 
LoadUrl(std::string url)80     int32_t WebviewControllerImpl::LoadUrl(std::string url)
81     {
82         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
83         if (!nweb_ptr) {
84             return NWebError::INIT_ERROR;
85         }
86         return nweb_ptr->Load(url);
87     }
88 
LoadUrl(std::string url,std::map<std::string,std::string> httpHeaders)89     int32_t WebviewControllerImpl::LoadUrl(std::string url, std::map<std::string, std::string> httpHeaders)
90     {
91         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
92         if (!nweb_ptr) {
93             return NWebError::INIT_ERROR;
94         }
95         return nweb_ptr->Load(url, httpHeaders);
96     }
97 
LoadData(std::string data,std::string mimeType,std::string encoding,std::string baseUrl,std::string historyUrl)98     ErrCode WebviewControllerImpl::LoadData(std::string data, std::string mimeType, std::string encoding,
99         std::string baseUrl, std::string historyUrl)
100     {
101         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
102         if (!nweb_ptr) {
103             return NWebError::INIT_ERROR;
104         }
105         if (baseUrl.empty() && historyUrl.empty()) {
106             return nweb_ptr->LoadWithData(data, mimeType, encoding);
107         }
108         return nweb_ptr->LoadWithDataAndBaseUrl(baseUrl, data, mimeType, encoding, historyUrl);
109     }
110 
Refresh()111     void WebviewControllerImpl::Refresh()
112     {
113         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
114         if (nweb_ptr) {
115             nweb_ptr->Reload();
116         }
117     }
118 
GetUserAgent()119     std::string WebviewControllerImpl::GetUserAgent()
120     {
121         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
122         if (!nweb_ptr) {
123             return "";
124         }
125         std::shared_ptr<OHOS::NWeb::NWebPreference> setting = nweb_ptr->GetPreference();
126         if (!setting) {
127             return "";
128         }
129         return setting->DefaultUserAgent();
130     }
131 
AccessForward()132     bool WebviewControllerImpl::AccessForward()
133     {
134         bool access = false;
135         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
136         if (nweb_ptr) {
137             access = nweb_ptr->IsNavigateForwardAllowed();
138         }
139         return access;
140     }
141 
AccessBackward()142     bool WebviewControllerImpl::AccessBackward()
143     {
144         bool access = false;
145         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
146         if (nweb_ptr) {
147             access = nweb_ptr->IsNavigatebackwardAllowed();
148         }
149         return access;
150     }
151 
SetCustomUserAgent(const std::string & userAgent)152     int32_t WebviewControllerImpl::SetCustomUserAgent(const std::string& userAgent)
153     {
154         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
155         if (!nweb_ptr) {
156             return NWebError::INIT_ERROR;
157         }
158         std::shared_ptr<OHOS::NWeb::NWebPreference> setting = nweb_ptr->GetPreference();
159         if (!setting) {
160             return NWebError::INIT_ERROR;
161         }
162         setting->PutUserAgent(userAgent);
163         return NWebError::NO_ERROR;
164     }
165 
GetCustomUserAgent() const166     std::string WebviewControllerImpl::GetCustomUserAgent() const
167     {
168         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
169         if (!nweb_ptr) {
170             return "";
171         }
172         std::shared_ptr<OHOS::NWeb::NWebPreference> setting = nweb_ptr->GetPreference();
173         if (!setting) {
174             return "";
175         }
176         return setting->UserAgent();
177     }
178 
RunJavaScript(std::string script,const std::function<void (RetDataCString)> & callbackRef)179     void WebviewControllerImpl::RunJavaScript(std::string script,
180         const std::function<void(RetDataCString)>& callbackRef)
181     {
182         RetDataCString ret = { .code = NWebError::INIT_ERROR, .data = nullptr };
183         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
184         if (!nweb_ptr) {
185             callbackRef(ret);
186             return;
187         }
188         auto callbackImpl = std::make_shared<WebviewJavaScriptExecuteCallback>(callbackRef);
189         nweb_ptr->ExecuteJavaScript(script, callbackImpl, false);
190     }
191 
GetUrl()192     std::string WebviewControllerImpl::GetUrl()
193     {
194         std::string url = "";
195         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
196         if (nweb_ptr) {
197             url = nweb_ptr->GetUrl();
198         }
199         return url;
200     }
201 
GetOriginalUrl()202     std::string WebviewControllerImpl::GetOriginalUrl()
203     {
204         std::string url = "";
205         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
206         if (nweb_ptr) {
207             url = nweb_ptr->GetOriginalUrl();
208         }
209         return url;
210     }
211 
ScrollPageUp(bool top)212     void WebviewControllerImpl::ScrollPageUp(bool top)
213     {
214         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
215         if (nweb_ptr) {
216             nweb_ptr->PageUp(top);
217         }
218         return;
219     }
220 
ScrollPageDown(bool bottom)221     void WebviewControllerImpl::ScrollPageDown(bool bottom)
222     {
223         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
224         if (nweb_ptr) {
225             nweb_ptr->PageDown(bottom);
226         }
227         return;
228     }
229 
ScrollTo(float x,float y)230     void WebviewControllerImpl::ScrollTo(float x, float y)
231     {
232         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
233         if (nweb_ptr) {
234             nweb_ptr->ScrollTo(x, y);
235         }
236         return;
237     }
238 
ScrollBy(float deltaX,float deltaY)239     void WebviewControllerImpl::ScrollBy(float deltaX, float deltaY)
240     {
241         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
242         if (nweb_ptr) {
243             nweb_ptr->ScrollBy(deltaX, deltaY);
244         }
245         return;
246     }
247 
Forward()248     void WebviewControllerImpl::Forward()
249     {
250         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
251         if (nweb_ptr) {
252             nweb_ptr->NavigateForward();
253         }
254         return;
255     }
256 
Backward()257     void WebviewControllerImpl::Backward()
258     {
259         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
260         if (nweb_ptr) {
261             nweb_ptr->NavigateBack();
262         }
263         return;
264     }
265 
BackOrForward(int32_t step)266     int32_t WebviewControllerImpl::BackOrForward(int32_t step)
267     {
268         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
269         if (!nweb_ptr) {
270             return NWebError::INIT_ERROR;
271         }
272         nweb_ptr->NavigateBackOrForward(step);
273         return NWebError::NO_ERROR;
274     }
275 
GetPageHeight()276     int32_t WebviewControllerImpl::GetPageHeight()
277     {
278         int32_t pageHeight = 0;
279         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
280         if (nweb_ptr) {
281             pageHeight = nweb_ptr->ContentHeight();
282         }
283         return pageHeight;
284     }
285 
GetTitle()286     std::string WebviewControllerImpl::GetTitle()
287     {
288         std::string title = "";
289         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
290         if (nweb_ptr) {
291             title = nweb_ptr->Title();
292         }
293         return title;
294     }
295 
Zoom(float factor)296     int32_t WebviewControllerImpl::Zoom(float factor)
297     {
298         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
299         if (!nweb_ptr) {
300             return NWebError::INIT_ERROR;
301         }
302         ErrCode result = NWebError::NO_ERROR;
303         result = nweb_ptr->Zoom(factor);
304 
305         return result;
306     }
307 
ZoomIn()308     int32_t WebviewControllerImpl::ZoomIn()
309     {
310         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
311         if (!nweb_ptr) {
312             return NWebError::INIT_ERROR;
313         }
314         ErrCode result = NWebError::NO_ERROR;
315         result = nweb_ptr->ZoomIn();
316 
317         return result;
318     }
319 
ZoomOut()320     int32_t WebviewControllerImpl::ZoomOut()
321     {
322         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
323         if (!nweb_ptr) {
324             return NWebError::INIT_ERROR;
325         }
326         ErrCode result = NWebError::NO_ERROR;
327         result = nweb_ptr->ZoomOut();
328 
329         return result;
330     }
331 
ClearHistory()332     void WebviewControllerImpl::ClearHistory()
333     {
334         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
335         if (nweb_ptr) {
336             nweb_ptr->DeleteNavigateHistory();
337         }
338     }
339 
AccessStep(int32_t step)340     bool WebviewControllerImpl::AccessStep(int32_t step)
341     {
342         bool access = false;
343         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
344         if (nweb_ptr) {
345             access = nweb_ptr->CanNavigateBackOrForward(step);
346         }
347         return access;
348     }
349 
OnActive()350     void WebviewControllerImpl::OnActive()
351     {
352         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
353         if (nweb_ptr) {
354             WEBVIEWLOGD("WebviewControllerImpl::OnActive start")
355             nweb_ptr->OnContinue();
356         }
357     }
358 
OnInactive()359     void WebviewControllerImpl::OnInactive()
360     {
361         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
362         if (nweb_ptr) {
363             WEBVIEWLOGD("WebviewControllerImpl::OnInactive start")
364             nweb_ptr->OnPause();
365         }
366     }
367 
GetHitTest()368     int WebviewControllerImpl::GetHitTest()
369     {
370         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
371         if (nweb_ptr) {
372             return ConverToWebHitTestType(nweb_ptr->GetHitTestResult()->GetType());
373         }
374         return static_cast<int>(WebHitTestType::UNKNOWN);
375     }
376 
GetHitTestValue()377     std::shared_ptr<NWeb::HitTestResult> WebviewControllerImpl::GetHitTestValue()
378     {
379         std::shared_ptr<NWeb::HitTestResult> nwebResult;
380         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
381         if (nweb_ptr) {
382             nwebResult = nweb_ptr->GetHitTestResult();
383             if (nwebResult) {
384                 nwebResult->SetType(ConverToWebHitTestType(nwebResult->GetType()));
385             }
386         }
387         return nwebResult;
388     }
389 
ConverToWebHitTestType(int hitType)390     int WebviewControllerImpl::ConverToWebHitTestType(int hitType)
391     {
392         WebHitTestType webHitType;
393         switch (hitType) {
394             case NWeb::HitTestResult::UNKNOWN_TYPE:
395                 webHitType = WebHitTestType::UNKNOWN;
396                 break;
397             case NWeb::HitTestResult::ANCHOR_TYPE:
398                 webHitType = WebHitTestType::HTTP;
399                 break;
400             case NWeb::HitTestResult::PHONE_TYPE:
401                 webHitType = WebHitTestType::PHONE;
402                 break;
403             case NWeb::HitTestResult::GEO_TYPE:
404                 webHitType = WebHitTestType::MAP;
405                 break;
406             case NWeb::HitTestResult::EMAIL_TYPE:
407                 webHitType = WebHitTestType::EMAIL;
408                 break;
409             case NWeb::HitTestResult::IMAGE_TYPE:
410                 webHitType = WebHitTestType::IMG;
411                 break;
412             case NWeb::HitTestResult::IMAGE_ANCHOR_TYPE:
413                 webHitType = WebHitTestType::HTTP_IMG;
414                 break;
415             case NWeb::HitTestResult::SRC_ANCHOR_TYPE:
416                 webHitType = WebHitTestType::HTTP;
417                 break;
418             case NWeb::HitTestResult::SRC_IMAGE_ANCHOR_TYPE:
419                 webHitType = WebHitTestType::HTTP_IMG;
420                 break;
421             case NWeb::HitTestResult::EDIT_TEXT_TYPE:
422                 webHitType = WebHitTestType::EDIT;
423                 break;
424             default:
425                 webHitType = WebHitTestType::UNKNOWN;
426                 break;
427         }
428         return static_cast<int>(webHitType);
429     }
430 
StoreWebArchiveCallback(std::string baseName,bool autoName,const std::function<void (RetDataCString)> & callbackRef)431     void WebviewControllerImpl::StoreWebArchiveCallback(std::string baseName, bool autoName,
432         const std::function<void(RetDataCString)>& callbackRef)
433     {
434         RetDataCString ret = { .code = NWebError::INIT_ERROR, .data = nullptr };
435         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
436         if (!nweb_ptr) {
437             callbackRef(ret);
438             return;
439         }
440         auto callbackImpl = std::make_shared<NWeb::NWebStoreWebArchiveCallback>();
441         callbackImpl->SetCallBack([cjCallback = callbackRef](std::string result) {
442             RetDataCString ret = { .code = NWebError::INVALID_RESOURCE, .data = nullptr };
443             if (result.empty()) {
444                 cjCallback(ret);
445                 return;
446             }
447             ret.code = NWebError::NO_ERROR;
448             ret.data = MallocCString(result);
449             if (ret.data == nullptr) {
450                 ret.code = NWebError::NEW_OOM;
451             }
452             cjCallback(ret);
453         });
454         nweb_ptr->StoreWebArchive(baseName, autoName, callbackImpl);
455         return;
456     }
457 
EnableSafeBrowsing(bool enable)458     void WebviewControllerImpl::EnableSafeBrowsing(bool enable)
459     {
460         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
461         if (nweb_ptr) {
462             nweb_ptr->EnableSafeBrowsing(enable);
463         }
464         return;
465     }
466 
IsSafeBrowsingEnabled()467     bool WebviewControllerImpl::IsSafeBrowsingEnabled()
468     {
469         bool is_safe_browsing_enabled = false;
470         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
471         if (nweb_ptr) {
472             is_safe_browsing_enabled = nweb_ptr->IsSafeBrowsingEnabled();
473         }
474         return is_safe_browsing_enabled;
475     }
476 
GetSecurityLevel()477     int WebviewControllerImpl::GetSecurityLevel()
478     {
479         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
480         if (!nweb_ptr) {
481             return static_cast<int>(SecurityLevel::NONE);
482         }
483 
484         int nwebSecurityLevel = nweb_ptr->GetSecurityLevel();
485         SecurityLevel securityLevel;
486         switch (nwebSecurityLevel) {
487             case static_cast<int>(CoreSecurityLevel::NONE):
488                 securityLevel = SecurityLevel::NONE;
489                 break;
490             case static_cast<int>(CoreSecurityLevel::SECURE):
491                 securityLevel = SecurityLevel::SECURE;
492                 break;
493             case static_cast<int>(CoreSecurityLevel::WARNING):
494                 securityLevel = SecurityLevel::WARNING;
495                 break;
496             case static_cast<int>(CoreSecurityLevel::DANGEROUS):
497                 securityLevel = SecurityLevel::DANGEROUS;
498                 break;
499             default:
500                 securityLevel = SecurityLevel::NONE;
501                 break;
502         }
503 
504         return static_cast<int>(securityLevel);
505     }
506 
IsIncognitoMode()507     bool WebviewControllerImpl::IsIncognitoMode()
508     {
509         bool incognitoMode = false;
510         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
511         if (nweb_ptr) {
512             incognitoMode = nweb_ptr->IsIncognitoMode();
513         }
514         return incognitoMode;
515     }
516 
RemoveCache(bool includeDiskFiles)517     void WebviewControllerImpl::RemoveCache(bool includeDiskFiles)
518     {
519         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
520         if (nweb_ptr) {
521             WEBVIEWLOGD("WebviewControllerImpl::RemoveCache start")
522             nweb_ptr->RemoveCache(includeDiskFiles);
523         }
524     }
525 
GetHistoryList()526     std::shared_ptr<OHOS::NWeb::NWebHistoryList> WebviewControllerImpl::GetHistoryList()
527     {
528         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
529         if (!nweb_ptr) {
530             return nullptr;
531         }
532         return nweb_ptr->GetHistoryList();
533     }
534 
GetListSize()535     int32_t WebHistoryListImpl::GetListSize()
536     {
537         int32_t listSize = 0;
538 
539         if (!sptrHistoryList_) {
540             return listSize;
541         }
542         listSize = sptrHistoryList_->GetListSize();
543         return listSize;
544     }
545 
GetCurrentIndex()546     int32_t WebHistoryListImpl::GetCurrentIndex()
547     {
548         int32_t currentIndex = 0;
549 
550         if (!sptrHistoryList_) {
551             return currentIndex;
552         }
553         currentIndex = sptrHistoryList_->GetCurrentIndex();
554         return currentIndex;
555     }
556 
GetItem(int32_t index)557     std::shared_ptr<OHOS::NWeb::NWebHistoryItem> WebHistoryListImpl::GetItem(int32_t index)
558     {
559         if (!sptrHistoryList_) {
560             return nullptr;
561         }
562         return sptrHistoryList_->GetItem(index);
563     }
564 
SetNWebJavaScriptResultCallBack()565     void WebviewControllerImpl::SetNWebJavaScriptResultCallBack()
566     {
567         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
568         if (!nweb_ptr) {
569             return;
570         }
571         if (javaScriptResultCb_ && (javaScriptResultCb_->GetNWebId() == nwebId_)) {
572             return;
573         }
574 
575         javaScriptResultCb_ = std::make_shared<WebviewJavaScriptResultCallBackImpl>(nwebId_);
576         nweb_ptr->SetNWebJavaScriptResultCallBack(javaScriptResultCb_);
577     }
578 
RegisterJavaScriptProxy(const std::vector<std::function<char * (const char *)>> & cjFuncs,const std::string & objName,const std::vector<std::string> & methodList)579     void WebviewControllerImpl::RegisterJavaScriptProxy(const std::vector<std::function<char*(const char*)>>& cjFuncs,
580         const std::string& objName, const std::vector<std::string>& methodList)
581     {
582         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
583         if (!nweb_ptr) {
584             WEBVIEWLOGE("WebviewControllerImpl::RegisterJavaScriptProxy nweb_ptr is null");
585             return;
586         }
587         JavaScriptOb::ObjectID objId =
588             static_cast<JavaScriptOb::ObjectID>(JavaScriptOb::JavaScriptObjIdErrorCode::WEBCONTROLLERERROR);
589 
590         if (!javaScriptResultCb_) {
591             WEBVIEWLOGE("WebviewControllerImpl::RegisterJavaScriptProxy javaScriptResultCb_ is null");
592             return;
593         }
594 
595         if (methodList.empty()) {
596             WEBVIEWLOGE("WebviewControllerImpl::RegisterJavaScriptProxy methodList is empty");
597             return;
598         }
599 
600         objId = javaScriptResultCb_->RegisterJavaScriptProxy(cjFuncs, objName, methodList);
601 
602         nweb_ptr->RegisterArkJSfunction(objName, methodList, objId);
603     }
604 
Stop()605     void WebviewControllerImpl::Stop()
606     {
607         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
608         if (nweb_ptr) {
609             return nweb_ptr->Stop();
610         }
611         return;
612     }
613 
SetBackForwardCacheOptions(int32_t size,int32_t timeToLive)614     void WebviewControllerImpl::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive)
615     {
616         auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_);
617         if (!nweb_ptr) {
618             WEBVIEWLOGE("WebviewControllerImpl::void SetBackForwardCacheOptions nweb_ptr is null");
619             return;
620         }
621         nweb_ptr->SetBackForwardCacheOptions(size, timeToLive);
622     }
623 }
624