Skip to content

Commit c15ad03

Browse files
[GTK] Implement webkit_web_view_is_playing_audio()
https://bugs.webkit.org/show_bug.cgi?id=138918 Patch by Adrian Perez de Castro <[email protected]> on 2014-12-18 Reviewed by Carlos Garcia Campos. Source/WebKit2: Implements webkit_web_view_is_playing_audio(), and overrides UIClient::isPlayingAudioDidChange() to be able to emit change notification signals for the new WebKitWebView::is-playing-audio property. * UIProcess/API/gtk/WebKitUIClient.cpp: (isPlayingAudioDidChange): Added. * UIProcess/API/gtk/WebKitWebView.cpp: (webkitWebViewIsPlayingAudioChanged): Helper function to emit the emit the notify::is-playing-audio signal when needed. (webkitWebViewGetProperty): Handle the WebKitWebView::is-playing-audio property. (webkit_web_view_class_init): Install the WebKitWebView::is-playing-audio property. (webkit_web_view_is_playing_audio): Added. * UIProcess/API/gtk/WebKitWebView.h: * UIProcess/API/gtk/WebKitWebViewPrivate.h: * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add webkit_web_view_is_playing_audio() to the list of public API functions. Tools: Add test case case for webkit_web_view_is_playing_audio() and the WebKitWebView::is-playing-audio property. * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp: (urlForResource): Utility function to get URLs pointing to resources under the Tools/TestWebKitAPI/Tests/WebKit2/ directory. (testWebViewIsPlayingAudio): Added. (beforeAll): * TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h: (getResourcesDir): Allow passing a flag to choose from the WebKit2 GTK API tests resources directory, or the WebKit2 C API tests resources directory. The default value of the flag is to use the WebKit2 GTK one, to avoid having to change existing tests. * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp: (isPlayingAudioChanged): Added. (WebViewTest::waitUntilIsPlayingAudioChanged): Added. * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@177496 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent badb154 commit c15ad03

File tree

9 files changed

+174
-4
lines changed

9 files changed

+174
-4
lines changed

Source/WebKit2/ChangeLog

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
2014-12-18 Adrian Perez de Castro <[email protected]>
2+
3+
[GTK] Implement webkit_web_view_is_playing_audio()
4+
https://bugs.webkit.org/show_bug.cgi?id=138918
5+
6+
Reviewed by Carlos Garcia Campos.
7+
8+
Implements webkit_web_view_is_playing_audio(), and overrides
9+
UIClient::isPlayingAudioDidChange() to be able to emit change
10+
notification signals for the new WebKitWebView::is-playing-audio
11+
property.
12+
13+
* UIProcess/API/gtk/WebKitUIClient.cpp:
14+
(isPlayingAudioDidChange): Added.
15+
* UIProcess/API/gtk/WebKitWebView.cpp:
16+
(webkitWebViewIsPlayingAudioChanged): Helper function to emit the
17+
emit the notify::is-playing-audio signal when needed.
18+
(webkitWebViewGetProperty): Handle the WebKitWebView::is-playing-audio
19+
property.
20+
(webkit_web_view_class_init): Install the
21+
WebKitWebView::is-playing-audio property.
22+
(webkit_web_view_is_playing_audio): Added.
23+
* UIProcess/API/gtk/WebKitWebView.h:
24+
* UIProcess/API/gtk/WebKitWebViewPrivate.h:
25+
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add
26+
webkit_web_view_is_playing_audio() to the list of public API
27+
functions.
28+
129
2014-12-18 Carlos Garcia Campos <[email protected]>
230

331
[GTK] Allow to build with ENABLE_NETWORK_CACHE

Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ class UIClient : public API::UIClient {
186186
webkitWebViewRunAsModal(m_webView);
187187
}
188188

189+
virtual void isPlayingAudioDidChange(WebPageProxy& page) override
190+
{
191+
webkitWebViewIsPlayingAudioChanged(m_webView);
192+
}
193+
189194
WebKitWebView* m_webView;
190195
};
191196

Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

+51-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ enum {
148148
PROP_FAVICON,
149149
PROP_URI,
150150
PROP_ZOOM_LEVEL,
151-
PROP_IS_LOADING
151+
PROP_IS_LOADING,
152+
PROP_IS_PLAYING_AUDIO
152153
};
153154

154155
typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap;
@@ -230,6 +231,11 @@ static void webkitWebViewSetIsLoading(WebKitWebView* webView, bool isLoading)
230231
g_object_notify(G_OBJECT(webView), "is-loading");
231232
}
232233

234+
void webkitWebViewIsPlayingAudioChanged(WebKitWebView* webView)
235+
{
236+
g_object_notify(G_OBJECT(webView), "is-playing-audio");
237+
}
238+
233239
class PageLoadStateObserver final : public PageLoadState::Observer {
234240
public:
235241
PageLoadStateObserver(WebKitWebView* webView)
@@ -721,6 +727,9 @@ static void webkitWebViewGetProperty(GObject* object, guint propId, GValue* valu
721727
case PROP_IS_LOADING:
722728
g_value_set_boolean(value, webkit_web_view_is_loading(webView));
723729
break;
730+
case PROP_IS_PLAYING_AUDIO:
731+
g_value_set_boolean(value, webkit_web_view_is_playing_audio(webView));
732+
break;
724733
default:
725734
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
726735
}
@@ -931,6 +940,26 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
931940
FALSE,
932941
WEBKIT_PARAM_READABLE));
933942

943+
/**
944+
* WebKitWebView::is-playing-audio:
945+
*
946+
* Whether the #WebKitWebView is currently playing audio from a page.
947+
* This property becomes %TRUE as soon as web content starts playing any
948+
* kind of audio. When a page is no longer playing any kind of sound,
949+
* the property is set back to %FALSE.
950+
*
951+
* Since: 2.8
952+
*/
953+
g_object_class_install_property(
954+
gObjectClass,
955+
PROP_IS_PLAYING_AUDIO,
956+
g_param_spec_boolean(
957+
"is-playing-audio",
958+
"Is Playing Audio",
959+
_("Whether the view is playing audio"),
960+
FALSE,
961+
WEBKIT_PARAM_READABLE));
962+
934963
/**
935964
* WebKitWebView::load-changed:
936965
* @web_view: the #WebKitWebView on which the signal is emitted
@@ -2453,6 +2482,27 @@ gboolean webkit_web_view_is_loading(WebKitWebView* webView)
24532482
return webView->priv->isLoading;
24542483
}
24552484

2485+
/**
2486+
* webkit_web_view_is_playing_audio:
2487+
* @web_view: a #WebKitWebView
2488+
*
2489+
* Gets the value of the #WebKitWebView::is-playing-audio property.
2490+
* You can monitor when a page in a #WebKitWebView is playing audio by
2491+
* connecting to the notify::is-playing-audio signal of @web_view. This
2492+
* is useful when the application wants to provide visual feedback when a
2493+
* page is producing sound.
2494+
*
2495+
* Returns: %TRUE if a page in @web_view is playing audio or %FALSE otherwise.
2496+
*
2497+
* Since: 2.8
2498+
*/
2499+
gboolean webkit_web_view_is_playing_audio(WebKitWebView* webView)
2500+
{
2501+
g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2502+
2503+
return getPage(webView)->isPlayingAudio();
2504+
}
2505+
24562506
/**
24572507
* webkit_web_view_go_back:
24582508
* @web_view: a #WebKitWebView

Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

+3
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ webkit_web_view_stop_loading (WebKitWebView
305305
WEBKIT_API gboolean
306306
webkit_web_view_is_loading (WebKitWebView *web_view);
307307

308+
WEBKIT_API gboolean
309+
webkit_web_view_is_playing_audio (WebKitWebView *web_view);
310+
308311
WEBKIT_API guint64
309312
webkit_web_view_get_page_id (WebKitWebView *web_view);
310313

Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h

+1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ void webkitWebViewInsecureContentDetected(WebKitWebView*, WebKitInsecureContentE
6060
bool webkitWebViewEmitShowNotification(WebKitWebView*, WebKitNotification*);
6161
void webkitWebViewEmitCloseNotification(WebKitWebView*, WebKitNotification*);
6262
void webkitWebViewWebProcessCrashed(WebKitWebView*);
63+
void webkitWebViewIsPlayingAudioChanged(WebKitWebView*);
6364

6465
#endif // WebKitWebViewPrivate_h

Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ webkit_web_view_reload
167167
webkit_web_view_reload_bypass_cache
168168
webkit_web_view_stop_loading
169169
webkit_web_view_is_loading
170+
webkit_web_view_is_playing_audio
170171
webkit_web_view_get_estimated_load_progress
171172
webkit_web_view_get_custom_charset
172173
webkit_web_view_set_custom_charset

Tools/ChangeLog

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
2014-12-18 Adrian Perez de Castro <[email protected]>
2+
3+
[GTK] Implement webkit_web_view_is_playing_audio()
4+
https://bugs.webkit.org/show_bug.cgi?id=138918
5+
6+
Reviewed by Carlos Garcia Campos.
7+
8+
Add test case case for webkit_web_view_is_playing_audio() and the
9+
WebKitWebView::is-playing-audio property.
10+
11+
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
12+
(urlForResource): Utility function to get URLs pointing to resources
13+
under the Tools/TestWebKitAPI/Tests/WebKit2/ directory.
14+
(testWebViewIsPlayingAudio): Added.
15+
(beforeAll):
16+
* TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h:
17+
(getResourcesDir): Allow passing a flag to choose from the WebKit2 GTK
18+
API tests resources directory, or the WebKit2 C API tests resources
19+
directory. The default value of the flag is to use the WebKit2 GTK
20+
one, to avoid having to change existing tests.
21+
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
22+
(isPlayingAudioChanged): Added.
23+
(WebViewTest::waitUntilIsPlayingAudioChanged): Added.
24+
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h:
25+
126
2014-12-18 Carlos Alberto Lopez Perez <[email protected]>
227

328
[GTK] [EFL] Enable per_test_timeout

Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
#include <glib/gstdio.h>
2727
#include <wtf/gobject/GRefPtr.h>
2828

29+
class IsPlayingAudioWebViewTest : public WebViewTest {
30+
public:
31+
MAKE_GLIB_TEST_FIXTURE(IsPlayingAudioWebViewTest);
32+
33+
static void isPlayingAudioChanged(GObject*, GParamSpec*, IsPlayingAudioWebViewTest* test)
34+
{
35+
g_signal_handlers_disconnect_by_func(test->m_webView, reinterpret_cast<void*>(isPlayingAudioChanged), test);
36+
g_main_loop_quit(test->m_mainLoop);
37+
}
38+
39+
void waitUntilIsPlayingAudioChanged()
40+
{
41+
g_signal_connect(m_webView, "notify::is-playing-audio", G_CALLBACK(isPlayingAudioChanged), this);
42+
g_main_loop_run(m_mainLoop);
43+
}
44+
};
45+
2946
static WebKitTestServer* gServer;
3047

3148
static void testWebViewWebContext(WebViewTest* test, gconstpointer)
@@ -702,6 +719,31 @@ static void testWebViewNotification(NotificationWebViewTest* test, gconstpointer
702719
g_assert(test->m_event == NotificationWebViewTest::Cancelled);
703720
}
704721

722+
static void testWebViewIsPlayingAudio(IsPlayingAudioWebViewTest* test, gconstpointer)
723+
{
724+
// The web view must be realized for the video to start playback and
725+
// trigger changes in WebKitWebView::is-playing-audio.
726+
test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL);
727+
728+
// Initially, web views should always report no audio being played.
729+
g_assert(!webkit_web_view_is_playing_audio(test->m_webView));
730+
731+
GUniquePtr<char> resourcePath(g_build_filename(Test::getResourcesDir(Test::WebKit2Resources).data(), "file-with-video.html", nullptr));
732+
GUniquePtr<char> resourceURL(g_filename_to_uri(resourcePath.get(), nullptr, nullptr));
733+
webkit_web_view_load_uri(test->m_webView, resourceURL.get());
734+
test->waitUntilLoadFinished();
735+
g_assert(!webkit_web_view_is_playing_audio(test->m_webView));
736+
737+
webkit_web_view_run_javascript(test->m_webView, "playVideo();", nullptr, nullptr, nullptr);
738+
test->waitUntilIsPlayingAudioChanged();
739+
g_assert(webkit_web_view_is_playing_audio(test->m_webView));
740+
741+
// Pause the video, and check again.
742+
webkit_web_view_run_javascript(test->m_webView, "document.getElementById('test-video').pause();", nullptr, nullptr, nullptr);
743+
test->waitUntilIsPlayingAudioChanged();
744+
g_assert(!webkit_web_view_is_playing_audio(test->m_webView));
745+
}
746+
705747
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
706748
{
707749
if (message->method != SOUP_METHOD_GET) {
@@ -733,6 +775,7 @@ void beforeAll()
733775
SnapshotWebViewTest::add("WebKitWebView", "snapshot", testWebViewSnapshot);
734776
WebViewTest::add("WebKitWebView", "page-visibility", testWebViewPageVisibility);
735777
NotificationWebViewTest::add("WebKitWebView", "notification", testWebViewNotification);
778+
IsPlayingAudioWebViewTest::add("WebKitWebView", "is-playing-audio", testWebViewIsPlayingAudio);
736779
}
737780

738781
void afterAll()

Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h

+17-3
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,24 @@ class Test {
107107
g_object_weak_ref(object, reinterpret_cast<GWeakNotify>(objectFinalized), this);
108108
}
109109

110-
static CString getResourcesDir()
110+
111+
enum ResourcesDir {
112+
WebKit2GTKResources,
113+
WebKit2Resources,
114+
};
115+
116+
static CString getResourcesDir(ResourcesDir resourcesDir = WebKit2GTKResources)
111117
{
112-
GUniquePtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Tools", "TestWebKitAPI", "Tests", "WebKit2Gtk", "resources", nullptr));
113-
return resourcesDir.get();
118+
switch (resourcesDir) {
119+
case WebKit2GTKResources: {
120+
GUniquePtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Tools", "TestWebKitAPI", "Tests", "WebKit2Gtk", "resources", nullptr));
121+
return resourcesDir.get();
122+
}
123+
case WebKit2Resources: {
124+
GUniquePtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Tools", "TestWebKitAPI", "Tests", "WebKit2", nullptr));
125+
return resourcesDir.get();
126+
}
127+
}
114128
}
115129

116130
void addLogFatalFlag(unsigned flag)

0 commit comments

Comments
 (0)