Skip to content
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

Fix Brave content settings page crash #9997

Merged
merged 3 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/resources/settings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ preprocess_if_expr("preprocess") {
"brave_overrides/settings_menu.js",
"brave_overrides/settings_section.js",
"brave_overrides/settings_ui.js",
"brave_overrides/site_details.js",
"brave_overrides/site_settings_page.js",
"brave_overrides/sync_account_control.js",
"brave_overrides/sync_controls.js",
Expand Down
2 changes: 2 additions & 0 deletions browser/resources/settings/brave_overrides/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import './config.js'
import { ContentSettingsTypes } from '../site_settings/constants.js'
ContentSettingsTypes.AUTOPLAY = 'autoplay',
ContentSettingsTypes.ETHEREUM = 'ethereum'
import './about_page.js'
import './appearance_page.js'
Expand All @@ -33,6 +34,7 @@ import './security_page.js'
import './settings_menu.js'
import './settings_section.js'
import './settings_ui.js'
import './site_details.js'
import './site_settings_page.js'
import './sync_account_control.js'
import './sync_controls.js'
19 changes: 17 additions & 2 deletions browser/resources/settings/brave_overrides/privacy_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,33 @@ RegisterPolymerTemplateModifications({
if (!pages) {
console.error(`[Brave Settings Overrides] Couldn't find privacy_page #pages`)
} else {
pages.insertAdjacentHTML('beforeend', `
<template is="dom-if" route-path="/content/autoplay" no-search>
<settings-subpage page-title="${I18nBehavior.i18n('siteSettingsCategoryAutoplay')}">
<category-default-setting
toggle-off-label="${I18nBehavior.i18n('siteSettingsBlocked')}"
toggle-on-label="${I18nBehavior.i18n('siteSettingsAllowed')}"
category="[[contentSettingsTypesEnum_.AUTOPLAY}}">
</category-default-setting>
<category-setting-exceptions
category="[[contentSettingsTypesEnum_.AUTOPLAY]]"
block-header="${I18nBehavior.i18n('siteSettingsBlock')}">
</category-setting-exceptions>
</settings-subpage>
</template>
`)
const isNativeBraveWalletEnabled = loadTimeData.getBoolean('isNativeBraveWalletFeatureEnabled')
if (isNativeBraveWalletEnabled) {
pages.insertAdjacentHTML('beforeend', `
<template is="dom-if" route-path="/content/ethereum" no-search>
<settings-subpage page-title="${I18nBehavior.i18n('siteSettingsCategoryEthereum')}">
<category-default-setting
category="[[ContentSettingsTypes.ETHEREUM]]"
category="[[contentSettingsTypesEnum_.ETHEREUM]]"
toggle-off-label="${I18nBehavior.i18n('siteSettingsEthereumBlock')}"
toggle-on-label="${I18nBehavior.i18n('siteSettingsEthereumAsk')}">
</category-default-setting>
<category-setting-exceptions
category="[[ContentSettingsTypes.ETHEREUM]]"
category="[[contentSettingsTypesEnum_.ETHEREUM]]"
read-only-list
block-header="${I18nBehavior.i18n('siteSettingsBlock')}"
allow-header="${I18nBehavior.i18n('siteSettingsAllow')}">
Expand Down
32 changes: 32 additions & 0 deletions browser/resources/settings/brave_overrides/site_details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2021 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/.

import {RegisterPolymerTemplateModifications} from 'chrome://brave-resources/polymer_overriding.js'
import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js'

RegisterPolymerTemplateModifications({
'site-details': (templateContent) => {
const firstPermissionItem = templateContent.querySelector('div.list-frame > site-details-permission:nth-child(1)')
if (!firstPermissionItem) {
console.error(`[Brave Settings Overrides] Couldn't find first permission item`)
} else {
firstPermissionItem.insertAdjacentHTML('beforebegin', `
<site-details-permission
category="[[contentSettingsTypesEnum_.AUTOPLAY]]"
icon="cr:extension" label="${I18nBehavior.i18n('siteSettingsAutoplay')}">
</site-details-permission>
`)
const isNativeBraveWalletEnabled = loadTimeData.getBoolean('isNativeBraveWalletFeatureEnabled')
if (isNativeBraveWalletEnabled) {
firstPermissionItem.insertAdjacentHTML('beforebegin', `
<site-details-permission
category="[[contentSettingsTypesEnum_.ETHEREUM]]"
icon="cr:extension" label="${I18nBehavior.i18n('siteSettingsEthereum')}">
</site-details-permission>
`)
}
}
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define HasRegisteredGroupName HasRegisteredGroupName_ChromiumImpl
#define ContentSettingsTypeToGroupName \
ContentSettingsTypeToGroupName_ChromiumImpl
#define GetVisiblePermissionCategoriesForOrigin \
GetVisiblePermissionCategoriesForOrigin_ChromiumImpl

// clang-format off
#define BRAVE_CONTENT_SETTINGS_TYPE_GROUP_NAMES_LIST \
Expand All @@ -31,6 +33,7 @@

#undef BRAVE_CONTENT_SETTINGS_TYPE_GROUP_NAMES_LIST
#undef BRAVE_SITE_SETTINGS_HELPER_CONTENT_SETTINGS_TYPE_FROM_GROUP_NAME
#undef GetVisiblePermissionCategoriesForOrigin
#undef ContentSettingsTypeToGroupName
#undef HasRegisteredGroupName

Expand All @@ -52,4 +55,15 @@ base::StringPiece ContentSettingsTypeToGroupName(ContentSettingsType type) {
return ContentSettingsTypeToGroupName_ChromiumImpl(type);
}

std::vector<ContentSettingsType> GetVisiblePermissionCategoriesForOrigin(
Profile* profile,
const GURL& origin) {
std::vector<ContentSettingsType> result =
GetVisiblePermissionCategoriesForOrigin_ChromiumImpl(profile, origin);
result.push_back(ContentSettingsType::AUTOPLAY);
result.push_back(ContentSettingsType::BRAVE_ETHEREUM);

return result;
}

} // namespace site_settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/browser/resources/settings/privacy_page/privacy_page.html b/chrome/browser/resources/settings/privacy_page/privacy_page.html
index 07c8a1c383f4dbd94b89663394a2dbc69491e435..c0d7619d335801021f99de431c06597f58290eb1 100644
index 07c8a1c383f4dbd94b89663394a2dbc69491e435..8e42b4766ef4896fbc09be4752fb760f4ea86925 100644
--- a/chrome/browser/resources/settings/privacy_page/privacy_page.html
+++ b/chrome/browser/resources/settings/privacy_page/privacy_page.html
@@ -29,6 +29,7 @@
Expand Down Expand Up @@ -40,23 +40,3 @@ index 07c8a1c383f4dbd94b89663394a2dbc69491e435..c0d7619d335801021f99de431c06597f
<category-setting-exceptions
category="[[contentSettingsTypesEnum_.JAVASCRIPT]]"
block-header="$i18n{siteSettingsBlock}"
@@ -772,6 +777,19 @@
</settings-subpage>
</template>
</template>
+ <template is="dom-if" route-path="/content/autoplay" no-search>
+ <settings-subpage page-title="$i18n{siteSettingsCategoryAutoplay}">
+ <category-default-setting
+ toggle-off-label="$i18n{siteSettingsBlocked}"
+ toggle-on-label="$i18n{siteSettingsAllowed}"
+ category="{{ContentSettingsTypes.AUTOPLAY}}">
+ </category-default-setting>
+ <category-setting-exceptions
+ category="{{ContentSettingsTypes.AUTOPLAY}}"
+ block-header="$i18n{siteSettingsBlock}">
+ </category-setting-exceptions>
+ </settings-subpage>
+ </template>
<template is="dom-if" route-path="/content/midiDevices" no-search>
<settings-subpage page-title="$i18n{siteSettingsMidiDevices}"
search-label="$i18n{siteSettingsAllSitesSearch}"

This file was deleted.

This file was deleted.