diff --git a/app/brave_exe.rc b/app/brave_exe.rc index cc778f67f19..f5711db3c75 100644 --- a/app/brave_exe.rc +++ b/app/brave_exe.rc @@ -60,6 +60,10 @@ IDR_X002_APP_LIST_SXS ICON "theme\\brave\\win\\app_list_sxs.ico" IDR_X003_INCOGNITO ICON "theme\\brave\\win\\incognito.ico" IDR_X004_DEV ICON "theme\\brave\\win\\brave_dev.ico" IDR_X005_BETA ICON "theme\\brave\\win\\brave_beta.ico" +IDR_X006_FILE ICON "theme\\brave\\win\\brave_file.ico" +IDR_X006_FILE_BETA ICON "theme\\brave\\win\\brave_file_beta.ico" +IDR_X006_FILE_DEVA ICON "theme\\brave\\win\\brave_file_dev.ico" +IDR_X006_FILE_SXS ICON "theme\\brave\\win\\brave_file_nightly.ico" #else IDR_X001_APP_LIST ICON "theme\\brave\\win\\app_list.ico" IDR_X003_INCOGNITO ICON "theme\\brave\\win\\incognito.ico" diff --git a/app/theme/brave/win/brave_file.ico b/app/theme/brave/win/brave_file.ico new file mode 100644 index 00000000000..bc7c7b924f4 Binary files /dev/null and b/app/theme/brave/win/brave_file.ico differ diff --git a/app/theme/brave/win/brave_file_beta.ico b/app/theme/brave/win/brave_file_beta.ico new file mode 100644 index 00000000000..c2f36be67fe Binary files /dev/null and b/app/theme/brave/win/brave_file_beta.ico differ diff --git a/app/theme/brave/win/brave_file_dev.ico b/app/theme/brave/win/brave_file_dev.ico new file mode 100644 index 00000000000..1e11d41d02f Binary files /dev/null and b/app/theme/brave/win/brave_file_dev.ico differ diff --git a/app/theme/brave/win/brave_file_nightly.ico b/app/theme/brave/win/brave_file_nightly.ico new file mode 100644 index 00000000000..23063abd4d8 Binary files /dev/null and b/app/theme/brave/win/brave_file_nightly.ico differ diff --git a/chromium_src/chrome/common/chrome_icon_resources_win.h b/chromium_src/chrome/common/chrome_icon_resources_win.h index e1a870a015f..4d05940765d 100644 --- a/chromium_src/chrome/common/chrome_icon_resources_win.h +++ b/chromium_src/chrome/common/chrome_icon_resources_win.h @@ -1,9 +1,10 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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/. */ -#ifndef CHROME_COMMON_CHROME_ICON_RESOURCES_WIN_H_ -#define CHROME_COMMON_CHROME_ICON_RESOURCES_WIN_H_ +#ifndef BRAVE_CHROMIUM_SRC_CHROME_COMMON_CHROME_ICON_RESOURCES_WIN_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_COMMON_CHROME_ICON_RESOURCES_WIN_H_ namespace icon_resources { @@ -36,6 +37,12 @@ enum { // The Brave Beta application icon. kBetaApplicationIndex = 9, + + // The various file type icon(ex, pdf). + kFileTypeIndex = 10, + kBetaFileTypeIndex = 11, + kDevFileTypeIndex = 12, + kSxSFileTypeIndex = 13, #else // The Brave Developer App Launcher icon. kAppLauncherIndex = 1, @@ -47,4 +54,4 @@ enum { } // namespace icon_resources -#endif // CHROME_COMMON_CHROME_ICON_RESOURCES_WIN_H_ +#endif // BRAVE_CHROMIUM_SRC_CHROME_COMMON_CHROME_ICON_RESOURCES_WIN_H_ diff --git a/chromium_src/chrome/installer/DEPS b/chromium_src/chrome/installer/DEPS index 9b2df46553b..9a5d0ad19be 100644 --- a/chromium_src/chrome/installer/DEPS +++ b/chromium_src/chrome/installer/DEPS @@ -2,6 +2,8 @@ include_rules = [ "+../../../../../chrome/installer/mini_installer", "+../../../../../chrome/installer/setup", "+../../../../../chrome/installer/util", + "+chrome/common", "+chrome/installer", "+chrome/install_static", + "+components/version_info", ] diff --git a/chromium_src/chrome/installer/setup/sources.gni b/chromium_src/chrome/installer/setup/sources.gni new file mode 100644 index 00000000000..455a603a629 --- /dev/null +++ b/chromium_src/chrome/installer/setup/sources.gni @@ -0,0 +1,11 @@ +# 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/. + +brave_chromium_src_chrome_installer_setup_sources = [] +brave_chromium_src_chrome_installer_setup_deps = [] + +if (is_win) { + brave_chromium_src_chrome_installer_setup_deps += [ "//brave/installer/util" ] +} diff --git a/chromium_src/chrome/installer/setup/uninstall.cc b/chromium_src/chrome/installer/setup/uninstall.cc new file mode 100644 index 00000000000..5a1ca4f6023 --- /dev/null +++ b/chromium_src/chrome/installer/setup/uninstall.cc @@ -0,0 +1,68 @@ +/* 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/. */ + +#include "brave/installer/util/brave_shell_util.h" + +#define UninstallProduct UninstallProduct_ChromiumImpl + +#include "../../../../../chrome/installer/setup/uninstall.cc" + +#undef UninstallProduct + +namespace installer { + +namespace { + +void DeleteBraveFileKeys(HKEY root) { + // Delete Software\Classes\BraveXXXFile. + std::wstring reg_prog_id(ShellUtil::kRegClasses); + reg_prog_id.push_back(base::FilePath::kSeparators[0]); + reg_prog_id.append(GetProgIdForFileType()); + InstallUtil::DeleteRegistryKey(root, reg_prog_id, WorkItem::kWow64Default); + + // Cleanup OpenWithList and OpenWithProgids: + // http://msdn.microsoft.com/en-us/library/bb166549 + std::wstring file_assoc_key; + std::wstring open_with_progids_key; + for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != nullptr; ++i) { + file_assoc_key.assign(ShellUtil::kRegClasses); + file_assoc_key.push_back(base::FilePath::kSeparators[0]); + file_assoc_key.append(ShellUtil::kPotentialFileAssociations[i]); + file_assoc_key.push_back(base::FilePath::kSeparators[0]); + + open_with_progids_key.assign(file_assoc_key); + open_with_progids_key.append(ShellUtil::kRegOpenWithProgids); + if (ShouldUseFileTypeProgId(ShellUtil::kPotentialFileAssociations[i])) { + InstallUtil::DeleteRegistryValue(root, open_with_progids_key, + WorkItem::kWow64Default, + GetProgIdForFileType()); + } + } +} + +} // namespace + +InstallStatus UninstallProduct(const ModifyParams& modify_params, + bool remove_all, + bool force_uninstall, + const base::CommandLine& cmd_line) { + DeleteBraveFileKeys(HKEY_CURRENT_USER); + + const InstallerState& installer_state = modify_params.installer_state; + const base::FilePath chrome_exe( + installer_state.target_path().Append(installer::kChromeExe)); + const std::wstring suffix( + ShellUtil::GetCurrentInstallationSuffix(chrome_exe)); + if (installer_state.system_install() || + (remove_all && + ShellUtil::QuickIsChromeRegisteredInHKLM(chrome_exe, suffix))) { + DeleteBraveFileKeys(HKEY_LOCAL_MACHINE); + } + + return UninstallProduct_ChromiumImpl(modify_params, remove_all, + force_uninstall, cmd_line); +} + +} // namespace installer diff --git a/chromium_src/chrome/installer/util/shell_util.cc b/chromium_src/chrome/installer/util/shell_util.cc index dbf8594212f..07d417130ca 100644 --- a/chromium_src/chrome/installer/util/shell_util.cc +++ b/chromium_src/chrome/installer/util/shell_util.cc @@ -3,6 +3,36 @@ * 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/notreached.h" +#include "brave/installer/util/brave_shell_util.h" +#include "chrome/common/chrome_icon_resources_win.h" +#include "chrome/install_static/install_util.h" +#include "components/version_info/channel.h" + +namespace { + +#if defined(OFFICIAL_BUILD) + +int GetIconIndexForFileType() { + switch (install_static::GetChromeChannel()) { + case version_info::Channel::STABLE: + return icon_resources::kFileTypeIndex; + case version_info::Channel::BETA: + return icon_resources::kBetaFileTypeIndex; + case version_info::Channel::DEV: + return icon_resources::kDevFileTypeIndex; + case version_info::Channel::CANARY: + return icon_resources::kSxSFileTypeIndex; + default: + NOTREACHED(); + return icon_resources::kFileTypeIndex; + } +} + +#endif // OFFICIAL_BUILD + +} // namespace + #define BRAVE_IPFS L"ipfs" #define BRAVE_IPNS L"ipns" @@ -12,7 +42,43 @@ if (base::EqualsCaseInsensitiveASCII(protocol, BRAVE_IPNS)) \ return base::StringPrintf(kSystemSettingsDefaultAppsFormat, L"IPNS"); +#if defined(OFFICIAL_BUILD) +// Add BraveFile prog id in registry with proper icon. +// This prog id will be referenced from serveral file association reg entry. +#define BRAVE_GET_CHROME_PROG_ID_ENTRIES \ + app_info.prog_id = installer::GetProgIdForFileType(); \ + app_info.file_type_icon_index = GetIconIndexForFileType(); \ + GetProgIdEntries(app_info, entries); + +// Give BraveXXFile prog id for some file type.(ex, .pdf or .svg) instead of +// BraveHTML. +#define BRAVE_GET_APP_EXT_REGISTRATION_ENTRIES \ + if (installer::ShouldUseFileTypeProgId(ext)) { \ + entries->push_back(std::make_unique( \ + key_name, installer::GetProgIdForFileType(), std::wstring())); \ + return; \ + } + +// Give BraveXXFile prog id for some file type.(ex, .pdf or .svg) instead of +// BraveHTML. +#define BRAVE_GET_SHELL_INTEGRATION_ENTRIES \ + const std::wstring file_ext = ShellUtil::kPotentialFileAssociations[i]; \ + if (installer::ShouldUseFileTypeProgId(file_ext)) { \ + entries->push_back(std::make_unique( \ + capabilities + L"\\FileAssociations", file_ext, \ + installer::GetProgIdForFileType())); \ + continue; \ + } +#else +#define BRAVE_GET_CHROME_PROG_ID_ENTRIES +#define BRAVE_GET_APP_EXT_REGISTRATION_ENTRIES +#define BRAVE_GET_SHELL_INTEGRATION_ENTRIES +#endif + #include "../../../../../chrome/installer/util/shell_util.cc" +#undef BRAVE_GET_SHELL_INTEGRATION_ENTRIES +#undef BRAVE_GET_APP_EXT_REGISTRATION_ENTRIES +#undef BRAVE_GET_CHROME_PROG_ID_ENTRIES #undef BRAVE_GET_TARGET_FOR_DEFAULT_APP_SETTINGS #undef BRAVE_IPFS #undef BRAVE_IPNS diff --git a/chromium_src/chrome/installer/util/sources.gni b/chromium_src/chrome/installer/util/sources.gni new file mode 100644 index 00000000000..d8a78c35024 --- /dev/null +++ b/chromium_src/chrome/installer/util/sources.gni @@ -0,0 +1,16 @@ +# 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/. + +brave_chromium_src_chrome_installer_util_sources = [] +brave_chromium_src_chrome_installer_util_deps = [] + +if (is_win) { + brave_chromium_src_chrome_installer_util_deps += [ + "//brave/installer/util", + "//chrome/common:non_code_constants", + "//chrome/install_static:install_static_util", + "//components/version_info", + ] +} diff --git a/installer/util/BUILD.gn b/installer/util/BUILD.gn new file mode 100644 index 00000000000..bf7b4bd2a99 --- /dev/null +++ b/installer/util/BUILD.gn @@ -0,0 +1,12 @@ +source_set("util") { + sources = [ + "brave_shell_util.cc", + "brave_shell_util.h", + ] + + deps = [ + "//base", + "//chrome/install_static:install_static_util", + "//components/version_info", + ] +} diff --git a/installer/util/DEPS b/installer/util/DEPS new file mode 100644 index 00000000000..30e9887a42b --- /dev/null +++ b/installer/util/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+chrome/install_static", + "+components/version_info", +] diff --git a/installer/util/brave_shell_util.cc b/installer/util/brave_shell_util.cc new file mode 100644 index 00000000000..340b98e18ce --- /dev/null +++ b/installer/util/brave_shell_util.cc @@ -0,0 +1,34 @@ +/* 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/. */ + +#include "brave/installer/util/brave_shell_util.h" + +#include "base/notreached.h" +#include "chrome/install_static/install_util.h" +#include "components/version_info/channel.h" + +namespace installer { + +std::wstring GetProgIdForFileType() { + switch (install_static::GetChromeChannel()) { + case version_info::Channel::STABLE: + return L"BraveFile"; + case version_info::Channel::BETA: + return L"BraveBFile"; + case version_info::Channel::DEV: + return L"BraveDFile"; + case version_info::Channel::CANARY: + return L"BraveSSFile"; + default: + NOTREACHED(); + return L"BraveFile"; + } +} + +bool ShouldUseFileTypeProgId(const std::wstring& ext) { + return (ext == L".pdf" || ext == L".svg"); +} + +} // namespace installer diff --git a/installer/util/brave_shell_util.h b/installer/util/brave_shell_util.h new file mode 100644 index 00000000000..dd5e299ca70 --- /dev/null +++ b/installer/util/brave_shell_util.h @@ -0,0 +1,18 @@ +/* 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/. */ + +#ifndef BRAVE_INSTALLER_UTIL_BRAVE_SHELL_UTIL_H_ +#define BRAVE_INSTALLER_UTIL_BRAVE_SHELL_UTIL_H_ + +#include + +namespace installer { + +std::wstring GetProgIdForFileType(); +bool ShouldUseFileTypeProgId(const std::wstring& ext); + +} // namespace installer + +#endif // BRAVE_INSTALLER_UTIL_BRAVE_SHELL_UTIL_H_ diff --git a/patches/chrome-installer-setup-BUILD.gn.patch b/patches/chrome-installer-setup-BUILD.gn.patch new file mode 100644 index 00000000000..13487483073 --- /dev/null +++ b/patches/chrome-installer-setup-BUILD.gn.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/installer/setup/BUILD.gn b/chrome/installer/setup/BUILD.gn +index db3796b6b6ef7c7c60cd6d75e93259c1a5edc364..e6fa111a618efea3ff70b55b75ed9c9297c4d040 100644 +--- a/chrome/installer/setup/BUILD.gn ++++ b/chrome/installer/setup/BUILD.gn +@@ -49,6 +49,7 @@ if (is_win) { + ] + + libs = [ "netapi32.lib" ] ++ import("//brave/chromium_src/chrome/installer/setup/sources.gni") deps += brave_chromium_src_chrome_installer_setup_deps sources+= brave_chromium_src_chrome_installer_setup_sources + } + + static_library("lib") { diff --git a/patches/chrome-installer-util-BUILD.gn.patch b/patches/chrome-installer-util-BUILD.gn.patch index f7fd7bff61f..3efb5a9beff 100644 --- a/patches/chrome-installer-util-BUILD.gn.patch +++ b/patches/chrome-installer-util-BUILD.gn.patch @@ -1,8 +1,16 @@ diff --git a/chrome/installer/util/BUILD.gn b/chrome/installer/util/BUILD.gn -index 2ea95551d977717045804377090c4e57bb4e0518..c3af7ec8bad26ee56ee5b2a786c1c8ece82f6e7b 100644 +index 2ea95551d977717045804377090c4e57bb4e0518..6859e33daa7de44c2b53601163bc6949bdebbd0c 100644 --- a/chrome/installer/util/BUILD.gn +++ b/chrome/installer/util/BUILD.gn -@@ -225,7 +225,18 @@ generate_embedded_i18n("generate_strings") { +@@ -190,6 +190,7 @@ static_library("with_no_strings") { + "initial_preferences.h", + ] + } ++ import("//brave/chromium_src/chrome/installer/util/sources.gni") deps += brave_chromium_src_chrome_installer_util_deps sources += brave_chromium_src_chrome_installer_util_sources + } + + # Use this version of installer_util to link to the generated strings in .rc +@@ -225,7 +226,18 @@ generate_embedded_i18n("generate_strings") { output_file_name_base = "installer_util_strings" diff --git a/patches/chrome-installer-util-shell_util.cc.patch b/patches/chrome-installer-util-shell_util.cc.patch index 9192911dd53..e3600cf2da5 100644 --- a/patches/chrome-installer-util-shell_util.cc.patch +++ b/patches/chrome-installer-util-shell_util.cc.patch @@ -1,8 +1,32 @@ diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc -index 3e81aacae5b091da6718b4394289605b86400c02..863f01c37945abb0219ea46bfb07370d6fb2bfe2 100644 +index 3e81aacae5b091da6718b4394289605b86400c02..af09cf6ba8489196d049fb2044a5bc3d4a58a9c6 100644 --- a/chrome/installer/util/shell_util.cc +++ b/chrome/installer/util/shell_util.cc -@@ -754,6 +754,7 @@ std::wstring GetTargetForDefaultAppsSettings(const wchar_t* protocol) { +@@ -392,6 +392,7 @@ void GetChromeProgIdEntries( + app_info.delegate_clsid = install_static::GetLegacyCommandExecuteImplClsid(); + + GetProgIdEntries(app_info, entries); ++ BRAVE_GET_CHROME_PROG_ID_ENTRIES + + if (!app_info.delegate_clsid.empty()) { + auto delegate_execute_entries = +@@ -488,6 +489,7 @@ void GetShellIntegrationEntries( + + const std::wstring html_prog_id(GetBrowserProgId(suffix)); + for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != nullptr; i++) { ++ BRAVE_GET_SHELL_INTEGRATION_ENTRIES + entries->push_back(std::make_unique( + capabilities + L"\\FileAssociations", + ShellUtil::kPotentialFileAssociations[i], html_prog_id)); +@@ -514,6 +516,7 @@ void GetAppExtRegistrationEntries( + key_name.append(ext); + key_name.push_back(base::FilePath::kSeparators[0]); + key_name.append(ShellUtil::kRegOpenWithProgids); ++ BRAVE_GET_APP_EXT_REGISTRATION_ENTRIES + entries->push_back( + std::make_unique(key_name, prog_id, std::wstring())); + } +@@ -754,6 +757,7 @@ std::wstring GetTargetForDefaultAppsSettings(const wchar_t* protocol) { return base::StringPrintf(kSystemSettingsDefaultAppsFormat, L"Browser"); if (base::EqualsCaseInsensitiveASCII(protocol, L"mailto")) return base::StringPrintf(kSystemSettingsDefaultAppsFormat, L"Email"); @@ -10,7 +34,7 @@ index 3e81aacae5b091da6718b4394289605b86400c02..863f01c37945abb0219ea46bfb07370d return L"SettingsPageAppsDefaultsProtocolView"; } -@@ -1661,8 +1662,10 @@ const wchar_t* ShellUtil::kPotentialFileAssociations[] = { +@@ -1661,8 +1665,10 @@ const wchar_t* ShellUtil::kPotentialFileAssociations[] = { L".htm", L".html", L".pdf", L".shtml", L".svg", L".xht", L".xhtml", L".webp", nullptr}; const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = {L"ftp", L"http",