Skip to content

Commit

Permalink
build: [m67] enable widevine support (#14519)
Browse files Browse the repository at this point in the history
* build: [m67] enable widevine support

* fix: remove plugin cache reset hack

It was added in (#8907) to make widevine cdm shows up in
navigator.plugins, since widevine support is no longer
enabled by a plugin it can be removed safely.
  • Loading branch information
deepak1556 authored and alexeykuzmin committed Sep 10, 2018
1 parent 3ed888b commit beae267
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 151 deletions.
2 changes: 0 additions & 2 deletions BUILD.gn
Expand Up @@ -438,8 +438,6 @@ static_library("electron_lib") {

if (enable_widevine) {
sources += [
"//chrome/common/widevine_cdm_constants.cc",
"//chrome/common/widevine_cdm_constants.h",
"//chrome/renderer/media/chrome_key_systems.cc",
"//chrome/renderer/media/chrome_key_systems.h",
"//chrome/renderer/media/chrome_key_systems_provider.cc",
Expand Down
75 changes: 18 additions & 57 deletions atom/app/atom_content_client.cc
Expand Up @@ -18,7 +18,6 @@
#include "content/public/common/content_constants.h"
#include "content/public/common/pepper_plugin_info.h"
#include "content/public/common/user_agent.h"
#include "media/media_buildflags.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/url_constants.h"
Expand All @@ -27,8 +26,6 @@

#if defined(WIDEVINE_CDM_AVAILABLE)
#include "base/native_library.h"
#include "base/strings/stringprintf.h"
#include "chrome/common/widevine_cdm_constants.h"
#include "content/public/common/cdm_info.h"
#include "media/base/video_codecs.h"
#endif // defined(WIDEVINE_CDM_AVAILABLE)
Expand All @@ -43,69 +40,38 @@ namespace atom {
namespace {

#if defined(WIDEVINE_CDM_AVAILABLE)
bool IsWidevineAvailable(base::FilePath* adapter_path,
base::FilePath* cdm_path,
bool IsWidevineAvailable(base::FilePath* cdm_path,
std::vector<media::VideoCodec>* codecs_supported) {
static enum {
NOT_CHECKED,
FOUND,
NOT_FOUND,
} widevine_cdm_file_check = NOT_CHECKED;

base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
*adapter_path = command_line->GetSwitchValuePath(switches::kWidevineCdmPath);
if (!adapter_path->empty()) {
*cdm_path = adapter_path->DirName().AppendASCII(
base::GetNativeLibraryName(kWidevineCdmLibraryName));
if (widevine_cdm_file_check == NOT_CHECKED) {
widevine_cdm_file_check =
(base::PathExists(*adapter_path) && base::PathExists(*cdm_path))
? FOUND
: NOT_FOUND;
if (widevine_cdm_file_check == NOT_CHECKED) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
*cdm_path = command_line->GetSwitchValuePath(switches::kWidevineCdmPath);
if (!cdm_path->empty()) {
*cdm_path = cdm_path->AppendASCII(
base::GetNativeLibraryName(kWidevineCdmLibraryName));
widevine_cdm_file_check = base::PathExists(*cdm_path) ? FOUND : NOT_FOUND;
}
if (widevine_cdm_file_check == FOUND) {
// Add the supported codecs as if they came from the component manifest.
// This list must match the CDM that is being bundled with Chrome.
codecs_supported->push_back(media::VideoCodec::kCodecVP8);
codecs_supported->push_back(media::VideoCodec::kCodecVP9);
}

if (widevine_cdm_file_check == FOUND) {
// Add the supported codecs as if they came from the component manifest.
// This list must match the CDM that is being bundled with Chrome.
codecs_supported->push_back(media::VideoCodec::kCodecVP8);
codecs_supported->push_back(media::VideoCodec::kCodecVP9);
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
codecs_supported->push_back(media::VideoCodec::kCodecH264);
codecs_supported->push_back(media::VideoCodec::kCodecH264);
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)

return true;
}
return true;
}

return false;
}

void AddWidevineAdapterFromCommandLine(
base::CommandLine* command_line,
std::vector<content::PepperPluginInfo>* plugins) {
base::FilePath adapter_path;
base::FilePath cdm_path;
std::vector<media::VideoCodec> video_codecs_supported;
if (IsWidevineAvailable(&adapter_path, &cdm_path, &video_codecs_supported)) {
auto cdm_version_string =
command_line->GetSwitchValueASCII(switches::kWidevineCdmVersion);
content::PepperPluginInfo info;
info.is_out_of_process = true;
info.path = adapter_path;
info.name = kWidevineCdmDisplayName;
info.description =
base::StringPrintf("%s (version: %s)", kWidevineCdmDescription,
cdm_version_string.c_str());
info.version = cdm_version_string;
info.permissions = kWidevineCdmPluginPermissions;

content::WebPluginMimeType mime_type(kWidevineCdmPluginMimeType,
kWidevineCdmPluginExtension,
kWidevineCdmPluginMimeTypeDescription);
info.mime_types.push_back(mime_type);

plugins->push_back(info);
}
}
#endif // defined(WIDEVINE_CDM_AVAILABLE)

#if defined(ENABLE_PEPPER_FLASH)
Expand Down Expand Up @@ -235,9 +201,6 @@ void AtomContentClient::AddPepperPlugins(
#if defined(ENABLE_PEPPER_FLASH)
AddPepperFlashFromCommandLine(command_line, plugins);
#endif // defined(ENABLE_PEPPER_FLASH)
#if defined(WIDEVINE_CDM_AVAILABLE)
AddWidevineAdapterFromCommandLine(command_line, plugins);
#endif // defined(WIDEVINE_CDM_AVAILABLE)
ComputeBuiltInPlugins(plugins);
}

Expand All @@ -246,12 +209,10 @@ void AtomContentClient::AddContentDecryptionModules(
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
if (cdms) {
#if defined(WIDEVINE_CDM_AVAILABLE)
base::FilePath adapter_path;
base::FilePath cdm_path;
std::vector<media::VideoCodec> video_codecs_supported;
bool supports_persistent_license = false;
if (IsWidevineAvailable(&adapter_path, &cdm_path,
&video_codecs_supported)) {
if (IsWidevineAvailable(&cdm_path, &video_codecs_supported)) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
auto cdm_version_string =
command_line->GetSwitchValueASCII(switches::kWidevineCdmVersion);
Expand Down
3 changes: 0 additions & 3 deletions atom/renderer/renderer_client_base.cc
Expand Up @@ -170,9 +170,6 @@ void RendererClientBase::RenderFrameCreated(
new ContentSettingsObserver(render_frame);
new printing::PrintWebViewHelper(render_frame);

// This is required for widevine plugin detection provided during runtime.
blink::ResetPluginCache();

#if defined(ENABLE_PDF_VIEWER)
// Allow access to file scheme from pdf viewer.
blink::WebSecurityPolicy::AddOriginAccessWhitelistEntry(
Expand Down
2 changes: 2 additions & 0 deletions atom/renderer/renderer_client_base.h
Expand Up @@ -10,6 +10,8 @@

#include "content/public/renderer/content_renderer_client.h"
#include "third_party/blink/public/web/web_local_frame.h"
// In SHARED_INTERMEDIATE_DIR.
#include "widevine_cdm_version.h" // NOLINT(build/include)

#if defined(WIDEVINE_CDM_AVAILABLE)
#include "chrome/renderer/media/chrome_key_systems_provider.h"
Expand Down
3 changes: 0 additions & 3 deletions build/args/all.gn
Expand Up @@ -6,9 +6,6 @@ root_extra_deps = [ "//electron" ]
v8_promise_internal_field_count = 1
v8_typed_array_max_size_in_heap = 0

# TODO(alexeykuzmin): [Ch67] Fix compilcation and enable it back.
enable_widevine = false

enable_cdm_host_verification = false
proprietary_codecs = true
ffmpeg_branding = "Chrome"
2 changes: 1 addition & 1 deletion docs/README.md
Expand Up @@ -93,8 +93,8 @@ These individual tutorials expand on topics discussed in the guide above.
* [Using asar Archives](tutorial/application-packaging.md#using-asar-archives)
* [Limitations](tutorial/application-packaging.md#limitations-of-the-node-api)
* [Adding Unpacked Files to asar Archives](tutorial/application-packaging.md#adding-unpacked-files-to-asar-archives)
* [In Detail: Testing Widevine CDM](tutorial/testing-widevine-cdm.md)
* [In Detail: Using Pepper Flash Plugin](tutorial/using-pepper-flash-plugin.md)
* [In Detail: Using Widevine CDM Plugin](tutorial/using-widevine-cdm-plugin.md)
* [Offscreen Rendering](tutorial/offscreen-rendering.md)

---
Expand Down
60 changes: 60 additions & 0 deletions docs/tutorial/testing-widevine-cdm.md
@@ -0,0 +1,60 @@
# Testing Widevine CDM

In Electron you can use the Widevine CDM library shipped with Chrome browser.

## Getting the library

Open `chrome://components/` in Chrome browser, find `Widevine Content Decryption Module`
and make sure it is up to date, then you can find the library files from the
application directory.

### On Windows

The library file `widevinecdm.dll` will be under
`Program Files(x86)/Google/Chrome/Application/CHROME_VERSION/WidevineCdm/_platform_specific/win_(x86|x64)/`
directory.

### On MacOS

The library file `libwidevinecdm.dylib` will be under
`/Applications/Google Chrome.app/Contents/Versions/CHROME_VERSION/Google Chrome Framework.framework/Versions/A/Libraries/WidevineCdm/_platform_specific/mac_(x86|x64)/`
directory.

**Note:** Make sure that chrome version used by Electron is greater than or
equal to the `min_chrome_version` value of Chrome's widevine cdm component.
The value can be found in `manifest.json` under `WidevineCdm` directory.

## Using the library

After getting the library files, you should pass the path to the file
with `--widevine-cdm-path` command line switch, and the library's version
with `--widevine-cdm-version` switch. The command line switches have to be
passed before the `ready` event of `app` module gets emitted.

Example code:

```javascript
const {app, BrowserWindow} = require('electron')

// You have to pass the directory that contains widevine library here, it is
// * `libwidevinecdm.dylib` on macOS,
// * `widevinecdm.dll` on Windows.
app.commandLine.appendSwitch('widevine-cdm-path', '/path/to/widevine_library')
// The version of plugin can be got from `chrome://plugins` page in Chrome.
app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866')

let win = null
app.on('ready', () => {
win = new BrowserWindow()
win.show()
})
```

## Verifying Widevine CDM support

To verify whether widevine works, you can use following ways:

* Open https://shaka-player-demo.appspot.com/ and load a manifest that uses
`Widevine`.
* Open http://www.dash-player.com/demo/drm-test-area/, check whether the page
says `bitdash uses Widevine in your browser`, then play the video.
85 changes: 0 additions & 85 deletions docs/tutorial/using-widevine-cdm-plugin.md

This file was deleted.

0 comments on commit beae267

Please sign in to comment.