diff options
author | xhwang <xhwang@chromium.org> | 2014-11-14 13:01:20 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-14 21:01:47 +0000 |
commit | 58bc11c76ea016ff24bb9e50c1662c5d628b5521 (patch) | |
tree | 2ec9c65195f37c60554e51d1ff7ca5a5f3eea0f2 /content/renderer | |
parent | 0dd42c478ba833b17e24f9bea4788fee1d7ef534 (diff) | |
download | chromium_src-58bc11c76ea016ff24bb9e50c1662c5d628b5521.zip chromium_src-58bc11c76ea016ff24bb9e50c1662c5d628b5521.tar.gz chromium_src-58bc11c76ea016ff24bb9e50c1662c5d628b5521.tar.bz2 |
Move Encrypted Media classes from /content to /media.
File move and format cleanup only. No functionality change.
List of classes moved:
- CdmSessionAdapter
- WebContentDecryptionModuleImpl
- WebContentDecryptionModuleSessionImpl
BUG=422730
Review URL: https://codereview.chromium.org/726803002
Cr-Commit-Position: refs/heads/master@{#304264}
Diffstat (limited to 'content/renderer')
12 files changed, 17 insertions, 855 deletions
diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc index c44bca6..8d160f5 100644 --- a/content/renderer/media/android/webmediaplayer_android.cc +++ b/content/renderer/media/android/webmediaplayer_android.cc @@ -25,7 +25,6 @@ #include "content/renderer/media/android/renderer_media_player_manager.h" #include "content/renderer/media/crypto/render_cdm_factory.h" #include "content/renderer/media/crypto/renderer_cdm_manager.h" -#include "content/renderer/media/webcontentdecryptionmodule_impl.h" #include "content/renderer/render_frame_impl.h" #include "content/renderer/render_thread_impl.h" #include "gpu/GLES2/gl2extchromium.h" @@ -39,6 +38,7 @@ #include "media/base/media_log.h" #include "media/base/media_switches.h" #include "media/base/video_frame.h" +#include "media/blink/webcontentdecryptionmodule_impl.h" #include "media/blink/webmediaplayer_delegate.h" #include "media/blink/webmediaplayer_util.h" #include "net/base/mime_util.h" @@ -176,7 +176,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( // Set the initial CDM, if specified. if (initial_cdm) { - web_cdm_ = ToWebContentDecryptionModuleImpl(initial_cdm); + web_cdm_ = media::ToWebContentDecryptionModuleImpl(initial_cdm); if (web_cdm_->GetCdmId() != media::MediaKeys::kInvalidCdmId) player_manager_->SetCdm(player_id_, web_cdm_->GetCdmId()); } @@ -1646,7 +1646,7 @@ void WebMediaPlayerAndroid::setContentDecryptionModule( if (!cdm) return; - web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); + web_cdm_ = media::ToWebContentDecryptionModuleImpl(cdm); if (!web_cdm_) return; @@ -1673,7 +1673,7 @@ void WebMediaPlayerAndroid::setContentDecryptionModule( return; } - web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); + web_cdm_ = media::ToWebContentDecryptionModuleImpl(cdm); DCHECK(web_cdm_); if (!decryptor_ready_cb_.is_null()) { diff --git a/content/renderer/media/android/webmediaplayer_android.h b/content/renderer/media/android/webmediaplayer_android.h index 83db690..3a1744a 100644 --- a/content/renderer/media/android/webmediaplayer_android.h +++ b/content/renderer/media/android/webmediaplayer_android.h @@ -58,13 +58,14 @@ struct MailboxHolder; namespace media { class MediaLog; +class WebContentDecryptionModuleImpl; class WebMediaPlayerDelegate; } namespace content { + class RendererCdmManager; class RendererMediaPlayerManager; -class WebContentDecryptionModuleImpl; // This class implements blink::WebMediaPlayer by keeping the android // media player in the browser process. It listens to all the status changes @@ -475,7 +476,7 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer, // Non-owned pointer to the CDM. Updated via calls to // setContentDecryptionModule(). - WebContentDecryptionModuleImpl* web_cdm_; + media::WebContentDecryptionModuleImpl* web_cdm_; // This is only Used by Clear Key key system implementation, where a renderer // side CDM will be used. This is similar to WebMediaPlayerImpl. For other key diff --git a/content/renderer/media/cdm_session_adapter.cc b/content/renderer/media/cdm_session_adapter.cc deleted file mode 100644 index 81a1e42..0000000 --- a/content/renderer/media/cdm_session_adapter.cc +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/renderer/media/cdm_session_adapter.h" - -#include "base/bind.h" -#include "base/logging.h" -#include "base/memory/weak_ptr.h" -#include "base/stl_util.h" -#include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" -#include "media/base/cdm_factory.h" -#include "media/base/cdm_promise.h" -#include "media/base/key_systems.h" -#include "media/base/media_keys.h" -#include "url/gurl.h" - -namespace content { - -const char kMediaEME[] = "Media.EME."; -const char kDot[] = "."; - -CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) { -} - -CdmSessionAdapter::~CdmSessionAdapter() {} - -bool CdmSessionAdapter::Initialize(media::CdmFactory* cdm_factory, - const std::string& key_system, - const GURL& security_origin) { - key_system_uma_prefix_ = - kMediaEME + media::GetKeySystemNameForUMA(key_system) + kDot; - - base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); - media_keys_ = cdm_factory->Create( - key_system, - security_origin, - base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), - base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), - base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), - base::Bind(&CdmSessionAdapter::OnSessionError, weak_this), - base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), - base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this)); - - // Success if |media_keys_| created. - return media_keys_; -} - -void CdmSessionAdapter::SetServerCertificate( - const uint8* server_certificate, - int server_certificate_length, - scoped_ptr<media::SimpleCdmPromise> promise) { - media_keys_->SetServerCertificate( - server_certificate, server_certificate_length, promise.Pass()); -} - -WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() { - return new WebContentDecryptionModuleSessionImpl(this); -} - -bool CdmSessionAdapter::RegisterSession( - const std::string& web_session_id, - base::WeakPtr<WebContentDecryptionModuleSessionImpl> session) { - // If this session ID is already registered, don't register it again. - if (ContainsKey(sessions_, web_session_id)) - return false; - - sessions_[web_session_id] = session; - return true; -} - -void CdmSessionAdapter::UnregisterSession(const std::string& web_session_id) { - DCHECK(ContainsKey(sessions_, web_session_id)); - sessions_.erase(web_session_id); -} - -void CdmSessionAdapter::InitializeNewSession( - const std::string& init_data_type, - const uint8* init_data, - int init_data_length, - media::MediaKeys::SessionType session_type, - scoped_ptr<media::NewSessionCdmPromise> promise) { - media_keys_->CreateSession(init_data_type, - init_data, - init_data_length, - session_type, - promise.Pass()); -} - -void CdmSessionAdapter::LoadSession( - const std::string& web_session_id, - scoped_ptr<media::NewSessionCdmPromise> promise) { - media_keys_->LoadSession(web_session_id, promise.Pass()); -} - -void CdmSessionAdapter::UpdateSession( - const std::string& web_session_id, - const uint8* response, - int response_length, - scoped_ptr<media::SimpleCdmPromise> promise) { - media_keys_->UpdateSession( - web_session_id, response, response_length, promise.Pass()); -} - -void CdmSessionAdapter::CloseSession( - const std::string& web_session_id, - scoped_ptr<media::SimpleCdmPromise> promise) { - media_keys_->CloseSession(web_session_id, promise.Pass()); -} - -void CdmSessionAdapter::RemoveSession( - const std::string& web_session_id, - scoped_ptr<media::SimpleCdmPromise> promise) { - media_keys_->RemoveSession(web_session_id, promise.Pass()); -} - -void CdmSessionAdapter::GetUsableKeyIds( - const std::string& web_session_id, - scoped_ptr<media::KeyIdsPromise> promise) { - media_keys_->GetUsableKeyIds(web_session_id, promise.Pass()); -} - -media::Decryptor* CdmSessionAdapter::GetDecryptor() { - return media_keys_->GetDecryptor(); -} - -const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const { - return key_system_uma_prefix_; -} - -#if defined(ENABLE_BROWSER_CDMS) -int CdmSessionAdapter::GetCdmId() const { - return media_keys_->GetCdmId(); -} -#endif // defined(ENABLE_BROWSER_CDMS) - -void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id, - const std::vector<uint8>& message, - const GURL& destination_url) { - WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); - DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " - << web_session_id; - if (session) - session->OnSessionMessage(message, destination_url); -} - -void CdmSessionAdapter::OnSessionKeysChange(const std::string& web_session_id, - bool has_additional_usable_key) { - WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); - DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " - << web_session_id; - if (session) - session->OnSessionKeysChange(has_additional_usable_key); -} - -void CdmSessionAdapter::OnSessionExpirationUpdate( - const std::string& web_session_id, - const base::Time& new_expiry_time) { - WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); - DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " - << web_session_id; - if (session) - session->OnSessionExpirationUpdate(new_expiry_time); -} - -void CdmSessionAdapter::OnSessionReady(const std::string& web_session_id) { - // Ready events not used by unprefixed EME. - // TODO(jrummell): Remove when prefixed EME removed. -} - -void CdmSessionAdapter::OnSessionClosed(const std::string& web_session_id) { - WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); - DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " - << web_session_id; - if (session) - session->OnSessionClosed(); -} - -void CdmSessionAdapter::OnSessionError( - const std::string& web_session_id, - media::MediaKeys::Exception exception_code, - uint32 system_code, - const std::string& error_message) { - // Error events not used by unprefixed EME. - // TODO(jrummell): Remove when prefixed EME removed. -} - -WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( - const std::string& web_session_id) { - // Since session objects may get garbage collected, it is possible that there - // are events coming back from the CDM and the session has been unregistered. - // We can not tell if the CDM is firing events at sessions that never existed. - SessionMap::iterator session = sessions_.find(web_session_id); - return (session != sessions_.end()) ? session->second.get() : NULL; -} - -} // namespace content diff --git a/content/renderer/media/cdm_session_adapter.h b/content/renderer/media/cdm_session_adapter.h deleted file mode 100644 index 264067e..0000000 --- a/content/renderer/media/cdm_session_adapter.h +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ -#define CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ - -#include <map> -#include <string> - -#include "base/basictypes.h" -#include "base/containers/hash_tables.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "media/base/media_keys.h" -#include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h" - -class GURL; - -namespace media { -class CdmFactory; -} - -namespace content { - -class WebContentDecryptionModuleSessionImpl; - -// Owns the CDM instance and makes calls from session objects to the CDM. -// Forwards the web session ID-based callbacks of the MediaKeys interface to the -// appropriate session object. Callers should hold references to this class -// as long as they need the CDM instance. -class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { - public: - CdmSessionAdapter(); - - // Returns true on success. - bool Initialize(media::CdmFactory* cdm_factory, - const std::string& key_system, - const GURL& security_origin); - - // Provides a server certificate to be used to encrypt messages to the - // license server. - void SetServerCertificate(const uint8* server_certificate, - int server_certificate_length, - scoped_ptr<media::SimpleCdmPromise> promise); - - // Creates a new session and adds it to the internal map. The caller owns the - // created session. RemoveSession() must be called when destroying it, if - // RegisterSession() was called. - WebContentDecryptionModuleSessionImpl* CreateSession(); - - // Adds a session to the internal map. Called once the session is successfully - // initialized. Returns true if the session was registered, false if there is - // already an existing session with the same |web_session_id|. - bool RegisterSession( - const std::string& web_session_id, - base::WeakPtr<WebContentDecryptionModuleSessionImpl> session); - - // Removes a session from the internal map. - void UnregisterSession(const std::string& web_session_id); - - // Initializes a session with the |init_data_type|, |init_data| and - // |session_type| provided. - void InitializeNewSession(const std::string& init_data_type, - const uint8* init_data, - int init_data_length, - media::MediaKeys::SessionType session_type, - scoped_ptr<media::NewSessionCdmPromise> promise); - - // Loads the session specified by |web_session_id|. - void LoadSession(const std::string& web_session_id, - scoped_ptr<media::NewSessionCdmPromise> promise); - - // Updates the session specified by |web_session_id| with |response|. - void UpdateSession(const std::string& web_session_id, - const uint8* response, - int response_length, - scoped_ptr<media::SimpleCdmPromise> promise); - - // Closes the session specified by |web_session_id|. - void CloseSession(const std::string& web_session_id, - scoped_ptr<media::SimpleCdmPromise> promise); - - // Removes stored session data associated with the session specified by - // |web_session_id|. - void RemoveSession(const std::string& web_session_id, - scoped_ptr<media::SimpleCdmPromise> promise); - - // Retrieves the key IDs for keys in the session that the CDM knows are - // currently usable to decrypt media data. - void GetUsableKeyIds(const std::string& web_session_id, - scoped_ptr<media::KeyIdsPromise> promise); - - // Returns the Decryptor associated with this CDM. May be NULL if no - // Decryptor is associated with the MediaKeys object. - // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor - // after WebContentDecryptionModule is freed. http://crbug.com/330324 - media::Decryptor* GetDecryptor(); - - // Returns a prefix to use for UMAs. - const std::string& GetKeySystemUMAPrefix() const; - -#if defined(ENABLE_BROWSER_CDMS) - // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId - // if no CDM ID is associated. - int GetCdmId() const; -#endif - - private: - friend class base::RefCounted<CdmSessionAdapter>; - typedef base::hash_map<std::string, - base::WeakPtr<WebContentDecryptionModuleSessionImpl> > - SessionMap; - - ~CdmSessionAdapter(); - - // Callbacks for firing session events. - void OnSessionMessage(const std::string& web_session_id, - const std::vector<uint8>& message, - const GURL& destination_url); - void OnSessionKeysChange(const std::string& web_session_id, - bool has_additional_usable_key); - void OnSessionExpirationUpdate(const std::string& web_session_id, - const base::Time& new_expiry_time); - void OnSessionReady(const std::string& web_session_id); - void OnSessionClosed(const std::string& web_session_id); - void OnSessionError(const std::string& web_session_id, - media::MediaKeys::Exception exception_code, - uint32 system_code, - const std::string& error_message); - - // Helper function of the callbacks. - WebContentDecryptionModuleSessionImpl* GetSession( - const std::string& web_session_id); - - scoped_ptr<media::MediaKeys> media_keys_; - - SessionMap sessions_; - - std::string key_system_uma_prefix_; - - // NOTE: Weak pointers must be invalidated before all other member variables. - base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ diff --git a/content/renderer/media/crypto/encrypted_media_player_support_impl.cc b/content/renderer/media/crypto/encrypted_media_player_support_impl.cc index 3cbb68b..86e3329 100644 --- a/content/renderer/media/crypto/encrypted_media_player_support_impl.cc +++ b/content/renderer/media/crypto/encrypted_media_player_support_impl.cc @@ -13,10 +13,10 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "content/renderer/media/crypto/render_cdm_factory.h" -#include "content/renderer/media/webcontentdecryptionmodule_impl.h" #include "media/base/bind_to_current_loop.h" #include "media/base/key_systems.h" #include "media/blink/encrypted_media_player_support.h" +#include "media/blink/webcontentdecryptionmodule_impl.h" #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" @@ -304,7 +304,7 @@ void EncryptedMediaPlayerSupportImpl::SetInitialContentDecryptionModule( // Used when loading media and no pipeline/decoder attached yet. DCHECK(decryptor_ready_cb_.is_null()); - web_cdm_ = ToWebContentDecryptionModuleImpl(initial_cdm); + web_cdm_ = media::ToWebContentDecryptionModuleImpl(initial_cdm); } void EncryptedMediaPlayerSupportImpl::SetContentDecryptionModule( @@ -313,7 +313,7 @@ void EncryptedMediaPlayerSupportImpl::SetContentDecryptionModule( if (!cdm) return; - web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); + web_cdm_ = media::ToWebContentDecryptionModuleImpl(cdm); if (web_cdm_ && !decryptor_ready_cb_.is_null()) base::ResetAndReturn(&decryptor_ready_cb_) @@ -332,7 +332,7 @@ void EncryptedMediaPlayerSupportImpl::SetContentDecryptionModule( return; } - web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); + web_cdm_ = media::ToWebContentDecryptionModuleImpl(cdm); if (web_cdm_ && !decryptor_ready_cb_.is_null()) { base::ResetAndReturn(&decryptor_ready_cb_) diff --git a/content/renderer/media/crypto/encrypted_media_player_support_impl.h b/content/renderer/media/crypto/encrypted_media_player_support_impl.h index d68d40b..88d55d1 100644 --- a/content/renderer/media/crypto/encrypted_media_player_support_impl.h +++ b/content/renderer/media/crypto/encrypted_media_player_support_impl.h @@ -11,6 +11,7 @@ #include "base/memory/weak_ptr.h" #include "content/renderer/media/crypto/proxy_decryptor.h" #include "media/blink/encrypted_media_player_support.h" +#include "media/blink/webcontentdecryptionmodule_impl.h" namespace blink { class WebMediaPlayerClient; @@ -119,7 +120,7 @@ class EncryptedMediaPlayerSupportImpl // Non-owned pointer to the CDM. Updated via calls to // setContentDecryptionModule(). - WebContentDecryptionModuleImpl* web_cdm_; + media::WebContentDecryptionModuleImpl* web_cdm_; media::DecryptorReadyCB decryptor_ready_cb_; diff --git a/content/renderer/media/webcontentdecryptionmodule_impl.cc b/content/renderer/media/webcontentdecryptionmodule_impl.cc deleted file mode 100644 index b5ec071..0000000 --- a/content/renderer/media/webcontentdecryptionmodule_impl.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/renderer/media/webcontentdecryptionmodule_impl.h" - -#include "base/basictypes.h" -#include "base/bind.h" -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "content/renderer/media/cdm_session_adapter.h" -#include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" -#include "media/base/cdm_promise.h" -#include "media/base/key_systems.h" -#include "media/base/media_keys.h" -#include "media/blink/cdm_result_promise.h" -#include "third_party/WebKit/public/platform/WebString.h" -#include "third_party/WebKit/public/web/WebSecurityOrigin.h" -#include "url/gurl.h" - -namespace content { - -WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create( - media::CdmFactory* cdm_factory, - const blink::WebSecurityOrigin& security_origin, - const base::string16& key_system) { - DCHECK(!security_origin.isNull()); - DCHECK(!key_system.empty()); - - // TODO(ddorwin): Guard against this in supported types check and remove this. - // Chromium only supports ASCII key systems. - if (!base::IsStringASCII(key_system)) { - NOTREACHED(); - return NULL; - } - - std::string key_system_ascii = base::UTF16ToASCII(key_system); - if (!media::IsConcreteSupportedKeySystem(key_system_ascii)) - return NULL; - - // If unique security origin, don't try to create the CDM. - if (security_origin.isUnique() || security_origin.toString() == "null") { - DLOG(ERROR) << "CDM use not allowed for unique security origin."; - return NULL; - } - - scoped_refptr<CdmSessionAdapter> adapter(new CdmSessionAdapter()); - GURL security_origin_as_gurl(security_origin.toString()); - - if (!adapter->Initialize( - cdm_factory, key_system_ascii, security_origin_as_gurl)) { - return NULL; - } - - return new WebContentDecryptionModuleImpl(adapter); -} - -WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( - scoped_refptr<CdmSessionAdapter> adapter) - : adapter_(adapter) { -} - -WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() { -} - -// The caller owns the created session. -blink::WebContentDecryptionModuleSession* -WebContentDecryptionModuleImpl::createSession() { - return adapter_->CreateSession(); -} - -blink::WebContentDecryptionModuleSession* -WebContentDecryptionModuleImpl::createSession( - blink::WebContentDecryptionModuleSession::Client* client) { - WebContentDecryptionModuleSessionImpl* session = adapter_->CreateSession(); - session->setClientInterface(client); - return session; -} - -void WebContentDecryptionModuleImpl::setServerCertificate( - const uint8* server_certificate, - size_t server_certificate_length, - blink::WebContentDecryptionModuleResult result) { - DCHECK(server_certificate); - adapter_->SetServerCertificate( - server_certificate, - server_certificate_length, - scoped_ptr<media::SimpleCdmPromise>( - new media::CdmResultPromise<>(result, std::string()))); -} - -media::Decryptor* WebContentDecryptionModuleImpl::GetDecryptor() { - return adapter_->GetDecryptor(); -} - -#if defined(ENABLE_BROWSER_CDMS) -int WebContentDecryptionModuleImpl::GetCdmId() const { - return adapter_->GetCdmId(); -} -#endif // defined(ENABLE_BROWSER_CDMS) - -} // namespace content diff --git a/content/renderer/media/webcontentdecryptionmodule_impl.h b/content/renderer/media/webcontentdecryptionmodule_impl.h deleted file mode 100644 index c535db7..0000000 --- a/content/renderer/media/webcontentdecryptionmodule_impl.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULE_IMPL_H_ -#define CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULE_IMPL_H_ - -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/strings/string16.h" -#include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" -#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" - -namespace blink { -#if defined(ENABLE_PEPPER_CDMS) -class WebLocalFrame; -#endif -class WebSecurityOrigin; -} - -namespace media { -class CdmFactory; -class Decryptor; -class MediaKeys; -} - -namespace content { - -class CdmSessionAdapter; -class WebContentDecryptionModuleSessionImpl; - -class WebContentDecryptionModuleImpl - : public blink::WebContentDecryptionModule { - public: - static WebContentDecryptionModuleImpl* Create( - media::CdmFactory* cdm_factory, - const blink::WebSecurityOrigin& security_origin, - const base::string16& key_system); - - virtual ~WebContentDecryptionModuleImpl(); - - // Returns the Decryptor associated with this CDM. May be NULL if no - // Decryptor associated with the MediaKeys object. - // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor - // after WebContentDecryptionModule is freed. http://crbug.com/330324 - media::Decryptor* GetDecryptor(); - -#if defined(ENABLE_BROWSER_CDMS) - // Returns the CDM ID associated with this object. May be kInvalidCdmId if no - // CDM ID is associated, such as when Clear Key is used. - int GetCdmId() const; -#endif // defined(ENABLE_BROWSER_CDMS) - - // blink::WebContentDecryptionModule implementation. - virtual blink::WebContentDecryptionModuleSession* createSession(); - // TODO(jrummell): Remove this method once blink updated. - virtual blink::WebContentDecryptionModuleSession* createSession( - blink::WebContentDecryptionModuleSession::Client* client); - - virtual void setServerCertificate( - const uint8* server_certificate, - size_t server_certificate_length, - blink::WebContentDecryptionModuleResult result); - - private: - // Takes reference to |adapter|. - WebContentDecryptionModuleImpl(scoped_refptr<CdmSessionAdapter> adapter); - - scoped_refptr<CdmSessionAdapter> adapter_; - - DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleImpl); -}; - -// Allow typecasting from blink type as this is the only implementation. -inline WebContentDecryptionModuleImpl* ToWebContentDecryptionModuleImpl( - blink::WebContentDecryptionModule* cdm) { - return static_cast<WebContentDecryptionModuleImpl*>(cdm); -} - -} // namespace content - -#endif // CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULE_IMPL_H_ diff --git a/content/renderer/media/webcontentdecryptionmodulesession_impl.cc b/content/renderer/media/webcontentdecryptionmodulesession_impl.cc deleted file mode 100644 index 871c31f..0000000 --- a/content/renderer/media/webcontentdecryptionmodulesession_impl.cc +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" - -#include "base/bind.h" -#include "base/callback_helpers.h" -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "content/renderer/media/cdm_session_adapter.h" -#include "media/base/cdm_promise.h" -#include "media/base/media_keys.h" -#include "media/blink/cdm_result_promise.h" -#include "media/blink/new_session_cdm_result_promise.h" -#include "third_party/WebKit/public/platform/WebURL.h" - -namespace content { - -const char kCreateSessionUMAName[] = "CreateSession"; -const char kLoadSessionUMAName[] = "LoadSession"; - -WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( - const scoped_refptr<CdmSessionAdapter>& adapter) - : adapter_(adapter), - is_closed_(false), - weak_ptr_factory_(this) { -} - -WebContentDecryptionModuleSessionImpl:: - ~WebContentDecryptionModuleSessionImpl() { - if (!web_session_id_.empty()) - adapter_->UnregisterSession(web_session_id_); -} - -void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) { - client_ = client; -} - -blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { - return blink::WebString::fromUTF8(web_session_id_); -} - -void WebContentDecryptionModuleSessionImpl::initializeNewSession( - const blink::WebString& init_data_type, - const uint8* init_data, - size_t init_data_length) { - // TODO(jrummell): Remove once blink updated. - NOTREACHED(); -} - -void WebContentDecryptionModuleSessionImpl::update(const uint8* response, - size_t response_length) { - // TODO(jrummell): Remove once blink updated. - NOTREACHED(); -} - -void WebContentDecryptionModuleSessionImpl::release() { - // TODO(jrummell): Remove once blink updated. - NOTREACHED(); -} - -void WebContentDecryptionModuleSessionImpl::initializeNewSession( - const blink::WebString& init_data_type, - const uint8* init_data, - size_t init_data_length, - const blink::WebString& session_type, - blink::WebContentDecryptionModuleResult result) { - DCHECK(web_session_id_.empty()); - - // TODO(ddorwin): Guard against this in supported types check and remove this. - // Chromium only supports ASCII MIME types. - if (!base::IsStringASCII(init_data_type)) { - NOTREACHED(); - std::string message = "The initialization data type " + - init_data_type.utf8() + - " is not supported by the key system."; - result.completeWithError( - blink::WebContentDecryptionModuleExceptionNotSupportedError, - 0, - blink::WebString::fromUTF8(message)); - return; - } - - std::string init_data_type_as_ascii = base::UTF16ToASCII(init_data_type); - DLOG_IF(WARNING, init_data_type_as_ascii.find('/') != std::string::npos) - << "init_data_type '" << init_data_type_as_ascii - << "' may be a MIME type"; - - adapter_->InitializeNewSession( - init_data_type_as_ascii, - init_data, - init_data_length, - media::MediaKeys::TEMPORARY_SESSION, - scoped_ptr<media::NewSessionCdmPromise>( - new media::NewSessionCdmResultPromise( - result, - adapter_->GetKeySystemUMAPrefix() + kCreateSessionUMAName, - base::Bind( - &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, - base::Unretained(this))))); -} - -void WebContentDecryptionModuleSessionImpl::load( - const blink::WebString& session_id, - blink::WebContentDecryptionModuleResult result) { - DCHECK(!session_id.isEmpty()); - DCHECK(web_session_id_.empty()); - - adapter_->LoadSession( - base::UTF16ToASCII(session_id), - scoped_ptr<media::NewSessionCdmPromise>( - new media::NewSessionCdmResultPromise( - result, - adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName, - base::Bind( - &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, - base::Unretained(this))))); -} - -void WebContentDecryptionModuleSessionImpl::update( - const uint8* response, - size_t response_length, - blink::WebContentDecryptionModuleResult result) { - DCHECK(response); - DCHECK(!web_session_id_.empty()); - adapter_->UpdateSession( - web_session_id_, - response, - response_length, - scoped_ptr<media::SimpleCdmPromise>( - new media::CdmResultPromise<>(result, std::string()))); -} - -void WebContentDecryptionModuleSessionImpl::close( - blink::WebContentDecryptionModuleResult result) { - DCHECK(!web_session_id_.empty()); - adapter_->CloseSession( - web_session_id_, - scoped_ptr<media::SimpleCdmPromise>( - new media::CdmResultPromise<>(result, std::string()))); -} - -void WebContentDecryptionModuleSessionImpl::remove( - blink::WebContentDecryptionModuleResult result) { - DCHECK(!web_session_id_.empty()); - adapter_->RemoveSession( - web_session_id_, - scoped_ptr<media::SimpleCdmPromise>( - new media::CdmResultPromise<>(result, std::string()))); -} - -void WebContentDecryptionModuleSessionImpl::getUsableKeyIds( - blink::WebContentDecryptionModuleResult result) { - DCHECK(!web_session_id_.empty()); - adapter_->GetUsableKeyIds( - web_session_id_, - scoped_ptr<media::KeyIdsPromise>( - new media::CdmResultPromise<media::KeyIdsVector>(result, - std::string()))); -} - -void WebContentDecryptionModuleSessionImpl::release( - blink::WebContentDecryptionModuleResult result) { - close(result); -} - -void WebContentDecryptionModuleSessionImpl::OnSessionMessage( - const std::vector<uint8>& message, - const GURL& destination_url) { - DCHECK(client_) << "Client not set before message event"; - client_->message( - message.empty() ? NULL : &message[0], message.size(), destination_url); -} - -void WebContentDecryptionModuleSessionImpl::OnSessionKeysChange( - bool has_additional_usable_key) { - // TODO(jrummell): Update this once Blink client supports this. -} - -void WebContentDecryptionModuleSessionImpl::OnSessionExpirationUpdate( - const base::Time& new_expiry_time) { - client_->expirationChanged(new_expiry_time.ToJsTime()); -} - -void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { - if (is_closed_) - return; - - is_closed_ = true; - client_->close(); -} - -blink::WebContentDecryptionModuleResult::SessionStatus -WebContentDecryptionModuleSessionImpl::OnSessionInitialized( - const std::string& web_session_id) { - // CDM will return NULL if the session to be loaded can't be found. - if (web_session_id.empty()) - return blink::WebContentDecryptionModuleResult::SessionNotFound; - - DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set."; - web_session_id_ = web_session_id; - return adapter_->RegisterSession(web_session_id_, - weak_ptr_factory_.GetWeakPtr()) - ? blink::WebContentDecryptionModuleResult::NewSession - : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; -} - -} // namespace content diff --git a/content/renderer/media/webcontentdecryptionmodulesession_impl.h b/content/renderer/media/webcontentdecryptionmodulesession_impl.h deleted file mode 100644 index c54c218..0000000 --- a/content/renderer/media/webcontentdecryptionmodulesession_impl.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ -#define CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ - -#include <map> -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/callback.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "media/base/media_keys.h" -#include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h" -#include "third_party/WebKit/public/platform/WebString.h" - -namespace media { -class MediaKeys; -} - -namespace content { -class CdmSessionAdapter; - -class WebContentDecryptionModuleSessionImpl - : public blink::WebContentDecryptionModuleSession { - public: - WebContentDecryptionModuleSessionImpl( - const scoped_refptr<CdmSessionAdapter>& adapter); - virtual ~WebContentDecryptionModuleSessionImpl(); - - // blink::WebContentDecryptionModuleSession implementation. - virtual void setClientInterface(Client* client); - virtual blink::WebString sessionId() const; - // TODO(jrummell): Remove the next 3 methods once blink updated. - virtual void initializeNewSession(const blink::WebString& mime_type, - const uint8* init_data, - size_t init_data_length); - virtual void update(const uint8* response, size_t response_length); - virtual void release(); - virtual void initializeNewSession( - const blink::WebString& init_data_type, - const uint8* init_data, - size_t init_data_length, - const blink::WebString& session_type, - blink::WebContentDecryptionModuleResult result); - virtual void load(const blink::WebString& session_id, - blink::WebContentDecryptionModuleResult result); - virtual void update(const uint8* response, - size_t response_length, - blink::WebContentDecryptionModuleResult result); - virtual void close(blink::WebContentDecryptionModuleResult result); - virtual void remove(blink::WebContentDecryptionModuleResult result); - virtual void getUsableKeyIds(blink::WebContentDecryptionModuleResult result); - - // TODO(jrummell): Remove the next method once blink updated. - virtual void release(blink::WebContentDecryptionModuleResult result); - - // Callbacks. - void OnSessionMessage(const std::vector<uint8>& message, - const GURL& destination_url); - void OnSessionKeysChange(bool has_additional_usable_key); - void OnSessionExpirationUpdate(const base::Time& new_expiry_time); - void OnSessionClosed(); - - private: - // Called when a new session is created. - blink::WebContentDecryptionModuleResult::SessionStatus OnSessionInitialized( - const std::string& web_session_id); - - scoped_refptr<CdmSessionAdapter> adapter_; - - // Non-owned pointer. - Client* client_; - - // Web session ID is the app visible ID for this session generated by the CDM. - // This value is not set until the CDM resolves the initializeNewSession() - // promise. - std::string web_session_id_; - - // Don't pass more than 1 close() event to blink:: - // TODO(jrummell): Remove this once blink tests handle close() promise and - // closed() event. - bool is_closed_; - - // Since promises will live until they are fired, use a weak reference when - // creating a promise in case this class disappears before the promise - // actually fires. - base::WeakPtrFactory<WebContentDecryptionModuleSessionImpl> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleSessionImpl); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_MEDIA_WEBCONTENTDECRYPTIONMODULESESSION_IMPL_H_ diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index 6a147a0..4c0f8df 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -77,7 +77,6 @@ #include "content/renderer/media/midi_dispatcher.h" #include "content/renderer/media/render_media_log.h" #include "content/renderer/media/user_media_client_impl.h" -#include "content/renderer/media/webcontentdecryptionmodule_impl.h" #include "content/renderer/media/webmediaplayer_ms.h" #include "content/renderer/mojo/service_registry_js_wrapper.h" #include "content/renderer/notification_permission_dispatcher.h" @@ -98,6 +97,7 @@ #include "gin/modules/module_registry.h" #include "media/base/audio_renderer_mixer_input.h" #include "media/base/renderer.h" +#include "media/blink/webcontentdecryptionmodule_impl.h" #include "media/blink/webmediaplayer_impl.h" #include "media/blink/webmediaplayer_params.h" #include "media/filters/gpu_video_accelerator_factories.h" @@ -1772,8 +1772,8 @@ RenderFrameImpl::createContentDecryptionModule( RenderCdmFactory cdm_factory; #endif - return WebContentDecryptionModuleImpl::Create(&cdm_factory, security_origin, - key_system); + return media::WebContentDecryptionModuleImpl::Create( + &cdm_factory, security_origin, key_system); } blink::WebApplicationCacheHost* RenderFrameImpl::createApplicationCacheHost( diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc index e9eb134..52165f6 100644 --- a/content/renderer/renderer_blink_platform_impl.cc +++ b/content/renderer/renderer_blink_platform_impl.cc @@ -47,7 +47,6 @@ #include "content/renderer/media/audio_decoder.h" #include "content/renderer/media/renderer_webaudiodevice_impl.h" #include "content/renderer/media/renderer_webmidiaccessor_impl.h" -#include "content/renderer/media/webcontentdecryptionmodule_impl.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/renderer_clipboard_client.h" #include "content/renderer/scheduler/renderer_scheduler.h" @@ -61,6 +60,7 @@ #include "media/audio/audio_output_device.h" #include "media/base/audio_hardware_config.h" #include "media/base/key_systems.h" +#include "media/blink/webcontentdecryptionmodule_impl.h" #include "media/filters/stream_parser_factory.h" #include "net/base/mime_util.h" #include "net/base/net_util.h" |