diff --git a/content/shell/BUILD.gn b/content/shell/BUILD.gn
index e2a6fb3d77d6e..1e96da71a8437 100644
--- a/content/shell/BUILD.gn
+++ b/content/shell/BUILD.gn
@@ -225,6 +225,7 @@ static_library("content_shell_lib") {
"browser/bluetooth/ios/shell_bluetooth_device_list_view_controller.mm",
"browser/bluetooth/shell_bluetooth_delegate_impl_client.cc",
"browser/bluetooth/shell_bluetooth_delegate_impl_client.h",
+ "browser/shell_browser_main_parts_ios.mm",
"browser/shell_file_select_helper.cc",
"browser/shell_file_select_helper.h",
"browser/shell_platform_delegate_ios.mm",
diff --git a/content/shell/app/ios-Info.plist b/content/shell/app/ios-Info.plist
index 278f1aaa96dfd..ac61d73599dee 100644
--- a/content/shell/app/ios-Info.plist
+++ b/content/shell/app/ios-Info.plist
@@ -54,5 +54,7 @@
Allow content_shell access to camera
NSBluetoothAlwaysUsageDescription
Allow content_shell access to Bluetooth
+ NSLocationWhenInUseUsageDescription
+ Allow content_shell access to location
diff --git a/content/shell/browser/shell_browser_main_parts.h b/content/shell/browser/shell_browser_main_parts.h
index 53f82fed9421c..5338f4f4b3f0a 100644
--- a/content/shell/browser/shell_browser_main_parts.h
+++ b/content/shell/browser/shell_browser_main_parts.h
@@ -12,6 +12,10 @@
#include "content/public/browser/browser_main_parts.h"
#include "content/shell/browser/shell_browser_context.h"
+#if BUILDFLAG(IS_IOS)
+#include "services/device/public/cpp/geolocation/geolocation_manager.h"
+#endif
+
namespace performance_manager {
class PerformanceManagerLifetime;
} // namespace performance_manager
@@ -52,6 +56,9 @@ class ShellBrowserMainParts : public BrowserMainParts {
std::unique_ptr& run_loop) override;
void PostMainMessageLoopRun() override;
void PostDestroyThreads() override;
+#if BUILDFLAG(IS_IOS)
+ device::GeolocationManager* GetGeolocationManager();
+#endif
ShellBrowserContext* browser_context() { return browser_context_.get(); }
ShellBrowserContext* off_the_record_browser_context() {
@@ -84,6 +91,9 @@ class ShellBrowserMainParts : public BrowserMainParts {
#if BUILDFLAG(IS_FUCHSIA)
std::unique_ptr fuchsia_view_presenter_;
#endif
+#if BUILDFLAG(IS_IOS)
+ std::unique_ptr geolocation_manager_;
+#endif
};
} // namespace content
diff --git a/content/shell/browser/shell_browser_main_parts_ios.mm b/content/shell/browser/shell_browser_main_parts_ios.mm
new file mode 100644
index 0000000000000..b9d0f28a9b046
--- /dev/null
+++ b/content/shell/browser/shell_browser_main_parts_ios.mm
@@ -0,0 +1,23 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/shell/browser/shell_browser_main_parts.h"
+
+#include "services/device/public/cpp/geolocation/system_geolocation_source_mac.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+namespace content {
+
+device::GeolocationManager* ShellBrowserMainParts::GetGeolocationManager() {
+ if (!geolocation_manager_) {
+ geolocation_manager_ =
+ device::SystemGeolocationSourceMac::CreateGeolocationManagerOnMac();
+ }
+ return geolocation_manager_.get();
+}
+
+} // namespace content
diff --git a/content/shell/browser/shell_content_browser_client.cc b/content/shell/browser/shell_content_browser_client.cc
index 534eaa8609b0d..442de361a3d29 100644
--- a/content/shell/browser/shell_content_browser_client.cc
+++ b/content/shell/browser/shell_content_browser_client.cc
@@ -102,7 +102,7 @@
#include "components/crash/content/browser/crash_handler_host_linux.h"
#endif
-#if BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@@ -254,14 +254,14 @@ base::flat_set GetIsolatedContextOriginSetFromFlag() {
// needed should be added here so that it's shared between the instances.
struct SharedState {
SharedState() {
-#if BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_MAC)
location_manager = std::make_unique();
location_manager->SetSystemPermission(
device::LocationSystemPermissionStatus::kAllowed);
#endif
}
-#if BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_MAC)
std::unique_ptr location_manager;
#endif
@@ -438,8 +438,12 @@ void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
}
device::GeolocationManager* ShellContentBrowserClient::GetGeolocationManager() {
-#if BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_MAC)
return GetSharedState().location_manager.get();
+#elif BUILDFLAG(IS_IOS)
+ // TODO(crbug.com/1431447, 1411704): Unify this to FakeGeolocationManager once
+ // exploring browser features in ContentShell on iOS is done.
+ return GetSharedState().shell_browser_main_parts->GetGeolocationManager();
#else
return nullptr;
#endif
diff --git a/services/device/public/cpp/device_features.cc b/services/device/public/cpp/device_features.cc
index bdd85a0bf6b07..5e32affe40113 100644
--- a/services/device/public/cpp/device_features.cc
+++ b/services/device/public/cpp/device_features.cc
@@ -17,7 +17,7 @@ BASE_FEATURE(kWinrtGeolocationImplementation,
"WinrtGeolocationImplementation",
base::FEATURE_DISABLED_BY_DEFAULT);
// Enables usage of the CoreLocation API for LocationProvider instead of
-// NetworkLocationProvider for macOS.
+// NetworkLocationProvider for macOS or iOS.
BASE_FEATURE(kMacCoreLocationBackend,
"MacCoreLocationBackend",
base::FEATURE_DISABLED_BY_DEFAULT);
diff --git a/services/device/public/cpp/geolocation/system_geolocation_source_mac.h b/services/device/public/cpp/geolocation/system_geolocation_source_mac.h
index 800714f466a21..64c87e139ece7 100644
--- a/services/device/public/cpp/geolocation/system_geolocation_source_mac.h
+++ b/services/device/public/cpp/geolocation/system_geolocation_source_mac.h
@@ -40,6 +40,9 @@ class COMPONENT_EXPORT(GEOLOCATION) SystemGeolocationSourceMac
void StartWatchingPosition(bool high_accuracy) override;
void StopWatchingPosition() override;
+ // Calls requestWhenInUseAuthorization from CLLocationManager.
+ void AppAttemptsToUseGeolocation() override;
+
private:
LocationSystemPermissionStatus GetSystemPermission() const;
diff --git a/services/device/public/cpp/geolocation/system_geolocation_source_mac.mm b/services/device/public/cpp/geolocation/system_geolocation_source_mac.mm
index e4f2cc1bdcb2a..9b0b59ea7f1a2 100644
--- a/services/device/public/cpp/geolocation/system_geolocation_source_mac.mm
+++ b/services/device/public/cpp/geolocation/system_geolocation_source_mac.mm
@@ -10,6 +10,7 @@
#include "base/functional/callback_helpers.h"
#include "base/sequence_checker.h"
+#include "build/build_config.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
@@ -109,6 +110,14 @@ - (BOOL)permissionInitialized;
return LocationSystemPermissionStatus::kDenied;
}
+void SystemGeolocationSourceMac::AppAttemptsToUseGeolocation() {
+#if BUILDFLAG(IS_IOS)
+ if (@available(ios 8.0, macOS 10.15, *)) {
+ [location_manager_ requestWhenInUseAuthorization];
+ }
+#endif
+}
+
} // namespace device
@implementation GeolocationManagerDelegate
@@ -131,6 +140,15 @@ - (void)locationManager:(CLLocationManager*)manager
} else {
_hasPermission = NO;
}
+
+#if BUILDFLAG(IS_IOS)
+ if (@available(iOS 8.0, *)) {
+ if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {
+ _hasPermission = YES;
+ }
+ }
+#endif
+
_manager->PermissionUpdated();
}