summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/win_util.cc54
-rw-r--r--app/win_util.h5
-rw-r--r--chrome/browser/browser.cc6
3 files changed, 65 insertions, 0 deletions
diff --git a/app/win_util.cc b/app/win_util.cc
index 9e54f5c..2d8c3f3 100644
--- a/app/win_util.cc
+++ b/app/win_util.cc
@@ -8,6 +8,7 @@
#include <atlapp.h>
#include <commdlg.h>
#include <dwmapi.h>
+#include <propvarutil.h>
#include <shellapi.h>
#include <shlobj.h>
@@ -19,6 +20,7 @@
#include "base/gfx/gdi_util.h"
#include "base/gfx/png_encoder.h"
#include "base/logging.h"
+#include "base/native_library.h"
#include "base/registry.h"
#include "base/scoped_handle.h"
#include "base/string_util.h"
@@ -35,6 +37,18 @@ const int kAutoHideTaskbarThicknessPx = 2;
namespace {
+const wchar_t kShell32[] = L"shell32.dll";
+const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow";
+
+// Define the type of SHGetPropertyStoreForWindow is SHGPSFW.
+typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd,
+ REFIID riid,
+ void** ppv);
+
+EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY PKEY_AppUserModel_ID =
+ { { 0x9F4C2855, 0x9F79, 0x4B39,
+ { 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, } }, 5 };
+
// Enforce visible dialog box.
UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message,
WPARAM wparam, LPARAM lparam) {
@@ -825,4 +839,44 @@ gfx::Font GetWindowTitleFont() {
return gfx::Font::CreateFont(caption_font);
}
+void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) {
+ // This funcationality is only available on Win7+.
+ if (win_util::GetWinVersion() != win_util::WINVERSION_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);
+
+ 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.
+ PROPVARIANT pv;
+ InitPropVariantFromString(app_id.c_str(), &pv);
+
+ IPropertyStore* pps;
+ SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function);
+ if (S_OK == SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps)) &&
+ S_OK == pps->SetValue(PKEY_AppUserModel_ID, pv)) {
+ pps->Commit();
+ }
+
+ // Cleanup.
+ base::UnloadNativeLibrary(shell32_library);
+}
+
} // namespace win_util
diff --git a/app/win_util.h b/app/win_util.h
index be5f325..c9340d1 100644
--- a/app/win_util.h
+++ b/app/win_util.h
@@ -288,6 +288,11 @@ gfx::Font GetWindowTitleFont();
// The thickness of an auto-hide taskbar in pixels.
extern const int kAutoHideTaskbarThicknessPx;
+// Sets the application id given as the Application Model ID for the window
+// specified. This method is used to insure that different web applications
+// do not group together on the Win7 task bar.
+void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd);
+
} // namespace win_util
#endif // APP_WIN_UTIL_H_
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 64d478a..c400d48 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -347,6 +347,12 @@ void Browser::OpenApplicationWindow(Profile* profile, const GURL& url) {
browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, true, -1,
false, NULL);
+#if defined(OS_WIN)
+ // Set the app user model id for this application to that of the application
+ // name. See http://crbug.com/7028.
+ win_util::SetAppIdForWindow(app_name, browser->window()->GetNativeHandle());
+#endif
+
TabContents* tab_contents = browser->GetSelectedTabContents();
tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
tab_contents->render_view_host()->SyncRendererPrefs();