mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: pass rfh instances through to the permission helper (#35986)
fix: pass rfh instances through to the permission helper (#35419) Co-authored-by: Samuel Attard <sam@electronjs.org>
This commit is contained in:
@@ -1328,7 +1328,7 @@ void WebContents::EnterFullscreenModeForTab(
|
||||
auto callback =
|
||||
base::BindRepeating(&WebContents::OnEnterFullscreenModeForTab,
|
||||
base::Unretained(this), requesting_frame, options);
|
||||
permission_helper->RequestFullscreenPermission(callback);
|
||||
permission_helper->RequestFullscreenPermission(requesting_frame, callback);
|
||||
}
|
||||
|
||||
void WebContents::OnEnterFullscreenModeForTab(
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "content/public/browser/tts_controller.h"
|
||||
#include "content/public/browser/tts_platform.h"
|
||||
#include "content/public/browser/url_loader_request_interceptor.h"
|
||||
#include "content/public/browser/weak_document_ptr.h"
|
||||
#include "content/public/common/content_descriptors.h"
|
||||
#include "content/public/common/content_paths.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
@@ -997,7 +998,7 @@ void ElectronBrowserClient::WebNotificationAllowed(
|
||||
return;
|
||||
}
|
||||
permission_helper->RequestWebNotificationPermission(
|
||||
base::BindOnce(std::move(callback), web_contents->IsAudioMuted()));
|
||||
rfh, base::BindOnce(std::move(callback), web_contents->IsAudioMuted()));
|
||||
}
|
||||
|
||||
void ElectronBrowserClient::RenderProcessHostDestroyed(
|
||||
@@ -1032,6 +1033,7 @@ void OnOpenExternal(const GURL& escaped_url, bool allowed) {
|
||||
|
||||
void HandleExternalProtocolInUI(
|
||||
const GURL& url,
|
||||
content::WeakDocumentPtr document_ptr,
|
||||
content::WebContents::OnceGetter web_contents_getter,
|
||||
bool has_user_gesture) {
|
||||
content::WebContents* web_contents = std::move(web_contents_getter).Run();
|
||||
@@ -1043,9 +1045,18 @@ void HandleExternalProtocolInUI(
|
||||
if (!permission_helper)
|
||||
return;
|
||||
|
||||
content::RenderFrameHost* rfh = document_ptr.AsRenderFrameHostIfValid();
|
||||
if (!rfh) {
|
||||
// If the render frame host is not valid it means it was a top level
|
||||
// navigation and the frame has already been disposed of. In this case we
|
||||
// take the current main frame and declare it responsible for the
|
||||
// transition.
|
||||
rfh = web_contents->GetMainFrame();
|
||||
}
|
||||
|
||||
GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
|
||||
auto callback = base::BindOnce(&OnOpenExternal, escaped_url);
|
||||
permission_helper->RequestOpenExternalPermission(std::move(callback),
|
||||
permission_helper->RequestOpenExternalPermission(rfh, std::move(callback),
|
||||
has_user_gesture, url);
|
||||
}
|
||||
|
||||
@@ -1065,6 +1076,9 @@ bool ElectronBrowserClient::HandleExternalProtocol(
|
||||
base::PostTask(
|
||||
FROM_HERE, {BrowserThread::UI},
|
||||
base::BindOnce(&HandleExternalProtocolInUI, url,
|
||||
initiator_document
|
||||
? initiator_document->GetWeakDocumentPtr()
|
||||
: content::WeakDocumentPtr(),
|
||||
std::move(web_contents_getter), has_user_gesture));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -61,16 +61,16 @@ WebContentsPermissionHelper::WebContentsPermissionHelper(
|
||||
WebContentsPermissionHelper::~WebContentsPermissionHelper() = default;
|
||||
|
||||
void WebContentsPermissionHelper::RequestPermission(
|
||||
content::RenderFrameHost* requesting_frame,
|
||||
content::PermissionType permission,
|
||||
base::OnceCallback<void(bool)> callback,
|
||||
bool user_gesture,
|
||||
const base::DictionaryValue* details) {
|
||||
auto* rfh = web_contents_->GetMainFrame();
|
||||
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
||||
web_contents_->GetBrowserContext()->GetPermissionControllerDelegate());
|
||||
auto origin = web_contents_->GetLastCommittedURL();
|
||||
permission_manager->RequestPermissionWithDetails(
|
||||
permission, rfh, origin, false, details,
|
||||
permission, requesting_frame, origin, false, details,
|
||||
base::BindOnce(&OnPermissionResponse, std::move(callback)));
|
||||
}
|
||||
|
||||
@@ -108,8 +108,10 @@ void WebContentsPermissionHelper::GrantDevicePermission(
|
||||
}
|
||||
|
||||
void WebContentsPermissionHelper::RequestFullscreenPermission(
|
||||
content::RenderFrameHost* requesting_frame,
|
||||
base::OnceCallback<void(bool)> callback) {
|
||||
RequestPermission(
|
||||
requesting_frame,
|
||||
static_cast<content::PermissionType>(PermissionType::FULLSCREEN),
|
||||
std::move(callback));
|
||||
}
|
||||
@@ -135,13 +137,16 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
|
||||
|
||||
// The permission type doesn't matter here, AUDIO_CAPTURE/VIDEO_CAPTURE
|
||||
// are presented as same type in content_converter.h.
|
||||
RequestPermission(content::PermissionType::AUDIO_CAPTURE, std::move(callback),
|
||||
RequestPermission(content::RenderFrameHost::FromID(request.render_process_id,
|
||||
request.render_frame_id),
|
||||
content::PermissionType::AUDIO_CAPTURE, std::move(callback),
|
||||
false, &details);
|
||||
}
|
||||
|
||||
void WebContentsPermissionHelper::RequestWebNotificationPermission(
|
||||
content::RenderFrameHost* requesting_frame,
|
||||
base::OnceCallback<void(bool)> callback) {
|
||||
RequestPermission(content::PermissionType::NOTIFICATIONS,
|
||||
RequestPermission(requesting_frame, content::PermissionType::NOTIFICATIONS,
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
@@ -151,6 +156,7 @@ void WebContentsPermissionHelper::RequestPointerLockPermission(
|
||||
base::OnceCallback<void(content::WebContents*, bool, bool, bool)>
|
||||
callback) {
|
||||
RequestPermission(
|
||||
web_contents_->GetMainFrame(),
|
||||
static_cast<content::PermissionType>(PermissionType::POINTER_LOCK),
|
||||
base::BindOnce(std::move(callback), web_contents_, user_gesture,
|
||||
last_unlocked_by_target),
|
||||
@@ -158,12 +164,14 @@ void WebContentsPermissionHelper::RequestPointerLockPermission(
|
||||
}
|
||||
|
||||
void WebContentsPermissionHelper::RequestOpenExternalPermission(
|
||||
content::RenderFrameHost* requesting_frame,
|
||||
base::OnceCallback<void(bool)> callback,
|
||||
bool user_gesture,
|
||||
const GURL& url) {
|
||||
base::DictionaryValue details;
|
||||
details.SetString("externalURL", url.spec());
|
||||
RequestPermission(
|
||||
requesting_frame,
|
||||
static_cast<content::PermissionType>(PermissionType::OPEN_EXTERNAL),
|
||||
std::move(callback), user_gesture, &details);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ class WebContentsPermissionHelper
|
||||
};
|
||||
|
||||
// Asynchronous Requests
|
||||
void RequestFullscreenPermission(base::OnceCallback<void(bool)> callback);
|
||||
void RequestFullscreenPermission(content::RenderFrameHost* requesting_frame,
|
||||
base::OnceCallback<void(bool)> callback);
|
||||
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
||||
content::MediaResponseCallback callback);
|
||||
void RequestPointerLockPermission(
|
||||
@@ -42,8 +43,10 @@ class WebContentsPermissionHelper
|
||||
base::OnceCallback<void(content::WebContents*, bool, bool, bool)>
|
||||
callback);
|
||||
void RequestWebNotificationPermission(
|
||||
content::RenderFrameHost* requesting_frame,
|
||||
base::OnceCallback<void(bool)> callback);
|
||||
void RequestOpenExternalPermission(base::OnceCallback<void(bool)> callback,
|
||||
void RequestOpenExternalPermission(content::RenderFrameHost* requesting_frame,
|
||||
base::OnceCallback<void(bool)> callback,
|
||||
bool user_gesture,
|
||||
const GURL& url);
|
||||
|
||||
@@ -73,7 +76,8 @@ class WebContentsPermissionHelper
|
||||
explicit WebContentsPermissionHelper(content::WebContents* web_contents);
|
||||
friend class content::WebContentsUserData<WebContentsPermissionHelper>;
|
||||
|
||||
void RequestPermission(content::PermissionType permission,
|
||||
void RequestPermission(content::RenderFrameHost* requesting_frame,
|
||||
content::PermissionType permission,
|
||||
base::OnceCallback<void(bool)> callback,
|
||||
bool user_gesture = false,
|
||||
const base::DictionaryValue* details = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user