Skip to content

Commit

Permalink
[wpe] Refactor WPEView to contain only public API
Browse files Browse the repository at this point in the history
Removed all public internal methods from WPEView and  moved
them to WKWebView. Now WPEView contains public API only.
  • Loading branch information
Jani Hautakangas committed Sep 6, 2024
1 parent 8715631 commit 48d60e2
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.wpewebkit.wpeview.WPEView
import org.wpewebkit.wpeview.WPEViewClient


const val INITIAL_URL = "https://igalia.com"
const val INITIAL_URL = "https://davidwalsh.name/demo/fullscreen.php"///"https://igalia.com"
const val SEARCH_URI_BASE = "https://duckduckgo.com/?q="

class BrowserFragment : Fragment(R.layout.fragment_browser) {
Expand Down Expand Up @@ -163,20 +163,6 @@ class BrowserFragment : Fragment(R.layout.fragment_browser) {
}
}
}

if (selectedTab.webview.wpeViewClient == null) {
selectedTab.webview.wpeViewClient = object : WPEViewClient {
override fun onPageStarted(view: WPEView, url: String) {
// DO nothing for now
super.onPageStarted(view, url)
}

override fun onPageFinished(view: WPEView, url: String) {
// DO nothing for now
super.onPageFinished(view, url)
}
}
}
}

override fun onStart() {
Expand Down
24 changes: 18 additions & 6 deletions wpe/src/main/cpp/Runtime/WKWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class JNIWKWebViewCache final : public JNI::TypedClass<JNIWKWebView> {
getJNIPageCache().m_onLoadChanged, wkWebView->m_webViewJavaInstance.get(), static_cast<int>(loadEvent));
}

static void onLoadProgress(WKWebView* wkWebView, GParamSpec* /*pspec*/, WebKitWebView* webView) noexcept
static void onEstimatedLoadProgress(WKWebView* wkWebView, GParamSpec* /*pspec*/, WebKitWebView* webView) noexcept
{
Logging::logDebug("WKWebView::onLoadProgress() [tid %d]", gettid());
callJavaMethod(getJNIPageCache().m_onLoadProgress, wkWebView->m_webViewJavaInstance.get(),
Logging::logDebug("WKWebView::onEstimatedLoadProgress() [tid %d]", gettid());
callJavaMethod(getJNIPageCache().m_onEstimatedLoadProgress, wkWebView->m_webViewJavaInstance.get(),
static_cast<jdouble>(webkit_web_view_get_estimated_load_progress(webView)));
}

Expand Down Expand Up @@ -226,7 +226,7 @@ class JNIWKWebViewCache final : public JNI::TypedClass<JNIWKWebView> {
// NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members)
const JNI::Method<void()> m_onClose;
const JNI::Method<void(jint)> m_onLoadChanged;
const JNI::Method<void(jdouble)> m_onLoadProgress;
const JNI::Method<void(jdouble)> m_onEstimatedLoadProgress;
const JNI::Method<void(jstring)> m_onUriChanged;
const JNI::Method<void(jstring, jboolean, jboolean)> m_onTitleChanged;
const JNI::Method<jboolean(jlong, jint, jstring, jstring, jstring)> m_onScriptDialog;
Expand All @@ -243,6 +243,7 @@ class JNIWKWebViewCache final : public JNI::TypedClass<JNIWKWebView> {
static void nativeDestroy(JNIEnv* env, jobject obj, jlong wkWebViewPtr) noexcept;
static void nativeLoadUrl(JNIEnv* env, jobject obj, jlong wkWebViewPtr, jstring url) noexcept;
static void nativeLoadHtml(JNIEnv* env, jobject obj, jlong wkWebViewPtr, jstring content, jstring baseUri) noexcept;
static jdouble nativeGetEstimatedLoadProgress(JNIEnv* env, jobject obj, jlong wkWebViewPtr) noexcept;
static void nativeGoBack(JNIEnv* env, jobject obj, jlong wkWebViewPtr) noexcept;
static void nativeGoForward(JNIEnv* env, jobject obj, jlong wkWebViewPtr) noexcept;
static void nativeStopLoading(JNIEnv* env, jobject obj, jlong wkWebViewPtr) noexcept;
Expand Down Expand Up @@ -275,7 +276,7 @@ JNIWKWebViewCache::JNIWKWebViewCache()
: JNI::TypedClass<JNIWKWebView>(true)
, m_onClose(getMethod<void()>("onClose"))
, m_onLoadChanged(getMethod<void(jint)>("onLoadChanged"))
, m_onLoadProgress(getMethod<void(jdouble)>("onLoadProgress"))
, m_onEstimatedLoadProgress(getMethod<void(jdouble)>("onEstimatedLoadProgress"))
, m_onUriChanged(getMethod<void(jstring)>("onUriChanged"))
, m_onTitleChanged(getMethod<void(jstring, jboolean, jboolean)>("onTitleChanged"))
, m_onScriptDialog(getMethod<jboolean(jlong, jint, jstring, jstring, jstring)>("onScriptDialog"))
Expand All @@ -292,6 +293,8 @@ JNIWKWebViewCache::JNIWKWebViewCache()
JNI::NativeMethod<void(jlong)>("nativeDestroy", JNIWKWebViewCache::nativeDestroy),
JNI::NativeMethod<void(jlong, jstring)>("nativeLoadUrl", JNIWKWebViewCache::nativeLoadUrl),
JNI::NativeMethod<void(jlong, jstring, jstring)>("nativeLoadHtml", JNIWKWebViewCache::nativeLoadHtml),
JNI::NativeMethod<jdouble(jlong)>(
"nativeGetEstimatedLoadProgress", JNIWKWebViewCache::nativeGetEstimatedLoadProgress),
JNI::NativeMethod<void(jlong)>("nativeGoBack", JNIWKWebViewCache::nativeGoBack),
JNI::NativeMethod<void(jlong)>("nativeGoForward", JNIWKWebViewCache::nativeGoForward),
JNI::NativeMethod<void(jlong)>("nativeStopLoading", JNIWKWebViewCache::nativeStopLoading),
Expand Down Expand Up @@ -363,6 +366,15 @@ void JNIWKWebViewCache::nativeLoadHtml(
}
}

jdouble JNIWKWebViewCache::nativeGetEstimatedLoadProgress(JNIEnv* /*env*/, jobject /*obj*/, jlong wkWebViewPtr) noexcept
{
auto* wkWebView = reinterpret_cast<WKWebView*>(wkWebViewPtr); // NOLINT(performance-no-int-to-ptr)
if ((wkWebView != nullptr) && (wkWebView->m_webView != nullptr)) {
return webkit_web_view_get_estimated_load_progress(wkWebView->m_webView);
}
return 0;
}

void JNIWKWebViewCache::nativeGoBack(JNIEnv* /*env*/, jobject /*obj*/, jlong wkWebViewPtr) noexcept
{
Logging::logDebug("WKWebView::nativeGoBack() [tid %d]", gettid());
Expand Down Expand Up @@ -584,7 +596,7 @@ WKWebView::WKWebView(JNIEnv* env, JNIWKWebView jniWKWebView, WKWebContext* wkWeb
m_signalHandlers.push_back(
g_signal_connect_swapped(m_webView, "load-changed", G_CALLBACK(JNIWKWebViewCache::onLoadChanged), this));
m_signalHandlers.push_back(g_signal_connect_swapped(
m_webView, "notify::estimated-load-progress", G_CALLBACK(JNIWKWebViewCache::onLoadProgress), this));
m_webView, "notify::estimated-load-progress", G_CALLBACK(JNIWKWebViewCache::onEstimatedLoadProgress), this));
m_signalHandlers.push_back(
g_signal_connect_swapped(m_webView, "notify::uri", G_CALLBACK(JNIWKWebViewCache::onUriChanged), this));
m_signalHandlers.push_back(
Expand Down
Loading

0 comments on commit 48d60e2

Please sign in to comment.