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 MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
6 #define MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "media/base/media_keys.h"
16 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h"
17 #include "third_party/WebKit/public/platform/WebString.h"
21 class CdmSessionAdapter
;
24 class WebContentDecryptionModuleSessionImpl
25 : public blink::WebContentDecryptionModuleSession
{
27 WebContentDecryptionModuleSessionImpl(
28 const scoped_refptr
<CdmSessionAdapter
>& adapter
);
29 virtual ~WebContentDecryptionModuleSessionImpl();
31 // blink::WebContentDecryptionModuleSession implementation.
32 virtual void setClientInterface(Client
* client
);
33 virtual blink::WebString
sessionId() const;
35 virtual void initializeNewSession(
36 const blink::WebString
& init_data_type
,
37 const uint8
* init_data
,
38 size_t init_data_length
,
39 const blink::WebString
& session_type
,
40 blink::WebContentDecryptionModuleResult result
);
41 virtual void load(const blink::WebString
& session_id
,
42 blink::WebContentDecryptionModuleResult result
);
43 virtual void update(const uint8
* response
,
44 size_t response_length
,
45 blink::WebContentDecryptionModuleResult result
);
46 virtual void close(blink::WebContentDecryptionModuleResult result
);
47 virtual void remove(blink::WebContentDecryptionModuleResult result
);
50 void OnSessionMessage(MediaKeys::MessageType message_type
,
51 const std::vector
<uint8
>& message
);
52 void OnSessionKeysChange(bool has_additional_usable_key
,
53 CdmKeysInfo keys_info
);
54 void OnSessionExpirationUpdate(const base::Time
& new_expiry_time
);
55 void OnSessionClosed();
58 // Called when a new session is created.
59 blink::WebContentDecryptionModuleResult::SessionStatus
OnSessionInitialized(
60 const std::string
& session_id
);
62 scoped_refptr
<CdmSessionAdapter
> adapter_
;
67 // Session ID is the app visible ID for this session generated by the CDM.
68 // This value is not set until the CDM resolves the initializeNewSession()
70 std::string session_id_
;
72 // Don't pass more than 1 close() event to blink::
73 // TODO(jrummell): Remove this once blink tests handle close() promise and
77 // Since promises will live until they are fired, use a weak reference when
78 // creating a promise in case this class disappears before the promise
80 base::WeakPtrFactory
<WebContentDecryptionModuleSessionImpl
> weak_ptr_factory_
;
82 DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl
);
87 #endif // MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_