Skip to content

Commit

Permalink
Support widevine in linux
Browse files Browse the repository at this point in the history
Widevine is only enabled when user accepts and browser is restarted
due to the use of zygote process in linux.
BraveWidevineBundleManager manages widevine bundle's install state and
it uses BraveWidevineBundleUnzipper to unzip downloaded zipped bundle.

Install is triggered by user and delayed background update is triggered at
the browser startup. When install is finished w/o error, browser will be
restarted.
  • Loading branch information
simonhong committed Feb 11, 2019
1 parent 7b16f3c commit b3cef89
Show file tree
Hide file tree
Showing 21 changed files with 747 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
<message name="IDS_INSTALL_AND_RUN_WIDEVINE" desc="Button to install and register Widevine with the component updater. 'Widevine' is the name of a plugin and should not be translated.">
Install and run Widevine
</message>
<message name="IDS_INSTALL_AND_RESTART_BROWSER" desc="Button to download widevine restart browser. Then, widevinw is registered. 'Widevine' is the name of a plugin and should not be translated.">
Install and restart browser
</message>
<message name="IDS_NOT_INSTALLED_WIDEVINE_TITLE" desc="Bubble info header text when Widevine is not installed. 'Widevine' is the name of a plugin and should not be translated.">
Widevine is not installed
</message>
Expand Down
17 changes: 16 additions & 1 deletion app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
#include "content/public/common/content_features.h"
#include "extensions/common/extension_features.h"
#include "gpu/config/gpu_finch_features.h"
#include "third_party/widevine/cdm/buildflags.h"
#include "ui/base/ui_base_features.h"

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
#include "brave/common/brave_paths.h"
#endif

#if BUILDFLAG(BRAVE_ADS_ENABLED)
#include "components/dom_distiller/core/dom_distiller_switches.h"
#endif
Expand Down Expand Up @@ -143,5 +148,15 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
enabled_features.str());
command_line.AppendSwitchASCII(switches::kDisableFeatures,
disabled_features.str());
return ChromeMainDelegate::BasicStartupComplete(exit_code);

bool ret = ChromeMainDelegate::BasicStartupComplete(exit_code);

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
// Override chrome::FILE_WIDEVINE_CDM path because we install it in user data
// dir. Must call after ChromeMainDelegate::BasicStartupComplete() to use
// chrome paths.
brave::OverridePath();
#endif

return ret;
}
4 changes: 4 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import("//brave/build/config.gni")
import("//build/config/features.gni")
import("//third_party/widevine/cdm/widevine.gni")

source_set("browser_process") {
sources = [
Expand Down Expand Up @@ -78,8 +79,11 @@ source_set("browser_process") {
"//content/public/browser",
"//brave/chromium_src:browser",
"themes",
"//third_party/widevine/cdm:buildflags",
]

if (bundle_widevine_cdm) { deps += [ "//brave/browser/widevine" ] }

if (is_win && is_official_build) {
sources += [
"//chrome/browser/google/google_update_win.cc",
Expand Down
9 changes: 9 additions & 0 deletions browser/brave_browser_main_extra_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

#include "brave/browser/brave_browser_main_extra_parts.h"

#include "brave/browser/brave_browser_process_impl.h"
#include "chrome/browser/first_run/first_run.h"
#include "third_party/widevine/cdm/buildflags.h"

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
#include "brave/browser/widevine/brave_widevine_bundle_manager.h"
#endif

BraveBrowserMainExtraParts::BraveBrowserMainExtraParts() {
}
Expand All @@ -14,4 +20,7 @@ BraveBrowserMainExtraParts::~BraveBrowserMainExtraParts() {

void BraveBrowserMainExtraParts::PreMainMessageLoopRun() {
brave::AutoImportMuon();
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
g_brave_browser_process->brave_widevine_bundle_manager()->StartupCheck();
#endif
}
13 changes: 13 additions & 0 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "components/component_updater/timer_update_scheduler.h"
#include "content/public/browser/browser_thread.h"

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
#include "brave/browser/widevine/brave_widevine_bundle_manager.h"
#endif

BraveBrowserProcessImpl* g_brave_browser_process = nullptr;

using content::BrowserThread;
Expand Down Expand Up @@ -149,3 +153,12 @@ void BraveBrowserProcessImpl::CreateProfileManager() {
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
profile_manager_ = std::make_unique<BraveProfileManager>(user_data_dir);
}

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
BraveWidevineBundleManager*
BraveBrowserProcessImpl::brave_widevine_bundle_manager() {
if (!brave_widevine_bundle_manager_)
brave_widevine_bundle_manager_.reset(new BraveWidevineBundleManager);
return brave_widevine_bundle_manager_.get();
}
#endif
11 changes: 11 additions & 0 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
#define BRAVE_BROWSER_BRAVE_BROWSER_PROCESS_IMPL_H_

#include "chrome/browser/browser_process_impl.h"
#include "third_party/widevine/cdm/buildflags.h"

namespace brave {
class BraveReferralsService;
class BraveStatsUpdater;
}

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
class BraveWidevineBundleManager;
#endif

namespace brave_shields {
class AdBlockService;
class AdBlockRegionalService;
Expand Down Expand Up @@ -40,6 +45,9 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
brave_shields::HTTPSEverywhereService* https_everywhere_service();
brave_shields::LocalDataFilesService* local_data_files_service();
extensions::BraveTorClientUpdater* tor_client_updater();
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
BraveWidevineBundleManager* brave_widevine_bundle_manager();
#endif

private:
void CreateProfileManager();
Expand All @@ -56,6 +64,9 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
std::unique_ptr<brave::BraveStatsUpdater> brave_stats_updater_;
std::unique_ptr<brave::BraveReferralsService> brave_referrals_service_;
std::unique_ptr<extensions::BraveTorClientUpdater> tor_client_updater_;
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
std::unique_ptr<BraveWidevineBundleManager> brave_widevine_bundle_manager_;
#endif

SEQUENCE_CHECKER(sequence_checker_);

Expand Down
8 changes: 8 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#include "components/signin/core/browser/signin_pref_names.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/sync/base/pref_names.h"
#include "third_party/widevine/cdm/buildflags.h"

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
#include "brave/browser/widevine/brave_widevine_bundle_manager.h"
#endif

namespace brave {

Expand All @@ -32,6 +37,9 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
tor::TorProfileService::RegisterProfilePrefs(registry);

registry->RegisterBooleanPref(kWidevineOptedIn, false);
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
BraveWidevineBundleManager::RegisterProfilePrefs(registry);
#endif

// Default Brave shields
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true);
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ source_set("ui") {
"webui/settings/brave_default_extensions_handler.h",
]

if (enable_widevine_cdm_component) {
if (enable_widevine_cdm_component || bundle_widevine_cdm) {
sources += [
"content_settings/brave_widevine_blocked_image_model.cc",
"content_settings/brave_widevine_blocked_image_model.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "brave/browser/ui/content_settings/brave_autoplay_blocked_image_model.h"
#include "third_party/widevine/cdm/buildflags.h"

#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) || BUILDFLAG(BUNDLE_WIDEVINE_CDM)
#include "brave/browser/ui/content_settings/brave_widevine_blocked_image_model.h"
#endif

Expand All @@ -26,7 +26,7 @@ void BraveGenerateContentSettingImageModels(
}
}

#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) || BUILDFLAG(BUNDLE_WIDEVINE_CDM)
result.push_back(std::make_unique<BraveWidevineBlockedImageModel>(
BraveWidevineBlockedImageModel::ImageType::PLUGINS,
CONTENT_SETTINGS_TYPE_PLUGINS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ IN_PROC_BROWSER_TEST_F(BraveWidevineBlockedImageModelBrowserTest,
ASSERT_FALSE(model->is_visible());
}

#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) || BUILDFLAG(BUNDLE_WIDEVINE_CDM)
class BraveWidevineIconVisibilityBrowserTest : public CertVerifierBrowserTest {
public:
BraveWidevineIconVisibilityBrowserTest()
Expand Down Expand Up @@ -248,4 +248,5 @@ IN_PROC_BROWSER_TEST_F(BraveWidevineIconVisibilityBrowserTest,
EXPECT_TRUE(content::ExecuteScript(active_contents(), widevine_js));
EXPECT_TRUE(IsWidevineIconVisible());
}
#endif // BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#endif // BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) ||
// BUILDFLAG(BUNDLE_WIDEVINE_CDM)
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,43 @@
#include "brave/browser/ui/brave_browser_content_setting_bubble_model_delegate.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/component_updater/widevine_cdm_component_installer.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/plugins/plugin_utils.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
#include "brave/grit/brave_generated_resources.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/prefs/pref_service.h"
#include "third_party/widevine/cdm/buildflags.h"
#include "ui/base/l10n/l10n_util.h"

BraveWidevineContentSettingPluginBubbleModel::BraveWidevineContentSettingPluginBubbleModel(
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
#include <string>

#include "base/bind.h"
#include "brave/browser/widevine/brave_widevine_bundle_manager.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#endif

namespace {
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
void OnWidevineInstallDone(const std::string& error) {
if (!error.empty()) {
LOG(ERROR) << __func__ << ": " << error;
return;
}

DVLOG(1) << __func__ << ": Widevine install completed w/o error";
// TODO(simonhong): This is very aggresive.
// Showing relaunch dialog would be better.
chrome::AttemptRelaunch();
}
#endif
}

BraveWidevineContentSettingPluginBubbleModel::
BraveWidevineContentSettingPluginBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents) :
ContentSettingSimpleBubbleModel(delegate,
Expand Down Expand Up @@ -49,11 +75,23 @@ void BraveWidevineContentSettingPluginBubbleModel::RunPluginsOnPage() {
if (!web_contents())
return;

#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
prefs->SetBoolean(kWidevineOptedIn, true);
RegisterWidevineCdmComponent(g_brave_browser_process->component_updater());
ChromeSubresourceFilterClient::FromWebContents(web_contents())
->OnReloadRequested();
#endif

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
auto* manager = g_brave_browser_process->brave_widevine_bundle_manager();
// User can request install again because |kWidevineOptedIn| is set when
// install is finished. In this case, just waiting previous install request.
if (manager->in_progress())
return;

manager->InstallWidevineBundle(base::BindOnce(&OnWidevineInstallDone), true);
#endif
}

void BraveWidevineContentSettingPluginBubbleModel::SetTitle() {
Expand All @@ -65,7 +103,11 @@ void BraveWidevineContentSettingPluginBubbleModel::SetMessage() {
}

void BraveWidevineContentSettingPluginBubbleModel::SetCustomLink() {
set_custom_link(l10n_util::GetStringUTF16(IDS_INSTALL_AND_RUN_WIDEVINE));
int message_id = IDS_INSTALL_AND_RUN_WIDEVINE;
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
message_id = IDS_INSTALL_AND_RESTART_BROWSER;
#endif
set_custom_link(l10n_util::GetStringUTF16(message_id));
set_custom_link_enabled(true);
}

Expand Down
26 changes: 26 additions & 0 deletions browser/widevine/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import("//third_party/widevine/cdm/widevine.gni")

assert(bundle_widevine_cdm)

source_set("widevine") {
sources = [
"brave_widevine_bundle_manager.cc",
"brave_widevine_bundle_manager.h",
"brave_widevine_bundle_unzipper.cc",
"brave_widevine_bundle_unzipper.h",
]

deps = [
"//base",
"//components/prefs",
"//components/pref_registry",
"//components/services/unzip/public/cpp",
"//content/public/browser",
"//content/public/common",
"//services/network/public/cpp",
"//services/service_manager/public/cpp",
"//third_party/widevine/cdm:buildflags",
"//third_party/widevine/cdm:headers",
"//url",
]
}
Loading

0 comments on commit b3cef89

Please sign in to comment.