Skip to content

Commit e757601

Browse files
authored
fix: use legacy base::Value serializers for ipc (7-1-x) (electron#21922)
1 parent 77448c7 commit e757601

15 files changed

Lines changed: 95 additions & 50 deletions

patches/chromium/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ accessible_pane_view.patch
9292
only_apply_transform_when_outermost_outer_webcontents.patch
9393
never_let_a_non-zero-size_pixel_snap_to_zero_size.patch
9494
fix_hi-dpi_transitions_on_catalina.patch
95+
typemap.patch

patches/chromium/typemap.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jeremy Apthorp <nornagon@nornagon.net>
3+
Date: Mon, 27 Jan 2020 16:02:41 -0800
4+
Subject: typemap
5+
6+
this adds electron's typemap to the global registry of typemaps. Only
7+
needed for temporarily supporting the legacy-ipc base::ListValue
8+
serializers until we switch to using SCA.
9+
10+
diff --git a/mojo/public/tools/bindings/chromium_bindings_configuration.gni b/mojo/public/tools/bindings/chromium_bindings_configuration.gni
11+
index 6e8bc9e2c4f0edca9f22eac5017b44000e477ea2..a482fdca501ed94ec135c18cd35bc2fe3cf6ed88 100644
12+
--- a/mojo/public/tools/bindings/chromium_bindings_configuration.gni
13+
+++ b/mojo/public/tools/bindings/chromium_bindings_configuration.gni
14+
@@ -22,6 +22,7 @@ _typemap_imports = [
15+
"//device/bluetooth/public/mojom/typemaps.gni",
16+
"//device/bluetooth/public/mojom/test/typemaps.gni",
17+
"//device/gamepad/public/cpp/typemaps.gni",
18+
+ "//electron/shell/common/api/typemaps.gni",
19+
"//fuchsia/mojom/test_typemaps.gni",
20+
"//gpu/ipc/common/typemaps.gni",
21+
"//ipc/typemaps.gni",

shell/browser/api/atom_api_web_contents.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,15 +1023,15 @@ void WebContents::OnElectronBrowserConnectionError() {
10231023

10241024
void WebContents::Message(bool internal,
10251025
const std::string& channel,
1026-
base::Value arguments) {
1026+
base::ListValue arguments) {
10271027
// webContents.emit('-ipc-message', new Event(), internal, channel,
10281028
// arguments);
10291029
EmitWithSender("-ipc-message", bindings_.dispatch_context(), base::nullopt,
10301030
internal, channel, std::move(arguments));
10311031
}
10321032

10331033
void WebContents::Invoke(const std::string& channel,
1034-
base::Value arguments,
1034+
base::ListValue arguments,
10351035
InvokeCallback callback) {
10361036
// webContents.emit('-ipc-invoke', new Event(), channel, arguments);
10371037
EmitWithSender("-ipc-invoke", bindings_.dispatch_context(),
@@ -1040,7 +1040,7 @@ void WebContents::Invoke(const std::string& channel,
10401040

10411041
void WebContents::MessageSync(bool internal,
10421042
const std::string& channel,
1043-
base::Value arguments,
1043+
base::ListValue arguments,
10441044
MessageSyncCallback callback) {
10451045
// webContents.emit('-ipc-message-sync', new Event(sender, message), internal,
10461046
// channel, arguments);
@@ -1052,19 +1052,18 @@ void WebContents::MessageTo(bool internal,
10521052
bool send_to_all,
10531053
int32_t web_contents_id,
10541054
const std::string& channel,
1055-
base::Value arguments) {
1055+
base::ListValue arguments) {
10561056
auto* web_contents = mate::TrackableObject<WebContents>::FromWeakMapID(
10571057
isolate(), web_contents_id);
10581058

10591059
if (web_contents) {
10601060
web_contents->SendIPCMessageWithSender(internal, send_to_all, channel,
1061-
base::ListValue(arguments.GetList()),
1062-
ID());
1061+
std::move(arguments), ID());
10631062
}
10641063
}
10651064

10661065
void WebContents::MessageHost(const std::string& channel,
1067-
base::Value arguments) {
1066+
base::ListValue arguments) {
10681067
// webContents.emit('ipc-message-host', new Event(), channel, args);
10691068
EmitWithSender("ipc-message-host", bindings_.dispatch_context(),
10701069
base::nullopt, channel, std::move(arguments));
@@ -1943,14 +1942,15 @@ void WebContents::TabTraverse(bool reverse) {
19431942
bool WebContents::SendIPCMessage(bool internal,
19441943
bool send_to_all,
19451944
const std::string& channel,
1946-
const base::ListValue& args) {
1947-
return SendIPCMessageWithSender(internal, send_to_all, channel, args);
1945+
base::ListValue args) {
1946+
return SendIPCMessageWithSender(internal, send_to_all, channel,
1947+
std::move(args));
19481948
}
19491949

19501950
bool WebContents::SendIPCMessageWithSender(bool internal,
19511951
bool send_to_all,
19521952
const std::string& channel,
1953-
const base::ListValue& args,
1953+
base::ListValue args,
19541954
int32_t sender_id) {
19551955
std::vector<content::RenderFrameHost*> target_hosts;
19561956
if (!send_to_all) {
@@ -1966,7 +1966,8 @@ bool WebContents::SendIPCMessageWithSender(bool internal,
19661966
mojom::ElectronRendererAssociatedPtr electron_ptr;
19671967
frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
19681968
mojo::MakeRequest(&electron_ptr));
1969-
electron_ptr->Message(internal, false, channel, args.Clone(), sender_id);
1969+
electron_ptr->Message(internal, false, channel,
1970+
base::ListValue(args.Clone().GetList()), sender_id);
19701971
}
19711972
return true;
19721973
}
@@ -1975,7 +1976,7 @@ bool WebContents::SendIPCMessageToFrame(bool internal,
19751976
bool send_to_all,
19761977
int32_t frame_id,
19771978
const std::string& channel,
1978-
const base::ListValue& args) {
1979+
base::ListValue args) {
19791980
auto frames = web_contents()->GetAllFrames();
19801981
auto iter = std::find_if(frames.begin(), frames.end(), [frame_id](auto* f) {
19811982
return f->GetRoutingID() == frame_id;
@@ -1988,7 +1989,7 @@ bool WebContents::SendIPCMessageToFrame(bool internal,
19881989
mojom::ElectronRendererAssociatedPtr electron_ptr;
19891990
(*iter)->GetRemoteAssociatedInterfaces()->GetInterface(
19901991
mojo::MakeRequest(&electron_ptr));
1991-
electron_ptr->Message(internal, send_to_all, channel, args.Clone(),
1992+
electron_ptr->Message(internal, send_to_all, channel, std::move(args),
19921993
0 /* sender_id */);
19931994
return true;
19941995
}

shell/browser/api/atom_api_web_contents.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,19 @@ class WebContents : public mate::TrackableObject<WebContents>,
217217
bool SendIPCMessage(bool internal,
218218
bool send_to_all,
219219
const std::string& channel,
220-
const base::ListValue& args);
220+
base::ListValue args);
221221

222222
bool SendIPCMessageWithSender(bool internal,
223223
bool send_to_all,
224224
const std::string& channel,
225-
const base::ListValue& args,
225+
base::ListValue args,
226226
int32_t sender_id = 0);
227227

228228
bool SendIPCMessageToFrame(bool internal,
229229
bool send_to_all,
230230
int32_t frame_id,
231231
const std::string& channel,
232-
const base::ListValue& args);
232+
base::ListValue args);
233233

234234
// Send WebInputEvent to the page.
235235
void SendInputEvent(v8::Isolate* isolate, v8::Local<v8::Value> input_event);
@@ -509,20 +509,21 @@ class WebContents : public mate::TrackableObject<WebContents>,
509509
// mojom::ElectronBrowser
510510
void Message(bool internal,
511511
const std::string& channel,
512-
base::Value arguments) override;
512+
base::ListValue arguments) override;
513513
void Invoke(const std::string& channel,
514-
base::Value arguments,
514+
base::ListValue arguments,
515515
InvokeCallback callback) override;
516516
void MessageSync(bool internal,
517517
const std::string& channel,
518-
base::Value arguments,
518+
base::ListValue arguments,
519519
MessageSyncCallback callback) override;
520520
void MessageTo(bool internal,
521521
bool send_to_all,
522522
int32_t web_contents_id,
523523
const std::string& channel,
524-
base::Value arguments) override;
525-
void MessageHost(const std::string& channel, base::Value arguments) override;
524+
base::ListValue arguments) override;
525+
void MessageHost(const std::string& channel,
526+
base::ListValue arguments) override;
526527
void UpdateDraggableRegions(
527528
std::vector<mojom::DraggableRegionPtr> regions) override;
528529
void SetTemporaryZoomLevel(double level) override;

shell/browser/api/event.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ bool Event::SendReply(const base::Value& result) {
6161
if (!callback_ || sender_ == nullptr)
6262
return false;
6363

64-
std::move(*callback_).Run(result.Clone());
64+
base::ListValue ret;
65+
ret.GetList().push_back(result.Clone());
66+
67+
std::move(*callback_).Run(std::move(ret));
6568
callback_.reset();
6669
return true;
6770
}

shell/common/api/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
33
mojom("mojo") {
44
sources = [
55
"api.mojom",
6+
"native_types.mojom",
67
]
78

89
public_deps = [

shell/common/api/api.mojom

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
module electron.mojom;
22

3-
import "mojo/public/mojom/base/values.mojom";
43
import "mojo/public/mojom/base/string16.mojom";
54
import "ui/gfx/geometry/mojom/geometry.mojom";
5+
import "electron/shell/common/api/native_types.mojom";
6+
import "mojo/public/mojom/base/values.mojom";
67

78
interface ElectronRenderer {
89
Message(
910
bool internal,
1011
bool send_to_all,
1112
string channel,
12-
mojo_base.mojom.ListValue arguments,
13+
LegacyListValue arguments,
1314
int32 sender_id);
1415

1516
UpdateCrashpadPipeName(string pipe_name);
@@ -32,21 +33,21 @@ interface ElectronBrowser {
3233
Message(
3334
bool internal,
3435
string channel,
35-
mojo_base.mojom.ListValue arguments);
36+
LegacyListValue arguments);
3637

3738
// Emits an event on |channel| from the ipcMain JavaScript object in the main
3839
// process, and returns the response.
3940
Invoke(
4041
string channel,
41-
mojo_base.mojom.ListValue arguments) => (mojo_base.mojom.Value result);
42+
LegacyListValue arguments) => (LegacyListValue result);
4243

4344
// Emits an event on |channel| from the ipcMain JavaScript object in the main
4445
// process, and waits synchronously for a response.
4546
[Sync]
4647
MessageSync(
4748
bool internal,
4849
string channel,
49-
mojo_base.mojom.ListValue arguments) => (mojo_base.mojom.Value result);
50+
LegacyListValue arguments) => (LegacyListValue result);
5051

5152
// Emits an event from the |ipcRenderer| JavaScript object in the target
5253
// WebContents's main frame, specified by |web_contents_id|.
@@ -55,11 +56,11 @@ interface ElectronBrowser {
5556
bool send_to_all,
5657
int32 web_contents_id,
5758
string channel,
58-
mojo_base.mojom.ListValue arguments);
59+
LegacyListValue arguments);
5960

6061
MessageHost(
6162
string channel,
62-
mojo_base.mojom.ListValue arguments);
63+
LegacyListValue arguments);
6364

6465
UpdateDraggableRegions(
6566
array<DraggableRegion> regions);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module electron.mojom;
2+
3+
[Native]
4+
struct LegacyListValue;

shell/common/api/remote_callback_freer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void RemoteCallbackFreer::RunDestructor() {
5555
(*iter)->GetRemoteAssociatedInterfaces()->GetInterface(
5656
mojo::MakeRequest(&electron_ptr));
5757
electron_ptr->Message(true /* internal */, false /* send_to_all */, channel,
58-
args.Clone(), sender_id);
58+
base::ListValue(args.Clone().GetList()), sender_id);
5959
}
6060

6161
Observe(nullptr);

shell/common/api/remote_object_freer.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "shell/common/api/remote_object_freer.h"
66

7+
#include <utility>
8+
79
#include "base/strings/utf_string_conversions.h"
810
#include "base/values.h"
911
#include "content/public/renderer/render_frame.h"
@@ -79,7 +81,7 @@ void RemoteObjectFreer::RunDestructor() {
7981
mojom::ElectronBrowserPtr electron_ptr;
8082
render_frame->GetRemoteInterfaces()->GetInterface(
8183
mojo::MakeRequest(&electron_ptr));
82-
electron_ptr->Message(true, channel, args.Clone());
84+
electron_ptr->Message(true, channel, std::move(args));
8385
}
8486

8587
} // namespace electron

0 commit comments

Comments
 (0)