Skip to content

Commit

Permalink
Componentize EncryptedMediaMessageFilter and rename it CdmMessageFilter.
Browse files Browse the repository at this point in the history
    
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
  • Loading branch information
ycheo@chromium.org committed May 9, 2014
1 parent fe7a12a commit 649b572
Show file tree
Hide file tree
Showing 28 changed files with 315 additions and 175 deletions.
2 changes: 2 additions & 0 deletions android_webview/android_webview.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions android_webview/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions android_webview/browser/aw_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions android_webview/renderer/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include_rules = [
"+android_webview/renderer",

"+components/autofill/content/renderer",
"+components/cdm/renderer",
"+components/visitedlink/renderer",

"+content/public/renderer",
Expand Down
38 changes: 3 additions & 35 deletions android_webview/renderer/aw_key_systems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,13 @@
// found in the LICENSE file.

#include "android_webview/renderer/aw_key_systems.h"

#include <string>

#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<KeySystemInfo>* 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<KeySystemInfo>* key_systems_info) {
AddWidevineWithCodecs(kWidevineKeySystem, true, key_systems_info);
std::vector<content::KeySystemInfo>* key_systems_info) {
cdm::AddAndroidWidevine(key_systems_info);
}

} // namespace android_webview
1 change: 1 addition & 0 deletions chrome/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions chrome/chrome_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -3140,6 +3138,7 @@
}],
['OS=="android"', {
'dependencies': [
'../components/components.gyp:cdm_browser',
'../components/components.gyp:web_contents_delegate_android',
'chrome_browser_jni_headers',
],
Expand Down
1 change: 0 additions & 1 deletion chrome/chrome_common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_renderer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 0 additions & 4 deletions chrome/common/common_message_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions chrome/renderer/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
124 changes: 15 additions & 109 deletions chrome/renderer/media/chrome_key_systems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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<KeySystemInfo>* 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<base::string16>& additional_param_names,
const std::vector<base::string16>& additional_param_values,
std::vector<std::string>* codecs) {
Expand Down Expand Up @@ -212,7 +145,9 @@ static void AddPepperBasedWidevine(
}

std::vector<std::string> 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) {
Expand All @@ -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<KeySystemInfo>* 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<SupportedCodecs>(response.compositing_codecs),
concrete_key_systems);
}

if (response.non_compositing_codecs != content::EME_CODEC_NONE) {
AddWidevineWithCodecs(
WIDEVINE_HR_NON_COMPOSITING,
static_cast<SupportedCodecs>(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<KeySystemInfo>* 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)
}
Loading

0 comments on commit 649b572

Please sign in to comment.