diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/web_contents_adapter.cpp | 10 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 4 | ||||
-rw-r--r-- | src/core/web_engine_settings.cpp | 34 | ||||
-rw-r--r-- | src/core/web_engine_settings.h | 6 |
4 files changed, 47 insertions, 7 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index effd6e340..6576a9c3b 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -60,7 +60,8 @@ #include "web_engine_context.h" #include "web_engine_settings.h" -#include <base/run_loop.h> +#include "base/command_line.h" +#include "base/run_loop.h" #include "base/values.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/web_contents/web_contents_impl.h" @@ -80,6 +81,7 @@ #include "content/public/common/resource_request_body.h" #include "content/public/common/url_constants.h" #include "content/public/common/web_preferences.h" +#include "content/public/common/webrtc_ip_handling_policy.h" #include "third_party/WebKit/public/web/WebFindOptions.h" #include "printing/features/features.h" #include "ui/base/clipboard/clipboard.h" @@ -428,10 +430,14 @@ void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient) rendererPrefs->caret_blink_interval = 0.5 * static_cast<double>(qtCursorFlashTime) / 1000; rendererPrefs->user_agent_override = d->browserContextAdapter->httpUserAgent().toStdString(); rendererPrefs->accept_languages = d->browserContextAdapter->httpAcceptLanguageWithoutQualities().toStdString(); -#if defined(ENABLE_WEBRTC) +#if BUILDFLAG(ENABLE_WEBRTC) base::CommandLine* commandLine = base::CommandLine::ForCurrentProcess(); if (commandLine->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) rendererPrefs->webrtc_ip_handling_policy = commandLine->GetSwitchValueASCII(switches::kForceWebRtcIPHandlingPolicy); + else + rendererPrefs->webrtc_ip_handling_policy = adapterClient->webEngineSettings()->testAttribute(WebEngineSettings::WebRTCPublicInterfacesOnly) + ? content::kWebRTCIPHandlingDefaultPublicInterfaceOnly + : content::kWebRTCIPHandlingDefault; #endif // Set web-contents font settings to the default font settings as Chromium constantly overrides // the global font defaults with the font settings of the latest web-contents created. diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 111a6943a..54aeac710 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -485,9 +485,9 @@ void WebContentsDelegateQt::RequestToLockMouse(content::WebContents *web_content m_viewClient->runMouseLockPermissionRequest(toQt(web_contents->GetVisibleURL())); } -void WebContentsDelegateQt::overrideWebPreferences(content::WebContents *, content::WebPreferences *webPreferences) +void WebContentsDelegateQt::overrideWebPreferences(content::WebContents *webContents, content::WebPreferences *webPreferences) { - m_viewClient->webEngineSettings()->overrideWebPreferences(webPreferences); + m_viewClient->webEngineSettings()->overrideWebPreferences(webContents, webPreferences); } QWeakPointer<WebContentsAdapter> WebContentsDelegateQt::createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp index a585e7bb3..58245d760 100644 --- a/src/core/web_engine_settings.cpp +++ b/src/core/web_engine_settings.cpp @@ -46,9 +46,13 @@ #include "base/command_line.h" #include "chrome/common/chrome_switches.h" #include "content/browser/gpu/gpu_process_host.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/web_contents.h" #include "content/public/common/content_switches.h" +#include "content/public/common/renderer_preferences.h" #include "content/public/common/web_preferences.h" #include "media/base/media_switches.h" +#include "content/public/common/webrtc_ip_handling_policy.h" #include "ui/events/event_switches.h" #include <QFont> @@ -127,7 +131,7 @@ WebEngineSettings::~WebEngineSettings() } } -void WebEngineSettings::overrideWebPreferences(content::WebPreferences *prefs) +void WebEngineSettings::overrideWebPreferences(content::WebContents *webContents, content::WebPreferences *prefs) { // Apply our settings on top of those. applySettingsToWebPreferences(prefs); @@ -136,6 +140,12 @@ void WebEngineSettings::overrideWebPreferences(content::WebPreferences *prefs) // before we get here (e.g. number_of_cpu_cores). if (webPreferences.isNull()) webPreferences.reset(new content::WebPreferences(*prefs)); + + if (webContents + && webContents->GetRenderViewHost() + && applySettingsToRendererPreferences(webContents->GetMutableRendererPrefs())) { + webContents->GetRenderViewHost()->SyncRendererPrefs(); + } } void WebEngineSettings::setAttribute(WebEngineSettings::Attribute attr, bool on) @@ -286,6 +296,7 @@ void WebEngineSettings::initDefaults() if (commandLine->HasSwitch(switches::kAutoplayPolicy)) playbackRequiresUserGesture = (commandLine->GetSwitchValueASCII(switches::kAutoplayPolicy) != switches::autoplay::kNoUserGestureRequiredPolicy); s_defaultAttributes.insert(PlaybackRequiresUserGesture, playbackRequiresUserGesture); + s_defaultAttributes.insert(WebRTCPublicInterfacesOnly, false); } if (s_defaultFontFamilies.isEmpty()) { @@ -332,9 +343,11 @@ void WebEngineSettings::doApply() return; // Override with our settings when applicable applySettingsToWebPreferences(webPreferences.data()); - Q_ASSERT(m_adapter); m_adapter->updateWebPreferences(*webPreferences.data()); + + if (applySettingsToRendererPreferences(m_adapter->webContents()->GetMutableRendererPrefs())) + m_adapter->webContents()->GetRenderViewHost()->SyncRendererPrefs(); } void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *prefs) @@ -390,6 +403,23 @@ void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *p prefs->default_encoding = defaultTextEncoding().toStdString(); } +bool WebEngineSettings::applySettingsToRendererPreferences(content::RendererPreferences *prefs) +{ + bool changed = false; +#if BUILDFLAG(ENABLE_WEBRTC) + if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) { + std::string webrtc_ip_handling_policy = testAttribute(WebEngineSettings::WebRTCPublicInterfacesOnly) + ? content::kWebRTCIPHandlingDefaultPublicInterfaceOnly + : content::kWebRTCIPHandlingDefault; + if (prefs->webrtc_ip_handling_policy != webrtc_ip_handling_policy) { + prefs->webrtc_ip_handling_policy = webrtc_ip_handling_policy; + changed = true; + } + } +#endif + return changed; +} + void WebEngineSettings::scheduleApplyRecursively() { scheduleApply(); diff --git a/src/core/web_engine_settings.h b/src/core/web_engine_settings.h index 5881303a2..06e6ac59c 100644 --- a/src/core/web_engine_settings.h +++ b/src/core/web_engine_settings.h @@ -48,6 +48,8 @@ #include <QSet> namespace content { +struct RendererPreferences; +class WebContents; struct WebPreferences; } namespace QtWebEngineCore { @@ -87,6 +89,7 @@ public: AllowWindowActivationFromJavaScript, ShowScrollBars, PlaybackRequiresUserGesture, + WebRTCPublicInterfacesOnly, }; // Must match the values from the public API in qwebenginesettings.h. @@ -121,7 +124,7 @@ public: void setParentSettings(WebEngineSettings *parentSettings); - void overrideWebPreferences(content::WebPreferences *prefs); + void overrideWebPreferences(content::WebContents *webContents, content::WebPreferences *prefs); void setAttribute(Attribute, bool on); bool testAttribute(Attribute) const; @@ -152,6 +155,7 @@ public: private: void doApply(); void applySettingsToWebPreferences(content::WebPreferences *); + bool applySettingsToRendererPreferences(content::RendererPreferences *); void setWebContentsAdapter(WebContentsAdapter *adapter) { m_adapter = adapter; } WebContentsAdapter* m_adapter; |