| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 #include "bindings/core/v8/ScriptPromiseProperty.h" | 29 #include "bindings/core/v8/ScriptPromiseProperty.h" |
| 30 #include "core/dom/ActiveDOMObject.h" | 30 #include "core/dom/ActiveDOMObject.h" |
| 31 #include "core/dom/DOMArrayPiece.h" | 31 #include "core/dom/DOMArrayPiece.h" |
| 32 #include "core/dom/DOMException.h" | 32 #include "core/dom/DOMException.h" |
| 33 #include "modules/EventTargetModules.h" | 33 #include "modules/EventTargetModules.h" |
| 34 #include "modules/encryptedmedia/MediaKeyStatusMap.h" | 34 #include "modules/encryptedmedia/MediaKeyStatusMap.h" |
| 35 #include "platform/Timer.h" | 35 #include "platform/Timer.h" |
| 36 #include "platform/heap/Handle.h" | 36 #include "platform/heap/Handle.h" |
| 37 #include "public/platform/WebContentDecryptionModuleSession.h" | 37 #include "public/platform/WebContentDecryptionModuleSession.h" |
| 38 #include "public/platform/WebEncryptedMediaTypes.h" |
| 38 | 39 |
| 39 namespace blink { | 40 namespace blink { |
| 40 | 41 |
| 41 class GenericEventQueue; | 42 class GenericEventQueue; |
| 42 class MediaKeys; | 43 class MediaKeys; |
| 43 | 44 |
| 44 // References are held by JS only. However, even if all JS references are | 45 // References are held by JS only. However, even if all JS references are |
| 45 // dropped, it won't be garbage collected until close event received or | 46 // dropped, it won't be garbage collected until close event received or |
| 46 // MediaKeys goes away (as determined by the validity of a WeakPtr). This allows | 47 // MediaKeys goes away (as determined by the validity of a WeakPtr). This allows |
| 47 // the CDM to continue to fire events for this session, as long as the session | 48 // the CDM to continue to fire events for this session, as long as the session |
| 48 // is open. | 49 // is open. |
| 49 // | 50 // |
| 50 // WeakPtr<MediaKeys> is used instead of having MediaKeys and MediaKeySession | 51 // WeakPtr<MediaKeys> is used instead of having MediaKeys and MediaKeySession |
| 51 // keep references to each other, and then having to inform the other object | 52 // keep references to each other, and then having to inform the other object |
| 52 // when it gets destroyed. | 53 // when it gets destroyed. |
| 53 // | 54 // |
| 54 // Because this object controls the lifetime of the WebContentDecryptionModuleSe
ssion, | 55 // Because this object controls the lifetime of the WebContentDecryptionModuleSe
ssion, |
| 55 // it may outlive any JavaScript references as long as the MediaKeys object is a
live. | 56 // it may outlive any JavaScript references as long as the MediaKeys object is a
live. |
| 56 // The WebContentDecryptionModuleSession has the same lifetime as this object. | 57 // The WebContentDecryptionModuleSession has the same lifetime as this object. |
| 57 class MediaKeySession final | 58 class MediaKeySession final |
| 58 : public RefCountedGarbageCollectedEventTargetWithInlineData<MediaKeySession
> | 59 : public RefCountedGarbageCollectedEventTargetWithInlineData<MediaKeySession
> |
| 59 , public ActiveDOMObject | 60 , public ActiveDOMObject |
| 60 , private WebContentDecryptionModuleSession::Client { | 61 , private WebContentDecryptionModuleSession::Client { |
| 61 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<M
ediaKeySession>); | 62 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<M
ediaKeySession>); |
| 62 DEFINE_WRAPPERTYPEINFO(); | 63 DEFINE_WRAPPERTYPEINFO(); |
| 63 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaKeySession); | 64 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaKeySession); |
| 64 public: | 65 public: |
| 65 static MediaKeySession* create(ScriptState*, MediaKeys*, const String& sessi
onType); | 66 static MediaKeySession* create(ScriptState*, MediaKeys*, WebEncryptedMediaSe
ssionType); |
| 66 static bool isValidSessionType(const String& sessionType); | 67 static WebEncryptedMediaInitDataType convertInitDataType(const String& initD
ataType); |
| 68 static WebEncryptedMediaSessionType convertSessionType(const String& session
Type); |
| 67 virtual ~MediaKeySession(); | 69 virtual ~MediaKeySession(); |
| 68 | 70 |
| 69 String sessionId() const; | 71 String sessionId() const; |
| 70 double expiration() const { return m_expiration; } | 72 double expiration() const { return m_expiration; } |
| 71 ScriptPromise closed(ScriptState*); | 73 ScriptPromise closed(ScriptState*); |
| 72 MediaKeyStatusMap* keyStatuses(); | 74 MediaKeyStatusMap* keyStatuses(); |
| 73 | 75 |
| 74 ScriptPromise generateRequest(ScriptState*, const String& initDataType, cons
t DOMArrayPiece& initData); | 76 ScriptPromise generateRequest(ScriptState*, const String& initDataType, cons
t DOMArrayPiece& initData); |
| 75 ScriptPromise load(ScriptState*, const String& sessionId); | 77 ScriptPromise load(ScriptState*, const String& sessionId); |
| 76 | 78 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 88 virtual bool hasPendingActivity() const override; | 90 virtual bool hasPendingActivity() const override; |
| 89 virtual void stop() override; | 91 virtual void stop() override; |
| 90 | 92 |
| 91 DECLARE_VIRTUAL_TRACE(); | 93 DECLARE_VIRTUAL_TRACE(); |
| 92 | 94 |
| 93 private: | 95 private: |
| 94 class PendingAction; | 96 class PendingAction; |
| 95 friend class NewSessionResultPromise; | 97 friend class NewSessionResultPromise; |
| 96 friend class LoadSessionResultPromise; | 98 friend class LoadSessionResultPromise; |
| 97 | 99 |
| 98 MediaKeySession(ScriptState*, MediaKeys*, const String& sessionType); | 100 MediaKeySession(ScriptState*, MediaKeys*, WebEncryptedMediaSessionType); |
| 99 | 101 |
| 100 void actionTimerFired(Timer<MediaKeySession>*); | 102 void actionTimerFired(Timer<MediaKeySession>*); |
| 101 | 103 |
| 102 // WebContentDecryptionModuleSession::Client | 104 // WebContentDecryptionModuleSession::Client |
| 103 virtual void message(MessageType, const unsigned char* message, size_t messa
geLength) override; | 105 virtual void message(MessageType, const unsigned char* message, size_t messa
geLength) override; |
| 104 virtual void close() override; | 106 virtual void close() override; |
| 105 virtual void expirationChanged(double updatedExpiryTimeInMS) override; | 107 virtual void expirationChanged(double updatedExpiryTimeInMS) override; |
| 106 virtual void keysStatusesChange(const WebVector<WebEncryptedMediaKeyInformat
ion>&, bool hasAdditionalUsableKey) override; | 108 virtual void keysStatusesChange(const WebVector<WebEncryptedMediaKeyInformat
ion>&, bool hasAdditionalUsableKey) override; |
| 107 | 109 |
| 108 // Called by NewSessionResult when the new session has been created. | 110 // Called by NewSessionResult when the new session has been created. |
| 109 void finishGenerateRequest(); | 111 void finishGenerateRequest(); |
| 110 | 112 |
| 111 // Called by LoadSessionResult when the session has been loaded. | 113 // Called by LoadSessionResult when the session has been loaded. |
| 112 void finishLoad(); | 114 void finishLoad(); |
| 113 | 115 |
| 114 String m_keySystem; | 116 String m_keySystem; |
| 115 OwnPtrWillBeMember<GenericEventQueue> m_asyncEventQueue; | 117 OwnPtrWillBeMember<GenericEventQueue> m_asyncEventQueue; |
| 116 OwnPtr<WebContentDecryptionModuleSession> m_session; | 118 OwnPtr<WebContentDecryptionModuleSession> m_session; |
| 117 | 119 |
| 118 // Used to determine if MediaKeys is still active. | 120 // Used to determine if MediaKeys is still active. |
| 119 WeakMember<MediaKeys> m_mediaKeys; | 121 WeakMember<MediaKeys> m_mediaKeys; |
| 120 | 122 |
| 121 // Session properties. | 123 // Session properties. |
| 122 String m_sessionType; | 124 WebEncryptedMediaSessionType m_sessionType; |
| 123 double m_expiration; | 125 double m_expiration; |
| 124 Member<MediaKeyStatusMap> m_keyStatusesMap; | 126 Member<MediaKeyStatusMap> m_keyStatusesMap; |
| 125 | 127 |
| 126 // Session states. | 128 // Session states. |
| 127 bool m_isUninitialized; | 129 bool m_isUninitialized; |
| 128 bool m_isCallable; | 130 bool m_isCallable; |
| 129 bool m_isClosed; // Is the CDM finished with this session? | 131 bool m_isClosed; // Is the CDM finished with this session? |
| 130 | 132 |
| 131 // Keep track of the closed promise. | 133 // Keep track of the closed promise. |
| 132 typedef ScriptPromiseProperty<Member<MediaKeySession>, ToV8UndefinedGenerato
r, RefPtrWillBeMember<DOMException>> ClosedPromise; | 134 typedef ScriptPromiseProperty<Member<MediaKeySession>, ToV8UndefinedGenerato
r, RefPtrWillBeMember<DOMException>> ClosedPromise; |
| 133 Member<ClosedPromise> m_closedPromise; | 135 Member<ClosedPromise> m_closedPromise; |
| 134 | 136 |
| 135 HeapDeque<Member<PendingAction>> m_pendingActions; | 137 HeapDeque<Member<PendingAction>> m_pendingActions; |
| 136 Timer<MediaKeySession> m_actionTimer; | 138 Timer<MediaKeySession> m_actionTimer; |
| 137 }; | 139 }; |
| 138 | 140 |
| 139 } // namespace blink | 141 } // namespace blink |
| 140 | 142 |
| 141 #endif // MediaKeySession_h | 143 #endif // MediaKeySession_h |
| OLD | NEW |