Chromium Code Reviews| Index: chrome/browser/shell_integration_win.cc |
| diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc |
| index 869b5b51311f5ff8019a259bc8d3301c07c44629..b8745c1a3cc21f1394ff20e5c4013183e1895989 100644 |
| --- a/chrome/browser/shell_integration_win.cc |
| +++ b/chrome/browser/shell_integration_win.cc |
| @@ -14,10 +14,12 @@ |
| #include "base/file_util.h" |
| #include "base/message_loop.h" |
| #include "base/path_service.h" |
| +#include "base/scoped_native_library.h" |
| #include "base/string_number_conversions.h" |
| #include "base/string_util.h" |
| #include "base/stringprintf.h" |
| #include "base/utf_string_conversions.h" |
| +#include "base/win/metro.h" |
| #include "base/win/registry.h" |
| #include "base/win/scoped_co_mem.h" |
| #include "base/win/scoped_comptr.h" |
| @@ -41,6 +43,9 @@ using content::BrowserThread; |
| namespace { |
| +// The name of the "ActivateApplication" entrypoint in metro_driver.dll. |
| +const char kActivateApplication[] = "ActivateApplication"; |
|
robertshield
2012/05/31 15:14:33
could we move this method name and the typedef of
|
| + |
| // Gets the short (8.3) form of |path|, putting the result in |short_path| and |
| // returning true on success. |short_path| is not modified on failure. |
| bool ShortNameFromPath(const FilePath& path, string16* short_path) { |
| @@ -387,6 +392,41 @@ void MigrateChromiumShortcutsCallback() { |
| } |
| } |
| +// Activates the application with the given AppUserModelId. |
| +bool ActivateApplication(const string16& app_id) { |
| + // Not supported when running in metro mode. |
| + // TODO(grt) This should perhaps check that this Chrome isn't in metro mode |
| + // or, if it is, that |app_id| doesn't identify this Chrome. |
| + if (base::win::GetMetroModule()) |
| + return false; |
| + |
| + // Delegate to metro_driver, which has the brains to invoke the activation |
| + // wizardry. |
| + bool success = false; |
| + const FilePath metro_driver_path(chrome::kMetroDriverDll); |
| + base::ScopedNativeLibrary metro_driver(metro_driver_path); |
| + if (!metro_driver.is_valid()) { |
| + PLOG(ERROR) << "Failed to load metro_driver."; |
| + } else { |
| + typedef HRESULT (*ActivateApplicationFn)(const wchar_t*); |
| + ActivateApplicationFn activate_application = |
| + reinterpret_cast<ActivateApplicationFn>( |
| + metro_driver.GetFunctionPointer(kActivateApplication)); |
| + if (!activate_application) { |
| + PLOG(ERROR) << "Failed to find activation method in metro_driver."; |
| + } else { |
| + HRESULT hr = activate_application(app_id.c_str()); |
| + if (FAILED(hr)) { |
| + LOG(ERROR) << "Failed to activate " << app_id |
| + << "; hr=0x" << std::hex << hr; |
| + } else { |
| + success = true; |
| + } |
| + } |
| + } |
| + return success; |
| +} |
| + |
| } // namespace |
| bool ShellIntegration::CanSetAsDefaultBrowser() { |
| @@ -537,3 +577,9 @@ void ShellIntegration::MigrateChromiumShortcuts() { |
| BrowserThread::FILE, FROM_HERE, |
| base::Bind(&MigrateChromiumShortcutsCallback)); |
| } |
| + |
| +bool ShellIntegration::ActivateMetroChrome() { |
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| + const string16 app_id(dist->GetBrowserAppId()); |
| + return ActivateApplication(app_id); |
| +} |