• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 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 #include "core/dom/ActiveDOMObject.h"
30 #include "core/events/GenericEventQueue.h"
31 #include "core/html/HTMLElement.h"
32 #include "core/html/track/TextTrack.h"
33 #include "core/html/track/TextTrackCue.h"
34 #include "core/html/track/vtt/VTTCue.h"
35 #include "platform/PODIntervalTree.h"
36 #include "platform/graphics/media/MediaPlayer.h"
37 #include "public/platform/WebMediaPlayerClient.h"
38 #include "public/platform/WebMimeRegistry.h"
39 
40 namespace blink {
41 class WebContentDecryptionModule;
42 class WebInbandTextTrack;
43 class WebLayer;
44 }
45 
46 namespace WebCore {
47 
48 #if ENABLE(WEB_AUDIO)
49 class AudioSourceProvider;
50 class AudioSourceProviderClient;
51 #endif
52 class AudioTrackList;
53 class ContentType;
54 class Event;
55 class ExceptionState;
56 class HTMLSourceElement;
57 class HTMLTrackElement;
58 class KURL;
59 class MediaController;
60 class MediaControls;
61 class MediaError;
62 class HTMLMediaSource;
63 class TextTrackList;
64 class TimeRanges;
65 class URLRegistry;
66 class VideoTrackList;
67 
68 typedef PODIntervalTree<double, TextTrackCue*> CueIntervalTree;
69 typedef CueIntervalTree::IntervalType CueInterval;
70 typedef Vector<CueInterval> CueList;
71 
72 // FIXME: The inheritance from MediaPlayerClient here should be private inheritance.
73 // But it can't be until the Chromium WebMediaPlayerClientImpl class is fixed so it
74 // no longer depends on typecasting a MediaPlayerClient to an HTMLMediaElement.
75 
76 class HTMLMediaElement : public HTMLElement, public WillBeHeapSupplementable<HTMLMediaElement>, public MediaPlayerClient, public ActiveDOMObject
77 {
78     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLMediaElement);
79 public:
80     static blink::WebMimeRegistry::SupportsType supportsType(const ContentType&, const String& keySystem = String());
81 
82     static void setMediaStreamRegistry(URLRegistry*);
83     static bool isMediaStreamURL(const String& url);
84 
85     virtual void trace(Visitor*) OVERRIDE;
86 #if ENABLE(WEB_AUDIO)
87     void clearWeakMembers(Visitor*);
88 #endif
89 
90     // Do not use player().
91     // FIXME: Replace all uses with webMediaPlayer() and remove this API.
player()92     MediaPlayer* player() const { return m_player.get(); }
webMediaPlayer()93     blink::WebMediaPlayer* webMediaPlayer() const { return m_player ? m_player->webMediaPlayer() : 0; }
94 
hasVideo()95     virtual bool hasVideo() const { return false; }
96     bool hasAudio() const;
97 
98     bool supportsSave() const;
99 
100     blink::WebLayer* platformLayer() const;
101 
102     enum DelayedActionType {
103         LoadMediaResource = 1 << 0,
104         LoadTextTrackResource = 1 << 1,
105         TextTrackChangesNotification = 1 << 2
106     };
107     void scheduleDelayedAction(DelayedActionType);
108 
isActive()109     bool isActive() const { return m_active; }
110 
111     // error state
112     PassRefPtrWillBeRawPtr<MediaError> error() const;
113 
114     // network state
115     void setSrc(const AtomicString&);
currentSrc()116     const KURL& currentSrc() const { return m_currentSrc; }
117 
118     enum NetworkState { NETWORK_EMPTY, NETWORK_IDLE, NETWORK_LOADING, NETWORK_NO_SOURCE };
119     NetworkState networkState() const;
120 
121     String preload() const;
122     void setPreload(const AtomicString&);
123 
124     PassRefPtr<TimeRanges> buffered() const;
125     void load();
126     String canPlayType(const String& mimeType, const String& keySystem = String()) const;
127 
128     // ready state
129     enum ReadyState { HAVE_NOTHING, HAVE_METADATA, HAVE_CURRENT_DATA, HAVE_FUTURE_DATA, HAVE_ENOUGH_DATA };
130     ReadyState readyState() const;
131     bool seeking() const;
132 
133     // playback state
134     double currentTime() const;
135     void setCurrentTime(double, ExceptionState&);
136     double duration() const;
137     bool paused() const;
138     double defaultPlaybackRate() const;
139     void setDefaultPlaybackRate(double);
140     double playbackRate() const;
141     void setPlaybackRate(double);
142     void updatePlaybackRate();
143     PassRefPtr<TimeRanges> played();
144     PassRefPtr<TimeRanges> seekable() const;
145     bool ended() const;
146     bool autoplay() const;
147     bool loop() const;
148     void setLoop(bool b);
149     void play();
150     void pause();
151 
152     // statistics
153     unsigned webkitAudioDecodedByteCount() const;
154     unsigned webkitVideoDecodedByteCount() const;
155 
156     // media source extensions
157     void closeMediaSource();
158     void durationChanged(double duration, bool requestSeek);
159 
160     // controls
161     bool controls() const;
162     void setControls(bool);
163     double volume() const;
164     void setVolume(double, ExceptionState&);
165     bool muted() const;
166     void setMuted(bool);
167 
168     // play/pause toggling that uses the media controller if present. togglePlayStateWillPlay() is
169     // true if togglePlayState() will call play() or unpause() on the media element or controller.
170     bool togglePlayStateWillPlay() const;
171     void togglePlayState();
172 
173     AudioTrackList& audioTracks();
174     void audioTrackChanged();
175 
176     VideoTrackList& videoTracks();
177     void selectedVideoTrackChanged(blink::WebMediaPlayer::TrackId*);
178 
179     PassRefPtrWillBeRawPtr<TextTrack> addTextTrack(const AtomicString& kind, const AtomicString& label, const AtomicString& language, ExceptionState&);
addTextTrack(const AtomicString & kind,const AtomicString & label,ExceptionState & exceptionState)180     PassRefPtrWillBeRawPtr<TextTrack> addTextTrack(const AtomicString& kind, const AtomicString& label, ExceptionState& exceptionState) { return addTextTrack(kind, label, emptyAtom, exceptionState); }
addTextTrack(const AtomicString & kind,ExceptionState & exceptionState)181     PassRefPtrWillBeRawPtr<TextTrack> addTextTrack(const AtomicString& kind, ExceptionState& exceptionState) { return addTextTrack(kind, emptyAtom, emptyAtom, exceptionState); }
182 
183     TextTrackList* textTracks();
currentlyActiveCues()184     CueList currentlyActiveCues() const { return m_currentlyActiveCues; }
185 
186     void addTextTrack(TextTrack*);
187     void removeTextTrack(TextTrack*);
188     void closeCaptionTracksChanged();
189     void notifyMediaPlayerOfTextTrackChanges();
190 
191     // Implements the "forget the media element's media-resource-specific tracks" algorithm in the HTML5 spec.
192     void forgetResourceSpecificTracks();
193 
194     void didAddTrackElement(HTMLTrackElement*);
195     void didRemoveTrackElement(HTMLTrackElement*);
196 
197     blink::WebMediaPlayer::TrackId addAudioTrack(const String& id, blink::WebMediaPlayerClient::AudioTrackKind, const AtomicString& label, const AtomicString& language, bool enabled);
198     void removeAudioTrack(blink::WebMediaPlayer::TrackId);
199     blink::WebMediaPlayer::TrackId addVideoTrack(const String& id, blink::WebMediaPlayerClient::VideoTrackKind, const AtomicString& label, const AtomicString& language, bool selected);
200     void removeVideoTrack(blink::WebMediaPlayer::TrackId);
201 
202     virtual void mediaPlayerDidAddTextTrack(blink::WebInbandTextTrack*) OVERRIDE FINAL;
203     virtual void mediaPlayerDidRemoveTextTrack(blink::WebInbandTextTrack*) OVERRIDE FINAL;
204     // FIXME: Remove this when WebMediaPlayerClientImpl::loadInternal does not depend on it.
mediaPlayerPosterURL()205     virtual KURL mediaPlayerPosterURL() OVERRIDE { return KURL(); }
206 
207     class TrackGroup {
208         STACK_ALLOCATED();
209     public:
210         enum GroupKind { CaptionsAndSubtitles, Description, Chapter, Metadata, Other };
211 
TrackGroup(GroupKind kind)212         explicit TrackGroup(GroupKind kind)
213             : visibleTrack(nullptr)
214             , defaultTrack(nullptr)
215             , kind(kind)
216             , hasSrcLang(false)
217         {
218         }
219 
220         WillBeHeapVector<RefPtrWillBeMember<TextTrack> > tracks;
221         RefPtrWillBeMember<TextTrack> visibleTrack;
222         RefPtrWillBeMember<TextTrack> defaultTrack;
223         GroupKind kind;
224         bool hasSrcLang;
225     };
226 
227     void configureTextTrackGroupForLanguage(const TrackGroup&) const;
228     void configureTextTracks();
229     void configureTextTrackGroup(const TrackGroup&);
230 
231     bool textTracksAreReady() const;
232     enum VisibilityChangeAssumption {
233         AssumeNoVisibleChange,
234         AssumeVisibleChange
235     };
236     void configureTextTrackDisplay(VisibilityChangeAssumption);
237     void updateTextTrackDisplay();
238     void textTrackReadyStateChanged(TextTrack*);
239 
240     void textTrackKindChanged(TextTrack*);
241     void textTrackModeChanged(TextTrack*);
242     void textTrackAddCues(TextTrack*, const TextTrackCueList*);
243     void textTrackRemoveCues(TextTrack*, const TextTrackCueList*);
244     void textTrackAddCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>);
245     void textTrackRemoveCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>);
246 
247     // EventTarget function.
248     // Both Node (via HTMLElement) and ActiveDOMObject define this method, which
249     // causes an ambiguity error at compile time. This class's constructor
250     // ensures that both implementations return document, so return the result
251     // of one of them here.
252     using HTMLElement::executionContext;
253 
hasSingleSecurityOrigin()254     bool hasSingleSecurityOrigin() const { return !m_player || m_player->hasSingleSecurityOrigin(); }
255 
256     bool isFullscreen() const;
257     void enterFullscreen();
258     void exitFullscreen();
259 
260     bool hasClosedCaptions() const;
261     bool closedCaptionsVisible() const;
262     void setClosedCaptionsVisible(bool);
263 
264     MediaControls* mediaControls() const;
265 
266     void sourceWasRemoved(HTMLSourceElement*);
267     void sourceWasAdded(HTMLSourceElement*);
268 
isPlaying()269     bool isPlaying() const { return m_playing; }
270 
271     // ActiveDOMObject functions.
272     virtual bool hasPendingActivity() const OVERRIDE FINAL;
273     virtual void contextDestroyed() OVERRIDE FINAL;
274 
275 #if ENABLE(WEB_AUDIO)
audioSourceNode()276     AudioSourceProviderClient* audioSourceNode() { return m_audioSourceNode; }
277     void setAudioSourceNode(AudioSourceProviderClient*);
278 
279     AudioSourceProvider* audioSourceProvider();
280 #endif
281 
282     enum InvalidURLAction { DoNothing, Complain };
283     bool isSafeToLoadURL(const KURL&, InvalidURLAction);
284 
285     MediaController* controller() const;
286     void setController(PassRefPtrWillBeRawPtr<MediaController>); // Resets the MediaGroup and sets the MediaController.
287 
288     void scheduleEvent(PassRefPtrWillBeRawPtr<Event>);
289 
290     // Current volume that should be used by the webMediaPlayer(). This method takes muted state
291     // and m_mediaController multipliers into account.
292     double playerVolume() const;
293 
294 #if ENABLE(OILPAN)
isFinalizing()295     bool isFinalizing() const { return m_isFinalizing; }
296 #endif
297 
298 protected:
299     HTMLMediaElement(const QualifiedName&, Document&);
300     virtual ~HTMLMediaElement();
301 
302     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
303     virtual void finishParsingChildren() OVERRIDE FINAL;
304     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
305     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
306 
307     virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
308 
309     enum DisplayMode { Unknown, Poster, PosterWaitingForVideo, Video };
displayMode()310     DisplayMode displayMode() const { return m_displayMode; }
setDisplayMode(DisplayMode mode)311     virtual void setDisplayMode(DisplayMode mode) { m_displayMode = mode; }
312 
313     void setControllerInternal(PassRefPtrWillBeRawPtr<MediaController>);
314 
ignoreTrackDisplayUpdateRequests()315     bool ignoreTrackDisplayUpdateRequests() const { return m_ignoreTrackDisplayUpdate > 0; }
316     void beginIgnoringTrackDisplayUpdateRequests();
317     void endIgnoringTrackDisplayUpdateRequests();
318 
319 private:
320     void createMediaPlayer();
321 
alwaysCreateUserAgentShadowRoot()322     virtual bool alwaysCreateUserAgentShadowRoot() const OVERRIDE FINAL { return true; }
areAuthorShadowsAllowed()323     virtual bool areAuthorShadowsAllowed() const OVERRIDE FINAL { return false; }
324 
325     virtual bool supportsFocus() const OVERRIDE FINAL;
326     virtual bool isMouseFocusable() const OVERRIDE FINAL;
327     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
328     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
329     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE FINAL;
330     virtual void didNotifySubtreeInsertionsToDocument() OVERRIDE;
331     virtual void removedFrom(ContainerNode*) OVERRIDE FINAL;
332     virtual void didRecalcStyle(StyleRecalcChange) OVERRIDE FINAL;
333 
334     virtual void didBecomeFullscreenElement() OVERRIDE FINAL;
335     virtual void willStopBeingFullscreenElement() OVERRIDE FINAL;
336     virtual bool isInteractiveContent() const OVERRIDE FINAL;
337     virtual void defaultEventHandler(Event*) OVERRIDE FINAL;
338 
339     // ActiveDOMObject functions.
340     virtual void stop() OVERRIDE FINAL;
341 
updateDisplayState()342     virtual void updateDisplayState() { }
343 
344     void setReadyState(ReadyState);
345     void setNetworkState(MediaPlayer::NetworkState);
346 
347     virtual void mediaPlayerNetworkStateChanged() OVERRIDE FINAL;
348     virtual void mediaPlayerReadyStateChanged() OVERRIDE FINAL;
349     virtual void mediaPlayerTimeChanged() OVERRIDE FINAL;
350     virtual void mediaPlayerDurationChanged() OVERRIDE FINAL;
351     virtual void mediaPlayerPlaybackStateChanged() OVERRIDE FINAL;
352     virtual void mediaPlayerRequestFullscreen() OVERRIDE FINAL;
353     virtual void mediaPlayerRequestSeek(double) OVERRIDE FINAL;
354     virtual void mediaPlayerRepaint() OVERRIDE FINAL;
355     virtual void mediaPlayerSizeChanged() OVERRIDE FINAL;
356     virtual void mediaPlayerSetWebLayer(blink::WebLayer*) OVERRIDE FINAL;
357     virtual void mediaPlayerMediaSourceOpened(blink::WebMediaSource*) OVERRIDE FINAL;
358 
359     void loadTimerFired(Timer<HTMLMediaElement>*);
360     void progressEventTimerFired(Timer<HTMLMediaElement>*);
361     void playbackProgressTimerFired(Timer<HTMLMediaElement>*);
362     void startPlaybackProgressTimer();
363     void startProgressEventTimer();
364     void stopPeriodicTimers();
365 
366     void seek(double time, ExceptionState&);
367     void finishSeek();
368     void checkIfSeekNeeded();
369     void addPlayedRange(double start, double end);
370 
371     void scheduleTimeupdateEvent(bool periodicEvent);
372     void scheduleEvent(const AtomicString& eventName); // FIXME: Rename to scheduleNamedEvent for clarity.
373 
374     // loading
375     void prepareForLoad();
376     void loadInternal();
377     void selectMediaResource();
378     void loadResource(const KURL&, ContentType&, const String& keySystem);
379     void startPlayerLoad();
380     void setPlayerPreload();
381     blink::WebMediaPlayer::LoadType loadType() const;
382     void scheduleNextSourceChild();
383     void loadNextSourceChild();
384     void userCancelledLoad();
385     void clearMediaPlayer(int flags);
386     void clearMediaPlayerAndAudioSourceProviderClientWithoutLocking();
387     bool havePotentialSourceChild();
388     void noneSupported();
389     void mediaEngineError(PassRefPtrWillBeRawPtr<MediaError>);
390     void cancelPendingEventsAndCallbacks();
391     void waitForSourceChange();
392     void prepareToPlay();
393 
394     KURL selectNextSourceChild(ContentType*, String* keySystem, InvalidURLAction);
395 
396     void mediaLoadingFailed(MediaPlayer::NetworkState);
397 
398     // deferred loading (preload=none)
399     bool loadIsDeferred() const;
400     void deferLoad();
401     void cancelDeferredLoad();
402     void startDeferredLoad();
403     void executeDeferredLoad();
404     void deferredLoadTimerFired(Timer<HTMLMediaElement>*);
405 
406     void updateActiveTextTrackCues(double);
407     HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const;
408 
409     void markCaptionAndSubtitleTracksAsUnconfigured();
410 
411     // This does not check user gesture restrictions.
412     void playInternal();
413 
414     void allowVideoRendering();
415 
416     void updateVolume();
417     void updatePlayState();
418     bool potentiallyPlaying() const;
419     bool endedPlayback() const;
420     bool stoppedDueToErrors() const;
421     bool couldPlayIfEnoughData() const;
422 
423     // Pauses playback without changing any states or generating events
424     void setPausedInternal(bool);
425 
426     void setShouldDelayLoadEvent(bool);
427     void invalidateCachedTime();
428     void refreshCachedTime() const;
429 
430     bool hasMediaControls() const;
431     bool createMediaControls();
432     void configureMediaControls();
433 
434     void prepareMediaFragmentURI();
435     void applyMediaFragmentURI();
436 
437     virtual void* preDispatchEventHandler(Event*) OVERRIDE FINAL;
438 
439     void changeNetworkStateFromLoadingToIdle();
440 
441     const AtomicString& mediaGroup() const;
442     void setMediaGroup(const AtomicString&);
443     void updateMediaController();
444     bool isBlocked() const;
445     bool isBlockedOnMediaController() const;
isAutoplaying()446     bool isAutoplaying() const { return m_autoplaying; }
447 
448     blink::WebMediaPlayer::CORSMode corsMode() const;
449 
450     // Returns the "direction of playback" value as specified in the HTML5 spec.
451     enum DirectionOfPlayback { Backward, Forward };
452     DirectionOfPlayback directionOfPlayback() const;
453 
454     // Returns the "effective playback rate" value as specified in the HTML5 spec.
455     double effectivePlaybackRate() const;
456 
457     // Creates placeholder AudioTrack and/or VideoTrack objects when WebMemediaPlayer objects
458     // advertise they have audio and/or video, but don't explicitly signal them via
459     // addAudioTrack() and addVideoTrack().
460     // FIXME: Remove this once all WebMediaPlayer implementations properly report their track info.
461     void createPlaceholderTracksIfNecessary();
462 
463     // Sets the selected/enabled tracks if they aren't set before we initially
464     // transition to HAVE_METADATA.
465     void selectInitialTracksIfNecessary();
466 
467     void audioTracksTimerFired(Timer<HTMLMediaElement>*);
468 
469     Timer<HTMLMediaElement> m_loadTimer;
470     Timer<HTMLMediaElement> m_progressEventTimer;
471     Timer<HTMLMediaElement> m_playbackProgressTimer;
472     Timer<HTMLMediaElement> m_audioTracksTimer;
473     RefPtr<TimeRanges> m_playedTimeRanges;
474     OwnPtrWillBeMember<GenericEventQueue> m_asyncEventQueue;
475 
476     double m_playbackRate;
477     double m_defaultPlaybackRate;
478     NetworkState m_networkState;
479     ReadyState m_readyState;
480     ReadyState m_readyStateMaximum;
481     KURL m_currentSrc;
482 
483     RefPtrWillBeMember<MediaError> m_error;
484 
485     double m_volume;
486     double m_lastSeekTime;
487 
488     double m_previousProgressTime;
489 
490     // Cached duration to suppress duplicate events if duration unchanged.
491     double m_duration;
492 
493     // The last time a timeupdate event was sent (wall clock).
494     double m_lastTimeUpdateEventWallTime;
495 
496     // The last time a timeupdate event was sent in movie time.
497     double m_lastTimeUpdateEventMovieTime;
498 
499     // Loading state.
500     enum LoadState { WaitingForSource, LoadingFromSrcAttr, LoadingFromSourceElement };
501     LoadState m_loadState;
502     RefPtrWillBeMember<HTMLSourceElement> m_currentSourceNode;
503     RefPtrWillBeMember<Node> m_nextChildNodeToConsider;
504 
505     // "Deferred loading" state (for preload=none).
506     enum DeferredLoadState {
507         // The load is not deferred.
508         NotDeferred,
509         // The load is deferred, and waiting for the task to set the
510         // delaying-the-load-event flag (to false).
511         WaitingForStopDelayingLoadEventTask,
512         // The load is the deferred, and waiting for a triggering event.
513         WaitingForTrigger,
514         // The load is deferred, and waiting for the task to set the
515         // delaying-the-load-event flag, after which the load will be executed.
516         ExecuteOnStopDelayingLoadEventTask
517     };
518     DeferredLoadState m_deferredLoadState;
519     Timer<HTMLMediaElement> m_deferredLoadTimer;
520 
521     OwnPtr<MediaPlayer> m_player;
522     blink::WebLayer* m_webLayer;
523 
524     MediaPlayer::Preload m_preload;
525 
526     DisplayMode m_displayMode;
527 
528     RefPtr<HTMLMediaSource> m_mediaSource;
529 
530     mutable double m_cachedTime;
531     mutable double m_cachedTimeWallClockUpdateTime;
532     mutable double m_minimumWallClockTimeToCacheMediaTime;
533 
534     double m_fragmentStartTime;
535     double m_fragmentEndTime;
536 
537     typedef unsigned PendingActionFlags;
538     PendingActionFlags m_pendingActionFlags;
539 
540     // FIXME: MediaElement has way too many state bits.
541     bool m_userGestureRequiredForPlay : 1;
542     bool m_playing : 1;
543     bool m_shouldDelayLoadEvent : 1;
544     bool m_haveFiredLoadedData : 1;
545     bool m_active : 1;
546     bool m_autoplaying : 1;
547     bool m_muted : 1;
548     bool m_paused : 1;
549     bool m_seeking : 1;
550 
551     // data has not been loaded since sending a "stalled" event
552     bool m_sentStalledEvent : 1;
553 
554     // time has not changed since sending an "ended" event
555     bool m_sentEndEvent : 1;
556 
557     bool m_pausedInternal : 1;
558 
559     bool m_closedCaptionsVisible : 1;
560 
561     bool m_completelyLoaded : 1;
562     bool m_havePreparedToPlay : 1;
563     bool m_delayingLoadForPreloadNone : 1;
564 
565     bool m_tracksAreReady : 1;
566     bool m_haveVisibleTextTrack : 1;
567     bool m_processingPreferenceChange : 1;
568 #if ENABLE(OILPAN)
569     bool m_isFinalizing : 1;
570 #endif
571     double m_lastTextTrackUpdateTime;
572 
573     RefPtrWillBeMember<AudioTrackList> m_audioTracks;
574     RefPtrWillBeMember<VideoTrackList> m_videoTracks;
575     RefPtrWillBeMember<TextTrackList> m_textTracks;
576     WillBeHeapVector<RefPtrWillBeMember<TextTrack> > m_textTracksWhenResourceSelectionBegan;
577 
578     CueIntervalTree m_cueTree;
579 
580     CueList m_currentlyActiveCues;
581     int m_ignoreTrackDisplayUpdate;
582 
583 #if ENABLE(WEB_AUDIO)
584     // This is a weak reference, since m_audioSourceNode holds a reference to us.
585     // FIXME: Oilpan: Consider making this a strongly traced pointer with oilpan where strong cycles are not a problem.
586     RawPtrWillBeWeakMember<AudioSourceProviderClient> m_audioSourceNode;
587 #endif
588 
589     friend class MediaController;
590     RefPtrWillBeMember<MediaController> m_mediaController;
591 
592     friend class Internals;
593     friend class TrackDisplayUpdateScope;
594 
595     static URLRegistry* s_mediaStreamRegistry;
596 };
597 
598 #ifndef NDEBUG
599 // Template specializations required by PodIntervalTree in debug mode.
600 template <>
601 struct ValueToString<double> {
602     static String string(const double value)
603     {
604         return String::number(value);
605     }
606 };
607 
608 template <>
609 struct ValueToString<TextTrackCue*> {
610     static String string(TextTrackCue* const& cue)
611     {
612         return cue->toString();
613     }
614 };
615 #endif
616 
617 inline bool isHTMLMediaElement(const Element& element)
618 {
619     return isHTMLAudioElement(element) || isHTMLVideoElement(element);
620 }
621 
622 inline bool isHTMLMediaElement(const HTMLElement& element)
623 {
624     return isHTMLAudioElement(element) || isHTMLVideoElement(element);
625 }
626 
627 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLMediaElement);
628 
629 } //namespace
630 
631 #endif
632