chrome: win: Fix app icon for default Chrome windows (fixes #3606)

This fixes the app icon for default Chrome windows such as DevTools
and Task Manager.

An ICON with value IDR_MAINFRAME (101) will be loaded from the main
executable is available. Otherwise, the default Chromium ICON will be
loaded from libcef.dll.
This commit is contained in:
Marshall Greenblatt 2023-11-20 19:35:05 -05:00
parent cf934a20a7
commit 3b652a9966
9 changed files with 97 additions and 15 deletions

View File

@ -684,5 +684,10 @@ patches = [
# scheme) with insecure destination.
# https://github.com/chromiumembedded/cef/issues/3596
'name': 'net_url_request_3596'
},
{
# chrome: win: Fix loading of default app icon.
# https://github.com/chromiumembedded/cef/issues/3606
'name': 'win_app_icon_3606'
}
]

View File

@ -0,0 +1,77 @@
diff --git chrome/browser/win/app_icon.cc chrome/browser/win/app_icon.cc
index db721b75aad6f..a4826e16dd43d 100644
--- chrome/browser/win/app_icon.cc
+++ chrome/browser/win/app_icon.cc
@@ -25,6 +25,10 @@ HICON GetAppIcon() {
// get correct scaling. (See http://crbug.com/551256)
const int icon_id = GetAppIconResourceId();
// HICON returned from LoadIcon do not leak and do not have to be destroyed.
+ // Try to load the icon from the exe first.
+ if (auto icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(icon_id))) {
+ return icon;
+ }
return LoadIcon(GetModuleHandle(chrome::kBrowserResourcesDll),
MAKEINTRESOURCE(icon_id));
}
@@ -35,6 +39,13 @@ HICON GetSmallAppIcon() {
const int icon_id = GetAppIconResourceId();
gfx::Size size = GetSmallAppIconSize();
// HICON returned from LoadImage must be released using DestroyIcon.
+ // Try to load the icon from the exe first.
+ if (auto icon = static_cast<HICON>(LoadImage(
+ GetModuleHandle(NULL), MAKEINTRESOURCE(icon_id),
+ IMAGE_ICON, size.width(), size.height(),
+ LR_DEFAULTCOLOR | LR_SHARED))) {
+ return icon;
+ }
return static_cast<HICON>(LoadImage(
GetModuleHandle(chrome::kBrowserResourcesDll), MAKEINTRESOURCE(icon_id),
IMAGE_ICON, size.width(), size.height(), LR_DEFAULTCOLOR | LR_SHARED));
@@ -51,14 +62,11 @@ gfx::Size GetSmallAppIconSize() {
std::unique_ptr<gfx::ImageFamily> GetAppIconImageFamily() {
const int icon_id = GetAppIconResourceId();
- // Get the icon from chrome.dll (not chrome.exe, which has different resource
- // IDs). If chrome.dll is not loaded, we are probably in a unit test, so fall
- // back to getting the icon from the current module (assuming it is
- // unit_tests.exe, that has the same resource IDs as chrome.dll).
- HMODULE module = GetModuleHandle(chrome::kBrowserResourcesDll);
- if (!module)
- module = GetModuleHandle(nullptr);
- DCHECK(module);
-
- return IconUtil::CreateImageFamilyFromIconResource(module, icon_id);
+ // Try to load the icon from the exe first.
+ if (auto image_family = IconUtil::CreateImageFamilyFromIconResource(
+ GetModuleHandle(NULL), icon_id)) {
+ return image_family;
+ }
+ return IconUtil::CreateImageFamilyFromIconResource(
+ GetModuleHandle(chrome::kBrowserResourcesDll), icon_id);
}
diff --git chrome/common/chrome_constants.cc chrome/common/chrome_constants.cc
index 3a39e2bb7b608..27c6038cf7a47 100644
--- chrome/common/chrome_constants.cc
+++ chrome/common/chrome_constants.cc
@@ -6,6 +6,7 @@
#include "build/branding_buildflags.h"
#include "build/build_config.h"
+#include "cef/libcef/features/features.h"
#include "chrome/common/chrome_version.h"
#define FPL FILE_PATH_LITERAL
@@ -100,7 +101,12 @@ const char kMacHelperSuffixAlerts[] = " (Alerts)";
#endif // BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_WIN)
-const base::FilePath::CharType kBrowserResourcesDll[] = FPL("chrome.dll");
+const base::FilePath::CharType kBrowserResourcesDll[] =
+#if BUILDFLAG(ENABLE_CEF)
+ FPL("libcef.dll");
+#else
+ FPL("chrome.dll");
+#endif
const base::FilePath::CharType kElfDll[] = FPL("chrome_elf.dll");
const base::FilePath::CharType kStatusTrayWindowClass[] =
FPL("Chrome_StatusTrayWindow");

View File

@ -54,7 +54,7 @@ int MainMessageLoopMultithreadedWin::Run() {
}
HACCEL hAccelTable =
LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT));
LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
MSG msg;

View File

@ -8,15 +8,13 @@
//
#define BINARY 256
#define IDC_MYICON 2
#define IDR_MAINFRAME 101
#define IDD_CEFCLIENT_DIALOG 102
#define IDS_APP_TITLE 103
#define IDD_ABOUTBOX 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_CEFCLIENT 107
#define IDI_SMALL 108
#define IDC_CEFCLIENT 109
#define IDR_MAINFRAME 128
#define IDC_NAV_BACK 200
#define IDC_NAV_FORWARD 201
#define IDC_NAV_RELOAD 202

View File

@ -340,7 +340,7 @@ void RootWindowWin::CreateRootWindow(const CefBrowserSettings& settings,
// Load strings from the resource file.
const std::wstring& window_title = GetResourceString(IDS_APP_TITLE);
const std::wstring& window_class = GetResourceString(IDC_CEFCLIENT);
const std::wstring& window_class = GetResourceString(IDR_MAINFRAME);
const cef_color_t background_color = MainContext::Get()->GetBackgroundColor();
const HBRUSH background_brush = CreateSolidBrush(
@ -446,10 +446,10 @@ void RootWindowWin::RegisterRootClass(HINSTANCE hInstance,
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CEFCLIENT));
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = background_brush;
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_CEFCLIENT);
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MAINFRAME);
wcex.lpszClassName = window_class.c_str();
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

View File

@ -68,7 +68,7 @@ IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_JS BINARY "..\\extensions\\set_page_color\\p
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_CEFCLIENT ICON "cefclient.ico"
IDR_MAINFRAME ICON "cefclient.ico"
IDI_SMALL ICON "small.ico"
/////////////////////////////////////////////////////////////////////////////
@ -76,7 +76,7 @@ IDI_SMALL ICON "small.ico"
// Menu
//
IDC_CEFCLIENT MENU
IDR_MAINFRAME MENU
BEGIN
POPUP "&File"
BEGIN
@ -116,7 +116,7 @@ END
// Accelerator
//
IDC_CEFCLIENT ACCELERATORS
IDR_MAINFRAME ACCELERATORS
BEGIN
"?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT
@ -133,7 +133,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "System"
BEGIN
ICON IDI_CEFCLIENT,IDC_MYICON,14,9,16,16
ICON IDR_MAINFRAME,IDC_MYICON,14,9,16,16
LTEXT "cefclient Version 1.0",IDC_STATIC,49,10,119,8,SS_NOPREFIX
LTEXT "Copyright (C) 2008",IDC_STATIC,49,20,119,8
DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP
@ -212,7 +212,7 @@ END
STRINGTABLE
BEGIN
IDS_APP_TITLE "cefclient"
IDC_CEFCLIENT "CEFCLIENT"
IDR_MAINFRAME "CEFCLIENT"
END
#endif // English (U.S.) resources

View File

@ -7,8 +7,8 @@
// Used by cefsimple.rc
//
#define IDI_CEFSIMPLE 100
#define IDI_SMALL 101
#define IDI_CEFSIMPLE 120
#define IDI_SMALL 121
// Avoid files associated with MacOS
#define _X86_

View File

@ -7,6 +7,8 @@
// Used by cefclient.rc
//
#define BINARY 256
#define ICI_CEFTESTS 120
#define IDI_SMALL 121
#define IDS_OSRTEST_HTML 1000
#define IDS_PDF_HTML 1001
#define IDS_PDF_PDF 1002

View File

@ -42,7 +42,7 @@ IDS_WINDOW_ICON_2X_PNG BINARY "..\\..\\..\\shared\\resources\\window_icon.2x.png
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
ICI_UNITTESTS ICON "ceftests.ico"
ICI_CEFTESTS ICON "ceftests.ico"
IDI_SMALL ICON "small.ico"
/////////////////////////////////////////////////////////////////////////////