Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Add widevine third party
Browse files Browse the repository at this point in the history
Add 2 new command options to use widevine:
- widevine-cdm-path: Path to widevine plugin
- widevine-cdm-version: Version of the widevine plugin
  • Loading branch information
clebeaupin authored and zcbenz committed Dec 29, 2015
1 parent 5f3c610 commit 9d878ad
Show file tree
Hide file tree
Showing 17 changed files with 529 additions and 12 deletions.
20 changes: 20 additions & 0 deletions atom.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@
# Defined in Chromium but not exposed in its gyp file.
'V8_USE_EXTERNAL_STARTUP_DATA',
'ENABLE_PLUGINS',
'ENABLE_PEPPER_CDMS',
'USE_PROPRIETARY_CODECS',
],
'sources': [
'<@(lib_sources)',
Expand All @@ -260,11 +262,18 @@
'<(libchromiumcontent_src_dir)/third_party/libyuv/include',
# The 'third_party/webrtc/modules/desktop_capture/desktop_frame.h' is using 'webrtc/base/scoped_ptr.h'.
'<(libchromiumcontent_src_dir)/third_party/',
'<(libchromiumcontent_src_dir)/components/cdm',
'<(libchromiumcontent_src_dir)/third_party/widevine',
],
'direct_dependent_settings': {
'include_dirs': [
'.',
],
'ldflags': [
'-Wl,--whole-archive',
'<@(libchromiumcontent_libraries)',
'-Wl,--no-whole-archive',
],
},
'export_dependent_settings': [
'vendor/brightray/brightray.gyp:brightray',
Expand Down Expand Up @@ -434,6 +443,7 @@
'<(libchromiumcontent_dir)/icudtl.dat',
'<(libchromiumcontent_dir)/natives_blob.bin',
'<(libchromiumcontent_dir)/snapshot_blob.bin',
'<(libchromiumcontent_dir)/widevinecdmadapter.plugin',
],
'xcode_settings': {
'ATOM_BUNDLE_ID': 'com.<(company_abbr).<(project_name).framework',
Expand Down Expand Up @@ -490,6 +500,16 @@
'${BUILT_PRODUCTS_DIR}/<(product_name) Framework.framework/Versions/A/<(product_name) Framework',
],
},
{
'postbuild_name': 'Fix path of libwidevinecdm',
'action': [
'install_name_tool',
'-change',
'@loader_path/libwidevinecdm.dylib',
'@rpath/libwidevinecdm.dylib',
'${BUILT_PRODUCTS_DIR}/<(product_name) Framework.framework/Versions/A/<(product_name) Framework',
],
},
{
'postbuild_name': 'Add symlinks for framework subdirectories',
'action': [
Expand Down
114 changes: 104 additions & 10 deletions atom/app/atom_content_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@
#include "atom/common/chrome_version.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/pepper_plugin_info.h"
#include "content/public/common/user_agent.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
#include "url/url_constants.h"

#include "third_party/widevine/cdm/stub/widevine_cdm_version.h"

// The following must be after widevine_cdm_version.h.
#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
// && !defined(WIDEVINE_CDM_IS_COMPONENT)
#include "chrome/common/widevine_cdm_constants.h"
#endif

namespace atom {

namespace {
Expand Down Expand Up @@ -63,6 +73,52 @@ content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path,
return plugin;
}


#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
//&& !defined(WIDEVINE_CDM_IS_COMPONENT)

content::PepperPluginInfo CreateWidevineCdmInfo(const base::FilePath& path,
const std::string& version) {
content::PepperPluginInfo widevine_cdm;
widevine_cdm.is_out_of_process = true;
widevine_cdm.path = path;
widevine_cdm.name = kWidevineCdmDisplayName;
widevine_cdm.description = kWidevineCdmDescription +
std::string(" (version: ") +
version + ")";
widevine_cdm.version = version;
content::WebPluginMimeType widevine_cdm_mime_type(
kWidevineCdmPluginMimeType,
kWidevineCdmPluginExtension,
kWidevineCdmPluginMimeTypeDescription);

// Add the supported codecs as if they came from the component manifest.
std::vector<std::string> codecs;
codecs.push_back(kCdmSupportedCodecVorbis);
codecs.push_back(kCdmSupportedCodecVp8);
codecs.push_back(kCdmSupportedCodecVp9);
#if defined(USE_PROPRIETARY_CODECS)
codecs.push_back(kCdmSupportedCodecAac);
codecs.push_back(kCdmSupportedCodecAvc1);
#endif // defined(USE_PROPRIETARY_CODECS)
std::string codec_string = base::JoinString(
codecs, std::string(1, kCdmSupportedCodecsValueDelimiter));
widevine_cdm_mime_type.additional_param_names.push_back(
base::ASCIIToUTF16(kCdmSupportedCodecsParamName));
widevine_cdm_mime_type.additional_param_values.push_back(
base::ASCIIToUTF16(codec_string));

widevine_cdm.mime_types.push_back(widevine_cdm_mime_type);
widevine_cdm.permissions = kWidevineCdmPluginPermissions;

return widevine_cdm;
}

#endif
// defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) &&
// !defined(WIDEVINE_CDM_IS_COMPONENT)


void ConvertStringWithSeparatorToVector(std::vector<std::string>* vec,
const char* separator,
const char* cmd_switch) {
Expand All @@ -76,6 +132,49 @@ void ConvertStringWithSeparatorToVector(std::vector<std::string>* vec,

} // namespace

void AddPepperFlashFromCommandLine(
std::vector<content::PepperPluginInfo>* plugins) {
auto command_line = base::CommandLine::ForCurrentProcess();
auto flash_path = command_line->GetSwitchValueNative(
switches::kPpapiFlashPath);
if (flash_path.empty())
return;

auto flash_version = command_line->GetSwitchValueASCII(
switches::kPpapiFlashVersion);

plugins->push_back(
CreatePepperFlashInfo(base::FilePath(flash_path), flash_version));
}

#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
//&& !defined(WIDEVINE_CDM_IS_COMPONENT)
void AddWidevineCdmFromCommandLine(
std::vector<content::PepperPluginInfo>* plugins) {
auto command_line = base::CommandLine::ForCurrentProcess();
auto widevine_cdm_path = command_line->GetSwitchValueNative(
switches::kWidevineCdmPath);
if (widevine_cdm_path.empty())
return;

if (!base::PathExists(base::FilePath(widevine_cdm_path)))
return;

auto widevine_cdm_version = command_line->GetSwitchValueASCII(
switches::kWidevineCdmVersion);
if (widevine_cdm_version.empty())
return;

plugins->push_back(
CreateWidevineCdmInfo(base::FilePath(widevine_cdm_path),
widevine_cdm_version));
}
#endif
// defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) &&
// !defined(WIDEVINE_CDM_IS_COMPONENT)



AtomContentClient::AtomContentClient() {
}

Expand Down Expand Up @@ -107,17 +206,12 @@ void AtomContentClient::AddAdditionalSchemes(

void AtomContentClient::AddPepperPlugins(
std::vector<content::PepperPluginInfo>* plugins) {
auto command_line = base::CommandLine::ForCurrentProcess();
auto flash_path = command_line->GetSwitchValuePath(
switches::kPpapiFlashPath);
if (flash_path.empty())
return;
AddPepperFlashFromCommandLine(plugins);

auto flash_version = command_line->GetSwitchValueASCII(
switches::kPpapiFlashVersion);

plugins->push_back(
CreatePepperFlashInfo(flash_path, flash_version));
#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
//&& !defined(WIDEVINE_CDM_IS_COMPONENT)
AddWidevineCdmFromCommandLine(plugins);
#endif
}

void AtomContentClient::AddServiceWorkerSchemes(
Expand Down
3 changes: 3 additions & 0 deletions atom/browser/atom_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/printing/printing_message_filter.h"
#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
#include "chrome/browser/renderer_host/pepper/widevine_cdm_message_filter.h"
#include "chrome/browser/speech/tts_message_filter.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/browser/client_certificate_delegate.h"
Expand Down Expand Up @@ -105,6 +106,8 @@ void AtomBrowserClient::RenderProcessWillLaunch(
int process_id = host->GetID();
host->AddFilter(new printing::PrintingMessageFilter(process_id));
host->AddFilter(new TtsMessageFilter(process_id, host->GetBrowserContext()));
host->AddFilter(
new WidevineCdmMessageFilter(process_id, host->GetBrowserContext()));
}

content::SpeechRecognitionManagerDelegate*
Expand Down
1 change: 1 addition & 0 deletions atom/common/common_message_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
#include "atom/common/api/api_messages.h"
#include "chrome/common/print_messages.h"
#include "chrome/common/tts_messages.h"
#include "chrome/common/widevine_cdm_messages.h"
6 changes: 6 additions & 0 deletions atom/common/options_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ const char kSharedWorker[] = "shared-worker";
const char kPageVisibility[] = "page-visiblity";
const char kOpenerID[] = "opener-id";

// Widevine options
// Path to Widevine CDM binaries.
const char kWidevineCdmPath[] = "widevine-cdm-path";
// Widevine CDM version.
const char kWidevineCdmVersion[] = "widevine-cdm-version";

} // namespace switches

} // namespace atom
3 changes: 3 additions & 0 deletions atom/common/options_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ extern const char kSharedWorker[];
extern const char kPageVisibility[];
extern const char kOpenerID[];

extern const char kWidevineCdmPath[];
extern const char kWidevineCdmVersion[];

} // namespace switches

} // namespace atom
Expand Down
7 changes: 7 additions & 0 deletions atom/renderer/atom_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "atom/renderer/atom_renderer_client.h"

#include <string>
#include <vector>

#include "atom/common/api/api_messages.h"
#include "atom/common/api/atom_bindings.h"
Expand All @@ -15,6 +16,7 @@
#include "atom/renderer/guest_view_container.h"
#include "atom/renderer/node_array_buffer_bridge.h"
#include "base/command_line.h"
#include "chrome/renderer/media/chrome_key_systems.h"
#include "chrome/renderer/pepper/pepper_helper.h"
#include "chrome/renderer/printing/print_web_view_helper.h"
#include "chrome/renderer/tts_dispatcher.h"
Expand Down Expand Up @@ -234,4 +236,9 @@ void AtomRendererClient::EnableWebRuntimeFeatures() {
blink::WebRuntimeFeatures::enableSharedWorker(true);
}

void AtomRendererClient::AddKeySystems(
std::vector<media::KeySystemInfo>* key_systems) {
AddChromeKeySystems(key_systems);
}

} // namespace atom
3 changes: 2 additions & 1 deletion atom/renderer/atom_renderer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_

#include <string>
#include <vector>

#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/render_process_observer.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ class AtomRendererClient : public content::ContentRendererClient,
bool ShouldOverridePageVisibilityState(
const content::RenderFrame* render_frame,
blink::WebPageVisibilityState* override_state) override;

void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems) override;
void EnableWebRuntimeFeatures();

scoped_ptr<NodeBindings> node_bindings_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 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 "chrome/browser/renderer_host/pepper/widevine_cdm_message_filter.h"

#include "base/bind.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/webplugininfo.h"
#include "content/public/browser/plugin_service.h"
using content::PluginService;
using content::WebPluginInfo;
using content::BrowserThread;

WidevineCdmMessageFilter::WidevineCdmMessageFilter(
int render_process_id,
content::BrowserContext* browser_context)
: BrowserMessageFilter(ChromeMsgStart),
render_process_id_(render_process_id),
browser_context_(browser_context) {
}

bool WidevineCdmMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(WidevineCdmMessageFilter, message)
#if defined(ENABLE_PEPPER_CDMS)
IPC_MESSAGE_HANDLER(
ChromeViewHostMsg_IsInternalPluginAvailableForMimeType,
OnIsInternalPluginAvailableForMimeType)
#endif
IPC_MESSAGE_UNHANDLED(return false)
IPC_END_MESSAGE_MAP()
return true;
}

#if defined(ENABLE_PEPPER_CDMS)
void WidevineCdmMessageFilter::OnIsInternalPluginAvailableForMimeType(
const std::string& mime_type,
bool* is_available,
std::vector<base::string16>* additional_param_names,
std::vector<base::string16>* additional_param_values) {

std::vector<WebPluginInfo> plugins;
PluginService::GetInstance()->GetInternalPlugins(&plugins);

for (size_t i = 0; i < plugins.size(); ++i) {
const WebPluginInfo& plugin = plugins[i];
const std::vector<content::WebPluginMimeType>& mime_types =
plugin.mime_types;
for (size_t j = 0; j < mime_types.size(); ++j) {

if (mime_types[j].mime_type == mime_type) {
*is_available = true;
*additional_param_names = mime_types[j].additional_param_names;
*additional_param_values = mime_types[j].additional_param_values;
return;
}
}
}

*is_available = false;
}
#endif // defined(ENABLE_PEPPER_CDMS)

void WidevineCdmMessageFilter::OnDestruct() const {
BrowserThread::DeleteOnUIThread::Destruct(this);
}

WidevineCdmMessageFilter::~WidevineCdmMessageFilter() {
}
Loading

0 comments on commit 9d878ad

Please sign in to comment.