mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Support configuration of user agent and locale (see issue #2969)
This change adds support for CefSettings and command-line configuration of user_agent, user_agent_product (formerly product_version) and locale.
This commit is contained in:
@@ -695,9 +695,9 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
|
||||
switches::kLocalesDirPath,
|
||||
switches::kLogFile,
|
||||
switches::kLogSeverity,
|
||||
switches::kProductVersion,
|
||||
switches::kResourcesDirPath,
|
||||
embedder_support::kUserAgent,
|
||||
switches::kUserAgentProductAndVersion,
|
||||
};
|
||||
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
|
||||
base::size(kSwitchNames));
|
||||
|
@@ -91,6 +91,16 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
|
||||
|
||||
const base::CommandLine* browser_cmd = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
{
|
||||
// Propagate the following switches to all command lines (along with any
|
||||
// associated values) if present in the browser command line.
|
||||
static const char* const kSwitchNames[] = {
|
||||
switches::kUserAgentProductAndVersion,
|
||||
};
|
||||
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
|
||||
base::size(kSwitchNames));
|
||||
}
|
||||
|
||||
const std::string& process_type =
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
if (process_type == switches::kRendererProcess) {
|
||||
|
@@ -150,9 +150,10 @@ bool AlloyMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
if (settings_->user_agent.length > 0) {
|
||||
command_line->AppendSwitchASCII(embedder_support::kUserAgent,
|
||||
CefString(&settings_->user_agent));
|
||||
} else if (settings_->product_version.length > 0) {
|
||||
command_line->AppendSwitchASCII(switches::kProductVersion,
|
||||
CefString(&settings_->product_version));
|
||||
} else if (settings_->user_agent_product.length > 0) {
|
||||
command_line->AppendSwitchASCII(
|
||||
switches::kUserAgentProductAndVersion,
|
||||
CefString(&settings_->user_agent_product));
|
||||
}
|
||||
|
||||
if (settings_->locale.length > 0) {
|
||||
|
@@ -126,6 +126,9 @@ const char kEnableChromeRuntime[] = "enable-chrome-runtime";
|
||||
// using the Chrome runtime.
|
||||
const char kDisableChromeLoginPrompt[] = "disable-chrome-login-prompt";
|
||||
|
||||
// Override the product component of the default User-Agent string.
|
||||
const char kUserAgentProductAndVersion[] = "user-agent-product";
|
||||
|
||||
#if defined(OS_MAC)
|
||||
// Path to the framework directory.
|
||||
const char kFrameworkDirPath[] = "framework-dir-path";
|
||||
|
@@ -55,6 +55,7 @@ extern const char kDisableNewBrowserInfoTimeout[];
|
||||
extern const char kDevToolsProtocolLogFile[];
|
||||
extern const char kEnableChromeRuntime[];
|
||||
extern const char kDisableChromeLoginPrompt[];
|
||||
extern const char kUserAgentProductAndVersion[];
|
||||
|
||||
#if defined(OS_MAC)
|
||||
extern const char kFrameworkDirPath[];
|
||||
|
@@ -16,8 +16,10 @@
|
||||
#include "base/command_line.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "components/embedder_support/switches.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "sandbox/policy/switches.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
|
||||
#if defined(OS_MAC)
|
||||
#include "libcef/common/util_mac.h"
|
||||
@@ -79,6 +81,22 @@ bool ChromeMainDelegateCef::BasicStartupComplete(int* exit_code) {
|
||||
command_line->AppendSwitch(sandbox::policy::switches::kNoSandbox);
|
||||
}
|
||||
|
||||
if (settings_->user_agent.length > 0) {
|
||||
command_line->AppendSwitchASCII(embedder_support::kUserAgent,
|
||||
CefString(&settings_->user_agent));
|
||||
} else if (settings_->user_agent_product.length > 0) {
|
||||
command_line->AppendSwitchASCII(
|
||||
switches::kUserAgentProductAndVersion,
|
||||
CefString(&settings_->user_agent_product));
|
||||
}
|
||||
|
||||
if (settings_->locale.length > 0) {
|
||||
command_line->AppendSwitchASCII(switches::kLang,
|
||||
CefString(&settings_->locale));
|
||||
} else if (!command_line->HasSwitch(switches::kLang)) {
|
||||
command_line->AppendSwitchASCII(switches::kLang, "en-US");
|
||||
}
|
||||
|
||||
if (settings_->javascript_flags.length > 0) {
|
||||
command_line->AppendSwitchASCII(switches::kJavaScriptFlags,
|
||||
CefString(&settings_->javascript_flags));
|
||||
|
Reference in New Issue
Block a user