From 3b652a9966bd4b605c960bf7c8acb064da7b3a42 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 20 Nov 2023 19:35:05 -0500 Subject: [PATCH] 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. --- patch/patch.cfg | 5 ++ patch/patches/win_app_icon_3606.patch | 77 +++++++++++++++++++ .../main_message_loop_multithreaded_win.cc | 2 +- tests/cefclient/browser/resource.h | 4 +- tests/cefclient/browser/root_window_win.cc | 6 +- tests/cefclient/resources/win/cefclient.rc | 10 +-- tests/cefsimple/resource.h | 4 +- tests/ceftests/resource.h | 2 + tests/ceftests/resources/win/ceftests.rc | 2 +- 9 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 patch/patches/win_app_icon_3606.patch diff --git a/patch/patch.cfg b/patch/patch.cfg index a5de37909..d2303d3b9 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -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' } ] diff --git a/patch/patches/win_app_icon_3606.patch b/patch/patches/win_app_icon_3606.patch new file mode 100644 index 000000000..a9ed9f77f --- /dev/null +++ b/patch/patches/win_app_icon_3606.patch @@ -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(LoadImage( ++ GetModuleHandle(NULL), MAKEINTRESOURCE(icon_id), ++ IMAGE_ICON, size.width(), size.height(), ++ LR_DEFAULTCOLOR | LR_SHARED))) { ++ return icon; ++ } + return static_cast(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 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"); diff --git a/tests/cefclient/browser/main_message_loop_multithreaded_win.cc b/tests/cefclient/browser/main_message_loop_multithreaded_win.cc index 156cd3e42..349c1611a 100644 --- a/tests/cefclient/browser/main_message_loop_multithreaded_win.cc +++ b/tests/cefclient/browser/main_message_loop_multithreaded_win.cc @@ -54,7 +54,7 @@ int MainMessageLoopMultithreadedWin::Run() { } HACCEL hAccelTable = - LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT)); + LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)); MSG msg; diff --git a/tests/cefclient/browser/resource.h b/tests/cefclient/browser/resource.h index b32f3e38e..32caf8897 100644 --- a/tests/cefclient/browser/resource.h +++ b/tests/cefclient/browser/resource.h @@ -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 diff --git a/tests/cefclient/browser/root_window_win.cc b/tests/cefclient/browser/root_window_win.cc index 19b489b1d..b4e910d7e 100644 --- a/tests/cefclient/browser/root_window_win.cc +++ b/tests/cefclient/browser/root_window_win.cc @@ -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)); diff --git a/tests/cefclient/resources/win/cefclient.rc b/tests/cefclient/resources/win/cefclient.rc index edd7e1b01..2273bc0fa 100644 --- a/tests/cefclient/resources/win/cefclient.rc +++ b/tests/cefclient/resources/win/cefclient.rc @@ -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 diff --git a/tests/cefsimple/resource.h b/tests/cefsimple/resource.h index ba1f3a9e0..be8dbc3ef 100644 --- a/tests/cefsimple/resource.h +++ b/tests/cefsimple/resource.h @@ -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_ diff --git a/tests/ceftests/resource.h b/tests/ceftests/resource.h index f87af0ff6..6d9a4b138 100644 --- a/tests/ceftests/resource.h +++ b/tests/ceftests/resource.h @@ -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 diff --git a/tests/ceftests/resources/win/ceftests.rc b/tests/ceftests/resources/win/ceftests.rc index 841b8ebcc..8fe40e80c 100644 --- a/tests/ceftests/resources/win/ceftests.rc +++ b/tests/ceftests/resources/win/ceftests.rc @@ -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" /////////////////////////////////////////////////////////////////////////////