2 * Copyright (C) 2013 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 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.
26 #ifndef MediaKeySession_h
27 #define MediaKeySession_h
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"
43 class ContentDecryptionModule;
44 class ContentDecryptionModuleSession;
46 class GenericEventQueue;
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 {
58 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<MediaKeySession>);
60 static PassRefPtrWillBeRawPtr<MediaKeySession> create(ExecutionContext*, ContentDecryptionModule*, MediaKeys*);
61 virtual ~MediaKeySession();
63 const String& keySystem() const { return m_keySystem; }
64 String sessionId() const;
66 void setError(MediaKeyError*);
67 MediaKeyError* error() { return m_error.get(); }
69 void initializeNewSession(const String& mimeType, const Uint8Array& initData);
70 void update(Uint8Array* response, ExceptionState&);
71 void release(ExceptionState&);
73 void enqueueEvent(PassRefPtr<Event>);
76 virtual const AtomicString& interfaceName() const OVERRIDE;
77 virtual ExecutionContext* executionContext() const OVERRIDE;
80 virtual bool hasPendingActivity() const OVERRIDE;
81 virtual void stop() OVERRIDE;
83 void trace(Visitor*) { }
86 MediaKeySession(ExecutionContext*, ContentDecryptionModule*, MediaKeys*);
87 void updateTimerFired(Timer<MediaKeySession>*);
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;
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.
102 Deque<RefPtr<Uint8Array> > m_pendingUpdates;
103 Timer<MediaKeySession> m_updateTimer;
108 #endif // MediaKeySession_h