mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
Compare commits
910 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e80f3fb19 | ||
|
|
e64d407bfd | ||
|
|
7771886073 | ||
|
|
9b1147c7c9 | ||
|
|
69ff736ace | ||
|
|
04c7453074 | ||
|
|
46c0859c49 | ||
|
|
31e43f54d0 | ||
|
|
d545757191 | ||
|
|
ddc85869de | ||
|
|
65faec8659 | ||
|
|
9b72734f7c | ||
|
|
29a6dd079c | ||
|
|
dd58f2a6ac | ||
|
|
8e68e6eb75 | ||
|
|
0a3ec23967 | ||
|
|
6f85e4de57 | ||
|
|
b8f3325a04 | ||
|
|
3e6cd062a7 | ||
|
|
a2f68c1e57 | ||
|
|
bff8573646 | ||
|
|
32ad5be74e | ||
|
|
3d60f82d03 | ||
|
|
3aa16f5632 | ||
|
|
d0f7f9f894 | ||
|
|
7865fa37fa | ||
|
|
714fa6f3c0 | ||
|
|
61d9d7c657 | ||
|
|
558bb52847 | ||
|
|
c979c90f46 | ||
|
|
a9ada36097 | ||
|
|
0c4b2e99ec | ||
|
|
f35b166844 | ||
|
|
ff54817a92 | ||
|
|
25e5432863 | ||
|
|
4b9ae99f34 | ||
|
|
e2e7a82ebc | ||
|
|
385e548073 | ||
|
|
938b3440ef | ||
|
|
eb821a3c7f | ||
|
|
4318ad8f3a | ||
|
|
b3c44d1fe6 | ||
|
|
401f6641c8 | ||
|
|
18e31da478 | ||
|
|
ae5d556845 | ||
|
|
ebc937cfd5 | ||
|
|
f09f926cba | ||
|
|
4964a09677 | ||
|
|
a7c4d21427 | ||
|
|
07cd1e6b4d | ||
|
|
7a135c736b | ||
|
|
183c687f49 | ||
|
|
b04eaabf4e | ||
|
|
aae58ffcae | ||
|
|
226dd755f8 | ||
|
|
2e6814c4b0 | ||
|
|
d4319badce | ||
|
|
b034bf9ae6 | ||
|
|
c0e688ff35 | ||
|
|
bf9b001989 | ||
|
|
0e0c3da49a | ||
|
|
63d994808c | ||
|
|
e0d566a7e7 | ||
|
|
eaa22b4aa8 | ||
|
|
99c3ff60bb | ||
|
|
38cca77346 | ||
|
|
a0872b2314 | ||
|
|
8517c499e9 | ||
|
|
3f23f8b2a3 | ||
|
|
45ab468ce1 | ||
|
|
be458b547a | ||
|
|
050bbfb211 | ||
|
|
0a4d90d41f | ||
|
|
0e56578e11 | ||
|
|
7a2777cc00 | ||
|
|
fc6b98766c | ||
|
|
7d06861a6d | ||
|
|
851a84d301 | ||
|
|
91bc35fbfc | ||
|
|
76414e58d4 | ||
|
|
d6ad3e6a17 | ||
|
|
49d6f5cc14 | ||
|
|
610f61603d | ||
|
|
6b371a5ef9 | ||
|
|
7ee06c354e | ||
|
|
a60ad6aeed | ||
|
|
693d840202 | ||
|
|
7a759ea0b6 | ||
|
|
83a4b7371b | ||
|
|
82bb6d4ccf | ||
|
|
2de54a3dbc | ||
|
|
7eac676fa7 | ||
|
|
54199d21c3 | ||
|
|
2483dcc09c | ||
|
|
1154f3c585 | ||
|
|
232d9fe808 | ||
|
|
5693b7f3a1 | ||
|
|
d4e631f1b9 | ||
|
|
2252ac060e | ||
|
|
bb28195b74 | ||
|
|
2f426a031a | ||
|
|
761b14316f | ||
|
|
f3a05c30ae | ||
|
|
7514372e79 | ||
|
|
151a338956 | ||
|
|
d57293503d | ||
|
|
c4009760c7 | ||
|
|
3408997289 | ||
|
|
9ca2b31b7c | ||
|
|
5aa0a1a77a | ||
|
|
3825bf0b6d | ||
|
|
d15bcfb1ed | ||
|
|
ccb051caf7 | ||
|
|
3284aabd48 | ||
|
|
6d575f80fa | ||
|
|
b91dcfb314 | ||
|
|
321e66d0cc | ||
|
|
81eedb6efa | ||
|
|
b08dc0f7e6 | ||
|
|
11c1c255bf | ||
|
|
c89bab9730 | ||
|
|
5ffe634824 | ||
|
|
3ad9fb1473 | ||
|
|
b0298cca2e | ||
|
|
ed8ab7e9ad | ||
|
|
c75726f9ef | ||
|
|
ff7e22c675 | ||
|
|
946c11145c | ||
|
|
ffd2224bbe | ||
|
|
c326de860d | ||
|
|
145aa919ca | ||
|
|
2cc55fee5e | ||
|
|
119e8bec93 | ||
|
|
82f91b7efa | ||
|
|
900feef89f | ||
|
|
c58d39e71b | ||
|
|
48f190690e | ||
|
|
faa308c88c | ||
|
|
9619688706 | ||
|
|
a724aced43 | ||
|
|
9a9f7af971 | ||
|
|
0184ccd019 | ||
|
|
cdd8021509 | ||
|
|
1e31bfe287 | ||
|
|
7304af93ed | ||
|
|
69f6a44e81 | ||
|
|
354b32a9fc | ||
|
|
d5bb0e968f | ||
|
|
9e12e8c63f | ||
|
|
ebcd094222 | ||
|
|
5dd735f5b3 | ||
|
|
46841d7373 | ||
|
|
707f110c0f | ||
|
|
0e5d181cc9 | ||
|
|
f3a2c27840 | ||
|
|
0032a5247f | ||
|
|
ef38019122 | ||
|
|
e280ae11b8 | ||
|
|
14602f55d5 | ||
|
|
27b4335084 | ||
|
|
a1c1012cc4 | ||
|
|
821b88e420 | ||
|
|
d90934517d | ||
|
|
2f765ac897 | ||
|
|
d25be9cf75 | ||
|
|
1b8a25bb81 | ||
|
|
361e5b2c55 | ||
|
|
7912ea5950 | ||
|
|
5b34f9bcc9 | ||
|
|
766cfc1f4c | ||
|
|
3e999ca127 | ||
|
|
c8f80baeea | ||
|
|
d527192c49 | ||
|
|
6a93200099 | ||
|
|
2f31302b75 | ||
|
|
2cb7b6bbf3 | ||
|
|
ba00be3798 | ||
|
|
c55f806191 | ||
|
|
de9eb14d46 | ||
|
|
cf390c0efb | ||
|
|
2c9b4d1def | ||
|
|
104ec2ba12 | ||
|
|
78a2a2f18d | ||
|
|
4d620f0a11 | ||
|
|
d483a135f5 | ||
|
|
7990d9b81e | ||
|
|
2b28ed4fc6 | ||
|
|
51c5882f4c | ||
|
|
1aae1c11e3 | ||
|
|
00cfedbfd8 | ||
|
|
7e3ff0f7d2 | ||
|
|
47f005f730 | ||
|
|
4f3d6117cd | ||
|
|
119382b55e | ||
|
|
8cf0e8ed5c | ||
|
|
fce543d725 | ||
|
|
8fb7481298 | ||
|
|
9cdb5eda89 | ||
|
|
c0f307e49c | ||
|
|
e8df32f354 | ||
|
|
5c68870ad7 | ||
|
|
f3f1f6b712 | ||
|
|
4ecb96e8d7 | ||
|
|
5343ccf10b | ||
|
|
cbb9c4323c | ||
|
|
be9f302af6 | ||
|
|
180a4f34c2 | ||
|
|
b1bfc74ecb | ||
|
|
bc7d2378df | ||
|
|
e31d3b52ee | ||
|
|
277373a95a | ||
|
|
d9e9bf9b87 | ||
|
|
3396d08a3b | ||
|
|
c76872f3f9 | ||
|
|
c7175b295a | ||
|
|
2ff3a15326 | ||
|
|
a6806e9e1c | ||
|
|
200051ccc0 | ||
|
|
36726bd70f | ||
|
|
9755288527 | ||
|
|
39e380bb66 | ||
|
|
4bdf7674f9 | ||
|
|
cfe8c3efd8 | ||
|
|
46b420158c | ||
|
|
9010ee340c | ||
|
|
f1de4896d4 | ||
|
|
9bbd1074ea | ||
|
|
bb3c08f306 | ||
|
|
203c4a72b5 | ||
|
|
cf504fc1bf | ||
|
|
38c3e61a78 | ||
|
|
337e82a4c0 | ||
|
|
a482d4e288 | ||
|
|
c1cdc38e33 | ||
|
|
38865f46d2 | ||
|
|
e290438a6d | ||
|
|
355d395b00 | ||
|
|
9a5b041f74 | ||
|
|
5395810c45 | ||
|
|
a91054883f | ||
|
|
0459dc7d6f | ||
|
|
28c7b5f0ab | ||
|
|
b7018da0c1 | ||
|
|
bdd272192c | ||
|
|
d9faf76cb5 | ||
|
|
52db4693e8 | ||
|
|
b362a59173 | ||
|
|
e8e4b19348 | ||
|
|
e674061bab | ||
|
|
77b3d218a4 | ||
|
|
364dac53d4 | ||
|
|
29b9281af4 | ||
|
|
4d2815e56b | ||
|
|
302372f4b4 | ||
|
|
bbd72e5658 | ||
|
|
3db0a8ef73 | ||
|
|
1a2df2f309 | ||
|
|
d5c37c301a | ||
|
|
eabc5166ac | ||
|
|
88a5abca4b | ||
|
|
f6b6f9524e | ||
|
|
645b98d81a | ||
|
|
c605d1a044 | ||
|
|
df1d39d6ec | ||
|
|
5f08a4f8be | ||
|
|
cc9c84cad4 | ||
|
|
25e6eb9d04 | ||
|
|
b4bd96b2ca | ||
|
|
4ba51dbad8 | ||
|
|
5a8af35927 | ||
|
|
a4babe6699 | ||
|
|
c1ea592457 | ||
|
|
225264f06b | ||
|
|
30cc82d265 | ||
|
|
14c39620f0 | ||
|
|
b395a66246 | ||
|
|
04158b15bb | ||
|
|
8b5f26a9f0 | ||
|
|
c65e9079cc | ||
|
|
91a67e4867 | ||
|
|
4079787378 | ||
|
|
0dc9e32039 | ||
|
|
28c7b346db | ||
|
|
c4f993add1 | ||
|
|
bb21822c10 | ||
|
|
124bb2910f | ||
|
|
0f54df5867 | ||
|
|
2bd1a7ec1e | ||
|
|
ee97b0864a | ||
|
|
96e0dfcae9 | ||
|
|
379a7b707b | ||
|
|
3963ee6d1d | ||
|
|
64cd5bf3a5 | ||
|
|
05074bae0c | ||
|
|
174a39be8f | ||
|
|
918e3ce0b6 | ||
|
|
9c0eca1d8b | ||
|
|
26e0a7d922 | ||
|
|
a498e0c033 | ||
|
|
0f66918825 | ||
|
|
050b866b6a | ||
|
|
8115a899df | ||
|
|
3dcb7cfef9 | ||
|
|
502f24e50d | ||
|
|
6ebef9d876 | ||
|
|
60af6c2791 | ||
|
|
6d76da55e2 | ||
|
|
b31057ca16 | ||
|
|
16dfa56c77 | ||
|
|
a7ed504575 | ||
|
|
dc4c32972d | ||
|
|
d1d0efbd07 | ||
|
|
afa684ad45 | ||
|
|
f66d21e426 | ||
|
|
9a68ce87eb | ||
|
|
ecb737760c | ||
|
|
5d32cd0269 | ||
|
|
499efd5ee7 | ||
|
|
c4115ed783 | ||
|
|
969a97b54f | ||
|
|
5be0851434 | ||
|
|
233d346d5a | ||
|
|
a879981dfb | ||
|
|
3d90bd4e8e | ||
|
|
ba1dd09be2 | ||
|
|
80aa832ebd | ||
|
|
a950e1d040 | ||
|
|
4d7ddcd750 | ||
|
|
d6612d230b | ||
|
|
1d9abfdb10 | ||
|
|
871ba507a6 | ||
|
|
5d64df141b | ||
|
|
ae846204cb | ||
|
|
6dcf5c5c79 | ||
|
|
e55a9b35b6 | ||
|
|
ae85864959 | ||
|
|
5cc0539919 | ||
|
|
b070774f5c | ||
|
|
7a8548d48f | ||
|
|
ac172abda7 | ||
|
|
29e5195c63 | ||
|
|
3926d9d717 | ||
|
|
fd8b9450ee | ||
|
|
34ac68c4a8 | ||
|
|
f3e30c7ae3 | ||
|
|
0b85fb7ea2 | ||
|
|
58a6fe13d6 | ||
|
|
92b9525cfd | ||
|
|
1918e76913 | ||
|
|
ff9b23ebe5 | ||
|
|
c0f6a44e39 | ||
|
|
3828e2a53a | ||
|
|
be69192a61 | ||
|
|
8c1b5311fd | ||
|
|
6d4480ea6b | ||
|
|
1fe4b3fa28 | ||
|
|
f115376595 | ||
|
|
8122dd2c33 | ||
|
|
d2c0f9f754 | ||
|
|
03d499bf34 | ||
|
|
5e043812ef | ||
|
|
7764ca7209 | ||
|
|
ded316cd5e | ||
|
|
4b45a5fc6d | ||
|
|
078d518e36 | ||
|
|
212d858bf4 | ||
|
|
3faf2480e0 | ||
|
|
55d5b02f87 | ||
|
|
8fa33ba120 | ||
|
|
826f1cb90c | ||
|
|
ed5a865efb | ||
|
|
90b6d13714 | ||
|
|
85333a5974 | ||
|
|
5f941c5180 | ||
|
|
06a5ade3c6 | ||
|
|
374406375b | ||
|
|
4089620729 | ||
|
|
1de0152b6b | ||
|
|
94246d428b | ||
|
|
3b88dd6ef7 | ||
|
|
2cbf3080d0 | ||
|
|
d0621db8fd | ||
|
|
6f9ff39728 | ||
|
|
a64cf5514f | ||
|
|
93fbb6c092 | ||
|
|
600c3f2c2f | ||
|
|
deff96a1b0 | ||
|
|
b03daaebe4 | ||
|
|
4ddd337a64 | ||
|
|
a64a0fa88e | ||
|
|
c0cf065c1a | ||
|
|
96b2623887 | ||
|
|
e0d277e667 | ||
|
|
485bbd9ccb | ||
|
|
d228bdfb9e | ||
|
|
70887ae21a | ||
|
|
96f9611cf4 | ||
|
|
ef80cc3d56 | ||
|
|
0d9de7deaf | ||
|
|
96ca070c3a | ||
|
|
8948e27ced | ||
|
|
30e5e993c1 | ||
|
|
fd7b49b32b | ||
|
|
d36a6de25c | ||
|
|
d01db5a656 | ||
|
|
7d5cd2051a | ||
|
|
95ed3238be | ||
|
|
02e41b41b2 | ||
|
|
cd25ddeb06 | ||
|
|
7df531bc4e | ||
|
|
6cba2c50a2 | ||
|
|
dbc5f67dca | ||
|
|
7d71ad6f91 | ||
|
|
0e27f133d7 | ||
|
|
b965e54efc | ||
|
|
a9ac75c1f9 | ||
|
|
033efdcaa1 | ||
|
|
51961fccfa | ||
|
|
ac65f38842 | ||
|
|
0b0679e065 | ||
|
|
3ca87d205f | ||
|
|
dacf7f8bdc | ||
|
|
2cca0f9bb7 | ||
|
|
441c9ce376 | ||
|
|
902c239fdf | ||
|
|
9e6726f304 | ||
|
|
329d45562b | ||
|
|
83b44b735f | ||
|
|
3417c42bfd | ||
|
|
7f4064af16 | ||
|
|
ace11f9bc8 | ||
|
|
cd91440e47 | ||
|
|
5e5c71e1d7 | ||
|
|
7d4a1223fd | ||
|
|
98d0daa2fd | ||
|
|
f105c84349 | ||
|
|
720197f9c8 | ||
|
|
4d0b2ac9be | ||
|
|
1f2b02c18f | ||
|
|
32d98851bc | ||
|
|
82fc099602 | ||
|
|
34c1727cb3 | ||
|
|
23d44e322d | ||
|
|
8e2ab8b20b | ||
|
|
05755ba202 | ||
|
|
0881fd6397 | ||
|
|
52e257668d | ||
|
|
df62e78b71 | ||
|
|
dcb670fa46 | ||
|
|
134792a594 | ||
|
|
71f542d8f6 | ||
|
|
52fe92d02e | ||
|
|
92ddfd0d4c | ||
|
|
c81c9ee2b4 | ||
|
|
fc169221be | ||
|
|
c43a61c576 | ||
|
|
c4e4f085dd | ||
|
|
088f936dab | ||
|
|
e2b1394ad1 | ||
|
|
3cb9aadb80 | ||
|
|
ca218b6395 | ||
|
|
52852b963a | ||
|
|
d0ae89befa | ||
|
|
2acf9ac72f | ||
|
|
102d8fe506 | ||
|
|
2ee59cc82c | ||
|
|
03e16ffa57 | ||
|
|
782825fc29 | ||
|
|
0299328521 | ||
|
|
eb02a422de | ||
|
|
72af4941f8 | ||
|
|
744f737cba | ||
|
|
f72d5a4184 | ||
|
|
17d2467932 | ||
|
|
241baf77f1 | ||
|
|
b4299a2872 | ||
|
|
45baaeaf2c | ||
|
|
1fd7a4bfab | ||
|
|
826063a2f7 | ||
|
|
349a3c20ae | ||
|
|
6436a12d7f | ||
|
|
000be5d1d4 | ||
|
|
434f1368a0 | ||
|
|
668049a593 | ||
|
|
5c250455ad | ||
|
|
791d6de8b0 | ||
|
|
a3e5173c47 | ||
|
|
b71a5a5955 | ||
|
|
30c670bd83 | ||
|
|
596c0a8672 | ||
|
|
2ac677228d | ||
|
|
ff1c90b638 | ||
|
|
90f23c187f | ||
|
|
854443a291 | ||
|
|
9c7f6affc2 | ||
|
|
fade3eb679 | ||
|
|
cdf4bfa68f | ||
|
|
f8614ab019 | ||
|
|
6f117b8e0c | ||
|
|
dee964e0fe | ||
|
|
5957ede41a | ||
|
|
959c7a76e9 | ||
|
|
a0cdcc5f8d | ||
|
|
9cc3fbabf7 | ||
|
|
3db691d693 | ||
|
|
c1ca8476f8 | ||
|
|
21d1849723 | ||
|
|
50010934d1 | ||
|
|
849dd0db64 | ||
|
|
de0e4735de | ||
|
|
2117524102 | ||
|
|
876064036d | ||
|
|
b57046e67d | ||
|
|
03892153de | ||
|
|
439ba5116f | ||
|
|
5c378de22f | ||
|
|
3f1d22759a | ||
|
|
baaeb7cece | ||
|
|
eb8dc6b675 | ||
|
|
a5e63dc5fd | ||
|
|
5ae3d1a1b2 | ||
|
|
18ca4b6a3a | ||
|
|
51cfb5cff1 | ||
|
|
4ff7976060 | ||
|
|
90d314cc3b | ||
|
|
547097b036 | ||
|
|
df0381e76c | ||
|
|
ddc38eda26 | ||
|
|
9c783f53ba | ||
|
|
ed3e5739dc | ||
|
|
cc85946f55 | ||
|
|
03f876470e | ||
|
|
5cc4a30207 | ||
|
|
a58d989b60 | ||
|
|
dc93d94bc8 | ||
|
|
6c998aa4f2 | ||
|
|
1c7a47239b | ||
|
|
7fc8afa3e5 | ||
|
|
7ec4e7b0d8 | ||
|
|
41a3f123f1 | ||
|
|
f6081b18b6 | ||
|
|
7a6fe00f49 | ||
|
|
c64b4a3926 | ||
|
|
0431833866 | ||
|
|
280f9bf49c | ||
|
|
c7aa747891 | ||
|
|
8584c2f14b | ||
|
|
dbda1a1b05 | ||
|
|
897c6e93cb | ||
|
|
d6d245d0c3 | ||
|
|
0e6db8fd56 | ||
|
|
649633bbb7 | ||
|
|
4250f84272 | ||
|
|
f7528a0204 | ||
|
|
c65a0d90b8 | ||
|
|
1152fecb75 | ||
|
|
48abef27d8 | ||
|
|
624ade2c25 | ||
|
|
f3c64ea9d8 | ||
|
|
e383aa31c8 | ||
|
|
607b53c883 | ||
|
|
e044ada65c | ||
|
|
c74ae107f1 | ||
|
|
45a937df0a | ||
|
|
163361ee6a | ||
|
|
4b18a38e9f | ||
|
|
db2fda1b6f | ||
|
|
eb8fcf833c | ||
|
|
177091ca6f | ||
|
|
442c1b22e3 | ||
|
|
1b8c11121f | ||
|
|
2845267c18 | ||
|
|
764a10f7c7 | ||
|
|
ab2a061b59 | ||
|
|
d243a45173 | ||
|
|
3f15f51615 | ||
|
|
cfbea4a0e3 | ||
|
|
d561c5531b | ||
|
|
d5d1fa8290 | ||
|
|
46e7214974 | ||
|
|
cfb2812cea | ||
|
|
8d1d842185 | ||
|
|
c31629ad98 | ||
|
|
aa2b2f7c8f | ||
|
|
0a23c0b032 | ||
|
|
5bc86eaf9c | ||
|
|
ca7dec2082 | ||
|
|
fc4e10b6c0 | ||
|
|
e80e3a53e9 | ||
|
|
1f55f1635f | ||
|
|
77f73830e8 | ||
|
|
d3c58ea48c | ||
|
|
a1a431eb87 | ||
|
|
3ddd917ff4 | ||
|
|
a33eeda4f7 | ||
|
|
8ec3bc0272 | ||
|
|
982649bab7 | ||
|
|
a7ee737226 | ||
|
|
e842482ec8 | ||
|
|
f00b0a3485 | ||
|
|
fe943f560b | ||
|
|
975f85ea56 | ||
|
|
e734536815 | ||
|
|
3dfc0098ec | ||
|
|
06a501d4a2 | ||
|
|
e1336d8453 | ||
|
|
f8418554a3 | ||
|
|
65b7924528 | ||
|
|
5017db855c | ||
|
|
c6313b3d2d | ||
|
|
4eb0d497ab | ||
|
|
2ebea5501e | ||
|
|
2d68d60e00 | ||
|
|
6deb7afb82 | ||
|
|
8727636fcc | ||
|
|
00294a5b25 | ||
|
|
c491fa59df | ||
|
|
d97cf8c438 | ||
|
|
7a68d632e6 | ||
|
|
28cff4644e | ||
|
|
9d72bd4de4 | ||
|
|
c1b9ca14e7 | ||
|
|
32a957c455 | ||
|
|
85fdacbc49 | ||
|
|
f8f091c250 | ||
|
|
c51fef1568 | ||
|
|
1523a82bab | ||
|
|
92f50664d0 | ||
|
|
5798b152a6 | ||
|
|
b1e69e1357 | ||
|
|
9c36576ddd | ||
|
|
f7f09b028b | ||
|
|
089001bd92 | ||
|
|
97aa7b8e68 | ||
|
|
366ca47136 | ||
|
|
d21e30f57b | ||
|
|
d1da0aad7f | ||
|
|
321f87fe61 | ||
|
|
6743b83786 | ||
|
|
f464b8c4c5 | ||
|
|
25d0a7b62a | ||
|
|
b5b49c9ed0 | ||
|
|
ffeab383b5 | ||
|
|
0bd006a8eb | ||
|
|
0f9dd3736c | ||
|
|
6310d6c699 | ||
|
|
b2d53f1e1e | ||
|
|
4179cedf37 | ||
|
|
66349261a5 | ||
|
|
c1f32afeeb | ||
|
|
8f1fa4177e | ||
|
|
535d264497 | ||
|
|
2eedcde914 | ||
|
|
6b4b7c9831 | ||
|
|
b6aae790cf | ||
|
|
74d1685523 | ||
|
|
c9007557e5 | ||
|
|
c4cb90ab85 | ||
|
|
0adbcfd806 | ||
|
|
fd442df851 | ||
|
|
f927398b53 | ||
|
|
6414cb05f0 | ||
|
|
3b4e706758 | ||
|
|
559fd5cb31 | ||
|
|
1672cffe96 | ||
|
|
b8ec886609 | ||
|
|
728be219a4 | ||
|
|
2e91bf1e15 | ||
|
|
515525cfc6 | ||
|
|
83d951db7e | ||
|
|
8483cb4aa7 | ||
|
|
8cca1c987b | ||
|
|
78b88a70bb | ||
|
|
165d168ee5 | ||
|
|
753fb31c54 | ||
|
|
62eb077f29 | ||
|
|
cd8099d336 | ||
|
|
30109d64f2 | ||
|
|
ae266e2e03 | ||
|
|
c366525370 | ||
|
|
8f04def7b2 | ||
|
|
55808dffcd | ||
|
|
07f8f5f95a | ||
|
|
d7d4b8638d | ||
|
|
9890d1e251 | ||
|
|
f563fc9d5e | ||
|
|
41c2685204 | ||
|
|
73fbb69c50 | ||
|
|
5f9c857eb0 | ||
|
|
5d54d42953 | ||
|
|
81e00d8e56 | ||
|
|
455f0669e7 | ||
|
|
5bb35bbdaf | ||
|
|
d63a848011 | ||
|
|
aafbd865bf | ||
|
|
63874da087 | ||
|
|
d1f0d6c184 | ||
|
|
9ff7807be8 | ||
|
|
23de301955 | ||
|
|
0a5f8611e8 | ||
|
|
6f116eeaa4 | ||
|
|
0242818f39 | ||
|
|
3748ee49ea | ||
|
|
a8a881c8db | ||
|
|
fb52fdc592 | ||
|
|
bb7c63c052 | ||
|
|
9e8b26cc4e | ||
|
|
5db8197a5d | ||
|
|
0b0a17ff91 | ||
|
|
a68e3371f3 | ||
|
|
47bf8e1bb3 | ||
|
|
65099ab489 | ||
|
|
40619efb3b | ||
|
|
f02f9ba9fb | ||
|
|
de05ff894b | ||
|
|
57d2ae1aec | ||
|
|
46c2953edb | ||
|
|
f2d3d55e95 | ||
|
|
a59b53c7e6 | ||
|
|
08b56b7675 | ||
|
|
90795c4fa4 | ||
|
|
90d1c0b2b6 | ||
|
|
ec4212cce1 | ||
|
|
a45d5960d7 | ||
|
|
51cb36fa9b | ||
|
|
b97d7e7ecd | ||
|
|
e12c0dcf66 | ||
|
|
4f45b72381 | ||
|
|
81843f0dfb | ||
|
|
20116d7f05 | ||
|
|
0642be296d | ||
|
|
c8860d006b | ||
|
|
b53a858400 | ||
|
|
511dc9a80b | ||
|
|
7e1168c518 | ||
|
|
57356036db | ||
|
|
666a106fa8 | ||
|
|
414dcfcd07 | ||
|
|
787dbbe610 | ||
|
|
bc9a7806a5 | ||
|
|
565e4c5910 | ||
|
|
8f35198bfb | ||
|
|
c06f023313 | ||
|
|
0c46a7a4d9 | ||
|
|
b21dbdb20d | ||
|
|
c9d0960f47 | ||
|
|
a54dd1085a | ||
|
|
1cf28e8b75 | ||
|
|
9fd98bb27b | ||
|
|
025aa49f67 | ||
|
|
5994bf6745 | ||
|
|
9e2b7dbea5 | ||
|
|
edf063bae3 | ||
|
|
e7b2b93cee | ||
|
|
82322968a3 | ||
|
|
53642b2b17 | ||
|
|
fb9cf86836 | ||
|
|
faf6c5ad29 | ||
|
|
4649d1c73b | ||
|
|
703cb6deea | ||
|
|
9aed2a465f | ||
|
|
746beb0d8b | ||
|
|
6162d9090d | ||
|
|
11223cbc9b | ||
|
|
7e0e12b8a3 | ||
|
|
ca2d74e118 | ||
|
|
673004b878 | ||
|
|
2a8e8a0603 | ||
|
|
4e53019b75 | ||
|
|
833269ffde | ||
|
|
e9ba26f50e | ||
|
|
20a540e680 | ||
|
|
bf3edf8f87 | ||
|
|
10969b8c3c | ||
|
|
c52cf01a3c | ||
|
|
1672c95de3 | ||
|
|
649f04b7bc | ||
|
|
934a7fc118 | ||
|
|
3a3b197327 | ||
|
|
ece4c81c1a | ||
|
|
dcd2bf451d | ||
|
|
87565ec667 | ||
|
|
2e1c50c891 | ||
|
|
77f69cbe08 | ||
|
|
c60745b8a3 | ||
|
|
32ea2b67f0 | ||
|
|
9b05381acc | ||
|
|
a19d20cfb8 | ||
|
|
c422011d58 | ||
|
|
1f5e0c42f3 | ||
|
|
6e6ab9b907 | ||
|
|
7f73240fd5 | ||
|
|
932ffdc1e1 | ||
|
|
fe8965efa2 | ||
|
|
bdef033459 | ||
|
|
6ed70327f5 | ||
|
|
e9fab747ec | ||
|
|
feb31d088b | ||
|
|
a8f2646ba6 | ||
|
|
b2e1a93177 | ||
|
|
86064a7bd8 | ||
|
|
6d2a088be9 | ||
|
|
aa6f7a5d9f | ||
|
|
1d81d1a706 | ||
|
|
e345209f91 | ||
|
|
29964079ae | ||
|
|
94f853c654 | ||
|
|
bae652f46d | ||
|
|
59ee2859a7 | ||
|
|
2bd94293e0 | ||
|
|
c93973ab7a | ||
|
|
894ae1b3f5 | ||
|
|
00daff6ac8 | ||
|
|
f921df7ad1 | ||
|
|
bea4de9262 | ||
|
|
7a03e5f0b2 | ||
|
|
405edebc51 | ||
|
|
d56617e5d0 | ||
|
|
ec4a0e096f | ||
|
|
d21d83cfc8 | ||
|
|
1f3a89197c | ||
|
|
2f3a8ecd42 | ||
|
|
7a23980f4b | ||
|
|
9086b8067b | ||
|
|
3b6f0d83e1 | ||
|
|
6fa940f2c1 | ||
|
|
335e9f68b7 | ||
|
|
4185efa08f | ||
|
|
8ba271efba | ||
|
|
1d8ab03146 | ||
|
|
1f246229b1 | ||
|
|
9474fc0082 | ||
|
|
af339f44f4 | ||
|
|
d03527ae47 | ||
|
|
40874ddec6 | ||
|
|
465dee2c33 | ||
|
|
869e0ab14d | ||
|
|
260778e0fb | ||
|
|
43a8b6039e | ||
|
|
ca4b4709e5 | ||
|
|
809bd3757b | ||
|
|
fbbb704146 | ||
|
|
a4fefbe836 | ||
|
|
5e199152e2 | ||
|
|
13247e592b | ||
|
|
044e43397f | ||
|
|
cb9be091aa | ||
|
|
e8e7edf017 | ||
|
|
9262731f2c | ||
|
|
ba7ce7225b | ||
|
|
939ee94e67 | ||
|
|
f9f34fd628 | ||
|
|
6d844a0b67 | ||
|
|
6f3c46cc7e | ||
|
|
122017e6fa | ||
|
|
16dcc464cf | ||
|
|
94aa0762f0 | ||
|
|
b3f134de06 | ||
|
|
363712d057 | ||
|
|
8bc0c343fa | ||
|
|
37f2113032 | ||
|
|
10db2bce4e | ||
|
|
c0db0011ec | ||
|
|
4de502252b | ||
|
|
a0b9d47d5e | ||
|
|
51f3fb9bde | ||
|
|
7cab7b6c7e | ||
|
|
993c2413e8 | ||
|
|
a9ca152069 | ||
|
|
4bbb70de74 | ||
|
|
db37ab1039 | ||
|
|
dffe4fdd4f | ||
|
|
ac6d815c0e | ||
|
|
af9cbb4514 | ||
|
|
04b7f0d2d6 | ||
|
|
65fa9d2883 | ||
|
|
508551b81b | ||
|
|
a369a4172b | ||
|
|
4d085c4aae | ||
|
|
d43ef97a7b | ||
|
|
de1d24b616 | ||
|
|
0252d7686c | ||
|
|
2a4f5c3284 | ||
|
|
af0ac9b95c | ||
|
|
90d6b91bf7 | ||
|
|
30ccb6aea5 | ||
|
|
0c711f690e | ||
|
|
89bf71e580 | ||
|
|
70c49b78ae | ||
|
|
d3efc52745 | ||
|
|
72db5ed7cb | ||
|
|
8907053a9d | ||
|
|
05b7c2bf80 | ||
|
|
047cad1a4d | ||
|
|
a82bcc7e3c | ||
|
|
c806c465fa | ||
|
|
6fc2a2a051 | ||
|
|
e61b88fc2a | ||
|
|
47b12eee57 | ||
|
|
783ee3e315 | ||
|
|
9e7bbcd8f6 | ||
|
|
d1b2d1a10e | ||
|
|
5ef5d60f77 | ||
|
|
95696c9456 | ||
|
|
5788600c46 | ||
|
|
ba9a55c391 | ||
|
|
d46834265f | ||
|
|
99f5f17a8d | ||
|
|
6c3d29712f | ||
|
|
ce26687577 |
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
# These env vars are only necessary for creating Electron releases.
|
||||
# See docs/development/releasing.md
|
||||
|
||||
APPVEYOR_TOKEN=
|
||||
APPVEYOR_CLOUD_TOKEN=
|
||||
CIRCLE_TOKEN=
|
||||
ELECTRON_GITHUB_TOKEN=
|
||||
VSTS_TOKEN=
|
||||
33
.github/CODEOWNERS
vendored
33
.github/CODEOWNERS
vendored
@@ -3,19 +3,24 @@
|
||||
# https://help.github.com/articles/about-codeowners
|
||||
# https://git-scm.com/docs/gitignore
|
||||
|
||||
# Everything that falls through the cracks:
|
||||
* @electron/reviewers
|
||||
# Most stuff in here is owned by the Community & Safety WG...
|
||||
/.github/* @electron/wg-community
|
||||
|
||||
# filename patterns
|
||||
*browser_view* @electron/browserview
|
||||
*notification* @electron/notifications
|
||||
*pdf* @electron/printing
|
||||
*printing* @electron/printing
|
||||
*updater* @electron/updater
|
||||
# ...except the Admin WG maintains this file.
|
||||
/.github/CODEOWNERS @electron/wg-admin
|
||||
|
||||
# directories
|
||||
/.github/ @electron/electrocats
|
||||
/default_app/ @electron/docs
|
||||
/docs/ @electron/docs
|
||||
/docs-translations/ @electron/i18n
|
||||
/npm/ @electron/electrocats
|
||||
# Upgrades WG
|
||||
/patches/ @electron/wg-upgrades
|
||||
|
||||
# Releases WG
|
||||
/npm/ @electron/wg-releases
|
||||
/script/release-notes @electron/wg-releases
|
||||
/script/prepare-release.js @electron/wg-releases
|
||||
/script/bump-version.js @electron/wg-releases
|
||||
/script/ci-release-build.js @electron/wg-releases
|
||||
/script/release.js @electron/wg-releases
|
||||
/script/upload-to-github.js @electron/wg-releases
|
||||
/script/release-artifact-cleanup.js @electron/wg-releases
|
||||
/script/get-last-major-for-master.js @electron/wg-releases
|
||||
/script/find-release.js @electron/wg-releases
|
||||
/script/download-circleci-artifacts.js @electron/wg-releases
|
||||
10
.github/PULL_REQUEST_TEMPLATE.md
vendored
10
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,4 +1,4 @@
|
||||
##### Description of Change
|
||||
#### Description of Change
|
||||
<!--
|
||||
Thank you for your Pull Request. Please provide a description above and review
|
||||
the requirements below.
|
||||
@@ -6,7 +6,7 @@ the requirements below.
|
||||
Contributors guide: https://github.com/electron/electron/blob/master/CONTRIBUTING.md
|
||||
-->
|
||||
|
||||
##### Checklist
|
||||
#### Checklist
|
||||
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
|
||||
|
||||
- [ ] PR description included and stakeholders cc'd
|
||||
@@ -14,9 +14,9 @@ Contributors guide: https://github.com/electron/electron/blob/master/CONTRIBUTIN
|
||||
- [ ] tests are [changed or added](https://github.com/electron/electron/blob/master/docs/development/testing.md)
|
||||
- [ ] relevant documentation is changed or added
|
||||
- [ ] PR title follows semantic [commit guidelines](https://github.com/electron/electron/blob/master/docs/development/pull-requests.md#commit-message-guidelines)
|
||||
- [ ] [PR release notes](https://github.com/electron/clerk/blob/master/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/master/README.md#examples).
|
||||
|
||||
|
||||
##### Release Notes
|
||||
<!-- Used to describe release notes for future release versions. See https://github.com/electron/clerk/blob/master/README.md for details. -->
|
||||
#### Release Notes
|
||||
|
||||
Notes: <!-- One-line Change Summary Here-->
|
||||
Notes: <!-- Please add a one-line description for app developers to read in the release notes, or `no-notes` if no notes relevant to app developers. Examples and help on special cases: https://github.com/electron/clerk/blob/master/README.md#examples -->
|
||||
|
||||
4
.github/config.yml
vendored
4
.github/config.yml
vendored
@@ -36,13 +36,15 @@ newPRWelcomeComment: |
|
||||
firstPRMergeComment: >
|
||||
Congrats on merging your first pull request! 🎉🎉🎉
|
||||
|
||||
# Configuration for trop - https://github.com/codebytere/trop
|
||||
# Configuration for trop - https://github.com/electron/trop
|
||||
|
||||
watchedProject:
|
||||
name: Backports
|
||||
|
||||
# Users authorized to run manual trop backports
|
||||
authorizedUsers:
|
||||
- alexeykuzmin
|
||||
- BinaryMuse
|
||||
- ckerr
|
||||
- codebytere
|
||||
- deepak1556
|
||||
|
||||
10
.gitignore
vendored
10
.gitignore
vendored
@@ -16,13 +16,6 @@
|
||||
*.vcxproj.user
|
||||
*.xcodeproj
|
||||
/.idea/
|
||||
/brightray/brightray.opensdf
|
||||
/brightray/brightray.sdf
|
||||
/brightray/brightray.sln
|
||||
/brightray/brightray.suo
|
||||
/brightray/brightray.v12.suo
|
||||
/brightray/brightray.vcxproj*
|
||||
/brightray/brightray.xcodeproj/
|
||||
/dist/
|
||||
/external_binaries/
|
||||
/out/
|
||||
@@ -63,3 +56,6 @@ spec/.hash
|
||||
|
||||
# Eslint Cache
|
||||
.eslintcache
|
||||
|
||||
# Generated native addon files
|
||||
/spec/fixtures/native-addon/echo/build/
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
pool:
|
||||
vmImage: 'Ubuntu 16.04'
|
||||
|
||||
steps:
|
||||
- bash: |
|
||||
# "depot_tools" has to be checkout into "//third_party/depot_tools" so pylint.py can a "pylintrc" file.
|
||||
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git "${AGENT_BUILDDIRECTORY}/third_party/depot_tools"
|
||||
echo "##vso[task.setvariable variable=PATH]$PATH:${AGENT_BUILDDIRECTORY}/third_party/depot_tools"
|
||||
displayName: Setup Depot Tools
|
||||
|
||||
- bash: |
|
||||
chromium_revision="$(grep -A1 chromium_version DEPS | tr -d '\n' | cut -d\' -f4)"
|
||||
buildtools_revision="$(curl -sL "https://chromium.googlesource.com/chromium/src/+/${chromium_revision}/DEPS?format=TEXT" | base64 -d | grep buildtools_revision -A1 | tr -d '\n' | cut -d\' -f4)"
|
||||
|
||||
git clone https://chromium.googlesource.com/chromium/buildtools "${AGENT_TEMPDIRECTORY}/buildtools"
|
||||
(cd "${AGENT_TEMPDIRECTORY}/buildtools" && git checkout "$buildtools_revision")
|
||||
echo "##vso[task.setvariable variable=CHROMIUM_BUILDTOOLS_PATH]$AGENT_TEMPDIRECTORY/buildtools"
|
||||
|
||||
download_from_google_storage --bucket chromium-gn -s "${AGENT_TEMPDIRECTORY}/buildtools/linux64/gn.sha1"
|
||||
displayName: Download gn binary
|
||||
|
||||
- bash: |
|
||||
# gn.py tries to find a gclient root folder starting from the current dir.
|
||||
# When it fails and returns "None" path, the whole script fails. Let's "fix" it.
|
||||
touch .gclient
|
||||
# Another option would be to checkout "buildtools" inside the Electron checkout,
|
||||
# but then we would lint its contents (at least gn format), and it doesn't pass it.
|
||||
|
||||
npm install
|
||||
npm run lint
|
||||
displayName: Run Lint
|
||||
487
BUILD.gn
487
BUILD.gn
@@ -1,18 +1,20 @@
|
||||
import("build/asar.gni")
|
||||
import("build/npm.gni")
|
||||
import("buildflags/buildflags.gni")
|
||||
import("electron_paks.gni")
|
||||
import("filenames.gni")
|
||||
import("//build/config/locales.gni")
|
||||
import("//build/config/ui.gni")
|
||||
import("//build/config/win/manifest.gni")
|
||||
import("//pdf/features.gni")
|
||||
import("//services/service_manager/public/service_manifest.gni")
|
||||
import("//third_party/ffmpeg/ffmpeg_options.gni")
|
||||
import("//third_party/widevine/cdm/widevine.gni")
|
||||
import("//tools/generate_library_loader/generate_library_loader.gni")
|
||||
import("//tools/grit/grit_rule.gni")
|
||||
import("//tools/grit/repack.gni")
|
||||
import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
|
||||
import("//v8/snapshot_toolchain.gni")
|
||||
import("build/asar.gni")
|
||||
import("build/extract_symbols.gni")
|
||||
import("build/js_wrap.gni")
|
||||
import("build/npm.gni")
|
||||
import("buildflags/buildflags.gni")
|
||||
import("electron_paks.gni")
|
||||
import("filenames.gni")
|
||||
|
||||
if (is_mac) {
|
||||
import("//build/config/mac/rules.gni")
|
||||
@@ -26,6 +28,13 @@ if (is_linux) {
|
||||
pkg_config("gio_unix") {
|
||||
packages = [ "gio-unix-2.0" ]
|
||||
}
|
||||
|
||||
pkg_config("libnotify_config") {
|
||||
packages = [
|
||||
"glib-2.0",
|
||||
"gdk-pixbuf-2.0",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
branding = read_file("atom/app/BRANDING.json", "json")
|
||||
@@ -45,65 +54,82 @@ config("branding") {
|
||||
]
|
||||
}
|
||||
|
||||
npm_action("atom_browserify_sandbox") {
|
||||
deps = [
|
||||
":atom_js2c_copy",
|
||||
npm_action("atom_browserify_sandbox_unwrapped") {
|
||||
script = "browserify"
|
||||
|
||||
inputs = [
|
||||
# FIXME(zcbenz): The dependencies of these files are not listed here, so
|
||||
# the generated file will be out-dated when dependencies are modified.
|
||||
# Use a script to generate all dependencies and put them here.
|
||||
"lib/sandboxed_renderer/init.js",
|
||||
"lib/sandboxed_renderer/api/exports/electron.js",
|
||||
]
|
||||
|
||||
sandbox_args = [
|
||||
outputs = [
|
||||
"$target_gen_dir/js2c/preload_bundle_unwrapped.js",
|
||||
]
|
||||
|
||||
args = [
|
||||
"lib/sandboxed_renderer/init.js",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/electron.js:electron",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/fs.js:fs",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/os.js:os",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/path.js:path",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/child_process.js:child_process",
|
||||
"-t",
|
||||
"aliasify",
|
||||
"--standalone",
|
||||
"sandboxed_preload",
|
||||
"-o",
|
||||
rebase_path(outputs[0]),
|
||||
]
|
||||
|
||||
inputs = [
|
||||
"lib/sandboxed_renderer/init.js",
|
||||
"lib/sandboxed_renderer/api/exports/electron.js",
|
||||
"lib/sandboxed_renderer/api/exports/fs.js",
|
||||
"lib/sandboxed_renderer/api/exports/os.js",
|
||||
"lib/sandboxed_renderer/api/exports/path.js",
|
||||
"lib/sandboxed_renderer/api/exports/child_process.js",
|
||||
]
|
||||
outputs = [
|
||||
"$target_gen_dir/js2c/preload_bundle.js",
|
||||
]
|
||||
|
||||
script = "browserify"
|
||||
args = sandbox_args + [
|
||||
"-o",
|
||||
rebase_path(outputs[0]),
|
||||
]
|
||||
}
|
||||
|
||||
npm_action("atom_browserify_isolated") {
|
||||
deps = [
|
||||
":atom_js2c_copy",
|
||||
]
|
||||
npm_action("atom_browserify_isolated_unwrapped") {
|
||||
script = "browserify"
|
||||
|
||||
inputs = [
|
||||
"lib/isolated_renderer/init.js",
|
||||
]
|
||||
|
||||
outputs = [
|
||||
"$target_gen_dir/js2c/isolated_bundle_unwrapped.js",
|
||||
]
|
||||
|
||||
args = [
|
||||
"lib/isolated_renderer/init.js",
|
||||
"-t",
|
||||
"aliasify",
|
||||
"--standalone",
|
||||
"isolated_preload",
|
||||
"-o",
|
||||
rebase_path(outputs[0]),
|
||||
]
|
||||
}
|
||||
|
||||
js_wrap("atom_browserify_isolated") {
|
||||
deps = [
|
||||
":atom_browserify_isolated_unwrapped",
|
||||
]
|
||||
|
||||
inputs = [
|
||||
"$target_gen_dir/js2c/isolated_bundle_unwrapped.js",
|
||||
]
|
||||
|
||||
outputs = [
|
||||
"$target_gen_dir/js2c/isolated_bundle.js",
|
||||
]
|
||||
}
|
||||
|
||||
script = "browserify"
|
||||
args = inputs + [
|
||||
"-t",
|
||||
"aliasify",
|
||||
"-o",
|
||||
rebase_path(outputs[0]),
|
||||
]
|
||||
js_wrap("atom_browserify_sandbox") {
|
||||
deps = [
|
||||
":atom_browserify_sandbox_unwrapped",
|
||||
]
|
||||
|
||||
inputs = [
|
||||
"$target_gen_dir/js2c/preload_bundle_unwrapped.js",
|
||||
]
|
||||
|
||||
outputs = [
|
||||
"$target_gen_dir/js2c/preload_bundle.js",
|
||||
]
|
||||
}
|
||||
|
||||
copy("atom_js2c_copy") {
|
||||
@@ -123,23 +149,25 @@ action("atom_js2c") {
|
||||
":atom_js2c_copy",
|
||||
]
|
||||
|
||||
js2c_sources = filenames.js2c_sources
|
||||
|
||||
browserify_sources = [
|
||||
"$target_gen_dir/js2c/isolated_bundle.js",
|
||||
"$target_gen_dir/js2c/preload_bundle.js",
|
||||
]
|
||||
|
||||
inputs = js2c_sources + browserify_sources
|
||||
sources = browserify_sources + [
|
||||
"$target_gen_dir/js2c/asar.js",
|
||||
"$target_gen_dir/js2c/asar_init.js",
|
||||
]
|
||||
|
||||
inputs = sources
|
||||
outputs = [
|
||||
"$target_gen_dir/atom_natives.h",
|
||||
"$root_gen_dir/atom_natives.cc",
|
||||
]
|
||||
|
||||
script = "tools/js2c.py"
|
||||
args = [ rebase_path("//third_party/electron_node") ] +
|
||||
rebase_path(outputs, root_build_dir) +
|
||||
[ rebase_path("$target_gen_dir/js2c", root_build_dir) ]
|
||||
rebase_path(sources, root_build_dir)
|
||||
}
|
||||
|
||||
asar("js2asar") {
|
||||
@@ -156,6 +184,8 @@ asar("js2asar") {
|
||||
"lib/browser/api/views/button.js",
|
||||
"lib/browser/api/views/label-button.js",
|
||||
"lib/browser/api/views/layout-manager.js",
|
||||
"lib/browser/api/views/md-text-button.js",
|
||||
"lib/browser/api/views/resize-area.js",
|
||||
"lib/browser/api/views/text-field.js",
|
||||
]
|
||||
}
|
||||
@@ -181,18 +211,53 @@ grit("resources") {
|
||||
"electron_resources.pak",
|
||||
]
|
||||
|
||||
# Mojo manifest overlays are generated.
|
||||
source_is_generated = true
|
||||
grit_flags = [
|
||||
"-E",
|
||||
"target_gen_dir=" + rebase_path(target_gen_dir, root_build_dir),
|
||||
]
|
||||
|
||||
deps = [
|
||||
":electron_content_manifest_overlays",
|
||||
":copy_shell_devtools_discovery_page",
|
||||
]
|
||||
|
||||
output_dir = "$target_gen_dir"
|
||||
}
|
||||
|
||||
copy("copy_shell_devtools_discovery_page") {
|
||||
sources = [
|
||||
"//content/shell/resources/shell_devtools_discovery_page.html",
|
||||
]
|
||||
outputs = [
|
||||
"$target_gen_dir/shell_devtools_discovery_page.html",
|
||||
]
|
||||
}
|
||||
|
||||
if (is_linux) {
|
||||
generate_library_loader("libnotify_loader") {
|
||||
name = "LibNotifyLoader"
|
||||
output_h = "libnotify_loader.h"
|
||||
output_cc = "libnotify_loader.cc"
|
||||
header = "<libnotify/notify.h>"
|
||||
config = ":libnotify_config"
|
||||
|
||||
functions = [
|
||||
"notify_is_initted",
|
||||
"notify_init",
|
||||
"notify_get_server_caps",
|
||||
"notify_get_server_info",
|
||||
"notify_notification_new",
|
||||
"notify_notification_add_action",
|
||||
"notify_notification_set_image_from_pixbuf",
|
||||
"notify_notification_set_timeout",
|
||||
"notify_notification_set_hint_string",
|
||||
"notify_notification_show",
|
||||
"notify_notification_close",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
static_library("electron_lib") {
|
||||
configs += [ "//v8:external_startup_data" ]
|
||||
configs += [ "//third_party/electron_node:node_internals" ]
|
||||
@@ -201,29 +266,39 @@ static_library("electron_lib") {
|
||||
|
||||
deps = [
|
||||
":atom_js2c",
|
||||
"brightray",
|
||||
"buildflags",
|
||||
"chromium_src:chrome",
|
||||
"manifests",
|
||||
"native_mate",
|
||||
"//base",
|
||||
"//base:base_static",
|
||||
"//base:i18n",
|
||||
"//chrome/app/resources:platform_locale_settings",
|
||||
"//components/certificate_transparency",
|
||||
"//components/net_log",
|
||||
"//components/network_session_configurator/common",
|
||||
"//components/prefs",
|
||||
"//components/printing/common",
|
||||
"//components/spellcheck/renderer",
|
||||
"//components/viz/host",
|
||||
"//components/viz/service",
|
||||
"//content/public/app:both",
|
||||
"//content/public/browser",
|
||||
"//content/public/child",
|
||||
"//content/public/common:service_names",
|
||||
"//gin",
|
||||
"//media/capture/mojom:video_capture",
|
||||
"//media/mojo/interfaces",
|
||||
"//net:extras",
|
||||
"//net:net_resources",
|
||||
"//net:net_with_v8",
|
||||
"//ppapi/host",
|
||||
"//ppapi/proxy",
|
||||
"//ppapi/shared_impl",
|
||||
"//printing",
|
||||
"//services/audio/public/mojom:constants",
|
||||
"//services/device/public/mojom",
|
||||
"//services/proxy_resolver:lib",
|
||||
"//services/video_capture/public/mojom:constants",
|
||||
"//services/viz/privileged/interfaces/compositing",
|
||||
"//skia",
|
||||
"//third_party/blink/public:blink",
|
||||
"//third_party/boringssl",
|
||||
@@ -238,12 +313,6 @@ static_library("electron_lib") {
|
||||
"//v8",
|
||||
]
|
||||
|
||||
# TODO: this requires a visibility patch to chromium src. it would be better
|
||||
# to use the publicly-available API, which I think is mojo-based. Once
|
||||
# electron switches to using the public API, we can remove this from the deps
|
||||
# list and remove the visibility patch from chromium.
|
||||
deps += [ "//services/device/wake_lock/power_save_blocker" ]
|
||||
|
||||
include_dirs = [
|
||||
"chromium_src",
|
||||
".",
|
||||
@@ -254,9 +323,13 @@ static_library("electron_lib") {
|
||||
"//third_party/blink/renderer",
|
||||
]
|
||||
|
||||
defines = []
|
||||
defines = [ "V8_DEPRECATION_WARNINGS" ]
|
||||
libs = []
|
||||
|
||||
if (is_linux) {
|
||||
defines += [ "GDK_DISABLE_DEPRECATION_WARNINGS" ]
|
||||
}
|
||||
|
||||
extra_source_filters = []
|
||||
if (!is_linux) {
|
||||
extra_source_filters += [
|
||||
@@ -285,8 +358,6 @@ static_library("electron_lib") {
|
||||
"*_views.cc",
|
||||
"*_views.h",
|
||||
"*\bviews/*",
|
||||
"*/autofill_popup.cc",
|
||||
"*/autofill_popup.h",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -295,16 +366,6 @@ static_library("electron_lib") {
|
||||
sources = filenames.lib_sources
|
||||
set_sources_assignment_filter(sources_assignment_filter)
|
||||
|
||||
sources += [
|
||||
"$target_gen_dir/atom_natives.h",
|
||||
"//extensions/browser/app_window/size_constraints.cc",
|
||||
"//extensions/browser/app_window/size_constraints.h",
|
||||
"//extensions/common/constants.cc",
|
||||
"//extensions/common/constants.h",
|
||||
"//extensions/common/url_pattern.cc",
|
||||
"//extensions/common/url_pattern.h",
|
||||
]
|
||||
|
||||
if (is_component_build) {
|
||||
defines += [ "NODE_SHARED_MODE" ]
|
||||
}
|
||||
@@ -321,6 +382,10 @@ static_library("electron_lib") {
|
||||
"//third_party/crashpad/crashpad/client",
|
||||
"//ui/accelerated_widget_mac",
|
||||
]
|
||||
sources += [
|
||||
"atom/browser/ui/views/autofill_popup_view.cc",
|
||||
"atom/browser/ui/views/autofill_popup_view.h",
|
||||
]
|
||||
include_dirs += [
|
||||
# NOTE(nornagon): other chromium files use the full path to include
|
||||
# crashpad; this is just here for compatibility between GN and GYP, so that
|
||||
@@ -353,8 +418,10 @@ static_library("electron_lib") {
|
||||
}
|
||||
if (is_linux) {
|
||||
deps += [
|
||||
":libnotify_loader",
|
||||
"//build/config/linux/gtk",
|
||||
"//chrome/browser/ui/libgtkui",
|
||||
"//dbus",
|
||||
"//device/bluetooth",
|
||||
"//ui/events/devices/x11",
|
||||
"//ui/events/platform/x11",
|
||||
@@ -367,10 +434,10 @@ static_library("electron_lib") {
|
||||
# Disable warnings for g_settings_list_schemas.
|
||||
"GLIB_DISABLE_DEPRECATION_WARNINGS",
|
||||
]
|
||||
|
||||
sources += filenames.lib_sources_nss
|
||||
}
|
||||
if (is_win) {
|
||||
sources += filenames.lib_sources_win
|
||||
libs += [ "dwmapi.lib" ]
|
||||
}
|
||||
if (is_linux || is_win) {
|
||||
@@ -391,12 +458,13 @@ static_library("electron_lib") {
|
||||
|
||||
if (enable_osr) {
|
||||
sources += [
|
||||
"atom/browser/api/atom_api_web_contents_osr.cc",
|
||||
"atom/browser/osr/osr_output_device.cc",
|
||||
"atom/browser/osr/osr_output_device.h",
|
||||
"atom/browser/osr/osr_host_display_client.cc",
|
||||
"atom/browser/osr/osr_host_display_client.h",
|
||||
"atom/browser/osr/osr_host_display_client_mac.mm",
|
||||
"atom/browser/osr/osr_render_widget_host_view.cc",
|
||||
"atom/browser/osr/osr_render_widget_host_view.h",
|
||||
"atom/browser/osr/osr_render_widget_host_view_mac.mm",
|
||||
"atom/browser/osr/osr_video_consumer.cc",
|
||||
"atom/browser/osr/osr_video_consumer.h",
|
||||
"atom/browser/osr/osr_view_proxy.cc",
|
||||
"atom/browser/osr/osr_view_proxy.h",
|
||||
"atom/browser/osr/osr_web_contents_view.cc",
|
||||
@@ -432,23 +500,26 @@ static_library("electron_lib") {
|
||||
"atom/browser/api/views/atom_api_label_button.h",
|
||||
"atom/browser/api/views/atom_api_layout_manager.cc",
|
||||
"atom/browser/api/views/atom_api_layout_manager.h",
|
||||
"atom/browser/api/views/atom_api_md_text_button.cc",
|
||||
"atom/browser/api/views/atom_api_md_text_button.h",
|
||||
"atom/browser/api/views/atom_api_resize_area.cc",
|
||||
"atom/browser/api/views/atom_api_resize_area.h",
|
||||
"atom/browser/api/views/atom_api_text_field.cc",
|
||||
"atom/browser/api/views/atom_api_text_field.h",
|
||||
]
|
||||
}
|
||||
|
||||
if (enable_pepper_flash) {
|
||||
deps += [ "components/pepper_flash" ]
|
||||
if (enable_basic_printing) {
|
||||
sources += [
|
||||
"atom/browser/printing/print_preview_message_handler.cc",
|
||||
"atom/browser/printing/print_preview_message_handler.h",
|
||||
"atom/renderer/printing/print_render_frame_helper_delegate.cc",
|
||||
"atom/renderer/printing/print_render_frame_helper_delegate.h",
|
||||
]
|
||||
}
|
||||
|
||||
if (enable_widevine) {
|
||||
sources += [
|
||||
"//chrome/renderer/media/chrome_key_systems.cc",
|
||||
"//chrome/renderer/media/chrome_key_systems.h",
|
||||
"//chrome/renderer/media/chrome_key_systems_provider.cc",
|
||||
"//chrome/renderer/media/chrome_key_systems_provider.h",
|
||||
]
|
||||
deps += [ "//components/cdm/renderer" ]
|
||||
if (enable_pepper_flash) {
|
||||
deps += [ "components/pepper_flash" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,6 +537,7 @@ if (is_mac) {
|
||||
electron_helper_name = "$electron_product_name Helper"
|
||||
electron_login_helper_name = "$electron_product_name Login Helper"
|
||||
electron_framework_version = "A"
|
||||
electron_version = read_file("ELECTRON_VERSION", "trim string")
|
||||
|
||||
mac_xib_bundle_data("electron_xibs") {
|
||||
sources = [
|
||||
@@ -548,7 +620,6 @@ if (is_mac) {
|
||||
}
|
||||
info_plist = "atom/common/resources/mac/Info.plist"
|
||||
|
||||
electron_version = read_file("VERSION", "trim string")
|
||||
extra_substitutions = [
|
||||
"ATOM_BUNDLE_ID=$electron_mac_bundle_id.framework",
|
||||
"ELECTRON_VERSION=$electron_version",
|
||||
@@ -558,6 +629,7 @@ if (is_mac) {
|
||||
sources = filenames.framework_sources
|
||||
|
||||
libs = [
|
||||
"AVFoundation.framework",
|
||||
"Carbon.framework",
|
||||
"QuartzCore.framework",
|
||||
"Quartz.framework",
|
||||
@@ -566,6 +638,11 @@ if (is_mac) {
|
||||
"ServiceManagement.framework",
|
||||
"StoreKit.framework",
|
||||
]
|
||||
|
||||
if (enable_osr) {
|
||||
libs += [ "IOSurface.framework" ]
|
||||
}
|
||||
|
||||
ldflags = [
|
||||
"-F",
|
||||
rebase_path("external_binaries", root_build_dir),
|
||||
@@ -586,6 +663,10 @@ if (is_mac) {
|
||||
deps = [
|
||||
":electron_framework+link",
|
||||
]
|
||||
if (!is_mas_build) {
|
||||
deps += [ "//sandbox/mac:seatbelt" ]
|
||||
}
|
||||
defines = [ "HELPER_EXECUTABLE" ]
|
||||
sources = filenames.app_sources
|
||||
include_dirs = [ "." ]
|
||||
info_plist = "atom/renderer/resources/mac/Info.plist"
|
||||
@@ -594,6 +675,12 @@ if (is_mac) {
|
||||
"-rpath",
|
||||
"@executable_path/../../..",
|
||||
]
|
||||
if (is_component_build) {
|
||||
ldflags += [
|
||||
"-rpath",
|
||||
"@executable_path/../../../../../..",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
bundle_data("electron_app_framework_bundle_data") {
|
||||
@@ -635,13 +722,44 @@ if (is_mac) {
|
||||
"$root_out_dir/$electron_login_helper_name.app",
|
||||
]
|
||||
outputs = [
|
||||
"{{bundle_contents_dir}}/Library/LoginItems",
|
||||
"{{bundle_contents_dir}}/Library/LoginItems/{{source_file_part}}",
|
||||
]
|
||||
}
|
||||
|
||||
action("electron_app_lproj_dirs") {
|
||||
outputs = []
|
||||
|
||||
foreach(locale, locales_as_mac_outputs) {
|
||||
outputs += [ "$target_gen_dir/app_infoplist_strings/$locale.lproj" ]
|
||||
}
|
||||
script = "build/mac/make_locale_dirs.py"
|
||||
args = rebase_path(outputs)
|
||||
}
|
||||
|
||||
foreach(locale, locales_as_mac_outputs) {
|
||||
bundle_data("electron_app_strings_${locale}_bundle_data") {
|
||||
sources = [
|
||||
"$target_gen_dir/app_infoplist_strings/$locale.lproj",
|
||||
]
|
||||
outputs = [
|
||||
"{{bundle_resources_dir}}/$locale.lproj",
|
||||
]
|
||||
public_deps = [
|
||||
":electron_app_lproj_dirs",
|
||||
]
|
||||
}
|
||||
}
|
||||
group("electron_app_strings_bundle_data") {
|
||||
public_deps = []
|
||||
foreach(locale, locales_as_mac_outputs) {
|
||||
public_deps += [ ":electron_app_strings_${locale}_bundle_data" ]
|
||||
}
|
||||
}
|
||||
|
||||
bundle_data("electron_app_resources") {
|
||||
public_deps = [
|
||||
":app2asar",
|
||||
":electron_app_strings_bundle_data",
|
||||
":js2asar",
|
||||
]
|
||||
sources = [
|
||||
@@ -672,6 +790,56 @@ if (is_mac) {
|
||||
"@executable_path/../Frameworks",
|
||||
]
|
||||
}
|
||||
|
||||
if (enable_dsyms) {
|
||||
extract_symbols("electron_framework_syms") {
|
||||
binary = "$root_out_dir/$electron_framework_name.framework/Versions/$electron_framework_version/$electron_framework_name"
|
||||
symbol_dir = "$root_out_dir/breakpad_symbols"
|
||||
dsym_file = "$root_out_dir/$electron_framework_name.dSYM/Contents/Resources/DWARF/$electron_framework_name"
|
||||
deps = [
|
||||
":electron_framework",
|
||||
]
|
||||
}
|
||||
|
||||
extract_symbols("electron_helper_syms") {
|
||||
binary = "$root_out_dir/$electron_helper_name.app/Contents/MacOS/$electron_helper_name"
|
||||
symbol_dir = "$root_out_dir/breakpad_symbols"
|
||||
dsym_file = "$root_out_dir/$electron_helper_name.dSYM/Contents/Resources/DWARF/$electron_helper_name"
|
||||
deps = [
|
||||
":electron_helper_app",
|
||||
]
|
||||
}
|
||||
|
||||
extract_symbols("electron_app_syms") {
|
||||
binary = "$root_out_dir/$electron_product_name.app/Contents/MacOS/$electron_product_name"
|
||||
symbol_dir = "$root_out_dir/breakpad_symbols"
|
||||
dsym_file = "$root_out_dir/$electron_product_name.dSYM/Contents/Resources/DWARF/$electron_product_name"
|
||||
deps = [
|
||||
":electron_app",
|
||||
]
|
||||
}
|
||||
|
||||
extract_symbols("crashpad_handler_syms") {
|
||||
binary = "$root_out_dir/crashpad_handler"
|
||||
symbol_dir = "$root_out_dir/breakpad_symbols"
|
||||
dsym_file = "$root_out_dir/crashpad_handler.dSYM/Contents/Resources/DWARF/crashpad_handler"
|
||||
deps = [
|
||||
"//third_party/crashpad/crashpad/handler:crashpad_handler",
|
||||
]
|
||||
}
|
||||
|
||||
group("electron_symbols") {
|
||||
deps = [
|
||||
":crashpad_handler_syms",
|
||||
":electron_app_syms",
|
||||
":electron_framework_syms",
|
||||
":electron_helper_syms",
|
||||
]
|
||||
}
|
||||
} else {
|
||||
group("electron_symbols") {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
windows_manifest("electron_app_manifest") {
|
||||
sources = [
|
||||
@@ -750,6 +918,16 @@ if (is_mac) {
|
||||
"/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll",
|
||||
"/DELAYLOAD:api-ms-win-core-winrt-string-l1-1-0.dll",
|
||||
]
|
||||
|
||||
# This is to support renaming of electron.exe. node-gyp has hard-coded
|
||||
# executable names which it will recognise as node. This module definition
|
||||
# file claims that the electron executable is in fact named "node.exe",
|
||||
# which is one of the executable names that node-gyp recognizes.
|
||||
# See https://github.com/nodejs/node-gyp/commit/52ceec3a6d15de3a8f385f43dbe5ecf5456ad07a
|
||||
ldflags += [ "/DEF:" + rebase_path("build/electron.def", root_build_dir) ]
|
||||
inputs = [
|
||||
"build/electron.def",
|
||||
]
|
||||
}
|
||||
if (is_linux) {
|
||||
ldflags = [ "-pie" ]
|
||||
@@ -759,74 +937,55 @@ if (is_mac) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group("electron_tests") {
|
||||
testonly = true
|
||||
if (is_official_build) {
|
||||
if (is_linux) {
|
||||
_target_executable_suffix = ""
|
||||
_target_shared_library_suffix = ".so"
|
||||
} else if (is_win) {
|
||||
_target_executable_suffix = ".exe"
|
||||
_target_shared_library_suffix = ".dll"
|
||||
}
|
||||
|
||||
deps = [
|
||||
":chromium_browsertests",
|
||||
":chromium_unittests",
|
||||
]
|
||||
}
|
||||
extract_symbols("electron_app_symbols") {
|
||||
binary = "$root_out_dir/$electron_project_name$_target_executable_suffix"
|
||||
symbol_dir = "$root_out_dir/breakpad_symbols"
|
||||
deps = [
|
||||
":electron_app",
|
||||
]
|
||||
}
|
||||
|
||||
group("chromium_unittests") {
|
||||
testonly = true
|
||||
extract_symbols("swiftshader_egl_symbols") {
|
||||
binary = "$root_out_dir/swiftshader/libEGL$_target_shared_library_suffix"
|
||||
symbol_dir = "$root_out_dir/breakpad_symbols"
|
||||
deps = [
|
||||
"//third_party/swiftshader/src/OpenGL/libEGL:swiftshader_libEGL",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//base:base_unittests",
|
||||
"//cc:cc_unittests",
|
||||
"//content/test:content_unittests",
|
||||
"//crypto:crypto_unittests",
|
||||
"//device:device_unittests",
|
||||
"//gin:gin_unittests",
|
||||
"//gpu:gpu_unittests",
|
||||
"//ipc:ipc_tests",
|
||||
"//media:media_unittests",
|
||||
"//media/capture:capture_unittests",
|
||||
"//media/midi:midi_unittests",
|
||||
"//media/mojo:media_mojo_unittests",
|
||||
"//mojo:mojo_unittests",
|
||||
"//net:net_unittests",
|
||||
"//ppapi:ppapi_unittests",
|
||||
"//printing:printing_unittests",
|
||||
"//skia:skia_unittests",
|
||||
"//sql:sql_unittests",
|
||||
"//storage:storage_unittests",
|
||||
"//third_party/angle/src/tests:angle_unittests",
|
||||
"//third_party/blink/public:all_blink",
|
||||
"//third_party/blink/public:test_support",
|
||||
"//third_party/leveldatabase:env_chromium_unittests",
|
||||
"//ui/base:ui_base_unittests",
|
||||
"//ui/compositor:compositor_unittests",
|
||||
"//ui/display:display_unittests",
|
||||
"//ui/events:events_unittests",
|
||||
"//ui/gl:gl_unittests",
|
||||
"//url:url_unittests",
|
||||
"//url/ipc:url_ipc_unittests",
|
||||
"//v8/test/unittests:unittests",
|
||||
]
|
||||
extract_symbols("swiftshader_gles_symbols") {
|
||||
binary =
|
||||
"$root_out_dir/swiftshader/libGLESv2$_target_shared_library_suffix"
|
||||
symbol_dir = "$root_out_dir/breakpad_symbols"
|
||||
deps = [
|
||||
"//third_party/swiftshader/src/OpenGL/libGLESv2:swiftshader_libGLESv2",
|
||||
]
|
||||
}
|
||||
|
||||
if (is_linux) {
|
||||
deps += [
|
||||
"//net:disk_cache_memory_test",
|
||||
"//sandbox/linux:sandbox_linux_unittests",
|
||||
]
|
||||
|
||||
if (use_dbus) {
|
||||
deps += [ "//dbus:dbus_unittests" ]
|
||||
group("electron_symbols") {
|
||||
deps = [
|
||||
":electron_app_symbols",
|
||||
]
|
||||
if (target_cpu == "x86" || target_cpu == "x64") {
|
||||
deps += [
|
||||
":swiftshader_egl_symbols",
|
||||
":swiftshader_gles_symbols",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group("chromium_browsertests") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"//content/test:content_browsertests",
|
||||
]
|
||||
}
|
||||
|
||||
template("dist_zip") {
|
||||
_runtime_deps_target = "${target_name}__deps"
|
||||
_runtime_deps_file =
|
||||
@@ -885,7 +1044,7 @@ group("licenses") {
|
||||
|
||||
copy("electron_version") {
|
||||
sources = [
|
||||
"VERSION",
|
||||
"ELECTRON_VERSION",
|
||||
]
|
||||
outputs = [
|
||||
"$root_build_dir/version",
|
||||
@@ -898,6 +1057,9 @@ dist_zip("electron_dist_zip") {
|
||||
":licenses",
|
||||
":electron_version",
|
||||
]
|
||||
if (is_linux) {
|
||||
data_deps += [ "//sandbox/linux:chrome_sandbox" ]
|
||||
}
|
||||
outputs = [
|
||||
"$root_build_dir/dist.zip",
|
||||
]
|
||||
@@ -925,6 +1087,7 @@ dist_zip("electron_chromedriver_zip") {
|
||||
dist_zip("electron_mksnapshot_zip") {
|
||||
data_deps = [
|
||||
"//v8:mksnapshot($v8_snapshot_toolchain)",
|
||||
"//tools/v8_context_snapshot:v8_context_snapshot_generator",
|
||||
":licenses",
|
||||
]
|
||||
outputs = [
|
||||
@@ -933,23 +1096,7 @@ dist_zip("electron_mksnapshot_zip") {
|
||||
}
|
||||
|
||||
group("electron") {
|
||||
deps = [
|
||||
public_deps = [
|
||||
":electron_app",
|
||||
]
|
||||
}
|
||||
|
||||
group("electron_content_manifest_overlays") {
|
||||
deps = [
|
||||
":electron_content_browser_manifest_overlay",
|
||||
":electron_content_packaged_services_manifest_overlay",
|
||||
]
|
||||
}
|
||||
|
||||
service_manifest("electron_content_packaged_services_manifest_overlay") {
|
||||
source = "//electron/manifests/electron_content_packaged_services_manifest_overlay.json"
|
||||
packaged_services = [ "//services/proxy_resolver:proxy_resolver_manifest" ]
|
||||
}
|
||||
|
||||
service_manifest("electron_content_browser_manifest_overlay") {
|
||||
source = "//electron/manifests/electron_content_browser_manifest_overlay.json"
|
||||
}
|
||||
|
||||
41
DEPS
41
DEPS
@@ -10,9 +10,9 @@ gclient_gn_args = [
|
||||
|
||||
vars = {
|
||||
'chromium_version':
|
||||
'69.0.3497.106',
|
||||
'73.0.3683.121',
|
||||
'node_version':
|
||||
'5654c276d0497ff9a0bb0d7550b9073b2e2e7d3f',
|
||||
'666c67e078bddc32f25409f4a929c1e9b5f47373',
|
||||
|
||||
'boto_version': 'f7574aa6cc2c819430c1f05e9a1a1a666ef8169b',
|
||||
'pyyaml_version': '3.12',
|
||||
@@ -21,12 +21,23 @@ vars = {
|
||||
'boto_git': 'https://github.com/boto',
|
||||
'chromium_git': 'https://chromium.googlesource.com',
|
||||
'electron_git': 'https://github.com/electron',
|
||||
'nodejs_git': 'https://github.com/nodejs',
|
||||
'requests_git': 'https://github.com/kennethreitz',
|
||||
'yaml_git': 'https://github.com/yaml',
|
||||
|
||||
# To be able to build clean Chromium from sources.
|
||||
'apply_patches': True,
|
||||
|
||||
# Python interface to Amazon Web Services. Is used for releases only.
|
||||
'checkout_boto': False,
|
||||
|
||||
# To allow in-house builds to checkout those manually.
|
||||
'checkout_chromium': True,
|
||||
'checkout_node': True,
|
||||
|
||||
# It's only needed to parse the native tests configurations.
|
||||
'checkout_pyyaml': False,
|
||||
|
||||
# Python "requests" module is used for releases only.
|
||||
'checkout_requests': False,
|
||||
|
||||
@@ -49,12 +60,18 @@ vars = {
|
||||
}
|
||||
|
||||
deps = {
|
||||
'src':
|
||||
(Var("chromium_git")) + '/chromium/src.git@' + (Var("chromium_version")),
|
||||
'src/third_party/electron_node':
|
||||
(Var("electron_git")) + '/node.git@' + (Var("node_version")),
|
||||
'src/electron/vendor/pyyaml':
|
||||
(Var("yaml_git")) + '/pyyaml.git@' + (Var("pyyaml_version")),
|
||||
'src': {
|
||||
'url': (Var("chromium_git")) + '/chromium/src.git@' + (Var("chromium_version")),
|
||||
'condition': 'checkout_chromium',
|
||||
},
|
||||
'src/third_party/electron_node': {
|
||||
'url': (Var("nodejs_git")) + '/node.git@' + (Var("node_version")),
|
||||
'condition': 'checkout_node',
|
||||
},
|
||||
'src/electron/vendor/pyyaml': {
|
||||
'url': (Var("yaml_git")) + '/pyyaml.git@' + (Var("pyyaml_version")),
|
||||
'condition': 'checkout_pyyaml',
|
||||
},
|
||||
'src/electron/vendor/boto': {
|
||||
'url': Var('boto_git') + '/boto.git' + '@' + Var('boto_version'),
|
||||
'condition': 'checkout_boto',
|
||||
@@ -68,12 +85,12 @@ deps = {
|
||||
hooks = [
|
||||
{
|
||||
'name': 'patch_chromium',
|
||||
'condition': 'checkout_chromium and apply_patches',
|
||||
'pattern': 'src/electron',
|
||||
'action': [
|
||||
'python',
|
||||
'src/electron/script/apply-patches',
|
||||
'--project-root=.',
|
||||
'--commit',
|
||||
'src/electron/script/apply_all_patches.py',
|
||||
'src/electron/patches/common/config.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -83,8 +100,6 @@ hooks = [
|
||||
'action': [
|
||||
'python',
|
||||
'src/electron/script/update-external-binaries.py',
|
||||
'--root-url=http://github.com/electron/electron-frameworks/releases/download',
|
||||
'--version=v1.4.0',
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
locales \
|
||||
lsb-release \
|
||||
nano \
|
||||
python-dbusmock \
|
||||
python-dbus \
|
||||
python-pip \
|
||||
python-setuptools \
|
||||
sudo \
|
||||
@@ -33,6 +33,9 @@ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
|
||||
# crcmod is required by gsutil, which is used for filling the gclient git cache
|
||||
RUN pip install -U crcmod
|
||||
|
||||
# dbusmock is needed for Electron tests
|
||||
RUN pip install python-dbusmock
|
||||
|
||||
RUN mkdir /tmp/workspace
|
||||
RUN chown builduser:builduser /tmp/workspace
|
||||
|
||||
|
||||
1
ELECTRON_VERSION
Normal file
1
ELECTRON_VERSION
Normal file
@@ -0,0 +1 @@
|
||||
5.0.8
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2013-2018 GitHub Inc.
|
||||
Copyright (c) 2013-2019 GitHub Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
[](https://circleci.com/gh/electron/electron/tree/master)
|
||||
[](https://windows-ci.electronjs.org/project/AppVeyor/electron/branch/master)
|
||||
[](https://github.visualstudio.com/electron/_build/latest?definitionId=36)
|
||||
[](https://david-dm.org/electron/electron?type=dev)
|
||||
[](https://atom-slack.herokuapp.com/)
|
||||
|
||||
|
||||
41
appveyor.yml
41
appveyor.yml
@@ -1,3 +1,28 @@
|
||||
# The config expects the following environment variables to be set:
|
||||
# - "GN_CONFIG" Build type. One of {'debug', 'testing', 'release'}.
|
||||
# - "GN_EXTRA_ARGS" Additional gn arguments for a build config,
|
||||
# e.g. 'target_cpu="x86"' to build for a 32bit platform.
|
||||
# https://gn.googlesource.com/gn/+/master/docs/reference.md#target_cpu
|
||||
# Don't forget to set up "NPM_CONFIG_ARCH" and "TARGET_ARCH" accordningly
|
||||
# if you pass a custom value for 'target_cpu'.
|
||||
# - "ELECTRON_RELEASE" Set it to '1' upload binaries on success.
|
||||
# - "NPM_CONFIG_ARCH" E.g. 'x86'. Is used to build native Node.js modules.
|
||||
# Must match 'target_cpu' passed to "GN_EXTRA_ARGS" and "TARGET_ARCH" value.
|
||||
# - "TARGET_ARCH" Choose from {'ia32', 'x64', 'arm', 'arm64', 'mips64el'}.
|
||||
# Is used in some publishing scripts, but does NOT affect the Electron binary.
|
||||
# Must match 'target_cpu' passed to "GN_EXTRA_ARGS" and "NPM_CONFIG_ARCH" value.
|
||||
# - "UPLOAD_TO_S3" Set it to '1' upload a release to the S3 bucket.
|
||||
# Otherwise the release will be uploaded to the Github Releases.
|
||||
# (The value is only checked if "ELECTRON_RELEASE" is defined.)
|
||||
#
|
||||
# The publishing scripts expect access tokens to be defined as env vars,
|
||||
# but those are not covered here.
|
||||
#
|
||||
# AppVeyor docs on variables:
|
||||
# https://www.appveyor.com/docs/environment-variables/
|
||||
# https://www.appveyor.com/docs/build-configuration/#secure-variables
|
||||
# https://www.appveyor.com/docs/build-configuration/#custom-environment-variables
|
||||
|
||||
version: 1.0.{build}
|
||||
build_cloud: libcc-20
|
||||
image: libcc-20-vs2017-15.7.4
|
||||
@@ -29,7 +54,8 @@ build_script:
|
||||
"https://github.com/electron/electron"
|
||||
- gclient sync --with_branch_heads --with_tags
|
||||
- cd src
|
||||
- gn gen out/Default "--args=import(\"//electron/build/args/%GN_CONFIG%.gn\") %GN_EXTRA_ARGS%"
|
||||
- ps: $env:BUILD_CONFIG_PATH="//electron/build/args/%GN_CONFIG%.gn"
|
||||
- gn gen out/Default "--args=import(\"%BUILD_CONFIG_PATH%\") %GN_EXTRA_ARGS%"
|
||||
- ninja -C out/Default electron:electron_app
|
||||
- gn gen out/ffmpeg "--args=import(\"//electron/build/args/ffmpeg.gn\") %GN_EXTRA_ARGS%"
|
||||
- ninja -C out/ffmpeg electron:electron_ffmpeg_zip
|
||||
@@ -42,20 +68,21 @@ build_script:
|
||||
- appveyor PushArtifact out/ffmpeg/ffmpeg.zip
|
||||
- ps: >-
|
||||
if ($env:GN_CONFIG -eq 'release') {
|
||||
ninja -C out/Default third_party/breakpad:dump_syms
|
||||
# Needed for msdia140.dll on 64-bit windows
|
||||
$env:Path += ";$pwd\third_party\llvm-build\Release+Asserts\bin"
|
||||
ninja -C out/Default electron:electron_symbols
|
||||
}
|
||||
- if "%GN_CONFIG%"=="release" ( python electron\script\dump-symbols.py -d %cd%\out\Default\electron.breakpad.syms -v)
|
||||
- ps: >-
|
||||
if ($env:GN_CONFIG -eq 'release') {
|
||||
python electron\script\zip-symbols.py
|
||||
appveyor PushArtifact out/Default/symbols.zip
|
||||
}
|
||||
- python electron/script/zip_manifests/check-zip-manifest.py out/Default/dist.zip electron/script/zip_manifests/dist_zip.win.%TARGET_ARCH%.manifest
|
||||
test_script:
|
||||
- ps: >-
|
||||
if ((-Not (Test-Path Env:\ELECTRON_RELEASE)) -And ($env:GN_CONFIG -in "testing", "release")) {
|
||||
$env:RUN_TESTS="true"
|
||||
}
|
||||
- if "%RUN_TESTS%"=="true" ( echo Verifying non proprietary ffmpeg & python electron\script\verify-ffmpeg.py --build-dir out\Default --source-root %cd% --ffmpeg-path out\ffmpeg )
|
||||
- ps: >-
|
||||
if ($env:RUN_TESTS -eq 'true') {
|
||||
New-Item .\out\Default\gen\node_headers\Release -Type directory
|
||||
@@ -64,8 +91,12 @@ test_script:
|
||||
echo "Skipping tests for $env:GN_CONFIG build"
|
||||
}
|
||||
- cd electron
|
||||
- if "%RUN_TESTS%"=="true" ( echo Running test suite & npm run test -- --ci )
|
||||
- if "%RUN_TESTS%"=="true" ( echo Running test suite & npm run test -- --ci --enable-logging)
|
||||
- cd ..
|
||||
- if "%RUN_TESTS%"=="true" ( echo Verifying non proprietary ffmpeg & python electron\script\verify-ffmpeg.py --build-dir out\Default --source-root %cd% --ffmpeg-path out\ffmpeg )
|
||||
- echo "About to verify mksnapshot"
|
||||
- if "%RUN_TESTS%"=="true" ( echo Verifying mksnapshot & python electron\script\verify-mksnapshot.py --build-dir out\Default --source-root %cd% )
|
||||
- echo "Done verifying mksnapshot"
|
||||
deploy_script:
|
||||
- cd electron
|
||||
- ps: >-
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/atom_version.h"
|
||||
#include "atom/common/chrome_version.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
@@ -17,10 +15,10 @@
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "content/public/common/content_constants.h"
|
||||
#include "content/public/common/pepper_plugin_info.h"
|
||||
#include "content/public/common/user_agent.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "ppapi/shared_impl/ppapi_permissions.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "url/url_constants.h"
|
||||
// In SHARED_INTERMEDIATE_DIR.
|
||||
#include "widevine_cdm_version.h" // NOLINT(build/include)
|
||||
@@ -179,33 +177,53 @@ AtomContentClient::AtomContentClient() {}
|
||||
|
||||
AtomContentClient::~AtomContentClient() {}
|
||||
|
||||
std::string AtomContentClient::GetProduct() const {
|
||||
return "Chrome/" CHROME_VERSION_STRING;
|
||||
}
|
||||
|
||||
std::string AtomContentClient::GetUserAgent() const {
|
||||
return content::BuildUserAgentFromProduct("Chrome/" CHROME_VERSION_STRING
|
||||
" " ATOM_PRODUCT_NAME
|
||||
"/" ATOM_VERSION_STRING);
|
||||
}
|
||||
|
||||
base::string16 AtomContentClient::GetLocalizedString(int message_id) const {
|
||||
return l10n_util::GetStringUTF16(message_id);
|
||||
}
|
||||
|
||||
void AtomContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
||||
schemes->standard_schemes.push_back("chrome-extension");
|
||||
base::StringPiece AtomContentClient::GetDataResource(
|
||||
int resource_id,
|
||||
ui::ScaleFactor scale_factor) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
||||
resource_id, scale_factor);
|
||||
}
|
||||
|
||||
gfx::Image& AtomContentClient::GetNativeImageNamed(int resource_id) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
|
||||
resource_id);
|
||||
}
|
||||
|
||||
base::RefCountedMemory* AtomContentClient::GetDataResourceBytes(
|
||||
int resource_id) const {
|
||||
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
|
||||
resource_id);
|
||||
}
|
||||
|
||||
void AtomContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
||||
std::vector<std::string> splited;
|
||||
ConvertStringWithSeparatorToVector(&splited, ",",
|
||||
switches::kRegisterServiceWorkerSchemes);
|
||||
switches::kServiceWorkerSchemes);
|
||||
for (const std::string& scheme : splited)
|
||||
schemes->service_worker_schemes.push_back(scheme);
|
||||
schemes->service_worker_schemes.push_back(url::kFileScheme);
|
||||
|
||||
ConvertStringWithSeparatorToVector(&splited, ",", switches::kStandardSchemes);
|
||||
for (const std::string& scheme : splited)
|
||||
schemes->standard_schemes.push_back(scheme);
|
||||
schemes->standard_schemes.push_back("chrome-extension");
|
||||
|
||||
ConvertStringWithSeparatorToVector(&splited, ",", switches::kSecureSchemes);
|
||||
for (const std::string& scheme : splited)
|
||||
schemes->secure_schemes.push_back(scheme);
|
||||
|
||||
ConvertStringWithSeparatorToVector(&splited, ",",
|
||||
switches::kBypassCSPSchemes);
|
||||
for (const std::string& scheme : splited)
|
||||
schemes->csp_bypassing_schemes.push_back(scheme);
|
||||
|
||||
ConvertStringWithSeparatorToVector(&splited, ",", switches::kCORSSchemes);
|
||||
for (const std::string& scheme : splited)
|
||||
schemes->cors_enabled_schemes.push_back(scheme);
|
||||
}
|
||||
|
||||
void AtomContentClient::AddPepperPlugins(
|
||||
|
||||
@@ -9,20 +9,22 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "brightray/common/content_client.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomContentClient : public brightray::ContentClient {
|
||||
class AtomContentClient : public content::ContentClient {
|
||||
public:
|
||||
AtomContentClient();
|
||||
~AtomContentClient() override;
|
||||
|
||||
protected:
|
||||
// content::ContentClient:
|
||||
std::string GetProduct() const override;
|
||||
std::string GetUserAgent() const override;
|
||||
base::string16 GetLocalizedString(int message_id) const override;
|
||||
base::StringPiece GetDataResource(int resource_id,
|
||||
ui::ScaleFactor) const override;
|
||||
gfx::Image& GetNativeImageNamed(int resource_id) const override;
|
||||
base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override;
|
||||
void AddAdditionalSchemes(Schemes* schemes) override;
|
||||
void AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) override;
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
#include "atom/app/atom_main_delegate.h"
|
||||
#include "atom/app/node_main.h"
|
||||
#include "atom/common/atom_command_line.h"
|
||||
#include "atom/common/mac/main_application_bundle.h"
|
||||
#include "base/at_exit.h"
|
||||
#include "base/i18n/icu_util.h"
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "brightray/common/mac/main_application_bundle.h"
|
||||
#include "content/public/app/content_main.h"
|
||||
|
||||
int AtomMain(int argc, char* argv[]) {
|
||||
@@ -28,7 +28,7 @@ int AtomInitializeICUandStartNode(int argc, char* argv[]) {
|
||||
base::AtExitManager atexit_manager;
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
base::mac::SetOverrideFrameworkBundlePath(
|
||||
brightray::MainApplicationBundlePath()
|
||||
atom::MainApplicationBundlePath()
|
||||
.Append("Contents")
|
||||
.Append("Frameworks")
|
||||
.Append(ATOM_PRODUCT_NAME " Framework.framework"));
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "atom/app/atom_main.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#if defined(OS_WIN)
|
||||
@@ -24,10 +25,15 @@
|
||||
#include "base/win/windows_version.h"
|
||||
#include "content/public/app/sandbox_helper_win.h"
|
||||
#include "sandbox/win/src/sandbox_types.h"
|
||||
#elif defined(OS_LINUX) // defined(OS_WIN)
|
||||
#elif defined(OS_LINUX) // defined(OS_WIN)
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include "atom/app/atom_main_delegate.h" // NOLINT
|
||||
#include "content/public/app/content_main.h"
|
||||
#else // defined(OS_LINUX)
|
||||
#include <mach-o/dyld.h>
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include "atom/app/atom_library_main.h"
|
||||
#endif // defined(OS_MACOSX)
|
||||
|
||||
@@ -37,13 +43,17 @@
|
||||
#include "base/i18n/icu_util.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
|
||||
#if defined(HELPER_EXECUTABLE) && !defined(MAS_BUILD)
|
||||
#include "sandbox/mac/seatbelt_exec.h" // nogncheck
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
const char kRunAsNode[] = "ELECTRON_RUN_AS_NODE";
|
||||
#endif
|
||||
|
||||
bool IsEnvSet(const char* name) {
|
||||
ALLOW_UNUSED_TYPE bool IsEnvSet(const char* name) {
|
||||
#if defined(OS_WIN)
|
||||
size_t required_size;
|
||||
getenv_s(&required_size, nullptr, 0, name);
|
||||
@@ -54,6 +64,25 @@ bool IsEnvSet(const char* name) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(OS_POSIX)
|
||||
void FixStdioStreams() {
|
||||
// libuv may mark stdin/stdout/stderr as close-on-exec, which interferes
|
||||
// with chromium's subprocess spawning. As a workaround, we detect if these
|
||||
// streams are closed on startup, and reopen them as /dev/null if necessary.
|
||||
// Otherwise, an unrelated file descriptor will be assigned as stdout/stderr
|
||||
// which may cause various errors when attempting to write to them.
|
||||
//
|
||||
// For details see https://github.com/libuv/libuv/issues/2062
|
||||
struct stat st;
|
||||
if (fstat(STDIN_FILENO, &st) < 0 && errno == EBADF)
|
||||
ignore_result(freopen("/dev/null", "r", stdin));
|
||||
if (fstat(STDOUT_FILENO, &st) < 0 && errno == EBADF)
|
||||
ignore_result(freopen("/dev/null", "w", stdout));
|
||||
if (fstat(STDERR_FILENO, &st) < 0 && errno == EBADF)
|
||||
ignore_result(freopen("/dev/null", "w", stderr));
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
#if defined(OS_WIN)
|
||||
@@ -155,6 +184,8 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||
#elif defined(OS_LINUX) // defined(OS_WIN)
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
FixStdioStreams();
|
||||
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
if (IsEnvSet(kRunAsNode)) {
|
||||
base::i18n::InitializeICU();
|
||||
@@ -174,12 +205,43 @@ int main(int argc, char* argv[]) {
|
||||
#else // defined(OS_LINUX)
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
FixStdioStreams();
|
||||
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
if (IsEnvSet(kRunAsNode)) {
|
||||
return AtomInitializeICUandStartNode(argc, argv);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HELPER_EXECUTABLE) && !defined(MAS_BUILD)
|
||||
uint32_t exec_path_size = 0;
|
||||
int rv = _NSGetExecutablePath(NULL, &exec_path_size);
|
||||
if (rv != -1) {
|
||||
fprintf(stderr, "_NSGetExecutablePath: get length failed\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
std::unique_ptr<char[]> exec_path(new char[exec_path_size]);
|
||||
rv = _NSGetExecutablePath(exec_path.get(), &exec_path_size);
|
||||
if (rv != 0) {
|
||||
fprintf(stderr, "_NSGetExecutablePath: get path failed\n");
|
||||
abort();
|
||||
}
|
||||
sandbox::SeatbeltExecServer::CreateFromArgumentsResult seatbelt =
|
||||
sandbox::SeatbeltExecServer::CreateFromArguments(exec_path.get(), argc,
|
||||
argv);
|
||||
if (seatbelt.sandbox_required) {
|
||||
if (!seatbelt.server) {
|
||||
fprintf(stderr, "Failed to create seatbelt sandbox server.\n");
|
||||
abort();
|
||||
}
|
||||
if (!seatbelt.server->InitializeSandbox()) {
|
||||
fprintf(stderr, "Failed to initialize sandbox.\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#endif // defined(HELPER_EXECUTABLE) && !defined(MAS_BUILD)
|
||||
|
||||
return AtomMain(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
#include <glib.h> // for g_setenv()
|
||||
#endif
|
||||
|
||||
#include "atom/app/atom_content_client.h"
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/browser/relauncher.h"
|
||||
#include "atom/common/google_api_key.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "atom/renderer/atom_renderer_client.h"
|
||||
#include "atom/renderer/atom_sandboxed_renderer_client.h"
|
||||
@@ -20,12 +23,17 @@
|
||||
#include "base/debug/stack_trace.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/path_service.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "ipc/ipc_buildflags.h"
|
||||
#include "services/service_manager/embedder/switches.h"
|
||||
#include "services/service_manager/sandbox/switches.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
|
||||
#if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED)
|
||||
#define IPC_MESSAGE_MACROS_LOG_ENABLED
|
||||
@@ -50,6 +58,30 @@ bool IsBrowserProcess(base::CommandLine* cmd) {
|
||||
return process_type.empty();
|
||||
}
|
||||
|
||||
bool IsSandboxEnabled(base::CommandLine* command_line) {
|
||||
return command_line->HasSwitch(switches::kEnableSandbox) ||
|
||||
!command_line->HasSwitch(service_manager::switches::kNoSandbox);
|
||||
}
|
||||
|
||||
// Returns true if this subprocess type needs the ResourceBundle initialized
|
||||
// and resources loaded.
|
||||
bool SubprocessNeedsResourceBundle(const std::string& process_type) {
|
||||
return
|
||||
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
||||
// The zygote process opens the resources for the renderers.
|
||||
process_type == service_manager::switches::kZygoteProcess ||
|
||||
#endif
|
||||
#if defined(OS_MACOSX)
|
||||
// Mac needs them too for scrollbar related images and for sandbox
|
||||
// profiles.
|
||||
process_type == ::switches::kPpapiPluginProcess ||
|
||||
process_type == ::switches::kPpapiBrokerProcess ||
|
||||
process_type == ::switches::kGpuProcess ||
|
||||
#endif
|
||||
process_type == ::switches::kRendererProcess ||
|
||||
process_type == ::switches::kUtilityProcess;
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void InvalidParameterHandler(const wchar_t*,
|
||||
const wchar_t*,
|
||||
@@ -62,6 +94,37 @@ void InvalidParameterHandler(const wchar_t*,
|
||||
|
||||
} // namespace
|
||||
|
||||
void LoadResourceBundle(const std::string& locale) {
|
||||
const bool initialized = ui::ResourceBundle::HasSharedInstance();
|
||||
if (initialized)
|
||||
ui::ResourceBundle::CleanupSharedInstance();
|
||||
|
||||
// Load other resource files.
|
||||
base::FilePath pak_dir;
|
||||
#if defined(OS_MACOSX)
|
||||
pak_dir =
|
||||
base::mac::FrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
||||
#else
|
||||
base::PathService::Get(base::DIR_MODULE, &pak_dir);
|
||||
#endif
|
||||
|
||||
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||
locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
||||
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
|
||||
bundle.ReloadLocaleResources(locale);
|
||||
bundle.AddDataPackFromPath(pak_dir.Append(FILE_PATH_LITERAL("resources.pak")),
|
||||
ui::SCALE_FACTOR_NONE);
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
NOTIMPLEMENTED()
|
||||
<< "Hi, whoever's fixing PDF support! Thanks! The pdf "
|
||||
"viewer resources haven't been ported over to the GN build yet, so "
|
||||
"you'll probably need to change this bit of code.";
|
||||
bundle.AddDataPackFromPath(
|
||||
pak_dir.Append(FILE_PATH_LITERAL("pdf_viewer_resources.pak")),
|
||||
ui::GetSupportedScaleFactors()[0]);
|
||||
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
}
|
||||
|
||||
AtomMainDelegate::AtomMainDelegate() {}
|
||||
|
||||
AtomMainDelegate::~AtomMainDelegate() {}
|
||||
@@ -101,23 +164,19 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
// Logging with pid and timestamp.
|
||||
logging::SetLogItems(true, false, true, false);
|
||||
|
||||
// Enable convient stack printing.
|
||||
#if defined(DEBUG) && defined(OS_LINUX)
|
||||
bool enable_stack_dumping = true;
|
||||
#else
|
||||
bool enable_stack_dumping = env->HasVar("ELECTRON_ENABLE_STACK_DUMPING");
|
||||
#endif
|
||||
#if defined(ARCH_CPU_ARM_FAMILY) && defined(ARCH_CPU_32_BITS)
|
||||
// For 32bit ARM enabling stack printing would end up crashing.
|
||||
// https://github.com/electron/electron/pull/11230#issuecomment-363232482
|
||||
enable_stack_dumping = false;
|
||||
#endif
|
||||
if (enable_stack_dumping)
|
||||
// Enable convient stack printing. This is enabled by default in non-official
|
||||
// builds.
|
||||
if (env->HasVar("ELECTRON_ENABLE_STACK_DUMPING"))
|
||||
base::debug::EnableInProcessStackDumping();
|
||||
|
||||
if (env->HasVar("ELECTRON_DISABLE_SANDBOX"))
|
||||
command_line->AppendSwitch(service_manager::switches::kNoSandbox);
|
||||
|
||||
chrome::RegisterPathProvider();
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
OverrideChildProcessPath();
|
||||
OverrideFrameworkBundlePath();
|
||||
SetUpBundleOverrides();
|
||||
#endif
|
||||
|
||||
@@ -129,30 +188,68 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
base::win::DisableHandleVerifier();
|
||||
#endif
|
||||
|
||||
return brightray::MainDelegate::BasicStartupComplete(exit_code);
|
||||
#if defined(OS_LINUX)
|
||||
// Check for --no-sandbox parameter when running as root.
|
||||
if (getuid() == 0 && IsSandboxEnabled(command_line))
|
||||
LOG(FATAL) << "Running as root without --"
|
||||
<< service_manager::switches::kNoSandbox
|
||||
<< " is not supported. See https://crbug.com/638180.";
|
||||
#endif
|
||||
|
||||
content_client_ = std::make_unique<AtomContentClient>();
|
||||
SetContentClient(content_client_.get());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AtomMainDelegate::PostEarlyInitialization(bool is_running_tests) {
|
||||
std::string custom_locale;
|
||||
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||
custom_locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
||||
auto* cmd_line = base::CommandLine::ForCurrentProcess();
|
||||
if (cmd_line->HasSwitch(::switches::kLang)) {
|
||||
const std::string locale = cmd_line->GetSwitchValueASCII(::switches::kLang);
|
||||
const base::FilePath locale_file_path =
|
||||
ui::ResourceBundle::GetSharedInstance().GetLocaleFilePath(locale, true);
|
||||
if (!locale_file_path.empty()) {
|
||||
custom_locale = locale;
|
||||
#if defined(OS_LINUX)
|
||||
/* When built with USE_GLIB, libcc's GetApplicationLocaleInternal() uses
|
||||
* glib's g_get_language_names(), which keys off of getenv("LC_ALL") */
|
||||
g_setenv("LC_ALL", custom_locale.c_str(), TRUE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
if (custom_locale.empty())
|
||||
l10n_util::OverrideLocaleWithCocoaLocale();
|
||||
#endif
|
||||
|
||||
LoadResourceBundle(custom_locale);
|
||||
|
||||
AtomBrowserClient::SetApplicationLocale(
|
||||
l10n_util::GetApplicationLocale(custom_locale));
|
||||
}
|
||||
|
||||
void AtomMainDelegate::PreSandboxStartup() {
|
||||
brightray::MainDelegate::PreSandboxStartup();
|
||||
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
std::string process_type =
|
||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
||||
|
||||
// Initialize ResourceBundle which handles files loaded from external
|
||||
// sources. The language should have been passed in to us from the
|
||||
// browser process as a command line flag.
|
||||
if (SubprocessNeedsResourceBundle(process_type)) {
|
||||
std::string locale = command_line->GetSwitchValueASCII(::switches::kLang);
|
||||
LoadResourceBundle(locale);
|
||||
}
|
||||
|
||||
// Only append arguments for browser process.
|
||||
if (!IsBrowserProcess(command_line))
|
||||
return;
|
||||
|
||||
if (!command_line->HasSwitch(switches::kEnableMixedSandbox)) {
|
||||
if (command_line->HasSwitch(switches::kEnableSandbox)) {
|
||||
// Disable setuid sandbox since it is not longer required on
|
||||
// linux(namespace sandbox is available on most distros).
|
||||
command_line->AppendSwitch(
|
||||
service_manager::switches::kDisableSetuidSandbox);
|
||||
} else {
|
||||
// Disable renderer sandbox for most of node's functions.
|
||||
command_line->AppendSwitch(service_manager::switches::kNoSandbox);
|
||||
}
|
||||
}
|
||||
|
||||
// Allow file:// URIs to read other file:// URIs by default.
|
||||
command_line->AppendSwitch(::switches::kAllowFileAccessFromFiles);
|
||||
|
||||
@@ -162,7 +259,7 @@ void AtomMainDelegate::PreSandboxStartup() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void AtomMainDelegate::PreContentInitialization() {
|
||||
void AtomMainDelegate::PreCreateMainMessageLoop() {
|
||||
#if defined(OS_MACOSX)
|
||||
RegisterAtomCrApp();
|
||||
#endif
|
||||
@@ -175,10 +272,9 @@ content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
|
||||
|
||||
content::ContentRendererClient*
|
||||
AtomMainDelegate::CreateContentRendererClient() {
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kEnableSandbox) ||
|
||||
!base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
service_manager::switches::kNoSandbox)) {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
if (IsSandboxEnabled(command_line)) {
|
||||
renderer_client_.reset(new AtomSandboxedRendererClient);
|
||||
} else {
|
||||
renderer_client_.reset(new AtomRendererClient);
|
||||
@@ -212,9 +308,12 @@ bool AtomMainDelegate::DelaySandboxInitialization(
|
||||
}
|
||||
#endif
|
||||
|
||||
std::unique_ptr<brightray::ContentClient>
|
||||
AtomMainDelegate::CreateContentClient() {
|
||||
return std::make_unique<AtomContentClient>();
|
||||
bool AtomMainDelegate::ShouldLockSchemeRegistry() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AtomMainDelegate::ShouldCreateFeatureList() {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "brightray/common/content_client.h"
|
||||
#include "brightray/common/main_delegate.h"
|
||||
#include "content/public/app/content_main_delegate.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomMainDelegate : public brightray::MainDelegate {
|
||||
void LoadResourceBundle(const std::string& locale);
|
||||
|
||||
class AtomMainDelegate : public content::ContentMainDelegate {
|
||||
public:
|
||||
AtomMainDelegate();
|
||||
~AtomMainDelegate() override;
|
||||
@@ -22,7 +24,8 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
||||
// content::ContentMainDelegate:
|
||||
bool BasicStartupComplete(int* exit_code) override;
|
||||
void PreSandboxStartup() override;
|
||||
void PreContentInitialization() override;
|
||||
void PreCreateMainMessageLoop() override;
|
||||
void PostEarlyInitialization(bool is_running_tests) override;
|
||||
content::ContentBrowserClient* CreateContentBrowserClient() override;
|
||||
content::ContentRendererClient* CreateContentRendererClient() override;
|
||||
content::ContentUtilityClient* CreateContentUtilityClient() override;
|
||||
@@ -33,20 +36,18 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
||||
bool ShouldSendMachPort(const std::string& process_type) override;
|
||||
bool DelaySandboxInitialization(const std::string& process_type) override;
|
||||
#endif
|
||||
|
||||
// brightray::MainDelegate:
|
||||
std::unique_ptr<brightray::ContentClient> CreateContentClient() override;
|
||||
#if defined(OS_MACOSX)
|
||||
void OverrideChildProcessPath() override;
|
||||
void OverrideFrameworkBundlePath() override;
|
||||
#endif
|
||||
bool ShouldLockSchemeRegistry() override;
|
||||
bool ShouldCreateFeatureList() override;
|
||||
|
||||
private:
|
||||
#if defined(OS_MACOSX)
|
||||
void OverrideChildProcessPath();
|
||||
void OverrideFrameworkBundlePath();
|
||||
void SetUpBundleOverrides();
|
||||
#endif
|
||||
|
||||
std::unique_ptr<content::ContentBrowserClient> browser_client_;
|
||||
std::unique_ptr<content::ContentClient> content_client_;
|
||||
std::unique_ptr<content::ContentRendererClient> renderer_client_;
|
||||
std::unique_ptr<content::ContentUtilityClient> utility_client_;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "atom/app/atom_main_delegate.h"
|
||||
|
||||
#include "atom/browser/mac/atom_application.h"
|
||||
#include "atom/common/application_info.h"
|
||||
#include "atom/common/mac/main_application_bundle.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/mac/bundle_locations.h"
|
||||
@@ -12,8 +14,6 @@
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
#include "brightray/common/mac/main_application_bundle.h"
|
||||
#include "content/public/common/content_paths.h"
|
||||
|
||||
namespace atom {
|
||||
@@ -21,9 +21,7 @@ namespace atom {
|
||||
namespace {
|
||||
|
||||
base::FilePath GetFrameworksPath() {
|
||||
return brightray::MainApplicationBundlePath()
|
||||
.Append("Contents")
|
||||
.Append("Frameworks");
|
||||
return MainApplicationBundlePath().Append("Contents").Append("Frameworks");
|
||||
}
|
||||
|
||||
base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path,
|
||||
@@ -46,8 +44,7 @@ void AtomMainDelegate::OverrideChildProcessPath() {
|
||||
base::FilePath helper_path =
|
||||
GetHelperAppPath(frameworks_path, ATOM_PRODUCT_NAME);
|
||||
if (!base::PathExists(helper_path))
|
||||
helper_path =
|
||||
GetHelperAppPath(frameworks_path, brightray::GetApplicationName());
|
||||
helper_path = GetHelperAppPath(frameworks_path, GetApplicationName());
|
||||
if (!base::PathExists(helper_path))
|
||||
LOG(FATAL) << "Unable to find helper app";
|
||||
base::PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
|
||||
@@ -55,7 +52,7 @@ void AtomMainDelegate::OverrideChildProcessPath() {
|
||||
|
||||
void AtomMainDelegate::SetUpBundleOverrides() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
NSBundle* bundle = brightray::MainApplicationBundle();
|
||||
NSBundle* bundle = MainApplicationBundle();
|
||||
std::string base_bundle_id =
|
||||
base::SysNSStringToUTF8([bundle bundleIdentifier]);
|
||||
NSString* team_id = [bundle objectForInfoDictionaryKey:@"ElectronTeamID"];
|
||||
|
||||
44
atom/app/manifests.cc
Normal file
44
atom/app/manifests.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2019 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/app/manifests.h"
|
||||
|
||||
#include "base/no_destructor.h"
|
||||
#include "printing/buildflags/buildflags.h"
|
||||
#include "services/proxy_resolver/proxy_resolver_manifest.h"
|
||||
#include "services/service_manager/public/cpp/manifest_builder.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
#include "components/services/pdf_compositor/pdf_compositor_manifest.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
||||
#include "chrome/services/printing/manifest.h"
|
||||
#endif
|
||||
|
||||
const service_manager::Manifest& GetElectronContentBrowserOverlayManifest() {
|
||||
static base::NoDestructor<service_manager::Manifest> manifest{
|
||||
service_manager::ManifestBuilder()
|
||||
.WithDisplayName("Electron (browser process)")
|
||||
.RequireCapability("device", "device:geolocation_control")
|
||||
.RequireCapability("proxy_resolver", "factory")
|
||||
.RequireCapability("chrome_printing", "converter")
|
||||
.RequireCapability("pdf_compositor", "compositor")
|
||||
.Build()};
|
||||
return *manifest;
|
||||
}
|
||||
|
||||
const std::vector<service_manager::Manifest>&
|
||||
GetElectronPackagedServicesOverlayManifest() {
|
||||
static base::NoDestructor<std::vector<service_manager::Manifest>> manifests{{
|
||||
proxy_resolver::GetManifest(),
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
pdf_compositor::GetManifest(),
|
||||
#endif
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
||||
chrome_printing::GetManifest(),
|
||||
#endif
|
||||
}};
|
||||
return *manifests;
|
||||
}
|
||||
16
atom/app/manifests.h
Normal file
16
atom/app/manifests.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2019 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_APP_MANIFESTS_H_
|
||||
#define ATOM_APP_MANIFESTS_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "services/service_manager/public/cpp/manifest.h"
|
||||
|
||||
const service_manager::Manifest& GetElectronContentBrowserOverlayManifest();
|
||||
const std::vector<service_manager::Manifest>&
|
||||
GetElectronPackagedServicesOverlayManifest();
|
||||
|
||||
#endif // ATOM_APP_MANIFESTS_H_
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "atom/common/node_bindings.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/feature_list.h"
|
||||
#include "base/task_scheduler/task_scheduler.h"
|
||||
#include "base/task/task_scheduler/task_scheduler.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "gin/array_buffer.h"
|
||||
#include "gin/public/isolate_holder.h"
|
||||
@@ -96,6 +96,7 @@ int NodeMain(int argc, char* argv[]) {
|
||||
}
|
||||
} while (more == true);
|
||||
|
||||
node_debugger.Stop();
|
||||
exit_code = node::EmitExit(env);
|
||||
node::RunAtExit(env);
|
||||
gin_env.platform()->DrainTasks(env->isolate());
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "atom/browser/api/gpuinfo_manager.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/atom_paths.h"
|
||||
#include "atom/browser/login_handler.h"
|
||||
#include "atom/browser/relauncher.h"
|
||||
#include "atom/common/atom_command_line.h"
|
||||
@@ -23,16 +24,13 @@
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "atom/common/native_mate_converters/network_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/sys_info.h"
|
||||
#include "brightray/browser/brightray_paths.h"
|
||||
#include "base/system/sys_info.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/icon_manager.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
@@ -49,17 +47,23 @@
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "net/ssl/client_cert_identity.h"
|
||||
#include "net/ssl/ssl_cert_request_info.h"
|
||||
#include "services/network/public/cpp/network_switches.h"
|
||||
#include "services/service_manager/sandbox/switches.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
// clang-format off
|
||||
// This header should be declared at the end to avoid
|
||||
// redefinition errors.
|
||||
#include "atom/common/node_includes.h" // NOLINT(build/include_alpha)
|
||||
// clang-format on
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "atom/browser/ui/win/jump_list.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include "atom/browser/ui/cocoa/atom_bundle_mover.h"
|
||||
#endif
|
||||
|
||||
@@ -390,15 +394,15 @@ IconLoader::IconSize GetIconSizeByString(const std::string& size) {
|
||||
// Return the path constant from string.
|
||||
int GetPathConstant(const std::string& name) {
|
||||
if (name == "appData")
|
||||
return brightray::DIR_APP_DATA;
|
||||
return DIR_APP_DATA;
|
||||
else if (name == "userData")
|
||||
return brightray::DIR_USER_DATA;
|
||||
return DIR_USER_DATA;
|
||||
else if (name == "cache")
|
||||
return brightray::DIR_CACHE;
|
||||
return DIR_CACHE;
|
||||
else if (name == "userCache")
|
||||
return brightray::DIR_USER_CACHE;
|
||||
return DIR_USER_CACHE;
|
||||
else if (name == "logs")
|
||||
return brightray::DIR_APP_LOGS;
|
||||
return DIR_APP_LOGS;
|
||||
else if (name == "home")
|
||||
return base::DIR_HOME;
|
||||
else if (name == "temp")
|
||||
@@ -529,18 +533,11 @@ int ImportIntoCertStore(CertificateManagerModel* model,
|
||||
}
|
||||
#endif
|
||||
|
||||
void OnIconDataAvailable(v8::Isolate* isolate,
|
||||
const App::FileIconCallback& callback,
|
||||
gfx::Image* icon) {
|
||||
v8::Locker locker(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
void OnIconDataAvailable(util::Promise promise, gfx::Image* icon) {
|
||||
if (icon && !icon->IsEmpty()) {
|
||||
callback.Run(v8::Null(isolate), *icon);
|
||||
promise.Resolve(*icon);
|
||||
} else {
|
||||
v8::Local<v8::String> error_message =
|
||||
v8::String::NewFromUtf8(isolate, "Failed to get file icon.");
|
||||
callback.Run(v8::Exception::Error(error_message), gfx::Image());
|
||||
promise.RejectWithErrorMessage("Failed to get file icon.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -678,7 +675,7 @@ void App::OnLogin(scoped_refptr<LoginHandler> login_handler,
|
||||
content::WebContents* web_contents = login_handler->GetWebContents();
|
||||
if (web_contents) {
|
||||
prevent_default = Emit(
|
||||
"login", WebContents::CreateFrom(isolate(), web_contents),
|
||||
"login", WebContents::FromOrCreate(isolate(), web_contents),
|
||||
request_details, login_handler->auth_info(),
|
||||
base::Bind(&PassLoginInformation, base::RetainedRef(login_handler)));
|
||||
}
|
||||
@@ -692,7 +689,7 @@ bool App::CanCreateWindow(
|
||||
content::RenderFrameHost* opener,
|
||||
const GURL& opener_url,
|
||||
const GURL& opener_top_level_frame_url,
|
||||
const GURL& source_origin,
|
||||
const url::Origin& source_origin,
|
||||
content::mojom::WindowContainerType container_type,
|
||||
const GURL& target_url,
|
||||
const content::Referrer& referrer,
|
||||
@@ -709,9 +706,12 @@ bool App::CanCreateWindow(
|
||||
content::WebContents* web_contents =
|
||||
content::WebContents::FromRenderFrameHost(opener);
|
||||
if (web_contents) {
|
||||
auto api_web_contents = WebContents::CreateFrom(isolate(), web_contents);
|
||||
api_web_contents->OnCreateWindow(target_url, referrer, frame_name,
|
||||
disposition, additional_features, body);
|
||||
auto api_web_contents = WebContents::From(isolate(), web_contents);
|
||||
// No need to emit any event if the WebContents is not available in JS.
|
||||
if (!api_web_contents.IsEmpty()) {
|
||||
api_web_contents->OnCreateWindow(target_url, referrer, frame_name,
|
||||
disposition, additional_features, body);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -730,7 +730,7 @@ void App::AllowCertificateError(
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
bool prevent_default = Emit(
|
||||
"certificate-error", WebContents::CreateFrom(isolate(), web_contents),
|
||||
"certificate-error", WebContents::FromOrCreate(isolate(), web_contents),
|
||||
request_url, net::ErrorToString(cert_error), ssl_info.cert, callback);
|
||||
|
||||
// Deny the certificate by default.
|
||||
@@ -757,7 +757,7 @@ void App::SelectClientCertificate(
|
||||
|
||||
bool prevent_default =
|
||||
Emit("select-client-certificate",
|
||||
WebContents::CreateFrom(isolate(), web_contents),
|
||||
WebContents::FromOrCreate(isolate(), web_contents),
|
||||
cert_request_info->host_and_port.ToString(), std::move(client_certs),
|
||||
base::Bind(&OnClientCertificateSelected, isolate(), shared_delegate,
|
||||
shared_identities));
|
||||
@@ -779,24 +779,24 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) {
|
||||
|
||||
void App::BrowserChildProcessLaunchedAndConnected(
|
||||
const content::ChildProcessData& data) {
|
||||
ChildProcessLaunched(data.process_type, data.handle);
|
||||
ChildProcessLaunched(data.process_type, data.GetProcess().Handle());
|
||||
}
|
||||
|
||||
void App::BrowserChildProcessHostDisconnected(
|
||||
const content::ChildProcessData& data) {
|
||||
ChildProcessDisconnected(base::GetProcId(data.handle));
|
||||
ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle()));
|
||||
}
|
||||
|
||||
void App::BrowserChildProcessCrashed(
|
||||
const content::ChildProcessData& data,
|
||||
const content::ChildProcessTerminationInfo& info) {
|
||||
ChildProcessDisconnected(base::GetProcId(data.handle));
|
||||
ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle()));
|
||||
}
|
||||
|
||||
void App::BrowserChildProcessKilled(
|
||||
const content::ChildProcessData& data,
|
||||
const content::ChildProcessTerminationInfo& info) {
|
||||
ChildProcessDisconnected(base::GetProcId(data.handle));
|
||||
ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle()));
|
||||
}
|
||||
|
||||
void App::RenderProcessReady(content::RenderProcessHost* host) {
|
||||
@@ -874,6 +874,45 @@ std::string App::GetLocale() {
|
||||
return g_browser_process->GetApplicationLocale();
|
||||
}
|
||||
|
||||
std::string App::GetLocaleCountryCode() {
|
||||
std::string region;
|
||||
#if defined(OS_WIN)
|
||||
WCHAR locale_name[LOCALE_NAME_MAX_LENGTH] = {0};
|
||||
|
||||
if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SISO3166CTRYNAME,
|
||||
(LPWSTR)&locale_name,
|
||||
sizeof(locale_name) / sizeof(WCHAR)) ||
|
||||
GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME,
|
||||
(LPWSTR)&locale_name,
|
||||
sizeof(locale_name) / sizeof(WCHAR))) {
|
||||
base::WideToUTF8(locale_name, wcslen(locale_name), ®ion);
|
||||
}
|
||||
#elif defined(OS_MACOSX)
|
||||
CFLocaleRef locale = CFLocaleCopyCurrent();
|
||||
CFStringRef value = CFStringRef(
|
||||
static_cast<CFTypeRef>(CFLocaleGetValue(locale, kCFLocaleCountryCode)));
|
||||
const CFIndex kCStringSize = 128;
|
||||
char temporaryCString[kCStringSize] = {0};
|
||||
CFStringGetCString(value, temporaryCString, kCStringSize,
|
||||
kCFStringEncodingUTF8);
|
||||
region = temporaryCString;
|
||||
#else
|
||||
const char* locale_ptr = setlocale(LC_TIME, NULL);
|
||||
if (!locale_ptr)
|
||||
locale_ptr = setlocale(LC_NUMERIC, NULL);
|
||||
if (locale_ptr) {
|
||||
std::string locale = locale_ptr;
|
||||
std::string::size_type rpos = locale.find('.');
|
||||
if (rpos != std::string::npos)
|
||||
locale = locale.substr(0, rpos);
|
||||
rpos = locale.find('_');
|
||||
if (rpos != std::string::npos && rpos + 1 < locale.size())
|
||||
region = locale.substr(rpos + 1);
|
||||
}
|
||||
#endif
|
||||
return region.size() == 2 ? region : std::string();
|
||||
}
|
||||
|
||||
void App::OnSecondInstance(const base::CommandLine::StringVector& cmd,
|
||||
const base::FilePath& cwd) {
|
||||
Emit("second-instance", cmd, cwd);
|
||||
@@ -890,7 +929,7 @@ bool App::RequestSingleInstanceLock() {
|
||||
return true;
|
||||
|
||||
base::FilePath user_dir;
|
||||
base::PathService::Get(brightray::DIR_USER_DATA, &user_dir);
|
||||
base::PathService::Get(DIR_USER_DATA, &user_dir);
|
||||
|
||||
auto cb = base::Bind(&App::OnSecondInstance, base::Unretained(this));
|
||||
|
||||
@@ -976,7 +1015,14 @@ bool App::IsAccessibilitySupportEnabled() {
|
||||
return ax_state->IsAccessibleBrowser();
|
||||
}
|
||||
|
||||
void App::SetAccessibilitySupportEnabled(bool enabled) {
|
||||
void App::SetAccessibilitySupportEnabled(bool enabled, mate::Arguments* args) {
|
||||
if (!Browser::Get()->is_ready()) {
|
||||
args->ThrowError(
|
||||
"app.setAccessibilitySupportEnabled() can only be called "
|
||||
"after app is ready");
|
||||
return;
|
||||
}
|
||||
|
||||
auto* ax_state = content::BrowserAccessibilityState::GetInstance();
|
||||
if (enabled) {
|
||||
ax_state->OnScreenReaderDetected();
|
||||
@@ -1077,16 +1123,14 @@ JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
|
||||
}
|
||||
#endif // defined(OS_WIN)
|
||||
|
||||
void App::GetFileIcon(const base::FilePath& path, mate::Arguments* args) {
|
||||
mate::Dictionary options;
|
||||
IconLoader::IconSize icon_size;
|
||||
FileIconCallback callback;
|
||||
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
|
||||
v8::Local<v8::Promise> App::GetFileIcon(const base::FilePath& path,
|
||||
mate::Arguments* args) {
|
||||
util::Promise promise(isolate());
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
base::FilePath normalized_path = path.NormalizePathSeparators();
|
||||
|
||||
IconLoader::IconSize icon_size;
|
||||
mate::Dictionary options;
|
||||
if (!args->GetNext(&options)) {
|
||||
icon_size = IconLoader::IconSize::NORMAL;
|
||||
} else {
|
||||
@@ -1095,22 +1139,18 @@ void App::GetFileIcon(const base::FilePath& path, mate::Arguments* args) {
|
||||
icon_size = GetIconSizeByString(icon_size_string);
|
||||
}
|
||||
|
||||
if (!args->GetNext(&callback)) {
|
||||
args->ThrowError("Missing required callback function");
|
||||
return;
|
||||
}
|
||||
|
||||
auto* icon_manager = AtomBrowserMainParts::Get()->GetIconManager();
|
||||
gfx::Image* icon =
|
||||
icon_manager->LookupIconFromFilepath(normalized_path, icon_size);
|
||||
if (icon) {
|
||||
callback.Run(v8::Null(isolate()), *icon);
|
||||
promise.Resolve(*icon);
|
||||
} else {
|
||||
icon_manager->LoadIcon(
|
||||
normalized_path, icon_size,
|
||||
base::Bind(&OnIconDataAvailable, isolate(), callback),
|
||||
base::BindOnce(&OnIconDataAvailable, std::move(promise)),
|
||||
&cancelable_task_tracker_);
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
std::vector<mate::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
|
||||
@@ -1158,30 +1198,30 @@ v8::Local<v8::Value> App::GetGPUFeatureStatus(v8::Isolate* isolate) {
|
||||
v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate,
|
||||
const std::string& info_type) {
|
||||
auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance();
|
||||
scoped_refptr<util::Promise> promise = new util::Promise(isolate);
|
||||
util::Promise promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
if (info_type != "basic" && info_type != "complete") {
|
||||
promise->RejectWithErrorMessage(
|
||||
promise.RejectWithErrorMessage(
|
||||
"Invalid info type. Use 'basic' or 'complete'");
|
||||
return promise->GetHandle();
|
||||
return handle;
|
||||
}
|
||||
std::string reason;
|
||||
if (!gpu_data_manager->GpuAccessAllowed(&reason)) {
|
||||
promise->RejectWithErrorMessage("GPU access not allowed. Reason: " +
|
||||
reason);
|
||||
return promise->GetHandle();
|
||||
promise.RejectWithErrorMessage("GPU access not allowed. Reason: " + reason);
|
||||
return handle;
|
||||
}
|
||||
|
||||
auto* const info_mgr = GPUInfoManager::GetInstance();
|
||||
if (info_type == "complete") {
|
||||
#if defined(OS_WIN)
|
||||
info_mgr->FetchCompleteInfo(promise);
|
||||
#if defined(OS_WIN) || defined(OS_MACOSX)
|
||||
info_mgr->FetchCompleteInfo(std::move(promise));
|
||||
#else
|
||||
info_mgr->FetchBasicInfo(promise);
|
||||
info_mgr->FetchBasicInfo(std::move(promise));
|
||||
#endif
|
||||
} else /* (info_type == "basic") */ {
|
||||
info_mgr->FetchBasicInfo(promise);
|
||||
info_mgr->FetchBasicInfo(std::move(promise));
|
||||
}
|
||||
return promise->GetHandle();
|
||||
return handle;
|
||||
}
|
||||
|
||||
static void RemoveNoSandboxSwitch(base::CommandLine* command_line) {
|
||||
@@ -1211,19 +1251,6 @@ void App::EnableSandbox(mate::Arguments* args) {
|
||||
command_line->AppendSwitch(switches::kEnableSandbox);
|
||||
}
|
||||
|
||||
void App::EnableMixedSandbox(mate::Arguments* args) {
|
||||
if (Browser::Get()->is_ready()) {
|
||||
args->ThrowError(
|
||||
"app.enableMixedSandbox() can only be called "
|
||||
"before app is ready");
|
||||
return;
|
||||
}
|
||||
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
RemoveNoSandboxSwitch(command_line);
|
||||
command_line->AppendSwitch(switches::kEnableMixedSandbox);
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
bool App::MoveToApplicationsFolder(mate::Arguments* args) {
|
||||
return ui::cocoa::AtomBundleMover::Move(args);
|
||||
@@ -1282,8 +1309,15 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||
base::Bind(&Browser::InvalidateCurrentActivity, browser))
|
||||
.SetMethod("updateCurrentActivity",
|
||||
base::Bind(&Browser::UpdateCurrentActivity, browser))
|
||||
// TODO(juturu): Remove in 2.0, deprecate before then with warnings
|
||||
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
||||
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
||||
#endif
|
||||
#if defined(OS_MACOSX) || defined(OS_LINUX)
|
||||
.SetMethod("setAboutPanelOptions",
|
||||
base::Bind(&Browser::SetAboutPanelOptions, browser))
|
||||
.SetMethod("showAboutPanel",
|
||||
base::Bind(&Browser::ShowAboutPanel, browser))
|
||||
#endif
|
||||
#if defined(OS_WIN)
|
||||
.SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser))
|
||||
@@ -1300,6 +1334,7 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("getPath", &App::GetPath)
|
||||
.SetMethod("setDesktopName", &App::SetDesktopName)
|
||||
.SetMethod("getLocale", &App::GetLocale)
|
||||
.SetMethod("getLocaleCountryCode", &App::GetLocaleCountryCode)
|
||||
#if defined(USE_NSS_CERTS)
|
||||
.SetMethod("importCertificate", &App::ImportCertificate)
|
||||
#endif
|
||||
@@ -1319,17 +1354,11 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("getAppMetrics", &App::GetAppMetrics)
|
||||
.SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus)
|
||||
.SetMethod("getGPUInfo", &App::GetGPUInfo)
|
||||
// TODO(juturu): Remove in 2.0, deprecate before then with warnings
|
||||
#if defined(OS_MACOSX)
|
||||
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
||||
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
||||
#endif
|
||||
#if defined(MAS_BUILD)
|
||||
.SetMethod("startAccessingSecurityScopedResource",
|
||||
&App::StartAccessingSecurityScopedResource)
|
||||
#endif
|
||||
.SetMethod("enableSandbox", &App::EnableSandbox)
|
||||
.SetMethod("enableMixedSandbox", &App::EnableMixedSandbox);
|
||||
.SetMethod("enableSandbox", &App::EnableSandbox);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
@@ -1338,25 +1367,6 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||
|
||||
namespace {
|
||||
|
||||
void AppendSwitch(const std::string& switch_string, mate::Arguments* args) {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
if (base::EndsWith(switch_string, "-path",
|
||||
base::CompareCase::INSENSITIVE_ASCII) ||
|
||||
switch_string == network::switches::kLogNetLog) {
|
||||
base::FilePath path;
|
||||
args->GetNext(&path);
|
||||
command_line->AppendSwitchPath(switch_string, path);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string value;
|
||||
if (args->GetNext(&value))
|
||||
command_line->AppendSwitchASCII(switch_string, value);
|
||||
else
|
||||
command_line->AppendSwitch(switch_string);
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
int DockBounce(const std::string& type) {
|
||||
int request_id = -1;
|
||||
@@ -1377,14 +1387,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("App", atom::api::App::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("App", atom::api::App::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
dict.Set("app", atom::api::App::Create(isolate));
|
||||
dict.SetMethod("appendSwitch", &AppendSwitch);
|
||||
dict.SetMethod("appendArgument", base::Bind(&base::CommandLine::AppendArg,
|
||||
base::Unretained(command_line)));
|
||||
#if defined(OS_MACOSX)
|
||||
auto browser = base::Unretained(Browser::Get());
|
||||
dict.SetMethod("dockBounce", &DockBounce);
|
||||
@@ -1406,4 +1413,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_app, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_app, Initialize)
|
||||
|
||||
@@ -141,7 +141,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||
bool CanCreateWindow(content::RenderFrameHost* opener,
|
||||
const GURL& opener_url,
|
||||
const GURL& opener_top_level_frame_url,
|
||||
const GURL& source_origin,
|
||||
const url::Origin& source_origin,
|
||||
content::mojom::WindowContainerType container_type,
|
||||
const GURL& target_url,
|
||||
const content::Referrer& referrer,
|
||||
@@ -182,6 +182,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||
|
||||
void SetDesktopName(const std::string& desktop_name);
|
||||
std::string GetLocale();
|
||||
std::string GetLocaleCountryCode();
|
||||
void OnSecondInstance(const base::CommandLine::StringVector& cmd,
|
||||
const base::FilePath& cwd);
|
||||
bool HasSingleInstanceLock() const;
|
||||
@@ -191,20 +192,20 @@ class App : public AtomBrowserClient::Delegate,
|
||||
void DisableHardwareAcceleration(mate::Arguments* args);
|
||||
void DisableDomainBlockingFor3DAPIs(mate::Arguments* args);
|
||||
bool IsAccessibilitySupportEnabled();
|
||||
void SetAccessibilitySupportEnabled(bool enabled);
|
||||
void SetAccessibilitySupportEnabled(bool enabled, mate::Arguments* args);
|
||||
Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
|
||||
#if defined(USE_NSS_CERTS)
|
||||
void ImportCertificate(const base::DictionaryValue& options,
|
||||
const net::CompletionCallback& callback);
|
||||
#endif
|
||||
void GetFileIcon(const base::FilePath& path, mate::Arguments* args);
|
||||
v8::Local<v8::Promise> GetFileIcon(const base::FilePath& path,
|
||||
mate::Arguments* args);
|
||||
|
||||
std::vector<mate::Dictionary> GetAppMetrics(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
|
||||
v8::Local<v8::Promise> GetGPUInfo(v8::Isolate* isolate,
|
||||
const std::string& info_type);
|
||||
void EnableSandbox(mate::Arguments* args);
|
||||
void EnableMixedSandbox(mate::Arguments* args);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
bool MoveToApplicationsFolder(mate::Arguments* args);
|
||||
|
||||
@@ -147,9 +147,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("autoUpdater", AutoUpdater::Create(isolate));
|
||||
dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_auto_updater, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_auto_updater, Initialize)
|
||||
|
||||
@@ -66,6 +66,7 @@ void BrowserView::Init(v8::Isolate* isolate,
|
||||
|
||||
web_contents_.Reset(isolate, web_contents.ToV8());
|
||||
api_web_contents_ = web_contents.get();
|
||||
Observe(web_contents->web_contents());
|
||||
|
||||
view_.reset(
|
||||
NativeBrowserView::Create(api_web_contents_->managed_web_contents()));
|
||||
@@ -74,7 +75,16 @@ void BrowserView::Init(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
BrowserView::~BrowserView() {
|
||||
api_web_contents_->DestroyWebContents(true /* async */);
|
||||
if (api_web_contents_) { // destroy() is called
|
||||
// Destroy WebContents asynchronously unless app is shutting down,
|
||||
// because destroy() might be called inside WebContents's event handler.
|
||||
api_web_contents_->DestroyWebContents(!Browser::Get()->is_shutting_down());
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserView::WebContentsDestroyed() {
|
||||
api_web_contents_ = nullptr;
|
||||
web_contents_.Reset();
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -149,8 +159,9 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
BrowserView::SetConstructor(isolate, base::Bind(&BrowserView::New));
|
||||
|
||||
mate::Dictionary browser_view(
|
||||
isolate, BrowserView::GetConstructor(isolate)->GetFunction());
|
||||
mate::Dictionary browser_view(isolate, BrowserView::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
browser_view.SetMethod("fromId",
|
||||
&mate::TrackableObject<BrowserView>::FromWeakMapID);
|
||||
browser_view.SetMethod("getAllViews",
|
||||
@@ -161,4 +172,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_browser_view, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_browser_view, Initialize)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/native_browser_view.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
namespace gfx {
|
||||
@@ -29,7 +30,8 @@ namespace api {
|
||||
|
||||
class WebContents;
|
||||
|
||||
class BrowserView : public mate::TrackableObject<BrowserView> {
|
||||
class BrowserView : public mate::TrackableObject<BrowserView>,
|
||||
public content::WebContentsObserver {
|
||||
public:
|
||||
static mate::WrappableBase* New(mate::Arguments* args);
|
||||
|
||||
@@ -47,6 +49,9 @@ class BrowserView : public mate::TrackableObject<BrowserView> {
|
||||
const mate::Dictionary& options);
|
||||
~BrowserView() override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void WebContentsDestroyed() override;
|
||||
|
||||
private:
|
||||
void Init(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> wrapper,
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_owner_delegate.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "gin/converter.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/gl/gpu_switching_manager.h"
|
||||
|
||||
@@ -66,7 +68,7 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
web_contents_.Reset(isolate, web_contents.ToV8());
|
||||
api_web_contents_ = web_contents.get();
|
||||
api_web_contents_ = web_contents->GetWeakPtr();
|
||||
api_web_contents_->AddObserver(this);
|
||||
Observe(api_web_contents_->web_contents());
|
||||
|
||||
@@ -74,10 +76,6 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
||||
mate::Dictionary(isolate, web_contents->GetWrapper())
|
||||
.Set("browserWindowOptions", options);
|
||||
|
||||
// Tell the content module to initialize renderer widget with transparent
|
||||
// mode.
|
||||
ui::GpuSwitchingManager::SetTransparent(window()->transparent());
|
||||
|
||||
// Associate with BrowserWindow.
|
||||
web_contents->SetOwnerWindow(window());
|
||||
|
||||
@@ -88,8 +86,7 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
||||
InitWith(isolate, wrapper);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
if (!window()->has_frame())
|
||||
OverrideNSWindowContentView(web_contents->managed_web_contents());
|
||||
OverrideNSWindowContentView(web_contents->managed_web_contents());
|
||||
#endif
|
||||
|
||||
// Init window after everything has been setup.
|
||||
@@ -97,7 +94,9 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
BrowserWindow::~BrowserWindow() {
|
||||
api_web_contents_->RemoveObserver(this);
|
||||
// FIXME This is a hack rather than a proper fix preventing shutdown crashes.
|
||||
if (api_web_contents_)
|
||||
api_web_contents_->RemoveObserver(this);
|
||||
// Note that the OnWindowClosed will not be called after the destructor runs,
|
||||
// since the window object is managed by the TopLevelWindow class.
|
||||
if (web_contents())
|
||||
@@ -133,7 +132,7 @@ void BrowserWindow::RenderViewCreated(
|
||||
render_view_host->GetProcess()->GetID(),
|
||||
render_view_host->GetRoutingID());
|
||||
if (impl)
|
||||
impl->SetBackgroundOpaque(false);
|
||||
impl->owner_delegate()->SetBackgroundOpaque(false);
|
||||
}
|
||||
|
||||
void BrowserWindow::DidFirstVisuallyNonEmptyPaint() {
|
||||
@@ -185,7 +184,14 @@ bool BrowserWindow::OnMessageReceived(const IPC::Message& message,
|
||||
}
|
||||
|
||||
void BrowserWindow::OnCloseContents() {
|
||||
DCHECK(web_contents());
|
||||
// On some machines it may happen that the window gets destroyed for twice,
|
||||
// checking web_contents() can effectively guard against that.
|
||||
// https://github.com/electron/electron/issues/16202.
|
||||
//
|
||||
// TODO(zcbenz): We should find out the root cause and improve the closing
|
||||
// procedure of BrowserWindow.
|
||||
if (!web_contents())
|
||||
return;
|
||||
|
||||
// Close all child windows before closing current window.
|
||||
v8::Locker locker(isolate());
|
||||
@@ -234,7 +240,7 @@ void BrowserWindow::OnCloseButtonClicked(bool* prevent_default) {
|
||||
return;
|
||||
|
||||
if (web_contents()->NeedToFireBeforeUnload())
|
||||
web_contents()->DispatchBeforeUnload();
|
||||
web_contents()->DispatchBeforeUnload(false /* auto_cancel */);
|
||||
else
|
||||
web_contents()->Close();
|
||||
}
|
||||
@@ -307,7 +313,29 @@ void BrowserWindow::SetBackgroundColor(const std::string& color_name) {
|
||||
}
|
||||
|
||||
void BrowserWindow::SetBrowserView(v8::Local<v8::Value> value) {
|
||||
TopLevelWindow::SetBrowserView(value);
|
||||
TopLevelWindow::ResetBrowserViews();
|
||||
TopLevelWindow::AddBrowserView(value);
|
||||
#if defined(OS_MACOSX)
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BrowserWindow::AddBrowserView(v8::Local<v8::Value> value) {
|
||||
TopLevelWindow::AddBrowserView(value);
|
||||
#if defined(OS_MACOSX)
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BrowserWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
|
||||
TopLevelWindow::RemoveBrowserView(value);
|
||||
#if defined(OS_MACOSX)
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BrowserWindow::ResetBrowserViews() {
|
||||
TopLevelWindow::ResetBrowserViews();
|
||||
#if defined(OS_MACOSX)
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
#endif
|
||||
@@ -315,7 +343,7 @@ void BrowserWindow::SetBrowserView(v8::Local<v8::Value> value) {
|
||||
|
||||
void BrowserWindow::SetVibrancy(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> value) {
|
||||
std::string type = mate::V8ToString(value);
|
||||
std::string type = gin::V8ToString(isolate, value);
|
||||
|
||||
auto* render_view_host = web_contents()->GetRenderViewHost();
|
||||
if (render_view_host) {
|
||||
@@ -323,7 +351,8 @@ void BrowserWindow::SetVibrancy(v8::Isolate* isolate,
|
||||
render_view_host->GetProcess()->GetID(),
|
||||
render_view_host->GetRoutingID());
|
||||
if (impl)
|
||||
impl->SetBackgroundOpaque(type.empty() ? !window_->transparent() : false);
|
||||
impl->owner_delegate()->SetBackgroundOpaque(
|
||||
type.empty() ? !window_->transparent() : false);
|
||||
}
|
||||
|
||||
TopLevelWindow::SetVibrancy(isolate, value);
|
||||
@@ -385,7 +414,9 @@ void BrowserWindow::Cleanup() {
|
||||
if (host)
|
||||
host->GetWidget()->RemoveInputEventObserver(this);
|
||||
|
||||
api_web_contents_->DestroyWebContents(true /* async */);
|
||||
// Destroy WebContents asynchronously unless app is shutting down,
|
||||
// because destroy() might be called inside WebContents's event handler.
|
||||
api_web_contents_->DestroyWebContents(!Browser::Get()->is_shutting_down());
|
||||
Observe(nullptr);
|
||||
}
|
||||
|
||||
@@ -451,4 +482,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_window, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_window, Initialize)
|
||||
|
||||
@@ -72,6 +72,9 @@ class BrowserWindow : public TopLevelWindow,
|
||||
void Blur() override;
|
||||
void SetBackgroundColor(const std::string& color_name) override;
|
||||
void SetBrowserView(v8::Local<v8::Value> value) override;
|
||||
void AddBrowserView(v8::Local<v8::Value> value) override;
|
||||
void RemoveBrowserView(v8::Local<v8::Value> value) override;
|
||||
void ResetBrowserViews() override;
|
||||
void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value) override;
|
||||
|
||||
// BrowserWindow APIs.
|
||||
@@ -82,7 +85,7 @@ class BrowserWindow : public TopLevelWindow,
|
||||
|
||||
private:
|
||||
#if defined(OS_MACOSX)
|
||||
void OverrideNSWindowContentView(brightray::InspectableWebContents* iwc);
|
||||
void OverrideNSWindowContentView(InspectableWebContents* iwc);
|
||||
#endif
|
||||
|
||||
// Helpers.
|
||||
@@ -113,7 +116,7 @@ class BrowserWindow : public TopLevelWindow,
|
||||
#endif
|
||||
|
||||
v8::Global<v8::Value> web_contents_;
|
||||
api::WebContents* api_web_contents_;
|
||||
base::WeakPtr<api::WebContents> api_web_contents_;
|
||||
|
||||
base::WeakPtrFactory<BrowserWindow> weak_factory_;
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#include "atom/browser/native_browser_view.h"
|
||||
#include "atom/browser/native_window_mac.h"
|
||||
#include "atom/browser/ui/inspectable_web_contents_view.h"
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||
|
||||
@interface NSView (WebContentsView)
|
||||
- (void)setMouseDownCanMoveWindow:(BOOL)can_move;
|
||||
@@ -55,15 +55,20 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
|
||||
|
||||
} // namespace
|
||||
|
||||
void BrowserWindow::OverrideNSWindowContentView(
|
||||
brightray::InspectableWebContents* iwc) {
|
||||
void BrowserWindow::OverrideNSWindowContentView(InspectableWebContents* iwc) {
|
||||
// Make NativeWindow use a NSView as content view.
|
||||
static_cast<NativeWindowMac*>(window())->OverrideNSWindowContentView();
|
||||
// Add webview to contentView.
|
||||
NSView* webView = iwc->GetView()->GetNativeView();
|
||||
NSView* contentView = [window()->GetNativeWindow() contentView];
|
||||
NSView* webView = iwc->GetView()->GetNativeView().GetNativeNSView();
|
||||
NSView* contentView =
|
||||
[window()->GetNativeWindow().GetNativeNSWindow() contentView];
|
||||
[webView setFrame:[contentView bounds]];
|
||||
[contentView addSubview:webView];
|
||||
|
||||
// ensure that buttons view is floated to top of view hierarchy
|
||||
NSArray* subviews = [contentView subviews];
|
||||
NSView* last = subviews.lastObject;
|
||||
[contentView addSubview:webView positioned:NSWindowBelow relativeTo:last];
|
||||
|
||||
[contentView viewDidMoveToWindow];
|
||||
}
|
||||
|
||||
@@ -76,7 +81,7 @@ void BrowserWindow::UpdateDraggableRegions(
|
||||
// All ControlRegionViews should be added as children of the WebContentsView,
|
||||
// because WebContentsView will be removed and re-added when entering and
|
||||
// leaving fullscreen mode.
|
||||
NSView* webView = web_contents()->GetNativeView();
|
||||
NSView* webView = web_contents()->GetNativeView().GetNativeNSView();
|
||||
NSInteger webViewWidth = NSWidth([webView bounds]);
|
||||
NSInteger webViewHeight = NSHeight([webView bounds]);
|
||||
|
||||
@@ -104,8 +109,10 @@ void BrowserWindow::UpdateDraggableRegions(
|
||||
DraggableRegionsToSkRegion(regions), webViewWidth, webViewHeight);
|
||||
}
|
||||
|
||||
if (window_->browser_view())
|
||||
window_->browser_view()->UpdateDraggableRegions(drag_exclude_rects);
|
||||
auto browser_views = window_->browser_views();
|
||||
for (NativeBrowserView* view : browser_views) {
|
||||
(view)->UpdateDraggableRegions(drag_exclude_rects);
|
||||
}
|
||||
|
||||
// Create and add a ControlRegionView for each region that needs to be
|
||||
// excluded from the dragging.
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/promise_util.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "content/public/browser/tracing_controller.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
@@ -23,15 +26,27 @@ struct Converter<base::trace_event::TraceConfig> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::trace_event::TraceConfig* out) {
|
||||
// (alexeykuzmin): A combination of "categoryFilter" and "traceOptions"
|
||||
// has to be checked first because none of the fields
|
||||
// in the `memory_dump_config` dict below are mandatory
|
||||
// and we cannot check the config format.
|
||||
Dictionary options;
|
||||
if (!ConvertFromV8(isolate, val, &options))
|
||||
return false;
|
||||
std::string category_filter, trace_options;
|
||||
if (!options.Get("categoryFilter", &category_filter) ||
|
||||
!options.Get("traceOptions", &trace_options))
|
||||
return false;
|
||||
*out = base::trace_event::TraceConfig(category_filter, trace_options);
|
||||
return true;
|
||||
if (ConvertFromV8(isolate, val, &options)) {
|
||||
std::string category_filter, trace_options;
|
||||
if (options.Get("categoryFilter", &category_filter) &&
|
||||
options.Get("traceOptions", &trace_options)) {
|
||||
*out = base::trace_event::TraceConfig(category_filter, trace_options);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
base::DictionaryValue memory_dump_config;
|
||||
if (ConvertFromV8(isolate, val, &memory_dump_config)) {
|
||||
*out = base::trace_event::TraceConfig(memory_dump_config);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,6 +60,11 @@ scoped_refptr<TracingController::TraceDataEndpoint> GetTraceDataEndpoint(
|
||||
const base::FilePath& path,
|
||||
const CompletionCallback& callback) {
|
||||
base::FilePath result_file_path = path;
|
||||
|
||||
// base::CreateTemporaryFile prevents blocking so we need to allow it
|
||||
// for now since offloading this to a different sequence would require
|
||||
// changing the api shape
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
if (result_file_path.empty() && !base::CreateTemporaryFile(&result_file_path))
|
||||
LOG(ERROR) << "Creating temporary file failed";
|
||||
|
||||
@@ -52,28 +72,72 @@ scoped_refptr<TracingController::TraceDataEndpoint> GetTraceDataEndpoint(
|
||||
result_file_path, base::Bind(callback, result_file_path));
|
||||
}
|
||||
|
||||
void StopRecording(const base::FilePath& path,
|
||||
const CompletionCallback& callback) {
|
||||
TracingController::GetInstance()->StopTracing(
|
||||
GetTraceDataEndpoint(path, callback));
|
||||
void OnRecordingStopped(const atom::util::CopyablePromise& promise,
|
||||
const base::FilePath& path) {
|
||||
promise.GetPromise().Resolve(path);
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> StopRecording(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
atom::util::Promise promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
// TODO(zcbenz): Remove the use of CopyablePromise when the
|
||||
// CreateFileEndpoint API accepts OnceCallback.
|
||||
TracingController::GetInstance()->StopTracing(GetTraceDataEndpoint(
|
||||
path,
|
||||
base::Bind(&OnRecordingStopped, atom::util::CopyablePromise(promise))));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void OnCategoriesAvailable(atom::util::Promise promise,
|
||||
const std::set<std::string>& categories) {
|
||||
promise.Resolve(categories);
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
|
||||
atom::util::Promise promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
// Note: This method always succeeds.
|
||||
TracingController::GetInstance()->GetCategories(
|
||||
base::BindOnce(&OnCategoriesAvailable, std::move(promise)));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void OnTracingStarted(atom::util::Promise promise) {
|
||||
promise.Resolve();
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> StartTracing(
|
||||
v8::Isolate* isolate,
|
||||
const base::trace_event::TraceConfig& trace_config) {
|
||||
atom::util::Promise promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
// Note: This method always succeeds.
|
||||
TracingController::GetInstance()->StartTracing(
|
||||
trace_config, base::BindOnce(&OnTracingStarted, std::move(promise)));
|
||||
return handle;
|
||||
}
|
||||
|
||||
bool GetTraceBufferUsage(
|
||||
const base::RepeatingCallback<void(float, size_t)>& callback) {
|
||||
return TracingController::GetInstance()->GetTraceBufferUsage(
|
||||
base::BindOnce(callback));
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
auto controller = base::Unretained(TracingController::GetInstance());
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
dict.SetMethod("getCategories",
|
||||
base::Bind(&TracingController::GetCategories, controller));
|
||||
dict.SetMethod("startRecording",
|
||||
base::Bind(&TracingController::StartTracing, controller));
|
||||
dict.SetMethod("getCategories", &GetCategories);
|
||||
dict.SetMethod("startRecording", &StartTracing);
|
||||
dict.SetMethod("stopRecording", &StopRecording);
|
||||
dict.SetMethod(
|
||||
"getTraceBufferUsage",
|
||||
base::Bind(&TracingController::GetTraceBufferUsage, controller));
|
||||
dict.SetMethod("getTraceBufferUsage", &GetTraceBufferUsage);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_content_tracing, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_content_tracing, Initialize)
|
||||
|
||||
@@ -12,9 +12,11 @@
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
@@ -134,74 +136,103 @@ inline net::CookieStore* GetCookieStore(
|
||||
return getter->GetURLRequestContext()->cookie_store();
|
||||
}
|
||||
|
||||
void ResolvePromiseWithCookies(util::Promise promise,
|
||||
const net::CookieList& cookie_list) {
|
||||
promise.Resolve(cookie_list);
|
||||
}
|
||||
|
||||
void ResolvePromise(util::Promise promise) {
|
||||
promise.Resolve();
|
||||
}
|
||||
|
||||
// Resolve |promise| in UI thread.
|
||||
void ResolvePromiseInUI(util::Promise promise) {
|
||||
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
|
||||
base::BindOnce(ResolvePromise, std::move(promise)));
|
||||
}
|
||||
|
||||
// Run |callback| on UI thread.
|
||||
void RunCallbackInUI(const base::Closure& callback) {
|
||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
|
||||
void RunCallbackInUI(base::OnceClosure callback) {
|
||||
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, std::move(callback));
|
||||
}
|
||||
|
||||
// Remove cookies from |list| not matching |filter|, and pass it to |callback|.
|
||||
void FilterCookies(std::unique_ptr<base::DictionaryValue> filter,
|
||||
const Cookies::GetCallback& callback,
|
||||
util::Promise promise,
|
||||
const net::CookieList& list) {
|
||||
net::CookieList result;
|
||||
for (const auto& cookie : list) {
|
||||
if (MatchesCookie(filter.get(), cookie))
|
||||
result.push_back(cookie);
|
||||
}
|
||||
RunCallbackInUI(base::Bind(callback, Cookies::SUCCESS, result));
|
||||
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::UI},
|
||||
base::BindOnce(ResolvePromiseWithCookies, std::move(promise), result));
|
||||
}
|
||||
|
||||
// Receives cookies matching |filter| in IO thread.
|
||||
void GetCookiesOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
std::unique_ptr<base::DictionaryValue> filter,
|
||||
const Cookies::GetCallback& callback) {
|
||||
util::Promise promise) {
|
||||
std::string url;
|
||||
filter->GetString("url", &url);
|
||||
|
||||
auto filtered_callback =
|
||||
base::Bind(FilterCookies, base::Passed(&filter), callback);
|
||||
base::BindOnce(FilterCookies, std::move(filter), std::move(promise));
|
||||
|
||||
// Empty url will match all url cookies.
|
||||
if (url.empty())
|
||||
GetCookieStore(getter)->GetAllCookiesAsync(filtered_callback);
|
||||
GetCookieStore(getter)->GetAllCookiesAsync(std::move(filtered_callback));
|
||||
else
|
||||
GetCookieStore(getter)->GetAllCookiesForURLAsync(GURL(url),
|
||||
filtered_callback);
|
||||
GetCookieStore(getter)->GetAllCookiesForURLAsync(
|
||||
GURL(url), std::move(filtered_callback));
|
||||
}
|
||||
|
||||
// Removes cookie with |url| and |name| in IO thread.
|
||||
void RemoveCookieOnIOThread(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
const GURL& url,
|
||||
const std::string& name,
|
||||
const base::Closure& callback) {
|
||||
void RemoveCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
const GURL& url,
|
||||
const std::string& name,
|
||||
util::Promise promise) {
|
||||
GetCookieStore(getter)->DeleteCookieAsync(
|
||||
url, name, base::BindOnce(RunCallbackInUI, callback));
|
||||
url, name, base::BindOnce(ResolvePromiseInUI, std::move(promise)));
|
||||
}
|
||||
|
||||
// Resolves/rejects the |promise| in UI thread.
|
||||
void SettlePromiseInUI(util::Promise promise, const std::string& errmsg) {
|
||||
if (errmsg.empty()) {
|
||||
promise.Resolve();
|
||||
} else {
|
||||
promise.RejectWithErrorMessage(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
// Callback of SetCookie.
|
||||
void OnSetCookie(const Cookies::SetCallback& callback, bool success) {
|
||||
void OnSetCookie(util::Promise promise, bool success) {
|
||||
const std::string errmsg = success ? "" : "Setting cookie failed";
|
||||
RunCallbackInUI(
|
||||
base::Bind(callback, success ? Cookies::SUCCESS : Cookies::FAILED));
|
||||
base::BindOnce(SettlePromiseInUI, std::move(promise), errmsg));
|
||||
}
|
||||
|
||||
// Flushes cookie store in IO thread.
|
||||
void FlushCookieStoreOnIOThread(
|
||||
scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
const base::Closure& callback) {
|
||||
GetCookieStore(getter)->FlushStore(base::BindOnce(RunCallbackInUI, callback));
|
||||
util::Promise promise) {
|
||||
GetCookieStore(getter)->FlushStore(
|
||||
base::BindOnce(ResolvePromiseInUI, std::move(promise)));
|
||||
}
|
||||
|
||||
// Sets cookie with |details| in IO thread.
|
||||
void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
std::unique_ptr<base::DictionaryValue> details,
|
||||
const Cookies::SetCallback& callback) {
|
||||
std::string url, name, value, domain, path;
|
||||
util::Promise promise) {
|
||||
std::string url_string, name, value, domain, path;
|
||||
bool secure = false;
|
||||
bool http_only = false;
|
||||
double creation_date;
|
||||
double expiration_date;
|
||||
double last_access_date;
|
||||
details->GetString("url", &url);
|
||||
details->GetString("url", &url_string);
|
||||
details->GetString("name", &name);
|
||||
details->GetString("value", &value);
|
||||
details->GetString("domain", &domain);
|
||||
@@ -230,24 +261,27 @@ void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
: base::Time::FromDoubleT(last_access_date);
|
||||
}
|
||||
|
||||
auto completion_callback = base::BindOnce(OnSetCookie, std::move(promise));
|
||||
GURL url(url_string);
|
||||
if (!url.is_valid()) {
|
||||
std::move(completion_callback).Run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name.empty()) {
|
||||
std::move(completion_callback).Run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<net::CanonicalCookie> canonical_cookie(
|
||||
net::CanonicalCookie::CreateSanitizedCookie(
|
||||
GURL(url), name, value, domain, path, creation_time, expiration_time,
|
||||
url, name, value, domain, path, creation_time, expiration_time,
|
||||
last_access_time, secure, http_only,
|
||||
net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT));
|
||||
auto completion_callback = base::BindOnce(OnSetCookie, callback);
|
||||
if (!canonical_cookie || !canonical_cookie->IsCanonical()) {
|
||||
std::move(completion_callback).Run(false);
|
||||
return;
|
||||
}
|
||||
if (url.empty()) {
|
||||
std::move(completion_callback).Run(false);
|
||||
return;
|
||||
}
|
||||
if (name.empty()) {
|
||||
std::move(completion_callback).Run(false);
|
||||
return;
|
||||
}
|
||||
GetCookieStore(getter)->SetCanonicalCookieAsync(
|
||||
std::move(canonical_cookie), secure, http_only,
|
||||
std::move(completion_callback));
|
||||
@@ -265,44 +299,61 @@ Cookies::Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||
|
||||
Cookies::~Cookies() {}
|
||||
|
||||
void Cookies::Get(const base::DictionaryValue& filter,
|
||||
const GetCallback& callback) {
|
||||
v8::Local<v8::Promise> Cookies::Get(const base::DictionaryValue& filter) {
|
||||
util::Promise promise(isolate());
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
auto copy = base::DictionaryValue::From(
|
||||
base::Value::ToUniquePtrValue(filter.Clone()));
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
content::BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(GetCookiesOnIO, base::RetainedRef(getter), std::move(copy),
|
||||
callback));
|
||||
std::move(promise)));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Cookies::Remove(const GURL& url,
|
||||
const std::string& name,
|
||||
const base::Closure& callback) {
|
||||
v8::Local<v8::Promise> Cookies::Remove(const GURL& url,
|
||||
const std::string& name) {
|
||||
util::Promise promise(isolate());
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
content::BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(RemoveCookieOnIOThread, base::RetainedRef(getter), url,
|
||||
name, callback));
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(RemoveCookieOnIO, base::RetainedRef(getter), url, name,
|
||||
std::move(promise)));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Cookies::Set(const base::DictionaryValue& details,
|
||||
const SetCallback& callback) {
|
||||
v8::Local<v8::Promise> Cookies::Set(const base::DictionaryValue& details) {
|
||||
util::Promise promise(isolate());
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
auto copy = base::DictionaryValue::From(
|
||||
base::Value::ToUniquePtrValue(details.Clone()));
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
content::BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(SetCookieOnIO, base::RetainedRef(getter), std::move(copy),
|
||||
callback));
|
||||
std::move(promise)));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Cookies::FlushStore(const base::Closure& callback) {
|
||||
v8::Local<v8::Promise> Cookies::FlushStore() {
|
||||
util::Promise promise(isolate());
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
content::BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(FlushCookieStoreOnIOThread, base::RetainedRef(getter),
|
||||
callback));
|
||||
std::move(promise)));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Cookies::OnCookieChanged(const CookieDetails* details) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/net/cookie_details.h"
|
||||
#include "atom/common/promise_util.h"
|
||||
#include "base/callback_list.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "net/cookies/canonical_cookie.h"
|
||||
@@ -35,9 +36,6 @@ class Cookies : public mate::TrackableObject<Cookies> {
|
||||
FAILED,
|
||||
};
|
||||
|
||||
using GetCallback = base::Callback<void(Error, const net::CookieList&)>;
|
||||
using SetCallback = base::Callback<void(Error)>;
|
||||
|
||||
static mate::Handle<Cookies> Create(v8::Isolate* isolate,
|
||||
AtomBrowserContext* browser_context);
|
||||
|
||||
@@ -49,12 +47,10 @@ class Cookies : public mate::TrackableObject<Cookies> {
|
||||
Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
~Cookies() override;
|
||||
|
||||
void Get(const base::DictionaryValue& filter, const GetCallback& callback);
|
||||
void Remove(const GURL& url,
|
||||
const std::string& name,
|
||||
const base::Closure& callback);
|
||||
void Set(const base::DictionaryValue& details, const SetCallback& callback);
|
||||
void FlushStore(const base::Closure& callback);
|
||||
v8::Local<v8::Promise> Get(const base::DictionaryValue& filter);
|
||||
v8::Local<v8::Promise> Set(const base::DictionaryValue& details);
|
||||
v8::Local<v8::Promise> Remove(const GURL& url, const std::string& name);
|
||||
v8::Local<v8::Promise> FlushStore();
|
||||
|
||||
// CookieChangeNotifier subscription:
|
||||
void OnCookieChanged(const CookieDetails*);
|
||||
|
||||
@@ -61,23 +61,26 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
|
||||
params.Swap(params_value);
|
||||
Emit("message", method, params);
|
||||
} else {
|
||||
auto send_command_callback = pending_requests_[id];
|
||||
pending_requests_.erase(id);
|
||||
if (send_command_callback.is_null())
|
||||
auto it = pending_requests_.find(id);
|
||||
if (it == pending_requests_.end())
|
||||
return;
|
||||
base::DictionaryValue* error_body = nullptr;
|
||||
base::DictionaryValue error;
|
||||
bool has_error;
|
||||
if ((has_error = dict->GetDictionary("error", &error_body))) {
|
||||
error.Swap(error_body);
|
||||
}
|
||||
|
||||
base::DictionaryValue* result_body = nullptr;
|
||||
base::DictionaryValue result;
|
||||
if (dict->GetDictionary("result", &result_body))
|
||||
result.Swap(result_body);
|
||||
send_command_callback.Run(has_error ? error.Clone() : base::Value(),
|
||||
result);
|
||||
atom::util::Promise promise = std::move(it->second);
|
||||
pending_requests_.erase(it);
|
||||
|
||||
base::DictionaryValue* error = nullptr;
|
||||
if (dict->GetDictionary("error", &error)) {
|
||||
std::string message;
|
||||
error->GetString("message", &message);
|
||||
promise.RejectWithErrorMessage(message);
|
||||
} else {
|
||||
base::DictionaryValue* result_body = nullptr;
|
||||
base::DictionaryValue result;
|
||||
if (dict->GetDictionary("result", &result_body)) {
|
||||
result.Swap(result_body);
|
||||
}
|
||||
promise.Resolve(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,23 +128,27 @@ void Debugger::Detach() {
|
||||
AgentHostClosed(agent_host_.get());
|
||||
}
|
||||
|
||||
void Debugger::SendCommand(mate::Arguments* args) {
|
||||
if (!agent_host_)
|
||||
return;
|
||||
v8::Local<v8::Promise> Debugger::SendCommand(mate::Arguments* args) {
|
||||
atom::util::Promise promise(isolate());
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
if (!agent_host_) {
|
||||
promise.RejectWithErrorMessage("No target available");
|
||||
return handle;
|
||||
}
|
||||
|
||||
std::string method;
|
||||
if (!args->GetNext(&method)) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
promise.RejectWithErrorMessage("Invalid method");
|
||||
return handle;
|
||||
}
|
||||
|
||||
base::DictionaryValue command_params;
|
||||
args->GetNext(&command_params);
|
||||
SendCommandCallback callback;
|
||||
args->GetNext(&callback);
|
||||
|
||||
base::DictionaryValue request;
|
||||
int request_id = ++previous_request_id_;
|
||||
pending_requests_[request_id] = callback;
|
||||
pending_requests_.emplace(request_id, std::move(promise));
|
||||
request.SetInteger("id", request_id);
|
||||
request.SetString("method", method);
|
||||
if (!command_params.empty())
|
||||
@@ -151,16 +158,13 @@ void Debugger::SendCommand(mate::Arguments* args) {
|
||||
std::string json_args;
|
||||
base::JSONWriter::Write(request, &json_args);
|
||||
agent_host_->DispatchProtocolMessage(this, json_args);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Debugger::ClearPendingRequests() {
|
||||
if (pending_requests_.empty())
|
||||
return;
|
||||
base::Value error(base::Value::Type::DICTIONARY);
|
||||
base::Value error_msg("target closed while handling command");
|
||||
error.SetKey("message", std::move(error_msg));
|
||||
for (const auto& it : pending_requests_)
|
||||
it.second.Run(error, base::Value());
|
||||
for (auto& it : pending_requests_)
|
||||
it.second.RejectWithErrorMessage("target closed while handling command");
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -194,9 +198,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary(isolate, exports)
|
||||
.Set("Debugger", Debugger::GetConstructor(isolate)->GetFunction());
|
||||
.Set("Debugger", Debugger::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_debugger, Initialize);
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_debugger, Initialize);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/common/promise_util.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/devtools_agent_host_client.h"
|
||||
@@ -32,9 +33,6 @@ class Debugger : public mate::TrackableObject<Debugger>,
|
||||
public content::DevToolsAgentHostClient,
|
||||
public content::WebContentsObserver {
|
||||
public:
|
||||
using SendCommandCallback =
|
||||
base::Callback<void(const base::Value&, const base::Value&)>;
|
||||
|
||||
static mate::Handle<Debugger> Create(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents);
|
||||
|
||||
@@ -56,12 +54,12 @@ class Debugger : public mate::TrackableObject<Debugger>,
|
||||
content::RenderFrameHost* new_rfh) override;
|
||||
|
||||
private:
|
||||
using PendingRequestMap = std::map<int, SendCommandCallback>;
|
||||
using PendingRequestMap = std::map<int, atom::util::Promise>;
|
||||
|
||||
void Attach(mate::Arguments* args);
|
||||
bool IsAttached();
|
||||
void Detach();
|
||||
void SendCommand(mate::Arguments* args);
|
||||
v8::Local<v8::Promise> SendCommand(mate::Arguments* args);
|
||||
void ClearPendingRequests();
|
||||
|
||||
content::WebContents* web_contents_; // Weak Reference.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "chrome/browser/media/webrtc/desktop_media_list.h"
|
||||
#include "chrome/browser/media/webrtc/window_icon_util.h"
|
||||
#include "content/public/browser/desktop_capture.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
|
||||
@@ -42,6 +43,12 @@ struct Converter<atom::api::DesktopCapturer::Source> {
|
||||
atom::api::NativeImage::Create(
|
||||
isolate, gfx::Image(source.media_list_source.thumbnail)));
|
||||
dict.Set("display_id", source.display_id);
|
||||
if (source.fetch_icon) {
|
||||
dict.Set(
|
||||
"appIcon",
|
||||
atom::api::NativeImage::Create(
|
||||
isolate, gfx::Image(GetWindowIcon(source.media_list_source.id))));
|
||||
}
|
||||
return ConvertToV8(isolate, dict);
|
||||
}
|
||||
};
|
||||
@@ -60,7 +67,9 @@ DesktopCapturer::~DesktopCapturer() {}
|
||||
|
||||
void DesktopCapturer::StartHandling(bool capture_window,
|
||||
bool capture_screen,
|
||||
const gfx::Size& thumbnail_size) {
|
||||
const gfx::Size& thumbnail_size,
|
||||
bool fetch_window_icons) {
|
||||
fetch_window_icons_ = fetch_window_icons;
|
||||
#if defined(OS_WIN)
|
||||
if (content::desktop_capture::CreateDesktopCaptureOptions()
|
||||
.allow_directx_capturer()) {
|
||||
@@ -79,10 +88,6 @@ void DesktopCapturer::StartHandling(bool capture_window,
|
||||
capture_screen_ = capture_screen;
|
||||
|
||||
{
|
||||
// Remove this once
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=795340 is fixed.
|
||||
base::ScopedAllowBaseSyncPrimitivesForTesting
|
||||
scoped_allow_base_sync_primitives;
|
||||
// Initialize the source list.
|
||||
// Apply the new thumbnail size and restart capture.
|
||||
if (capture_window) {
|
||||
@@ -134,8 +139,8 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
|
||||
capture_window_ = false;
|
||||
const auto& media_list_sources = list->GetSources();
|
||||
for (const auto& media_list_source : media_list_sources) {
|
||||
window_sources.emplace_back(
|
||||
DesktopCapturer::Source{media_list_source, std::string()});
|
||||
window_sources.emplace_back(DesktopCapturer::Source{
|
||||
media_list_source, std::string(), fetch_window_icons_});
|
||||
}
|
||||
std::move(window_sources.begin(), window_sources.end(),
|
||||
std::back_inserter(captured_sources_));
|
||||
@@ -187,7 +192,7 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
|
||||
}
|
||||
|
||||
if (!capture_window_ && !capture_screen_)
|
||||
Emit("finished", captured_sources_);
|
||||
Emit("finished", captured_sources_, fetch_window_icons_);
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -221,4 +226,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_desktop_capturer, Initialize);
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_desktop_capturer, Initialize);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "chrome/browser/media/webrtc/desktop_media_list_observer.h"
|
||||
#include "chrome/browser/media/webrtc/native_desktop_media_list.h"
|
||||
#include "native_mate/handle.h"
|
||||
@@ -18,13 +18,16 @@ namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
class DesktopCapturer : public mate::EventEmitter<DesktopCapturer>,
|
||||
class DesktopCapturer : public mate::TrackableObject<DesktopCapturer>,
|
||||
public DesktopMediaListObserver {
|
||||
public:
|
||||
struct Source {
|
||||
DesktopMediaList::Source media_list_source;
|
||||
// Will be an empty string if not available.
|
||||
std::string display_id;
|
||||
|
||||
// Whether or not this source should provide an icon.
|
||||
bool fetch_icon = false;
|
||||
};
|
||||
|
||||
static mate::Handle<DesktopCapturer> Create(v8::Isolate* isolate);
|
||||
@@ -34,7 +37,8 @@ class DesktopCapturer : public mate::EventEmitter<DesktopCapturer>,
|
||||
|
||||
void StartHandling(bool capture_window,
|
||||
bool capture_screen,
|
||||
const gfx::Size& thumbnail_size);
|
||||
const gfx::Size& thumbnail_size,
|
||||
bool fetch_window_icons);
|
||||
|
||||
protected:
|
||||
explicit DesktopCapturer(v8::Isolate* isolate);
|
||||
@@ -59,6 +63,7 @@ class DesktopCapturer : public mate::EventEmitter<DesktopCapturer>,
|
||||
std::vector<DesktopCapturer::Source> captured_sources_;
|
||||
bool capture_window_ = false;
|
||||
bool capture_screen_ = false;
|
||||
bool fetch_window_icons_ = false;
|
||||
#if defined(OS_WIN)
|
||||
bool using_directx_capturer_ = false;
|
||||
#endif // defined(OS_WIN)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
#include "atom/browser/ui/message_box.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/file_dialog_converter.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/image_converter.h"
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
@@ -19,50 +20,6 @@
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
template <>
|
||||
struct Converter<file_dialog::Filter> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
file_dialog::Filter* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
if (!dict.Get("name", &(out->first)))
|
||||
return false;
|
||||
if (!dict.Get("extensions", &(out->second)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<file_dialog::DialogSettings> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
file_dialog::DialogSettings* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
dict.Get("window", &(out->parent_window));
|
||||
dict.Get("title", &(out->title));
|
||||
dict.Get("message", &(out->message));
|
||||
dict.Get("buttonLabel", &(out->button_label));
|
||||
dict.Get("nameFieldLabel", &(out->name_field_label));
|
||||
dict.Get("defaultPath", &(out->default_path));
|
||||
dict.Get("filters", &(out->filters));
|
||||
dict.Get("properties", &(out->properties));
|
||||
dict.Get("showsTagField", &(out->shows_tag_field));
|
||||
#if defined(MAS_BUILD)
|
||||
dict.Get("securityScopedBookmarks", &(out->security_scoped_bookmarks));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
namespace {
|
||||
|
||||
void ShowMessageBox(int type,
|
||||
@@ -139,4 +96,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_dialog, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_dialog, Initialize)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/file_dialog_converter.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
@@ -102,7 +103,7 @@ bool DownloadItem::IsPaused() const {
|
||||
}
|
||||
|
||||
void DownloadItem::Resume() {
|
||||
download_item_->Resume();
|
||||
download_item_->Resume(true /* user_gesture */);
|
||||
}
|
||||
|
||||
bool DownloadItem::CanResume() const {
|
||||
@@ -165,6 +166,15 @@ base::FilePath DownloadItem::GetSavePath() const {
|
||||
return save_path_;
|
||||
}
|
||||
|
||||
file_dialog::DialogSettings DownloadItem::GetSaveDialogOptions() const {
|
||||
return dialog_options_;
|
||||
}
|
||||
|
||||
void DownloadItem::SetSaveDialogOptions(
|
||||
const file_dialog::DialogSettings& options) {
|
||||
dialog_options_ = options;
|
||||
}
|
||||
|
||||
std::string DownloadItem::GetLastModifiedTime() const {
|
||||
return download_item_->GetLastModifiedTime();
|
||||
}
|
||||
@@ -200,6 +210,8 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("isDone", &DownloadItem::IsDone)
|
||||
.SetMethod("setSavePath", &DownloadItem::SetSavePath)
|
||||
.SetMethod("getSavePath", &DownloadItem::GetSavePath)
|
||||
.SetMethod("setSaveDialogOptions", &DownloadItem::SetSaveDialogOptions)
|
||||
.SetMethod("getSaveDialogOptions", &DownloadItem::GetSaveDialogOptions)
|
||||
.SetMethod("getLastModifiedTime", &DownloadItem::GetLastModifiedTime)
|
||||
.SetMethod("getETag", &DownloadItem::GetETag)
|
||||
.SetMethod("getStartTime", &DownloadItem::GetStartTime);
|
||||
@@ -232,10 +244,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary(isolate, exports)
|
||||
.Set("DownloadItem",
|
||||
atom::api::DownloadItem::GetConstructor(isolate)->GetFunction());
|
||||
.Set("DownloadItem", atom::api::DownloadItem::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_download_item, Initialize);
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_download_item, Initialize);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "components/download/public/common/download_item.h"
|
||||
#include "native_mate/handle.h"
|
||||
@@ -44,6 +45,8 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
|
||||
bool IsDone() const;
|
||||
void SetSavePath(const base::FilePath& path);
|
||||
base::FilePath GetSavePath() const;
|
||||
file_dialog::DialogSettings GetSaveDialogOptions() const;
|
||||
void SetSaveDialogOptions(const file_dialog::DialogSettings& options);
|
||||
std::string GetLastModifiedTime() const;
|
||||
std::string GetETag() const;
|
||||
double GetStartTime() const;
|
||||
@@ -58,6 +61,7 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
|
||||
|
||||
private:
|
||||
base::FilePath save_path_;
|
||||
file_dialog::DialogSettings dialog_options_;
|
||||
download::DownloadItem* download_item_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DownloadItem);
|
||||
|
||||
26
atom/browser/api/atom_api_event.cc
Normal file
26
atom/browser/api/atom_api_event.cc
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
namespace {
|
||||
|
||||
v8::Local<v8::Object> CreateWithSender(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> sender) {
|
||||
return mate::internal::CreateJSEvent(isolate, sender, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
dict.SetMethod("createWithSender", &CreateWithSender);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_event, Initialize)
|
||||
@@ -5,16 +5,46 @@
|
||||
#include "atom/browser/api/atom_api_global_shortcut.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/atom_api_system_preferences.h"
|
||||
#include "atom/common/native_mate_converters/accelerator_converter.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include "base/mac/mac_util.h"
|
||||
#endif
|
||||
|
||||
using extensions::GlobalShortcutListener;
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
bool RegisteringMediaKeyForUntrustedClient(const ui::Accelerator& accelerator) {
|
||||
if (base::mac::IsAtLeastOS10_14()) {
|
||||
constexpr ui::KeyboardCode mediaKeys[] = {
|
||||
ui::VKEY_MEDIA_PLAY_PAUSE, ui::VKEY_MEDIA_NEXT_TRACK,
|
||||
ui::VKEY_MEDIA_PREV_TRACK, ui::VKEY_MEDIA_STOP};
|
||||
|
||||
if (std::find(std::begin(mediaKeys), std::end(mediaKeys),
|
||||
accelerator.key_code()) != std::end(mediaKeys)) {
|
||||
bool trusted =
|
||||
atom::api::SystemPreferences::IsTrustedAccessibilityClient(false);
|
||||
if (!trusted)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
@@ -31,15 +61,43 @@ void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) {
|
||||
if (accelerator_callback_map_.find(accelerator) ==
|
||||
accelerator_callback_map_.end()) {
|
||||
// This should never occur, because if it does, GlobalGlobalShortcutListener
|
||||
// notifes us with wrong accelerator.
|
||||
// notifies us with wrong accelerator.
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
accelerator_callback_map_[accelerator].Run();
|
||||
}
|
||||
|
||||
bool GlobalShortcut::RegisterAll(
|
||||
const std::vector<ui::Accelerator>& accelerators,
|
||||
const base::Closure& callback) {
|
||||
std::vector<ui::Accelerator> registered;
|
||||
|
||||
for (auto& accelerator : accelerators) {
|
||||
#if defined(OS_MACOSX)
|
||||
if (RegisteringMediaKeyForUntrustedClient(accelerator))
|
||||
return false;
|
||||
|
||||
GlobalShortcutListener* listener = GlobalShortcutListener::GetInstance();
|
||||
if (!listener->RegisterAccelerator(accelerator, this)) {
|
||||
// unregister all shortcuts if any failed
|
||||
UnregisterSome(registered);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
registered.push_back(accelerator);
|
||||
accelerator_callback_map_[accelerator] = callback;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GlobalShortcut::Register(const ui::Accelerator& accelerator,
|
||||
const base::Closure& callback) {
|
||||
#if defined(OS_MACOSX)
|
||||
if (RegisteringMediaKeyForUntrustedClient(accelerator))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if (!GlobalShortcutListener::GetInstance()->RegisterAccelerator(accelerator,
|
||||
this)) {
|
||||
return false;
|
||||
@@ -58,6 +116,13 @@ void GlobalShortcut::Unregister(const ui::Accelerator& accelerator) {
|
||||
this);
|
||||
}
|
||||
|
||||
void GlobalShortcut::UnregisterSome(
|
||||
const std::vector<ui::Accelerator>& accelerators) {
|
||||
for (auto& accelerator : accelerators) {
|
||||
Unregister(accelerator);
|
||||
}
|
||||
}
|
||||
|
||||
bool GlobalShortcut::IsRegistered(const ui::Accelerator& accelerator) {
|
||||
return ContainsKey(accelerator_callback_map_, accelerator);
|
||||
}
|
||||
@@ -77,6 +142,7 @@ void GlobalShortcut::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "GlobalShortcut"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("registerAll", &GlobalShortcut::RegisterAll)
|
||||
.SetMethod("register", &GlobalShortcut::Register)
|
||||
.SetMethod("isRegistered", &GlobalShortcut::IsRegistered)
|
||||
.SetMethod("unregister", &GlobalShortcut::Unregister)
|
||||
@@ -100,4 +166,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_global_shortcut, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_global_shortcut, Initialize)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "base/callback.h"
|
||||
@@ -33,10 +34,13 @@ class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
|
||||
private:
|
||||
typedef std::map<ui::Accelerator, base::Closure> AcceleratorCallbackMap;
|
||||
|
||||
bool RegisterAll(const std::vector<ui::Accelerator>& accelerators,
|
||||
const base::Closure& callback);
|
||||
bool Register(const ui::Accelerator& accelerator,
|
||||
const base::Closure& callback);
|
||||
bool IsRegistered(const ui::Accelerator& accelerator);
|
||||
void Unregister(const ui::Accelerator& accelerator);
|
||||
void UnregisterSome(const std::vector<ui::Accelerator>& accelerators);
|
||||
void UnregisterAll();
|
||||
|
||||
// GlobalShortcutListener::Observer implementation.
|
||||
|
||||
@@ -62,7 +62,7 @@ struct Converter<in_app_purchase::Product> {
|
||||
dict.Set("formattedPrice", val.formattedPrice);
|
||||
|
||||
// Downloadable Content Information
|
||||
dict.Set("isDownloadable", val.downloadable);
|
||||
dict.Set("isDownloadable", val.isDownloadable);
|
||||
|
||||
return dict.GetHandle();
|
||||
}
|
||||
@@ -132,11 +132,12 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("inAppPurchase", InAppPurchase::Create(isolate));
|
||||
dict.Set("InAppPurchase",
|
||||
InAppPurchase::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("InAppPurchase", InAppPurchase::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_in_app_purchase, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_in_app_purchase, Initialize)
|
||||
|
||||
@@ -41,6 +41,8 @@ void Menu::AfterInit(v8::Isolate* isolate) {
|
||||
delegate.Get("isCommandIdEnabled", &is_enabled_);
|
||||
delegate.Get("isCommandIdVisible", &is_visible_);
|
||||
delegate.Get("getAcceleratorForCommandId", &get_accelerator_);
|
||||
delegate.Get("shouldRegisterAcceleratorForCommandId",
|
||||
&should_register_accelerator_);
|
||||
delegate.Get("executeCommand", &execute_command_);
|
||||
delegate.Get("menuWillShow", &menu_will_show_);
|
||||
}
|
||||
@@ -74,6 +76,12 @@ bool Menu::GetAcceleratorForCommandIdWithParams(
|
||||
return mate::ConvertFromV8(isolate(), val, accelerator);
|
||||
}
|
||||
|
||||
bool Menu::ShouldRegisterAcceleratorForCommandId(int command_id) const {
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
return should_register_accelerator_.Run(GetWrapper(), command_id);
|
||||
}
|
||||
|
||||
void Menu::ExecuteCommand(int command_id, int flags) {
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
@@ -82,7 +90,7 @@ void Menu::ExecuteCommand(int command_id, int flags) {
|
||||
command_id);
|
||||
}
|
||||
|
||||
void Menu::MenuWillShow(ui::SimpleMenuModel* source) {
|
||||
void Menu::OnMenuWillShow(ui::SimpleMenuModel* source) {
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
menu_will_show_.Run(GetWrapper());
|
||||
@@ -155,6 +163,12 @@ base::string16 Menu::GetSublabelAt(int index) const {
|
||||
return model_->GetSublabelAt(index);
|
||||
}
|
||||
|
||||
base::string16 Menu::GetAcceleratorTextAt(int index) const {
|
||||
ui::Accelerator accelerator;
|
||||
model_->GetAcceleratorAtWithParams(index, true, &accelerator);
|
||||
return accelerator.GetShortcutText();
|
||||
}
|
||||
|
||||
bool Menu::IsItemCheckedAt(int index) const {
|
||||
return model_->IsItemCheckedAt(index);
|
||||
}
|
||||
@@ -195,6 +209,7 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("getCommandIdAt", &Menu::GetCommandIdAt)
|
||||
.SetMethod("getLabelAt", &Menu::GetLabelAt)
|
||||
.SetMethod("getSublabelAt", &Menu::GetSublabelAt)
|
||||
.SetMethod("getAcceleratorTextAt", &Menu::GetAcceleratorTextAt)
|
||||
.SetMethod("isItemCheckedAt", &Menu::IsItemCheckedAt)
|
||||
.SetMethod("isEnabledAt", &Menu::IsEnabledAt)
|
||||
.SetMethod("isVisibleAt", &Menu::IsVisibleAt)
|
||||
@@ -218,7 +233,9 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
Menu::SetConstructor(isolate, base::Bind(&Menu::New));
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("Menu", Menu::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set(
|
||||
"Menu",
|
||||
Menu::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
#if defined(OS_MACOSX)
|
||||
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
|
||||
dict.SetMethod("sendActionToFirstResponder",
|
||||
@@ -228,4 +245,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_menu, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_menu, Initialize)
|
||||
|
||||
@@ -51,8 +51,9 @@ class Menu : public mate::TrackableObject<Menu>,
|
||||
int command_id,
|
||||
bool use_default_accelerator,
|
||||
ui::Accelerator* accelerator) const override;
|
||||
bool ShouldRegisterAcceleratorForCommandId(int command_id) const override;
|
||||
void ExecuteCommand(int command_id, int event_flags) override;
|
||||
void MenuWillShow(ui::SimpleMenuModel* source) override;
|
||||
void OnMenuWillShow(ui::SimpleMenuModel* source) override;
|
||||
|
||||
virtual void PopupAt(TopLevelWindow* window,
|
||||
int x,
|
||||
@@ -91,6 +92,7 @@ class Menu : public mate::TrackableObject<Menu>,
|
||||
int GetCommandIdAt(int index) const;
|
||||
base::string16 GetLabelAt(int index) const;
|
||||
base::string16 GetSublabelAt(int index) const;
|
||||
base::string16 GetAcceleratorTextAt(int index) const;
|
||||
bool IsItemCheckedAt(int index) const;
|
||||
bool IsEnabledAt(int index) const;
|
||||
bool IsVisibleAt(int index) const;
|
||||
@@ -101,6 +103,7 @@ class Menu : public mate::TrackableObject<Menu>,
|
||||
base::Callback<bool(v8::Local<v8::Value>, int)> is_visible_;
|
||||
base::Callback<v8::Local<v8::Value>(v8::Local<v8::Value>, int, bool)>
|
||||
get_accelerator_;
|
||||
base::Callback<bool(v8::Local<v8::Value>, int)> should_register_accelerator_;
|
||||
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>, int)>
|
||||
execute_command_;
|
||||
base::Callback<void(v8::Local<v8::Value>)> menu_will_show_;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "base/mac/scoped_sending_event.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
@@ -43,7 +45,7 @@ void MenuMac::PopupAt(TopLevelWindow* window,
|
||||
auto popup = base::Bind(&MenuMac::PopupOnUI, weak_factory_.GetWeakPtr(),
|
||||
native_window->GetWeakPtr(), window->weak_map_id(), x,
|
||||
y, positioning_item, callback);
|
||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, popup);
|
||||
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, popup);
|
||||
}
|
||||
|
||||
void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
|
||||
@@ -54,7 +56,7 @@ void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
|
||||
base::Closure callback) {
|
||||
if (!native_window)
|
||||
return;
|
||||
NSWindow* nswindow = native_window->GetNativeWindow();
|
||||
NSWindow* nswindow = native_window->GetNativeWindow().GetNativeNSWindow();
|
||||
|
||||
auto close_callback = base::Bind(
|
||||
&MenuMac::OnClosed, weak_factory_.GetWeakPtr(), window_id, callback);
|
||||
@@ -97,7 +99,7 @@ void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
|
||||
|
||||
[popup_controllers_[window_id] setCloseCallback:close_callback];
|
||||
// Make sure events can be pumped while the menu is up.
|
||||
base::MessageLoop::ScopedNestableTaskAllower allow;
|
||||
base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
|
||||
|
||||
// One of the events that could be pumped is |window.close()|.
|
||||
// User-initiated event-tracking loops protect against this by
|
||||
|
||||
@@ -31,7 +31,9 @@ void Net::BuildPrototype(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
|
||||
return URLRequest::GetConstructor(isolate)->GetFunction();
|
||||
return URLRequest::GetConstructor(isolate)
|
||||
->GetFunction(isolate->GetCurrentContext())
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
@@ -53,9 +55,10 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("net", Net::Create(isolate));
|
||||
dict.Set("Net", Net::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("Net",
|
||||
Net::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_net, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_net, Initialize)
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/net/system_network_context_manager.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "base/command_line.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "components/net_log/chrome_net_log.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
@@ -27,8 +28,8 @@ NetLog::NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {
|
||||
Init(isolate);
|
||||
|
||||
net_log_writer_ =
|
||||
atom::AtomBrowserMainParts::Get()->net_log()->net_export_file_writer();
|
||||
net_log_writer_ = g_browser_process->system_network_context_manager()
|
||||
->GetNetExportFileWriter();
|
||||
net_log_writer_->AddObserver(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include "atom/browser/api/atom_api_notification.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_menu.h"
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "atom/common/native_mate_converters/image_converter.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "base/guid.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/browser_client.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
@@ -22,10 +22,10 @@
|
||||
|
||||
namespace mate {
|
||||
template <>
|
||||
struct Converter<brightray::NotificationAction> {
|
||||
struct Converter<atom::NotificationAction> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
brightray::NotificationAction* out) {
|
||||
atom::NotificationAction* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
@@ -38,7 +38,7 @@ struct Converter<brightray::NotificationAction> {
|
||||
}
|
||||
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
brightray::NotificationAction val) {
|
||||
atom::NotificationAction val) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("text", val.text);
|
||||
dict.Set("type", val.type);
|
||||
@@ -56,7 +56,8 @@ Notification::Notification(v8::Isolate* isolate,
|
||||
mate::Arguments* args) {
|
||||
InitWith(isolate, wrapper);
|
||||
|
||||
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
|
||||
presenter_ = static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
|
||||
->GetNotificationPresenter();
|
||||
|
||||
mate::Dictionary opts;
|
||||
if (args->GetNext(&opts)) {
|
||||
@@ -119,7 +120,7 @@ base::string16 Notification::GetSound() const {
|
||||
return sound_;
|
||||
}
|
||||
|
||||
std::vector<brightray::NotificationAction> Notification::GetActions() const {
|
||||
std::vector<atom::NotificationAction> Notification::GetActions() const {
|
||||
return actions_;
|
||||
}
|
||||
|
||||
@@ -157,7 +158,7 @@ void Notification::SetSound(const base::string16& new_sound) {
|
||||
}
|
||||
|
||||
void Notification::SetActions(
|
||||
const std::vector<brightray::NotificationAction>& actions) {
|
||||
const std::vector<atom::NotificationAction>& actions) {
|
||||
actions_ = actions;
|
||||
}
|
||||
|
||||
@@ -200,7 +201,7 @@ void Notification::Show() {
|
||||
if (presenter_) {
|
||||
notification_ = presenter_->CreateNotification(this, base::GenerateGUID());
|
||||
if (notification_) {
|
||||
brightray::NotificationOptions options;
|
||||
atom::NotificationOptions options;
|
||||
options.title = title_;
|
||||
options.subtitle = subtitle_;
|
||||
options.msg = body_;
|
||||
@@ -218,7 +219,8 @@ void Notification::Show() {
|
||||
}
|
||||
|
||||
bool Notification::IsSupported() {
|
||||
return !!brightray::BrowserClient::Get()->GetNotificationPresenter();
|
||||
return !!static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
|
||||
->GetNotificationPresenter();
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -261,12 +263,13 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
Notification::SetConstructor(isolate, base::Bind(&Notification::New));
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("Notification",
|
||||
Notification::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("Notification", Notification::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
|
||||
dict.SetMethod("isSupported", &Notification::IsSupported);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_common_notification, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_common_notification, Initialize)
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/notifications/notification.h"
|
||||
#include "atom/browser/notifications/notification_delegate.h"
|
||||
#include "atom/browser/notifications/notification_presenter.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/notification.h"
|
||||
#include "brightray/browser/notification_delegate.h"
|
||||
#include "brightray/browser/notification_presenter.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace atom {
|
||||
namespace api {
|
||||
|
||||
class Notification : public mate::TrackableObject<Notification>,
|
||||
public brightray::NotificationDelegate {
|
||||
public NotificationDelegate {
|
||||
public:
|
||||
static mate::WrappableBase* New(mate::Arguments* args);
|
||||
static bool IsSupported();
|
||||
@@ -55,7 +55,7 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||
bool GetHasReply() const;
|
||||
base::string16 GetReplyPlaceholder() const;
|
||||
base::string16 GetSound() const;
|
||||
std::vector<brightray::NotificationAction> GetActions() const;
|
||||
std::vector<atom::NotificationAction> GetActions() const;
|
||||
base::string16 GetCloseButtonText() const;
|
||||
|
||||
// Prop Setters
|
||||
@@ -66,7 +66,7 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||
void SetHasReply(bool new_has_reply);
|
||||
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
|
||||
void SetSound(const base::string16& sound);
|
||||
void SetActions(const std::vector<brightray::NotificationAction>& actions);
|
||||
void SetActions(const std::vector<atom::NotificationAction>& actions);
|
||||
void SetCloseButtonText(const base::string16& text);
|
||||
|
||||
private:
|
||||
@@ -80,12 +80,12 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||
bool has_reply_ = false;
|
||||
base::string16 reply_placeholder_;
|
||||
base::string16 sound_;
|
||||
std::vector<brightray::NotificationAction> actions_;
|
||||
std::vector<atom::NotificationAction> actions_;
|
||||
base::string16 close_button_text_;
|
||||
|
||||
brightray::NotificationPresenter* presenter_;
|
||||
atom::NotificationPresenter* presenter_;
|
||||
|
||||
base::WeakPtr<brightray::Notification> notification_;
|
||||
base::WeakPtr<atom::Notification> notification_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Notification);
|
||||
};
|
||||
|
||||
@@ -84,19 +84,19 @@ void PowerMonitor::OnResume() {
|
||||
Emit("resume");
|
||||
}
|
||||
|
||||
void PowerMonitor::QuerySystemIdleState(v8::Isolate* isolate,
|
||||
int idle_threshold,
|
||||
const ui::IdleCallback& callback) {
|
||||
ui::IdleState PowerMonitor::QuerySystemIdleState(v8::Isolate* isolate,
|
||||
int idle_threshold) {
|
||||
if (idle_threshold > 0) {
|
||||
ui::CalculateIdleState(idle_threshold, callback);
|
||||
return ui::CalculateIdleState(idle_threshold);
|
||||
} else {
|
||||
isolate->ThrowException(v8::Exception::TypeError(mate::StringToV8(
|
||||
isolate, "Invalid idle threshold, must be greater than 0")));
|
||||
return ui::IDLE_STATE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerMonitor::QuerySystemIdleTime(const ui::IdleTimeCallback& callback) {
|
||||
ui::CalculateIdleTime(callback);
|
||||
int PowerMonitor::QuerySystemIdleTime() {
|
||||
return ui::CalculateIdleTime();
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -122,8 +122,8 @@ void PowerMonitor::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("blockShutdown", &PowerMonitor::BlockShutdown)
|
||||
.SetMethod("unblockShutdown", &PowerMonitor::UnblockShutdown)
|
||||
#endif
|
||||
.SetMethod("querySystemIdleState", &PowerMonitor::QuerySystemIdleState)
|
||||
.SetMethod("querySystemIdleTime", &PowerMonitor::QuerySystemIdleTime);
|
||||
.SetMethod("_querySystemIdleState", &PowerMonitor::QuerySystemIdleState)
|
||||
.SetMethod("_querySystemIdleTime", &PowerMonitor::QuerySystemIdleTime);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
@@ -141,10 +141,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("powerMonitor", PowerMonitor::Create(isolate));
|
||||
dict.Set("PowerMonitor",
|
||||
PowerMonitor::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("PowerMonitor", PowerMonitor::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_power_monitor, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_power_monitor, Initialize)
|
||||
|
||||
@@ -46,10 +46,8 @@ class PowerMonitor : public mate::TrackableObject<PowerMonitor>,
|
||||
void OnResume() override;
|
||||
|
||||
private:
|
||||
void QuerySystemIdleState(v8::Isolate* isolate,
|
||||
int idle_threshold,
|
||||
const ui::IdleCallback& callback);
|
||||
void QuerySystemIdleTime(const ui::IdleTimeCallback& callback);
|
||||
ui::IdleState QuerySystemIdleState(v8::Isolate* isolate, int idle_threshold);
|
||||
int QuerySystemIdleTime();
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Static callback invoked when a message comes in to our messaging window.
|
||||
|
||||
@@ -6,9 +6,13 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/task_scheduler/post_task.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "content/public/common/service_manager_connection.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "services/device/public/mojom/constants.mojom.h"
|
||||
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
|
||||
#include "services/service_manager/public/cpp/connector.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
@@ -39,16 +43,19 @@ namespace atom {
|
||||
namespace api {
|
||||
|
||||
PowerSaveBlocker::PowerSaveBlocker(v8::Isolate* isolate)
|
||||
: current_blocker_type_(
|
||||
device::mojom::WakeLockType::kPreventAppSuspension) {
|
||||
: current_lock_type_(device::mojom::WakeLockType::kPreventAppSuspension),
|
||||
is_wake_lock_active_(false) {
|
||||
Init(isolate);
|
||||
}
|
||||
|
||||
PowerSaveBlocker::~PowerSaveBlocker() {}
|
||||
|
||||
void PowerSaveBlocker::UpdatePowerSaveBlocker() {
|
||||
if (power_save_blocker_types_.empty()) {
|
||||
power_save_blocker_.reset();
|
||||
if (wake_lock_types_.empty()) {
|
||||
if (is_wake_lock_active_) {
|
||||
GetWakeLock()->CancelWakeLock();
|
||||
is_wake_lock_active_ = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,45 +65,57 @@ void PowerSaveBlocker::UpdatePowerSaveBlocker() {
|
||||
// higher precedence level than |WakeLockType::kPreventAppSuspension|.
|
||||
//
|
||||
// Only the highest-precedence blocker type takes effect.
|
||||
device::mojom::WakeLockType new_blocker_type =
|
||||
device::mojom::WakeLockType new_lock_type =
|
||||
device::mojom::WakeLockType::kPreventAppSuspension;
|
||||
for (const auto& element : power_save_blocker_types_) {
|
||||
for (const auto& element : wake_lock_types_) {
|
||||
if (element.second == device::mojom::WakeLockType::kPreventDisplaySleep) {
|
||||
new_blocker_type = device::mojom::WakeLockType::kPreventDisplaySleep;
|
||||
new_lock_type = device::mojom::WakeLockType::kPreventDisplaySleep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!power_save_blocker_ || new_blocker_type != current_blocker_type_) {
|
||||
auto new_blocker = std::make_unique<device::PowerSaveBlocker>(
|
||||
new_blocker_type, device::mojom::WakeLockReason::kOther,
|
||||
ATOM_PRODUCT_NAME, base::ThreadTaskRunnerHandle::Get(),
|
||||
// This task runner may be used by some device service
|
||||
// implementation bits to interface with dbus client code, which in
|
||||
// turn imposes some subtle thread affinity on the clients. We
|
||||
// therefore require a single-thread runner.
|
||||
base::CreateSingleThreadTaskRunnerWithTraits(
|
||||
{base::MayBlock(), base::TaskPriority::BACKGROUND}));
|
||||
power_save_blocker_.swap(new_blocker);
|
||||
current_blocker_type_ = new_blocker_type;
|
||||
if (current_lock_type_ != new_lock_type) {
|
||||
GetWakeLock()->ChangeType(new_lock_type, base::DoNothing());
|
||||
current_lock_type_ = new_lock_type;
|
||||
}
|
||||
if (!is_wake_lock_active_) {
|
||||
GetWakeLock()->RequestWakeLock();
|
||||
is_wake_lock_active_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
device::mojom::WakeLock* PowerSaveBlocker::GetWakeLock() {
|
||||
if (!wake_lock_) {
|
||||
device::mojom::WakeLockProviderPtr wake_lock_provider;
|
||||
DCHECK(content::ServiceManagerConnection::GetForProcess());
|
||||
auto* connector =
|
||||
content::ServiceManagerConnection::GetForProcess()->GetConnector();
|
||||
connector->BindInterface(device::mojom::kServiceName,
|
||||
mojo::MakeRequest(&wake_lock_provider));
|
||||
|
||||
wake_lock_provider->GetWakeLockWithoutContext(
|
||||
device::mojom::WakeLockType::kPreventAppSuspension,
|
||||
device::mojom::WakeLockReason::kOther, ATOM_PRODUCT_NAME,
|
||||
mojo::MakeRequest(&wake_lock_));
|
||||
}
|
||||
return wake_lock_.get();
|
||||
}
|
||||
|
||||
int PowerSaveBlocker::Start(device::mojom::WakeLockType type) {
|
||||
static int count = 0;
|
||||
power_save_blocker_types_[count] = type;
|
||||
wake_lock_types_[count] = type;
|
||||
UpdatePowerSaveBlocker();
|
||||
return count++;
|
||||
}
|
||||
|
||||
bool PowerSaveBlocker::Stop(int id) {
|
||||
bool success = power_save_blocker_types_.erase(id) > 0;
|
||||
bool success = wake_lock_types_.erase(id) > 0;
|
||||
UpdatePowerSaveBlocker();
|
||||
return success;
|
||||
}
|
||||
|
||||
bool PowerSaveBlocker::IsStarted(int id) {
|
||||
return power_save_blocker_types_.find(id) != power_save_blocker_types_.end();
|
||||
return wake_lock_types_.find(id) != wake_lock_types_.end();
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -132,4 +151,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_power_save_blocker, Initialize);
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_power_save_blocker, Initialize);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "services/device/wake_lock/power_save_blocker/power_save_blocker.h"
|
||||
#include "services/device/public/mojom/wake_lock.mojom.h"
|
||||
|
||||
namespace mate {
|
||||
class Dictionary;
|
||||
@@ -37,14 +37,19 @@ class PowerSaveBlocker : public mate::TrackableObject<PowerSaveBlocker> {
|
||||
bool Stop(int id);
|
||||
bool IsStarted(int id);
|
||||
|
||||
std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_;
|
||||
device::mojom::WakeLock* GetWakeLock();
|
||||
|
||||
// Current blocker type used by |power_save_blocker_|
|
||||
device::mojom::WakeLockType current_blocker_type_;
|
||||
// Current wake lock level.
|
||||
device::mojom::WakeLockType current_lock_type_;
|
||||
|
||||
// Whether the wake lock is currently active.
|
||||
bool is_wake_lock_active_;
|
||||
|
||||
// Map from id to the corresponding blocker type for each request.
|
||||
using WakeLockTypeMap = std::map<int, device::mojom::WakeLockType>;
|
||||
WakeLockTypeMap power_save_blocker_types_;
|
||||
WakeLockTypeMap wake_lock_types_;
|
||||
|
||||
device::mojom::WakeLockPtr wake_lock_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker);
|
||||
};
|
||||
|
||||
@@ -24,47 +24,119 @@
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
namespace {
|
||||
|
||||
// List of registered custom standard schemes.
|
||||
std::vector<std::string> g_standard_schemes;
|
||||
|
||||
struct SchemeOptions {
|
||||
bool standard = false;
|
||||
bool secure = false;
|
||||
bool bypassCSP = false;
|
||||
bool allowServiceWorkers = false;
|
||||
bool supportFetchAPI = false;
|
||||
bool corsEnabled = false;
|
||||
};
|
||||
|
||||
struct CustomScheme {
|
||||
std::string scheme;
|
||||
SchemeOptions options;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace mate {
|
||||
|
||||
template <>
|
||||
struct Converter<CustomScheme> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
CustomScheme* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
if (!dict.Get("scheme", &(out->scheme)))
|
||||
return false;
|
||||
mate::Dictionary opt;
|
||||
// options are optional. Default values specified in SchemeOptions are used
|
||||
if (dict.Get("privileges", &opt)) {
|
||||
opt.Get("standard", &(out->options.standard));
|
||||
opt.Get("supportFetchAPI", &(out->options.supportFetchAPI));
|
||||
opt.Get("secure", &(out->options.secure));
|
||||
opt.Get("bypassCSP", &(out->options.bypassCSP));
|
||||
opt.Get("allowServiceWorkers", &(out->options.allowServiceWorkers));
|
||||
opt.Get("supportFetchAPI", &(out->options.supportFetchAPI));
|
||||
opt.Get("corsEnabled", &(out->options.corsEnabled));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
std::vector<std::string> GetStandardSchemes() {
|
||||
return g_standard_schemes;
|
||||
}
|
||||
|
||||
void RegisterStandardSchemes(const std::vector<std::string>& schemes,
|
||||
mate::Arguments* args) {
|
||||
g_standard_schemes = schemes;
|
||||
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
|
||||
mate::Arguments* args) {
|
||||
std::vector<CustomScheme> custom_schemes;
|
||||
if (!mate::ConvertFromV8(args->isolate(), val, &custom_schemes)) {
|
||||
args->ThrowError("Argument must be an array of custom schemes.");
|
||||
return;
|
||||
}
|
||||
|
||||
mate::Dictionary opts;
|
||||
bool secure = false;
|
||||
args->GetNext(&opts) && opts.Get("secure", &secure);
|
||||
|
||||
// Dynamically register the schemes.
|
||||
auto* policy = content::ChildProcessSecurityPolicy::GetInstance();
|
||||
for (const std::string& scheme : schemes) {
|
||||
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITH_HOST);
|
||||
if (secure) {
|
||||
url::AddSecureScheme(scheme.c_str());
|
||||
std::vector<std::string> secure_schemes, cspbypassing_schemes, fetch_schemes,
|
||||
service_worker_schemes, cors_schemes;
|
||||
for (const auto& custom_scheme : custom_schemes) {
|
||||
// Register scheme to privileged list (https, wss, data, chrome-extension)
|
||||
if (custom_scheme.options.standard) {
|
||||
auto* policy = content::ChildProcessSecurityPolicy::GetInstance();
|
||||
url::AddStandardScheme(custom_scheme.scheme.c_str(),
|
||||
url::SCHEME_WITH_HOST);
|
||||
g_standard_schemes.push_back(custom_scheme.scheme);
|
||||
policy->RegisterWebSafeScheme(custom_scheme.scheme);
|
||||
}
|
||||
if (custom_scheme.options.secure) {
|
||||
secure_schemes.push_back(custom_scheme.scheme);
|
||||
url::AddSecureScheme(custom_scheme.scheme.c_str());
|
||||
}
|
||||
if (custom_scheme.options.bypassCSP) {
|
||||
cspbypassing_schemes.push_back(custom_scheme.scheme);
|
||||
url::AddCSPBypassingScheme(custom_scheme.scheme.c_str());
|
||||
}
|
||||
if (custom_scheme.options.corsEnabled) {
|
||||
cors_schemes.push_back(custom_scheme.scheme);
|
||||
url::AddCorsEnabledScheme(custom_scheme.scheme.c_str());
|
||||
}
|
||||
if (custom_scheme.options.supportFetchAPI) {
|
||||
fetch_schemes.push_back(custom_scheme.scheme);
|
||||
}
|
||||
if (custom_scheme.options.allowServiceWorkers) {
|
||||
service_worker_schemes.push_back(custom_scheme.scheme);
|
||||
}
|
||||
policy->RegisterWebSafeScheme(scheme);
|
||||
}
|
||||
|
||||
// Add the schemes to command line switches, so child processes can also
|
||||
// register them.
|
||||
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
||||
atom::switches::kStandardSchemes, base::JoinString(schemes, ","));
|
||||
if (secure) {
|
||||
const auto AppendSchemesToCmdLine = [](const char* switch_name,
|
||||
std::vector<std::string> schemes) {
|
||||
// Add the schemes to command line switches, so child processes can also
|
||||
// register them.
|
||||
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
||||
atom::switches::kSecureSchemes, base::JoinString(schemes, ","));
|
||||
}
|
||||
switch_name, base::JoinString(schemes, ","));
|
||||
};
|
||||
|
||||
AppendSchemesToCmdLine(atom::switches::kSecureSchemes, secure_schemes);
|
||||
AppendSchemesToCmdLine(atom::switches::kBypassCSPSchemes,
|
||||
cspbypassing_schemes);
|
||||
AppendSchemesToCmdLine(atom::switches::kCORSSchemes, cors_schemes);
|
||||
AppendSchemesToCmdLine(atom::switches::kFetchSchemes, fetch_schemes);
|
||||
AppendSchemesToCmdLine(atom::switches::kServiceWorkerSchemes,
|
||||
service_worker_schemes);
|
||||
AppendSchemesToCmdLine(atom::switches::kStandardSchemes, g_standard_schemes);
|
||||
}
|
||||
|
||||
Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||
@@ -73,20 +145,14 @@ Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||
}
|
||||
|
||||
Protocol::~Protocol() {}
|
||||
|
||||
void Protocol::RegisterServiceWorkerSchemes(
|
||||
const std::vector<std::string>& schemes) {
|
||||
atom::AtomBrowserClient::SetCustomServiceWorkerSchemes(schemes);
|
||||
}
|
||||
|
||||
void Protocol::UnregisterProtocol(const std::string& scheme,
|
||||
mate::Arguments* args) {
|
||||
CompletionCallback callback;
|
||||
args->GetNext(&callback);
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraitsAndReplyWithResult(
|
||||
FROM_HERE, {content::BrowserThread::IO},
|
||||
base::BindOnce(&Protocol::UnregisterProtocolInIO,
|
||||
base::RetainedRef(getter), scheme),
|
||||
base::BindOnce(&Protocol::OnIOCompleted, GetWeakPtr(), callback));
|
||||
@@ -103,22 +169,30 @@ Protocol::ProtocolError Protocol::UnregisterProtocolInIO(
|
||||
return PROTOCOL_OK;
|
||||
}
|
||||
|
||||
void Protocol::IsProtocolHandled(const std::string& scheme,
|
||||
const BooleanCallback& callback) {
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&Protocol::IsProtocolHandledInIO, base::RetainedRef(getter),
|
||||
scheme),
|
||||
callback);
|
||||
}
|
||||
|
||||
// static
|
||||
bool Protocol::IsProtocolHandledInIO(
|
||||
bool IsProtocolHandledInIO(
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
const std::string& scheme) {
|
||||
return request_context_getter->job_factory()->IsHandledProtocol(scheme);
|
||||
bool is_handled =
|
||||
request_context_getter->job_factory()->IsHandledProtocol(scheme);
|
||||
return is_handled;
|
||||
}
|
||||
|
||||
void PromiseCallback(util::Promise promise, bool handled) {
|
||||
promise.Resolve(handled);
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> Protocol::IsProtocolHandled(const std::string& scheme) {
|
||||
util::Promise promise(isolate());
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
|
||||
base::PostTaskWithTraitsAndReplyWithResult(
|
||||
FROM_HERE, {content::BrowserThread::IO},
|
||||
base::BindOnce(&IsProtocolHandledInIO, base::RetainedRef(getter), scheme),
|
||||
base::BindOnce(&PromiseCallback, std::move(promise)));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Protocol::UninterceptProtocol(const std::string& scheme,
|
||||
@@ -127,8 +201,8 @@ void Protocol::UninterceptProtocol(const std::string& scheme,
|
||||
args->GetNext(&callback);
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraitsAndReplyWithResult(
|
||||
FROM_HERE, {content::BrowserThread::IO},
|
||||
base::BindOnce(&Protocol::UninterceptProtocolInIO,
|
||||
base::RetainedRef(getter), scheme),
|
||||
base::BindOnce(&Protocol::OnIOCompleted, GetWeakPtr(), callback));
|
||||
@@ -188,8 +262,6 @@ void Protocol::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "Protocol"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("registerServiceWorkerSchemes",
|
||||
&Protocol::RegisterServiceWorkerSchemes)
|
||||
.SetMethod("registerStringProtocol",
|
||||
&Protocol::RegisterProtocol<URLRequestStringJob>)
|
||||
.SetMethod("registerBufferProtocol",
|
||||
@@ -221,16 +293,16 @@ void Protocol::BuildPrototype(v8::Isolate* isolate,
|
||||
|
||||
namespace {
|
||||
|
||||
void RegisterStandardSchemes(const std::vector<std::string>& schemes,
|
||||
mate::Arguments* args) {
|
||||
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
|
||||
mate::Arguments* args) {
|
||||
if (atom::Browser::Get()->is_ready()) {
|
||||
args->ThrowError(
|
||||
"protocol.registerStandardSchemes should be called before "
|
||||
"protocol.registerSchemesAsPrivileged should be called before "
|
||||
"app is ready");
|
||||
return;
|
||||
}
|
||||
|
||||
atom::api::RegisterStandardSchemes(schemes, args);
|
||||
atom::api::RegisterSchemesAsPrivileged(val, args);
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
@@ -239,10 +311,10 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.SetMethod("registerStandardSchemes", &RegisterStandardSchemes);
|
||||
dict.SetMethod("registerSchemesAsPrivileged", &RegisterSchemesAsPrivileged);
|
||||
dict.SetMethod("getStandardSchemes", &atom::api::GetStandardSchemes);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_protocol, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_protocol, Initialize)
|
||||
|
||||
@@ -14,8 +14,11 @@
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
#include "atom/common/promise_util.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/arguments.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
@@ -31,15 +34,15 @@ namespace atom {
|
||||
namespace api {
|
||||
|
||||
std::vector<std::string> GetStandardSchemes();
|
||||
void RegisterStandardSchemes(const std::vector<std::string>& schemes,
|
||||
mate::Arguments* args);
|
||||
|
||||
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
|
||||
mate::Arguments* args);
|
||||
|
||||
class Protocol : public mate::TrackableObject<Protocol> {
|
||||
public:
|
||||
using Handler =
|
||||
base::Callback<void(const base::DictionaryValue&, v8::Local<v8::Value>)>;
|
||||
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||
using BooleanCallback = base::Callback<void(bool)>;
|
||||
|
||||
static mate::Handle<Protocol> Create(v8::Isolate* isolate,
|
||||
AtomBrowserContext* browser_context);
|
||||
@@ -92,9 +95,6 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
DISALLOW_COPY_AND_ASSIGN(CustomProtocolHandler);
|
||||
};
|
||||
|
||||
// Register schemes that can handle service worker.
|
||||
void RegisterServiceWorkerSchemes(const std::vector<std::string>& schemes);
|
||||
|
||||
// Register the protocol with certain request job.
|
||||
template <typename RequestJob>
|
||||
void RegisterProtocol(const std::string& scheme,
|
||||
@@ -104,8 +104,8 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
args->GetNext(&callback);
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraitsAndReplyWithResult(
|
||||
FROM_HERE, {content::BrowserThread::IO},
|
||||
base::BindOnce(&Protocol::RegisterProtocolInIO<RequestJob>,
|
||||
base::RetainedRef(getter), isolate(), scheme, handler),
|
||||
base::BindOnce(&Protocol::OnIOCompleted, GetWeakPtr(), callback));
|
||||
@@ -134,11 +134,7 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
const std::string& scheme);
|
||||
|
||||
// Whether the protocol has handler registered.
|
||||
void IsProtocolHandled(const std::string& scheme,
|
||||
const BooleanCallback& callback);
|
||||
static bool IsProtocolHandledInIO(
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
const std::string& scheme);
|
||||
v8::Local<v8::Promise> IsProtocolHandled(const std::string& scheme);
|
||||
|
||||
// Replace the protocol handler with a new one.
|
||||
template <typename RequestJob>
|
||||
@@ -149,8 +145,8 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
args->GetNext(&callback);
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraitsAndReplyWithResult(
|
||||
FROM_HERE, {content::BrowserThread::IO},
|
||||
base::BindOnce(&Protocol::InterceptProtocolInIO<RequestJob>,
|
||||
base::RetainedRef(getter), isolate(), scheme, handler),
|
||||
base::BindOnce(&Protocol::OnIOCompleted, GetWeakPtr(), callback));
|
||||
|
||||
@@ -26,7 +26,7 @@ bool IsWebContents(v8::Isolate* isolate, content::RenderProcessHost* process) {
|
||||
if (!web_contents)
|
||||
return false;
|
||||
|
||||
auto api_web_contents = WebContents::CreateFrom(isolate, web_contents);
|
||||
auto api_web_contents = WebContents::FromOrCreate(isolate, web_contents);
|
||||
auto type = api_web_contents->GetType();
|
||||
return type == WebContents::Type::BROWSER_WINDOW ||
|
||||
type == WebContents::Type::WEB_VIEW;
|
||||
@@ -87,5 +87,5 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_render_process_preferences,
|
||||
Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_render_process_preferences,
|
||||
Initialize)
|
||||
|
||||
@@ -52,6 +52,19 @@ std::vector<std::string> MetricsToArray(uint32_t metrics) {
|
||||
return array;
|
||||
}
|
||||
|
||||
void DelayEmit(Screen* screen,
|
||||
const base::StringPiece& name,
|
||||
const display::Display& display) {
|
||||
screen->Emit(name, display);
|
||||
}
|
||||
|
||||
void DelayEmitWithMetrics(Screen* screen,
|
||||
const base::StringPiece& name,
|
||||
const display::Display& display,
|
||||
const std::vector<std::string>& metrics) {
|
||||
screen->Emit(name, display, metrics);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Screen::Screen(v8::Isolate* isolate, display::Screen* screen)
|
||||
@@ -101,16 +114,23 @@ static gfx::Rect DIPToScreenRect(atom::NativeWindow* window,
|
||||
#endif
|
||||
|
||||
void Screen::OnDisplayAdded(const display::Display& new_display) {
|
||||
Emit("display-added", new_display);
|
||||
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
||||
FROM_HERE, base::Bind(&DelayEmit, base::Unretained(this), "display-added",
|
||||
new_display));
|
||||
}
|
||||
|
||||
void Screen::OnDisplayRemoved(const display::Display& old_display) {
|
||||
Emit("display-removed", old_display);
|
||||
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
||||
FROM_HERE, base::Bind(&DelayEmit, base::Unretained(this),
|
||||
"display-removed", old_display));
|
||||
}
|
||||
|
||||
void Screen::OnDisplayMetricsChanged(const display::Display& display,
|
||||
uint32_t changed_metrics) {
|
||||
Emit("display-metrics-changed", display, MetricsToArray(changed_metrics));
|
||||
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
||||
FROM_HERE, base::Bind(&DelayEmitWithMetrics, base::Unretained(this),
|
||||
"display-metrics-changed", display,
|
||||
MetricsToArray(changed_metrics)));
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -164,9 +184,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("screen", Screen::Create(isolate));
|
||||
dict.Set("Screen", Screen::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set(
|
||||
"Screen",
|
||||
Screen::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_common_screen, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_common_screen, Initialize)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/atom_permission_manager.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/media/media_device_id_salt.h"
|
||||
#include "atom/browser/net/atom_cert_verifier.h"
|
||||
#include "atom/browser/session_preferences.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
@@ -31,7 +32,7 @@
|
||||
#include "base/guid.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "brightray/browser/media/media_device_id_salt.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/download/public/common/download_danger_type.h"
|
||||
@@ -39,6 +40,7 @@
|
||||
#include "components/prefs/value_map_pref_store.h"
|
||||
#include "components/proxy_config/proxy_config_dictionary.h"
|
||||
#include "components/proxy_config/proxy_config_pref_names.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/download_item_utils.h"
|
||||
#include "content/public/browser/download_manager_delegate.h"
|
||||
@@ -59,7 +61,6 @@
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
using atom::api::Cookies;
|
||||
using content::BrowserThread;
|
||||
using content::StoragePartition;
|
||||
|
||||
@@ -211,12 +212,12 @@ std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
|
||||
|
||||
// Runs the callback in UI thread.
|
||||
void RunCallbackInUI(const base::Callback<void()>& callback) {
|
||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
|
||||
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, callback);
|
||||
}
|
||||
template <typename... T>
|
||||
void RunCallbackInUI(const base::Callback<void(T...)>& callback, T... result) {
|
||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||
base::BindOnce(callback, result...));
|
||||
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
|
||||
base::BindOnce(callback, result...));
|
||||
}
|
||||
|
||||
// Callback of HttpCache::GetBackend.
|
||||
@@ -359,7 +360,7 @@ void DestroyGlobalHandle(v8::Isolate* isolate,
|
||||
if (!global_handle.IsEmpty()) {
|
||||
v8::Local<v8::Value> local_handle = global_handle.Get(isolate);
|
||||
if (local_handle->IsObject()) {
|
||||
v8::Local<v8::Object> object = local_handle->ToObject();
|
||||
v8::Local<v8::Object> object = local_handle->ToObject(isolate);
|
||||
void* ptr = object->GetAlignedPointerFromInternalField(0);
|
||||
if (!ptr)
|
||||
return;
|
||||
@@ -419,10 +420,21 @@ void Session::ResolveProxy(
|
||||
browser_context_->GetResolveProxyHelper()->ResolveProxy(url, callback);
|
||||
}
|
||||
|
||||
void Session::GetCacheSize(const net::CompletionCallback& callback) {
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||
->GetNetworkContext()
|
||||
->ComputeHttpCacheSize(
|
||||
base::Time(), base::Time::Max(),
|
||||
base::BindOnce(
|
||||
[](const net::CompletionCallback& cb, bool is_upper_bound,
|
||||
int64_t size_or_error) { cb.Run(size_or_error); },
|
||||
callback));
|
||||
}
|
||||
|
||||
template <Session::CacheAction action>
|
||||
void Session::DoCacheAction(const net::CompletionCallback& callback) {
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&DoCacheActionInIO,
|
||||
WrapRefCounted(browser_context_->GetRequestContext()),
|
||||
action, callback));
|
||||
@@ -440,12 +452,11 @@ void Session::ClearStorageData(mate::Arguments* args) {
|
||||
if (options.storage_types & StoragePartition::REMOVE_DATA_MASK_COOKIES) {
|
||||
// Reset media device id salt when cookies are cleared.
|
||||
// https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid
|
||||
brightray::MediaDeviceIDSalt::Reset(browser_context()->prefs());
|
||||
MediaDeviceIDSalt::Reset(browser_context()->prefs());
|
||||
}
|
||||
storage_partition->ClearData(
|
||||
options.storage_types, options.quota_types, options.origin,
|
||||
content::StoragePartition::OriginMatcherFunction(), base::Time(),
|
||||
base::Time::Max(), base::Bind(&OnClearStorageDataDone, callback));
|
||||
storage_partition->ClearData(options.storage_types, options.quota_types,
|
||||
options.origin, base::Time(), base::Time::Max(),
|
||||
base::Bind(&OnClearStorageDataDone, callback));
|
||||
}
|
||||
|
||||
void Session::FlushStorageData() {
|
||||
@@ -471,13 +482,14 @@ void Session::SetProxy(const mate::Dictionary& options,
|
||||
if (!pac_url.empty()) {
|
||||
browser_context_->in_memory_pref_store()->SetValue(
|
||||
proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreatePacScript(pac_url,
|
||||
true /* pac_mandatory */),
|
||||
std::make_unique<base::Value>(ProxyConfigDictionary::CreatePacScript(
|
||||
pac_url, true /* pac_mandatory */)),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
} else {
|
||||
browser_context_->in_memory_pref_store()->SetValue(
|
||||
proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateFixedServers(proxy_rules, bypass_list),
|
||||
std::make_unique<base::Value>(ProxyConfigDictionary::CreateFixedServers(
|
||||
proxy_rules, bypass_list)),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
}
|
||||
|
||||
@@ -532,8 +544,8 @@ void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
||||
return;
|
||||
}
|
||||
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&SetCertVerifyProcInIO,
|
||||
WrapRefCounted(browser_context_->GetRequestContext()),
|
||||
base::Bind(&WrapVerifyProc, proc)));
|
||||
@@ -567,8 +579,8 @@ void Session::ClearHostResolverCache(mate::Arguments* args) {
|
||||
base::Closure callback;
|
||||
args->GetNext(&callback);
|
||||
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&ClearHostResolverCacheInIO,
|
||||
WrapRefCounted(browser_context_->GetRequestContext()),
|
||||
callback));
|
||||
@@ -583,16 +595,16 @@ void Session::ClearAuthCache(mate::Arguments* args) {
|
||||
base::Closure callback;
|
||||
args->GetNext(&callback);
|
||||
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&ClearAuthCacheInIO,
|
||||
WrapRefCounted(browser_context_->GetRequestContext()),
|
||||
options, callback));
|
||||
}
|
||||
|
||||
void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&AllowNTLMCredentialsForDomainsInIO,
|
||||
WrapRefCounted(browser_context_->GetRequestContext()),
|
||||
domains));
|
||||
@@ -622,8 +634,8 @@ void Session::GetBlobData(const std::string& uuid,
|
||||
return;
|
||||
|
||||
AtomBlobReader* blob_reader = browser_context()->GetBlobReader();
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&AtomBlobReader::StartReading,
|
||||
base::Unretained(blob_reader), uuid, callback));
|
||||
}
|
||||
@@ -747,7 +759,7 @@ void Session::BuildPrototype(v8::Isolate* isolate,
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.MakeDestroyable()
|
||||
.SetMethod("resolveProxy", &Session::ResolveProxy)
|
||||
.SetMethod("getCacheSize", &Session::DoCacheAction<CacheAction::STATS>)
|
||||
.SetMethod("getCacheSize", &Session::GetCacheSize)
|
||||
.SetMethod("clearCache", &Session::DoCacheAction<CacheAction::CLEAR>)
|
||||
.SetMethod("clearStorageData", &Session::ClearStorageData)
|
||||
.SetMethod("flushStorageData", &Session::FlushStorageData)
|
||||
@@ -783,6 +795,8 @@ void Session::BuildPrototype(v8::Isolate* isolate,
|
||||
|
||||
namespace {
|
||||
|
||||
using atom::api::Cookies;
|
||||
using atom::api::Protocol;
|
||||
using atom::api::Session;
|
||||
|
||||
v8::Local<v8::Value> FromPartition(const std::string& partition,
|
||||
@@ -802,11 +816,18 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("Session", Session::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("Cookies", Cookies::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set(
|
||||
"Session",
|
||||
Session::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
dict.Set(
|
||||
"Cookies",
|
||||
Cookies::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
dict.Set(
|
||||
"Protocol",
|
||||
Protocol::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
dict.SetMethod("fromPartition", &FromPartition);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_session, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_session, Initialize)
|
||||
|
||||
@@ -66,6 +66,7 @@ class Session : public mate::TrackableObject<Session>,
|
||||
const ResolveProxyHelper::ResolveProxyCallback& callback);
|
||||
template <CacheAction action>
|
||||
void DoCacheAction(const net::CompletionCallback& callback);
|
||||
void GetCacheSize(const net::CompletionCallback& callback);
|
||||
void ClearStorageData(mate::Arguments* args);
|
||||
void FlushStorageData();
|
||||
void SetProxy(const mate::Dictionary& options, const base::Closure& callback);
|
||||
|
||||
@@ -37,6 +37,12 @@ bool SystemPreferences::IsInvertedColorScheme() {
|
||||
return color_utils::IsInvertedColorScheme();
|
||||
}
|
||||
|
||||
#if !defined(OS_WIN)
|
||||
bool SystemPreferences::IsHighContrastColorScheme() {
|
||||
return false;
|
||||
}
|
||||
#endif // !defined(OS_WIN)
|
||||
|
||||
// static
|
||||
mate::Handle<SystemPreferences> SystemPreferences::Create(
|
||||
v8::Isolate* isolate) {
|
||||
@@ -49,10 +55,13 @@ void SystemPreferences::BuildPrototype(
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "SystemPreferences"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
#if defined(OS_WIN)
|
||||
.SetMethod("getAccentColor", &SystemPreferences::GetAccentColor)
|
||||
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
|
||||
#if defined(OS_WIN) || defined(OS_MACOSX)
|
||||
.SetMethod("getColor", &SystemPreferences::GetColor)
|
||||
.SetMethod("getAccentColor", &SystemPreferences::GetAccentColor)
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
|
||||
#elif defined(OS_MACOSX)
|
||||
.SetMethod("postNotification", &SystemPreferences::PostNotification)
|
||||
.SetMethod("subscribeNotification",
|
||||
@@ -83,9 +92,17 @@ void SystemPreferences::BuildPrototype(
|
||||
&SystemPreferences::GetAppLevelAppearance)
|
||||
.SetMethod("setAppLevelAppearance",
|
||||
&SystemPreferences::SetAppLevelAppearance)
|
||||
.SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
|
||||
.SetMethod("isTrustedAccessibilityClient",
|
||||
&SystemPreferences::IsTrustedAccessibilityClient)
|
||||
.SetMethod("getMediaAccessStatus",
|
||||
&SystemPreferences::GetMediaAccessStatus)
|
||||
.SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess)
|
||||
#endif
|
||||
.SetMethod("isInvertedColorScheme",
|
||||
&SystemPreferences::IsInvertedColorScheme)
|
||||
.SetMethod("isHighContrastColorScheme",
|
||||
&SystemPreferences::IsHighContrastColorScheme)
|
||||
.SetMethod("isDarkMode", &SystemPreferences::IsDarkMode);
|
||||
}
|
||||
|
||||
@@ -104,10 +121,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("systemPreferences", SystemPreferences::Create(isolate));
|
||||
dict.Set("SystemPreferences",
|
||||
SystemPreferences::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("SystemPreferences", SystemPreferences::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_system_preferences, Initialize);
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_system_preferences, Initialize);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
#include "atom/common/promise_util.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/values.h"
|
||||
#include "native_mate/handle.h"
|
||||
@@ -48,11 +49,12 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
bool IsAeroGlassEnabled();
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_MACOSX)
|
||||
std::string GetAccentColor();
|
||||
std::string GetColor(const std::string& color, mate::Arguments* args);
|
||||
#endif
|
||||
#if defined(OS_WIN)
|
||||
bool IsAeroGlassEnabled();
|
||||
|
||||
void InitializeWindow();
|
||||
|
||||
@@ -67,7 +69,8 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||
base::Callback<void(const std::string&, const base::DictionaryValue&)>;
|
||||
|
||||
void PostNotification(const std::string& name,
|
||||
const base::DictionaryValue& user_info);
|
||||
const base::DictionaryValue& user_info,
|
||||
mate::Arguments* args);
|
||||
int SubscribeNotification(const std::string& name,
|
||||
const NotificationCallback& callback);
|
||||
void UnsubscribeNotification(int id);
|
||||
@@ -90,6 +93,17 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||
void RemoveUserDefault(const std::string& name);
|
||||
bool IsSwipeTrackingFromScrollEventsEnabled();
|
||||
|
||||
std::string GetSystemColor(const std::string& color, mate::Arguments* args);
|
||||
|
||||
static bool IsTrustedAccessibilityClient(bool prompt);
|
||||
|
||||
// TODO(codebytere): Write tests for these methods once we
|
||||
// are running tests on a Mojave machine
|
||||
std::string GetMediaAccessStatus(const std::string& media_type,
|
||||
mate::Arguments* args);
|
||||
v8::Local<v8::Promise> AskForMediaAccess(v8::Isolate* isolate,
|
||||
const std::string& media_type);
|
||||
|
||||
// TODO(MarshallOfSound): Write tests for these methods once we
|
||||
// are running tests on a Mojave machine
|
||||
v8::Local<v8::Value> GetEffectiveAppearance(v8::Isolate* isolate);
|
||||
@@ -98,15 +112,13 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||
#endif
|
||||
bool IsDarkMode();
|
||||
bool IsInvertedColorScheme();
|
||||
bool IsHighContrastColorScheme();
|
||||
|
||||
protected:
|
||||
explicit SystemPreferences(v8::Isolate* isolate);
|
||||
~SystemPreferences() override;
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
void DoPostNotification(const std::string& name,
|
||||
const base::DictionaryValue& user_info,
|
||||
NotificationCenterKind kind);
|
||||
int DoSubscribeNotification(const std::string& name,
|
||||
const NotificationCallback& callback,
|
||||
NotificationCenterKind kind);
|
||||
@@ -139,6 +151,8 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||
|
||||
bool invertered_color_scheme_;
|
||||
|
||||
bool high_contrast_color_scheme_;
|
||||
|
||||
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
|
||||
#endif
|
||||
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
|
||||
|
||||
@@ -6,16 +6,21 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "atom/browser/mac/atom_application.h"
|
||||
#include "atom/browser/mac/dict_util.h"
|
||||
#include "atom/browser/ui/cocoa/NSColor+Hex.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "base/mac/sdk_forward_declarations.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "net/base/mac/url_conversions.h"
|
||||
#include "ui/native_theme/native_theme.h"
|
||||
|
||||
namespace mate {
|
||||
template <>
|
||||
@@ -53,11 +58,11 @@ struct Converter<NSAppearance*> {
|
||||
return v8::Null(isolate);
|
||||
}
|
||||
|
||||
if (val.name == NSAppearanceNameAqua) {
|
||||
if ([val.name isEqualToString:NSAppearanceNameAqua]) {
|
||||
return mate::ConvertToV8(isolate, "light");
|
||||
}
|
||||
if (@available(macOS 10.14, *)) {
|
||||
if (val.name == NSAppearanceNameDarkAqua) {
|
||||
if ([val.name isEqualToString:NSAppearanceNameDarkAqua]) {
|
||||
return mate::ConvertToV8(isolate, "dark");
|
||||
}
|
||||
}
|
||||
@@ -78,12 +83,45 @@ int g_next_id = 0;
|
||||
// The map to convert |id| to |int|.
|
||||
std::map<int, id> g_id_map;
|
||||
|
||||
AVMediaType ParseMediaType(const std::string& media_type) {
|
||||
if (media_type == "camera") {
|
||||
return AVMediaTypeVideo;
|
||||
} else if (media_type == "microphone") {
|
||||
return AVMediaTypeAudio;
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
std::string ConvertAuthorizationStatus(AVAuthorizationStatusMac status) {
|
||||
switch (status) {
|
||||
case AVAuthorizationStatusNotDeterminedMac:
|
||||
return "not-determined";
|
||||
case AVAuthorizationStatusRestrictedMac:
|
||||
return "restricted";
|
||||
case AVAuthorizationStatusDeniedMac:
|
||||
return "denied";
|
||||
case AVAuthorizationStatusAuthorizedMac:
|
||||
return "granted";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void SystemPreferences::PostNotification(
|
||||
const std::string& name,
|
||||
const base::DictionaryValue& user_info) {
|
||||
DoPostNotification(name, user_info, kNSDistributedNotificationCenter);
|
||||
void SystemPreferences::PostNotification(const std::string& name,
|
||||
const base::DictionaryValue& user_info,
|
||||
mate::Arguments* args) {
|
||||
bool immediate = false;
|
||||
args->GetNext(&immediate);
|
||||
|
||||
NSDistributedNotificationCenter* center =
|
||||
[NSDistributedNotificationCenter defaultCenter];
|
||||
[center postNotificationName:base::SysUTF8ToNSString(name)
|
||||
object:nil
|
||||
userInfo:DictionaryValueToNSDictionary(user_info)
|
||||
deliverImmediately:immediate];
|
||||
}
|
||||
|
||||
int SystemPreferences::SubscribeNotification(
|
||||
@@ -100,7 +138,10 @@ void SystemPreferences::UnsubscribeNotification(int request_id) {
|
||||
void SystemPreferences::PostLocalNotification(
|
||||
const std::string& name,
|
||||
const base::DictionaryValue& user_info) {
|
||||
DoPostNotification(name, user_info, kNSNotificationCenter);
|
||||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
||||
[center postNotificationName:base::SysUTF8ToNSString(name)
|
||||
object:nil
|
||||
userInfo:DictionaryValueToNSDictionary(user_info)];
|
||||
}
|
||||
|
||||
int SystemPreferences::SubscribeLocalNotification(
|
||||
@@ -116,7 +157,11 @@ void SystemPreferences::UnsubscribeLocalNotification(int request_id) {
|
||||
void SystemPreferences::PostWorkspaceNotification(
|
||||
const std::string& name,
|
||||
const base::DictionaryValue& user_info) {
|
||||
DoPostNotification(name, user_info, kNSWorkspaceNotificationCenter);
|
||||
NSNotificationCenter* center =
|
||||
[[NSWorkspace sharedWorkspace] notificationCenter];
|
||||
[center postNotificationName:base::SysUTF8ToNSString(name)
|
||||
object:nil
|
||||
userInfo:DictionaryValueToNSDictionary(user_info)];
|
||||
}
|
||||
|
||||
int SystemPreferences::SubscribeWorkspaceNotification(
|
||||
@@ -130,29 +175,6 @@ void SystemPreferences::UnsubscribeWorkspaceNotification(int request_id) {
|
||||
DoUnsubscribeNotification(request_id, kNSWorkspaceNotificationCenter);
|
||||
}
|
||||
|
||||
void SystemPreferences::DoPostNotification(
|
||||
const std::string& name,
|
||||
const base::DictionaryValue& user_info,
|
||||
NotificationCenterKind kind) {
|
||||
NSNotificationCenter* center;
|
||||
switch (kind) {
|
||||
case kNSDistributedNotificationCenter:
|
||||
center = [NSDistributedNotificationCenter defaultCenter];
|
||||
break;
|
||||
case kNSNotificationCenter:
|
||||
center = [NSNotificationCenter defaultCenter];
|
||||
break;
|
||||
case kNSWorkspaceNotificationCenter:
|
||||
center = [[NSWorkspace sharedWorkspace] notificationCenter];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
[center postNotificationName:base::SysUTF8ToNSString(name)
|
||||
object:nil
|
||||
userInfo:DictionaryValueToNSDictionary(user_info)];
|
||||
}
|
||||
|
||||
int SystemPreferences::DoSubscribeNotification(
|
||||
const std::string& name,
|
||||
const NotificationCallback& callback,
|
||||
@@ -360,12 +382,185 @@ void SystemPreferences::SetUserDefault(const std::string& name,
|
||||
}
|
||||
}
|
||||
|
||||
std::string SystemPreferences::GetAccentColor() {
|
||||
NSColor* sysColor = nil;
|
||||
if (@available(macOS 10.14, *))
|
||||
sysColor = [NSColor controlAccentColor];
|
||||
|
||||
return base::SysNSStringToUTF8([sysColor RGBAValue]);
|
||||
}
|
||||
|
||||
std::string SystemPreferences::GetSystemColor(const std::string& color,
|
||||
mate::Arguments* args) {
|
||||
NSColor* sysColor = nil;
|
||||
if (color == "blue") {
|
||||
sysColor = [NSColor systemBlueColor];
|
||||
} else if (color == "brown") {
|
||||
sysColor = [NSColor systemBrownColor];
|
||||
} else if (color == "gray") {
|
||||
sysColor = [NSColor systemGrayColor];
|
||||
} else if (color == "green") {
|
||||
sysColor = [NSColor systemGreenColor];
|
||||
} else if (color == "orange") {
|
||||
sysColor = [NSColor systemOrangeColor];
|
||||
} else if (color == "pink") {
|
||||
sysColor = [NSColor systemPinkColor];
|
||||
} else if (color == "purple") {
|
||||
sysColor = [NSColor systemPurpleColor];
|
||||
} else if (color == "red") {
|
||||
sysColor = [NSColor systemRedColor];
|
||||
} else if (color == "yellow") {
|
||||
sysColor = [NSColor systemYellowColor];
|
||||
} else {
|
||||
args->ThrowError("Unknown system color: " + color);
|
||||
return "";
|
||||
}
|
||||
|
||||
return base::SysNSStringToUTF8([sysColor hexadecimalValue]);
|
||||
}
|
||||
|
||||
// static
|
||||
bool SystemPreferences::IsTrustedAccessibilityClient(bool prompt) {
|
||||
NSDictionary* options = @{(id)kAXTrustedCheckOptionPrompt : @(prompt)};
|
||||
return AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
|
||||
}
|
||||
|
||||
std::string SystemPreferences::GetColor(const std::string& color,
|
||||
mate::Arguments* args) {
|
||||
NSColor* sysColor = nil;
|
||||
if (color == "alternate-selected-control-text") {
|
||||
sysColor = [NSColor alternateSelectedControlTextColor];
|
||||
} else if (color == "control-background") {
|
||||
sysColor = [NSColor controlBackgroundColor];
|
||||
} else if (color == "control") {
|
||||
sysColor = [NSColor controlColor];
|
||||
} else if (color == "control-text") {
|
||||
sysColor = [NSColor controlTextColor];
|
||||
} else if (color == "disabled-control") {
|
||||
sysColor = [NSColor disabledControlTextColor];
|
||||
} else if (color == "find-highlight") {
|
||||
if (@available(macOS 10.14, *))
|
||||
sysColor = [NSColor findHighlightColor];
|
||||
} else if (color == "grid") {
|
||||
sysColor = [NSColor gridColor];
|
||||
} else if (color == "header-text") {
|
||||
sysColor = [NSColor headerTextColor];
|
||||
} else if (color == "highlight") {
|
||||
sysColor = [NSColor highlightColor];
|
||||
} else if (color == "keyboard-focus-indicator") {
|
||||
sysColor = [NSColor keyboardFocusIndicatorColor];
|
||||
} else if (color == "label") {
|
||||
sysColor = [NSColor labelColor];
|
||||
} else if (color == "link") {
|
||||
sysColor = [NSColor linkColor];
|
||||
} else if (color == "placeholder-text") {
|
||||
sysColor = [NSColor placeholderTextColor];
|
||||
} else if (color == "quaternary-label") {
|
||||
sysColor = [NSColor quaternaryLabelColor];
|
||||
} else if (color == "scrubber-textured-background") {
|
||||
if (@available(macOS 10.12.2, *))
|
||||
sysColor = [NSColor scrubberTexturedBackgroundColor];
|
||||
} else if (color == "secondary-label") {
|
||||
sysColor = [NSColor secondaryLabelColor];
|
||||
} else if (color == "selected-content-background") {
|
||||
if (@available(macOS 10.14, *))
|
||||
sysColor = [NSColor selectedContentBackgroundColor];
|
||||
} else if (color == "selected-control") {
|
||||
sysColor = [NSColor selectedControlColor];
|
||||
} else if (color == "selected-control-text") {
|
||||
sysColor = [NSColor selectedControlTextColor];
|
||||
} else if (color == "selected-menu-item-text") {
|
||||
sysColor = [NSColor selectedMenuItemTextColor];
|
||||
} else if (color == "selected-text-background") {
|
||||
sysColor = [NSColor selectedTextBackgroundColor];
|
||||
} else if (color == "selected-text") {
|
||||
sysColor = [NSColor selectedTextColor];
|
||||
} else if (color == "separator") {
|
||||
if (@available(macOS 10.14, *))
|
||||
sysColor = [NSColor separatorColor];
|
||||
} else if (color == "shadow") {
|
||||
sysColor = [NSColor shadowColor];
|
||||
} else if (color == "tertiary-label") {
|
||||
sysColor = [NSColor tertiaryLabelColor];
|
||||
} else if (color == "text-background") {
|
||||
sysColor = [NSColor textBackgroundColor];
|
||||
} else if (color == "text") {
|
||||
sysColor = [NSColor textColor];
|
||||
} else if (color == "under-page-background") {
|
||||
sysColor = [NSColor underPageBackgroundColor];
|
||||
} else if (color == "unemphasized-selected-content-background") {
|
||||
if (@available(macOS 10.14, *))
|
||||
sysColor = [NSColor unemphasizedSelectedContentBackgroundColor];
|
||||
} else if (color == "unemphasized-selected-text-background") {
|
||||
if (@available(macOS 10.14, *))
|
||||
sysColor = [NSColor unemphasizedSelectedTextBackgroundColor];
|
||||
} else if (color == "unemphasized-selected-text") {
|
||||
if (@available(macOS 10.14, *))
|
||||
sysColor = [NSColor unemphasizedSelectedTextColor];
|
||||
} else if (color == "window-background") {
|
||||
sysColor = [NSColor windowBackgroundColor];
|
||||
} else if (color == "window-frame-text") {
|
||||
sysColor = [NSColor windowFrameTextColor];
|
||||
} else {
|
||||
args->ThrowError("Unknown color: " + color);
|
||||
return "";
|
||||
}
|
||||
|
||||
return base::SysNSStringToUTF8([sysColor hexadecimalValue]);
|
||||
}
|
||||
|
||||
std::string SystemPreferences::GetMediaAccessStatus(
|
||||
const std::string& media_type,
|
||||
mate::Arguments* args) {
|
||||
if (auto type = ParseMediaType(media_type)) {
|
||||
if (@available(macOS 10.14, *)) {
|
||||
return ConvertAuthorizationStatus(
|
||||
[AVCaptureDevice authorizationStatusForMediaType:type]);
|
||||
} else {
|
||||
// access always allowed pre-10.14 Mojave
|
||||
return ConvertAuthorizationStatus(AVAuthorizationStatusAuthorizedMac);
|
||||
}
|
||||
} else {
|
||||
args->ThrowError("Invalid media type");
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> SystemPreferences::AskForMediaAccess(
|
||||
v8::Isolate* isolate,
|
||||
const std::string& media_type) {
|
||||
util::Promise promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
if (auto type = ParseMediaType(media_type)) {
|
||||
if (@available(macOS 10.14, *)) {
|
||||
__block util::Promise p = std::move(promise);
|
||||
[AVCaptureDevice requestAccessForMediaType:type
|
||||
completionHandler:^(BOOL granted) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
p.Resolve(!!granted);
|
||||
});
|
||||
}];
|
||||
} else {
|
||||
// access always allowed pre-10.14 Mojave
|
||||
promise.Resolve(true);
|
||||
}
|
||||
} else {
|
||||
promise.RejectWithErrorMessage("Invalid media type");
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void SystemPreferences::RemoveUserDefault(const std::string& name) {
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults removeObjectForKey:base::SysUTF8ToNSString(name)];
|
||||
}
|
||||
|
||||
bool SystemPreferences::IsDarkMode() {
|
||||
if (@available(macOS 10.15, *)) {
|
||||
return ui::NativeTheme::GetInstanceForNativeUi()->SystemDarkModeEnabled();
|
||||
}
|
||||
NSString* mode = [[NSUserDefaults standardUserDefaults]
|
||||
stringForKey:@"AppleInterfaceStyle"];
|
||||
return [mode isEqualToString:@"Dark"];
|
||||
|
||||
@@ -20,6 +20,18 @@ namespace {
|
||||
const wchar_t kSystemPreferencesWindowClass[] =
|
||||
L"Electron_SystemPreferencesHostWindow";
|
||||
|
||||
bool g_is_high_contract_color_scheme = false;
|
||||
bool g_is_high_contract_color_scheme_initialized = false;
|
||||
|
||||
void UpdateHighContrastColorScheme() {
|
||||
HIGHCONTRAST high_contrast = {0};
|
||||
high_contrast.cbSize = sizeof(HIGHCONTRAST);
|
||||
g_is_high_contract_color_scheme =
|
||||
SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &high_contrast, 0) &&
|
||||
((high_contrast.dwFlags & HCF_HIGHCONTRASTON) != 0);
|
||||
g_is_high_contract_color_scheme_initialized = true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace api {
|
||||
@@ -28,6 +40,12 @@ bool SystemPreferences::IsAeroGlassEnabled() {
|
||||
return ui::win::IsAeroGlassEnabled();
|
||||
}
|
||||
|
||||
bool SystemPreferences::IsHighContrastColorScheme() {
|
||||
if (!g_is_high_contract_color_scheme_initialized)
|
||||
UpdateHighContrastColorScheme();
|
||||
return g_is_high_contract_color_scheme;
|
||||
}
|
||||
|
||||
std::string hexColorDWORDToRGBA(DWORD color) {
|
||||
DWORD rgba = color << 8 | color >> 24;
|
||||
std::ostringstream stream;
|
||||
@@ -119,6 +137,7 @@ std::string SystemPreferences::GetColor(const std::string& color,
|
||||
|
||||
void SystemPreferences::InitializeWindow() {
|
||||
invertered_color_scheme_ = IsInvertedColorScheme();
|
||||
high_contrast_color_scheme_ = IsHighContrastColorScheme();
|
||||
|
||||
// Wait until app is ready before creating sys color listener
|
||||
// Creating this listener before the app is ready causes global shortcuts
|
||||
@@ -169,6 +188,9 @@ LRESULT CALLBACK SystemPreferences::WndProc(HWND hwnd,
|
||||
Emit("accent-color-changed", hexColorDWORDToRGBA(new_color));
|
||||
current_color_ = new_color_string;
|
||||
}
|
||||
} else if (message == WM_SYSCOLORCHANGE ||
|
||||
(message == WM_SETTINGCHANGE && wparam == SPI_SETHIGHCONTRAST)) {
|
||||
UpdateHighContrastColorScheme();
|
||||
}
|
||||
return ::DefWindowProc(hwnd, message, wparam, lparam);
|
||||
}
|
||||
@@ -179,6 +201,13 @@ void SystemPreferences::OnSysColorChange() {
|
||||
invertered_color_scheme_ = new_invertered_color_scheme;
|
||||
Emit("inverted-color-scheme-changed", new_invertered_color_scheme);
|
||||
}
|
||||
|
||||
bool new_high_contrast_color_scheme = IsHighContrastColorScheme();
|
||||
if (new_high_contrast_color_scheme != high_contrast_color_scheme_) {
|
||||
high_contrast_color_scheme_ = new_high_contrast_color_scheme;
|
||||
Emit("high-contrast-color-scheme-changed", new_high_contrast_color_scheme);
|
||||
}
|
||||
|
||||
Emit("color-changed");
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "gin/converter.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "native_mate/persistent_dictionary.h"
|
||||
|
||||
@@ -158,7 +159,7 @@ void TopLevelWindow::OnWindowClosed() {
|
||||
Emit("closed");
|
||||
|
||||
RemoveFromParentChildWindows();
|
||||
ResetBrowserView();
|
||||
TopLevelWindow::ResetBrowserViews();
|
||||
|
||||
// Destroy the native class when window is closed.
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, GetDestroyClosure());
|
||||
@@ -266,7 +267,7 @@ void TopLevelWindow::OnWindowAlwaysOnTopChanged() {
|
||||
Emit("always-on-top-changed", IsAlwaysOnTop());
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnExecuteWindowsCommand(const std::string& command_name) {
|
||||
void TopLevelWindow::OnExecuteAppCommand(const std::string& command_name) {
|
||||
Emit("app-command", command_name);
|
||||
}
|
||||
|
||||
@@ -293,6 +294,7 @@ void TopLevelWindow::OnWindowMessage(UINT message,
|
||||
#endif
|
||||
|
||||
void TopLevelWindow::SetContentView(mate::Handle<View> view) {
|
||||
ResetBrowserViews();
|
||||
content_view_.Reset(isolate(), view.ToV8());
|
||||
window_->SetContentView(view->view());
|
||||
}
|
||||
@@ -643,7 +645,8 @@ void TopLevelWindow::SetFocusable(bool focusable) {
|
||||
void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
|
||||
mate::Handle<Menu> menu;
|
||||
if (value->IsObject() &&
|
||||
mate::V8ToString(value->ToObject()->GetConstructorName()) == "Menu" &&
|
||||
gin::V8ToString(
|
||||
isolate, value->ToObject(isolate)->GetConstructorName()) == "Menu" &&
|
||||
mate::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
|
||||
menu_.Reset(isolate, menu.ToV8());
|
||||
window_->SetMenu(menu->model());
|
||||
@@ -656,6 +659,11 @@ void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
|
||||
}
|
||||
}
|
||||
|
||||
void TopLevelWindow::RemoveMenu() {
|
||||
menu_.Reset();
|
||||
window_->SetMenu(nullptr);
|
||||
}
|
||||
|
||||
void TopLevelWindow::SetParentWindow(v8::Local<v8::Value> value,
|
||||
mate::Arguments* args) {
|
||||
if (IsModal()) {
|
||||
@@ -669,6 +677,7 @@ void TopLevelWindow::SetParentWindow(v8::Local<v8::Value> value,
|
||||
parent_window_.Reset();
|
||||
window_->SetParentWindow(nullptr);
|
||||
} else if (mate::ConvertFromV8(isolate(), value, &parent)) {
|
||||
RemoveFromParentChildWindows();
|
||||
parent_window_.Reset(isolate(), value);
|
||||
window_->SetParentWindow(parent->window_.get());
|
||||
parent->child_windows_.Set(isolate(), weak_map_id(), GetWrapper());
|
||||
@@ -678,21 +687,43 @@ void TopLevelWindow::SetParentWindow(v8::Local<v8::Value> value,
|
||||
}
|
||||
|
||||
void TopLevelWindow::SetBrowserView(v8::Local<v8::Value> value) {
|
||||
ResetBrowserView();
|
||||
ResetBrowserViews();
|
||||
AddBrowserView(value);
|
||||
}
|
||||
|
||||
void TopLevelWindow::AddBrowserView(v8::Local<v8::Value> value) {
|
||||
mate::Handle<BrowserView> browser_view;
|
||||
if (value->IsNull() || value->IsUndefined()) {
|
||||
window_->SetBrowserView(nullptr);
|
||||
} else if (mate::ConvertFromV8(isolate(), value, &browser_view)) {
|
||||
window_->SetBrowserView(browser_view->view());
|
||||
browser_view->web_contents()->SetOwnerWindow(window_.get());
|
||||
browser_view_.Reset(isolate(), value);
|
||||
if (value->IsObject() &&
|
||||
mate::ConvertFromV8(isolate(), value, &browser_view)) {
|
||||
auto get_that_view = browser_views_.find(browser_view->weak_map_id());
|
||||
if (get_that_view == browser_views_.end()) {
|
||||
window_->AddBrowserView(browser_view->view());
|
||||
browser_view->web_contents()->SetOwnerWindow(window_.get());
|
||||
browser_views_[browser_view->weak_map_id()].Reset(isolate(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TopLevelWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
|
||||
mate::Handle<BrowserView> browser_view;
|
||||
if (value->IsObject() &&
|
||||
mate::ConvertFromV8(isolate(), value, &browser_view)) {
|
||||
auto get_that_view = browser_views_.find(browser_view->weak_map_id());
|
||||
if (get_that_view != browser_views_.end()) {
|
||||
window_->RemoveBrowserView(browser_view->view());
|
||||
browser_view->web_contents()->SetOwnerWindow(nullptr);
|
||||
|
||||
(*get_that_view).second.Reset(isolate(), value);
|
||||
browser_views_.erase(get_that_view);
|
||||
}
|
||||
}
|
||||
}
|
||||
v8::Local<v8::Value> TopLevelWindow::GetNativeWindowHandle() {
|
||||
gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget();
|
||||
return ToBuffer(isolate(), static_cast<void*>(&handle), sizeof(handle));
|
||||
// TODO(MarshallOfSound): Replace once
|
||||
// https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has
|
||||
// landed
|
||||
NativeWindowHandle handle = window_->GetNativeWindowHandle();
|
||||
return ToBuffer(isolate(), &handle, sizeof(handle));
|
||||
}
|
||||
|
||||
void TopLevelWindow::SetProgressBar(double progress, mate::Arguments* args) {
|
||||
@@ -737,7 +768,7 @@ void TopLevelWindow::SetAutoHideCursor(bool auto_hide) {
|
||||
|
||||
void TopLevelWindow::SetVibrancy(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> value) {
|
||||
std::string type = mate::V8ToString(value);
|
||||
std::string type = gin::V8ToString(isolate, value);
|
||||
window_->SetVibrancy(type);
|
||||
}
|
||||
|
||||
@@ -841,12 +872,29 @@ std::vector<v8::Local<v8::Object>> TopLevelWindow::GetChildWindows() const {
|
||||
return child_windows_.Values(isolate());
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> TopLevelWindow::GetBrowserView() const {
|
||||
if (browser_view_.IsEmpty()) {
|
||||
v8::Local<v8::Value> TopLevelWindow::GetBrowserView(
|
||||
mate::Arguments* args) const {
|
||||
if (browser_views_.size() == 0) {
|
||||
return v8::Null(isolate());
|
||||
} else if (browser_views_.size() == 1) {
|
||||
auto first_view = browser_views_.begin();
|
||||
return v8::Local<v8::Value>::New(isolate(), (*first_view).second);
|
||||
} else {
|
||||
args->ThrowError(
|
||||
"BrowserWindow have multiple BrowserViews, "
|
||||
"Use getBrowserViews() instead");
|
||||
return v8::Null(isolate());
|
||||
}
|
||||
}
|
||||
|
||||
return v8::Local<v8::Value>::New(isolate(), browser_view_);
|
||||
std::vector<v8::Local<v8::Value>> TopLevelWindow::GetBrowserViews() const {
|
||||
std::vector<v8::Local<v8::Value>> ret;
|
||||
|
||||
for (auto const& views_iter : browser_views_) {
|
||||
ret.push_back(v8::Local<v8::Value>::New(isolate(), views_iter.second));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool TopLevelWindow::IsModal() const {
|
||||
@@ -938,17 +986,21 @@ int32_t TopLevelWindow::GetID() const {
|
||||
return weak_map_id();
|
||||
}
|
||||
|
||||
void TopLevelWindow::ResetBrowserView() {
|
||||
if (browser_view_.IsEmpty())
|
||||
return;
|
||||
void TopLevelWindow::ResetBrowserViews() {
|
||||
for (auto& item : browser_views_) {
|
||||
mate::Handle<BrowserView> browser_view;
|
||||
if (mate::ConvertFromV8(isolate(),
|
||||
v8::Local<v8::Value>::New(isolate(), item.second),
|
||||
&browser_view) &&
|
||||
!browser_view.IsEmpty()) {
|
||||
window_->RemoveBrowserView(browser_view->view());
|
||||
browser_view->web_contents()->SetOwnerWindow(nullptr);
|
||||
}
|
||||
|
||||
mate::Handle<BrowserView> browser_view;
|
||||
if (mate::ConvertFromV8(isolate(), GetBrowserView(), &browser_view) &&
|
||||
!browser_view.IsEmpty()) {
|
||||
browser_view->web_contents()->SetOwnerWindow(nullptr);
|
||||
item.second.Reset();
|
||||
}
|
||||
|
||||
browser_view_.Reset();
|
||||
browser_views_.clear();
|
||||
}
|
||||
|
||||
void TopLevelWindow::RemoveFromParentChildWindows() {
|
||||
@@ -1056,10 +1108,11 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("setContentProtection", &TopLevelWindow::SetContentProtection)
|
||||
.SetMethod("setFocusable", &TopLevelWindow::SetFocusable)
|
||||
.SetMethod("setMenu", &TopLevelWindow::SetMenu)
|
||||
#if !defined(OS_WIN)
|
||||
.SetMethod("removeMenu", &TopLevelWindow::RemoveMenu)
|
||||
.SetMethod("setParentWindow", &TopLevelWindow::SetParentWindow)
|
||||
#endif
|
||||
.SetMethod("setBrowserView", &TopLevelWindow::SetBrowserView)
|
||||
.SetMethod("addBrowserView", &TopLevelWindow::AddBrowserView)
|
||||
.SetMethod("removeBrowserView", &TopLevelWindow::RemoveBrowserView)
|
||||
.SetMethod("getNativeWindowHandle",
|
||||
&TopLevelWindow::GetNativeWindowHandle)
|
||||
.SetMethod("setProgressBar", &TopLevelWindow::SetProgressBar)
|
||||
@@ -1097,6 +1150,7 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("getParentWindow", &TopLevelWindow::GetParentWindow)
|
||||
.SetMethod("getChildWindows", &TopLevelWindow::GetChildWindows)
|
||||
.SetMethod("getBrowserView", &TopLevelWindow::GetBrowserView)
|
||||
.SetMethod("getBrowserViews", &TopLevelWindow::GetBrowserViews)
|
||||
.SetMethod("isModal", &TopLevelWindow::IsModal)
|
||||
.SetMethod("setThumbarButtons", &TopLevelWindow::SetThumbarButtons)
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
@@ -1131,8 +1185,9 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
TopLevelWindow::SetConstructor(isolate, base::Bind(&TopLevelWindow::New));
|
||||
|
||||
mate::Dictionary constructor(
|
||||
isolate, TopLevelWindow::GetConstructor(isolate)->GetFunction());
|
||||
mate::Dictionary constructor(isolate, TopLevelWindow::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
constructor.SetMethod("fromId",
|
||||
&mate::TrackableObject<TopLevelWindow>::FromWeakMapID);
|
||||
constructor.SetMethod("getAllWindows",
|
||||
@@ -1144,4 +1199,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_top_level_window, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_top_level_window, Initialize)
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/common/api/atom_api_native_image.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
@@ -78,7 +80,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||
void OnWindowEnterHtmlFullScreen() override;
|
||||
void OnWindowLeaveHtmlFullScreen() override;
|
||||
void OnWindowAlwaysOnTopChanged() override;
|
||||
void OnExecuteWindowsCommand(const std::string& command_name) override;
|
||||
void OnExecuteAppCommand(const std::string& command_name) override;
|
||||
void OnTouchBarItemResult(const std::string& item_id,
|
||||
const base::DictionaryValue& details) override;
|
||||
void OnNewWindowForTab() override;
|
||||
@@ -163,8 +165,13 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||
void SetContentProtection(bool enable);
|
||||
void SetFocusable(bool focusable);
|
||||
void SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> menu);
|
||||
void RemoveMenu();
|
||||
void SetParentWindow(v8::Local<v8::Value> value, mate::Arguments* args);
|
||||
virtual void SetBrowserView(v8::Local<v8::Value> value);
|
||||
virtual void AddBrowserView(v8::Local<v8::Value> value);
|
||||
virtual void RemoveBrowserView(v8::Local<v8::Value> value);
|
||||
virtual std::vector<v8::Local<v8::Value>> GetBrowserViews() const;
|
||||
virtual void ResetBrowserViews();
|
||||
v8::Local<v8::Value> GetNativeWindowHandle();
|
||||
void SetProgressBar(double progress, mate::Arguments* args);
|
||||
void SetOverlayIcon(const gfx::Image& overlay,
|
||||
@@ -195,7 +202,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||
v8::Local<v8::Value> GetContentView() const;
|
||||
v8::Local<v8::Value> GetParentWindow() const;
|
||||
std::vector<v8::Local<v8::Object>> GetChildWindows() const;
|
||||
v8::Local<v8::Value> GetBrowserView() const;
|
||||
v8::Local<v8::Value> GetBrowserView(mate::Arguments* args) const;
|
||||
bool IsModal() const;
|
||||
|
||||
// Extra APIs added in JS.
|
||||
@@ -226,8 +233,8 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||
|
||||
template <typename... Args>
|
||||
void EmitEventSoon(base::StringPiece eventName) {
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::UI, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {content::BrowserThread::UI},
|
||||
base::BindOnce(base::IgnoreResult(&TopLevelWindow::Emit<Args...>),
|
||||
weak_factory_.GetWeakPtr(), eventName));
|
||||
}
|
||||
@@ -238,7 +245,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||
#endif
|
||||
|
||||
v8::Global<v8::Value> content_view_;
|
||||
v8::Global<v8::Value> browser_view_;
|
||||
std::map<int32_t, v8::Global<v8::Value>> browser_views_;
|
||||
v8::Global<v8::Value> menu_;
|
||||
v8::Global<v8::Value> parent_window_;
|
||||
KeyWeakMap<int> child_windows_;
|
||||
|
||||
@@ -254,9 +254,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
Tray::SetConstructor(isolate, base::Bind(&Tray::New));
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("Tray", Tray::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set(
|
||||
"Tray",
|
||||
Tray::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_tray, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_tray, Initialize)
|
||||
|
||||
@@ -76,8 +76,9 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
View::SetConstructor(isolate, base::Bind(&View::New));
|
||||
|
||||
mate::Dictionary constructor(isolate,
|
||||
View::GetConstructor(isolate)->GetFunction());
|
||||
mate::Dictionary constructor(
|
||||
isolate,
|
||||
View::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("View", constructor);
|
||||
@@ -85,4 +86,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_view, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_view, Initialize)
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||
#include "atom/browser/atom_navigation_throttle.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/child_web_contents_tracker.h"
|
||||
#include "atom/browser/lib/bluetooth_chooser.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/net/atom_network_delegate.h"
|
||||
#include "atom/browser/ui/drag_util.h"
|
||||
#include "atom/browser/ui/inspectable_web_contents.h"
|
||||
#include "atom/browser/ui/inspectable_web_contents_view.h"
|
||||
#include "atom/browser/web_contents_permission_helper.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "atom/browser/web_contents_zoom_controller.h"
|
||||
@@ -44,21 +47,18 @@
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "base/values.h"
|
||||
#include "brightray/browser/inspectable_web_contents.h"
|
||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/printing/print_preview_message_handler.h"
|
||||
#include "chrome/browser/printing/print_view_manager_basic.h"
|
||||
#include "chrome/browser/ssl/security_state_tab_helper.h"
|
||||
#include "content/browser/frame_host/frame_tree_node.h"
|
||||
#include "content/browser/frame_host/render_frame_host_manager.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_view_base.h"
|
||||
#include "content/common/view_messages.h"
|
||||
#include "content/common/widget_messages.h"
|
||||
#include "content/public/browser/child_process_security_policy.h"
|
||||
#include "content/public/browser/download_request_utils.h"
|
||||
#include "content/public/browser/favicon_status.h"
|
||||
@@ -81,13 +81,12 @@
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
|
||||
#include "third_party/blink/public/platform/web_input_event.h"
|
||||
#include "third_party/blink/public/web/web_find_options.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/events/base_event_utils.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
#include "atom/browser/osr/osr_output_device.h"
|
||||
#include "atom/browser/osr/osr_render_widget_host_view.h"
|
||||
#include "atom/browser/osr/osr_web_contents_view.h"
|
||||
#endif
|
||||
@@ -101,34 +100,16 @@
|
||||
#include "ui/gfx/font_render_params.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
#include "chrome/browser/printing/print_view_manager_basic.h"
|
||||
#include "components/printing/common/print_messages.h"
|
||||
#endif
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace {
|
||||
|
||||
struct PrintSettings {
|
||||
bool silent;
|
||||
bool print_background;
|
||||
base::string16 device_name;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace mate {
|
||||
|
||||
template <>
|
||||
struct Converter<PrintSettings> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
PrintSettings* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
dict.Get("silent", &(out->silent));
|
||||
dict.Get("printBackground", &(out->print_background));
|
||||
dict.Get("deviceName", &(out->device_name));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
template <>
|
||||
struct Converter<printing::PrinterBasicInfo> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
@@ -142,6 +123,7 @@ struct Converter<printing::PrinterBasicInfo> {
|
||||
return dict.GetHandle();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template <>
|
||||
struct Converter<WindowOpenDisposition> {
|
||||
@@ -258,7 +240,7 @@ namespace api {
|
||||
namespace {
|
||||
|
||||
content::ServiceWorkerContext* GetServiceWorkerContext(
|
||||
const content::WebContents* web_contents) {
|
||||
content::WebContents* web_contents) {
|
||||
auto* context = web_contents->GetBrowserContext();
|
||||
auto* site_instance = web_contents->GetSiteInstance();
|
||||
if (!context || !site_instance)
|
||||
@@ -273,12 +255,11 @@ content::ServiceWorkerContext* GetServiceWorkerContext(
|
||||
}
|
||||
|
||||
// Called when CapturePage is done.
|
||||
void OnCapturePageDone(const base::Callback<void(const gfx::Image&)>& callback,
|
||||
const SkBitmap& bitmap) {
|
||||
void OnCapturePageDone(util::Promise promise, const SkBitmap& bitmap) {
|
||||
// Hack to enable transparency in captured image
|
||||
// TODO(nitsakh) Remove hack once fixed in chromium
|
||||
const_cast<SkBitmap&>(bitmap).setAlphaType(kPremul_SkAlphaType);
|
||||
callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||
promise.Resolve(gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -305,25 +286,32 @@ struct WebContents::FrameDispatchHelper {
|
||||
};
|
||||
|
||||
WebContents::WebContents(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents,
|
||||
Type type)
|
||||
: content::WebContentsObserver(web_contents), type_(type) {
|
||||
const mate::Dictionary options = mate::Dictionary::CreateEmpty(isolate);
|
||||
if (type == REMOTE) {
|
||||
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent(),
|
||||
false);
|
||||
Init(isolate);
|
||||
AttachAsUserData(web_contents);
|
||||
InitZoomController(web_contents, options);
|
||||
} else {
|
||||
auto session = Session::CreateFrom(isolate, GetBrowserContext());
|
||||
session_.Reset(isolate, session.ToV8());
|
||||
InitWithSessionAndOptions(isolate, web_contents, session, options);
|
||||
}
|
||||
content::WebContents* web_contents)
|
||||
: content::WebContentsObserver(web_contents),
|
||||
type_(REMOTE),
|
||||
weak_factory_(this) {
|
||||
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent(),
|
||||
false);
|
||||
Init(isolate);
|
||||
AttachAsUserData(web_contents);
|
||||
InitZoomController(web_contents, mate::Dictionary::CreateEmpty(isolate));
|
||||
}
|
||||
|
||||
WebContents::WebContents(v8::Isolate* isolate,
|
||||
const mate::Dictionary& options) {
|
||||
std::unique_ptr<content::WebContents> web_contents,
|
||||
Type type)
|
||||
: content::WebContentsObserver(web_contents.get()),
|
||||
type_(type),
|
||||
weak_factory_(this) {
|
||||
DCHECK(type != REMOTE) << "Can't take ownership of a remote WebContents";
|
||||
auto session = Session::CreateFrom(isolate, GetBrowserContext());
|
||||
session_.Reset(isolate, session.ToV8());
|
||||
InitWithSessionAndOptions(isolate, std::move(web_contents), session,
|
||||
mate::Dictionary::CreateEmpty(isolate));
|
||||
}
|
||||
|
||||
WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
|
||||
: weak_factory_(this) {
|
||||
// Read options.
|
||||
options.Get("backgroundThrottling", &background_throttling_);
|
||||
|
||||
@@ -405,7 +393,7 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||
web_contents = content::WebContents::Create(params);
|
||||
}
|
||||
|
||||
InitWithSessionAndOptions(isolate, web_contents.release(), session, options);
|
||||
InitWithSessionAndOptions(isolate, std::move(web_contents), session, options);
|
||||
}
|
||||
|
||||
void WebContents::InitZoomController(content::WebContents* web_contents,
|
||||
@@ -417,43 +405,47 @@ void WebContents::InitZoomController(content::WebContents* web_contents,
|
||||
zoom_controller_->SetDefaultZoomFactor(zoom_factor);
|
||||
}
|
||||
|
||||
void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents,
|
||||
mate::Handle<api::Session> session,
|
||||
const mate::Dictionary& options) {
|
||||
Observe(web_contents);
|
||||
InitWithWebContents(web_contents, session->browser_context(), IsGuest());
|
||||
void WebContents::InitWithSessionAndOptions(
|
||||
v8::Isolate* isolate,
|
||||
std::unique_ptr<content::WebContents> owned_web_contents,
|
||||
mate::Handle<api::Session> session,
|
||||
const mate::Dictionary& options) {
|
||||
Observe(owned_web_contents.get());
|
||||
// TODO(zcbenz): Make InitWithWebContents take unique_ptr.
|
||||
// At the time of writing we are going through a refactoring and I don't want
|
||||
// to make other people's work harder.
|
||||
InitWithWebContents(owned_web_contents.release(), session->browser_context(),
|
||||
IsGuest());
|
||||
|
||||
managed_web_contents()->GetView()->SetDelegate(this);
|
||||
|
||||
auto* prefs = web_contents->GetMutableRendererPrefs();
|
||||
auto* prefs = web_contents()->GetMutableRendererPrefs();
|
||||
prefs->accept_languages = g_browser_process->GetApplicationLocale();
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_WIN)
|
||||
// Update font settings.
|
||||
CR_DEFINE_STATIC_LOCAL(
|
||||
const gfx::FontRenderParams, params,
|
||||
(gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr)));
|
||||
prefs->should_antialias_text = params.antialiasing;
|
||||
prefs->use_subpixel_positioning = params.subpixel_positioning;
|
||||
prefs->hinting = params.hinting;
|
||||
prefs->use_autohinter = params.autohinter;
|
||||
prefs->use_bitmaps = params.use_bitmaps;
|
||||
prefs->subpixel_rendering = params.subpixel_rendering;
|
||||
static const base::NoDestructor<gfx::FontRenderParams> params(
|
||||
gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr));
|
||||
prefs->should_antialias_text = params->antialiasing;
|
||||
prefs->use_subpixel_positioning = params->subpixel_positioning;
|
||||
prefs->hinting = params->hinting;
|
||||
prefs->use_autohinter = params->autohinter;
|
||||
prefs->use_bitmaps = params->use_bitmaps;
|
||||
prefs->subpixel_rendering = params->subpixel_rendering;
|
||||
#endif
|
||||
|
||||
// Save the preferences in C++.
|
||||
new WebContentsPreferences(web_contents, options);
|
||||
new WebContentsPreferences(web_contents(), options);
|
||||
|
||||
// Initialize permission helper.
|
||||
WebContentsPermissionHelper::CreateForWebContents(web_contents);
|
||||
WebContentsPermissionHelper::CreateForWebContents(web_contents());
|
||||
// Initialize security state client.
|
||||
SecurityStateTabHelper::CreateForWebContents(web_contents);
|
||||
SecurityStateTabHelper::CreateForWebContents(web_contents());
|
||||
// Initialize zoom controller.
|
||||
InitZoomController(web_contents, options);
|
||||
InitZoomController(web_contents(), options);
|
||||
|
||||
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent(),
|
||||
false);
|
||||
web_contents()->SetUserAgentOverride(GetBrowserContext()->GetUserAgent(),
|
||||
false);
|
||||
|
||||
if (IsGuest()) {
|
||||
NativeWindow* owner_window = nullptr;
|
||||
@@ -469,7 +461,7 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
Init(isolate);
|
||||
AttachAsUserData(web_contents);
|
||||
AttachAsUserData(web_contents());
|
||||
}
|
||||
|
||||
WebContents::~WebContents() {
|
||||
@@ -480,14 +472,25 @@ WebContents::~WebContents() {
|
||||
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
||||
|
||||
if (type_ == WEB_VIEW) {
|
||||
DCHECK(!web_contents()->GetOuterWebContents())
|
||||
<< "Should never manually destroy an attached webview";
|
||||
// For webview simply destroy the WebContents immediately.
|
||||
DestroyWebContents(false /* async */);
|
||||
} else if (type_ == BROWSER_WINDOW && owner_window()) {
|
||||
// For BrowserWindow we should close the window and clean up everything
|
||||
// before WebContents is destroyed.
|
||||
for (ExtendedWebContentsObserver& observer : observers_)
|
||||
observer.OnCloseContents();
|
||||
// BrowserWindow destroys WebContents asynchronously, manually emit the
|
||||
// destroyed event here.
|
||||
WebContentsDestroyed();
|
||||
} else if (Browser::Get()->is_shutting_down()) {
|
||||
// Destroy WebContents directly when app is shutting down.
|
||||
DestroyWebContents(false /* async */);
|
||||
} else {
|
||||
if (type_ == BROWSER_WINDOW && owner_window()) {
|
||||
for (ExtendedWebContentsObserver& observer : observers_)
|
||||
observer.OnCloseContents();
|
||||
} else {
|
||||
DestroyWebContents(true /* async */);
|
||||
}
|
||||
// Destroy WebContents asynchronously unless app is shutting down,
|
||||
// because destroy() might be called inside WebContents's event handler.
|
||||
DestroyWebContents(true /* async */);
|
||||
// The WebContentsDestroyed will not be called automatically because we
|
||||
// destroy the webContents in the next tick. So we have to manually
|
||||
// call it here to make sure "destroyed" event is emitted.
|
||||
@@ -531,10 +534,10 @@ void WebContents::WebContentsCreated(content::WebContents* source_contents,
|
||||
const std::string& frame_name,
|
||||
const GURL& target_url,
|
||||
content::WebContents* new_contents) {
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
auto api_web_contents = CreateFrom(isolate(), new_contents, BROWSER_WINDOW);
|
||||
Emit("-web-contents-created", api_web_contents, target_url, frame_name);
|
||||
ChildWebContentsTracker::CreateForWebContents(new_contents);
|
||||
auto* tracker = ChildWebContentsTracker::FromWebContents(new_contents);
|
||||
tracker->url = target_url;
|
||||
tracker->frame_name = frame_name;
|
||||
}
|
||||
|
||||
void WebContents::AddNewContents(
|
||||
@@ -544,13 +547,17 @@ void WebContents::AddNewContents(
|
||||
const gfx::Rect& initial_rect,
|
||||
bool user_gesture,
|
||||
bool* was_blocked) {
|
||||
new ChildWebContentsTracker(new_contents.get());
|
||||
auto* tracker = ChildWebContentsTracker::FromWebContents(new_contents.get());
|
||||
DCHECK(tracker);
|
||||
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
auto api_web_contents = CreateFrom(isolate(), new_contents.release());
|
||||
auto api_web_contents =
|
||||
CreateAndTake(isolate(), std::move(new_contents), BROWSER_WINDOW);
|
||||
if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
|
||||
initial_rect.x(), initial_rect.y(), initial_rect.width(),
|
||||
initial_rect.height())) {
|
||||
initial_rect.height(), tracker->url, tracker->frame_name)) {
|
||||
// TODO(zcbenz): Can we make this sync?
|
||||
api_web_contents->DestroyWebContents(true /* async */);
|
||||
}
|
||||
}
|
||||
@@ -594,7 +601,7 @@ void WebContents::SetContentsBounds(content::WebContents* source,
|
||||
|
||||
void WebContents::CloseContents(content::WebContents* source) {
|
||||
Emit("close");
|
||||
#if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
HideAutofillPopup();
|
||||
#endif
|
||||
if (managed_web_contents())
|
||||
@@ -612,15 +619,15 @@ void WebContents::UpdateTargetURL(content::WebContents* source,
|
||||
Emit("update-target-url", url);
|
||||
}
|
||||
|
||||
void WebContents::HandleKeyboardEvent(
|
||||
bool WebContents::HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
if (type_ == WEB_VIEW && embedder_) {
|
||||
// Send the unhandled keyboard events back to the embedder.
|
||||
embedder_->HandleKeyboardEvent(source, event);
|
||||
return embedder_->HandleKeyboardEvent(source, event);
|
||||
} else {
|
||||
// Go to the default keyboard handling.
|
||||
CommonWebContentsDelegate::HandleKeyboardEvent(source, event);
|
||||
return CommonWebContentsDelegate::HandleKeyboardEvent(source, event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -720,7 +727,7 @@ void WebContents::FindReply(content::WebContents* web_contents,
|
||||
bool WebContents::CheckMediaAccessPermission(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
const GURL& security_origin,
|
||||
content::MediaStreamType type) {
|
||||
blink::MediaStreamType type) {
|
||||
auto* web_contents =
|
||||
content::WebContents::FromRenderFrameHost(render_frame_host);
|
||||
auto* permission_helper =
|
||||
@@ -763,7 +770,8 @@ void WebContents::OnAudioStateChanged(bool audible) {
|
||||
Emit("-audio-state-changed", audible);
|
||||
}
|
||||
|
||||
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
||||
void WebContents::BeforeUnloadFired(bool proceed,
|
||||
const base::TimeTicks& proceed_time) {
|
||||
// Do nothing, we override this method just to avoid compilation error since
|
||||
// there are two virtual functions named BeforeUnloadFired.
|
||||
}
|
||||
@@ -776,8 +784,29 @@ void WebContents::RenderViewCreated(content::RenderViewHost* render_view_host) {
|
||||
impl->disable_hidden_ = !background_throttling_;
|
||||
}
|
||||
|
||||
void WebContents::RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||
content::RenderViewHost* new_host) {
|
||||
currently_committed_process_id_ = new_host->GetProcess()->GetID();
|
||||
}
|
||||
|
||||
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||
// This event is necessary for tracking any states with respect to
|
||||
// intermediate render view hosts aka speculative render view hosts. Currently
|
||||
// used by object-registry.js to ref count remote objects.
|
||||
Emit("render-view-deleted", render_view_host->GetProcess()->GetID());
|
||||
|
||||
if (-1 == currently_committed_process_id_ ||
|
||||
render_view_host->GetProcess()->GetID() ==
|
||||
currently_committed_process_id_) {
|
||||
currently_committed_process_id_ = -1;
|
||||
|
||||
// When the RVH that has been deleted is the current RVH it means that the
|
||||
// the web contents are being closed. This is communicated by this event.
|
||||
// Currently tracked by guest-window-manager.js to destroy the
|
||||
// BrowserWindow.
|
||||
Emit("current-render-view-deleted",
|
||||
render_view_host->GetProcess()->GetID());
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
||||
@@ -812,6 +841,10 @@ void WebContents::DidChangeThemeColor(SkColor theme_color) {
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::DidAcquireFullscreen(content::RenderFrameHost* rfh) {
|
||||
set_fullscreen_frame(rfh);
|
||||
}
|
||||
|
||||
void WebContents::DocumentLoadedInFrame(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
if (!render_frame_host->GetParent())
|
||||
@@ -974,8 +1007,8 @@ void WebContents::DevToolsFocused() {
|
||||
void WebContents::DevToolsOpened() {
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
auto handle = WebContents::CreateFrom(
|
||||
isolate(), managed_web_contents()->GetDevToolsWebContents());
|
||||
auto handle =
|
||||
FromOrCreate(isolate(), managed_web_contents()->GetDevToolsWebContents());
|
||||
devtools_web_contents_.Reset(isolate(), handle.ToV8());
|
||||
|
||||
// Set inspected tabID.
|
||||
@@ -985,8 +1018,7 @@ void WebContents::DevToolsOpened() {
|
||||
|
||||
// Inherit owner window in devtools when it doesn't have one.
|
||||
auto* devtools = managed_web_contents()->GetDevToolsWebContents();
|
||||
bool has_window =
|
||||
devtools->GetUserData(NativeWindowRelay::kNativeWindowRelayUserDataKey);
|
||||
bool has_window = devtools->GetUserData(NativeWindowRelay::UserDataKey());
|
||||
if (owner_window() && !has_window)
|
||||
handle->SetOwnerWindow(devtools, owner_window());
|
||||
|
||||
@@ -1001,7 +1033,7 @@ void WebContents::DevToolsClosed() {
|
||||
Emit("devtools-closed");
|
||||
}
|
||||
|
||||
#if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
void WebContents::ShowAutofillPopup(content::RenderFrameHost* frame_host,
|
||||
const gfx::RectF& bounds,
|
||||
const std::vector<base::string16>& values,
|
||||
@@ -1026,7 +1058,7 @@ void WebContents::ShowAutofillPopup(content::RenderFrameHost* frame_host,
|
||||
bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(WebContents, message)
|
||||
IPC_MESSAGE_HANDLER_CODE(ViewHostMsg_SetCursor, OnCursorChange,
|
||||
IPC_MESSAGE_HANDLER_CODE(WidgetHostMsg_SetCursor, OnCursorChange,
|
||||
handled = false)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
@@ -1048,7 +1080,7 @@ bool WebContents::OnMessageReceived(const IPC::Message& message,
|
||||
FrameDispatchHelper::OnSetTemporaryZoomLevel)
|
||||
IPC_MESSAGE_FORWARD_DELAY_REPLY(AtomFrameHostMsg_GetZoomLevel, &helper,
|
||||
FrameDispatchHelper::OnGetZoomLevel)
|
||||
#if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
IPC_MESSAGE_HANDLER(AtomAutofillFrameHostMsg_ShowPopup, ShowAutofillPopup)
|
||||
IPC_MESSAGE_HANDLER(AtomAutofillFrameHostMsg_HidePopup, HideAutofillPopup)
|
||||
#endif
|
||||
@@ -1099,6 +1131,37 @@ void WebContents::NavigationEntryCommitted(
|
||||
details.is_same_document, details.did_replace_entry);
|
||||
}
|
||||
|
||||
void WebContents::SetBackgroundThrottling(bool allowed) {
|
||||
background_throttling_ = allowed;
|
||||
|
||||
auto* contents = web_contents();
|
||||
if (!contents) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* render_view_host = contents->GetRenderViewHost();
|
||||
if (!render_view_host) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* render_process_host = render_view_host->GetProcess();
|
||||
if (!render_process_host) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* render_widget_host_impl = content::RenderWidgetHostImpl::FromID(
|
||||
render_process_host->GetID(), render_view_host->GetRoutingID());
|
||||
if (!render_widget_host_impl) {
|
||||
return;
|
||||
}
|
||||
|
||||
render_widget_host_impl->disable_hidden_ = !background_throttling_;
|
||||
|
||||
if (render_widget_host_impl->is_hidden()) {
|
||||
render_widget_host_impl->WasShown(false);
|
||||
}
|
||||
}
|
||||
|
||||
int WebContents::GetProcessID() const {
|
||||
return web_contents()->GetMainFrame()->GetProcess()->GetID();
|
||||
}
|
||||
@@ -1130,8 +1193,9 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||
if (!options.Get("httpReferrer", ¶ms.referrer)) {
|
||||
GURL http_referrer;
|
||||
if (options.Get("httpReferrer", &http_referrer))
|
||||
params.referrer = content::Referrer(http_referrer.GetAsReferrer(),
|
||||
blink::kWebReferrerPolicyDefault);
|
||||
params.referrer =
|
||||
content::Referrer(http_referrer.GetAsReferrer(),
|
||||
network::mojom::ReferrerPolicy::kDefault);
|
||||
}
|
||||
|
||||
std::string user_agent;
|
||||
@@ -1157,6 +1221,9 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||
params.transition_type = ui::PAGE_TRANSITION_TYPED;
|
||||
params.should_clear_history_list = true;
|
||||
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
||||
// Discord non-committed entries to ensure that we don't re-use a pending
|
||||
// entry
|
||||
web_contents()->GetController().DiscardNonCommittedEntries();
|
||||
web_contents()->GetController().LoadURLWithParams(params);
|
||||
|
||||
// Set the background color of RenderWidgetHostView.
|
||||
@@ -1271,14 +1338,16 @@ void WebContents::OpenDevTools(mate::Arguments* args) {
|
||||
if (type_ == WEB_VIEW || !owner_window()) {
|
||||
state = "detach";
|
||||
}
|
||||
bool activate = true;
|
||||
if (args && args->Length() == 1) {
|
||||
mate::Dictionary options;
|
||||
if (args->GetNext(&options)) {
|
||||
options.Get("mode", &state);
|
||||
options.Get("activate", &activate);
|
||||
}
|
||||
}
|
||||
managed_web_contents()->SetDockState(state);
|
||||
managed_web_contents()->ShowDevTools();
|
||||
managed_web_contents()->ShowDevTools(activate);
|
||||
}
|
||||
|
||||
void WebContents::CloseDevTools() {
|
||||
@@ -1313,8 +1382,8 @@ void WebContents::EnableDeviceEmulation(
|
||||
frame_host ? frame_host->GetView()->GetRenderWidgetHost() : nullptr;
|
||||
if (!widget_host)
|
||||
return;
|
||||
widget_host->Send(
|
||||
new ViewMsg_EnableDeviceEmulation(widget_host->GetRoutingID(), params));
|
||||
widget_host->Send(new WidgetMsg_EnableDeviceEmulation(
|
||||
widget_host->GetRoutingID(), params));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1329,7 +1398,7 @@ void WebContents::DisableDeviceEmulation() {
|
||||
if (!widget_host)
|
||||
return;
|
||||
widget_host->Send(
|
||||
new ViewMsg_DisableDeviceEmulation(widget_host->GetRoutingID()));
|
||||
new WidgetMsg_DisableDeviceEmulation(widget_host->GetRoutingID()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1422,40 +1491,58 @@ bool WebContents::IsCurrentlyAudible() {
|
||||
return web_contents()->IsCurrentlyAudible();
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
void WebContents::Print(mate::Arguments* args) {
|
||||
PrintSettings settings = {false, false, base::string16()};
|
||||
if (args->Length() >= 1 && !args->GetNext(&settings)) {
|
||||
args->ThrowError();
|
||||
bool silent = false, print_background = false;
|
||||
base::string16 device_name;
|
||||
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
|
||||
base::DictionaryValue settings;
|
||||
if (args->Length() >= 1 && !args->GetNext(&options)) {
|
||||
args->ThrowError("Invalid print settings specified");
|
||||
return;
|
||||
}
|
||||
auto* print_view_manager_basic_ptr =
|
||||
printing::PrintViewManagerBasic::FromWebContents(web_contents());
|
||||
if (args->Length() == 2) {
|
||||
base::Callback<void(bool)> callback;
|
||||
if (!args->GetNext(&callback)) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
print_view_manager_basic_ptr->SetCallback(callback);
|
||||
printing::CompletionCallback callback;
|
||||
if (args->Length() == 2 && !args->GetNext(&callback)) {
|
||||
args->ThrowError("Invalid optional callback provided");
|
||||
return;
|
||||
}
|
||||
print_view_manager_basic_ptr->PrintNow(
|
||||
web_contents()->GetMainFrame(), settings.silent,
|
||||
settings.print_background, settings.device_name);
|
||||
options.Get("silent", &silent);
|
||||
options.Get("printBackground", &print_background);
|
||||
if (options.Get("deviceName", &device_name) && !device_name.empty()) {
|
||||
settings.SetString(printing::kSettingDeviceName, device_name);
|
||||
}
|
||||
auto* print_view_manager =
|
||||
printing::PrintViewManagerBasic::FromWebContents(web_contents());
|
||||
auto* focused_frame = web_contents()->GetFocusedFrame();
|
||||
auto* rfh = focused_frame && focused_frame->HasSelection()
|
||||
? focused_frame
|
||||
: web_contents()->GetMainFrame();
|
||||
print_view_manager->PrintNow(
|
||||
rfh,
|
||||
std::make_unique<PrintMsg_PrintPages>(rfh->GetRoutingID(), silent,
|
||||
print_background, settings),
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
std::vector<printing::PrinterBasicInfo> WebContents::GetPrinterList() {
|
||||
std::vector<printing::PrinterBasicInfo> printers;
|
||||
auto print_backend = printing::PrintBackend::CreateInstance(nullptr);
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
print_backend->EnumeratePrinters(&printers);
|
||||
{
|
||||
// TODO(deepak1556): Deprecate this api in favor of an
|
||||
// async version and post a non blocing task call.
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
print_backend->EnumeratePrinters(&printers);
|
||||
}
|
||||
return printers;
|
||||
}
|
||||
|
||||
void WebContents::PrintToPDF(const base::DictionaryValue& setting,
|
||||
const PrintToPDFCallback& callback) {
|
||||
printing::PrintPreviewMessageHandler::FromWebContents(web_contents())
|
||||
->PrintToPDF(setting, callback);
|
||||
void WebContents::PrintToPDF(
|
||||
const base::DictionaryValue& settings,
|
||||
const PrintPreviewMessageHandler::PrintToPDFCallback& callback) {
|
||||
PrintPreviewMessageHandler::FromWebContents(web_contents())
|
||||
->PrintToPDF(settings, callback);
|
||||
}
|
||||
#endif
|
||||
|
||||
void WebContents::AddWorkSpace(mate::Arguments* args,
|
||||
const base::FilePath& path) {
|
||||
@@ -1520,17 +1607,22 @@ void WebContents::ReplaceMisspelling(const base::string16& word) {
|
||||
}
|
||||
|
||||
uint32_t WebContents::FindInPage(mate::Arguments* args) {
|
||||
uint32_t request_id = GetNextRequestId();
|
||||
base::string16 search_text;
|
||||
blink::WebFindOptions options;
|
||||
if (!args->GetNext(&search_text) || search_text.empty()) {
|
||||
args->ThrowError("Must provide a non-empty search content");
|
||||
return 0;
|
||||
}
|
||||
|
||||
args->GetNext(&options);
|
||||
uint32_t request_id = GetNextRequestId();
|
||||
mate::Dictionary dict;
|
||||
auto options = blink::mojom::FindOptions::New();
|
||||
if (args->GetNext(&dict)) {
|
||||
dict.Get("forward", &options->forward);
|
||||
dict.Get("matchCase", &options->match_case);
|
||||
dict.Get("findNext", &options->find_next);
|
||||
}
|
||||
|
||||
web_contents()->Find(request_id, search_text, options);
|
||||
web_contents()->Find(request_id, search_text, std::move(options));
|
||||
return request_id;
|
||||
}
|
||||
|
||||
@@ -1588,13 +1680,41 @@ bool WebContents::SendIPCMessageWithSender(bool internal,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id) {
|
||||
auto* frame_host = web_contents()->GetMainFrame();
|
||||
if (frame_host) {
|
||||
return frame_host->Send(new AtomFrameMsg_Message(frame_host->GetRoutingID(),
|
||||
internal, send_to_all,
|
||||
channel, args, sender_id));
|
||||
std::vector<content::RenderFrameHost*> target_hosts;
|
||||
if (!send_to_all) {
|
||||
auto* frame_host = web_contents()->GetMainFrame();
|
||||
if (frame_host) {
|
||||
target_hosts.push_back(frame_host);
|
||||
}
|
||||
} else {
|
||||
target_hosts = web_contents()->GetAllFrames();
|
||||
}
|
||||
return false;
|
||||
|
||||
bool handled = false;
|
||||
for (auto* frame_host : target_hosts) {
|
||||
handled = frame_host->Send(
|
||||
new AtomFrameMsg_Message(frame_host->GetRoutingID(), internal,
|
||||
false, channel, args, sender_id)) ||
|
||||
handled;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool WebContents::SendIPCMessageToFrame(bool internal,
|
||||
bool send_to_all,
|
||||
int32_t frame_id,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args) {
|
||||
auto frames = web_contents()->GetAllFrames();
|
||||
auto iter = std::find_if(frames.begin(), frames.end(), [frame_id](auto* f) {
|
||||
return f->GetRoutingID() == frame_id;
|
||||
});
|
||||
if (iter == frames.end())
|
||||
return false;
|
||||
if (!(*iter)->IsRenderFrameLive())
|
||||
return false;
|
||||
return (*iter)->Send(new AtomFrameMsg_Message(
|
||||
frame_id, internal, send_to_all, channel, args, 0 /* sender_id */));
|
||||
}
|
||||
|
||||
void WebContents::SendInputEvent(v8::Isolate* isolate,
|
||||
@@ -1636,6 +1756,19 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
|
||||
mouse_wheel_event);
|
||||
#endif
|
||||
} else {
|
||||
// Chromium expects phase info in wheel events (and applies a
|
||||
// DCHECK to verify it). See: https://crbug.com/756524.
|
||||
mouse_wheel_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
|
||||
mouse_wheel_event.dispatch_type = blink::WebInputEvent::kBlocking;
|
||||
rwh->ForwardWheelEvent(mouse_wheel_event);
|
||||
|
||||
// Send a synthetic wheel event with phaseEnded to finish scrolling.
|
||||
mouse_wheel_event.has_synthetic_phase = true;
|
||||
mouse_wheel_event.delta_x = 0;
|
||||
mouse_wheel_event.delta_y = 0;
|
||||
mouse_wheel_event.phase = blink::WebMouseWheelEvent::kPhaseEnded;
|
||||
mouse_wheel_event.dispatch_type =
|
||||
blink::WebInputEvent::kEventNonBlocking;
|
||||
rwh->ForwardWheelEvent(mouse_wheel_event);
|
||||
}
|
||||
return;
|
||||
@@ -1693,28 +1826,25 @@ void WebContents::StartDrag(const mate::Dictionary& item,
|
||||
|
||||
// Start dragging.
|
||||
if (!files.empty()) {
|
||||
base::MessageLoop::ScopedNestableTaskAllower allow;
|
||||
base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
|
||||
DragFileItems(files, icon->image(), web_contents()->GetNativeView());
|
||||
} else {
|
||||
args->ThrowError("Must specify either 'file' or 'files' option");
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::CapturePage(mate::Arguments* args) {
|
||||
v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* args) {
|
||||
gfx::Rect rect;
|
||||
base::Callback<void(const gfx::Image&)> callback;
|
||||
util::Promise promise(isolate());
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
if (!(args->Length() == 1 && args->GetNext(&callback)) &&
|
||||
!(args->Length() == 2 && args->GetNext(&rect) &&
|
||||
args->GetNext(&callback))) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
// get rect arguments if they exist
|
||||
args->GetNext(&rect);
|
||||
|
||||
auto* const view = web_contents()->GetRenderWidgetHostView();
|
||||
if (!view) {
|
||||
callback.Run(gfx::Image());
|
||||
return;
|
||||
promise.Resolve(gfx::Image());
|
||||
return handle;
|
||||
}
|
||||
|
||||
// Capture full page if user doesn't specify a |rect|.
|
||||
@@ -1733,7 +1863,8 @@ void WebContents::CapturePage(mate::Arguments* args) {
|
||||
bitmap_size = gfx::ScaleToCeiledSize(view_size, scale);
|
||||
|
||||
view->CopyFromSurface(gfx::Rect(rect.origin(), view_size), bitmap_size,
|
||||
base::BindOnce(&OnCapturePageDone, callback));
|
||||
base::BindOnce(&OnCapturePageDone, std::move(promise)));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void WebContents::OnCursorChange(const content::WebCursor& cursor) {
|
||||
@@ -1889,6 +2020,13 @@ v8::Local<v8::Value> WebContents::GetLastWebPreferences(
|
||||
return mate::ConvertToV8(isolate, *web_preferences->last_preference());
|
||||
}
|
||||
|
||||
bool WebContents::IsRemoteModuleEnabled() const {
|
||||
if (auto* web_preferences = WebContentsPreferences::From(web_contents())) {
|
||||
return web_preferences->IsRemoteModuleEnabled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> WebContents::GetOwnerBrowserWindow() const {
|
||||
if (owner_window())
|
||||
return BrowserWindow::From(isolate(), owner_window());
|
||||
@@ -1989,6 +2127,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "WebContents"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.MakeDestroyable()
|
||||
.SetMethod("setBackgroundThrottling",
|
||||
&WebContents::SetBackgroundThrottling)
|
||||
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
||||
.SetMethod("getOSProcessId", &WebContents::GetOSProcessID)
|
||||
.SetMethod("equal", &WebContents::Equal)
|
||||
@@ -2036,12 +2176,14 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("isFocused", &WebContents::IsFocused)
|
||||
.SetMethod("tabTraverse", &WebContents::TabTraverse)
|
||||
.SetMethod("_send", &WebContents::SendIPCMessage)
|
||||
.SetMethod("_sendToFrame", &WebContents::SendIPCMessageToFrame)
|
||||
.SetMethod("sendInputEvent", &WebContents::SendInputEvent)
|
||||
.SetMethod("beginFrameSubscription", &WebContents::BeginFrameSubscription)
|
||||
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
|
||||
.SetMethod("startDrag", &WebContents::StartDrag)
|
||||
.SetMethod("isGuest", &WebContents::IsGuest)
|
||||
.SetMethod("attachToIframe", &WebContents::AttachToIframe)
|
||||
.SetMethod("detachFromOuterFrame", &WebContents::DetachFromOuterFrame)
|
||||
.SetMethod("isOffscreen", &WebContents::IsOffScreen)
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
.SetMethod("startPainting", &WebContents::StartPainting)
|
||||
@@ -2052,21 +2194,24 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
#endif
|
||||
.SetMethod("invalidate", &WebContents::Invalidate)
|
||||
.SetMethod("setZoomLevel", &WebContents::SetZoomLevel)
|
||||
.SetMethod("_getZoomLevel", &WebContents::GetZoomLevel)
|
||||
.SetMethod("getZoomLevel", &WebContents::GetZoomLevel)
|
||||
.SetMethod("setZoomFactor", &WebContents::SetZoomFactor)
|
||||
.SetMethod("_getZoomFactor", &WebContents::GetZoomFactor)
|
||||
.SetMethod("getZoomFactor", &WebContents::GetZoomFactor)
|
||||
.SetMethod("getType", &WebContents::GetType)
|
||||
.SetMethod("_getPreloadPath", &WebContents::GetPreloadPath)
|
||||
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
|
||||
.SetMethod("getLastWebPreferences", &WebContents::GetLastWebPreferences)
|
||||
.SetMethod("_isRemoteModuleEnabled", &WebContents::IsRemoteModuleEnabled)
|
||||
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
|
||||
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
|
||||
.SetMethod("unregisterServiceWorker",
|
||||
&WebContents::UnregisterServiceWorker)
|
||||
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
|
||||
.SetMethod("print", &WebContents::Print)
|
||||
.SetMethod("getPrinters", &WebContents::GetPrinterList)
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
.SetMethod("_print", &WebContents::Print)
|
||||
.SetMethod("_getPrinters", &WebContents::GetPrinterList)
|
||||
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
||||
#endif
|
||||
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
||||
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
||||
.SetMethod("showDefinitionForSelection",
|
||||
@@ -2097,7 +2242,7 @@ void WebContents::OnRendererMessage(content::RenderFrameHost* frame_host,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args) {
|
||||
// webContents.emit(channel, new Event(), args...);
|
||||
Emit(channel, args);
|
||||
EmitWithSender(channel, frame_host, nullptr, args);
|
||||
}
|
||||
|
||||
void WebContents::OnRendererMessageSync(content::RenderFrameHost* frame_host,
|
||||
@@ -2123,35 +2268,43 @@ void WebContents::OnRendererMessageTo(content::RenderFrameHost* frame_host,
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::CreateFrom(
|
||||
v8::Isolate* isolate,
|
||||
content::WebContents* web_contents) {
|
||||
// We have an existing WebContents object in JS.
|
||||
auto* existing = TrackableObject::FromWrappedClass(isolate, web_contents);
|
||||
if (existing)
|
||||
return mate::CreateHandle(isolate, static_cast<WebContents*>(existing));
|
||||
|
||||
// Otherwise create a new WebContents wrapper object.
|
||||
return mate::CreateHandle(isolate,
|
||||
new WebContents(isolate, web_contents, REMOTE));
|
||||
}
|
||||
|
||||
mate::Handle<WebContents> WebContents::CreateFrom(
|
||||
v8::Isolate* isolate,
|
||||
content::WebContents* web_contents,
|
||||
Type type) {
|
||||
// Otherwise create a new WebContents wrapper object.
|
||||
return mate::CreateHandle(isolate,
|
||||
new WebContents(isolate, web_contents, type));
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::Create(v8::Isolate* isolate,
|
||||
const mate::Dictionary& options) {
|
||||
return mate::CreateHandle(isolate, new WebContents(isolate, options));
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::CreateAndTake(
|
||||
v8::Isolate* isolate,
|
||||
std::unique_ptr<content::WebContents> web_contents,
|
||||
Type type) {
|
||||
return mate::CreateHandle(
|
||||
isolate, new WebContents(isolate, std::move(web_contents), type));
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::From(
|
||||
v8::Isolate* isolate,
|
||||
content::WebContents* web_contents) {
|
||||
auto* existing = TrackableObject::FromWrappedClass(isolate, web_contents);
|
||||
if (existing)
|
||||
return mate::CreateHandle(isolate, static_cast<WebContents*>(existing));
|
||||
else
|
||||
return mate::Handle<WebContents>();
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::FromOrCreate(
|
||||
v8::Isolate* isolate,
|
||||
content::WebContents* web_contents) {
|
||||
auto existing = From(isolate, web_contents);
|
||||
if (!existing.IsEmpty())
|
||||
return existing;
|
||||
else
|
||||
return mate::CreateHandle(isolate, new WebContents(isolate, web_contents));
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
@@ -2166,7 +2319,9 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("WebContents", WebContents::GetConstructor(isolate)->GetFunction());
|
||||
dict.Set("WebContents", WebContents::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
dict.SetMethod("create", &WebContents::Create);
|
||||
dict.SetMethod("fromId", &mate::TrackableObject<WebContents>::FromWeakMapID);
|
||||
dict.SetMethod("getAllWebContents",
|
||||
@@ -2175,4 +2330,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_web_contents, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_web_contents, Initialize)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "atom/browser/common_web_contents_delegate.h"
|
||||
#include "atom/browser/ui/autofill_popup.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "base/observer_list_types.h"
|
||||
#include "content/common/cursors/webcursor.h"
|
||||
#include "content/public/browser/keyboard_event_processing_result.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
@@ -22,17 +23,18 @@
|
||||
#include "content/public/common/favicon_url.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "printing/backend/print_backend.h"
|
||||
#include "printing/buildflags/buildflags.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
#include "atom/browser/printing/print_preview_message_handler.h"
|
||||
#include "printing/backend/print_backend.h"
|
||||
#endif
|
||||
|
||||
namespace blink {
|
||||
struct WebDeviceEmulationParams;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
class InspectableWebContents;
|
||||
}
|
||||
|
||||
namespace mate {
|
||||
class Arguments;
|
||||
class Dictionary;
|
||||
@@ -46,12 +48,12 @@ namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
class AtomJavaScriptDialogManager;
|
||||
class InspectableWebContents;
|
||||
class WebContentsZoomController;
|
||||
class WebViewGuestDelegate;
|
||||
class FrameSubscriber;
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
class OffScreenWebContentsView;
|
||||
class OffScreenRenderWidgetHostView;
|
||||
#endif
|
||||
|
||||
@@ -59,10 +61,13 @@ namespace api {
|
||||
|
||||
// Certain events are only in WebContentsDelegate, provide our own Observer to
|
||||
// dispatch those events.
|
||||
class ExtendedWebContentsObserver {
|
||||
class ExtendedWebContentsObserver : public base::CheckedObserver {
|
||||
public:
|
||||
virtual void OnCloseContents() {}
|
||||
virtual void OnRendererResponsive() {}
|
||||
|
||||
protected:
|
||||
~ExtendedWebContentsObserver() override {}
|
||||
};
|
||||
|
||||
// Wrapper around the content::WebContents.
|
||||
@@ -79,29 +84,51 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
OFF_SCREEN, // Used for offscreen rendering
|
||||
};
|
||||
|
||||
// For node.js callback function type: function(error, buffer)
|
||||
using PrintToPDFCallback =
|
||||
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
|
||||
|
||||
// Create from an existing WebContents.
|
||||
static mate::Handle<WebContents> CreateFrom(
|
||||
v8::Isolate* isolate,
|
||||
content::WebContents* web_contents);
|
||||
static mate::Handle<WebContents> CreateFrom(
|
||||
v8::Isolate* isolate,
|
||||
content::WebContents* web_contents,
|
||||
Type type);
|
||||
|
||||
// Create a new WebContents.
|
||||
// Create a new WebContents and return the V8 wrapper of it.
|
||||
static mate::Handle<WebContents> Create(v8::Isolate* isolate,
|
||||
const mate::Dictionary& options);
|
||||
|
||||
// Create a new V8 wrapper for an existing |web_content|.
|
||||
//
|
||||
// The lifetime of |web_contents| will be managed by this class.
|
||||
static mate::Handle<WebContents> CreateAndTake(
|
||||
v8::Isolate* isolate,
|
||||
std::unique_ptr<content::WebContents> web_contents,
|
||||
Type type);
|
||||
|
||||
// Get the V8 wrapper of |web_content|, return empty handle if not wrapped.
|
||||
static mate::Handle<WebContents> From(v8::Isolate* isolate,
|
||||
content::WebContents* web_content);
|
||||
|
||||
// Get the V8 wrapper of the |web_contents|, or create one if not existed.
|
||||
//
|
||||
// The lifetime of |web_contents| is NOT managed by this class, and the type
|
||||
// of this wrapper is always REMOTE.
|
||||
static mate::Handle<WebContents> FromOrCreate(
|
||||
v8::Isolate* isolate,
|
||||
content::WebContents* web_contents);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
// Notifies to destroy any guest web contents before destroying self.
|
||||
base::WeakPtr<WebContents> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
|
||||
|
||||
// Destroy the managed content::WebContents instance.
|
||||
//
|
||||
// Note: The |async| should only be |true| when users are expecting to use the
|
||||
// webContents immediately after the call. Always pass |false| if you are not
|
||||
// sure.
|
||||
// See https://github.com/electron/electron/issues/8930.
|
||||
//
|
||||
// Note: When destroying a webContents member inside a destructor, the |async|
|
||||
// should always be |false|, otherwise the destroy task might be delayed after
|
||||
// normal shutdown procedure, resulting in an assertion.
|
||||
// The normal pattern for calling this method in destructor is:
|
||||
// api_web_contents_->DestroyWebContents(!Browser::Get()->is_shutting_down())
|
||||
// See https://github.com/electron/electron/issues/15133.
|
||||
void DestroyWebContents(bool async);
|
||||
|
||||
void SetBackgroundThrottling(bool allowed);
|
||||
int GetProcessID() const;
|
||||
base::ProcessId GetOSProcessID() const;
|
||||
Type GetType() const;
|
||||
@@ -142,15 +169,18 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void SetAudioMuted(bool muted);
|
||||
bool IsAudioMuted();
|
||||
bool IsCurrentlyAudible();
|
||||
void Print(mate::Arguments* args);
|
||||
std::vector<printing::PrinterBasicInfo> GetPrinterList();
|
||||
void SetEmbedder(const WebContents* embedder);
|
||||
void SetDevToolsWebContents(const WebContents* devtools);
|
||||
v8::Local<v8::Value> GetNativeView() const;
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
void Print(mate::Arguments* args);
|
||||
std::vector<printing::PrinterBasicInfo> GetPrinterList();
|
||||
// Print current page as PDF.
|
||||
void PrintToPDF(const base::DictionaryValue& setting,
|
||||
const PrintToPDFCallback& callback);
|
||||
void PrintToPDF(
|
||||
const base::DictionaryValue& settings,
|
||||
const PrintPreviewMessageHandler::PrintToPDFCallback& callback);
|
||||
#endif
|
||||
|
||||
// DevTools workspace api.
|
||||
void AddWorkSpace(mate::Arguments* args, const base::FilePath& path);
|
||||
@@ -190,6 +220,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id = 0);
|
||||
|
||||
bool SendIPCMessageToFrame(bool internal,
|
||||
bool send_to_all,
|
||||
int32_t frame_id,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args);
|
||||
|
||||
// Send WebInputEvent to the page.
|
||||
void SendInputEvent(v8::Isolate* isolate, v8::Local<v8::Value> input_event);
|
||||
|
||||
@@ -202,12 +238,13 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
|
||||
// Captures the page with |rect|, |callback| would be called when capturing is
|
||||
// done.
|
||||
void CapturePage(mate::Arguments* args);
|
||||
v8::Local<v8::Promise> CapturePage(mate::Arguments* args);
|
||||
|
||||
// Methods for creating <webview>.
|
||||
bool IsGuest() const;
|
||||
void AttachToIframe(content::WebContents* embedder_web_contents,
|
||||
int embedder_frame_id);
|
||||
void DetachFromOuterFrame();
|
||||
|
||||
// Methods for offscreen rendering
|
||||
bool IsOffScreen() const;
|
||||
@@ -249,6 +286,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate) const;
|
||||
v8::Local<v8::Value> GetLastWebPreferences(v8::Isolate* isolate) const;
|
||||
|
||||
bool IsRemoteModuleEnabled() const;
|
||||
|
||||
// Returns the owner window.
|
||||
v8::Local<v8::Value> GetOwnerBrowserWindow() const;
|
||||
|
||||
@@ -272,23 +311,30 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
observers_.AddObserver(obs);
|
||||
}
|
||||
void RemoveObserver(ExtendedWebContentsObserver* obs) {
|
||||
observers_.RemoveObserver(obs);
|
||||
// Trying to remove from an empty collection leads to an access violation
|
||||
if (observers_.might_have_observers())
|
||||
observers_.RemoveObserver(obs);
|
||||
}
|
||||
|
||||
bool EmitNavigationEvent(const std::string& event,
|
||||
content::NavigationHandle* navigation_handle);
|
||||
|
||||
protected:
|
||||
// Does not manage lifetime of |web_contents|.
|
||||
WebContents(v8::Isolate* isolate, content::WebContents* web_contents);
|
||||
// Takes over ownership of |web_contents|.
|
||||
WebContents(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents,
|
||||
std::unique_ptr<content::WebContents> web_contents,
|
||||
Type type);
|
||||
// Creates a new content::WebContents.
|
||||
WebContents(v8::Isolate* isolate, const mate::Dictionary& options);
|
||||
~WebContents() override;
|
||||
|
||||
void InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents,
|
||||
mate::Handle<class Session> session,
|
||||
const mate::Dictionary& options);
|
||||
void InitWithSessionAndOptions(
|
||||
v8::Isolate* isolate,
|
||||
std::unique_ptr<content::WebContents> web_contents,
|
||||
mate::Handle<class Session> session,
|
||||
const mate::Dictionary& options);
|
||||
|
||||
// content::WebContentsDelegate:
|
||||
bool DidAddMessageToConsole(content::WebContents* source,
|
||||
@@ -319,7 +365,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void CloseContents(content::WebContents* source) override;
|
||||
void ActivateContents(content::WebContents* contents) override;
|
||||
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
|
||||
void HandleKeyboardEvent(
|
||||
bool HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
content::KeyboardEventProcessingResult PreHandleKeyboardEvent(
|
||||
@@ -347,7 +393,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
bool final_update) override;
|
||||
bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& security_origin,
|
||||
content::MediaStreamType type) override;
|
||||
blink::MediaStreamType type) override;
|
||||
void RequestMediaAccessPermission(
|
||||
content::WebContents* web_contents,
|
||||
const content::MediaStreamRequest& request,
|
||||
@@ -363,8 +409,11 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void OnAudioStateChanged(bool audible) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
||||
void BeforeUnloadFired(bool proceed,
|
||||
const base::TimeTicks& proceed_time) override;
|
||||
void RenderViewCreated(content::RenderViewHost*) override;
|
||||
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||
content::RenderViewHost* new_host) override;
|
||||
void RenderViewDeleted(content::RenderViewHost*) override;
|
||||
void RenderProcessGone(base::TerminationStatus status) override;
|
||||
void DocumentLoadedInFrame(
|
||||
@@ -401,11 +450,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
const MediaPlayerId& id,
|
||||
content::WebContentsObserver::MediaStoppedReason reason) override;
|
||||
void DidChangeThemeColor(SkColor theme_color) override;
|
||||
void DidAcquireFullscreen(content::RenderFrameHost* rfh) override;
|
||||
|
||||
// brightray::InspectableWebContentsDelegate:
|
||||
// InspectableWebContentsDelegate:
|
||||
void DevToolsReloadPage() override;
|
||||
|
||||
// brightray::InspectableWebContentsViewDelegate:
|
||||
// InspectableWebContentsViewDelegate:
|
||||
void DevToolsFocused() override;
|
||||
void DevToolsOpened() override;
|
||||
void DevToolsClosed() override;
|
||||
@@ -424,7 +474,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
uint32_t GetNextRequestId() { return ++request_id_; }
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
OffScreenWebContentsView* GetOffScreenWebContentsView() const;
|
||||
OffScreenWebContentsView* GetOffScreenWebContentsView() const override;
|
||||
OffScreenRenderWidgetHostView* GetOffScreenRenderWidgetHostView() const;
|
||||
#endif
|
||||
|
||||
@@ -470,7 +520,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
|
||||
std::unique_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||
std::unique_ptr<WebViewGuestDelegate> guest_delegate_;
|
||||
|
||||
std::unique_ptr<FrameSubscriber> frame_subscriber_;
|
||||
|
||||
// The host webcontents that may contain this webcontents.
|
||||
@@ -494,6 +543,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
// Observers of this WebContents.
|
||||
base::ObserverList<ExtendedWebContentsObserver> observers_;
|
||||
|
||||
// The ID of the process of the currently committed RenderViewHost.
|
||||
// -1 means no speculative RVH has been committed yet.
|
||||
int currently_committed_process_id_ = -1;
|
||||
|
||||
base::WeakPtrFactory<WebContents> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
|
||||
#include "content/browser/web_contents/web_contents_impl.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
#include "atom/browser/osr/osr_render_widget_host_view.h"
|
||||
#include "atom/browser/osr/osr_web_contents_view.h"
|
||||
#include "content/browser/web_contents/web_contents_impl.h"
|
||||
#endif
|
||||
|
||||
// Including both web_contents_impl.h and node.h would introduce a error, we
|
||||
// have to isolate the usage of WebContentsImpl into a clean file to fix it:
|
||||
@@ -16,17 +19,33 @@ namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
void WebContents::DetachFromOuterFrame() {
|
||||
// See detach_webview_frame.patch on how to detach.
|
||||
auto* impl = static_cast<content::WebContentsImpl*>(web_contents());
|
||||
impl->GetRenderManagerForTesting()->RemoveOuterDelegateFrame();
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
OffScreenWebContentsView* WebContents::GetOffScreenWebContentsView() const {
|
||||
const auto* impl =
|
||||
static_cast<const content::WebContentsImpl*>(web_contents());
|
||||
return static_cast<OffScreenWebContentsView*>(impl->GetView());
|
||||
if (IsOffScreen()) {
|
||||
const auto* impl =
|
||||
static_cast<const content::WebContentsImpl*>(web_contents());
|
||||
return static_cast<OffScreenWebContentsView*>(impl->GetView());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
OffScreenRenderWidgetHostView* WebContents::GetOffScreenRenderWidgetHostView()
|
||||
const {
|
||||
return static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (IsOffScreen()) {
|
||||
return static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -17,7 +17,7 @@ bool WebContents::IsFocused() const {
|
||||
return false;
|
||||
|
||||
if (GetType() != BACKGROUND_PAGE) {
|
||||
auto window = [web_contents()->GetNativeView() window];
|
||||
auto window = [web_contents()->GetNativeView().GetNativeNSView() window];
|
||||
// On Mac the render widget host view does not lose focus when the window
|
||||
// loses focus so check if the top level window is the key window.
|
||||
if (window && ![window isKeyWindow])
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
#include "atom/browser/api/atom_api_web_contents_view.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/ui/inspectable_web_contents_view.h"
|
||||
#include "atom/common/api/constructor.h"
|
||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
@@ -30,12 +31,14 @@ class WebContentsViewRelay
|
||||
|
||||
atom::api::WebContentsView* view_ = nullptr;
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContentsViewRelay);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsViewRelay)
|
||||
|
||||
DEFINE_WEB_CONTENTS_USER_DATA_KEY(WebContentsViewRelay);
|
||||
} // namespace
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -43,7 +46,7 @@ namespace api {
|
||||
|
||||
WebContentsView::WebContentsView(v8::Isolate* isolate,
|
||||
mate::Handle<WebContents> web_contents,
|
||||
brightray::InspectableWebContents* iwc)
|
||||
InspectableWebContents* iwc)
|
||||
#if defined(OS_MACOSX)
|
||||
: View(new DelayedNativeViewHost(iwc->GetView()->GetNativeView())),
|
||||
#else
|
||||
@@ -64,8 +67,11 @@ WebContentsView::WebContentsView(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
WebContentsView::~WebContentsView() {
|
||||
if (api_web_contents_)
|
||||
api_web_contents_->DestroyWebContents(false /* async */);
|
||||
if (api_web_contents_) { // destroy() is called
|
||||
// Destroy WebContents asynchronously unless app is shutting down,
|
||||
// because destroy() might be called inside WebContents's event handler.
|
||||
api_web_contents_->DestroyWebContents(!Browser::Get()->is_shutting_down());
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentsView::WebContentsDestroyed() {
|
||||
@@ -125,4 +131,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_web_contents_view, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_web_contents_view, Initialize)
|
||||
|
||||
@@ -9,12 +9,10 @@
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
namespace brightray {
|
||||
class InspectableWebContents;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class InspectableWebContents;
|
||||
|
||||
namespace api {
|
||||
|
||||
class WebContents;
|
||||
@@ -30,7 +28,7 @@ class WebContentsView : public View, public content::WebContentsObserver {
|
||||
protected:
|
||||
WebContentsView(v8::Isolate* isolate,
|
||||
mate::Handle<WebContents> web_contents,
|
||||
brightray::InspectableWebContents* iwc);
|
||||
InspectableWebContents* iwc);
|
||||
~WebContentsView() override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
@@ -29,7 +31,7 @@ struct Converter<URLPattern> {
|
||||
if (!ConvertFromV8(isolate, val, &pattern))
|
||||
return false;
|
||||
*out = URLPattern(URLPattern::SCHEME_ALL);
|
||||
return out->Parse(pattern) == URLPattern::PARSE_SUCCESS;
|
||||
return out->Parse(pattern) == URLPattern::ParseResult::kSuccess;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -97,8 +99,8 @@ void WebRequest::SetListener(Method method, Event type, mate::Arguments* args) {
|
||||
browser_context_->GetRequestContext());
|
||||
if (!url_request_context_getter)
|
||||
return;
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&CallNetworkDelegateMethod<Method, Event, Listener>,
|
||||
base::RetainedRef(url_request_context_getter), method,
|
||||
type, std::move(patterns), std::move(listener)));
|
||||
|
||||
@@ -55,4 +55,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_web_view_manager, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_web_view_manager, Initialize)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
|
||||
#include "atom/browser/api/event.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "native_mate/arguments.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
@@ -34,7 +35,8 @@ v8::Local<v8::Object> CreateEventObject(v8::Isolate* isolate) {
|
||||
}
|
||||
|
||||
return v8::Local<v8::ObjectTemplate>::New(isolate, event_template)
|
||||
->NewInstance();
|
||||
->NewInstance(isolate->GetCurrentContext())
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -55,7 +57,10 @@ v8::Local<v8::Object> CreateJSEvent(v8::Isolate* isolate,
|
||||
} else {
|
||||
event = CreateEventObject(isolate);
|
||||
}
|
||||
mate::Dictionary(isolate, event).Set("sender", object);
|
||||
mate::Dictionary dict(isolate, event);
|
||||
dict.Set("sender", object);
|
||||
if (sender)
|
||||
dict.Set("frameId", sender->GetRoutingID());
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/api/event_emitter_caller.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/wrappable.h"
|
||||
|
||||
namespace content {
|
||||
@@ -97,11 +98,13 @@ class EventEmitter : public Wrappable<T> {
|
||||
bool EmitWithEvent(const base::StringPiece& name,
|
||||
v8::Local<v8::Object> event,
|
||||
const Args&... args) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
EmitEvent(isolate(), GetWrapper(), name, event, args...);
|
||||
return event->Get(StringToV8(isolate(), "defaultPrevented"))
|
||||
->BooleanValue();
|
||||
->BooleanValue(isolate()->GetCurrentContext())
|
||||
.ToChecked();
|
||||
}
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(EventEmitter);
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
|
||||
#include "atom/browser/api/frame_subscriber.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "components/viz/common/frame_sinks/copy_output_request.h"
|
||||
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
|
||||
#include "components/viz/service/surfaces/surface_manager.h"
|
||||
#include "content/browser/compositor/surface_utils.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_view_base.h"
|
||||
#include "ui/gfx/geometry/rect_conversions.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
#include "ui/gfx/skbitmap_operations.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
@@ -19,6 +18,8 @@ namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
constexpr static int kMaxFrameRate = 30;
|
||||
|
||||
FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents,
|
||||
const FrameCaptureCallback& callback,
|
||||
@@ -27,48 +28,123 @@ FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
||||
isolate_(isolate),
|
||||
callback_(callback),
|
||||
only_dirty_(only_dirty),
|
||||
weak_ptr_factory_(this) {}
|
||||
weak_ptr_factory_(this) {
|
||||
content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
|
||||
if (rvh)
|
||||
AttachToHost(rvh->GetWidget());
|
||||
}
|
||||
|
||||
FrameSubscriber::~FrameSubscriber() = default;
|
||||
|
||||
gfx::Rect FrameSubscriber::GetDamageRect() {
|
||||
auto* view = web_contents()->GetRenderWidgetHostView();
|
||||
if (view == nullptr)
|
||||
return gfx::Rect();
|
||||
void FrameSubscriber::AttachToHost(content::RenderWidgetHost* host) {
|
||||
host_ = host;
|
||||
|
||||
auto* view_base = static_cast<content::RenderWidgetHostViewBase*>(view);
|
||||
viz::SurfaceManager* surface_manager =
|
||||
content::GetFrameSinkManager()->surface_manager();
|
||||
viz::Surface* surface =
|
||||
surface_manager->GetSurfaceForId(view_base->GetCurrentSurfaceId());
|
||||
if (surface == nullptr)
|
||||
return gfx::Rect();
|
||||
// The view can be null if the renderer process has crashed.
|
||||
// (https://crbug.com/847363)
|
||||
if (!host_->GetView())
|
||||
return;
|
||||
|
||||
if (surface->HasActiveFrame()) {
|
||||
const viz::CompositorFrame& frame = surface->GetActiveFrame();
|
||||
viz::RenderPass* root_pass = frame.render_pass_list.back().get();
|
||||
gfx::Size frame_size = root_pass->output_rect.size();
|
||||
gfx::Rect damage_rect =
|
||||
gfx::ToEnclosingRect(gfx::RectF(root_pass->damage_rect));
|
||||
damage_rect.Intersect(gfx::Rect(frame_size));
|
||||
return gfx::ScaleToEnclosedRect(damage_rect,
|
||||
1.0f / frame.device_scale_factor());
|
||||
} else {
|
||||
return gfx::Rect();
|
||||
// Create and configure the video capturer.
|
||||
video_capturer_ = host_->GetView()->CreateVideoCapturer();
|
||||
video_capturer_->SetResolutionConstraints(
|
||||
host_->GetView()->GetViewBounds().size(),
|
||||
host_->GetView()->GetViewBounds().size(), true);
|
||||
video_capturer_->SetAutoThrottlingEnabled(false);
|
||||
video_capturer_->SetMinSizeChangePeriod(base::TimeDelta());
|
||||
video_capturer_->SetFormat(media::PIXEL_FORMAT_ARGB,
|
||||
gfx::ColorSpace::CreateREC709());
|
||||
video_capturer_->SetMinCapturePeriod(base::TimeDelta::FromSeconds(1) /
|
||||
kMaxFrameRate);
|
||||
video_capturer_->Start(this);
|
||||
}
|
||||
|
||||
void FrameSubscriber::DetachFromHost() {
|
||||
if (!host_)
|
||||
return;
|
||||
video_capturer_.reset();
|
||||
host_ = nullptr;
|
||||
}
|
||||
|
||||
void FrameSubscriber::RenderViewCreated(content::RenderViewHost* host) {
|
||||
if (!host_)
|
||||
AttachToHost(host->GetWidget());
|
||||
}
|
||||
|
||||
void FrameSubscriber::RenderViewDeleted(content::RenderViewHost* host) {
|
||||
if (host->GetWidget() == host_) {
|
||||
DetachFromHost();
|
||||
}
|
||||
}
|
||||
|
||||
void FrameSubscriber::DidReceiveCompositorFrame() {
|
||||
auto* view = web_contents()->GetRenderWidgetHostView();
|
||||
if (view == nullptr)
|
||||
return;
|
||||
|
||||
view->CopyFromSurface(
|
||||
gfx::Rect(), view->GetViewBounds().size(),
|
||||
base::BindOnce(&FrameSubscriber::Done, weak_ptr_factory_.GetWeakPtr(),
|
||||
GetDamageRect()));
|
||||
void FrameSubscriber::RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||
content::RenderViewHost* new_host) {
|
||||
if ((old_host && old_host->GetWidget() == host_) || (!old_host && !host_)) {
|
||||
DetachFromHost();
|
||||
AttachToHost(new_host->GetWidget());
|
||||
}
|
||||
}
|
||||
|
||||
void FrameSubscriber::OnFrameCaptured(
|
||||
base::ReadOnlySharedMemoryRegion data,
|
||||
::media::mojom::VideoFrameInfoPtr info,
|
||||
const gfx::Rect& update_rect,
|
||||
const gfx::Rect& content_rect,
|
||||
viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr callbacks) {
|
||||
gfx::Size view_size = host_->GetView()->GetViewBounds().size();
|
||||
if (view_size != content_rect.size()) {
|
||||
video_capturer_->SetResolutionConstraints(view_size, view_size, true);
|
||||
video_capturer_->RequestRefreshFrame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.IsValid()) {
|
||||
callbacks->Done();
|
||||
return;
|
||||
}
|
||||
base::ReadOnlySharedMemoryMapping mapping = data.Map();
|
||||
if (!mapping.IsValid()) {
|
||||
DLOG(ERROR) << "Shared memory mapping failed.";
|
||||
return;
|
||||
}
|
||||
if (mapping.size() <
|
||||
media::VideoFrame::AllocationSize(info->pixel_format, info->coded_size)) {
|
||||
DLOG(ERROR) << "Shared memory size was less than expected.";
|
||||
return;
|
||||
}
|
||||
|
||||
// The SkBitmap's pixels will be marked as immutable, but the installPixels()
|
||||
// API requires a non-const pointer. So, cast away the const.
|
||||
void* const pixels = const_cast<void*>(mapping.memory());
|
||||
|
||||
// Call installPixels() with a |releaseProc| that: 1) notifies the capturer
|
||||
// that this consumer has finished with the frame, and 2) releases the shared
|
||||
// memory mapping.
|
||||
struct FramePinner {
|
||||
// Keeps the shared memory that backs |frame_| mapped.
|
||||
base::ReadOnlySharedMemoryMapping mapping;
|
||||
// Prevents FrameSinkVideoCapturer from recycling the shared memory that
|
||||
// backs |frame_|.
|
||||
viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr releaser;
|
||||
};
|
||||
|
||||
SkBitmap bitmap;
|
||||
bitmap.installPixels(
|
||||
SkImageInfo::MakeN32(content_rect.width(), content_rect.height(),
|
||||
kPremul_SkAlphaType),
|
||||
pixels,
|
||||
media::VideoFrame::RowBytes(media::VideoFrame::kARGBPlane,
|
||||
info->pixel_format, info->coded_size.width()),
|
||||
[](void* addr, void* context) {
|
||||
delete static_cast<FramePinner*>(context);
|
||||
},
|
||||
new FramePinner{std::move(mapping), std::move(callbacks)});
|
||||
bitmap.setImmutable();
|
||||
|
||||
Done(content_rect, bitmap);
|
||||
}
|
||||
|
||||
void FrameSubscriber::OnStopped() {}
|
||||
|
||||
void FrameSubscriber::Done(const gfx::Rect& damage, const SkBitmap& frame) {
|
||||
if (frame.drawsNothing())
|
||||
return;
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#ifndef ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
|
||||
#define ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
|
||||
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include <memory>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "components/viz/common/frame_sinks/copy_output_result.h"
|
||||
#include "components/viz/host/client_frame_sink_video_capturer.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace atom {
|
||||
@@ -20,7 +20,8 @@ namespace api {
|
||||
|
||||
class WebContents;
|
||||
|
||||
class FrameSubscriber : public content::WebContentsObserver {
|
||||
class FrameSubscriber : public content::WebContentsObserver,
|
||||
public viz::mojom::FrameSinkVideoConsumer {
|
||||
public:
|
||||
using FrameCaptureCallback =
|
||||
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
|
||||
@@ -32,14 +33,32 @@ class FrameSubscriber : public content::WebContentsObserver {
|
||||
~FrameSubscriber() override;
|
||||
|
||||
private:
|
||||
gfx::Rect GetDamageRect();
|
||||
void DidReceiveCompositorFrame() override;
|
||||
void AttachToHost(content::RenderWidgetHost* host);
|
||||
void DetachFromHost();
|
||||
|
||||
void RenderViewCreated(content::RenderViewHost* host) override;
|
||||
void RenderViewDeleted(content::RenderViewHost* host) override;
|
||||
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||
content::RenderViewHost* new_host) override;
|
||||
|
||||
// viz::mojom::FrameSinkVideoConsumer implementation.
|
||||
void OnFrameCaptured(
|
||||
base::ReadOnlySharedMemoryRegion data,
|
||||
::media::mojom::VideoFrameInfoPtr info,
|
||||
const gfx::Rect& update_rect,
|
||||
const gfx::Rect& content_rect,
|
||||
viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr callbacks) override;
|
||||
void OnStopped() override;
|
||||
|
||||
void Done(const gfx::Rect& damage, const SkBitmap& frame);
|
||||
|
||||
v8::Isolate* isolate_;
|
||||
FrameCaptureCallback callback_;
|
||||
bool only_dirty_;
|
||||
|
||||
content::RenderWidgetHost* host_;
|
||||
std::unique_ptr<viz::ClientFrameSinkVideoCapturer> video_capturer_;
|
||||
|
||||
base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
|
||||
|
||||
@@ -107,6 +107,18 @@ void GPUInfoEnumerator::EndOverlayCapability() {
|
||||
value_stack.pop();
|
||||
}
|
||||
|
||||
void GPUInfoEnumerator::BeginDx12VulkanVersionInfo() {
|
||||
value_stack.push(std::move(current));
|
||||
current = std::make_unique<base::DictionaryValue>();
|
||||
}
|
||||
|
||||
void GPUInfoEnumerator::EndDx12VulkanVersionInfo() {
|
||||
auto& top_value = value_stack.top();
|
||||
top_value->SetDictionary(kDx12VulkanVersionInfoKey, std::move(current));
|
||||
current = std::move(top_value);
|
||||
value_stack.pop();
|
||||
}
|
||||
|
||||
std::unique_ptr<base::DictionaryValue> GPUInfoEnumerator::GetDictionary() {
|
||||
return std::move(current);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ class GPUInfoEnumerator final : public gpu::GPUInfo::Enumerator {
|
||||
"videoEncodeAcceleratorSupportedProfile";
|
||||
const char* kAuxAttributesKey = "auxAttributes";
|
||||
const char* kOverlayCapabilityKey = "overlayCapability";
|
||||
const char* kDx12VulkanVersionInfoKey = "dx12VulkanVersionInfo";
|
||||
|
||||
public:
|
||||
GPUInfoEnumerator();
|
||||
@@ -44,6 +45,8 @@ class GPUInfoEnumerator final : public gpu::GPUInfo::Enumerator {
|
||||
void EndAuxAttributes() override;
|
||||
void BeginOverlayCapability() override;
|
||||
void EndOverlayCapability() override;
|
||||
void BeginDx12VulkanVersionInfo() override;
|
||||
void EndDx12VulkanVersionInfo() override;
|
||||
std::unique_ptr<base::DictionaryValue> GetDictionary();
|
||||
|
||||
private:
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/gpuinfo_manager.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/api/gpu_info_enumerator.h"
|
||||
#include "base/memory/singleton.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
@@ -26,11 +29,12 @@ GPUInfoManager::~GPUInfoManager() {
|
||||
|
||||
// Based on
|
||||
// https://chromium.googlesource.com/chromium/src.git/+/69.0.3497.106/content/browser/gpu/gpu_data_manager_impl_private.cc#838
|
||||
bool GPUInfoManager::NeedsCompleteGpuInfoCollection() {
|
||||
#if defined(OS_WIN)
|
||||
const auto& gpu_info = gpu_data_manager_->GetGPUInfo();
|
||||
return (gpu_info.dx_diagnostics.values.empty() &&
|
||||
gpu_info.dx_diagnostics.children.empty());
|
||||
bool GPUInfoManager::NeedsCompleteGpuInfoCollection() const {
|
||||
#if defined(OS_MACOSX)
|
||||
return gpu_data_manager_->GetGPUInfo().gl_vendor.empty();
|
||||
#elif defined(OS_WIN)
|
||||
return (gpu_data_manager_->GetGPUInfo().dx_diagnostics.values.empty() &&
|
||||
gpu_data_manager_->GetGPUInfo().dx_diagnostics.children.empty());
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
@@ -41,8 +45,8 @@ void GPUInfoManager::ProcessCompleteInfo() {
|
||||
const auto result = EnumerateGPUInfo(gpu_data_manager_->GetGPUInfo());
|
||||
// We have received the complete information, resolve all promises that
|
||||
// were waiting for this info.
|
||||
for (const auto& promise : complete_info_promise_set_) {
|
||||
promise->Resolve(*result);
|
||||
for (auto& promise : complete_info_promise_set_) {
|
||||
promise.Resolve(*result);
|
||||
}
|
||||
complete_info_promise_set_.clear();
|
||||
}
|
||||
@@ -57,8 +61,8 @@ void GPUInfoManager::OnGpuInfoUpdate() {
|
||||
}
|
||||
|
||||
// Should be posted to the task runner
|
||||
void GPUInfoManager::CompleteInfoFetcher(scoped_refptr<util::Promise> promise) {
|
||||
complete_info_promise_set_.push_back(promise);
|
||||
void GPUInfoManager::CompleteInfoFetcher(util::Promise promise) {
|
||||
complete_info_promise_set_.emplace_back(std::move(promise));
|
||||
|
||||
if (NeedsCompleteGpuInfoCollection()) {
|
||||
gpu_data_manager_->RequestCompleteGpuInfoIfNeeded();
|
||||
@@ -67,18 +71,18 @@ void GPUInfoManager::CompleteInfoFetcher(scoped_refptr<util::Promise> promise) {
|
||||
}
|
||||
}
|
||||
|
||||
void GPUInfoManager::FetchCompleteInfo(scoped_refptr<util::Promise> promise) {
|
||||
void GPUInfoManager::FetchCompleteInfo(util::Promise promise) {
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&GPUInfoManager::CompleteInfoFetcher,
|
||||
base::Unretained(this), promise));
|
||||
base::Unretained(this), std::move(promise)));
|
||||
}
|
||||
|
||||
// This fetches the info synchronously, so no need to post to the task queue.
|
||||
// There cannot be multiple promises as they are resolved synchronously.
|
||||
void GPUInfoManager::FetchBasicInfo(scoped_refptr<util::Promise> promise) {
|
||||
void GPUInfoManager::FetchBasicInfo(util::Promise promise) {
|
||||
gpu::GPUInfo gpu_info;
|
||||
CollectBasicGraphicsInfo(&gpu_info);
|
||||
promise->Resolve(*EnumerateGPUInfo(gpu_info));
|
||||
promise.Resolve(*EnumerateGPUInfo(gpu_info));
|
||||
}
|
||||
|
||||
std::unique_ptr<base::DictionaryValue> GPUInfoManager::EnumerateGPUInfo(
|
||||
|
||||
@@ -24,9 +24,9 @@ class GPUInfoManager : public content::GpuDataManagerObserver {
|
||||
|
||||
GPUInfoManager();
|
||||
~GPUInfoManager() override;
|
||||
bool NeedsCompleteGpuInfoCollection();
|
||||
void FetchCompleteInfo(scoped_refptr<util::Promise> promise);
|
||||
void FetchBasicInfo(scoped_refptr<util::Promise> promise);
|
||||
bool NeedsCompleteGpuInfoCollection() const;
|
||||
void FetchCompleteInfo(util::Promise promise);
|
||||
void FetchBasicInfo(util::Promise promise);
|
||||
void OnGpuInfoUpdate() override;
|
||||
|
||||
private:
|
||||
@@ -34,12 +34,12 @@ class GPUInfoManager : public content::GpuDataManagerObserver {
|
||||
gpu::GPUInfo gpu_info) const;
|
||||
|
||||
// These should be posted to the task queue
|
||||
void CompleteInfoFetcher(scoped_refptr<util::Promise> promise);
|
||||
void CompleteInfoFetcher(util::Promise promise);
|
||||
void ProcessCompleteInfo();
|
||||
|
||||
// This set maintains all the promises that should be fulfilled
|
||||
// once we have the complete information data
|
||||
std::vector<scoped_refptr<util::Promise>> complete_info_promise_set_;
|
||||
std::vector<util::Promise> complete_info_promise_set_;
|
||||
content::GpuDataManager* gpu_data_manager_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GPUInfoManager);
|
||||
|
||||
@@ -57,7 +57,9 @@ void SavePageHandler::OnDownloadUpdated(download::DownloadItem* item) {
|
||||
callback_.Run(v8::Null(isolate));
|
||||
} else {
|
||||
v8::Local<v8::String> error_message =
|
||||
v8::String::NewFromUtf8(isolate, "Fail to save page");
|
||||
v8::String::NewFromUtf8(isolate, "Fail to save page",
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked();
|
||||
callback_.Run(v8::Exception::Error(error_message));
|
||||
}
|
||||
Destroy(item);
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "atom/browser/net/url_request_stream_job.h"
|
||||
#include "atom/common/api/event_emitter_caller.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
@@ -17,12 +19,15 @@ namespace mate {
|
||||
StreamSubscriber::StreamSubscriber(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> emitter,
|
||||
base::WeakPtr<atom::URLRequestStreamJob> url_job)
|
||||
: isolate_(isolate),
|
||||
base::WeakPtr<atom::URLRequestStreamJob> url_job,
|
||||
scoped_refptr<base::SequencedTaskRunner> ui_task_runner)
|
||||
: base::RefCountedDeleteOnSequence<StreamSubscriber>(ui_task_runner),
|
||||
isolate_(isolate),
|
||||
emitter_(isolate, emitter),
|
||||
url_job_(url_job),
|
||||
weak_factory_(this) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
DCHECK(ui_task_runner->RunsTasksInCurrentSequence());
|
||||
|
||||
auto weak_self = weak_factory_.GetWeakPtr();
|
||||
On("data", base::Bind(&StreamSubscriber::OnData, weak_self));
|
||||
On("end", base::Bind(&StreamSubscriber::OnEnd, weak_self));
|
||||
@@ -30,13 +35,12 @@ StreamSubscriber::StreamSubscriber(
|
||||
}
|
||||
|
||||
StreamSubscriber::~StreamSubscriber() {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
RemoveAllListeners();
|
||||
}
|
||||
|
||||
void StreamSubscriber::On(const std::string& event,
|
||||
EventCallback&& callback) { // NOLINT
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
DCHECK(owning_task_runner()->RunsTasksInCurrentSequence());
|
||||
DCHECK(js_handlers_.find(event) == js_handlers_.end());
|
||||
|
||||
v8::Locker locker(isolate_);
|
||||
@@ -50,7 +54,7 @@ void StreamSubscriber::On(const std::string& event,
|
||||
}
|
||||
|
||||
void StreamSubscriber::Off(const std::string& event) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
DCHECK(owning_task_runner()->RunsTasksInCurrentSequence());
|
||||
DCHECK(js_handlers_.find(event) != js_handlers_.end());
|
||||
|
||||
v8::Locker locker(isolate_);
|
||||
@@ -76,26 +80,25 @@ void StreamSubscriber::OnData(mate::Arguments* args) {
|
||||
|
||||
// Pass the data to the URLJob in IO thread.
|
||||
std::vector<char> buffer(data, data + length);
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&atom::URLRequestStreamJob::OnData, url_job_,
|
||||
base::Passed(&buffer)));
|
||||
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::IO},
|
||||
base::Bind(&atom::URLRequestStreamJob::OnData,
|
||||
url_job_, base::Passed(&buffer)));
|
||||
}
|
||||
|
||||
void StreamSubscriber::OnEnd(mate::Arguments* args) {
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {content::BrowserThread::IO},
|
||||
base::Bind(&atom::URLRequestStreamJob::OnEnd, url_job_));
|
||||
}
|
||||
|
||||
void StreamSubscriber::OnError(mate::Arguments* args) {
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&atom::URLRequestStreamJob::OnError, url_job_,
|
||||
net::ERR_FAILED));
|
||||
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::IO},
|
||||
base::Bind(&atom::URLRequestStreamJob::OnError,
|
||||
url_job_, net::ERR_FAILED));
|
||||
}
|
||||
|
||||
void StreamSubscriber::RemoveAllListeners() {
|
||||
DCHECK(owning_task_runner()->RunsTasksInCurrentSequence());
|
||||
v8::Locker locker(isolate_);
|
||||
v8::Isolate::Scope isolate_scope(isolate_);
|
||||
v8::HandleScope handle_scope(isolate_);
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/ref_counted_delete_on_sequence.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "v8/include/v8.h"
|
||||
@@ -23,17 +25,25 @@ namespace mate {
|
||||
|
||||
class Arguments;
|
||||
|
||||
class StreamSubscriber {
|
||||
class StreamSubscriber
|
||||
: public base::RefCountedDeleteOnSequence<StreamSubscriber> {
|
||||
public:
|
||||
REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE();
|
||||
|
||||
StreamSubscriber(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> emitter,
|
||||
base::WeakPtr<atom::URLRequestStreamJob> url_job);
|
||||
~StreamSubscriber();
|
||||
base::WeakPtr<atom::URLRequestStreamJob> url_job,
|
||||
scoped_refptr<base::SequencedTaskRunner> ui_task_runner);
|
||||
|
||||
private:
|
||||
friend class base::DeleteHelper<StreamSubscriber>;
|
||||
friend class base::RefCountedDeleteOnSequence<StreamSubscriber>;
|
||||
|
||||
using JSHandlersMap = std::map<std::string, v8::Global<v8::Value>>;
|
||||
using EventCallback = base::Callback<void(mate::Arguments* args)>;
|
||||
|
||||
~StreamSubscriber();
|
||||
|
||||
void On(const std::string& event, EventCallback&& callback); // NOLINT
|
||||
void Off(const std::string& event);
|
||||
|
||||
|
||||
@@ -84,4 +84,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_box_layout, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_box_layout, Initialize)
|
||||
|
||||
@@ -13,8 +13,10 @@ namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
Button::Button(views::Button* button) : View(button) {
|
||||
Button::Button(views::Button* impl) : View(impl) {
|
||||
view()->set_owned_by_client();
|
||||
// Make the button focusable as per the platform.
|
||||
button()->SetFocusForPlatform();
|
||||
}
|
||||
|
||||
Button::~Button() {}
|
||||
@@ -55,4 +57,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_button, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_button, Initialize)
|
||||
|
||||
@@ -27,6 +27,8 @@ class Button : public View, public views::ButtonListener {
|
||||
// views::ButtonListener:
|
||||
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
|
||||
|
||||
views::Button* button() const { return static_cast<views::Button*>(view()); }
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Button);
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "atom/common/api/constructor.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/views/controls/button/label_button.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
@@ -15,11 +14,29 @@ namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
LabelButton::LabelButton(views::LabelButton* impl) : Button(impl) {}
|
||||
|
||||
LabelButton::LabelButton(const std::string& text)
|
||||
: Button(new views::LabelButton(this, base::UTF8ToUTF16(text))) {}
|
||||
|
||||
LabelButton::~LabelButton() {}
|
||||
|
||||
const base::string16& LabelButton::GetText() const {
|
||||
return label_button()->GetText();
|
||||
}
|
||||
|
||||
void LabelButton::SetText(const base::string16& text) {
|
||||
label_button()->SetText(text);
|
||||
}
|
||||
|
||||
bool LabelButton::IsDefault() const {
|
||||
return label_button()->is_default();
|
||||
}
|
||||
|
||||
void LabelButton::SetIsDefault(bool is_default) {
|
||||
label_button()->SetIsDefault(is_default);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::WrappableBase* LabelButton::New(mate::Arguments* args,
|
||||
const std::string& text) {
|
||||
@@ -33,6 +50,11 @@ mate::WrappableBase* LabelButton::New(mate::Arguments* args,
|
||||
void LabelButton::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "LabelButton"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("getText", &LabelButton::GetText)
|
||||
.SetMethod("setText", &LabelButton::SetText)
|
||||
.SetMethod("isDefault", &LabelButton::IsDefault)
|
||||
.SetMethod("setIsDefault", &LabelButton::SetIsDefault);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
@@ -55,4 +77,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_label_button, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_label_button, Initialize)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/api/views/atom_api_button.h"
|
||||
#include "ui/views/controls/button/label_button.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -21,10 +22,20 @@ class LabelButton : public Button {
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
const base::string16& GetText() const;
|
||||
void SetText(const base::string16& text);
|
||||
bool IsDefault() const;
|
||||
void SetIsDefault(bool is_default);
|
||||
|
||||
protected:
|
||||
explicit LabelButton(views::LabelButton* impl);
|
||||
explicit LabelButton(const std::string& text);
|
||||
~LabelButton() override;
|
||||
|
||||
views::LabelButton* label_button() const {
|
||||
return static_cast<views::LabelButton*>(view());
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(LabelButton);
|
||||
};
|
||||
|
||||
@@ -60,4 +60,4 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_layout_manager, Initialize)
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_layout_manager, Initialize)
|
||||
|
||||
57
atom/browser/api/views/atom_api_md_text_button.cc
Normal file
57
atom/browser/api/views/atom_api_md_text_button.cc
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/views/atom_api_md_text_button.h"
|
||||
|
||||
#include "atom/common/api/constructor.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
MdTextButton::MdTextButton(const std::string& text)
|
||||
: LabelButton(views::MdTextButton::Create(this, base::UTF8ToUTF16(text))) {}
|
||||
|
||||
MdTextButton::~MdTextButton() {}
|
||||
|
||||
// static
|
||||
mate::WrappableBase* MdTextButton::New(mate::Arguments* args,
|
||||
const std::string& text) {
|
||||
// Constructor call.
|
||||
auto* view = new MdTextButton(text);
|
||||
view->InitWith(args->isolate(), args->GetThis());
|
||||
return view;
|
||||
}
|
||||
|
||||
// static
|
||||
void MdTextButton::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "MdTextButton"));
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
||||
namespace {
|
||||
|
||||
using atom::api::MdTextButton;
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("MdTextButton", mate::CreateConstructor<MdTextButton>(
|
||||
isolate, base::Bind(&MdTextButton::New)));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_md_text_button, Initialize)
|
||||
41
atom/browser/api/views/atom_api_md_text_button.h
Normal file
41
atom/browser/api/views/atom_api_md_text_button.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_API_VIEWS_ATOM_API_MD_TEXT_BUTTON_H_
|
||||
#define ATOM_BROWSER_API_VIEWS_ATOM_API_MD_TEXT_BUTTON_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/api/views/atom_api_label_button.h"
|
||||
#include "ui/views/controls/button/md_text_button.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
class MdTextButton : public LabelButton {
|
||||
public:
|
||||
static mate::WrappableBase* New(mate::Arguments* args,
|
||||
const std::string& text);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
protected:
|
||||
explicit MdTextButton(const std::string& text);
|
||||
~MdTextButton() override;
|
||||
|
||||
views::MdTextButton* md_text_button() const {
|
||||
return static_cast<views::MdTextButton*>(view());
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(MdTextButton);
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_API_VIEWS_ATOM_API_MD_TEXT_BUTTON_H_
|
||||
60
atom/browser/api/views/atom_api_resize_area.cc
Normal file
60
atom/browser/api/views/atom_api_resize_area.cc
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/views/atom_api_resize_area.h"
|
||||
|
||||
#include "atom/common/api/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
ResizeArea::ResizeArea() : View(new views::ResizeArea(this)) {
|
||||
view()->set_owned_by_client();
|
||||
}
|
||||
|
||||
ResizeArea::~ResizeArea() {}
|
||||
|
||||
void ResizeArea::OnResize(int resize_amount, bool done_resizing) {
|
||||
Emit("resize", resize_amount, done_resizing);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::WrappableBase* ResizeArea::New(mate::Arguments* args) {
|
||||
// Constructor call.
|
||||
auto* view = new ResizeArea();
|
||||
view->InitWith(args->isolate(), args->GetThis());
|
||||
return view;
|
||||
}
|
||||
|
||||
// static
|
||||
void ResizeArea::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "ResizeArea"));
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
||||
namespace {
|
||||
|
||||
using atom::api::ResizeArea;
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("ResizeArea", mate::CreateConstructor<ResizeArea>(
|
||||
isolate, base::Bind(&ResizeArea::New)));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_resize_area, Initialize)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user