diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-21 22:07:37 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-21 22:07:37 +0000 |
commit | 2de2d62f73f4e58000055c0522a62af5d6da3cf5 (patch) | |
tree | 74be815663f4a0ae103db997e02949ef497e9459 | |
parent | 72640fb4cac75e9f42fb0e186353bc8b3b196905 (diff) | |
download | chromium_src-2de2d62f73f4e58000055c0522a62af5d6da3cf5.zip chromium_src-2de2d62f73f4e58000055c0522a62af5d6da3cf5.tar.gz chromium_src-2de2d62f73f4e58000055c0522a62af5d6da3cf5.tar.bz2 |
Support grouping taskbar icons for panels with regular taskbar icon for Chromium on Windows 7.
Per discussion, we do not want to use different taskbar icon for each panel since they're now managed altogether. We also need to set its icon path so that the taskbar icon will not be changed once all chromium tabbed windows are closed.
BUG=none
TEST=Manual test by launching panels, closing tabbed window and verifying taskbar icon for panels are grouped together with chrome
Review URL: http://codereview.chromium.org/8366026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106790 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/win/win_util.cc | 27 | ||||
-rw-r--r-- | base/win/win_util.h | 6 | ||||
-rw-r--r-- | chrome/browser/shell_integration.h | 4 | ||||
-rw-r--r-- | chrome/browser/shell_integration_win.cc | 17 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 8 | ||||
-rw-r--r-- | ui/base/win/shell.cc | 85 | ||||
-rw-r--r-- | ui/base/win/shell.h | 3 |
7 files changed, 105 insertions, 45 deletions
diff --git a/base/win/win_util.cc b/base/win/win_util.cc index 10ae261..15a6445 100644 --- a/base/win/win_util.cc +++ b/base/win/win_util.cc @@ -97,21 +97,16 @@ bool UserAccountControlIsEnabled() { return (uac_enabled != 0); } -bool SetAppIdForPropertyStore(IPropertyStore* property_store, - const wchar_t* app_id) { +bool SetStringValueForPropertyStore(IPropertyStore* property_store, + const PROPERTYKEY& property_key, + const wchar_t* property_string_value) { DCHECK(property_store); - // App id should be less than 128 chars and contain no space. And recommended - // format is CompanyName.ProductName[.SubProduct.ProductNumber]. - // See http://msdn.microsoft.com/en-us/library/dd378459%28VS.85%29.aspx - DCHECK(lstrlen(app_id) < 128 && wcschr(app_id, L' ') == NULL); - PROPVARIANT property_value; - if (FAILED(InitPropVariantFromString(app_id, &property_value))) + if (FAILED(InitPropVariantFromString(property_string_value, &property_value))) return false; - HRESULT result = property_store->SetValue(PKEY_AppUserModel_ID, - property_value); + HRESULT result = property_store->SetValue(property_key, property_value); if (S_OK == result) result = property_store->Commit(); @@ -119,6 +114,18 @@ bool SetAppIdForPropertyStore(IPropertyStore* property_store, return SUCCEEDED(result); } +bool SetAppIdForPropertyStore(IPropertyStore* property_store, + const wchar_t* app_id) { + // App id should be less than 128 chars and contain no space. And recommended + // format is CompanyName.ProductName[.SubProduct.ProductNumber]. + // See http://msdn.microsoft.com/en-us/library/dd378459%28VS.85%29.aspx + DCHECK(lstrlen(app_id) < 128 && wcschr(app_id, L' ') == NULL); + + return SetStringValueForPropertyStore(property_store, + PKEY_AppUserModel_ID, + app_id); +} + static const char16 kAutoRunKeyPath[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; diff --git a/base/win/win_util.h b/base/win/win_util.h index 1fe26c7..66c5016 100644 --- a/base/win/win_util.h +++ b/base/win/win_util.h @@ -67,6 +67,12 @@ BASE_EXPORT bool IsAltPressed(); // if the OS is Vista or later. BASE_EXPORT bool UserAccountControlIsEnabled(); +// Sets the string value for given key in given IPropertyStore. +BASE_EXPORT bool SetStringValueForPropertyStore( + IPropertyStore* property_store, + const PROPERTYKEY& property_key, + const wchar_t* property_string_value); + // Sets the application id in given IPropertyStore. The function is intended // for tagging application/chromium shortcut, browser window and jump list for // Win7. diff --git a/chrome/browser/shell_integration.h b/chrome/browser/shell_integration.h index c65f800..5bd8dd0 100644 --- a/chrome/browser/shell_integration.h +++ b/chrome/browser/shell_integration.h @@ -134,6 +134,10 @@ class ShellIntegration { // chrome::kBrowserAppID as app_name. static std::wstring GetChromiumAppId(const FilePath& profile_path); + // Returns the path to the Chromium icon. This is used to specify the icon + // to use for the taskbar group on Win 7. + static string16 GetChromiumIconPath(); + // Migrates existing chrome shortcuts by tagging them with correct app id. // see http://crbug.com/28104 static void MigrateChromiumShortcuts(); diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc index f432431..25f868a 100644 --- a/chrome/browser/shell_integration_win.cc +++ b/chrome/browser/shell_integration_win.cc @@ -13,6 +13,7 @@ #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/stringprintf.h" #include "base/task.h" @@ -520,6 +521,22 @@ std::wstring ShellIntegration::GetChromiumAppId(const FilePath& profile_path) { profile_path); } +string16 ShellIntegration::GetChromiumIconPath() { + // Determine the app path. If we can't determine what that is, we have + // bigger fish to fry... + FilePath app_path; + if (!PathService::Get(base::FILE_EXE, &app_path)) { + NOTREACHED(); + return string16(); + } + + string16 icon_path(app_path.value()); + icon_path.push_back(','); + icon_path += base::IntToString16( + BrowserDistribution::GetDistribution()->GetIconIndex()); + return icon_path; +} + void ShellIntegration::MigrateChromiumShortcuts() { if (base::win::GetVersion() < base::win::VERSION_WIN7) return; diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 09a522d..12f4a10 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -493,10 +493,16 @@ void Browser::InitBrowserWindow() { // Set the app user model id for this application to that of the application // name. See http://crbug.com/7028. ui::win::SetAppIdForWindow( - is_app() ? + is_app() && !is_type_panel() ? ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) : ShellIntegration::GetChromiumAppId(profile_->GetPath()), window()->GetNativeHandle()); + + if (is_type_panel()) { + ui::win::SetAppIconForWindow( + ShellIntegration::GetChromiumIconPath(), + window()->GetNativeHandle()); + } } #endif diff --git a/ui/base/win/shell.cc b/ui/base/win/shell.cc index c78730c..29efce8 100644 --- a/ui/base/win/shell.cc +++ b/ui/base/win/shell.cc @@ -5,7 +5,8 @@ #include "ui/base/win/shell.h" #include <shellapi.h> -#include <shlobj.h> +#include <shlobj.h> // Must be before propkey. +#include <propkey.h> #include "base/file_path.h" #include "base/native_library.h" @@ -27,6 +28,51 @@ typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd, REFIID riid, void** ppv); +void SetAppIdAndIconForWindow(const string16& app_id, + const string16& app_icon, + HWND hwnd) { + // This functionality is only available on Win7+. + if (base::win::GetVersion() < base::win::VERSION_WIN7) + return; + + // Load Shell32.dll into memory. + // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. + std::wstring shell32_filename(kShell32); + FilePath shell32_filepath(shell32_filename); + base::NativeLibrary shell32_library = base::LoadNativeLibrary( + shell32_filepath, NULL); + + if (!shell32_library) + return; + + // Get the function pointer for SHGetPropertyStoreForWindow. + void* function = base::GetFunctionPointerFromNativeLibrary( + shell32_library, + kSHGetPropertyStoreForWindow); + + if (!function) { + base::UnloadNativeLibrary(shell32_library); + return; + } + + // Set the application's name. + base::win::ScopedComPtr<IPropertyStore> pps; + SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); + HRESULT result = SHGetPropertyStoreForWindow( + hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); + if (S_OK == result) { + if (!app_id.empty()) + base::win::SetAppIdForPropertyStore(pps, app_id.c_str()); + if (!app_icon.empty()) { + base::win::SetStringValueForPropertyStore( + pps, PKEY_AppUserModel_RelaunchIconResource, app_icon.c_str()); + } + } + + // Cleanup. + base::UnloadNativeLibrary(shell32_library); +} + } // namespace // Open an item via a shell execute command. Error code checking and casting @@ -72,40 +118,11 @@ bool OpenItemWithExternalApp(const string16& full_path) { } void SetAppIdForWindow(const string16& app_id, HWND hwnd) { - // This functionality is only available on Win7+. - if (base::win::GetVersion() < base::win::VERSION_WIN7) - return; - - // Load Shell32.dll into memory. - // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. - std::wstring shell32_filename(kShell32); - FilePath shell32_filepath(shell32_filename); - base::NativeLibrary shell32_library = base::LoadNativeLibrary( - shell32_filepath, NULL); - - if (!shell32_library) - return; - - // Get the function pointer for SHGetPropertyStoreForWindow. - void* function = base::GetFunctionPointerFromNativeLibrary( - shell32_library, - kSHGetPropertyStoreForWindow); - - if (!function) { - base::UnloadNativeLibrary(shell32_library); - return; - } - - // Set the application's name. - base::win::ScopedComPtr<IPropertyStore> pps; - SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); - HRESULT result = SHGetPropertyStoreForWindow( - hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); - if (S_OK == result) - base::win::SetAppIdForPropertyStore(pps, app_id.c_str()); + SetAppIdAndIconForWindow(app_id, string16(), hwnd); +} - // Cleanup. - base::UnloadNativeLibrary(shell32_library); +void SetAppIconForWindow(const string16& app_icon, HWND hwnd) { + SetAppIdAndIconForWindow(string16(), app_icon, hwnd); } } // namespace win diff --git a/ui/base/win/shell.h b/ui/base/win/shell.h index 8fe8642..b02bce1 100644 --- a/ui/base/win/shell.h +++ b/ui/base/win/shell.h @@ -37,6 +37,9 @@ bool OpenItemWithExternalApp(const string16& full_path); // do not group together on the Win7 task bar. UI_EXPORT void SetAppIdForWindow(const string16& app_id, HWND hwnd); +// Sets the application icon for the window specified. +UI_EXPORT void SetAppIconForWindow(const string16& app_icon, HWND hwnd); + } // namespace win } // namespace ui |