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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "media/base/media_keys.h"
17 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h"
18 #include "third_party/WebKit/public/platform/WebString.h"
25 class CdmSessionAdapter
;
27 class WebContentDecryptionModuleSessionImpl
28 : public blink::WebContentDecryptionModuleSession
{
30 WebContentDecryptionModuleSessionImpl(
31 const scoped_refptr
<CdmSessionAdapter
>& adapter
);
32 virtual ~WebContentDecryptionModuleSessionImpl();
34 // blink::WebContentDecryptionModuleSession implementation.
35 virtual void setClientInterface(Client
* client
);
36 virtual blink::WebString
sessionId() const;
37 // TODO(jrummell): Remove the next 3 methods once blink updated.
38 virtual void initializeNewSession(const blink::WebString
& mime_type
,
39 const uint8
* init_data
,
40 size_t init_data_length
);
41 virtual void update(const uint8
* response
, size_t response_length
);
42 virtual void release();
43 virtual void initializeNewSession(
44 const blink::WebString
& init_data_type
,
45 const uint8
* init_data
,
46 size_t init_data_length
,
47 const blink::WebString
& session_type
,
48 blink::WebContentDecryptionModuleResult result
);
49 virtual void update(const uint8
* response
,
50 size_t response_length
,
51 blink::WebContentDecryptionModuleResult result
);
52 virtual void release(blink::WebContentDecryptionModuleResult result
);
55 void OnSessionMessage(const std::vector
<uint8
>& message
,
56 const GURL
& destination_url
);
57 void OnSessionReady();
58 void OnSessionClosed();
59 void OnSessionError(media::MediaKeys::Exception exception_code
,
61 const std::string
& error_message
);
64 typedef std::map
<uint32
, blink::WebContentDecryptionModuleResult
> ResultMap
;
66 // These function are used as callbacks when CdmPromise resolves/rejects.
67 // |result_index| = kReservedIndex means that there is no
68 // WebContentDecryptionModuleResult.
69 void SessionCreated(uint32 result_index
, const std::string
& web_session_id
);
70 void SessionUpdatedOrReleased(uint32 result_index
);
71 void SessionError(uint32 result_index
,
72 media::MediaKeys::Exception exception_code
,
74 const std::string
& error_message
);
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
81 uint32
AddResult(blink::WebContentDecryptionModuleResult result
);
83 scoped_refptr
<CdmSessionAdapter
> adapter_
;
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()
91 std::string web_session_id_
;
93 // Don't pass more than 1 close() event to blink::
94 // TODO(jrummell): Remove this once blink tests handle close() promise and
98 // Keep track of all the outstanding WebContentDecryptionModuleResult objects.
99 uint32 next_available_result_index_
;
100 ResultMap outstanding_results_
;
102 // 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
105 base::WeakPtrFactory
<WebContentDecryptionModuleSessionImpl
> weak_ptr_factory_
;
107 DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl
);
110 } // namespace content
112 #endif // CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_