2018-10-24 10:49:10 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/application_info.h"
|
2017-12-05 20:58:48 +00:00
|
|
|
|
2023-09-07 08:14:01 +00:00
|
|
|
#include "base/i18n/rtl.h"
|
2018-09-19 11:10:26 +00:00
|
|
|
#include "base/no_destructor.h"
|
2019-01-21 18:32:34 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
2023-09-07 08:14:01 +00:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2019-01-21 18:32:34 +00:00
|
|
|
#include "chrome/common/chrome_version.h"
|
|
|
|
#include "content/public/common/user_agent.h"
|
2019-06-19 21:31:55 +00:00
|
|
|
#include "electron/electron_version.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/browser.h"
|
2018-09-19 11:10:26 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2017-12-05 20:58:48 +00:00
|
|
|
|
2021-07-14 20:10:37 +00:00
|
|
|
std::string& OverriddenApplicationName() {
|
|
|
|
static base::NoDestructor<std::string> overridden_application_name;
|
|
|
|
return *overridden_application_name;
|
2018-02-20 16:16:51 +00:00
|
|
|
}
|
|
|
|
|
2021-07-14 20:10:37 +00:00
|
|
|
std::string& OverriddenApplicationVersion() {
|
|
|
|
static base::NoDestructor<std::string> overridden_application_version;
|
|
|
|
return *overridden_application_version;
|
2018-02-20 16:16:51 +00:00
|
|
|
}
|
2021-07-14 20:10:37 +00:00
|
|
|
|
|
|
|
std::string GetPossiblyOverriddenApplicationName() {
|
|
|
|
std::string ret = OverriddenApplicationName();
|
|
|
|
if (!ret.empty())
|
|
|
|
return ret;
|
|
|
|
return GetApplicationName();
|
2017-12-05 20:58:48 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 18:32:34 +00:00
|
|
|
std::string GetApplicationUserAgent() {
|
|
|
|
// Construct user agent string.
|
|
|
|
Browser* browser = Browser::Get();
|
|
|
|
std::string name, user_agent;
|
|
|
|
if (!base::RemoveChars(browser->GetName(), " ", &name))
|
|
|
|
name = browser->GetName();
|
2019-06-17 20:37:55 +00:00
|
|
|
if (name == ELECTRON_PRODUCT_NAME) {
|
|
|
|
user_agent = "Chrome/" CHROME_VERSION_STRING " " ELECTRON_PRODUCT_NAME
|
|
|
|
"/" ELECTRON_VERSION_STRING;
|
2019-01-21 18:32:34 +00:00
|
|
|
} else {
|
|
|
|
user_agent = base::StringPrintf(
|
2019-06-17 20:37:55 +00:00
|
|
|
"%s/%s Chrome/%s " ELECTRON_PRODUCT_NAME "/" ELECTRON_VERSION_STRING,
|
2019-01-21 18:32:34 +00:00
|
|
|
name.c_str(), browser->GetVersion().c_str(), CHROME_VERSION_STRING);
|
|
|
|
}
|
|
|
|
return content::BuildUserAgentFromProduct(user_agent);
|
|
|
|
}
|
|
|
|
|
2023-09-07 08:14:01 +00:00
|
|
|
bool IsAppRTL() {
|
|
|
|
const std::string& locale = g_browser_process->GetApplicationLocale();
|
|
|
|
base::i18n::TextDirection text_direction =
|
|
|
|
base::i18n::GetTextDirectionForLocaleInStartUp(locale.c_str());
|
|
|
|
return text_direction == base::i18n::RIGHT_TO_LEFT;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|