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 "webkit/glue/webmediaplayerclient_impl.h" | |
7 | |
8 #if ENABLE(VIDEO) | |
9 | |
10 #include "webkit/api/public/WebCanvas.h" | |
11 #include "webkit/api/public/WebCString.h" | |
12 #include "webkit/api/public/WebKit.h" | |
13 #include "webkit/api/public/WebKitClient.h" | |
14 #include "webkit/api/public/WebMediaPlayer.h" | |
15 #include "webkit/api/public/WebRect.h" | |
16 #include "webkit/api/public/WebSize.h" | |
17 #include "webkit/api/public/WebString.h" | |
18 #include "webkit/api/public/WebURL.h" | |
19 #include "webkit/glue/glue_util.h" | |
20 #include "webkit/glue/webframe_impl.h" | |
21 #include "webkit/glue/webview.h" | |
22 #include "webkit/glue/webview_delegate.h" | |
23 | |
24 #include "CString.h" | |
25 #include "Frame.h" | |
26 #include "GraphicsContext.h" | |
27 #include "HTMLMediaElement.h" | |
28 #include "IntSize.h" | |
29 #include "KURL.h" | |
30 #include "MediaPlayer.h" | |
31 #include "NotImplemented.h" | |
32 #include "PlatformContextSkia.h" | |
33 | |
34 using namespace WebCore; | |
35 using namespace WebKit; | |
36 | |
37 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl() | |
38 : m_webMediaPlayer(0) { | |
39 } | |
40 | |
41 | |
42 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl() { | |
43 delete m_webMediaPlayer; | |
44 } | |
45 | |
46 ////////////////////////////////////////////////////////////////////////////// | |
47 // WebMediaPlayerClientImpl, WebMediaPlayerClient implementations | |
48 void WebMediaPlayerClientImpl::networkStateChanged() { | |
49 ASSERT(m_mediaPlayer); | |
50 m_mediaPlayer->networkStateChanged(); | |
51 } | |
52 | |
53 void WebMediaPlayerClientImpl::readyStateChanged() { | |
54 ASSERT(m_mediaPlayer); | |
55 m_mediaPlayer->readyStateChanged(); | |
56 } | |
57 | |
58 void WebMediaPlayerClientImpl::volumeChanged() { | |
59 ASSERT(m_mediaPlayer); | |
60 m_mediaPlayer->volumeChanged(); | |
61 } | |
62 | |
63 void WebMediaPlayerClientImpl::timeChanged() { | |
64 ASSERT(m_mediaPlayer); | |
65 m_mediaPlayer->timeChanged(); | |
66 } | |
67 | |
68 void WebMediaPlayerClientImpl::repaint() { | |
69 ASSERT(m_mediaPlayer); | |
70 m_mediaPlayer->repaint(); | |
71 } | |
72 | |
73 void WebMediaPlayerClientImpl::durationChanged() { | |
74 ASSERT(m_mediaPlayer); | |
75 m_mediaPlayer->durationChanged(); | |
76 } | |
77 | |
78 void WebMediaPlayerClientImpl::rateChanged() { | |
79 ASSERT(m_mediaPlayer); | |
80 m_mediaPlayer->rateChanged(); | |
81 } | |
82 | |
83 void WebMediaPlayerClientImpl::sizeChanged() { | |
84 ASSERT(m_mediaPlayer); | |
85 m_mediaPlayer->sizeChanged(); | |
86 } | |
87 | |
88 void WebMediaPlayerClientImpl::sawUnsupportedTracks() { | |
89 ASSERT(m_mediaPlayer); | |
90 m_mediaPlayer->mediaPlayerClient()->mediaPlayerSawUnsupportedTracks( | |
91 m_mediaPlayer); | |
92 } | |
93 | |
94 ////////////////////////////////////////////////////////////////////////////// | |
95 // WebMediaPlayerClientImpl, MediaPlayerPrivateInterface implementations | |
96 void WebMediaPlayerClientImpl::load(const String& url) { | |
97 delete m_webMediaPlayer; | |
98 | |
99 WebCore::Frame* frame = static_cast<HTMLMediaElement*>( | |
100 m_mediaPlayer->mediaPlayerClient())->document()->frame(); | |
101 WebFrame* webFrame = WebFrameImpl::FromFrame(frame); | |
102 WebViewDelegate* d = webFrame->GetView()->GetDelegate(); | |
103 m_webMediaPlayer = d->CreateWebMediaPlayer(this); | |
104 m_webMediaPlayer->load(webkit_glue::KURLToWebURL(KURL(url))); | |
105 } | |
106 | |
107 void WebMediaPlayerClientImpl::cancelLoad() { | |
108 if (m_webMediaPlayer) | |
109 m_webMediaPlayer->cancelLoad(); | |
110 } | |
111 | |
112 void WebMediaPlayerClientImpl::play() { | |
113 if (m_webMediaPlayer) | |
114 m_webMediaPlayer->play(); | |
115 } | |
116 | |
117 void WebMediaPlayerClientImpl::pause() { | |
118 if (m_webMediaPlayer) | |
119 m_webMediaPlayer->pause(); | |
120 } | |
121 | |
122 IntSize WebMediaPlayerClientImpl::naturalSize() const { | |
123 if (m_webMediaPlayer) { | |
124 const WebSize& size = m_webMediaPlayer->naturalSize(); | |
125 return IntSize(size.width, size.height); | |
126 } | |
127 return IntSize(0, 0); | |
128 } | |
129 | |
130 bool WebMediaPlayerClientImpl::hasVideo() const { | |
131 if (m_webMediaPlayer) | |
132 return m_webMediaPlayer->hasVideo(); | |
133 return false; | |
134 } | |
135 | |
136 void WebMediaPlayerClientImpl::setVisible(bool visible) { | |
137 if (m_webMediaPlayer) | |
138 m_webMediaPlayer->setVisible(visible); | |
139 } | |
140 | |
141 float WebMediaPlayerClientImpl::duration() const { | |
142 if (m_webMediaPlayer) | |
143 return m_webMediaPlayer->duration(); | |
144 return 0.0f; | |
145 } | |
146 | |
147 float WebMediaPlayerClientImpl::currentTime() const { | |
148 if (m_webMediaPlayer) | |
149 return m_webMediaPlayer->currentTime(); | |
150 return 0.0f; | |
151 } | |
152 | |
153 void WebMediaPlayerClientImpl::seek(float time) { | |
154 if (m_webMediaPlayer) | |
155 m_webMediaPlayer->seek(time); | |
156 } | |
157 | |
158 bool WebMediaPlayerClientImpl::seeking() const { | |
159 return m_webMediaPlayer->seeking(); | |
160 } | |
161 | |
162 void WebMediaPlayerClientImpl::setEndTime(float time) { | |
163 if (m_webMediaPlayer) | |
164 m_webMediaPlayer->setEndTime(time); | |
165 } | |
166 | |
167 void WebMediaPlayerClientImpl::setRate(float rate) { | |
168 if (m_webMediaPlayer) | |
169 m_webMediaPlayer->setRate(rate); | |
170 } | |
171 | |
172 bool WebMediaPlayerClientImpl::paused() const { | |
173 if (m_webMediaPlayer) | |
174 return m_webMediaPlayer->paused(); | |
175 return false; | |
176 } | |
177 | |
178 void WebMediaPlayerClientImpl::setVolume(float volume) { | |
179 if (m_webMediaPlayer) | |
180 m_webMediaPlayer->setVolume(volume); | |
181 } | |
182 | |
183 MediaPlayer::NetworkState WebMediaPlayerClientImpl::networkState() const { | |
184 COMPILE_ASSERT( | |
185 int(WebMediaPlayer::Empty) == int(MediaPlayer::Empty), Empty); | |
186 COMPILE_ASSERT( | |
187 int(WebMediaPlayer::Idle) == int(MediaPlayer::Idle), Idle); | |
188 COMPILE_ASSERT( | |
189 int(WebMediaPlayer::Loading) == int(MediaPlayer::Loading), Loading); | |
190 COMPILE_ASSERT( | |
191 int(WebMediaPlayer::Loaded) == int(MediaPlayer::Loaded), Loaded); | |
192 COMPILE_ASSERT( | |
193 int(WebMediaPlayer::FormatError) == int(MediaPlayer::FormatError), | |
194 FormatError); | |
195 COMPILE_ASSERT( | |
196 int(WebMediaPlayer::NetworkError) == int(MediaPlayer::NetworkError), | |
197 NetworkError); | |
198 COMPILE_ASSERT( | |
199 int(WebMediaPlayer::DecodeError) == int(MediaPlayer::DecodeError), | |
200 DecodeError); | |
201 | |
202 if (m_webMediaPlayer) | |
203 return static_cast<MediaPlayer::NetworkState>( | |
204 m_webMediaPlayer->networkState()); | |
205 return MediaPlayer::Empty; | |
206 } | |
207 | |
208 MediaPlayer::ReadyState WebMediaPlayerClientImpl::readyState() const { | |
209 COMPILE_ASSERT( | |
210 int(WebMediaPlayer::HaveNothing) == int(MediaPlayer::HaveNothing), | |
211 HaveNothing); | |
212 COMPILE_ASSERT( | |
213 int(WebMediaPlayer::HaveMetadata) == int(MediaPlayer::HaveMetadata), | |
214 HaveMetadata); | |
215 COMPILE_ASSERT( | |
216 int(WebMediaPlayer::HaveCurrentData) == int(MediaPlayer::HaveCurrentData), | |
217 HaveCurrentData); | |
218 COMPILE_ASSERT( | |
219 int(WebMediaPlayer::HaveFutureData) == int(MediaPlayer::HaveFutureData), | |
220 HaveFutureData); | |
221 COMPILE_ASSERT( | |
222 int(WebMediaPlayer::HaveEnoughData) == int(MediaPlayer::HaveEnoughData), | |
223 HaveEnoughData); | |
224 | |
225 if (m_webMediaPlayer) | |
226 return static_cast<MediaPlayer::ReadyState>(m_webMediaPlayer->readyState()); | |
227 return MediaPlayer::HaveNothing; | |
228 } | |
229 | |
230 float WebMediaPlayerClientImpl::maxTimeSeekable() const { | |
231 if (m_webMediaPlayer) | |
232 return m_webMediaPlayer->maxTimeSeekable(); | |
233 return 0.0f; | |
234 } | |
235 | |
236 float WebMediaPlayerClientImpl::maxTimeBuffered() const { | |
237 if (m_webMediaPlayer) | |
238 return m_webMediaPlayer->maxTimeBuffered(); | |
239 return 0.0f; | |
240 } | |
241 | |
242 int WebMediaPlayerClientImpl::dataRate() const { | |
243 if (m_webMediaPlayer) | |
244 return m_webMediaPlayer->dataRate(); | |
245 return 0; | |
246 } | |
247 | |
248 bool WebMediaPlayerClientImpl::totalBytesKnown() const { | |
249 if (m_webMediaPlayer) | |
250 return m_webMediaPlayer->totalBytesKnown(); | |
251 return false; | |
252 } | |
253 | |
254 unsigned WebMediaPlayerClientImpl::totalBytes() const { | |
255 if (m_webMediaPlayer) | |
256 return static_cast<unsigned>(m_webMediaPlayer->totalBytes()); | |
257 return 0; | |
258 } | |
259 | |
260 unsigned WebMediaPlayerClientImpl::bytesLoaded() const { | |
261 if (m_webMediaPlayer) | |
262 return static_cast<unsigned>(m_webMediaPlayer->bytesLoaded()); | |
263 return 0; | |
264 } | |
265 | |
266 void WebMediaPlayerClientImpl::setSize(const IntSize& size) { | |
267 if (m_webMediaPlayer) | |
268 m_webMediaPlayer->setSize(WebSize(size.width(), size.height())); | |
269 } | |
270 | |
271 void WebMediaPlayerClientImpl::paint(GraphicsContext* context, | |
272 const IntRect& rect) { | |
273 // TODO(hclam): enable this for mac. | |
274 #if WEBKIT_USING_SKIA | |
275 if (m_webMediaPlayer) | |
276 m_webMediaPlayer->paint( | |
277 context->platformContext()->canvas(), | |
278 WebRect(rect.x(), rect.y(), rect.width(), rect.height())); | |
279 #endif | |
280 } | |
281 | |
282 void WebMediaPlayerClientImpl::setAutobuffer(bool autoBuffer) { | |
283 if (m_webMediaPlayer) | |
284 m_webMediaPlayer->setAutoBuffer(autoBuffer); | |
285 } | |
286 | |
287 // static | |
288 MediaPlayerPrivateInterface* WebMediaPlayerClientImpl::create( | |
289 MediaPlayer* player) { | |
290 WebMediaPlayerClientImpl* client = new WebMediaPlayerClientImpl(); | |
291 client->m_mediaPlayer = player; | |
292 return client; | |
293 } | |
294 | |
295 // static | |
296 void WebMediaPlayerClientImpl::getSupportedTypes( | |
297 HashSet<String>& supportedTypes) { | |
298 // TODO(hclam): decide what to do here, we should fill in the HashSet about | |
299 // codecs that we support. | |
300 notImplemented(); | |
301 } | |
302 | |
303 // static | |
304 MediaPlayer::SupportsType WebMediaPlayerClientImpl::supportsType( | |
305 const String& type, const String& codecs) { | |
306 // TODO(hclam): implement this nicely. | |
307 return MediaPlayer::IsSupported; | |
308 } | |
309 | |
310 #endif // ENABLE(VIDEO) | |
OLD | NEW |