Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / encryptedmedia / MediaKeySession.h
1 /*
2  * Copyright (C) 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 INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef MediaKeySession_h
27 #define MediaKeySession_h
28
29 #include "bindings/v8/ScriptWrappable.h"
30 #include "core/dom/ActiveDOMObject.h"
31 #include "core/events/EventTarget.h"
32 #include "heap/Handle.h"
33 #include "platform/Timer.h"
34 #include "platform/drm/ContentDecryptionModuleSession.h"
35 #include "wtf/Deque.h"
36 #include "wtf/PassRefPtr.h"
37 #include "wtf/RefCounted.h"
38 #include "wtf/Uint8Array.h"
39 #include "wtf/text/WTFString.h"
40
41 namespace WebCore {
42
43 class ContentDecryptionModule;
44 class ContentDecryptionModuleSession;
45 class ExceptionState;
46 class GenericEventQueue;
47 class MediaKeyError;
48 class MediaKeys;
49
50 // References are held by JS and MediaKeys.
51 // Because this object controls the lifetime of the ContentDecryptionModuleSession,
52 // it may outlive any references to it as long as the MediaKeys object is alive.
53 // The ContentDecryptionModuleSession has the same lifetime as this object.
54 class MediaKeySession FINAL
55     : public RefCountedWillBeRefCountedGarbageCollected<MediaKeySession>, public ActiveDOMObject, public ScriptWrappable, public EventTargetWithInlineData
56     , private ContentDecryptionModuleSessionClient {
57     DECLARE_GC_INFO;
58     DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<MediaKeySession>);
59 public:
60     static PassRefPtrWillBeRawPtr<MediaKeySession> create(ExecutionContext*, ContentDecryptionModule*, MediaKeys*);
61     virtual ~MediaKeySession();
62
63     const String& keySystem() const { return m_keySystem; }
64     String sessionId() const;
65
66     void setError(MediaKeyError*);
67     MediaKeyError* error() { return m_error.get(); }
68
69     void initializeNewSession(const String& mimeType, const Uint8Array& initData);
70     void update(Uint8Array* response, ExceptionState&);
71     void release(ExceptionState&);
72
73     void enqueueEvent(PassRefPtr<Event>);
74
75     // EventTarget
76     virtual const AtomicString& interfaceName() const OVERRIDE;
77     virtual ExecutionContext* executionContext() const OVERRIDE;
78
79     // ActiveDOMObject
80     virtual bool hasPendingActivity() const OVERRIDE;
81     virtual void stop() OVERRIDE;
82
83     void trace(Visitor*) { }
84
85 private:
86     MediaKeySession(ExecutionContext*, ContentDecryptionModule*, MediaKeys*);
87     void updateTimerFired(Timer<MediaKeySession>*);
88
89     // ContentDecryptionModuleSessionClient
90     virtual void message(const unsigned char* message, size_t messageLength, const KURL& destinationURL) OVERRIDE;
91     virtual void ready() OVERRIDE;
92     virtual void close() OVERRIDE;
93     virtual void error(MediaKeyErrorCode, unsigned long systemCode) OVERRIDE;
94
95     String m_keySystem;
96     RefPtr<MediaKeyError> m_error;
97     OwnPtr<GenericEventQueue> m_asyncEventQueue;
98     OwnPtr<ContentDecryptionModuleSession> m_session;
99     // Used to remove the reference from the parent MediaKeys when close()'d.
100     MediaKeys* m_keys;
101
102     Deque<RefPtr<Uint8Array> > m_pendingUpdates;
103     Timer<MediaKeySession> m_updateTimer;
104 };
105
106 }
107
108 #endif // MediaKeySession_h