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

Linux support #205

Merged
merged 9 commits into from
Jul 5, 2018
6 changes: 5 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
]
}
Expand Down
13 changes: 13 additions & 0 deletions app/theme/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Binary file added app/theme/brave/product_logo_128_beta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/theme/brave/product_logo_128_dev.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/theme/brave/product_logo_128_development.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/theme/brave/product_logo_128_nightly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions app/theme/brave_unscaled_resources.grd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/brave_unscaled_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="brave_unscaled_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<if expr="is_linux">
<include name="IDR_PRODUCT_LOGO_128_BETA" file="brave/product_logo_128_beta.png" type="BINDATA" />
<include name="IDR_PRODUCT_LOGO_128_DEV" file="brave/product_logo_128_dev.png" type="BINDATA" />
<include name="IDR_PRODUCT_LOGO_128_DEVELOPMENT" file="brave/product_logo_128_development.png" type="BINDATA" />
<include name="IDR_PRODUCT_LOGO_128_NIGHTLY" file="brave/product_logo_128_nightly.png" type="BINDATA" />
</if>
</includes>
</release>
</grit>
2 changes: 2 additions & 0 deletions brave_paks.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions browser/brave_resources_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
}
3 changes: 3 additions & 0 deletions browser/resources/resource_ids
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
"brave/app/theme/brave_theme_resources.grd": {
"structures": [36000],
},
"brave/app/theme/brave_unscaled_resources.grd": {
"includes": [36500],
},
}
10 changes: 10 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand All @@ -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",
]
}
}
21 changes: 21 additions & 0 deletions browser/ui/views/brave_browser_main_extra_parts_views_linux.cc
Original file line number Diff line number Diff line change
@@ -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<BraveViewsDelegateLinux>();

ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized();
}

25 changes: 25 additions & 0 deletions browser/ui/views/brave_browser_main_extra_parts_views_linux.h
Original file line number Diff line number Diff line change
@@ -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::ViewsDelegate> views_delegate_;

DISALLOW_COPY_AND_ASSIGN(BraveBrowserMainExtraPartsViewsLinux);
};

#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_BROWSER_MAIN_EXTRA_PARTS_VIEWS_LINUX_H_

37 changes: 37 additions & 0 deletions browser/ui/views/brave_views_delegate_linux.cc
Original file line number Diff line number Diff line change
@@ -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());
}

21 changes: 21 additions & 0 deletions browser/ui/views/brave_views_delegate_linux.h
Original file line number Diff line number Diff line change
@@ -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_
39 changes: 39 additions & 0 deletions browser/ui/views/brave_views_delegate_linux_browsertest.cc
Original file line number Diff line number Diff line change
@@ -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
}

12 changes: 0 additions & 12 deletions build/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions build/linux/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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\"",
]
}
22 changes: 22 additions & 0 deletions build/linux/channels.gni
Original file line number Diff line number Diff line change
@@ -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")
}

25 changes: 25 additions & 0 deletions chromium_src/chrome/common/channel_info_posix.cc
Original file line number Diff line number Diff line change
@@ -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

27 changes: 27 additions & 0 deletions chromium_src/chrome/common/chrome_paths_linux.cc
Original file line number Diff line number Diff line change
@@ -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<base::Environment> 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
2 changes: 2 additions & 0 deletions chromium_src/chrome/grit/chrome_unscaled_resources.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "brave/grit/brave_unscaled_resources.h"
#include "gen/chrome/grit/chrome_unscaled_resources.h"
Loading