diff --git a/BUILD.gn b/BUILD.gn index 6d582f80116d..4f2683b30af0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -12,6 +12,10 @@ if (is_mac) { import("//brave/build/mac/tweak_info_plist.gni") } +if (is_linux) { + import("//brave/build/linux/channels.gni") +} + group("child_dependencies") { public_deps = [ "//brave/renderer", @@ -75,7 +79,7 @@ group("create_dist") { } if (is_linux) { deps += [ - "//chrome/installer/linux:$brave_linux_channel", + "//chrome/installer/linux:$linux_channel", "//brave/app/linux:dist_resources", ] } diff --git a/app/theme/BUILD.gn b/app/theme/BUILD.gn index bfad27d1bc28..470019941580 100644 --- a/app/theme/BUILD.gn +++ b/app/theme/BUILD.gn @@ -17,3 +17,16 @@ grit("brave_theme_resources") { output_dir = "$root_gen_dir/brave" } + +grit("brave_unscaled_resources") { + source = "brave_unscaled_resources.grd" + defines = chrome_grit_defines + outputs = [ + "grit/brave_unscaled_resources.h", + "brave_unscaled_resources.pak", + ] + + resource_ids = "//brave/browser/resources/resource_ids" + + output_dir = "$root_gen_dir/brave" +} diff --git a/app/theme/brave/product_logo_128_beta.png b/app/theme/brave/product_logo_128_beta.png new file mode 100644 index 000000000000..128f3fac8591 Binary files /dev/null and b/app/theme/brave/product_logo_128_beta.png differ diff --git a/app/theme/brave/product_logo_128_dev.png b/app/theme/brave/product_logo_128_dev.png new file mode 100644 index 000000000000..31912059826d Binary files /dev/null and b/app/theme/brave/product_logo_128_dev.png differ diff --git a/app/theme/brave/product_logo_128_development.png b/app/theme/brave/product_logo_128_development.png new file mode 100644 index 000000000000..46ab5f31d545 Binary files /dev/null and b/app/theme/brave/product_logo_128_development.png differ diff --git a/app/theme/brave/product_logo_128_nightly.png b/app/theme/brave/product_logo_128_nightly.png new file mode 100644 index 000000000000..4ed96a97e267 Binary files /dev/null and b/app/theme/brave/product_logo_128_nightly.png differ diff --git a/app/theme/brave_unscaled_resources.grd b/app/theme/brave_unscaled_resources.grd new file mode 100644 index 000000000000..730a86eae474 --- /dev/null +++ b/app/theme/brave_unscaled_resources.grd @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/brave_paks.gni b/brave_paks.gni index c4200cb1e812..e61df6352083 100644 --- a/brave_paks.gni +++ b/brave_paks.gni @@ -55,12 +55,14 @@ template("brave_extra_paks") { output = "${invoker.output_dir}/brave_resources.pak" sources = [ "$root_gen_dir/brave/brave_generated_resources.pak", + "$root_gen_dir/brave/brave_unscaled_resources.pak", "$root_gen_dir/components/brave_components_resources.pak", "$target_gen_dir/browser/resources/brave_extension.pak", ] deps = [ "//brave/app:brave_generated_resources_grit", + "//brave/app/theme:brave_unscaled_resources", "//brave/components/resources:brave_components_resources_grit", "//brave/browser/resources:brave_extension_grit", "//brave/common/extensions/api" diff --git a/browser/brave_resources_browsertest.cc b/browser/brave_resources_browsertest.cc index d50dfda3841f..e13b441c1569 100644 --- a/browser/brave_resources_browsertest.cc +++ b/browser/brave_resources_browsertest.cc @@ -3,6 +3,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/grit/brave_theme_resources.h" +#include "brave/grit/brave_unscaled_resources.h" #include "chrome/test/base/in_process_browser_test.h" #include "ui/base/resource/resource_bundle.h" @@ -14,4 +15,15 @@ IN_PROC_BROWSER_TEST_F(BraveResourcesBrowserTest, ResourceExistanceTest) { ui::ResourceBundle::GetSharedInstance().GetImageNamed( IDR_PRODUCT_LOGO_32_DEV); EXPECT_FALSE(test_image.IsEmpty()); + +#if defined(OS_LINUX) + test_image = + ui::ResourceBundle::GetSharedInstance().GetImageNamed( + IDR_PRODUCT_LOGO_128_BETA); + EXPECT_FALSE(test_image.IsEmpty()); + test_image = + ui::ResourceBundle::GetSharedInstance().GetImageNamed( + IDR_PRODUCT_LOGO_128_DEV); + EXPECT_FALSE(test_image.IsEmpty()); +#endif } diff --git a/browser/resources/resource_ids b/browser/resources/resource_ids index 350f2040cd40..66a5407f764b 100644 --- a/browser/resources/resource_ids +++ b/browser/resources/resource_ids @@ -18,4 +18,7 @@ "brave/app/theme/brave_theme_resources.grd": { "structures": [36000], }, + "brave/app/theme/brave_unscaled_resources.grd": { + "includes": [36500], + }, } diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 04c14e7b1ac9..12bd6bd0b86d 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -42,6 +42,7 @@ source_set("ui") { deps = [ "//brave/app:command_ids", + "//brave/app/theme:brave_unscaled_resources", "//brave/app/theme:brave_theme_resources", "//chrome/app:command_ids", ] @@ -53,4 +54,13 @@ source_set("ui") { ] deps += [ "//google_update" ] } + + if (is_linux) { + sources += [ + "views/brave_browser_main_extra_parts_views_linux.cc", + "views/brave_browser_main_extra_parts_views_linux.h", + "views/brave_views_delegate_linux.cc", + "views/brave_views_delegate_linux.h", + ] + } } diff --git a/browser/ui/views/brave_browser_main_extra_parts_views_linux.cc b/browser/ui/views/brave_browser_main_extra_parts_views_linux.cc new file mode 100644 index 000000000000..923f8eaec2a2 --- /dev/null +++ b/browser/ui/views/brave_browser_main_extra_parts_views_linux.cc @@ -0,0 +1,21 @@ +/* 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/views/brave_browser_main_extra_parts_views_linux.h" + +#include "brave/browser/ui/views/brave_views_delegate_linux.h" + +BraveBrowserMainExtraPartsViewsLinux::BraveBrowserMainExtraPartsViewsLinux() { +} + +BraveBrowserMainExtraPartsViewsLinux::~BraveBrowserMainExtraPartsViewsLinux() { +} + +void BraveBrowserMainExtraPartsViewsLinux::ToolkitInitialized() { + if (!views::ViewsDelegate::GetInstance()) + views_delegate_ = std::make_unique(); + + ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized(); +} + diff --git a/browser/ui/views/brave_browser_main_extra_parts_views_linux.h b/browser/ui/views/brave_browser_main_extra_parts_views_linux.h new file mode 100644 index 000000000000..358d8c8c112f --- /dev/null +++ b/browser/ui/views/brave_browser_main_extra_parts_views_linux.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_UI_VIEWS_BRAVE_BROWSER_MAIN_EXTRA_PARTS_VIEWS_LINUX_H_ +#define BRAVE_BROWSER_UI_VIEWS_BRAVE_BROWSER_MAIN_EXTRA_PARTS_VIEWS_LINUX_H_ + +#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" + +class BraveBrowserMainExtraPartsViewsLinux : public ChromeBrowserMainExtraPartsViewsLinux { + public: + BraveBrowserMainExtraPartsViewsLinux(); + ~BraveBrowserMainExtraPartsViewsLinux() override; + + private: + // ChromeBrowserMainExtraPartsViewsLinux overrides: + void ToolkitInitialized() override; + + std::unique_ptr views_delegate_; + + DISALLOW_COPY_AND_ASSIGN(BraveBrowserMainExtraPartsViewsLinux); +}; + +#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_BROWSER_MAIN_EXTRA_PARTS_VIEWS_LINUX_H_ + diff --git a/browser/ui/views/brave_views_delegate_linux.cc b/browser/ui/views/brave_views_delegate_linux.cc new file mode 100644 index 000000000000..cc9adb2debb5 --- /dev/null +++ b/browser/ui/views/brave_views_delegate_linux.cc @@ -0,0 +1,37 @@ +/* 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/views/brave_views_delegate_linux.h" + +#include "chrome/common/channel_info.h" +#include "chrome/grit/chrome_unscaled_resources.h" +#include "components/version_info/channel.h" +#include "ui/base/resource/resource_bundle.h" + +namespace { + +int GetWindowIconResourceId() { +#if defined(OFFICIAL_BUILD) + switch (chrome::GetChannel()) { + case version_info::Channel::DEV: + return IDR_PRODUCT_LOGO_128_DEV; + case version_info::Channel::BETA: + return IDR_PRODUCT_LOGO_128_BETA; + case version_info::Channel::CANARY: + return IDR_PRODUCT_LOGO_128_NIGHTLY; + default: + return IDR_PRODUCT_LOGO_128; + } +#else + return IDR_PRODUCT_LOGO_128_DEVELOPMENT; +#endif +} + +} // namespace + +gfx::ImageSkia* BraveViewsDelegateLinux::GetDefaultWindowIcon() const { + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + return rb.GetImageSkiaNamed(GetWindowIconResourceId()); +} + diff --git a/browser/ui/views/brave_views_delegate_linux.h b/browser/ui/views/brave_views_delegate_linux.h new file mode 100644 index 000000000000..d13dac79a384 --- /dev/null +++ b/browser/ui/views/brave_views_delegate_linux.h @@ -0,0 +1,21 @@ +/* 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_VIEWS_BRAVE_VIEWS_DELEGATE_LINUX_H_ +#define BRAVE_BROWSER_UI_VIEWS_BRAVE_VIEWS_DELEGATE_LINUX_H_ + +#include "chrome/browser/ui/views/chrome_views_delegate.h" + +class BraveViewsDelegateLinux : public ChromeViewsDelegate { + public: + BraveViewsDelegateLinux() = default; + ~BraveViewsDelegateLinux() override = default; + private: + // ChromeViewsDelegate overrides: + gfx::ImageSkia* GetDefaultWindowIcon() const override; + + DISALLOW_COPY_AND_ASSIGN(BraveViewsDelegateLinux); +}; + +#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_VIEWS_DELEGATE_LINUX_H_ diff --git a/browser/ui/views/brave_views_delegate_linux_browsertest.cc b/browser/ui/views/brave_views_delegate_linux_browsertest.cc new file mode 100644 index 000000000000..1330b0bb3a7d --- /dev/null +++ b/browser/ui/views/brave_views_delegate_linux_browsertest.cc @@ -0,0 +1,39 @@ +/* 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/views/brave_views_delegate_linux.h" +#include "chrome/grit/chrome_unscaled_resources.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/views/views_delegate.h" + +using BraveViewsDelegateViewLinuxBrowserTest = InProcessBrowserTest; + +IN_PROC_BROWSER_TEST_F(BraveViewsDelegateViewLinuxBrowserTest, GetDefaultWindowIconTest) { + auto env = base::Environment::Create(); + views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); + auto& rb = ui::ResourceBundle::GetSharedInstance(); + +#if defined(OFFICIAL_BUILD) + env->SetVar("CHROME_VERSION_EXTRA", LINUX_CHANNEL_STABLE); + EXPECT_EQ(rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_128)->bitmap(), + views_delegate->GetDefaultWindowIcon()->bitmap()); + env->SetVar("CHROME_VERSION_EXTRA", LINUX_CHANNEL_BETA); + EXPECT_EQ(rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_128_BETA)->bitmap(), + views_delegate->GetDefaultWindowIcon()->bitmap()); + env->SetVar("CHROME_VERSION_EXTRA", LINUX_CHANNEL_DEV); + EXPECT_EQ(rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_128_DEV)->bitmap(), + views_delegate->GetDefaultWindowIcon()->bitmap()); + env->SetVar("CHROME_VERSION_EXTRA", BRAVE_LINUX_CHANNEL_DEV); + EXPECT_EQ(rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_128_DEV)->bitmap(), + views_delegate->GetDefaultWindowIcon()->bitmap()); + env->SetVar("CHROME_VERSION_EXTRA", BRAVE_LINUX_CHANNEL_NIGHTLY); + EXPECT_EQ(rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_128_NIGHTLY)->bitmap(), + views_delegate->GetDefaultWindowIcon()->bitmap()); +#else // OFFICIAL_BUILD + EXPECT_EQ(rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_128_DEVELOPMENT)->bitmap(), + views_delegate->GetDefaultWindowIcon()->bitmap()); +#endif +} + diff --git a/build/config.gni b/build/config.gni index 36f338c2daea..0600704b0034 100644 --- a/build/config.gni +++ b/build/config.gni @@ -25,18 +25,6 @@ if (is_win) { brave_exe = "$chrome_product_full_name.app" } -if (is_linux) { - # Our channle name and upstream linux channel name is different. - brave_linux_channel = "" - if (brave_channel == "") { - brave_linux_channel = "stable" - } else if (brave_channel == "dev") { - brave_linux_channel = "unstable" - } else { - assert(brave_channel == "beta", "Not supported channel name: $brave_channel") - } -} - brave_icon_dir = "nightly" if (is_component_build) { brave_icon_dir = "dev" diff --git a/build/linux/BUILD.gn b/build/linux/BUILD.gn new file mode 100644 index 000000000000..a010d167f2d9 --- /dev/null +++ b/build/linux/BUILD.gn @@ -0,0 +1,14 @@ +import("//brave/build/linux/channels.gni") + +assert(is_linux) + +config("linux_channel_names") { + defines= [ + "BRAVE_LINUX_CHANNEL_STABLE=\"$brave_linux_channel_stable\"", + "BRAVE_LINUX_CHANNEL_DEV=\"$brave_linux_channel_dev\"", + "BRAVE_LINUX_CHANNEL_NIGHTLY=\"$brave_linux_channel_nightly\"", + "LINUX_CHANNEL_STABLE=\"$linux_channel_stable\"", + "LINUX_CHANNEL_BETA=\"$linux_channel_beta\"", + "LINUX_CHANNEL_DEV=\"$linux_channel_dev\"", + ] +} diff --git a/build/linux/channels.gni b/build/linux/channels.gni new file mode 100644 index 000000000000..1e5999ff9b00 --- /dev/null +++ b/build/linux/channels.gni @@ -0,0 +1,22 @@ +assert(is_linux) + +brave_linux_channel_stable = "" +brave_linux_channel_dev = "dev" +brave_linux_channel_nightly = "nightly" +linux_channel_stable = "stable" +linux_channel_beta = "beta" +linux_channel_dev = "unstable" + +# Our channel name and upstream linux channel name is different. +if (brave_channel == "") { + linux_channel = linux_channel_stable +} else if (brave_channel == "beta") { + linux_channel = linux_channel_beta +} else if (brave_channel == "dev") { + linux_channel = linux_channel_dev +} else if (brave_channel == "nightly") { + linux_channel = brave_linux_channel_nightly +} else { + assert(false, "Not supported channel name: $brave_channel") +} + diff --git a/chromium_src/chrome/common/channel_info_posix.cc b/chromium_src/chrome/common/channel_info_posix.cc new file mode 100644 index 000000000000..9be9cf37739d --- /dev/null +++ b/chromium_src/chrome/common/channel_info_posix.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/channel_info.h" + +#include "base/strings/string_util.h" +#include "brave/common/brave_channel_info_posix.h" +#include "build/build_config.h" +#include "components/version_info/version_info.h" + +namespace chrome { + +std::string GetChannelName() { + std::string modifier; + brave::GetChannelImpl(&modifier, nullptr); + return modifier; +} + +version_info::Channel GetChannel() { + return brave::GetChannelImpl(nullptr, nullptr); +} + +} // namespace chrome + diff --git a/chromium_src/chrome/common/chrome_paths_linux.cc b/chromium_src/chrome/common/chrome_paths_linux.cc new file mode 100644 index 000000000000..c2f3a7a23add --- /dev/null +++ b/chromium_src/chrome/common/chrome_paths_linux.cc @@ -0,0 +1,27 @@ +/* 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/. */ + +#define GetDefaultUserDataDirectory GetDefaultUserDataDirectory_Disabled +#include "../../../../chrome/common/chrome_paths_linux.cc" +#undef GetDefaultUserDataDirectory + +#include "brave/common/brave_channel_info_posix.h" + +namespace chrome { + +bool GetDefaultUserDataDirectory(base::FilePath* result) { + std::unique_ptr env(base::Environment::Create()); + base::FilePath config_dir; + std::string chrome_config_home_str; + config_dir = + GetXDGDirectory(env.get(), kXdgConfigHomeEnvVar, kDotConfigDir); + + std::string data_dir_suffix; + brave::GetChannelImpl(nullptr, &data_dir_suffix); + + *result = config_dir.Append("BraveSoftware/Brave-Browser" + data_dir_suffix); + return true; +} + +} // namespace chrome diff --git a/chromium_src/chrome/grit/chrome_unscaled_resources.h b/chromium_src/chrome/grit/chrome_unscaled_resources.h new file mode 100644 index 000000000000..aba01b081c45 --- /dev/null +++ b/chromium_src/chrome/grit/chrome_unscaled_resources.h @@ -0,0 +1,2 @@ +#include "brave/grit/brave_unscaled_resources.h" +#include "gen/chrome/grit/chrome_unscaled_resources.h" \ No newline at end of file diff --git a/common/BUILD.gn b/common/BUILD.gn index ff6509a05fdf..9c214516a9d6 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -39,8 +39,14 @@ source_set("common") { if (is_linux) { sources += [ + "brave_channel_info_posix.cc", + "brave_channel_info_posix.h", "importer/chrome_importer_utils_linux.cc", ] + + configs += [ + "//brave/build/linux:linux_channel_names", + ] } if (is_win) { @@ -50,12 +56,3 @@ source_set("common") { } } -source_set("constants") { - # TODO(simonhong): Remove if clauses. - if (is_official_build) { - sources = [ - "//brave/common/brave_channel_info_linux.cc", - "//brave/common/brave_channel_info_linux.h", - ] - } -} diff --git a/common/brave_channel_info_linux.cc b/common/brave_channel_info_linux.cc deleted file mode 100644 index d8b95a8ad9b2..000000000000 --- a/common/brave_channel_info_linux.cc +++ /dev/null @@ -1,26 +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/common/brave_channel_info_linux.h" - -namespace brave { - -std::string GetChannelSuffixForDataDir() { - std::string modifier; - std::string data_dir_suffix; - - char* env = getenv("CHROME_VERSION_EXTRA"); - if (env) - modifier = env; - - // Chrome doesn't support canary channel on linux. - if (modifier == "unstable") // linux version of "dev" - data_dir_suffix = "-Dev"; - else if (modifier == "beta") - data_dir_suffix = "-Beta"; - - return data_dir_suffix; -} - -} // namespace brave diff --git a/common/brave_channel_info_linux.h b/common/brave_channel_info_linux.h deleted file mode 100644 index 0775e3bede61..000000000000 --- a/common/brave_channel_info_linux.h +++ /dev/null @@ -1,16 +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_COMMON_BRAVE_CHANNEL_INFO_LINUX_H_ -#define BRAVE_COMMON_BRAVE_CHANNEL_INFO_LINUX_H_ - -#include - -namespace brave { - -std::string GetChannelSuffixForDataDir(); - -} // namespace brave - -#endif // BRAVE_COMMON_BRAVE_CHANNEL_INFO_LINUX_H_ diff --git a/common/brave_channel_info_mac_unittest.cc b/common/brave_channel_info_mac_unittest.cc deleted file mode 100644 index 26a690214fca..000000000000 --- a/common/brave_channel_info_mac_unittest.cc +++ /dev/null @@ -1,27 +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 "chrome/common/channel_info.h" - -#include "base/files/file_path.h" -#include "chrome/common/channel_info.h" -#include "chrome/common/chrome_paths_internal.h" -#include "components/version_info/channel.h" -#include "testing/gtest/include/gtest/gtest.h" - -TEST(BraveChannelInfoMacTest, ChannelTest) { -#if defined(OFFICIAL_BUILD) - EXPECT_EQ(version_info::Channel::STABLE, - chrome::GetChannelByName("")); - EXPECT_EQ(version_info::Channel::BETA, - chrome::GetChannelByName("beta")); - EXPECT_EQ(version_info::Channel::DEV, - chrome::GetChannelByName("dev")); - EXPECT_EQ(version_info::Channel::CANARY, - chrome::GetChannelByName("nightly")); -#else - EXPECT_EQ(version_info::Channel::UNKNOWN, - chrome::GetChannelByName("")); -#endif -} diff --git a/common/brave_channel_info_posix.cc b/common/brave_channel_info_posix.cc new file mode 100644 index 000000000000..6f5a138126a9 --- /dev/null +++ b/common/brave_channel_info_posix.cc @@ -0,0 +1,52 @@ +/* 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/common/brave_channel_info_posix.h" + +#include "base/strings/string_util.h" +#include "build/build_config.h" + +namespace brave { + +version_info::Channel GetChannelImpl(std::string* modifier_out, + std::string* data_dir_suffix_out) { + version_info::Channel channel = version_info::Channel::UNKNOWN; + std::string modifier; + std::string data_dir_suffix; + +#if defined(OFFICIAL_BUILD) + char* env = getenv("CHROME_VERSION_EXTRA"); + if (env) + modifier = env; + + if (modifier == LINUX_CHANNEL_DEV) + modifier = BRAVE_LINUX_CHANNEL_DEV; + if (modifier == LINUX_CHANNEL_STABLE) { + channel = version_info::Channel::STABLE; + modifier = BRAVE_LINUX_CHANNEL_STABLE; + } else if (modifier == BRAVE_LINUX_CHANNEL_DEV) { + channel = version_info::Channel::DEV; + data_dir_suffix = "-Dev"; + } else if (modifier == LINUX_CHANNEL_BETA) { + channel = version_info::Channel::BETA; + data_dir_suffix = "-Beta"; + } else if (modifier == BRAVE_LINUX_CHANNEL_NIGHTLY) { + channel = version_info::Channel::CANARY; + data_dir_suffix = "-Nightly"; + } else { + modifier = "unknown"; + } +#else + data_dir_suffix = "-Development"; +#endif + + if (modifier_out) + modifier_out->swap(modifier); + if (data_dir_suffix_out) + data_dir_suffix_out->swap(data_dir_suffix); + + return channel; +} + +} // namespace brave diff --git a/common/brave_channel_info_posix.h b/common/brave_channel_info_posix.h new file mode 100644 index 000000000000..dca2e0b677b7 --- /dev/null +++ b/common/brave_channel_info_posix.h @@ -0,0 +1,18 @@ +/* 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_COMMON_BRAVE_CHANNEL_INFO_POSIX_H_ +#define BRAVE_COMMON_BRAVE_CHANNEL_INFO_POSIX_H_ + +#include "components/version_info/version_info.h" + +namespace brave { + +version_info::Channel GetChannelImpl(std::string* modifier_out, + std::string* data_dir_suffix_out); + +} + +#endif // BRAVE_COMMON_BRAVE_CHANNEL_INFO_POSIX_H_ + diff --git a/common/brave_channel_info_unittest.cc b/common/brave_channel_info_unittest.cc new file mode 100644 index 000000000000..07046dd3482e --- /dev/null +++ b/common/brave_channel_info_unittest.cc @@ -0,0 +1,83 @@ +/* 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 "chrome/common/channel_info.h" + +#include "base/files/file_path.h" +#include "chrome/common/chrome_paths_internal.h" +#include "components/version_info/channel.h" +#include "testing/gtest/include/gtest/gtest.h" + +#if defined(OS_LINUX) +#include "base/environment.h" +#endif + +#if defined(OS_MACOSX) +// GetChannelByName is only supported on MacOS. +TEST(BraveChannelInfoTest, ChannelByNameTest) { +#if defined(OFFICIAL_BUILD) + EXPECT_EQ(version_info::Channel::STABLE, + chrome::GetChannelByName("")); + EXPECT_EQ(version_info::Channel::BETA, + chrome::GetChannelByName("beta")); + EXPECT_EQ(version_info::Channel::DEV, + chrome::GetChannelByName("dev")); + EXPECT_EQ(version_info::Channel::CANARY, + chrome::GetChannelByName("nightly")); +#else + EXPECT_EQ(version_info::Channel::UNKNOWN, + chrome::GetChannelByName("")); +#endif +} +#endif // OS_MACOSX + +#if defined(OS_LINUX) +TEST(BraveChannelInfoTest, ParentDirectoryOfUserDataDirectoryTest) { + base::FilePath path; + EXPECT_TRUE(chrome::GetDefaultUserDataDirectory(&path)); + EXPECT_EQ("BraveSoftware", path.DirName().BaseName().AsUTF8Unsafe()); +} + +TEST(BraveChannelInfoTest, DefaultUserDataDirectoryAndChannelTest) { + base::FilePath path; +#if defined(OFFICIAL_BUILD) + auto env = base::Environment::Create(); + + env->SetVar("CHROME_VERSION_EXTRA", LINUX_CHANNEL_STABLE); + EXPECT_TRUE(chrome::GetDefaultUserDataDirectory(&path)); + EXPECT_EQ("Brave-Browser", path.BaseName().AsUTF8Unsafe()); + EXPECT_EQ(version_info::Channel::STABLE, chrome::GetChannel()); + EXPECT_EQ(BRAVE_LINUX_CHANNEL_STABLE, chrome::GetChannelName()); + + env->SetVar("CHROME_VERSION_EXTRA", LINUX_CHANNEL_BETA); + EXPECT_TRUE(chrome::GetDefaultUserDataDirectory(&path)); + EXPECT_EQ("Brave-Browser-Beta", path.BaseName().AsUTF8Unsafe()); + EXPECT_EQ(version_info::Channel::BETA, chrome::GetChannel()); + EXPECT_EQ(LINUX_CHANNEL_BETA, chrome::GetChannelName()); + + env->SetVar("CHROME_VERSION_EXTRA", BRAVE_LINUX_CHANNEL_DEV); + EXPECT_TRUE(chrome::GetDefaultUserDataDirectory(&path)); + EXPECT_EQ("Brave-Browser-Dev", path.BaseName().AsUTF8Unsafe()); + EXPECT_EQ(version_info::Channel::DEV, chrome::GetChannel()); + EXPECT_EQ(BRAVE_LINUX_CHANNEL_DEV, chrome::GetChannelName()); + + env->SetVar("CHROME_VERSION_EXTRA", LINUX_CHANNEL_DEV); + EXPECT_TRUE(chrome::GetDefaultUserDataDirectory(&path)); + EXPECT_EQ("Brave-Browser-Dev", path.BaseName().AsUTF8Unsafe()); + EXPECT_EQ(version_info::Channel::DEV, chrome::GetChannel()); + EXPECT_EQ(BRAVE_LINUX_CHANNEL_DEV, chrome::GetChannelName()); + + env->SetVar("CHROME_VERSION_EXTRA", BRAVE_LINUX_CHANNEL_NIGHTLY); + EXPECT_TRUE(chrome::GetDefaultUserDataDirectory(&path)); + EXPECT_EQ("Brave-Browser-Nightly", path.BaseName().AsUTF8Unsafe()); + EXPECT_EQ(version_info::Channel::CANARY, chrome::GetChannel()); + EXPECT_EQ(BRAVE_LINUX_CHANNEL_NIGHTLY, chrome::GetChannelName()); +#else // OFFICIAL_BUILD + EXPECT_TRUE(chrome::GetDefaultUserDataDirectory(&path)); + EXPECT_EQ("Brave-Browser-Development", path.BaseName().AsUTF8Unsafe()); + EXPECT_EQ(version_info::Channel::UNKNOWN, chrome::GetChannel()); + EXPECT_EQ(BRAVE_LINUX_CHANNEL_STABLE, chrome::GetChannelName()); +#endif // !OFFICIAL_BUILD +} +#endif diff --git a/patches/chrome-browser-chrome_content_browser_client.cc.patch b/patches/chrome-browser-chrome_content_browser_client.cc.patch index 93348482b0c5..4a7548a5a8ea 100644 --- a/patches/chrome-browser-chrome_content_browser_client.cc.patch +++ b/patches/chrome-browser-chrome_content_browser_client.cc.patch @@ -1,8 +1,19 @@ diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc -index 196205f32d149db75ea3edeb01b3521735cafa08..39897ad441746b4259c6bf02effa81911206824e 100644 +index 196205f32d149db75ea3edeb01b3521735cafa08..38f93d1df536a478c32306e415f40900ff4c7759 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc -@@ -782,6 +782,16 @@ void GetGuestViewDefaultContentSettingRules( +@@ -461,6 +461,10 @@ + #include "chrome/services/file_util/public/mojom/constants.mojom.h" + #endif + ++#if defined(BRAVE_CHROMIUM_BUILD) && defined(OS_LINUX) ++#include "brave/browser/ui/views/brave_browser_main_extra_parts_views_linux.h" ++#endif ++ + using base::FileDescriptor; + using content::BrowserThread; + using content::BrowserURLHandler; +@@ -782,6 +786,16 @@ void GetGuestViewDefaultContentSettingRules( base::Value::FromUniquePtrValue( content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK)), std::string(), incognito)); @@ -19,3 +30,15 @@ index 196205f32d149db75ea3edeb01b3521735cafa08..39897ad441746b4259c6bf02effa8191 } AppLoadedInTabSource ClassifyAppLoadedInTabSource( +@@ -1050,7 +1064,11 @@ content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( + // which they are added. + #if defined(TOOLKIT_VIEWS) + #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) ++#if defined(BRAVE_CHROMIUM_BUILD) ++ main_parts->AddParts(new BraveBrowserMainExtraPartsViewsLinux()); ++#else + main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux()); ++#endif + #else + main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); + #endif diff --git a/patches/chrome-common-BUILD.gn.patch b/patches/chrome-common-BUILD.gn.patch deleted file mode 100644 index b81880ad4adb..000000000000 --- a/patches/chrome-common-BUILD.gn.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/chrome/common/BUILD.gn b/chrome/common/BUILD.gn -index eb650f8aa7009371e31077e0f4a754807efd7613..11c036a1922da9f00a8b196657bdfc15431c4f9c 100644 ---- a/chrome/common/BUILD.gn -+++ b/chrome/common/BUILD.gn -@@ -579,6 +579,12 @@ static_library("constants") { - "//third_party/widevine/cdm:headers", - ] - -+ if (brave_chromium_build) { -+ deps += [ -+ "//brave/common:constants" -+ ] -+ } -+ - if (is_android) { - # This dependency must only be added for Android. - # diff --git a/patches/chrome-common-channel_info_posix.cc.patch b/patches/chrome-common-channel_info_posix.cc.patch deleted file mode 100644 index 91a06eccb3cf..000000000000 --- a/patches/chrome-common-channel_info_posix.cc.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/chrome/common/channel_info_posix.cc b/chrome/common/channel_info_posix.cc -index 7978d188e03342dd8ed59e8bff47f24af23d6641..52711bdf1d3a58b22a4303eb576af76f0e491933 100644 ---- a/chrome/common/channel_info_posix.cc -+++ b/chrome/common/channel_info_posix.cc -@@ -25,7 +25,7 @@ version_info::Channel GetChannelImpl(std::string* modifier_out, - if (env) - modifier = env; - --#if defined(GOOGLE_CHROME_BUILD) -+#if defined(GOOGLE_CHROME_BUILD) || (defined(BRAVE_CHROMIUM_BUILD) && defined(OFFICIAL_BUILD)) - // Only ever return "", "unknown", "dev" or "beta" in a branded build. - if (modifier == "unstable") // linux version of "dev" - modifier = "dev"; diff --git a/patches/chrome-common-chrome_paths_linux.cc.patch b/patches/chrome-common-chrome_paths_linux.cc.patch deleted file mode 100644 index 81dc2b71cfcb..000000000000 --- a/patches/chrome-common-chrome_paths_linux.cc.patch +++ /dev/null @@ -1,34 +0,0 @@ -diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc -index fc47bd3f12418fdaed879e0b485bfc7cb572a6e8..9d7f74be49456b05c593ae2df4831c754d931a73 100644 ---- a/chrome/common/chrome_paths_linux.cc -+++ b/chrome/common/chrome_paths_linux.cc -@@ -16,6 +16,10 @@ - #include "chrome/common/channel_info.h" - #include "chrome/common/chrome_paths_internal.h" - -+#if defined(BRAVE_CHROMIUM_BUILD) && defined(OFFICIAL_BUILD) -+#include "brave/common/brave_channel_info_linux.h" -+#endif -+ - namespace chrome { - - using base::nix::GetXDGDirectory; -@@ -87,10 +91,18 @@ bool GetDefaultUserDataDirectory(base::FilePath* result) { - GetXDGDirectory(env.get(), kXdgConfigHomeEnvVar, kDotConfigDir); - } - -+#if defined(BRAVE_CHROMIUM_BUILD) -+#if defined(OFFICIAL_BUILD) -+ *result = config_dir.Append("Brave-Browser" + brave::GetChannelSuffixForDataDir()); -+#else -+ *result = config_dir.Append("Brave-Browser-Development"); -+#endif -+#else - #if defined(GOOGLE_CHROME_BUILD) - *result = config_dir.Append("google-chrome" + GetChannelSuffixForDataDir()); - #else - *result = config_dir.Append("chromium"); -+#endif - #endif - return true; - } diff --git a/patches/chrome-installer-linux-BUILD.gn.patch b/patches/chrome-installer-linux-BUILD.gn.patch index 6d2997f3180f..346fd6ba0d70 100644 --- a/patches/chrome-installer-linux-BUILD.gn.patch +++ b/patches/chrome-installer-linux-BUILD.gn.patch @@ -1,5 +1,5 @@ diff --git a/chrome/installer/linux/BUILD.gn b/chrome/installer/linux/BUILD.gn -index fbabd6c3414f5cb69cf4c7ab6ef5f957cb391376..ab6bf7f0d65ae03730d977b17782d52ad3c30736 100644 +index fbabd6c3414f5cb69cf4c7ab6ef5f957cb391376..b9a82deb60d40228dbe67bf5d91c88888d44eda6 100644 --- a/chrome/installer/linux/BUILD.gn +++ b/chrome/installer/linux/BUILD.gn @@ -25,11 +25,10 @@ declare_args() { @@ -36,3 +36,10 @@ index fbabd6c3414f5cb69cf4c7ab6ef5f957cb391376..ab6bf7f0d65ae03730d977b17782d52a ] } +@@ -524,3 +523,6 @@ linux_package("beta") { + linux_package("unstable") { + channel = "unstable" + } ++linux_package("nightly") { ++ channel = "nightly" ++} diff --git a/patches/chrome-installer-linux-debian-build.sh.patch b/patches/chrome-installer-linux-debian-build.sh.patch index 9796ca9b068a..40e083945ab0 100644 --- a/patches/chrome-installer-linux-debian-build.sh.patch +++ b/patches/chrome-installer-linux-debian-build.sh.patch @@ -1,5 +1,5 @@ diff --git a/chrome/installer/linux/debian/build.sh b/chrome/installer/linux/debian/build.sh -index 8234cafbb5f95ec608dfa5eff3d0098def1d225a..b6cdc060387389fb93616686a1895ca7e95c98b6 100755 +index 8234cafbb5f95ec608dfa5eff3d0098def1d225a..f1d5799806fc733b875e62cfd2c97662362a3ce7 100755 --- a/chrome/installer/linux/debian/build.sh +++ b/chrome/installer/linux/debian/build.sh @@ -21,7 +21,7 @@ gen_changelog() { @@ -38,7 +38,18 @@ index 8234cafbb5f95ec608dfa5eff3d0098def1d225a..b6cdc060387389fb93616686a1895ca7 grep '^ Depends: ' | sed 's/^ Depends: //' | sed 's/, /\n/g' | \ LANG=C sort > "${ACTUAL_DEPENDS}" BAD_DIFF=0 -@@ -259,6 +259,11 @@ fi +@@ -159,6 +159,10 @@ verify_channel() { + CHANNEL=unstable + RELEASENOTES="http://googlechromereleases.blogspot.com/search/label/Dev%20updates" + ;; ++ nightly ) ++ CHANNEL=nightly ++ RELEASENOTES="https://community.brave.com" ++ ;; + testing|beta ) + CHANNEL=beta + RELEASENOTES="http://googlechromereleases.blogspot.com/search/label/Beta%20updates" +@@ -259,6 +263,11 @@ fi eval $(sed -e "s/^\([^=]\+\)=\(.*\)$/export \1='\2'/" \ "${BUILDDIR}/installer/theme/BRANDING") diff --git a/patches/chrome-installer-linux-rpm-build.sh.patch b/patches/chrome-installer-linux-rpm-build.sh.patch index f41803319e40..1a7f6b205be9 100644 --- a/patches/chrome-installer-linux-rpm-build.sh.patch +++ b/patches/chrome-installer-linux-rpm-build.sh.patch @@ -1,5 +1,5 @@ diff --git a/chrome/installer/linux/rpm/build.sh b/chrome/installer/linux/rpm/build.sh -index 261faeaf26f34f2e89229579ae7933e23e4299e6..201aacd532ea70067279ec970134f3b28108f368 100755 +index 261faeaf26f34f2e89229579ae7933e23e4299e6..f4bde0a98bd7d6fa4e6c6a4f1ee63e6132b0e997 100755 --- a/chrome/installer/linux/rpm/build.sh +++ b/chrome/installer/linux/rpm/build.sh @@ -15,8 +15,9 @@ gen_spec() { @@ -25,3 +25,13 @@ index 261faeaf26f34f2e89229579ae7933e23e4299e6..201aacd532ea70067279ec970134f3b2 mv "$RPMBUILD_DIR/RPMS/$ARCHITECTURE/${PKGNAME}.${ARCHITECTURE}.rpm" \ "${OUTPUTDIR}" # Make sure the package is world-readable, otherwise it causes problems when +@@ -146,6 +150,9 @@ verify_channel() { + unstable|dev|alpha ) + CHANNEL=unstable + ;; ++ nightly ) ++ CHANNEL=nightly ++ ;; + testing|beta ) + CHANNEL=beta + ;; diff --git a/test/BUILD.gn b/test/BUILD.gn index 327ba7efa08e..200d68a7d7d4 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -42,9 +42,10 @@ test("brave_unit_tests") { "../utility/importer/chrome_importer_unittest.cc", ] - if (is_mac) { + # On Windows, brave_install_static_unittests covers channel test. + if (is_mac || is_linux) { sources += [ - "//brave/common/brave_channel_info_mac_unittest.cc", + "//brave/common/brave_channel_info_unittest.cc", ] } @@ -54,6 +55,7 @@ test("brave_unit_tests") { configs += [ "//brave/build/geolocation", + "//brave/build/linux:linux_channel_names", ] deps = [ @@ -146,6 +148,15 @@ test("brave_browser_tests") { "//chrome/browser/extensions/updater/extension_cache_fake.cc", "//chrome/browser/extensions/updater/extension_cache_fake.h", ] + if (is_linux) { + sources += [ + "//brave/browser/ui/views/brave_views_delegate_linux_browsertest.cc", + ] + configs += [ + "//brave/build/linux:linux_channel_names", + ] + } + defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ] deps = [ "//chrome/browser/ui",