Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shobjidl.h> | 8 #include <shobjidl.h> |
| 9 #include <propkey.h> | 9 #include <propkey.h> |
| 10 #include <propvarutil.h> | 10 #include <propvarutil.h> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/scoped_native_library.h" | |
| 17 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 19 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
| 20 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "base/win/metro.h" | |
| 21 #include "base/win/registry.h" | 23 #include "base/win/registry.h" |
| 22 #include "base/win/scoped_co_mem.h" | 24 #include "base/win/scoped_co_mem.h" |
| 23 #include "base/win/scoped_comptr.h" | 25 #include "base/win/scoped_comptr.h" |
| 24 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
| 25 #include "chrome/browser/web_applications/web_app.h" | 27 #include "chrome/browser/web_applications/web_app.h" |
| 26 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 27 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_paths_internal.h" | 30 #include "chrome/common/chrome_paths_internal.h" |
| 29 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/installer/setup/setup_util.h" | 32 #include "chrome/installer/setup/setup_util.h" |
| 31 #include "chrome/installer/util/browser_distribution.h" | 33 #include "chrome/installer/util/browser_distribution.h" |
| 32 #include "chrome/installer/util/create_reg_key_work_item.h" | 34 #include "chrome/installer/util/create_reg_key_work_item.h" |
| 33 #include "chrome/installer/util/set_reg_value_work_item.h" | 35 #include "chrome/installer/util/set_reg_value_work_item.h" |
| 34 #include "chrome/installer/util/shell_util.h" | 36 #include "chrome/installer/util/shell_util.h" |
| 35 #include "chrome/installer/util/util_constants.h" | 37 #include "chrome/installer/util/util_constants.h" |
| 36 #include "chrome/installer/util/work_item.h" | 38 #include "chrome/installer/util/work_item.h" |
| 37 #include "chrome/installer/util/work_item_list.h" | 39 #include "chrome/installer/util/work_item_list.h" |
| 38 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 39 | 41 |
| 40 using content::BrowserThread; | 42 using content::BrowserThread; |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 46 // The name of the "ActivateApplication" entrypoint in metro_driver.dll. | |
| 47 const char kActivateApplication[] = "ActivateApplication"; | |
|
robertshield
2012/05/31 15:14:33
could we move this method name and the typedef of
| |
| 48 | |
| 44 // Gets the short (8.3) form of |path|, putting the result in |short_path| and | 49 // Gets the short (8.3) form of |path|, putting the result in |short_path| and |
| 45 // returning true on success. |short_path| is not modified on failure. | 50 // returning true on success. |short_path| is not modified on failure. |
| 46 bool ShortNameFromPath(const FilePath& path, string16* short_path) { | 51 bool ShortNameFromPath(const FilePath& path, string16* short_path) { |
| 47 DCHECK(short_path); | 52 DCHECK(short_path); |
| 48 string16 result(MAX_PATH, L'\0'); | 53 string16 result(MAX_PATH, L'\0'); |
| 49 DWORD short_length = GetShortPathName(path.value().c_str(), &result[0], | 54 DWORD short_length = GetShortPathName(path.value().c_str(), &result[0], |
| 50 result.size()); | 55 result.size()); |
| 51 if (short_length == 0 || short_length > result.size()) { | 56 if (short_length == 0 || short_length > result.size()) { |
| 52 PLOG(ERROR) << "Error getting short (8.3) path"; | 57 PLOG(ERROR) << "Error getting short (8.3) path"; |
| 53 return false; | 58 return false; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 continue; | 385 continue; |
| 381 } | 386 } |
| 382 | 387 |
| 383 if (kLocations[i].sub_dir) | 388 if (kLocations[i].sub_dir) |
| 384 path = path.Append(kLocations[i].sub_dir); | 389 path = path.Append(kLocations[i].sub_dir); |
| 385 | 390 |
| 386 MigrateWin7ShortcutsInPath(chrome_exe, path); | 391 MigrateWin7ShortcutsInPath(chrome_exe, path); |
| 387 } | 392 } |
| 388 } | 393 } |
| 389 | 394 |
| 395 // Activates the application with the given AppUserModelId. | |
| 396 bool ActivateApplication(const string16& app_id) { | |
| 397 // Not supported when running in metro mode. | |
| 398 // TODO(grt) This should perhaps check that this Chrome isn't in metro mode | |
| 399 // or, if it is, that |app_id| doesn't identify this Chrome. | |
| 400 if (base::win::GetMetroModule()) | |
| 401 return false; | |
| 402 | |
| 403 // Delegate to metro_driver, which has the brains to invoke the activation | |
| 404 // wizardry. | |
| 405 bool success = false; | |
| 406 const FilePath metro_driver_path(chrome::kMetroDriverDll); | |
| 407 base::ScopedNativeLibrary metro_driver(metro_driver_path); | |
| 408 if (!metro_driver.is_valid()) { | |
| 409 PLOG(ERROR) << "Failed to load metro_driver."; | |
| 410 } else { | |
| 411 typedef HRESULT (*ActivateApplicationFn)(const wchar_t*); | |
| 412 ActivateApplicationFn activate_application = | |
| 413 reinterpret_cast<ActivateApplicationFn>( | |
| 414 metro_driver.GetFunctionPointer(kActivateApplication)); | |
| 415 if (!activate_application) { | |
| 416 PLOG(ERROR) << "Failed to find activation method in metro_driver."; | |
| 417 } else { | |
| 418 HRESULT hr = activate_application(app_id.c_str()); | |
| 419 if (FAILED(hr)) { | |
| 420 LOG(ERROR) << "Failed to activate " << app_id | |
| 421 << "; hr=0x" << std::hex << hr; | |
| 422 } else { | |
| 423 success = true; | |
| 424 } | |
| 425 } | |
| 426 } | |
| 427 return success; | |
| 428 } | |
| 429 | |
| 390 } // namespace | 430 } // namespace |
| 391 | 431 |
| 392 bool ShellIntegration::CanSetAsDefaultBrowser() { | 432 bool ShellIntegration::CanSetAsDefaultBrowser() { |
| 393 return BrowserDistribution::GetDistribution()->CanSetAsDefault(); | 433 return BrowserDistribution::GetDistribution()->CanSetAsDefault(); |
| 394 } | 434 } |
| 395 | 435 |
| 396 bool ShellIntegration::SetAsDefaultBrowser() { | 436 bool ShellIntegration::SetAsDefaultBrowser() { |
| 397 FilePath chrome_exe; | 437 FilePath chrome_exe; |
| 398 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 438 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 399 LOG(ERROR) << "Error getting app exe path"; | 439 LOG(ERROR) << "Error getting app exe path"; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 } | 570 } |
| 531 | 571 |
| 532 void ShellIntegration::MigrateChromiumShortcuts() { | 572 void ShellIntegration::MigrateChromiumShortcuts() { |
| 533 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 573 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 534 return; | 574 return; |
| 535 | 575 |
| 536 BrowserThread::PostTask( | 576 BrowserThread::PostTask( |
| 537 BrowserThread::FILE, FROM_HERE, | 577 BrowserThread::FILE, FROM_HERE, |
| 538 base::Bind(&MigrateChromiumShortcutsCallback)); | 578 base::Bind(&MigrateChromiumShortcutsCallback)); |
| 539 } | 579 } |
| 580 | |
| 581 bool ShellIntegration::ActivateMetroChrome() { | |
| 582 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 583 const string16 app_id(dist->GetBrowserAppId()); | |
| 584 return ActivateApplication(app_id); | |
| 585 } | |
| OLD | NEW |