-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support widevine in linux by bundling #1475
Changes from 10 commits
728a048
06c6b61
cd87646
932f4aa
a2c2278
87d1b6f
72afe60
f93c3aa
9a814a0
81ca1a1
064a84b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
|
@@ -7,30 +8,35 @@ | |
#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 | ||
|
||
void BraveGenerateContentSettingImageModels( | ||
std::vector<std::unique_ptr<ContentSettingImageModel>>& result) { | ||
std::vector<std::unique_ptr<ContentSettingImageModel>>* result) { | ||
// lint complains to use pointer or const referencc for |result|. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, totally agree about that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. basically, this rule is fixed in CC, so we don't even need to have comments like this in the codebase :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. using like this is natural in chromium project :) Removed. |
||
// So, changed to pointer because it is modified in this function. | ||
// Assigned to ref again to make it clear. | ||
// Otherwise, we need to use (*result)[i] for deferencing its element. | ||
std::vector<std::unique_ptr<ContentSettingImageModel>>& result_ref = *result; | ||
// Remove the cookies content setting image model | ||
// https://github.com/brave/brave-browser/issues/1197 | ||
// TODO(iefremov): This changes break internal image models ordering which is | ||
// based on enum values. This breaks tests and probably should be fixed | ||
// (by adding more diff of course). | ||
for (size_t i = 0; i < result.size(); i++) { | ||
if (result[i]->image_type() == | ||
for (size_t i = 0; i < result_ref.size(); i++) { | ||
if (result_ref[i]->image_type() == | ||
ContentSettingImageModel::ImageType::COOKIES) { | ||
result.erase(result.begin() + i); | ||
result_ref.erase(result_ref.begin() + i); | ||
break; | ||
} | ||
} | ||
|
||
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) | ||
result.push_back(std::make_unique<BraveWidevineBlockedImageModel>( | ||
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) || BUILDFLAG(BUNDLE_WIDEVINE_CDM) | ||
result_ref.push_back(std::make_unique<BraveWidevineBlockedImageModel>( | ||
BraveWidevineBlockedImageModel::ImageType::PLUGINS, | ||
CONTENT_SETTINGS_TYPE_PLUGINS)); | ||
#endif | ||
|
||
result.push_back(std::make_unique<BraveAutoplayBlockedImageModel>()); | ||
result_ref.push_back(std::make_unique<BraveAutoplayBlockedImageModel>()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_CONTENT_SETTING_IMAGE_MODELS_H_ | ||
#define BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_CONTENT_SETTING_IMAGE_MODELS_H_ | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
class ContentSettingImageModel; | ||
|
||
void BraveGenerateContentSettingImageModels( | ||
std::vector<std::unique_ptr<ContentSettingImageModel>>&); | ||
std::vector<std::unique_ptr<ContentSettingImageModel>>* result); | ||
|
||
#endif // BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_CONTENT_SETTING_IMAGE_MODELS_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/content_settings/brave_widevine_bundle_util.h" | ||
|
||
#include "brave/common/pref_names.h" | ||
#include "chrome/browser/profiles/profile_manager.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "content/browser/media/cdm_registry_impl.h" | ||
#include "content/public/browser/browser_thread.h" | ||
|
||
void MaybeRegisterWidevineCdm() { | ||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||
|
||
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | ||
// Only registers widevine cdm when user explicitly requested. | ||
if (!prefs->GetBoolean(kWidevineOptedIn)) | ||
return; | ||
|
||
auto* cdm_registry = content::CdmRegistryImpl::GetInstance(); | ||
cdm_registry->RegisterCdm(cdm_registry->cached_widevine_cdm_info()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_WIDEVINE_BUNDLE_UTIL_H_ | ||
#define BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_WIDEVINE_BUNDLE_UTIL_H_ | ||
|
||
#include "third_party/widevine/cdm/buildflags.h" | ||
|
||
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM) | ||
void MaybeRegisterWidevineCdm(); | ||
#endif | ||
|
||
#endif // BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_WIDEVINE_BUNDLE_UTIL_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "build/build_config.h" // For OS_LINUX | ||
|
||
#if defined(OS_LINUX) | ||
#include "content/browser/media/cdm_registry_impl.h" | ||
|
||
#include <algorithm> | ||
|
||
#define Init Init_ChromiumImpl | ||
#include "../../../../../content/browser/media/cdm_registry_impl.cc" // NOLINT | ||
#undef Init | ||
|
||
namespace content { | ||
|
||
namespace { | ||
// This leaks but would be fine. | ||
CdmInfo* g_widevine_info = nullptr; | ||
} | ||
|
||
void CdmRegistryImpl::Init() { | ||
Init_ChromiumImpl(); | ||
|
||
// On linux, we want to register widevine cdm to CdmRegistry when users opt | ||
// in. Otherwise, widevine is initialized by default w/o user accept. | ||
// So, widevine cdm is erased from |cdms_| and it is registered when users opt | ||
// in. Also, we try to register it during the startup in | ||
// BraveBrowserMainExtraParts::PreMainMessageLoopRun() by checking opted in | ||
// prefs. | ||
cdms_.erase( | ||
std::remove_if(cdms_.begin(), cdms_.end(), [](const CdmInfo& info) { | ||
// It would be better to use |kWidevineKeySystem| constant instead of | ||
// using "com.widevine.alpha". To use constant, it requires adding | ||
// widevine dependency to content module. | ||
// However, using this string directly seems fine because it would not | ||
// be changed and can avoid addtional patching for this. | ||
if (info.supported_key_system == "com.widevine.alpha") { | ||
DCHECK(!g_widevine_info); | ||
// Cache upstream created info to reuse when brave wants to register | ||
// it later. | ||
g_widevine_info = new CdmInfo(info); | ||
return true; | ||
} | ||
return false; | ||
}), | ||
cdms_.end()); | ||
} | ||
|
||
const CdmInfo& CdmRegistryImpl::cached_widevine_cdm_info() const { | ||
DCHECK(g_widevine_info); | ||
return *g_widevine_info; | ||
} | ||
|
||
} // namespace content | ||
|
||
#else // OS_LINUX | ||
// This overridden file is only used on linux. | ||
#include "../../../../../content/browser/media/cdm_registry_impl.cc" // NOLINT | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change announced somewhere? A think, if it was then we should fix all sources at once, otherwise its better to fix the linter. @bbondy could you please clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iefremov it is enforced by the linter. There was a discussion in
#brave-core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bridiver maybe we can fix the whole codebase by a single PR then? I can do one