fix: geolocation crashes electron on macOS (#29343) (#29913)

This commit is contained in:
Omar Kilani 2021-06-28 20:26:57 -07:00 committed by GitHub
parent 9142563748
commit 1b4ce6c69a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 1 deletions

View file

@ -882,7 +882,13 @@ ElectronBrowserClient::GetSystemNetworkContext() {
std::unique_ptr<content::BrowserMainParts>
ElectronBrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& params) {
return std::make_unique<ElectronBrowserMainParts>(params);
auto browser_main_parts = std::make_unique<ElectronBrowserMainParts>(params);
#if defined(OS_MAC)
browser_main_parts_ = browser_main_parts.get();
#endif
return browser_main_parts;
}
void ElectronBrowserClient::WebNotificationAllowed(
@ -1618,4 +1624,12 @@ void ElectronBrowserClient::RegisterBrowserInterfaceBindersForServiceWorker(
base::BindRepeating(&BindBadgeServiceForServiceWorker));
}
device::GeolocationManager* ElectronBrowserClient::GetGeolocationManager() {
#if defined(OS_MAC)
return browser_main_parts_->GetGeolocationManager();
#else
return nullptr;
#endif
}
} // namespace electron

View file

@ -34,6 +34,7 @@ class SSLCertRequestInfo;
namespace electron {
class ElectronBrowserMainParts;
class NotificationPresenter;
class PlatformNotificationService;
@ -88,6 +89,8 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
content::BluetoothDelegate* GetBluetoothDelegate() override;
device::GeolocationManager* GetGeolocationManager() override;
protected:
void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
content::SpeechRecognitionManagerDelegate*
@ -299,6 +302,10 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
std::unique_ptr<ElectronSerialDelegate> serial_delegate_;
std::unique_ptr<ElectronBluetoothDelegate> bluetooth_delegate_;
#if defined(OS_MAC)
ElectronBrowserMainParts* browser_main_parts_ = nullptr;
#endif
DISALLOW_COPY_AND_ASSIGN(ElectronBrowserClient);
};

View file

@ -93,6 +93,7 @@
#endif
#if defined(OS_MAC)
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "shell/browser/ui/cocoa/views_delegate_mac.h"
#else
#include "shell/browser/ui/views/electron_views_delegate.h"
@ -553,6 +554,12 @@ ElectronBrowserMainParts::GetGeolocationControl() {
return geolocation_control_.get();
}
#if defined(OS_MAC)
device::GeolocationManager* ElectronBrowserMainParts::GetGeolocationManager() {
return geolocation_manager_.get();
}
#endif
IconManager* ElectronBrowserMainParts::GetIconManager() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!icon_manager_.get())

View file

@ -39,6 +39,10 @@ class GtkUiPlatform;
}
#endif
namespace device {
class GeolocationManager;
} // namespace device
namespace electron {
class ElectronBrowserContext;
@ -83,6 +87,10 @@ class ElectronBrowserMainParts : public content::BrowserMainParts {
// used to enable the location services once per client.
device::mojom::GeolocationControl* GetGeolocationControl();
#if defined(OS_MAC)
device::GeolocationManager* GetGeolocationManager();
#endif
// Returns handle to the class responsible for extracting file icons.
IconManager* GetIconManager();
@ -161,6 +169,10 @@ class ElectronBrowserMainParts : public content::BrowserMainParts {
mojo::Remote<device::mojom::GeolocationControl> geolocation_control_;
#if defined(OS_MAC)
std::unique_ptr<device::GeolocationManager> geolocation_manager_;
#endif
static ElectronBrowserMainParts* self_;
DISALLOW_COPY_AND_ASSIGN(ElectronBrowserMainParts);

View file

@ -7,6 +7,7 @@
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/path_service.h"
#include "services/device/public/cpp/geolocation/geolocation_manager_impl_mac.h"
#import "shell/browser/mac/electron_application.h"
#include "shell/browser/mac/electron_application_delegate.h"
#include "shell/common/electron_paths.h"
@ -27,6 +28,8 @@ void ElectronBrowserMainParts::PreCreateMainMessageLoop() {
[[NSUserDefaults standardUserDefaults]
setObject:@"NO"
forKey:@"NSTreatUnknownArgumentsAsOpen"];
geolocation_manager_ = device::GeolocationManagerImpl::Create();
}
void ElectronBrowserMainParts::FreeAppDelegate() {