Remove unnecessary rotation callback
[framework/web/webkit-efl.git] / Source / WebCore / html / HTMLMediaElement.h
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef HTMLMediaElement_h
27 #define HTMLMediaElement_h
28
29 #if ENABLE(VIDEO)
30
31 #include "HTMLElement.h"
32 #include "ActiveDOMObject.h"
33 #include "GenericEventQueue.h"
34 #include "MediaCanStartListener.h"
35 #include "MediaControllerInterface.h"
36 #include "MediaPlayer.h"
37
38 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
39 #include "MediaPlayerProxy.h"
40 #endif
41
42 #if ENABLE(VIDEO_TRACK)
43 #include "PODIntervalTree.h"
44 #include "TextTrack.h"
45 #include "TextTrackCue.h"
46 #endif
47
48 namespace WebCore {
49
50 #if ENABLE(WEB_AUDIO)
51 class AudioSourceProvider;
52 class MediaElementAudioSourceNode;
53 #endif
54 class Event;
55 class HTMLSourceElement;
56 class HTMLTrackElement;
57 class MediaController;
58 class MediaControls;
59 class MediaError;
60 class KURL;
61 class TextTrackList;
62 class TimeRanges;
63 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
64 class Widget;
65 #endif
66 #if PLATFORM(MAC)
67 class DisplaySleepDisabler;
68 #endif
69
70 #if ENABLE(VIDEO_TRACK)
71 typedef PODIntervalTree<double, TextTrackCue*> CueIntervalTree;
72 typedef Vector<CueIntervalTree::IntervalType> CueList;
73 #endif
74
75 // FIXME: The inheritance from MediaPlayerClient here should be private inheritance.
76 // But it can't be until the Chromium WebMediaPlayerClientImpl class is fixed so it
77 // no longer depends on typecasting a MediaPlayerClient to an HTMLMediaElement.
78
79 class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, public MediaPlayerSupportsTypeClient, private MediaCanStartListener, public ActiveDOMObject, public MediaControllerInterface
80 #if ENABLE(VIDEO_TRACK)
81     , private TextTrackClient
82 #endif
83 {
84 public:
85     MediaPlayer* player() const { return m_player.get(); }
86
87     void createShadowSubtree();
88     virtual void willAddAuthorShadowRoot() OVERRIDE;
89
90     virtual bool isVideo() const = 0;
91     virtual bool hasVideo() const { return false; }
92     virtual bool hasAudio() const;
93
94     void rewind(float timeDelta);
95     void returnToRealtime();
96
97     // Eventually overloaded in HTMLVideoElement
98     virtual bool supportsFullscreen() const { return false; };
99
100     virtual bool supportsSave() const;
101     virtual bool supportsScanning() const;
102     
103     PlatformMedia platformMedia() const;
104 #if USE(ACCELERATED_COMPOSITING)
105     PlatformLayer* platformLayer() const;
106 #endif
107
108     void scheduleLoad();
109
110     enum LoadType {
111         MediaResource = 1 << 0,
112         TextTrackResource = 1 << 1
113     };
114     void scheduleLoad(LoadType);
115     
116     MediaPlayer::MovieLoadType movieLoadType() const;
117     
118     bool inActiveDocument() const { return m_inActiveDocument; }
119     
120 // DOM API
121 // error state
122     PassRefPtr<MediaError> error() const;
123
124 // network state
125     void setSrc(const String&);
126     const KURL& currentSrc() const { return m_currentSrc; }
127
128     enum NetworkState { NETWORK_EMPTY, NETWORK_IDLE, NETWORK_LOADING, NETWORK_NO_SOURCE };
129     NetworkState networkState() const;
130
131     String preload() const;    
132     void setPreload(const String&);
133
134     PassRefPtr<TimeRanges> buffered() const;
135     void load();
136     String canPlayType(const String& mimeType, const String& keySystem = String(), const KURL& = KURL()) const;
137
138 // ready state
139     ReadyState readyState() const;
140     bool seeking() const;
141
142 // playback state
143     float currentTime() const;
144     void setCurrentTime(float, ExceptionCode&);
145     double initialTime() const;
146     float startTime() const;
147     float duration() const;
148     bool paused() const;
149     float defaultPlaybackRate() const;
150     void setDefaultPlaybackRate(float);
151     float playbackRate() const;
152     void setPlaybackRate(float);
153     void updatePlaybackRate();
154     bool webkitPreservesPitch() const;
155     void setWebkitPreservesPitch(bool);
156     PassRefPtr<TimeRanges> played();
157     PassRefPtr<TimeRanges> seekable() const;
158     bool ended() const;
159     bool autoplay() const;    
160     void setAutoplay(bool b);
161     bool loop() const;    
162     void setLoop(bool b);
163     void play();
164     void pause();
165
166 // captions
167     bool webkitHasClosedCaptions() const;
168     bool webkitClosedCaptionsVisible() const;
169     void setWebkitClosedCaptionsVisible(bool);
170
171 #if ENABLE(MEDIA_STATISTICS)
172 // Statistics
173     unsigned webkitAudioDecodedByteCount() const;
174     unsigned webkitVideoDecodedByteCount() const;
175 #endif
176
177 #if ENABLE(MEDIA_SOURCE)
178 //  Media Source.
179     const KURL& webkitMediaSourceURL() const { return m_mediaSourceURL; }
180     void webkitSourceAddId(const String&, const String&, ExceptionCode&);
181     void webkitSourceRemoveId(const String&, ExceptionCode&);
182     PassRefPtr<TimeRanges> webkitSourceBuffered(const String&, ExceptionCode&);
183     void webkitSourceAppend(const String&, PassRefPtr<Uint8Array> data, ExceptionCode&);
184     void webkitSourceAbort(const String&, ExceptionCode&);
185     enum EndOfStreamStatus { EOS_NO_ERROR, EOS_NETWORK_ERR, EOS_DECODE_ERR };
186     void webkitSourceEndOfStream(unsigned short, ExceptionCode&);
187     enum SourceState { SOURCE_CLOSED, SOURCE_OPEN, SOURCE_ENDED };
188     SourceState webkitSourceState() const;
189     void setSourceState(SourceState);
190
191     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceopen);
192     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceended);
193     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceclose);
194 #endif 
195
196 #if ENABLE(ENCRYPTED_MEDIA)
197     void webkitGenerateKeyRequest(const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionCode&);
198     void webkitGenerateKeyRequest(const String& keySystem, ExceptionCode&);
199     void webkitAddKey(const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initData, const String& sessionId, ExceptionCode&);
200     void webkitAddKey(const String& keySystem, PassRefPtr<Uint8Array> key, ExceptionCode&);
201     void webkitCancelKeyRequest(const String& keySystem, const String& sessionId, ExceptionCode&);
202
203     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeyadded);
204     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeyerror);
205     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeymessage);
206     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitneedkey);
207 #endif
208
209 // controls
210     bool controls() const;
211     void setControls(bool);
212     float volume() const;
213     void setVolume(float, ExceptionCode&);
214     bool muted() const;
215     void setMuted(bool);
216
217     void togglePlayState();
218     void beginScrubbing();
219     void endScrubbing();
220     
221     bool canPlay() const;
222
223     float percentLoaded() const;
224
225 #if ENABLE(VIDEO_TRACK)
226     PassRefPtr<TextTrack> addTextTrack(const String& kind, const String& label, const String& language, ExceptionCode&);
227     PassRefPtr<TextTrack> addTextTrack(const String& kind, const String& label, ExceptionCode& ec) { return addTextTrack(kind, label, emptyString(), ec); }
228     PassRefPtr<TextTrack> addTextTrack(const String& kind, ExceptionCode& ec) { return addTextTrack(kind, emptyString(), emptyString(), ec); }
229
230     TextTrackList* textTracks();
231     CueList currentlyActiveCues() const { return m_currentlyActiveCues; }
232
233     virtual void didAddTrack(HTMLTrackElement*);
234     virtual void willRemoveTrack(HTMLTrackElement*);
235
236     struct TrackGroup {
237         enum GroupKind { CaptionsAndSubtitles, Description, Chapter, Metadata, Other };
238
239         TrackGroup(GroupKind kind)
240             : visibleTrack(0)
241             , defaultTrack(0)
242             , kind(kind)
243             , hasSrcLang(false)
244         {
245         }
246
247         Vector<HTMLTrackElement*> tracks;
248         HTMLTrackElement* visibleTrack;
249         HTMLTrackElement* defaultTrack;
250         GroupKind kind;
251         bool hasSrcLang;
252     };
253
254     void configureTextTrackGroupForLanguage(const TrackGroup&) const;
255     void configureTextTracks();
256     void configureTextTrackGroup(const TrackGroup&) const;
257
258     bool userIsInterestedInThisTrackKind(String) const;
259     bool textTracksAreReady() const;
260     void configureTextTrackDisplay();
261     void updateClosedCaptionsControls();
262
263     // TextTrackClient
264     virtual void textTrackReadyStateChanged(TextTrack*);
265     virtual void textTrackKindChanged(TextTrack*);
266     virtual void textTrackModeChanged(TextTrack*);
267     virtual void textTrackAddCues(TextTrack*, const TextTrackCueList*);
268     virtual void textTrackRemoveCues(TextTrack*, const TextTrackCueList*);
269     virtual void textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>);
270     virtual void textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>);
271 #endif
272
273 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
274     void allocateMediaPlayerIfNecessary();
275     void setNeedWidgetUpdate(bool needWidgetUpdate) { m_needWidgetUpdate = needWidgetUpdate; }
276     void deliverNotification(MediaPlayerProxyNotificationType notification);
277     void setMediaPlayerProxy(WebMediaPlayerProxy* proxy);
278     void getPluginProxyParams(KURL& url, Vector<String>& names, Vector<String>& values);
279     void createMediaPlayerProxy();
280     void updateWidget(PluginCreationOption);
281 #endif
282
283     // EventTarget function.
284     // Both Node (via HTMLElement) and ActiveDOMObject define this method, which
285     // causes an ambiguity error at compile time. This class's constructor
286     // ensures that both implementations return document, so return the result
287     // of one of them here.
288     virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE { return HTMLElement::scriptExecutionContext(); }
289
290     bool hasSingleSecurityOrigin() const { return !m_player || m_player->hasSingleSecurityOrigin(); }
291     
292     bool isFullscreen() const;
293     void enterFullscreen();
294     void exitFullscreen();
295
296     bool hasClosedCaptions() const;
297     bool closedCaptionsVisible() const;
298     void setClosedCaptionsVisible(bool);
299
300     MediaControls* mediaControls() const;
301
302     void sourceWasRemoved(HTMLSourceElement*);
303     void sourceWasAdded(HTMLSourceElement*);
304
305     void privateBrowsingStateDidChange();
306
307     // Media cache management.
308     static void getSitesInMediaCache(Vector<String>&);
309     static void clearMediaCache();
310     static void clearMediaCacheForSite(const String&);
311
312     bool isPlaying() const { return m_playing; }
313
314     virtual bool hasPendingActivity() const;
315
316 #if ENABLE(WEB_AUDIO)
317     MediaElementAudioSourceNode* audioSourceNode() { return m_audioSourceNode; }
318     void setAudioSourceNode(MediaElementAudioSourceNode*);
319
320     AudioSourceProvider* audioSourceProvider();
321 #endif
322
323     enum InvalidURLAction { DoNothing, Complain };
324     bool isSafeToLoadURL(const KURL&, InvalidURLAction);
325
326     const String& mediaGroup() const;
327     void setMediaGroup(const String&);
328
329     MediaController* controller() const;
330     void setController(PassRefPtr<MediaController>);
331
332     virtual bool dispatchEvent(PassRefPtr<Event>);
333
334     virtual bool willRespondToMouseClickEvents() OVERRIDE;
335
336 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
337     bool suspended() { return m_suspended; }
338 #endif
339
340 #if ENABLE(TIZEN_FULLSCREEN_API)
341     void updateMediaControlsStyle();
342 #endif
343
344 protected:
345     HTMLMediaElement(const QualifiedName&, Document*, bool);
346     virtual ~HTMLMediaElement();
347
348     virtual void parseAttribute(const Attribute&) OVERRIDE;
349     virtual void finishParsingChildren();
350     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
351     virtual void attach();
352
353     virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
354
355     enum DisplayMode { Unknown, None, Poster, PosterWaitingForVideo, Video };
356     DisplayMode displayMode() const { return m_displayMode; }
357     virtual void setDisplayMode(DisplayMode mode) { m_displayMode = mode; }
358     
359     virtual bool isMediaElement() const { return true; }
360
361     // Restrictions to change default behaviors.
362     enum BehaviorRestrictionFlags {
363         NoRestrictions = 0,
364         RequireUserGestureForLoadRestriction = 1 << 0,
365         RequireUserGestureForRateChangeRestriction = 1 << 1,
366         RequireUserGestureForFullscreenRestriction = 1 << 2,
367         RequirePageConsentToLoadMediaRestriction = 1 << 3,
368     };
369     typedef unsigned BehaviorRestrictions;
370     
371     bool userGestureRequiredForLoad() const { return m_restrictions & RequireUserGestureForLoadRestriction; }
372     bool userGestureRequiredForRateChange() const { return m_restrictions & RequireUserGestureForRateChangeRestriction; }
373     bool userGestureRequiredForFullscreen() const { return m_restrictions & RequireUserGestureForFullscreenRestriction; }
374     bool pageConsentRequiredForLoad() const { return m_restrictions & RequirePageConsentToLoadMediaRestriction; }
375     
376     void addBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions |= restriction; }
377     void removeBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions &= ~restriction; }
378     
379 private:
380     void createMediaPlayer();
381
382     virtual bool supportsFocus() const;
383     virtual bool isMouseFocusable() const;
384     virtual bool rendererIsNeeded(const NodeRenderingContext&);
385     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
386     virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const OVERRIDE;
387     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
388     virtual void removedFrom(ContainerNode*) OVERRIDE;
389     virtual void didRecalcStyle(StyleChange);
390     
391     virtual void defaultEventHandler(Event*);
392
393     virtual void didBecomeFullscreenElement();
394     virtual void willStopBeingFullscreenElement();
395
396     // ActiveDOMObject functions.
397     virtual bool canSuspend() const;
398     virtual void suspend(ReasonForSuspension);
399     virtual void resume();
400     virtual void stop();
401     
402     virtual void mediaVolumeDidChange();
403
404     virtual void updateDisplayState() { }
405     
406     void setReadyState(MediaPlayer::ReadyState);
407     void setNetworkState(MediaPlayer::NetworkState);
408
409     virtual Document* mediaPlayerOwningDocument();
410     virtual void mediaPlayerNetworkStateChanged(MediaPlayer*);
411     virtual void mediaPlayerReadyStateChanged(MediaPlayer*);
412     virtual void mediaPlayerTimeChanged(MediaPlayer*);
413     virtual void mediaPlayerVolumeChanged(MediaPlayer*);
414     virtual void mediaPlayerMuteChanged(MediaPlayer*);
415     virtual void mediaPlayerDurationChanged(MediaPlayer*);
416     virtual void mediaPlayerRateChanged(MediaPlayer*);
417     virtual void mediaPlayerPlaybackStateChanged(MediaPlayer*);
418     virtual void mediaPlayerSawUnsupportedTracks(MediaPlayer*);
419     virtual void mediaPlayerResourceNotSupported(MediaPlayer*);
420     virtual void mediaPlayerRepaint(MediaPlayer*);
421     virtual void mediaPlayerSizeChanged(MediaPlayer*);
422 #if USE(ACCELERATED_COMPOSITING)
423     virtual bool mediaPlayerRenderingCanBeAccelerated(MediaPlayer*);
424     virtual void mediaPlayerRenderingModeChanged(MediaPlayer*);
425 #endif
426     virtual void mediaPlayerEngineUpdated(MediaPlayer*);
427     
428     virtual void mediaPlayerFirstVideoFrameAvailable(MediaPlayer*);
429     virtual void mediaPlayerCharacteristicChanged(MediaPlayer*);
430
431 #if ENABLE(MEDIA_SOURCE)
432     virtual void mediaPlayerSourceOpened();
433     virtual String mediaPlayerSourceURL() const;
434     bool isValidSourceId(const String&, ExceptionCode&) const;
435 #endif
436
437 #if ENABLE(ENCRYPTED_MEDIA)
438     virtual void mediaPlayerKeyAdded(MediaPlayer*, const String& keySystem, const String& sessionId) OVERRIDE;
439     virtual void mediaPlayerKeyError(MediaPlayer*, const String& keySystem, const String& sessionId, MediaPlayerClient::MediaKeyErrorCode, unsigned short systemCode) OVERRIDE;
440     virtual void mediaPlayerKeyMessage(MediaPlayer*, const String& keySystem, const String& sessionId, const unsigned char* message, unsigned messageLength) OVERRIDE;
441     virtual void mediaPlayerKeyNeeded(MediaPlayer*, const String& keySystem, const String& sessionId, const unsigned char* initData, unsigned initDataLength) OVERRIDE;
442 #endif
443
444     virtual String mediaPlayerReferrer() const OVERRIDE;
445     virtual String mediaPlayerUserAgent() const OVERRIDE;
446     virtual CORSMode mediaPlayerCORSMode() const OVERRIDE;
447
448     virtual bool mediaPlayerNeedsSiteSpecificHacks() const OVERRIDE;
449     virtual String mediaPlayerDocumentHost() const OVERRIDE;
450
451     virtual void mediaPlayerExitFullscreen() OVERRIDE;
452     virtual bool mediaPlayerIsVideo() const OVERRIDE;
453     virtual LayoutRect mediaPlayerContentBoxRect() const OVERRIDE;
454     virtual void mediaPlayerSetSize(const IntSize&) OVERRIDE;
455     virtual void mediaPlayerPause() OVERRIDE;
456     virtual void mediaPlayerPlay() OVERRIDE;
457     virtual bool mediaPlayerIsPaused() const OVERRIDE;
458     virtual bool mediaPlayerIsLooping() const OVERRIDE;
459     virtual HostWindow* mediaPlayerHostWindow() OVERRIDE;
460     virtual IntRect mediaPlayerWindowClipRect() OVERRIDE;
461
462 #if PLATFORM(WIN) && USE(AVFOUNDATION)
463     virtual GraphicsDeviceAdapter* mediaPlayerGraphicsDeviceAdapter(const MediaPlayer*) const OVERRIDE;
464 #endif
465
466 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
467     virtual void setSuspended(bool);
468 #endif
469
470     void loadTimerFired(Timer<HTMLMediaElement>*);
471     void progressEventTimerFired(Timer<HTMLMediaElement>*);
472     void playbackProgressTimerFired(Timer<HTMLMediaElement>*);
473     void startPlaybackProgressTimer();
474     void startProgressEventTimer();
475     void stopPeriodicTimers();
476
477     void seek(float time, ExceptionCode&);
478     void finishSeek();
479     void checkIfSeekNeeded();
480     void addPlayedRange(float start, float end);
481     
482     void scheduleTimeupdateEvent(bool periodicEvent);
483     void scheduleEvent(const AtomicString& eventName);
484     
485     // loading
486     void selectMediaResource();
487     void loadResource(const KURL&, ContentType&, const String& keySystem);
488     void scheduleNextSourceChild();
489     void loadNextSourceChild();
490     void userCancelledLoad();
491     bool havePotentialSourceChild();
492     void noneSupported();
493     void mediaEngineError(PassRefPtr<MediaError> err);
494     void cancelPendingEventsAndCallbacks();
495     void waitForSourceChange();
496     void prepareToPlay();
497
498     KURL selectNextSourceChild(ContentType*, String* keySystem, InvalidURLAction);
499
500     void mediaLoadingFailed(MediaPlayer::NetworkState);
501
502 #if ENABLE(VIDEO_TRACK)
503     void updateActiveTextTrackCues(float);
504     bool userIsInterestedInThisLanguage(const String&) const;
505     HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const;
506
507     bool ignoreTrackDisplayUpdateRequests() const { return m_ignoreTrackDisplayUpdate > 0; }
508     void beginIgnoringTrackDisplayUpdateRequests() { ++m_ignoreTrackDisplayUpdate; }
509     void endIgnoringTrackDisplayUpdateRequests() { ASSERT(m_ignoreTrackDisplayUpdate); --m_ignoreTrackDisplayUpdate; }
510 #endif
511
512     // These "internal" functions do not check user gesture restrictions.
513     void loadInternal();
514     void playInternal();
515     void pauseInternal();
516
517     void prepareForLoad();
518     void allowVideoRendering();
519
520     bool processingMediaPlayerCallback() const { return m_processingMediaPlayerCallback > 0; }
521     void beginProcessingMediaPlayerCallback() { ++m_processingMediaPlayerCallback; }
522     void endProcessingMediaPlayerCallback() { ASSERT(m_processingMediaPlayerCallback); --m_processingMediaPlayerCallback; }
523
524     void updateVolume();
525     void updatePlayState();
526     bool potentiallyPlaying() const;
527     bool endedPlayback() const;
528     bool stoppedDueToErrors() const;
529     bool pausedForUserInteraction() const;
530     bool couldPlayIfEnoughData() const;
531
532     float minTimeSeekable() const;
533     float maxTimeSeekable() const;
534
535     // Pauses playback without changing any states or generating events
536     void setPausedInternal(bool);
537
538     void setPlaybackRateInternal(float);
539
540     virtual void mediaCanStart();
541
542     void setShouldDelayLoadEvent(bool);
543     void invalidateCachedTime();
544     void refreshCachedTime() const;
545
546     bool hasMediaControls() const;
547     bool createMediaControls();
548     void configureMediaControls();
549
550     void prepareMediaFragmentURI();
551     void applyMediaFragmentURI();
552
553     virtual void* preDispatchEventHandler(Event*);
554
555     void changeNetworkStateFromLoadingToIdle();
556
557     void removeBehaviorsRestrictionsAfterFirstUserGesture();
558
559 #if ENABLE(MICRODATA)
560     virtual String itemValueText() const;
561     virtual void setItemValueText(const String&, ExceptionCode&);
562 #endif
563
564     void updateMediaController();
565     bool isBlocked() const;
566     bool isBlockedOnMediaController() const;
567     bool hasCurrentSrc() const { return !m_currentSrc.isEmpty(); }
568     bool isLiveStream() const { return movieLoadType() == MediaPlayer::LiveStream; }
569     bool isAutoplaying() const { return m_autoplaying; }
570
571 #if PLATFORM(MAC)
572     void updateDisableSleep();
573     bool shouldDisableSleep() const;
574 #endif
575
576 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
577     bool shouldSuspendMedia();
578 #endif
579
580     Timer<HTMLMediaElement> m_loadTimer;
581     Timer<HTMLMediaElement> m_progressEventTimer;
582     Timer<HTMLMediaElement> m_playbackProgressTimer;
583     RefPtr<TimeRanges> m_playedTimeRanges;
584     OwnPtr<GenericEventQueue> m_asyncEventQueue;
585
586     float m_playbackRate;
587     float m_defaultPlaybackRate;
588     bool m_webkitPreservesPitch;
589     NetworkState m_networkState;
590     ReadyState m_readyState;
591     ReadyState m_readyStateMaximum;
592     KURL m_currentSrc;
593
594     RefPtr<MediaError> m_error;
595
596     float m_volume;
597     float m_lastSeekTime;
598     
599     unsigned m_previousProgress;
600     double m_previousProgressTime;
601
602     // The last time a timeupdate event was sent (wall clock).
603     double m_lastTimeUpdateEventWallTime;
604
605     // The last time a timeupdate event was sent in movie time.
606     float m_lastTimeUpdateEventMovieTime;
607     
608     // Loading state.
609     enum LoadState { WaitingForSource, LoadingFromSrcAttr, LoadingFromSourceElement };
610     LoadState m_loadState;
611     RefPtr<HTMLSourceElement> m_currentSourceNode;
612     RefPtr<Node> m_nextChildNodeToConsider;
613
614     OwnPtr<MediaPlayer> m_player;
615 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
616     RefPtr<Widget> m_proxyWidget;
617 #endif
618
619     BehaviorRestrictions m_restrictions;
620     
621     MediaPlayer::Preload m_preload;
622
623     DisplayMode m_displayMode;
624
625     // Counter incremented while processing a callback from the media player, so we can avoid
626     // calling the media engine recursively.
627     int m_processingMediaPlayerCallback;
628
629 #if ENABLE(MEDIA_SOURCE)
630     KURL m_mediaSourceURL;
631     SourceState m_sourceState;
632     HashSet<String> m_sourceIDs;
633 #endif
634
635     mutable float m_cachedTime;
636     mutable double m_cachedTimeWallClockUpdateTime;
637     mutable double m_minimumWallClockTimeToCacheMediaTime;
638
639     double m_fragmentStartTime;
640     double m_fragmentEndTime;
641
642     typedef unsigned PendingLoadFlags;
643     PendingLoadFlags m_pendingLoadFlags;
644
645     bool m_playing : 1;
646     bool m_isWaitingUntilMediaCanStart : 1;
647     bool m_shouldDelayLoadEvent : 1;
648     bool m_haveFiredLoadedData : 1;
649     bool m_inActiveDocument : 1;
650     bool m_autoplaying : 1;
651     bool m_muted : 1;
652     bool m_paused : 1;
653     bool m_seeking : 1;
654
655     // data has not been loaded since sending a "stalled" event
656     bool m_sentStalledEvent : 1;
657
658     // time has not changed since sending an "ended" event
659     bool m_sentEndEvent : 1;
660
661     bool m_pausedInternal : 1;
662
663     // Not all media engines provide enough information about a file to be able to
664     // support progress events so setting m_sendProgressEvents disables them 
665     bool m_sendProgressEvents : 1;
666
667     bool m_isFullscreen : 1;
668     bool m_closedCaptionsVisible : 1;
669
670 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
671     bool m_needWidgetUpdate : 1;
672 #endif
673
674     bool m_dispatchingCanPlayEvent : 1;
675     bool m_loadInitiatedByUserGesture : 1;
676     bool m_completelyLoaded : 1;
677     bool m_havePreparedToPlay : 1;
678     bool m_parsingInProgress : 1;
679
680 #if ENABLE(VIDEO_TRACK)
681     bool m_tracksAreReady : 1;
682     bool m_haveVisibleTextTrack : 1;
683     float m_lastTextTrackUpdateTime;
684
685     RefPtr<TextTrackList> m_textTracks;
686     Vector<RefPtr<TextTrack> > m_textTracksWhenResourceSelectionBegan;
687
688     CueIntervalTree m_cueTree;
689
690     CueList m_currentlyActiveCues;
691     int m_ignoreTrackDisplayUpdate;
692     bool m_disableCaptions;
693 #endif
694
695 #if ENABLE(WEB_AUDIO)
696     // This is a weak reference, since m_audioSourceNode holds a reference to us.
697     // The value is set just after the MediaElementAudioSourceNode is created.
698     // The value is cleared in MediaElementAudioSourceNode::~MediaElementAudioSourceNode().
699     MediaElementAudioSourceNode* m_audioSourceNode;
700 #endif
701
702     String m_mediaGroup;
703     friend class MediaController;
704     RefPtr<MediaController> m_mediaController;
705
706 #if PLATFORM(MAC)
707     OwnPtr<DisplaySleepDisabler> m_sleepDisabler;
708 #endif
709
710 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
711     bool m_suspended;
712 #endif
713 };
714
715 #if ENABLE(VIDEO_TRACK)
716 #ifndef NDEBUG
717 // Template specializations required by PodIntervalTree in debug mode.
718 template <>
719 struct ValueToString<double> {
720     static String string(const double value)
721     {
722         return String::number(value);
723     }
724 };
725
726 template <>
727 struct ValueToString<TextTrackCue*> {
728     static String string(TextTrackCue* const& cue)
729     {
730         return String::format("%p id=%s interval=%f-->%f cue=%s)", cue, cue->id().utf8().data(), cue->startTime(), cue->endTime(), cue->text().utf8().data());
731     }
732 };
733 #endif
734 #endif
735
736 inline bool isMediaElement(Node* node)
737 {
738     return node && node->isElementNode() && toElement(node)->isMediaElement();
739 }
740
741 inline HTMLMediaElement* toMediaElement(Node* node)
742 {
743     ASSERT(!node || isMediaElement(node));
744     return static_cast<HTMLMediaElement*>(node);
745 }
746
747 } //namespace
748
749 #endif
750 #endif