0

Revert "[Privacy Hub] Macro alias for geolocation"

This reverts commit bfbcef1764.

Reason for revert: Suspected to cause crbug/1420557

Original change's description:
> [Privacy Hub] Macro alias for geolocation
>
> Instead of repeating the list of OSs that support different aspects of
> geolocation everywhere, we introduce clearly named macros that can be
> used for the purpose of making the code more obvious and easier to
> refactor.
>
> Change-Id: Ic49b986750955066417c5d77112ca99e123eefa7
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4287096
> Reviewed-by: Peter Kvitek <kvitekp@chromium.org>
> Reviewed-by: Peter Beverloo <peter@chromium.org>
> Commit-Queue: Jan Láník <janlanik@google.com>
> Reviewed-by: Mike Taylor <miketaylr@chromium.org>
> Reviewed-by: Marc Treib <treib@chromium.org>
> Reviewed-by: Balazs Engedy <engedy@chromium.org>
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1110966}

Change-Id: I3386a4befc4281fadf0c5464fe9fbdc46810d74b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4301109
Commit-Queue: Jan Láník <janlanik@google.com>
Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
Owners-Override: Dave Tapuska <dtapuska@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1111803}
This commit is contained in:
Jan Láník
2023-03-01 20:53:26 +00:00
committed by Chromium LUCI CQ
parent f9ae90a583
commit d599a243a7
29 changed files with 102 additions and 116 deletions

@ -3478,7 +3478,7 @@ std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
device::GeolocationManager*
ChromeContentBrowserClient::GetGeolocationManager() {
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
return g_browser_process->platform_part()->geolocation_manager();
#else
return nullptr;

@ -41,10 +41,10 @@
#include "chrome/browser/geolocation/geolocation_permission_context_delegate_android.h"
#endif // BUILDFLAG(IS_ANDROID)
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#endif
#endif // BUILDFLAG(IS_MAC)
namespace {
@ -59,10 +59,10 @@ permissions::PermissionManager::PermissionContextMap CreatePermissionContexts(
delegates.geolocation_permission_context_delegate =
std::make_unique<GeolocationPermissionContextDelegate>(profile);
#endif // BUILDFLAG(IS_ANDROID)
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
delegates.geolocation_manager =
g_browser_process->platform_part()->geolocation_manager();
#endif
#endif // BUILDFLAG(IS_MAC)
delegates.media_stream_device_enumerator =
MediaCaptureDevicesDispatcher::GetInstance();
delegates.camera_pan_tilt_zoom_permission_context_delegate =

@ -71,7 +71,6 @@
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "ppapi/buildflags/buildflags.h"
#include "services/device/public/cpp/device_features.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/cpp/geolocation/location_system_permission_status.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
@ -89,6 +88,7 @@
#include "base/mac/mac_util.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#endif
using base::UserMetricsAction;
@ -838,7 +838,7 @@ ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel(
#if BUILDFLAG(IS_MAC)
InitializeSystemMediaPermissionBubble();
return;
#endif
#endif // BUILDFLAG(IS_MAC)
}
SetTitle();
@ -902,7 +902,7 @@ void ContentSettingMediaStreamBubbleModel::OnDoneButtonClicked() {
base::mac::SystemSettingsPane::kPrivacySecurity_Microphone);
}
return;
#endif
#endif // BUILDFLAG(IS_MAC)
}
}
@ -1112,7 +1112,7 @@ void ContentSettingMediaStreamBubbleModel::
SetCustomLink();
set_done_button_text(l10n_util::GetStringUTF16(IDS_OPEN_SETTINGS_LINK));
}
#endif
#endif // BUILDFLAG(IS_MAC)
bool ContentSettingMediaStreamBubbleModel::ShouldShowSystemMediaPermissions() {
#if BUILDFLAG(IS_MAC)
@ -1126,7 +1126,7 @@ bool ContentSettingMediaStreamBubbleModel::ShouldShowSystemMediaPermissions() {
!(MicrophoneAccessed() && MicrophoneBlocked()));
#else
return false;
#endif
#endif // BUILDFLAG(IS_MAC)
}
void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType(
@ -1262,7 +1262,7 @@ ContentSettingGeolocationBubbleModel::ContentSettingGeolocationBubbleModel(
// the bubble to enable the user to trigger the system dialog.
InitializeSystemGeolocationPermissionBubble();
}
#endif
#endif // BUILDFLAG(IS_MAC)
}
ContentSettingGeolocationBubbleModel::~ContentSettingGeolocationBubbleModel() =
@ -1279,7 +1279,7 @@ void ContentSettingGeolocationBubbleModel::OnDoneButtonClicked() {
base::mac::OpenSystemSettingsPane(
base::mac::SystemSettingsPane::kPrivacySecurity_LocationServices);
return;
#endif
#endif // BUILDFLAG(IS_MAC)
}
}
@ -1294,9 +1294,9 @@ void ContentSettingGeolocationBubbleModel::CommitChanges() {
ContentSettingSingleRadioGroup::CommitChanges();
}
#if BUILDFLAG(IS_MAC)
void ContentSettingGeolocationBubbleModel::
InitializeSystemGeolocationPermissionBubble() {
#if BUILDFLAG(IS_MAC)
if (base::FeatureList::IsEnabled(features::kLocationPermissionsExperiment)) {
set_title(l10n_util::GetStringUTF16(
IDS_GEOLOCATION_TURNED_OFF_IN_MACOS_SETTINGS));
@ -1313,8 +1313,8 @@ void ContentSettingGeolocationBubbleModel::
set_done_button_text(l10n_util::GetStringUTF16(IDS_OPEN_SETTINGS_LINK));
set_radio_group(RadioGroup());
show_system_geolocation_bubble_ = true;
#endif // BUILDFLAG(IS_MAC)
}
#endif
void ContentSettingGeolocationBubbleModel::SetCustomLink() {
auto* map = HostContentSettingsMapFactory::GetForProfile(

@ -49,12 +49,12 @@
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/web_contents_tester.h"
#include "services/device/public/cpp/device_features.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#include "ui/base/l10n/l10n_util.h"
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/cpp/geolocation/location_system_permission_status.h"
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@ -725,7 +725,7 @@ TEST_F(ContentSettingBubbleModelTest, AccumulateMediastreamMicAndCamera) {
}
TEST_F(ContentSettingBubbleModelTest, Geolocation) {
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
auto fake_geolocation_manager =
std::make_unique<device::FakeGeolocationManager>();
device::FakeGeolocationManager* geolocation_manager =
@ -733,7 +733,7 @@ TEST_F(ContentSettingBubbleModelTest, Geolocation) {
TestingBrowserProcess::GetGlobal()
->GetTestPlatformPart()
->SetGeolocationManager(std::move(fake_geolocation_manager));
#endif
#endif // BUILDFLAG(IS_MAC)
WebContentsTester::For(web_contents())
->NavigateAndCommit(GURL("https://www.example.com"));
@ -748,7 +748,7 @@ TEST_F(ContentSettingBubbleModelTest, Geolocation) {
CONTENT_SETTING_ALLOW);
content_settings->OnContentAllowed(ContentSettingsType::GEOLOCATION);
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
// System-level geolocation permission is blocked.
{
auto content_setting_bubble_model =
@ -788,7 +788,7 @@ TEST_F(ContentSettingBubbleModelTest, Geolocation) {
// This should be a no-op.
content_setting_bubble_model->CommitChanges();
}
#endif
#endif // BUILDFLAG(IS_MAC)
// Go from allow by default to block by default to allow by default.
{

@ -44,7 +44,6 @@
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/web_contents.h"
#include "services/device/public/cpp/device_features.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/cpp/geolocation/location_system_permission_status.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/pointer/touch_ui_controller.h"
@ -54,11 +53,10 @@
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#include "chrome/browser/browser_process_platform_part.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#endif
using content::WebContents;
@ -106,10 +104,10 @@ class ContentSettingGeolocationImageModel : public ContentSettingImageModel {
bool UpdateAndGetVisibility(WebContents* web_contents) override;
bool IsGeolocationAccessed();
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
bool IsGeolocationAllowedOnASystemLevel();
bool IsGeolocationPermissionDetermined();
#endif
#endif // BUILDFLAG(IS_MAC)
std::unique_ptr<ContentSettingBubbleModel> CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate,
@ -185,7 +183,7 @@ class ContentSettingMediaImageModel : public ContentSettingImageModel {
bool DidMicAccessFailBecauseOfSystemLevelBlock();
bool IsCameraAccessPendingOnSystemLevelPrompt();
bool IsMicAccessPendingOnSystemLevelPrompt();
#endif
#endif // BUILDFLAG(IS_MAC)
std::unique_ptr<ContentSettingBubbleModel> CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate,
@ -580,7 +578,7 @@ bool ContentSettingGeolocationImageModel::UpdateAndGetVisibility(
return true;
}
}
#endif
#endif // BUILDFLAG(IS_MAC)
set_icon(vector_icons::kLocationOnIcon,
is_allowed ? gfx::kNoneIcon : vector_icons::kBlockedBadgeIcon);
@ -592,7 +590,7 @@ bool ContentSettingGeolocationImageModel::UpdateAndGetVisibility(
return true;
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
bool ContentSettingGeolocationImageModel::IsGeolocationAllowedOnASystemLevel() {
device::GeolocationManager* geolocation_manager =
g_browser_process->platform_part()->geolocation_manager();
@ -611,7 +609,7 @@ bool ContentSettingGeolocationImageModel::IsGeolocationPermissionDetermined() {
return permission != device::LocationSystemPermissionStatus::kNotDetermined;
}
#endif
#endif // BUILDFLAG(IS_MAC)
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingGeolocationImageModel::CreateBubbleModelImpl(
@ -834,7 +832,7 @@ bool ContentSettingMediaImageModel::UpdateAndGetVisibility(
}
return true;
}
#endif
#endif // BUILDFLAG(IS_MAC)
DCHECK(IsMicAccessed() || IsCamAccessed());
@ -900,7 +898,7 @@ bool ContentSettingMediaImageModel::IsMicAccessPendingOnSystemLevelPrompt() {
IsMicAccessed() && !IsMicBlockedOnSiteLevel());
}
#endif
#endif // BUILDFLAG(IS_MAC)
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingMediaImageModel::CreateBubbleModelImpl(

@ -46,13 +46,13 @@
#include "content/public/test/web_contents_tester.h"
#include "net/cookies/cookie_options.h"
#include "services/device/public/cpp/device_features.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h"
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/cpp/geolocation/location_system_permission_status.h"
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@ -298,7 +298,7 @@ TEST_F(ContentSettingImageModelTest, SensorAccessed) {
/* explanatory_string_id = */ 0);
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
// Test the correct ContentSettingImageModel for various permutations of site
// and system level Geolocation permissions
TEST_F(ContentSettingImageModelTest, GeolocationAccessPermissionsChanged) {

@ -91,9 +91,6 @@
#if BUILDFLAG(IS_MAC)
#include "base/mac/scoped_nsautorelease_pool.h"
#include "chrome/test/base/scoped_bundle_swizzler_mac.h"
#endif
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@ -182,7 +179,7 @@ FakeDeviceSyncImplFactory* GetFakeDeviceSyncImplFactory() {
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
class ChromeBrowserMainExtraPartsBrowserProcessInjection
: public ChromeBrowserMainExtraParts {
public:
@ -208,7 +205,7 @@ class ChromeBrowserMainExtraPartsBrowserProcessInjection
ChromeBrowserMainExtraPartsBrowserProcessInjection& operator=(
const ChromeBrowserMainExtraPartsBrowserProcessInjection&) = delete;
};
#endif
#endif // BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// For browser tests that depend on AccountManager on Lacros - e.g. tests that
@ -534,7 +531,7 @@ size_t InProcessBrowserTest::GetTestPreCount() {
void InProcessBrowserTest::CreatedBrowserMainParts(
content::BrowserMainParts* parts) {
BrowserTestBase::CreatedBrowserMainParts(parts);
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
static_cast<ChromeBrowserMainParts*>(parts)->AddParts(
std::make_unique<ChromeBrowserMainExtraPartsBrowserProcessInjection>());
#endif

@ -6,13 +6,13 @@
#include "build/build_config.h"
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
TestingBrowserProcessPlatformPart::TestingBrowserProcessPlatformPart() {
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
auto fake_geolocation_manager =
std::make_unique<device::FakeGeolocationManager>();
fake_geolocation_manager->SetSystemPermission(
@ -23,7 +23,7 @@ TestingBrowserProcessPlatformPart::TestingBrowserProcessPlatformPart() {
TestingBrowserProcessPlatformPart::~TestingBrowserProcessPlatformPart() {
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
void TestingBrowserProcessPlatformPart::SetGeolocationManager(
std::unique_ptr<device::GeolocationManager> geolocation_manager) {
geolocation_manager_ = std::move(geolocation_manager);

@ -7,7 +7,6 @@
#include "build/build_config.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
// A TestingBrowserProcessPlatformPart is essentially a
// BrowserProcessPlatformPart except it doesn't have an OomPriorityManager on
@ -20,7 +19,7 @@ class TestingBrowserProcessPlatformPart : public BrowserProcessPlatformPart {
TestingBrowserProcessPlatformPart& operator=(
const TestingBrowserProcessPlatformPart&) = delete;
~TestingBrowserProcessPlatformPart() override;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
void SetGeolocationManager(
std::unique_ptr<device::GeolocationManager> geolocation_manager);
#endif

@ -33,7 +33,6 @@ static_library("browser_util") {
"//components/prefs",
"//components/version_info",
"//content/public/browser",
"//services/device/public/cpp/geolocation",
]
}

@ -9,7 +9,6 @@ include_rules = [
"+components/version_info",
"+content/public/browser",
"+content/public/common",
"+services/device/public/cpp/geolocation/geolocation_manager.h",
"+net",
"+third_party/blink/public/common",
"+third_party/re2",

@ -24,10 +24,9 @@
#include "components/permissions/contexts/nfc_permission_context_android.h"
#endif // BUILDFLAG(IS_ANDROID)
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
// TODO(257906959): rename the file and class to not contain 'mac'
#if BUILDFLAG(IS_MAC)
#include "components/permissions/contexts/geolocation_permission_context_mac.h"
#endif
#endif // BUILDFLAG(IS_MAC)
namespace embedder_support {
@ -48,9 +47,9 @@ CreateDefaultPermissionContexts(content::BrowserContext* browser_context,
DCHECK(delegates.camera_pan_tilt_zoom_permission_context_delegate);
DCHECK(delegates.geolocation_permission_context_delegate);
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
DCHECK(delegates.geolocation_manager);
#endif
#endif // BUILDFLAG(IS_MAC)
DCHECK(delegates.media_stream_device_enumerator);
DCHECK(delegates.nfc_permission_context_delegate);
@ -78,7 +77,7 @@ CreateDefaultPermissionContexts(content::BrowserContext* browser_context,
std::make_unique<permissions::GeolocationPermissionContextAndroid>(
browser_context,
std::move(delegates.geolocation_permission_context_delegate));
#elif PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#elif BUILDFLAG(IS_MAC)
permission_contexts[ContentSettingsType::GEOLOCATION] =
std::make_unique<permissions::GeolocationPermissionContextMac>(
browser_context,

@ -11,12 +11,17 @@
#include "components/permissions/contexts/geolocation_permission_context.h"
#include "components/permissions/contexts/nfc_permission_context.h"
#include "components/permissions/permission_manager.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
namespace content {
class BrowserContext;
} // namespace content
#if BUILDFLAG(IS_MAC)
namespace device {
class GeolocationManager;
} // namespace device
#endif // BUILDFLAG(IS_MAC)
namespace webrtc {
class MediaStreamDeviceEnumerator;
} // namespace webrtc
@ -35,9 +40,9 @@ struct PermissionContextDelegates {
camera_pan_tilt_zoom_permission_context_delegate;
std::unique_ptr<permissions::GeolocationPermissionContext::Delegate>
geolocation_permission_context_delegate;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
raw_ptr<device::GeolocationManager> geolocation_manager;
#endif
#endif // BUILDFLAG(IS_MAC)
raw_ptr<webrtc::MediaStreamDeviceEnumerator> media_stream_device_enumerator;
std::unique_ptr<permissions::NfcPermissionContext::Delegate>
nfc_permission_context_delegate;

@ -59,7 +59,6 @@
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/web_contents_tester.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "url/origin.h"
@ -73,9 +72,6 @@
#if BUILDFLAG(IS_MAC)
#include "components/permissions/contexts/geolocation_permission_context_mac.h"
#endif
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@ -199,7 +195,7 @@ class GeolocationPermissionContextTests
std::vector<std::unique_ptr<MockPermissionPromptFactory>>
mock_permission_prompt_factories_;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
std::unique_ptr<device::FakeGeolocationManager> fake_geolocation_manager_;
#endif
@ -350,7 +346,7 @@ void GeolocationPermissionContextTests::SetUp() {
MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */,
GRANTED);
MockLocationSettings::ClearHasShownLocationSettingsDialog();
#elif PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#elif BUILDFLAG(IS_MAC)
fake_geolocation_manager_ =
std::make_unique<device::FakeGeolocationManager>();
fake_geolocation_manager_->SetSystemPermission(
@ -1121,7 +1117,7 @@ TEST_F(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) {
}
#endif // BUILDFLAG(IS_ANDROID)
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
TEST_F(GeolocationPermissionContextTests,
AllSystemAndSitePermissionCombinations) {
GURL requesting_frame("https://www.example.com/geolocation");

@ -102,7 +102,7 @@
#include "components/crash/content/browser/crash_handler_host_linux.h"
#endif
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@ -246,14 +246,14 @@ base::flat_set<url::Origin> GetIsolatedContextOriginSetFromFlag() {
// needed should be added here so that it's shared between the instances.
struct SharedState {
SharedState() {
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
location_manager = std::make_unique<device::FakeGeolocationManager>();
location_manager->SetSystemPermission(
device::LocationSystemPermissionStatus::kAllowed);
#endif
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
std::unique_ptr<device::FakeGeolocationManager> location_manager;
#endif
@ -430,7 +430,7 @@ void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
}
device::GeolocationManager* ShellContentBrowserClient::GetGeolocationManager() {
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
return GetSharedState().location_manager.get();
#else
return nullptr;

@ -10,7 +10,6 @@ include_rules = [
"+printing",
"+services/cert_verifier/public/mojom",
"+services/network",
"+services/device/public/cpp/geolocation",
"+storage/browser/quota",
"+storage/common/quota",
"+third_party/skia/include",

@ -33,6 +33,10 @@
#include "headless/lib/browser/policy/headless_policies.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/command_line.h"
#endif
@ -93,7 +97,7 @@ void HeadlessBrowserMainParts::PostMainMessageLoopRun() {
#endif
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
device::GeolocationManager* HeadlessBrowserMainParts::GetGeolocationManager() {
return geolocation_manager_.get();
}

@ -12,7 +12,6 @@
#include "content/public/browser/browser_main_parts.h"
#include "headless/public/headless_browser.h"
#include "headless/public/headless_export.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#if defined(HEADLESS_USE_PREFS)
#include "components/prefs/pref_registry_simple.h"
@ -23,6 +22,10 @@
#include "headless/lib/browser/policy/headless_browser_policy_connector.h"
#endif
namespace device {
class GeolocationManager;
} // namespace device
namespace headless {
class HeadlessBrowserImpl;
@ -42,7 +45,7 @@ class HEADLESS_EXPORT HeadlessBrowserMainParts
void WillRunMainMessageLoop(
std::unique_ptr<base::RunLoop>& run_loop) override;
void PostMainMessageLoopRun() override;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
void PreCreateMainMessageLoop() override;
#endif
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_WIN)
@ -50,7 +53,7 @@ class HEADLESS_EXPORT HeadlessBrowserMainParts
#endif
void QuitMainMessageLoop();
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
device::GeolocationManager* GetGeolocationManager();
void SetGeolocationManagerForTesting(
std::unique_ptr<device::GeolocationManager> fake_geolocation_manager);
@ -82,7 +85,7 @@ class HEADLESS_EXPORT HeadlessBrowserMainParts
bool devtools_http_handler_started_ = false;
base::OnceClosure quit_main_message_loop_;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
std::unique_ptr<device::GeolocationManager> geolocation_manager_;
#endif
};

@ -337,7 +337,7 @@ bool HeadlessContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
device::GeolocationManager*
HeadlessContentBrowserClient::GetGeolocationManager() {
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
return browser_->browser_main_parts()->GetGeolocationManager();
#else
return nullptr;

@ -12,7 +12,6 @@ include_rules = [
"+components/devtools/simple_devtools_protocol_client",
"+components/policy",
"+components/prefs",
"+services/device/public/cpp/geolocation/geolocation_manager.h",
"+services/device/public/cpp/test/fake_geolocation_manager.h",
"+tools/v8_context_snapshot/buildflags.h",
]

@ -22,14 +22,13 @@
#include "headless/lib/browser/headless_web_contents_impl.h"
#include "headless/lib/headless_content_main_delegate.h"
#include "headless/public/headless_web_contents.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/v8_context_snapshot/buildflags.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_switches.h"
#include "url/gurl.h"
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@ -93,7 +92,7 @@ void HeadlessBrowserTest::PostRunTestOnMainThread() {
base::RunLoop().RunUntilIdle();
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
void HeadlessBrowserTest::CreatedBrowserMainParts(
content::BrowserMainParts* parts) {
auto fake_geolocation_manager =

@ -12,12 +12,11 @@
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "services/device/device_service.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_network_connection_tracker.h"
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@ -64,7 +63,7 @@ DeviceServiceTestBase::~DeviceServiceTestBase() = default;
void DeviceServiceTestBase::SetUp() {
GeolocationManager* geolocation_manager = nullptr;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
fake_geolocation_manager_ = std::make_unique<FakeGeolocationManager>();
geolocation_manager = fake_geolocation_manager_.get();
#endif

@ -9,7 +9,6 @@
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/mojom/device_service.mojom.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "services/network/test/test_url_loader_factory.h"
@ -53,7 +52,7 @@ class DeviceServiceTestBase : public testing::Test {
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
std::unique_ptr<FakeGeolocationManager> fake_geolocation_manager_;
#endif

@ -18,7 +18,6 @@
#include "components/device_event_log/device_event_log.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/device/geolocation/position_cache.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/cpp/geolocation/geoposition.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
@ -59,7 +58,7 @@ NetworkLocationProvider::NetworkLocationProvider(
base::BindRepeating(&NetworkLocationProvider::OnLocationResponse,
base::Unretained(this)))) {
DCHECK(position_cache_);
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
geolocation_manager_ = geolocation_manager;
permission_observers_ = geolocation_manager->GetObserverList();
permission_observers_->AddObserver(this);
@ -74,7 +73,7 @@ NetworkLocationProvider::NetworkLocationProvider(
NetworkLocationProvider::~NetworkLocationProvider() {
DCHECK(thread_checker_.CalledOnValidThread());
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
permission_observers_->RemoveObserver(this);
#endif
if (IsStarted())
@ -94,7 +93,7 @@ void NetworkLocationProvider::OnPermissionGranted() {
RequestPosition();
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
void NetworkLocationProvider::OnSystemPermissionUpdated(
LocationSystemPermissionStatus new_status) {
is_awaiting_initial_permission_status_ = false;
@ -120,7 +119,7 @@ void NetworkLocationProvider::OnSystemPermissionUpdated(
void NetworkLocationProvider::OnWifiDataUpdate() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(IsStarted());
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
if (!is_system_permission_granted_) {
if (!is_awaiting_initial_permission_status_) {
mojom::Geoposition error_position;
@ -216,7 +215,7 @@ void NetworkLocationProvider::RequestPosition() {
<< is_new_data_available_ << " is_wifi_data_complete_="
<< is_wifi_data_complete_;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
if (!is_system_permission_granted_) {
return;
}

@ -30,7 +30,7 @@ namespace device {
class PositionCache;
class NetworkLocationProvider : public LocationProvider
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
,
public GeolocationManager::PermissionObserver
#endif
@ -55,7 +55,7 @@ class NetworkLocationProvider : public LocationProvider
const mojom::Geoposition& GetPosition() override;
void OnPermissionGranted() override;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
// GeolocationPermissionObserver implementation.
void OnSystemPermissionUpdated(
LocationSystemPermissionStatus new_status) override;
@ -81,7 +81,7 @@ class NetworkLocationProvider : public LocationProvider
WifiDataProviderHandle::WifiDataUpdateCallback wifi_data_update_callback_;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
// Used to keep track of macOS System Permission changes. Also, ensures
// lifetime of PermissionObserverList as the BrowserProcess may destroy its
// reference on the UI Thread before we destroy this provider.
@ -113,7 +113,7 @@ class NetworkLocationProvider : public LocationProvider
base::ThreadChecker thread_checker_;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
bool is_system_permission_granted_ = false;
bool is_awaiting_initial_permission_status_ = true;

@ -29,7 +29,6 @@
#include "services/device/geolocation/fake_position_cache.h"
#include "services/device/geolocation/location_arbitrator.h"
#include "services/device/geolocation/wifi_data_provider.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/device/public/cpp/geolocation/geoposition.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
@ -37,7 +36,7 @@
#include "services/network/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif
@ -139,14 +138,13 @@ class GeolocationNetworkProviderTest : public testing::Test {
std::unique_ptr<LocationProvider> CreateProvider(
bool set_permission_granted,
const std::string& api_key = std::string()) {
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
fake_geolocation_manager_ = std::make_unique<FakeGeolocationManager>();
auto provider = std::make_unique<NetworkLocationProvider>(
test_url_loader_factory_.GetSafeWeakWrapper(),
fake_geolocation_manager_.get(),
base::SingleThreadTaskRunner::GetCurrentDefault(), api_key,
&position_cache_);
// TODO(janlan): have a look at this
// For macOS we must simulate the granting of location permission
if (grant_system_permission_by_default_) {
fake_geolocation_manager_->SetSystemPermission(
@ -168,7 +166,7 @@ class GeolocationNetworkProviderTest : public testing::Test {
bool grant_system_permission_by_default_ = true;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
std::unique_ptr<FakeGeolocationManager> fake_geolocation_manager_;
#endif
@ -648,10 +646,9 @@ TEST_F(GeolocationNetworkProviderTest, NetworkRequestResponseMalformed) {
EXPECT_TRUE(position->error_technical.empty());
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
// Tests that, callbacks and network requests are never made until we have
// system location permission.
// TODO:(janlanik): rename
TEST_F(GeolocationNetworkProviderTest, MacOSSystemPermissionsTest) {
// Do not grant system permission when creating the provider.
grant_system_permission_by_default_ = false;

@ -11,7 +11,7 @@ GeolocationManager::GeolocationManager(
std::unique_ptr<SystemGeolocationSource> system_geolocation_source)
: system_geolocation_source_(std::move(system_geolocation_source)),
observers_(base::MakeRefCounted<PermissionObserverList>())
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_APPLE)
,
position_observers_(base::MakeRefCounted<PositionObserverList>())
#endif
@ -20,7 +20,7 @@ GeolocationManager::GeolocationManager(
system_geolocation_source_->RegisterPermissionUpdateCallback(
base::BindRepeating(&GeolocationManager::UpdateSystemPermission,
weak_factory_.GetWeakPtr()));
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_APPLE)
system_geolocation_source_->RegisterPositionUpdateCallback(
base::BindRepeating(&GeolocationManager::NotifyPositionObservers,
weak_factory_.GetWeakPtr()));

@ -9,11 +9,7 @@
#include "build/build_config.h"
#include "build/buildflag.h"
#define PLATFORM_REQUIRES_GEOLOCATION_PERMISSION \
(BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_CHROMEOS))
#define PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER BUILDFLAG(IS_APPLE)
#if PLATFORM_REQUIRES_GEOLOCATION_PERMISSION
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_CHROMEOS)
#include <memory>
#include "base/memory/weak_ptr.h"
@ -22,13 +18,13 @@
#include "services/device/public/cpp/geolocation/system_geolocation_source.h"
#endif
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_APPLE)
#include "services/device/public/mojom/geoposition.mojom.h"
#endif
namespace device {
#if !PLATFORM_REQUIRES_GEOLOCATION_PERMISSION
#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_CHROMEOS)
// Default empty implementation of Geolocation Manager. It is used on operation
// systems for which we don't support system-level geolocation. A separate class
// (as opposed to nullptr) makes sure no unsupported calls are made in such
@ -50,7 +46,7 @@ class COMPONENT_EXPORT(GEOLOCATION) GeolocationManager {
using PermissionObserverList =
base::ObserverListThreadSafe<PermissionObserver>;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_APPLE)
class PositionObserver : public base::CheckedObserver {
public:
virtual void OnPositionUpdated(const mojom::Geoposition& position) = 0;
@ -75,7 +71,7 @@ class COMPONENT_EXPORT(GEOLOCATION) GeolocationManager {
// Returns the list of permission observers.
scoped_refptr<PermissionObserverList> GetObserverList() const;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_APPLE)
// Starts the system level process for watching position updates. These
// updates will trigger a call to and observers in the |position_observers_|
// list. Upon call the |position_observers_| will be notified of the current
@ -98,7 +94,7 @@ class COMPONENT_EXPORT(GEOLOCATION) GeolocationManager {
private:
void UpdateSystemPermission(LocationSystemPermissionStatus status);
void NotifyPermissionObservers();
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_APPLE)
void NotifyPositionObservers(const mojom::Geoposition& position);
#endif
@ -110,7 +106,7 @@ class COMPONENT_EXPORT(GEOLOCATION) GeolocationManager {
LocationSystemPermissionStatus permission_cache_ =
LocationSystemPermissionStatus::kNotDetermined;
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_APPLE)
mojom::Geoposition last_position_;
// Using scoped_refptr so objects can hold a reference and ensure this list
// is not destroyed on shutdown before it had a chance to remove itself from

@ -31,7 +31,7 @@ class SourceImpl : public device::SystemGeolocationSource {
callback_ = callback;
}
#if PLATFORM_REQUIRES_SINGLETON_GEOPOSITION_OBSERVER
#if BUILDFLAG(IS_MAC)
// This methods are not used in the tests, but need to be implemented on Mac.
void RegisterPositionUpdateCallback(PositionUpdateCallback) override {}
void StartWatchingPosition(bool) override {}