diff --git a/lib/config.js b/lib/config.js index dd5c8f149824..1983da71e036 100644 --- a/lib/config.js +++ b/lib/config.js @@ -52,7 +52,7 @@ const Config = function () { this.braveReferralsApiKey = getNPMConfig(['brave_referrals_api_key']) || '' this.ignore_compile_failure = false this.enable_hangout_services_extension = true - + this.widevineVersion = getNPMConfig(['widevine', 'version']) } Config.prototype.buildArgs = function () { @@ -73,7 +73,7 @@ Config.prototype.buildArgs = function () { ffmpeg_branding: "Chrome", enable_nacl: false, // branding_path_component: "brave", - enable_widevine: process.platform !== 'linux', + enable_widevine: true, target_cpu: this.targetArch, is_official_build: this.officialBuild, is_debug: this.buildConfig !== 'Release', diff --git a/lib/util.js b/lib/util.js index a1b45a5a6172..788808a9bc11 100644 --- a/lib/util.js +++ b/lib/util.js @@ -4,6 +4,8 @@ const config = require('./config') const fs = require('fs-extra') const crypto = require('crypto') const autoGeneratedBraveToChromiumMapping = Object.assign({}, require('./l10nUtil').autoGeneratedBraveToChromiumMapping) +const admZip = require('adm-zip') +const request = require('sync-request') const runGClient = (args, options = {}) => { if (config.gClientVerbose) args.push('--verbose') @@ -208,6 +210,76 @@ const util = { fs.copySync(srcDir, dstDir) }, + // In linux, WidevineCdm library is bundled instead of installing it by component + // updating during the runtime. In linux, we can't load cdm library during the runtime + // because processes except browser process are forked from zygote process not created from + // brave.exe binary. So, cdm should be loaded(not initialized) into zygote process space + // before zygote enters the sandbox. + // This method places WidevineCdm lib and header file into proper place before building. + prepareWidevineCdmLibIfNeeded: () => { + const widevineDir = path.join(config.srcDir, 'third_party', 'widevine', 'cdm', 'linux', 'x64') + fs.ensureDirSync(widevineDir) + + const widevineConfig = { + widevineDir, + configuredVersion: config.widevineVersion, + versionFilePath: path.join(widevineDir, 'version'), + widevineCdmHeaderFilePath: path.join(widevineDir, 'widevine_cdm_version.h'), + widevineCdmLibFilePath: path.join(widevineDir, 'libwidevinecdm.so') + } + + // If version file isn't existed, do fresh install. + if (!fs.existsSync(widevineConfig.versionFilePath)) { + console.log("No widevine version file.") + util.doPrepareWidevineCdmLib(widevineConfig) + return + } + + // If installed version is different with configured version, do fresh install. + const installedVersion = fs.readFileSync(widevineConfig.versionFilePath, 'utf8') + if (installedVersion !== widevineConfig.configuredVersion) { + console.log("Different widevine version is installed") + util.doPrepareWidevineCdmLib(widevineConfig) + return + } + + // Double check necessary header and lib exists. + if (fs.existsSync(widevineConfig.widevineCdmHeaderFilePath) && + fs.existsSync(widevineConfig.widevineCdmLibFilePath)) + return; + + util.doPrepareWidevineCdmLib(widevineConfig) + }, + + doPrepareWidevineCdmLib: (widevineConfig) => { + console.log('Install widevinecdm library') + + // Create version file. + fs.writeFileSync(widevineConfig.versionFilePath, widevineConfig.configuredVersion) + + // Crate header file. + const headerFileContent = +`#ifndef WIDEVINE_CDM_VERSION_H_ +#define WIDEVINE_CDM_VERSION_H_ +#define WIDEVINE_CDM_VERSION_STRING \"${widevineConfig.configuredVersion}\" +#endif // WIDEVINE_CDM_VERSION_H_`; + fs.writeFileSync(widevineConfig.widevineCdmHeaderFilePath, headerFileContent) + + // Synchronously download widevine pkg and extracts into cdm dir. + const widevineZipFileName = `${widevineConfig.configuredVersion}-linux-x64.zip` + const widevineUrl = `https://redirector.gvt1.com/edgedl/widevine-cdm/${widevineZipFileName}` + const res = request('GET', widevineUrl) + const widevineZipFilePath = path.join(widevineConfig.widevineDir, widevineZipFileName) + fs.writeFileSync(widevineZipFilePath, res.body) + const zip = new admZip(widevineZipFilePath); + zip.extractAllTo(widevineConfig.widevineDir, true) + // During the create_dist, /usr/lib/rpm/elfdeps requires that binaries have an exectuable bit set. + fs.chmodSync(widevineConfig.widevineCdmLibFilePath, 0o755) + + // Delete zip file. + fs.removeSync(widevineZipFilePath) + }, + signApp: (options = config.defaultOptions) => { console.log('signing ...') @@ -218,6 +290,7 @@ const util = { console.log('building ' + config.buildTarget + '...') if (process.platform === 'win32') util.updateOmahaMidlFiles() + if (process.platform === 'linux') util.prepareWidevineCdmLibIfNeeded() let num_compile_failure = 1 if (config.ignore_compile_failure) diff --git a/package.json b/package.json index 2fd5be5b1f08..f92cee0fa8a5 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,9 @@ "url": "https://github.com/brave/brave-core.git" } } + }, + "widevine": { + "version": "4.10.1196.0" } }, "repository": { @@ -252,8 +255,10 @@ }, "homepage": "https://github.com/brave/brave-browser#readme", "dependencies": { + "adm-zip": "^0.4.13", "commander": "^2.9.0", - "fs-extra": "^1.0.0" + "fs-extra": "^1.0.0", + "sync-request": "^6.0.0" }, "devDependencies": { "ip": "^1.1.5"