Skip to content

Commit

Permalink
Updated widevine permission bubble
Browse files Browse the repository at this point in the history
fix brave/brave-browser#9907

Permission bubble for widevine has custom footnote style.
  • Loading branch information
simonhong committed Jan 13, 2022
1 parent b1eb0dd commit 6741457
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 41 deletions.
24 changes: 18 additions & 6 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@
<message name="IDS_SETTINGS_IMPORT_PAYMENTS_CHECKBOX" desc="Checkbox for importing payments info">
Payment methods
</message>
<!-- Widevine -->
<message name="IDS_WIDEVINE_PERMISSION_REQUEST_TEXT_FRAGMENT" desc="Text fragment for Widevine permission request. 'Widevine' is the name of a plugin and should not be translated.">
Install and run Widevine
Install and run Google Widevine
</message>
<message name="IDS_WIDEVINE_DONT_ASK_AGAIN_CHECKBOX" desc="Checkbox for prevent showing widevine install prompt">
Don't ask again
Expand All @@ -237,16 +238,27 @@
</message>
<if expr="is_linux">
<message name="IDS_WIDEVINE_PERMISSION_REQUEST_TEXT_FRAGMENT_INSTALL" desc="Text fragment for Widevine permission request. 'Widevine' is the name of a plugin and should not be translated.">
Install Widevine
Install Google Widevine
</message>
<message name="IDS_WIDEVINE_PERMISSION_REQUEST_TEXT_FRAGMENT_RESTART_BROWSER" desc="Text fragment for Widevine permission request. 'Widevine' is the name of a plugin and should not be translated.">
Restart browser to enable Widevine
Restart browser to enable Google Widevine
</message>
</if>
<message name="IDS_WIDEVINE_INSTALL_MESSAGE" desc="Bubble info text when Widevine is not installed. 'Widevine' is the name of a plugin and should not be translated.">
Google Widevine is a piece of Digital Rights Management (DRM) code that we at Brave Software do not own and cannot inspect. The Google Widevine code is loaded from Google servers, not from our servers. It is loaded only when you enable this option. We discourage the use of DRM, but we respect user choice and acknowledge that some Brave users would like to use services that require it.

By installing this extension, you are agreeing to the Google Widevine Terms of Use. You agree that Brave is not responsible for any damages or losses in connection with your use of Google Widevine.
Widevine is sometimes needed to play media on a webpage. It's a Google extension loaded from Google servers, which Brave cannot inspect. By installing, you'll agree to Google's terms of use.
</message>
<message name="IDS_WIDEVINE_PERMISSIONS_BUBBLE_FOOTNOTE_TEXT" desc="Message shown on the bottom of the widevine permissions bubble.">
<ph name="LEARN_MORE_ABOUT_WIDEVINE">$1<ex>Learn more about Widevine</ex></ph>.
Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/extensions</ex></ph>.
</message>
<message name="IDS_WIDEVINE_PERMISSIONS_BUBBLE_LEARN_MORE" desc="Message shown on the bottom of the widevine permissions bubble.">
Learn more about Widevine
</message>
<message name="IDS_PERMISSIONS_BUBBLE_SETTINGS_EXTENSIONS_LINK" desc="Settings extenions link in the widevine permission bubble footnote description.">
brave://settings/extensions
</message>
<message name="IDS_BRAVE_PERMISSIONS_BUBBLE_PROMPT" desc="The label that is used to introduce permission request details to the user in a popup.">
<ph name="SITE_NAME">$1<ex>google.com</ex></ph> is asking you to
</message>
<!-- Autoplay -->
<message name="IDS_SETTINGS_SITE_SETTINGS_AUTOPLAY" desc="Label for autoplay site settings.">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include "base/feature_list.h"
#include "brave/common/url_constants.h"
#include "brave/components/permissions/permission_lifetime_utils.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/grit/brave_components_strings.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_prompt.h"
Expand All @@ -25,7 +27,7 @@

#if BUILDFLAG(ENABLE_WIDEVINE)
#include "brave/browser/widevine/widevine_permission_request.h"
#include "brave/grit/brave_generated_resources.h"
#include "brave/common/webui_url_constants.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "components/permissions/request_type.h"
#include "ui/base/l10n/l10n_util.h"
Expand All @@ -37,6 +39,48 @@

namespace {

std::unique_ptr<views::StyledLabel> CreateStyledLabelForFootnote(
Browser* browser,
const std::u16string& footnote,
const std::vector<std::u16string>& replacements,
const std::vector<GURL>& urls) {
// For now, only two links are added to permission bubble footnote.
DCHECK_EQ(2UL, replacements.size());
DCHECK_EQ(replacements.size(), urls.size());

std::vector<size_t> offsets;
std::u16string footnote_text =
base::ReplaceStringPlaceholders(footnote, replacements, &offsets);

auto label = std::make_unique<views::StyledLabel>();
label->SetText(footnote_text);
label->SetDefaultTextStyle(views::style::STYLE_SECONDARY);

auto add_link = [&](size_t idx, GURL url) {
DCHECK(idx < offsets.size());
DCHECK(idx < replacements.size());

gfx::Range link_range(offsets[idx],
offsets[idx] + replacements[idx].length());

views::StyledLabel::RangeStyleInfo link_style =
views::StyledLabel::RangeStyleInfo::CreateForLink(base::BindRepeating(
[](Browser* browser, const GURL& url) {
chrome::AddSelectedTabWithURL(browser, url,
ui::PAGE_TRANSITION_LINK);
},
base::Unretained(browser), std::move(url)));

label->AddStyleRange(link_range, link_style);
};

for (size_t i = 0; i < urls.size(); ++i) {
add_link(i, urls[i]);
}

return label;
}

#if BUILDFLAG(ENABLE_WIDEVINE)
class DontAskAgainCheckbox : public views::Checkbox {
public:
Expand Down Expand Up @@ -95,6 +139,22 @@ void AddAdditionalWidevineViewControlsIfNeeded(
dialog_delegate_view->AddChildView(
new DontAskAgainCheckbox(widevine_request));
}

void AddWidevineFootnoteView(
views::BubbleDialogDelegateView* dialog_delegate_view,
Browser* browser) {
const std::u16string footnote =
l10n_util::GetStringUTF16(IDS_WIDEVINE_PERMISSIONS_BUBBLE_FOOTNOTE_TEXT);
const std::vector<std::u16string> replacements{
l10n_util::GetStringUTF16(IDS_WIDEVINE_PERMISSIONS_BUBBLE_LEARN_MORE),
l10n_util::GetStringUTF16(
IDS_PERMISSIONS_BUBBLE_SETTINGS_EXTENSIONS_LINK)};
const std::vector<GURL> urls{GURL(kWidevineLearnMoreUrl),
GURL(kExtensionSettingsURL)};

dialog_delegate_view->SetFootnoteView(
CreateStyledLabelForFootnote(browser, footnote, replacements, urls));
}
#else
void AddAdditionalWidevineViewControlsIfNeeded(
views::BubbleDialogDelegateView* dialog_delegate_view,
Expand Down Expand Up @@ -173,46 +233,31 @@ views::View* AddPermissionLifetimeComboboxIfNeeded(

void AddFootnoteViewIfNeeded(
views::BubbleDialogDelegateView* dialog_delegate_view,
const std::vector<permissions::PermissionRequest*>& requests,
Browser* browser) {
#if BUILDFLAG(ENABLE_WIDEVINE)
// Widevine permission bubble has custom footnote.
if (HasWidevinePermissionRequest(requests)) {
AddWidevineFootnoteView(dialog_delegate_view, browser);
return;
}
#endif

if (!base::FeatureList::IsEnabled(
permissions::features::kPermissionLifetime)) {
return;
}

std::vector<std::u16string> replacements{
const std::u16string footnote =
l10n_util::GetStringUTF16(IDS_PERMISSIONS_BUBBLE_FOOTNOTE_TEXT);
const std::vector<std::u16string> replacements{
l10n_util::GetStringUTF16(IDS_PERMISSIONS_BUBBLE_SITE_PERMISSION_LINK),
l10n_util::GetStringUTF16(IDS_LEARN_MORE)};
std::vector<size_t> offsets;
std::u16string footnote_text = base::ReplaceStringPlaceholders(
l10n_util::GetStringUTF16(IDS_PERMISSIONS_BUBBLE_FOOTNOTE_TEXT),
replacements, &offsets);

auto label = std::make_unique<views::StyledLabel>();
label->SetText(footnote_text);
label->SetDefaultTextStyle(views::style::STYLE_SECONDARY);

auto add_link = [&](size_t idx, GURL url) {
DCHECK(idx < offsets.size());
DCHECK(idx < replacements.size());

gfx::Range link_range(offsets[idx],
offsets[idx] + replacements[idx].length());

views::StyledLabel::RangeStyleInfo link_style =
views::StyledLabel::RangeStyleInfo::CreateForLink(base::BindRepeating(
[](Browser* browser, const GURL& url) {
chrome::AddSelectedTabWithURL(browser, url,
ui::PAGE_TRANSITION_LINK);
},
base::Unretained(browser), std::move(url)));

label->AddStyleRange(link_range, link_style);
};

add_link(0, GURL(chrome::kChromeUIContentSettingsURL));
add_link(1, GURL(kPermissionPromptLearnMoreUrl));
const std::vector<GURL> urls{GURL(chrome::kChromeUIContentSettingsURL),
GURL(kPermissionPromptLearnMoreUrl)};

dialog_delegate_view->SetFootnoteView(std::move(label));
dialog_delegate_view->SetFootnoteView(
CreateStyledLabelForFootnote(browser, footnote, replacements, urls));
}

} // namespace
Expand All @@ -221,7 +266,7 @@ void AddFootnoteViewIfNeeded(
AddAdditionalWidevineViewControlsIfNeeded(this, delegate_->Requests()); \
auto* permission_lifetime_view = \
AddPermissionLifetimeComboboxIfNeeded(this, delegate_); \
AddFootnoteViewIfNeeded(this, browser_); \
AddFootnoteViewIfNeeded(this, delegate_->Requests(), browser_); \
if (permission_lifetime_view) { \
set_fixed_width( \
std::max(GetPreferredSize().width(), \
Expand All @@ -230,5 +275,9 @@ void AddFootnoteViewIfNeeded(
set_should_ignore_snapping(true); \
}

// undef upstream one first then define it with our one.
#undef IDS_PERMISSIONS_BUBBLE_PROMPT
#define IDS_PERMISSIONS_BUBBLE_PROMPT IDS_BRAVE_PERMISSIONS_BUBBLE_PROMPT
#include "src/chrome/browser/ui/views/permission_bubble/permission_prompt_bubble_view.cc"
#undef BRAVE_PERMISSION_PROMPT_BUBBLE_VIEW
#undef IDS_PERMISSIONS_BUBBLE_PROMPT
4 changes: 3 additions & 1 deletion common/url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const char kMagnetScheme[] = "magnet";
const char kBinanceScheme[] = "com.brave.binance";
const char kGeminiScheme[] = "com.brave.gemini";
const char kFTXScheme[] = "com.brave.ftx";
const char kWidevineMoreInfoURL[] = "https://www.eff.org/issues/drm";
const char kWidevineTOS[] = "https://policies.google.com/terms";
const char kRewardsUpholdSupport[] = "https://uphold.com/en/brave/support";
const char kP3ALearnMoreURL[] = "https://brave.com/P3A";
Expand All @@ -28,3 +27,6 @@ const char kSpeedreaderLearnMoreUrl[] =
const char kWebDiscoveryLearnMoreUrl[] =
"https://brave.com/browser/privacy/#web-discovery-project";
const char kBraveSearchUrl[] = "https://search.brave.com/";
const char kWidevineLearnMoreUrl[] =
"https://support.brave.com/hc/en-us/articles/"
"360023851591-How-do-I-view-DRM-protected-content-";
2 changes: 1 addition & 1 deletion common/url_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ extern const char kMagnetScheme[];
extern const char kBinanceScheme[];
extern const char kGeminiScheme[];
extern const char kFTXScheme[];
extern const char kWidevineMoreInfoURL[];
extern const char kWidevineTOS[];
extern const char kRewardsUpholdSupport[];
extern const char kP3ALearnMoreURL[];
Expand All @@ -24,6 +23,7 @@ extern const char kPermissionPromptLearnMoreUrl[];
extern const char kSpeedreaderLearnMoreUrl[];
extern const char kWebDiscoveryLearnMoreUrl[];
extern const char kBraveSearchUrl[];
extern const char kWidevineLearnMoreUrl[];

// This is introduced to replace |kDownloadChromeUrl| in
// outdated_upgrade_bubble_view.cc"
Expand Down

0 comments on commit 6741457

Please sign in to comment.