fix: use acceptLanguages argument in session.setUserAgent() (#23944)

This commit is contained in:
Milan Burda 2020-06-04 13:05:37 +02:00 committed by GitHub
parent 90caa5eac9
commit 3fa4299939
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -40,6 +40,7 @@
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_auth_preferences.h"
#include "net/http/http_cache.h"
#include "net/http/http_util.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/features.h"
#include "shell/browser/api/electron_api_app.h"
@ -591,9 +592,16 @@ void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
void Session::SetUserAgent(const std::string& user_agent,
gin::Arguments* args) {
browser_context_->SetUserAgent(user_agent);
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
->GetNetworkContext()
->SetUserAgent(user_agent);
auto* network_context = content::BrowserContext::GetDefaultStoragePartition(
browser_context_.get())
->GetNetworkContext();
network_context->SetUserAgent(user_agent);
std::string accept_lang;
if (args->GetNext(&accept_lang)) {
network_context->SetAcceptLanguage(
net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang));
}
}
std::string Session::GetUserAgent() {