| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "WebMediaPlayerClientImpl.h" | |
| 7 | |
| 8 #if ENABLE(VIDEO) | |
| 9 | |
| 10 #include "CString.h" | |
| 11 #include "Frame.h" | |
| 12 #include "GraphicsContext.h" | |
| 13 #include "HTMLMediaElement.h" | |
| 14 #include "IntSize.h" | |
| 15 #include "KURL.h" | |
| 16 #include "MediaPlayer.h" | |
| 17 #include "NotImplemented.h" | |
| 18 #include "TimeRanges.h" | |
| 19 | |
| 20 #include "WebCanvas.h" | |
| 21 #include "WebCString.h" | |
| 22 #include "WebFrameClient.h" | |
| 23 #include "WebFrameImpl.h" | |
| 24 #include "WebKit.h" | |
| 25 #include "WebKitClient.h" | |
| 26 #include "WebMediaPlayer.h" | |
| 27 #include "WebMimeRegistry.h" | |
| 28 #include "WebRect.h" | |
| 29 #include "WebSize.h" | |
| 30 #include "WebString.h" | |
| 31 #include "WebURL.h" | |
| 32 | |
| 33 // WebCommon.h defines WEBKIT_USING_SKIA so this has to be included last. | |
| 34 #if WEBKIT_USING_SKIA | |
| 35 #include "PlatformContextSkia.h" | |
| 36 #endif | |
| 37 | |
| 38 #include <wtf/Assertions.h> | |
| 39 | |
| 40 using namespace WebCore; | |
| 41 | |
| 42 namespace WebKit { | |
| 43 | |
| 44 static WebMediaPlayer* createWebMediaPlayer( | |
| 45 WebMediaPlayerClient* client, Frame* frame) | |
| 46 { | |
| 47 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame); | |
| 48 if (!webFrame->client()) | |
| 49 return 0; | |
| 50 return webFrame->client()->createMediaPlayer(webFrame, client); | |
| 51 } | |
| 52 | |
| 53 bool WebMediaPlayerClientImpl::m_isEnabled = false; | |
| 54 | |
| 55 bool WebMediaPlayerClientImpl::isEnabled() | |
| 56 { | |
| 57 return m_isEnabled; | |
| 58 } | |
| 59 | |
| 60 void WebMediaPlayerClientImpl::setIsEnabled(bool isEnabled) | |
| 61 { | |
| 62 m_isEnabled = isEnabled; | |
| 63 } | |
| 64 | |
| 65 void WebMediaPlayerClientImpl::registerSelf(MediaEngineRegistrar registrar) | |
| 66 { | |
| 67 if (m_isEnabled) { | |
| 68 registrar(WebMediaPlayerClientImpl::create, | |
| 69 WebMediaPlayerClientImpl::getSupportedTypes, | |
| 70 WebMediaPlayerClientImpl::supportsType); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 // WebMediaPlayerClient -------------------------------------------------------- | |
| 75 | |
| 76 void WebMediaPlayerClientImpl::networkStateChanged() | |
| 77 { | |
| 78 ASSERT(m_mediaPlayer); | |
| 79 m_mediaPlayer->networkStateChanged(); | |
| 80 } | |
| 81 | |
| 82 void WebMediaPlayerClientImpl::readyStateChanged() | |
| 83 { | |
| 84 ASSERT(m_mediaPlayer); | |
| 85 m_mediaPlayer->readyStateChanged(); | |
| 86 } | |
| 87 | |
| 88 void WebMediaPlayerClientImpl::volumeChanged() | |
| 89 { | |
| 90 ASSERT(m_mediaPlayer); | |
| 91 m_mediaPlayer->volumeChanged(); | |
| 92 } | |
| 93 | |
| 94 void WebMediaPlayerClientImpl::timeChanged() | |
| 95 { | |
| 96 ASSERT(m_mediaPlayer); | |
| 97 m_mediaPlayer->timeChanged(); | |
| 98 } | |
| 99 | |
| 100 void WebMediaPlayerClientImpl::repaint() | |
| 101 { | |
| 102 ASSERT(m_mediaPlayer); | |
| 103 m_mediaPlayer->repaint(); | |
| 104 } | |
| 105 | |
| 106 void WebMediaPlayerClientImpl::durationChanged() | |
| 107 { | |
| 108 ASSERT(m_mediaPlayer); | |
| 109 m_mediaPlayer->durationChanged(); | |
| 110 } | |
| 111 | |
| 112 void WebMediaPlayerClientImpl::rateChanged() | |
| 113 { | |
| 114 ASSERT(m_mediaPlayer); | |
| 115 m_mediaPlayer->rateChanged(); | |
| 116 } | |
| 117 | |
| 118 void WebMediaPlayerClientImpl::sizeChanged() | |
| 119 { | |
| 120 ASSERT(m_mediaPlayer); | |
| 121 m_mediaPlayer->sizeChanged(); | |
| 122 } | |
| 123 | |
| 124 void WebMediaPlayerClientImpl::sawUnsupportedTracks() | |
| 125 { | |
| 126 ASSERT(m_mediaPlayer); | |
| 127 m_mediaPlayer->mediaPlayerClient()->mediaPlayerSawUnsupportedTracks(m_mediaPlayer); | |
| 128 } | |
| 129 | |
| 130 // MediaPlayerPrivateInterface ------------------------------------------------- | |
| 131 | |
| 132 void WebMediaPlayerClientImpl::load(const String& url) | |
| 133 { | |
| 134 Frame* frame = static_cast<HTMLMediaElement*>( | |
| 135 m_mediaPlayer->mediaPlayerClient())->document()->frame(); | |
| 136 m_webMediaPlayer.set(createWebMediaPlayer(this, frame)); | |
| 137 if (m_webMediaPlayer.get()) | |
| 138 m_webMediaPlayer->load(KURL(ParsedURLString, url)); | |
| 139 } | |
| 140 | |
| 141 void WebMediaPlayerClientImpl::cancelLoad() | |
| 142 { | |
| 143 if (m_webMediaPlayer.get()) | |
| 144 m_webMediaPlayer->cancelLoad(); | |
| 145 } | |
| 146 | |
| 147 void WebMediaPlayerClientImpl::play() | |
| 148 { | |
| 149 if (m_webMediaPlayer.get()) | |
| 150 m_webMediaPlayer->play(); | |
| 151 } | |
| 152 | |
| 153 void WebMediaPlayerClientImpl::pause() | |
| 154 { | |
| 155 if (m_webMediaPlayer.get()) | |
| 156 m_webMediaPlayer->pause(); | |
| 157 } | |
| 158 | |
| 159 IntSize WebMediaPlayerClientImpl::naturalSize() const | |
| 160 { | |
| 161 if (m_webMediaPlayer.get()) | |
| 162 return m_webMediaPlayer->naturalSize(); | |
| 163 return IntSize(); | |
| 164 } | |
| 165 | |
| 166 bool WebMediaPlayerClientImpl::hasVideo() const | |
| 167 { | |
| 168 if (m_webMediaPlayer.get()) | |
| 169 return m_webMediaPlayer->hasVideo(); | |
| 170 return false; | |
| 171 } | |
| 172 | |
| 173 bool WebMediaPlayerClientImpl::hasAudio() const | |
| 174 { | |
| 175 if (m_webMediaPlayer.get()) | |
| 176 return m_webMediaPlayer->hasAudio(); | |
| 177 return false; | |
| 178 } | |
| 179 | |
| 180 void WebMediaPlayerClientImpl::setVisible(bool visible) | |
| 181 { | |
| 182 if (m_webMediaPlayer.get()) | |
| 183 m_webMediaPlayer->setVisible(visible); | |
| 184 } | |
| 185 | |
| 186 float WebMediaPlayerClientImpl::duration() const | |
| 187 { | |
| 188 if (m_webMediaPlayer.get()) | |
| 189 return m_webMediaPlayer->duration(); | |
| 190 return 0.0f; | |
| 191 } | |
| 192 | |
| 193 float WebMediaPlayerClientImpl::currentTime() const | |
| 194 { | |
| 195 if (m_webMediaPlayer.get()) | |
| 196 return m_webMediaPlayer->currentTime(); | |
| 197 return 0.0f; | |
| 198 } | |
| 199 | |
| 200 void WebMediaPlayerClientImpl::seek(float time) | |
| 201 { | |
| 202 if (m_webMediaPlayer.get()) | |
| 203 m_webMediaPlayer->seek(time); | |
| 204 } | |
| 205 | |
| 206 bool WebMediaPlayerClientImpl::seeking() const | |
| 207 { | |
| 208 if (m_webMediaPlayer.get()) | |
| 209 return m_webMediaPlayer->seeking(); | |
| 210 return false; | |
| 211 } | |
| 212 | |
| 213 void WebMediaPlayerClientImpl::setEndTime(float time) | |
| 214 { | |
| 215 if (m_webMediaPlayer.get()) | |
| 216 m_webMediaPlayer->setEndTime(time); | |
| 217 } | |
| 218 | |
| 219 void WebMediaPlayerClientImpl::setRate(float rate) | |
| 220 { | |
| 221 if (m_webMediaPlayer.get()) | |
| 222 m_webMediaPlayer->setRate(rate); | |
| 223 } | |
| 224 | |
| 225 bool WebMediaPlayerClientImpl::paused() const | |
| 226 { | |
| 227 if (m_webMediaPlayer.get()) | |
| 228 return m_webMediaPlayer->paused(); | |
| 229 return false; | |
| 230 } | |
| 231 | |
| 232 bool WebMediaPlayerClientImpl::supportsFullscreen() const | |
| 233 { | |
| 234 if (m_webMediaPlayer.get()) | |
| 235 return m_webMediaPlayer->supportsFullscreen(); | |
| 236 return false; | |
| 237 } | |
| 238 | |
| 239 bool WebMediaPlayerClientImpl::supportsSave() const | |
| 240 { | |
| 241 if (m_webMediaPlayer.get()) | |
| 242 return m_webMediaPlayer->supportsSave(); | |
| 243 return false; | |
| 244 } | |
| 245 | |
| 246 void WebMediaPlayerClientImpl::setVolume(float volume) | |
| 247 { | |
| 248 if (m_webMediaPlayer.get()) | |
| 249 m_webMediaPlayer->setVolume(volume); | |
| 250 } | |
| 251 | |
| 252 MediaPlayer::NetworkState WebMediaPlayerClientImpl::networkState() const | |
| 253 { | |
| 254 if (m_webMediaPlayer.get()) | |
| 255 return static_cast<MediaPlayer::NetworkState>(m_webMediaPlayer->networkState()); | |
| 256 return MediaPlayer::Empty; | |
| 257 } | |
| 258 | |
| 259 MediaPlayer::ReadyState WebMediaPlayerClientImpl::readyState() const | |
| 260 { | |
| 261 if (m_webMediaPlayer.get()) | |
| 262 return static_cast<MediaPlayer::ReadyState>(m_webMediaPlayer->readyState()); | |
| 263 return MediaPlayer::HaveNothing; | |
| 264 } | |
| 265 | |
| 266 float WebMediaPlayerClientImpl::maxTimeSeekable() const | |
| 267 { | |
| 268 if (m_webMediaPlayer.get()) | |
| 269 return m_webMediaPlayer->maxTimeSeekable(); | |
| 270 return 0.0f; | |
| 271 } | |
| 272 | |
| 273 PassRefPtr<TimeRanges> WebMediaPlayerClientImpl::buffered() const | |
| 274 { | |
| 275 if (m_webMediaPlayer.get()) { | |
| 276 const WebTimeRanges& webRanges = m_webMediaPlayer->buffered(); | |
| 277 | |
| 278 // FIXME: Save the time ranges in a member variable and update it when needed. | |
| 279 RefPtr<TimeRanges> ranges = TimeRanges::create(); | |
| 280 for (size_t i = 0; i < webRanges.size(); ++i) | |
| 281 ranges->add(webRanges[i].start, webRanges[i].end); | |
| 282 return ranges.release(); | |
| 283 } | |
| 284 return TimeRanges::create(); | |
| 285 } | |
| 286 | |
| 287 int WebMediaPlayerClientImpl::dataRate() const | |
| 288 { | |
| 289 if (m_webMediaPlayer.get()) | |
| 290 return m_webMediaPlayer->dataRate(); | |
| 291 return 0; | |
| 292 } | |
| 293 | |
| 294 bool WebMediaPlayerClientImpl::totalBytesKnown() const | |
| 295 { | |
| 296 if (m_webMediaPlayer.get()) | |
| 297 return m_webMediaPlayer->totalBytesKnown(); | |
| 298 return false; | |
| 299 } | |
| 300 | |
| 301 unsigned WebMediaPlayerClientImpl::totalBytes() const | |
| 302 { | |
| 303 if (m_webMediaPlayer.get()) | |
| 304 return static_cast<unsigned>(m_webMediaPlayer->totalBytes()); | |
| 305 return 0; | |
| 306 } | |
| 307 | |
| 308 unsigned WebMediaPlayerClientImpl::bytesLoaded() const | |
| 309 { | |
| 310 if (m_webMediaPlayer.get()) | |
| 311 return static_cast<unsigned>(m_webMediaPlayer->bytesLoaded()); | |
| 312 return 0; | |
| 313 } | |
| 314 | |
| 315 void WebMediaPlayerClientImpl::setSize(const IntSize& size) | |
| 316 { | |
| 317 if (m_webMediaPlayer.get()) | |
| 318 m_webMediaPlayer->setSize(WebSize(size.width(), size.height())); | |
| 319 } | |
| 320 | |
| 321 void WebMediaPlayerClientImpl::paint(GraphicsContext* context, const IntRect& rect) | |
| 322 { | |
| 323 // Normally GraphicsContext operations do nothing when painting is disabled. | |
| 324 // Since we're accessing platformContext() directly we have to manually | |
| 325 // check. | |
| 326 if (m_webMediaPlayer.get() && !context->paintingDisabled()) { | |
| 327 #if WEBKIT_USING_SKIA | |
| 328 m_webMediaPlayer->paint(context->platformContext()->canvas(), rect); | |
| 329 #elif WEBKIT_USING_CG | |
| 330 m_webMediaPlayer->paint(context->platformContext(), rect); | |
| 331 #else | |
| 332 notImplemented(); | |
| 333 #endif | |
| 334 } | |
| 335 } | |
| 336 | |
| 337 void WebMediaPlayerClientImpl::setAutobuffer(bool autoBuffer) | |
| 338 { | |
| 339 if (m_webMediaPlayer.get()) | |
| 340 m_webMediaPlayer->setAutoBuffer(autoBuffer); | |
| 341 } | |
| 342 | |
| 343 bool WebMediaPlayerClientImpl::hasSingleSecurityOrigin() const | |
| 344 { | |
| 345 if (m_webMediaPlayer.get()) | |
| 346 return m_webMediaPlayer->hasSingleSecurityOrigin(); | |
| 347 return false; | |
| 348 } | |
| 349 | |
| 350 MediaPlayer::MovieLoadType WebMediaPlayerClientImpl::movieLoadType() const | |
| 351 { | |
| 352 if (m_webMediaPlayer.get()) | |
| 353 return static_cast<MediaPlayer::MovieLoadType>( | |
| 354 m_webMediaPlayer->movieLoadType()); | |
| 355 return MediaPlayer::Unknown; | |
| 356 } | |
| 357 | |
| 358 MediaPlayerPrivateInterface* WebMediaPlayerClientImpl::create(MediaPlayer* player) | |
| 359 { | |
| 360 WebMediaPlayerClientImpl* client = new WebMediaPlayerClientImpl(); | |
| 361 client->m_mediaPlayer = player; | |
| 362 return client; | |
| 363 } | |
| 364 | |
| 365 void WebMediaPlayerClientImpl::getSupportedTypes(HashSet<String>& supportedTypes) | |
| 366 { | |
| 367 // FIXME: integrate this list with WebMediaPlayerClientImpl::supportsType. | |
| 368 notImplemented(); | |
| 369 } | |
| 370 | |
| 371 MediaPlayer::SupportsType WebMediaPlayerClientImpl::supportsType(const String& type, | |
| 372 const String& codecs) | |
| 373 { | |
| 374 WebMimeRegistry::SupportsType supportsType = | |
| 375 webKitClient()->mimeRegistry()->supportsMediaMIMEType(type, codecs); | |
| 376 | |
| 377 switch (supportsType) { | |
| 378 default: | |
| 379 ASSERT_NOT_REACHED(); | |
| 380 case WebMimeRegistry::IsNotSupported: | |
| 381 return MediaPlayer::IsNotSupported; | |
| 382 case WebMimeRegistry::IsSupported: | |
| 383 return MediaPlayer::IsSupported; | |
| 384 case WebMimeRegistry::MayBeSupported: | |
| 385 return MediaPlayer::MayBeSupported; | |
| 386 } | |
| 387 return MediaPlayer::IsNotSupported; | |
| 388 } | |
| 389 | |
| 390 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl() | |
| 391 : m_mediaPlayer(0) | |
| 392 { | |
| 393 } | |
| 394 | |
| 395 } // namespace WebKit | |
| 396 | |
| 397 #endif // ENABLE(VIDEO) | |
| OLD | NEW |