Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "content/renderer/media/webcontentdecryptionmoduleresult_helper.h" | |
| 16 #include "media/base/media_keys.h" | 17 #include "media/base/media_keys.h" |
| 17 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h " | 18 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h " |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 | 20 |
| 20 namespace media { | 21 namespace media { |
| 21 class MediaKeys; | 22 class MediaKeys; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 class CdmSessionAdapter; | 26 class CdmSessionAdapter; |
| 26 | 27 |
| 27 class WebContentDecryptionModuleSessionImpl | 28 class WebContentDecryptionModuleSessionImpl |
| 28 : public blink::WebContentDecryptionModuleSession { | 29 : public blink::WebContentDecryptionModuleSession { |
| 29 public: | 30 public: |
| 30 WebContentDecryptionModuleSessionImpl( | 31 WebContentDecryptionModuleSessionImpl( |
| 31 const scoped_refptr<CdmSessionAdapter>& adapter); | 32 const scoped_refptr<CdmSessionAdapter>& adapter); |
| 32 virtual ~WebContentDecryptionModuleSessionImpl(); | 33 virtual ~WebContentDecryptionModuleSessionImpl(); |
| 33 | 34 |
| 34 // blink::WebContentDecryptionModuleSession implementation. | 35 // blink::WebContentDecryptionModuleSession implementation. |
| 35 virtual void setClientInterface(Client* client); | 36 virtual void setClientInterface(Client* client); |
| 36 virtual blink::WebString sessionId() const; | 37 virtual blink::WebString sessionId() const; |
| 37 // TODO(jrummell): Remove the next 3 methods once blink updated. | 38 // TODO(jrummell): Remove the next 3 methods once blink updated. |
|
ddorwin
2014/09/12 21:46:30
Is there a reason Blink hasn't been updated? Chrom
jrummell
2014/09/15 18:22:40
Not really. Just haven't gotten around to doing th
| |
| 38 virtual void initializeNewSession(const blink::WebString& mime_type, | 39 virtual void initializeNewSession(const blink::WebString& mime_type, |
| 39 const uint8* init_data, | 40 const uint8* init_data, |
| 40 size_t init_data_length); | 41 size_t init_data_length); |
| 41 virtual void update(const uint8* response, size_t response_length); | 42 virtual void update(const uint8* response, size_t response_length); |
| 42 virtual void release(); | 43 virtual void release(); |
| 43 virtual void initializeNewSession( | 44 virtual void initializeNewSession( |
| 44 const blink::WebString& init_data_type, | 45 const blink::WebString& init_data_type, |
| 45 const uint8* init_data, | 46 const uint8* init_data, |
| 46 size_t init_data_length, | 47 size_t init_data_length, |
| 47 const blink::WebString& session_type, | 48 const blink::WebString& session_type, |
| 48 blink::WebContentDecryptionModuleResult result); | 49 blink::WebContentDecryptionModuleResult result); |
| 49 virtual void update(const uint8* response, | 50 virtual void update(const uint8* response, |
| 50 size_t response_length, | 51 size_t response_length, |
| 51 blink::WebContentDecryptionModuleResult result); | 52 blink::WebContentDecryptionModuleResult result); |
| 53 virtual void close(blink::WebContentDecryptionModuleResult result); | |
| 54 virtual void remove(blink::WebContentDecryptionModuleResult result); | |
| 55 virtual void getUsableKeyIds(blink::WebContentDecryptionModuleResult result); | |
| 56 | |
| 57 // TODO(jrummell): Remove the next method once blink updated. | |
| 52 virtual void release(blink::WebContentDecryptionModuleResult result); | 58 virtual void release(blink::WebContentDecryptionModuleResult result); |
| 53 | 59 |
| 54 // Callbacks. | 60 // Callbacks. |
| 55 void OnSessionMessage(const std::vector<uint8>& message, | 61 void OnSessionMessage(const std::vector<uint8>& message, |
| 56 const GURL& destination_url); | 62 const GURL& destination_url); |
| 63 void OnSessionKeysChange(bool has_additional_usable_key); | |
| 64 void OnSessionExpirationChange(double new_expiry_time); | |
| 57 void OnSessionReady(); | 65 void OnSessionReady(); |
| 58 void OnSessionClosed(); | 66 void OnSessionClosed(); |
| 59 void OnSessionError(media::MediaKeys::Exception exception_code, | 67 void OnSessionError(media::MediaKeys::Exception exception_code, |
| 60 uint32 system_code, | 68 uint32 system_code, |
| 61 const std::string& error_message); | 69 const std::string& error_message); |
| 62 | 70 |
| 63 private: | 71 private: |
| 64 typedef std::map<uint32, blink::WebContentDecryptionModuleResult> ResultMap; | |
| 65 | |
| 66 // These function are used as callbacks when CdmPromise resolves/rejects. | 72 // These function are used as callbacks when CdmPromise resolves/rejects. |
| 67 // |result_index| = kReservedIndex means that there is no | 73 // |result_index| = kReservedIndex means that there is no |
| 68 // WebContentDecryptionModuleResult. | 74 // WebContentDecryptionModuleResult. |
| 69 void SessionCreated(uint32 result_index, const std::string& web_session_id); | 75 void SessionCreated(uint32 result_index, const std::string& web_session_id); |
| 70 void SessionUpdatedOrReleased(uint32 result_index); | 76 void SessionUpdatedOrReleased(uint32 result_index); |
| 77 void KeyIdsAvailable(uint32 result_index, const media::KeyIdsVector& key_ids); | |
| 71 void SessionError(uint32 result_index, | 78 void SessionError(uint32 result_index, |
| 72 media::MediaKeys::Exception exception_code, | 79 media::MediaKeys::Exception exception_code, |
| 73 uint32 system_code, | 80 uint32 system_code, |
| 74 const std::string& error_message); | 81 const std::string& error_message); |
| 75 | 82 |
| 76 // As initializeNewSession(), update(), and release() get passed a | |
| 77 // WebContentDecryptionModuleResult, keep track of them since this class owns | |
| 78 // it and needs to keep them around until completed. Returns the index used | |
| 79 // to locate the WebContentDecryptionModuleResult when the operation is | |
| 80 // complete. | |
| 81 uint32 AddResult(blink::WebContentDecryptionModuleResult result); | |
| 82 | |
| 83 scoped_refptr<CdmSessionAdapter> adapter_; | 83 scoped_refptr<CdmSessionAdapter> adapter_; |
| 84 | 84 |
| 85 // Non-owned pointer. | 85 // Non-owned pointer. |
| 86 Client* client_; | 86 Client* client_; |
| 87 | 87 |
| 88 // Web session ID is the app visible ID for this session generated by the CDM. | 88 // Web session ID is the app visible ID for this session generated by the CDM. |
| 89 // This value is not set until the CDM resolves the initializeNewSession() | 89 // This value is not set until the CDM resolves the initializeNewSession() |
| 90 // promise. | 90 // promise. |
| 91 std::string web_session_id_; | 91 std::string web_session_id_; |
| 92 | 92 |
| 93 // Don't pass more than 1 close() event to blink:: | 93 // Don't pass more than 1 close() event to blink:: |
| 94 // TODO(jrummell): Remove this once blink tests handle close() promise and | 94 // TODO(jrummell): Remove this once blink tests handle close() promise and |
| 95 // closed() event. | 95 // closed() event. |
| 96 bool is_closed_; | 96 bool is_closed_; |
| 97 | 97 |
| 98 // Keep track of all the outstanding WebContentDecryptionModuleResult objects. | 98 // Keep track of all the outstanding WebContentDecryptionModuleResult objects. |
| 99 uint32 next_available_result_index_; | 99 WebContentDecryptionModuleResultHelper outstanding_results_; |
| 100 ResultMap outstanding_results_; | |
| 101 | 100 |
| 102 // Since promises will live until they are fired, use a weak reference when | 101 // Since promises will live until they are fired, use a weak reference when |
| 103 // creating a promise in case this class disappears before the promise | 102 // creating a promise in case this class disappears before the promise |
| 104 // actually fires. | 103 // actually fires. |
| 105 base::WeakPtrFactory<WebContentDecryptionModuleSessionImpl> weak_ptr_factory_; | 104 base::WeakPtrFactory<WebContentDecryptionModuleSessionImpl> weak_ptr_factory_; |
| 106 | 105 |
| 107 DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl); | 106 DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl); |
| 108 }; | 107 }; |
| 109 | 108 |
| 110 } // namespace content | 109 } // namespace content |
| 111 | 110 |
| 112 #endif // CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ | 111 #endif // CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ |
| OLD | NEW |