28#include "IPlugWebView.h"
30#include <emscripten.h>
31#include <emscripten/bind.h>
44 void* OpenWebView(
void* pParent,
float x,
float y,
float w,
float h,
float scale);
46 void HideWebView(
bool hide);
47 void LoadHTML(
const char* html);
48 void LoadURL(
const char* url);
49 void LoadFile(
const char* fileName,
const char* bundleID);
50 void ReloadPageContent();
51 void EvaluateJavaScript(
const char* scriptStr, IWebView::completionHandlerFunc func);
52 void EnableScroll(
bool enable);
53 void EnableInteraction(
bool enable);
54 void SetWebViewBounds(
float x,
float y,
float w,
float h,
float scale);
55 void GetWebRoot(WDL_String& path)
const { path.Set(mWebRoot.Get()); }
56 void GetLocalDownloadPathForFile(
const char* fileName, WDL_String& localPath);
70uintptr_t OwnerPtr(
IWebView* pWebView)
72 return reinterpret_cast<uintptr_t
>(pWebView);
75void OnMessageFromWebView(uintptr_t ownerPtr,
const std::string& json)
77 if (
auto* pWebView =
reinterpret_cast<IWebView*
>(ownerPtr))
79 pWebView->OnMessageFromWebView(json.c_str());
83void OnWebContentLoaded(uintptr_t ownerPtr)
85 if (
auto* pWebView =
reinterpret_cast<IWebView*
>(ownerPtr))
87 pWebView->OnWebContentLoaded();
92IWebViewImpl::IWebViewImpl(
IWebView* owner)
98IWebViewImpl::~IWebViewImpl()
103void* IWebViewImpl::OpenWebView(
void* pParent,
float x,
float y,
float w,
float h,
float scale)
109 if (typeof window.__iPlugWebViewOpen ===
'function') {
110 window.__iPlugWebViewOpen($0, $1, $2, $3, $4, $5);
112 }, OwnerPtr(mIWebView), x, y, w, h, scale);
115 return reinterpret_cast<void*
>(mIWebView);
118void IWebViewImpl::CloseWebView()
124 if (typeof window.__iPlugWebViewClose ===
'function') {
125 window.__iPlugWebViewClose($0);
127 }, OwnerPtr(mIWebView));
132void IWebViewImpl::HideWebView(
bool hide)
135 if (typeof window.__iPlugWebViewHide ===
'function') {
136 window.__iPlugWebViewHide($0, !!$1);
138 }, OwnerPtr(mIWebView), hide);
141void IWebViewImpl::LoadHTML(
const char* html)
144 if (typeof window.__iPlugWebViewLoadHTML ===
'function') {
145 window.__iPlugWebViewLoadHTML($0, UTF8ToString($1));
147 }, OwnerPtr(mIWebView), html ? html :
"");
150void IWebViewImpl::LoadURL(
const char* url)
153 if (typeof window.__iPlugWebViewLoadURL ===
'function') {
154 window.__iPlugWebViewLoadURL($0, UTF8ToString($1));
156 }, OwnerPtr(mIWebView), url ? url :
"");
159void IWebViewImpl::LoadFile(
const char* fileName,
const char* bundleID)
164 if (fileName && fileName[0] !=
'\0')
166 WDL_String requestedFile(fileName);
167 filePart.Set(requestedFile.get_filepart());
170 if (filePart.GetLength() == 0)
172 filePart.Set(
"index.html");
178 webFile.SetFormatted(1024,
"web/%s", filePart.Get());
181 if (typeof window.__iPlugWebViewLoadFile ===
'function') {
182 window.__iPlugWebViewLoadFile($0, UTF8ToString($1), UTF8ToString($2));
184 }, OwnerPtr(mIWebView), webFile.Get(), mWebRoot.Get());
187void IWebViewImpl::ReloadPageContent()
190 if (typeof window.__iPlugWebViewReload ===
'function') {
191 window.__iPlugWebViewReload($0);
193 }, OwnerPtr(mIWebView));
196void IWebViewImpl::EvaluateJavaScript(
const char* scriptStr, IWebView::completionHandlerFunc func)
199 if (typeof window.__iPlugWebViewEvaluate ===
'function') {
200 window.__iPlugWebViewEvaluate($0, UTF8ToString($1));
202 }, OwnerPtr(mIWebView), scriptStr ? scriptStr :
"");
210void IWebViewImpl::EnableScroll(
bool enable)
213 if (typeof window.__iPlugWebViewEnableScroll ===
'function') {
214 window.__iPlugWebViewEnableScroll($0, !!$1);
216 }, OwnerPtr(mIWebView), enable);
219void IWebViewImpl::EnableInteraction(
bool enable)
222 if (typeof window.__iPlugWebViewEnableInteraction ===
'function') {
223 window.__iPlugWebViewEnableInteraction($0, !!$1);
225 }, OwnerPtr(mIWebView), enable);
228void IWebViewImpl::SetWebViewBounds(
float x,
float y,
float w,
float h,
float scale)
231 if (typeof window.__iPlugWebViewSetBounds ===
'function') {
232 window.__iPlugWebViewSetBounds($0, $1, $2, $3, $4, $5);
234 }, OwnerPtr(mIWebView), x, y, w, h, scale);
237void IWebViewImpl::GetLocalDownloadPathForFile(
const char* fileName, WDL_String& localPath)
239 localPath.Set(fileName ? fileName :
"");
242EMSCRIPTEN_BINDINGS(IPlugWebViewWeb) {
243 emscripten::function(
"IPlugWebView_OnMessage", &OnMessageFromWebView);
244 emscripten::function(
"IPlugWebView_OnContentLoaded", &OnWebContentLoaded);
247#include "IPlugWebView.cpp"
IWebView is a base interface for hosting a platform web view inside an IPlug plug-in's UI.
virtual void OnWebViewReady()
Called when the web view is ready to receive navigation instructions.