2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef MediaController_h
27 #define MediaController_h
29 #include "core/events/EventTarget.h"
30 #include "core/html/HTMLMediaElement.h"
31 #include "wtf/LinkedHashSet.h"
32 #include "wtf/PassRefPtr.h"
33 #include "wtf/RefCounted.h"
39 class ExecutionContext;
40 class GenericEventQueue;
42 class MediaController FINAL : public RefCountedWillBeGarbageCollectedFinalized<MediaController>, public EventTargetWithInlineData {
43 DEFINE_WRAPPERTYPEINFO();
44 REFCOUNTED_EVENT_TARGET(MediaController);
45 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaController);
47 static PassRefPtrWillBeRawPtr<MediaController> create(ExecutionContext*);
48 virtual ~MediaController();
50 void addMediaElement(HTMLMediaElement*);
51 void removeMediaElement(HTMLMediaElement*);
53 PassRefPtrWillBeRawPtr<TimeRanges> buffered() const;
54 PassRefPtrWillBeRawPtr<TimeRanges> seekable() const;
55 PassRefPtrWillBeRawPtr<TimeRanges> played();
57 double duration() const;
58 double currentTime() const;
59 void setCurrentTime(double);
61 bool paused() const { return m_paused; }
66 double defaultPlaybackRate() const { return m_defaultPlaybackRate; }
67 void setDefaultPlaybackRate(double);
69 double playbackRate() const;
70 void setPlaybackRate(double);
72 double volume() const { return m_volume; }
73 void setVolume(double, ExceptionState&);
75 bool muted() const { return m_muted; }
78 typedef HTMLMediaElement::ReadyState ReadyState;
79 ReadyState readyState() const { return m_readyState; }
81 enum PlaybackState { WAITING, PLAYING, ENDED };
82 const AtomicString& playbackState() const;
84 bool isRestrained() const;
85 bool isBlocked() const;
88 void clearExecutionContext() { m_executionContext = nullptr; }
91 virtual void trace(Visitor*) OVERRIDE;
94 MediaController(ExecutionContext*);
95 void reportControllerState();
96 void updateReadyState();
97 void updatePlaybackState();
98 void updateMediaElements();
99 void bringElementUpToSpeed(HTMLMediaElement*);
100 void scheduleEvent(const AtomicString& eventName);
101 void clearPositionTimerFired(Timer<MediaController>*);
102 bool hasEnded() const;
103 void scheduleTimeupdateEvent();
104 void timeupdateTimerFired(Timer<MediaController>*);
105 void startTimeupdateTimer();
108 virtual const AtomicString& interfaceName() const OVERRIDE;
109 virtual ExecutionContext* executionContext() const OVERRIDE { return m_executionContext; }
111 friend class HTMLMediaElement;
112 friend class MediaControllerEventListener;
113 // FIXME: A MediaController should ideally keep an otherwise
114 // unreferenced slaved media element alive. When Oilpan is
115 // enabled by default, consider making the hash set references
116 // strong to accomplish that. crbug.com/383072
117 typedef WillBeHeapLinkedHashSet<RawPtrWillBeWeakMember<HTMLMediaElement> > MediaElementSequence;
118 MediaElementSequence m_mediaElements;
120 double m_defaultPlaybackRate;
122 mutable double m_position;
124 ReadyState m_readyState;
125 PlaybackState m_playbackState;
126 OwnPtrWillBeMember<GenericEventQueue> m_pendingEventsQueue;
127 mutable Timer<MediaController> m_clearPositionTimer;
128 OwnPtr<Clock> m_clock;
129 RawPtrWillBeWeakMember<ExecutionContext> m_executionContext;
130 Timer<MediaController> m_timeupdateTimer;
131 double m_previousTimeupdateTime;
136 #endif // MediaController_h