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> | |
| 11 #include <tchar.h> | |
| 12 #include <strsafe.h> | |
| 13 | 10 |
| 14 #include "base/bind.h" | 11 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 16 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 17 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 18 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 19 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 20 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 21 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 22 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 23 #include "base/win/registry.h" | 20 #include "base/win/registry.h" |
| 24 #include "base/win/scoped_comptr.h" | 21 #include "base/win/scoped_comptr.h" |
| 25 #include "base/win/shortcut.h" | 22 #include "base/win/shortcut.h" |
| 26 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 27 #include "chrome/browser/web_applications/web_app.h" | 24 #include "chrome/browser/web_applications/web_app.h" |
| 28 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/common/chrome_paths_internal.h" | 26 #include "chrome/common/chrome_paths_internal.h" |
| 30 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/installer/setup/setup_util.h" | 28 #include "chrome/installer/setup/setup_util.h" |
| 32 #include "chrome/installer/util/browser_distribution.h" | 29 #include "chrome/installer/util/browser_distribution.h" |
| 33 #include "chrome/installer/util/create_reg_key_work_item.h" | 30 #include "chrome/installer/util/create_reg_key_work_item.h" |
| 34 #include "chrome/installer/util/install_util.h" | 31 #include "chrome/installer/util/install_util.h" |
| 35 #include "chrome/installer/util/set_reg_value_work_item.h" | 32 #include "chrome/installer/util/set_reg_value_work_item.h" |
| 36 #include "chrome/installer/util/shell_util.h" | 33 #include "chrome/installer/util/shell_util.h" |
| 37 #include "chrome/installer/util/util_constants.h" | 34 #include "chrome/installer/util/util_constants.h" |
| 38 #include "chrome/installer/util/work_item.h" | 35 #include "chrome/installer/util/work_item.h" |
| 39 #include "chrome/installer/util/work_item_list.h" | 36 #include "chrome/installer/util/work_item_list.h" |
| 40 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 41 | 38 |
| 42 // propsys.lib is required for PropvariantTo*(). | |
| 43 #pragma comment(lib, "propsys.lib") | |
| 44 | |
| 45 using content::BrowserThread; | 39 using content::BrowserThread; |
| 46 | 40 |
| 47 namespace { | 41 namespace { |
| 48 | 42 |
| 49 #if defined(GOOGLE_CHROME_BUILD) | 43 #if defined(GOOGLE_CHROME_BUILD) |
| 50 const wchar_t kAppListAppName[] = L"ChromeAppList"; | 44 const wchar_t kAppListAppName[] = L"ChromeAppList"; |
| 51 #else | 45 #else |
| 52 const wchar_t kAppListAppName[] = L"ChromiumAppList"; | 46 const wchar_t kAppListAppName[] = L"ChromiumAppList"; |
| 53 #endif | 47 #endif |
| 54 | 48 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 file_util::FileEnumerator shortcuts_enum( | 372 file_util::FileEnumerator shortcuts_enum( |
| 379 path, false, // not recursive | 373 path, false, // not recursive |
| 380 file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); | 374 file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); |
| 381 | 375 |
| 382 bool is_per_user_install = | 376 bool is_per_user_install = |
| 383 InstallUtil::IsPerUserInstall(chrome_exe.value().c_str()); | 377 InstallUtil::IsPerUserInstall(chrome_exe.value().c_str()); |
| 384 | 378 |
| 385 int shortcuts_migrated = 0; | 379 int shortcuts_migrated = 0; |
| 386 FilePath target_path; | 380 FilePath target_path; |
| 387 string16 arguments; | 381 string16 arguments; |
| 388 string16 existing_app_id; | |
| 389 for (FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); | 382 for (FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); |
| 390 shortcut = shortcuts_enum.Next()) { | 383 shortcut = shortcuts_enum.Next()) { |
| 391 // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once | 384 // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once |
| 392 // it is fixed to work with FilePaths with spaces. | 385 // it is fixed to work with FilePaths with spaces. |
| 393 if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) || | 386 if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) || |
| 394 chrome_exe != target_path) { | 387 chrome_exe != target_path) { |
| 395 continue; | 388 continue; |
| 396 } | 389 } |
| 397 CommandLine command_line(CommandLine::FromString(base::StringPrintf( | 390 CommandLine command_line(CommandLine::FromString(base::StringPrintf( |
| 398 L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str()))); | 391 L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str()))); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 420 | 413 |
| 421 // Validate the existing app id for the shortcut. | 414 // Validate the existing app id for the shortcut. |
| 422 base::win::ScopedComPtr<IPropertyStore> property_store; | 415 base::win::ScopedComPtr<IPropertyStore> property_store; |
| 423 PROPVARIANT pv_app_id; | 416 PROPVARIANT pv_app_id; |
| 424 PropVariantInit(&pv_app_id); | 417 PropVariantInit(&pv_app_id); |
| 425 if (FAILED(property_store.QueryFrom(shell_link)) || | 418 if (FAILED(property_store.QueryFrom(shell_link)) || |
| 426 property_store->GetValue(PKEY_AppUserModel_ID, &pv_app_id) != S_OK) { | 419 property_store->GetValue(PKEY_AppUserModel_ID, &pv_app_id) != S_OK) { |
| 427 // When in doubt, prefer not updating the shortcut. | 420 // When in doubt, prefer not updating the shortcut. |
| 428 NOTREACHED(); | 421 NOTREACHED(); |
| 429 continue; | 422 continue; |
| 430 } else if (pv_app_id.vt == VT_EMPTY) { | |
| 431 // If there is no app_id set, set our app_id if one is expected. | |
| 432 if (!expected_app_id.empty()) | |
| 433 updated_properties.set_app_id(expected_app_id); | |
| 434 } else { | 423 } else { |
| 435 // Validate that the existing app_id is the expected app_id; if not, set | 424 switch (pv_app_id.vt) { |
| 436 // the expected app_id on the shortcut. | 425 case VT_EMPTY: |
| 437 size_t expected_size = expected_app_id.size() + 1; | 426 // If there is no app_id set, set our app_id if one is expected. |
| 438 HRESULT result = PropVariantToString( | 427 if (!expected_app_id.empty()) |
| 439 pv_app_id, WriteInto(&existing_app_id, expected_size), expected_size); | 428 updated_properties.set_app_id(expected_app_id); |
| 429 break; | |
| 430 case VT_LPWSTR: | |
| 431 if (expected_app_id != string16(pv_app_id.pwszVal)) | |
| 432 updated_properties.set_app_id(expected_app_id); | |
| 433 break; | |
| 434 default: | |
| 435 NOTREACHED(); | |
|
grt (UTC plus 2)
2013/01/08 04:21:45
PropVariantClear(&pv_app_id) here to ensure that w
gab
2013/01/08 22:33:23
Added a ScopedPropVariant to base/win.
| |
| 436 continue; | |
| 437 } | |
| 440 PropVariantClear(&pv_app_id); | 438 PropVariantClear(&pv_app_id); |
| 441 if (result != S_OK && result != STRSAFE_E_INSUFFICIENT_BUFFER) { | |
| 442 // Accept the STRSAFE_E_INSUFFICIENT_BUFFER error state as it means the | |
| 443 // existing appid is longer than |expected_app_id| and thus we will | |
| 444 // simply assume inequality. | |
| 445 NOTREACHED(); | |
| 446 continue; | |
| 447 } else if (result == STRSAFE_E_INSUFFICIENT_BUFFER || | |
| 448 expected_app_id != existing_app_id) { | |
| 449 updated_properties.set_app_id(expected_app_id); | |
| 450 } | |
| 451 } | 439 } |
| 452 | 440 |
| 453 if (check_dual_mode) { | 441 if (check_dual_mode) { |
| 454 BOOL existing_dual_mode; | |
| 455 PROPVARIANT pv_dual_mode; | 442 PROPVARIANT pv_dual_mode; |
| 456 PropVariantInit(&pv_dual_mode); | 443 PropVariantInit(&pv_dual_mode); |
| 457 if (property_store->GetValue(PKEY_AppUserModel_IsDualMode, | 444 if (property_store->GetValue(PKEY_AppUserModel_IsDualMode, |
| 458 &pv_dual_mode) != S_OK) { | 445 &pv_dual_mode) != S_OK) { |
| 459 // When in doubt, prefer to not update the shortcut. | 446 // When in doubt, prefer to not update the shortcut. |
| 460 NOTREACHED(); | 447 NOTREACHED(); |
| 461 continue; | 448 continue; |
| 462 } else if (pv_dual_mode.vt == VT_EMPTY) { | |
| 463 // If dual_mode is not set at all, make sure it gets set to true. | |
| 464 updated_properties.set_dual_mode(true); | |
| 465 } else { | 449 } else { |
| 466 // If it is set to false, make sure it gets set to true as well. | 450 switch (pv_dual_mode.vt) { |
| 467 if (PropVariantToBoolean(pv_dual_mode, &existing_dual_mode) != S_OK) { | 451 case VT_EMPTY: |
| 468 NOTREACHED(); | 452 // If dual_mode is not set at all, make sure it gets set to true. |
| 469 continue; | 453 updated_properties.set_dual_mode(true); |
| 454 break; | |
| 455 case VT_BOOL: | |
| 456 // If it is set to false, make sure it gets set to true as well. | |
| 457 if (!pv_dual_mode.boolVal) | |
| 458 updated_properties.set_dual_mode(true); | |
| 459 break; | |
| 460 default: | |
| 461 NOTREACHED(); | |
|
grt (UTC plus 2)
2013/01/08 04:21:45
same comment here
gab
2013/01/08 22:33:23
Done.
| |
| 462 continue; | |
| 470 } | 463 } |
| 471 PropVariantClear(&pv_dual_mode); | 464 PropVariantClear(&pv_dual_mode); |
| 472 if (!existing_dual_mode) | |
| 473 updated_properties.set_dual_mode(true); | |
| 474 } | 465 } |
| 475 } | 466 } |
| 476 | 467 |
| 477 persist_file.Release(); | 468 persist_file.Release(); |
| 478 shell_link.Release(); | 469 shell_link.Release(); |
| 479 | 470 |
| 480 // Update the shortcut if some of its properties need to be updated. | 471 // Update the shortcut if some of its properties need to be updated. |
| 481 if (updated_properties.options && | 472 if (updated_properties.options && |
| 482 base::win::CreateOrUpdateShortcutLink( | 473 base::win::CreateOrUpdateShortcutLink( |
| 483 shortcut, updated_properties, | 474 shortcut, updated_properties, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 508 } | 499 } |
| 509 | 500 |
| 510 shortcut = shortcut.Append(shortcut_name).Append(shortcut_name + | 501 shortcut = shortcut.Append(shortcut_name).Append(shortcut_name + |
| 511 installer::kLnkExt); | 502 installer::kLnkExt); |
| 512 if (file_util::PathExists(shortcut)) | 503 if (file_util::PathExists(shortcut)) |
| 513 return shortcut; | 504 return shortcut; |
| 514 } | 505 } |
| 515 | 506 |
| 516 return FilePath(); | 507 return FilePath(); |
| 517 } | 508 } |
| OLD | NEW |