Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / media / blink / webcontentdecryptionmodulesession_impl.h
blob881c07e13c2e06e0622f4de0a76067786106275d
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_
8 #include <string>
9 #include <vector>
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"
19 namespace media {
21 class CdmSessionAdapter;
22 class MediaKeys;
24 class WebContentDecryptionModuleSessionImpl
25 : public blink::WebContentDecryptionModuleSession {
26 public:
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 blink::WebEncryptedMediaInitDataType init_data_type,
37 const unsigned char* initData,
38 size_t initDataLength,
39 blink::WebEncryptedMediaSessionType session_type,
40 blink::WebContentDecryptionModuleResult result);
41 virtual void initializeNewSession(
42 const blink::WebString& init_data_type,
43 const uint8* init_data,
44 size_t init_data_length,
45 const blink::WebString& session_type,
46 blink::WebContentDecryptionModuleResult result);
47 virtual void load(const blink::WebString& session_id,
48 blink::WebContentDecryptionModuleResult result);
49 virtual void update(const uint8* response,
50 size_t response_length,
51 blink::WebContentDecryptionModuleResult result);
52 virtual void close(blink::WebContentDecryptionModuleResult result);
53 virtual void remove(blink::WebContentDecryptionModuleResult result);
55 // Callbacks.
56 void OnSessionMessage(MediaKeys::MessageType message_type,
57 const std::vector<uint8>& message);
58 void OnSessionKeysChange(bool has_additional_usable_key,
59 CdmKeysInfo keys_info);
60 void OnSessionExpirationUpdate(const base::Time& new_expiry_time);
61 void OnSessionClosed();
63 private:
64 // Called when a new session is created.
65 blink::WebContentDecryptionModuleResult::SessionStatus OnSessionInitialized(
66 const std::string& session_id);
68 scoped_refptr<CdmSessionAdapter> adapter_;
70 // Non-owned pointer.
71 Client* client_;
73 // Session ID is the app visible ID for this session generated by the CDM.
74 // This value is not set until the CDM resolves the initializeNewSession()
75 // promise.
76 std::string session_id_;
78 // Don't pass more than 1 close() event to blink::
79 // TODO(jrummell): Remove this once blink tests handle close() promise and
80 // closed() event.
81 bool is_closed_;
83 // Since promises will live until they are fired, use a weak reference when
84 // creating a promise in case this class disappears before the promise
85 // actually fires.
86 base::WeakPtrFactory<WebContentDecryptionModuleSessionImpl> weak_ptr_factory_;
88 DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl);
91 } // namespace media
93 #endif // MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_