Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: chrome/browser/shell_integration_win.cc

Issue 11786005: Remove uses of PropVariantTo*; removing the need to DelayLoad propsys.dll. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: +comment Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
22 #include "base/win/scoped_propvariant.h"
25 #include "base/win/shortcut.h" 23 #include "base/win/shortcut.h"
26 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
27 #include "chrome/browser/web_applications/web_app.h" 25 #include "chrome/browser/web_applications/web_app.h"
28 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
29 #include "chrome/common/chrome_paths_internal.h" 27 #include "chrome/common/chrome_paths_internal.h"
30 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
31 #include "chrome/installer/setup/setup_util.h" 29 #include "chrome/installer/setup/setup_util.h"
32 #include "chrome/installer/util/browser_distribution.h" 30 #include "chrome/installer/util/browser_distribution.h"
33 #include "chrome/installer/util/create_reg_key_work_item.h" 31 #include "chrome/installer/util/create_reg_key_work_item.h"
34 #include "chrome/installer/util/install_util.h" 32 #include "chrome/installer/util/install_util.h"
35 #include "chrome/installer/util/set_reg_value_work_item.h" 33 #include "chrome/installer/util/set_reg_value_work_item.h"
36 #include "chrome/installer/util/shell_util.h" 34 #include "chrome/installer/util/shell_util.h"
37 #include "chrome/installer/util/util_constants.h" 35 #include "chrome/installer/util/util_constants.h"
38 #include "chrome/installer/util/work_item.h" 36 #include "chrome/installer/util/work_item.h"
39 #include "chrome/installer/util/work_item_list.h" 37 #include "chrome/installer/util/work_item_list.h"
40 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
41 39
42 // propsys.lib is required for PropvariantTo*().
43 #pragma comment(lib, "propsys.lib")
44
45 using content::BrowserThread; 40 using content::BrowserThread;
46 41
47 namespace { 42 namespace {
48 43
49 #if defined(GOOGLE_CHROME_BUILD) 44 #if defined(GOOGLE_CHROME_BUILD)
50 const wchar_t kAppListAppName[] = L"ChromeAppList"; 45 const wchar_t kAppListAppName[] = L"ChromeAppList";
51 #else 46 #else
52 const wchar_t kAppListAppName[] = L"ChromiumAppList"; 47 const wchar_t kAppListAppName[] = L"ChromiumAppList";
53 #endif 48 #endif
54 49
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 file_util::FileEnumerator shortcuts_enum( 373 file_util::FileEnumerator shortcuts_enum(
379 path, false, // not recursive 374 path, false, // not recursive
380 file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); 375 file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk"));
381 376
382 bool is_per_user_install = 377 bool is_per_user_install =
383 InstallUtil::IsPerUserInstall(chrome_exe.value().c_str()); 378 InstallUtil::IsPerUserInstall(chrome_exe.value().c_str());
384 379
385 int shortcuts_migrated = 0; 380 int shortcuts_migrated = 0;
386 FilePath target_path; 381 FilePath target_path;
387 string16 arguments; 382 string16 arguments;
388 string16 existing_app_id;
389 for (FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); 383 for (FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty();
390 shortcut = shortcuts_enum.Next()) { 384 shortcut = shortcuts_enum.Next()) {
391 // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once 385 // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once
392 // it is fixed to work with FilePaths with spaces. 386 // it is fixed to work with FilePaths with spaces.
393 if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) || 387 if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) ||
394 chrome_exe != target_path) { 388 chrome_exe != target_path) {
395 continue; 389 continue;
396 } 390 }
397 CommandLine command_line(CommandLine::FromString(base::StringPrintf( 391 CommandLine command_line(CommandLine::FromString(base::StringPrintf(
398 L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str()))); 392 L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str())));
(...skipping 14 matching lines...) Expand all
413 DLOG(WARNING) << "Failed loading shortcut at " << shortcut.value(); 407 DLOG(WARNING) << "Failed loading shortcut at " << shortcut.value();
414 continue; 408 continue;
415 } 409 }
416 410
417 // Any properties that need to be updated on the shortcut will be stored in 411 // Any properties that need to be updated on the shortcut will be stored in
418 // |updated_properties|. 412 // |updated_properties|.
419 base::win::ShortcutProperties updated_properties; 413 base::win::ShortcutProperties updated_properties;
420 414
421 // Validate the existing app id for the shortcut. 415 // Validate the existing app id for the shortcut.
422 base::win::ScopedComPtr<IPropertyStore> property_store; 416 base::win::ScopedComPtr<IPropertyStore> property_store;
423 PROPVARIANT pv_app_id; 417 base::win::ScopedPropVariant pv_app_id;
424 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);
440 PropVariantClear(&pv_app_id); 429 break;
441 if (result != S_OK && result != STRSAFE_E_INSUFFICIENT_BUFFER) { 430 case VT_LPWSTR:
442 // Accept the STRSAFE_E_INSUFFICIENT_BUFFER error state as it means the 431 if (expected_app_id != string16(pv_app_id->pwszVal))
443 // existing appid is longer than |expected_app_id| and thus we will 432 updated_properties.set_app_id(expected_app_id);
444 // simply assume inequality. 433 break;
445 NOTREACHED(); 434 default:
446 continue; 435 NOTREACHED();
447 } else if (result == STRSAFE_E_INSUFFICIENT_BUFFER || 436 continue;
448 expected_app_id != existing_app_id) {
449 updated_properties.set_app_id(expected_app_id);
450 } 437 }
451 } 438 }
452 439
453 if (check_dual_mode) { 440 if (check_dual_mode) {
454 BOOL existing_dual_mode; 441 base::win::ScopedPropVariant pv_dual_mode;
455 PROPVARIANT pv_dual_mode;
456 PropVariantInit(&pv_dual_mode);
457 if (property_store->GetValue(PKEY_AppUserModel_IsDualMode, 442 if (property_store->GetValue(PKEY_AppUserModel_IsDualMode,
458 &pv_dual_mode) != S_OK) { 443 &pv_dual_mode) != S_OK) {
459 // When in doubt, prefer to not update the shortcut. 444 // When in doubt, prefer to not update the shortcut.
460 NOTREACHED(); 445 NOTREACHED();
461 continue; 446 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 { 447 } else {
466 // If it is set to false, make sure it gets set to true as well. 448 switch (pv_dual_mode->vt) {
467 if (PropVariantToBoolean(pv_dual_mode, &existing_dual_mode) != S_OK) { 449 case VT_EMPTY:
468 NOTREACHED(); 450 // If dual_mode is not set at all, make sure it gets set to true.
469 continue; 451 updated_properties.set_dual_mode(true);
452 break;
453 case VT_BOOL:
454 // If it is set to false, make sure it gets set to true as well.
455 if (!pv_dual_mode->boolVal)
456 updated_properties.set_dual_mode(true);
457 break;
458 default:
459 NOTREACHED();
460 continue;
470 } 461 }
471 PropVariantClear(&pv_dual_mode);
472 if (!existing_dual_mode)
473 updated_properties.set_dual_mode(true);
474 } 462 }
475 } 463 }
476 464
477 persist_file.Release(); 465 persist_file.Release();
478 shell_link.Release(); 466 shell_link.Release();
479 467
480 // Update the shortcut if some of its properties need to be updated. 468 // Update the shortcut if some of its properties need to be updated.
481 if (updated_properties.options && 469 if (updated_properties.options &&
482 base::win::CreateOrUpdateShortcutLink( 470 base::win::CreateOrUpdateShortcutLink(
483 shortcut, updated_properties, 471 shortcut, updated_properties,
(...skipping 24 matching lines...) Expand all
508 } 496 }
509 497
510 shortcut = shortcut.Append(shortcut_name).Append(shortcut_name + 498 shortcut = shortcut.Append(shortcut_name).Append(shortcut_name +
511 installer::kLnkExt); 499 installer::kLnkExt);
512 if (file_util::PathExists(shortcut)) 500 if (file_util::PathExists(shortcut))
513 return shortcut; 501 return shortcut;
514 } 502 }
515 503
516 return FilePath(); 504 return FilePath();
517 } 505 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698