| 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 <shlwapi.h> | 8 #include <shlwapi.h> |
| 9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
| 10 #include <propkey.h> // Needs to come after shobjidl.h. | 10 #include <propkey.h> // Needs to come after shobjidl.h. |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 for (size_t i = 0; i < arraysize(kLocations); ++i) { | 186 for (size_t i = 0; i < arraysize(kLocations); ++i) { |
| 187 base::FilePath path; | 187 base::FilePath path; |
| 188 if (!PathService::Get(kLocations[i].location_id, &path)) { | 188 if (!PathService::Get(kLocations[i].location_id, &path)) { |
| 189 NOTREACHED(); | 189 NOTREACHED(); |
| 190 continue; | 190 continue; |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (kLocations[i].sub_dir) | 193 if (kLocations[i].sub_dir) |
| 194 path = path.Append(kLocations[i].sub_dir); | 194 path = path.Append(kLocations[i].sub_dir); |
| 195 | 195 |
| 196 bool check_dual_mode = kLocations[i].location_id == base::DIR_START_MENU || | 196 // Clear |dual_mode| property from taskbar pins as those are user-level |
| 197 kLocations[i].location_id == base::DIR_TASKBAR_PINS; | 197 // shortcuts which aren't handled by the installer. |
| 198 bool clear_dual_mode = kLocations[i].location_id == base::DIR_TASKBAR_PINS; |
| 198 ShellIntegration::MigrateShortcutsInPathInternal(chrome_exe, path, | 199 ShellIntegration::MigrateShortcutsInPathInternal(chrome_exe, path, |
| 199 check_dual_mode); | 200 clear_dual_mode); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 // Windows 8 introduced a new protocol->executable binding system which cannot | 204 // Windows 8 introduced a new protocol->executable binding system which cannot |
| 204 // be retrieved in the HKCR registry subkey method implemented below. We call | 205 // be retrieved in the HKCR registry subkey method implemented below. We call |
| 205 // AssocQueryString with the new Win8-only flag ASSOCF_IS_PROTOCOL instead. | 206 // AssocQueryString with the new Win8-only flag ASSOCF_IS_PROTOCOL instead. |
| 206 base::string16 GetAppForProtocolUsingAssocQuery(const GURL& url) { | 207 base::string16 GetAppForProtocolUsingAssocQuery(const GURL& url) { |
| 207 base::string16 url_scheme = base::ASCIIToUTF16(url.scheme()); | 208 base::string16 url_scheme = base::ASCIIToUTF16(url.scheme()); |
| 208 // Don't attempt to query protocol association on an empty string. | 209 // Don't attempt to query protocol association on an empty string. |
| 209 if (url_scheme.empty()) | 210 if (url_scheme.empty()) |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 static const int64_t kMigrateChromiumShortcutsDelaySeconds = 15; | 519 static const int64_t kMigrateChromiumShortcutsDelaySeconds = 15; |
| 519 BrowserThread::PostDelayedTask( | 520 BrowserThread::PostDelayedTask( |
| 520 BrowserThread::FILE, FROM_HERE, | 521 BrowserThread::FILE, FROM_HERE, |
| 521 base::Bind(&MigrateChromiumShortcutsCallback), | 522 base::Bind(&MigrateChromiumShortcutsCallback), |
| 522 base::TimeDelta::FromSeconds(kMigrateChromiumShortcutsDelaySeconds)); | 523 base::TimeDelta::FromSeconds(kMigrateChromiumShortcutsDelaySeconds)); |
| 523 } | 524 } |
| 524 | 525 |
| 525 int ShellIntegration::MigrateShortcutsInPathInternal( | 526 int ShellIntegration::MigrateShortcutsInPathInternal( |
| 526 const base::FilePath& chrome_exe, | 527 const base::FilePath& chrome_exe, |
| 527 const base::FilePath& path, | 528 const base::FilePath& path, |
| 528 bool check_dual_mode) { | 529 bool clear_dual_mode) { |
| 529 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7); | 530 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7); |
| 530 | 531 |
| 531 // Enumerate all pinned shortcuts in the given path directly. | 532 // Enumerate all pinned shortcuts in the given path directly. |
| 532 base::FileEnumerator shortcuts_enum( | 533 base::FileEnumerator shortcuts_enum( |
| 533 path, false, // not recursive | 534 path, false, // not recursive |
| 534 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); | 535 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); |
| 535 | 536 |
| 536 bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe); | 537 bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe); |
| 537 | 538 |
| 538 int shortcuts_migrated = 0; | 539 int shortcuts_migrated = 0; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 case VT_LPWSTR: | 592 case VT_LPWSTR: |
| 592 if (expected_app_id != base::string16(propvariant.get().pwszVal)) | 593 if (expected_app_id != base::string16(propvariant.get().pwszVal)) |
| 593 updated_properties.set_app_id(expected_app_id); | 594 updated_properties.set_app_id(expected_app_id); |
| 594 break; | 595 break; |
| 595 default: | 596 default: |
| 596 NOTREACHED(); | 597 NOTREACHED(); |
| 597 continue; | 598 continue; |
| 598 } | 599 } |
| 599 } | 600 } |
| 600 | 601 |
| 601 // Only set dual mode if the expected app id is the default app id. | 602 // Clear |dual_mode| property from any shortcuts that previously had it (as |
| 603 // requested by caller). |
| 602 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 604 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 603 base::string16 default_chromium_model_id( | 605 base::string16 default_chromium_model_id( |
| 604 ShellUtil::GetBrowserModelId(dist, is_per_user_install)); | 606 ShellUtil::GetBrowserModelId(dist, is_per_user_install)); |
| 605 if (check_dual_mode && expected_app_id == default_chromium_model_id) { | 607 if (clear_dual_mode && expected_app_id == default_chromium_model_id) { |
| 606 // TODO(scottmg): Simplify with no Metro: http://crbug.com/558054. | |
| 607 const bool dual_mode_desired = false; | |
| 608 propvariant.Reset(); | 608 propvariant.Reset(); |
| 609 if (property_store->GetValue(PKEY_AppUserModel_IsDualMode, | 609 if (property_store->GetValue(PKEY_AppUserModel_IsDualMode, |
| 610 propvariant.Receive()) != S_OK) { | 610 propvariant.Receive()) != S_OK) { |
| 611 // When in doubt, prefer to not update the shortcut. | 611 // When in doubt, prefer to not update the shortcut. |
| 612 NOTREACHED(); | 612 NOTREACHED(); |
| 613 continue; | 613 continue; |
| 614 } else { | 614 } |
| 615 switch (propvariant.get().vt) { | 615 if (propvariant.get().vt == VT_BOOL && |
| 616 case VT_EMPTY: | 616 !!propvariant.get().boolVal) { |
| 617 // If dual_mode is not set at all, make sure it gets set to true if | 617 updated_properties.set_dual_mode(false); |
| 618 // desired. | |
| 619 if (dual_mode_desired) | |
| 620 updated_properties.set_dual_mode(true); | |
| 621 break; | |
| 622 case VT_BOOL: | |
| 623 // Make sure dual_mode is set as desired. | |
| 624 if ((!!propvariant.get().boolVal) != dual_mode_desired) | |
| 625 updated_properties.set_dual_mode(dual_mode_desired); | |
| 626 break; | |
| 627 default: | |
| 628 NOTREACHED(); | |
| 629 continue; | |
| 630 } | |
| 631 } | 618 } |
| 632 } | 619 } |
| 633 | 620 |
| 634 persist_file.Release(); | 621 persist_file.Release(); |
| 635 shell_link.Release(); | 622 shell_link.Release(); |
| 636 | 623 |
| 637 // Update the shortcut if some of its properties need to be updated. | 624 // Update the shortcut if some of its properties need to be updated. |
| 638 if (updated_properties.options && | 625 if (updated_properties.options && |
| 639 base::win::CreateOrUpdateShortcutLink( | 626 base::win::CreateOrUpdateShortcutLink( |
| 640 shortcut, updated_properties, | 627 shortcut, updated_properties, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 if (!RegisterBrowser()) | 727 if (!RegisterBrowser()) |
| 741 return false; | 728 return false; |
| 742 | 729 |
| 743 if (ShouldResetDefaultBrowser()) | 730 if (ShouldResetDefaultBrowser()) |
| 744 ResetDefaultBrowser(); | 731 ResetDefaultBrowser(); |
| 745 | 732 |
| 746 base::CommandLine cmdline(base::FilePath(L"openwith.exe")); | 733 base::CommandLine cmdline(base::FilePath(L"openwith.exe")); |
| 747 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); | 734 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); |
| 748 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); | 735 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); |
| 749 } | 736 } |
| OLD | NEW |