diff --git a/browser/extensions/BUILD.gn b/browser/extensions/BUILD.gn index 0c995051da42..7d359e2bef0c 100644 --- a/browser/extensions/BUILD.gn +++ b/browser/extensions/BUILD.gn @@ -12,6 +12,8 @@ source_set("extensions") { "api/brave_sync_api.h", "api/brave_sync_event_router.cc", "api/brave_sync_event_router.h", + "api/brave_theme_api.cc", + "api/brave_theme_api.h", "api/settings_private/brave_prefs_util.cc", "api/settings_private/brave_prefs_util.h", "brave_component_extension.cc", @@ -30,6 +32,8 @@ source_set("extensions") { "brave_extension_provider.h", "brave_extension_service.cc", "brave_extension_service.h", + "brave_theme_event_router.cc", + "brave_theme_event_router.h", "brave_tor_client_updater.cc", "brave_tor_client_updater.h", ] diff --git a/browser/extensions/api/brave_theme_api.cc b/browser/extensions/api/brave_theme_api.cc new file mode 100644 index 000000000000..d7070f3587d7 --- /dev/null +++ b/browser/extensions/api/brave_theme_api.cc @@ -0,0 +1,63 @@ +/* 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/extensions/api/brave_theme_api.h" + +#include + +#include "base/values.h" +#include "brave/browser/themes/brave_theme_service.h" +#include "brave/common/extensions/api/brave_theme.h" +#include "brave/common/pref_names.h" +#include "chrome/browser/profiles/profile.h" +#include "components/prefs/pref_service.h" + +using BTS = BraveThemeService; + +namespace { +void SetBraveThemeTypePref(Profile* profile, + BraveThemeType type) { + profile->GetPrefs()->SetInteger(kBraveThemeType, type); +} + +BraveThemeType GetBraveThemeTypeFromString( + base::StringPiece theme) { + if (theme == "Default") + return BraveThemeType::BRAVE_THEME_TYPE_DEFAULT; + + if (theme == "Light") + return BraveThemeType::BRAVE_THEME_TYPE_LIGHT; + + if (theme == "Dark") + return BraveThemeType::BRAVE_THEME_TYPE_DARK; + + NOTREACHED(); + return BraveThemeType::BRAVE_THEME_TYPE_DEFAULT; +} + +} // namespace + +namespace extensions { +namespace api { + +ExtensionFunction::ResponseAction BraveThemeSetBraveThemeTypeFunction::Run() { + std::unique_ptr params( + brave_theme::SetBraveThemeType::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params.get()); + + Profile* profile = Profile::FromBrowserContext(browser_context()); + SetBraveThemeTypePref(profile, GetBraveThemeTypeFromString(params->type)); + + return RespondNow(NoArguments()); +} + +ExtensionFunction::ResponseAction BraveThemeGetBraveThemeTypeFunction::Run() { + Profile* profile = Profile::FromBrowserContext(browser_context()); + const std::string theme_type = BTS::GetStringFromBraveThemeType( + BTS::GetActiveBraveThemeType(profile)); + return RespondNow(OneArgument(std::make_unique(theme_type))); +} + +} // namespace api +} // namespace extensions diff --git a/browser/extensions/api/brave_theme_api.h b/browser/extensions/api/brave_theme_api.h new file mode 100644 index 000000000000..b948a0bf1226 --- /dev/null +++ b/browser/extensions/api/brave_theme_api.h @@ -0,0 +1,36 @@ +/* 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_EXTENSIONS_API_BRAVE_THEME_API_H_ +#define BRAVE_BROWSER_EXTENSIONS_API_BRAVE_THEME_API_H_ + +#include "extensions/browser/extension_function.h" + +namespace extensions { +namespace api { + +class BraveThemeSetBraveThemeTypeFunction : public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("braveTheme.setBraveThemeType", UNKNOWN) + + protected: + ~BraveThemeSetBraveThemeTypeFunction() override {} + + ResponseAction Run() override; +}; + +class BraveThemeGetBraveThemeTypeFunction : public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("braveTheme.getBraveThemeType", UNKNOWN) + + protected: + ~BraveThemeGetBraveThemeTypeFunction() override {} + + ResponseAction Run() override; +}; + +} // namespace api +} // namespace extensions + +#endif // BRAVE_BROWSER_EXTENSIONS_API_BRAVE_THEME_API_H_ diff --git a/browser/extensions/api/brave_theme_api_browsertest.cc b/browser/extensions/api/brave_theme_api_browsertest.cc new file mode 100644 index 000000000000..b22d09137f96 --- /dev/null +++ b/browser/extensions/api/brave_theme_api_browsertest.cc @@ -0,0 +1,107 @@ +/* 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 "base/values.h" +#include "brave/browser/extensions/api/brave_theme_api.h" +#include "brave/browser/extensions/brave_theme_event_router.h" +#include "brave/browser/themes/brave_theme_service.h" +#include "brave/browser/themes/theme_properties.h" +#include "brave/common/pref_names.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/browser/extensions/extension_function_test_utils.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/themes/theme_properties.h" +#include "chrome/browser/themes/theme_service_factory.h" +#include "chrome/browser/ui/browser.h" +#include "components/prefs/pref_service.h" +#include "extensions/common/extension_builder.h" +#include "testing/gmock/include/gmock/gmock.h" + +using extensions::api::BraveThemeGetBraveThemeTypeFunction; +using extensions::api::BraveThemeSetBraveThemeTypeFunction; +using extension_function_test_utils::RunFunctionAndReturnSingleResult; +using BTS = BraveThemeService; + +class BraveThemeAPIBrowserTest : public InProcessBrowserTest { + public: + void SetUpOnMainThread() override { + InProcessBrowserTest::SetUpOnMainThread(); + extension_ = extensions::ExtensionBuilder("Test").Build(); + } + + scoped_refptr extension() { + return extension_; + } + + private: + scoped_refptr extension_; +}; + +namespace { +class MockBraveThemeEventRouter : public extensions::BraveThemeEventRouter { + public: + MockBraveThemeEventRouter() {} + ~MockBraveThemeEventRouter() override {} + + MOCK_METHOD1(OnBraveThemeTypeChanged, void(Profile*)); +}; + +void SetBraveThemeType(Profile* profile, BraveThemeType type) { + profile->GetPrefs()->SetInteger(kBraveThemeType, type); +} +} // namespace + +IN_PROC_BROWSER_TEST_F(BraveThemeAPIBrowserTest, + BraveThemeGetBraveThemeTypeTest) { + Profile* profile = browser()->profile(); + + // Check default type is set initially. + EXPECT_EQ(BraveThemeType::BRAVE_THEME_TYPE_DEFAULT, + BTS::GetUserPreferredBraveThemeType(profile)); + + // Change to Light type and check it from api. + SetBraveThemeType(profile, BraveThemeType::BRAVE_THEME_TYPE_LIGHT); + EXPECT_EQ(BraveThemeType::BRAVE_THEME_TYPE_LIGHT, + BTS::GetUserPreferredBraveThemeType(profile)); + scoped_refptr get_function( + new BraveThemeGetBraveThemeTypeFunction()); + get_function->set_extension(extension().get()); + std::unique_ptr value; + value.reset(RunFunctionAndReturnSingleResult(get_function.get(), + std::string("[]"), + browser())); + EXPECT_EQ(value->GetString(), "Light"); +} + +IN_PROC_BROWSER_TEST_F(BraveThemeAPIBrowserTest, + BraveThemeSetBraveThemeTypeTest) { + Profile* profile = browser()->profile(); + + // Check default type is set initially. + EXPECT_EQ(BraveThemeType::BRAVE_THEME_TYPE_DEFAULT, + BTS::GetUserPreferredBraveThemeType(profile)); + + // Change theme type to Light via api and check it. + scoped_refptr set_function( + new BraveThemeSetBraveThemeTypeFunction()); + set_function->set_extension(extension().get()); + RunFunctionAndReturnSingleResult(set_function.get(), + std::string("[\"Light\"]"), + browser()); + + EXPECT_EQ(BraveThemeType::BRAVE_THEME_TYPE_LIGHT, + BTS::GetUserPreferredBraveThemeType(profile)); +} + +IN_PROC_BROWSER_TEST_F(BraveThemeAPIBrowserTest, + BraveThemeEventRouterTest) { + Profile* profile = browser()->profile(); + MockBraveThemeEventRouter* mock_router_ = new MockBraveThemeEventRouter; + EXPECT_CALL(*mock_router_, OnBraveThemeTypeChanged(profile)).Times(1); + + BraveThemeService* service = static_cast( + ThemeServiceFactory::GetForProfile(browser()->profile())); + service->SetBraveThemeEventRouterForTesting(mock_router_); + SetBraveThemeType(profile, BraveThemeType::BRAVE_THEME_TYPE_LIGHT); +} diff --git a/browser/extensions/brave_theme_event_router.cc b/browser/extensions/brave_theme_event_router.cc new file mode 100644 index 000000000000..8ae27e7be176 --- /dev/null +++ b/browser/extensions/brave_theme_event_router.cc @@ -0,0 +1,47 @@ +/* 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/extensions/brave_theme_event_router.h" + +#include "brave/browser/themes/brave_theme_service.h" +#include "brave/common/extensions/api/brave_theme.h" +#include "chrome/browser/profiles/profile.h" +#include "extensions/browser/event_router.h" +#include "extensions/browser/extension_event_histogram_value.h" + +using BTS = BraveThemeService; + +namespace extensions { + +class BraveThemeEventRouterImpl : public BraveThemeEventRouter { + public: + BraveThemeEventRouterImpl() {} + ~BraveThemeEventRouterImpl() override {} + + void OnBraveThemeTypeChanged(Profile* profile) override; + + private: + DISALLOW_COPY_AND_ASSIGN(BraveThemeEventRouterImpl); +}; + +void BraveThemeEventRouterImpl::OnBraveThemeTypeChanged(Profile* profile) { + EventRouter* event_router = EventRouter::Get(profile); + const std::string theme_type = BTS::GetStringFromBraveThemeType( + BTS::GetActiveBraveThemeType(profile)); + + auto event = std::make_unique( + extensions::events::BRAVE_ON_BRAVE_THEME_TYPE_CHANGED, + api::brave_theme::OnBraveThemeTypeChanged::kEventName, + api::brave_theme::OnBraveThemeTypeChanged::Create(theme_type), + profile); + + event_router->BroadcastEvent(std::move(event)); +} + +// static +std::unique_ptr BraveThemeEventRouter::Create() { + return std::make_unique(); +} + +} // namespace extensions diff --git a/browser/extensions/brave_theme_event_router.h b/browser/extensions/brave_theme_event_router.h new file mode 100644 index 000000000000..efa8c8cd86f5 --- /dev/null +++ b/browser/extensions/brave_theme_event_router.h @@ -0,0 +1,25 @@ +/* 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_EXTENSIONS_BRAVE_THEME_EVENT_ROUTER_H_ +#define BRAVE_BROWSER_EXTENSIONS_BRAVE_THEME_EVENT_ROUTER_H_ + +#include + +class Profile; + +namespace extensions { + +class BraveThemeEventRouter { + public: + static std::unique_ptr Create(); + + virtual ~BraveThemeEventRouter() {} + + virtual void OnBraveThemeTypeChanged(Profile* profile) = 0; +}; + +} // namespace extensions + +#endif // BRAVE_BROWSER_EXTENSIONS_BRAVE_THEME_EVENT_ROUTER_H_ diff --git a/browser/resources/settings/brave_appearance_page/brave_appearance_browser_proxy.js b/browser/resources/settings/brave_appearance_page/brave_appearance_browser_proxy.js index ba44b5484e16..a99aa422cee4 100644 --- a/browser/resources/settings/brave_appearance_page/brave_appearance_browser_proxy.js +++ b/browser/resources/settings/brave_appearance_page/brave_appearance_browser_proxy.js @@ -21,12 +21,12 @@ cr.define('settings', function() { class BraveAppearanceBrowserProxyImpl { /** @override */ getBraveThemeType() { - return cr.sendWithPromise('getBraveThemeType'); + return new Promise(resolve => chrome.braveTheme.getBraveThemeType(resolve)) } /** @override */ setBraveThemeType(theme) { - chrome.send('setBraveThemeType', [theme]); + chrome.braveTheme.setBraveThemeType(theme); } } diff --git a/browser/resources/settings/brave_appearance_page/brave_appearance_page.js b/browser/resources/settings/brave_appearance_page/brave_appearance_page.js index 62d3dca58475..8467c9221c59 100644 --- a/browser/resources/settings/brave_appearance_page/brave_appearance_page.js +++ b/browser/resources/settings/brave_appearance_page/brave_appearance_page.js @@ -13,7 +13,6 @@ Polymer({ readOnly: true, type: Array, value: [ - 'Default', 'Light', 'Dark', ], @@ -58,4 +57,4 @@ Polymer({ Polymer({ is: 'settings-brave-appearance-toolbar', }); -})(); \ No newline at end of file +})(); diff --git a/browser/themes/brave_theme_service.cc b/browser/themes/brave_theme_service.cc index ecb15a805fa2..720c082894b9 100644 --- a/browser/themes/brave_theme_service.cc +++ b/browser/themes/brave_theme_service.cc @@ -4,13 +4,12 @@ #include "brave/browser/themes/brave_theme_service.h" -#include - -#include "brave/common/brave_switches.h" -#include "brave/browser/themes/theme_properties.h" -#include "brave/common/pref_names.h" #include "base/command_line.h" #include "base/strings/string_util.h" +#include "brave/browser/extensions/brave_theme_event_router.h" +#include "brave/browser/themes/theme_properties.h" +#include "brave/common/brave_switches.h" +#include "brave/common/pref_names.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/common/channel_info.h" @@ -31,11 +30,13 @@ BraveThemeType BraveThemeService::GetUserPreferredBraveThemeType( const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(switches::kUiMode)) { - std::string requested_theme_value = command_line.GetSwitchValueASCII(switches::kUiMode); - std::string requested_theme_value_lower = base::ToLowerASCII(requested_theme_value); + std::string requested_theme_value = + command_line.GetSwitchValueASCII(switches::kUiMode); + std::string requested_theme_value_lower = + base::ToLowerASCII(requested_theme_value); if (requested_theme_value_lower == "light") return BraveThemeType::BRAVE_THEME_TYPE_LIGHT; - if (requested_theme_value_lower == "light") + if (requested_theme_value_lower == "dark") return BraveThemeType::BRAVE_THEME_TYPE_DARK; } // get value from preferences @@ -43,6 +44,21 @@ BraveThemeType BraveThemeService::GetUserPreferredBraveThemeType( profile->GetPrefs()->GetInteger(kBraveThemeType)); } +// static +std::string BraveThemeService::GetStringFromBraveThemeType( + BraveThemeType type) { + switch (type) { + case BraveThemeType::BRAVE_THEME_TYPE_DEFAULT: + return "Default"; + case BraveThemeType::BRAVE_THEME_TYPE_LIGHT: + return "Light"; + case BraveThemeType::BRAVE_THEME_TYPE_DARK: + return "Dark"; + default: + NOTREACHED(); + } +} + // static BraveThemeType BraveThemeService::GetActiveBraveThemeType( Profile* profile) { @@ -81,14 +97,13 @@ void BraveThemeService::Init(Profile* profile) { ThemeService::Init(profile); } - - SkColor BraveThemeService::GetDefaultColor(int id, bool incognito) const { // Brave Tor profiles are always 'incognito' (for now) if (!incognito && profile()->IsTorProfile()) incognito = true; const BraveThemeType theme = GetActiveBraveThemeType(profile()); - const base::Optional braveColor = MaybeGetDefaultColorForBraveUi(id, incognito, theme); + const base::Optional braveColor = + MaybeGetDefaultColorForBraveUi(id, incognito, theme); if (braveColor) return braveColor.value(); // make sure we fallback to chrome's dark theme (incognito) for our dark theme @@ -100,4 +115,15 @@ SkColor BraveThemeService::GetDefaultColor(int id, bool incognito) const { void BraveThemeService::OnPreferenceChanged(const std::string& pref_name) { DCHECK(pref_name == kBraveThemeType); NotifyThemeChanged(); + + if (!brave_theme_event_router_) + brave_theme_event_router_ = extensions::BraveThemeEventRouter::Create(); + + brave_theme_event_router_->OnBraveThemeTypeChanged(profile()); +} + + +void BraveThemeService::SetBraveThemeEventRouterForTesting( + extensions::BraveThemeEventRouter* mock_router) { + brave_theme_event_router_.reset(mock_router); } diff --git a/browser/themes/brave_theme_service.h b/browser/themes/brave_theme_service.h index c90d906d1653..08b4b34bca79 100644 --- a/browser/themes/brave_theme_service.h +++ b/browser/themes/brave_theme_service.h @@ -5,9 +5,16 @@ #ifndef BRAVE_BROWSER_THEMES_BRAVE_THEME_SERVICE_H_ #define BRAVE_BROWSER_THEMES_BRAVE_THEME_SERVICE_H_ +#include +#include + #include "chrome/browser/themes/theme_service.h" #include "components/prefs/pref_member.h" +namespace extensions { +class BraveThemeEventRouter; +} + namespace user_prefs { class PrefRegistrySyncable; } @@ -22,6 +29,7 @@ class BraveThemeService : public ThemeService { public: static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); static BraveThemeType GetUserPreferredBraveThemeType(Profile* profile); + static std::string GetStringFromBraveThemeType(BraveThemeType type); static BraveThemeType GetActiveBraveThemeType(Profile* profile); BraveThemeService(); @@ -35,10 +43,17 @@ class BraveThemeService : public ThemeService { SkColor GetDefaultColor(int id, bool incognito) const override; private: + FRIEND_TEST_ALL_PREFIXES(BraveThemeAPIBrowserTest, BraveThemeEventRouterTest); + // Own |mock_router|. + void SetBraveThemeEventRouterForTesting( + extensions::BraveThemeEventRouter* mock_router); + void OnPreferenceChanged(const std::string& pref_name); IntegerPrefMember brave_theme_type_pref_; + std::unique_ptr brave_theme_event_router_; + DISALLOW_COPY_AND_ASSIGN(BraveThemeService); }; diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 46a99f52827b..d1b008287179 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -71,8 +71,6 @@ source_set("ui") { "webui/brave_webui_source.h", "webui/brave_welcome_ui.cc", "webui/brave_welcome_ui.h", - "webui/settings/brave_appearance_handler.cc", - "webui/settings/brave_appearance_handler.h", "webui/settings/brave_privacy_handler.cc", "webui/settings/brave_privacy_handler.h", "webui/settings/default_brave_shields_handler.cc", diff --git a/browser/ui/webui/brave_md_settings_ui.cc b/browser/ui/webui/brave_md_settings_ui.cc index b7596d63d9fa..7133c9608f53 100644 --- a/browser/ui/webui/brave_md_settings_ui.cc +++ b/browser/ui/webui/brave_md_settings_ui.cc @@ -6,7 +6,6 @@ #include "brave/browser/resources/grit/brave_settings_resources.h" #include "brave/browser/resources/grit/brave_settings_resources_map.h" -#include "brave/browser/ui/webui/settings/brave_appearance_handler.h" #include "brave/browser/ui/webui/settings/brave_privacy_handler.h" #include "brave/browser/ui/webui/settings/default_brave_shields_handler.h" #include "chrome/browser/profiles/profile.h" @@ -17,7 +16,6 @@ BraveMdSettingsUI::BraveMdSettingsUI(content::WebUI* web_ui, const std::string& host) : MdSettingsUI(web_ui) { web_ui->AddMessageHandler(std::make_unique()); - web_ui->AddMessageHandler(std::make_unique()); web_ui->AddMessageHandler(std::make_unique()); web_ui->AddMessageHandler(std::make_unique()); } diff --git a/browser/ui/webui/settings/brave_appearance_handler.cc b/browser/ui/webui/settings/brave_appearance_handler.cc deleted file mode 100644 index 8378c053dc7d..000000000000 --- a/browser/ui/webui/settings/brave_appearance_handler.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* 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/webui/settings/brave_appearance_handler.h" - -#include - -#include "base/bind.h" -#include "base/values.h" -#include "brave/browser/themes/brave_theme_service.h" -#include "brave/common/pref_names.h" -#include "chrome/browser/profiles/profile.h" -#include "components/prefs/pref_service.h" -#include "content/public/browser/web_ui.h" - -namespace { -void SetBraveThemeTypePref(Profile* profile, - BraveThemeType type) { - profile->GetPrefs()->SetInteger(kBraveThemeType, type); -} - -BraveThemeType GetBraveThemeTypeFromString( - base::StringPiece theme) { - if (theme == "Default") - return BraveThemeType::BRAVE_THEME_TYPE_DEFAULT; - - if (theme == "Light") - return BraveThemeType::BRAVE_THEME_TYPE_LIGHT; - - if (theme == "Dark") - return BraveThemeType::BRAVE_THEME_TYPE_DARK; - - NOTREACHED(); - return BraveThemeType::BRAVE_THEME_TYPE_DEFAULT; -} - -std::string GetStringFromBraveThemeType( - BraveThemeType theme) { - switch (theme) { - case BraveThemeType::BRAVE_THEME_TYPE_DEFAULT: - return "Default"; - case BraveThemeType::BRAVE_THEME_TYPE_LIGHT: - return "Light"; - case BraveThemeType::BRAVE_THEME_TYPE_DARK: - return "Dark"; - default: - NOTREACHED(); - } -} -} // namespace - -void BraveAppearanceHandler::RegisterMessages() { - profile_ = Profile::FromWebUI(web_ui()); - - web_ui()->RegisterMessageCallback( - "getBraveThemeType", - base::BindRepeating(&BraveAppearanceHandler::GetBraveThemeType, - base::Unretained(this))); - web_ui()->RegisterMessageCallback( - "setBraveThemeType", - base::BindRepeating(&BraveAppearanceHandler::SetBraveThemeType, - base::Unretained(this))); -} - -void BraveAppearanceHandler::SetBraveThemeType(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); - CHECK(profile_); - - std::string theme; - args->GetString(0, &theme); - SetBraveThemeTypePref(profile_, GetBraveThemeTypeFromString(theme)); -} - -void BraveAppearanceHandler::GetBraveThemeType(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); - CHECK(profile_); - - AllowJavascript(); - ResolveJavascriptCallback( - args->GetList()[0].Clone(), - base::Value(GetStringFromBraveThemeType( - BraveThemeService::GetUserPreferredBraveThemeType(profile_)))); -} diff --git a/browser/ui/webui/settings/brave_appearance_handler.h b/browser/ui/webui/settings/brave_appearance_handler.h deleted file mode 100644 index 56f3c1f94af3..000000000000 --- a/browser/ui/webui/settings/brave_appearance_handler.h +++ /dev/null @@ -1,31 +0,0 @@ -/* 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_WEBUI_SETTINGS_BRAVE_APPEARANCE_HANDLER_H_ -#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_APPEARANCE_HANDLER_H_ - -#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" - -class Profile; - -class BraveAppearanceHandler : public settings::SettingsPageUIHandler { - public: - BraveAppearanceHandler() = default; - ~BraveAppearanceHandler() override = default; - - private: - // SettingsPageUIHandler overrides: - void RegisterMessages() override; - void OnJavascriptAllowed() override {} - void OnJavascriptDisallowed() override {} - - void SetBraveThemeType(const base::ListValue* args); - void GetBraveThemeType(const base::ListValue* args); - - Profile* profile_ = nullptr; - - DISALLOW_COPY_AND_ASSIGN(BraveAppearanceHandler); -}; - -#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_APPEARANCE_HANDLER_H_ diff --git a/common/extensions/api/BUILD.gn b/common/extensions/api/BUILD.gn index 9cc8bfa151d4..5f96a39c12d4 100644 --- a/common/extensions/api/BUILD.gn +++ b/common/extensions/api/BUILD.gn @@ -41,6 +41,7 @@ json_features("behavior_features") { brave_extensions_api_schema_sources = [ "brave_shields.json", "brave_rewards.json", + "brave_theme.json", "rewards_notifications.json", "brave_sync.json", ] diff --git a/common/extensions/api/_api_features.json b/common/extensions/api/_api_features.json index cfda020773bf..1fae9bf431f0 100644 --- a/common/extensions/api/_api_features.json +++ b/common/extensions/api/_api_features.json @@ -1,7 +1,7 @@ // 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/. -// Command to get whitelist ID: echo -n mnojpmjdmbbfmejpflffifhffcmidifd | openssl sha1 +// Command to get whitelist ID: echo -n mnojpmjdmbbfmejpflffifhffcmidifd | openssl sha1 | tr '[:lower:]' '[:upper:]' // Same for sync api: echo -n nomlkjnggnifocmealianaaiobmebgil | openssl sha1 { @@ -88,5 +88,20 @@ "whitelist": [ "46E9817CBF915C0D1F6BCCF916C42CC666FF1D64" ] - } + }, + "braveTheme": [{ + "channel": "stable", + "contexts": ["blessed_extension"], + "whitelist": [ + "A321D47A2B4CA86898167A55CA8B2E02385EA7CD", // braveShields + "46E9817CBF915C0D1F6BCCF916C42CC666FF1D64" // braveRewards + ] + }, { + "channel": "stable", + "contexts": ["webui"], + "matches": [ + "chrome://welcome/*", + "chrome://settings/*" + ] + }] } diff --git a/common/extensions/api/brave_theme.json b/common/extensions/api/brave_theme.json new file mode 100644 index 000000000000..c495003657bd --- /dev/null +++ b/common/extensions/api/brave_theme.json @@ -0,0 +1,65 @@ +// 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/. + +[ + { + "namespace": "braveTheme", + "description": "Use the chrome.braveTheme API to get/set brave theme", + "compiler_options": { + "implemented_in": "brave/browser/extensions/api/brave_theme_api.h" + }, + "events": [ + { + "name": "onBraveThemeTypeChanged", + "type": "function", + "description": "Fired when brave theme is changed", + "parameters": [ + { + "name": "type", + "type": "string", + "description": "new active theme type(ex, Dark or Light)" + } + ] + } + ], + "functions": [ + { + "name": "setBraveThemeType", + "type": "function", + "description": "Set brave theme", + "parameters": [ + { + "name": "type", + "type": "string" + }, + { + "name": "callback", + "type": "function", + "optional": true, + "parameters": [] + } + ] + }, + { + "name": "getBraveThemeType", + "type": "function", + "description": "Get brave theme", + "parameters": [ + { + "name": "callback", + "type": "function", + "description": "Function called when current theme type is fetched", + "parameters": [ + { + "name": "type", + "type": "string", + "description": "current theme type(ex, Dark or Light)" + } + ] + } + ] + } + ] + } +] diff --git a/patches/extensions-browser-extension_event_histogram_value.h.patch b/patches/extensions-browser-extension_event_histogram_value.h.patch index 775578488ff8..4303b30890a0 100644 --- a/patches/extensions-browser-extension_event_histogram_value.h.patch +++ b/patches/extensions-browser-extension_event_histogram_value.h.patch @@ -1,8 +1,8 @@ diff --git a/extensions/browser/extension_event_histogram_value.h b/extensions/browser/extension_event_histogram_value.h -index cd8295f9c966d188fc58f3b37e1b4203c24e297d..f40357ea6b5ccb2fd4a6613234eb5b3017997b48 100644 +index cd8295f9c966d188fc58f3b37e1b4203c24e297d..519fbbed3c03d92906bc0f212ac9ca93fc564d6f 100644 --- a/extensions/browser/extension_event_histogram_value.h +++ b/extensions/browser/extension_event_histogram_value.h -@@ -444,6 +444,17 @@ enum HistogramValue { +@@ -444,6 +444,18 @@ enum HistogramValue { SYSTEM_POWER_SOURCE_ONPOWERCHANGED = 423, WEB_REQUEST_ON_ACTION_IGNORED = 424, ARC_APPS_PRIVATE_ON_INSTALLED = 425, @@ -12,6 +12,7 @@ index cd8295f9c966d188fc58f3b37e1b4203c24e297d..f40357ea6b5ccb2fd4a6613234eb5b30 + BRAVE_ON_WALLET_PROPERTIES, + BRAVE_ON_PUBLISHER_DATA, + BRAVE_ON_CURRENT_REPORT, ++ BRAVE_ON_BRAVE_THEME_TYPE_CHANGED, + BRAVE_REWARDS_NOTIFICATION_ADDED, + BRAVE_REWARDS_NOTIFICATION_DELETED, + BRAVE_REWARDS_ALL_NOTIFICATIONS_DELETED, diff --git a/test/BUILD.gn b/test/BUILD.gn index 9e40c0da656d..23a79e6cabfc 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -222,6 +222,7 @@ test("brave_browser_tests") { "//brave/browser/brave_resources_browsertest.cc", "//brave/browser/extensions/brave_tor_client_updater_browsertest.cc", "//brave/browser/extensions/api/brave_shields_api_browsertest.cc", + "//brave/browser/extensions/api/brave_theme_api_browsertest.cc", "//brave/browser/renderer_context_menu/brave_mock_render_view_context_menu.cc", "//brave/browser/renderer_context_menu/brave_mock_render_view_context_menu.h", "//brave/browser/renderer_context_menu/brave_spelling_menu_observer_browsertest.cc", @@ -290,6 +291,7 @@ test("brave_browser_tests") { "//ppapi/buildflags", ":brave_browser_tests_deps", ":browser_tests_runner", + "//testing/gmock", ] data_deps = [ "//ppapi:ppapi_tests",