| 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" |
| 23 #include "base/win/metro_exports.h" |
| 21 #include "base/win/registry.h" | 24 #include "base/win/registry.h" |
| 22 #include "base/win/scoped_co_mem.h" | 25 #include "base/win/scoped_co_mem.h" |
| 23 #include "base/win/scoped_comptr.h" | 26 #include "base/win/scoped_comptr.h" |
| 24 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
| 25 #include "chrome/browser/web_applications/web_app.h" | 28 #include "chrome/browser/web_applications/web_app.h" |
| 26 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 27 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_paths_internal.h" | 31 #include "chrome/common/chrome_paths_internal.h" |
| 29 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/installer/setup/setup_util.h" | 33 #include "chrome/installer/setup/setup_util.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 continue; | 383 continue; |
| 381 } | 384 } |
| 382 | 385 |
| 383 if (kLocations[i].sub_dir) | 386 if (kLocations[i].sub_dir) |
| 384 path = path.Append(kLocations[i].sub_dir); | 387 path = path.Append(kLocations[i].sub_dir); |
| 385 | 388 |
| 386 MigrateWin7ShortcutsInPath(chrome_exe, path); | 389 MigrateWin7ShortcutsInPath(chrome_exe, path); |
| 387 } | 390 } |
| 388 } | 391 } |
| 389 | 392 |
| 393 // Activates the application with the given AppUserModelId. |
| 394 bool ActivateApplication(const string16& app_id) { |
| 395 // Not supported when running in metro mode. |
| 396 // TODO(grt) This should perhaps check that this Chrome isn't in metro mode |
| 397 // or, if it is, that |app_id| doesn't identify this Chrome. |
| 398 if (base::win::GetMetroModule()) |
| 399 return false; |
| 400 |
| 401 // Delegate to metro_driver, which has the brains to invoke the activation |
| 402 // wizardry. |
| 403 bool success = false; |
| 404 const FilePath metro_driver_path(chrome::kMetroDriverDll); |
| 405 base::ScopedNativeLibrary metro_driver(metro_driver_path); |
| 406 if (!metro_driver.is_valid()) { |
| 407 PLOG(ERROR) << "Failed to load metro_driver."; |
| 408 } else { |
| 409 metro_exports::ActivateApplicationFn activate_application = |
| 410 reinterpret_cast<metro_exports::ActivateApplicationFn>( |
| 411 metro_driver.GetFunctionPointer( |
| 412 metro_exports::kActivateApplication)); |
| 413 if (!activate_application) { |
| 414 PLOG(ERROR) << "Failed to find activation method in metro_driver."; |
| 415 } else { |
| 416 HRESULT hr = activate_application(app_id.c_str()); |
| 417 if (FAILED(hr)) { |
| 418 LOG(ERROR) << "Failed to activate " << app_id |
| 419 << "; hr=0x" << std::hex << hr; |
| 420 } else { |
| 421 success = true; |
| 422 } |
| 423 } |
| 424 } |
| 425 return success; |
| 426 } |
| 427 |
| 390 } // namespace | 428 } // namespace |
| 391 | 429 |
| 392 bool ShellIntegration::CanSetAsDefaultBrowser() { | 430 bool ShellIntegration::CanSetAsDefaultBrowser() { |
| 393 return BrowserDistribution::GetDistribution()->CanSetAsDefault(); | 431 return BrowserDistribution::GetDistribution()->CanSetAsDefault(); |
| 394 } | 432 } |
| 395 | 433 |
| 396 bool ShellIntegration::SetAsDefaultBrowser() { | 434 bool ShellIntegration::SetAsDefaultBrowser() { |
| 397 FilePath chrome_exe; | 435 FilePath chrome_exe; |
| 398 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 436 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 399 LOG(ERROR) << "Error getting app exe path"; | 437 LOG(ERROR) << "Error getting app exe path"; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 568 } |
| 531 | 569 |
| 532 void ShellIntegration::MigrateChromiumShortcuts() { | 570 void ShellIntegration::MigrateChromiumShortcuts() { |
| 533 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 571 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 534 return; | 572 return; |
| 535 | 573 |
| 536 BrowserThread::PostTask( | 574 BrowserThread::PostTask( |
| 537 BrowserThread::FILE, FROM_HERE, | 575 BrowserThread::FILE, FROM_HERE, |
| 538 base::Bind(&MigrateChromiumShortcutsCallback)); | 576 base::Bind(&MigrateChromiumShortcutsCallback)); |
| 539 } | 577 } |
| 578 |
| 579 bool ShellIntegration::ActivateMetroChrome() { |
| 580 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 581 const string16 app_id(dist->GetBrowserAppId()); |
| 582 return ActivateApplication(app_id); |
| 583 } |
| OLD | NEW |