application_info.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/common/application_info.h"
  5. #include "base/i18n/rtl.h"
  6. #include "base/no_destructor.h"
  7. #include "chrome/browser/browser_process.h"
  8. #include "chrome/common/chrome_version.h"
  9. #include "content/public/common/user_agent.h"
  10. #include "electron/electron_version.h"
  11. #include "shell/browser/browser.h"
  12. #include "third_party/abseil-cpp/absl/strings/str_format.h"
  13. namespace electron {
  14. std::string& OverriddenApplicationName() {
  15. static base::NoDestructor<std::string> overridden_application_name;
  16. return *overridden_application_name;
  17. }
  18. std::string& OverriddenApplicationVersion() {
  19. static base::NoDestructor<std::string> overridden_application_version;
  20. return *overridden_application_version;
  21. }
  22. std::string GetPossiblyOverriddenApplicationName() {
  23. std::string ret = OverriddenApplicationName();
  24. if (!ret.empty())
  25. return ret;
  26. return GetApplicationName();
  27. }
  28. std::string GetApplicationUserAgent() {
  29. // Construct user agent string.
  30. Browser* browser = Browser::Get();
  31. std::string name, user_agent;
  32. if (!base::RemoveChars(browser->GetName(), " ", &name))
  33. name = browser->GetName();
  34. if (name == ELECTRON_PRODUCT_NAME) {
  35. user_agent = "Chrome/" CHROME_VERSION_STRING " " ELECTRON_PRODUCT_NAME
  36. "/" ELECTRON_VERSION_STRING;
  37. } else {
  38. user_agent = absl::StrFormat(
  39. "%s/%s Chrome/%s " ELECTRON_PRODUCT_NAME "/" ELECTRON_VERSION_STRING,
  40. name.c_str(), browser->GetVersion().c_str(), CHROME_VERSION_STRING);
  41. }
  42. return content::BuildUserAgentFromProduct(user_agent);
  43. }
  44. bool IsAppRTL() {
  45. const std::string& locale = g_browser_process->GetApplicationLocale();
  46. base::i18n::TextDirection text_direction =
  47. base::i18n::GetTextDirectionForLocaleInStartUp(locale.c_str());
  48. return text_direction == base::i18n::RIGHT_TO_LEFT;
  49. }
  50. } // namespace electron