| Index: Source/core/html/HTMLMediaElement.cpp
 | 
| diff --git a/Source/core/html/HTMLMediaElement.cpp b/Source/core/html/HTMLMediaElement.cpp
 | 
| index 214862aea367bfeba004bd1695efcc675e53bdb7..239625bea5c882d22da0f06e68761746571fe0a6 100644
 | 
| --- a/Source/core/html/HTMLMediaElement.cpp
 | 
| +++ b/Source/core/html/HTMLMediaElement.cpp
 | 
| @@ -63,15 +63,19 @@
 | 
|  #include "core/layout/LayoutView.h"
 | 
|  #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h"
 | 
|  #include "core/loader/FrameLoader.h"
 | 
| +#include "core/loader/FrameLoaderClient.h"
 | 
|  #include "platform/ContentType.h"
 | 
|  #include "platform/Logging.h"
 | 
|  #include "platform/MIMETypeFromURL.h"
 | 
|  #include "platform/MIMETypeRegistry.h"
 | 
|  #include "platform/RuntimeEnabledFeatures.h"
 | 
|  #include "platform/UserGestureIndicator.h"
 | 
| +#include "platform/audio/AudioBus.h"
 | 
| +#include "platform/audio/AudioSourceProviderClient.h"
 | 
|  #include "platform/graphics/GraphicsLayer.h"
 | 
|  #include "platform/weborigin/SecurityOrigin.h"
 | 
|  #include "public/platform/Platform.h"
 | 
| +#include "public/platform/WebAudioSourceProvider.h"
 | 
|  #include "public/platform/WebContentDecryptionModule.h"
 | 
|  #include "public/platform/WebInbandTextTrack.h"
 | 
|  #include "wtf/CurrentTime.h"
 | 
| @@ -331,7 +335,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
 | 
|      , m_deferredLoadState(NotDeferred)
 | 
|      , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired)
 | 
|      , m_webLayer(nullptr)
 | 
| -    , m_preload(MediaPlayer::Auto)
 | 
| +    , m_preload(WebMediaPlayer::PreloadAuto)
 | 
|      , m_displayMode(Unknown)
 | 
|      , m_cachedTime(std::numeric_limits<double>::quiet_NaN())
 | 
|      , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN())
 | 
| @@ -487,10 +491,10 @@ void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument)
 | 
|      if (m_shouldDelayLoadEvent) {
 | 
|          document().incrementLoadEventDelayCount();
 | 
|          // Note: Keeping the load event delay count increment on oldDocument that was added
 | 
| -        // when m_shouldDelayLoadEvent was set so that destruction of m_player can not
 | 
| +        // when m_shouldDelayLoadEvent was set so that destruction of m_webMediaPlayer can not
 | 
|          // cause load event dispatching in oldDocument.
 | 
|      } else {
 | 
| -        // Incrementing the load event delay count so that destruction of m_player can not
 | 
| +        // Incrementing the load event delay count so that destruction of m_webMediaPlayer can not
 | 
|          // cause load event dispatching in oldDocument.
 | 
|          oldDocument.incrementLoadEventDelayCount();
 | 
|      }
 | 
| @@ -505,7 +509,7 @@ void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument)
 | 
|      // document changes so that playback can be resumed properly.
 | 
|      userCancelledLoad();
 | 
|  
 | 
| -    // Decrement the load event delay count on oldDocument now that m_player has been destroyed
 | 
| +    // Decrement the load event delay count on oldDocument now that m_webMediaPlayer has been destroyed
 | 
|      // and there is no risk of dispatching a load event from within the destructor.
 | 
|      oldDocument.decrementLoadEventDelayCount();
 | 
|  
 | 
| @@ -539,19 +543,18 @@ void HTMLMediaElement::parseAttribute(const QualifiedName& name, const AtomicStr
 | 
|          configureMediaControls();
 | 
|      } else if (name == preloadAttr) {
 | 
|          if (equalIgnoringCase(value, "none")) {
 | 
| -            m_preload = MediaPlayer::None;
 | 
| +            m_preload = WebMediaPlayer::PreloadNone;
 | 
|          } else if (equalIgnoringCase(value, "metadata")) {
 | 
| -            m_preload = MediaPlayer::MetaData;
 | 
| +            m_preload = WebMediaPlayer::PreloadMetaData;
 | 
|          } else {
 | 
|              // The spec does not define an "invalid value default" but "auto" is suggested as the
 | 
|              // "missing value default", so use it for everything except "none" and "metadata"
 | 
| -            m_preload = MediaPlayer::Auto;
 | 
| +            m_preload = WebMediaPlayer::PreloadAuto;
 | 
|          }
 | 
|  
 | 
|          // The attribute must be ignored if the autoplay attribute is present
 | 
| -        if (m_player)
 | 
| +        if (m_webMediaPlayer)
 | 
|              setPlayerPreload();
 | 
| -
 | 
|      } else if (name == mediagroupAttr && RuntimeEnabledFeatures::mediaControllerEnabled()) {
 | 
|          setMediaGroup(value);
 | 
|      } else {
 | 
| @@ -995,7 +998,7 @@ void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c
 | 
|      if (attemptLoad && canLoadURL(url, contentType, keySystem)) {
 | 
|          ASSERT(!webMediaPlayer());
 | 
|  
 | 
| -        if (!m_havePreparedToPlay && !autoplay() && m_preload == MediaPlayer::None) {
 | 
| +        if (!m_havePreparedToPlay && !autoplay() && m_preload == WebMediaPlayer::PreloadNone) {
 | 
|              WTF_LOG(Media, "HTMLMediaElement::loadResource(%p) : Delaying load because preload == 'none'", this);
 | 
|              deferLoad();
 | 
|          } else {
 | 
| @@ -1034,14 +1037,14 @@ void HTMLMediaElement::startPlayerLoad()
 | 
|      if (!requestURL.pass().isEmpty())
 | 
|          requestURL.setPass(String());
 | 
|  
 | 
| -    m_player->load(loadType(), requestURL, corsMode());
 | 
| +    prepareAndLoadMediaPlayer(requestURL);
 | 
|  }
 | 
|  
 | 
|  void HTMLMediaElement::setPlayerPreload()
 | 
|  {
 | 
| -    m_player->setPreload(effectivePreloadType());
 | 
| +    m_webMediaPlayer->setPreload(effectivePreloadType());
 | 
|  
 | 
| -    if (loadIsDeferred() && m_preload != MediaPlayer::None)
 | 
| +    if (loadIsDeferred() && m_preload != WebMediaPlayer::PreloadNone)
 | 
|          startDeferredLoad();
 | 
|  }
 | 
|  
 | 
| @@ -1305,7 +1308,7 @@ void HTMLMediaElement::cancelPendingEventsAndCallbacks()
 | 
|          source->cancelPendingErrorEvent();
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerNetworkStateChanged()
 | 
| +void HTMLMediaElement::networkStateChanged()
 | 
|  {
 | 
|      setNetworkState(webMediaPlayer()->networkState());
 | 
|  }
 | 
| @@ -1396,7 +1399,6 @@ void HTMLMediaElement::setNetworkState(WebMediaPlayer::NetworkState state)
 | 
|  
 | 
|  void HTMLMediaElement::changeNetworkStateFromLoadingToIdle()
 | 
|  {
 | 
| -    ASSERT(m_player);
 | 
|      m_progressEventTimer.stop();
 | 
|  
 | 
|      // Schedule one last progress event so we guarantee that at least one is fired
 | 
| @@ -1407,7 +1409,7 @@ void HTMLMediaElement::changeNetworkStateFromLoadingToIdle()
 | 
|      m_networkState = NETWORK_IDLE;
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerReadyStateChanged()
 | 
| +void HTMLMediaElement::readyStateChanged()
 | 
|  {
 | 
|      setReadyState(static_cast<ReadyState>(webMediaPlayer()->readyState()));
 | 
|  }
 | 
| @@ -1562,7 +1564,6 @@ void HTMLMediaElement::setReadyState(ReadyState state)
 | 
|  
 | 
|  void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*)
 | 
|  {
 | 
| -    ASSERT(m_player);
 | 
|      if (m_networkState != NETWORK_LOADING)
 | 
|          return;
 | 
|  
 | 
| @@ -1615,7 +1616,7 @@ void HTMLMediaElement::seek(double time)
 | 
|          return;
 | 
|  
 | 
|      // If the media engine has been told to postpone loading data, let it go ahead now.
 | 
| -    if (m_preload < MediaPlayer::Auto && m_readyState < HAVE_FUTURE_DATA)
 | 
| +    if (m_preload < WebMediaPlayer::PreloadAuto && m_readyState < HAVE_FUTURE_DATA)
 | 
|          prepareToPlay();
 | 
|  
 | 
|      // Get the current time before setting m_seeking, m_lastSeekTime is returned once it is set.
 | 
| @@ -1789,10 +1790,10 @@ void HTMLMediaElement::setCurrentTime(double time, ExceptionState& exceptionStat
 | 
|  
 | 
|  double HTMLMediaElement::duration() const
 | 
|  {
 | 
| -    // FIXME: remove m_player check once we figure out how m_player is going
 | 
| -    // out of sync with readystate. m_player is cleared but readystate is not set
 | 
| -    // to HAVE_NOTHING
 | 
| -    if (!m_player || m_readyState < HAVE_METADATA)
 | 
| +    // FIXME: remove m_webMediaPlayer check once we figure out how
 | 
| +    // m_webMediaPlayer is going out of sync with readystate.
 | 
| +    // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING.
 | 
| +    if (!m_webMediaPlayer || m_readyState < HAVE_METADATA)
 | 
|          return std::numeric_limits<double>::quiet_NaN();
 | 
|  
 | 
|      // FIXME: Refactor so m_duration is kept current (in both MSE and
 | 
| @@ -1861,7 +1862,10 @@ HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::directionOfPlayback() co
 | 
|  void HTMLMediaElement::updatePlaybackRate()
 | 
|  {
 | 
|      double effectiveRate = effectivePlaybackRate();
 | 
| -    if (m_player && potentiallyPlaying())
 | 
| +    // FIXME: remove m_webMediaPlayer check once we figure out how
 | 
| +    // m_webMediaPlayer is going out of sync with readystate.
 | 
| +    // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING.
 | 
| +    if (m_webMediaPlayer && potentiallyPlaying())
 | 
|          webMediaPlayer()->setRate(effectiveRate);
 | 
|  }
 | 
|  
 | 
| @@ -1881,13 +1885,13 @@ bool HTMLMediaElement::autoplay() const
 | 
|  String HTMLMediaElement::preload() const
 | 
|  {
 | 
|      switch (m_preload) {
 | 
| -    case MediaPlayer::None:
 | 
| +    case WebMediaPlayer::PreloadNone:
 | 
|          return "none";
 | 
|          break;
 | 
| -    case MediaPlayer::MetaData:
 | 
| +    case WebMediaPlayer::PreloadMetaData:
 | 
|          return "metadata";
 | 
|          break;
 | 
| -    case MediaPlayer::Auto:
 | 
| +    case WebMediaPlayer::PreloadAuto:
 | 
|          return "auto";
 | 
|          break;
 | 
|      }
 | 
| @@ -1902,9 +1906,9 @@ void HTMLMediaElement::setPreload(const AtomicString& preload)
 | 
|      setAttribute(preloadAttr, preload);
 | 
|  }
 | 
|  
 | 
| -MediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const
 | 
| +WebMediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const
 | 
|  {
 | 
| -    return autoplay() ? MediaPlayer::Auto : m_preload;
 | 
| +    return autoplay() ? WebMediaPlayer::PreloadAuto : m_preload;
 | 
|  }
 | 
|  
 | 
|  void HTMLMediaElement::play()
 | 
| @@ -1929,7 +1933,7 @@ void HTMLMediaElement::playInternal()
 | 
|      WTF_LOG(Media, "HTMLMediaElement::playInternal(%p)", this);
 | 
|  
 | 
|      // 4.8.10.9. Playing the media resource
 | 
| -    if (!m_player || m_networkState == NETWORK_EMPTY)
 | 
| +    if (m_networkState == NETWORK_EMPTY)
 | 
|          scheduleDelayedAction(LoadMediaResource);
 | 
|  
 | 
|      // Generally "ended" and "looping" are exclusive. Here, the loop attribute
 | 
| @@ -1989,7 +1993,7 @@ void HTMLMediaElement::pause()
 | 
|  {
 | 
|      WTF_LOG(Media, "HTMLMediaElement::pause(%p)", this);
 | 
|  
 | 
| -    if (!m_player || m_networkState == NETWORK_EMPTY)
 | 
| +    if (m_networkState == NETWORK_EMPTY)
 | 
|          scheduleDelayedAction(LoadMediaResource);
 | 
|  
 | 
|      m_autoplaying = false;
 | 
| @@ -2134,8 +2138,6 @@ void HTMLMediaElement::startPlaybackProgressTimer()
 | 
|  
 | 
|  void HTMLMediaElement::playbackProgressTimerFired(Timer<HTMLMediaElement>*)
 | 
|  {
 | 
| -    ASSERT(m_player);
 | 
| -
 | 
|      if (!std::isnan(m_fragmentEndTime) && currentTime() >= m_fragmentEndTime && directionOfPlayback() == Forward) {
 | 
|          m_fragmentEndTime = std::numeric_limits<double>::quiet_NaN();
 | 
|          if (!m_mediaController && !m_paused) {
 | 
| @@ -2230,11 +2232,11 @@ void HTMLMediaElement::audioTracksTimerFired(Timer<HTMLMediaElement>*)
 | 
|      webMediaPlayer()->enabledAudioTracksChanged(enabledTrackIds);
 | 
|  }
 | 
|  
 | 
| -WebMediaPlayer::TrackId HTMLMediaElement::addAudioTrack(const String& id, WebMediaPlayerClient::AudioTrackKind kind, const AtomicString& label, const AtomicString& language, bool enabled)
 | 
| +WebMediaPlayer::TrackId HTMLMediaElement::addAudioTrack(const WebString& id, blink::WebMediaPlayerClient::AudioTrackKind kind, const WebString& label, const WebString& language, bool enabled)
 | 
|  {
 | 
|      AtomicString kindString = AudioKindToString(kind);
 | 
|      WTF_LOG(Media, "HTMLMediaElement::addAudioTrack(%p, '%s', '%s', '%s', '%s', %d)",
 | 
| -        this, id.ascii().data(), kindString.ascii().data(), label.ascii().data(), language.ascii().data(), enabled);
 | 
| +        this, id.latin1().data(), kindString.ascii().data(), label.latin1().data(), language.latin1().data(), enabled);
 | 
|  
 | 
|      if (!RuntimeEnabledFeatures::audioVideoTracksEnabled())
 | 
|          return 0;
 | 
| @@ -2274,11 +2276,11 @@ void HTMLMediaElement::selectedVideoTrackChanged(WebMediaPlayer::TrackId* select
 | 
|      webMediaPlayer()->selectedVideoTrackChanged(selectedTrackId);
 | 
|  }
 | 
|  
 | 
| -WebMediaPlayer::TrackId HTMLMediaElement::addVideoTrack(const String& id, WebMediaPlayerClient::VideoTrackKind kind, const AtomicString& label, const AtomicString& language, bool selected)
 | 
| +WebMediaPlayer::TrackId HTMLMediaElement::addVideoTrack(const WebString& id, blink::WebMediaPlayerClient::VideoTrackKind kind, const WebString& label, const WebString& language, bool selected)
 | 
|  {
 | 
|      AtomicString kindString = VideoKindToString(kind);
 | 
|      WTF_LOG(Media, "HTMLMediaElement::addVideoTrack(%p, '%s', '%s', '%s', '%s', %d)",
 | 
| -        this, id.ascii().data(), kindString.ascii().data(), label.ascii().data(), language.ascii().data(), selected);
 | 
| +        this, id.latin1().data(), kindString.ascii().data(), label.latin1().data(), language.latin1().data(), selected);
 | 
|  
 | 
|      if (!RuntimeEnabledFeatures::audioVideoTracksEnabled())
 | 
|          return 0;
 | 
| @@ -2303,7 +2305,7 @@ void HTMLMediaElement::removeVideoTrack(WebMediaPlayer::TrackId trackId)
 | 
|      videoTracks().remove(trackId);
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerDidAddTextTrack(WebInbandTextTrack* webTrack)
 | 
| +void HTMLMediaElement::addTextTrack(WebInbandTextTrack* webTrack)
 | 
|  {
 | 
|      // 4.8.10.12.2 Sourcing in-band text tracks
 | 
|      // 1. Associate the relevant data with a new text track and its corresponding new TextTrack object.
 | 
| @@ -2332,10 +2334,10 @@ void HTMLMediaElement::mediaPlayerDidAddTextTrack(WebInbandTextTrack* webTrack)
 | 
|      // 9. Fire an event with the name addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent
 | 
|      // interface, with the track attribute initialized to the text track's TextTrack object, at the media element's
 | 
|      // textTracks attribute's TextTrackList object.
 | 
| -    addTextTrack(textTrack.get());
 | 
| +    mediaPlayerAddTextTrack(textTrack.get());
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerDidRemoveTextTrack(WebInbandTextTrack* webTrack)
 | 
| +void HTMLMediaElement::removeTextTrack(WebInbandTextTrack* webTrack)
 | 
|  {
 | 
|      if (!m_textTracks)
 | 
|          return;
 | 
| @@ -2346,7 +2348,7 @@ void HTMLMediaElement::mediaPlayerDidRemoveTextTrack(WebInbandTextTrack* webTrac
 | 
|      if (!textTrack)
 | 
|          return;
 | 
|  
 | 
| -    removeTextTrack(textTrack.get());
 | 
| +    mediaPlayerRemoveTextTrack(textTrack.get());
 | 
|  }
 | 
|  
 | 
|  void HTMLMediaElement::textTracksChanged()
 | 
| @@ -2355,14 +2357,14 @@ void HTMLMediaElement::textTracksChanged()
 | 
|          mediaControls()->refreshClosedCaptionsButtonVisibility();
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::addTextTrack(TextTrack* track)
 | 
| +void HTMLMediaElement::mediaPlayerAddTextTrack(TextTrack* track)
 | 
|  {
 | 
|      textTracks()->append(track);
 | 
|  
 | 
|      textTracksChanged();
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::removeTextTrack(TextTrack* track)
 | 
| +void HTMLMediaElement::mediaPlayerRemoveTextTrack(TextTrack* track)
 | 
|  {
 | 
|      m_textTracks->remove(track);
 | 
|  
 | 
| @@ -2408,7 +2410,7 @@ PassRefPtrWillBeRawPtr<TextTrack> HTMLMediaElement::addTextTrack(const AtomicStr
 | 
|      //    interface, with the track attribute initialised to the new text
 | 
|      //    track's TextTrack object, at the media element's textTracks
 | 
|      //    attribute's TextTrackList object.
 | 
| -    addTextTrack(textTrack.get());
 | 
| +    mediaPlayerAddTextTrack(textTrack.get());
 | 
|  
 | 
|      // Note: Due to side effects when changing track parameters, we have to
 | 
|      // first append the track to the text track list.
 | 
| @@ -2441,7 +2443,7 @@ void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement)
 | 
|      if (!textTrack)
 | 
|          return;
 | 
|  
 | 
| -    addTextTrack(textTrack.get());
 | 
| +    mediaPlayerAddTextTrack(textTrack.get());
 | 
|  
 | 
|      // Do not schedule the track loading until parsing finishes so we don't start before all tracks
 | 
|      // in the markup have been added.
 | 
| @@ -2469,7 +2471,7 @@ void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement)
 | 
|      // When a track element's parent element changes and the old parent was a media element,
 | 
|      // then the user agent must remove the track element's corresponding text track from the
 | 
|      // media element's list of text tracks.
 | 
| -    removeTextTrack(textTrack.get());
 | 
| +    mediaPlayerRemoveTextTrack(textTrack.get());
 | 
|  
 | 
|      size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack.get());
 | 
|      if (index != kNotFound)
 | 
| @@ -2676,7 +2678,7 @@ void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement* source)
 | 
|      }
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerTimeChanged()
 | 
| +void HTMLMediaElement::timeChanged()
 | 
|  {
 | 
|      WTF_LOG(Media, "HTMLMediaElement::mediaPlayerTimeChanged(%p)", this);
 | 
|  
 | 
| @@ -2729,19 +2731,19 @@ void HTMLMediaElement::mediaPlayerTimeChanged()
 | 
|      updatePlayState();
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerDurationChanged()
 | 
| +void HTMLMediaElement::durationChanged()
 | 
|  {
 | 
| -    WTF_LOG(Media, "HTMLMediaElement::mediaPlayerDurationChanged(%p)", this);
 | 
| -    // FIXME: Change MediaPlayerClient & WebMediaPlayer to convey
 | 
| -    // the currentTime when the duration change occured. The current
 | 
| -    // WebMediaPlayer implementations always clamp currentTime() to
 | 
| -    // duration() so the requestSeek condition here is always false.
 | 
| -    durationChanged(duration(), currentTime() > duration());
 | 
| +    WTF_LOG(Media, "HTMLMediaElement::durationChanged(%p)", this);
 | 
| +    // FIXME: Change WebMediaPlayer to convey the currentTime
 | 
| +    // when the duration change occured. The current WebMediaPlayer
 | 
| +    // implementations always clamp currentTime() to duration()
 | 
| +    // so the requestSeek condition here is always false.
 | 
| +    mediaPlayerDurationChanged(duration(), currentTime() > duration());
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::durationChanged(double duration, bool requestSeek)
 | 
| +void HTMLMediaElement::mediaPlayerDurationChanged(double duration, bool requestSeek)
 | 
|  {
 | 
| -    WTF_LOG(Media, "HTMLMediaElement::durationChanged(%p, %f, %d)", this, duration, requestSeek);
 | 
| +    WTF_LOG(Media, "HTMLMediaElement::mediaPlayerDurationChanged(%p, %f, %d)", this, duration, requestSeek);
 | 
|  
 | 
|      // Abort if duration unchanged.
 | 
|      if (m_duration == duration)
 | 
| @@ -2760,7 +2762,7 @@ void HTMLMediaElement::durationChanged(double duration, bool requestSeek)
 | 
|          seek(duration);
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerPlaybackStateChanged()
 | 
| +void HTMLMediaElement::playbackStateChanged()
 | 
|  {
 | 
|      WTF_LOG(Media, "HTMLMediaElement::mediaPlayerPlaybackStateChanged(%p)", this);
 | 
|  
 | 
| @@ -2816,7 +2818,7 @@ void HTMLMediaElement::disconnectedFromRemoteDevice()
 | 
|  }
 | 
|  
 | 
|  // MediaPlayerPresentation methods
 | 
| -void HTMLMediaElement::mediaPlayerRepaint()
 | 
| +void HTMLMediaElement::repaint()
 | 
|  {
 | 
|      if (m_webLayer)
 | 
|          m_webLayer->invalidate();
 | 
| @@ -2826,7 +2828,7 @@ void HTMLMediaElement::mediaPlayerRepaint()
 | 
|          layoutObject()->setShouldDoFullPaintInvalidation();
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerSizeChanged()
 | 
| +void HTMLMediaElement::sizeChanged()
 | 
|  {
 | 
|      WTF_LOG(Media, "HTMLMediaElement::mediaPlayerSizeChanged(%p)", this);
 | 
|  
 | 
| @@ -2891,7 +2893,7 @@ bool HTMLMediaElement::couldPlayIfEnoughData() const
 | 
|  bool HTMLMediaElement::endedPlayback(LoopCondition loopCondition) const
 | 
|  {
 | 
|      double dur = duration();
 | 
| -    if (!m_player || std::isnan(dur))
 | 
| +    if (std::isnan(dur))
 | 
|          return false;
 | 
|  
 | 
|      // 4.8.10.8 Playing the media resource
 | 
| @@ -2927,9 +2929,6 @@ bool HTMLMediaElement::stoppedDueToErrors() const
 | 
|  
 | 
|  void HTMLMediaElement::updatePlayState()
 | 
|  {
 | 
| -    if (!m_player)
 | 
| -        return;
 | 
| -
 | 
|      bool isPlaying = webMediaPlayer() && !webMediaPlayer()->paused();
 | 
|      bool shouldBePlaying = potentiallyPlaying();
 | 
|  
 | 
| @@ -3020,7 +3019,7 @@ void HTMLMediaElement::userCancelledLoad()
 | 
|      // 6 - Abort the overall resource selection algorithm.
 | 
|      m_currentSourceNode = nullptr;
 | 
|  
 | 
| -    // Reset m_readyState since m_player is gone.
 | 
| +    // Reset m_readyState since m_webMediaPlayer is gone.
 | 
|      m_readyState = HAVE_NOTHING;
 | 
|      invalidateCachedTime();
 | 
|      updateMediaController();
 | 
| @@ -3033,7 +3032,7 @@ void HTMLMediaElement::clearMediaPlayerAndAudioSourceProviderClientWithoutLockin
 | 
|      if (audioSourceProvider())
 | 
|          audioSourceProvider()->setClient(0);
 | 
|  #endif
 | 
| -    m_player.clear();
 | 
| +    m_webMediaPlayer.clear(); // Revisit
 | 
|  }
 | 
|  
 | 
|  void HTMLMediaElement::clearMediaPlayer(int flags)
 | 
| @@ -3241,7 +3240,7 @@ void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
 | 
|  {
 | 
|      WTF_LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%p, %s)", this, boolString(closedCaptionVisible));
 | 
|  
 | 
| -    if (!m_player || !hasClosedCaptions())
 | 
| +    if (!hasClosedCaptions())
 | 
|          return;
 | 
|  
 | 
|      m_closedCaptionsVisible = closedCaptionVisible;
 | 
| @@ -3423,18 +3422,9 @@ void HTMLMediaElement::createMediaPlayer()
 | 
|  
 | 
|      closeMediaSource();
 | 
|  
 | 
| -    m_player = MediaPlayer::create(this);
 | 
| -
 | 
|      // We haven't yet found out if any remote routes are available.
 | 
|      m_remoteRoutesAvailable = false;
 | 
|      m_playingRemotely = false;
 | 
| -
 | 
| -#if ENABLE(WEB_AUDIO)
 | 
| -    if (m_audioSourceNode && audioSourceProvider()) {
 | 
| -        // When creating the player, make sure its AudioSourceProvider knows about the client.
 | 
| -        audioSourceProvider()->setClient(m_audioSourceNode);
 | 
| -    }
 | 
| -#endif
 | 
|  }
 | 
|  
 | 
|  #if ENABLE(WEB_AUDIO)
 | 
| @@ -3450,8 +3440,8 @@ void HTMLMediaElement::setAudioSourceNode(AudioSourceProviderClient* sourceNode)
 | 
|  
 | 
|  AudioSourceProvider* HTMLMediaElement::audioSourceProvider()
 | 
|  {
 | 
| -    if (m_player)
 | 
| -        return m_player->audioSourceProvider();
 | 
| +    if (m_webMediaPlayer)
 | 
| +        return &m_audioSourceProvider;
 | 
|  
 | 
|      return nullptr;
 | 
|  }
 | 
| @@ -3566,7 +3556,7 @@ WebMediaPlayer::CORSMode HTMLMediaElement::corsMode() const
 | 
|      return WebMediaPlayer::CORSModeAnonymous;
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerSetWebLayer(WebLayer* webLayer)
 | 
| +void HTMLMediaElement::setWebLayer(blink::WebLayer* webLayer)
 | 
|  {
 | 
|      if (webLayer == m_webLayer)
 | 
|          return;
 | 
| @@ -3586,7 +3576,7 @@ void HTMLMediaElement::mediaPlayerSetWebLayer(WebLayer* webLayer)
 | 
|          GraphicsLayer::registerContentsLayer(m_webLayer);
 | 
|  }
 | 
|  
 | 
| -void HTMLMediaElement::mediaPlayerMediaSourceOpened(WebMediaSource* webMediaSource)
 | 
| +void HTMLMediaElement::mediaSourceOpened(blink::WebMediaSource* webMediaSource)
 | 
|  {
 | 
|      m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource));
 | 
|  }
 | 
| @@ -3657,12 +3647,98 @@ void HTMLMediaElement::selectInitialTracksIfNecessary()
 | 
|          videoTracks().anonymousIndexedGetter(0)->setSelected(true);
 | 
|  }
 | 
|  
 | 
| +void HTMLMediaElement::prepareAndLoadMediaPlayer(const WTF::String& url)
 | 
| +{
 | 
| +    ASSERT(!m_webMediaPlayer);
 | 
| +
 | 
| +    WebURL poster = mediaPlayerPosterURL();
 | 
| +
 | 
| +    KURL kurl(ParsedURLString, url);
 | 
| +    LocalFrame* frame = document().frame();
 | 
| +    ASSERT(frame);
 | 
| +    m_webMediaPlayer = frame->loader().client()->createWebMediaPlayer(this, kurl);
 | 
| +    if (!m_webMediaPlayer)
 | 
| +        return;
 | 
| +
 | 
| +#if ENABLE(WEB_AUDIO)
 | 
| +    // Make sure if we create/re-create the WebMediaPlayer that we update our wrapper.
 | 
| +    m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider());
 | 
| +#endif
 | 
| +    m_webMediaPlayer->setVolume(effectiveMediaVolume());
 | 
| +
 | 
| +    m_webMediaPlayer->setPoster(poster);
 | 
| +
 | 
| +    m_webMediaPlayer->setPreload(effectivePreloadType());
 | 
| +
 | 
| +    m_webMediaPlayer->load(loadType(), kurl, corsMode());
 | 
| +
 | 
| +    if (isFullscreen())
 | 
| +        m_webMediaPlayer->enterFullscreen();
 | 
| +}
 | 
| +
 | 
|  #if ENABLE(WEB_AUDIO)
 | 
|  void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
 | 
|  {
 | 
|      if (!visitor->isHeapObjectAlive(m_audioSourceNode) && audioSourceProvider())
 | 
|          audioSourceProvider()->setClient(nullptr);
 | 
|  }
 | 
| +
 | 
| +void HTMLMediaElement::AudioSourceProviderImpl::wrap(WebAudioSourceProvider* provider)
 | 
| +{
 | 
| +    MutexLocker locker(provideInputLock);
 | 
| +
 | 
| +    if (m_webAudioSourceProvider && provider != m_webAudioSourceProvider)
 | 
| +        m_webAudioSourceProvider->setClient(0);
 | 
| +
 | 
| +    m_webAudioSourceProvider = provider;
 | 
| +    if (m_webAudioSourceProvider)
 | 
| +        m_webAudioSourceProvider->setClient(m_client.get());
 | 
| +}
 | 
| +
 | 
| +void HTMLMediaElement::AudioSourceProviderImpl::setClient(AudioSourceProviderClient* client)
 | 
| +{
 | 
| +    MutexLocker locker(provideInputLock);
 | 
| +
 | 
| +    if (client)
 | 
| +        m_client = new HTMLMediaElement::AudioClientImpl(client);
 | 
| +    else
 | 
| +        m_client.clear();
 | 
| +
 | 
| +    if (m_webAudioSourceProvider)
 | 
| +        m_webAudioSourceProvider->setClient(m_client.get());
 | 
| +}
 | 
| +
 | 
| +void HTMLMediaElement::AudioSourceProviderImpl::provideInput(blink::AudioBus* bus, size_t framesToProcess)
 | 
| +{
 | 
| +    ASSERT(bus);
 | 
| +    if (!bus)
 | 
| +        return;
 | 
| +
 | 
| +    MutexTryLocker tryLocker(provideInputLock);
 | 
| +    if (!tryLocker.locked() || !m_webAudioSourceProvider || !m_client.get()) {
 | 
| +        bus->zero();
 | 
| +        return;
 | 
| +    }
 | 
| +
 | 
| +    // Wrap the AudioBus channel data using WebVector.
 | 
| +    size_t n = bus->numberOfChannels();
 | 
| +    WebVector<float*> webAudioData(n);
 | 
| +    for (size_t i = 0; i < n; ++i)
 | 
| +        webAudioData[i] = bus->channel(i)->mutableData();
 | 
| +
 | 
| +    m_webAudioSourceProvider->provideInput(webAudioData, framesToProcess);
 | 
| +}
 | 
| +
 | 
| +void HTMLMediaElement::AudioClientImpl::setFormat(size_t numberOfChannels, float sampleRate)
 | 
| +{
 | 
| +    if (m_client)
 | 
| +        m_client->setFormat(numberOfChannels, sampleRate);
 | 
| +}
 | 
| +
 | 
| +DEFINE_TRACE(HTMLMediaElement::AudioClientImpl)
 | 
| +{
 | 
| +    visitor->trace(m_client);
 | 
| +}
 | 
|  #endif
 | 
|  
 | 
|  }
 | 
| 
 |