Entering Tab View after a bunch of YouTube pages were opened in background tabs makes...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2012 21:52:47 +0000 (21:52 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2012 21:52:47 +0000 (21:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103358

Reviewed by Adele Peterson.

To fix this, this patch adds WKPageSetMayStartMediaWhenInWindow(), which allows the client to
prevent media from starting automatically when the view is put in a window.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode): Encode mayStartMediaWhenInWindow.
(WebKit::WebPageCreationParameters::decode): Decode mayStartMediaWhenInWindow.
* Shared/WebPageCreationParameters.h:
(WebPageCreationParameters): Added boolean member mayStartMediaWhenInWindow.
* UIProcess/API/C/WKPage.cpp:
(WKPageSetMayStartMediaWhenInWindow): Added. Calls through to WebPageProxy.
* UIProcess/API/C/WKPagePrivate.h: Declared WKPageSetMayStartMediaWhenInWindow.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy): Added initializiation of m_mayStartMediaWhenInWindow
to true, the value matching the current behavior.
(WebKit::WebPageProxy::setMayStartMediaWhenInWindow): Added. Updates
m_mayStartMediaWhenInWindow and sends a message to the Web process to do the same.
(WebKit::WebPageProxy::creationParameters): Changed to set mayStartMediaWhenInWindow in the
process creation parameters.
* UIProcess/WebPageProxy.h:
(WebPageProxy): Declared setMayStartMediaWhenInWindow() and added member variable
m_mayStartMediaWhenInWindow.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage): Initialized m_mayStartMediaWhenInWindow from the creation
parameters.
(WebKit::WebPage::setIsInWindow): Made starting of media upon being added to a window
conditional on m_mayStartMediaWhenInWindow.
(WebKit::WebPage::setMayStartMediaWhenInWindow): Added. Sets m_mayStartMediaWhenInWindow. If
already in a window when changing from false to true, starts m_setCanStartMediaTimer.
* WebProcess/WebPage/WebPage.h:
(WebPage): Declared setMayStartMediaWhenInWindow() and added member variable m_mayStartMediaWhenInWindow.
* WebProcess/WebPage/WebPage.messages.in: Added SetMayStartMediaWhenInWindow.

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPageCreationParameters.cpp
Source/WebKit2/Shared/WebPageCreationParameters.h
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPagePrivate.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index d4fff195f8ca94e4bff0d565823af1f2bb8c9639..ceb1031412590ec10a4aa00f79602bb27d658f25 100644 (file)
@@ -1,3 +1,42 @@
+2012-11-27  Dan Bernstein  <mitz@apple.com>
+
+        Entering Tab View after a bunch of YouTube pages were opened in background tabs makes all of them start playing simultaneously
+        https://bugs.webkit.org/show_bug.cgi?id=103358
+
+        Reviewed by Adele Peterson.
+
+        To fix this, this patch adds WKPageSetMayStartMediaWhenInWindow(), which allows the client to
+        prevent media from starting automatically when the view is put in a window.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode): Encode mayStartMediaWhenInWindow.
+        (WebKit::WebPageCreationParameters::decode): Decode mayStartMediaWhenInWindow.
+        * Shared/WebPageCreationParameters.h:
+        (WebPageCreationParameters): Added boolean member mayStartMediaWhenInWindow.
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetMayStartMediaWhenInWindow): Added. Calls through to WebPageProxy.
+        * UIProcess/API/C/WKPagePrivate.h: Declared WKPageSetMayStartMediaWhenInWindow.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy): Added initializiation of m_mayStartMediaWhenInWindow
+        to true, the value matching the current behavior.
+        (WebKit::WebPageProxy::setMayStartMediaWhenInWindow): Added. Updates
+        m_mayStartMediaWhenInWindow and sends a message to the Web process to do the same.
+        (WebKit::WebPageProxy::creationParameters): Changed to set mayStartMediaWhenInWindow in the
+        process creation parameters.
+        * UIProcess/WebPageProxy.h:
+        (WebPageProxy): Declared setMayStartMediaWhenInWindow() and added member variable
+        m_mayStartMediaWhenInWindow.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage): Initialized m_mayStartMediaWhenInWindow from the creation
+        parameters.
+        (WebKit::WebPage::setIsInWindow): Made starting of media upon being added to a window
+        conditional on m_mayStartMediaWhenInWindow.
+        (WebKit::WebPage::setMayStartMediaWhenInWindow): Added. Sets m_mayStartMediaWhenInWindow. If
+        already in a window when changing from false to true, starts m_setCanStartMediaTimer.
+        * WebProcess/WebPage/WebPage.h:
+        (WebPage): Declared setMayStartMediaWhenInWindow() and added member variable m_mayStartMediaWhenInWindow.
+        * WebProcess/WebPage/WebPage.messages.in: Added SetMayStartMediaWhenInWindow.
+
 2012-11-27  Pratik Solanki  <psolanki@apple.com>
 
         objc/objc-runtime.h does not exist on all PLATFORM(MAC)
index 2a4afd938c6d5172bacfa6201d4a52bc4383e2d2..22e28849c4b88baeafa890b72e8fda94f8f4b5cc 100644 (file)
@@ -57,6 +57,7 @@ void WebPageCreationParameters::encode(CoreIPC::ArgumentEncoder& encoder) const
     encoder << canRunModal;
     encoder << deviceScaleFactor;
     encoder << mediaVolume;
+    encoder << mayStartMediaWhenInWindow;
 
 #if PLATFORM(MAC)
     encoder << isSmartInsertDeleteEnabled;
@@ -119,6 +120,8 @@ bool WebPageCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, WebPag
         return false;
     if (!decoder->decode(parameters.mediaVolume))
         return false;
+    if (!decoder->decode(parameters.mayStartMediaWhenInWindow))
+        return false;
 
 #if PLATFORM(MAC)
     if (!decoder->decode(parameters.isSmartInsertDeleteEnabled))
index 214c04c50482eca8905c3d19d717af0f8991e86e..7a580f3e38e6a21a5134dd3dc3688283ef5256cd 100644 (file)
@@ -85,6 +85,7 @@ struct WebPageCreationParameters {
     float deviceScaleFactor;
     
     float mediaVolume;
+    bool mayStartMediaWhenInWindow;
 
 #if PLATFORM(MAC)
     bool isSmartInsertDeleteEnabled;
index 259bca727eeee3e93025add0c22d4d5bdbd73ebf..ef871bb4c6ad185f2f751bf980228f8ea3f1d224 100644 (file)
@@ -764,3 +764,8 @@ WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef)
 {
     return toAPI(toImpl(pageRef)->relatedPages().leakRef());
 }
+
+void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
+{
+    toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
+}
index 3a9de69afd6359abc06f527cf524e39afc6d7ec9..4f0e85ba56dbec7a677acfc1e41815fd2ebdd304 100644 (file)
@@ -93,6 +93,7 @@ WK_EXPORT WKImageRef WKPageCreateSnapshotOfVisibleContent(WKPageRef page);
 WK_EXPORT void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync);
 
 WK_EXPORT void WKPageSetMediaVolume(WKPageRef page, float volume);
+WK_EXPORT void WKPageSetMayStartMediaWhenInWindow(WKPageRef page, bool mayStartMedia);
 
 WK_EXPORT WKArrayRef WKPageCopyRelatedPages(WKPageRef page);
 
index 1e408802bc51a38fc6f564aa3d37dd4a2876b53d..df416c09dbc66bb05fe2c20119409380f571e431 100644 (file)
@@ -234,6 +234,7 @@ WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> p
     , m_shouldSendEventsSynchronously(false)
     , m_suppressVisibilityUpdates(false)
     , m_mediaVolume(1)
+    , m_mayStartMediaWhenInWindow(true)
 #if ENABLE(PAGE_VISIBILITY_API)
     , m_visibilityState(PageVisibilityStateVisible)
 #endif
@@ -2782,6 +2783,19 @@ void WebPageProxy::setMediaVolume(float volume)
     m_process->send(Messages::WebPage::SetMediaVolume(volume), m_pageID);    
 }
 
+void WebPageProxy::setMayStartMediaWhenInWindow(bool mayStartMedia)
+{
+    if (mayStartMedia == m_mayStartMediaWhenInWindow)
+        return;
+
+    m_mayStartMediaWhenInWindow = mayStartMedia;
+
+    if (!isValid())
+        return;
+
+    process()->send(Messages::WebPage::SetMayStartMediaWhenInWindow(mayStartMedia), m_pageID);
+}
+
 #if PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(GTK)
 void WebPageProxy::handleDownloadRequest(DownloadProxy* download)
 {
@@ -3763,6 +3777,7 @@ WebPageCreationParameters WebPageProxy::creationParameters() const
     parameters.canRunModal = m_canRunModal;
     parameters.deviceScaleFactor = m_intrinsicDeviceScaleFactor;
     parameters.mediaVolume = m_mediaVolume;
+    parameters.mayStartMediaWhenInWindow = m_mayStartMediaWhenInWindow;
 
 #if PLATFORM(MAC)
     parameters.isSmartInsertDeleteEnabled = m_isSmartInsertDeleteEnabled;
index 91fad303e166758e1f46eaa560aa57a933b8dae0..98fa8a4f126a00c478f2eb76a386e52e7ca07de4 100644 (file)
@@ -736,6 +736,7 @@ public:
     void printMainFrame();
     
     void setMediaVolume(float);
+    void setMayStartMediaWhenInWindow(bool);
 
     // WebPopupMenuProxy::Client
     virtual NativeWebMouseEvent* currentlyProcessedMouseDownEvent();
@@ -1238,6 +1239,7 @@ private:
     bool m_suppressVisibilityUpdates;
 
     float m_mediaVolume;
+    bool m_mayStartMediaWhenInWindow;
 
 #if PLATFORM(QT)
     WTF::HashSet<RefPtr<QtRefCountedNetworkRequestData> > m_applicationSchemeRequests;
index 154458bc74aa764f7fd4448a291de01395d276d8..1c30ea9ef6daffb67d8e6a61821025c43efea782 100644 (file)
@@ -325,6 +325,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
 #endif
 
     m_page->setCanStartMedia(false);
+    m_mayStartMediaWhenInWindow = parameters.mayStartMediaWhenInWindow;
 
     m_pageGroup = WebProcess::shared().webPageGroup(parameters.pageGroupData);
     m_page->setGroupName(m_pageGroup->identifier());
@@ -1893,7 +1894,9 @@ void WebPage::setIsInWindow(bool isInWindow)
         // Defer the call to Page::setCanStartMedia() since it ends up sending a syncrhonous messages to the UI process
         // in order to get plug-in connections, and the UI process will be waiting for the Web process to update the backing
         // store after moving the view into a window, until it times out and paints white. See <rdar://problem/9242771>.
-        m_setCanStartMediaTimer.startOneShot(0);
+        if (m_mayStartMediaWhenInWindow)
+            m_setCanStartMediaTimer.startOneShot(0);
+
         m_page->didMoveOnscreen();
     }
 }
@@ -3318,6 +3321,16 @@ void WebPage::setMediaVolume(float volume)
     m_page->setMediaVolume(volume);
 }
 
+void WebPage::setMayStartMediaWhenInWindow(bool mayStartMedia)
+{
+    if (mayStartMedia == m_mayStartMediaWhenInWindow)
+        return;
+
+    m_mayStartMediaWhenInWindow = mayStartMedia;
+    if (m_mayStartMediaWhenInWindow && m_page->isOnscreen())
+        m_setCanStartMediaTimer.startOneShot(0);
+}
+
 void WebPage::runModal()
 {
     if (m_isClosed)
index 19af39c6ee714d66b000070f20b37410a1b51426..00ea81c8cbefed9a6b41ab0568f9fcf5b4fecab6 100644 (file)
@@ -525,6 +525,7 @@ public:
 #endif
 
     void setMediaVolume(float);
+    void setMayStartMediaWhenInWindow(bool);
 
     bool mainFrameHasCustomRepresentation() const;
 
@@ -851,6 +852,7 @@ private:
 #endif
     
     WebCore::RunLoop::Timer<WebPage> m_setCanStartMediaTimer;
+    bool m_mayStartMediaWhenInWindow;
 
     HashMap<uint64_t, RefPtr<WebUndoStep> > m_undoStepMap;
 
index bbf6a686cecf15a7ebe362c14a5d2a93e4836f76..ad4292b4beebb2c198c1167336d5b7e4951eb054 100644 (file)
@@ -226,6 +226,7 @@ messages -> WebPage {
 
     # Media
     SetMediaVolume(float volume)
+    SetMayStartMediaWhenInWindow(bool mayStartMedia)
 
     SetMemoryCacheMessagesEnabled(bool memoryCacheMessagesEnabled)