summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2021-12-03 12:11:06 +0100
committerPeter Varga <pvarga@inf.u-szeged.hu>2021-12-08 11:40:32 +0100
commitca1074f7d0b91ccb9290acbfe51ecab54ad2efb9 (patch)
treec70c37c9db21a7c8baa53b75c427eca709dbeea6
parentb6099cd9d1efab2af4a38476b3f543796f26f065 (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. Pick-to: 6.2 Change-Id: I25d51c9ce8911b95ff69cc72bc6aae7023e7edbe Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/browser_main_parts_qt.cpp26
-rw-r--r--src/core/browser_main_parts_qt.h11
-rw-r--r--src/core/content_browser_client_qt.cpp15
-rw-r--r--src/core/content_browser_client_qt.h10
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 32d8d839c..74b69bf98 100644
--- a/src/core/browser_main_parts_qt.cpp
+++ b/src/core/browser_main_parts_qt.cpp
@@ -88,6 +88,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
@@ -226,6 +227,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;
@@ -250,6 +266,9 @@ int BrowserMainPartsQt::PreEarlyInitialization()
void BrowserMainPartsQt::PreCreateMainMessageLoop()
{
+#if defined(OS_MAC)
+ m_locationPermissionManager = std::make_unique<FakeSystemGeolocationPermissionManager>();
+#endif
}
void BrowserMainPartsQt::PostCreateMainMessageLoop()
@@ -324,4 +343,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 f8a754632..3eb86a657 100644
--- a/src/core/browser_main_parts_qt.h
+++ b/src/core/browser_main_parts_qt.h
@@ -52,6 +52,10 @@ namespace content {
class ServiceManagerConnection;
}
+namespace device {
+class GeolocationSystemPermissionManager;
+}
+
namespace performance_manager {
class PerformanceManager;
class PerformanceManagerRegistry;
@@ -75,11 +79,18 @@ 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_;
std::unique_ptr<WebUsbDetectorQt> m_webUsbDetector;
+#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 68f903154..8fbb2d668 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -72,6 +72,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"
@@ -234,7 +235,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)
@@ -588,6 +592,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 4bae6186f..35730f9d2 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
@@ -167,6 +172,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,
@@ -266,6 +273,7 @@ public:
private:
scoped_refptr<ShareGroupQt> m_shareGroupQt;
+ BrowserMainPartsQt *m_browserMainParts = nullptr;
};
} // namespace QtWebEngineCore