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/ContextLifecycleObserver.h"
31 #include "core/events/EventTarget.h"
32 #include "platform/Timer.h"
33 #include "platform/drm/ContentDecryptionModuleSession.h"
34 #include "wtf/Deque.h"
35 #include "wtf/PassRefPtr.h"
36 #include "wtf/RefCounted.h"
37 #include "wtf/Uint8Array.h"
38 #include "wtf/text/WTFString.h"
42 class ContentDecryptionModule;
43 class ContentDecryptionModuleSession;
45 class GenericEventQueue;
49 // References are held by JS and MediaKeys.
50 // Because this object controls the lifetime of the ContentDecryptionModuleSession,
51 // it may outlive any references to it as long as the MediaKeys object is alive.
52 // The ContentDecryptionModuleSession has the same lifetime as this object.
53 class MediaKeySession FINAL
54 : public RefCounted<MediaKeySession>, public ScriptWrappable, public EventTargetWithInlineData, public ContextLifecycleObserver
55 , private ContentDecryptionModuleSessionClient {
56 REFCOUNTED_EVENT_TARGET(MediaKeySession);
58 static PassRefPtr<MediaKeySession> create(ExecutionContext*, ContentDecryptionModule*, MediaKeys*);
59 virtual ~MediaKeySession();
61 const String& keySystem() const { return m_keySystem; }
62 String sessionId() const;
64 void setError(MediaKeyError*);
65 MediaKeyError* error() { return m_error.get(); }
67 void initializeNewSession(const String& mimeType, const Uint8Array& initData);
68 void update(Uint8Array* response, ExceptionState&);
69 void release(ExceptionState&);
71 void enqueueEvent(PassRefPtr<Event>);
73 virtual const AtomicString& interfaceName() const OVERRIDE;
74 virtual ExecutionContext* executionContext() const OVERRIDE;
77 MediaKeySession(ExecutionContext*, ContentDecryptionModule*, MediaKeys*);
78 void updateTimerFired(Timer<MediaKeySession>*);
80 // ContentDecryptionModuleSessionClient
81 virtual void message(const unsigned char* message, size_t messageLength, const KURL& destinationURL) OVERRIDE;
82 virtual void ready() OVERRIDE;
83 virtual void close() OVERRIDE;
84 virtual void error(MediaKeyErrorCode, unsigned long systemCode) OVERRIDE;
87 RefPtr<MediaKeyError> m_error;
88 OwnPtr<GenericEventQueue> m_asyncEventQueue;
89 OwnPtr<ContentDecryptionModuleSession> m_session;
90 // Used to remove the reference from the parent MediaKeys when close()'d.
93 Deque<RefPtr<Uint8Array> > m_pendingUpdates;
94 Timer<MediaKeySession> m_updateTimer;
99 #endif // MediaKeySession_h