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.
|
|
|
|
|
|
|
|
#include "atom/common/application_info.h"
|
2017-12-05 20:58:48 +00:00
|
|
|
|
2019-01-21 18:32:34 +00:00
|
|
|
#include "atom/browser/browser.h"
|
|
|
|
#include "atom/common/atom_version.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"
|
|
|
|
#include "chrome/common/chrome_version.h"
|
|
|
|
#include "content/public/common/user_agent.h"
|
2018-09-19 11:10:26 +00:00
|
|
|
|
2018-10-24 10:49:10 +00:00
|
|
|
namespace atom {
|
2017-12-05 20:58:48 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
base::NoDestructor<std::string> g_overridden_application_name;
|
|
|
|
base::NoDestructor<std::string> g_overridden_application_version;
|
2017-12-05 20:58:48 +00:00
|
|
|
|
2018-03-12 00:33:06 +00:00
|
|
|
} // namespace
|
2017-12-05 20:58:48 +00:00
|
|
|
|
2018-03-12 00:33:06 +00:00
|
|
|
// name
|
2017-12-05 20:58:48 +00:00
|
|
|
void OverrideApplicationName(const std::string& name) {
|
2018-09-13 00:25:56 +00:00
|
|
|
*g_overridden_application_name = name;
|
2017-12-05 20:58:48 +00:00
|
|
|
}
|
2018-02-20 16:16:51 +00:00
|
|
|
std::string GetOverriddenApplicationName() {
|
2018-09-13 00:25:56 +00:00
|
|
|
return *g_overridden_application_name;
|
2018-02-20 16:16:51 +00:00
|
|
|
}
|
|
|
|
|
2018-03-12 00:33:06 +00:00
|
|
|
// version
|
2018-02-20 16:16:51 +00:00
|
|
|
void OverrideApplicationVersion(const std::string& version) {
|
2018-09-13 00:25:56 +00:00
|
|
|
*g_overridden_application_version = version;
|
2018-02-20 16:16:51 +00:00
|
|
|
}
|
|
|
|
std::string GetOverriddenApplicationVersion() {
|
2018-09-13 00:25:56 +00:00
|
|
|
return *g_overridden_application_version;
|
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();
|
|
|
|
if (name == ATOM_PRODUCT_NAME) {
|
|
|
|
user_agent = "Chrome/" CHROME_VERSION_STRING " " ATOM_PRODUCT_NAME
|
|
|
|
"/" ATOM_VERSION_STRING;
|
|
|
|
} else {
|
|
|
|
user_agent = base::StringPrintf(
|
|
|
|
"%s/%s Chrome/%s " ATOM_PRODUCT_NAME "/" ATOM_VERSION_STRING,
|
|
|
|
name.c_str(), browser->GetVersion().c_str(), CHROME_VERSION_STRING);
|
|
|
|
}
|
|
|
|
return content::BuildUserAgentFromProduct(user_agent);
|
|
|
|
}
|
|
|
|
|
2018-10-24 10:49:10 +00:00
|
|
|
} // namespace atom
|