diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-03-02 12:33:15 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-03-03 00:37:20 +0100 |
commit | a0a2780d42622476d69762f5f794af06b2e7d6cd (patch) | |
tree | 0e8476cade6d5940c84eba962d821b704256f9cf /src/core/profile_adapter.cpp | |
parent | 218d7ddae16c777714819eab5c487a355413279b (diff) |
Update user-agent without replacing entire network context
Use added API to treat user-agent changes like accept-language changes.
3rdparty changes:
> Allow changing user-agent without replace the entire network context
> Destroy old network context before creating the replacement
> Enable plugin.mojom for plugin placeholder
> Suppress racy DCHECK
> Restore -fno-delete-null-pointer-checks
Change-Id: Ie94f74332704313d63e064c61118afc53a95c0d8
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'src/core/profile_adapter.cpp')
-rw-r--r-- | src/core/profile_adapter.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/core/profile_adapter.cpp b/src/core/profile_adapter.cpp index 7387cc421..e9e2a2c5d 100644 --- a/src/core/profile_adapter.cpp +++ b/src/core/profile_adapter.cpp @@ -352,16 +352,21 @@ QString ProfileAdapter::httpUserAgent() const void ProfileAdapter::setHttpUserAgent(const QString &userAgent) { - if (m_httpUserAgent == userAgent) + const QString httpUserAgent = userAgent.simplified(); + if (m_httpUserAgent == httpUserAgent) return; - m_httpUserAgent = userAgent.simplified(); + m_httpUserAgent = httpUserAgent; + const std::string stdUserAgent = httpUserAgent.toStdString(); std::vector<content::WebContentsImpl *> list = content::WebContentsImpl::GetAllWebContents(); for (content::WebContentsImpl *web_contents : list) if (web_contents->GetBrowserContext() == m_profile.data()) - web_contents->SetUserAgentOverride(m_httpUserAgent.toStdString(), true); + web_contents->SetUserAgentOverride(stdUserAgent, true); - m_profile->m_profileIOData->resetNetworkContext(); + content::BrowserContext::ForEachStoragePartition( + m_profile.get(), base::BindRepeating([](const std::string &user_agent, content::StoragePartition *storage_partition) { + storage_partition->GetNetworkContext()->SetUserAgent(user_agent); + }, stdUserAgent)); } ProfileAdapter::HttpCacheType ProfileAdapter::httpCacheType() const |