Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "WebMediaPlayerClientImpl.h" | 6 #include "WebMediaPlayerClientImpl.h" |
| 7 | 7 |
| 8 #include "WebDocument.h" | 8 #include "WebDocument.h" |
| 9 #include "WebFrameClient.h" | 9 #include "WebFrameClient.h" |
| 10 #include "WebFrameImpl.h" | 10 #include "WebFrameImpl.h" |
| 11 #include "WebHelperPlugin.h" | 11 #include "WebHelperPlugin.h" |
| 12 #include "WebViewImpl.h" | 12 #include "WebViewImpl.h" |
| 13 #include "core/frame/Frame.h" | 13 #include "core/frame/Frame.h" |
| 14 #include "core/html/HTMLMediaElement.h" | 14 #include "core/html/HTMLMediaElement.h" |
| 15 #include "core/html/TimeRanges.h" | 15 #include "core/html/TimeRanges.h" |
| 16 #include "core/rendering/RenderLayerCompositor.h" | 16 #include "core/rendering/RenderLayerCompositor.h" |
| 17 #include "core/rendering/RenderView.h" | 17 #include "core/rendering/RenderView.h" |
| 18 #include "modules/encryptedMedia/HTMLMediaElementEncryptedMedia.h" | |
| 19 #include "modules/encryptedMedia/MediaKeyNeededEvent.h" | |
| 18 #include "modules/mediastream/MediaStreamRegistry.h" | 20 #include "modules/mediastream/MediaStreamRegistry.h" |
| 19 #include "platform/audio/AudioBus.h" | 21 #include "platform/audio/AudioBus.h" |
| 20 #include "platform/audio/AudioSourceProviderClient.h" | 22 #include "platform/audio/AudioSourceProviderClient.h" |
| 21 #include "platform/geometry/IntSize.h" | 23 #include "platform/geometry/IntSize.h" |
| 22 #include "platform/graphics/GraphicsContext.h" | 24 #include "platform/graphics/GraphicsContext.h" |
| 23 #include "platform/graphics/GraphicsLayer.h" | 25 #include "platform/graphics/GraphicsLayer.h" |
| 24 #include "platform/graphics/gpu/Extensions3DUtil.h" | 26 #include "platform/graphics/gpu/Extensions3DUtil.h" |
| 25 #include "platform/graphics/skia/GaneshUtils.h" | 27 #include "platform/graphics/skia/GaneshUtils.h" |
| 26 #include "public/platform/Platform.h" | 28 #include "public/platform/Platform.h" |
| 27 #include "public/platform/WebAudioSourceProvider.h" | 29 #include "public/platform/WebAudioSourceProvider.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 53 | 55 |
| 54 static PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(WebMediaPlayerClient* cli ent, const WebURL& url, Frame* frame) | 56 static PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(WebMediaPlayerClient* cli ent, const WebURL& url, Frame* frame) |
| 55 { | 57 { |
| 56 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame); | 58 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame); |
| 57 | 59 |
| 58 if (!webFrame->client()) | 60 if (!webFrame->client()) |
| 59 return nullptr; | 61 return nullptr; |
| 60 return adoptPtr(webFrame->client()->createMediaPlayer(webFrame, url, client) ); | 62 return adoptPtr(webFrame->client()->createMediaPlayer(webFrame, url, client) ); |
| 61 } | 63 } |
| 62 | 64 |
| 63 WebMediaPlayer* WebMediaPlayerClientImpl::mediaPlayer() const | 65 WebMediaPlayer* WebMediaPlayerClientImpl::webMediaPlayer() const |
| 64 { | 66 { |
| 65 return m_webMediaPlayer.get(); | 67 return m_webMediaPlayer.get(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 // WebMediaPlayerClient -------------------------------------------------------- | 70 // WebMediaPlayerClient -------------------------------------------------------- |
| 69 | 71 |
| 70 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl() | 72 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl() |
| 71 { | 73 { |
| 74 HTMLMediaElementEncryptedMedia::playerDestroyed(mediaElement()); | |
| 75 | |
| 72 // Explicitly destroy the WebMediaPlayer to allow verification of tear down. | 76 // Explicitly destroy the WebMediaPlayer to allow verification of tear down. |
| 73 m_webMediaPlayer.clear(); | 77 m_webMediaPlayer.clear(); |
| 74 | 78 |
| 75 // Ensure the m_webMediaPlayer destroyed any WebHelperPlugin used. | 79 // Ensure the m_webMediaPlayer destroyed any WebHelperPlugin used. |
| 76 ASSERT(!m_helperPlugin); | 80 ASSERT(!m_helperPlugin); |
| 77 } | 81 } |
| 78 | 82 |
| 79 void WebMediaPlayerClientImpl::networkStateChanged() | 83 void WebMediaPlayerClientImpl::networkStateChanged() |
| 80 { | 84 { |
| 81 m_client->mediaPlayerNetworkStateChanged(); | 85 m_client->mediaPlayerNetworkStateChanged(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 m_client->mediaPlayerPlaybackStateChanged(); | 125 m_client->mediaPlayerPlaybackStateChanged(); |
| 122 } | 126 } |
| 123 | 127 |
| 124 WebMediaPlayer::Preload WebMediaPlayerClientImpl::preload() const | 128 WebMediaPlayer::Preload WebMediaPlayerClientImpl::preload() const |
| 125 { | 129 { |
| 126 return static_cast<WebMediaPlayer::Preload>(m_preload); | 130 return static_cast<WebMediaPlayer::Preload>(m_preload); |
| 127 } | 131 } |
| 128 | 132 |
| 129 void WebMediaPlayerClientImpl::keyAdded(const WebString& keySystem, const WebStr ing& sessionId) | 133 void WebMediaPlayerClientImpl::keyAdded(const WebString& keySystem, const WebStr ing& sessionId) |
| 130 { | 134 { |
| 131 m_client->mediaPlayerKeyAdded(keySystem, sessionId); | 135 HTMLMediaElementEncryptedMedia::keyAdded(mediaElement(), keySystem, sessionI d); |
| 132 } | 136 } |
| 133 | 137 |
| 134 void WebMediaPlayerClientImpl::keyError(const WebString& keySystem, const WebStr ing& sessionId, MediaKeyErrorCode errorCode, unsigned short systemCode) | 138 void WebMediaPlayerClientImpl::keyError(const WebString& keySystem, const WebStr ing& sessionId, MediaKeyErrorCode errorCode, unsigned short systemCode) |
| 135 { | 139 { |
| 136 m_client->mediaPlayerKeyError(keySystem, sessionId, static_cast<MediaPlayerC lient::MediaKeyErrorCode>(errorCode), systemCode); | 140 HTMLMediaElementEncryptedMedia::keyError(mediaElement(), keySystem, sessionI d, errorCode, systemCode); |
| 137 } | 141 } |
| 138 | 142 |
| 139 void WebMediaPlayerClientImpl::keyMessage(const WebString& keySystem, const WebS tring& sessionId, const unsigned char* message, unsigned messageLength, const We bURL& defaultURL) | 143 void WebMediaPlayerClientImpl::keyMessage(const WebString& keySystem, const WebS tring& sessionId, const unsigned char* message, unsigned messageLength, const We bURL& defaultURL) |
| 140 { | 144 { |
| 141 m_client->mediaPlayerKeyMessage(keySystem, sessionId, message, messageLength , defaultURL); | 145 HTMLMediaElementEncryptedMedia::keyMessage(mediaElement(), keySystem, sessio nId, message, messageLength, defaultURL); |
| 142 } | 146 } |
| 143 | 147 |
| 144 void WebMediaPlayerClientImpl::keyNeeded(const WebString& contentType, const uns igned char* initData, unsigned initDataLength) | 148 void WebMediaPlayerClientImpl::keyNeeded(const WebString& contentType, const uns igned char* initData, unsigned initDataLength) |
| 145 { | 149 { |
| 146 m_client->mediaPlayerKeyNeeded(contentType, initData, initDataLength); | 150 HTMLMediaElementEncryptedMedia::keyNeeded(mediaElement(), contentType, initD ata, initDataLength); |
| 147 } | 151 } |
| 148 | 152 |
| 149 WebPlugin* WebMediaPlayerClientImpl::createHelperPlugin(const WebString& pluginT ype, WebFrame* frame) | 153 WebPlugin* WebMediaPlayerClientImpl::createHelperPlugin(const WebString& pluginT ype, WebFrame* frame) |
| 150 { | 154 { |
| 151 ASSERT(!m_helperPlugin); | 155 ASSERT(!m_helperPlugin); |
| 152 | 156 |
| 153 m_helperPlugin = adoptPtr(frame->view()->createHelperPlugin(pluginType, fram e->document())); | 157 m_helperPlugin = adoptPtr(frame->view()->createHelperPlugin(pluginType, fram e->document())); |
| 154 if (!m_helperPlugin) | 158 if (!m_helperPlugin) |
| 155 return 0; | 159 return 0; |
| 156 | 160 |
| 157 WebPlugin* plugin = m_helperPlugin->getPlugin(); | 161 WebPlugin* plugin = m_helperPlugin->getPlugin(); |
| 158 if (!plugin) { | 162 if (!plugin) { |
| 159 // There is no need to keep the helper plugin around and the caller | 163 // There is no need to keep the helper plugin around and the caller |
| 160 // should not be expected to call close after a failure (null pointer). | 164 // should not be expected to call close after a failure (null pointer). |
| 161 closeHelperPluginSoon(frame); | 165 closeHelperPluginSoon(frame); |
| 162 return 0; | 166 return 0; |
| 163 } | 167 } |
| 164 | 168 |
| 165 return plugin; | 169 return plugin; |
| 166 } | 170 } |
| 167 | 171 |
| 168 // FIXME: |frame| no longer needed. | 172 void WebMediaPlayerClientImpl::closeHelperPluginSoon(WebFrame*) |
|
ddorwin
2014/02/27 00:37:59
That's not what the FIXME meant. You should just r
c.shu
2014/02/27 14:49:46
Done.
| |
| 169 void WebMediaPlayerClientImpl::closeHelperPluginSoon(WebFrame* frame) | |
| 170 { | 173 { |
| 171 ASSERT(m_helperPlugin); | 174 ASSERT(m_helperPlugin); |
| 172 m_helperPlugin.clear(); | 175 m_helperPlugin.clear(); |
| 173 } | 176 } |
| 174 | 177 |
| 175 void WebMediaPlayerClientImpl::setWebLayer(blink::WebLayer* layer) | 178 void WebMediaPlayerClientImpl::setWebLayer(blink::WebLayer* layer) |
| 176 { | 179 { |
| 177 m_client->mediaPlayerSetWebLayer(layer); | 180 m_client->mediaPlayerSetWebLayer(layer); |
| 178 } | 181 } |
| 179 | 182 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 loadInternal(); | 223 loadInternal(); |
| 221 } | 224 } |
| 222 | 225 |
| 223 void WebMediaPlayerClientImpl::loadInternal() | 226 void WebMediaPlayerClientImpl::loadInternal() |
| 224 { | 227 { |
| 225 #if ENABLE(WEB_AUDIO) | 228 #if ENABLE(WEB_AUDIO) |
| 226 m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlayer's WebAudioSourceProvider. | 229 m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlayer's WebAudioSourceProvider. |
| 227 #endif | 230 #endif |
| 228 | 231 |
| 229 // FIXME: Remove this cast | 232 // FIXME: Remove this cast |
| 230 Frame* frame = static_cast<HTMLMediaElement*>(m_client)->document().frame(); | 233 Frame* frame = static_cast<HTMLMediaElement*>(m_client)->document().frame(); |
|
ddorwin
2014/02/27 00:37:59
FYI, you didn't address acolwell's nit from PS5. Y
c.shu
2014/02/27 14:49:46
Done.
| |
| 231 | 234 |
| 232 WebURL poster = m_client->mediaPlayerPosterURL(); | 235 WebURL poster = m_client->mediaPlayerPosterURL(); |
| 233 | 236 |
| 234 // This does not actually check whether the hardware can support accelerated | 237 // This does not actually check whether the hardware can support accelerated |
| 235 // compositing, but only if the flag is set. However, this is checked lazily | 238 // compositing, but only if the flag is set. However, this is checked lazily |
| 236 // in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there | 239 // in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there |
| 237 // if necessary. | 240 // if necessary. |
| 238 m_needsWebLayerForVideo = frame->contentRenderer()->compositor()->hasAcceler atedCompositing(); | 241 m_needsWebLayerForVideo = frame->contentRenderer()->compositor()->hasAcceler atedCompositing(); |
| 239 | 242 |
| 240 m_webMediaPlayer = createWebMediaPlayer(this, m_url, frame); | 243 m_webMediaPlayer = createWebMediaPlayer(this, m_url, frame); |
| 241 if (m_webMediaPlayer) { | 244 if (m_webMediaPlayer) { |
| 242 #if ENABLE(WEB_AUDIO) | 245 #if ENABLE(WEB_AUDIO) |
| 243 // Make sure if we create/re-create the WebMediaPlayer that we update ou r wrapper. | 246 // Make sure if we create/re-create the WebMediaPlayer that we update ou r wrapper. |
| 244 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider()); | 247 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider()); |
| 245 #endif | 248 #endif |
| 246 | 249 |
| 247 // Tell WebMediaPlayer about the poster image URL. | 250 // Tell WebMediaPlayer about the poster image URL. |
| 248 m_webMediaPlayer->setPoster(poster); | 251 m_webMediaPlayer->setPoster(poster); |
| 249 | 252 |
| 250 // Tell WebMediaPlayer about any connected CDM (may be null). | 253 // Tell WebMediaPlayer about any connected CDM (may be null). |
| 251 m_webMediaPlayer->setContentDecryptionModule(m_cdm); | 254 m_webMediaPlayer->setContentDecryptionModule(HTMLMediaElementEncryptedMe dia::contentDecryptionModule(mediaElement())); |
| 252 | 255 |
| 253 WebMediaPlayer::CORSMode corsMode = static_cast<WebMediaPlayer::CORSMode >(m_client->mediaPlayerCORSMode()); | 256 WebMediaPlayer::CORSMode corsMode = static_cast<WebMediaPlayer::CORSMode >(m_client->mediaPlayerCORSMode()); |
| 254 m_webMediaPlayer->load(m_loadType, m_url, corsMode); | 257 m_webMediaPlayer->load(m_loadType, m_url, corsMode); |
| 255 } | 258 } |
| 256 } | 259 } |
| 257 | 260 |
| 258 void WebMediaPlayerClientImpl::play() | 261 void WebMediaPlayerClientImpl::play() |
| 259 { | 262 { |
| 260 if (m_webMediaPlayer) | 263 if (m_webMediaPlayer) |
| 261 m_webMediaPlayer->play(); | 264 m_webMediaPlayer->play(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 277 { | 280 { |
| 278 if (m_webMediaPlayer) | 281 if (m_webMediaPlayer) |
| 279 m_webMediaPlayer->exitFullscreen(); | 282 m_webMediaPlayer->exitFullscreen(); |
| 280 } | 283 } |
| 281 | 284 |
| 282 bool WebMediaPlayerClientImpl::canShowFullscreenOverlay() const | 285 bool WebMediaPlayerClientImpl::canShowFullscreenOverlay() const |
| 283 { | 286 { |
| 284 return m_webMediaPlayer && m_webMediaPlayer->canEnterFullscreen(); | 287 return m_webMediaPlayer && m_webMediaPlayer->canEnterFullscreen(); |
| 285 } | 288 } |
| 286 | 289 |
| 287 MediaPlayer::MediaKeyException WebMediaPlayerClientImpl::generateKeyRequest(cons t String& keySystem, const unsigned char* initData, unsigned initDataLength) | |
| 288 { | |
| 289 if (!m_webMediaPlayer) | |
| 290 return MediaPlayer::InvalidPlayerState; | |
| 291 | |
| 292 WebMediaPlayer::MediaKeyException result = m_webMediaPlayer->generateKeyRequ est(keySystem, initData, initDataLength); | |
| 293 return static_cast<MediaPlayer::MediaKeyException>(result); | |
| 294 } | |
| 295 | |
| 296 MediaPlayer::MediaKeyException WebMediaPlayerClientImpl::addKey(const String& ke ySystem, const unsigned char* key, unsigned keyLength, const unsigned char* init Data, unsigned initDataLength, const String& sessionId) | |
| 297 { | |
| 298 if (!m_webMediaPlayer) | |
| 299 return MediaPlayer::InvalidPlayerState; | |
| 300 | |
| 301 WebMediaPlayer::MediaKeyException result = m_webMediaPlayer->addKey(keySyste m, key, keyLength, initData, initDataLength, sessionId); | |
| 302 return static_cast<MediaPlayer::MediaKeyException>(result); | |
| 303 } | |
| 304 | |
| 305 MediaPlayer::MediaKeyException WebMediaPlayerClientImpl::cancelKeyRequest(const String& keySystem, const String& sessionId) | |
| 306 { | |
| 307 if (!m_webMediaPlayer) | |
| 308 return MediaPlayer::InvalidPlayerState; | |
| 309 | |
| 310 WebMediaPlayer::MediaKeyException result = m_webMediaPlayer->cancelKeyReques t(keySystem, sessionId); | |
| 311 return static_cast<MediaPlayer::MediaKeyException>(result); | |
| 312 } | |
| 313 | |
| 314 void WebMediaPlayerClientImpl::setContentDecryptionModule(WebContentDecryptionMo dule* cdm) | |
| 315 { | |
| 316 m_cdm = cdm; | |
| 317 if (m_webMediaPlayer) | |
| 318 m_webMediaPlayer->setContentDecryptionModule(cdm); | |
| 319 } | |
| 320 | |
| 321 void WebMediaPlayerClientImpl::prepareToPlay() | 290 void WebMediaPlayerClientImpl::prepareToPlay() |
| 322 { | 291 { |
| 323 if (m_delayingLoad) | 292 if (m_delayingLoad) |
| 324 startDelayedLoad(); | 293 startDelayedLoad(); |
| 325 } | 294 } |
| 326 | 295 |
| 327 IntSize WebMediaPlayerClientImpl::naturalSize() const | 296 IntSize WebMediaPlayerClientImpl::naturalSize() const |
| 328 { | 297 { |
| 329 if (m_webMediaPlayer) | 298 if (m_webMediaPlayer) |
| 330 return m_webMediaPlayer->naturalSize(); | 299 return m_webMediaPlayer->naturalSize(); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 } | 583 } |
| 615 | 584 |
| 616 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client) | 585 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client) |
| 617 : m_client(client) | 586 : m_client(client) |
| 618 , m_delayingLoad(false) | 587 , m_delayingLoad(false) |
| 619 , m_preload(MediaPlayer::Auto) | 588 , m_preload(MediaPlayer::Auto) |
| 620 , m_needsWebLayerForVideo(false) | 589 , m_needsWebLayerForVideo(false) |
| 621 , m_volume(1.0) | 590 , m_volume(1.0) |
| 622 , m_muted(false) | 591 , m_muted(false) |
| 623 , m_rate(1.0) | 592 , m_rate(1.0) |
| 624 , m_cdm(0) | |
| 625 , m_loadType(WebMediaPlayer::LoadTypeURL) | 593 , m_loadType(WebMediaPlayer::LoadTypeURL) |
| 626 { | 594 { |
| 627 ASSERT(m_client); | 595 ASSERT(m_client); |
| 628 } | 596 } |
| 629 | 597 |
| 630 #if ENABLE(WEB_AUDIO) | 598 #if ENABLE(WEB_AUDIO) |
| 631 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::wrap(WebAudioSourceProvi der* provider) | 599 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::wrap(WebAudioSourceProvi der* provider) |
| 632 { | 600 { |
| 633 MutexLocker locker(provideInputLock); | 601 MutexLocker locker(provideInputLock); |
| 634 | 602 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 | 641 |
| 674 m_webAudioSourceProvider->provideInput(webAudioData, framesToProcess); | 642 m_webAudioSourceProvider->provideInput(webAudioData, framesToProcess); |
| 675 } | 643 } |
| 676 | 644 |
| 677 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel s, float sampleRate) | 645 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel s, float sampleRate) |
| 678 { | 646 { |
| 679 if (m_client) | 647 if (m_client) |
| 680 m_client->setFormat(numberOfChannels, sampleRate); | 648 m_client->setFormat(numberOfChannels, sampleRate); |
| 681 } | 649 } |
| 682 | 650 |
| 651 WebCore::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const | |
| 652 { | |
| 653 return *static_cast<WebCore::HTMLMediaElement*>(m_client); | |
|
ddorwin
2014/02/27 00:37:59
WebCore:: is unnecessary.
c.shu
2014/02/27 14:49:46
Done.
| |
| 654 } | |
| 655 | |
| 683 #endif | 656 #endif |
| 684 | 657 |
| 685 } // namespace blink | 658 } // namespace blink |
| OLD | NEW |