diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index 57e330b80725..3c05b9be51c1 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -166,6 +166,12 @@ Install Crypto Wallets + + Don't ask again + + + Ask when a site wants to install Widevine on your computer. + Install Widevine diff --git a/browser/brave_drm_tab_helper.cc b/browser/brave_drm_tab_helper.cc index 5287efbb4593..ed6c727b6bb4 100644 --- a/browser/brave_drm_tab_helper.cc +++ b/browser/brave_drm_tab_helper.cc @@ -22,8 +22,10 @@ BraveDrmTabHelper::~BraveDrmTabHelper() {} bool BraveDrmTabHelper::ShouldShowWidevineOptIn() const { // If the user already opted in, don't offer it. - PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); - if (prefs->GetBoolean(kWidevineOptedIn)) { + PrefService* prefs = + static_cast(web_contents()->GetBrowserContext())->GetPrefs(); + if (prefs->GetBoolean(kWidevineOptedIn) || + !prefs->GetBoolean(kAskWidevineInstall)) { return false; } diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 6e5ecac3df1a..24849fafb9fd 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -57,6 +57,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { #endif registry->RegisterBooleanPref(kWidevineOptedIn, false); + registry->RegisterBooleanPref(kAskWidevineInstall, true); #if BUILDFLAG(BUNDLE_WIDEVINE_CDM) BraveWidevineBundleManager::RegisterProfilePrefs(registry); #endif diff --git a/browser/extensions/api/settings_private/brave_prefs_util.cc b/browser/extensions/api/settings_private/brave_prefs_util.cc index 02cfb070f2c8..aac999bcc88e 100644 --- a/browser/extensions/api/settings_private/brave_prefs_util.cc +++ b/browser/extensions/api/settings_private/brave_prefs_util.cc @@ -57,6 +57,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() { settings_api::PrefType::PREF_TYPE_BOOLEAN; (*s_brave_whitelist)[kBraveThemeType] = settings_api::PrefType::PREF_TYPE_NUMBER; + (*s_brave_whitelist)[kAskWidevineInstall] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; // Clear browsing data on exit prefs. (*s_brave_whitelist)[browsing_data::prefs::kDeleteBrowsingHistoryOnExit] = settings_api::PrefType::PREF_TYPE_BOOLEAN; diff --git a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html index ed6860dc26d0..9f31e33c8c4b 100644 --- a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html +++ b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html @@ -82,6 +82,11 @@ sub-label="$i18n{ipfsCompanionEnabledDesc}" on-settings-boolean-control-change="onIPFSCompanionEnabledChange_"> + + OnWidevineKeySystemAccessRequest(); content::RunAllTasksUntilIdle(); EXPECT_TRUE(observer.bubble_added_); + + // Check permission bubble is not visible when user turns it off. + observer.bubble_added_ = false; + DontAskWidevineInstall(GetActiveWebContents(), true); + EXPECT_TRUE(content::NavigateToURL(GetActiveWebContents(), + GURL("chrome://newtab/"))); + drm_tab_helper->OnWidevineKeySystemAccessRequest(); + content::RunAllTasksUntilIdle(); + EXPECT_FALSE(observer.bubble_added_); + + // Check permission bubble is visible when user turns it on. + observer.bubble_added_ = false; + DontAskWidevineInstall(GetActiveWebContents(), false); + EXPECT_TRUE(content::NavigateToURL(GetActiveWebContents(), + GURL("chrome://newtab/"))); + drm_tab_helper->OnWidevineKeySystemAccessRequest(); + content::RunAllTasksUntilIdle(); + EXPECT_TRUE(observer.bubble_added_); } // Check extra text is added. @@ -122,8 +140,9 @@ IN_PROC_BROWSER_TEST_F(WidevinePermissionRequestBrowserTest, BubbleTest) { DCHECK(delegate_view); // Original PermissionsBubbleDialogDelegateView has one child. // It's label that includes icon and fragment test. - // For widevine permission requests, one more label is added. - EXPECT_EQ(2ull, delegate_view->children().size()); + // For widevine permission requests, two more child views are added. + // one for extra label and the other one is do not ask checkbox. + EXPECT_EQ(3ul, delegate_view->children().size()); } // OptedInPref of bundling tests are done by diff --git a/browser/widevine/widevine_utils.cc b/browser/widevine/widevine_utils.cc index ca1e5f0b4d31..4683d176357e 100644 --- a/browser/widevine/widevine_utils.cc +++ b/browser/widevine/widevine_utils.cc @@ -7,9 +7,12 @@ #include "brave/browser/brave_browser_process_impl.h" #include "brave/browser/widevine/widevine_permission_request.h" +#include "brave/common/pref_names.h" #include "brave/grit/brave_generated_resources.h" #include "chrome/browser/permissions/permission_request_manager.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" +#include "components/prefs/pref_service.h" #if BUILDFLAG(BUNDLE_WIDEVINE_CDM) #include @@ -24,10 +27,8 @@ #endif #if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) -#include "brave/common/pref_names.h" #include "chrome/browser/component_updater/widevine_cdm_component_installer.h" #include "chrome/browser/profiles/profile_manager.h" -#include "components/prefs/pref_service.h" #endif #if BUILDFLAG(BUNDLE_WIDEVINE_CDM) @@ -88,7 +89,8 @@ void RequestWidevinePermission(content::WebContents* web_contents) { void EnableWidevineCdmComponent(content::WebContents* web_contents) { DCHECK(web_contents); - PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); + PrefService* prefs = + static_cast(web_contents->GetBrowserContext())->GetPrefs(); if (prefs->GetBoolean(kWidevineOptedIn)) return; @@ -120,3 +122,8 @@ void InstallBundleOrRestartBrowser() { } } #endif + +void DontAskWidevineInstall(content::WebContents* web_contents, bool dont_ask) { + Profile* profile = static_cast(web_contents->GetBrowserContext()); + profile->GetPrefs()->SetBoolean(kAskWidevineInstall, !dont_ask); +} diff --git a/browser/widevine/widevine_utils.h b/browser/widevine/widevine_utils.h index 6df663ba006c..dfef84e25eb7 100644 --- a/browser/widevine/widevine_utils.h +++ b/browser/widevine/widevine_utils.h @@ -23,4 +23,6 @@ void InstallBundleOrRestartBrowser(); void EnableWidevineCdmComponent(content::WebContents* web_contents); #endif +void DontAskWidevineInstall(content::WebContents* web_contents, bool dont_ask); + #endif // BRAVE_BROWSER_WIDEVINE_WIDEVINE_UTILS_H_ diff --git a/chromium_src/chrome/browser/ui/views/permission_bubble/permission_prompt_impl.cc b/chromium_src/chrome/browser/ui/views/permission_bubble/permission_prompt_impl.cc index 49b758d725a7..f9e48ebeda28 100644 --- a/chromium_src/chrome/browser/ui/views/permission_bubble/permission_prompt_impl.cc +++ b/chromium_src/chrome/browser/ui/views/permission_bubble/permission_prompt_impl.cc @@ -6,15 +6,43 @@ #include #include "brave/browser/widevine/widevine_permission_request.h" +#include "brave/grit/brave_generated_resources.h" #include "chrome/browser/permissions/permission_request.h" #include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/chrome_typography.h" #include "ui/gfx/text_constants.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/label.h" #include "ui/views/window/dialog_delegate.h" namespace { +class DontAskAgainCheckbox : public views::Checkbox, + public views::ButtonListener { + public: + explicit DontAskAgainCheckbox(WidevinePermissionRequest* request); + + private: + // views::ButtonListener overrides: + void ButtonPressed(Button* sender, const ui::Event& event) override; + + WidevinePermissionRequest* request_; + + DISALLOW_COPY_AND_ASSIGN(DontAskAgainCheckbox); +}; + +DontAskAgainCheckbox::DontAskAgainCheckbox(WidevinePermissionRequest* request) + : Checkbox(l10n_util::GetStringUTF16(IDS_WIDEVINE_DONT_ASK_AGAIN_CHECKBOX), + this), + request_(request) { +} + +void DontAskAgainCheckbox::ButtonPressed(Button* sender, + const ui::Event& event) { + request_->set_dont_ask_widevine_install(GetChecked()); +} + bool HasWidevinePermissionRequest( const std::vector& requests) { // When widevine permission is requested, |requests| only includes Widevine @@ -27,7 +55,7 @@ bool HasWidevinePermissionRequest( return false; } -void AddWidevineExplanatoryMessageTextIfNeeded( +void AddAdditionalWidevineViewControlsIfNeeded( views::DialogDelegateView* dialog_delegate, const std::vector& requests) { if (!HasWidevinePermissionRequest(requests)) @@ -47,6 +75,7 @@ void AddWidevineExplanatoryMessageTextIfNeeded( // Resize width. Then, it's height deduced. text->SizeToFit(preferred_dialog_width - dialog_delegate->margins().width()); dialog_delegate->AddChildView(text); + dialog_delegate->AddChildView(new DontAskAgainCheckbox(widevine_request)); } } // namespace diff --git a/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc b/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc index fa7c11eb4c64..bd5f536c0e95 100644 --- a/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc +++ b/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc @@ -46,6 +46,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source, IDS_SETTINGS_BRAVE_GET_STARTED_TITLE}, {"braveAdditionalSettingsTitle", IDS_SETTINGS_BRAVE_ADDITIONAL_SETTINGS}, + {"appearanceSettingsAskWidevineInstallDesc", + IDS_SETTINGS_ASK_WIDEVINE_INSTALL_DESC}, {"appearanceSettingsBraveTheme", IDS_SETTINGS_APPEARANCE_SETTINGS_BRAVE_THEMES}, {"appearanceSettingsLocationBarIsWide", diff --git a/common/pref_names.cc b/common/pref_names.cc index 027de1c2ea50..608a4634b476 100644 --- a/common/pref_names.cc +++ b/common/pref_names.cc @@ -23,6 +23,7 @@ const char kAdBlockCustomFilters[] = "brave.ad_block.custom_filters"; const char kAdBlockRegionalFilters[] = "brave.ad_block.regional_filters"; const char kWidevineOptedIn[] = "brave.widevine_opted_in"; const char kWidevineInstalledVersion[] = "brave.widevine_installed_version"; +const char kAskWidevineInstall[] = "brave.ask_widevine_install"; const char kUseAlternativeSearchEngineProvider[] = "brave.use_alternate_private_search_engine"; const char kAlternativeSearchEngineProviderInTor[] = diff --git a/common/pref_names.h b/common/pref_names.h index a0c42b220b71..bd958d5ea83a 100644 --- a/common/pref_names.h +++ b/common/pref_names.h @@ -21,6 +21,7 @@ extern const char kAdBlockCustomFilters[]; extern const char kAdBlockRegionalFilters[]; extern const char kWidevineOptedIn[]; extern const char kWidevineInstalledVersion[]; +extern const char kAskWidevineInstall[]; extern const char kUseAlternativeSearchEngineProvider[]; extern const char kAlternativeSearchEngineProviderInTor[]; extern const char kBraveThemeType[]; diff --git a/patches/chrome-browser-ui-views-permission_bubble-permission_prompt_impl.cc.patch b/patches/chrome-browser-ui-views-permission_bubble-permission_prompt_impl.cc.patch index 049137d71c37..1452f09576be 100644 --- a/patches/chrome-browser-ui-views-permission_bubble-permission_prompt_impl.cc.patch +++ b/patches/chrome-browser-ui-views-permission_bubble-permission_prompt_impl.cc.patch @@ -1,15 +1,12 @@ diff --git a/chrome/browser/ui/views/permission_bubble/permission_prompt_impl.cc b/chrome/browser/ui/views/permission_bubble/permission_prompt_impl.cc -index 489db17efe96db01666c57e01f6be0c2d37be873..8564f7450243c3a3e12aa96c338d71e4c072e4b3 100644 +index 489db17efe96db01666c57e01f6be0c2d37be873..84d5a95b37b2219a4abbb3c28554be0168b12562 100644 --- a/chrome/browser/ui/views/permission_bubble/permission_prompt_impl.cc +++ b/chrome/browser/ui/views/permission_bubble/permission_prompt_impl.cc -@@ -148,6 +148,10 @@ PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView( +@@ -148,6 +148,7 @@ PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView( AddChildView(label_container); } -+#if defined(BRAVE_CHROMIUM_BUILD) -+ AddWidevineExplanatoryMessageTextIfNeeded(this, requests); -+#endif -+ ++ AddAdditionalWidevineViewControlsIfNeeded(this, requests); chrome::RecordDialogCreation(chrome::DialogIdentifier::PERMISSIONS); }