summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@theqtcompany.com>2015-12-14 14:54:39 +0100
committerAlexandru Croitor <alexandru.croitor@theqtcompany.com>2015-12-15 17:03:10 +0000
commit26aa7e314e58ea7be375fc767f6806127e50338d (patch)
treef1575597351effd890379420fca63f04100d8e87 /src/core
parent6414f93b39c57b2718a622430f7e0329b3512c8b (diff)
Add support for checking if audio is played in a page.
Add support for checking if audio is played in a page, as well as the ability to (un)mute the audio. Modify demobrowser example to show (muted) in the tab title, if the tab is muted, or (audible) if there is audio playing in the tab. Fix HTML5 audio/video (un)mute to also work. Change-Id: I7213645e67be2f9da1c5f96cdf6c7eef5341ae4b Task-number: QTBUG-48788 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/web_contents_adapter.cpp18
-rw-r--r--src/core/web_contents_adapter.h3
-rw-r--r--src/core/web_contents_adapter_client.h1
-rw-r--r--src/core/web_contents_delegate_qt.cpp9
4 files changed, 31 insertions, 0 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 543ad24cb..923bb1e2d 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -795,6 +795,24 @@ void WebContentsAdapter::download(const QUrl &url, const QString &suggestedFileN
dlm->DownloadUrl(params.Pass());
}
+bool WebContentsAdapter::isAudioMuted() const
+{
+ const Q_D(WebContentsAdapter);
+ return d->webContents->IsAudioMuted();
+}
+
+void WebContentsAdapter::setAudioMuted(bool muted)
+{
+ Q_D(WebContentsAdapter);
+ d->webContents->SetAudioMuted(muted);
+}
+
+bool WebContentsAdapter::wasRecentlyAudible()
+{
+ Q_D(WebContentsAdapter);
+ return d->webContents->WasRecentlyAudible();
+}
+
void WebContentsAdapter::copyImageAt(const QPoint &location)
{
Q_D(WebContentsAdapter);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index df9cbb266..01da38894 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -114,6 +114,9 @@ public:
void stopFinding();
void updateWebPreferences(const content::WebPreferences &webPreferences);
void download(const QUrl &url, const QString &suggestedFileName);
+ bool isAudioMuted() const;
+ void setAudioMuted(bool mute);
+ bool wasRecentlyAudible();
// Must match blink::WebMediaPlayerAction::Type.
enum MediaPlayerAction {
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index cbe5a687a..92d5aa093 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -198,6 +198,7 @@ public:
virtual void loadProgressChanged(int progress) = 0;
virtual void didUpdateTargetURL(const QUrl&) = 0;
virtual void selectionChanged() = 0;
+ virtual void wasRecentlyAudibleChanged(bool wasRecentlyAudible) = 0;
virtual QRectF viewportRect() const = 0;
virtual qreal dpiScale() const = 0;
virtual QColor backgroundColor() const = 0;
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index f1c9a7f34..c8e8da713 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -122,6 +122,15 @@ void WebContentsDelegateQt::NavigationStateChanged(content::WebContents* source,
m_viewClient->urlChanged(toQt(source->GetVisibleURL()));
if (changed_flags & content::INVALIDATE_TYPE_TITLE)
m_viewClient->titleChanged(toQt(source->GetTitle()));
+
+ // NavigationStateChanged gets called with INVALIDATE_TYPE_TAB by AudioStateProvider::Notify,
+ // whenever an audio sound gets played or stopped, this is the only way to actually figure out
+ // if there was a recently played audio sound.
+ // Make sure to only emit the signal when loading isn't in progress, because it causes multiple
+ // false signals to be emitted.
+ if ((changed_flags & content::INVALIDATE_TYPE_TAB) && !(changed_flags & content::INVALIDATE_TYPE_LOAD)) {
+ m_viewClient->wasRecentlyAudibleChanged(source->WasRecentlyAudible());
+ }
}
void WebContentsDelegateQt::AddNewContents(content::WebContents* source, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture, bool* was_blocked)