Changeset 135819 in webkit


Ignore:
Timestamp:
Nov 26, 2012 10:34:35 PM (11 years ago)
Author:
mitz@apple.com
Message:

<rdar://problem/11931191> 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.
Location:
trunk/Source/WebKit2
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r135818 r135819  
     12012-11-26  Dan Bernstein  <mitz@apple.com>
     2
     3        <rdar://problem/11931191> Entering Tab View after a bunch of YouTube pages were opened in background tabs makes all of them start playing simultaneously
     4        https://bugs.webkit.org/show_bug.cgi?id=103358
     5
     6        Reviewed by Adele Peterson.
     7
     8        To fix this, this patch adds WKPageSetMayStartMediaWhenInWindow(), which allows the client to
     9        prevent media from starting automatically when the view is put in a window.
     10
     11        * Shared/WebPageCreationParameters.cpp:
     12        (WebKit::WebPageCreationParameters::encode): Encode mayStartMediaWhenInWindow.
     13        (WebKit::WebPageCreationParameters::decode): Decode mayStartMediaWhenInWindow.
     14        * Shared/WebPageCreationParameters.h:
     15        (WebPageCreationParameters): Added boolean member mayStartMediaWhenInWindow.
     16        * UIProcess/API/C/WKPage.cpp:
     17        (WKPageSetMayStartMediaWhenInWindow): Added. Calls through to WebPageProxy.
     18        * UIProcess/API/C/WKPagePrivate.h: Declared WKPageSetMayStartMediaWhenInWindow.
     19        * UIProcess/WebPageProxy.cpp:
     20        (WebKit::WebPageProxy::WebPageProxy): Added initializiation of m_mayStartMediaWhenInWindow
     21        to true, the value matching the current behavior.
     22        (WebKit::WebPageProxy::setMayStartMediaWhenInWindow): Added. Updates
     23        m_mayStartMediaWhenInWindow and sends a message to the Web process to do the same.
     24        (WebKit::WebPageProxy::creationParameters): Changed to set mayStartMediaWhenInWindow in the
     25        process creation parameters.
     26        * UIProcess/WebPageProxy.h:
     27        (WebPageProxy): Declared setMayStartMediaWhenInWindow() and added member variable
     28        m_mayStartMediaWhenInWindow.
     29        * WebProcess/WebPage/WebPage.cpp:
     30        (WebKit::WebPage::WebPage): Initialized m_mayStartMediaWhenInWindow from the creation
     31        parameters.
     32        (WebKit::WebPage::setIsInWindow): Made starting of media upon being added to a window
     33        conditional on m_mayStartMediaWhenInWindow.
     34        (WebKit::WebPage::setMayStartMediaWhenInWindow): Added. Sets m_mayStartMediaWhenInWindow. If
     35        already in a window when changing from false to true, starts m_setCanStartMediaTimer.
     36        * WebProcess/WebPage/WebPage.h:
     37        (WebPage): Declared setMayStartMediaWhenInWindow() and added member variable m_mayStartMediaWhenInWindow.
     38        * WebProcess/WebPage/WebPage.messages.in: Added SetMayStartMediaWhenInWindow.
     39
    1402012-11-26  Huang Dongsung  <luxtella@company100.net>
    241
  • trunk/Source/WebKit2/Shared/WebPageCreationParameters.cpp

    r132926 r135819  
    5858    encoder << deviceScaleFactor;
    5959    encoder << mediaVolume;
     60    encoder << mayStartMediaWhenInWindow;
    6061
    6162#if PLATFORM(MAC)
     
    120121    if (!decoder->decode(parameters.mediaVolume))
    121122        return false;
     123    if (!decoder->decode(parameters.mayStartMediaWhenInWindow))
     124        return false;
    122125
    123126#if PLATFORM(MAC)
  • trunk/Source/WebKit2/Shared/WebPageCreationParameters.h

    r132361 r135819  
    8686   
    8787    float mediaVolume;
     88    bool mayStartMediaWhenInWindow;
    8889
    8990#if PLATFORM(MAC)
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r133828 r135819  
    765765    return toAPI(toImpl(pageRef)->relatedPages().leakRef());
    766766}
     767
     768void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
     769{
     770    toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
     771}
  • trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h

    r130214 r135819  
    9494
    9595WK_EXPORT void WKPageSetMediaVolume(WKPageRef page, float volume);
     96WK_EXPORT void WKPageSetMayStartMediaWhenInWindow(WKPageRef page, bool mayStartMedia);
    9697
    9798WK_EXPORT WKArrayRef WKPageCopyRelatedPages(WKPageRef page);
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r135066 r135819  
    235235    , m_suppressVisibilityUpdates(false)
    236236    , m_mediaVolume(1)
     237    , m_mayStartMediaWhenInWindow(true)
    237238#if ENABLE(PAGE_VISIBILITY_API)
    238239    , m_visibilityState(PageVisibilityStateVisible)
     
    27812782   
    27822783    m_process->send(Messages::WebPage::SetMediaVolume(volume), m_pageID);   
     2784}
     2785
     2786void WebPageProxy::setMayStartMediaWhenInWindow(bool mayStartMedia)
     2787{
     2788    if (mayStartMedia == m_mayStartMediaWhenInWindow)
     2789        return;
     2790
     2791    m_mayStartMediaWhenInWindow = mayStartMedia;
     2792
     2793    if (!isValid())
     2794        return;
     2795
     2796    process()->send(Messages::WebPage::SetMayStartMediaWhenInWindow(mayStartMedia), m_pageID);
    27832797}
    27842798
     
    37643778    parameters.deviceScaleFactor = m_intrinsicDeviceScaleFactor;
    37653779    parameters.mediaVolume = m_mediaVolume;
     3780    parameters.mayStartMediaWhenInWindow = m_mayStartMediaWhenInWindow;
    37663781
    37673782#if PLATFORM(MAC)
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r134820 r135819  
    737737   
    738738    void setMediaVolume(float);
     739    void setMayStartMediaWhenInWindow(bool);
    739740
    740741    // WebPopupMenuProxy::Client
     
    12391240
    12401241    float m_mediaVolume;
     1242    bool m_mayStartMediaWhenInWindow;
    12411243
    12421244#if PLATFORM(QT)
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r135803 r135819  
    365365   
    366366    setMediaVolume(parameters.mediaVolume);
     367    m_mayStartMediaWhenInWindow = parameters.mayStartMediaWhenInWindow;
    367368
    368369    WebProcess::shared().addMessageReceiver(Messages::WebPage::messageReceiverName(), m_pageID, this);
     
    18931894        // in order to get plug-in connections, and the UI process will be waiting for the Web process to update the backing
    18941895        // store after moving the view into a window, until it times out and paints white. See <rdar://problem/9242771>.
    1895         m_setCanStartMediaTimer.startOneShot(0);
     1896        if (m_mayStartMediaWhenInWindow)
     1897            m_setCanStartMediaTimer.startOneShot(0);
     1898
    18961899        m_page->didMoveOnscreen();
    18971900    }
     
    33183321}
    33193322
     3323void WebPage::setMayStartMediaWhenInWindow(bool mayStartMedia)
     3324{
     3325    if (mayStartMedia == m_mayStartMediaWhenInWindow)
     3326        return;
     3327
     3328    m_mayStartMediaWhenInWindow = mayStartMedia;
     3329    if (m_mayStartMediaWhenInWindow && m_page->isOnscreen())
     3330        m_setCanStartMediaTimer.startOneShot(0);
     3331}
     3332
    33203333void WebPage::runModal()
    33213334{
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r134953 r135819  
    526526
    527527    void setMediaVolume(float);
     528    void setMayStartMediaWhenInWindow(bool);
    528529
    529530    bool mainFrameHasCustomRepresentation() const;
     
    852853   
    853854    WebCore::RunLoop::Timer<WebPage> m_setCanStartMediaTimer;
     855    bool m_mayStartMediaWhenInWindow;
    854856
    855857    HashMap<uint64_t, RefPtr<WebUndoStep> > m_undoStepMap;
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r133935 r135819  
    227227    # Media
    228228    SetMediaVolume(float volume)
     229    SetMayStartMediaWhenInWindow(bool mayStartMedia)
    229230
    230231    SetMemoryCacheMessagesEnabled(bool memoryCacheMessagesEnabled)
Note: See TracChangeset for help on using the changeset viewer.