diff options
-rw-r--r-- | app/win_util.cc | 14 | ||||
-rw-r--r-- | base/file_util.h | 10 | ||||
-rw-r--r-- | base/file_util_unittest.cc | 2 | ||||
-rw-r--r-- | base/file_util_win.cc | 129 | ||||
-rw-r--r-- | base/win_util.cc | 27 | ||||
-rw-r--r-- | base/win_util.h | 7 | ||||
-rw-r--r-- | chrome/browser/browser.cc | 16 | ||||
-rw-r--r-- | chrome/browser/browser.h | 4 | ||||
-rw-r--r-- | chrome/browser/user_data_manager.cc | 3 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.cc | 11 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.h | 5 | ||||
-rw-r--r-- | chrome/common/chrome_constants.cc | 9 | ||||
-rw-r--r-- | chrome/common/chrome_constants.h | 3 | ||||
-rw-r--r-- | chrome/installer/setup/install.cc | 3 | ||||
-rw-r--r-- | chrome/installer/util/shell_util.cc | 6 |
15 files changed, 130 insertions, 119 deletions
diff --git a/app/win_util.cc b/app/win_util.cc index b3b66c2..9e1587e 100644 --- a/app/win_util.cc +++ b/app/win_util.cc @@ -6,7 +6,6 @@ #include <commdlg.h> #include <dwmapi.h> -#include <propvarutil.h> #include <shellapi.h> #include <shlobj.h> @@ -47,10 +46,6 @@ 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) { @@ -854,7 +849,7 @@ gfx::Font GetWindowTitleFont() { } void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { - // This funcationality is only available on Win7+. + // This functionality is only available on Win7+. if (win_util::GetWinVersion() != win_util::WINVERSION_WIN7) return; @@ -879,20 +874,15 @@ void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { } // Set the application's name. - PROPVARIANT pv; - InitPropVariantFromString(app_id.c_str(), &pv); - 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 (S_OK == pps->SetValue(PKEY_AppUserModel_ID, pv)) - pps->Commit(); + SetAppIdForPropertyStore(pps, app_id.c_str()); } // Cleanup. - PropVariantClear(&pv); base::UnloadNativeLibrary(shell32_library); } diff --git a/base/file_util.h b/base/file_util.h index 60e9793..915065e 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -218,24 +218,24 @@ bool ResolveShortcut(FilePath* path); // 'source' is the existing file, 'destination' is the new link file to be // created; for best results pass the filename with the .lnk extension. // The 'icon' can specify a dll or exe in which case the icon index is the -// resource id. +// resource id. 'app_id' is the app model id for the shortcut on Win7. // Note that if the shortcut exists it will overwrite it. bool CreateShortcutLink(const wchar_t *source, const wchar_t *destination, const wchar_t *working_dir, const wchar_t *arguments, const wchar_t *description, const wchar_t *icon, - int icon_index); + int icon_index, const wchar_t* app_id); // Update a Windows shortcut (.LNK file). This method assumes the shortcut // link already exists (otherwise false is returned). Ensure you have // initialized COM before calling into this function. Only 'destination' // parameter is required, everything else can be NULL (but if everything else // is NULL no changes are made to the shortcut). 'destination' is the link -// file to be updated. For best results pass the filename with the .lnk -// extension. +// file to be updated. 'app_id' is the app model id for the shortcut on Win7. +// For best results pass the filename with the .lnk extension. bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination, const wchar_t *working_dir, const wchar_t *arguments, const wchar_t *description, const wchar_t *icon, - int icon_index); + int icon_index, const wchar_t* app_id); // Pins a shortcut to the Windows 7 taskbar. The shortcut file must already // exist and be a shortcut that points to an executable. diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 40a4163..6d57e2c 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -989,7 +989,7 @@ TEST_F(FileUtilTest, CreateShortcutTest) { CoInitialize(NULL); EXPECT_TRUE(file_util::CreateShortcutLink(target_file.value().c_str(), link_file.value().c_str(), - NULL, NULL, NULL, NULL, 0)); + NULL, NULL, NULL, NULL, 0, NULL)); FilePath resolved_name = link_file; EXPECT_TRUE(file_util::ResolveShortcut(&resolved_name)); std::wstring read_contents = ReadTextFile(resolved_name); diff --git a/base/file_util_win.cc b/base/file_util_win.cc index e050324..a320aca 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -5,6 +5,7 @@ #include "base/file_util.h" #include <windows.h> +#include <propvarutil.h> #include <shellapi.h> #include <shlobj.h> #include <time.h> @@ -12,6 +13,7 @@ #include "base/file_path.h" #include "base/logging.h" +#include "base/scoped_comptr_win.h" #include "base/scoped_handle.h" #include "base/string_util.h" #include "base/time.h" @@ -258,38 +260,32 @@ bool GetFileCreationLocalTime(const std::wstring& filename, bool ResolveShortcut(FilePath* path) { HRESULT result; - IShellLink *shell = NULL; + ScopedComPtr<IShellLink> i_shell_link; bool is_resolved = false; // Get pointer to the IShellLink interface - result = CoCreateInstance(CLSID_ShellLink, NULL, - CLSCTX_INPROC_SERVER, IID_IShellLink, - reinterpret_cast<LPVOID*>(&shell)); + result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL, + CLSCTX_INPROC_SERVER); if (SUCCEEDED(result)) { - IPersistFile *persist = NULL; + ScopedComPtr<IPersistFile> persist; // Query IShellLink for the IPersistFile interface - result = shell->QueryInterface(IID_IPersistFile, - reinterpret_cast<LPVOID*>(&persist)); + result = persist.QueryFrom(i_shell_link); if (SUCCEEDED(result)) { WCHAR temp_path[MAX_PATH]; // Load the shell link result = persist->Load(path->value().c_str(), STGM_READ); if (SUCCEEDED(result)) { // Try to find the target of a shortcut - result = shell->Resolve(0, SLR_NO_UI); + result = i_shell_link->Resolve(0, SLR_NO_UI); if (SUCCEEDED(result)) { - result = shell->GetPath(temp_path, MAX_PATH, + result = i_shell_link->GetPath(temp_path, MAX_PATH, NULL, SLGP_UNCPRIORITY); *path = FilePath(temp_path); is_resolved = true; } } } - if (persist) - persist->Release(); } - if (shell) - shell->Release(); return is_resolved; } @@ -297,58 +293,46 @@ bool ResolveShortcut(FilePath* path) { bool CreateShortcutLink(const wchar_t *source, const wchar_t *destination, const wchar_t *working_dir, const wchar_t *arguments, const wchar_t *description, const wchar_t *icon, - int icon_index) { - IShellLink *i_shell_link = NULL; - IPersistFile *i_persist_file = NULL; + int icon_index, const wchar_t* app_id) { + ScopedComPtr<IShellLink> i_shell_link; + ScopedComPtr<IPersistFile> i_persist_file; // Get pointer to the IShellLink interface - HRESULT result = CoCreateInstance(CLSID_ShellLink, NULL, - CLSCTX_INPROC_SERVER, IID_IShellLink, - reinterpret_cast<LPVOID*>(&i_shell_link)); + HRESULT result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL, + CLSCTX_INPROC_SERVER); if (FAILED(result)) return false; // Query IShellLink for the IPersistFile interface - result = i_shell_link->QueryInterface(IID_IPersistFile, - reinterpret_cast<LPVOID*>(&i_persist_file)); - if (FAILED(result)) { - i_shell_link->Release(); + result = i_persist_file.QueryFrom(i_shell_link); + if (FAILED(result)) return false; - } - if (FAILED(i_shell_link->SetPath(source))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (FAILED(i_shell_link->SetPath(source))) return false; - } - if (working_dir && FAILED(i_shell_link->SetWorkingDirectory(working_dir))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (working_dir && FAILED(i_shell_link->SetWorkingDirectory(working_dir))) return false; - } - if (arguments && FAILED(i_shell_link->SetArguments(arguments))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (arguments && FAILED(i_shell_link->SetArguments(arguments))) return false; - } - if (description && FAILED(i_shell_link->SetDescription(description))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (description && FAILED(i_shell_link->SetDescription(description))) return false; - } - if (icon && FAILED(i_shell_link->SetIconLocation(icon, icon_index))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (icon && FAILED(i_shell_link->SetIconLocation(icon, icon_index))) return false; + + if (app_id && (win_util::GetWinVersion() >= win_util::WINVERSION_WIN7)) { + ScopedComPtr<IPropertyStore> property_store; + if (FAILED(property_store.QueryFrom(i_shell_link))) + return false; + + if (!win_util::SetAppIdForPropertyStore(property_store, app_id)) + return false; } result = i_persist_file->Save(destination, TRUE); - i_persist_file->Release(); - i_shell_link->Release(); return SUCCEEDED(result); } @@ -356,60 +340,45 @@ bool CreateShortcutLink(const wchar_t *source, const wchar_t *destination, bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination, const wchar_t *working_dir, const wchar_t *arguments, const wchar_t *description, const wchar_t *icon, - int icon_index) { + int icon_index, const wchar_t* app_id) { // Get pointer to the IPersistFile interface and load existing link - IShellLink *i_shell_link = NULL; - if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, - CLSCTX_INPROC_SERVER, IID_IShellLink, - reinterpret_cast<LPVOID*>(&i_shell_link)))) + ScopedComPtr<IShellLink> i_shell_link; + if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL, + CLSCTX_INPROC_SERVER))) return false; - IPersistFile *i_persist_file = NULL; - if (FAILED(i_shell_link->QueryInterface( - IID_IPersistFile, reinterpret_cast<LPVOID*>(&i_persist_file)))) { - i_shell_link->Release(); + ScopedComPtr<IPersistFile> i_persist_file; + if (FAILED(i_persist_file.QueryFrom(i_shell_link))) return false; - } - if (FAILED(i_persist_file->Load(destination, 0))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (FAILED(i_persist_file->Load(destination, 0))) return false; - } - if (source && FAILED(i_shell_link->SetPath(source))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (source && FAILED(i_shell_link->SetPath(source))) return false; - } - if (working_dir && FAILED(i_shell_link->SetWorkingDirectory(working_dir))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (working_dir && FAILED(i_shell_link->SetWorkingDirectory(working_dir))) return false; - } - if (arguments && FAILED(i_shell_link->SetArguments(arguments))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (arguments && FAILED(i_shell_link->SetArguments(arguments))) return false; - } - if (description && FAILED(i_shell_link->SetDescription(description))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (description && FAILED(i_shell_link->SetDescription(description))) return false; - } - if (icon && FAILED(i_shell_link->SetIconLocation(icon, icon_index))) { - i_persist_file->Release(); - i_shell_link->Release(); + if (icon && FAILED(i_shell_link->SetIconLocation(icon, icon_index))) return false; + + if (app_id && win_util::GetWinVersion() >= win_util::WINVERSION_WIN7) { + ScopedComPtr<IPropertyStore> property_store; + if (FAILED(property_store.QueryFrom(i_shell_link))) + return false; + + if (!win_util::SetAppIdForPropertyStore(property_store, app_id)) + return false; } HRESULT result = i_persist_file->Save(destination, TRUE); - i_persist_file->Release(); - i_shell_link->Release(); return SUCCEEDED(result); } diff --git a/base/win_util.cc b/base/win_util.cc index e66dc1c..fa168d0 100644 --- a/base/win_util.cc +++ b/base/win_util.cc @@ -4,6 +4,7 @@ #include "base/win_util.h" +#include <propvarutil.h> #include <sddl.h> #include "base/logging.h" @@ -384,6 +385,32 @@ base::KeyboardCode WinToKeyboardCode(WORD keycode) { return static_cast<base::KeyboardCode>(keycode); } +bool SetAppIdForPropertyStore(IPropertyStore* property_store, + const wchar_t* app_id) { + 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); + + static const PROPERTYKEY kPKEYAppUserModelID = + { { 0x9F4C2855, 0x9F79, 0x4B39, + { 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, } }, 5 }; + + PROPVARIANT property_value; + if (FAILED(InitPropVariantFromString(app_id, &property_value))) + return false; + + HRESULT result = property_store->SetValue(kPKEYAppUserModelID, + property_value); + if (S_OK == result) + result = property_store->Commit(); + + PropVariantClear(&property_value); + return SUCCEEDED(result); +} + } // namespace win_util #ifdef _MSC_VER diff --git a/base/win_util.h b/base/win_util.h index 307eddb..bc10c38 100644 --- a/base/win_util.h +++ b/base/win_util.h @@ -7,6 +7,7 @@ #include <windows.h> #include <aclapi.h> +#include <shlobj.h> #include <string> @@ -110,6 +111,12 @@ std::wstring FormatLastWin32Error(); WORD KeyboardCodeToWin(base::KeyboardCode keycode); base::KeyboardCode WinToKeyboardCode(WORD keycode); +// Sets the application id in given IPropertyStore. The function is intended +// for tagging application/chromium shortcut, browser window and jump list for +// Win7. +bool SetAppIdForPropertyStore(IPropertyStore* property_store, + const wchar_t* app_id); + } // namespace win_util #endif // BASE_WIN_UTIL_H__ diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index c13c6c9..23c6a08 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -50,6 +50,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/window_sizer.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_constants.h" @@ -234,7 +235,7 @@ void Browser::CreateBrowserWindow() { // Set the app user model id for this application to that of the application // name. See http://crbug.com/7028. win_util::SetAppIdForWindow(type_ & TYPE_APP ? app_name_ : - l10n_util::GetString(IDS_PRODUCT_NAME), + std::wstring(chrome::kBrowserAppID), window()->GetNativeHandle()); #endif @@ -318,7 +319,7 @@ void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { // static void Browser::OpenApplicationWindow(Profile* profile, const GURL& url) { - std::wstring app_name = ComputeApplicationNameFromURL(url); + std::wstring app_name = web_app::GenerateApplicationNameFromURL(url); RegisterAppPrefs(app_name); Browser* browser = Browser::CreateForApp(app_name, profile, false); @@ -2094,7 +2095,7 @@ bool Browser::IsApplication() const { void Browser::ConvertContentsToApplication(TabContents* contents) { const GURL& url = contents->controller().GetActiveEntry()->url(); - std::wstring app_name = ComputeApplicationNameFromURL(url); + std::wstring app_name = web_app::GenerateApplicationNameFromURL(url); RegisterAppPrefs(app_name); DetachContents(contents); @@ -3027,15 +3028,6 @@ void Browser::CloseFrame() { } // static -std::wstring Browser::ComputeApplicationNameFromURL(const GURL& url) { - std::string t; - t.append(url.host()); - t.append("_"); - t.append(url.path()); - return UTF8ToWide(t); -} - -// static void Browser::RegisterAppPrefs(const std::wstring& app_name) { // A set of apps that we've already started. static std::set<std::wstring>* g_app_names = NULL; diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 3e52a59..4fac987 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -704,10 +704,6 @@ class Browser : public TabStripModelDelegate, // after a return to the message loop. void CloseFrame(); - // Compute a deterministic name based on the URL. We use this pseudo name - // as a key to store window location per application URLs. - static std::wstring ComputeApplicationNameFromURL(const GURL& url); - FRIEND_TEST(BrowserTest, NoTabsInPopups); // Create a preference dictionary for the provided application name. This is diff --git a/chrome/browser/user_data_manager.cc b/chrome/browser/user_data_manager.cc index bd2ba88..588f699 100644 --- a/chrome/browser/user_data_manager.cc +++ b/chrome/browser/user_data_manager.cc @@ -257,7 +257,8 @@ bool UserDataManager::CreateDesktopShortcutForProfile( args.c_str(), NULL, exe_path.c_str(), - 0); + 0, + chrome::kBrowserAppID); #else // TODO(port): should probably use freedesktop.org standard for desktop files. NOTIMPLEMENTED(); diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc index ebf8387..f15f95d 100644 --- a/chrome/browser/web_applications/web_app.cc +++ b/chrome/browser/web_applications/web_app.cc @@ -270,7 +270,8 @@ bool CreateShortcutTask::CreateShortcut() { wide_switchs.c_str(), shortcut_info_.description.c_str(), icon_file.value().c_str(), - 0); + 0, + web_app::GenerateApplicationNameFromURL(shortcut_info_.url).c_str()); } if (success && pin_to_taskbar) { @@ -291,6 +292,14 @@ bool CreateShortcutTask::CreateShortcut() { namespace web_app { +std::wstring GenerateApplicationNameFromURL(const GURL& url) { + std::string t; + t.append(url.host()); + t.append("_"); + t.append(url.path()); + return UTF8ToWide(t); +} + void CreateShortcut( const FilePath& data_dir, const ShellIntegration::ShortcutInfo& shortcut_info, diff --git a/chrome/browser/web_applications/web_app.h b/chrome/browser/web_applications/web_app.h index f6c9612..9bcfe0f 100644 --- a/chrome/browser/web_applications/web_app.h +++ b/chrome/browser/web_applications/web_app.h @@ -11,6 +11,11 @@ namespace web_app { +// Compute a deterministic name based on the URL. We use this pseudo name +// as a key to store window location per application URLs in Browser and +// as app id for BrowserWindow, shortcut and jump list. +std::wstring GenerateApplicationNameFromURL(const GURL& url); + // Callback after user dismisses CreateShortcutView. "true" indicates // shortcut is created successfully. Otherwise, it is false. typedef Callback1<bool>::Type CreateShortcutCallback; diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc index 81d03ea..1a936b5 100644 --- a/chrome/common/chrome_constants.cc +++ b/chrome/common/chrome_constants.cc @@ -59,6 +59,15 @@ const char kStatsFilename[] = "ChromeStats2"; const wchar_t kBrowserAppName[] = L"Chromium"; const char kStatsFilename[] = "ChromiumStats2"; #endif + +#if defined(OS_WIN) +#if defined(GOOGLE_CHROME_BUILD) +const wchar_t kBrowserAppID[] = L"Chrome"; +#else +const wchar_t kBrowserAppID[] = L"Chromium"; +#endif +#endif // defined(OS_WIN) + const wchar_t kMessageWindowClass[] = L"Chrome_MessageWindow"; const wchar_t kCrashReportLog[] = L"Reported Crashes.txt"; const wchar_t kTestingInterfaceDLL[] = L"testing_interface.dll"; diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h index 946767f..4473f32 100644 --- a/chrome/common/chrome_constants.h +++ b/chrome/common/chrome_constants.h @@ -21,6 +21,9 @@ extern const FilePath::CharType kHelperProcessExecutablePath[]; extern const FilePath::CharType kFrameworkName[]; #endif extern const wchar_t kBrowserAppName[]; +#if defined(OS_WIN) +extern const wchar_t kBrowserAppID[]; +#endif // defined(OS_WIN) extern const wchar_t kMessageWindowClass[]; extern const wchar_t kCrashReportLog[]; extern const wchar_t kTestingInterfaceDLL[]; diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index 002ccf1..143f5ba 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -279,7 +279,8 @@ bool CreateOrUpdateChromeShortcuts(const std::wstring& exe_path, uninstall_link.value().c_str(), NULL, arguments.c_str(), - NULL, setup_exe.c_str(), 0); + NULL, setup_exe.c_str(), 0, + NULL); } // Update Desktop and Quick Launch shortcuts. If --create-new-shortcuts diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc index f8022f0..d4b39cc 100644 --- a/chrome/installer/util/shell_util.cc +++ b/chrome/installer/util/shell_util.cc @@ -774,7 +774,8 @@ bool ShellUtil::UpdateChromeShortcut(const std::wstring& chrome_exe, NULL, // arguments description.c_str(), // description chrome_exe.c_str(), // icon file - icon_index); // icon index + icon_index, // icon index + chrome::kBrowserAppID); // app id } else { return file_util::UpdateShortcutLink(chrome_exe.c_str(), // target shortcut.c_str(), // shortcut @@ -782,6 +783,7 @@ bool ShellUtil::UpdateChromeShortcut(const std::wstring& chrome_exe, NULL, // arguments description.c_str(), // description chrome_exe.c_str(), // icon file - 0); // icon index + 0, // icon index + chrome::kBrowserAppID); // app id } } |