#ifndef MediaKeySession_h
#define MediaKeySession_h
#include "bindings/v8/ScriptWrappable.h"
#include "core/dom/ActiveDOMObject.h"
#include "core/events/EventTarget.h"
#include "heap/Handle.h"
#include "platform/Timer.h"
#include "public/platform/WebContentDecryptionModuleSession.h"
#include "wtf/Deque.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/Uint8Array.h"
#include "wtf/WeakPtr.h"
#include "wtf/text/WTFString.h"
namespace blink {
class WebContentDecryptionModule;
}
namespace WebCore {
class ExceptionState;
class GenericEventQueue;
class MediaKeyError;
class MediaKeys;
class MediaKeySession FINAL
: public RefCountedWillBeRefCountedGarbageCollected<MediaKeySession>, public ActiveDOMObject, public ScriptWrappable, public EventTargetWithInlineData
, private blink::WebContentDecryptionModuleSession::Client {
DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<MediaKeySession>);
public:
static PassRefPtrWillBeRawPtr<MediaKeySession> create(ExecutionContext*, blink::WebContentDecryptionModule*, WeakPtr<MediaKeys>);
virtual ~MediaKeySession();
const String& keySystem() const { return m_keySystem; }
String sessionId() const;
void setError(MediaKeyError*);
MediaKeyError* error() { return m_error.get(); }
void initializeNewSession(const String& mimeType, const Uint8Array& initData);
void update(Uint8Array* response, ExceptionState&);
void release(ExceptionState&);
void enqueueEvent(PassRefPtrWillBeRawPtr<Event>);
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ExecutionContext* executionContext() const OVERRIDE;
virtual bool hasPendingActivity() const OVERRIDE;
virtual void stop() OVERRIDE;
void trace(Visitor*) { }
private:
struct PendingAction {
enum Type {
Update,
Release
};
const Type type;
const RefPtr<Uint8Array> data;
static PassOwnPtr<PendingAction> CreatePendingUpdate(PassRefPtr<Uint8Array> data);
static PassOwnPtr<PendingAction> CreatePendingRelease();
~PendingAction();
private:
PendingAction(Type, PassRefPtr<Uint8Array> data);
};
MediaKeySession(ExecutionContext*, blink::WebContentDecryptionModule*, WeakPtr<MediaKeys>);
void actionTimerFired(Timer<MediaKeySession>*);
virtual void message(const unsigned char* message, size_t messageLength, const blink::WebURL& destinationURL) OVERRIDE;
virtual void ready() OVERRIDE;
virtual void close() OVERRIDE;
virtual void error(MediaKeyErrorCode, unsigned long systemCode) OVERRIDE;
String m_keySystem;
RefPtr<MediaKeyError> m_error;
OwnPtr<GenericEventQueue> m_asyncEventQueue;
OwnPtr<blink::WebContentDecryptionModuleSession> m_session;
WeakPtr<MediaKeys> m_keys;
bool m_isClosed;
Deque<OwnPtr<PendingAction> > m_pendingActions;
Timer<MediaKeySession> m_actionTimer;
};
}
#endif