[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 <fjacky@google.com>
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 <ntfschr@chromium.org>
    Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
    Reviewed-by: Nico Weber <thakis@chromium.org>
    Reviewed-by: Christian Dullweber <dullweber@chromium.org>
    Reviewed-by: Elias Klim <elklm@chromium.org>
    Commit-Queue: Florian Jacky <fjacky@chromium.org>
    Reviewed-by: Shawn Quereshi <shawnq@google.com>
    Reviewed-by: Camille Lamy <clamy@chromium.org>
    Reviewed-by: Zijie He <zijiehe@google.com>
    Cr-Commit-Position: refs/heads/main@{#1513690}
This commit is contained in:
Claudio DeSouza
2025-10-15 18:31:59 -04:00
committed by Emerick Rogul
parent 9bcbcd6ba4
commit 9e111593fc
4 changed files with 23 additions and 17 deletions
@@ -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: {
@@ -8,7 +8,7 @@
#include "content/public/browser/permission_controller.h"
#define UnsubscribeFromPermissionStatusChange \
#define UnsubscribeFromPermissionResultChange \
PermissionControllerDelegateNotUsed() {} \
virtual void RequestPermissionsForOrigin( \
const std::vector<blink::PermissionType>& permissions, \
@@ -22,10 +22,10 @@
content::RenderFrameHost* render_frame_host, \
const GURL& requesting_origin); \
\
virtual void UnsubscribeFromPermissionStatusChange
virtual void UnsubscribeFromPermissionResultChange
#include <content/public/browser/permission_controller_delegate.h> // IWYU pragma: export
#undef UnsubscribeFromPermissionStatusChange
#undef UnsubscribeFromPermissionResultChange
#endif // BRAVE_CHROMIUM_SRC_CONTENT_PUBLIC_BROWSER_PERMISSION_CONTROLLER_DELEGATE_H_
@@ -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(
@@ -53,10 +53,11 @@ BravePermissionManager::GetPermissionStatusForOrigin(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
base::AutoReset<GURL> 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