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

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: even better! 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; 383 base::win::ScopedPropVariant pv_buffer;
grt (UTC plus 2) 2013/01/10 16:05:20 why buffer?
gab 2013/01/10 18:11:38 Idk, random name choice? |propvariant| better?
389 for (FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); 384 for (FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty();
390 shortcut = shortcuts_enum.Next()) { 385 shortcut = shortcuts_enum.Next()) {
391 // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once 386 // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once
392 // it is fixed to work with FilePaths with spaces. 387 // it is fixed to work with FilePaths with spaces.
393 if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) || 388 if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) ||
394 chrome_exe != target_path) { 389 chrome_exe != target_path) {
395 continue; 390 continue;
396 } 391 }
397 CommandLine command_line(CommandLine::FromString(base::StringPrintf( 392 CommandLine command_line(CommandLine::FromString(base::StringPrintf(
398 L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str()))); 393 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(); 408 DLOG(WARNING) << "Failed loading shortcut at " << shortcut.value();
414 continue; 409 continue;
415 } 410 }
416 411
417 // Any properties that need to be updated on the shortcut will be stored in 412 // Any properties that need to be updated on the shortcut will be stored in
418 // |updated_properties|. 413 // |updated_properties|.
419 base::win::ShortcutProperties updated_properties; 414 base::win::ShortcutProperties updated_properties;
420 415
421 // Validate the existing app id for the shortcut. 416 // Validate the existing app id for the shortcut.
422 base::win::ScopedComPtr<IPropertyStore> property_store; 417 base::win::ScopedComPtr<IPropertyStore> property_store;
423 PROPVARIANT pv_app_id; 418 pv_buffer.Reset();
424 PropVariantInit(&pv_app_id);
425 if (FAILED(property_store.QueryFrom(shell_link)) || 419 if (FAILED(property_store.QueryFrom(shell_link)) ||
426 property_store->GetValue(PKEY_AppUserModel_ID, &pv_app_id) != S_OK) { 420 property_store->GetValue(PKEY_AppUserModel_ID,
421 pv_buffer.Receive()) != S_OK) {
gab 2013/01/10 15:30:42 I was thinking it could be nice if we replaced Rec
grt (UTC plus 2) 2013/01/10 16:05:20 I think code consistency is more important so that
gab 2013/01/10 18:11:38 Ok that's what I thought too, but just checking. T
427 // When in doubt, prefer not updating the shortcut. 422 // When in doubt, prefer not updating the shortcut.
428 NOTREACHED(); 423 NOTREACHED();
429 continue; 424 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 { 425 } else {
435 // Validate that the existing app_id is the expected app_id; if not, set 426 switch (pv_buffer.get().vt) {
436 // the expected app_id on the shortcut. 427 case VT_EMPTY:
437 size_t expected_size = expected_app_id.size() + 1; 428 // If there is no app_id set, set our app_id if one is expected.
438 HRESULT result = PropVariantToString( 429 if (!expected_app_id.empty())
439 pv_app_id, WriteInto(&existing_app_id, expected_size), expected_size); 430 updated_properties.set_app_id(expected_app_id);
440 PropVariantClear(&pv_app_id); 431 break;
441 if (result != S_OK && result != STRSAFE_E_INSUFFICIENT_BUFFER) { 432 case VT_LPWSTR:
442 // Accept the STRSAFE_E_INSUFFICIENT_BUFFER error state as it means the 433 if (expected_app_id != string16(pv_buffer.get().pwszVal))
443 // existing appid is longer than |expected_app_id| and thus we will 434 updated_properties.set_app_id(expected_app_id);
444 // simply assume inequality. 435 break;
445 NOTREACHED(); 436 default:
446 continue; 437 NOTREACHED();
447 } else if (result == STRSAFE_E_INSUFFICIENT_BUFFER || 438 continue;
448 expected_app_id != existing_app_id) {
449 updated_properties.set_app_id(expected_app_id);
450 } 439 }
451 } 440 }
452 441
453 if (check_dual_mode) { 442 if (check_dual_mode) {
454 BOOL existing_dual_mode; 443 pv_buffer.Reset();
455 PROPVARIANT pv_dual_mode;
456 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_buffer.Receive()) != 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_buffer.get().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_buffer.get().boolVal)
458 updated_properties.set_dual_mode(true);
459 break;
460 default:
461 NOTREACHED();
462 continue;
470 } 463 }
471 PropVariantClear(&pv_dual_mode);
472 if (!existing_dual_mode)
473 updated_properties.set_dual_mode(true);
474 } 464 }
475 } 465 }
476 466
477 persist_file.Release(); 467 persist_file.Release();
478 shell_link.Release(); 468 shell_link.Release();
479 469
480 // Update the shortcut if some of its properties need to be updated. 470 // Update the shortcut if some of its properties need to be updated.
481 if (updated_properties.options && 471 if (updated_properties.options &&
482 base::win::CreateOrUpdateShortcutLink( 472 base::win::CreateOrUpdateShortcutLink(
483 shortcut, updated_properties, 473 shortcut, updated_properties,
(...skipping 24 matching lines...) Expand all
508 } 498 }
509 499
510 shortcut = shortcut.Append(shortcut_name).Append(shortcut_name + 500 shortcut = shortcut.Append(shortcut_name).Append(shortcut_name +
511 installer::kLnkExt); 501 installer::kLnkExt);
512 if (file_util::PathExists(shortcut)) 502 if (file_util::PathExists(shortcut))
513 return shortcut; 503 return shortcut;
514 } 504 }
515 505
516 return FilePath(); 506 return FilePath();
517 } 507 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698