-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Geolocation System Permission in Permissions API on macOS.
Currently the Permissions API is only using the site level permission. This is confusing when the site level is allowed and the system level permission is denied. The Permission API will say you are allowed to but the request says permission denied. This change creates a GeolocationPermissionContextMac which subscribes to system permission updates and injects them where needed. Bug: 1200933 Change-Id: I2c5bdc9785ce3481d3d78bf4523ffab967789af8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2877775 Commit-Queue: James Hollyer <jameshollyer@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Reviewed-by: Balazs Engedy <engedy@chromium.org> Reviewed-by: Clark DuVall <cduvall@chromium.org> Cr-Commit-Position: refs/heads/master@{#892317}
- Loading branch information
1 parent
c6499b8
commit 0fa6eca
Showing
8 changed files
with
283 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
components/permissions/contexts/geolocation_permission_context_mac.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/permissions/contexts/geolocation_permission_context_mac.h" | ||
|
||
#include "content/public/browser/browser_thread.h" | ||
#include "services/device/public/cpp/geolocation/location_system_permission_status.h" | ||
|
||
namespace permissions { | ||
GeolocationPermissionContextMac::GeolocationPermissionContextMac( | ||
content::BrowserContext* browser_context, | ||
std::unique_ptr<Delegate> delegate, | ||
device::GeolocationManager* geolocation_manager) | ||
: GeolocationPermissionContext(browser_context, std::move(delegate)) { | ||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||
system_permission_observers_ = geolocation_manager->GetObserverList(); | ||
system_permission_observers_->AddObserver(this); | ||
system_permission_ = geolocation_manager->GetSystemPermission(); | ||
} | ||
|
||
GeolocationPermissionContextMac::~GeolocationPermissionContextMac() { | ||
system_permission_observers_->RemoveObserver(this); | ||
} | ||
|
||
ContentSetting GeolocationPermissionContextMac::GetPermissionStatusInternal( | ||
content::RenderFrameHost* render_frame_host, | ||
const GURL& requesting_origin, | ||
const GURL& embedding_origin) const { | ||
auto site_permission = | ||
GeolocationPermissionContext::GetPermissionStatusInternal( | ||
render_frame_host, requesting_origin, embedding_origin); | ||
if (site_permission != ContentSetting::CONTENT_SETTING_ALLOW) | ||
return site_permission; | ||
|
||
switch (system_permission_) { | ||
case LocationSystemPermissionStatus::kNotDetermined: | ||
return ContentSetting::CONTENT_SETTING_ASK; | ||
case LocationSystemPermissionStatus::kDenied: | ||
return ContentSetting::CONTENT_SETTING_BLOCK; | ||
case LocationSystemPermissionStatus::kAllowed: | ||
return ContentSetting::CONTENT_SETTING_ALLOW; | ||
} | ||
} | ||
|
||
void GeolocationPermissionContextMac::OnSystemPermissionUpdated( | ||
LocationSystemPermissionStatus new_status) { | ||
system_permission_ = new_status; | ||
for (permissions::Observer& obs : permission_observers_) { | ||
obs.OnPermissionChanged(ContentSettingsPattern::Wildcard(), | ||
ContentSettingsPattern::Wildcard(), | ||
ContentSettingsType::GEOLOCATION); | ||
} | ||
} | ||
|
||
} // namespace permissions |
66 changes: 66 additions & 0 deletions
66
components/permissions/contexts/geolocation_permission_context_mac.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_PERMISSIONS_CONTEXTS_GEOLOCATION_PERMISSION_CONTEXT_MAC_H_ | ||
#define COMPONENTS_PERMISSIONS_CONTEXTS_GEOLOCATION_PERMISSION_CONTEXT_MAC_H_ | ||
|
||
// The flow for geolocation permissions on macOS needs to take into account | ||
// the system geolocation settings so it differs from the other platforms. It | ||
// works as follows. | ||
// GeolocationPermissionContextMac::RequestPermission intercepts the flow | ||
// and proceeds to check the system location permission. | ||
// If enabled, it proceeds with the per site flow via | ||
// GeolocationPermissionContext (which will check per site permissions, create | ||
// infobars, etc.). | ||
// | ||
// It also fires OnPermissionChanged when the effective permission state may | ||
// have changed when the system permission is updated. | ||
|
||
#include "components/permissions/contexts//geolocation_permission_context.h" | ||
#include "services/device/public/cpp/geolocation/geolocation_manager.h" | ||
|
||
namespace permissions { | ||
|
||
using device::LocationSystemPermissionStatus; | ||
|
||
class GeolocationPermissionContextMac | ||
: public GeolocationPermissionContext, | ||
public device::GeolocationManager::PermissionObserver { | ||
public: | ||
GeolocationPermissionContextMac( | ||
content::BrowserContext* browser_context, | ||
std::unique_ptr<Delegate> delegate, | ||
device::GeolocationManager* geolocation_manager); | ||
~GeolocationPermissionContextMac() override; | ||
|
||
GeolocationPermissionContextMac(const GeolocationPermissionContextMac&) = | ||
delete; | ||
GeolocationPermissionContextMac& operator=( | ||
const GeolocationPermissionContextMac&) = delete; | ||
|
||
private: | ||
// GeolocationPermissionContext: | ||
ContentSetting GetPermissionStatusInternal( | ||
content::RenderFrameHost* render_frame_host, | ||
const GURL& requesting_origin, | ||
const GURL& embedding_origin) const override; | ||
|
||
// device::GeolocationManager::PermissionObserver: | ||
void OnSystemPermissionUpdated( | ||
LocationSystemPermissionStatus new_status) override; | ||
|
||
LocationSystemPermissionStatus system_permission_ = | ||
LocationSystemPermissionStatus::kNotDetermined; | ||
|
||
scoped_refptr<device::GeolocationManager::PermissionObserverList> | ||
system_permission_observers_; | ||
|
||
// Must be the last member, to ensure that it will be destroyed first, which | ||
// will invalidate weak pointers. | ||
base::WeakPtrFactory<GeolocationPermissionContextMac> weak_factory_{this}; | ||
}; | ||
|
||
} // namespace permissions | ||
|
||
#endif // COMPONENTS_PERMISSIONS_CONTEXTS_GEOLOCATION_PERMISSION_CONTEXT_MAC_H_ |
Oops, something went wrong.