diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2021-12-03 12:11:06 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2021-12-09 09:07:31 +0100 |
commit | 8565ed8855fb65dd2db08f7cd901addce2a5ffe2 (patch) | |
tree | 85551c5f35be20ece78ffa3ef8dca9331ba66c06 /src/core | |
parent | 4a06aad046a8599b5957d8de72ea7694ace78100 (diff) |
Fix crash with disabled geolocation on macOS
QtWebEngine uses custom LocationProvider for geolocation. If geolocation
is disabled, Chromium fallbacks to NetworkLocationProvider.
NetworkLocationProvider uses GeolocationSystemPermissionManager and
tThere is no nullptr check for the manager instance so
QtWebEngine has to provide it. This fix implements a
FakeSystemGeolocationPermissionManager what is meant to be used only
on macOS if geolocation is disabled.
LocationSystemPermissionStatus is always set to denied by the fake manager.
Change-Id: I25d51c9ce8911b95ff69cc72bc6aae7023e7edbe
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit ca1074f7d0b91ccb9290acbfe51ecab54ad2efb9)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/browser_main_parts_qt.cpp | 26 | ||||
-rw-r--r-- | src/core/browser_main_parts_qt.h | 11 | ||||
-rw-r--r-- | src/core/content_browser_client_qt.cpp | 15 | ||||
-rw-r--r-- | src/core/content_browser_client_qt.h | 10 |
4 files changed, 60 insertions, 2 deletions
diff --git a/src/core/browser_main_parts_qt.cpp b/src/core/browser_main_parts_qt.cpp index 46d472abb..6facacc00 100644 --- a/src/core/browser_main_parts_qt.cpp +++ b/src/core/browser_main_parts_qt.cpp @@ -81,6 +81,7 @@ #if defined(OS_MAC) #include "base/message_loop/message_pump_mac.h" +#include "services/device/public/cpp/geolocation/geolocation_system_permission_mac.h" #include "ui/base/idle/idle.h" #endif @@ -219,6 +220,21 @@ private: QWebEngineMessagePumpScheduler m_scheduler; }; +#if defined(OS_MAC) +class FakeSystemGeolocationPermissionManager : public device::GeolocationSystemPermissionManager +{ +public: + FakeSystemGeolocationPermissionManager() = default; + ~FakeSystemGeolocationPermissionManager() override = default; + + // GeolocationSystemPermissionManager implementation: + device::LocationSystemPermissionStatus GetSystemPermission() override + { + return device::LocationSystemPermissionStatus::kDenied; + } +}; +#endif // defined(OS_MAC) + std::unique_ptr<base::MessagePump> messagePumpFactory() { static bool madePrimaryPump = false; @@ -243,6 +259,9 @@ int BrowserMainPartsQt::PreEarlyInitialization() void BrowserMainPartsQt::PreMainMessageLoopStart() { +#if defined(OS_MAC) + m_locationPermissionManager = std::make_unique<FakeSystemGeolocationPermissionManager>(); +#endif } void BrowserMainPartsQt::PreMainMessageLoopRun() @@ -300,4 +319,11 @@ void BrowserMainPartsQt::PostCreateThreads() performance_manager_registry_ = performance_manager::PerformanceManagerRegistry::Create(); } +#if defined(OS_MAC) +device::GeolocationSystemPermissionManager *BrowserMainPartsQt::GetLocationPermissionManager() +{ + return m_locationPermissionManager.get(); +} +#endif + } // namespace QtWebEngineCore diff --git a/src/core/browser_main_parts_qt.h b/src/core/browser_main_parts_qt.h index 9d0967612..5261207fc 100644 --- a/src/core/browser_main_parts_qt.h +++ b/src/core/browser_main_parts_qt.h @@ -50,6 +50,10 @@ namespace content { class ServiceManagerConnection; } +namespace device { +class GeolocationSystemPermissionManager; +} + namespace performance_manager { class PerformanceManager; class PerformanceManagerRegistry; @@ -72,10 +76,17 @@ public: int PreCreateThreads() override; void PostCreateThreads() override; +#if defined(OS_MAC) + device::GeolocationSystemPermissionManager *GetLocationPermissionManager(); +#endif + private: DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsQt); std::unique_ptr<performance_manager::PerformanceManager> performance_manager_; std::unique_ptr<performance_manager::PerformanceManagerRegistry> performance_manager_registry_; +#if defined(OS_MAC) + std::unique_ptr<device::GeolocationSystemPermissionManager> m_locationPermissionManager; +#endif }; } // namespace QtWebEngineCore diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index f8d1afe10..9c6787340 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -73,6 +73,7 @@ #include "mojo/public/cpp/bindings/self_owned_associated_receiver.h" #include "net/ssl/client_cert_identity.h" #include "net/ssl/client_cert_store.h" +#include "services/device/public/cpp/geolocation/geolocation_system_permission_mac.h" #include "services/network/network_service.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/common/loader/url_loader_throttle.h" @@ -229,7 +230,10 @@ ContentBrowserClientQt::~ContentBrowserClientQt() std::unique_ptr<content::BrowserMainParts> ContentBrowserClientQt::CreateBrowserMainParts(const content::MainFunctionParams&) { - return std::make_unique<BrowserMainPartsQt>(); + Q_ASSERT(!m_browserMainParts); + auto browserMainParts = std::make_unique<BrowserMainPartsQt>(); + m_browserMainParts = browserMainParts.get(); + return browserMainParts; } void ContentBrowserClientQt::RenderProcessWillLaunch(content::RenderProcessHost *host) @@ -594,6 +598,15 @@ std::unique_ptr<device::LocationProvider> ContentBrowserClientQt::OverrideSystem } #endif +device::GeolocationSystemPermissionManager *ContentBrowserClientQt::GetLocationPermissionManager() +{ +#if defined(OS_MAC) + return m_browserMainParts->GetLocationPermissionManager(); +#else + return nullptr; +#endif +} + bool ContentBrowserClientQt::ShouldEnableStrictSiteIsolation() { // mirroring AwContentBrowserClient, CastContentBrowserClient and diff --git a/src/core/content_browser_client_qt.h b/src/core/content_browser_client_qt.h index 94ee69bf1..b6e78e852 100644 --- a/src/core/content_browser_client_qt.h +++ b/src/core/content_browser_client_qt.h @@ -58,7 +58,11 @@ class ResourceContext; class WebContents; struct MainFunctionParams; struct Referrer; -} +} // namespace content + +namespace device { +class GeolocationSystemPermissionManager; +} // namespace device namespace gl { class GLShareGroup; @@ -66,6 +70,7 @@ class GLShareGroup; namespace QtWebEngineCore { +class BrowserMainPartsQt; class ShareGroupQt; class ContentBrowserClientQt : public content::ContentBrowserClient @@ -164,6 +169,8 @@ public: #if QT_CONFIG(webengine_geolocation) std::unique_ptr<device::LocationProvider> OverrideSystemLocationProvider() override; #endif + device::GeolocationSystemPermissionManager *GetLocationPermissionManager() override; + bool ShouldIsolateErrorPage(bool in_main_frame) override; bool ShouldUseProcessPerSite(content::BrowserContext *browser_context, const GURL &effective_url) override; bool DoesSiteRequireDedicatedProcess(content::BrowserContext *browser_context, @@ -262,6 +269,7 @@ public: private: scoped_refptr<ShareGroupQt> m_shareGroupQt; + BrowserMainPartsQt *m_browserMainParts = nullptr; }; } // namespace QtWebEngineCore |