chore: clean up ElectronPermissionManager
(#38636)
chore: clean up ElectronPermissionManager
This commit is contained in:
parent
bbfba4fc24
commit
933544d449
1 changed files with 58 additions and 41 deletions
|
@ -146,9 +146,14 @@ void ElectronPermissionManager::RequestPermission(
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
const GURL& requesting_origin,
|
const GURL& requesting_origin,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
StatusCallback response_callback) {
|
StatusCallback callback) {
|
||||||
|
if (render_frame_host->IsNestedWithinFencedFrame()) {
|
||||||
|
std::move(callback).Run(blink::mojom::PermissionStatus::DENIED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RequestPermissionWithDetails(permission, render_frame_host, requesting_origin,
|
RequestPermissionWithDetails(permission, render_frame_host, requesting_origin,
|
||||||
user_gesture, {}, std::move(response_callback));
|
user_gesture, {}, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronPermissionManager::RequestPermissionWithDetails(
|
void ElectronPermissionManager::RequestPermissionWithDetails(
|
||||||
|
@ -170,9 +175,15 @@ void ElectronPermissionManager::RequestPermissions(
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
const GURL& requesting_origin,
|
const GURL& requesting_origin,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
StatusesCallback response_callback) {
|
StatusesCallback callback) {
|
||||||
|
if (render_frame_host->IsNestedWithinFencedFrame()) {
|
||||||
|
std::move(callback).Run(std::vector<blink::mojom::PermissionStatus>(
|
||||||
|
permissions.size(), blink::mojom::PermissionStatus::DENIED));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RequestPermissionsWithDetails(permissions, render_frame_host, user_gesture,
|
RequestPermissionsWithDetails(permissions, render_frame_host, user_gesture,
|
||||||
{}, std::move(response_callback));
|
{}, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronPermissionManager::RequestPermissionsWithDetails(
|
void ElectronPermissionManager::RequestPermissionsWithDetails(
|
||||||
|
@ -248,6 +259,12 @@ void ElectronPermissionManager::RequestPermissionsFromCurrentDocument(
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
base::OnceCallback<void(const std::vector<blink::mojom::PermissionStatus>&)>
|
base::OnceCallback<void(const std::vector<blink::mojom::PermissionStatus>&)>
|
||||||
callback) {
|
callback) {
|
||||||
|
if (render_frame_host->IsNestedWithinFencedFrame()) {
|
||||||
|
std::move(callback).Run(std::vector<blink::mojom::PermissionStatus>(
|
||||||
|
permissions.size(), blink::mojom::PermissionStatus::DENIED));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RequestPermissionsWithDetails(permissions, render_frame_host, user_gesture,
|
RequestPermissionsWithDetails(permissions, render_frame_host, user_gesture,
|
||||||
{}, std::move(callback));
|
{}, std::move(callback));
|
||||||
}
|
}
|
||||||
|
@ -274,19 +291,6 @@ ElectronPermissionManager::GetPermissionResultForOriginWithoutContext(
|
||||||
status, content::PermissionStatusSource::UNSPECIFIED);
|
status, content::PermissionStatusSource::UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
ElectronPermissionManager::SubscriptionId
|
|
||||||
ElectronPermissionManager::SubscribePermissionStatusChange(
|
|
||||||
blink::PermissionType permission,
|
|
||||||
content::RenderProcessHost* render_process_host,
|
|
||||||
content::RenderFrameHost* render_frame_host,
|
|
||||||
const GURL& requesting_origin,
|
|
||||||
base::RepeatingCallback<void(blink::mojom::PermissionStatus)> callback) {
|
|
||||||
return SubscriptionId(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronPermissionManager::UnsubscribePermissionStatusChange(
|
|
||||||
SubscriptionId id) {}
|
|
||||||
|
|
||||||
void ElectronPermissionManager::CheckBluetoothDevicePair(
|
void ElectronPermissionManager::CheckBluetoothDevicePair(
|
||||||
gin_helper::Dictionary details,
|
gin_helper::Dictionary details,
|
||||||
PairCallback pair_callback) const {
|
PairCallback pair_callback) const {
|
||||||
|
@ -304,9 +308,9 @@ bool ElectronPermissionManager::CheckPermissionWithDetails(
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
const GURL& requesting_origin,
|
const GURL& requesting_origin,
|
||||||
base::Value::Dict details) const {
|
base::Value::Dict details) const {
|
||||||
if (check_handler_.is_null()) {
|
if (check_handler_.is_null())
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
auto* web_contents =
|
auto* web_contents =
|
||||||
render_frame_host
|
render_frame_host
|
||||||
? content::WebContents::FromRenderFrameHost(render_frame_host)
|
? content::WebContents::FromRenderFrameHost(render_frame_host)
|
||||||
|
@ -336,18 +340,17 @@ bool ElectronPermissionManager::CheckDevicePermission(
|
||||||
const url::Origin& origin,
|
const url::Origin& origin,
|
||||||
const base::Value& device,
|
const base::Value& device,
|
||||||
ElectronBrowserContext* browser_context) const {
|
ElectronBrowserContext* browser_context) const {
|
||||||
if (device_permission_handler_.is_null()) {
|
if (device_permission_handler_.is_null())
|
||||||
return browser_context->CheckDevicePermission(origin, device, permission);
|
return browser_context->CheckDevicePermission(origin, device, permission);
|
||||||
} else {
|
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
v8::Local<v8::Object> details = gin::DataObjectBuilder(isolate)
|
v8::Local<v8::Object> details = gin::DataObjectBuilder(isolate)
|
||||||
.Set("deviceType", permission)
|
.Set("deviceType", permission)
|
||||||
.Set("origin", origin.Serialize())
|
.Set("origin", origin.Serialize())
|
||||||
.Set("device", device.Clone())
|
.Set("device", device.Clone())
|
||||||
.Build();
|
.Build();
|
||||||
return device_permission_handler_.Run(details);
|
return device_permission_handler_.Run(details);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronPermissionManager::GrantDevicePermission(
|
void ElectronPermissionManager::GrantDevicePermission(
|
||||||
|
@ -371,22 +374,23 @@ void ElectronPermissionManager::RevokeDevicePermission(
|
||||||
ElectronPermissionManager::USBProtectedClasses
|
ElectronPermissionManager::USBProtectedClasses
|
||||||
ElectronPermissionManager::CheckProtectedUSBClasses(
|
ElectronPermissionManager::CheckProtectedUSBClasses(
|
||||||
const USBProtectedClasses& classes) const {
|
const USBProtectedClasses& classes) const {
|
||||||
if (protected_usb_handler_.is_null()) {
|
if (protected_usb_handler_.is_null())
|
||||||
return classes;
|
return classes;
|
||||||
} else {
|
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
v8::Local<v8::Object> details = gin::DataObjectBuilder(isolate)
|
v8::Local<v8::Object> details =
|
||||||
.Set("protectedClasses", classes)
|
gin::DataObjectBuilder(isolate).Set("protectedClasses", classes).Build();
|
||||||
.Build();
|
return protected_usb_handler_.Run(details);
|
||||||
return protected_usb_handler_.Run(details);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blink::mojom::PermissionStatus
|
blink::mojom::PermissionStatus
|
||||||
ElectronPermissionManager::GetPermissionStatusForCurrentDocument(
|
ElectronPermissionManager::GetPermissionStatusForCurrentDocument(
|
||||||
blink::PermissionType permission,
|
blink::PermissionType permission,
|
||||||
content::RenderFrameHost* render_frame_host) {
|
content::RenderFrameHost* render_frame_host) {
|
||||||
|
if (render_frame_host->IsNestedWithinFencedFrame())
|
||||||
|
return blink::mojom::PermissionStatus::DENIED;
|
||||||
|
|
||||||
base::Value::Dict details;
|
base::Value::Dict details;
|
||||||
details.Set("embeddingOrigin",
|
details.Set("embeddingOrigin",
|
||||||
content::PermissionUtil::GetLastCommittedOriginAsURL(
|
content::PermissionUtil::GetLastCommittedOriginAsURL(
|
||||||
|
@ -412,12 +416,25 @@ ElectronPermissionManager::GetPermissionStatusForEmbeddedRequester(
|
||||||
blink::PermissionType permission,
|
blink::PermissionType permission,
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
const url::Origin& overridden_origin) {
|
const url::Origin& overridden_origin) {
|
||||||
if (render_frame_host->IsNestedWithinFencedFrame()) {
|
if (render_frame_host->IsNestedWithinFencedFrame())
|
||||||
return blink::mojom::PermissionStatus::DENIED;
|
return blink::mojom::PermissionStatus::DENIED;
|
||||||
}
|
|
||||||
return GetPermissionStatus(
|
return GetPermissionStatus(
|
||||||
permission, overridden_origin.GetURL(),
|
permission, overridden_origin.GetURL(),
|
||||||
render_frame_host->GetLastCommittedOrigin().GetURL());
|
render_frame_host->GetLastCommittedOrigin().GetURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElectronPermissionManager::SubscriptionId
|
||||||
|
ElectronPermissionManager::SubscribePermissionStatusChange(
|
||||||
|
blink::PermissionType permission,
|
||||||
|
content::RenderProcessHost* render_process_host,
|
||||||
|
content::RenderFrameHost* render_frame_host,
|
||||||
|
const GURL& requesting_origin,
|
||||||
|
base::RepeatingCallback<void(blink::mojom::PermissionStatus)> callback) {
|
||||||
|
return SubscriptionId();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronPermissionManager::UnsubscribePermissionStatusChange(
|
||||||
|
SubscriptionId id) {}
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
Loading…
Reference in a new issue