From 649b57279934b2bf99eda48e1b9dc40e6be169be Mon Sep 17 00:00:00 2001 From: "ycheo@chromium.org" Date: Fri, 9 May 2014 14:54:44 +0000 Subject: [PATCH] Componentize EncryptedMediaMessageFilter and rename it CdmMessageFilter. The motivation is to reuse the Widevine keysystem registration logic in Android Webview. BUG=322395 Review URL: https://codereview.chromium.org/253593002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269297 0039d316-1c4b-4281-b951-d872f2087c98 --- android_webview/android_webview.gyp | 2 + android_webview/browser/DEPS | 1 + .../browser/aw_content_browser_client.cc | 2 + android_webview/renderer/DEPS | 1 + android_webview/renderer/aw_key_systems.cc | 38 +----- chrome/browser/DEPS | 1 + .../browser/chrome_content_browser_client.cc | 4 +- chrome/chrome_browser.gypi | 3 +- chrome/chrome_common.gypi | 1 - chrome/chrome_renderer.gypi | 1 + chrome/common/common_message_generator.h | 4 - chrome/renderer/DEPS | 1 + chrome/renderer/media/chrome_key_systems.cc | 124 +++--------------- components/cdm.gypi | 62 +++++++++ components/cdm/DEPS | 3 + components/cdm/OWNERS | 3 + components/cdm/browser/DEPS | 4 + .../cdm/browser/cdm_message_filter_android.cc | 22 ++-- .../cdm/browser/cdm_message_filter_android.h | 20 +-- components/cdm/common/DEPS | 3 + components/cdm/common/OWNERS | 13 ++ .../cdm/common/cdm_message_generator.cc | 34 +++++ components/cdm/common/cdm_message_generator.h | 11 ++ .../cdm/common/cdm_messages_android.h | 2 +- components/cdm/renderer/DEPS | 3 + .../cdm/renderer/widevine_key_systems.cc | 93 +++++++++++++ .../cdm/renderer/widevine_key_systems.h | 33 +++++ components/components.gyp | 1 + 28 files changed, 315 insertions(+), 175 deletions(-) create mode 100644 components/cdm.gypi create mode 100644 components/cdm/DEPS create mode 100644 components/cdm/OWNERS create mode 100644 components/cdm/browser/DEPS rename chrome/browser/media/encrypted_media_message_filter_android.cc => components/cdm/browser/cdm_message_filter_android.cc (83%) rename chrome/browser/media/encrypted_media_message_filter_android.h => components/cdm/browser/cdm_message_filter_android.h (64%) create mode 100644 components/cdm/common/DEPS create mode 100644 components/cdm/common/OWNERS create mode 100644 components/cdm/common/cdm_message_generator.cc create mode 100644 components/cdm/common/cdm_message_generator.h rename chrome/common/encrypted_media_messages_android.h => components/cdm/common/cdm_messages_android.h (95%) create mode 100644 components/cdm/renderer/DEPS create mode 100644 components/cdm/renderer/widevine_key_systems.cc create mode 100644 components/cdm/renderer/widevine_key_systems.h diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp index ae0c693b48ef..f84eccd3d276 100644 --- a/android_webview/android_webview.gyp +++ b/android_webview/android_webview.gyp @@ -90,6 +90,8 @@ '../android_webview/native/webview_native.gyp:webview_native', '../components/components.gyp:auto_login_parser', '../components/components.gyp:autofill_content_renderer', + '../components/components.gyp:cdm_browser', + '../components/components.gyp:cdm_renderer', '../components/components.gyp:data_reduction_proxy_browser', '../components/components.gyp:navigation_interception', '../components/components.gyp:visitedlink_browser', diff --git a/android_webview/browser/DEPS b/android_webview/browser/DEPS index 5ac20cd73186..417b2c9d38c5 100644 --- a/android_webview/browser/DEPS +++ b/android_webview/browser/DEPS @@ -11,6 +11,7 @@ include_rules = [ "+components/autofill/content/browser", "+components/autofill/core/browser", "+components/autofill/core/common", + "+components/cdm/browser", "+components/data_reduction_proxy/browser", "+components/navigation_interception", "+components/user_prefs", diff --git a/android_webview/browser/aw_content_browser_client.cc b/android_webview/browser/aw_content_browser_client.cc index db2dfa908f7d..1ba73c75efd6 100644 --- a/android_webview/browser/aw_content_browser_client.cc +++ b/android_webview/browser/aw_content_browser_client.cc @@ -18,6 +18,7 @@ #include "android_webview/common/url_constants.h" #include "base/base_paths_android.h" #include "base/path_service.h" +#include "components/cdm/browser/cdm_message_filter_android.h" #include "content/public/browser/access_token_store.h" #include "content/public/browser/browser_message_filter.h" #include "content/public/browser/browser_thread.h" @@ -207,6 +208,7 @@ void AwContentBrowserClient::RenderProcessWillLaunch( host->GetID(), content::kFileScheme); host->AddFilter(new AwContentsMessageFilter(host->GetID())); + host->AddFilter(new cdm::CdmMessageFilterAndroid()); } net::URLRequestContextGetter* AwContentBrowserClient::CreateRequestContext( diff --git a/android_webview/renderer/DEPS b/android_webview/renderer/DEPS index a40a8a23ee99..b5cbb484f643 100644 --- a/android_webview/renderer/DEPS +++ b/android_webview/renderer/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+android_webview/renderer", "+components/autofill/content/renderer", + "+components/cdm/renderer", "+components/visitedlink/renderer", "+content/public/renderer", diff --git a/android_webview/renderer/aw_key_systems.cc b/android_webview/renderer/aw_key_systems.cc index b276c88f5a45..fb17c01b506a 100644 --- a/android_webview/renderer/aw_key_systems.cc +++ b/android_webview/renderer/aw_key_systems.cc @@ -3,45 +3,13 @@ // found in the LICENSE file. #include "android_webview/renderer/aw_key_systems.h" - -#include - -#include "base/command_line.h" -#include "base/logging.h" -#include "content/public/common/eme_codec.h" -#include "third_party/widevine/cdm/widevine_cdm_common.h" - -using content::KeySystemInfo; - -namespace { - -// Return |name|'s parent key system. -std::string GetDirectParentName(const std::string& name) { - int last_period = name.find_last_of('.'); - DCHECK_GT(last_period, 0); - return name.substr(0, last_period); -} - -void AddWidevineWithCodecs(const std::string& key_system_name, - bool add_parent_name, - std::vector* concrete_key_systems) { - KeySystemInfo info(key_system_name); - - if (add_parent_name) - info.parent_key_system = GetDirectParentName(key_system_name); - - info.supported_codecs = content::EME_CODEC_MP4_ALL; - - concrete_key_systems->push_back(info); -} - -} // namespace +#include "components/cdm/renderer/widevine_key_systems.h" namespace android_webview { void AwAddKeySystems( - std::vector* key_systems_info) { - AddWidevineWithCodecs(kWidevineKeySystem, true, key_systems_info); + std::vector* key_systems_info) { + cdm::AddAndroidWidevine(key_systems_info); } } // namespace android_webview diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 08683bfb0737..dccea1841621 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -16,6 +16,7 @@ include_rules = [ "+components/bookmarks/core/common", "+components/bookmarks/core/test", "+components/breakpad", + "+components/cdm/browser", "+components/cloud_devices/common", "+components/data_reduction_proxy", "+components/dom_distiller", diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index e9df65a949bf..06b97e7f9bce 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -98,6 +98,7 @@ #include "chrome/common/url_constants.h" #include "chrome/installer/util/google_update_settings.h" #include "chromeos/chromeos_constants.h" +#include "components/cdm/browser/cdm_message_filter_android.h" #include "components/cloud_devices/common/cloud_devices_switches.h" #include "components/nacl/browser/nacl_browser.h" #include "components/nacl/browser/nacl_host_message_filter.h" @@ -177,7 +178,6 @@ #include "chrome/browser/android/new_tab_page_url_handler.h" #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h" #include "chrome/browser/chrome_browser_main_android.h" -#include "chrome/browser/media/encrypted_media_message_filter_android.h" #include "chrome/common/descriptors_android.h" #include "components/breakpad/browser/crash_dump_manager_android.h" #elif defined(OS_POSIX) @@ -930,7 +930,7 @@ void ChromeContentBrowserClient::RenderProcessWillLaunch( context)); #endif #if defined(OS_ANDROID) - host->AddFilter(new EncryptedMediaMessageFilterAndroid()); + host->AddFilter(new cdm::CdmMessageFilterAndroid()); #endif if (switches::IsNewProfileManagement()) host->AddFilter(new PrincipalsMessageFilter(id)); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 92e76a3ebb64..d04f617bd74d 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1062,8 +1062,6 @@ 'browser/media/desktop_media_picker.h', 'browser/media/desktop_streams_registry.cc', 'browser/media/desktop_streams_registry.h', - 'browser/media/encrypted_media_message_filter_android.cc', - 'browser/media/encrypted_media_message_filter_android.h', 'browser/media/media_capture_devices_dispatcher.cc', 'browser/media/media_capture_devices_dispatcher.h', 'browser/media/media_device_id_salt.cc', @@ -3140,6 +3138,7 @@ }], ['OS=="android"', { 'dependencies': [ + '../components/components.gyp:cdm_browser', '../components/components.gyp:web_contents_delegate_android', 'chrome_browser_jni_headers', ], diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 57157b9e4ebe..eab0246ddf3b 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -111,7 +111,6 @@ 'common/custom_handlers/protocol_handler.cc', 'common/custom_handlers/protocol_handler.h', 'common/descriptors_android.h', - 'common/encrypted_media_messages_android.h', 'common/extensions/api/bluetooth/bluetooth_manifest_data.cc', 'common/extensions/api/bluetooth/bluetooth_manifest_data.h', 'common/extensions/api/bluetooth/bluetooth_manifest_handler.cc', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 98bd09444a92..9d6ef223e849 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -15,6 +15,7 @@ 'chrome_resources.gyp:chrome_strings', '../third_party/re2/re2.gyp:re2', '../components/components.gyp:autofill_content_renderer', + '../components/components.gyp:cdm_renderer', '../components/components.gyp:startup_metric_utils', '../components/components.gyp:plugins_renderer', '../components/components.gyp:translate_core_common', diff --git a/chrome/common/common_message_generator.h b/chrome/common/common_message_generator.h index 3fd05f69a4b6..462077ef7ff7 100644 --- a/chrome/common/common_message_generator.h +++ b/chrome/common/common_message_generator.h @@ -27,7 +27,3 @@ #if defined(ENABLE_WEBRTC) #include "chrome/common/media/webrtc_logging_messages.h" #endif - -#if defined(OS_ANDROID) -#include "chrome/common/encrypted_media_messages_android.h" -#endif diff --git a/chrome/renderer/DEPS b/chrome/renderer/DEPS index d65e9dfbac27..b607af897024 100644 --- a/chrome/renderer/DEPS +++ b/chrome/renderer/DEPS @@ -3,6 +3,7 @@ include_rules = [ "+components/autofill/content/common", "+components/autofill/content/renderer", "+components/autofill/core/common", + "+components/cdm/renderer", "+components/nacl/renderer", "+components/plugins/renderer", "+components/signin/core/common", diff --git a/chrome/renderer/media/chrome_key_systems.cc b/chrome/renderer/media/chrome_key_systems.cc index 71937fd87c2f..818d4010ac9c 100644 --- a/chrome/renderer/media/chrome_key_systems.cc +++ b/chrome/renderer/media/chrome_key_systems.cc @@ -12,6 +12,7 @@ #include "base/strings/string_split.h" #include "base/strings/utf_string_conversions.h" #include "chrome/common/render_messages.h" +#include "components/cdm/renderer/widevine_key_systems.h" #include "content/public/renderer/render_thread.h" #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. @@ -23,10 +24,6 @@ #include "base/version.h" #endif -#if defined(OS_ANDROID) -#include "chrome/common/encrypted_media_messages_android.h" -#endif - using content::KeySystemInfo; using content::SupportedCodecs; @@ -99,76 +96,12 @@ static void AddExternalClearKey( info.key_system = kExternalClearKeyCrashKeySystem; concrete_key_systems->push_back(info); } -#endif // defined(ENABLE_PEPPER_CDMS) - #if defined(WIDEVINE_CDM_AVAILABLE) -enum WidevineCdmType { - WIDEVINE, - WIDEVINE_HR, -#if defined(OS_ANDROID) - WIDEVINE_HR_NON_COMPOSITING, -#endif -}; - -#if !defined(OS_ANDROID) -static bool IsWidevineHrSupported() { - // TODO(jrummell): Need to call CheckPlatformState() but it is - // asynchronous, and needs to be done in the browser. - return false; -} -#endif - -// Return |name|'s parent key system. -static std::string GetDirectParentName(std::string name) { - int last_period = name.find_last_of('.'); - DCHECK_GT(last_period, 0); - return name.substr(0, last_period); -} - -static void AddWidevineWithCodecs( - WidevineCdmType widevine_cdm_type, - SupportedCodecs supported_codecs, - std::vector* concrete_key_systems) { - KeySystemInfo info(kWidevineKeySystem); - - switch (widevine_cdm_type) { - case WIDEVINE: - // For standard Widevine, add parent name. - info.parent_key_system = GetDirectParentName(kWidevineKeySystem); - break; - case WIDEVINE_HR: - info.key_system.append(".hr"); - break; -#if defined(OS_ANDROID) - case WIDEVINE_HR_NON_COMPOSITING: - info.key_system.append(".hrnoncompositing"); - break; -#endif - default: - NOTREACHED(); - } - - // TODO(xhwang): A container or an initDataType may be supported even though - // there are no codecs supported in that container. Fix this when we support - // initDataType. - info.supported_codecs = supported_codecs; - -#if defined(ENABLE_PEPPER_CDMS) - info.pepper_type = kWidevineCdmPluginMimeType; -#endif // defined(ENABLE_PEPPER_CDMS) - - concrete_key_systems->push_back(info); -} - -#if defined(ENABLE_PEPPER_CDMS) -// When the adapter is registered, a name-value pair is inserted in -// additional_param_* that lists the supported codecs. The name is "codecs" and -// the value is a comma-delimited list of codecs. // This function finds "codecs" and parses the value into the vector |codecs|. // Converts the codec strings to UTF-8 since we only expect ASCII strings and // this simplifies the rest of the code in this file. -void GetSupportedCodecs( +void GetSupportedCodecsForPepperCdm( const std::vector& additional_param_names, const std::vector& additional_param_values, std::vector* codecs) { @@ -212,7 +145,9 @@ static void AddPepperBasedWidevine( } std::vector codecs; - GetSupportedCodecs(additional_param_names, additional_param_values, &codecs); + GetSupportedCodecsForPepperCdm(additional_param_names, + additional_param_values, + &codecs); SupportedCodecs supported_codecs = content::EME_CODEC_NONE; for (size_t i = 0; i < codecs.size(); ++i) { @@ -230,52 +165,23 @@ static void AddPepperBasedWidevine( #endif // defined(USE_PROPRIETARY_CODECS) } - AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); - - if (IsWidevineHrSupported()) - AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); -} -#elif defined(OS_ANDROID) -static void AddAndroidWidevine( - std::vector* concrete_key_systems) { - SupportedKeySystemRequest request; - SupportedKeySystemResponse response; - - request.key_system = kWidevineKeySystem; - request.codecs = content::EME_CODEC_WEBM_ALL | content::EME_CODEC_MP4_ALL; - content::RenderThread::Get()->Send( - new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); - DCHECK(response.compositing_codecs & content::EME_CODEC_ALL) - << "unrecognized codec"; - DCHECK(response.non_compositing_codecs & content::EME_CODEC_ALL) - << "unrecognized codec"; - if (response.compositing_codecs != content::EME_CODEC_NONE) { - AddWidevineWithCodecs( - WIDEVINE, - static_cast(response.compositing_codecs), - concrete_key_systems); - } - - if (response.non_compositing_codecs != content::EME_CODEC_NONE) { - AddWidevineWithCodecs( - WIDEVINE_HR_NON_COMPOSITING, - static_cast(response.non_compositing_codecs), - concrete_key_systems); - } + cdm::AddWidevineWithCodecs(cdm::WIDEVINE, + supported_codecs, + concrete_key_systems); } -#endif // defined(ENABLE_PEPPER_CDMS) #endif // defined(WIDEVINE_CDM_AVAILABLE) +#endif // defined(ENABLE_PEPPER_CDMS) void AddChromeKeySystems(std::vector* key_systems_info) { #if defined(ENABLE_PEPPER_CDMS) AddExternalClearKey(key_systems_info); -#endif #if defined(WIDEVINE_CDM_AVAILABLE) -#if defined(ENABLE_PEPPER_CDMS) AddPepperBasedWidevine(key_systems_info); -#elif defined(OS_ANDROID) - AddAndroidWidevine(key_systems_info); -#endif -#endif +#endif // defined(WIDEVINE_CDM_AVAILABLE) +#endif // defined(ENABLE_PEPPER_CDMS) + +#if defined(OS_ANDROID) + cdm::AddAndroidWidevine(key_systems_info); +#endif // defined(OS_ANDROID) } diff --git a/components/cdm.gypi b/components/cdm.gypi new file mode 100644 index 000000000000..14f9234180b5 --- /dev/null +++ b/components/cdm.gypi @@ -0,0 +1,62 @@ +# 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. + +{ + 'targets': [ + { + 'target_name': 'cdm_common', + 'type': 'static_library', + 'dependencies': [ + '../base/base.gyp:base', + '../content/content.gyp:content_common', + '../ipc/ipc.gyp:ipc', + ], + 'sources': [ + 'cdm/common/cdm_message_generator.cc', + 'cdm/common/cdm_message_generator.h', + 'cdm/common/cdm_messages_android.h', + ], + }, + { + 'target_name': 'cdm_renderer', + 'type': 'static_library', + 'dependencies': [ + 'cdm_common', + '../base/base.gyp:base', + '../content/content.gyp:content_common', + '../content/content.gyp:content_renderer', + '../third_party/widevine/cdm/widevine_cdm.gyp:widevine_cdm_version_h', + ], + 'include_dirs': [ + # Needed by widevine_key_systems.cc. + '<(SHARED_INTERMEDIATE_DIR)', + ], + 'sources': [ + 'cdm/renderer/widevine_key_systems.cc', + 'cdm/renderer/widevine_key_systems.h', + ], + }, + ], + 'conditions': [ + ['OS == "android"', { + 'targets': [ + { + 'target_name': 'cdm_browser', + 'type': 'static_library', + 'dependencies': [ + 'cdm_common', + '../base/base.gyp:base', + '../content/content.gyp:content_browser', + '../content/content.gyp:content_common', + '../media/media.gyp:media', + ], + 'sources': [ + 'cdm/browser/cdm_message_filter_android.cc', + 'cdm/browser/cdm_message_filter_android.h', + ], + }, + ], + }], + ], +} diff --git a/components/cdm/DEPS b/components/cdm/DEPS new file mode 100644 index 000000000000..1c40d981eb61 --- /dev/null +++ b/components/cdm/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+ipc", +] diff --git a/components/cdm/OWNERS b/components/cdm/OWNERS new file mode 100644 index 000000000000..1f6205e40c0a --- /dev/null +++ b/components/cdm/OWNERS @@ -0,0 +1,3 @@ +ddorwin@chromium.org +scherkus@chromium.org +xhwang@chromium.org diff --git a/components/cdm/browser/DEPS b/components/cdm/browser/DEPS new file mode 100644 index 000000000000..d0fb59f1b272 --- /dev/null +++ b/components/cdm/browser/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+content/public/browser", + "+media/base/android", +] diff --git a/chrome/browser/media/encrypted_media_message_filter_android.cc b/components/cdm/browser/cdm_message_filter_android.cc similarity index 83% rename from chrome/browser/media/encrypted_media_message_filter_android.cc rename to components/cdm/browser/cdm_message_filter_android.cc index e16b0e9b948c..82dac5e1ac0f 100644 --- a/chrome/browser/media/encrypted_media_message_filter_android.cc +++ b/components/cdm/browser/cdm_message_filter_android.cc @@ -1,12 +1,12 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// 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 "chrome/browser/media/encrypted_media_message_filter_android.h" +#include "components/cdm/browser/cdm_message_filter_android.h" #include -#include "chrome/common/encrypted_media_messages_android.h" +#include "components/cdm/common/cdm_messages_android.h" #include "ipc/ipc_message_macros.h" #include "media/base/android/media_codec_bridge.h" #include "media/base/android/media_drm_bridge.h" @@ -16,7 +16,7 @@ using content::SupportedCodecs; using media::MediaCodecBridge; using media::MediaDrmBridge; -namespace chrome { +namespace cdm { const size_t kMaxKeySystemLength = 256; @@ -65,16 +65,16 @@ static SupportedCodecs GetSupportedCodecs( return supported_codecs; } -EncryptedMediaMessageFilterAndroid::EncryptedMediaMessageFilterAndroid() +CdmMessageFilterAndroid::CdmMessageFilterAndroid() : BrowserMessageFilter(EncryptedMediaMsgStart) {} -EncryptedMediaMessageFilterAndroid::~EncryptedMediaMessageFilterAndroid() {} +CdmMessageFilterAndroid::~CdmMessageFilterAndroid() {} -bool EncryptedMediaMessageFilterAndroid::OnMessageReceived( +bool CdmMessageFilterAndroid::OnMessageReceived( const IPC::Message& message, bool* message_was_ok) { bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX( - EncryptedMediaMessageFilterAndroid, message, *message_was_ok) + CdmMessageFilterAndroid, message, *message_was_ok) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_GetSupportedKeySystems, OnGetSupportedKeySystems) IPC_MESSAGE_UNHANDLED(handled = false) @@ -82,14 +82,14 @@ bool EncryptedMediaMessageFilterAndroid::OnMessageReceived( return handled; } -void EncryptedMediaMessageFilterAndroid::OverrideThreadForMessage( +void CdmMessageFilterAndroid::OverrideThreadForMessage( const IPC::Message& message, BrowserThread::ID* thread) { // Move the IPC handling to FILE thread as it is not very cheap. if (message.type() == ChromeViewHostMsg_GetSupportedKeySystems::ID) *thread = BrowserThread::FILE; } -void EncryptedMediaMessageFilterAndroid::OnGetSupportedKeySystems( +void CdmMessageFilterAndroid::OnGetSupportedKeySystems( const SupportedKeySystemRequest& request, SupportedKeySystemResponse* response) { if (!response) { @@ -112,4 +112,4 @@ void EncryptedMediaMessageFilterAndroid::OnGetSupportedKeySystems( response->non_compositing_codecs = GetSupportedCodecs(request, false); } -} // namespace chrome +} // namespace cdm diff --git a/chrome/browser/media/encrypted_media_message_filter_android.h b/components/cdm/browser/cdm_message_filter_android.h similarity index 64% rename from chrome/browser/media/encrypted_media_message_filter_android.h rename to components/cdm/browser/cdm_message_filter_android.h index 9d426ae59a78..b639fa88c890 100644 --- a/chrome/browser/media/encrypted_media_message_filter_android.h +++ b/components/cdm/browser/cdm_message_filter_android.h @@ -1,9 +1,9 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// 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 CHROME_BROWSER_MEDIA_ENCRYPTED_MEDIA_MESSAGE_FILTER_ANDROID_H_ -#define CHROME_BROWSER_MEDIA_ENCRYPTED_MEDIA_MESSAGE_FILTER_ANDROID_H_ +#ifndef COMPONENTS_CDM_BROWSER_CDM_MESSAGE_FILTER_ANDROID_H_ +#define COMPONENTS_CDM_BROWSER_CDM_MESSAGE_FILTER_ANDROID_H_ #include "base/basictypes.h" #include "content/public/browser/browser_message_filter.h" @@ -11,17 +11,17 @@ struct SupportedKeySystemRequest; struct SupportedKeySystemResponse; -namespace chrome { +namespace cdm { // Message filter for EME on android. It is responsible for getting the // SupportedKeySystems information and passing it back to renderer. -class EncryptedMediaMessageFilterAndroid +class CdmMessageFilterAndroid : public content::BrowserMessageFilter { public: - EncryptedMediaMessageFilterAndroid(); + CdmMessageFilterAndroid(); private: - virtual ~EncryptedMediaMessageFilterAndroid(); + virtual ~CdmMessageFilterAndroid(); // BrowserMessageFilter implementation. virtual bool OnMessageReceived(const IPC::Message& message, @@ -35,9 +35,9 @@ class EncryptedMediaMessageFilterAndroid const SupportedKeySystemRequest& request, SupportedKeySystemResponse* response); - DISALLOW_COPY_AND_ASSIGN(EncryptedMediaMessageFilterAndroid); + DISALLOW_COPY_AND_ASSIGN(CdmMessageFilterAndroid); }; -} // namespace chrome +} // namespace cdm -#endif // CHROME_BROWSER_MEDIA_ENCRYPTED_MEDIA_MESSAGE_FILTER_ANDROID_H_ +#endif // COMPONENTS_CDM_BROWSER_CDM_MESSAGE_FILTER_ANDROID_H_ diff --git a/components/cdm/common/DEPS b/components/cdm/common/DEPS new file mode 100644 index 000000000000..d5923ee96cb0 --- /dev/null +++ b/components/cdm/common/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/public/common", +] diff --git a/components/cdm/common/OWNERS b/components/cdm/common/OWNERS new file mode 100644 index 000000000000..acdf36065094 --- /dev/null +++ b/components/cdm/common/OWNERS @@ -0,0 +1,13 @@ +# Changes to IPC messages require a security review to avoid introducing +# new sandbox escapes. +per-file encrypted_media_messages*.h=set noparent +per-file encrypted_media_messages*.h=cdn@chromium.org +per-file encrypted_media_messages*.h=cevans@chromium.org +per-file encrypted_media_messages*.h=dcheng@chromium.org +per-file encrypted_media_messages*.h=inferno@chromium.org +per-file encrypted_media_messages*.h=jln@chromium.org +per-file encrypted_media_messages*.h=jschuh@chromium.org +per-file encrypted_media_messages*.h=kenrb@chromium.org +per-file encrypted_media_messages*.h=nasko@chromium.org +per-file encrypted_media_messages*.h=palmer@chromium.org +per-file encrypted_media_messages*.h=tsepez@chromium.org diff --git a/components/cdm/common/cdm_message_generator.cc b/components/cdm/common/cdm_message_generator.cc new file mode 100644 index 000000000000..2aabce727a5b --- /dev/null +++ b/components/cdm/common/cdm_message_generator.cc @@ -0,0 +1,34 @@ +// 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. + +// Get basic type definitions. +#define IPC_MESSAGE_IMPL +#include "components/cdm/common/cdm_message_generator.h" + +// Generate constructors. +#include "ipc/struct_constructor_macros.h" +#include "components/cdm/common/cdm_message_generator.h" + +// Generate destructors. +#include "ipc/struct_destructor_macros.h" +#include "components/cdm/common/cdm_message_generator.h" + +// Generate param traits write methods. +#include "ipc/param_traits_write_macros.h" +namespace IPC { +#include "components/cdm/common/cdm_message_generator.h" +} // namespace IPC + +// Generate param traits read methods. +#include "ipc/param_traits_read_macros.h" +namespace IPC { +#include "components/cdm/common/cdm_message_generator.h" +} // namespace IPC + +// Generate param traits log methods. +#include "ipc/param_traits_log_macros.h" +namespace IPC { +#include "components/cdm/common/cdm_message_generator.h" +} // namespace IPC + diff --git a/components/cdm/common/cdm_message_generator.h b/components/cdm/common/cdm_message_generator.h new file mode 100644 index 000000000000..b528207d00f8 --- /dev/null +++ b/components/cdm/common/cdm_message_generator.h @@ -0,0 +1,11 @@ +// 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. + +// Multiply-included file, no traditional include guard. + +#include "base/basictypes.h" // for OS_ANDROID and some basic types. + +#if defined(OS_ANDROID) +#include "components/cdm/common/cdm_messages_android.h" +#endif diff --git a/chrome/common/encrypted_media_messages_android.h b/components/cdm/common/cdm_messages_android.h similarity index 95% rename from chrome/common/encrypted_media_messages_android.h rename to components/cdm/common/cdm_messages_android.h index 034fb3bbc14f..e63f81b01cd8 100644 --- a/chrome/common/encrypted_media_messages_android.h +++ b/components/cdm/common/cdm_messages_android.h @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// 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. diff --git a/components/cdm/renderer/DEPS b/components/cdm/renderer/DEPS new file mode 100644 index 000000000000..725e151a7a51 --- /dev/null +++ b/components/cdm/renderer/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/public/renderer", +] diff --git a/components/cdm/renderer/widevine_key_systems.cc b/components/cdm/renderer/widevine_key_systems.cc new file mode 100644 index 000000000000..d42ec7d680c7 --- /dev/null +++ b/components/cdm/renderer/widevine_key_systems.cc @@ -0,0 +1,93 @@ +// 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 "components/cdm/renderer/widevine_key_systems.h" + +#include +#include + +#include "base/logging.h" +#include "components/cdm/common/cdm_messages_android.h" +#include "content/public/renderer/key_system_info.h" +#include "content/public/renderer/render_thread.h" + +#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. + +#if defined(WIDEVINE_CDM_AVAILABLE) + +using content::KeySystemInfo; +using content::SupportedCodecs; + +namespace cdm { + +// Return |name|'s parent key system. +static std::string GetDirectParentName(std::string name) { + int last_period = name.find_last_of('.'); + DCHECK_GT(last_period, 0); + return name.substr(0, last_period); +} + +void AddWidevineWithCodecs(WidevineCdmType widevine_cdm_type, + SupportedCodecs supported_codecs, + std::vector* concrete_key_systems) { + KeySystemInfo info(kWidevineKeySystem); + + switch (widevine_cdm_type) { + case WIDEVINE: + // For standard Widevine, add parent name. + info.parent_key_system = GetDirectParentName(kWidevineKeySystem); + break; +#if defined(OS_ANDROID) + case WIDEVINE_HR_NON_COMPOSITING: + info.key_system.append(".hrnoncompositing"); + break; +#endif // defined(OS_ANDROID) + default: + NOTREACHED(); + } + + // TODO(xhwang): A container or an initDataType may be supported even though + // there are no codecs supported in that container. Fix this when we support + // initDataType. + info.supported_codecs = supported_codecs; + +#if defined(ENABLE_PEPPER_CDMS) + info.pepper_type = kWidevineCdmPluginMimeType; +#endif // defined(ENABLE_PEPPER_CDMS) + + concrete_key_systems->push_back(info); +} + +#if defined(OS_ANDROID) +void AddAndroidWidevine(std::vector* concrete_key_systems) { + SupportedKeySystemRequest request; + SupportedKeySystemResponse response; + + request.key_system = kWidevineKeySystem; + request.codecs = content::EME_CODEC_WEBM_ALL | content::EME_CODEC_MP4_ALL; + content::RenderThread::Get()->Send( + new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); + DCHECK(response.compositing_codecs & content::EME_CODEC_ALL) + << "unrecognized codec"; + DCHECK(response.non_compositing_codecs & content::EME_CODEC_ALL) + << "unrecognized codec"; + if (response.compositing_codecs != content::EME_CODEC_NONE) { + AddWidevineWithCodecs( + WIDEVINE, + static_cast(response.compositing_codecs), + concrete_key_systems); + } + + if (response.non_compositing_codecs != content::EME_CODEC_NONE) { + AddWidevineWithCodecs( + WIDEVINE_HR_NON_COMPOSITING, + static_cast(response.non_compositing_codecs), + concrete_key_systems); + } +} +#endif // OS_ANDROID + +} // namespace cdm + +#endif // defined(WIDEVINE_CDM_AVAILABLE) diff --git a/components/cdm/renderer/widevine_key_systems.h b/components/cdm/renderer/widevine_key_systems.h new file mode 100644 index 000000000000..3bed60ca4a60 --- /dev/null +++ b/components/cdm/renderer/widevine_key_systems.h @@ -0,0 +1,33 @@ +// 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 COMPONENTS_CDM_RENDERER_WIDEVINE_KEY_SYSTEMS_H_ +#define COMPONENTS_CDM_RENDERER_WIDEVINE_KEY_SYSTEMS_H_ + +#include + +#include "content/public/renderer/key_system_info.h" + +namespace cdm { + +enum WidevineCdmType { + WIDEVINE, +#if defined(OS_ANDROID) + WIDEVINE_HR_NON_COMPOSITING, +#endif // defined(OS_ANDROID) +}; + +void AddWidevineWithCodecs( + WidevineCdmType widevine_cdm_type, + content::SupportedCodecs supported_codecs, + std::vector* concrete_key_systems); + +#if defined(OS_ANDROID) +void AddAndroidWidevine( + std::vector* concrete_key_systems); +#endif // defined(OS_ANDROID) + +} // namespace cdm + +#endif // COMPONENTS_CDM_RENDERER_WIDEVINE_KEY_SYSTEMS_H_ diff --git a/components/components.gyp b/components/components.gyp index a5c116f18afa..47576cc6ec30 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -48,6 +48,7 @@ 'conditions': [ ['OS != "ios"', { 'includes': [ + 'cdm.gypi', 'navigation_interception.gypi', 'plugins.gypi', 'sessions.gypi',