Changeset 55699 in webkit


Ignore:
Timestamp:
Mar 8, 2010 5:06:58 PM (14 years ago)
Author:
Darin Adler
Message:

2010-03-08 Darin Adler <Darin Adler>

Reviewed by Jon Honeycutt.

Don't auto-play <audio> and <video> elements loaded in background tabs
https://bugs.webkit.org/show_bug.cgi?id=35886
rdar://problem/7117745

  • manual-tests/video-in-non-frontmost-tab.html: Added.
  • manual-tests/resources/video-tab.html: Added.
  • html/HTMLMediaElement.h: Added MediaCanStartListener as a base class, and added the mediaCanStart function as well as a boolean, m_isWaitingUntilMediaCanStart.
  • html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_isWaitingUntilMediaCanStart. (WebCore::HTMLMediaElement::~HTMLMediaElement): Call removeMediaCanStartListener if m_isWaitingUntilMediaCanStart is true. (WebCore::HTMLMediaElement::loadInternal): Set m_isWaitingUntilMediaCanStart and call addMediaCanStartListener if canStartMedia is false. (WebCore::HTMLMediaElement::mediaCanStart): Clear m_isWaitingUntilMediaCanStart and call loadInternal.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r55693 r55699  
     12010-03-08  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Jon Honeycutt.
     4
     5        Don't auto-play <audio> and <video> elements loaded in background tabs
     6        https://bugs.webkit.org/show_bug.cgi?id=35886
     7        rdar://problem/7117745
     8
     9        * manual-tests/video-in-non-frontmost-tab.html: Added.
     10        * manual-tests/resources/video-tab.html: Added.
     11
     12        * html/HTMLMediaElement.h: Added MediaCanStartListener as a base class, and
     13        added the mediaCanStart function as well as a boolean,
     14        m_isWaitingUntilMediaCanStart.
     15
     16        * html/HTMLMediaElement.cpp:
     17        (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize
     18        m_isWaitingUntilMediaCanStart.
     19        (WebCore::HTMLMediaElement::~HTMLMediaElement): Call
     20        removeMediaCanStartListener if m_isWaitingUntilMediaCanStart is true.
     21        (WebCore::HTMLMediaElement::loadInternal): Set m_isWaitingUntilMediaCanStart
     22        and call addMediaCanStartListener if canStartMedia is false.
     23        (WebCore::HTMLMediaElement::mediaCanStart): Clear m_isWaitingUntilMediaCanStart
     24        and call loadInternal.
     25
    1262010-03-08  Csaba Osztrogonác  <ossy@webkit.org>
    227
  • trunk/WebCore/html/HTMLMediaElement.cpp

    r55682 r55699  
    106106    , m_playing(false)
    107107    , m_processingMediaPlayerCallback(0)
     108    , m_isWaitingUntilMediaCanStart(false)
    108109    , m_processingLoad(false)
    109110    , m_delayingTheLoadEvent(false)
     
    130131HTMLMediaElement::~HTMLMediaElement()
    131132{
     133    if (m_isWaitingUntilMediaCanStart) {
     134        if (Page* page = document()->page())
     135            page->removeMediaCanStartListener(this);
     136    }
     137
    132138    document()->unregisterForDocumentActivationCallbacks(this);
    133139    document()->unregisterForMediaVolumeCallbacks(this);
     
    465471void HTMLMediaElement::loadInternal()
    466472{
     473    // If we can't start a load right away, start it later.
     474    Page* page = document()->page();
     475    if (page && !page->canStartMedia()) {
     476        if (m_isWaitingUntilMediaCanStart)
     477            return;
     478        page->addMediaCanStartListener(this);
     479        m_isWaitingUntilMediaCanStart = true;
     480        return;
     481    }
     482
    467483    // If the load() method for this element is already being invoked, then abort these steps.
    468484    if (m_processingLoad)
     
    19611977}
    19621978
     1979void HTMLMediaElement::mediaCanStart()
     1980{
     1981    ASSERT(m_isWaitingUntilMediaCanStart);
     1982    m_isWaitingUntilMediaCanStart = false;
     1983    loadInternal();
     1984}
     1985
    19631986}
    19641987
  • trunk/WebCore/html/HTMLMediaElement.h

    r55682 r55699  
    3030
    3131#include "HTMLElement.h"
     32#include "MediaCanStartListener.h"
    3233#include "MediaPlayer.h"
    3334
     
    4445// no longer depends on typecasting a MediaPlayerClient to an HTMLMediaElement.
    4546
    46 class HTMLMediaElement : public HTMLElement, public MediaPlayerClient {
     47class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, private MediaCanStartListener {
    4748public:
    4849    MediaPlayer* player() const { return m_player.get(); }
     
    263264    void setPausedInternal(bool);
    264265
     266    virtual void mediaCanStart();
     267
    265268    // Restrictions to change default behaviors. This is effectively a compile time choice at the moment
    266269    // because there are no accessor functions.
     
    315318    // calling the media engine recursively.
    316319    int m_processingMediaPlayerCallback;
     320
     321    bool m_isWaitingUntilMediaCanStart;
    317322
    318323    bool m_processingLoad : 1;
  • trunk/WebKit/mac/WebView/WebView.mm

    r55697 r55699  
    976976#endif
    977977
    978     _private->closed = YES;
    979    
    980978    [[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
    981979    [[NSNotificationCenter defaultCenter] removeObserver:self];
     
    10101008        return;
    10111009
     1010    _private->closed = YES;
     1011
    10121012    [self _closingEventHandling];
    10131013
     
    10421042
    10431043    [_private->inspector webViewClosed];
    1044 
    1045     // setHostWindow:nil must be called before this value is set (see 5408186)
    1046     _private->closed = YES;
    10471044
    10481045    // To avoid leaks, call removeDragCaret in case it wasn't called after moveDragCaretToPoint.
     
    33403337- (void)setHostWindow:(NSWindow *)hostWindow
    33413338{
    3342     if (_private->closed)
     3339    if (_private->closed && hostWindow)
    33433340        return;
    33443341    if (hostWindow == _private->hostWindow)
Note: See TracChangeset for help on using the changeset viewer.