diff --git a/app/BUILD.gn b/app/BUILD.gn index 291b6f133f8a..a969497a8090 100644 --- a/app/BUILD.gn +++ b/app/BUILD.gn @@ -85,6 +85,7 @@ source_set("browser_tests") { "//components/network_time", "//components/omnibox/browser", "//components/optimization_guide/core", + "//components/performance_manager", "//components/permissions", "//components/privacy_sandbox", "//components/reading_list/features:flags", diff --git a/app/brave_main_delegate_browsertest.cc b/app/brave_main_delegate_browsertest.cc index fe7f84d59774..e1f271a45d12 100644 --- a/app/brave_main_delegate_browsertest.cc +++ b/app/brave_main_delegate_browsertest.cc @@ -26,6 +26,7 @@ #include "components/omnibox/common/omnibox_features.h" #include "components/optimization_guide/core/optimization_guide_features.h" #include "components/password_manager/core/common/password_manager_features.h" +#include "components/performance_manager/public/features.h" #include "components/permissions/features.h" #include "components/privacy_sandbox/privacy_sandbox_features.h" #include "components/reading_list/features/reading_list_switches.h" @@ -216,6 +217,8 @@ IN_PROC_BROWSER_TEST_F(BraveMainDelegateBrowserTest, EnabledFeatures) { &features::kWinrtGeolocationImplementation, #endif #if !BUILDFLAG(IS_ANDROID) + &performance_manager::features::kBatterySaverModeAvailable, + &performance_manager::features::kHighEfficiencyModeAvailable, &safe_browsing::kDownloadBubble, &safe_browsing::kDownloadBubbleV2, &sharing_hub::kDesktopScreenshots, diff --git a/browser/resources/settings/brave_icons.html b/browser/resources/settings/brave_icons.html index a0b6ee225a47..cb482ca4d852 100644 --- a/browser/resources/settings/brave_icons.html +++ b/browser/resources/settings/brave_icons.html @@ -195,6 +195,15 @@ + + + + + + + + diff --git a/browser/resources/settings/brave_overrides/basic_page.ts b/browser/resources/settings/brave_overrides/basic_page.ts index 39e3209b8155..cdb6bdd07e7a 100644 --- a/browser/resources/settings/brave_overrides/basic_page.ts +++ b/browser/resources/settings/brave_overrides/basic_page.ts @@ -1,7 +1,7 @@ // Copyright (c) 2020 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 https://mozilla.org/MPL/2.0/. +// You can obtain one at https://mozilla.org/MPL/2.0/. // @ts-nocheck TODO(petemill): Define types and remove ts-nocheck @@ -75,20 +75,6 @@ function createNestedSectionElement(sectionName, nestedUnder, titleName, childNa ` } - -/** - * Creates a settings-toggle-button element and returns it. - * @param {string} pref - preference path to handle by toggle - * @param {string} label - label for the element - * @returns {Element} - */ - function createToggleButtonElement (pref, label) { - return html` - - - ` -} - RegisterStyleOverride( 'settings-basic-page', html` @@ -275,6 +261,21 @@ RegisterPolymerTemplateModifications({ prefs: '{{prefs}}' } )) + + // Remove all hidden performance options from basic page. + // We moved performance elements in system settings. + const performanceTemplate = actualTemplate.content.querySelector( + 'template[if="[[showPerformancePage_(pageVisibility.performance)]]"]') + if (performanceTemplate) { + performanceTemplate.remove() + } + + const batteryTemplate = actualTemplate.content.querySelector( + 'template[if="[[showBatteryPage_(pageVisibility.performance)]]"]') + if (batteryTemplate) { + batteryTemplate.remove() + } + // Get Started at top let last = basicPageEl.insertAdjacentElement('afterbegin', sectionGetStarted) @@ -329,10 +330,6 @@ RegisterPolymerTemplateModifications({ // Move help tips after downloads const sectionDownloads = getSectionElement(advancedSubSectionsTemplate.content, 'downloads') sectionDownloads.insertAdjacentElement('afterend', sectionHelpTips) - // Add an element to Chromium's system section - const buttonElement = createToggleButtonElement("prefs.brave.enable_closing_last_tab", "braveHelpTipsClosingLastTab") - const sectionSystem = getSectionElement(advancedSubSectionsTemplate.content, 'system') - sectionSystem.appendChild(buttonElement) } } }) diff --git a/browser/resources/settings/brave_overrides/icons.ts b/browser/resources/settings/brave_overrides/icons.ts index d98a4a401900..bc550df6360b 100644 --- a/browser/resources/settings/brave_overrides/icons.ts +++ b/browser/resources/settings/brave_overrides/icons.ts @@ -15,7 +15,8 @@ OverrideIronIcons('settings', 'brave_settings', { assignment: 'autofill', language: 'language', build: 'system', - restore: 'reset-settings' + restore: 'reset-settings', + performance: 'performance' }) OverrideIronIcons('cr', 'brave_settings', { security: 'privacy-security', diff --git a/browser/resources/settings/brave_overrides/index.ts b/browser/resources/settings/brave_overrides/index.ts index 74795251ca40..0de5e7a37176 100644 --- a/browser/resources/settings/brave_overrides/index.ts +++ b/browser/resources/settings/brave_overrides/index.ts @@ -39,3 +39,4 @@ import './site_details.js' import './site_settings_page.js' import './sync_account_control.js' import './sync_controls.js' +import './system_page.js' diff --git a/browser/resources/settings/brave_overrides/settings_menu.ts b/browser/resources/settings/brave_overrides/settings_menu.ts index 16163bb98fc0..9fe96f395560 100644 --- a/browser/resources/settings/brave_overrides/settings_menu.ts +++ b/browser/resources/settings/brave_overrides/settings_menu.ts @@ -223,6 +223,13 @@ RegisterPolymerTemplateModifications({ } else { menuEl.insertAdjacentElement('afterbegin', titleEl) } + + // Hide performance menu. We moved it under system menu instead. + const performanceEl = getMenuElement(templateContent, '/performance') + if (performanceEl) { + performanceEl.remove() + } + // Add 'Get Started' item const peopleEl = getMenuElement(templateContent, '/people') const getStartedEl = createMenuElement( diff --git a/browser/resources/settings/brave_overrides/system_page.ts b/browser/resources/settings/brave_overrides/system_page.ts new file mode 100644 index 000000000000..df6e0aa55132 --- /dev/null +++ b/browser/resources/settings/brave_overrides/system_page.ts @@ -0,0 +1,24 @@ +// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. + +import {html, RegisterPolymerTemplateModifications} from 'chrome://resources/brave/polymer_overriding.js' +import {loadTimeData} from '../i18n_setup.js' +import '../brave_system_page/brave_performance_page.js' + +RegisterPolymerTemplateModifications({ + 'settings-system-page': (templateContent) => { + templateContent.appendChild( + html` + + + + + + `) + } +}) diff --git a/browser/resources/settings/brave_routes.ts b/browser/resources/settings/brave_routes.ts index 26293a33d7c3..30e5156c6de8 100644 --- a/browser/resources/settings/brave_routes.ts +++ b/browser/resources/settings/brave_routes.ts @@ -81,6 +81,10 @@ export default function addBraveRoutes(r: Partial) { } else if (!isGuest) { console.error('[Brave Settings Overrides] Could not move autofill route to advanced route', r) } + // Deleted performance menu and system menu includes it instead. + if (r.PERFORMANCE) { + delete r.PERFORMANCE + } // Safety check route is moved to advanced. if (r.SAFETY_CHECK && r.ADVANCED) { r.SAFETY_CHECK.parent = r.ADVANCED diff --git a/browser/resources/settings/brave_system_page/brave_performance_page.html b/browser/resources/settings/brave_system_page/brave_performance_page.html new file mode 100644 index 000000000000..2806bf89d880 --- /dev/null +++ b/browser/resources/settings/brave_system_page/brave_performance_page.html @@ -0,0 +1,21 @@ + + + + + diff --git a/browser/resources/settings/brave_system_page/brave_performance_page.ts b/browser/resources/settings/brave_system_page/brave_performance_page.ts new file mode 100644 index 000000000000..54791bdce485 --- /dev/null +++ b/browser/resources/settings/brave_system_page/brave_performance_page.ts @@ -0,0 +1,86 @@ +// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. + +import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js' +import {WebUiListenerMixin, WebUiListenerMixinInterface} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js' +import {BaseMixin} from '../base_mixin.js' +import {PerformanceBrowserProxy, PerformanceBrowserProxyImpl} from '../performance_page/performance_browser_proxy.js' +import {getTemplate} from './brave_performance_page.html.js' +import {pageVisibility} from '../page_visibility.js' +import {loadTimeData} from '../i18n_setup.js' +import '../performance_page/battery_page.js' +import '../performance_page/performance_page.js' + +/** + * 'settings-brave-performance-page' is the settings page containing + * brave's performance features. + */ + +const SettingsBravePerformancePageElementBase = + WebUiListenerMixin(BaseMixin(PolymerElement)) as { + new(): PolymerElement & WebUiListenerMixinInterface + } + +export class SettingsBravePerformancePageElement + extends SettingsBravePerformancePageElementBase { + static get is() { + return 'settings-brave-performance-page' + } + + static get template() { + return getTemplate() + } + + static get properties() { + return { + /** + * Used to hide battery settings section if the device has no battery + */ + showBatterySettings_: { + type: Boolean, + value: false, + }, + } + } + + private showBatterySettings_: boolean; + private performanceBrowserProxy_: PerformanceBrowserProxy = + PerformanceBrowserProxyImpl.getInstance(); + + override connectedCallback() { + super.connectedCallback() + + if (loadTimeData.getBoolean('batterySaverModeAvailable')) { + this.addWebUiListener( + 'device-has-battery-changed', + this.onDeviceHasBatteryChanged_.bind(this)) + this.performanceBrowserProxy_.getDeviceHasBattery().then( + this.onDeviceHasBatteryChanged_.bind(this)) + } + } + + private showPerformancePage_(): boolean { + return pageVisibility?.performance !== false && + loadTimeData.getBoolean('highEfficiencyModeAvailable') + } + + private showBatteryPage_(): boolean { + return pageVisibility?.performance !== false && + loadTimeData.getBoolean('batterySaverModeAvailable') + } + + private onDeviceHasBatteryChanged_(deviceHasBattery: boolean) { + this.showBatterySettings_ = deviceHasBattery + } +} + +declare global { + interface HTMLElementTagNameMap { + 'settings-brave-performance-page': SettingsBravePerformancePageElement + } +} + +customElements.define( + SettingsBravePerformancePageElement.is, SettingsBravePerformancePageElement) diff --git a/browser/resources/settings/sources.gni b/browser/resources/settings/sources.gni index be612ff29b65..04d034c2f039 100644 --- a/browser/resources/settings/sources.gni +++ b/browser/resources/settings/sources.gni @@ -37,6 +37,7 @@ brave_settings_web_component_files = [ "brave_sync_page/brave_sync_page.ts", "brave_sync_page/brave_sync_setup.ts", "brave_sync_page/brave_sync_subpage.ts", + "brave_system_page/brave_performance_page.ts", "brave_tor_page/brave_tor_bridges_dialog.ts", "brave_tor_page/brave_tor_snowflake_install_failed_dialog.ts", "brave_tor_page/brave_tor_subpage.ts", @@ -85,6 +86,7 @@ brave_settings_non_web_component_files = [ "brave_overrides/settings_section.ts", "brave_overrides/settings_ui.ts", "brave_overrides/site_details.ts", + "brave_overrides/system_page.ts", "brave_overrides/add_site_dialog.ts", "brave_overrides/site_settings_page.ts", "brave_overrides/sync_account_control.ts", diff --git a/chromium_src/chrome/common/url_constants.cc b/chromium_src/chrome/common/url_constants.cc index bfd067d9684f..fc78b4eb794f 100644 --- a/chromium_src/chrome/common/url_constants.cc +++ b/chromium_src/chrome/common/url_constants.cc @@ -25,7 +25,8 @@ const char kAutomaticSettingsResetLearnMoreURL[] = const char kAdvancedProtectionDownloadLearnMoreURL[] = "https://support.brave.com/"; -const char kBatterySaverModeLearnMoreUrl[] = "https://support.brave.com/"; +const char kBatterySaverModeLearnMoreUrl[] = + "https://support.brave.com/hc/en-us/articles/13380606172557"; const char kBluetoothAdapterOffHelpURL[] = "https://support.brave.com/"; @@ -139,7 +140,8 @@ const char kLearnMoreReportingURL[] = "https://support.brave.com/hc/en-us/articles/" "360017905872-How-do-I-enable-or-disable-automatic-crash-reporting-"; -const char kHighEfficiencyModeLearnMoreUrl[] = "https://support.brave.com/"; +const char kHighEfficiencyModeLearnMoreUrl[] = + "https://support.brave.com/hc/en-us/articles/13383683902733"; const char kManagedUiLearnMoreUrl[] = "https://support.brave.com/"; diff --git a/chromium_src/chrome/common/webui_url_constants.cc b/chromium_src/chrome/common/webui_url_constants.cc index f75cf2da1199..843de9dbb6dd 100644 --- a/chromium_src/chrome/common/webui_url_constants.cc +++ b/chromium_src/chrome/common/webui_url_constants.cc @@ -1,7 +1,7 @@ -/* Copyright 2021 The Brave Authors. All rights reserved. +/* 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/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "brave/components/constants/webui_url_constants.h" #include "chrome/common/webui_url_constants.h" @@ -10,5 +10,18 @@ kChromeUIAttributionInternalsHost, kAdblockHost, kAdblockInternalsHost, \ kIPFSWebUIHost, kRewardsPageHost, kRewardsInternalsHost, kWelcomeHost, \ kWalletPageHost, kTorInternalsHost +#define kChromeUIPerformanceSettingsURL kChromeUIPerformanceSettingsURL_UnUsed +#define kPerformanceSubPage kPerformanceSubPage_UnUsed + #include "src/chrome/common/webui_url_constants.cc" + +#undef kPerformanceSubPage +#undef kChromeUIPerformanceSettingsURL #undef kChromeUIAttributionInternalsHost + +namespace chrome { + +const char kChromeUIPerformanceSettingsURL[] = "chrome://settings/system"; +const char kPerformanceSubPage[] = "system"; + +} // namespace chrome diff --git a/chromium_src/components/performance_manager/features.cc b/chromium_src/components/performance_manager/features.cc new file mode 100644 index 000000000000..8b2cce7972e5 --- /dev/null +++ b/chromium_src/components/performance_manager/features.cc @@ -0,0 +1,20 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#include "src/components/performance_manager/features.cc" + +#include "base/feature_override.h" +#include "build/build_config.h" + +namespace performance_manager::features { + +#if !BUILDFLAG(IS_ANDROID) +OVERRIDE_FEATURE_DEFAULT_STATES({{ + {kBatterySaverModeAvailable, base::FEATURE_ENABLED_BY_DEFAULT}, + {kHighEfficiencyModeAvailable, base::FEATURE_ENABLED_BY_DEFAULT}, +}}); +#endif + +} // namespace performance_manager::features diff --git a/test/filters/unit_tests.filter b/test/filters/unit_tests.filter index a12a1fea0a7c..e771bd94d960 100644 --- a/test/filters/unit_tests.filter +++ b/test/filters/unit_tests.filter @@ -188,6 +188,19 @@ # groups -All/TabGroupViewsTest.UnderlineBoundsWhenTabsAreNotVisible/1 +# These tests are disabled because of turning the performance features on. +# Re-enable when performance features are enabled by default from upstream. +# performance_manager::features::kBatterySaverModeAvailable, +# performance_manager::features::kHighEfficiencyModeAvailable +-AppMenuModelTest.DisabledPerformanceItem +-CLSUkmPageLoadMetricsObserverTest.BeforeInputOrScroll* +-HighEfficiencyModeTest.* +-OfflinePreviewsUKMPageLoadMetricsObserverTest.OfflinePreviewReported +-PageDiscardingHelperTest.* +-UkmPageLoadMetricsObserverWithMockTimeTest.LargestContentfulPaintRecordOnHidden +-UrgentPageDiscardingPolicyTest.DiscardOnCriticalPressure +-UrgentPageDiscardingPolicyTest.NoDiscardOnModeratePressure + # Tests below this point have not been diagnosed or had issues created yet. -AboutFlagsHistogramTest.* -AboutFlagsTest.* diff --git a/vector_icons/chrome/app/vector_icons/battery_saver.icon b/vector_icons/chrome/app/vector_icons/battery_saver.icon new file mode 100644 index 000000000000..5c1000721f5e --- /dev/null +++ b/vector_icons/chrome/app/vector_icons/battery_saver.icon @@ -0,0 +1,39 @@ +// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. + +CANVAS_DIMENSIONS, 25, +MOVE_TO, 20.58f, 3.92f, +R_ARC_TO, 0.19f, 0.19f, 0, 0, 0, -0.19f, -0.18f, +CUBIC_TO, 11.83f, 3.72f, 7.68f, 5.82f, 5.85f, 8.52f, +R_CUBIC_TO, -1.85f, 2.73f, -1.56f, 6.39f, -0.46f, 10.06f, +R_CUBIC_TO, 0.01f, 0.04f, 0.06f, 0.1f, 0.12f, 0.11f, +R_CUBIC_TO, 3.63f, 1.03f, 6.31f, 0.98f, 8.3f, 0.32f, +R_CUBIC_TO, 1.98f, -0.66f, 3.37f, -1.96f, 4.36f, -3.61f, +R_CUBIC_TO, 2.01f, -3.37f, 2.32f, -8.1f, 2.4f, -11.47f, +CLOSE, +R_MOVE_TO, -0.19f, -1.78f, +R_ARC_TO, 1.79f, 1.79f, 0, 0, 1, 1.79f, 1.83f, +R_CUBIC_TO, -0.08f, 3.33f, -0.37f, 8.48f, -2.63f, 12.25f, +R_CUBIC_TO, -1.15f, 1.92f, -2.81f, 3.51f, -5.22f, 4.31f, +R_CUBIC_TO, -2.37f, 0.79f, -5.35f, 0.79f, -9.12f, -0.26f, +R_LINE_TO, -1.42f, 1.42f, +R_ARC_TO, 0.85f, 0.85f, 0, 1, 1, -1.2f, -1.2f, +R_LINE_TO, 1.32f, -1.32f, +R_ARC_TO, 1.72f, 1.72f, 0, 0, 1, -0.04f, -0.12f, +R_CUBIC_TO, -1.14f, -3.78f, -1.61f, -8.06f, 0.66f, -11.42f, +R_CUBIC_TO, 2.29f, -3.38f, 7.14f, -5.5f, 15.87f, -5.48f, +CLOSE, +R_MOVE_TO, -6.52f, 5.67f, +R_ARC_TO, 0.8f, 0.8f, 0, 0, 0, -1.28f, -0.96f, +R_LINE_TO, -3.41f, 4.59f, +R_ARC_TO, 0.8f, 0.8f, 0, 0, 0, 0.64f, 1.28f, +R_H_LINE_TO, 2.66f, +LINE_TO, 11.17f, 16.06f, +R_ARC_TO, 0.8f, 0.8f, 0, 1, 0, 1.36f, 0.85f, +R_LINE_TO, 2.86f, -4.57f, +R_ARC_TO, 0.8f, 0.8f, 0, 0, 0, -0.68f, -1.23f, +R_H_LINE_TO, -2.74f, +R_LINE_TO, 1.9f, -3.31f, +CLOSE