fix: ensure ElectronBrowser mojo service is only bound to appropriate render frames (#33323)
* fix: ensure ElectronBrowser mojo service is only bound to authorized render frames Notes: no-notes * refactor: extract electron API IPC to its own mojo interface * fix: just check main frame not primary main frame
This commit is contained in:
parent
f2b06324b8
commit
e07c2b84d7
17 changed files with 381 additions and 229 deletions
|
@ -350,6 +350,8 @@ filenames = {
|
||||||
"shell/browser/child_web_contents_tracker.h",
|
"shell/browser/child_web_contents_tracker.h",
|
||||||
"shell/browser/cookie_change_notifier.cc",
|
"shell/browser/cookie_change_notifier.cc",
|
||||||
"shell/browser/cookie_change_notifier.h",
|
"shell/browser/cookie_change_notifier.h",
|
||||||
|
"shell/browser/electron_api_ipc_handler_impl.cc",
|
||||||
|
"shell/browser/electron_api_ipc_handler_impl.h",
|
||||||
"shell/browser/electron_autofill_driver.cc",
|
"shell/browser/electron_autofill_driver.cc",
|
||||||
"shell/browser/electron_autofill_driver.h",
|
"shell/browser/electron_autofill_driver.h",
|
||||||
"shell/browser/electron_autofill_driver_factory.cc",
|
"shell/browser/electron_autofill_driver_factory.cc",
|
||||||
|
@ -358,8 +360,6 @@ filenames = {
|
||||||
"shell/browser/electron_browser_client.h",
|
"shell/browser/electron_browser_client.h",
|
||||||
"shell/browser/electron_browser_context.cc",
|
"shell/browser/electron_browser_context.cc",
|
||||||
"shell/browser/electron_browser_context.h",
|
"shell/browser/electron_browser_context.h",
|
||||||
"shell/browser/electron_browser_handler_impl.cc",
|
|
||||||
"shell/browser/electron_browser_handler_impl.h",
|
|
||||||
"shell/browser/electron_browser_main_parts.cc",
|
"shell/browser/electron_browser_main_parts.cc",
|
||||||
"shell/browser/electron_browser_main_parts.h",
|
"shell/browser/electron_browser_main_parts.h",
|
||||||
"shell/browser/electron_download_manager_delegate.cc",
|
"shell/browser/electron_download_manager_delegate.cc",
|
||||||
|
@ -376,6 +376,8 @@ filenames = {
|
||||||
"shell/browser/electron_quota_permission_context.h",
|
"shell/browser/electron_quota_permission_context.h",
|
||||||
"shell/browser/electron_speech_recognition_manager_delegate.cc",
|
"shell/browser/electron_speech_recognition_manager_delegate.cc",
|
||||||
"shell/browser/electron_speech_recognition_manager_delegate.h",
|
"shell/browser/electron_speech_recognition_manager_delegate.h",
|
||||||
|
"shell/browser/electron_web_contents_utility_handler_impl.cc",
|
||||||
|
"shell/browser/electron_web_contents_utility_handler_impl.h",
|
||||||
"shell/browser/electron_web_ui_controller_factory.cc",
|
"shell/browser/electron_web_ui_controller_factory.cc",
|
||||||
"shell/browser/electron_web_ui_controller_factory.h",
|
"shell/browser/electron_web_ui_controller_factory.h",
|
||||||
"shell/browser/event_emitter_mixin.cc",
|
"shell/browser/event_emitter_mixin.cc",
|
||||||
|
|
|
@ -1751,7 +1751,7 @@ void WebContents::Message(bool internal,
|
||||||
// webContents.emit('-ipc-message', new Event(), internal, channel,
|
// webContents.emit('-ipc-message', new Event(), internal, channel,
|
||||||
// arguments);
|
// arguments);
|
||||||
EmitWithSender("-ipc-message", render_frame_host,
|
EmitWithSender("-ipc-message", render_frame_host,
|
||||||
electron::mojom::ElectronBrowser::InvokeCallback(), internal,
|
electron::mojom::ElectronApiIPC::InvokeCallback(), internal,
|
||||||
channel, std::move(arguments));
|
channel, std::move(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1759,7 +1759,7 @@ void WebContents::Invoke(
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
blink::CloneableMessage arguments,
|
blink::CloneableMessage arguments,
|
||||||
electron::mojom::ElectronBrowser::InvokeCallback callback,
|
electron::mojom::ElectronApiIPC::InvokeCallback callback,
|
||||||
content::RenderFrameHost* render_frame_host) {
|
content::RenderFrameHost* render_frame_host) {
|
||||||
TRACE_EVENT1("electron", "WebContents::Invoke", "channel", channel);
|
TRACE_EVENT1("electron", "WebContents::Invoke", "channel", channel);
|
||||||
// webContents.emit('-ipc-invoke', new Event(), internal, channel, arguments);
|
// webContents.emit('-ipc-invoke', new Event(), internal, channel, arguments);
|
||||||
|
@ -1785,7 +1785,7 @@ void WebContents::ReceivePostMessage(
|
||||||
v8::Local<v8::Value> message_value =
|
v8::Local<v8::Value> message_value =
|
||||||
electron::DeserializeV8Value(isolate, message);
|
electron::DeserializeV8Value(isolate, message);
|
||||||
EmitWithSender("-ipc-ports", render_frame_host,
|
EmitWithSender("-ipc-ports", render_frame_host,
|
||||||
electron::mojom::ElectronBrowser::InvokeCallback(), false,
|
electron::mojom::ElectronApiIPC::InvokeCallback(), false,
|
||||||
channel, message_value, std::move(wrapped_ports));
|
channel, message_value, std::move(wrapped_ports));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1793,7 +1793,7 @@ void WebContents::MessageSync(
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
blink::CloneableMessage arguments,
|
blink::CloneableMessage arguments,
|
||||||
electron::mojom::ElectronBrowser::MessageSyncCallback callback,
|
electron::mojom::ElectronApiIPC::MessageSyncCallback callback,
|
||||||
content::RenderFrameHost* render_frame_host) {
|
content::RenderFrameHost* render_frame_host) {
|
||||||
TRACE_EVENT1("electron", "WebContents::MessageSync", "channel", channel);
|
TRACE_EVENT1("electron", "WebContents::MessageSync", "channel", channel);
|
||||||
// webContents.emit('-ipc-message-sync', new Event(sender, message), internal,
|
// webContents.emit('-ipc-message-sync', new Event(sender, message), internal,
|
||||||
|
@ -1831,7 +1831,7 @@ void WebContents::MessageHost(const std::string& channel,
|
||||||
TRACE_EVENT1("electron", "WebContents::MessageHost", "channel", channel);
|
TRACE_EVENT1("electron", "WebContents::MessageHost", "channel", channel);
|
||||||
// webContents.emit('ipc-message-host', new Event(), channel, args);
|
// webContents.emit('ipc-message-host', new Event(), channel, args);
|
||||||
EmitWithSender("ipc-message-host", render_frame_host,
|
EmitWithSender("ipc-message-host", render_frame_host,
|
||||||
electron::mojom::ElectronBrowser::InvokeCallback(), channel,
|
electron::mojom::ElectronApiIPC::InvokeCallback(), channel,
|
||||||
std::move(arguments));
|
std::move(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3270,7 +3270,8 @@ void WebContents::SetTemporaryZoomLevel(double level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::DoGetZoomLevel(
|
void WebContents::DoGetZoomLevel(
|
||||||
electron::mojom::ElectronBrowser::DoGetZoomLevelCallback callback) {
|
electron::mojom::ElectronWebContentsUtility::DoGetZoomLevelCallback
|
||||||
|
callback) {
|
||||||
std::move(callback).Run(GetZoomLevel());
|
std::move(callback).Run(GetZoomLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
bool EmitWithSender(base::StringPiece name,
|
bool EmitWithSender(base::StringPiece name,
|
||||||
content::RenderFrameHost* sender,
|
content::RenderFrameHost* sender,
|
||||||
electron::mojom::ElectronBrowser::InvokeCallback callback,
|
electron::mojom::ElectronApiIPC::InvokeCallback callback,
|
||||||
Args&&... args) {
|
Args&&... args) {
|
||||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
@ -399,7 +399,7 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
fullscreen_frame_ = rfh;
|
fullscreen_frame_ = rfh;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mojom::ElectronBrowser
|
// mojom::ElectronApiIPC
|
||||||
void Message(bool internal,
|
void Message(bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
blink::CloneableMessage arguments,
|
blink::CloneableMessage arguments,
|
||||||
|
@ -407,9 +407,8 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
void Invoke(bool internal,
|
void Invoke(bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
blink::CloneableMessage arguments,
|
blink::CloneableMessage arguments,
|
||||||
electron::mojom::ElectronBrowser::InvokeCallback callback,
|
electron::mojom::ElectronApiIPC::InvokeCallback callback,
|
||||||
content::RenderFrameHost* render_frame_host);
|
content::RenderFrameHost* render_frame_host);
|
||||||
void OnFirstNonEmptyLayout(content::RenderFrameHost* render_frame_host);
|
|
||||||
void ReceivePostMessage(const std::string& channel,
|
void ReceivePostMessage(const std::string& channel,
|
||||||
blink::TransferableMessage message,
|
blink::TransferableMessage message,
|
||||||
content::RenderFrameHost* render_frame_host);
|
content::RenderFrameHost* render_frame_host);
|
||||||
|
@ -417,7 +416,7 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
blink::CloneableMessage arguments,
|
blink::CloneableMessage arguments,
|
||||||
electron::mojom::ElectronBrowser::MessageSyncCallback callback,
|
electron::mojom::ElectronApiIPC::MessageSyncCallback callback,
|
||||||
content::RenderFrameHost* render_frame_host);
|
content::RenderFrameHost* render_frame_host);
|
||||||
void MessageTo(int32_t web_contents_id,
|
void MessageTo(int32_t web_contents_id,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
|
@ -425,10 +424,15 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
void MessageHost(const std::string& channel,
|
void MessageHost(const std::string& channel,
|
||||||
blink::CloneableMessage arguments,
|
blink::CloneableMessage arguments,
|
||||||
content::RenderFrameHost* render_frame_host);
|
content::RenderFrameHost* render_frame_host);
|
||||||
|
|
||||||
|
// mojom::ElectronWebContentsUtility
|
||||||
|
void OnFirstNonEmptyLayout(content::RenderFrameHost* render_frame_host);
|
||||||
void UpdateDraggableRegions(std::vector<mojom::DraggableRegionPtr> regions);
|
void UpdateDraggableRegions(std::vector<mojom::DraggableRegionPtr> regions);
|
||||||
void SetTemporaryZoomLevel(double level);
|
void SetTemporaryZoomLevel(double level);
|
||||||
void DoGetZoomLevel(
|
void DoGetZoomLevel(
|
||||||
electron::mojom::ElectronBrowser::DoGetZoomLevelCallback callback);
|
electron::mojom::ElectronWebContentsUtility::DoGetZoomLevelCallback
|
||||||
|
callback);
|
||||||
|
|
||||||
void SetImageAnimationPolicy(const std::string& new_policy);
|
void SetImageAnimationPolicy(const std::string& new_policy);
|
||||||
|
|
||||||
// Grants |origin| access to |device|.
|
// Grants |origin| access to |device|.
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace gin_helper {
|
||||||
|
|
||||||
class Event : public gin::Wrappable<Event> {
|
class Event : public gin::Wrappable<Event> {
|
||||||
public:
|
public:
|
||||||
using InvokeCallback = electron::mojom::ElectronBrowser::InvokeCallback;
|
using InvokeCallback = electron::mojom::ElectronApiIPC::InvokeCallback;
|
||||||
|
|
||||||
static gin::WrapperInfo kWrapperInfo;
|
static gin::WrapperInfo kWrapperInfo;
|
||||||
|
|
||||||
|
|
108
shell/browser/electron_api_ipc_handler_impl.cc
Normal file
108
shell/browser/electron_api_ipc_handler_impl.cc
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
// Copyright (c) 2022 Slack Technologies, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "shell/browser/electron_api_ipc_handler_impl.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "content/public/browser/render_frame_host.h"
|
||||||
|
#include "content/public/browser/render_process_host.h"
|
||||||
|
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
||||||
|
|
||||||
|
namespace electron {
|
||||||
|
ElectronApiIPCHandlerImpl::ElectronApiIPCHandlerImpl(
|
||||||
|
content::RenderFrameHost* frame_host,
|
||||||
|
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver)
|
||||||
|
: render_process_id_(frame_host->GetProcess()->GetID()),
|
||||||
|
render_frame_id_(frame_host->GetRoutingID()) {
|
||||||
|
content::WebContents* web_contents =
|
||||||
|
content::WebContents::FromRenderFrameHost(frame_host);
|
||||||
|
DCHECK(web_contents);
|
||||||
|
content::WebContentsObserver::Observe(web_contents);
|
||||||
|
|
||||||
|
receiver_.Bind(std::move(receiver));
|
||||||
|
receiver_.set_disconnect_handler(base::BindOnce(
|
||||||
|
&ElectronApiIPCHandlerImpl::OnConnectionError, GetWeakPtr()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ElectronApiIPCHandlerImpl::~ElectronApiIPCHandlerImpl() = default;
|
||||||
|
|
||||||
|
void ElectronApiIPCHandlerImpl::WebContentsDestroyed() {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronApiIPCHandlerImpl::OnConnectionError() {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronApiIPCHandlerImpl::Message(bool internal,
|
||||||
|
const std::string& channel,
|
||||||
|
blink::CloneableMessage arguments) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->Message(internal, channel, std::move(arguments),
|
||||||
|
GetRenderFrameHost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ElectronApiIPCHandlerImpl::Invoke(bool internal,
|
||||||
|
const std::string& channel,
|
||||||
|
blink::CloneableMessage arguments,
|
||||||
|
InvokeCallback callback) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->Invoke(internal, channel, std::move(arguments),
|
||||||
|
std::move(callback), GetRenderFrameHost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronApiIPCHandlerImpl::ReceivePostMessage(
|
||||||
|
const std::string& channel,
|
||||||
|
blink::TransferableMessage message) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->ReceivePostMessage(channel, std::move(message),
|
||||||
|
GetRenderFrameHost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronApiIPCHandlerImpl::MessageSync(bool internal,
|
||||||
|
const std::string& channel,
|
||||||
|
blink::CloneableMessage arguments,
|
||||||
|
MessageSyncCallback callback) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->MessageSync(internal, channel, std::move(arguments),
|
||||||
|
std::move(callback), GetRenderFrameHost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronApiIPCHandlerImpl::MessageTo(int32_t web_contents_id,
|
||||||
|
const std::string& channel,
|
||||||
|
blink::CloneableMessage arguments) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->MessageTo(web_contents_id, channel, std::move(arguments));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronApiIPCHandlerImpl::MessageHost(const std::string& channel,
|
||||||
|
blink::CloneableMessage arguments) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->MessageHost(channel, std::move(arguments),
|
||||||
|
GetRenderFrameHost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content::RenderFrameHost* ElectronApiIPCHandlerImpl::GetRenderFrameHost() {
|
||||||
|
return content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void ElectronApiIPCHandlerImpl::Create(
|
||||||
|
content::RenderFrameHost* frame_host,
|
||||||
|
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver) {
|
||||||
|
new ElectronApiIPCHandlerImpl(frame_host, std::move(receiver));
|
||||||
|
}
|
||||||
|
} // namespace electron
|
|
@ -1,9 +1,9 @@
|
||||||
// Copyright (c) 2019 Slack Technologies, Inc.
|
// Copyright (c) 2022 Slack Technologies, Inc.
|
||||||
// Use of this source code is governed by the MIT license that can be
|
// Use of this source code is governed by the MIT license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef ELECTRON_SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_
|
#ifndef ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_
|
||||||
#define ELECTRON_SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_
|
#define ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -18,23 +18,23 @@ class RenderFrameHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
|
class ElectronApiIPCHandlerImpl : public mojom::ElectronApiIPC,
|
||||||
public content::WebContentsObserver {
|
public content::WebContentsObserver {
|
||||||
public:
|
public:
|
||||||
explicit ElectronBrowserHandlerImpl(
|
explicit ElectronApiIPCHandlerImpl(
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver);
|
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver);
|
||||||
|
|
||||||
static void Create(
|
static void Create(
|
||||||
content::RenderFrameHost* frame_host,
|
content::RenderFrameHost* frame_host,
|
||||||
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver);
|
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver);
|
||||||
|
|
||||||
// disable copy
|
// disable copy
|
||||||
ElectronBrowserHandlerImpl(const ElectronBrowserHandlerImpl&) = delete;
|
ElectronApiIPCHandlerImpl(const ElectronApiIPCHandlerImpl&) = delete;
|
||||||
ElectronBrowserHandlerImpl& operator=(const ElectronBrowserHandlerImpl&) =
|
ElectronApiIPCHandlerImpl& operator=(const ElectronApiIPCHandlerImpl&) =
|
||||||
delete;
|
delete;
|
||||||
|
|
||||||
// mojom::ElectronBrowser:
|
// mojom::ElectronApiIPC:
|
||||||
void Message(bool internal,
|
void Message(bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
blink::CloneableMessage arguments) override;
|
blink::CloneableMessage arguments) override;
|
||||||
|
@ -42,7 +42,6 @@ class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
blink::CloneableMessage arguments,
|
blink::CloneableMessage arguments,
|
||||||
InvokeCallback callback) override;
|
InvokeCallback callback) override;
|
||||||
void OnFirstNonEmptyLayout() override;
|
|
||||||
void ReceivePostMessage(const std::string& channel,
|
void ReceivePostMessage(const std::string& channel,
|
||||||
blink::TransferableMessage message) override;
|
blink::TransferableMessage message) override;
|
||||||
void MessageSync(bool internal,
|
void MessageSync(bool internal,
|
||||||
|
@ -54,17 +53,13 @@ class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
|
||||||
blink::CloneableMessage arguments) override;
|
blink::CloneableMessage arguments) override;
|
||||||
void MessageHost(const std::string& channel,
|
void MessageHost(const std::string& channel,
|
||||||
blink::CloneableMessage arguments) override;
|
blink::CloneableMessage arguments) override;
|
||||||
void UpdateDraggableRegions(
|
|
||||||
std::vector<mojom::DraggableRegionPtr> regions) override;
|
|
||||||
void SetTemporaryZoomLevel(double level) override;
|
|
||||||
void DoGetZoomLevel(DoGetZoomLevelCallback callback) override;
|
|
||||||
|
|
||||||
base::WeakPtr<ElectronBrowserHandlerImpl> GetWeakPtr() {
|
base::WeakPtr<ElectronApiIPCHandlerImpl> GetWeakPtr() {
|
||||||
return weak_factory_.GetWeakPtr();
|
return weak_factory_.GetWeakPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~ElectronBrowserHandlerImpl() override;
|
~ElectronApiIPCHandlerImpl() override;
|
||||||
|
|
||||||
// content::WebContentsObserver:
|
// content::WebContentsObserver:
|
||||||
void WebContentsDestroyed() override;
|
void WebContentsDestroyed() override;
|
||||||
|
@ -76,9 +71,9 @@ class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
|
||||||
const int render_process_id_;
|
const int render_process_id_;
|
||||||
const int render_frame_id_;
|
const int render_frame_id_;
|
||||||
|
|
||||||
mojo::AssociatedReceiver<mojom::ElectronBrowser> receiver_{this};
|
mojo::AssociatedReceiver<mojom::ElectronApiIPC> receiver_{this};
|
||||||
|
|
||||||
base::WeakPtrFactory<ElectronBrowserHandlerImpl> weak_factory_{this};
|
base::WeakPtrFactory<ElectronApiIPCHandlerImpl> weak_factory_{this};
|
||||||
};
|
};
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_
|
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_
|
|
@ -77,13 +77,14 @@
|
||||||
#include "shell/browser/api/electron_api_web_request.h"
|
#include "shell/browser/api/electron_api_web_request.h"
|
||||||
#include "shell/browser/badging/badge_manager.h"
|
#include "shell/browser/badging/badge_manager.h"
|
||||||
#include "shell/browser/child_web_contents_tracker.h"
|
#include "shell/browser/child_web_contents_tracker.h"
|
||||||
|
#include "shell/browser/electron_api_ipc_handler_impl.h"
|
||||||
#include "shell/browser/electron_autofill_driver_factory.h"
|
#include "shell/browser/electron_autofill_driver_factory.h"
|
||||||
#include "shell/browser/electron_browser_context.h"
|
#include "shell/browser/electron_browser_context.h"
|
||||||
#include "shell/browser/electron_browser_handler_impl.h"
|
|
||||||
#include "shell/browser/electron_browser_main_parts.h"
|
#include "shell/browser/electron_browser_main_parts.h"
|
||||||
#include "shell/browser/electron_navigation_throttle.h"
|
#include "shell/browser/electron_navigation_throttle.h"
|
||||||
#include "shell/browser/electron_quota_permission_context.h"
|
#include "shell/browser/electron_quota_permission_context.h"
|
||||||
#include "shell/browser/electron_speech_recognition_manager_delegate.h"
|
#include "shell/browser/electron_speech_recognition_manager_delegate.h"
|
||||||
|
#include "shell/browser/electron_web_contents_utility_handler_impl.h"
|
||||||
#include "shell/browser/font_defaults.h"
|
#include "shell/browser/font_defaults.h"
|
||||||
#include "shell/browser/javascript_environment.h"
|
#include "shell/browser/javascript_environment.h"
|
||||||
#include "shell/browser/media/media_capture_devices_dispatcher.h"
|
#include "shell/browser/media/media_capture_devices_dispatcher.h"
|
||||||
|
@ -1515,14 +1516,33 @@ void ElectronBrowserClient::
|
||||||
render_frame_host, // NOLINT(runtime/references)
|
render_frame_host, // NOLINT(runtime/references)
|
||||||
blink::AssociatedInterfaceRegistry&
|
blink::AssociatedInterfaceRegistry&
|
||||||
associated_registry) { // NOLINT(runtime/references)
|
associated_registry) { // NOLINT(runtime/references)
|
||||||
|
auto* contents =
|
||||||
|
content::WebContents::FromRenderFrameHost(&render_frame_host);
|
||||||
|
if (contents) {
|
||||||
|
auto* prefs = WebContentsPreferences::From(contents);
|
||||||
|
if (render_frame_host.GetFrameTreeNodeId() ==
|
||||||
|
contents->GetMainFrame()->GetFrameTreeNodeId() ||
|
||||||
|
(prefs && prefs->AllowsNodeIntegrationInSubFrames())) {
|
||||||
|
associated_registry.AddInterface(base::BindRepeating(
|
||||||
|
[](content::RenderFrameHost* render_frame_host,
|
||||||
|
mojo::PendingAssociatedReceiver<electron::mojom::ElectronApiIPC>
|
||||||
|
receiver) {
|
||||||
|
ElectronApiIPCHandlerImpl::Create(render_frame_host,
|
||||||
|
std::move(receiver));
|
||||||
|
},
|
||||||
|
&render_frame_host));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
associated_registry.AddInterface(base::BindRepeating(
|
associated_registry.AddInterface(base::BindRepeating(
|
||||||
[](content::RenderFrameHost* render_frame_host,
|
[](content::RenderFrameHost* render_frame_host,
|
||||||
mojo::PendingAssociatedReceiver<electron::mojom::ElectronBrowser>
|
mojo::PendingAssociatedReceiver<
|
||||||
receiver) {
|
electron::mojom::ElectronWebContentsUtility> receiver) {
|
||||||
ElectronBrowserHandlerImpl::Create(render_frame_host,
|
ElectronWebContentsUtilityHandlerImpl::Create(render_frame_host,
|
||||||
std::move(receiver));
|
std::move(receiver));
|
||||||
},
|
},
|
||||||
&render_frame_host));
|
&render_frame_host));
|
||||||
|
|
||||||
associated_registry.AddInterface(base::BindRepeating(
|
associated_registry.AddInterface(base::BindRepeating(
|
||||||
[](content::RenderFrameHost* render_frame_host,
|
[](content::RenderFrameHost* render_frame_host,
|
||||||
mojo::PendingAssociatedReceiver<mojom::ElectronAutofillDriver>
|
mojo::PendingAssociatedReceiver<mojom::ElectronAutofillDriver>
|
||||||
|
|
|
@ -1,141 +0,0 @@
|
||||||
// Copyright (c) 2019 Slack Technologies, Inc.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "shell/browser/electron_browser_handler_impl.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "content/public/browser/browser_context.h"
|
|
||||||
#include "content/public/browser/browser_thread.h"
|
|
||||||
#include "content/public/browser/render_frame_host.h"
|
|
||||||
#include "content/public/browser/render_process_host.h"
|
|
||||||
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
|
||||||
|
|
||||||
namespace electron {
|
|
||||||
ElectronBrowserHandlerImpl::ElectronBrowserHandlerImpl(
|
|
||||||
content::RenderFrameHost* frame_host,
|
|
||||||
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver)
|
|
||||||
: render_process_id_(frame_host->GetProcess()->GetID()),
|
|
||||||
render_frame_id_(frame_host->GetRoutingID()) {
|
|
||||||
content::WebContents* web_contents =
|
|
||||||
content::WebContents::FromRenderFrameHost(frame_host);
|
|
||||||
DCHECK(web_contents);
|
|
||||||
content::WebContentsObserver::Observe(web_contents);
|
|
||||||
|
|
||||||
receiver_.Bind(std::move(receiver));
|
|
||||||
receiver_.set_disconnect_handler(base::BindOnce(
|
|
||||||
&ElectronBrowserHandlerImpl::OnConnectionError, GetWeakPtr()));
|
|
||||||
}
|
|
||||||
|
|
||||||
ElectronBrowserHandlerImpl::~ElectronBrowserHandlerImpl() = default;
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::WebContentsDestroyed() {
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::OnConnectionError() {
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::Message(bool internal,
|
|
||||||
const std::string& channel,
|
|
||||||
blink::CloneableMessage arguments) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->Message(internal, channel, std::move(arguments),
|
|
||||||
GetRenderFrameHost());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void ElectronBrowserHandlerImpl::Invoke(bool internal,
|
|
||||||
const std::string& channel,
|
|
||||||
blink::CloneableMessage arguments,
|
|
||||||
InvokeCallback callback) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->Invoke(internal, channel, std::move(arguments),
|
|
||||||
std::move(callback), GetRenderFrameHost());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::OnFirstNonEmptyLayout() {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->OnFirstNonEmptyLayout(GetRenderFrameHost());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::ReceivePostMessage(
|
|
||||||
const std::string& channel,
|
|
||||||
blink::TransferableMessage message) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->ReceivePostMessage(channel, std::move(message),
|
|
||||||
GetRenderFrameHost());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::MessageSync(bool internal,
|
|
||||||
const std::string& channel,
|
|
||||||
blink::CloneableMessage arguments,
|
|
||||||
MessageSyncCallback callback) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->MessageSync(internal, channel, std::move(arguments),
|
|
||||||
std::move(callback), GetRenderFrameHost());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::MessageTo(int32_t web_contents_id,
|
|
||||||
const std::string& channel,
|
|
||||||
blink::CloneableMessage arguments) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->MessageTo(web_contents_id, channel, std::move(arguments));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::MessageHost(
|
|
||||||
const std::string& channel,
|
|
||||||
blink::CloneableMessage arguments) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->MessageHost(channel, std::move(arguments),
|
|
||||||
GetRenderFrameHost());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::UpdateDraggableRegions(
|
|
||||||
std::vector<mojom::DraggableRegionPtr> regions) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->UpdateDraggableRegions(std::move(regions));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::SetTemporaryZoomLevel(double level) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->SetTemporaryZoomLevel(level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronBrowserHandlerImpl::DoGetZoomLevel(
|
|
||||||
DoGetZoomLevelCallback callback) {
|
|
||||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
|
||||||
if (api_web_contents) {
|
|
||||||
api_web_contents->DoGetZoomLevel(std::move(callback));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
content::RenderFrameHost* ElectronBrowserHandlerImpl::GetRenderFrameHost() {
|
|
||||||
return content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
void ElectronBrowserHandlerImpl::Create(
|
|
||||||
content::RenderFrameHost* frame_host,
|
|
||||||
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver) {
|
|
||||||
new ElectronBrowserHandlerImpl(frame_host, std::move(receiver));
|
|
||||||
}
|
|
||||||
} // namespace electron
|
|
83
shell/browser/electron_web_contents_utility_handler_impl.cc
Normal file
83
shell/browser/electron_web_contents_utility_handler_impl.cc
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
// Copyright (c) 2022 Slack Technologies, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "shell/browser/electron_web_contents_utility_handler_impl.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "content/public/browser/render_frame_host.h"
|
||||||
|
#include "content/public/browser/render_process_host.h"
|
||||||
|
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
||||||
|
|
||||||
|
namespace electron {
|
||||||
|
ElectronWebContentsUtilityHandlerImpl::ElectronWebContentsUtilityHandlerImpl(
|
||||||
|
content::RenderFrameHost* frame_host,
|
||||||
|
mojo::PendingAssociatedReceiver<mojom::ElectronWebContentsUtility> receiver)
|
||||||
|
: render_process_id_(frame_host->GetProcess()->GetID()),
|
||||||
|
render_frame_id_(frame_host->GetRoutingID()) {
|
||||||
|
content::WebContents* web_contents =
|
||||||
|
content::WebContents::FromRenderFrameHost(frame_host);
|
||||||
|
DCHECK(web_contents);
|
||||||
|
content::WebContentsObserver::Observe(web_contents);
|
||||||
|
|
||||||
|
receiver_.Bind(std::move(receiver));
|
||||||
|
receiver_.set_disconnect_handler(base::BindOnce(
|
||||||
|
&ElectronWebContentsUtilityHandlerImpl::OnConnectionError, GetWeakPtr()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ElectronWebContentsUtilityHandlerImpl::
|
||||||
|
~ElectronWebContentsUtilityHandlerImpl() = default;
|
||||||
|
|
||||||
|
void ElectronWebContentsUtilityHandlerImpl::WebContentsDestroyed() {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronWebContentsUtilityHandlerImpl::OnConnectionError() {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronWebContentsUtilityHandlerImpl::OnFirstNonEmptyLayout() {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->OnFirstNonEmptyLayout(GetRenderFrameHost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronWebContentsUtilityHandlerImpl::UpdateDraggableRegions(
|
||||||
|
std::vector<mojom::DraggableRegionPtr> regions) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->UpdateDraggableRegions(std::move(regions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronWebContentsUtilityHandlerImpl::SetTemporaryZoomLevel(
|
||||||
|
double level) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->SetTemporaryZoomLevel(level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronWebContentsUtilityHandlerImpl::DoGetZoomLevel(
|
||||||
|
DoGetZoomLevelCallback callback) {
|
||||||
|
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->DoGetZoomLevel(std::move(callback));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content::RenderFrameHost*
|
||||||
|
ElectronWebContentsUtilityHandlerImpl::GetRenderFrameHost() {
|
||||||
|
return content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void ElectronWebContentsUtilityHandlerImpl::Create(
|
||||||
|
content::RenderFrameHost* frame_host,
|
||||||
|
mojo::PendingAssociatedReceiver<mojom::ElectronWebContentsUtility>
|
||||||
|
receiver) {
|
||||||
|
new ElectronWebContentsUtilityHandlerImpl(frame_host, std::move(receiver));
|
||||||
|
}
|
||||||
|
} // namespace electron
|
71
shell/browser/electron_web_contents_utility_handler_impl.h
Normal file
71
shell/browser/electron_web_contents_utility_handler_impl.h
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
// Copyright (c) 2022 Slack Technologies, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_
|
||||||
|
#define ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
|
#include "electron/shell/common/api/api.mojom.h"
|
||||||
|
#include "shell/browser/api/electron_api_web_contents.h"
|
||||||
|
|
||||||
|
namespace content {
|
||||||
|
class RenderFrameHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace electron {
|
||||||
|
class ElectronWebContentsUtilityHandlerImpl
|
||||||
|
: public mojom::ElectronWebContentsUtility,
|
||||||
|
public content::WebContentsObserver {
|
||||||
|
public:
|
||||||
|
explicit ElectronWebContentsUtilityHandlerImpl(
|
||||||
|
content::RenderFrameHost* render_frame_host,
|
||||||
|
mojo::PendingAssociatedReceiver<mojom::ElectronWebContentsUtility>
|
||||||
|
receiver);
|
||||||
|
|
||||||
|
static void Create(
|
||||||
|
content::RenderFrameHost* frame_host,
|
||||||
|
mojo::PendingAssociatedReceiver<mojom::ElectronWebContentsUtility>
|
||||||
|
receiver);
|
||||||
|
|
||||||
|
// disable copy
|
||||||
|
ElectronWebContentsUtilityHandlerImpl(
|
||||||
|
const ElectronWebContentsUtilityHandlerImpl&) = delete;
|
||||||
|
ElectronWebContentsUtilityHandlerImpl& operator=(
|
||||||
|
const ElectronWebContentsUtilityHandlerImpl&) = delete;
|
||||||
|
|
||||||
|
// mojom::ElectronWebContentsUtility:
|
||||||
|
void OnFirstNonEmptyLayout() override;
|
||||||
|
void UpdateDraggableRegions(
|
||||||
|
std::vector<mojom::DraggableRegionPtr> regions) override;
|
||||||
|
void SetTemporaryZoomLevel(double level) override;
|
||||||
|
void DoGetZoomLevel(DoGetZoomLevelCallback callback) override;
|
||||||
|
|
||||||
|
base::WeakPtr<ElectronWebContentsUtilityHandlerImpl> GetWeakPtr() {
|
||||||
|
return weak_factory_.GetWeakPtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
~ElectronWebContentsUtilityHandlerImpl() override;
|
||||||
|
|
||||||
|
// content::WebContentsObserver:
|
||||||
|
void WebContentsDestroyed() override;
|
||||||
|
|
||||||
|
void OnConnectionError();
|
||||||
|
|
||||||
|
content::RenderFrameHost* GetRenderFrameHost();
|
||||||
|
|
||||||
|
const int render_process_id_;
|
||||||
|
const int render_frame_id_;
|
||||||
|
|
||||||
|
mojo::AssociatedReceiver<mojom::ElectronWebContentsUtility> receiver_{this};
|
||||||
|
|
||||||
|
base::WeakPtrFactory<ElectronWebContentsUtilityHandlerImpl> weak_factory_{
|
||||||
|
this};
|
||||||
|
};
|
||||||
|
} // namespace electron
|
||||||
|
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_
|
|
@ -71,6 +71,9 @@ class WebContentsPreferences
|
||||||
bool ShouldDisableHtmlFullscreenWindowResize() const {
|
bool ShouldDisableHtmlFullscreenWindowResize() const {
|
||||||
return disable_html_fullscreen_window_resize_;
|
return disable_html_fullscreen_window_resize_;
|
||||||
}
|
}
|
||||||
|
bool AllowsNodeIntegrationInSubFrames() const {
|
||||||
|
return node_integration_in_sub_frames_;
|
||||||
|
}
|
||||||
bool ShouldDisableDialogs() const { return disable_dialogs_; }
|
bool ShouldDisableDialogs() const { return disable_dialogs_; }
|
||||||
bool ShouldUseSafeDialogs() const { return safe_dialogs_; }
|
bool ShouldUseSafeDialogs() const { return safe_dialogs_; }
|
||||||
bool GetSafeDialogsMessage(std::string* message) const;
|
bool GetSafeDialogsMessage(std::string* message) const;
|
||||||
|
|
|
@ -31,7 +31,21 @@ struct DraggableRegion {
|
||||||
gfx.mojom.Rect bounds;
|
gfx.mojom.Rect bounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface ElectronBrowser {
|
interface ElectronWebContentsUtility {
|
||||||
|
// Informs underlying WebContents that first non-empty layout was performed
|
||||||
|
// by compositor.
|
||||||
|
OnFirstNonEmptyLayout();
|
||||||
|
|
||||||
|
UpdateDraggableRegions(
|
||||||
|
array<DraggableRegion> regions);
|
||||||
|
|
||||||
|
SetTemporaryZoomLevel(double zoom_level);
|
||||||
|
|
||||||
|
[Sync]
|
||||||
|
DoGetZoomLevel() => (double result);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface ElectronApiIPC {
|
||||||
// Emits an event on |channel| from the ipcMain JavaScript object in the main
|
// Emits an event on |channel| from the ipcMain JavaScript object in the main
|
||||||
// process.
|
// process.
|
||||||
Message(
|
Message(
|
||||||
|
@ -46,10 +60,6 @@ interface ElectronBrowser {
|
||||||
string channel,
|
string channel,
|
||||||
blink.mojom.CloneableMessage arguments) => (blink.mojom.CloneableMessage result);
|
blink.mojom.CloneableMessage arguments) => (blink.mojom.CloneableMessage result);
|
||||||
|
|
||||||
// Informs underlying WebContents that first non-empty layout was performed
|
|
||||||
// by compositor.
|
|
||||||
OnFirstNonEmptyLayout();
|
|
||||||
|
|
||||||
ReceivePostMessage(string channel, blink.mojom.TransferableMessage message);
|
ReceivePostMessage(string channel, blink.mojom.TransferableMessage message);
|
||||||
|
|
||||||
// Emits an event on |channel| from the ipcMain JavaScript object in the main
|
// Emits an event on |channel| from the ipcMain JavaScript object in the main
|
||||||
|
@ -70,12 +80,4 @@ interface ElectronBrowser {
|
||||||
MessageHost(
|
MessageHost(
|
||||||
string channel,
|
string channel,
|
||||||
blink.mojom.CloneableMessage arguments);
|
blink.mojom.CloneableMessage arguments);
|
||||||
|
|
||||||
UpdateDraggableRegions(
|
|
||||||
array<DraggableRegion> regions);
|
|
||||||
|
|
||||||
SetTemporaryZoomLevel(double zoom_level);
|
|
||||||
|
|
||||||
[Sync]
|
|
||||||
DoGetZoomLevel() => (double result);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,7 +54,7 @@ v8::Local<v8::Object> CreateNativeEvent(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> sender,
|
v8::Local<v8::Object> sender,
|
||||||
content::RenderFrameHost* frame,
|
content::RenderFrameHost* frame,
|
||||||
electron::mojom::ElectronBrowser::MessageSyncCallback callback) {
|
electron::mojom::ElectronApiIPC::MessageSyncCallback callback) {
|
||||||
v8::Local<v8::Object> event;
|
v8::Local<v8::Object> event;
|
||||||
if (frame && callback) {
|
if (frame && callback) {
|
||||||
gin::Handle<Event> native_event = Event::Create(isolate);
|
gin::Handle<Event> native_event = Event::Create(isolate);
|
||||||
|
|
|
@ -29,7 +29,7 @@ v8::Local<v8::Object> CreateNativeEvent(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> sender,
|
v8::Local<v8::Object> sender,
|
||||||
content::RenderFrameHost* frame,
|
content::RenderFrameHost* frame,
|
||||||
electron::mojom::ElectronBrowser::MessageSyncCallback callback);
|
electron::mojom::ElectronApiIPC::MessageSyncCallback callback);
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
|
|
|
@ -60,16 +60,16 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
weak_context_.SetWeak();
|
weak_context_.SetWeak();
|
||||||
|
|
||||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||||
&electron_browser_remote_);
|
&electron_ipc_remote_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDestruct() override { electron_browser_remote_.reset(); }
|
void OnDestruct() override { electron_ipc_remote_.reset(); }
|
||||||
|
|
||||||
void WillReleaseScriptContext(v8::Local<v8::Context> context,
|
void WillReleaseScriptContext(v8::Local<v8::Context> context,
|
||||||
int32_t world_id) override {
|
int32_t world_id) override {
|
||||||
if (weak_context_.IsEmpty() ||
|
if (weak_context_.IsEmpty() ||
|
||||||
weak_context_.Get(context->GetIsolate()) == context)
|
weak_context_.Get(context->GetIsolate()) == context)
|
||||||
electron_browser_remote_.reset();
|
electron_ipc_remote_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// gin::Wrappable:
|
// gin::Wrappable:
|
||||||
|
@ -92,7 +92,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
v8::Local<v8::Value> arguments) {
|
v8::Local<v8::Value> arguments) {
|
||||||
if (!electron_browser_remote_) {
|
if (!electron_ipc_remote_) {
|
||||||
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
if (!electron::SerializeV8Value(isolate, arguments, &message)) {
|
if (!electron::SerializeV8Value(isolate, arguments, &message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
electron_browser_remote_->Message(internal, channel, std::move(message));
|
electron_ipc_remote_->Message(internal, channel, std::move(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> Invoke(v8::Isolate* isolate,
|
v8::Local<v8::Promise> Invoke(v8::Isolate* isolate,
|
||||||
|
@ -108,7 +108,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
v8::Local<v8::Value> arguments) {
|
v8::Local<v8::Value> arguments) {
|
||||||
if (!electron_browser_remote_) {
|
if (!electron_ipc_remote_) {
|
||||||
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
||||||
return v8::Local<v8::Promise>();
|
return v8::Local<v8::Promise>();
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
gin_helper::Promise<blink::CloneableMessage> p(isolate);
|
gin_helper::Promise<blink::CloneableMessage> p(isolate);
|
||||||
auto handle = p.GetHandle();
|
auto handle = p.GetHandle();
|
||||||
|
|
||||||
electron_browser_remote_->Invoke(
|
electron_ipc_remote_->Invoke(
|
||||||
internal, channel, std::move(message),
|
internal, channel, std::move(message),
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](gin_helper::Promise<blink::CloneableMessage> p,
|
[](gin_helper::Promise<blink::CloneableMessage> p,
|
||||||
|
@ -134,7 +134,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
v8::Local<v8::Value> message_value,
|
v8::Local<v8::Value> message_value,
|
||||||
absl::optional<v8::Local<v8::Value>> transfer) {
|
absl::optional<v8::Local<v8::Value>> transfer) {
|
||||||
if (!electron_browser_remote_) {
|
if (!electron_ipc_remote_) {
|
||||||
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -166,8 +166,8 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
transferable_message.ports = std::move(ports);
|
transferable_message.ports = std::move(ports);
|
||||||
electron_browser_remote_->ReceivePostMessage(
|
electron_ipc_remote_->ReceivePostMessage(channel,
|
||||||
channel, std::move(transferable_message));
|
std::move(transferable_message));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendTo(v8::Isolate* isolate,
|
void SendTo(v8::Isolate* isolate,
|
||||||
|
@ -175,7 +175,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
int32_t web_contents_id,
|
int32_t web_contents_id,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
v8::Local<v8::Value> arguments) {
|
v8::Local<v8::Value> arguments) {
|
||||||
if (!electron_browser_remote_) {
|
if (!electron_ipc_remote_) {
|
||||||
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -183,15 +183,15 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
if (!electron::SerializeV8Value(isolate, arguments, &message)) {
|
if (!electron::SerializeV8Value(isolate, arguments, &message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
electron_browser_remote_->MessageTo(web_contents_id, channel,
|
electron_ipc_remote_->MessageTo(web_contents_id, channel,
|
||||||
std::move(message));
|
std::move(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendToHost(v8::Isolate* isolate,
|
void SendToHost(v8::Isolate* isolate,
|
||||||
gin_helper::ErrorThrower thrower,
|
gin_helper::ErrorThrower thrower,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
v8::Local<v8::Value> arguments) {
|
v8::Local<v8::Value> arguments) {
|
||||||
if (!electron_browser_remote_) {
|
if (!electron_ipc_remote_) {
|
||||||
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
if (!electron::SerializeV8Value(isolate, arguments, &message)) {
|
if (!electron::SerializeV8Value(isolate, arguments, &message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
electron_browser_remote_->MessageHost(channel, std::move(message));
|
electron_ipc_remote_->MessageHost(channel, std::move(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> SendSync(v8::Isolate* isolate,
|
v8::Local<v8::Value> SendSync(v8::Isolate* isolate,
|
||||||
|
@ -207,7 +207,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
v8::Local<v8::Value> arguments) {
|
v8::Local<v8::Value> arguments) {
|
||||||
if (!electron_browser_remote_) {
|
if (!electron_ipc_remote_) {
|
||||||
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
|
||||||
return v8::Local<v8::Value>();
|
return v8::Local<v8::Value>();
|
||||||
}
|
}
|
||||||
|
@ -217,14 +217,13 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
blink::CloneableMessage result;
|
blink::CloneableMessage result;
|
||||||
electron_browser_remote_->MessageSync(internal, channel, std::move(message),
|
electron_ipc_remote_->MessageSync(internal, channel, std::move(message),
|
||||||
&result);
|
&result);
|
||||||
return electron::DeserializeV8Value(isolate, result);
|
return electron::DeserializeV8Value(isolate, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Global<v8::Context> weak_context_;
|
v8::Global<v8::Context> weak_context_;
|
||||||
mojo::AssociatedRemote<electron::mojom::ElectronBrowser>
|
mojo::AssociatedRemote<electron::mojom::ElectronApiIPC> electron_ipc_remote_;
|
||||||
electron_browser_remote_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
gin::WrapperInfo IPCRenderer::kWrapperInfo = {gin::kEmbedderNativeGin};
|
gin::WrapperInfo IPCRenderer::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||||
|
|
|
@ -453,10 +453,11 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
||||||
if (!MaybeGetRenderFrame(isolate, "setZoomLevel", &render_frame))
|
if (!MaybeGetRenderFrame(isolate, "setZoomLevel", &render_frame))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
|
mojo::AssociatedRemote<mojom::ElectronWebContentsUtility>
|
||||||
|
web_contents_utility_remote;
|
||||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||||
&browser_remote);
|
&web_contents_utility_remote);
|
||||||
browser_remote->SetTemporaryZoomLevel(level);
|
web_contents_utility_remote->SetTemporaryZoomLevel(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
double GetZoomLevel(v8::Isolate* isolate) {
|
double GetZoomLevel(v8::Isolate* isolate) {
|
||||||
|
@ -465,10 +466,11 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
||||||
if (!MaybeGetRenderFrame(isolate, "getZoomLevel", &render_frame))
|
if (!MaybeGetRenderFrame(isolate, "getZoomLevel", &render_frame))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
|
mojo::AssociatedRemote<mojom::ElectronWebContentsUtility>
|
||||||
|
web_contents_utility_remote;
|
||||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||||
&browser_remote);
|
&web_contents_utility_remote);
|
||||||
browser_remote->DoGetZoomLevel(&result);
|
web_contents_utility_remote->DoGetZoomLevel(&result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,9 +149,11 @@ void ElectronRenderFrameObserver::DraggableRegionsChanged() {
|
||||||
regions.push_back(std::move(region));
|
regions.push_back(std::move(region));
|
||||||
}
|
}
|
||||||
|
|
||||||
mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
|
mojo::AssociatedRemote<mojom::ElectronWebContentsUtility>
|
||||||
render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(&browser_remote);
|
web_contents_utility_remote;
|
||||||
browser_remote->UpdateDraggableRegions(std::move(regions));
|
render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||||
|
&web_contents_utility_remote);
|
||||||
|
web_contents_utility_remote->UpdateDraggableRegions(std::move(regions));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronRenderFrameObserver::WillReleaseScriptContext(
|
void ElectronRenderFrameObserver::WillReleaseScriptContext(
|
||||||
|
@ -168,10 +170,11 @@ void ElectronRenderFrameObserver::OnDestruct() {
|
||||||
void ElectronRenderFrameObserver::DidMeaningfulLayout(
|
void ElectronRenderFrameObserver::DidMeaningfulLayout(
|
||||||
blink::WebMeaningfulLayout layout_type) {
|
blink::WebMeaningfulLayout layout_type) {
|
||||||
if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
|
if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
|
||||||
mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
|
mojo::AssociatedRemote<mojom::ElectronWebContentsUtility>
|
||||||
|
web_contents_utility_remote;
|
||||||
render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(
|
render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||||
&browser_remote);
|
&web_contents_utility_remote);
|
||||||
browser_remote->OnFirstNonEmptyLayout();
|
web_contents_utility_remote->OnFirstNonEmptyLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue