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. 4 5#ifndef CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ 6#define CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ 7 8#include <map> 9#include <string> 10#include <vector> 11 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" 19 20namespace media { 21class MediaKeys; 22} 23 24namespace content { 25class CdmSessionAdapter; 26 27class WebContentDecryptionModuleSessionImpl 28 : public blink::WebContentDecryptionModuleSession { 29 public: 30 WebContentDecryptionModuleSessionImpl( 31 const scoped_refptr<CdmSessionAdapter>& adapter); 32 virtual ~WebContentDecryptionModuleSessionImpl(); 33 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 close(blink::WebContentDecryptionModuleResult result); 53 virtual void remove(blink::WebContentDecryptionModuleResult result); 54 virtual void getUsableKeyIds(blink::WebContentDecryptionModuleResult result); 55 56 // TODO(jrummell): Remove the next method once blink updated. 57 virtual void release(blink::WebContentDecryptionModuleResult result); 58 59 // Callbacks. 60 void OnSessionMessage(const std::vector<uint8>& message, 61 const GURL& destination_url); 62 void OnSessionKeysChange(bool has_additional_usable_key); 63 void OnSessionExpirationUpdate(const base::Time& new_expiry_time); 64 void OnSessionReady(); 65 void OnSessionClosed(); 66 void OnSessionError(media::MediaKeys::Exception exception_code, 67 uint32 system_code, 68 const std::string& error_message); 69 70 private: 71 // Called when a new session is created. 72 blink::WebContentDecryptionModuleResult::SessionStatus OnSessionInitialized( 73 const std::string& web_session_id); 74 75 scoped_refptr<CdmSessionAdapter> adapter_; 76 77 // Non-owned pointer. 78 Client* client_; 79 80 // Web session ID is the app visible ID for this session generated by the CDM. 81 // This value is not set until the CDM resolves the initializeNewSession() 82 // promise. 83 std::string web_session_id_; 84 85 // Don't pass more than 1 close() event to blink:: 86 // TODO(jrummell): Remove this once blink tests handle close() promise and 87 // closed() event. 88 bool is_closed_; 89 90 // Since promises will live until they are fired, use a weak reference when 91 // creating a promise in case this class disappears before the promise 92 // actually fires. 93 base::WeakPtrFactory<WebContentDecryptionModuleSessionImpl> weak_ptr_factory_; 94 95 DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl); 96}; 97 98} // namespace content 99 100#endif // CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ 101