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