Skip to content

Commit

Permalink
WIP: Check location service status on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Apr 30, 2024
1 parent 6c3a1a4 commit 00613e0
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 19 deletions.
15 changes: 12 additions & 3 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions browser/ui/geolocation/geolocation_utils.cc
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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_
32 changes: 32 additions & 0 deletions browser/ui/geolocation/geolocation_utils_mac.mm
Original file line number Diff line number Diff line change
@@ -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 <CoreLocation/CoreLocation.h>

#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
6 changes: 3 additions & 3 deletions browser/ui/geolocation/geolocation_utils_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>

Expand All @@ -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() {
Expand Down Expand Up @@ -49,4 +49,4 @@ bool IsSystemLocationSettingEnabled() {
status == DeviceAccessStatus::DeviceAccessStatus_DeniedByUser);
}

} // namespace geolocation::win
} // namespace geolocation
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<views::WidgetDelegate> widget_delegate_weak_ptr,
PermissionPromptBubbleBaseView* bubble_base_view,
Expand All @@ -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
}

Expand Down

0 comments on commit 00613e0

Please sign in to comment.