refactor: use mojo for electron internal IPC (#17406)
* refactor: use mojo for electron internal IPC * add sender_id, drop MessageSync * remove usages of AtomFrameMsg_Message * iwyu * first draft of renderer->browser direction * refactor to reuse a single ipc interface * implement TakeHeapSnapshot through mojo * the rest of the owl^WtakeHeapSnapshot mojofication * remove no-op overrides in AtomRendererClient * delete renderer-side ElectronApiServiceImpl when its pipe is destroyed * looks like we don't need to overlay the renderer manifest after all * don't try to send 2 replies to a sync rpc * undo changes to manifests.cc * unify sandboxed + unsandboxed ipc events * lint * register ElectronBrowser mojo service on devtools WebContents * fix takeHeapSnapshopt failure paths * {electron_api => atom}::mojom * add send_to_all to ElectronRenderer::Message * keep interface alive until callback is called * review comments * use GetContext from RendererClientBase * robustify a test that uses window.open * MessageSync posts a task to put sync messages in the same queue as async ones * add v8::MicrotasksScope and node::CallbackScope * iwyu * use weakptr to api::WebContents instead of Unretained * make MessageSync an asynchronous message & use non-associated interface * iwyu + comments * remove unused WeakPtrFactory * inline OnRendererMessage[Sync] * cleanups & comments * use helper methods instead of inline lambdas * remove unneeded async in test * add mojo to manifests deps * add gn check for //electron/manifests and mojo * don't register renderer side service until preload has been run * update gn check targets list * move interface registration back to RenderFrameCreated
This commit is contained in:
parent
5b696491db
commit
53f6cbccbf
32 changed files with 620 additions and 401 deletions
11
atom/common/api/BUILD.gn
Normal file
11
atom/common/api/BUILD.gn
Normal file
|
@ -0,0 +1,11 @@
|
|||
import("//mojo/public/tools/bindings/mojom.gni")
|
||||
|
||||
mojom("mojo") {
|
||||
sources = [
|
||||
"api.mojom",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//mojo/public/mojom/base",
|
||||
]
|
||||
}
|
29
atom/common/api/api.mojom
Normal file
29
atom/common/api/api.mojom
Normal file
|
@ -0,0 +1,29 @@
|
|||
module atom.mojom;
|
||||
|
||||
import "mojo/public/mojom/base/values.mojom";
|
||||
|
||||
interface ElectronRenderer {
|
||||
Message(
|
||||
bool internal,
|
||||
bool send_to_all,
|
||||
string channel,
|
||||
mojo_base.mojom.ListValue arguments,
|
||||
int32 sender_id);
|
||||
|
||||
TakeHeapSnapshot(handle file) => (bool success);
|
||||
};
|
||||
|
||||
interface ElectronBrowser {
|
||||
Message(
|
||||
bool internal,
|
||||
string channel,
|
||||
mojo_base.mojom.ListValue arguments);
|
||||
|
||||
// NB. this is not marked [Sync] because mojo synchronous methods can be
|
||||
// reordered with respect to asynchronous methods on the same channel.
|
||||
// Instead, callers can manually block on the response to this method.
|
||||
MessageSync(
|
||||
bool internal,
|
||||
string channel,
|
||||
mojo_base.mojom.ListValue arguments) => (mojo_base.mojom.Value result);
|
||||
};
|
|
@ -25,17 +25,6 @@ IPC_STRUCT_TRAITS_BEGIN(atom::DraggableRegion)
|
|||
IPC_STRUCT_TRAITS_MEMBER(bounds)
|
||||
IPC_STRUCT_TRAITS_END()
|
||||
|
||||
IPC_MESSAGE_ROUTED3(AtomFrameHostMsg_Message,
|
||||
bool /* internal */,
|
||||
std::string /* channel */,
|
||||
base::ListValue /* arguments */)
|
||||
|
||||
IPC_SYNC_MESSAGE_ROUTED3_1(AtomFrameHostMsg_Message_Sync,
|
||||
bool /* internal */,
|
||||
std::string /* channel */,
|
||||
base::ListValue /* arguments */,
|
||||
base::ListValue /* result */)
|
||||
|
||||
IPC_MESSAGE_ROUTED5(AtomFrameHostMsg_Message_To,
|
||||
bool /* internal */,
|
||||
bool /* send_to_all */,
|
||||
|
@ -47,13 +36,6 @@ IPC_MESSAGE_ROUTED2(AtomFrameHostMsg_Message_Host,
|
|||
std::string /* channel */,
|
||||
base::ListValue /* arguments */)
|
||||
|
||||
IPC_MESSAGE_ROUTED5(AtomFrameMsg_Message,
|
||||
bool /* internal */,
|
||||
bool /* send_to_all */,
|
||||
std::string /* channel */,
|
||||
base::ListValue /* arguments */,
|
||||
int32_t /* sender_id */)
|
||||
|
||||
IPC_MESSAGE_ROUTED0(AtomViewMsg_Offscreen)
|
||||
|
||||
IPC_MESSAGE_ROUTED3(AtomAutofillFrameHostMsg_ShowPopup,
|
||||
|
@ -85,7 +67,3 @@ IPC_SYNC_MESSAGE_ROUTED0_1(AtomFrameHostMsg_GetZoomLevel, double /* result */)
|
|||
IPC_MESSAGE_ROUTED2(AtomFrameHostMsg_PDFSaveURLAs,
|
||||
GURL /* url */,
|
||||
content::Referrer /* referrer */)
|
||||
|
||||
IPC_MESSAGE_ROUTED2(AtomFrameMsg_TakeHeapSnapshot,
|
||||
IPC::PlatformFileForTransit /* file_handle */,
|
||||
std::string /* channel */)
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
#include "atom/common/api/remote_callback_freer.h"
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "electron/atom/common/api/api.mojom.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -41,8 +42,11 @@ void RemoteCallbackFreer::RunDestructor() {
|
|||
args.AppendInteger(object_id_);
|
||||
auto* frame_host = web_contents()->GetMainFrame();
|
||||
if (frame_host) {
|
||||
frame_host->Send(new AtomFrameMsg_Message(frame_host->GetRoutingID(), true,
|
||||
false, channel, args, sender_id));
|
||||
mojom::ElectronRendererAssociatedPtr electron_ptr;
|
||||
frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
mojo::MakeRequest(&electron_ptr));
|
||||
electron_ptr->Message(true /* internal */, false /* send_to_all */, channel,
|
||||
args.Clone(), sender_id);
|
||||
}
|
||||
|
||||
Observe(nullptr);
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "electron/atom/common/api/api.mojom.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
||||
#include "third_party/blink/public/web/web_local_frame.h"
|
||||
|
||||
using blink::WebLocalFrame;
|
||||
|
@ -60,8 +62,11 @@ void RemoteObjectFreer::RunDestructor() {
|
|||
base::ListValue args;
|
||||
args.AppendString(context_id_);
|
||||
args.AppendInteger(object_id_);
|
||||
render_frame->Send(new AtomFrameHostMsg_Message(render_frame->GetRoutingID(),
|
||||
true, channel, args));
|
||||
|
||||
mojom::ElectronBrowserAssociatedPtr electron_ptr;
|
||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
mojo::MakeRequest(&electron_ptr));
|
||||
electron_ptr->Message(true, channel, args.Clone());
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue