Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions wpeview/src/main/cpp/Runtime/WKWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,44 @@ class JNIWKWebViewCache final : public JNI::TypedClass<JNIWKWebView> {
static_cast<jboolean>(webkit_web_view_can_go_forward(webView)));
}

static void onIsPlayingAudioChanged(WKWebView* wkWebView, GParamSpec* /*pspec*/, WebKitWebView* webView) noexcept
{
Logging::logDebug("WKWebView::onIsPlayingAudioChanged() [tid %d]", gettid());
callJavaMethod(getJNIPageCache().m_onIsPlayingAudioChanged, wkWebView->m_webViewJavaInstance.get(),
static_cast<jboolean>(webkit_web_view_is_playing_audio(webView)));
}

static void onIsMutedChanged(WKWebView* wkWebView, GParamSpec* /*pspec*/, WebKitWebView* webView) noexcept
{
Logging::logDebug("WKWebView::onIsMutedChanged() [tid %d]", gettid());
callJavaMethod(getJNIPageCache().m_onIsMutedChanged, wkWebView->m_webViewJavaInstance.get(),
static_cast<jboolean>(webkit_web_view_get_is_muted(webView)));
}

static void onCameraCaptureStateChanged(
WKWebView* wkWebView, GParamSpec* /*pspec*/, WebKitWebView* webView) noexcept
{
Logging::logDebug("WKWebView::onCameraCaptureStateChanged() [tid %d]", gettid());
callJavaMethod(getJNIPageCache().m_onCameraCaptureStateChanged, wkWebView->m_webViewJavaInstance.get(),
static_cast<jint>(webkit_web_view_get_camera_capture_state(webView)));
}

static void onMicrophoneCaptureStateChanged(
WKWebView* wkWebView, GParamSpec* /*pspec*/, WebKitWebView* webView) noexcept
{
Logging::logDebug("WKWebView::onMicrophoneCaptureStateChanged() [tid %d]", gettid());
callJavaMethod(getJNIPageCache().m_onMicrophoneCaptureStateChanged, wkWebView->m_webViewJavaInstance.get(),
static_cast<jint>(webkit_web_view_get_microphone_capture_state(webView)));
}

static void onDisplayCaptureStateChanged(
WKWebView* wkWebView, GParamSpec* /*pspec*/, WebKitWebView* webView) noexcept
{
Logging::logDebug("WKWebView::onDisplayCaptureStateChanged() [tid %d]", gettid());
callJavaMethod(getJNIPageCache().m_onDisplayCaptureStateChanged, wkWebView->m_webViewJavaInstance.get(),
static_cast<jint>(webkit_web_view_get_display_capture_state(webView)));
}

static gboolean onScriptDialog(WKWebView* wkWebView, WebKitScriptDialog* dialog, WebKitWebView* webView) noexcept
{
auto dialogPtr = reinterpret_cast<jlong>(webkit_script_dialog_ref(dialog));
Expand Down Expand Up @@ -382,6 +420,11 @@ class JNIWKWebViewCache final : public JNI::TypedClass<JNIWKWebView> {
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<void(jboolean)> m_onIsPlayingAudioChanged;
const JNI::Method<void(jboolean)> m_onIsMutedChanged;
const JNI::Method<void(jint)> m_onCameraCaptureStateChanged;
const JNI::Method<void(jint)> m_onMicrophoneCaptureStateChanged;
const JNI::Method<void(jint)> m_onDisplayCaptureStateChanged;
const JNI::Method<jboolean(jlong, jint, jstring, jstring, jstring)> m_onScriptDialog;
const JNI::Method<void()> m_onInputMethodContextIn;
const JNI::Method<void()> m_onInputMethodContextOut;
Expand Down Expand Up @@ -437,6 +480,11 @@ JNIWKWebViewCache::JNIWKWebViewCache()
, m_onEstimatedLoadProgress(getMethod<void(jdouble)>("onEstimatedLoadProgress"))
, m_onUriChanged(getMethod<void(jstring)>("onUriChanged"))
, m_onTitleChanged(getMethod<void(jstring, jboolean, jboolean)>("onTitleChanged"))
, m_onIsPlayingAudioChanged(getMethod<void(jboolean)>("onIsPlayingAudioChanged"))
, m_onIsMutedChanged(getMethod<void(jboolean)>("onIsMutedChanged"))
, m_onCameraCaptureStateChanged(getMethod<void(jint)>("onCameraCaptureStateChanged"))
, m_onMicrophoneCaptureStateChanged(getMethod<void(jint)>("onMicrophoneCaptureStateChanged"))
, m_onDisplayCaptureStateChanged(getMethod<void(jint)>("onDisplayCaptureStateChanged"))
, m_onScriptDialog(getMethod<jboolean(jlong, jint, jstring, jstring, jstring)>("onScriptDialog"))
, m_onInputMethodContextIn(getMethod<void()>("onInputMethodContextIn"))
, m_onInputMethodContextOut(getMethod<void()>("onInputMethodContextOut"))
Expand Down Expand Up @@ -812,6 +860,16 @@ WKWebView::WKWebView(JNIEnv* env, JNIWKWebView jniWKWebView, WKWebContext* wkWeb
g_signal_connect_swapped(m_webView, "notify::uri", G_CALLBACK(JNIWKWebViewCache::onUriChanged), this));
m_signalHandlers.push_back(
g_signal_connect_swapped(m_webView, "notify::title", G_CALLBACK(JNIWKWebViewCache::onTitleChanged), this));
m_signalHandlers.push_back(g_signal_connect_swapped(
m_webView, "notify::is-playing-audio", G_CALLBACK(JNIWKWebViewCache::onIsPlayingAudioChanged), this));
m_signalHandlers.push_back(
g_signal_connect_swapped(m_webView, "notify::is-muted", G_CALLBACK(JNIWKWebViewCache::onIsMutedChanged), this));
m_signalHandlers.push_back(g_signal_connect_swapped(
m_webView, "notify::camera-capture-state", G_CALLBACK(JNIWKWebViewCache::onCameraCaptureStateChanged), this));
m_signalHandlers.push_back(g_signal_connect_swapped(m_webView, "notify::microphone-capture-state",
G_CALLBACK(JNIWKWebViewCache::onMicrophoneCaptureStateChanged), this));
m_signalHandlers.push_back(g_signal_connect_swapped(
m_webView, "notify::display-capture-state", G_CALLBACK(JNIWKWebViewCache::onDisplayCaptureStateChanged), this));
m_signalHandlers.push_back(
g_signal_connect_swapped(m_webView, "script-dialog", G_CALLBACK(JNIWKWebViewCache::onScriptDialog), this));
m_signalHandlers.push_back(
Expand Down
34 changes: 34 additions & 0 deletions wpeview/src/main/java/org/wpewebkit/wpe/WKWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public final class WKWebView {
public static final int WEBKIT_TLS_ERRORS_POLICY_IGNORE = 0;
public static final int WEBKIT_TLS_ERRORS_POLICY_FAIL = 1;

public static final int WEBKIT_MEDIA_CAPTURE_STATE_NONE = 0;
public static final int WEBKIT_MEDIA_CAPTURE_STATE_ACTIVE = 1;
public static final int WEBKIT_MEDIA_CAPTURE_STATE_MUTED = 2;

protected long nativePtr = 0;
public long getNativePtr() { return nativePtr; }

Expand Down Expand Up @@ -496,6 +500,36 @@ private void onTitleChanged(@NonNull String title, boolean canGoBack, boolean ca
wpeChromeClient.onReceivedTitle(wpeView, title);
}

@Keep
private void onIsPlayingAudioChanged(boolean isPlayingAudio) {
if (wpeChromeClient != null)
wpeChromeClient.onAudioStateChanged(wpeView, isPlayingAudio);
}

@Keep
private void onIsMutedChanged(boolean isMuted) {
if (wpeChromeClient != null)
wpeChromeClient.onMutedStateChanged(wpeView, isMuted);
}

@Keep
private void onCameraCaptureStateChanged(int state) {
if (wpeChromeClient != null)
wpeChromeClient.onCameraCaptureStateChanged(wpeView, state);
}

@Keep
private void onMicrophoneCaptureStateChanged(int state) {
if (wpeChromeClient != null)
wpeChromeClient.onMicrophoneCaptureStateChanged(wpeView, state);
}

@Keep
private void onDisplayCaptureStateChanged(int state) {
if (wpeChromeClient != null)
wpeChromeClient.onDisplayCaptureStateChanged(wpeView, state);
}

@SuppressLint("StringFormatInvalid")
@Keep
private boolean onScriptDialog(long nativeDialogPtr, int dialogType, @NonNull String url, @NonNull String message,
Expand Down
56 changes: 56 additions & 0 deletions wpeview/src/main/java/org/wpewebkit/wpeview/WPEChromeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,62 @@ default void onReceivedTitle(@NonNull WPEView view, @NonNull String title) {}
*/
default void onUriChanged(@NonNull WPEView view, @NonNull String uri) {}

/**
* Notify the host application that the audio playback state has changed.
* This is called when the WebView starts or stops playing audio.
* @param view The WPEView that initiated the callback.
* @param isPlayingAudio {@code true} if the WebView is currently playing audio,
* {@code false} otherwise.
*/
default void onAudioStateChanged(@NonNull WPEView view, boolean isPlayingAudio) {}

/**
* Notify the host application that the muted state has changed.
* This is called when the WebView is muted or unmuted.
* @param view The WPEView that initiated the callback.
* @param isMuted {@code true} if the WebView is currently muted,
* {@code false} otherwise.
*/
default void onMutedStateChanged(@NonNull WPEView view, boolean isMuted) {}

/**
* Notify the host application that the camera capture state has changed.
* This is called when a page starts or stops capturing from the camera.
* @param view The WPEView that initiated the callback.
* @param state The capture state. One of:
* <ul>
* <li>{@code 0} - MEDIA_CAPTURE_STATE_NONE: Camera capture is not active.</li>
* <li>{@code 1} - MEDIA_CAPTURE_STATE_ACTIVE: Camera capture is active.</li>
* <li>{@code 2} - MEDIA_CAPTURE_STATE_MUTED: Camera capture is muted.</li>
* </ul>
*/
default void onCameraCaptureStateChanged(@NonNull WPEView view, int state) {}

/**
* Notify the host application that the microphone capture state has changed.
* This is called when a page starts or stops capturing from the microphone.
* @param view The WPEView that initiated the callback.
* @param state The capture state. One of:
* <ul>
* <li>{@code 0} - MEDIA_CAPTURE_STATE_NONE: Camera capture is not active.</li>
* <li>{@code 1} - MEDIA_CAPTURE_STATE_ACTIVE: Camera capture is active.</li>
* <li>{@code 2} - MEDIA_CAPTURE_STATE_MUTED: Camera capture is muted.</li>
* </ul>
*/
default void onMicrophoneCaptureStateChanged(@NonNull WPEView view, int state) {}

/**
* Notify the host application that the display capture state has changed.
* This is called when a page starts or stops screen sharing.
* @param state The capture state. One of:
* <ul>
* <li>{@code 0} - MEDIA_CAPTURE_STATE_NONE: Camera capture is not active.</li>
* <li>{@code 1} - MEDIA_CAPTURE_STATE_ACTIVE: Camera capture is active.</li>
* <li>{@code 2} - MEDIA_CAPTURE_STATE_MUTED: Camera capture is muted.</li>
* </ul>
*/
default void onDisplayCaptureStateChanged(@NonNull WPEView view, int state) {}

/**
* A callback interface used by the host application to notify
* the current page that its custom view has been dismissed.
Expand Down