diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 4724889c569b..d6d1de6b7418 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -606,11 +606,20 @@ source_set("ui") { ] } - if (is_win) { + if (is_win || is_mac || is_linux) { sources += [ - "geolocation/geolocation_utils_win.cc", - "geolocation/geolocation_utils_win.h", + "geolocation/geolocation_utils.cc", + "geolocation/geolocation_utils.h", ] + + if (is_win) { + sources += [ "geolocation/geolocation_utils_win.cc" ] + } + + if (is_mac) { + sources += [ "geolocation/geolocation_utils_mac.mm" ] + frameworks = [ "CoreLocation.framework" ] + } } # brave's obsolete infobar is only used on Windows and Mac now. diff --git a/browser/ui/geolocation/geolocation_utils.cc b/browser/ui/geolocation/geolocation_utils.cc new file mode 100644 index 000000000000..94cd3f606100 --- /dev/null +++ b/browser/ui/geolocation/geolocation_utils.cc @@ -0,0 +1,18 @@ +/* Copyright (c) 2024 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/geolocation/geolocation_utils.h" + +#include "build/build_config.h" + +namespace geolocation { + +#if BUILDFLAG(IS_LINUX) +bool IsSystemLocationSettingEnabled() { + return false; +} +#endif + +} // namespace geolocation diff --git a/browser/ui/geolocation/geolocation_utils_win.h b/browser/ui/geolocation/geolocation_utils.h similarity index 60% rename from browser/ui/geolocation/geolocation_utils_win.h rename to browser/ui/geolocation/geolocation_utils.h index 178754df8788..093234cb0745 100644 --- a/browser/ui/geolocation/geolocation_utils_win.h +++ b/browser/ui/geolocation/geolocation_utils.h @@ -3,14 +3,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_WIN_H_ -#define BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_WIN_H_ +#ifndef BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_H_ +#define BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_H_ -namespace geolocation::win { +namespace geolocation { // True when system location service is available to applications. bool IsSystemLocationSettingEnabled(); -} // namespace geolocation::win +} // namespace geolocation -#endif // BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_WIN_H_ +#endif // BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_H_ diff --git a/browser/ui/geolocation/geolocation_utils_mac.mm b/browser/ui/geolocation/geolocation_utils_mac.mm new file mode 100644 index 000000000000..bc1a17f11dce --- /dev/null +++ b/browser/ui/geolocation/geolocation_utils_mac.mm @@ -0,0 +1,32 @@ +/* Copyright (c) 2024 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/geolocation/geolocation_utils.h" + +#import + +#include "base/logging.h" + +namespace geolocation { + +bool IsSystemLocationSettingEnabled() { + // Service is off globally. + if (![CLLocationManager locationServicesEnabled]) { + return false; + } + + CLLocationManager* manager = [[CLLocationManager alloc] init]; + if (@available(macOS 11.0, *)) { + auto status = [manager authorizationStatus]; + LOG(ERROR) << __func__ << " ##### " << (int)status; + if (status == kCLAuthorizationStatusAuthorized) { + return true; + } + } + + return false; +} + +} // namespace geolocation diff --git a/browser/ui/geolocation/geolocation_utils_win.cc b/browser/ui/geolocation/geolocation_utils_win.cc index e4444bea5714..563cd12b8867 100644 --- a/browser/ui/geolocation/geolocation_utils_win.cc +++ b/browser/ui/geolocation/geolocation_utils_win.cc @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/browser/ui/geolocation/geolocation_utils_win.h" +#include "brave/browser/ui/geolocation/geolocation_utils.h" #include @@ -20,7 +20,7 @@ using ABI::Windows::Devices::Enumeration::IDeviceAccessInformation; using ABI::Windows::Devices::Enumeration::IDeviceAccessInformationStatics; using Microsoft::WRL::ComPtr; -namespace geolocation::win { +namespace geolocation { // Copied from services/device/geolocation/win/location_provider_winrt.cc bool IsSystemLocationSettingEnabled() { @@ -49,4 +49,4 @@ bool IsSystemLocationSettingEnabled() { status == DeviceAccessStatus::DeviceAccessStatus_DeniedByUser); } -} // namespace geolocation::win +} // namespace geolocation diff --git a/chromium_src/chrome/browser/ui/views/permissions/permission_prompt_bubble_base_view.cc b/chromium_src/chrome/browser/ui/views/permissions/permission_prompt_bubble_base_view.cc index 70342d243368..1b8f0b98da44 100644 --- a/chromium_src/chrome/browser/ui/views/permissions/permission_prompt_bubble_base_view.cc +++ b/chromium_src/chrome/browser/ui/views/permissions/permission_prompt_bubble_base_view.cc @@ -13,6 +13,7 @@ #include "base/strings/string_util.h" #include "base/task/thread_pool.h" #include "brave/browser/brave_geolocation_permission_tab_helper.h" +#include "brave/browser/ui/geolocation/geolocation_utils.h" #include "brave/browser/ui/views/dialog_footnote_utils.h" #include "brave/browser/ui/views/infobars/custom_styled_label.h" #include "brave/components/constants/url_constants.h" @@ -52,10 +53,6 @@ #include "ui/views/window/dialog_client_view.h" #include "ui/views/window/dialog_delegate.h" -#if BUILDFLAG(IS_WIN) -#include "brave/browser/ui/geolocation/geolocation_utils_win.h" -#endif - #if BUILDFLAG(ENABLE_WIDEVINE) #include "brave/browser/widevine/widevine_permission_request.h" #endif @@ -333,7 +330,7 @@ void AddGeolocationDescriptionIfNeeded( base::ThreadPool::CreateCOMSTATaskRunner({base::MayBlock()}) ->PostTaskAndReplyWithResult( FROM_HERE, - base::BindOnce(&geolocation::win::IsSystemLocationSettingEnabled), + base::BindOnce(&geolocation::IsSystemLocationSettingEnabled), base::BindOnce( [](base::WeakPtr widget_delegate_weak_ptr, PermissionPromptBubbleBaseView* bubble_base_view, @@ -354,9 +351,8 @@ void AddGeolocationDescriptionIfNeeded( bubble_base_view->AsWeakPtr(), bubble_base_view, browser, enable_high_accuracy)); #else - AddGeolocationDescription(bubble_base_view, browser, - /*use_exact_location_label*/ false, - /*enable_high_accuracy*/ false); + AddGeolocationDescription(bubble_base_view, browser, enable_high_accuracy, + geolocation::IsSystemLocationSettingEnabled()); #endif }