chore: modernize ListValue usage in permission manager (#34662)
This commit is contained in:
parent
4ddd03b1b3
commit
0d4e417594
5 changed files with 54 additions and 59 deletions
|
@ -137,8 +137,7 @@ void ElectronPermissionManager::RequestPermission(
|
|||
bool user_gesture,
|
||||
StatusCallback response_callback) {
|
||||
RequestPermissionWithDetails(permission, render_frame_host, requesting_origin,
|
||||
user_gesture, nullptr,
|
||||
std::move(response_callback));
|
||||
user_gesture, {}, std::move(response_callback));
|
||||
}
|
||||
|
||||
void ElectronPermissionManager::RequestPermissionWithDetails(
|
||||
|
@ -146,11 +145,11 @@ void ElectronPermissionManager::RequestPermissionWithDetails(
|
|||
content::RenderFrameHost* render_frame_host,
|
||||
const GURL& requesting_origin,
|
||||
bool user_gesture,
|
||||
const base::DictionaryValue* details,
|
||||
base::Value::Dict details,
|
||||
StatusCallback response_callback) {
|
||||
RequestPermissionsWithDetails(
|
||||
std::vector<blink::PermissionType>(1, permission), render_frame_host,
|
||||
user_gesture, details,
|
||||
user_gesture, std::move(details),
|
||||
base::BindOnce(PermissionRequestResponseCallbackWrapper,
|
||||
std::move(response_callback)));
|
||||
}
|
||||
|
@ -162,14 +161,14 @@ void ElectronPermissionManager::RequestPermissions(
|
|||
bool user_gesture,
|
||||
StatusesCallback response_callback) {
|
||||
RequestPermissionsWithDetails(permissions, render_frame_host, user_gesture,
|
||||
nullptr, std::move(response_callback));
|
||||
{}, std::move(response_callback));
|
||||
}
|
||||
|
||||
void ElectronPermissionManager::RequestPermissionsWithDetails(
|
||||
const std::vector<blink::PermissionType>& permissions,
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
bool user_gesture,
|
||||
const base::DictionaryValue* details,
|
||||
base::Value::Dict details,
|
||||
StatusesCallback response_callback) {
|
||||
if (permissions.empty()) {
|
||||
std::move(response_callback).Run({});
|
||||
|
@ -204,13 +203,11 @@ void ElectronPermissionManager::RequestPermissionsWithDetails(
|
|||
const auto callback =
|
||||
base::BindRepeating(&ElectronPermissionManager::OnPermissionResponse,
|
||||
base::Unretained(this), request_id, i);
|
||||
auto mutable_details =
|
||||
details == nullptr ? base::DictionaryValue() : details->Clone();
|
||||
mutable_details.SetStringKey(
|
||||
"requestingUrl", render_frame_host->GetLastCommittedURL().spec());
|
||||
mutable_details.SetBoolKey("isMainFrame",
|
||||
render_frame_host->GetParent() == nullptr);
|
||||
request_handler_.Run(web_contents, permission, callback, mutable_details);
|
||||
details.Set("requestingUrl",
|
||||
render_frame_host->GetLastCommittedURL().spec());
|
||||
details.Set("isMainFrame", render_frame_host->GetParent() == nullptr);
|
||||
request_handler_.Run(web_contents, permission, callback,
|
||||
base::Value(std::move(details)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,17 +238,17 @@ void ElectronPermissionManager::RequestPermissionsFromCurrentDocument(
|
|||
base::OnceCallback<void(const std::vector<blink::mojom::PermissionStatus>&)>
|
||||
callback) {
|
||||
RequestPermissionsWithDetails(permissions, render_frame_host, user_gesture,
|
||||
nullptr, std::move(callback));
|
||||
{}, std::move(callback));
|
||||
}
|
||||
|
||||
blink::mojom::PermissionStatus ElectronPermissionManager::GetPermissionStatus(
|
||||
blink::PermissionType permission,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin) {
|
||||
base::DictionaryValue details;
|
||||
details.SetString("embeddingOrigin", embedding_origin.spec());
|
||||
bool granted = CheckPermissionWithDetails(permission, nullptr,
|
||||
requesting_origin, &details);
|
||||
base::Value::Dict details;
|
||||
details.Set("embeddingOrigin", embedding_origin.spec());
|
||||
bool granted = CheckPermissionWithDetails(permission, {}, requesting_origin,
|
||||
std::move(details));
|
||||
return granted ? blink::mojom::PermissionStatus::GRANTED
|
||||
: blink::mojom::PermissionStatus::DENIED;
|
||||
}
|
||||
|
@ -273,7 +270,7 @@ bool ElectronPermissionManager::CheckPermissionWithDetails(
|
|||
blink::PermissionType permission,
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
const GURL& requesting_origin,
|
||||
const base::DictionaryValue* details) const {
|
||||
base::Value::Dict details) const {
|
||||
if (check_handler_.is_null()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -281,27 +278,24 @@ bool ElectronPermissionManager::CheckPermissionWithDetails(
|
|||
render_frame_host
|
||||
? content::WebContents::FromRenderFrameHost(render_frame_host)
|
||||
: nullptr;
|
||||
auto mutable_details =
|
||||
details == nullptr ? base::DictionaryValue() : details->Clone();
|
||||
if (render_frame_host) {
|
||||
mutable_details.SetStringKey(
|
||||
"requestingUrl", render_frame_host->GetLastCommittedURL().spec());
|
||||
details.Set("requestingUrl",
|
||||
render_frame_host->GetLastCommittedURL().spec());
|
||||
}
|
||||
mutable_details.SetBoolKey(
|
||||
"isMainFrame",
|
||||
render_frame_host && render_frame_host->GetParent() == nullptr);
|
||||
details.Set("isMainFrame",
|
||||
render_frame_host && render_frame_host->GetParent() == nullptr);
|
||||
switch (permission) {
|
||||
case blink::PermissionType::AUDIO_CAPTURE:
|
||||
mutable_details.SetStringKey("mediaType", "audio");
|
||||
details.Set("mediaType", "audio");
|
||||
break;
|
||||
case blink::PermissionType::VIDEO_CAPTURE:
|
||||
mutable_details.SetStringKey("mediaType", "video");
|
||||
details.Set("mediaType", "video");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return check_handler_.Run(web_contents, permission, requesting_origin,
|
||||
mutable_details);
|
||||
base::Value(std::move(details)));
|
||||
}
|
||||
|
||||
bool ElectronPermissionManager::CheckDevicePermission(
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "shell/browser/electron_browser_context.h"
|
||||
|
||||
namespace base {
|
||||
class DictionaryValue;
|
||||
class Value;
|
||||
} // namespace base
|
||||
|
||||
|
@ -67,7 +66,7 @@ class ElectronPermissionManager : public content::PermissionControllerDelegate {
|
|||
content::RenderFrameHost* render_frame_host,
|
||||
const GURL& requesting_origin,
|
||||
bool user_gesture,
|
||||
const base::DictionaryValue* details,
|
||||
base::Value::Dict details,
|
||||
StatusCallback callback);
|
||||
void RequestPermissions(const std::vector<blink::PermissionType>& permissions,
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
|
@ -78,7 +77,7 @@ class ElectronPermissionManager : public content::PermissionControllerDelegate {
|
|||
const std::vector<blink::PermissionType>& permissions,
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
bool user_gesture,
|
||||
const base::DictionaryValue* details,
|
||||
base::Value::Dict details,
|
||||
StatusesCallback callback);
|
||||
|
||||
blink::mojom::PermissionStatus GetPermissionStatusForCurrentDocument(
|
||||
|
@ -88,7 +87,7 @@ class ElectronPermissionManager : public content::PermissionControllerDelegate {
|
|||
bool CheckPermissionWithDetails(blink::PermissionType permission,
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
const GURL& requesting_origin,
|
||||
const base::DictionaryValue* details) const;
|
||||
base::Value::Dict details) const;
|
||||
|
||||
bool CheckDevicePermission(blink::PermissionType permission,
|
||||
const url::Origin& origin,
|
||||
|
|
|
@ -61,14 +61,14 @@ std::unique_ptr<content::HidChooser> ElectronHidDelegate::RunChooser(
|
|||
bool ElectronHidDelegate::CanRequestDevicePermission(
|
||||
content::BrowserContext* browser_context,
|
||||
const url::Origin& origin) {
|
||||
base::DictionaryValue details;
|
||||
details.SetString("securityOrigin", origin.GetURL().spec());
|
||||
base::Value::Dict details;
|
||||
details.Set("securityOrigin", origin.GetURL().spec());
|
||||
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
||||
browser_context->GetPermissionControllerDelegate());
|
||||
return permission_manager->CheckPermissionWithDetails(
|
||||
static_cast<blink::PermissionType>(
|
||||
WebContentsPermissionHelper::PermissionType::HID),
|
||||
nullptr, origin.GetURL(), &details);
|
||||
nullptr, origin.GetURL(), std::move(details));
|
||||
}
|
||||
|
||||
bool ElectronHidDelegate::HasDevicePermission(
|
||||
|
|
|
@ -64,25 +64,25 @@ void WebContentsPermissionHelper::RequestPermission(
|
|||
blink::PermissionType permission,
|
||||
base::OnceCallback<void(bool)> callback,
|
||||
bool user_gesture,
|
||||
const base::DictionaryValue* details) {
|
||||
base::Value::Dict details) {
|
||||
auto* rfh = web_contents_->GetPrimaryMainFrame();
|
||||
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
||||
web_contents_->GetBrowserContext()->GetPermissionControllerDelegate());
|
||||
auto origin = web_contents_->GetLastCommittedURL();
|
||||
permission_manager->RequestPermissionWithDetails(
|
||||
permission, rfh, origin, false, details,
|
||||
permission, rfh, origin, false, std::move(details),
|
||||
base::BindOnce(&OnPermissionResponse, std::move(callback)));
|
||||
}
|
||||
|
||||
bool WebContentsPermissionHelper::CheckPermission(
|
||||
blink::PermissionType permission,
|
||||
const base::DictionaryValue* details) const {
|
||||
base::Value::Dict details) const {
|
||||
auto* rfh = web_contents_->GetPrimaryMainFrame();
|
||||
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
||||
web_contents_->GetBrowserContext()->GetPermissionControllerDelegate());
|
||||
auto origin = web_contents_->GetLastCommittedURL();
|
||||
return permission_manager->CheckPermissionWithDetails(permission, rfh, origin,
|
||||
details);
|
||||
std::move(details));
|
||||
}
|
||||
|
||||
void WebContentsPermissionHelper::RequestFullscreenPermission(
|
||||
|
@ -98,23 +98,23 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
|
|||
auto callback = base::BindOnce(&MediaAccessAllowed, request,
|
||||
std::move(response_callback));
|
||||
|
||||
base::DictionaryValue details;
|
||||
auto media_types = std::make_unique<base::ListValue>();
|
||||
base::Value::Dict details;
|
||||
base::Value::List media_types;
|
||||
if (request.audio_type ==
|
||||
blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE) {
|
||||
media_types->Append("audio");
|
||||
media_types.Append("audio");
|
||||
}
|
||||
if (request.video_type ==
|
||||
blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE) {
|
||||
media_types->Append("video");
|
||||
media_types.Append("video");
|
||||
}
|
||||
details.SetList("mediaTypes", std::move(media_types));
|
||||
details.SetString("securityOrigin", request.security_origin.spec());
|
||||
details.Set("mediaTypes", std::move(media_types));
|
||||
details.Set("securityOrigin", request.security_origin.spec());
|
||||
|
||||
// The permission type doesn't matter here, AUDIO_CAPTURE/VIDEO_CAPTURE
|
||||
// are presented as same type in content_converter.h.
|
||||
RequestPermission(blink::PermissionType::AUDIO_CAPTURE, std::move(callback),
|
||||
false, &details);
|
||||
false, std::move(details));
|
||||
}
|
||||
|
||||
void WebContentsPermissionHelper::RequestWebNotificationPermission(
|
||||
|
@ -138,30 +138,32 @@ void WebContentsPermissionHelper::RequestOpenExternalPermission(
|
|||
base::OnceCallback<void(bool)> callback,
|
||||
bool user_gesture,
|
||||
const GURL& url) {
|
||||
base::DictionaryValue details;
|
||||
details.SetString("externalURL", url.spec());
|
||||
base::Value::Dict details;
|
||||
details.Set("externalURL", url.spec());
|
||||
RequestPermission(
|
||||
static_cast<blink::PermissionType>(PermissionType::OPEN_EXTERNAL),
|
||||
std::move(callback), user_gesture, &details);
|
||||
std::move(callback), user_gesture, std::move(details));
|
||||
}
|
||||
|
||||
bool WebContentsPermissionHelper::CheckMediaAccessPermission(
|
||||
const GURL& security_origin,
|
||||
blink::mojom::MediaStreamType type) const {
|
||||
base::DictionaryValue details;
|
||||
details.SetString("securityOrigin", security_origin.spec());
|
||||
details.SetString("mediaType", MediaStreamTypeToString(type));
|
||||
base::Value::Dict details;
|
||||
details.Set("securityOrigin", security_origin.spec());
|
||||
details.Set("mediaType", MediaStreamTypeToString(type));
|
||||
// The permission type doesn't matter here, AUDIO_CAPTURE/VIDEO_CAPTURE
|
||||
// are presented as same type in content_converter.h.
|
||||
return CheckPermission(blink::PermissionType::AUDIO_CAPTURE, &details);
|
||||
return CheckPermission(blink::PermissionType::AUDIO_CAPTURE,
|
||||
std::move(details));
|
||||
}
|
||||
|
||||
bool WebContentsPermissionHelper::CheckSerialAccessPermission(
|
||||
const url::Origin& embedding_origin) const {
|
||||
base::DictionaryValue details;
|
||||
details.SetString("securityOrigin", embedding_origin.GetURL().spec());
|
||||
base::Value::Dict details;
|
||||
details.Set("securityOrigin", embedding_origin.GetURL().spec());
|
||||
return CheckPermission(
|
||||
static_cast<blink::PermissionType>(PermissionType::SERIAL), &details);
|
||||
static_cast<blink::PermissionType>(PermissionType::SERIAL),
|
||||
std::move(details));
|
||||
}
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPermissionHelper);
|
||||
|
|
|
@ -59,10 +59,10 @@ class WebContentsPermissionHelper
|
|||
void RequestPermission(blink::PermissionType permission,
|
||||
base::OnceCallback<void(bool)> callback,
|
||||
bool user_gesture = false,
|
||||
const base::DictionaryValue* details = nullptr);
|
||||
base::Value::Dict details = {});
|
||||
|
||||
bool CheckPermission(blink::PermissionType permission,
|
||||
const base::DictionaryValue* details) const;
|
||||
base::Value::Dict details) const;
|
||||
|
||||
// TODO(clavin): refactor to use the WebContents provided by the
|
||||
// WebContentsUserData base class instead of storing a duplicate ref
|
||||
|
|
Loading…
Add table
Reference in a new issue