feat: route deprecated sync clipboard read through permission checks (#45377)

* feat: route deprecated clipboard commands through permission checks

* docs: address review feedback

* fix: enable checks for child windows
This commit is contained in:
Robo 2025-02-05 15:13:29 +09:00 committed by GitHub
parent e9d5eeb118
commit bec6ddda70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 441 additions and 35 deletions

View file

@ -31,6 +31,7 @@
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "shell/common/web_contents_utility.mojom.h"
#include "shell/renderer/api/context_bridge/object_cache.h"
#include "shell/renderer/api/electron_api_context_bridge.h"
#include "shell/renderer/api/electron_api_spell_check_client.h"

View file

@ -6,10 +6,12 @@
#include "content/public/renderer/render_frame.h"
#include "shell/common/options_switches.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/platform/url_conversion.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_view.h"
namespace electron {
@ -21,6 +23,15 @@ ContentSettingsObserver::ContentSettingsObserver(
ContentSettingsObserver::~ContentSettingsObserver() = default;
mojom::ElectronWebContentsUtility&
ContentSettingsObserver::GetWebContentsUtility() {
if (!web_contents_utility_) {
render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
&web_contents_utility_);
}
return *web_contents_utility_;
}
bool ContentSettingsObserver::AllowStorageAccessSync(StorageType storage_type) {
blink::WebFrame* frame = render_frame()->GetWebFrame();
if (frame->GetSecurityOrigin().IsOpaque() ||
@ -32,6 +43,20 @@ bool ContentSettingsObserver::AllowStorageAccessSync(StorageType storage_type) {
return true;
}
bool ContentSettingsObserver::AllowReadFromClipboardSync() {
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
if (frame->View()->GetWebPreferences().dom_paste_enabled) {
blink::mojom::PermissionStatus status{
blink::mojom::PermissionStatus::DENIED};
GetWebContentsUtility().CanAccessClipboardDeprecated(
mojom::PermissionName::DEPRECATED_SYNC_CLIPBOARD_READ,
frame->GetLocalFrameToken(), &status);
return status == blink::mojom::PermissionStatus::GRANTED;
} else {
return false;
}
}
void ContentSettingsObserver::OnDestruct() {
delete this;
}

View file

@ -6,7 +6,10 @@
#define ELECTRON_SHELL_RENDERER_CONTENT_SETTINGS_OBSERVER_H_
#include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "shell/common/web_contents_utility.mojom.h"
#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "url/origin.h"
namespace electron {
@ -22,10 +25,17 @@ class ContentSettingsObserver : public content::RenderFrameObserver,
// blink::WebContentSettingsClient implementation.
bool AllowStorageAccessSync(StorageType storage_type) override;
bool AllowReadFromClipboardSync() override;
private:
// content::RenderFrameObserver implementation.
void OnDestruct() override;
// A getter for `content_settings_manager_` that ensures it is bound.
mojom::ElectronWebContentsUtility& GetWebContentsUtility();
mojo::AssociatedRemote<mojom::ElectronWebContentsUtility>
web_contents_utility_;
};
} // namespace electron

View file

@ -10,9 +10,9 @@
#include "base/memory/weak_ptr.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "electron/shell/common/api/api.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "shell/common/api/api.mojom.h"
namespace electron {

View file

@ -9,13 +9,14 @@
#include "base/memory/ref_counted_memory.h"
#include "base/trace_event/trace_event.h"
#include "content/public/renderer/render_frame.h"
#include "electron/shell/common/api/api.mojom.h"
#include "ipc/ipc_message_macros.h"
#include "net/base/net_module.h"
#include "net/grit/net_resources.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "shell/common/api/api.mojom.h"
#include "shell/common/gin_helper/microtasks_scope.h"
#include "shell/common/options_switches.h"
#include "shell/common/web_contents_utility.mojom.h"
#include "shell/common/world_ids.h"
#include "shell/renderer/renderer_client_base.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"