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

Development no longer restricted to dark theme only #365

Merged
merged 2 commits into from
Aug 28, 2018
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
17 changes: 17 additions & 0 deletions browser/themes/brave_theme_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

#include "brave/browser/themes/brave_theme_service.h"

#include <string>

#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 "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "components/pref_registry/pref_registry_syncable.h"
Expand All @@ -19,6 +24,18 @@ void BraveThemeService::RegisterProfilePrefs(

// static
BraveThemeService::BraveThemeType BraveThemeService::GetBraveThemeType(Profile* profile) {
// allow override via cli flag
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);
if (requested_theme_value_lower == "light")
return BraveThemeService::BraveThemeType::BRAVE_THEME_TYPE_LIGHT;
if (requested_theme_value_lower == "light")
return BraveThemeService::BraveThemeType::BRAVE_THEME_TYPE_DARK;
}
// get value from preferences
return static_cast<BraveThemeService::BraveThemeType>(
profile->GetPrefs()->GetInteger(kBraveThemeType));
}
Expand Down
7 changes: 0 additions & 7 deletions browser/themes/brave_theme_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ void SetBraveThemeType(Profile* profile, BTS::BraveThemeType type) {

IN_PROC_BROWSER_TEST_F(BraveThemeServiceTest, BraveThemeChangeTest) {
Profile* profile = browser()->profile();
#if defined(OFFICIAL_BUILD)
const SkColor light_frame_color = SkColorSetRGB(0xD8, 0xDE, 0xE1);
#endif
const SkColor dark_frame_color = SkColorSetRGB(0x58, 0x5B, 0x5E);

// Check default type is set initially.
Expand All @@ -33,12 +31,7 @@ IN_PROC_BROWSER_TEST_F(BraveThemeServiceTest, BraveThemeChangeTest) {
const ui::ThemeProvider& tp = ThemeService::GetThemeProviderForProfile(profile);
SetBraveThemeType(browser()->profile(), BTS::BRAVE_THEME_TYPE_LIGHT);
EXPECT_EQ(BTS::BRAVE_THEME_TYPE_LIGHT, BTS::GetBraveThemeType(profile));
#if defined(OFFICIAL_BUILD)
EXPECT_EQ(light_frame_color, tp.GetColor(ThemeProperties::COLOR_FRAME));
#else
// Non-official build always uses dark theme.
EXPECT_EQ(dark_frame_color, tp.GetColor(ThemeProperties::COLOR_FRAME));
#endif

SetBraveThemeType(browser()->profile(), BTS::BRAVE_THEME_TYPE_DARK);
EXPECT_EQ(BTS::BRAVE_THEME_TYPE_DARK, BTS::GetBraveThemeType(profile));
Expand Down
18 changes: 6 additions & 12 deletions browser/themes/theme_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

namespace {

#if defined(OFFICIAL_BUILD)
base::Optional<SkColor> MaybeGetDefaultColorForBraveUiReleaseChannel(int id, bool incognito) {
base::Optional<SkColor> MaybeGetDefaultColorForBraveLightUi(int id, bool incognito) {
switch (id) {
// Applies when the window is active, tabs and also tab bar everywhere except active tab
case ThemeProperties::COLOR_FRAME:
Expand All @@ -41,9 +40,8 @@ base::Optional<SkColor> MaybeGetDefaultColorForBraveUiReleaseChannel(int id, boo
return base::nullopt;
}
}
#endif

base::Optional<SkColor> MaybeGetDefaultColorForBraveUiDevChannel(int id, bool incognito) {
base::Optional<SkColor> MaybeGetDefaultColorForBraveDarkUi(int id, bool incognito) {
switch (id) {
// Applies when the window is active, tabs and also tab bar everywhere except active tab
case ThemeProperties::COLOR_FRAME:
Expand Down Expand Up @@ -74,29 +72,25 @@ base::Optional<SkColor> MaybeGetDefaultColorForBraveUiDevChannel(int id, bool in

// Returns a |nullopt| if the UI color is not handled by Brave.
base::Optional<SkColor> MaybeGetDefaultColorForBraveUi(int id, bool incognito, Profile* profile) {
#if !defined(OFFICIAL_BUILD)
return MaybeGetDefaultColorForBraveUiDevChannel(id, incognito);
#else
switch (BraveThemeService::GetBraveThemeType(profile)) {
case BraveThemeService::BRAVE_THEME_TYPE_DEFAULT:
switch (chrome::GetChannel()) {
case version_info::Channel::STABLE:
case version_info::Channel::BETA:
return MaybeGetDefaultColorForBraveUiReleaseChannel(id, incognito);
return MaybeGetDefaultColorForBraveLightUi(id, incognito);
case version_info::Channel::DEV:
case version_info::Channel::CANARY:
case version_info::Channel::UNKNOWN:
default:
return MaybeGetDefaultColorForBraveUiDevChannel(id, incognito);
return MaybeGetDefaultColorForBraveDarkUi(id, incognito);
}
case BraveThemeService::BRAVE_THEME_TYPE_LIGHT:
return MaybeGetDefaultColorForBraveUiReleaseChannel(id, incognito);
return MaybeGetDefaultColorForBraveLightUi(id, incognito);
case BraveThemeService::BRAVE_THEME_TYPE_DARK:
return MaybeGetDefaultColorForBraveUiDevChannel(id, incognito);
return MaybeGetDefaultColorForBraveDarkUi(id, incognito);
default:
NOTREACHED();

}
#endif
return base::nullopt;
}
4 changes: 4 additions & 0 deletions common/brave_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ const char kDisablePDFJSExtension[] = "disable-pdfjs-extension";
// Allows disabling the Tor client updater extension.
const char kDisableTorClientUpdaterExtension[] = "disable-tor-client-updater-extension";

// Specifies overriding the built-in theme setting.
// Valid values are: "dark" | "light".
const char kUiMode[] = "ui-mode";

} // namespace switches
2 changes: 2 additions & 0 deletions common/brave_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extern const char kDisablePDFJSExtension[];

extern const char kDisableTorClientUpdaterExtension[];

extern const char kUiMode[];

} // namespace switches

#endif // BRAVE_COMMON_BRAVE_SWITCHES_H_
Expand Down