Figure out whether a plug-in is playing audio.
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Nov 2014 07:21:54 +0000 (07:21 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Nov 2014 07:21:54 +0000 (07:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137219

Reviewed by Anders Carlsson.

Source/WebCore:

Add NPPVpluginIsPlayingAudio. Export some WebCore methods that will be used in WebKit2.

No new tests, but manually tested with an example plugin.

* WebCore.exp.in:
* plugins/npapi.h:

Source/WebKit2:

Handle the setting of the NPPVpluginIsPlayingAudio variable.

* PluginProcess/PluginControllerProxy.cpp:
(WebKit::PluginControllerProxy::setPluginIsPlayingAudio):
Send a SetPluginIsPlayingAudio message to the WebProcess.
* PluginProcess/PluginControllerProxy.h:
* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::NPN_SetValue):
Handle NPPVpluginIsPlayingAudio. Call NetscapePlugin::setIsPlayingAudio().
* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::setIsPlayingAudio):
Call PluginControllerProxy::setPluginIsPlayingAudio().
* WebProcess/Plugins/Netscape/NetscapePlugin.h:
* WebProcess/Plugins/PluginController.h:
* WebProcess/Plugins/PluginProxy.cpp:
(WebKit::PluginProxy::setPluginIsPlayingAudio):
Call PluginView::setPluginIsPlayingAudio().
* WebProcess/Plugins/PluginProxy.h:
* WebProcess/Plugins/PluginProxy.messages.in:
Add the SetPluginIsPlayingAudio message.
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::PluginView):
Initialize m_pluginIsPlayingAudio.
(WebKit::PluginView::~PluginView):
Remove itself from the Document's list of AudioProducers.
(WebKit::PluginView::initializePlugin):
Add itself to the Document's list of AudioProducers.
(WebKit::PluginView::pageMutedStateDidChange):
Add a FIXME.
(WebKit::PluginView::setPluginIsPlayingAudio):
If m_pluginIsPlayingAudio has changed, tell the Document to update its audio playing state.
* WebProcess/Plugins/PluginView.h:
Now inherits AudioProducer.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175686 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/plugins/npapi.h
Source/WebKit2/ChangeLog
Source/WebKit2/PluginProcess/PluginControllerProxy.cpp
Source/WebKit2/PluginProcess/PluginControllerProxy.h
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
Source/WebKit2/WebProcess/Plugins/PluginController.h
Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp
Source/WebKit2/WebProcess/Plugins/PluginProxy.h
Source/WebKit2/WebProcess/Plugins/PluginProxy.messages.in
Source/WebKit2/WebProcess/Plugins/PluginView.cpp
Source/WebKit2/WebProcess/Plugins/PluginView.h

index 100b533..fa27451 100644 (file)
@@ -1,3 +1,17 @@
+2014-11-04  Ada Chan  <adachan@apple.com>
+
+        Figure out whether a plug-in is playing audio.
+        https://bugs.webkit.org/show_bug.cgi?id=137219
+
+        Reviewed by Anders Carlsson.
+
+        Add NPPVpluginIsPlayingAudio. Export some WebCore methods that will be used in WebKit2.
+
+        No new tests, but manually tested with an example plugin.
+
+        * WebCore.exp.in:
+        * plugins/npapi.h:
+
 2014-11-05  Simon Fraser  <simon.fraser@apple.com>
 
         Fix crash introduced in r175656
index b73ebaf..68fc3b9 100644 (file)
@@ -1323,12 +1323,15 @@ __ZN7WebCore8Document12updateLayoutEv
 __ZN7WebCore8Document13createElementERKNS_13QualifiedNameEb
 __ZN7WebCore8Document13svgExtensionsEv
 __ZN7WebCore8Document14createTextNodeERKN3WTF6StringE
+__ZN7WebCore8Document16addAudioProducerEPNS_13AudioProducerE
 __ZN7WebCore8Document16isPageBoxVisibleEi
 __ZN7WebCore8Document16shortcutIconURLsEv
 __ZN7WebCore8Document17setFocusedElementEN3WTF10PassRefPtrINS_7ElementEEENS_14FocusDirectionE
 __ZN7WebCore8Document19accessSVGExtensionsEv
+__ZN7WebCore8Document19removeAudioProducerEPNS_13AudioProducerE
 __ZN7WebCore8Document19updateStyleIfNeededEv
 __ZN7WebCore8Document20styleResolverChangedENS_23StyleResolverUpdateFlagE
+__ZN7WebCore8Document20updateIsPlayingAudioEv
 __ZN7WebCore8Document22createDocumentFragmentEv
 __ZN7WebCore8Document23didAddWheelEventHandlerEv
 __ZN7WebCore8Document24addMediaCanStartListenerEPNS_21MediaCanStartListenerE
index c539f5f..1bede3a 100644 (file)
@@ -379,6 +379,9 @@ typedef enum {
   , NPPVpluginCoreAnimationLayer = 1003
 #endif
 
+  /* Used for figuring out whether a plug-in is playing audio. */
+  , NPPVpluginIsPlayingAudio = 4000
+
 } NPPVariable;
 
 /*
index d9621d5..31d8b82 100644 (file)
@@ -1,3 +1,44 @@
+2014-11-04  Ada Chan  <adachan@apple.com>
+
+        Figure out whether a plug-in is playing audio.
+        https://bugs.webkit.org/show_bug.cgi?id=137219
+
+        Reviewed by Anders Carlsson.
+
+        Handle the setting of the NPPVpluginIsPlayingAudio variable.
+
+        * PluginProcess/PluginControllerProxy.cpp:
+        (WebKit::PluginControllerProxy::setPluginIsPlayingAudio):
+        Send a SetPluginIsPlayingAudio message to the WebProcess.
+        * PluginProcess/PluginControllerProxy.h:
+        * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
+        (WebKit::NPN_SetValue):
+        Handle NPPVpluginIsPlayingAudio. Call NetscapePlugin::setIsPlayingAudio().
+        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
+        (WebKit::NetscapePlugin::setIsPlayingAudio):
+        Call PluginControllerProxy::setPluginIsPlayingAudio().
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
+        * WebProcess/Plugins/PluginController.h:
+        * WebProcess/Plugins/PluginProxy.cpp:
+        (WebKit::PluginProxy::setPluginIsPlayingAudio):
+        Call PluginView::setPluginIsPlayingAudio().
+        * WebProcess/Plugins/PluginProxy.h:
+        * WebProcess/Plugins/PluginProxy.messages.in:
+        Add the SetPluginIsPlayingAudio message.
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::PluginView):
+        Initialize m_pluginIsPlayingAudio.
+        (WebKit::PluginView::~PluginView):
+        Remove itself from the Document's list of AudioProducers.
+        (WebKit::PluginView::initializePlugin):
+        Add itself to the Document's list of AudioProducers.
+        (WebKit::PluginView::pageMutedStateDidChange):
+        Add a FIXME.
+        (WebKit::PluginView::setPluginIsPlayingAudio):
+        If m_pluginIsPlayingAudio has changed, tell the Document to update its audio playing state.
+        * WebProcess/Plugins/PluginView.h:
+        Now inherits AudioProducer.
+
 2014-11-05  Dan Bernstein  <mitz@apple.com>
 
         Tried to fix the GTK build.
index 498f3f3..de32a26 100644 (file)
@@ -310,6 +310,11 @@ bool PluginControllerProxy::evaluate(NPObject* npObject, const String& scriptStr
     return true;
 }
 
+void PluginControllerProxy::setPluginIsPlayingAudio(bool pluginIsPlayingAudio)
+{
+    m_connection->connection()->send(Messages::PluginProxy::SetPluginIsPlayingAudio(pluginIsPlayingAudio), m_pluginInstanceID);
+}
+
 void PluginControllerProxy::setStatusbarText(const String& statusbarText)
 {
     m_connection->connection()->send(Messages::PluginProxy::SetStatusbarText(statusbarText), m_pluginInstanceID);
index ac573de..27c8ada 100644 (file)
@@ -92,6 +92,7 @@ private:
     virtual NPObject* windowScriptNPObject() override;
     virtual NPObject* pluginElementNPObject() override;
     virtual bool evaluate(NPObject*, const String& scriptString, NPVariant* result, bool allowPopups) override;
+    virtual void setPluginIsPlayingAudio(bool) override;
     virtual void setStatusbarText(const String&) override;
     virtual bool isAcceleratedCompositingEnabled() override;
     virtual void pluginProcessCrashed() override;
index 328643e..ef8f0ef 100644 (file)
@@ -575,6 +575,12 @@ static NPError NPN_SetValue(NPP npp, NPPVariable variable, void *value)
             return NPERR_NO_ERROR;
         }
 
+        case NPPVpluginIsPlayingAudio: {
+            RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
+            plugin->setIsPlayingAudio(value);
+            return NPERR_NO_ERROR;
+        }
+
         default:
             notImplemented();
             return NPERR_GENERIC_ERROR;
index 9405e52..3f7cd51 100644 (file)
@@ -399,6 +399,11 @@ bool NetscapePlugin::getAuthenticationInfo(const ProtectionSpace& protectionSpac
     return controller()->getAuthenticationInfo(protectionSpace, username, password);
 }    
 
+void NetscapePlugin::setIsPlayingAudio(bool isPlayingAudio)
+{
+    controller()->setPluginIsPlayingAudio(isPlayingAudio);
+}
+
 NPError NetscapePlugin::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* savedData)
 {
     return m_pluginModule->pluginFuncs().newp(pluginType, &m_npp, mode, argc, argn, argv, savedData);
index c3bc00c..5ba5de8 100644 (file)
@@ -129,6 +129,8 @@ public:
     void setCookiesForURL(const String& urlString, const String& cookieString);
     bool getAuthenticationInfo(const WebCore::ProtectionSpace&, String& username, String& password);
 
+    void setIsPlayingAudio(bool);
+
     // Member functions for calling into the plug-in.
     NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData*);
     NPError NPP_Destroy(NPSavedData**);
index ddc1aee..6d28a8c 100644 (file)
@@ -155,6 +155,9 @@ public:
     // Called when the a plug-in instance fails to initialized, either synchronously or asynchronously.
     virtual void didFailToInitializePlugin() = 0;
 
+    // Called by the Netscape plug-in when it starts or stops playing audio.
+    virtual void setPluginIsPlayingAudio(bool) = 0;
+
     // Helper class for delaying destruction of a plug-in.
     class PluginDestructionProtector {
     public:
index 9652d77..00ba475 100644 (file)
@@ -654,6 +654,11 @@ void PluginProxy::evaluate(const NPVariantData& npObjectAsVariantData, const Str
     releaseNPVariantValue(&npObjectAsVariant);
 }
 
+void PluginProxy::setPluginIsPlayingAudio(bool pluginIsPlayingAudio)
+{
+    controller()->setPluginIsPlayingAudio(pluginIsPlayingAudio);
+}
+
 void PluginProxy::cancelStreamLoad(uint64_t streamID)
 {
     controller()->cancelStreamLoad(streamID);
index 41ea051..84117fc 100644 (file)
@@ -163,6 +163,7 @@ private:
     void getAuthenticationInfo(const WebCore::ProtectionSpace&, bool& returnValue, String& username, String& password);
     void getPluginElementNPObject(uint64_t& pluginElementNPObjectID);
     void evaluate(const NPVariantData& npObjectAsVariantData, const String& scriptString, bool allowPopups, bool& returnValue, NPVariantData& resultData);
+    void setPluginIsPlayingAudio(bool);
     void cancelStreamLoad(uint64_t streamID);
     void cancelManualStreamLoad();
     void setStatusbarText(const String& statusbarText);
index 49fb1c1..e08817f 100644 (file)
@@ -83,6 +83,9 @@ messages -> PluginProxy LegacyReceiver {
     
     # Tells the WebProcess that the plug-in failed to initialize.
     DidFailToCreatePlugin() -> ()
+
+    # Tells the WebProcess that the plug-in has started or stopped playing audio.
+    SetPluginIsPlayingAudio(bool pluginIsPlayingAudio)
 }
 
 #endif
index f3359b8..d8c17b6 100644 (file)
@@ -297,6 +297,7 @@ PluginView::PluginView(PassRefPtr<HTMLPlugInElement> pluginElement, PassRefPtr<P
     , m_countSnapshotRetries(0)
     , m_didReceiveUserInteraction(false)
     , m_pageScaleFactor(1)
+    , m_pluginIsPlayingAudio(false)
 {
     m_webPage->addPluginView(this);
 }
@@ -311,6 +312,8 @@ PluginView::~PluginView()
     if (m_isWaitingUntilMediaCanStart)
         m_pluginElement->document().removeMediaCanStartListener(this);
 
+    m_pluginElement->document().removeAudioProducer(this);
+
     destroyPluginAndReset();
 
     // Null out the plug-in element explicitly so we'll crash earlier if we try to use
@@ -589,6 +592,8 @@ void PluginView::initializePlugin()
         }
     }
 
+    m_pluginElement->document().addAudioProducer(this);
+
 #if ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)
     HTMLPlugInImageElement& plugInImageElement = downcast<HTMLPlugInImageElement>(*m_pluginElement);
     m_didPlugInStartOffScreen = !m_webPage->plugInIntersectsSearchRect(plugInImageElement);
@@ -1324,6 +1329,11 @@ void PluginView::mediaCanStart()
     initializePlugin();
 }
 
+void PluginView::pageMutedStateDidChange()
+{
+    // FIXME: To be implemented (https://bugs.webkit.org/show_bug.cgi?id=138105).
+}
+
 bool PluginView::isPluginVisible()
 {
     return isVisible();
@@ -1433,6 +1443,15 @@ bool PluginView::evaluate(NPObject* npObject, const String& scriptString, NPVari
     UserGestureIndicator gestureIndicator(allowPopups ? DefinitelyProcessingUserGesture : PossiblyProcessingUserGesture);
     return m_npRuntimeObjectMap.evaluate(npObject, scriptString, result);
 }
+
+void PluginView::setPluginIsPlayingAudio(bool pluginIsPlayingAudio)
+{
+    if (m_pluginIsPlayingAudio == pluginIsPlayingAudio)
+        return;
+
+    m_pluginIsPlayingAudio = pluginIsPlayingAudio;
+    m_pluginElement->document().updateIsPlayingAudio();
+}
 #endif
 
 void PluginView::setStatusbarText(const String& statusbarText)
index c8efc46..7f821eb 100644 (file)
@@ -31,6 +31,7 @@
 #include "Plugin.h"
 #include "PluginController.h"
 #include "WebFrame.h"
+#include <WebCore/AudioProducer.h>
 #include <WebCore/FindOptions.h>
 #include <WebCore/Image.h>
 #include <WebCore/MediaCanStartListener.h>
@@ -56,7 +57,7 @@ namespace WebKit {
 
 class WebEvent;
 
-class PluginView : public WebCore::PluginViewBase, public PluginController, private WebCore::MediaCanStartListener, private WebFrame::LoadListener {
+class PluginView : public WebCore::PluginViewBase, public PluginController, private WebCore::MediaCanStartListener, private WebFrame::LoadListener, private WebCore::AudioProducer {
 public:
     static PassRefPtr<PluginView> create(PassRefPtr<WebCore::HTMLPlugInElement>, PassRefPtr<Plugin>, const Plugin::Parameters&);
 
@@ -179,6 +180,10 @@ private:
     // WebCore::MediaCanStartListener
     virtual void mediaCanStart() override;
 
+    // WebCore::AudioProducer
+    virtual bool isPlayingAudio() override { return m_pluginIsPlayingAudio; }
+    virtual void pageMutedStateDidChange() override;
+
     // PluginController
     virtual bool isPluginVisible() override;
     virtual void invalidate(const WebCore::IntRect&) override;
@@ -190,6 +195,7 @@ private:
     virtual NPObject* windowScriptNPObject() override;
     virtual NPObject* pluginElementNPObject() override;
     virtual bool evaluate(NPObject*, const String& scriptString, NPVariant* result, bool allowPopups) override;
+    virtual void setPluginIsPlayingAudio(bool) override;
 #endif
     virtual void setStatusbarText(const String&) override;
     virtual bool isAcceleratedCompositingEnabled() override;
@@ -278,6 +284,8 @@ private:
     bool m_didReceiveUserInteraction;
 
     double m_pageScaleFactor;
+
+    bool m_pluginIsPlayingAudio;
 };
 
 } // namespace WebKit