remote_open_url_util.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/host/remote_open_url/remote_open_url_util.h"
  5. #include "base/logging.h"
  6. #include "build/build_config.h"
  7. #if BUILDFLAG(IS_WIN)
  8. #include "base/win/registry.h"
  9. #include "base/win/windows_types.h"
  10. #include "base/win/windows_version.h"
  11. #endif
  12. namespace remoting {
  13. #if BUILDFLAG(IS_WIN)
  14. #if defined(OFFICIAL_BUILD)
  15. const wchar_t kUrlForwarderRegisteredAppName[] =
  16. L"Chrome Remote Desktop URL Forwarder";
  17. #else
  18. const wchar_t kUrlForwarderRegisteredAppName[] = L"Chromoting URL Forwarder";
  19. #endif
  20. const wchar_t kRegisteredApplicationsKeyName[] =
  21. L"SOFTWARE\\RegisteredApplications";
  22. #endif // defined (OS_WIN)
  23. bool IsRemoteOpenUrlSupported() {
  24. #if BUILDFLAG(IS_LINUX)
  25. return true;
  26. #elif BUILDFLAG(IS_WIN)
  27. // The modern default apps settings dialog is only available to Windows 8+.
  28. // Given older Windows versions are EOL, we only advertise the feature on
  29. // Windows 8+.
  30. if (base::win::GetVersion() < base::win::Version::WIN8) {
  31. return false;
  32. }
  33. // The MSI installs the ProgID and capabilities into registry, but not the
  34. // entry in RegisteredApplications, which must be applied out of band to
  35. // enable the feature.
  36. base::win::RegKey registered_apps_key;
  37. LONG result = registered_apps_key.Open(
  38. HKEY_LOCAL_MACHINE, kRegisteredApplicationsKeyName, KEY_READ);
  39. if (result != ERROR_SUCCESS) {
  40. LOG(ERROR) << "Failed to determine whether URL forwarding is supported "
  41. "since registry key HKLM\\"
  42. << kRegisteredApplicationsKeyName
  43. << "cannot be opened. Result: " << result;
  44. return false;
  45. }
  46. return registered_apps_key.HasValue(kUrlForwarderRegisteredAppName);
  47. #else
  48. // Not supported on other platforms.
  49. return false;
  50. #endif
  51. }
  52. } // namespace remoting