Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / mediasource / MediaSourceBase.h
1 /*
2  * Copyright (C) 2013 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef MediaSourceBase_h
32 #define MediaSourceBase_h
33
34 #include "core/dom/ActiveDOMObject.h"
35 #include "core/events/EventTarget.h"
36 #include "core/html/HTMLMediaSource.h"
37 #include "core/html/URLRegistry.h"
38 #include "public/platform/WebMediaSource.h"
39 #include "wtf/PassOwnPtr.h"
40 #include "wtf/RefCounted.h"
41 #include "wtf/Vector.h"
42
43 namespace blink {
44 class WebSourceBuffer;
45 }
46
47 namespace WebCore {
48
49 class ExceptionState;
50 class GenericEventQueue;
51
52 class MediaSourceBase : public RefCountedGarbageCollected<MediaSourceBase>, public HTMLMediaSource, public ActiveDOMObject, public EventTargetWithInlineData {
53     DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedGarbageCollected<MediaSourceBase>);
54 public:
55     static const AtomicString& openKeyword();
56     static const AtomicString& closedKeyword();
57     static const AtomicString& endedKeyword();
58
59     virtual ~MediaSourceBase();
60
61     void addedToRegistry();
62     void removedFromRegistry();
63     void openIfInEndedState();
64     bool isOpen() const;
65
66     // HTMLMediaSource
67     virtual bool attachToElement(HTMLMediaElement*) OVERRIDE FINAL;
68     virtual void setWebMediaSourceAndOpen(PassOwnPtr<blink::WebMediaSource>) OVERRIDE FINAL;
69     virtual void close() OVERRIDE FINAL;
70     virtual bool isClosed() const OVERRIDE FINAL;
71     virtual double duration() const OVERRIDE FINAL;
72     virtual PassRefPtr<TimeRanges> buffered() const OVERRIDE FINAL;
73     virtual void refHTMLMediaSource() OVERRIDE FINAL { ref(); }
74     virtual void derefHTMLMediaSource() OVERRIDE FINAL { deref(); }
75
76     void setDuration(double, ExceptionState&);
77     const AtomicString& readyState() const { return m_readyState; }
78     void setReadyState(const AtomicString&);
79     void endOfStream(const AtomicString& error, ExceptionState&);
80     void endOfStream(ExceptionState&);
81
82     // ActiveDOMObject interface
83     virtual bool hasPendingActivity() const OVERRIDE FINAL;
84     virtual void stop() OVERRIDE FINAL;
85
86     // EventTarget interface
87     virtual ExecutionContext* executionContext() const OVERRIDE FINAL;
88
89     // URLRegistrable interface
90     virtual URLRegistry& registry() const OVERRIDE FINAL;
91
92     virtual void trace(Visitor*) { }
93
94 protected:
95     explicit MediaSourceBase(ExecutionContext*);
96
97     virtual void onReadyStateChange(const AtomicString& oldState, const AtomicString& newState) = 0;
98     virtual Vector<RefPtr<TimeRanges> > activeRanges() const = 0;
99     virtual bool isUpdating() const = 0;
100
101     PassOwnPtr<blink::WebSourceBuffer> createWebSourceBuffer(const String& type, const Vector<String>& codecs, ExceptionState&);
102     void scheduleEvent(const AtomicString& eventName);
103     GenericEventQueue* asyncEventQueue() const { return m_asyncEventQueue.get(); }
104
105 private:
106     void endOfStreamInternal(const blink::WebMediaSource::EndOfStreamStatus, ExceptionState&);
107     OwnPtr<blink::WebMediaSource> m_webMediaSource;
108     AtomicString m_readyState;
109     OwnPtr<GenericEventQueue> m_asyncEventQueue;
110     // FIXME: oilpan: This should become a Member. For now, m_attachedElement will be cleared by the HTMLMediaElement destructor.
111     HTMLMediaElement* m_attachedElement;
112 };
113
114 }
115
116 #endif