From 9e111593fcdf2aca8ff58f98f8d587de0d2bcf6f Mon Sep 17 00:00:00 2001 From: Claudio DeSouza Date: Thu, 11 Sep 2025 16:51:51 +0100 Subject: [PATCH] [cr142] Reanchoring `PermissionController` overrides A few functions are now renamed for this type, and some of them now return `content::PermissionResult`. Chromium changes: https://chromium.googlesource.com/chromium/src/+/342191c07aadd1a8fb9833414c4c9a53ac810bea commit 342191c07aadd1a8fb9833414c4c9a53ac810bea Author: Florian Jacky Date: Wed Sep 10 07:32:47 2025 -0700 [PermissionOptions] Multi-state permission subscriptions & setting changes With permissions with options, a subscription will no longer be uniquely defined by a permission type, since a permission option change may or may not impact a status change description (as the status depends on the request). Additionally, permission implementations may need to be notified about permission setting changes that do not affect the permission status. This CL refactors the infrastructure to enable subscribing to PermissionResult changes instead of simply permission status changes. PermissionResults contain the PermissionStatus, a PermissionStatusSource, and an optional PermissionSetting, hence this refactoring not only enables permission implementations to handle PermissionSetting changes that may not be part of the web-facing API, but also avoids them having to query the PermissionSetting after a change notification. Change-Id: I4e048730417d58e046da0ed2bb920268db155518 Bug: 408965890 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6899206 Reviewed-by: Nate Fischer Reviewed-by: Andrey Kosyakov Reviewed-by: Nico Weber Reviewed-by: Christian Dullweber Reviewed-by: Elias Klim Commit-Queue: Florian Jacky Reviewed-by: Shawn Quereshi Reviewed-by: Camille Lamy Reviewed-by: Zijie He Cr-Commit-Position: refs/heads/main@{#1513690} --- ..._localhost_permission_network_delegate_helper.cc | 12 +++++++----- .../public/browser/permission_controller_delegate.h | 6 +++--- .../google_sign_in_permission_util.cc | 13 ++++++++----- components/permissions/brave_permission_manager.cc | 9 +++++---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/browser/net/brave_localhost_permission_network_delegate_helper.cc b/browser/net/brave_localhost_permission_network_delegate_helper.cc index 779311aabb8..f4f7c19ee93 100644 --- a/browser/net/brave_localhost_permission_network_delegate_helper.cc +++ b/browser/net/brave_localhost_permission_network_delegate_helper.cc @@ -120,11 +120,13 @@ int OnBeforeURLRequest_LocalhostPermissionWork( auto* permission_controller = contents->GetBrowserContext()->GetPermissionController(); auto current_status = - permission_controller->GetPermissionStatusForCurrentDocument( - content::PermissionDescriptorUtil:: - CreatePermissionDescriptorForPermissionType( - blink::PermissionType::BRAVE_LOCALHOST_ACCESS), - /* rfh */ contents->GetPrimaryMainFrame()); + permission_controller + ->GetPermissionResultForCurrentDocument( + content::PermissionDescriptorUtil:: + CreatePermissionDescriptorForPermissionType( + blink::PermissionType::BRAVE_LOCALHOST_ACCESS), + /* rfh */ contents->GetPrimaryMainFrame()) + .status; switch (current_status) { case blink::mojom::PermissionStatus::GRANTED: { diff --git a/chromium_src/content/public/browser/permission_controller_delegate.h b/chromium_src/content/public/browser/permission_controller_delegate.h index 881ca9c2b0e..d45aad2261a 100644 --- a/chromium_src/content/public/browser/permission_controller_delegate.h +++ b/chromium_src/content/public/browser/permission_controller_delegate.h @@ -8,7 +8,7 @@ #include "content/public/browser/permission_controller.h" -#define UnsubscribeFromPermissionStatusChange \ +#define UnsubscribeFromPermissionResultChange \ PermissionControllerDelegateNotUsed() {} \ virtual void RequestPermissionsForOrigin( \ const std::vector& permissions, \ @@ -22,10 +22,10 @@ content::RenderFrameHost* render_frame_host, \ const GURL& requesting_origin); \ \ - virtual void UnsubscribeFromPermissionStatusChange + virtual void UnsubscribeFromPermissionResultChange #include // IWYU pragma: export -#undef UnsubscribeFromPermissionStatusChange +#undef UnsubscribeFromPermissionResultChange #endif // BRAVE_CHROMIUM_SRC_CONTENT_PUBLIC_BROWSER_PERMISSION_CONTROLLER_DELEGATE_H_ diff --git a/components/google_sign_in_permission/google_sign_in_permission_util.cc b/components/google_sign_in_permission/google_sign_in_permission_util.cc index c50f81f7e1e..6f88929d7ff 100644 --- a/components/google_sign_in_permission/google_sign_in_permission_util.cc +++ b/components/google_sign_in_permission/google_sign_in_permission_util.cc @@ -112,11 +112,14 @@ blink::mojom::PermissionStatus GetCurrentGoogleSignInPermissionStatus( content::PermissionControllerDelegate* permission_controller, content::WebContents* contents, const GURL& request_initiator_url) { - return permission_controller->GetPermissionStatusForCurrentDocument( - content::PermissionDescriptorUtil:: - CreatePermissionDescriptorForPermissionType( - blink::PermissionType::BRAVE_GOOGLE_SIGN_IN), - contents->GetPrimaryMainFrame(), /*should_include_device_status=*/false); + return permission_controller + ->GetPermissionResultForCurrentDocument( + content::PermissionDescriptorUtil:: + CreatePermissionDescriptorForPermissionType( + blink::PermissionType::BRAVE_GOOGLE_SIGN_IN), + contents->GetPrimaryMainFrame(), + /*should_include_device_status=*/false) + .status; } void CreateGoogleSignInPermissionRequest( diff --git a/components/permissions/brave_permission_manager.cc b/components/permissions/brave_permission_manager.cc index e4abe44fade..de2b91c082e 100644 --- a/components/permissions/brave_permission_manager.cc +++ b/components/permissions/brave_permission_manager.cc @@ -53,10 +53,11 @@ BravePermissionManager::GetPermissionStatusForOrigin( DCHECK_CURRENTLY_ON(content::BrowserThread::UI); base::AutoReset auto_reset_requesting_origin(&forced_requesting_origin_, requesting_origin); - return GetPermissionStatusForCurrentDocument( - content::PermissionDescriptorUtil:: - CreatePermissionDescriptorForPermissionType(permission), - render_frame_host, /*should_include_device_status=*/false); + return GetPermissionResultForCurrentDocument( + content::PermissionDescriptorUtil:: + CreatePermissionDescriptorForPermissionType(permission), + render_frame_host, /*should_include_device_status=*/false) + .status; } } // namespace permissions