mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
Compare commits
546 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b8a6aea74 | ||
|
|
16e224bb86 | ||
|
|
459d389e03 | ||
|
|
8e4581a3c0 | ||
|
|
c97c3fb9a1 | ||
|
|
7ce8156691 | ||
|
|
0e6a70c556 | ||
|
|
b68d559329 | ||
|
|
18fcd6990b | ||
|
|
5fe130a684 | ||
|
|
d367af3fa4 | ||
|
|
549ec51bce | ||
|
|
b4674923c9 | ||
|
|
71598e15bf | ||
|
|
cd3c061448 | ||
|
|
163790d107 | ||
|
|
2fdc5780ff | ||
|
|
b76642bd10 | ||
|
|
209e24bf0f | ||
|
|
731773765e | ||
|
|
333fe87490 | ||
|
|
36f0ef703a | ||
|
|
605722c397 | ||
|
|
132c13a11b | ||
|
|
04d24f61fe | ||
|
|
8eb5e651a2 | ||
|
|
5cd0fc4d52 | ||
|
|
d12697c657 | ||
|
|
0819176cb1 | ||
|
|
7d1f6dae6f | ||
|
|
5c2bb42d49 | ||
|
|
db9615f5cd | ||
|
|
09c5da7147 | ||
|
|
4b12a95d37 | ||
|
|
200a19dad9 | ||
|
|
2ee6e43fb3 | ||
|
|
0fef09281b | ||
|
|
f91a81fe77 | ||
|
|
78eff673ec | ||
|
|
51dc8ad70a | ||
|
|
d8cd9b71b0 | ||
|
|
c78a3ff714 | ||
|
|
4642630674 | ||
|
|
a6a5d50c3f | ||
|
|
b4790a7531 | ||
|
|
9199d0df0a | ||
|
|
a84e6227ef | ||
|
|
35dcdfc492 | ||
|
|
2f4333b852 | ||
|
|
bd1fd9680f | ||
|
|
cf79f439ce | ||
|
|
e829a28947 | ||
|
|
6d756d9d13 | ||
|
|
29abfa68e9 | ||
|
|
ab98dcd7cf | ||
|
|
6494ed6b13 | ||
|
|
8893c9502a | ||
|
|
13b6ed6dc5 | ||
|
|
8aa815e6d1 | ||
|
|
719f68a44b | ||
|
|
4c48f0cd36 | ||
|
|
8ef3351846 | ||
|
|
9f0ac13edc | ||
|
|
5459137d3d | ||
|
|
52b2c0d27f | ||
|
|
89087d402d | ||
|
|
64e84b8f6a | ||
|
|
24586c1330 | ||
|
|
f8c6056eec | ||
|
|
03ab9b2686 | ||
|
|
f1a8c5a1ca | ||
|
|
488801e244 | ||
|
|
bf1765f941 | ||
|
|
994be9cdab | ||
|
|
d4e4c6ca15 | ||
|
|
47cb06e201 | ||
|
|
cac97cca0d | ||
|
|
16c08e7e37 | ||
|
|
2de5f9de6c | ||
|
|
06a3875726 | ||
|
|
1ae8bed96a | ||
|
|
2ec74b5958 | ||
|
|
72ebb2c9fe | ||
|
|
52166d2999 | ||
|
|
676cfa03a1 | ||
|
|
64a89fe755 | ||
|
|
2bd03f6eda | ||
|
|
eeaee1a0b7 | ||
|
|
fed9ef0687 | ||
|
|
75448ad7ed | ||
|
|
25db6e0bd8 | ||
|
|
cefe540ec0 | ||
|
|
8363a39a56 | ||
|
|
57ef6adbbd | ||
|
|
5ae9c633ca | ||
|
|
b6a5e927e0 | ||
|
|
625c17fa24 | ||
|
|
f776932718 | ||
|
|
55c07cec68 | ||
|
|
161dc45ec8 | ||
|
|
29827fa66b | ||
|
|
40b6a1a37c | ||
|
|
e4ae579b16 | ||
|
|
582a42f97c | ||
|
|
9a0a10e766 | ||
|
|
cd1c331112 | ||
|
|
8a2b665097 | ||
|
|
690513db7f | ||
|
|
13c1b078f9 | ||
|
|
4da7578dab | ||
|
|
c821a06e2f | ||
|
|
cd7b3dd291 | ||
|
|
bb42c2c7b6 | ||
|
|
af62b7b5c9 | ||
|
|
8f9a109fa6 | ||
|
|
05468cc3fa | ||
|
|
94d69777fa | ||
|
|
67144aaf2a | ||
|
|
d9efc3b4bf | ||
|
|
c32aac0a56 | ||
|
|
92b15c81e9 | ||
|
|
19d742de37 | ||
|
|
e8f33f51fb | ||
|
|
7f7cdbf775 | ||
|
|
7f42c0fa21 | ||
|
|
8306dc427a | ||
|
|
66b3972fbc | ||
|
|
ed244648d0 | ||
|
|
790fba598e | ||
|
|
129159c895 | ||
|
|
f4c696b922 | ||
|
|
f54506acc0 | ||
|
|
4466082592 | ||
|
|
a8256a62e0 | ||
|
|
683917ae67 | ||
|
|
a22b9be681 | ||
|
|
3b20f2aced | ||
|
|
5d23b7468e | ||
|
|
d5b47d1059 | ||
|
|
47e9deeb9a | ||
|
|
6d6e75795f | ||
|
|
cc3066e746 | ||
|
|
0fcc0f3e0a | ||
|
|
da83ba6c06 | ||
|
|
3c186946eb | ||
|
|
31beee9599 | ||
|
|
912ed2ca10 | ||
|
|
c2352d3499 | ||
|
|
3a3b05b2f0 | ||
|
|
95a8f3fc70 | ||
|
|
34cd1435b4 | ||
|
|
d4be2da70e | ||
|
|
e5c4e34ac4 | ||
|
|
6dfa7b5383 | ||
|
|
94382cbaa2 | ||
|
|
981908c336 | ||
|
|
3ee054e316 | ||
|
|
f22d4bf0c0 | ||
|
|
d46e986e80 | ||
|
|
bd6d41bd87 | ||
|
|
4457edb1d3 | ||
|
|
e920ce3e24 | ||
|
|
ce8aa073ee | ||
|
|
2396b51cb6 | ||
|
|
317406f26d | ||
|
|
67a9931b55 | ||
|
|
ad851547e0 | ||
|
|
c4cbb5ecdb | ||
|
|
b97c22d4d7 | ||
|
|
fe631e6eeb | ||
|
|
1314b7c7e5 | ||
|
|
c026863d48 | ||
|
|
51d5ef9d86 | ||
|
|
16fb847009 | ||
|
|
cd8ceec62e | ||
|
|
98a9d8a9e3 | ||
|
|
4e2f242ad0 | ||
|
|
02bdace366 | ||
|
|
6ed538b952 | ||
|
|
dfbe158ca9 | ||
|
|
fb37b5720d | ||
|
|
57ab704300 | ||
|
|
4a310ad630 | ||
|
|
a9ad783bca | ||
|
|
b5c9fe78f1 | ||
|
|
e4bb456964 | ||
|
|
b45ed8d9a2 | ||
|
|
bdf73fcd4c | ||
|
|
3e720bd611 | ||
|
|
ad89a923e9 | ||
|
|
725115e0b5 | ||
|
|
419a14a63f | ||
|
|
d9102efff7 | ||
|
|
895ab49857 | ||
|
|
ebbb974aca | ||
|
|
8a6ba7c49f | ||
|
|
f98da217e1 | ||
|
|
2060acd914 | ||
|
|
014d80c359 | ||
|
|
9b7ad675c6 | ||
|
|
6ee8f6e4f2 | ||
|
|
4d56281972 | ||
|
|
5584e3fd49 | ||
|
|
4a376694b4 | ||
|
|
fbdea15649 | ||
|
|
f961f0617f | ||
|
|
1c60575dc0 | ||
|
|
abf8ffd3a2 | ||
|
|
935cd92ef3 | ||
|
|
172a5a71fc | ||
|
|
c244e83e10 | ||
|
|
291604515f | ||
|
|
904b75ab4a | ||
|
|
2de0b025f1 | ||
|
|
5f52ca918f | ||
|
|
16a95a42ff | ||
|
|
4282ed6a3c | ||
|
|
a642782a00 | ||
|
|
0bb4e0e44a | ||
|
|
d91ddc6177 | ||
|
|
2b9826404a | ||
|
|
4d5790dc09 | ||
|
|
c22b138b67 | ||
|
|
fdad5892d9 | ||
|
|
c3791bba78 | ||
|
|
bf5f85645e | ||
|
|
f1f801b7a2 | ||
|
|
5ede62459c | ||
|
|
abd97a7513 | ||
|
|
30d815e28f | ||
|
|
e233eab4f2 | ||
|
|
b202bba2e6 | ||
|
|
d78efe7c22 | ||
|
|
b169ac016e | ||
|
|
d1685f79a2 | ||
|
|
01e891652f | ||
|
|
c82d21b39f | ||
|
|
63c2a7f1a9 | ||
|
|
9a60fde59b | ||
|
|
f46fcd158a | ||
|
|
1b1735bca9 | ||
|
|
3a5977e09f | ||
|
|
d34800bb0a | ||
|
|
662261f84f | ||
|
|
33a926c5d3 | ||
|
|
c372dcb462 | ||
|
|
9a768dd4f0 | ||
|
|
82377cbfd5 | ||
|
|
83ba21f622 | ||
|
|
f31bfab127 | ||
|
|
466fc9a2fa | ||
|
|
fd41f1e8bc | ||
|
|
32b2ef3539 | ||
|
|
cde6b41a05 | ||
|
|
3ecfadf367 | ||
|
|
27c3727ddb | ||
|
|
ea147c588f | ||
|
|
e8a02316ce | ||
|
|
0dcf061dc1 | ||
|
|
f2d91bc53c | ||
|
|
ddda8e4197 | ||
|
|
4fe294ed04 | ||
|
|
be57151037 | ||
|
|
71ee864d1d | ||
|
|
427b9567ca | ||
|
|
5e7d6f89e8 | ||
|
|
7644799790 | ||
|
|
dbecc8d5f5 | ||
|
|
4ae1998d09 | ||
|
|
bbd8f091e0 | ||
|
|
6f806190b6 | ||
|
|
e80e4ae02c | ||
|
|
04b797ff0c | ||
|
|
f960c2dc63 | ||
|
|
9b445c27a2 | ||
|
|
97a2889fd9 | ||
|
|
c548b9c87e | ||
|
|
097d4d9870 | ||
|
|
b238ac5981 | ||
|
|
fe19e63fbc | ||
|
|
efd8a8a624 | ||
|
|
fa169ee7ff | ||
|
|
0e7bc6b8ec | ||
|
|
f8185296f4 | ||
|
|
4129d45d21 | ||
|
|
361505661f | ||
|
|
b558485394 | ||
|
|
a9a331938e | ||
|
|
7c69c2846b | ||
|
|
cda8b119e2 | ||
|
|
975978b414 | ||
|
|
5ee0ff9ee9 | ||
|
|
ca63ea0882 | ||
|
|
50c913fe92 | ||
|
|
22f51372f5 | ||
|
|
e4d90f747f | ||
|
|
4a8d7c1819 | ||
|
|
3a81a5224d | ||
|
|
3993161a63 | ||
|
|
25019de690 | ||
|
|
8fea373758 | ||
|
|
b0e8cafa00 | ||
|
|
1a8c0230a7 | ||
|
|
6980982e32 | ||
|
|
ec5d05e226 | ||
|
|
3387459be2 | ||
|
|
9963ddc485 | ||
|
|
46d80e8f05 | ||
|
|
ef30adcaef | ||
|
|
36c376b1ec | ||
|
|
dcbc6a127b | ||
|
|
e4415f0021 | ||
|
|
b4403fa9ec | ||
|
|
a725a49759 | ||
|
|
76f1e6d526 | ||
|
|
d19ae50cad | ||
|
|
9f461aed68 | ||
|
|
3913e18447 | ||
|
|
90fb7bc52d | ||
|
|
76d33c37d7 | ||
|
|
033f9bcced | ||
|
|
1c97fc79ad | ||
|
|
0097f89adb | ||
|
|
32ba219146 | ||
|
|
add7f8a4aa | ||
|
|
2785a4cc48 | ||
|
|
827741a9c6 | ||
|
|
ca623f16bf | ||
|
|
3bd54b7920 | ||
|
|
613a51f5fb | ||
|
|
e5d30636c2 | ||
|
|
e1beeb95e3 | ||
|
|
4ca8039104 | ||
|
|
e817192df3 | ||
|
|
2bb7497312 | ||
|
|
82ffa4d2b1 | ||
|
|
707503ac40 | ||
|
|
7fee639edf | ||
|
|
d1545a64ae | ||
|
|
40631edb70 | ||
|
|
4d1cd7e15f | ||
|
|
4c10925694 | ||
|
|
fc2bc20572 | ||
|
|
4a195e6283 | ||
|
|
24bcd3b21e | ||
|
|
9ab53b0e4b | ||
|
|
e5380fd671 | ||
|
|
d9c769fa69 | ||
|
|
d8d7e5b9bb | ||
|
|
f8e1dfbbc6 | ||
|
|
f02cae1b0a | ||
|
|
fa7f900b2b | ||
|
|
75e5695317 | ||
|
|
66ef52197a | ||
|
|
9e3f108fad | ||
|
|
1571c3537d | ||
|
|
18780487c2 | ||
|
|
ce042d0524 | ||
|
|
312b8c95ba | ||
|
|
6e8bc6a597 | ||
|
|
d9c90be1de | ||
|
|
ed023a560e | ||
|
|
15ae6b8d36 | ||
|
|
853ce0bbd7 | ||
|
|
1c190388e5 | ||
|
|
3fdc4543b8 | ||
|
|
be06a3d562 | ||
|
|
95e72c24cc | ||
|
|
c8d0ef05a6 | ||
|
|
85119db81a | ||
|
|
4d9470c24e | ||
|
|
2b1894f356 | ||
|
|
dca872d987 | ||
|
|
4660d3c265 | ||
|
|
f2bf8d6db3 | ||
|
|
ae8ac97f32 | ||
|
|
2b82e523bf | ||
|
|
9d54092f41 | ||
|
|
5f357d39b2 | ||
|
|
1817ddc18a | ||
|
|
102fb66461 | ||
|
|
0f67b1866a | ||
|
|
f2853a0b89 | ||
|
|
6c5429c7f0 | ||
|
|
a6ba0cd107 | ||
|
|
57e6b75871 | ||
|
|
904505bb21 | ||
|
|
56afe4dd5d | ||
|
|
2d190b9952 | ||
|
|
298d3a0144 | ||
|
|
22c50d0800 | ||
|
|
06834b723b | ||
|
|
a04222f398 | ||
|
|
0d4d2080ca | ||
|
|
7142cae041 | ||
|
|
921e7e0f91 | ||
|
|
f2fdc556a4 | ||
|
|
1835d90bb7 | ||
|
|
f5cf3556b1 | ||
|
|
a53b1f7edf | ||
|
|
f64dbbea3e | ||
|
|
6842ac98c3 | ||
|
|
294dbac869 | ||
|
|
5f27bb597f | ||
|
|
4c145f44a4 | ||
|
|
abe63ebd84 | ||
|
|
4f67415607 | ||
|
|
e2ec50173f | ||
|
|
d2ab8322b7 | ||
|
|
9ae59e8ac7 | ||
|
|
6d7d068e49 | ||
|
|
ae6a1b409f | ||
|
|
4608f5e9cd | ||
|
|
9300859983 | ||
|
|
52240750a1 | ||
|
|
d76bd4a103 | ||
|
|
bfac7f7a17 | ||
|
|
36d2512ff8 | ||
|
|
ca7e2c4d96 | ||
|
|
817dfbdc27 | ||
|
|
5fa7ae7d72 | ||
|
|
c54eca8dff | ||
|
|
72f5381c31 | ||
|
|
7ca2363d78 | ||
|
|
dec7c40fd8 | ||
|
|
a8846e0432 | ||
|
|
ff87592722 | ||
|
|
8c5f171a93 | ||
|
|
ea74e825c9 | ||
|
|
2b3ef714bd | ||
|
|
23afffa46d | ||
|
|
129cdb7680 | ||
|
|
8d3404d26c | ||
|
|
05e0564426 | ||
|
|
d8be645d5a | ||
|
|
3f499f69ff | ||
|
|
75b24c7d76 | ||
|
|
c6cf91d11f | ||
|
|
3a50c9e48c | ||
|
|
7c2b1468c8 | ||
|
|
fb6c80d12e | ||
|
|
d826e1e5fb | ||
|
|
04a0aaa35f | ||
|
|
f5fbd52dbd | ||
|
|
5575d17d0e | ||
|
|
0e7970fec5 | ||
|
|
fdfd8807a0 | ||
|
|
da07e72f20 | ||
|
|
f4a27f699a | ||
|
|
e3c21424de | ||
|
|
b5aa2a31a1 | ||
|
|
05ae1960d1 | ||
|
|
dde791d475 | ||
|
|
16b2f08cd3 | ||
|
|
0143a45488 | ||
|
|
2f1683445b | ||
|
|
4c78f98da6 | ||
|
|
3ff2959f0c | ||
|
|
36c4b1705d | ||
|
|
d8adbc0875 | ||
|
|
b527846ee4 | ||
|
|
ee45f0e8bc | ||
|
|
ca5ee0fc81 | ||
|
|
ecf29f72bc | ||
|
|
c811beb1e2 | ||
|
|
0c091428d3 | ||
|
|
858198a2bd | ||
|
|
1649d8f900 | ||
|
|
eb42fdbbc6 | ||
|
|
6cc571bdfe | ||
|
|
da648511b3 | ||
|
|
18b3dfa350 | ||
|
|
05be71e9bc | ||
|
|
36819e2638 | ||
|
|
9b585458c1 | ||
|
|
c424d0e9f3 | ||
|
|
81783b255e | ||
|
|
80c8ab4c39 | ||
|
|
826a4e0e48 | ||
|
|
7917748b21 | ||
|
|
b7f974f469 | ||
|
|
5c5fd377f7 | ||
|
|
0a995c3731 | ||
|
|
47b754e914 | ||
|
|
00ef99826d | ||
|
|
45943302ee | ||
|
|
2157f898bb | ||
|
|
132c7aba2d | ||
|
|
1ae88f0f0f | ||
|
|
c0f0fcba7b | ||
|
|
cdb1711fe1 | ||
|
|
20b4cae980 | ||
|
|
67bc4afe88 | ||
|
|
fb78169396 | ||
|
|
ba7e26539f | ||
|
|
500d15f53a | ||
|
|
fad977e27d | ||
|
|
4983ef77bd | ||
|
|
4a6066c69e | ||
|
|
1690df9bcf | ||
|
|
5c94f7ccd4 | ||
|
|
494c3f3255 | ||
|
|
ec4d596189 | ||
|
|
bc04e951cf | ||
|
|
e3109c9f1f | ||
|
|
6fc6aae62d | ||
|
|
b44c66b5c2 | ||
|
|
20c1530278 | ||
|
|
a213a8639f | ||
|
|
38583ca721 | ||
|
|
5126f02184 | ||
|
|
c910686b01 | ||
|
|
23833cf7f4 | ||
|
|
b37c73436b | ||
|
|
32f0ae5b50 | ||
|
|
87809e65aa | ||
|
|
916fa4b9a8 | ||
|
|
217e8f4078 | ||
|
|
21f05fc363 | ||
|
|
51b5e953f4 | ||
|
|
5bdb4b9aa1 | ||
|
|
bcfe243b3c | ||
|
|
2814dc316a | ||
|
|
fc3026dcfe | ||
|
|
1f580cbb67 | ||
|
|
237b7bedaa | ||
|
|
c34c5965c5 | ||
|
|
8f611687f1 | ||
|
|
a6ad824ccb | ||
|
|
c1737e5c16 | ||
|
|
1d148fe2fb | ||
|
|
88a1c7973c | ||
|
|
7a52a4cff1 | ||
|
|
ee08d98d2e | ||
|
|
9cf4156928 | ||
|
|
45f022b9db | ||
|
|
0d3cc8aaa7 | ||
|
|
5b69421625 | ||
|
|
397a503da3 | ||
|
|
51cadc6e90 | ||
|
|
3971249868 | ||
|
|
3a850b94f5 | ||
|
|
a179e48e3b | ||
|
|
2de9123cfd | ||
|
|
378e56e254 | ||
|
|
0d3aaaf0af |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@
|
||||
/vendor/brightray/vendor/download/
|
||||
/vendor/python_26/
|
||||
/vendor/npm/
|
||||
/vendor/.gclient
|
||||
node_modules/
|
||||
*.xcodeproj
|
||||
*.swp
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -13,3 +13,6 @@
|
||||
[submodule "vendor/native_mate"]
|
||||
path = vendor/native_mate
|
||||
url = https://github.com/zcbenz/native-mate.git
|
||||
[submodule "vendor/crashpad"]
|
||||
path = vendor/crashpad
|
||||
url = https://github.com/atom/crashpad.git
|
||||
|
||||
71
CONTRIBUTING.md
Normal file
71
CONTRIBUTING.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# Contributing to Electron
|
||||
|
||||
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
|
||||
|
||||
The following is a set of guidelines for contributing to Electron.
|
||||
These are just guidelines, not rules, use your best judgment and feel free to
|
||||
propose changes to this document in a pull request.
|
||||
|
||||
## Submitting Issues
|
||||
|
||||
* You can create an issue [here](https://github.com/atom/electron/issues/new),
|
||||
but before doing that please read the notes below and include as many details as
|
||||
possible with your report. If you can, please include:
|
||||
* The version of Electron you are using
|
||||
* The operating system you are using
|
||||
* If applicable, what you were doing when the issue arose and what you
|
||||
expected to happen
|
||||
* Other things that will help resolve your issue:
|
||||
* Screenshots and animated GIFs
|
||||
* Error output that appears in your terminal, dev tools or as an alert
|
||||
* Perform a [cursory search](https://github.com/atom/electron/issues?utf8=✓&q=is%3Aissue+)
|
||||
to see if a similar issue has already been submitted
|
||||
|
||||
## Submitting Pull Requests
|
||||
|
||||
* Include screenshots and animated GIFs in your pull request whenever possible.
|
||||
* Follow the CoffeeScript, JavaScript, C++ and Python [coding style defined in docs](/docs/development/coding-style.md).
|
||||
* Write documentation in [Markdown](https://daringfireball.net/projects/markdown).
|
||||
* Use short, present tense commit messages. See [Commit Message Styleguide](#git-commit-messages-styleguide).
|
||||
|
||||
## Styleguides
|
||||
|
||||
### General Code
|
||||
|
||||
* End files with a newline.
|
||||
* Place requires in the following order:
|
||||
* Built in Node Modules (such as `path`)
|
||||
* Built in Electron Modules (such as `ipc`, `app`)
|
||||
* Local Modules (using relative paths)
|
||||
* Place class properties in the following order:
|
||||
* Class methods and properties (methods starting with a `@`)
|
||||
* Instance methods and properties
|
||||
* Avoid platform-dependent code:
|
||||
* Use `path.join()` to concatenate filenames.
|
||||
* Use `os.tmpdir()` rather than `/tmp` when you need to reference the
|
||||
temporary directory.
|
||||
* Using a plain `return` when returning explicitly at the end of a function.
|
||||
* Not `return null`, `return undefined`, `null`, or `undefined`
|
||||
|
||||
### Git Commit Messages
|
||||
|
||||
* Use the present tense ("Add feature" not "Added feature")
|
||||
* Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
|
||||
* Limit the first line to 72 characters or less
|
||||
* Reference issues and pull requests liberally
|
||||
* Consider starting the commit message with an applicable emoji:
|
||||
* :art: `:art:` when improving the format/structure of the code
|
||||
* :racehorse: `:racehorse:` when improving performance
|
||||
* :non-potable_water: `:non-potable_water:` when plugging memory leaks
|
||||
* :memo: `:memo:` when writing docs
|
||||
* :penguin: `:penguin:` when fixing something on Linux
|
||||
* :apple: `:apple:` when fixing something on Mac OS
|
||||
* :checkered_flag: `:checkered_flag:` when fixing something on Windows
|
||||
* :bug: `:bug:` when fixing a bug
|
||||
* :fire: `:fire:` when removing code or files
|
||||
* :green_heart: `:green_heart:` when fixing the CI build
|
||||
* :white_check_mark: `:white_check_mark:` when adding tests
|
||||
* :lock: `:lock:` when dealing with security
|
||||
* :arrow_up: `:arrow_up:` when upgrading dependencies
|
||||
* :arrow_down: `:arrow_down:` when downgrading dependencies
|
||||
* :shirt: `:shirt:` when removing linter warnings
|
||||
27
README.md
27
README.md
@@ -1,18 +1,37 @@
|
||||
# Electron [](https://travis-ci.org/atom/electron)
|
||||
[](http://electron.atom.io/)
|
||||
|
||||
[](https://travis-ci.org/atom/electron)
|
||||
[](https://david-dm.org/atom/electron#info=devDependencies)
|
||||
|
||||
:zap: *formerly known as Atom Shell* :zap:
|
||||
|
||||
The Electron framework lets you write cross-platform desktop applications
|
||||
using JavaScript, HTML and CSS. It is based on [io.js](http://iojs.org) and
|
||||
[Chromium](http://www.chromium.org) and is used in the [Atom
|
||||
editor](https://github.com/atom/atom).
|
||||
|
||||
Follow [@ElectronJS](https://twitter.com/electronjs) on Twitter for important
|
||||
announcements.
|
||||
|
||||
## Downloads
|
||||
|
||||
Prebuilt binaries and debug symbols of Electron for Linux, Windows and Mac can
|
||||
be found on the [releases](https://github.com/atom/electron/releases) page.
|
||||
|
||||
You can also use [`npm`](https://docs.npmjs.com/) to install prebuilt electron
|
||||
binaries:
|
||||
|
||||
```sh
|
||||
# Install the `electron` command globally in your $PATH
|
||||
npm install electron-prebuilt -g
|
||||
|
||||
# Install as a development dependency
|
||||
npm install electron-prebuilt --save-dev
|
||||
```
|
||||
|
||||
### Mirrors
|
||||
|
||||
- [China](https://npm.taobao.org/mirrors/atom-shell)
|
||||
- [China](https://npm.taobao.org/mirrors/electron)
|
||||
|
||||
## Documentation
|
||||
|
||||
@@ -22,5 +41,7 @@ contains documents describing how to build and contribute to Electron.
|
||||
|
||||
## Community
|
||||
|
||||
There is an [`atom-shell` category on the Atom forums](http://discuss.atom.io/category/atom-shell)
|
||||
There is an [`electron` category on the Atom forums](http://discuss.atom.io/category/electron)
|
||||
as well as an `#atom-shell` channel on Freenode.
|
||||
|
||||
Check out [awesome-electron](https://github.com/sindresorhus/awesome-electron) for a community maintained list of useful example apps, tools and resources.
|
||||
|
||||
26
atom.gyp
26
atom.gyp
@@ -4,7 +4,7 @@
|
||||
'product_name%': 'Electron',
|
||||
'company_name%': 'GitHub, Inc',
|
||||
'company_abbr%': 'github',
|
||||
'version%': '0.24.0',
|
||||
'version%': '0.28.1',
|
||||
|
||||
'atom_source_root': '<!(["python", "tools/atom_source_root.py"])',
|
||||
},
|
||||
@@ -45,6 +45,7 @@
|
||||
'dependencies': [
|
||||
'<(project_name)_framework',
|
||||
'<(project_name)_helper',
|
||||
'vendor/breakpad/breakpad.gyp:dump_syms',
|
||||
],
|
||||
'xcode_settings': {
|
||||
'ATOM_BUNDLE_ID': 'com.<(company_abbr).<(project_name)',
|
||||
@@ -114,15 +115,6 @@
|
||||
],
|
||||
}], # OS!="mac"
|
||||
['OS=="win"', {
|
||||
'msvs_settings': {
|
||||
'VCLinkerTool': {
|
||||
'AdditionalOptions': [
|
||||
# Force linking even though we have duplicate symbols between
|
||||
# BoringSSL and OpenSSL.
|
||||
'/FORCE:MULTIPLE',
|
||||
],
|
||||
},
|
||||
},
|
||||
'copies': [
|
||||
{
|
||||
'variables': {
|
||||
@@ -133,7 +125,9 @@
|
||||
'<@(libchromiumcontent_shared_v8_libraries)',
|
||||
],
|
||||
}, {
|
||||
'copied_libraries': [],
|
||||
'copied_libraries': [
|
||||
'<(libchromiumcontent_dir)/pdf.dll',
|
||||
],
|
||||
}],
|
||||
],
|
||||
},
|
||||
@@ -151,6 +145,9 @@
|
||||
'<(libchromiumcontent_dir)/snapshot_blob.bin',
|
||||
'external_binaries/d3dcompiler_47.dll',
|
||||
'external_binaries/xinput1_3.dll',
|
||||
'external_binaries/msvcp120.dll',
|
||||
'external_binaries/msvcr120.dll',
|
||||
'external_binaries/vccorlib120.dll',
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -279,7 +276,8 @@
|
||||
}], # OS=="win"
|
||||
['OS=="mac"', {
|
||||
'dependencies': [
|
||||
'vendor/breakpad/breakpad.gyp:breakpad',
|
||||
'vendor/crashpad/client/client.gyp:crashpad_client',
|
||||
'vendor/crashpad/handler/handler.gyp:crashpad_handler',
|
||||
],
|
||||
}], # OS=="mac"
|
||||
['OS=="linux"', {
|
||||
@@ -434,8 +432,7 @@
|
||||
{
|
||||
'destination': '<(PRODUCT_DIR)/<(product_name) Framework.framework/Versions/A/Resources',
|
||||
'files': [
|
||||
'<(PRODUCT_DIR)/Inspector',
|
||||
'<(PRODUCT_DIR)/crash_report_sender.app',
|
||||
'<(PRODUCT_DIR)/crashpad_handler',
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -456,7 +453,6 @@
|
||||
'tools/mac/create-framework-subdir-symlinks.sh',
|
||||
'<(product_name) Framework',
|
||||
'Libraries',
|
||||
'Frameworks',
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -8,9 +8,60 @@
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/chrome_version.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/public/common/content_constants.h"
|
||||
#include "content/public/common/pepper_plugin_info.h"
|
||||
#include "ppapi/shared_impl/ppapi_permissions.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path,
|
||||
const std::string& version) {
|
||||
content::PepperPluginInfo plugin;
|
||||
|
||||
plugin.is_out_of_process = true;
|
||||
plugin.name = content::kFlashPluginName;
|
||||
plugin.path = path;
|
||||
plugin.permissions = ppapi::PERMISSION_ALL_BITS;
|
||||
|
||||
std::vector<std::string> flash_version_numbers;
|
||||
base::SplitString(version, '.', &flash_version_numbers);
|
||||
if (flash_version_numbers.size() < 1)
|
||||
flash_version_numbers.push_back("11");
|
||||
// |SplitString()| puts in an empty string given an empty string. :(
|
||||
else if (flash_version_numbers[0].empty())
|
||||
flash_version_numbers[0] = "11";
|
||||
if (flash_version_numbers.size() < 2)
|
||||
flash_version_numbers.push_back("2");
|
||||
if (flash_version_numbers.size() < 3)
|
||||
flash_version_numbers.push_back("999");
|
||||
if (flash_version_numbers.size() < 4)
|
||||
flash_version_numbers.push_back("999");
|
||||
// E.g., "Shockwave Flash 10.2 r154":
|
||||
plugin.description = plugin.name + " " + flash_version_numbers[0] + "." +
|
||||
flash_version_numbers[1] + " r" + flash_version_numbers[2];
|
||||
plugin.version = JoinString(flash_version_numbers, '.');
|
||||
content::WebPluginMimeType swf_mime_type(
|
||||
content::kFlashPluginSwfMimeType,
|
||||
content::kFlashPluginSwfExtension,
|
||||
content::kFlashPluginSwfDescription);
|
||||
plugin.mime_types.push_back(swf_mime_type);
|
||||
content::WebPluginMimeType spl_mime_type(
|
||||
content::kFlashPluginSplMimeType,
|
||||
content::kFlashPluginSplExtension,
|
||||
content::kFlashPluginSplDescription);
|
||||
plugin.mime_types.push_back(spl_mime_type);
|
||||
|
||||
return plugin;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AtomContentClient::AtomContentClient() {
|
||||
}
|
||||
|
||||
@@ -27,4 +78,19 @@ void AtomContentClient::AddAdditionalSchemes(
|
||||
standard_schemes->push_back("chrome-extension");
|
||||
}
|
||||
|
||||
void AtomContentClient::AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) {
|
||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||
auto flash_path = command_line->GetSwitchValueNative(
|
||||
switches::kPpapiFlashPath);
|
||||
if (flash_path.empty())
|
||||
return;
|
||||
|
||||
auto flash_version = command_line->GetSwitchValueASCII(
|
||||
switches::kPpapiFlashVersion);
|
||||
|
||||
plugins->push_back(
|
||||
CreatePepperFlashInfo(base::FilePath(flash_path), flash_version));
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -23,6 +23,8 @@ class AtomContentClient : public brightray::ContentClient {
|
||||
void AddAdditionalSchemes(
|
||||
std::vector<std::string>* standard_schemes,
|
||||
std::vector<std::string>* savable_schemes) override;
|
||||
void AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomContentClient);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/common/google_api_key.h"
|
||||
#include "atom/renderer/atom_renderer_client.h"
|
||||
#include "atom/utility/atom_content_utility_client.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/debug/stack_trace.h"
|
||||
#include "base/environment.h"
|
||||
@@ -63,6 +64,10 @@ void AtomMainDelegate::PreSandboxStartup() {
|
||||
std::string process_type = command_line->GetSwitchValueASCII(
|
||||
switches::kProcessType);
|
||||
|
||||
if (process_type == switches::kUtilityProcess) {
|
||||
AtomContentUtilityClient::PreSandboxStartup();
|
||||
}
|
||||
|
||||
// Only append arguments for browser process.
|
||||
if (!process_type.empty())
|
||||
return;
|
||||
@@ -77,6 +82,9 @@ void AtomMainDelegate::PreSandboxStartup() {
|
||||
// Disable renderer sandbox for most of node's functions.
|
||||
command_line->AppendSwitch(switches::kNoSandbox);
|
||||
|
||||
// Allow file:// URIs to read other file:// URIs by default.
|
||||
command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
// Enable AVFoundation.
|
||||
command_line->AppendSwitch("enable-avfoundation");
|
||||
@@ -94,6 +102,11 @@ content::ContentRendererClient*
|
||||
return renderer_client_.get();
|
||||
}
|
||||
|
||||
content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
|
||||
utility_client_.reset(new AtomContentUtilityClient);
|
||||
return utility_client_.get();
|
||||
}
|
||||
|
||||
scoped_ptr<brightray::ContentClient> AtomMainDelegate::CreateContentClient() {
|
||||
return scoped_ptr<brightray::ContentClient>(new AtomContentClient).Pass();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
||||
void PreSandboxStartup() override;
|
||||
content::ContentBrowserClient* CreateContentBrowserClient() override;
|
||||
content::ContentRendererClient* CreateContentRendererClient() override;
|
||||
content::ContentUtilityClient* CreateContentUtilityClient() override;
|
||||
|
||||
// brightray::MainDelegate:
|
||||
scoped_ptr<brightray::ContentClient> CreateContentClient() override;
|
||||
@@ -35,6 +36,7 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
||||
brightray::ContentClient content_client_;
|
||||
scoped_ptr<content::ContentBrowserClient> browser_client_;
|
||||
scoped_ptr<content::ContentRendererClient> renderer_client_;
|
||||
scoped_ptr<content::ContentUtilityClient> utility_client_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate);
|
||||
};
|
||||
|
||||
@@ -26,7 +26,19 @@ int NodeMain(int argc, char *argv[]) {
|
||||
|
||||
JavascriptEnvironment gin_env;
|
||||
node::Environment* env = node::CreateEnvironment(
|
||||
gin_env.isolate(), gin_env.context(), argc, argv, exec_argc, exec_argv);
|
||||
gin_env.isolate(), uv_default_loop(), gin_env.context(), argc, argv,
|
||||
exec_argc, exec_argv);
|
||||
|
||||
// Start debugger.
|
||||
node::node_isolate = gin_env.isolate();
|
||||
if (node::use_debug_agent)
|
||||
node::StartDebug(env, node::debug_wait_connect);
|
||||
|
||||
node::LoadEnvironment(env);
|
||||
|
||||
// Enable debugger.
|
||||
if (node::use_debug_agent)
|
||||
node::EnableDebug(env);
|
||||
|
||||
bool more;
|
||||
do {
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#include "atom/browser/api/atom_api_menu.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/browser.h"
|
||||
@@ -25,6 +29,10 @@
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#endif
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
using atom::Browser;
|
||||
@@ -34,7 +42,7 @@ namespace mate {
|
||||
#if defined(OS_WIN)
|
||||
template<>
|
||||
struct Converter<Browser::UserTask> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
Browser::UserTask* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
@@ -200,6 +208,13 @@ void App::SetDesktopName(const std::string& desktop_name) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void App::SetAppUserModelId(const std::string& app_id) {
|
||||
#if defined(OS_WIN)
|
||||
base::string16 app_id_utf16 = base::UTF8ToUTF16(app_id);
|
||||
SetCurrentProcessExplicitAppUserModelID(app_id_utf16.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
auto browser = base::Unretained(Browser::Get());
|
||||
@@ -222,7 +237,8 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
||||
.SetMethod("setPath", &App::SetPath)
|
||||
.SetMethod("getPath", &App::GetPath)
|
||||
.SetMethod("resolveProxy", &App::ResolveProxy)
|
||||
.SetMethod("setDesktopName", &App::SetDesktopName);
|
||||
.SetMethod("setDesktopName", &App::SetDesktopName)
|
||||
.SetMethod("setAppUserModelId", &App::SetAppUserModelId);
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -261,8 +277,8 @@ void DockSetMenu(atom::api::Menu* menu) {
|
||||
}
|
||||
#endif
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ class App : public mate::EventEmitter,
|
||||
|
||||
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
||||
void SetDesktopName(const std::string& desktop_name);
|
||||
void SetAppUserModelId(const std::string& app_id);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(App);
|
||||
};
|
||||
|
||||
@@ -77,8 +77,8 @@ mate::Handle<AutoUpdater> AutoUpdater::Create(v8::Isolate* isolate) {
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("autoUpdater", atom::api::AutoUpdater::Create(isolate));
|
||||
|
||||
@@ -17,38 +17,24 @@ using content::TracingController;
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<typename T>
|
||||
struct Converter<std::set<T> > {
|
||||
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const std::set<T>& val) {
|
||||
v8::Handle<v8::Array> result = v8::Array::New(
|
||||
isolate, static_cast<int>(val.size()));
|
||||
typename std::set<T>::const_iterator it;
|
||||
int i;
|
||||
for (i = 0, it = val.begin(); it != val.end(); ++it, ++i)
|
||||
result->Set(i, Converter<T>::ToV8(isolate, *it));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<base::debug::CategoryFilter> {
|
||||
struct Converter<base::trace_event::CategoryFilter> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
base::debug::CategoryFilter* out) {
|
||||
v8::Local<v8::Value> val,
|
||||
base::trace_event::CategoryFilter* out) {
|
||||
std::string filter;
|
||||
if (!ConvertFromV8(isolate, val, &filter))
|
||||
return false;
|
||||
*out = base::debug::CategoryFilter(filter);
|
||||
*out = base::trace_event::CategoryFilter(filter);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<base::debug::TraceOptions> {
|
||||
struct Converter<base::trace_event::TraceOptions> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
base::debug::TraceOptions* out) {
|
||||
v8::Local<v8::Value> val,
|
||||
base::trace_event::TraceOptions* out) {
|
||||
std::string options;
|
||||
if (!ConvertFromV8(isolate, val, &options))
|
||||
return false;
|
||||
@@ -60,8 +46,8 @@ struct Converter<base::debug::TraceOptions> {
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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(
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace mate {
|
||||
template<>
|
||||
struct Converter<file_dialog::Filter> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
v8::Local<v8::Value> val,
|
||||
file_dialog::Filter* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
@@ -52,7 +52,7 @@ void ShowMessageBox(int type,
|
||||
const std::string& message = texts[1];
|
||||
const std::string& detail = texts[2];
|
||||
|
||||
v8::Handle<v8::Value> peek = args->PeekNext();
|
||||
v8::Local<v8::Value> peek = args->PeekNext();
|
||||
atom::MessageBoxCallback callback;
|
||||
if (mate::Converter<atom::MessageBoxCallback>::FromV8(args->isolate(),
|
||||
peek,
|
||||
@@ -72,7 +72,7 @@ void ShowOpenDialog(const std::string& title,
|
||||
int properties,
|
||||
atom::NativeWindow* window,
|
||||
mate::Arguments* args) {
|
||||
v8::Handle<v8::Value> peek = args->PeekNext();
|
||||
v8::Local<v8::Value> peek = args->PeekNext();
|
||||
file_dialog::OpenDialogCallback callback;
|
||||
if (mate::Converter<file_dialog::OpenDialogCallback>::FromV8(args->isolate(),
|
||||
peek,
|
||||
@@ -92,7 +92,7 @@ void ShowSaveDialog(const std::string& title,
|
||||
const file_dialog::Filters& filters,
|
||||
atom::NativeWindow* window,
|
||||
mate::Arguments* args) {
|
||||
v8::Handle<v8::Value> peek = args->PeekNext();
|
||||
v8::Local<v8::Value> peek = args->PeekNext();
|
||||
file_dialog::SaveDialogCallback callback;
|
||||
if (mate::Converter<file_dialog::SaveDialogCallback>::FromV8(args->isolate(),
|
||||
peek,
|
||||
@@ -106,8 +106,8 @@ void ShowSaveDialog(const std::string& title,
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("showMessageBox", &ShowMessageBox);
|
||||
dict.SetMethod("showErrorBox", &atom::ShowErrorBox);
|
||||
|
||||
@@ -86,8 +86,8 @@ mate::Handle<GlobalShortcut> GlobalShortcut::Create(v8::Isolate* isolate) {
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("globalShortcut", atom::api::GlobalShortcut::Create(isolate));
|
||||
|
||||
@@ -58,7 +58,7 @@ bool Menu::GetAcceleratorForCommandId(int command_id,
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::Locker locker(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Handle<v8::Value> val = get_accelerator_.Run(command_id);
|
||||
v8::Local<v8::Value> val = get_accelerator_.Run(command_id);
|
||||
return mate::ConvertFromV8(isolate, val, accelerator);
|
||||
}
|
||||
|
||||
@@ -70,10 +70,6 @@ void Menu::MenuWillShow(ui::SimpleMenuModel* source) {
|
||||
menu_will_show_.Run();
|
||||
}
|
||||
|
||||
void Menu::AttachToWindow(Window* window) {
|
||||
window->window()->SetMenu(model_.get());
|
||||
}
|
||||
|
||||
void Menu::InsertItemAt(
|
||||
int index, int command_id, const base::string16& label) {
|
||||
model_->InsertItemAt(index, command_id, label);
|
||||
@@ -150,7 +146,7 @@ bool Menu::IsVisibleAt(int index) const {
|
||||
|
||||
// static
|
||||
void Menu::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype) {
|
||||
v8::Local<v8::ObjectTemplate> prototype) {
|
||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||
.SetMethod("insertItem", &Menu::InsertItemAt)
|
||||
.SetMethod("insertCheckItem", &Menu::InsertCheckItemAt)
|
||||
@@ -168,7 +164,6 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("isItemCheckedAt", &Menu::IsItemCheckedAt)
|
||||
.SetMethod("isEnabledAt", &Menu::IsEnabledAt)
|
||||
.SetMethod("isVisibleAt", &Menu::IsVisibleAt)
|
||||
.SetMethod("attachToWindow", &Menu::AttachToWindow)
|
||||
.SetMethod("_popup", &Menu::Popup)
|
||||
.SetMethod("_popupAt", &Menu::PopupAt);
|
||||
}
|
||||
@@ -180,14 +175,14 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
using atom::api::Menu;
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<Menu>(
|
||||
isolate, "Menu", base::Bind(&Menu::Create));
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("Menu", static_cast<v8::Handle<v8::Value>>(constructor));
|
||||
dict.Set("Menu", static_cast<v8::Local<v8::Value>>(constructor));
|
||||
#if defined(OS_MACOSX)
|
||||
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
|
||||
dict.SetMethod("sendActionToFirstResponder",
|
||||
|
||||
@@ -23,7 +23,7 @@ class Menu : public mate::Wrappable,
|
||||
static mate::Wrappable* Create();
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype);
|
||||
v8::Local<v8::ObjectTemplate> prototype);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
// Set the global menubar.
|
||||
@@ -51,7 +51,6 @@ class Menu : public mate::Wrappable,
|
||||
void ExecuteCommand(int command_id, int event_flags) override;
|
||||
void MenuWillShow(ui::SimpleMenuModel* source) override;
|
||||
|
||||
virtual void AttachToWindow(Window* window);
|
||||
virtual void Popup(Window* window) = 0;
|
||||
virtual void PopupAt(Window* window, int x, int y) = 0;
|
||||
|
||||
@@ -88,7 +87,7 @@ class Menu : public mate::Wrappable,
|
||||
base::Callback<bool(int)> is_checked_;
|
||||
base::Callback<bool(int)> is_enabled_;
|
||||
base::Callback<bool(int)> is_visible_;
|
||||
base::Callback<v8::Handle<v8::Value>(int)> get_accelerator_;
|
||||
base::Callback<v8::Local<v8::Value>(int)> get_accelerator_;
|
||||
base::Callback<void(int)> execute_command_;
|
||||
base::Callback<void()> menu_will_show_;
|
||||
|
||||
@@ -99,4 +98,27 @@ class Menu : public mate::Wrappable,
|
||||
|
||||
} // namespace atom
|
||||
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<ui::SimpleMenuModel*> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
ui::SimpleMenuModel** out) {
|
||||
// null would be tranfered to NULL.
|
||||
if (val->IsNull()) {
|
||||
*out = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
atom::api::Menu* menu;
|
||||
if (!Converter<atom::api::Menu*>::FromV8(isolate, val, &menu))
|
||||
return false;
|
||||
*out = menu->model();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
#endif // ATOM_BROWSER_API_ATOM_API_MENU_H_
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "atom/browser/api/atom_api_power_monitor.h"
|
||||
|
||||
#include "atom/browser/browser.h"
|
||||
#include "base/power_monitor/power_monitor.h"
|
||||
#include "base/power_monitor/power_monitor_device_source.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
@@ -38,8 +39,15 @@ void PowerMonitor::OnResume() {
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<PowerMonitor> PowerMonitor::Create(v8::Isolate* isolate) {
|
||||
return CreateHandle(isolate, new PowerMonitor);
|
||||
v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
|
||||
if (!Browser::Get()->is_ready()) {
|
||||
node::ThrowError(
|
||||
isolate,
|
||||
"Cannot initialize \"power-monitor\" module before app is ready");
|
||||
return v8::Null(isolate);
|
||||
}
|
||||
|
||||
return CreateHandle(isolate, new PowerMonitor).ToV8();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
@@ -49,17 +57,16 @@ mate::Handle<PowerMonitor> PowerMonitor::Create(v8::Isolate* isolate) {
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
#if defined(OS_MACOSX)
|
||||
base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
|
||||
#endif
|
||||
|
||||
using atom::api::PowerMonitor;
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Handle<PowerMonitor> power_monitor = PowerMonitor::Create(isolate);
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("powerMonitor", power_monitor);
|
||||
dict.Set("powerMonitor", PowerMonitor::Create(isolate));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace api {
|
||||
class PowerMonitor : public mate::EventEmitter,
|
||||
public base::PowerObserver {
|
||||
public:
|
||||
static mate::Handle<PowerMonitor> Create(v8::Isolate* isolate);
|
||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
||||
|
||||
protected:
|
||||
PowerMonitor();
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<const net::URLRequest*> {
|
||||
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const net::URLRequest* val) {
|
||||
return mate::ObjectTemplateBuilder(isolate)
|
||||
.SetValue("method", val->method())
|
||||
@@ -42,6 +42,14 @@ namespace {
|
||||
|
||||
typedef net::URLRequestJobFactory::ProtocolHandler ProtocolHandler;
|
||||
|
||||
scoped_refptr<base::RefCountedBytes> BufferToRefCountedBytes(
|
||||
v8::Local<v8::Value> buf) {
|
||||
scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes);
|
||||
auto start = reinterpret_cast<const unsigned char*>(node::Buffer::Data(buf));
|
||||
data->data().assign(start, start + node::Buffer::Length(buf));
|
||||
return data;
|
||||
}
|
||||
|
||||
class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||
public:
|
||||
CustomProtocolRequestJob(Protocol* registry,
|
||||
@@ -63,7 +71,7 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||
// Call the JS handler.
|
||||
Protocol::JsProtocolHandler callback =
|
||||
registry_->GetProtocolHandler(request()->url().scheme());
|
||||
v8::Handle<v8::Value> result = callback.Run(request());
|
||||
v8::Local<v8::Value> result = callback.Run(request());
|
||||
|
||||
// Determine the type of the job we are going to create.
|
||||
if (result->IsString()) {
|
||||
@@ -73,7 +81,7 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||
GetWeakPtr(), "text/plain", "UTF-8", data));
|
||||
return;
|
||||
} else if (result->IsObject()) {
|
||||
v8::Handle<v8::Object> obj = result->ToObject();
|
||||
v8::Local<v8::Object> obj = result->ToObject();
|
||||
mate::Dictionary dict(isolate, obj);
|
||||
std::string name = mate::V8ToString(obj->GetConstructorName());
|
||||
if (name == "RequestStringJob") {
|
||||
@@ -88,14 +96,15 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||
return;
|
||||
} else if (name == "RequestBufferJob") {
|
||||
std::string mime_type, encoding;
|
||||
v8::Handle<v8::Value> buffer;
|
||||
v8::Local<v8::Value> buffer;
|
||||
dict.Get("mimeType", &mime_type);
|
||||
dict.Get("encoding", &encoding);
|
||||
dict.Get("data", &buffer);
|
||||
|
||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&AdapterRequestJob::CreateBufferJobAndStart,
|
||||
GetWeakPtr(), mime_type, encoding, buffer->ToObject()));
|
||||
GetWeakPtr(), mime_type, encoding,
|
||||
BufferToRefCountedBytes(buffer)));
|
||||
return;
|
||||
} else if (name == "RequestFileJob") {
|
||||
base::FilePath path;
|
||||
@@ -105,6 +114,15 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||
base::Bind(&AdapterRequestJob::CreateFileJobAndStart,
|
||||
GetWeakPtr(), path));
|
||||
return;
|
||||
} else if (name == "RequestErrorJob") {
|
||||
// Default value net::ERR_NOT_IMPLEMENTED
|
||||
int error = -11;
|
||||
dict.Get("error", &error);
|
||||
|
||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&AdapterRequestJob::CreateErrorJobAndStart,
|
||||
GetWeakPtr(), error));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,28 +192,19 @@ Protocol::JsProtocolHandler Protocol::GetProtocolHandler(
|
||||
mate::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
return mate::ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("registerProtocol",
|
||||
base::Bind(&Protocol::RegisterProtocol,
|
||||
base::Unretained(this)))
|
||||
.SetMethod("unregisterProtocol",
|
||||
base::Bind(&Protocol::UnregisterProtocol,
|
||||
base::Unretained(this)))
|
||||
.SetMethod("isHandledProtocol",
|
||||
base::Bind(&Protocol::IsHandledProtocol,
|
||||
base::Unretained(this)))
|
||||
.SetMethod("interceptProtocol",
|
||||
base::Bind(&Protocol::InterceptProtocol,
|
||||
base::Unretained(this)))
|
||||
.SetMethod("uninterceptProtocol",
|
||||
base::Bind(&Protocol::UninterceptProtocol,
|
||||
base::Unretained(this)));
|
||||
.SetMethod("registerProtocol", &Protocol::RegisterProtocol)
|
||||
.SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol)
|
||||
.SetMethod("isHandledProtocol", &Protocol::IsHandledProtocol)
|
||||
.SetMethod("interceptProtocol", &Protocol::InterceptProtocol)
|
||||
.SetMethod("uninterceptProtocol", &Protocol::UninterceptProtocol);
|
||||
}
|
||||
|
||||
void Protocol::RegisterProtocol(const std::string& scheme,
|
||||
void Protocol::RegisterProtocol(v8::Isolate* isolate,
|
||||
const std::string& scheme,
|
||||
const JsProtocolHandler& callback) {
|
||||
if (ContainsKey(protocol_handlers_, scheme) ||
|
||||
job_factory_->IsHandledProtocol(scheme))
|
||||
return node::ThrowError("The scheme is already registered");
|
||||
return node::ThrowError(isolate, "The scheme is already registered");
|
||||
|
||||
protocol_handlers_[scheme] = callback;
|
||||
BrowserThread::PostTask(BrowserThread::IO,
|
||||
@@ -204,10 +213,11 @@ void Protocol::RegisterProtocol(const std::string& scheme,
|
||||
base::Unretained(this), scheme));
|
||||
}
|
||||
|
||||
void Protocol::UnregisterProtocol(const std::string& scheme) {
|
||||
void Protocol::UnregisterProtocol(v8::Isolate* isolate,
|
||||
const std::string& scheme) {
|
||||
ProtocolHandlersMap::iterator it(protocol_handlers_.find(scheme));
|
||||
if (it == protocol_handlers_.end())
|
||||
return node::ThrowError("The scheme has not been registered");
|
||||
return node::ThrowError(isolate, "The scheme has not been registered");
|
||||
|
||||
protocol_handlers_.erase(it);
|
||||
BrowserThread::PostTask(BrowserThread::IO,
|
||||
@@ -220,13 +230,14 @@ bool Protocol::IsHandledProtocol(const std::string& scheme) {
|
||||
return job_factory_->IsHandledProtocol(scheme);
|
||||
}
|
||||
|
||||
void Protocol::InterceptProtocol(const std::string& scheme,
|
||||
void Protocol::InterceptProtocol(v8::Isolate* isolate,
|
||||
const std::string& scheme,
|
||||
const JsProtocolHandler& callback) {
|
||||
if (!job_factory_->HasProtocolHandler(scheme))
|
||||
return node::ThrowError("Scheme does not exist.");
|
||||
return node::ThrowError(isolate, "Scheme does not exist.");
|
||||
|
||||
if (ContainsKey(protocol_handlers_, scheme))
|
||||
return node::ThrowError("Cannot intercept custom procotols");
|
||||
return node::ThrowError(isolate, "Cannot intercept custom procotols");
|
||||
|
||||
protocol_handlers_[scheme] = callback;
|
||||
BrowserThread::PostTask(BrowserThread::IO,
|
||||
@@ -235,10 +246,11 @@ void Protocol::InterceptProtocol(const std::string& scheme,
|
||||
base::Unretained(this), scheme));
|
||||
}
|
||||
|
||||
void Protocol::UninterceptProtocol(const std::string& scheme) {
|
||||
void Protocol::UninterceptProtocol(v8::Isolate* isolate,
|
||||
const std::string& scheme) {
|
||||
ProtocolHandlersMap::iterator it(protocol_handlers_.find(scheme));
|
||||
if (it == protocol_handlers_.end())
|
||||
return node::ThrowError("The scheme has not been registered");
|
||||
return node::ThrowError(isolate, "The scheme has not been registered");
|
||||
|
||||
protocol_handlers_.erase(it);
|
||||
BrowserThread::PostTask(BrowserThread::IO,
|
||||
@@ -330,8 +342,8 @@ mate::Handle<Protocol> Protocol::Create(v8::Isolate* isolate) {
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("protocol", atom::api::Protocol::Create(isolate));
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace api {
|
||||
|
||||
class Protocol : public mate::EventEmitter {
|
||||
public:
|
||||
typedef base::Callback<v8::Handle<v8::Value>(const net::URLRequest*)>
|
||||
typedef base::Callback<v8::Local<v8::Value>(const net::URLRequest*)>
|
||||
JsProtocolHandler;
|
||||
|
||||
static mate::Handle<Protocol> Create(v8::Isolate* isolate);
|
||||
@@ -43,9 +43,10 @@ class Protocol : public mate::EventEmitter {
|
||||
|
||||
// Register/unregister an networking |scheme| which would be handled by
|
||||
// |callback|.
|
||||
void RegisterProtocol(const std::string& scheme,
|
||||
void RegisterProtocol(v8::Isolate* isolate,
|
||||
const std::string& scheme,
|
||||
const JsProtocolHandler& callback);
|
||||
void UnregisterProtocol(const std::string& scheme);
|
||||
void UnregisterProtocol(v8::Isolate* isolate, const std::string& scheme);
|
||||
|
||||
// Returns whether a scheme has been registered.
|
||||
// FIXME Should accept a callback and be asynchronous so we do not have to use
|
||||
@@ -53,9 +54,10 @@ class Protocol : public mate::EventEmitter {
|
||||
bool IsHandledProtocol(const std::string& scheme);
|
||||
|
||||
// Intercept/unintercept an existing protocol handler.
|
||||
void InterceptProtocol(const std::string& scheme,
|
||||
void InterceptProtocol(v8::Isolate* isolate,
|
||||
const std::string& scheme,
|
||||
const JsProtocolHandler& callback);
|
||||
void UninterceptProtocol(const std::string& scheme);
|
||||
void UninterceptProtocol(v8::Isolate* isolate, const std::string& scheme);
|
||||
|
||||
// The networking related operations have to be done in IO thread.
|
||||
void RegisterProtocolInIO(const std::string& scheme);
|
||||
|
||||
@@ -48,6 +48,7 @@ std::vector<std::string> MetricsToArray(uint32_t metrics) {
|
||||
} // namespace
|
||||
|
||||
Screen::Screen(gfx::Screen* screen) : screen_(screen) {
|
||||
displays_ = screen_->GetAllDisplays();
|
||||
screen_->AddObserver(this);
|
||||
}
|
||||
|
||||
@@ -64,11 +65,6 @@ gfx::Display Screen::GetPrimaryDisplay() {
|
||||
}
|
||||
|
||||
std::vector<gfx::Display> Screen::GetAllDisplays() {
|
||||
// The Screen::GetAllDisplays doesn't update when there is display added or
|
||||
// removed, so we have to manually maintain the displays_ to make it up to
|
||||
// date.
|
||||
if (displays_.size() == 0)
|
||||
displays_ = screen_->GetAllDisplays();
|
||||
return displays_;
|
||||
}
|
||||
|
||||
@@ -115,15 +111,16 @@ mate::ObjectTemplateBuilder Screen::GetObjectTemplateBuilder(
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Handle<v8::Value> Screen::Create(v8::Isolate* isolate) {
|
||||
v8::Local<v8::Value> Screen::Create(v8::Isolate* isolate) {
|
||||
if (!Browser::Get()->is_ready()) {
|
||||
node::ThrowError("Cannot initialize \"screen\" module before app is ready");
|
||||
node::ThrowError(isolate,
|
||||
"Cannot initialize \"screen\" module before app is ready");
|
||||
return v8::Null(isolate);
|
||||
}
|
||||
|
||||
gfx::Screen* screen = gfx::Screen::GetNativeScreen();
|
||||
if (!screen) {
|
||||
node::ThrowError("Failed to get screen information");
|
||||
node::ThrowError(isolate, "Failed to get screen information");
|
||||
return v8::Null(isolate);
|
||||
}
|
||||
|
||||
@@ -136,8 +133,8 @@ v8::Handle<v8::Value> Screen::Create(v8::Isolate* isolate) {
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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.Set("screen", atom::api::Screen::Create(context->GetIsolate()));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace api {
|
||||
class Screen : public mate::EventEmitter,
|
||||
public gfx::DisplayObserver {
|
||||
public:
|
||||
static v8::Handle<v8::Value> Create(v8::Isolate* isolate);
|
||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
||||
|
||||
protected:
|
||||
explicit Screen(gfx::Screen* screen);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "atom/browser/api/atom_api_menu.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/ui/tray_icon.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 "native_mate/constructor.h"
|
||||
@@ -31,16 +32,16 @@ Tray::~Tray() {
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Wrappable* Tray::New(const gfx::Image& image) {
|
||||
mate::Wrappable* Tray::New(v8::Isolate* isolate, const gfx::Image& image) {
|
||||
if (!Browser::Get()->is_ready()) {
|
||||
node::ThrowError("Cannot create Tray before app is ready");
|
||||
node::ThrowError(isolate, "Cannot create Tray before app is ready");
|
||||
return nullptr;
|
||||
}
|
||||
return new Tray(image);
|
||||
}
|
||||
|
||||
void Tray::OnClicked() {
|
||||
Emit("clicked");
|
||||
void Tray::OnClicked(const gfx::Rect& bounds) {
|
||||
Emit("clicked", bounds);
|
||||
}
|
||||
|
||||
void Tray::OnDoubleClicked() {
|
||||
@@ -127,7 +128,7 @@ bool Tray::CheckTrayLife(mate::Arguments* args) {
|
||||
|
||||
// static
|
||||
void Tray::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype) {
|
||||
v8::Local<v8::ObjectTemplate> prototype) {
|
||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||
.SetMethod("destroy", &Tray::Destroy)
|
||||
.SetMethod("setImage", &Tray::SetImage)
|
||||
@@ -146,14 +147,14 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
using atom::api::Tray;
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
v8::Handle<v8::Function> constructor = mate::CreateConstructor<Tray>(
|
||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<Tray>(
|
||||
isolate, "Tray", base::Bind(&Tray::New));
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("Tray", static_cast<v8::Handle<v8::Value>>(constructor));
|
||||
dict.Set("Tray", static_cast<v8::Local<v8::Value>>(constructor));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -31,17 +31,17 @@ class Menu;
|
||||
class Tray : public mate::EventEmitter,
|
||||
public TrayIconObserver {
|
||||
public:
|
||||
static mate::Wrappable* New(const gfx::Image& image);
|
||||
static mate::Wrappable* New(v8::Isolate* isolate, const gfx::Image& image);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype);
|
||||
v8::Local<v8::ObjectTemplate> prototype);
|
||||
|
||||
protected:
|
||||
explicit Tray(const gfx::Image& image);
|
||||
virtual ~Tray();
|
||||
|
||||
// TrayIconObserver:
|
||||
void OnClicked() override;
|
||||
void OnClicked(const gfx::Rect&) override;
|
||||
void OnDoubleClicked() override;
|
||||
void OnBalloonShow() override;
|
||||
void OnBalloonClicked() override;
|
||||
|
||||
@@ -4,82 +4,139 @@
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/web_dialog_helper.h"
|
||||
#include "atom/browser/web_view_manager.h"
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "atom/common/native_mate_converters/image_converter.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/inspectable_web_contents.h"
|
||||
#include "content/public/browser/favicon_status.h"
|
||||
#include "content/public/browser/guest_host.h"
|
||||
#include "content/public/browser/navigation_details.h"
|
||||
#include "content/public/browser/navigation_entry.h"
|
||||
#include "content/public/browser/plugin_service.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
#include "content/public/browser/resource_request_details.h"
|
||||
#include "content/public/browser/service_worker_context.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/browser/site_instance.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "native_mate/callback.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "vendor/brightray/browser/media/media_stream_devices_controller.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<atom::api::SetSizeParams> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
atom::api::SetSizeParams* out) {
|
||||
mate::Dictionary params;
|
||||
if (!ConvertFromV8(isolate, val, ¶ms))
|
||||
return false;
|
||||
bool autosize;
|
||||
if (params.Get("enableAutoSize", &autosize))
|
||||
out->enable_auto_size.reset(new bool(true));
|
||||
gfx::Size size;
|
||||
if (params.Get("min", &size))
|
||||
out->min_size.reset(new gfx::Size(size));
|
||||
if (params.Get("max", &size))
|
||||
out->max_size.reset(new gfx::Size(size));
|
||||
if (params.Get("normal", &size))
|
||||
out->normal_size.reset(new gfx::Size(size));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
namespace {
|
||||
|
||||
const int kDefaultWidth = 300;
|
||||
const int kDefaultHeight = 300;
|
||||
|
||||
v8::Persistent<v8::ObjectTemplate> template_;
|
||||
|
||||
// Get the window that has the |guest| embedded.
|
||||
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
||||
WebViewManager::WebViewInfo info;
|
||||
if (WebViewManager::GetInfoForProcess(guest->GetRenderProcessHost(), &info))
|
||||
return NativeWindow::FromRenderView(
|
||||
info.embedder->GetRenderProcessHost()->GetID(),
|
||||
info.embedder->GetRoutingID());
|
||||
else
|
||||
// The wrapWebContents funtion which is implemented in JavaScript
|
||||
using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||
WrapWebContentsCallback g_wrap_web_contents;
|
||||
|
||||
content::ServiceWorkerContext* GetServiceWorkerContext(
|
||||
const content::WebContents* web_contents) {
|
||||
auto context = web_contents->GetBrowserContext();
|
||||
auto site_instance = web_contents->GetSiteInstance();
|
||||
if (!context || !site_instance)
|
||||
return nullptr;
|
||||
|
||||
auto storage_partition =
|
||||
content::BrowserContext::GetStoragePartition(context, site_instance);
|
||||
if (!storage_partition)
|
||||
return nullptr;
|
||||
|
||||
return storage_partition->GetServiceWorkerContext();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
WebContents::WebContents(brightray::InspectableWebContents* web_contents)
|
||||
: WebContents(web_contents->GetWebContents()) {
|
||||
inspectable_web_contents_ = web_contents;
|
||||
}
|
||||
|
||||
WebContents::WebContents(content::WebContents* web_contents)
|
||||
: content::WebContentsObserver(web_contents),
|
||||
guest_instance_id_(-1),
|
||||
element_instance_id_(-1),
|
||||
: CommonWebContentsDelegate(false),
|
||||
content::WebContentsObserver(web_contents),
|
||||
guest_opaque_(true),
|
||||
guest_sizer_(nullptr),
|
||||
auto_size_enabled_(false) {
|
||||
guest_host_(nullptr),
|
||||
auto_size_enabled_(false),
|
||||
is_full_page_plugin_(false),
|
||||
inspectable_web_contents_(nullptr) {
|
||||
}
|
||||
|
||||
WebContents::WebContents(const mate::Dictionary& options)
|
||||
: guest_instance_id_(-1),
|
||||
element_instance_id_(-1),
|
||||
: CommonWebContentsDelegate(true),
|
||||
guest_opaque_(true),
|
||||
guest_sizer_(nullptr),
|
||||
auto_size_enabled_(false) {
|
||||
options.Get("guestInstanceId", &guest_instance_id_);
|
||||
|
||||
guest_host_(nullptr),
|
||||
auto_size_enabled_(false),
|
||||
is_full_page_plugin_(false) {
|
||||
auto browser_context = AtomBrowserContext::Get();
|
||||
content::SiteInstance* site_instance = content::SiteInstance::CreateForURL(
|
||||
browser_context, GURL("chrome-guest://fake-host"));
|
||||
|
||||
content::WebContents::CreateParams params(browser_context, site_instance);
|
||||
bool is_guest;
|
||||
if (options.Get("isGuest", &is_guest) && is_guest)
|
||||
params.guest_delegate = this;
|
||||
params.guest_delegate = this;
|
||||
auto web_contents = content::WebContents::Create(params);
|
||||
|
||||
storage_.reset(brightray::InspectableWebContents::Create(params));
|
||||
Observe(storage_->GetWebContents());
|
||||
web_contents()->SetDelegate(this);
|
||||
NativeWindow* owner_window = nullptr;
|
||||
WebContents* embedder = nullptr;
|
||||
if (options.Get("embedder", &embedder) && embedder)
|
||||
owner_window = NativeWindow::FromWebContents(embedder->web_contents());
|
||||
|
||||
InitWithWebContents(web_contents, owner_window);
|
||||
inspectable_web_contents_ = managed_web_contents();
|
||||
|
||||
Observe(GetWebContents());
|
||||
}
|
||||
|
||||
WebContents::~WebContents() {
|
||||
@@ -127,47 +184,7 @@ content::WebContents* WebContents::OpenURLFromTab(
|
||||
if (Emit("will-navigate", params.url))
|
||||
return nullptr;
|
||||
|
||||
content::NavigationController::LoadURLParams load_url_params(params.url);
|
||||
load_url_params.referrer = params.referrer;
|
||||
load_url_params.transition_type = params.transition;
|
||||
load_url_params.extra_headers = params.extra_headers;
|
||||
load_url_params.should_replace_current_entry =
|
||||
params.should_replace_current_entry;
|
||||
load_url_params.is_renderer_initiated = params.is_renderer_initiated;
|
||||
load_url_params.transferred_global_request_id =
|
||||
params.transferred_global_request_id;
|
||||
|
||||
web_contents()->GetController().LoadURLWithParams(load_url_params);
|
||||
return web_contents();
|
||||
}
|
||||
|
||||
void WebContents::RunFileChooser(content::WebContents* guest,
|
||||
const content::FileChooserParams& params) {
|
||||
if (!web_dialog_helper_)
|
||||
web_dialog_helper_.reset(new WebDialogHelper(GetWindowFromGuest(guest)));
|
||||
web_dialog_helper_->RunFileChooser(guest, params);
|
||||
}
|
||||
|
||||
void WebContents::EnumerateDirectory(content::WebContents* guest,
|
||||
int request_id,
|
||||
const base::FilePath& path) {
|
||||
if (!web_dialog_helper_)
|
||||
web_dialog_helper_.reset(new WebDialogHelper(GetWindowFromGuest(guest)));
|
||||
web_dialog_helper_->EnumerateDirectory(guest, request_id, path);
|
||||
}
|
||||
|
||||
bool WebContents::CheckMediaAccessPermission(content::WebContents* web_contents,
|
||||
const GURL& security_origin,
|
||||
content::MediaStreamType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebContents::RequestMediaAccessPermission(
|
||||
content::WebContents*,
|
||||
const content::MediaStreamRequest& request,
|
||||
const content::MediaResponseCallback& callback) {
|
||||
brightray::MediaStreamDevicesController controller(request, callback);
|
||||
controller.TakeAction();
|
||||
return CommonWebContentsDelegate::OpenURLFromTab(source, params);
|
||||
}
|
||||
|
||||
void WebContents::HandleKeyboardEvent(
|
||||
@@ -181,6 +198,17 @@ void WebContents::HandleKeyboardEvent(
|
||||
web_contents(), event);
|
||||
}
|
||||
|
||||
void WebContents::EnterFullscreenModeForTab(content::WebContents* source,
|
||||
const GURL& origin) {
|
||||
CommonWebContentsDelegate::EnterFullscreenModeForTab(source, origin);
|
||||
Emit("enter-html-full-screen");
|
||||
}
|
||||
|
||||
void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
||||
CommonWebContentsDelegate::ExitFullscreenModeForTab(source);
|
||||
Emit("leave-html-full-screen");
|
||||
}
|
||||
|
||||
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||
Emit("render-view-deleted",
|
||||
render_view_host->GetProcess()->GetID(),
|
||||
@@ -191,6 +219,25 @@ void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
||||
Emit("crashed");
|
||||
}
|
||||
|
||||
void WebContents::PluginCrashed(const base::FilePath& plugin_path,
|
||||
base::ProcessId plugin_pid) {
|
||||
content::WebPluginInfo info;
|
||||
auto plugin_service = content::PluginService::GetInstance();
|
||||
plugin_service->GetPluginInfoByPath(plugin_path, &info);
|
||||
Emit("plugin-crashed", info.name, info.version);
|
||||
}
|
||||
|
||||
void WebContents::OnGpuProcessCrashed(base::TerminationStatus exit_code) {
|
||||
if (exit_code == base::TERMINATION_STATUS_PROCESS_CRASHED)
|
||||
Emit("gpu-crashed");
|
||||
}
|
||||
|
||||
void WebContents::DocumentLoadedInFrame(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
if (!render_frame_host->GetParent())
|
||||
Emit("dom-ready");
|
||||
}
|
||||
|
||||
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& validated_url) {
|
||||
bool is_main_frame = !render_frame_host->GetParent();
|
||||
@@ -216,23 +263,49 @@ void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
|
||||
Emit("did-fail-load", error_code, error_description);
|
||||
}
|
||||
|
||||
void WebContents::DidStartLoading(content::RenderViewHost* render_view_host) {
|
||||
void WebContents::DidStartLoading() {
|
||||
Emit("did-start-loading");
|
||||
}
|
||||
|
||||
void WebContents::DidStopLoading(content::RenderViewHost* render_view_host) {
|
||||
void WebContents::DidStopLoading() {
|
||||
Emit("did-stop-loading");
|
||||
}
|
||||
|
||||
void WebContents::DidGetResourceResponseStart(
|
||||
const content::ResourceRequestDetails& details) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::Locker locker(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
base::DictionaryValue response_headers;
|
||||
|
||||
net::HttpResponseHeaders* headers = details.headers.get();
|
||||
if (!headers)
|
||||
return;
|
||||
void* iter = nullptr;
|
||||
std::string key;
|
||||
std::string value;
|
||||
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
|
||||
key = base::StringToLowerASCII(key);
|
||||
value = base::StringToLowerASCII(value);
|
||||
if (response_headers.HasKey(key)) {
|
||||
base::ListValue* values = nullptr;
|
||||
if (response_headers.GetList(key, &values))
|
||||
values->AppendString(value);
|
||||
} else {
|
||||
scoped_ptr<base::ListValue> values(new base::ListValue());
|
||||
values->AppendString(value);
|
||||
response_headers.Set(key, values.Pass());
|
||||
}
|
||||
}
|
||||
|
||||
Emit("did-get-response-details",
|
||||
details.socket_address.IsEmpty(),
|
||||
details.url,
|
||||
details.original_url,
|
||||
details.http_response_code,
|
||||
details.method,
|
||||
details.referrer);
|
||||
details.referrer,
|
||||
response_headers);
|
||||
}
|
||||
|
||||
void WebContents::DidGetRedirectForResourceRequest(
|
||||
@@ -253,7 +326,22 @@ void WebContents::DidNavigateMainFrame(
|
||||
|
||||
void WebContents::TitleWasSet(content::NavigationEntry* entry,
|
||||
bool explicit_set) {
|
||||
Emit("page-title-set", entry->GetTitle(), explicit_set);
|
||||
// Back/Forward navigation may have pruned entries.
|
||||
if (entry)
|
||||
Emit("page-title-set", entry->GetTitle(), explicit_set);
|
||||
}
|
||||
|
||||
void WebContents::DidUpdateFaviconURL(
|
||||
const std::vector<content::FaviconURL>& urls) {
|
||||
std::set<GURL> unique_urls;
|
||||
for (auto iter = urls.begin(); iter != urls.end(); ++iter) {
|
||||
if (iter->icon_type != content::FaviconURL::FAVICON)
|
||||
continue;
|
||||
const GURL& url = iter->icon_url;
|
||||
if (url.is_valid())
|
||||
unique_urls.insert(url);
|
||||
}
|
||||
Emit("page-favicon-updated", unique_urls);
|
||||
}
|
||||
|
||||
bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||
@@ -276,15 +364,11 @@ void WebContents::RenderViewReady() {
|
||||
// WebContents::GetRenderWidgetHostView will return the RWHV of an
|
||||
// interstitial page if one is showing at this time. We only want opacity
|
||||
// to apply to web pages.
|
||||
if (guest_opaque_) {
|
||||
web_contents()
|
||||
->GetRenderViewHost()
|
||||
->GetView()
|
||||
->SetBackgroundColorToDefault();
|
||||
} else {
|
||||
web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor(
|
||||
SK_ColorTRANSPARENT);
|
||||
}
|
||||
auto render_view_host_view = web_contents()->GetRenderViewHost()->GetView();
|
||||
if (guest_opaque_)
|
||||
render_view_host_view->SetBackgroundColorToDefault();
|
||||
else
|
||||
render_view_host_view->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||
}
|
||||
|
||||
void WebContents::WebContentsDestroyed() {
|
||||
@@ -294,61 +378,48 @@ void WebContents::WebContentsDestroyed() {
|
||||
}
|
||||
|
||||
void WebContents::NavigationEntryCommitted(
|
||||
const content::LoadCommittedDetails& load_details) {
|
||||
auto entry = web_contents()->GetController().GetLastCommittedEntry();
|
||||
entry->SetVirtualURL(load_details.entry->GetOriginalRequestURL());
|
||||
const content::LoadCommittedDetails& details) {
|
||||
Emit("navigation-entry-commited", details.entry->GetURL(),
|
||||
details.is_in_page, details.did_replace_entry);
|
||||
}
|
||||
|
||||
void WebContents::DidAttach(int guest_proxy_routing_id) {
|
||||
Emit("did-attach");
|
||||
}
|
||||
|
||||
void WebContents::ElementSizeChanged(const gfx::Size& size) {
|
||||
element_size_ = size;
|
||||
|
||||
// Only resize if needed.
|
||||
if (!size.IsEmpty())
|
||||
guest_sizer_->SizeContents(size);
|
||||
}
|
||||
|
||||
content::WebContents* WebContents::GetOwnerWebContents() const {
|
||||
return embedder_web_contents_;
|
||||
}
|
||||
|
||||
void WebContents::GuestSizeChanged(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size) {
|
||||
void WebContents::GuestSizeChanged(const gfx::Size& new_size) {
|
||||
if (!auto_size_enabled_)
|
||||
return;
|
||||
GuestSizeChangedDueToAutoSize(guest_size_, new_size);
|
||||
guest_size_ = new_size;
|
||||
GuestSizeChangedDueToAutoSize(old_size, new_size);
|
||||
}
|
||||
|
||||
void WebContents::RegisterDestructionCallback(
|
||||
const DestructionCallback& callback) {
|
||||
destruction_callback_ = callback;
|
||||
}
|
||||
|
||||
void WebContents::SetGuestSizer(content::GuestSizer* guest_sizer) {
|
||||
guest_sizer_ = guest_sizer;
|
||||
void WebContents::SetGuestHost(content::GuestHost* guest_host) {
|
||||
guest_host_ = guest_host;
|
||||
}
|
||||
|
||||
void WebContents::WillAttach(content::WebContents* embedder_web_contents,
|
||||
int element_instance_id,
|
||||
bool is_full_page_plugin) {
|
||||
embedder_web_contents_ = embedder_web_contents;
|
||||
element_instance_id_ = element_instance_id;
|
||||
is_full_page_plugin_ = is_full_page_plugin;
|
||||
}
|
||||
|
||||
void WebContents::Destroy() {
|
||||
if (storage_) {
|
||||
if (!destruction_callback_.is_null())
|
||||
destruction_callback_.Run();
|
||||
|
||||
if (is_guest() && managed_web_contents()) {
|
||||
// When force destroying the "destroyed" event is not emitted.
|
||||
WebContentsDestroyed();
|
||||
|
||||
// Give the content module an opportunity to perform some cleanup.
|
||||
guest_host_->WillDestroy();
|
||||
guest_host_ = nullptr;
|
||||
|
||||
Observe(nullptr);
|
||||
storage_.reset();
|
||||
DestroyWebContents();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,22 +431,20 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||
content::NavigationController::LoadURLParams params(url);
|
||||
|
||||
GURL http_referrer;
|
||||
if (options.Get("httpreferrer", &http_referrer))
|
||||
if (options.Get("httpReferrer", &http_referrer))
|
||||
params.referrer = content::Referrer(http_referrer.GetAsReferrer(),
|
||||
blink::WebReferrerPolicyDefault);
|
||||
|
||||
std::string user_agent;
|
||||
if (options.Get("userAgent", &user_agent))
|
||||
SetUserAgent(user_agent);
|
||||
|
||||
params.transition_type = ui::PAGE_TRANSITION_TYPED;
|
||||
params.should_clear_history_list = true;
|
||||
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
||||
web_contents()->GetController().LoadURLWithParams(params);
|
||||
}
|
||||
|
||||
GURL WebContents::GetURL() const {
|
||||
auto entry = web_contents()->GetController().GetLastCommittedEntry();
|
||||
if (!entry)
|
||||
return GURL::EmptyGURL();
|
||||
return entry->GetVirtualURL();
|
||||
}
|
||||
|
||||
base::string16 WebContents::GetTitle() const {
|
||||
return web_contents()->GetTitle();
|
||||
}
|
||||
@@ -392,45 +461,22 @@ void WebContents::Stop() {
|
||||
web_contents()->Stop();
|
||||
}
|
||||
|
||||
void WebContents::Reload(const mate::Dictionary& options) {
|
||||
// Navigating to a URL would always restart the renderer process, we want this
|
||||
// because normal reloading will break our node integration.
|
||||
// This is done by AtomBrowserClient::ShouldSwapProcessesForNavigation.
|
||||
LoadURL(GetURL(), options);
|
||||
}
|
||||
|
||||
void WebContents::ReloadIgnoringCache(const mate::Dictionary& options) {
|
||||
// Hack to remove pending entries that ignores cache and treated as a fresh
|
||||
// load.
|
||||
void WebContents::ReloadIgnoringCache() {
|
||||
web_contents()->GetController().ReloadIgnoringCache(false);
|
||||
Reload(options);
|
||||
}
|
||||
|
||||
bool WebContents::CanGoBack() const {
|
||||
return web_contents()->GetController().CanGoBack();
|
||||
}
|
||||
|
||||
bool WebContents::CanGoForward() const {
|
||||
return web_contents()->GetController().CanGoForward();
|
||||
}
|
||||
|
||||
bool WebContents::CanGoToOffset(int offset) const {
|
||||
return web_contents()->GetController().CanGoToOffset(offset);
|
||||
}
|
||||
|
||||
void WebContents::GoBack() {
|
||||
atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce();
|
||||
web_contents()->GetController().GoBack();
|
||||
}
|
||||
|
||||
void WebContents::GoForward() {
|
||||
atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce();
|
||||
web_contents()->GetController().GoForward();
|
||||
}
|
||||
|
||||
void WebContents::GoToIndex(int index) {
|
||||
web_contents()->GetController().GoToIndex(index);
|
||||
}
|
||||
|
||||
void WebContents::GoToOffset(int offset) {
|
||||
atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce();
|
||||
web_contents()->GetController().GoToOffset(offset);
|
||||
}
|
||||
|
||||
@@ -458,17 +504,80 @@ void WebContents::ExecuteJavaScript(const base::string16& code) {
|
||||
web_contents()->GetMainFrame()->ExecuteJavaScript(code);
|
||||
}
|
||||
|
||||
void WebContents::OpenDevTools() {
|
||||
storage_->SetCanDock(false);
|
||||
storage_->ShowDevTools();
|
||||
void WebContents::OpenDevTools(mate::Arguments* args) {
|
||||
if (!inspectable_web_contents())
|
||||
return;
|
||||
bool detach = false;
|
||||
if (is_guest()) {
|
||||
detach = true;
|
||||
} else if (args && args->Length() == 1) {
|
||||
mate::Dictionary options;
|
||||
args->GetNext(&options) && options.Get("detach", &detach);
|
||||
}
|
||||
inspectable_web_contents()->SetCanDock(!detach);
|
||||
inspectable_web_contents()->ShowDevTools();
|
||||
}
|
||||
|
||||
void WebContents::CloseDevTools() {
|
||||
storage_->CloseDevTools();
|
||||
if (!inspectable_web_contents())
|
||||
return;
|
||||
inspectable_web_contents()->CloseDevTools();
|
||||
}
|
||||
|
||||
bool WebContents::IsDevToolsOpened() {
|
||||
return storage_->IsDevToolsViewShowing();
|
||||
if (!inspectable_web_contents())
|
||||
return false;
|
||||
return inspectable_web_contents()->IsDevToolsViewShowing();
|
||||
}
|
||||
|
||||
void WebContents::ToggleDevTools() {
|
||||
if (IsDevToolsOpened())
|
||||
CloseDevTools();
|
||||
else
|
||||
OpenDevTools(nullptr);
|
||||
}
|
||||
|
||||
void WebContents::InspectElement(int x, int y) {
|
||||
if (!inspectable_web_contents())
|
||||
return;
|
||||
OpenDevTools(nullptr);
|
||||
scoped_refptr<content::DevToolsAgentHost> agent(
|
||||
content::DevToolsAgentHost::GetOrCreateFor(web_contents()));
|
||||
agent->InspectElement(x, y);
|
||||
}
|
||||
|
||||
void WebContents::InspectServiceWorker() {
|
||||
if (!inspectable_web_contents())
|
||||
return;
|
||||
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
||||
if (agent_host->GetType() ==
|
||||
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
||||
OpenDevTools(nullptr);
|
||||
inspectable_web_contents()->AttachTo(agent_host);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::HasServiceWorker(
|
||||
const base::Callback<void(bool)>& callback) {
|
||||
auto context = GetServiceWorkerContext(web_contents());
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
context->CheckHasServiceWorker(web_contents()->GetLastCommittedURL(),
|
||||
GURL::EmptyGURL(),
|
||||
callback);
|
||||
}
|
||||
|
||||
void WebContents::UnregisterServiceWorker(
|
||||
const base::Callback<void(bool)>& callback) {
|
||||
auto context = GetServiceWorkerContext(web_contents());
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
context->UnregisterServiceWorker(web_contents()->GetLastCommittedURL(),
|
||||
callback);
|
||||
}
|
||||
|
||||
void WebContents::Undo() {
|
||||
@@ -491,6 +600,10 @@ void WebContents::Paste() {
|
||||
web_contents()->Paste();
|
||||
}
|
||||
|
||||
void WebContents::PasteAndMatchStyle() {
|
||||
web_contents()->PasteAndMatchStyle();
|
||||
}
|
||||
|
||||
void WebContents::Delete() {
|
||||
web_contents()->Delete();
|
||||
}
|
||||
@@ -516,31 +629,57 @@ bool WebContents::SendIPCMessage(const base::string16& channel,
|
||||
return Send(new AtomViewMsg_Message(routing_id(), channel, args));
|
||||
}
|
||||
|
||||
void WebContents::SetAutoSize(bool enabled,
|
||||
const gfx::Size& min_size,
|
||||
const gfx::Size& max_size) {
|
||||
void WebContents::SetSize(const SetSizeParams& params) {
|
||||
bool enable_auto_size =
|
||||
params.enable_auto_size ? *params.enable_auto_size : auto_size_enabled_;
|
||||
gfx::Size min_size = params.min_size ? *params.min_size : min_auto_size_;
|
||||
gfx::Size max_size = params.max_size ? *params.max_size : max_auto_size_;
|
||||
|
||||
if (params.normal_size)
|
||||
normal_size_ = *params.normal_size;
|
||||
|
||||
min_auto_size_ = min_size;
|
||||
min_auto_size_.SetToMin(max_size);
|
||||
max_auto_size_ = max_size;
|
||||
max_auto_size_.SetToMax(min_size);
|
||||
|
||||
enabled &= !min_auto_size_.IsEmpty() && !max_auto_size_.IsEmpty();
|
||||
if (!enabled && !auto_size_enabled_)
|
||||
return;
|
||||
|
||||
auto_size_enabled_ = enabled;
|
||||
|
||||
if (!attached())
|
||||
return;
|
||||
enable_auto_size &= !min_auto_size_.IsEmpty() && !max_auto_size_.IsEmpty();
|
||||
|
||||
content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
|
||||
if (auto_size_enabled_) {
|
||||
if (enable_auto_size) {
|
||||
// Autosize is being enabled.
|
||||
rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
|
||||
normal_size_.SetSize(0, 0);
|
||||
} else {
|
||||
rvh->DisableAutoResize(element_size_);
|
||||
guest_size_ = element_size_;
|
||||
GuestSizeChangedDueToAutoSize(guest_size_, element_size_);
|
||||
// Autosize is being disabled.
|
||||
// Use default width/height if missing from partially defined normal size.
|
||||
if (normal_size_.width() && !normal_size_.height())
|
||||
normal_size_.set_height(GetDefaultSize().height());
|
||||
if (!normal_size_.width() && normal_size_.height())
|
||||
normal_size_.set_width(GetDefaultSize().width());
|
||||
|
||||
gfx::Size new_size;
|
||||
if (!normal_size_.IsEmpty()) {
|
||||
new_size = normal_size_;
|
||||
} else if (!guest_size_.IsEmpty()) {
|
||||
new_size = guest_size_;
|
||||
} else {
|
||||
new_size = GetDefaultSize();
|
||||
}
|
||||
|
||||
if (auto_size_enabled_) {
|
||||
// Autosize was previously enabled.
|
||||
rvh->DisableAutoResize(new_size);
|
||||
GuestSizeChangedDueToAutoSize(guest_size_, new_size);
|
||||
} else {
|
||||
// Autosize was already disabled.
|
||||
guest_host_->SizeContents(new_size);
|
||||
}
|
||||
|
||||
guest_size_ = new_size;
|
||||
}
|
||||
|
||||
auto_size_enabled_ = enable_auto_size;
|
||||
}
|
||||
|
||||
void WebContents::SetAllowTransparency(bool allow) {
|
||||
@@ -562,6 +701,10 @@ void WebContents::SetAllowTransparency(bool allow) {
|
||||
}
|
||||
}
|
||||
|
||||
bool WebContents::IsGuest() const {
|
||||
return is_guest();
|
||||
}
|
||||
|
||||
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
if (template_.IsEmpty())
|
||||
@@ -569,20 +712,14 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||
.SetMethod("destroy", &WebContents::Destroy)
|
||||
.SetMethod("isAlive", &WebContents::IsAlive)
|
||||
.SetMethod("_loadUrl", &WebContents::LoadURL)
|
||||
.SetMethod("getUrl", &WebContents::GetURL)
|
||||
.SetMethod("getTitle", &WebContents::GetTitle)
|
||||
.SetMethod("isLoading", &WebContents::IsLoading)
|
||||
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
|
||||
.SetMethod("stop", &WebContents::Stop)
|
||||
.SetMethod("_reload", &WebContents::Reload)
|
||||
.SetMethod("_stop", &WebContents::Stop)
|
||||
.SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
|
||||
.SetMethod("canGoBack", &WebContents::CanGoBack)
|
||||
.SetMethod("canGoForward", &WebContents::CanGoForward)
|
||||
.SetMethod("canGoToOffset", &WebContents::CanGoToOffset)
|
||||
.SetMethod("goBack", &WebContents::GoBack)
|
||||
.SetMethod("goForward", &WebContents::GoForward)
|
||||
.SetMethod("goToIndex", &WebContents::GoToIndex)
|
||||
.SetMethod("goToOffset", &WebContents::GoToOffset)
|
||||
.SetMethod("_goBack", &WebContents::GoBack)
|
||||
.SetMethod("_goForward", &WebContents::GoForward)
|
||||
.SetMethod("_goToOffset", &WebContents::GoToOffset)
|
||||
.SetMethod("getRoutingId", &WebContents::GetRoutingID)
|
||||
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
||||
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
||||
@@ -592,20 +729,27 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
||||
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
||||
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
|
||||
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
|
||||
.SetMethod("inspectElement", &WebContents::InspectElement)
|
||||
.SetMethod("undo", &WebContents::Undo)
|
||||
.SetMethod("redo", &WebContents::Redo)
|
||||
.SetMethod("cut", &WebContents::Cut)
|
||||
.SetMethod("copy", &WebContents::Copy)
|
||||
.SetMethod("paste", &WebContents::Paste)
|
||||
.SetMethod("pasteAndMatchStyle", &WebContents::PasteAndMatchStyle)
|
||||
.SetMethod("delete", &WebContents::Delete)
|
||||
.SetMethod("selectAll", &WebContents::SelectAll)
|
||||
.SetMethod("unselect", &WebContents::Unselect)
|
||||
.SetMethod("replace", &WebContents::Replace)
|
||||
.SetMethod("replaceMisspelling", &WebContents::ReplaceMisspelling)
|
||||
.SetMethod("_send", &WebContents::SendIPCMessage)
|
||||
.SetMethod("setAutoSize", &WebContents::SetAutoSize)
|
||||
.SetMethod("setSize", &WebContents::SetSize)
|
||||
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
|
||||
.SetMethod("isGuest", &WebContents::is_guest)
|
||||
.SetMethod("isGuest", &WebContents::IsGuest)
|
||||
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
|
||||
.SetMethod("unregisterServiceWorker",
|
||||
&WebContents::UnregisterServiceWorker)
|
||||
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
|
||||
.Build());
|
||||
|
||||
return mate::ObjectTemplateBuilder(
|
||||
@@ -632,16 +776,46 @@ void WebContents::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
||||
new_size.width(), new_size.height());
|
||||
}
|
||||
|
||||
gfx::Size WebContents::GetDefaultSize() const {
|
||||
if (is_full_page_plugin_) {
|
||||
// Full page plugins default to the size of the owner's viewport.
|
||||
return embedder_web_contents_->GetRenderWidgetHostView()
|
||||
->GetVisibleViewportSize();
|
||||
} else {
|
||||
return gfx::Size(kDefaultWidth, kDefaultHeight);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::CreateFrom(
|
||||
v8::Isolate* isolate, brightray::InspectableWebContents* web_contents) {
|
||||
auto handle = mate::CreateHandle(isolate, new WebContents(web_contents));
|
||||
g_wrap_web_contents.Run(handle.ToV8());
|
||||
return handle;
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::CreateFrom(
|
||||
v8::Isolate* isolate, content::WebContents* web_contents) {
|
||||
return mate::CreateHandle(isolate, new WebContents(web_contents));
|
||||
auto handle = mate::CreateHandle(isolate, new WebContents(web_contents));
|
||||
g_wrap_web_contents.Run(handle.ToV8());
|
||||
return handle;
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::Create(
|
||||
v8::Isolate* isolate, const mate::Dictionary& options) {
|
||||
return mate::CreateHandle(isolate, new WebContents(options));
|
||||
auto handle = mate::CreateHandle(isolate, new WebContents(options));
|
||||
g_wrap_web_contents.Run(handle.ToV8());
|
||||
return handle;
|
||||
}
|
||||
|
||||
void SetWrapWebContents(const WrapWebContentsCallback& callback) {
|
||||
g_wrap_web_contents = callback;
|
||||
}
|
||||
|
||||
void ClearWrapWebContents() {
|
||||
g_wrap_web_contents.Reset();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
@@ -651,11 +825,13 @@ mate::Handle<WebContents> WebContents::Create(
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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.SetMethod("create", &atom::api::WebContents::Create);
|
||||
dict.SetMethod("_setWrapWebContents", &atom::api::SetWrapWebContents);
|
||||
dict.SetMethod("_clearWrapWebContents", &atom::api::ClearWrapWebContents);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -6,34 +6,55 @@
|
||||
#define ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
#include "brightray/browser/default_web_contents_delegate.h"
|
||||
#include "atom/browser/common_web_contents_delegate.h"
|
||||
#include "content/public/browser/browser_plugin_guest_delegate.h"
|
||||
#include "content/public/browser/web_contents_delegate.h"
|
||||
#include "content/public/common/favicon_url.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/browser/gpu_data_manager_observer.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
namespace brightray {
|
||||
class InspectableWebContents;
|
||||
}
|
||||
|
||||
namespace mate {
|
||||
class Arguments;
|
||||
class Dictionary;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class WebDialogHelper;
|
||||
|
||||
namespace api {
|
||||
|
||||
// A struct of parameters for SetSize(). The parameters are all declared as
|
||||
// scoped pointers since they are all optional. Null pointers indicate that the
|
||||
// parameter has not been provided, and the last used value should be used. Note
|
||||
// that when |enable_auto_size| is true, providing |normal_size| is not
|
||||
// meaningful. This is because the normal size of the guestview is overridden
|
||||
// whenever autosizing occurs.
|
||||
struct SetSizeParams {
|
||||
SetSizeParams() {}
|
||||
~SetSizeParams() {}
|
||||
|
||||
scoped_ptr<bool> enable_auto_size;
|
||||
scoped_ptr<gfx::Size> min_size;
|
||||
scoped_ptr<gfx::Size> max_size;
|
||||
scoped_ptr<gfx::Size> normal_size;
|
||||
};
|
||||
|
||||
class WebContents : public mate::EventEmitter,
|
||||
public content::BrowserPluginGuestDelegate,
|
||||
public content::WebContentsDelegate,
|
||||
public content::WebContentsObserver {
|
||||
public CommonWebContentsDelegate,
|
||||
public content::WebContentsObserver,
|
||||
public content::GpuDataManagerObserver {
|
||||
public:
|
||||
// Create from an existing WebContents.
|
||||
static mate::Handle<WebContents> CreateFrom(
|
||||
v8::Isolate* isolate, brightray::InspectableWebContents* web_contents);
|
||||
static mate::Handle<WebContents> CreateFrom(
|
||||
v8::Isolate* isolate, content::WebContents* web_contents);
|
||||
|
||||
@@ -44,19 +65,13 @@ class WebContents : public mate::EventEmitter,
|
||||
void Destroy();
|
||||
bool IsAlive() const;
|
||||
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
||||
GURL GetURL() const;
|
||||
base::string16 GetTitle() const;
|
||||
bool IsLoading() const;
|
||||
bool IsWaitingForResponse() const;
|
||||
void Stop();
|
||||
void Reload(const mate::Dictionary& options);
|
||||
void ReloadIgnoringCache(const mate::Dictionary& options);
|
||||
bool CanGoBack() const;
|
||||
bool CanGoForward() const;
|
||||
bool CanGoToOffset(int offset) const;
|
||||
void ReloadIgnoringCache();
|
||||
void GoBack();
|
||||
void GoForward();
|
||||
void GoToIndex(int index);
|
||||
void GoToOffset(int offset);
|
||||
int GetRoutingID() const;
|
||||
int GetProcessID() const;
|
||||
@@ -64,9 +79,14 @@ class WebContents : public mate::EventEmitter,
|
||||
void SetUserAgent(const std::string& user_agent);
|
||||
void InsertCSS(const std::string& css);
|
||||
void ExecuteJavaScript(const base::string16& code);
|
||||
void OpenDevTools();
|
||||
void OpenDevTools(mate::Arguments* args);
|
||||
void CloseDevTools();
|
||||
bool IsDevToolsOpened();
|
||||
void ToggleDevTools();
|
||||
void InspectElement(int x, int y);
|
||||
void InspectServiceWorker();
|
||||
void HasServiceWorker(const base::Callback<void(bool)>&);
|
||||
void UnregisterServiceWorker(const base::Callback<void(bool)>&);
|
||||
|
||||
// Editing commands.
|
||||
void Undo();
|
||||
@@ -74,6 +94,7 @@ class WebContents : public mate::EventEmitter,
|
||||
void Cut();
|
||||
void Copy();
|
||||
void Paste();
|
||||
void PasteAndMatchStyle();
|
||||
void Delete();
|
||||
void SelectAll();
|
||||
void Unselect();
|
||||
@@ -84,25 +105,26 @@ class WebContents : public mate::EventEmitter,
|
||||
bool SendIPCMessage(const base::string16& channel,
|
||||
const base::ListValue& args);
|
||||
|
||||
// Toggles autosize mode for corresponding <webview>.
|
||||
void SetAutoSize(bool enabled,
|
||||
const gfx::Size& min_size,
|
||||
const gfx::Size& max_size);
|
||||
// Used to toggle autosize mode for this GuestView, and set both the automatic
|
||||
// and normal sizes.
|
||||
void SetSize(const SetSizeParams& params);
|
||||
|
||||
// Sets the transparency of the guest.
|
||||
void SetAllowTransparency(bool allow);
|
||||
|
||||
// Returns whether this is a guest view.
|
||||
bool is_guest() const { return guest_instance_id_ != -1; }
|
||||
bool IsGuest() const;
|
||||
|
||||
// Returns whether this guest has an associated embedder.
|
||||
bool attached() const { return !!embedder_web_contents_; }
|
||||
|
||||
content::WebContents* web_contents() const {
|
||||
return content::WebContentsObserver::web_contents();
|
||||
// Returns the current InspectableWebContents object, nullptr will be returned
|
||||
// if current WebContents can not beinspected, e.g. it is the devtools.
|
||||
brightray::InspectableWebContents* inspectable_web_contents() const {
|
||||
return inspectable_web_contents_;
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit WebContents(brightray::InspectableWebContents* web_contents);
|
||||
explicit WebContents(content::WebContents* web_contents);
|
||||
explicit WebContents(const mate::Dictionary& options);
|
||||
~WebContents();
|
||||
@@ -130,25 +152,18 @@ class WebContents : public mate::EventEmitter,
|
||||
content::WebContents* OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) override;
|
||||
void RunFileChooser(content::WebContents* web_contents,
|
||||
const content::FileChooserParams& params) override;
|
||||
void EnumerateDirectory(content::WebContents* web_contents,
|
||||
int request_id,
|
||||
const base::FilePath& path) override;
|
||||
bool CheckMediaAccessPermission(content::WebContents* web_contents,
|
||||
const GURL& security_origin,
|
||||
content::MediaStreamType type) override;
|
||||
void RequestMediaAccessPermission(
|
||||
content::WebContents*,
|
||||
const content::MediaStreamRequest&,
|
||||
const content::MediaResponseCallback&) override;
|
||||
void HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
void EnterFullscreenModeForTab(content::WebContents* source,
|
||||
const GURL& origin) override;
|
||||
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void RenderViewDeleted(content::RenderViewHost*) override;
|
||||
void RenderProcessGone(base::TerminationStatus status) override;
|
||||
void DocumentLoadedInFrame(
|
||||
content::RenderFrameHost* render_frame_host) override;
|
||||
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& validated_url) override;
|
||||
void DidFailLoad(content::RenderFrameHost* render_frame_host,
|
||||
@@ -159,8 +174,8 @@ class WebContents : public mate::EventEmitter,
|
||||
const GURL& validated_url,
|
||||
int error_code,
|
||||
const base::string16& error_description) override;
|
||||
void DidStartLoading(content::RenderViewHost* render_view_host) override;
|
||||
void DidStopLoading(content::RenderViewHost* render_view_host) override;
|
||||
void DidStartLoading() override;
|
||||
void DidStopLoading() override;
|
||||
void DidGetResourceResponseStart(
|
||||
const content::ResourceRequestDetails& details) override;
|
||||
void DidGetRedirectForResourceRequest(
|
||||
@@ -175,19 +190,23 @@ class WebContents : public mate::EventEmitter,
|
||||
void NavigationEntryCommitted(
|
||||
const content::LoadCommittedDetails& load_details) override;
|
||||
void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
|
||||
void DidUpdateFaviconURL(
|
||||
const std::vector<content::FaviconURL>& urls) override;
|
||||
void PluginCrashed(const base::FilePath& plugin_path,
|
||||
base::ProcessId plugin_pid) override;
|
||||
|
||||
// content::BrowserPluginGuestDelegate:
|
||||
void DidAttach(int guest_proxy_routing_id) final;
|
||||
void ElementSizeChanged(const gfx::Size& size) final;
|
||||
content::WebContents* GetOwnerWebContents() const final;
|
||||
void GuestSizeChanged(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size) final;
|
||||
void RegisterDestructionCallback(const DestructionCallback& callback) final;
|
||||
void SetGuestSizer(content::GuestSizer* guest_sizer) final;
|
||||
void GuestSizeChanged(const gfx::Size& new_size) final;
|
||||
void SetGuestHost(content::GuestHost* guest_host) final;
|
||||
void WillAttach(content::WebContents* embedder_web_contents,
|
||||
int element_instance_id,
|
||||
bool is_full_page_plugin) final;
|
||||
|
||||
// content::GpuDataManagerObserver:
|
||||
void OnGpuProcessCrashed(base::TerminationStatus exit_code) override;
|
||||
|
||||
private:
|
||||
// Called when received a message from renderer.
|
||||
void OnRendererMessage(const base::string16& channel,
|
||||
@@ -198,26 +217,20 @@ class WebContents : public mate::EventEmitter,
|
||||
const base::ListValue& args,
|
||||
IPC::Message* message);
|
||||
|
||||
// This method is invoked when the contents auto-resized to give the container
|
||||
// an opportunity to match it if it wishes.
|
||||
//
|
||||
// This gives the derived class an opportunity to inform its container element
|
||||
// or perform other actions.
|
||||
void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size);
|
||||
|
||||
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
||||
|
||||
// Unique ID for a guest WebContents.
|
||||
int guest_instance_id_;
|
||||
|
||||
// |element_instance_id_| is an identifer that's unique to a particular
|
||||
// element.
|
||||
int element_instance_id_;
|
||||
|
||||
DestructionCallback destruction_callback_;
|
||||
// Returns the default size of the guestview.
|
||||
gfx::Size GetDefaultSize() const;
|
||||
|
||||
// Stores whether the contents of the guest can be transparent.
|
||||
bool guest_opaque_;
|
||||
|
||||
// Stores the WebContents that managed by this class.
|
||||
scoped_ptr<brightray::InspectableWebContents> storage_;
|
||||
|
||||
// The WebContents that attaches this guest view.
|
||||
content::WebContents* embedder_web_contents_;
|
||||
|
||||
@@ -228,8 +241,8 @@ class WebContents : public mate::EventEmitter,
|
||||
// element may not match the size of the guest.
|
||||
gfx::Size guest_size_;
|
||||
|
||||
// A pointer to the guest_sizer.
|
||||
content::GuestSizer* guest_sizer_;
|
||||
// A pointer to the guest_host.
|
||||
content::GuestHost* guest_host_;
|
||||
|
||||
// Indicates whether autosize mode is enabled or not.
|
||||
bool auto_size_enabled_;
|
||||
@@ -240,6 +253,16 @@ class WebContents : public mate::EventEmitter,
|
||||
// The minimum size constraints of the container element in autosize mode.
|
||||
gfx::Size min_auto_size_;
|
||||
|
||||
// The size that will be used when autosize mode is disabled.
|
||||
gfx::Size normal_size_;
|
||||
|
||||
// Whether the guest view is inside a plugin document.
|
||||
bool is_full_page_plugin_;
|
||||
|
||||
// Current InspectableWebContents object, can be nullptr for WebContents of
|
||||
// devtools. It is a weak reference.
|
||||
brightray::InspectableWebContents* inspectable_web_contents_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<content::WebContents*> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
content::WebContents** out) {
|
||||
atom::api::WebContents* contents;
|
||||
if (!Converter<atom::api::WebContents*>::FromV8(isolate, val, &contents))
|
||||
@@ -27,7 +27,7 @@ struct Converter<content::WebContents*> {
|
||||
|
||||
template<>
|
||||
struct Converter<atom::WebViewManager::WebViewInfo> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
atom::WebViewManager::WebViewInfo* out) {
|
||||
Dictionary options;
|
||||
if (!ConvertFromV8(isolate, val, &options))
|
||||
@@ -81,8 +81,8 @@ void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {
|
||||
manager->RemoveGuest(guest_instance_id);
|
||||
}
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("addGuest", &AddGuest);
|
||||
dict.SetMethod("removeGuest", &RemoveGuest);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "atom/browser/api/atom_api_window.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_menu.h"
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "native_mate/callback.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
@@ -31,7 +33,7 @@ namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<PrintSettings> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
PrintSettings* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
@@ -123,6 +125,18 @@ void Window::OnWindowRestore() {
|
||||
Emit("restore");
|
||||
}
|
||||
|
||||
void Window::OnWindowResize() {
|
||||
Emit("resize");
|
||||
}
|
||||
|
||||
void Window::OnWindowMove() {
|
||||
Emit("move");
|
||||
}
|
||||
|
||||
void Window::OnWindowMoved() {
|
||||
Emit("moved");
|
||||
}
|
||||
|
||||
void Window::OnWindowEnterFullScreen() {
|
||||
Emit("enter-full-screen");
|
||||
}
|
||||
@@ -131,6 +145,14 @@ void Window::OnWindowLeaveFullScreen() {
|
||||
Emit("leave-full-screen");
|
||||
}
|
||||
|
||||
void Window::OnWindowEnterHtmlFullScreen() {
|
||||
Emit("enter-html-full-screen");
|
||||
}
|
||||
|
||||
void Window::OnWindowLeaveHtmlFullScreen() {
|
||||
Emit("leave-html-full-screen");
|
||||
}
|
||||
|
||||
void Window::OnRendererUnresponsive() {
|
||||
Emit("unresponsive");
|
||||
}
|
||||
@@ -143,11 +165,32 @@ void Window::OnDevToolsFocus() {
|
||||
Emit("devtools-focused");
|
||||
}
|
||||
|
||||
void Window::OnDevToolsOpened() {
|
||||
Emit("devtools-opened");
|
||||
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::Locker locker(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto handle =
|
||||
WebContents::CreateFrom(isolate, window_->GetDevToolsWebContents());
|
||||
devtools_web_contents_.Reset(isolate, handle.ToV8());
|
||||
}
|
||||
|
||||
void Window::OnDevToolsClosed() {
|
||||
Emit("devtools-closed");
|
||||
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::Locker locker(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
devtools_web_contents_.Reset();
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
||||
const mate::Dictionary& options) {
|
||||
if (!Browser::Get()->is_ready()) {
|
||||
node::ThrowError("Cannot create BrowserWindow before app is ready");
|
||||
node::ThrowError(isolate,
|
||||
"Cannot create BrowserWindow before app is ready");
|
||||
return nullptr;
|
||||
}
|
||||
return new Window(options);
|
||||
@@ -222,6 +265,14 @@ bool Window::IsFullscreen() {
|
||||
return window_->IsFullscreen();
|
||||
}
|
||||
|
||||
void Window::SetBounds(const gfx::Rect& bounds) {
|
||||
window_->SetBounds(bounds);
|
||||
}
|
||||
|
||||
gfx::Rect Window::GetBounds() {
|
||||
return window_->GetBounds();
|
||||
}
|
||||
|
||||
void Window::SetSize(int width, int height) {
|
||||
window_->SetSize(gfx::Size(width, height));
|
||||
}
|
||||
@@ -326,22 +377,6 @@ bool Window::IsKiosk() {
|
||||
return window_->IsKiosk();
|
||||
}
|
||||
|
||||
void Window::OpenDevTools(bool can_dock) {
|
||||
window_->OpenDevTools(can_dock);
|
||||
}
|
||||
|
||||
void Window::CloseDevTools() {
|
||||
window_->CloseDevTools();
|
||||
}
|
||||
|
||||
bool Window::IsDevToolsOpened() {
|
||||
return window_->IsDevToolsOpened();
|
||||
}
|
||||
|
||||
void Window::InspectElement(int x, int y) {
|
||||
window_->InspectElement(x, y);
|
||||
}
|
||||
|
||||
void Window::FocusOnWebView() {
|
||||
window_->FocusOnWebView();
|
||||
}
|
||||
@@ -404,6 +439,10 @@ void Window::SetOverlayIcon(const gfx::Image& overlay,
|
||||
window_->SetOverlayIcon(overlay, description);
|
||||
}
|
||||
|
||||
void Window::SetMenu(ui::SimpleMenuModel* menu) {
|
||||
window_->SetMenu(menu);
|
||||
}
|
||||
|
||||
void Window::SetAutoHideMenuBar(bool auto_hide) {
|
||||
window_->SetAutoHideMenuBar(auto_hide);
|
||||
}
|
||||
@@ -434,18 +473,25 @@ bool Window::IsVisibleOnAllWorkspaces() {
|
||||
return window_->IsVisibleOnAllWorkspaces();
|
||||
}
|
||||
|
||||
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
|
||||
return WebContents::CreateFrom(isolate, window_->GetWebContents());
|
||||
v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
|
||||
if (web_contents_.IsEmpty()) {
|
||||
auto handle =
|
||||
WebContents::CreateFrom(isolate, window_->managed_web_contents());
|
||||
web_contents_.Reset(isolate, handle.ToV8());
|
||||
}
|
||||
return v8::Local<v8::Value>::New(isolate, web_contents_);
|
||||
}
|
||||
|
||||
mate::Handle<WebContents> Window::GetDevToolsWebContents(
|
||||
v8::Isolate* isolate) const {
|
||||
return WebContents::CreateFrom(isolate, window_->GetDevToolsWebContents());
|
||||
v8::Local<v8::Value> Window::DevToolsWebContents(v8::Isolate* isolate) {
|
||||
if (devtools_web_contents_.IsEmpty())
|
||||
return v8::Null(isolate);
|
||||
else
|
||||
return v8::Local<v8::Value>::New(isolate, devtools_web_contents_);
|
||||
}
|
||||
|
||||
// static
|
||||
void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype) {
|
||||
v8::Local<v8::ObjectTemplate> prototype) {
|
||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||
.SetMethod("destroy", &Window::Destroy)
|
||||
.SetMethod("close", &Window::Close)
|
||||
@@ -464,6 +510,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("isMinimized", &Window::IsMinimized)
|
||||
.SetMethod("setFullScreen", &Window::SetFullScreen)
|
||||
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
||||
.SetMethod("getBounds", &Window::GetBounds)
|
||||
.SetMethod("setBounds", &Window::SetBounds)
|
||||
.SetMethod("getSize", &Window::GetSize)
|
||||
.SetMethod("setSize", &Window::SetSize)
|
||||
.SetMethod("getContentSize", &Window::GetContentSize)
|
||||
@@ -489,10 +537,6 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
||||
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
||||
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
|
||||
.SetMethod("_openDevTools", &Window::OpenDevTools)
|
||||
.SetMethod("closeDevTools", &Window::CloseDevTools)
|
||||
.SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened)
|
||||
.SetMethod("inspectElement", &Window::InspectElement)
|
||||
.SetMethod("focusOnWebView", &Window::FocusOnWebView)
|
||||
.SetMethod("blurWebView", &Window::BlurWebView)
|
||||
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
|
||||
@@ -500,6 +544,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("print", &Window::Print)
|
||||
.SetMethod("setProgressBar", &Window::SetProgressBar)
|
||||
.SetMethod("setOverlayIcon", &Window::SetOverlayIcon)
|
||||
.SetMethod("_setMenu", &Window::SetMenu)
|
||||
.SetMethod("setAutoHideMenuBar", &Window::SetAutoHideMenuBar)
|
||||
.SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide)
|
||||
.SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility)
|
||||
@@ -512,8 +557,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("showDefinitionForSelection",
|
||||
&Window::ShowDefinitionForSelection)
|
||||
#endif
|
||||
.SetMethod("_getWebContents", &Window::GetWebContents)
|
||||
.SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents);
|
||||
.SetProperty("webContents", &Window::WebContents)
|
||||
.SetProperty("devToolsWebContents", &Window::DevToolsWebContents);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
@@ -523,14 +568,14 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
using atom::api::Window;
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
|
||||
isolate, "BrowserWindow", base::Bind(&Window::New));
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("BrowserWindow", static_cast<v8::Handle<v8::Value>>(constructor));
|
||||
dict.Set("BrowserWindow", static_cast<v8::Local<v8::Value>>(constructor));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -16,11 +16,19 @@
|
||||
|
||||
class GURL;
|
||||
|
||||
namespace gfx {
|
||||
class Rect;
|
||||
}
|
||||
|
||||
namespace mate {
|
||||
class Arguments;
|
||||
class Dictionary;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
class SimpleMenuModel;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class NativeWindow;
|
||||
@@ -36,7 +44,7 @@ class Window : public mate::EventEmitter,
|
||||
const mate::Dictionary& options);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype);
|
||||
v8::Local<v8::ObjectTemplate> prototype);
|
||||
|
||||
NativeWindow* window() const { return window_.get(); }
|
||||
|
||||
@@ -60,11 +68,18 @@ class Window : public mate::EventEmitter,
|
||||
void OnWindowUnmaximize() override;
|
||||
void OnWindowMinimize() override;
|
||||
void OnWindowRestore() override;
|
||||
void OnWindowResize() override;
|
||||
void OnWindowMove() override;
|
||||
void OnWindowMoved() override;
|
||||
void OnWindowEnterFullScreen() override;
|
||||
void OnWindowLeaveFullScreen() override;
|
||||
void OnWindowEnterHtmlFullScreen() override;
|
||||
void OnWindowLeaveHtmlFullScreen() override;
|
||||
void OnRendererUnresponsive() override;
|
||||
void OnRendererResponsive() override;
|
||||
void OnDevToolsFocus() override;
|
||||
void OnDevToolsOpened() override;
|
||||
void OnDevToolsClosed() override;
|
||||
|
||||
private:
|
||||
// APIs for NativeWindow.
|
||||
@@ -85,6 +100,8 @@ class Window : public mate::EventEmitter,
|
||||
bool IsMinimized();
|
||||
void SetFullScreen(bool fullscreen);
|
||||
bool IsFullscreen();
|
||||
void SetBounds(const gfx::Rect& bounds);
|
||||
gfx::Rect GetBounds();
|
||||
void SetSize(int width, int height);
|
||||
std::vector<int> GetSize();
|
||||
void SetContentSize(int width, int height);
|
||||
@@ -106,10 +123,6 @@ class Window : public mate::EventEmitter,
|
||||
void SetSkipTaskbar(bool skip);
|
||||
void SetKiosk(bool kiosk);
|
||||
bool IsKiosk();
|
||||
void OpenDevTools(bool can_dock);
|
||||
void CloseDevTools();
|
||||
bool IsDevToolsOpened();
|
||||
void InspectElement(int x, int y);
|
||||
void FocusOnWebView();
|
||||
void BlurWebView();
|
||||
bool IsWebViewFocused();
|
||||
@@ -122,6 +135,7 @@ class Window : public mate::EventEmitter,
|
||||
void SetProgressBar(double progress);
|
||||
void SetOverlayIcon(const gfx::Image& overlay,
|
||||
const std::string& description);
|
||||
void SetMenu(ui::SimpleMenuModel* menu);
|
||||
void SetAutoHideMenuBar(bool auto_hide);
|
||||
bool IsMenuBarAutoHide();
|
||||
void SetMenuBarVisibility(bool visible);
|
||||
@@ -134,9 +148,11 @@ class Window : public mate::EventEmitter,
|
||||
void SetVisibleOnAllWorkspaces(bool visible);
|
||||
bool IsVisibleOnAllWorkspaces();
|
||||
|
||||
// APIs for WebContents.
|
||||
mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
|
||||
mate::Handle<WebContents> GetDevToolsWebContents(v8::Isolate* isolate) const;
|
||||
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> DevToolsWebContents(v8::Isolate* isolate);
|
||||
|
||||
v8::Global<v8::Value> web_contents_;
|
||||
v8::Global<v8::Value> devtools_web_contents_;
|
||||
|
||||
scoped_ptr<NativeWindow> window_;
|
||||
|
||||
@@ -152,7 +168,7 @@ namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<atom::NativeWindow*> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
atom::NativeWindow** out) {
|
||||
// null would be tranfered to NULL.
|
||||
if (val->IsNull()) {
|
||||
|
||||
@@ -43,13 +43,13 @@ bool EventEmitter::CallEmit(v8::Isolate* isolate,
|
||||
content::WebContents* sender,
|
||||
IPC::Message* message,
|
||||
ValueArray args) {
|
||||
v8::Handle<v8::Object> event;
|
||||
v8::Local<v8::Object> event;
|
||||
bool use_native_event = sender && message;
|
||||
|
||||
if (use_native_event) {
|
||||
mate::Handle<mate::Event> native_event = mate::Event::Create(isolate);
|
||||
native_event->SetSenderAndMessage(sender, message);
|
||||
event = v8::Handle<v8::Object>::Cast(native_event.ToV8());
|
||||
event = v8::Local<v8::Object>::Cast(native_event.ToV8());
|
||||
} else {
|
||||
event = CreateEventObject(isolate);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace mate {
|
||||
// Provide helperers to emit event in JavaScript.
|
||||
class EventEmitter : public Wrappable {
|
||||
public:
|
||||
typedef std::vector<v8::Handle<v8::Value>> ValueArray;
|
||||
typedef std::vector<v8::Local<v8::Value>> ValueArray;
|
||||
|
||||
protected:
|
||||
EventEmitter();
|
||||
|
||||
@@ -2,7 +2,6 @@ EventEmitter = require('events').EventEmitter
|
||||
IDWeakMap = require 'id-weak-map'
|
||||
app = require 'app'
|
||||
ipc = require 'ipc'
|
||||
wrapWebContents = require('web-contents').wrap
|
||||
|
||||
BrowserWindow = process.atomBinding('window').BrowserWindow
|
||||
BrowserWindow::__proto__ = EventEmitter.prototype
|
||||
@@ -16,10 +15,6 @@ BrowserWindow::_init = ->
|
||||
menu = app.getApplicationMenu()
|
||||
@setMenu menu if menu?
|
||||
|
||||
@webContents = @getWebContents()
|
||||
@devToolsWebContents = null
|
||||
@webContents.once 'destroyed', => @webContents = null
|
||||
|
||||
# Remember the window ID.
|
||||
Object.defineProperty this, 'id',
|
||||
value: BrowserWindow.windows.add(this)
|
||||
@@ -40,35 +35,11 @@ BrowserWindow::_init = ->
|
||||
@once 'closed', =>
|
||||
BrowserWindow.windows.remove @id if BrowserWindow.windows.has @id
|
||||
|
||||
BrowserWindow::openDevTools = (options={}) ->
|
||||
options.detach ?= false
|
||||
@_openDevTools !options.detach
|
||||
|
||||
# Force devToolsWebContents to be created.
|
||||
@devToolsWebContents = @getDevToolsWebContents()
|
||||
@devToolsWebContents.once 'destroyed', => @devToolsWebContents = null
|
||||
|
||||
# Emit devtools events.
|
||||
@devToolsWebContents.once 'did-finish-load', => @emit 'devtools-opened'
|
||||
@devToolsWebContents.once 'destroyed', => @emit 'devtools-closed'
|
||||
|
||||
BrowserWindow::toggleDevTools = ->
|
||||
if @isDevToolsOpened() then @closeDevTools() else @openDevTools()
|
||||
|
||||
BrowserWindow::getWebContents = ->
|
||||
wrapWebContents @_getWebContents()
|
||||
|
||||
BrowserWindow::getDevToolsWebContents = ->
|
||||
wrapWebContents @_getDevToolsWebContents()
|
||||
|
||||
BrowserWindow::setMenu = (menu) ->
|
||||
if process.platform is 'darwin'
|
||||
throw new Error('BrowserWindow.setMenu is not available on OS X')
|
||||
|
||||
throw new TypeError('Invalid menu') unless menu?.constructor?.name is 'Menu'
|
||||
throw new TypeError('Invalid menu') unless menu is null or menu?.constructor?.name is 'Menu'
|
||||
|
||||
@menu = menu # Keep a reference of menu in case of GC.
|
||||
@menu.attachToWindow this
|
||||
@_setMenu menu
|
||||
|
||||
BrowserWindow.getAllWindows = ->
|
||||
windows = BrowserWindow.windows
|
||||
@@ -80,11 +51,11 @@ BrowserWindow.getFocusedWindow = ->
|
||||
|
||||
BrowserWindow.fromWebContents = (webContents) ->
|
||||
windows = BrowserWindow.getAllWindows()
|
||||
return window for window in windows when webContents.equal window.webContents
|
||||
return window for window in windows when window.webContents?.equal webContents
|
||||
|
||||
BrowserWindow.fromDevToolsWebContents = (webContents) ->
|
||||
windows = BrowserWindow.getAllWindows()
|
||||
return window for window in windows when webContents.equal window.devToolsWebContents
|
||||
return window for window in windows when window.devToolsWebContents?.equal webContents
|
||||
|
||||
BrowserWindow.fromId = (id) ->
|
||||
BrowserWindow.windows.get id
|
||||
@@ -105,7 +76,12 @@ BrowserWindow::stop = -> @webContents.stop()
|
||||
BrowserWindow::getRoutingId = -> @webContents.getRoutingId()
|
||||
BrowserWindow::getProcessId = -> @webContents.getProcessId()
|
||||
BrowserWindow::isCrashed = -> @webContents.isCrashed()
|
||||
BrowserWindow::executeJavaScriptInDevTools = (code) ->
|
||||
@devToolsWebContents.executeJavaScript code
|
||||
BrowserWindow::executeJavaScriptInDevTools = (code) -> @devToolsWebContents?.executeJavaScript code
|
||||
BrowserWindow::openDevTools = -> @webContents.openDevTools.apply @webContents, arguments
|
||||
BrowserWindow::closeDevTools = -> @webContents.closeDevTools()
|
||||
BrowserWindow::isDevToolsOpened = -> @webContents.isDevToolsOpened()
|
||||
BrowserWindow::toggleDevTools = -> @webContents.toggleDevTools()
|
||||
BrowserWindow::inspectElement = -> @webContents.inspectElement.apply @webContents, arguments
|
||||
BrowserWindow::inspectServiceWorker = -> @webContents.inspectServiceWorker()
|
||||
|
||||
module.exports = BrowserWindow
|
||||
|
||||
@@ -130,10 +130,11 @@ Menu::_callMenuWillShow = ->
|
||||
|
||||
applicationMenu = null
|
||||
Menu.setApplicationMenu = (menu) ->
|
||||
throw new TypeError('Invalid menu') unless menu?.constructor is Menu
|
||||
throw new TypeError('Invalid menu') unless menu is null or menu.constructor is Menu
|
||||
applicationMenu = menu # Keep a reference.
|
||||
|
||||
if process.platform is 'darwin'
|
||||
return if menu is null
|
||||
menu._callMenuWillShow()
|
||||
bindings.setApplicationMenu menu
|
||||
else
|
||||
|
||||
116
atom/browser/api/lib/navigation-controller.coffee
Normal file
116
atom/browser/api/lib/navigation-controller.coffee
Normal file
@@ -0,0 +1,116 @@
|
||||
ipc = require 'ipc'
|
||||
|
||||
# The history operation in renderer is redirected to browser.
|
||||
ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) ->
|
||||
event.sender[method] args...
|
||||
|
||||
ipc.on 'ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', (event, method, args...) ->
|
||||
event.returnValue = event.sender[method] args...
|
||||
|
||||
# JavaScript implementation of Chromium's NavigationController.
|
||||
# Instead of relying on Chromium for history control, we compeletely do history
|
||||
# control on user land, and only rely on WebContents.loadUrl for navigation.
|
||||
# This helps us avoid Chromium's various optimizations so we can ensure renderer
|
||||
# process is restarted everytime.
|
||||
class NavigationController
|
||||
constructor: (@webContents) ->
|
||||
@clearHistory()
|
||||
|
||||
@webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) =>
|
||||
if @inPageIndex > -1 and not inPage
|
||||
# Navigated to a new page, clear in-page mark.
|
||||
@inPageIndex = -1
|
||||
else if @inPageIndex is -1 and inPage
|
||||
# Started in-page navigations.
|
||||
@inPageIndex = @currentIndex
|
||||
|
||||
if @pendingIndex >= 0 # Go to index.
|
||||
@currentIndex = @pendingIndex
|
||||
@pendingIndex = -1
|
||||
@history[@currentIndex] = url
|
||||
else if replaceEntry # Non-user initialized navigation.
|
||||
@history[@currentIndex] = url
|
||||
else # Normal navigation.
|
||||
@history = @history.slice 0, @currentIndex + 1 # Clear history.
|
||||
currentEntry = @history[@currentIndex]
|
||||
if currentEntry?.url isnt url
|
||||
@currentIndex++
|
||||
@history.push url
|
||||
|
||||
loadUrl: (url, options={}) ->
|
||||
@pendingIndex = -1
|
||||
@webContents._loadUrl url, options
|
||||
|
||||
getUrl: ->
|
||||
if @currentIndex is -1
|
||||
''
|
||||
else
|
||||
@history[@currentIndex]
|
||||
|
||||
stop: ->
|
||||
@pendingIndex = -1
|
||||
@webContents._stop()
|
||||
|
||||
reload: ->
|
||||
@pendingIndex = @currentIndex
|
||||
@webContents._loadUrl @getUrl(), {}
|
||||
|
||||
reloadIgnoringCache: ->
|
||||
@webContents._reloadIgnoringCache() # Rely on WebContents to clear cache.
|
||||
@reload()
|
||||
|
||||
canGoBack: ->
|
||||
@getActiveIndex() > 0
|
||||
|
||||
canGoForward: ->
|
||||
@getActiveIndex() < @history.length - 1
|
||||
|
||||
canGoToIndex: (index) ->
|
||||
index >=0 and index < @history.length
|
||||
|
||||
canGoToOffset: (offset) ->
|
||||
@canGoToIndex @currentIndex + offset
|
||||
|
||||
clearHistory: ->
|
||||
@history = []
|
||||
@currentIndex = -1
|
||||
@pendingIndex = -1
|
||||
@inPageIndex = -1
|
||||
|
||||
goBack: ->
|
||||
return unless @canGoBack()
|
||||
@pendingIndex = @getActiveIndex() - 1
|
||||
if @inPageIndex > -1 and @pendingIndex >= @inPageIndex
|
||||
@webContents._goBack()
|
||||
else
|
||||
@webContents._loadUrl @history[@pendingIndex], {}
|
||||
|
||||
goForward: ->
|
||||
return unless @canGoForward()
|
||||
@pendingIndex = @getActiveIndex() + 1
|
||||
if @inPageIndex > -1 and @pendingIndex >= @inPageIndex
|
||||
@webContents._goForward()
|
||||
else
|
||||
@webContents._loadUrl @history[@pendingIndex], {}
|
||||
|
||||
goToIndex: (index) ->
|
||||
return unless @canGoToIndex index
|
||||
@pendingIndex = index
|
||||
@webContents._loadUrl @history[@pendingIndex], {}
|
||||
|
||||
goToOffset: (offset) ->
|
||||
return unless @canGoToOffset offset
|
||||
pendingIndex = @currentIndex + offset
|
||||
if @inPageIndex > -1 and pendingIndex >= @inPageIndex
|
||||
@pendingIndex = pendingIndex
|
||||
@webContents._goToOffset offset
|
||||
else
|
||||
@goToIndex pendingIndex
|
||||
|
||||
getActiveIndex: ->
|
||||
if @pendingIndex is -1 then @currentIndex else @pendingIndex
|
||||
|
||||
length: ->
|
||||
@history.length
|
||||
|
||||
module.exports = NavigationController
|
||||
@@ -30,4 +30,8 @@ protocol.RequestFileJob =
|
||||
class RequestFileJob
|
||||
constructor: (@path) ->
|
||||
|
||||
protocol.RequestErrorJob =
|
||||
class RequestErrorJob
|
||||
constructor: (@error) ->
|
||||
|
||||
module.exports = protocol
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
EventEmitter = require('events').EventEmitter
|
||||
NavigationController = require './navigation-controller'
|
||||
binding = process.atomBinding 'web_contents'
|
||||
ipc = require 'ipc'
|
||||
|
||||
module.exports.wrap = (webContents) ->
|
||||
return null unless webContents.isAlive()
|
||||
|
||||
wrapWebContents = (webContents) ->
|
||||
# webContents is an EventEmitter.
|
||||
webContents.__proto__ = EventEmitter.prototype
|
||||
|
||||
@@ -26,10 +25,11 @@ module.exports.wrap = (webContents) ->
|
||||
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
|
||||
webContents.equal = (other) -> @getId() is other.getId()
|
||||
|
||||
# Provide a default parameter for |urlOptions|.
|
||||
webContents.loadUrl = (url, urlOptions={}) -> @_loadUrl url, urlOptions
|
||||
webContents.reload = (urlOptions={}) -> @_reload urlOptions
|
||||
webContents.reloadIgnoringCache = (urlOptions={}) -> @_reloadIgnoringCache urlOptions
|
||||
# The navigation controller.
|
||||
controller = new NavigationController(webContents)
|
||||
for name, method of NavigationController.prototype when method instanceof Function
|
||||
do (name, method) ->
|
||||
webContents[name] = -> method.apply controller, arguments
|
||||
|
||||
# Translate |disposition| to string for 'new-window' event.
|
||||
webContents.on '-new-window', (args..., disposition) ->
|
||||
@@ -60,5 +60,8 @@ module.exports.wrap = (webContents) ->
|
||||
|
||||
webContents
|
||||
|
||||
binding._setWrapWebContents wrapWebContents
|
||||
process.once 'exit', binding._clearWrapWebContents
|
||||
|
||||
module.exports.create = (options={}) ->
|
||||
@wrap binding.create(options)
|
||||
binding.create(options)
|
||||
|
||||
@@ -7,49 +7,95 @@
|
||||
#include "atom/browser/atom_access_token_store.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
||||
#include "atom/browser/atom_quota_permission_context.h"
|
||||
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/web_view_manager.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "chrome/browser/printing/printing_message_filter.h"
|
||||
#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
|
||||
#include "chrome/browser/speech/tts_message_filter.h"
|
||||
#include "content/public/browser/browser_ppapi_host.h"
|
||||
#include "content/public/browser/client_certificate_delegate.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/resource_dispatcher_host.h"
|
||||
#include "content/public/browser/site_instance.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "net/cert/x509_certificate.h"
|
||||
#include "net/ssl/ssl_cert_request_info.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
struct FindByProcessId {
|
||||
explicit FindByProcessId(int child_process_id)
|
||||
: child_process_id_(child_process_id) {
|
||||
}
|
||||
// The default routing id of WebContents.
|
||||
// In Electron each RenderProcessHost only has one WebContents, so this ID is
|
||||
// same for every WebContents.
|
||||
int kDefaultRoutingID = 2;
|
||||
|
||||
bool operator() (NativeWindow* const window) {
|
||||
content::WebContents* web_contents = window->GetWebContents();
|
||||
if (!web_contents)
|
||||
return false;
|
||||
// Next navigation should not restart renderer process.
|
||||
bool g_suppress_renderer_process_restart = false;
|
||||
|
||||
int id = window->GetWebContents()->GetRenderProcessHost()->GetID();
|
||||
return id == child_process_id_;
|
||||
}
|
||||
|
||||
int child_process_id_;
|
||||
// Find out the owner of the child process according to |process_id|.
|
||||
enum ProcessOwner {
|
||||
OWNER_NATIVE_WINDOW,
|
||||
OWNER_GUEST_WEB_CONTENTS,
|
||||
OWNER_NONE, // it might be devtools though.
|
||||
};
|
||||
ProcessOwner GetProcessOwner(int process_id,
|
||||
NativeWindow** window,
|
||||
WebViewManager::WebViewInfo* info) {
|
||||
auto web_contents = content::WebContents::FromRenderViewHost(
|
||||
content::RenderViewHost::FromID(process_id, kDefaultRoutingID));
|
||||
if (!web_contents)
|
||||
return OWNER_NONE;
|
||||
|
||||
// First search for NativeWindow.
|
||||
for (auto native_window : *WindowList::GetInstance())
|
||||
if (web_contents == native_window->GetWebContents()) {
|
||||
*window = native_window;
|
||||
return OWNER_NATIVE_WINDOW;
|
||||
}
|
||||
|
||||
// Then search for guest WebContents.
|
||||
if (WebViewManager::GetInfoForWebContents(web_contents, info))
|
||||
return OWNER_GUEST_WEB_CONTENTS;
|
||||
|
||||
return OWNER_NONE;
|
||||
}
|
||||
|
||||
scoped_refptr<net::X509Certificate> ImportCertFromFile(
|
||||
const base::FilePath& path) {
|
||||
std::string cert_data;
|
||||
if (!base::ReadFileToString(path, &cert_data))
|
||||
return nullptr;
|
||||
|
||||
net::CertificateList certs =
|
||||
net::X509Certificate::CreateCertificateListFromBytes(
|
||||
cert_data.data(), cert_data.size(),
|
||||
net::X509Certificate::FORMAT_AUTO);
|
||||
|
||||
if (certs.empty())
|
||||
return nullptr;
|
||||
|
||||
return certs[0];
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AtomBrowserClient::AtomBrowserClient()
|
||||
: dying_render_process_(NULL) {
|
||||
// static
|
||||
void AtomBrowserClient::SuppressRendererProcessRestartForOnce() {
|
||||
g_suppress_renderer_process_restart = true;
|
||||
}
|
||||
|
||||
AtomBrowserClient::AtomBrowserClient() {
|
||||
}
|
||||
|
||||
AtomBrowserClient::~AtomBrowserClient() {
|
||||
@@ -71,16 +117,8 @@ content::AccessTokenStore* AtomBrowserClient::CreateAccessTokenStore() {
|
||||
return new AtomAccessTokenStore;
|
||||
}
|
||||
|
||||
void AtomBrowserClient::ResourceDispatcherHostCreated() {
|
||||
resource_dispatcher_delegate_.reset(new AtomResourceDispatcherHostDelegate);
|
||||
content::ResourceDispatcherHost::Get()->SetDelegate(
|
||||
resource_dispatcher_delegate_.get());
|
||||
}
|
||||
|
||||
void AtomBrowserClient::OverrideWebkitPrefs(
|
||||
content::RenderViewHost* render_view_host,
|
||||
const GURL& url,
|
||||
content::WebPreferences* prefs) {
|
||||
content::RenderViewHost* host, content::WebPreferences* prefs) {
|
||||
prefs->javascript_enabled = true;
|
||||
prefs->web_security_enabled = true;
|
||||
prefs->javascript_can_open_windows_automatically = true;
|
||||
@@ -98,88 +136,101 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
||||
prefs->allow_displaying_insecure_content = false;
|
||||
prefs->allow_running_insecure_content = false;
|
||||
|
||||
// Turn off web security for devtools.
|
||||
if (url.SchemeIs("chrome-devtools")) {
|
||||
prefs->web_security_enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Custom preferences of guest page.
|
||||
auto process = render_view_host->GetProcess();
|
||||
auto web_contents = content::WebContents::FromRenderViewHost(host);
|
||||
WebViewManager::WebViewInfo info;
|
||||
if (WebViewManager::GetInfoForProcess(process, &info)) {
|
||||
if (WebViewManager::GetInfoForWebContents(web_contents, &info)) {
|
||||
prefs->web_security_enabled = !info.disable_web_security;
|
||||
return;
|
||||
}
|
||||
|
||||
NativeWindow* window = NativeWindow::FromRenderView(
|
||||
process->GetID(), render_view_host->GetRoutingID());
|
||||
NativeWindow* window = NativeWindow::FromWebContents(web_contents);
|
||||
if (window)
|
||||
window->OverrideWebkitPrefs(url, prefs);
|
||||
}
|
||||
|
||||
bool AtomBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
|
||||
content::SiteInstance* site_instance,
|
||||
const GURL& current_url,
|
||||
const GURL& new_url) {
|
||||
if (site_instance->HasProcess())
|
||||
dying_render_process_ = site_instance->GetProcess();
|
||||
|
||||
// Restart renderer process for all navigations, this relies on a patch to
|
||||
// Chromium: http://git.io/_PaNyg.
|
||||
return true;
|
||||
window->OverrideWebkitPrefs(prefs);
|
||||
}
|
||||
|
||||
std::string AtomBrowserClient::GetApplicationLocale() {
|
||||
return l10n_util::GetApplicationLocale("");
|
||||
}
|
||||
|
||||
void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||
content::BrowserContext* browser_context,
|
||||
content::SiteInstance* current_instance,
|
||||
const GURL& url,
|
||||
content::SiteInstance** new_instance) {
|
||||
if (g_suppress_renderer_process_restart) {
|
||||
g_suppress_renderer_process_restart = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Restart renderer process for all navigations except "javacript:" scheme.
|
||||
if (url.SchemeIs(url::kJavaScriptScheme))
|
||||
return;
|
||||
|
||||
*new_instance = content::SiteInstance::CreateForURL(browser_context, url);
|
||||
}
|
||||
|
||||
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||
base::CommandLine* command_line,
|
||||
int child_process_id) {
|
||||
WindowList* list = WindowList::GetInstance();
|
||||
NativeWindow* window = NULL;
|
||||
int process_id) {
|
||||
std::string process_type = command_line->GetSwitchValueASCII("type");
|
||||
if (process_type != "renderer")
|
||||
return;
|
||||
|
||||
// Find the owner of this child process.
|
||||
WindowList::const_iterator iter = std::find_if(
|
||||
list->begin(), list->end(), FindByProcessId(child_process_id));
|
||||
if (iter != list->end())
|
||||
window = *iter;
|
||||
NativeWindow* window;
|
||||
WebViewManager::WebViewInfo info;
|
||||
ProcessOwner owner = GetProcessOwner(process_id, &window, &info);
|
||||
|
||||
// If the render process is a newly started one, which means the window still
|
||||
// uses the old going-to-be-swapped render process, then we try to find the
|
||||
// window from the swapped render process.
|
||||
if (window == NULL && dying_render_process_ != NULL) {
|
||||
child_process_id = dying_render_process_->GetID();
|
||||
WindowList::const_iterator iter = std::find_if(
|
||||
list->begin(), list->end(), FindByProcessId(child_process_id));
|
||||
if (iter != list->end())
|
||||
window = *iter;
|
||||
if (owner == OWNER_NATIVE_WINDOW) {
|
||||
window->AppendExtraCommandLineSwitches(command_line);
|
||||
} else if (owner == OWNER_GUEST_WEB_CONTENTS) {
|
||||
command_line->AppendSwitchASCII(
|
||||
switches::kGuestInstanceID, base::IntToString(info.guest_instance_id));
|
||||
command_line->AppendSwitchASCII(
|
||||
switches::kNodeIntegration, info.node_integration ? "true" : "false");
|
||||
if (info.plugins)
|
||||
command_line->AppendSwitch(switches::kEnablePlugins);
|
||||
if (!info.preload_script.empty())
|
||||
command_line->AppendSwitchPath(
|
||||
switches::kPreloadScript, info.preload_script);
|
||||
}
|
||||
}
|
||||
|
||||
if (window != NULL) {
|
||||
window->AppendExtraCommandLineSwitches(command_line, child_process_id);
|
||||
void AtomBrowserClient::DidCreatePpapiPlugin(
|
||||
content::BrowserPpapiHost* browser_host) {
|
||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (command_line->HasSwitch(switches::kEnablePlugins))
|
||||
browser_host->GetPpapiHost()->AddHostFactoryFilter(
|
||||
scoped_ptr<ppapi::host::HostFactory>(
|
||||
new chrome::ChromeBrowserPepperHostFactory(browser_host)));
|
||||
}
|
||||
|
||||
content::QuotaPermissionContext*
|
||||
AtomBrowserClient::CreateQuotaPermissionContext() {
|
||||
return new AtomQuotaPermissionContext;
|
||||
}
|
||||
|
||||
void AtomBrowserClient::SelectClientCertificate(
|
||||
content::WebContents* web_contents,
|
||||
net::SSLCertRequestInfo* cert_request_info,
|
||||
scoped_ptr<content::ClientCertificateDelegate> delegate) {
|
||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||
auto cert_path = command_line->GetSwitchValueNative(
|
||||
switches::kClientCertificate);
|
||||
|
||||
// TODO(zcbenz): allow users to select certificate from
|
||||
// client_cert list. Right now defaults to first certificate
|
||||
// in the list.
|
||||
scoped_refptr<net::X509Certificate> certificate;
|
||||
if (cert_path.empty()) {
|
||||
if (!cert_request_info->client_certs.empty())
|
||||
certificate = cert_request_info->client_certs[0];
|
||||
} else {
|
||||
// Append commnad line arguments for guest web view.
|
||||
auto child_process = content::RenderProcessHost::FromID(child_process_id);
|
||||
WebViewManager::WebViewInfo info;
|
||||
if (WebViewManager::GetInfoForProcess(child_process, &info)) {
|
||||
command_line->AppendSwitchASCII(
|
||||
switches::kGuestInstanceID,
|
||||
base::IntToString(info.guest_instance_id));
|
||||
command_line->AppendSwitchASCII(
|
||||
switches::kNodeIntegration,
|
||||
info.node_integration ? "true" : "false");
|
||||
if (info.plugins)
|
||||
command_line->AppendSwitch(switches::kEnablePlugins);
|
||||
if (!info.preload_script.empty())
|
||||
command_line->AppendSwitchPath(
|
||||
switches::kPreloadScript,
|
||||
info.preload_script);
|
||||
}
|
||||
certificate = ImportCertFromFile(base::FilePath(cert_path));
|
||||
}
|
||||
|
||||
dying_render_process_ = NULL;
|
||||
if (certificate.get())
|
||||
delegate->ContinueWithCertificate(certificate.get());
|
||||
}
|
||||
|
||||
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
||||
|
||||
@@ -9,42 +9,52 @@
|
||||
|
||||
#include "brightray/browser/browser_client.h"
|
||||
|
||||
namespace atom {
|
||||
namespace content {
|
||||
class QuotaPermissionContext;
|
||||
class ClientCertificateDelegate;
|
||||
}
|
||||
|
||||
class AtomResourceDispatcherHostDelegate;
|
||||
namespace net {
|
||||
class SSLCertRequestInfo;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserClient : public brightray::BrowserClient {
|
||||
public:
|
||||
AtomBrowserClient();
|
||||
virtual ~AtomBrowserClient();
|
||||
|
||||
// Don't force renderer process to restart for once.
|
||||
static void SuppressRendererProcessRestartForOnce();
|
||||
|
||||
protected:
|
||||
// content::ContentBrowserClient:
|
||||
void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
|
||||
content::SpeechRecognitionManagerDelegate*
|
||||
CreateSpeechRecognitionManagerDelegate() override;
|
||||
content::AccessTokenStore* CreateAccessTokenStore() override;
|
||||
void ResourceDispatcherHostCreated() override;
|
||||
void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
|
||||
const GURL& url,
|
||||
content::WebPreferences* prefs) override;
|
||||
bool ShouldSwapBrowsingInstancesForNavigation(
|
||||
content::SiteInstance* site_instance,
|
||||
const GURL& current_url,
|
||||
const GURL& new_url) override;
|
||||
std::string GetApplicationLocale() override;
|
||||
void OverrideSiteInstanceForNavigation(
|
||||
content::BrowserContext* browser_context,
|
||||
content::SiteInstance* current_instance,
|
||||
const GURL& dest_url,
|
||||
content::SiteInstance** new_instance);
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id) override;
|
||||
void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
|
||||
content::QuotaPermissionContext* CreateQuotaPermissionContext() override;
|
||||
void SelectClientCertificate(
|
||||
content::WebContents* web_contents,
|
||||
net::SSLCertRequestInfo* cert_request_info,
|
||||
scoped_ptr<content::ClientCertificateDelegate> delegate) override;
|
||||
|
||||
private:
|
||||
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||
const content::MainFunctionParams&) override;
|
||||
|
||||
scoped_ptr<AtomResourceDispatcherHostDelegate> resource_dispatcher_delegate_;
|
||||
|
||||
// The render process which would be swapped out soon.
|
||||
content::RenderProcessHost* dying_render_process_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient);
|
||||
};
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
||||
#include "atom/browser/net/http_protocol_handler.h"
|
||||
#include "atom/browser/web_view_manager.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
@@ -15,8 +16,11 @@
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "net/ftp/ftp_network_layer.h"
|
||||
#include "net/url_request/data_protocol_handler.h"
|
||||
#include "net/url_request/ftp_protocol_handler.h"
|
||||
#include "net/url_request/url_request_intercepting_job_factory.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "url/url_constants.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
@@ -59,6 +63,21 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory(
|
||||
url::kFileScheme, new asar::AsarProtocolHandler(
|
||||
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
||||
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kHttpScheme, new HttpProtocolHandler(url::kHttpScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kHttpsScheme, new HttpProtocolHandler(url::kHttpsScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kWsScheme, new HttpProtocolHandler(url::kWsScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kWssScheme, new HttpProtocolHandler(url::kWssScheme));
|
||||
|
||||
auto host_resolver = url_request_context_getter()
|
||||
->GetURLRequestContext()
|
||||
->host_resolver();
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kFtpScheme, new net::FtpProtocolHandler(
|
||||
new net::FtpNetworkLayer(host_resolver)));
|
||||
|
||||
// Set up interceptors in the reverse order.
|
||||
scoped_ptr<net::URLRequestJobFactory> top_job_factory = job_factory.Pass();
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/javascript_environment.h"
|
||||
#include "atom/browser/node_debugger.h"
|
||||
#include "atom/common/api/atom_bindings.h"
|
||||
#include "atom/common/node_bindings.h"
|
||||
#include "base/command_line.h"
|
||||
@@ -60,16 +59,9 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||
|
||||
node_bindings_->Initialize();
|
||||
|
||||
// Support the "--debug" switch.
|
||||
node_debugger_.reset(new NodeDebugger(js_env_->isolate()));
|
||||
|
||||
// Create the global environment.
|
||||
global_env = node_bindings_->CreateEnvironment(js_env_->context());
|
||||
|
||||
// Make sure node can get correct environment when debugging.
|
||||
if (node_debugger_->IsRunning())
|
||||
global_env->AssignToContext(v8::Debug::GetDebugContext());
|
||||
|
||||
// Add atom-shell extended APIs.
|
||||
atom_bindings_->BindTo(js_env_->isolate(), global_env->process_object());
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ class AtomBindings;
|
||||
class Browser;
|
||||
class JavascriptEnvironment;
|
||||
class NodeBindings;
|
||||
class NodeDebugger;
|
||||
|
||||
class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
public:
|
||||
@@ -46,7 +45,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
scoped_ptr<JavascriptEnvironment> js_env_;
|
||||
scoped_ptr<NodeBindings> node_bindings_;
|
||||
scoped_ptr<AtomBindings> atom_bindings_;
|
||||
scoped_ptr<NodeDebugger> node_debugger_;
|
||||
|
||||
base::Timer gc_timer_;
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ void AtomJavaScriptDialogManager::RunBeforeUnloadDialog(
|
||||
const base::string16& message_text,
|
||||
bool is_reload,
|
||||
const DialogClosedCallback& callback) {
|
||||
|
||||
bool prevent_reload = message_text.empty() ||
|
||||
message_text == base::ASCIIToUTF16("false");
|
||||
callback.Run(!prevent_reload, message_text);
|
||||
|
||||
@@ -30,7 +30,7 @@ class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager {
|
||||
const DialogClosedCallback& callback) override;
|
||||
void CancelActiveAndPendingDialogs(
|
||||
content::WebContents* web_contents) override {}
|
||||
void WebContentsDestroyed(content::WebContents* web_contents) override {}
|
||||
void ResetDialogState(content::WebContents* web_contents) override {};
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
24
atom/browser/atom_quota_permission_context.cc
Normal file
24
atom/browser/atom_quota_permission_context.cc
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/atom_quota_permission_context.h"
|
||||
|
||||
#include "storage/common/quota/quota_types.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
AtomQuotaPermissionContext::AtomQuotaPermissionContext() {
|
||||
}
|
||||
|
||||
AtomQuotaPermissionContext::~AtomQuotaPermissionContext() {
|
||||
}
|
||||
|
||||
void AtomQuotaPermissionContext::RequestQuotaPermission(
|
||||
const content::StorageQuotaParams& params,
|
||||
int render_process_id,
|
||||
const PermissionCallback& callback) {
|
||||
callback.Run(response::QUOTA_PERMISSION_RESPONSE_ALLOW);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
31
atom/browser/atom_quota_permission_context.h
Normal file
31
atom/browser/atom_quota_permission_context.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_ATOM_QUOTA_PERMISSION_CONTEXT_H_
|
||||
#define ATOM_BROWSER_ATOM_QUOTA_PERMISSION_CONTEXT_H_
|
||||
|
||||
#include "content/public/browser/quota_permission_context.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomQuotaPermissionContext : public content::QuotaPermissionContext {
|
||||
public:
|
||||
typedef content::QuotaPermissionContext::QuotaPermissionResponse response;
|
||||
|
||||
AtomQuotaPermissionContext();
|
||||
virtual ~AtomQuotaPermissionContext();
|
||||
|
||||
// content::QuotaPermissionContext:
|
||||
void RequestQuotaPermission(
|
||||
const content::StorageQuotaParams& params,
|
||||
int render_process_id,
|
||||
const PermissionCallback& callback) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomQuotaPermissionContext);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_ATOM_QUOTA_PERMISSION_CONTEXT_H_
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() {
|
||||
}
|
||||
|
||||
void AtomResourceDispatcherHostDelegate::OnResponseStarted(
|
||||
net::URLRequest* request,
|
||||
content::ResourceContext* resource_context,
|
||||
content::ResourceResponse* response,
|
||||
IPC::Sender* sender) {
|
||||
// Remove the "X-Frame-Options" from response headers for devtools.
|
||||
if (request->url().SchemeIs("chrome-devtools")) {
|
||||
net::HttpResponseHeaders* response_headers = request->response_headers();
|
||||
if (response_headers && response_headers->HasHeader("x-frame-options"))
|
||||
response_headers->RemoveHeader("x-frame-options");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
@@ -1,30 +0,0 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
|
||||
#define ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "content/public/browser/resource_dispatcher_host_delegate.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomResourceDispatcherHostDelegate
|
||||
: public content::ResourceDispatcherHostDelegate {
|
||||
public:
|
||||
AtomResourceDispatcherHostDelegate();
|
||||
|
||||
// content::ResourceDispatcherHostDelegate:
|
||||
void OnResponseStarted(net::URLRequest* request,
|
||||
content::ResourceContext* resource_context,
|
||||
content::ResourceResponse* response,
|
||||
IPC::Sender* sender) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomResourceDispatcherHostDelegate);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
|
||||
335
atom/browser/common_web_contents_delegate.cc
Normal file
335
atom/browser/common_web_contents_delegate.cc
Normal file
@@ -0,0 +1,335 @@
|
||||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/common_web_contents_delegate.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
#include "atom/browser/web_dialog_helper.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "chrome/browser/ui/browser_dialogs.h"
|
||||
#include "content/public/browser/child_process_security_policy.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "storage/browser/fileapi/isolated_context.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
struct FileSystem {
|
||||
FileSystem() {
|
||||
}
|
||||
FileSystem(const std::string& file_system_name,
|
||||
const std::string& root_url,
|
||||
const std::string& file_system_path)
|
||||
: file_system_name(file_system_name),
|
||||
root_url(root_url),
|
||||
file_system_path(file_system_path) {
|
||||
}
|
||||
|
||||
std::string file_system_name;
|
||||
std::string root_url;
|
||||
std::string file_system_path;
|
||||
};
|
||||
|
||||
std::string RegisterFileSystem(content::WebContents* web_contents,
|
||||
const base::FilePath& path,
|
||||
std::string* registered_name) {
|
||||
auto isolated_context = storage::IsolatedContext::GetInstance();
|
||||
std::string file_system_id = isolated_context->RegisterFileSystemForPath(
|
||||
storage::kFileSystemTypeNativeLocal,
|
||||
std::string(),
|
||||
path,
|
||||
registered_name);
|
||||
|
||||
content::ChildProcessSecurityPolicy* policy =
|
||||
content::ChildProcessSecurityPolicy::GetInstance();
|
||||
content::RenderViewHost* render_view_host = web_contents->GetRenderViewHost();
|
||||
int renderer_id = render_view_host->GetProcess()->GetID();
|
||||
policy->GrantReadFileSystem(renderer_id, file_system_id);
|
||||
policy->GrantWriteFileSystem(renderer_id, file_system_id);
|
||||
policy->GrantCreateFileForFileSystem(renderer_id, file_system_id);
|
||||
policy->GrantDeleteFromFileSystem(renderer_id, file_system_id);
|
||||
|
||||
if (!policy->CanReadFile(renderer_id, path))
|
||||
policy->GrantReadFile(renderer_id, path);
|
||||
|
||||
return file_system_id;
|
||||
}
|
||||
|
||||
FileSystem CreateFileSystemStruct(
|
||||
content::WebContents* web_contents,
|
||||
const std::string& file_system_id,
|
||||
const std::string& registered_name,
|
||||
const std::string& file_system_path) {
|
||||
const GURL origin = web_contents->GetURL().GetOrigin();
|
||||
std::string file_system_name =
|
||||
storage::GetIsolatedFileSystemName(origin, file_system_id);
|
||||
std::string root_url = storage::GetIsolatedFileSystemRootURIString(
|
||||
origin, file_system_id, registered_name);
|
||||
return FileSystem(file_system_name, root_url, file_system_path);
|
||||
}
|
||||
|
||||
base::DictionaryValue* CreateFileSystemValue(const FileSystem& file_system) {
|
||||
base::DictionaryValue* file_system_value = new base::DictionaryValue();
|
||||
file_system_value->SetString("fileSystemName", file_system.file_system_name);
|
||||
file_system_value->SetString("rootURL", file_system.root_url);
|
||||
file_system_value->SetString("fileSystemPath", file_system.file_system_path);
|
||||
return file_system_value;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CommonWebContentsDelegate::CommonWebContentsDelegate(bool is_guest)
|
||||
: is_guest_(is_guest),
|
||||
owner_window_(nullptr),
|
||||
html_fullscreen_(false),
|
||||
native_fullscreen_(false) {
|
||||
}
|
||||
|
||||
CommonWebContentsDelegate::~CommonWebContentsDelegate() {
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::InitWithWebContents(
|
||||
content::WebContents* web_contents,
|
||||
NativeWindow* owner_window) {
|
||||
owner_window_ = owner_window;
|
||||
web_contents->SetDelegate(this);
|
||||
|
||||
// Create InspectableWebContents.
|
||||
web_contents_.reset(brightray::InspectableWebContents::Create(web_contents));
|
||||
web_contents_->SetDelegate(this);
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::DestroyWebContents() {
|
||||
web_contents_.reset();
|
||||
}
|
||||
|
||||
content::WebContents* CommonWebContentsDelegate::GetWebContents() const {
|
||||
if (!web_contents_)
|
||||
return nullptr;
|
||||
return web_contents_->GetWebContents();
|
||||
}
|
||||
|
||||
content::WebContents*
|
||||
CommonWebContentsDelegate::GetDevToolsWebContents() const {
|
||||
if (!web_contents_)
|
||||
return nullptr;
|
||||
return web_contents_->GetDevToolsWebContents();
|
||||
}
|
||||
|
||||
content::WebContents* CommonWebContentsDelegate::OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) {
|
||||
content::NavigationController::LoadURLParams load_url_params(params.url);
|
||||
load_url_params.referrer = params.referrer;
|
||||
load_url_params.transition_type = params.transition;
|
||||
load_url_params.extra_headers = params.extra_headers;
|
||||
load_url_params.should_replace_current_entry =
|
||||
params.should_replace_current_entry;
|
||||
load_url_params.is_renderer_initiated = params.is_renderer_initiated;
|
||||
load_url_params.transferred_global_request_id =
|
||||
params.transferred_global_request_id;
|
||||
load_url_params.should_clear_history_list = true;
|
||||
|
||||
source->GetController().LoadURLWithParams(load_url_params);
|
||||
return source;
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::RequestToLockMouse(
|
||||
content::WebContents* web_contents,
|
||||
bool user_gesture,
|
||||
bool last_unlocked_by_target) {
|
||||
GetWebContents()->GotResponseToLockMouseRequest(true);
|
||||
}
|
||||
|
||||
bool CommonWebContentsDelegate::CanOverscrollContent() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CommonWebContentsDelegate::IsPopupOrPanel(
|
||||
const content::WebContents* source) const {
|
||||
return !is_guest_;
|
||||
}
|
||||
|
||||
content::JavaScriptDialogManager*
|
||||
CommonWebContentsDelegate::GetJavaScriptDialogManager(
|
||||
content::WebContents* source) {
|
||||
if (!dialog_manager_)
|
||||
dialog_manager_.reset(new AtomJavaScriptDialogManager);
|
||||
|
||||
return dialog_manager_.get();
|
||||
}
|
||||
|
||||
content::ColorChooser* CommonWebContentsDelegate::OpenColorChooser(
|
||||
content::WebContents* web_contents,
|
||||
SkColor color,
|
||||
const std::vector<content::ColorSuggestion>& suggestions) {
|
||||
return chrome::ShowColorChooser(web_contents, color);
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::RunFileChooser(
|
||||
content::WebContents* guest,
|
||||
const content::FileChooserParams& params) {
|
||||
if (!web_dialog_helper_)
|
||||
web_dialog_helper_.reset(new WebDialogHelper(owner_window_));
|
||||
web_dialog_helper_->RunFileChooser(guest, params);
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::EnumerateDirectory(content::WebContents* guest,
|
||||
int request_id,
|
||||
const base::FilePath& path) {
|
||||
if (!web_dialog_helper_)
|
||||
web_dialog_helper_.reset(new WebDialogHelper(owner_window_));
|
||||
web_dialog_helper_->EnumerateDirectory(guest, request_id, path);
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::EnterFullscreenModeForTab(
|
||||
content::WebContents* source, const GURL& origin) {
|
||||
if (!owner_window_)
|
||||
return;
|
||||
SetHtmlApiFullscreen(true);
|
||||
owner_window_->NotifyWindowEnterHtmlFullScreen();
|
||||
source->GetRenderViewHost()->WasResized();
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::ExitFullscreenModeForTab(
|
||||
content::WebContents* source) {
|
||||
if (!owner_window_)
|
||||
return;
|
||||
SetHtmlApiFullscreen(false);
|
||||
owner_window_->NotifyWindowLeaveHtmlFullScreen();
|
||||
source->GetRenderViewHost()->WasResized();
|
||||
}
|
||||
|
||||
bool CommonWebContentsDelegate::IsFullscreenForTabOrPending(
|
||||
const content::WebContents* source) const {
|
||||
return html_fullscreen_;
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::DevToolsSaveToFile(
|
||||
const std::string& url, const std::string& content, bool save_as) {
|
||||
base::FilePath path;
|
||||
PathsMap::iterator it = saved_files_.find(url);
|
||||
if (it != saved_files_.end() && !save_as) {
|
||||
path = it->second;
|
||||
} else {
|
||||
file_dialog::Filters filters;
|
||||
base::FilePath default_path(base::FilePath::FromUTF8Unsafe(url));
|
||||
if (!file_dialog::ShowSaveDialog(owner_window_, url, default_path,
|
||||
filters, &path)) {
|
||||
base::StringValue url_value(url);
|
||||
web_contents_->CallClientFunction(
|
||||
"DevToolsAPI.canceledSaveURL", &url_value, nullptr, nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
saved_files_[url] = path;
|
||||
base::WriteFile(path, content.data(), content.size());
|
||||
|
||||
// Notify devtools.
|
||||
base::StringValue url_value(url);
|
||||
web_contents_->CallClientFunction(
|
||||
"DevToolsAPI.savedURL", &url_value, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::DevToolsAppendToFile(
|
||||
const std::string& url, const std::string& content) {
|
||||
PathsMap::iterator it = saved_files_.find(url);
|
||||
if (it == saved_files_.end())
|
||||
return;
|
||||
base::AppendToFile(it->second, content.data(), content.size());
|
||||
|
||||
// Notify devtools.
|
||||
base::StringValue url_value(url);
|
||||
web_contents_->CallClientFunction(
|
||||
"DevToolsAPI.appendedToURL", &url_value, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::DevToolsAddFileSystem() {
|
||||
file_dialog::Filters filters;
|
||||
base::FilePath default_path;
|
||||
std::vector<base::FilePath> paths;
|
||||
int flag = file_dialog::FILE_DIALOG_OPEN_DIRECTORY;
|
||||
if (!file_dialog::ShowOpenDialog(owner_window_, "", default_path,
|
||||
filters, flag, &paths))
|
||||
return;
|
||||
|
||||
base::FilePath path = paths[0];
|
||||
std::string registered_name;
|
||||
std::string file_system_id = RegisterFileSystem(GetDevToolsWebContents(),
|
||||
path,
|
||||
®istered_name);
|
||||
|
||||
WorkspaceMap::iterator it = saved_paths_.find(file_system_id);
|
||||
if (it != saved_paths_.end())
|
||||
return;
|
||||
|
||||
saved_paths_[file_system_id] = path;
|
||||
|
||||
FileSystem file_system = CreateFileSystemStruct(GetDevToolsWebContents(),
|
||||
file_system_id,
|
||||
registered_name,
|
||||
path.AsUTF8Unsafe());
|
||||
|
||||
scoped_ptr<base::StringValue> error_string_value(
|
||||
new base::StringValue(std::string()));
|
||||
scoped_ptr<base::DictionaryValue> file_system_value;
|
||||
if (!file_system.file_system_path.empty())
|
||||
file_system_value.reset(CreateFileSystemValue(file_system));
|
||||
web_contents_->CallClientFunction(
|
||||
"DevToolsAPI.fileSystemAdded",
|
||||
error_string_value.get(),
|
||||
file_system_value.get(),
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::DevToolsRemoveFileSystem(
|
||||
const std::string& file_system_path) {
|
||||
if (!web_contents_)
|
||||
return;
|
||||
|
||||
base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path);
|
||||
storage::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path);
|
||||
|
||||
for (auto it = saved_paths_.begin(); it != saved_paths_.end(); ++it)
|
||||
if (it->second == path) {
|
||||
saved_paths_.erase(it);
|
||||
break;
|
||||
}
|
||||
|
||||
base::StringValue file_system_path_value(file_system_path);
|
||||
web_contents_->CallClientFunction(
|
||||
"DevToolsAPI.fileSystemRemoved",
|
||||
&file_system_path_value,
|
||||
nullptr,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::SetHtmlApiFullscreen(bool enter_fullscreen) {
|
||||
// Window is already in fullscreen mode, save the state.
|
||||
if (enter_fullscreen && owner_window_->IsFullscreen()) {
|
||||
native_fullscreen_ = true;
|
||||
html_fullscreen_ = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Exit html fullscreen state but not window's fullscreen mode.
|
||||
if (!enter_fullscreen && native_fullscreen_) {
|
||||
html_fullscreen_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
owner_window_->SetFullScreen(enter_fullscreen);
|
||||
html_fullscreen_ = enter_fullscreen;
|
||||
native_fullscreen_ = false;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
124
atom/browser/common_web_contents_delegate.h
Normal file
124
atom/browser/common_web_contents_delegate.h
Normal file
@@ -0,0 +1,124 @@
|
||||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|
||||
#define ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "brightray/browser/default_web_contents_delegate.h"
|
||||
#include "brightray/browser/inspectable_web_contents_impl.h"
|
||||
#include "brightray/browser/inspectable_web_contents_delegate.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomJavaScriptDialogManager;
|
||||
class NativeWindow;
|
||||
class WebDialogHelper;
|
||||
|
||||
class CommonWebContentsDelegate
|
||||
: public brightray::DefaultWebContentsDelegate,
|
||||
public brightray::InspectableWebContentsDelegate {
|
||||
public:
|
||||
explicit CommonWebContentsDelegate(bool is_guest);
|
||||
virtual ~CommonWebContentsDelegate();
|
||||
|
||||
// Create a InspectableWebContents object and takes onwership of
|
||||
// |web_contents|.
|
||||
void InitWithWebContents(content::WebContents* web_contents,
|
||||
NativeWindow* owner_window);
|
||||
|
||||
// Destroy the managed InspectableWebContents object.
|
||||
void DestroyWebContents();
|
||||
|
||||
// Returns the WebContents managed by this delegate.
|
||||
content::WebContents* GetWebContents() const;
|
||||
|
||||
// Returns the WebContents of devtools.
|
||||
content::WebContents* GetDevToolsWebContents() const;
|
||||
|
||||
brightray::InspectableWebContents* managed_web_contents() const {
|
||||
return web_contents_.get();
|
||||
}
|
||||
|
||||
bool is_guest() const { return is_guest_; }
|
||||
|
||||
protected:
|
||||
// content::WebContentsDelegate:
|
||||
content::WebContents* OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) override;
|
||||
void RequestToLockMouse(content::WebContents* web_contents,
|
||||
bool user_gesture,
|
||||
bool last_unlocked_by_target) override;
|
||||
bool CanOverscrollContent() const override;
|
||||
bool IsPopupOrPanel(const content::WebContents* source) const override;
|
||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
||||
content::WebContents* source) override;
|
||||
content::ColorChooser* OpenColorChooser(
|
||||
content::WebContents* web_contents,
|
||||
SkColor color,
|
||||
const std::vector<content::ColorSuggestion>& suggestions) override;
|
||||
void RunFileChooser(content::WebContents* web_contents,
|
||||
const content::FileChooserParams& params) override;
|
||||
void EnumerateDirectory(content::WebContents* web_contents,
|
||||
int request_id,
|
||||
const base::FilePath& path) override;
|
||||
void EnterFullscreenModeForTab(content::WebContents* source,
|
||||
const GURL& origin) override;
|
||||
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
||||
bool IsFullscreenForTabOrPending(
|
||||
const content::WebContents* source) const override;
|
||||
|
||||
// brightray::InspectableWebContentsDelegate:
|
||||
void DevToolsSaveToFile(const std::string& url,
|
||||
const std::string& content,
|
||||
bool save_as) override;
|
||||
void DevToolsAppendToFile(const std::string& url,
|
||||
const std::string& content) override;
|
||||
void DevToolsAddFileSystem() override;
|
||||
void DevToolsRemoveFileSystem(const std::string& file_system_path) override;
|
||||
|
||||
private:
|
||||
// Set fullscreen mode triggered by html api.
|
||||
void SetHtmlApiFullscreen(bool enter_fullscreen);
|
||||
|
||||
// Whether this is guest WebContents or NativeWindow.
|
||||
const bool is_guest_;
|
||||
|
||||
// The window that this WebContents belongs to.
|
||||
NativeWindow* owner_window_;
|
||||
|
||||
// Whether window is fullscreened by HTML5 api.
|
||||
bool html_fullscreen_;
|
||||
|
||||
// Whether window is fullscreened by window api.
|
||||
bool native_fullscreen_;
|
||||
|
||||
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||
|
||||
// The stored InspectableWebContents object.
|
||||
// Notice that web_contents_ must be placed after dialog_manager_, so we can
|
||||
// make sure web_contents_ is destroyed before dialog_manager_, otherwise a
|
||||
// crash would happen.
|
||||
scoped_ptr<brightray::InspectableWebContents> web_contents_;
|
||||
|
||||
// Maps url to file path, used by the file requests sent from devtools.
|
||||
typedef std::map<std::string, base::FilePath> PathsMap;
|
||||
PathsMap saved_files_;
|
||||
|
||||
// Maps file system id to file path, used by the file system requests
|
||||
// sent from devtools.
|
||||
typedef std::map<std::string, base::FilePath> WorkspaceMap;
|
||||
WorkspaceMap saved_paths_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CommonWebContentsDelegate);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|
||||
@@ -1,10 +1,7 @@
|
||||
var app = require('app');
|
||||
var Menu = require('menu');
|
||||
var MenuItem = require('menu-item');
|
||||
var BrowserWindow = require('browser-window');
|
||||
|
||||
var mainWindow = null;
|
||||
var menu = null;
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function() {
|
||||
@@ -15,177 +12,9 @@ app.on('ready', function() {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
resizable: false,
|
||||
'auto-hide-menu-bar': true,
|
||||
'use-content-size': true,
|
||||
});
|
||||
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
||||
mainWindow.focus();
|
||||
|
||||
if (process.platform == 'darwin') {
|
||||
var template = [
|
||||
{
|
||||
label: 'Electron',
|
||||
submenu: [
|
||||
{
|
||||
label: 'About Electron',
|
||||
selector: 'orderFrontStandardAboutPanel:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Services',
|
||||
submenu: []
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Hide Electron',
|
||||
accelerator: 'Command+H',
|
||||
selector: 'hide:'
|
||||
},
|
||||
{
|
||||
label: 'Hide Others',
|
||||
accelerator: 'Command+Shift+H',
|
||||
selector: 'hideOtherApplications:'
|
||||
},
|
||||
{
|
||||
label: 'Show All',
|
||||
selector: 'unhideAllApplications:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Quit',
|
||||
accelerator: 'Command+Q',
|
||||
click: function() { app.quit(); }
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Undo',
|
||||
accelerator: 'Command+Z',
|
||||
selector: 'undo:'
|
||||
},
|
||||
{
|
||||
label: 'Redo',
|
||||
accelerator: 'Shift+Command+Z',
|
||||
selector: 'redo:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Cut',
|
||||
accelerator: 'Command+X',
|
||||
selector: 'cut:'
|
||||
},
|
||||
{
|
||||
label: 'Copy',
|
||||
accelerator: 'Command+C',
|
||||
selector: 'copy:'
|
||||
},
|
||||
{
|
||||
label: 'Paste',
|
||||
accelerator: 'Command+V',
|
||||
selector: 'paste:'
|
||||
},
|
||||
{
|
||||
label: 'Select All',
|
||||
accelerator: 'Command+A',
|
||||
selector: 'selectAll:'
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Reload',
|
||||
accelerator: 'Command+R',
|
||||
click: function() { mainWindow.restart(); }
|
||||
},
|
||||
{
|
||||
label: 'Enter Fullscreen',
|
||||
click: function() { mainWindow.setFullScreen(true); }
|
||||
},
|
||||
{
|
||||
label: 'Toggle DevTools',
|
||||
accelerator: 'Alt+Command+I',
|
||||
click: function() { mainWindow.toggleDevTools(); }
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Window',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Minimize',
|
||||
accelerator: 'Command+M',
|
||||
selector: 'performMiniaturize:'
|
||||
},
|
||||
{
|
||||
label: 'Close',
|
||||
accelerator: 'Command+W',
|
||||
selector: 'performClose:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Bring All to Front',
|
||||
selector: 'arrangeInFront:'
|
||||
},
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
menu = Menu.buildFromTemplate(template);
|
||||
Menu.setApplicationMenu(menu);
|
||||
} else {
|
||||
var template = [
|
||||
{
|
||||
label: '&File',
|
||||
submenu: [
|
||||
{
|
||||
label: '&Open',
|
||||
accelerator: 'Ctrl+O',
|
||||
},
|
||||
{
|
||||
label: '&Close',
|
||||
accelerator: 'Ctrl+W',
|
||||
click: function() { mainWindow.close(); }
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '&View',
|
||||
submenu: [
|
||||
{
|
||||
label: '&Reload',
|
||||
accelerator: 'Ctrl+R',
|
||||
click: function() { mainWindow.restart(); }
|
||||
},
|
||||
{
|
||||
label: '&Enter Fullscreen',
|
||||
click: function() { mainWindow.setFullScreen(true); }
|
||||
},
|
||||
{
|
||||
label: '&Toggle DevTools',
|
||||
accelerator: 'Alt+Ctrl+I',
|
||||
click: function() { mainWindow.toggleDevTools(); }
|
||||
},
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
menu = Menu.buildFromTemplate(template);
|
||||
mainWindow.setMenu(menu);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,6 +2,8 @@ var app = require('app');
|
||||
var dialog = require('dialog');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var Menu = require('menu');
|
||||
var BrowserWindow = require('browser-window');
|
||||
|
||||
// Quit when all windows are closed and no other one is listening to this.
|
||||
app.on('window-all-closed', function() {
|
||||
@@ -11,11 +13,14 @@ app.on('window-all-closed', function() {
|
||||
|
||||
// Parse command line options.
|
||||
var argv = process.argv.slice(1);
|
||||
var option = { file: null, version: null, webdriver: null };
|
||||
var option = { file: null, help: null, version: null, webdriver: null };
|
||||
for (var i in argv) {
|
||||
if (argv[i] == '--version' || argv[i] == '-v') {
|
||||
option.version = true;
|
||||
break;
|
||||
} else if (argv[i] == '--help' || argv[i] == '-h') {
|
||||
option.help = true;
|
||||
break;
|
||||
} else if (argv[i] == '--test-type=webdriver') {
|
||||
option.webdriver = true;
|
||||
} else if (argv[i][0] == '-') {
|
||||
@@ -26,6 +31,246 @@ for (var i in argv) {
|
||||
}
|
||||
}
|
||||
|
||||
// Create default menu.
|
||||
app.once('ready', function() {
|
||||
var template;
|
||||
if (process.platform == 'darwin') {
|
||||
template = [
|
||||
{
|
||||
label: 'Electron',
|
||||
submenu: [
|
||||
{
|
||||
label: 'About Electron',
|
||||
selector: 'orderFrontStandardAboutPanel:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Services',
|
||||
submenu: []
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Hide Electron',
|
||||
accelerator: 'Command+H',
|
||||
selector: 'hide:'
|
||||
},
|
||||
{
|
||||
label: 'Hide Others',
|
||||
accelerator: 'Command+Shift+H',
|
||||
selector: 'hideOtherApplications:'
|
||||
},
|
||||
{
|
||||
label: 'Show All',
|
||||
selector: 'unhideAllApplications:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Quit',
|
||||
accelerator: 'Command+Q',
|
||||
click: function() { app.quit(); }
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Undo',
|
||||
accelerator: 'Command+Z',
|
||||
selector: 'undo:'
|
||||
},
|
||||
{
|
||||
label: 'Redo',
|
||||
accelerator: 'Shift+Command+Z',
|
||||
selector: 'redo:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Cut',
|
||||
accelerator: 'Command+X',
|
||||
selector: 'cut:'
|
||||
},
|
||||
{
|
||||
label: 'Copy',
|
||||
accelerator: 'Command+C',
|
||||
selector: 'copy:'
|
||||
},
|
||||
{
|
||||
label: 'Paste',
|
||||
accelerator: 'Command+V',
|
||||
selector: 'paste:'
|
||||
},
|
||||
{
|
||||
label: 'Select All',
|
||||
accelerator: 'Command+A',
|
||||
selector: 'selectAll:'
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Reload',
|
||||
accelerator: 'Command+R',
|
||||
click: function() {
|
||||
var focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow)
|
||||
focusedWindow.reload();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Full Screen',
|
||||
accelerator: 'Ctrl+Command+F',
|
||||
click: function() {
|
||||
var focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow)
|
||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: 'Alt+Command+I',
|
||||
click: function() {
|
||||
var focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow)
|
||||
focusedWindow.toggleDevTools();
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Window',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Minimize',
|
||||
accelerator: 'Command+M',
|
||||
selector: 'performMiniaturize:'
|
||||
},
|
||||
{
|
||||
label: 'Close',
|
||||
accelerator: 'Command+W',
|
||||
selector: 'performClose:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Bring All to Front',
|
||||
selector: 'arrangeInFront:'
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Help',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Learn More',
|
||||
click: function() { require('shell').openExternal('http://electron.atom.io') }
|
||||
},
|
||||
{
|
||||
label: 'Documentation',
|
||||
click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme') }
|
||||
},
|
||||
{
|
||||
label: 'Community Discussions',
|
||||
click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron') }
|
||||
},
|
||||
{
|
||||
label: 'Search Issues',
|
||||
click: function() { require('shell').openExternal('https://github.com/atom/electron/issues') }
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
} else {
|
||||
template = [
|
||||
{
|
||||
label: '&File',
|
||||
submenu: [
|
||||
{
|
||||
label: '&Open',
|
||||
accelerator: 'Ctrl+O',
|
||||
},
|
||||
{
|
||||
label: '&Close',
|
||||
accelerator: 'Ctrl+W',
|
||||
click: function() {
|
||||
var focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow)
|
||||
focusedWindow.close();
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '&View',
|
||||
submenu: [
|
||||
{
|
||||
label: '&Reload',
|
||||
accelerator: 'Ctrl+R',
|
||||
click: function() {
|
||||
var focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow)
|
||||
focusedWindow.reload();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle &Full Screen',
|
||||
accelerator: 'F11',
|
||||
click: function() {
|
||||
var focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow)
|
||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle &Developer Tools',
|
||||
accelerator: 'Alt+Ctrl+I',
|
||||
click: function() {
|
||||
var focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow)
|
||||
focusedWindow.toggleDevTools();
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Help',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Learn More',
|
||||
click: function() { require('shell').openExternal('http://electron.atom.io') }
|
||||
},
|
||||
{
|
||||
label: 'Documentation',
|
||||
click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme') }
|
||||
},
|
||||
{
|
||||
label: 'Community Discussions',
|
||||
click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron') }
|
||||
},
|
||||
{
|
||||
label: 'Search Issues',
|
||||
click: function() { require('shell').openExternal('https://github.com/atom/electron/issues') }
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
var menu = Menu.buildFromTemplate(template);
|
||||
Menu.setApplicationMenu(menu);
|
||||
});
|
||||
|
||||
// Start the specified app if there is one specified in command line, otherwise
|
||||
// start the default app.
|
||||
if (option.file && !option.webdriver) {
|
||||
@@ -50,7 +295,7 @@ if (option.file && !option.webdriver) {
|
||||
} catch(e) {
|
||||
if (e.code == 'MODULE_NOT_FOUND') {
|
||||
app.focus();
|
||||
dialog.showErrorBox('Error opening app', 'The app provided is not a valid electron app, please read the docs on how to write one:\nhttps://github.com/atom/electron/tree/master/docs');
|
||||
dialog.showErrorBox('Error opening app', 'The app provided is not a valid electron app, please read the docs on how to write one:\nhttps://github.com/atom/electron/tree/master/docs\n\n' + e.toString());
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.error('App threw an error when running', e);
|
||||
@@ -58,7 +303,17 @@ if (option.file && !option.webdriver) {
|
||||
}
|
||||
}
|
||||
} else if (option.version) {
|
||||
console.log('v' + process.versions['electron']);
|
||||
console.log('v' + process.versions.electron);
|
||||
process.exit(0);
|
||||
} else if (option.help) {
|
||||
var helpMessage = "Electron v" + process.versions.electron + " - Cross Platform Desktop Application Shell\n\n";
|
||||
helpMessage += "Usage: electron [options] [path]\n\n";
|
||||
helpMessage += "A path to an Electron application may be specified. The path must be to \n";
|
||||
helpMessage += "an index.js file or to a folder containing a package.json or index.js file.\n\n";
|
||||
helpMessage += "Options:\n";
|
||||
helpMessage += " -h, --help Print this usage message.\n";
|
||||
helpMessage += " -v, --version Print the version.";
|
||||
console.log(helpMessage);
|
||||
process.exit(0);
|
||||
} else {
|
||||
require('./default_app.js');
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
|
||||
#include "atom/browser/javascript_environment.h"
|
||||
|
||||
#include "gin/array_buffer.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
JavascriptEnvironment::JavascriptEnvironment()
|
||||
: isolate_(isolate_holder_.isolate()),
|
||||
: initialized_(Initialize()),
|
||||
isolate_(isolate_holder_.isolate()),
|
||||
isolate_scope_(isolate_),
|
||||
locker_(isolate_),
|
||||
handle_scope_(isolate_),
|
||||
@@ -15,4 +18,11 @@ JavascriptEnvironment::JavascriptEnvironment()
|
||||
context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {
|
||||
}
|
||||
|
||||
bool JavascriptEnvironment::Initialize() {
|
||||
gin::IsolateHolder::LoadV8Snapshot();
|
||||
gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
|
||||
gin::ArrayBufferAllocator::SharedInstance());
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -20,6 +20,9 @@ class JavascriptEnvironment {
|
||||
}
|
||||
|
||||
private:
|
||||
bool Initialize();
|
||||
|
||||
bool initialized_;
|
||||
gin::IsolateHolder isolate_holder_;
|
||||
v8::Isolate* isolate_;
|
||||
v8::Isolate::Scope isolate_scope_;
|
||||
|
||||
@@ -10,12 +10,18 @@ supportedWebViewEvents = [
|
||||
'did-stop-loading'
|
||||
'did-get-response-details'
|
||||
'did-get-redirect-request'
|
||||
'dom-ready'
|
||||
'console-message'
|
||||
'new-window'
|
||||
'close'
|
||||
'crashed'
|
||||
'gpu-crashed'
|
||||
'plugin-crashed'
|
||||
'destroyed'
|
||||
'page-title-set'
|
||||
'page-favicon-updated'
|
||||
'enter-html-full-screen'
|
||||
'leave-html-full-screen'
|
||||
]
|
||||
|
||||
nextInstanceId = 0
|
||||
@@ -32,10 +38,7 @@ createGuest = (embedder, params) ->
|
||||
webViewManager ?= process.atomBinding 'web_view_manager'
|
||||
|
||||
id = getNextInstanceId embedder
|
||||
guest = webContents.create
|
||||
isGuest: true
|
||||
guestInstanceId: id
|
||||
storagePartitionId: params.storagePartitionId
|
||||
guest = webContents.create {embedder}
|
||||
guestInstances[id] = {guest, embedder}
|
||||
|
||||
# Destroy guest when the embedder is gone or navigated.
|
||||
@@ -52,14 +55,21 @@ createGuest = (embedder, params) ->
|
||||
delete @attachParams
|
||||
|
||||
@viewInstanceId = params.instanceId
|
||||
min = width: params.minwidth, height: params.minheight
|
||||
max = width: params.maxwidth, height: params.maxheight
|
||||
@setAutoSize params.autosize, min, max
|
||||
@setSize
|
||||
normal:
|
||||
width: params.elementWidth, height: params.elementHeight
|
||||
enableAutoSize: params.autosize
|
||||
min:
|
||||
width: params.minwidth, height: params.minheight
|
||||
max:
|
||||
width: params.maxwidth, height: params.maxheight
|
||||
|
||||
if params.src
|
||||
if params.httpreferrer
|
||||
@loadUrl params.src, {httpreferrer: params.httpreferrer}
|
||||
else
|
||||
@loadUrl params.src
|
||||
opts = {}
|
||||
opts.httpReferrer = params.httpreferrer if params.httpreferrer
|
||||
opts.userAgent = params.useragent if params.useragent
|
||||
@loadUrl params.src, opts
|
||||
|
||||
if params.allowtransparency?
|
||||
@setAllowTransparency params.allowtransparency
|
||||
|
||||
@@ -115,7 +125,7 @@ destroyGuest = (embedder, id) ->
|
||||
delete reverseEmbedderElementsMap[id]
|
||||
delete embedderElementsMap[key]
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, type, params, requestId) ->
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, params, requestId) ->
|
||||
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', (event, elementInstanceId, guestInstanceId, params) ->
|
||||
@@ -124,8 +134,8 @@ ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', (event, elementInstanceId,
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, id) ->
|
||||
destroyGuest event.sender, id
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_SIZE', (event, id, params) ->
|
||||
guestInstances[id]?.guest.setAutoSize params.enableAutoSize, params.min, params.max
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', (event, id, params) ->
|
||||
guestInstances[id]?.guest.setSize params
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', (event, id, allowtransparency) ->
|
||||
guestInstances[id]?.guest.setAllowTransparency allowtransparency
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
module = require 'module'
|
||||
util = require 'util'
|
||||
Module = require 'module'
|
||||
|
||||
# We modified the original process.argv to let node.js load the atom.js,
|
||||
# we need to restore it here.
|
||||
process.argv.splice 1, 1
|
||||
|
||||
# Add browser/api/lib to require's search paths,
|
||||
# which contains javascript part of Atom's built-in libraries.
|
||||
globalPaths = module.globalPaths
|
||||
# Add browser/api/lib to module search paths, which contains javascript part of
|
||||
# Electron's built-in libraries.
|
||||
globalPaths = Module.globalPaths
|
||||
globalPaths.push path.resolve(__dirname, '..', 'api', 'lib')
|
||||
|
||||
# Import common settings.
|
||||
@@ -81,6 +81,9 @@ if packageJson.desktopName?
|
||||
else
|
||||
app.setDesktopName "#{app.getName()}.desktop"
|
||||
|
||||
# Chrome 42 disables NPAPI plugins by default, reenable them here
|
||||
app.commandLine.appendSwitch 'enable-npapi'
|
||||
|
||||
# Set the user path according to application's name.
|
||||
app.setPath 'userData', path.join(app.getPath('appData'), app.getName())
|
||||
app.setPath 'userCache', path.join(app.getPath('cache'), app.getName())
|
||||
@@ -89,4 +92,4 @@ app.setPath 'userCache', path.join(app.getPath('cache'), app.getName())
|
||||
require './chrome-extension'
|
||||
|
||||
# Finally load app's main.js and transfer control to C++.
|
||||
module._load path.join(packagePath, packageJson.main), module, true
|
||||
Module._load path.join(packagePath, packageJson.main), Module, true
|
||||
|
||||
@@ -7,6 +7,7 @@ v8Util = process.atomBinding 'v8_util'
|
||||
valueToMeta = (sender, value) ->
|
||||
meta = type: typeof value
|
||||
|
||||
meta.type = 'buffer' if Buffer.isBuffer value
|
||||
meta.type = 'value' if value is null
|
||||
meta.type = 'array' if Array.isArray value
|
||||
|
||||
@@ -26,6 +27,8 @@ valueToMeta = (sender, value) ->
|
||||
|
||||
meta.members = []
|
||||
meta.members.push {name: prop, type: typeof field} for prop, field of value
|
||||
else if meta.type is 'buffer'
|
||||
meta.value = Array::slice.call value, 0
|
||||
else
|
||||
meta.type = 'value'
|
||||
meta.value = value
|
||||
@@ -43,6 +46,7 @@ unwrapArgs = (sender, args) ->
|
||||
when 'value' then meta.value
|
||||
when 'remote-object' then objectsRegistry.get meta.id
|
||||
when 'array' then unwrapArgs sender, meta.value
|
||||
when 'buffer' then new Buffer(meta.value)
|
||||
when 'object'
|
||||
ret = v8Util.createObjectWithName meta.name
|
||||
for member in meta.members
|
||||
@@ -107,6 +111,9 @@ ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, guestInstanceId) ->
|
||||
catch e
|
||||
event.returnValue = errorToMeta e
|
||||
|
||||
ipc.on 'ATOM_BROWSER_CURRENT_WEB_CONTENTS', (event) ->
|
||||
event.returnValue = valueToMeta event.sender, event.sender
|
||||
|
||||
ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, id, args) ->
|
||||
try
|
||||
args = unwrapArgs event.sender, args
|
||||
|
||||
@@ -18,6 +18,4 @@
|
||||
// CrAppControlProtocol:
|
||||
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
|
||||
|
||||
- (IBAction)closeAllWindows:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
@@ -36,10 +36,6 @@
|
||||
andEventID:kAEGetURL];
|
||||
}
|
||||
|
||||
- (IBAction)closeAllWindows:(id)sender {
|
||||
atom::Browser::Get()->Quit();
|
||||
}
|
||||
|
||||
- (void)handleURLEvent:(NSAppleEventDescriptor*)event
|
||||
withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
|
||||
NSString* url = [
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
#include "atom/browser/web_dialog_helper.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/atom_version.h"
|
||||
@@ -31,16 +28,12 @@
|
||||
#include "brightray/browser/inspectable_web_contents.h"
|
||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||
#include "chrome/browser/printing/print_view_manager_basic.h"
|
||||
#include "chrome/browser/ui/browser_dialogs.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/invalidate_type.h"
|
||||
#include "content/public/browser/navigation_entry.h"
|
||||
#include "content/public/browser/notification_details.h"
|
||||
#include "content/public/browser/notification_source.h"
|
||||
#include "content/public/browser/notification_types.h"
|
||||
#include "content/public/browser/plugin_service.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
@@ -78,6 +71,7 @@ const char* kWebRuntimeFeatures[] = {
|
||||
switches::kOverlayScrollbars,
|
||||
switches::kOverlayFullscreenVideo,
|
||||
switches::kSharedWorker,
|
||||
switches::kPageVisibility,
|
||||
};
|
||||
|
||||
std::string RemoveWhitespace(const std::string& str) {
|
||||
@@ -92,7 +86,8 @@ std::string RemoveWhitespace(const std::string& str) {
|
||||
|
||||
NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||
const mate::Dictionary& options)
|
||||
: content::WebContentsObserver(web_contents),
|
||||
: CommonWebContentsDelegate(false),
|
||||
content::WebContentsObserver(web_contents),
|
||||
has_frame_(true),
|
||||
transparent_(false),
|
||||
enable_larger_than_screen_(false),
|
||||
@@ -100,11 +95,11 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||
node_integration_(true),
|
||||
has_dialog_attached_(false),
|
||||
zoom_factor_(1.0),
|
||||
weak_factory_(this),
|
||||
inspectable_web_contents_(
|
||||
brightray::InspectableWebContents::Create(web_contents)) {
|
||||
weak_factory_(this) {
|
||||
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
||||
|
||||
InitWithWebContents(web_contents, this);
|
||||
|
||||
options.Get(switches::kFrame, &has_frame_);
|
||||
options.Get(switches::kTransparent, &transparent_);
|
||||
options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
|
||||
@@ -136,9 +131,6 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||
// Read the zoom factor before any navigation.
|
||||
options.Get(switches::kZoomFactor, &zoom_factor_);
|
||||
|
||||
web_contents->SetDelegate(this);
|
||||
inspectable_web_contents()->SetDelegate(this);
|
||||
|
||||
WindowList::AddWindow(this);
|
||||
|
||||
// Override the user agent to contain application and atom-shell's version.
|
||||
@@ -169,18 +161,13 @@ NativeWindow* NativeWindow::Create(const mate::Dictionary& options) {
|
||||
}
|
||||
|
||||
// static
|
||||
NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) {
|
||||
// Stupid iterating.
|
||||
NativeWindow* NativeWindow::FromWebContents(
|
||||
content::WebContents* web_contents) {
|
||||
WindowList& window_list = *WindowList::GetInstance();
|
||||
for (auto w = window_list.begin(); w != window_list.end(); ++w) {
|
||||
auto& window = *w;
|
||||
content::WebContents* web_contents = window->GetWebContents();
|
||||
int window_process_id = web_contents->GetRenderProcessHost()->GetID();
|
||||
int window_routing_id = web_contents->GetRoutingID();
|
||||
if (window_routing_id == routing_id && window_process_id == process_id)
|
||||
for (NativeWindow* window : window_list) {
|
||||
if (window->GetWebContents() == web_contents)
|
||||
return window;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -192,7 +179,7 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||
int width = -1, height = -1;
|
||||
options.Get(switches::kWidth, &width);
|
||||
options.Get(switches::kHeight, &height);
|
||||
Move(gfx::Rect(x, y, width, height));
|
||||
SetBounds(gfx::Rect(x, y, width, height));
|
||||
} else if (options.Get(switches::kCenter, ¢er) && center) {
|
||||
Center();
|
||||
}
|
||||
@@ -237,6 +224,22 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||
Show();
|
||||
}
|
||||
|
||||
void NativeWindow::SetSize(const gfx::Size& size) {
|
||||
SetBounds(gfx::Rect(GetPosition(), size));
|
||||
}
|
||||
|
||||
gfx::Size NativeWindow::GetSize() {
|
||||
return GetBounds().size();
|
||||
}
|
||||
|
||||
void NativeWindow::SetPosition(const gfx::Point& position) {
|
||||
SetBounds(gfx::Rect(position, GetSize()));
|
||||
}
|
||||
|
||||
gfx::Point NativeWindow::GetPosition() {
|
||||
return GetBounds().origin();
|
||||
}
|
||||
|
||||
void NativeWindow::SetRepresentedFilename(const std::string& filename) {
|
||||
}
|
||||
|
||||
@@ -281,26 +284,6 @@ bool NativeWindow::HasModalDialog() {
|
||||
return has_dialog_attached_;
|
||||
}
|
||||
|
||||
void NativeWindow::OpenDevTools(bool can_dock) {
|
||||
inspectable_web_contents()->SetCanDock(can_dock);
|
||||
inspectable_web_contents()->ShowDevTools();
|
||||
}
|
||||
|
||||
void NativeWindow::CloseDevTools() {
|
||||
inspectable_web_contents()->CloseDevTools();
|
||||
}
|
||||
|
||||
bool NativeWindow::IsDevToolsOpened() {
|
||||
return inspectable_web_contents()->IsDevToolsViewShowing();
|
||||
}
|
||||
|
||||
void NativeWindow::InspectElement(int x, int y) {
|
||||
OpenDevTools(true);
|
||||
scoped_refptr<content::DevToolsAgentHost> agent(
|
||||
content::DevToolsAgentHost::GetOrCreateFor(GetWebContents()));
|
||||
agent->InspectElement(x, y);
|
||||
}
|
||||
|
||||
void NativeWindow::FocusOnWebView() {
|
||||
GetWebContents()->GetRenderViewHost()->Focus();
|
||||
}
|
||||
@@ -349,13 +332,6 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
|
||||
kBGRA_8888_SkColorType);
|
||||
}
|
||||
|
||||
void NativeWindow::DestroyWebContents() {
|
||||
if (!inspectable_web_contents_)
|
||||
return;
|
||||
|
||||
inspectable_web_contents_.reset();
|
||||
}
|
||||
|
||||
void NativeWindow::CloseWebContents() {
|
||||
bool prevent_default = false;
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||
@@ -385,20 +361,8 @@ void NativeWindow::CloseWebContents() {
|
||||
web_contents->Close();
|
||||
}
|
||||
|
||||
content::WebContents* NativeWindow::GetWebContents() const {
|
||||
if (!inspectable_web_contents_)
|
||||
return nullptr;
|
||||
return inspectable_web_contents()->GetWebContents();
|
||||
}
|
||||
|
||||
content::WebContents* NativeWindow::GetDevToolsWebContents() const {
|
||||
if (!inspectable_web_contents_)
|
||||
return nullptr;
|
||||
return inspectable_web_contents()->devtools_web_contents();
|
||||
}
|
||||
|
||||
void NativeWindow::AppendExtraCommandLineSwitches(
|
||||
base::CommandLine* command_line, int child_process_id) {
|
||||
base::CommandLine* command_line) {
|
||||
// Append --node-integration to renderer process.
|
||||
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
||||
node_integration_ ? "true" : "false");
|
||||
@@ -435,8 +399,7 @@ void NativeWindow::AppendExtraCommandLineSwitches(
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindow::OverrideWebkitPrefs(const GURL& url,
|
||||
content::WebPreferences* prefs) {
|
||||
void NativeWindow::OverrideWebkitPrefs(content::WebPreferences* prefs) {
|
||||
if (web_preferences_.IsEmpty())
|
||||
return;
|
||||
|
||||
@@ -504,6 +467,18 @@ void NativeWindow::NotifyWindowRestore() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowRestore());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowResize() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowResize());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowMove() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMove());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowMoved() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMoved());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowEnterFullScreen() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||
OnWindowEnterFullScreen());
|
||||
@@ -514,6 +489,16 @@ void NativeWindow::NotifyWindowLeaveFullScreen() {
|
||||
OnWindowLeaveFullScreen());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowEnterHtmlFullScreen() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||
OnWindowEnterHtmlFullScreen());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowLeaveHtmlFullScreen() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||
OnWindowLeaveHtmlFullScreen());
|
||||
}
|
||||
|
||||
bool NativeWindow::ShouldCreateWebContents(
|
||||
content::WebContents* web_contents,
|
||||
int route_id,
|
||||
@@ -557,26 +542,7 @@ content::WebContents* NativeWindow::OpenURLFromTab(
|
||||
if (prevent_default)
|
||||
return nullptr;
|
||||
|
||||
content::NavigationController::LoadURLParams load_url_params(params.url);
|
||||
load_url_params.referrer = params.referrer;
|
||||
load_url_params.transition_type = params.transition;
|
||||
load_url_params.extra_headers = params.extra_headers;
|
||||
load_url_params.should_replace_current_entry =
|
||||
params.should_replace_current_entry;
|
||||
load_url_params.is_renderer_initiated = params.is_renderer_initiated;
|
||||
load_url_params.transferred_global_request_id =
|
||||
params.transferred_global_request_id;
|
||||
|
||||
source->GetController().LoadURLWithParams(load_url_params);
|
||||
return source;
|
||||
}
|
||||
|
||||
content::JavaScriptDialogManager* NativeWindow::GetJavaScriptDialogManager(
|
||||
content::WebContents* source) {
|
||||
if (!dialog_manager_)
|
||||
dialog_manager_.reset(new AtomJavaScriptDialogManager);
|
||||
|
||||
return dialog_manager_.get();
|
||||
return CommonWebContentsDelegate::OpenURLFromTab(source, params);
|
||||
}
|
||||
|
||||
void NativeWindow::RenderViewCreated(
|
||||
@@ -604,38 +570,6 @@ void NativeWindow::BeforeUnloadFired(content::WebContents* tab,
|
||||
}
|
||||
}
|
||||
|
||||
content::ColorChooser* NativeWindow::OpenColorChooser(
|
||||
content::WebContents* web_contents,
|
||||
SkColor color,
|
||||
const std::vector<content::ColorSuggestion>& suggestions) {
|
||||
return chrome::ShowColorChooser(web_contents, color);
|
||||
}
|
||||
|
||||
void NativeWindow::RunFileChooser(content::WebContents* web_contents,
|
||||
const content::FileChooserParams& params) {
|
||||
if (!web_dialog_helper_)
|
||||
web_dialog_helper_.reset(new WebDialogHelper(this));
|
||||
web_dialog_helper_->RunFileChooser(web_contents, params);
|
||||
}
|
||||
|
||||
void NativeWindow::EnumerateDirectory(content::WebContents* web_contents,
|
||||
int request_id,
|
||||
const base::FilePath& path) {
|
||||
if (!web_dialog_helper_)
|
||||
web_dialog_helper_.reset(new WebDialogHelper(this));
|
||||
web_dialog_helper_->EnumerateDirectory(web_contents, request_id, path);
|
||||
}
|
||||
|
||||
void NativeWindow::RequestToLockMouse(content::WebContents* web_contents,
|
||||
bool user_gesture,
|
||||
bool last_unlocked_by_target) {
|
||||
GetWebContents()->GotResponseToLockMouseRequest(true);
|
||||
}
|
||||
|
||||
bool NativeWindow::CanOverscrollContent() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void NativeWindow::ActivateContents(content::WebContents* contents) {
|
||||
FocusOnWebView();
|
||||
}
|
||||
@@ -646,8 +580,7 @@ void NativeWindow::DeactivateContents(content::WebContents* contents) {
|
||||
|
||||
void NativeWindow::MoveContents(content::WebContents* source,
|
||||
const gfx::Rect& pos) {
|
||||
SetPosition(pos.origin());
|
||||
SetSize(pos.size());
|
||||
SetBounds(pos);
|
||||
}
|
||||
|
||||
void NativeWindow::CloseContents(content::WebContents* source) {
|
||||
@@ -665,11 +598,6 @@ void NativeWindow::CloseContents(content::WebContents* source) {
|
||||
window_unresposive_closure_.Cancel();
|
||||
}
|
||||
|
||||
bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
|
||||
// Only popup window can use things like window.moveTo.
|
||||
return true;
|
||||
}
|
||||
|
||||
void NativeWindow::RendererUnresponsive(content::WebContents* source) {
|
||||
// Schedule the unresponsive shortly later, since we may receive the
|
||||
// responsive event soon. This could happen after the whole application had
|
||||
@@ -722,47 +650,18 @@ void NativeWindow::Observe(int type,
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindow::DevToolsSaveToFile(const std::string& url,
|
||||
const std::string& content,
|
||||
bool save_as) {
|
||||
base::FilePath path;
|
||||
PathsMap::iterator it = saved_files_.find(url);
|
||||
if (it != saved_files_.end() && !save_as) {
|
||||
path = it->second;
|
||||
} else {
|
||||
file_dialog::Filters filters;
|
||||
base::FilePath default_path(base::FilePath::FromUTF8Unsafe(url));
|
||||
if (!file_dialog::ShowSaveDialog(this, url, default_path, filters, &path)) {
|
||||
base::StringValue url_value(url);
|
||||
CallDevToolsFunction("DevToolsAPI.canceledSaveURL", &url_value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
saved_files_[url] = path;
|
||||
base::WriteFile(path, content.data(), content.size());
|
||||
|
||||
// Notify devtools.
|
||||
base::StringValue url_value(url);
|
||||
CallDevToolsFunction("DevToolsAPI.savedURL", &url_value);
|
||||
}
|
||||
|
||||
void NativeWindow::DevToolsAppendToFile(const std::string& url,
|
||||
const std::string& content) {
|
||||
PathsMap::iterator it = saved_files_.find(url);
|
||||
if (it == saved_files_.end())
|
||||
return;
|
||||
base::AppendToFile(it->second, content.data(), content.size());
|
||||
|
||||
// Notify devtools.
|
||||
base::StringValue url_value(url);
|
||||
CallDevToolsFunction("DevToolsAPI.appendedToURL", &url_value);
|
||||
}
|
||||
|
||||
void NativeWindow::DevToolsFocused() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsFocus());
|
||||
}
|
||||
|
||||
void NativeWindow::DevToolsOpened() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsOpened());
|
||||
}
|
||||
|
||||
void NativeWindow::DevToolsClosed() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsClosed());
|
||||
}
|
||||
|
||||
void NativeWindow::ScheduleUnresponsiveEvent(int ms) {
|
||||
if (!window_unresposive_closure_.IsCancelled())
|
||||
return;
|
||||
@@ -791,27 +690,4 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
|
||||
callback.Run(bitmap);
|
||||
}
|
||||
|
||||
void NativeWindow::CallDevToolsFunction(const std::string& function_name,
|
||||
const base::Value* arg1,
|
||||
const base::Value* arg2,
|
||||
const base::Value* arg3) {
|
||||
std::string params;
|
||||
if (arg1) {
|
||||
std::string json;
|
||||
base::JSONWriter::Write(arg1, &json);
|
||||
params.append(json);
|
||||
if (arg2) {
|
||||
base::JSONWriter::Write(arg2, &json);
|
||||
params.append(", " + json);
|
||||
if (arg3) {
|
||||
base::JSONWriter::Write(arg3, &json);
|
||||
params.append(", " + json);
|
||||
}
|
||||
}
|
||||
}
|
||||
base::string16 javascript =
|
||||
base::UTF8ToUTF16(function_name + "(" + params + ");");
|
||||
GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript(javascript);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -9,15 +9,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/common_web_contents_delegate.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "base/cancelable_callback.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "brightray/browser/default_web_contents_delegate.h"
|
||||
#include "brightray/browser/inspectable_web_contents_delegate.h"
|
||||
#include "brightray/browser/inspectable_web_contents_impl.h"
|
||||
#include "content/public/browser/notification_registrar.h"
|
||||
#include "content/public/browser/notification_observer.h"
|
||||
#include "content/public/browser/readback_types.h"
|
||||
@@ -50,12 +48,9 @@ class MenuModel;
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomJavaScriptDialogManager;
|
||||
struct DraggableRegion;
|
||||
class WebDialogHelper;
|
||||
|
||||
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
public brightray::InspectableWebContentsDelegate,
|
||||
class NativeWindow : public CommonWebContentsDelegate,
|
||||
public content::WebContentsObserver,
|
||||
public content::NotificationObserver {
|
||||
public:
|
||||
@@ -91,14 +86,13 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
// managing the window's live.
|
||||
static NativeWindow* Create(const mate::Dictionary& options);
|
||||
|
||||
// Find a window from its process id and routing id.
|
||||
static NativeWindow* FromRenderView(int process_id, int routing_id);
|
||||
// Find a window from its WebContents
|
||||
static NativeWindow* FromWebContents(content::WebContents* web_contents);
|
||||
|
||||
void InitFromOptions(const mate::Dictionary& options);
|
||||
|
||||
virtual void Close() = 0;
|
||||
virtual void CloseImmediately() = 0;
|
||||
virtual void Move(const gfx::Rect& pos) = 0;
|
||||
virtual void Focus(bool focus) = 0;
|
||||
virtual bool IsFocused() = 0;
|
||||
virtual void Show() = 0;
|
||||
@@ -112,9 +106,13 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
virtual void Restore() = 0;
|
||||
virtual bool IsMinimized() = 0;
|
||||
virtual void SetFullScreen(bool fullscreen) = 0;
|
||||
virtual bool IsFullscreen() = 0;
|
||||
virtual void SetSize(const gfx::Size& size) = 0;
|
||||
virtual gfx::Size GetSize() = 0;
|
||||
virtual bool IsFullscreen() const = 0;
|
||||
virtual void SetBounds(const gfx::Rect& bounds) = 0;
|
||||
virtual gfx::Rect GetBounds() = 0;
|
||||
virtual void SetSize(const gfx::Size& size);
|
||||
virtual gfx::Size GetSize();
|
||||
virtual void SetPosition(const gfx::Point& position);
|
||||
virtual gfx::Point GetPosition();
|
||||
virtual void SetContentSize(const gfx::Size& size) = 0;
|
||||
virtual gfx::Size GetContentSize() = 0;
|
||||
virtual void SetMinimumSize(const gfx::Size& size) = 0;
|
||||
@@ -126,8 +124,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
virtual void SetAlwaysOnTop(bool top) = 0;
|
||||
virtual bool IsAlwaysOnTop() = 0;
|
||||
virtual void Center() = 0;
|
||||
virtual void SetPosition(const gfx::Point& position) = 0;
|
||||
virtual gfx::Point GetPosition() = 0;
|
||||
virtual void SetTitle(const std::string& title) = 0;
|
||||
virtual std::string GetTitle() = 0;
|
||||
virtual void FlashFrame(bool flash) = 0;
|
||||
@@ -148,10 +144,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
virtual bool IsVisibleOnAllWorkspaces() = 0;
|
||||
|
||||
virtual bool IsClosed() const { return is_closed_; }
|
||||
virtual void OpenDevTools(bool can_dock);
|
||||
virtual void CloseDevTools();
|
||||
virtual bool IsDevToolsOpened();
|
||||
virtual void InspectElement(int x, int y);
|
||||
|
||||
virtual void FocusOnWebView();
|
||||
virtual void BlurWebView();
|
||||
@@ -179,20 +171,13 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
// Should be called by platform code when user want to close the window.
|
||||
virtual void CloseWebContents();
|
||||
|
||||
// Destroy the WebContents immediately.
|
||||
virtual void DestroyWebContents();
|
||||
|
||||
base::WeakPtr<NativeWindow> GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
content::WebContents* GetWebContents() const;
|
||||
content::WebContents* GetDevToolsWebContents() const;
|
||||
|
||||
// Called when renderer process is going to be started.
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id);
|
||||
void OverrideWebkitPrefs(const GURL& url, content::WebPreferences* prefs);
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line);
|
||||
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
||||
|
||||
// Public API used by platform-dependent delegates and observers to send UI
|
||||
// related notifications.
|
||||
@@ -203,8 +188,13 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
void NotifyWindowUnmaximize();
|
||||
void NotifyWindowMinimize();
|
||||
void NotifyWindowRestore();
|
||||
void NotifyWindowMove();
|
||||
void NotifyWindowResize();
|
||||
void NotifyWindowMoved();
|
||||
void NotifyWindowEnterFullScreen();
|
||||
void NotifyWindowLeaveFullScreen();
|
||||
void NotifyWindowEnterHtmlFullScreen();
|
||||
void NotifyWindowLeaveHtmlFullScreen();
|
||||
|
||||
void AddObserver(NativeWindowObserver* obs) {
|
||||
observers_.AddObserver(obs);
|
||||
@@ -214,6 +204,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
observers_.RemoveObserver(obs);
|
||||
}
|
||||
|
||||
brightray::InspectableWebContents* inspectable_web_contents() const {
|
||||
return managed_web_contents();
|
||||
}
|
||||
|
||||
bool has_frame() const { return has_frame_; }
|
||||
|
||||
void set_has_dialog_attached(bool has_dialog_attached) {
|
||||
@@ -224,11 +218,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
explicit NativeWindow(content::WebContents* web_contents,
|
||||
const mate::Dictionary& options);
|
||||
|
||||
brightray::InspectableWebContentsImpl* inspectable_web_contents() const {
|
||||
return static_cast<brightray::InspectableWebContentsImpl*>(
|
||||
inspectable_web_contents_.get());
|
||||
}
|
||||
|
||||
// Called when the window needs to update its draggable region.
|
||||
virtual void UpdateDraggableRegions(
|
||||
const std::vector<DraggableRegion>& regions) = 0;
|
||||
@@ -246,31 +235,14 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
content::WebContents* OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) override;
|
||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
||||
content::WebContents* source) override;
|
||||
void BeforeUnloadFired(content::WebContents* tab,
|
||||
bool proceed,
|
||||
bool* proceed_to_fire_unload) override;
|
||||
content::ColorChooser* OpenColorChooser(
|
||||
content::WebContents* web_contents,
|
||||
SkColor color,
|
||||
const std::vector<content::ColorSuggestion>& suggestions) override;
|
||||
void RunFileChooser(content::WebContents* web_contents,
|
||||
const content::FileChooserParams& params) override;
|
||||
void EnumerateDirectory(content::WebContents* web_contents,
|
||||
int request_id,
|
||||
const base::FilePath& path) override;
|
||||
void RequestToLockMouse(content::WebContents* web_contents,
|
||||
bool user_gesture,
|
||||
bool last_unlocked_by_target) override;
|
||||
bool CanOverscrollContent() const override;
|
||||
void ActivateContents(content::WebContents* contents) override;
|
||||
void DeactivateContents(content::WebContents* contents) override;
|
||||
void MoveContents(content::WebContents* source,
|
||||
const gfx::Rect& pos) override;
|
||||
void CloseContents(content::WebContents* source) override;
|
||||
bool IsPopupOrPanel(
|
||||
const content::WebContents* source) const override;
|
||||
void RendererUnresponsive(content::WebContents* source) override;
|
||||
void RendererResponsive(content::WebContents* source) override;
|
||||
|
||||
@@ -285,12 +257,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
const content::NotificationDetails& details) override;
|
||||
|
||||
// Implementations of brightray::InspectableWebContentsDelegate.
|
||||
void DevToolsSaveToFile(const std::string& url,
|
||||
const std::string& content,
|
||||
bool save_as) override;
|
||||
void DevToolsAppendToFile(const std::string& url,
|
||||
const std::string& content) override;
|
||||
void DevToolsFocused() override;
|
||||
void DevToolsOpened() override;
|
||||
void DevToolsClosed() override;
|
||||
|
||||
// Whether window has standard frame.
|
||||
bool has_frame_;
|
||||
@@ -311,12 +280,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
// Dispatch unresponsive event to observers.
|
||||
void NotifyWindowUnresponsive();
|
||||
|
||||
// Call a function in devtools.
|
||||
void CallDevToolsFunction(const std::string& function_name,
|
||||
const base::Value* arg1 = NULL,
|
||||
const base::Value* arg2 = NULL,
|
||||
const base::Value* arg3 = NULL);
|
||||
|
||||
// Called when CapturePage has done.
|
||||
void OnCapturePageDone(const CapturePageCallback& callback,
|
||||
const SkBitmap& bitmap,
|
||||
@@ -352,18 +315,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
|
||||
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
||||
|
||||
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||
|
||||
// Notice that inspectable_web_contents_ must be placed after dialog_manager_,
|
||||
// so we can make sure inspectable_web_contents_ is destroyed before
|
||||
// dialog_manager_, otherwise a crash would happen.
|
||||
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
||||
|
||||
// Maps url to file path, used by the file requests sent from devtools.
|
||||
typedef std::map<std::string, base::FilePath> PathsMap;
|
||||
PathsMap saved_files_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
|
||||
};
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ class NativeWindowMac : public NativeWindow {
|
||||
// NativeWindow implementation.
|
||||
void Close() override;
|
||||
void CloseImmediately() override;
|
||||
void Move(const gfx::Rect& pos) override;
|
||||
void Focus(bool focus) override;
|
||||
bool IsFocused() override;
|
||||
void Show() override;
|
||||
@@ -44,9 +43,9 @@ class NativeWindowMac : public NativeWindow {
|
||||
void Restore() override;
|
||||
bool IsMinimized() override;
|
||||
void SetFullScreen(bool fullscreen) override;
|
||||
bool IsFullscreen() override;
|
||||
void SetSize(const gfx::Size& size) override;
|
||||
gfx::Size GetSize() override;
|
||||
bool IsFullscreen() const override;
|
||||
void SetBounds(const gfx::Rect& bounds) override;
|
||||
gfx::Rect GetBounds() override;
|
||||
void SetContentSize(const gfx::Size& size) override;
|
||||
gfx::Size GetContentSize() override;
|
||||
void SetMinimumSize(const gfx::Size& size) override;
|
||||
@@ -58,8 +57,6 @@ class NativeWindowMac : public NativeWindow {
|
||||
void SetAlwaysOnTop(bool top) override;
|
||||
bool IsAlwaysOnTop() override;
|
||||
void Center() override;
|
||||
void SetPosition(const gfx::Point& position) override;
|
||||
gfx::Point GetPosition() override;
|
||||
void SetTitle(const std::string& title) override;
|
||||
std::string GetTitle() override;
|
||||
void FlashFrame(bool flash) override;
|
||||
|
||||
@@ -11,14 +11,14 @@
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "brightray/browser/inspectable_web_contents.h"
|
||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||
#include "content/public/browser/browser_accessibility_state.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "vendor/brightray/browser/inspectable_web_contents.h"
|
||||
#include "vendor/brightray/browser/inspectable_web_contents_view.h"
|
||||
|
||||
static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
|
||||
@@ -54,10 +54,8 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> {
|
||||
@private
|
||||
atom::NativeWindowMac* shell_;
|
||||
BOOL acceptsFirstMouse_;
|
||||
}
|
||||
- (id)initWithShell:(atom::NativeWindowMac*)shell;
|
||||
- (void)setAcceptsFirstMouse:(BOOL)accept;
|
||||
@end
|
||||
|
||||
@implementation AtomNSWindowDelegate
|
||||
@@ -65,15 +63,10 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
- (id)initWithShell:(atom::NativeWindowMac*)shell {
|
||||
if ((self = [super init])) {
|
||||
shell_ = shell;
|
||||
acceptsFirstMouse_ = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setAcceptsFirstMouse:(BOOL)accept {
|
||||
acceptsFirstMouse_ = accept;
|
||||
}
|
||||
|
||||
- (void)windowDidBecomeMain:(NSNotification*)notification {
|
||||
content::WebContents* web_contents = shell_->GetWebContents();
|
||||
if (!web_contents)
|
||||
@@ -105,6 +98,15 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
- (void)windowDidResize:(NSNotification*)notification {
|
||||
if (!shell_->has_frame())
|
||||
shell_->ClipWebView();
|
||||
|
||||
shell_->NotifyWindowResize();
|
||||
}
|
||||
|
||||
- (void)windowDidMove:(NSNotification*)notification {
|
||||
// TODO(zcbenz): Remove the alias after figuring out a proper
|
||||
// way to disptach move.
|
||||
shell_->NotifyWindowMove();
|
||||
shell_->NotifyWindowMoved();
|
||||
}
|
||||
|
||||
- (void)windowDidMiniaturize:(NSNotification*)notification {
|
||||
@@ -151,10 +153,6 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)acceptsFirstMouse:(NSEvent*)event {
|
||||
return acceptsFirstMouse_;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface AtomNSWindow : EventProcessingWindow {
|
||||
@@ -162,6 +160,8 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
atom::NativeWindowMac* shell_;
|
||||
bool enable_larger_than_screen_;
|
||||
}
|
||||
@property BOOL acceptsFirstMouse;
|
||||
@property BOOL disableAutoHideCursor;
|
||||
- (void)setShell:(atom::NativeWindowMac*)shell;
|
||||
- (void)setEnableLargerThanScreen:(bool)enable;
|
||||
@end
|
||||
@@ -184,16 +184,6 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
return [super constrainFrameRect:frameRect toScreen:screen];
|
||||
}
|
||||
|
||||
- (IBAction)reload:(id)sender {
|
||||
content::WebContents* web_contents = shell_->GetWebContents();
|
||||
content::NavigationController::LoadURLParams params(web_contents->GetURL());
|
||||
web_contents->GetController().LoadURLWithParams(params);
|
||||
}
|
||||
|
||||
- (IBAction)showDevTools:(id)sender {
|
||||
shell_->OpenDevTools(true);
|
||||
}
|
||||
|
||||
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
||||
if (![attribute isEqualToString:@"AXChildren"])
|
||||
return [super accessibilityAttributeValue:attribute];
|
||||
@@ -329,11 +319,18 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||
width,
|
||||
height);
|
||||
|
||||
bool useStandardWindow = true;
|
||||
options.Get(switches::kStandardWindow, &useStandardWindow);
|
||||
|
||||
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
|
||||
NSMiniaturizableWindowMask | NSResizableWindowMask;
|
||||
if (!useStandardWindow || transparent_ || !has_frame_) {
|
||||
styleMask |= NSTexturedBackgroundWindowMask;
|
||||
}
|
||||
|
||||
window_.reset([[AtomNSWindow alloc]
|
||||
initWithContentRect:cocoa_bounds
|
||||
styleMask:NSTitledWindowMask | NSClosableWindowMask |
|
||||
NSMiniaturizableWindowMask | NSResizableWindowMask |
|
||||
NSTexturedBackgroundWindowMask
|
||||
styleMask:styleMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES]);
|
||||
[window_ setShell:this];
|
||||
@@ -349,6 +346,10 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||
[window_ setBackgroundColor:[NSColor clearColor]];
|
||||
}
|
||||
|
||||
// Remove non-transparent corners, see http://git.io/vfonD.
|
||||
if (!has_frame_)
|
||||
[window_ setOpaque:NO];
|
||||
|
||||
// We will manage window's lifetime ourselves.
|
||||
[window_ setReleasedWhenClosed:NO];
|
||||
|
||||
@@ -361,7 +362,12 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||
// Enable the NSView to accept first mouse event.
|
||||
bool acceptsFirstMouse = false;
|
||||
options.Get(switches::kAcceptFirstMouse, &acceptsFirstMouse);
|
||||
[window_delegate_ setAcceptsFirstMouse:acceptsFirstMouse];
|
||||
[window_ setAcceptsFirstMouse:acceptsFirstMouse];
|
||||
|
||||
// Disable auto-hiding cursor.
|
||||
bool disableAutoHideCursor = false;
|
||||
options.Get(switches::kDisableAutoHideCursor, &disableAutoHideCursor);
|
||||
[window_ setDisableAutoHideCursor:disableAutoHideCursor];
|
||||
|
||||
// Disable fullscreen button when 'fullscreen' is specified to false.
|
||||
bool fullscreen;
|
||||
@@ -392,18 +398,6 @@ void NativeWindowMac::CloseImmediately() {
|
||||
[window_ close];
|
||||
}
|
||||
|
||||
void NativeWindowMac::Move(const gfx::Rect& pos) {
|
||||
NSRect cocoa_bounds = NSMakeRect(pos.x(), 0,
|
||||
pos.width(),
|
||||
pos.height());
|
||||
// Flip coordinates based on the primary screen.
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
cocoa_bounds.origin.y =
|
||||
NSHeight([screen frame]) - pos.height() - pos.y();
|
||||
|
||||
[window_ setFrame:cocoa_bounds display:YES];
|
||||
}
|
||||
|
||||
void NativeWindowMac::Focus(bool focus) {
|
||||
if (!IsVisible())
|
||||
return;
|
||||
@@ -476,22 +470,28 @@ void NativeWindowMac::SetFullScreen(bool fullscreen) {
|
||||
[window_ toggleFullScreen:nil];
|
||||
}
|
||||
|
||||
bool NativeWindowMac::IsFullscreen() {
|
||||
bool NativeWindowMac::IsFullscreen() const {
|
||||
return [window_ styleMask] & NSFullScreenWindowMask;
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetSize(const gfx::Size& size) {
|
||||
NSRect frame = [window_ frame];
|
||||
frame.origin.y -= size.height() - frame.size.height;
|
||||
frame.size.width = size.width();
|
||||
frame.size.height = size.height();
|
||||
void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
|
||||
NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0,
|
||||
bounds.width(),
|
||||
bounds.height());
|
||||
// Flip coordinates based on the primary screen.
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
cocoa_bounds.origin.y =
|
||||
NSHeight([screen frame]) - bounds.height() - bounds.y();
|
||||
|
||||
[window_ setFrame:frame display:YES];
|
||||
[window_ setFrame:cocoa_bounds display:YES];
|
||||
}
|
||||
|
||||
gfx::Size NativeWindowMac::GetSize() {
|
||||
gfx::Rect NativeWindowMac::GetBounds() {
|
||||
NSRect frame = [window_ frame];
|
||||
return gfx::Size(frame.size.width, frame.size.height);
|
||||
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
||||
return bounds;
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetContentSize(const gfx::Size& size) {
|
||||
@@ -564,18 +564,6 @@ void NativeWindowMac::Center() {
|
||||
[window_ center];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetPosition(const gfx::Point& position) {
|
||||
Move(gfx::Rect(position, GetSize()));
|
||||
}
|
||||
|
||||
gfx::Point NativeWindowMac::GetPosition() {
|
||||
NSRect frame = [window_ frame];
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
|
||||
return gfx::Point(frame.origin.x,
|
||||
NSHeight([screen frame]) - frame.origin.y - frame.size.height);
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetTitle(const std::string& title) {
|
||||
// We don't want the title to show in transparent window.
|
||||
if (transparent_)
|
||||
|
||||
@@ -47,11 +47,18 @@ class NativeWindowObserver {
|
||||
virtual void OnWindowUnmaximize() {}
|
||||
virtual void OnWindowMinimize() {}
|
||||
virtual void OnWindowRestore() {}
|
||||
virtual void OnWindowResize() {}
|
||||
virtual void OnWindowMove() {}
|
||||
virtual void OnWindowMoved() {}
|
||||
virtual void OnWindowEnterFullScreen() {}
|
||||
virtual void OnWindowLeaveFullScreen() {}
|
||||
virtual void OnWindowEnterHtmlFullScreen() {}
|
||||
virtual void OnWindowLeaveHtmlFullScreen() {}
|
||||
|
||||
// Called when devtools window gets focused.
|
||||
// Redirect devtools events.
|
||||
virtual void OnDevToolsFocus() {}
|
||||
virtual void OnDevToolsOpened() {}
|
||||
virtual void OnDevToolsClosed() {}
|
||||
|
||||
// Called when renderer is hung.
|
||||
virtual void OnRendererUnresponsive() {}
|
||||
|
||||
@@ -176,6 +176,7 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
|
||||
options.Get(switches::kWidth, &width);
|
||||
options.Get(switches::kHeight, &height);
|
||||
gfx::Rect bounds(0, 0, width, height);
|
||||
widget_size_ = bounds.size();
|
||||
|
||||
window_->AddObserver(this);
|
||||
|
||||
@@ -291,10 +292,6 @@ void NativeWindowViews::CloseImmediately() {
|
||||
window_->CloseNow();
|
||||
}
|
||||
|
||||
void NativeWindowViews::Move(const gfx::Rect& bounds) {
|
||||
window_->SetBounds(bounds);
|
||||
}
|
||||
|
||||
void NativeWindowViews::Focus(bool focus) {
|
||||
if (focus)
|
||||
window_->Activate();
|
||||
@@ -369,40 +366,41 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool NativeWindowViews::IsFullscreen() {
|
||||
bool NativeWindowViews::IsFullscreen() const {
|
||||
return window_->IsFullscreen();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetSize(const gfx::Size& size) {
|
||||
void NativeWindowViews::SetBounds(const gfx::Rect& bounds) {
|
||||
#if defined(USE_X11)
|
||||
// On Linux the minimum and maximum size should be updated with window size
|
||||
// when window is not resizable.
|
||||
if (!resizable_) {
|
||||
SetMaximumSize(size);
|
||||
SetMinimumSize(size);
|
||||
SetMaximumSize(bounds.size());
|
||||
SetMinimumSize(bounds.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
window_->SetSize(size);
|
||||
window_->SetBounds(bounds);
|
||||
}
|
||||
|
||||
gfx::Size NativeWindowViews::GetSize() {
|
||||
gfx::Rect NativeWindowViews::GetBounds() {
|
||||
#if defined(OS_WIN)
|
||||
if (IsMinimized())
|
||||
return window_->GetRestoredBounds().size();
|
||||
return window_->GetRestoredBounds();
|
||||
#endif
|
||||
|
||||
return window_->GetWindowBoundsInScreen().size();
|
||||
return window_->GetWindowBoundsInScreen();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetContentSize(const gfx::Size& size) {
|
||||
if (!has_frame_) {
|
||||
SetSize(size);
|
||||
NativeWindow::SetSize(size);
|
||||
return;
|
||||
}
|
||||
|
||||
gfx::Rect bounds = window_->GetWindowBoundsInScreen();
|
||||
SetSize(ContentBoundsToWindowBounds(gfx::Rect(bounds.origin(), size)).size());
|
||||
bounds.set_size(size);
|
||||
SetBounds(ContentBoundsToWindowBounds(bounds));
|
||||
}
|
||||
|
||||
gfx::Size NativeWindowViews::GetContentSize() {
|
||||
@@ -492,19 +490,6 @@ void NativeWindowViews::Center() {
|
||||
window_->CenterWindow(GetSize());
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetPosition(const gfx::Point& position) {
|
||||
window_->SetBounds(gfx::Rect(position, GetSize()));
|
||||
}
|
||||
|
||||
gfx::Point NativeWindowViews::GetPosition() {
|
||||
#if defined(OS_WIN)
|
||||
if (IsMinimized())
|
||||
return window_->GetRestoredBounds().origin();
|
||||
#endif
|
||||
|
||||
return window_->GetWindowBoundsInScreen().origin();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetTitle(const std::string& title) {
|
||||
title_ = title;
|
||||
window_->UpdateWindowTitle();
|
||||
@@ -556,6 +541,19 @@ bool NativeWindowViews::IsKiosk() {
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
|
||||
if (menu_model == nullptr) {
|
||||
// Remove accelerators
|
||||
accelerator_table_.clear();
|
||||
GetFocusManager()->UnregisterAccelerators(this);
|
||||
// and menu bar.
|
||||
#if defined(USE_X11)
|
||||
global_menu_bar_.reset();
|
||||
#endif
|
||||
SetMenuBarVisibility(false);
|
||||
menu_bar_.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterAccelerators(menu_model);
|
||||
|
||||
#if defined(USE_X11)
|
||||
@@ -728,7 +726,8 @@ void NativeWindowViews::OnWidgetActivationChanged(
|
||||
else
|
||||
NotifyWindowBlur();
|
||||
|
||||
if (active && GetWebContents() && !IsDevToolsOpened())
|
||||
if (active && GetWebContents() &&
|
||||
!inspectable_web_contents()->IsDevToolsViewShowing())
|
||||
GetWebContents()->Focus();
|
||||
|
||||
// Hide menu bar when window is blured.
|
||||
@@ -736,6 +735,17 @@ void NativeWindowViews::OnWidgetActivationChanged(
|
||||
SetMenuBarVisibility(false);
|
||||
}
|
||||
|
||||
void NativeWindowViews::OnWidgetBoundsChanged(
|
||||
views::Widget* widget, const gfx::Rect& bounds) {
|
||||
if (widget != window_.get())
|
||||
return;
|
||||
|
||||
if (widget_size_ != bounds.size()) {
|
||||
NotifyWindowResize();
|
||||
widget_size_ = bounds.size();
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowViews::DeleteDelegate() {
|
||||
NotifyWindowClosed();
|
||||
}
|
||||
@@ -823,6 +833,10 @@ views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView(
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::OnWidgetMove() {
|
||||
NotifyWindowMove();
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
|
||||
// Windows uses the 4 lower order bits of |command_id| for type-specific
|
||||
@@ -856,7 +870,8 @@ void NativeWindowViews::GetDevToolsWindowWMClass(
|
||||
}
|
||||
#endif
|
||||
|
||||
void NativeWindowViews::HandleMouseDown() {
|
||||
void NativeWindowViews::ActivateContents(content::WebContents* contents) {
|
||||
NativeWindow::ActivateContents(contents);
|
||||
// Hide menu bar when web view is clicked.
|
||||
if (menu_bar_autohide_ && menu_bar_visible_)
|
||||
SetMenuBarVisibility(false);
|
||||
|
||||
@@ -35,7 +35,6 @@ class NativeWindowViews : public NativeWindow,
|
||||
// NativeWindow:
|
||||
void Close() override;
|
||||
void CloseImmediately() override;
|
||||
void Move(const gfx::Rect& pos) override;
|
||||
void Focus(bool focus) override;
|
||||
bool IsFocused() override;
|
||||
void Show() override;
|
||||
@@ -49,9 +48,9 @@ class NativeWindowViews : public NativeWindow,
|
||||
void Restore() override;
|
||||
bool IsMinimized() override;
|
||||
void SetFullScreen(bool fullscreen) override;
|
||||
bool IsFullscreen() override;
|
||||
void SetSize(const gfx::Size& size) override;
|
||||
gfx::Size GetSize() override;
|
||||
bool IsFullscreen() const override;
|
||||
void SetBounds(const gfx::Rect& bounds) override;
|
||||
gfx::Rect GetBounds() override;
|
||||
void SetContentSize(const gfx::Size& size) override;
|
||||
gfx::Size GetContentSize() override;
|
||||
void SetMinimumSize(const gfx::Size& size) override;
|
||||
@@ -63,8 +62,6 @@ class NativeWindowViews : public NativeWindow,
|
||||
void SetAlwaysOnTop(bool top) override;
|
||||
bool IsAlwaysOnTop() override;
|
||||
void Center() override;
|
||||
void SetPosition(const gfx::Point& position) override;
|
||||
gfx::Point GetPosition() override;
|
||||
void SetTitle(const std::string& title) override;
|
||||
std::string GetTitle() override;
|
||||
void FlashFrame(bool flash) override;
|
||||
@@ -96,6 +93,8 @@ class NativeWindowViews : public NativeWindow,
|
||||
// views::WidgetObserver:
|
||||
void OnWidgetActivationChanged(
|
||||
views::Widget* widget, bool active) override;
|
||||
void OnWidgetBoundsChanged(
|
||||
views::Widget* widget, const gfx::Rect& bounds) override;
|
||||
|
||||
// views::WidgetDelegate:
|
||||
void DeleteDelegate() override;
|
||||
@@ -116,6 +115,7 @@ class NativeWindowViews : public NativeWindow,
|
||||
views::ClientView* CreateClientView(views::Widget* widget) override;
|
||||
views::NonClientFrameView* CreateNonClientFrameView(
|
||||
views::Widget* widget) override;
|
||||
void OnWidgetMove() override;
|
||||
#if defined(OS_WIN)
|
||||
bool ExecuteWindowsCommand(int command_id) override;
|
||||
#endif
|
||||
@@ -128,7 +128,7 @@ class NativeWindowViews : public NativeWindow,
|
||||
#endif
|
||||
|
||||
// content::WebContentsDelegate:
|
||||
void HandleMouseDown() override;
|
||||
void ActivateContents(content::WebContents* contents) override;
|
||||
void HandleKeyboardEvent(
|
||||
content::WebContents*,
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
@@ -176,6 +176,7 @@ class NativeWindowViews : public NativeWindow,
|
||||
std::string title_;
|
||||
gfx::Size minimum_size_;
|
||||
gfx::Size maximum_size_;
|
||||
gfx::Size widget_size_;
|
||||
|
||||
scoped_ptr<SkRegion> draggable_region_;
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "atom/browser/net/adapter_request_job.h"
|
||||
|
||||
#include "base/threading/sequenced_worker_pool.h"
|
||||
#include "atom/browser/net/url_request_buffer_job.h"
|
||||
#include "atom/browser/net/url_request_string_job.h"
|
||||
#include "atom/browser/net/asar/url_request_asar_job.h"
|
||||
#include "atom/common/asar/asar_util.h"
|
||||
#include "atom/browser/net/url_request_buffer_job.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/url_request/url_request_error_job.h"
|
||||
@@ -71,8 +71,6 @@ base::WeakPtr<AdapterRequestJob> AdapterRequestJob::GetWeakPtr() {
|
||||
}
|
||||
|
||||
void AdapterRequestJob::CreateErrorJobAndStart(int error_code) {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||
|
||||
real_job_ = new net::URLRequestErrorJob(
|
||||
request(), network_delegate(), error_code);
|
||||
real_job_->Start();
|
||||
@@ -81,25 +79,21 @@ void AdapterRequestJob::CreateErrorJobAndStart(int error_code) {
|
||||
void AdapterRequestJob::CreateStringJobAndStart(const std::string& mime_type,
|
||||
const std::string& charset,
|
||||
const std::string& data) {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||
|
||||
real_job_ = new URLRequestStringJob(
|
||||
request(), network_delegate(), mime_type, charset, data);
|
||||
real_job_->Start();
|
||||
}
|
||||
|
||||
void AdapterRequestJob::CreateBufferJobAndStart(const std::string& mime_type,
|
||||
const std::string& charset,
|
||||
v8::Local<v8::Object> buffer) {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||
|
||||
void AdapterRequestJob::CreateBufferJobAndStart(
|
||||
const std::string& mime_type,
|
||||
const std::string& charset,
|
||||
scoped_refptr<base::RefCountedBytes> data) {
|
||||
real_job_ = new URLRequestBufferJob(
|
||||
request(), network_delegate(), mime_type, charset, buffer);
|
||||
request(), network_delegate(), mime_type, charset, data);
|
||||
real_job_->Start();
|
||||
}
|
||||
|
||||
void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||
real_job_ = asar::CreateJobFromPath(
|
||||
path,
|
||||
request(),
|
||||
@@ -111,8 +105,6 @@ void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
|
||||
}
|
||||
|
||||
void AdapterRequestJob::CreateJobFromProtocolHandlerAndStart() {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||
DCHECK(protocol_handler_);
|
||||
real_job_ = protocol_handler_->MaybeCreateJob(request(),
|
||||
network_delegate());
|
||||
if (!real_job_.get())
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/ref_counted_memory.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "net/url_request/url_request_job.h"
|
||||
#include "net/url_request/url_request_job_factory.h"
|
||||
@@ -53,7 +54,7 @@ class AdapterRequestJob : public net::URLRequestJob {
|
||||
const std::string& data);
|
||||
void CreateBufferJobAndStart(const std::string& mime_type,
|
||||
const std::string& charset,
|
||||
v8::Local<v8::Object> buffer);
|
||||
scoped_refptr<base::RefCountedBytes> data);
|
||||
void CreateFileJobAndStart(const base::FilePath& path);
|
||||
void CreateJobFromProtocolHandlerAndStart();
|
||||
|
||||
|
||||
26
atom/browser/net/http_protocol_handler.cc
Normal file
26
atom/browser/net/http_protocol_handler.cc
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/net/http_protocol_handler.h"
|
||||
|
||||
#include "net/url_request/url_request_http_job.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
HttpProtocolHandler::HttpProtocolHandler(const std::string& scheme)
|
||||
: scheme_(scheme) {
|
||||
}
|
||||
|
||||
HttpProtocolHandler::~HttpProtocolHandler() {
|
||||
}
|
||||
|
||||
net::URLRequestJob* HttpProtocolHandler::MaybeCreateJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const {
|
||||
return net::URLRequestHttpJob::Factory(request,
|
||||
network_delegate,
|
||||
scheme_);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
30
atom/browser/net/http_protocol_handler.h
Normal file
30
atom/browser/net/http_protocol_handler.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_
|
||||
#define ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "net/url_request/url_request_job_factory.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class HttpProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
|
||||
public:
|
||||
explicit HttpProtocolHandler(const std::string&);
|
||||
virtual ~HttpProtocolHandler();
|
||||
|
||||
// net::URLRequestJobFactory::ProtocolHandler:
|
||||
net::URLRequestJob* MaybeCreateJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const override;
|
||||
|
||||
private:
|
||||
std::string scheme_;
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_
|
||||
@@ -10,18 +10,16 @@
|
||||
|
||||
namespace atom {
|
||||
|
||||
URLRequestBufferJob::URLRequestBufferJob(net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate,
|
||||
const std::string& mime_type,
|
||||
const std::string& charset,
|
||||
v8::Local<v8::Object> data)
|
||||
URLRequestBufferJob::URLRequestBufferJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate,
|
||||
const std::string& mime_type,
|
||||
const std::string& charset,
|
||||
scoped_refptr<base::RefCountedBytes> data)
|
||||
: net::URLRequestSimpleJob(request, network_delegate),
|
||||
mime_type_(mime_type),
|
||||
charset_(charset),
|
||||
buffer_data_(new base::RefCountedBytes()) {
|
||||
auto input = reinterpret_cast<const unsigned char*>(node::Buffer::Data(data));
|
||||
size_t length = node::Buffer::Length(data);
|
||||
buffer_data_->data().assign(input, input + length);
|
||||
buffer_data_(data) {
|
||||
}
|
||||
|
||||
int URLRequestBufferJob::GetRefCountedData(
|
||||
|
||||
@@ -19,7 +19,7 @@ class URLRequestBufferJob : public net::URLRequestSimpleJob {
|
||||
net::NetworkDelegate* network_delegate,
|
||||
const std::string& mime_type,
|
||||
const std::string& charset,
|
||||
v8::Local<v8::Object> buffer);
|
||||
scoped_refptr<base::RefCountedBytes> data);
|
||||
|
||||
// URLRequestSimpleJob:
|
||||
int GetRefCountedData(std::string* mime_type,
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/node_debugger.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "net/socket/tcp_listen_socket.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
// NodeDebugger is stored in Isolate's data, slots 0, 1, 3 have already been
|
||||
// taken by gin, blink and node, using 2 is a safe option for now.
|
||||
const int kIsolateSlot = 2;
|
||||
|
||||
const char* kContentLength = "Content-Length";
|
||||
|
||||
} // namespace
|
||||
|
||||
NodeDebugger::NodeDebugger(v8::Isolate* isolate)
|
||||
: isolate_(isolate),
|
||||
thread_("NodeDebugger"),
|
||||
content_length_(-1),
|
||||
weak_factory_(this) {
|
||||
bool use_debug_agent = false;
|
||||
int port = 5858;
|
||||
bool wait_for_connection = false;
|
||||
|
||||
std::string port_str;
|
||||
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
|
||||
if (cmd->HasSwitch("debug")) {
|
||||
use_debug_agent = true;
|
||||
port_str = cmd->GetSwitchValueASCII("debug");
|
||||
}
|
||||
if (cmd->HasSwitch("debug-brk")) {
|
||||
use_debug_agent = true;
|
||||
wait_for_connection = true;
|
||||
port_str = cmd->GetSwitchValueASCII("debug-brk");
|
||||
}
|
||||
|
||||
if (use_debug_agent) {
|
||||
if (!port_str.empty())
|
||||
base::StringToInt(port_str, &port);
|
||||
|
||||
isolate_->SetData(kIsolateSlot, this);
|
||||
v8::Debug::SetMessageHandler(DebugMessageHandler);
|
||||
|
||||
if (wait_for_connection)
|
||||
v8::Debug::DebugBreak(isolate_);
|
||||
|
||||
// Start a new IO thread.
|
||||
base::Thread::Options options;
|
||||
options.message_loop_type = base::MessageLoop::TYPE_IO;
|
||||
if (!thread_.StartWithOptions(options)) {
|
||||
LOG(ERROR) << "Unable to start debugger thread";
|
||||
return;
|
||||
}
|
||||
|
||||
// Start the server in new IO thread.
|
||||
thread_.message_loop()->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&NodeDebugger::StartServer, weak_factory_.GetWeakPtr(),
|
||||
port));
|
||||
}
|
||||
}
|
||||
|
||||
NodeDebugger::~NodeDebugger() {
|
||||
thread_.Stop();
|
||||
}
|
||||
|
||||
bool NodeDebugger::IsRunning() const {
|
||||
return thread_.IsRunning();
|
||||
}
|
||||
|
||||
void NodeDebugger::StartServer(int port) {
|
||||
server_ = net::TCPListenSocket::CreateAndListen("127.0.0.1", port, this);
|
||||
if (!server_) {
|
||||
LOG(ERROR) << "Cannot start debugger server";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void NodeDebugger::CloseSession() {
|
||||
accepted_socket_.reset();
|
||||
}
|
||||
|
||||
void NodeDebugger::OnMessage(const std::string& message) {
|
||||
if (message.find("\"type\":\"request\",\"command\":\"disconnect\"}") !=
|
||||
std::string::npos)
|
||||
CloseSession();
|
||||
|
||||
base::string16 message16 = base::UTF8ToUTF16(message);
|
||||
v8::Debug::SendCommand(
|
||||
isolate_,
|
||||
reinterpret_cast<const uint16_t*>(message16.data()), message16.size());
|
||||
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&v8::Debug::ProcessDebugMessages));
|
||||
}
|
||||
|
||||
void NodeDebugger::SendMessage(const std::string& message) {
|
||||
if (accepted_socket_) {
|
||||
std::string header = base::StringPrintf(
|
||||
"%s: %d\r\n\r\n", kContentLength, static_cast<int>(message.size()));
|
||||
accepted_socket_->Send(header);
|
||||
accepted_socket_->Send(message);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeDebugger::SendConnectMessage() {
|
||||
accepted_socket_->Send(base::StringPrintf(
|
||||
"Type: connect\r\n"
|
||||
"V8-Version: %s\r\n"
|
||||
"Protocol-Version: 1\r\n"
|
||||
"Embedding-Host: %s\r\n"
|
||||
"%s: 0\r\n",
|
||||
v8::V8::GetVersion(), ATOM_PRODUCT_NAME, kContentLength), true);
|
||||
}
|
||||
|
||||
// static
|
||||
void NodeDebugger::DebugMessageHandler(const v8::Debug::Message& message) {
|
||||
NodeDebugger* self = static_cast<NodeDebugger*>(
|
||||
message.GetIsolate()->GetData(kIsolateSlot));
|
||||
|
||||
if (self) {
|
||||
std::string message8(*v8::String::Utf8Value(message.GetJSON()));
|
||||
self->thread_.message_loop()->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&NodeDebugger::SendMessage, self->weak_factory_.GetWeakPtr(),
|
||||
message8));
|
||||
}
|
||||
}
|
||||
|
||||
void NodeDebugger::DidAccept(net::StreamListenSocket* server,
|
||||
scoped_ptr<net::StreamListenSocket> socket) {
|
||||
// Only accept one session.
|
||||
if (accepted_socket_) {
|
||||
socket->Send(std::string("Remote debugging session already active"), true);
|
||||
return;
|
||||
}
|
||||
|
||||
accepted_socket_ = socket.Pass();
|
||||
SendConnectMessage();
|
||||
}
|
||||
|
||||
void NodeDebugger::DidRead(net::StreamListenSocket* socket,
|
||||
const char* data,
|
||||
int len) {
|
||||
buffer_.append(data, len);
|
||||
|
||||
do {
|
||||
if (buffer_.size() == 0)
|
||||
return;
|
||||
|
||||
// Read the "Content-Length" header.
|
||||
if (content_length_ < 0) {
|
||||
size_t pos = buffer_.find("\r\n\r\n");
|
||||
if (pos == std::string::npos)
|
||||
return;
|
||||
|
||||
// We can be sure that the header is "Content-Length: xxx\r\n".
|
||||
std::string content_length = buffer_.substr(16, pos - 16);
|
||||
if (!base::StringToInt(content_length, &content_length_)) {
|
||||
DidClose(accepted_socket_.get());
|
||||
return;
|
||||
}
|
||||
|
||||
// Strip header from buffer.
|
||||
buffer_ = buffer_.substr(pos + 4);
|
||||
}
|
||||
|
||||
// Read the message.
|
||||
if (buffer_.size() >= static_cast<size_t>(content_length_)) {
|
||||
std::string message = buffer_.substr(0, content_length_);
|
||||
buffer_ = buffer_.substr(content_length_);
|
||||
|
||||
OnMessage(message);
|
||||
|
||||
// Get ready for next message.
|
||||
content_length_ = -1;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
void NodeDebugger::DidClose(net::StreamListenSocket* socket) {
|
||||
// If we lost the connection, then simulate a disconnect msg:
|
||||
OnMessage("{\"seq\":1,\"type\":\"request\",\"command\":\"disconnect\"}");
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
@@ -1,59 +0,0 @@
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_NODE_DEBUGGER_H_
|
||||
#define ATOM_BROWSER_NODE_DEBUGGER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "net/socket/stream_listen_socket.h"
|
||||
#include "v8/include/v8-debug.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
// Add support for node's "--debug" switch.
|
||||
class NodeDebugger : public net::StreamListenSocket::Delegate {
|
||||
public:
|
||||
explicit NodeDebugger(v8::Isolate* isolate);
|
||||
virtual ~NodeDebugger();
|
||||
|
||||
bool IsRunning() const;
|
||||
|
||||
private:
|
||||
void StartServer(int port);
|
||||
void CloseSession();
|
||||
void OnMessage(const std::string& message);
|
||||
void SendMessage(const std::string& message);
|
||||
void SendConnectMessage();
|
||||
|
||||
static void DebugMessageHandler(const v8::Debug::Message& message);
|
||||
|
||||
// net::StreamListenSocket::Delegate:
|
||||
void DidAccept(net::StreamListenSocket* server,
|
||||
scoped_ptr<net::StreamListenSocket> socket) override;
|
||||
void DidRead(net::StreamListenSocket* socket,
|
||||
const char* data,
|
||||
int len) override;
|
||||
void DidClose(net::StreamListenSocket* socket) override;
|
||||
|
||||
v8::Isolate* isolate_;
|
||||
|
||||
base::Thread thread_;
|
||||
scoped_ptr<net::StreamListenSocket> server_;
|
||||
scoped_ptr<net::StreamListenSocket> accepted_socket_;
|
||||
|
||||
std::string buffer_;
|
||||
int content_length_;
|
||||
|
||||
base::WeakPtrFactory<NodeDebugger> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NodeDebugger);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_NODE_DEBUGGER_H_
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>atom.icns</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>0.24.0</string>
|
||||
<string>0.28.1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.8.0</string>
|
||||
<key>NSMainNibFile</key>
|
||||
|
||||
@@ -50,8 +50,8 @@ END
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 0,24,0,0
|
||||
PRODUCTVERSION 0,24,0,0
|
||||
FILEVERSION 0,28,1,0
|
||||
PRODUCTVERSION 0,28,1,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -68,12 +68,12 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "GitHub, Inc."
|
||||
VALUE "FileDescription", "Electron"
|
||||
VALUE "FileVersion", "0.24.0"
|
||||
VALUE "FileVersion", "0.28.1"
|
||||
VALUE "InternalName", "electron.exe"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2015 GitHub, Inc. All rights reserved."
|
||||
VALUE "OriginalFilename", "electron.exe"
|
||||
VALUE "ProductName", "Electron"
|
||||
VALUE "ProductVersion", "0.24.0"
|
||||
VALUE "ProductVersion", "0.28.1"
|
||||
VALUE "SquirrelAwareVersion", "1"
|
||||
END
|
||||
END
|
||||
|
||||
@@ -109,8 +109,12 @@ bool StringToAccelerator(const std::string& description,
|
||||
modifiers |= ui::EF_SHIFT_DOWN;
|
||||
} else if (tokens[i] == "ctrl" || tokens[i] == "control") {
|
||||
modifiers |= ui::EF_CONTROL_DOWN;
|
||||
} else if (tokens[i] == "super") {
|
||||
modifiers |= ui::EF_COMMAND_DOWN;
|
||||
#if defined(OS_MACOSX)
|
||||
} else if (tokens[i] == "cmd" || tokens[i] == "command") {
|
||||
modifiers |= ui::EF_COMMAND_DOWN;
|
||||
#endif
|
||||
} else if (tokens[i] == "commandorcontrol" || tokens[i] == "cmdorctrl") {
|
||||
#if defined(OS_MACOSX)
|
||||
modifiers |= ui::EF_COMMAND_DOWN;
|
||||
@@ -171,7 +175,7 @@ bool StringToAccelerator(const std::string& description,
|
||||
} else if (tokens[i].size() > 1 && tokens[i][0] == 'f') {
|
||||
// F1 - F24.
|
||||
int n;
|
||||
if (base::StringToInt(tokens[i].c_str() + 1, &n)) {
|
||||
if (base::StringToInt(tokens[i].c_str() + 1, &n) && n > 0 && n < 25) {
|
||||
key = static_cast<ui::KeyboardCode>(ui::VKEY_F1 + n - 1);
|
||||
} else {
|
||||
LOG(WARNING) << tokens[i] << "is not available on keyboard";
|
||||
|
||||
@@ -93,12 +93,15 @@ class FileChooserDialog {
|
||||
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
|
||||
|
||||
if (!default_path.empty()) {
|
||||
if (base::DirectoryExists(default_path))
|
||||
if (base::DirectoryExists(default_path)) {
|
||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog_),
|
||||
default_path.value().c_str());
|
||||
else
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog_),
|
||||
default_path.value().c_str());
|
||||
} else {
|
||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog_),
|
||||
default_path.DirName().value().c_str());
|
||||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog_),
|
||||
default_path.BaseName().value().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (!filters.empty())
|
||||
|
||||
@@ -26,8 +26,8 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon,
|
||||
const base::string16& contents) {
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyClicked() {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked());
|
||||
void TrayIcon::NotifyClicked(const gfx::Rect& bounds) {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked(bounds));
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyDoubleClicked() {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "atom/browser/ui/tray_icon_observer.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "ui/base/models/simple_menu_model.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -50,7 +51,7 @@ class TrayIcon {
|
||||
|
||||
void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
|
||||
void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
|
||||
void NotifyClicked();
|
||||
void NotifyClicked(const gfx::Rect& = gfx::Rect());
|
||||
void NotifyDoubleClicked();
|
||||
void NotifyBalloonShow();
|
||||
void NotifyBalloonClicked();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "atom/browser/ui/cocoa/atom_menu_controller.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/gfx/screen.h"
|
||||
|
||||
@interface StatusItemController : NSObject {
|
||||
atom::TrayIconCocoa* trayIcon_; // weak
|
||||
@@ -25,7 +26,14 @@
|
||||
}
|
||||
|
||||
- (void)handleClick:(id)sender {
|
||||
trayIcon_->NotifyClicked();
|
||||
// Get the frame of the NSStatusItem.
|
||||
NSRect frame = [NSApp currentEvent].window.frame;
|
||||
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
|
||||
// Flip coordinates to gfx (0,0 in top-left corner) using current screen.
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
||||
|
||||
trayIcon_->NotifyClicked(bounds);
|
||||
}
|
||||
|
||||
- (void)handleDoubleClick:(id)sender {
|
||||
|
||||
@@ -42,6 +42,7 @@ void TrayIconGtk::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
}
|
||||
|
||||
void TrayIconGtk::OnClick() {
|
||||
NotifyClicked();
|
||||
}
|
||||
|
||||
bool TrayIconGtk::HasClickAction() {
|
||||
|
||||
@@ -5,11 +5,15 @@
|
||||
#ifndef ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_
|
||||
#define ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_
|
||||
|
||||
namespace gfx {
|
||||
class Rect;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class TrayIconObserver {
|
||||
public:
|
||||
virtual void OnClicked() {}
|
||||
virtual void OnClicked(const gfx::Rect&) {}
|
||||
virtual void OnDoubleClicked() {}
|
||||
virtual void OnBalloonShow() {}
|
||||
virtual void OnBalloonClicked() {}
|
||||
|
||||
@@ -49,7 +49,16 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
|
||||
bool left_mouse_click) {
|
||||
// Pass to the observer if appropriate.
|
||||
if (left_mouse_click) {
|
||||
NotifyClicked();
|
||||
NOTIFYICONIDENTIFIER icon_id;
|
||||
memset(&icon_id, 0, sizeof(NOTIFYICONIDENTIFIER));
|
||||
icon_id.uID = icon_id_;
|
||||
icon_id.hWnd = window_;
|
||||
icon_id.cbSize = sizeof(NOTIFYICONIDENTIFIER);
|
||||
|
||||
RECT rect = { 0 };
|
||||
Shell_NotifyIconGetRect(&icon_id, &rect);
|
||||
|
||||
NotifyClicked(gfx::Rect(rect));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,18 +10,30 @@
|
||||
|
||||
namespace atom {
|
||||
|
||||
// static
|
||||
bool WebViewManager::GetInfoForProcess(content::RenderProcessHost* process,
|
||||
WebViewInfo* info) {
|
||||
if (!process)
|
||||
return false;
|
||||
auto context = process->GetBrowserContext();
|
||||
namespace {
|
||||
|
||||
WebViewManager* GetManagerFromWebContents(
|
||||
const content::WebContents* web_contents) {
|
||||
auto context = web_contents->GetBrowserContext();
|
||||
if (!context)
|
||||
return false;
|
||||
auto manager = context->GetGuestManager();
|
||||
return nullptr;
|
||||
return static_cast<WebViewManager*>(context->GetGuestManager());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
bool WebViewManager::GetInfoForWebContents(
|
||||
const content::WebContents* web_contents, WebViewInfo* info) {
|
||||
auto manager = GetManagerFromWebContents(web_contents);
|
||||
if (!manager)
|
||||
return false;
|
||||
return static_cast<WebViewManager*>(manager)->GetInfo(process->GetID(), info);
|
||||
base::AutoLock auto_lock(manager->lock_);
|
||||
auto iter = manager->webview_info_map_.find(web_contents);
|
||||
if (iter == manager->webview_info_map_.end())
|
||||
return false;
|
||||
*info = iter->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
WebViewManager::WebViewManager(content::BrowserContext* context) {
|
||||
@@ -37,12 +49,11 @@ void WebViewManager::AddGuest(int guest_instance_id,
|
||||
const WebViewInfo& info) {
|
||||
base::AutoLock auto_lock(lock_);
|
||||
web_contents_embdder_map_[guest_instance_id] = { web_contents, embedder };
|
||||
|
||||
int guest_process_id = web_contents->GetRenderProcessHost()->GetID();
|
||||
webview_info_map_[guest_process_id] = info;
|
||||
webview_info_map_[web_contents] = info;
|
||||
|
||||
// Map the element in embedder to guest.
|
||||
ElementInstanceKey key(embedder, element_instance_id);
|
||||
int owner_process_id = embedder->GetRenderProcessHost()->GetID();
|
||||
ElementInstanceKey key(owner_process_id, element_instance_id);
|
||||
element_instance_id_to_guest_map_[key] = guest_instance_id;
|
||||
}
|
||||
|
||||
@@ -53,9 +64,7 @@ void WebViewManager::RemoveGuest(int guest_instance_id) {
|
||||
|
||||
auto web_contents = web_contents_embdder_map_[guest_instance_id].web_contents;
|
||||
web_contents_embdder_map_.erase(guest_instance_id);
|
||||
|
||||
int guest_process_id = web_contents->GetRenderProcessHost()->GetID();
|
||||
webview_info_map_.erase(guest_process_id);
|
||||
webview_info_map_.erase(web_contents);
|
||||
|
||||
// Remove the record of element in embedder too.
|
||||
for (const auto& element : element_instance_id_to_guest_map_)
|
||||
@@ -65,20 +74,10 @@ void WebViewManager::RemoveGuest(int guest_instance_id) {
|
||||
}
|
||||
}
|
||||
|
||||
bool WebViewManager::GetInfo(int guest_process_id, WebViewInfo* webview_info) {
|
||||
base::AutoLock auto_lock(lock_);
|
||||
WebViewInfoMap::iterator iter = webview_info_map_.find(guest_process_id);
|
||||
if (iter != webview_info_map_.end()) {
|
||||
*webview_info = iter->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
content::WebContents* WebViewManager::GetGuestByInstanceID(
|
||||
content::WebContents* embedder,
|
||||
int owner_process_id,
|
||||
int element_instance_id) {
|
||||
ElementInstanceKey key(embedder, element_instance_id);
|
||||
ElementInstanceKey key(owner_process_id, element_instance_id);
|
||||
if (!ContainsKey(element_instance_id_to_guest_map_, key))
|
||||
return nullptr;
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||
base::FilePath preload_script;
|
||||
};
|
||||
|
||||
// Finds the WebViewManager attached with |process| and returns the
|
||||
// Finds the WebViewManager attached with |web_contents| and returns the
|
||||
// WebViewInfo of it.
|
||||
static bool GetInfoForProcess(content::RenderProcessHost* process,
|
||||
WebViewInfo* info);
|
||||
static bool GetInfoForWebContents(const content::WebContents* web_contents,
|
||||
WebViewInfo* info);
|
||||
|
||||
explicit WebViewManager(content::BrowserContext* context);
|
||||
virtual ~WebViewManager();
|
||||
@@ -44,15 +44,10 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||
const WebViewInfo& info);
|
||||
void RemoveGuest(int guest_instance_id);
|
||||
|
||||
// Looks up the information for the embedder <webview> for a given render
|
||||
// view, if one exists. Called on the IO thread.
|
||||
bool GetInfo(int guest_process_id, WebViewInfo* webview_info);
|
||||
|
||||
protected:
|
||||
// content::BrowserPluginGuestManager:
|
||||
content::WebContents* GetGuestByInstanceID(
|
||||
content::WebContents* embedder_web_contents,
|
||||
int element_instance_id) override;
|
||||
content::WebContents* GetGuestByInstanceID(int owner_process_id,
|
||||
int element_instance_id) override;
|
||||
bool ForEachGuest(content::WebContents* embedder,
|
||||
const GuestCallback& callback) override;
|
||||
|
||||
@@ -65,30 +60,29 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||
std::map<int, WebContentsWithEmbedder> web_contents_embdder_map_;
|
||||
|
||||
struct ElementInstanceKey {
|
||||
content::WebContents* owner_web_contents;
|
||||
int embedder_process_id;
|
||||
int element_instance_id;
|
||||
|
||||
ElementInstanceKey(content::WebContents* owner_web_contents,
|
||||
int element_instance_id)
|
||||
: owner_web_contents(owner_web_contents),
|
||||
ElementInstanceKey(int embedder_process_id, int element_instance_id)
|
||||
: embedder_process_id(embedder_process_id),
|
||||
element_instance_id(element_instance_id) {}
|
||||
|
||||
bool operator<(const ElementInstanceKey& other) const {
|
||||
if (owner_web_contents != other.owner_web_contents)
|
||||
return owner_web_contents < other.owner_web_contents;
|
||||
if (embedder_process_id != other.embedder_process_id)
|
||||
return embedder_process_id < other.embedder_process_id;
|
||||
return element_instance_id < other.element_instance_id;
|
||||
}
|
||||
|
||||
bool operator==(const ElementInstanceKey& other) const {
|
||||
return (owner_web_contents == other.owner_web_contents) &&
|
||||
return (embedder_process_id == other.embedder_process_id) &&
|
||||
(element_instance_id == other.element_instance_id);
|
||||
}
|
||||
};
|
||||
// (web_contents, element_instance_id) => guest_instance_id
|
||||
// (embedder_process_id, element_instance_id) => guest_instance_id
|
||||
std::map<ElementInstanceKey, int> element_instance_id_to_guest_map_;
|
||||
|
||||
typedef std::map<int, WebViewInfo> WebViewInfoMap;
|
||||
// guest_process_id => (guest_instance_id, embedder, ...)
|
||||
typedef std::map<const content::WebContents*, WebViewInfo> WebViewInfoMap;
|
||||
// web_contents => (guest_instance_id, embedder, ...)
|
||||
WebViewInfoMap webview_info_map_;
|
||||
|
||||
base::Lock lock_;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace {
|
||||
|
||||
class Archive : public mate::Wrappable {
|
||||
public:
|
||||
static v8::Handle<v8::Value> Create(v8::Isolate* isolate,
|
||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
scoped_ptr<asar::Archive> archive(new asar::Archive(path));
|
||||
if (!archive->Init())
|
||||
@@ -34,7 +34,7 @@ class Archive : public mate::Wrappable {
|
||||
: archive_(archive.Pass()) {}
|
||||
|
||||
// Reads the offset and size of file.
|
||||
v8::Handle<v8::Value> GetFileInfo(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> GetFileInfo(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
asar::Archive::FileInfo info;
|
||||
if (!archive_ || !archive_->GetFileInfo(path, &info))
|
||||
@@ -47,7 +47,7 @@ class Archive : public mate::Wrappable {
|
||||
}
|
||||
|
||||
// Returns a fake result of fs.stat(path).
|
||||
v8::Handle<v8::Value> Stat(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> Stat(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
asar::Archive::Stats stats;
|
||||
if (!archive_ || !archive_->Stat(path, &stats))
|
||||
@@ -62,7 +62,7 @@ class Archive : public mate::Wrappable {
|
||||
}
|
||||
|
||||
// Returns all files under a directory.
|
||||
v8::Handle<v8::Value> Readdir(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> Readdir(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
std::vector<base::FilePath> files;
|
||||
if (!archive_ || !archive_->Readdir(path, &files))
|
||||
@@ -71,7 +71,7 @@ class Archive : public mate::Wrappable {
|
||||
}
|
||||
|
||||
// Returns the path of file with symbol link resolved.
|
||||
v8::Handle<v8::Value> Realpath(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> Realpath(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
base::FilePath realpath;
|
||||
if (!archive_ || !archive_->Realpath(path, &realpath))
|
||||
@@ -80,7 +80,7 @@ class Archive : public mate::Wrappable {
|
||||
}
|
||||
|
||||
// Copy the file out into a temporary file and returns the new path.
|
||||
v8::Handle<v8::Value> CopyFileOut(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> CopyFileOut(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
base::FilePath new_path;
|
||||
if (!archive_ || !archive_->CopyFileOut(path, &new_path))
|
||||
@@ -88,6 +88,13 @@ class Archive : public mate::Wrappable {
|
||||
return mate::ConvertToV8(isolate, new_path);
|
||||
}
|
||||
|
||||
// Return the file descriptor.
|
||||
int GetFD() const {
|
||||
if (!archive_)
|
||||
return -1;
|
||||
return archive_->GetFD();
|
||||
}
|
||||
|
||||
// Free the resources used by archive.
|
||||
void Destroy() {
|
||||
archive_.reset();
|
||||
@@ -102,6 +109,7 @@ class Archive : public mate::Wrappable {
|
||||
.SetMethod("readdir", &Archive::Readdir)
|
||||
.SetMethod("realpath", &Archive::Realpath)
|
||||
.SetMethod("copyFileOut", &Archive::CopyFileOut)
|
||||
.SetMethod("getFd", &Archive::GetFD)
|
||||
.SetMethod("destroy", &Archive::Destroy);
|
||||
}
|
||||
|
||||
@@ -112,8 +120,8 @@ class Archive : public mate::Wrappable {
|
||||
};
|
||||
|
||||
void InitAsarSupport(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> process,
|
||||
v8::Handle<v8::Value> require) {
|
||||
v8::Local<v8::Value> process,
|
||||
v8::Local<v8::Value> require) {
|
||||
// Evaluate asar_init.coffee.
|
||||
v8::Local<v8::Script> asar_init = v8::Script::Compile(v8::String::NewFromUtf8(
|
||||
isolate,
|
||||
@@ -123,8 +131,8 @@ void InitAsarSupport(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> result = asar_init->Run();
|
||||
|
||||
// Initialize asar support.
|
||||
base::Callback<void(v8::Handle<v8::Value>,
|
||||
v8::Handle<v8::Value>,
|
||||
base::Callback<void(v8::Local<v8::Value>,
|
||||
v8::Local<v8::Value>,
|
||||
std::string)> init;
|
||||
if (mate::ConvertFromV8(isolate, result, &init)) {
|
||||
init.Run(process,
|
||||
@@ -133,8 +141,8 @@ void InitAsarSupport(v8::Isolate* isolate,
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("createArchive", &Archive::Create);
|
||||
dict.SetMethod("initAsarSupport", &InitAsarSupport);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "atom/common/native_mate_converters/image_converter.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "native_mate/arguments.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/base/clipboard/clipboard.h"
|
||||
@@ -15,36 +16,32 @@
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<ui::ClipboardType> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
ui::ClipboardType* out) {
|
||||
std::string type;
|
||||
if (!Converter<std::string>::FromV8(isolate, val, &type))
|
||||
return false;
|
||||
|
||||
if (type == "selection")
|
||||
*out = ui::CLIPBOARD_TYPE_SELECTION;
|
||||
else
|
||||
*out = ui::CLIPBOARD_TYPE_COPY_PASTE;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
namespace {
|
||||
|
||||
bool Has(const std::string& format_string, ui::ClipboardType type) {
|
||||
ui::ClipboardType GetClipboardType(mate::Arguments* args) {
|
||||
std::string type;
|
||||
if (args->GetNext(&type) && type == "selection")
|
||||
return ui::CLIPBOARD_TYPE_SELECTION;
|
||||
else
|
||||
return ui::CLIPBOARD_TYPE_COPY_PASTE;
|
||||
}
|
||||
|
||||
std::vector<base::string16> AvailableFormats(mate::Arguments* args) {
|
||||
std::vector<base::string16> format_types;
|
||||
bool ignore;
|
||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||
clipboard->ReadAvailableTypes(GetClipboardType(args), &format_types, &ignore);
|
||||
return format_types;
|
||||
}
|
||||
|
||||
bool Has(const std::string& format_string, mate::Arguments* args) {
|
||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||
ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string));
|
||||
return clipboard->IsFormatAvailable(format, type);
|
||||
return clipboard->IsFormatAvailable(format, GetClipboardType(args));
|
||||
}
|
||||
|
||||
std::string Read(const std::string& format_string,
|
||||
ui::ClipboardType type) {
|
||||
mate::Arguments* args) {
|
||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||
ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string));
|
||||
|
||||
@@ -53,41 +50,62 @@ std::string Read(const std::string& format_string,
|
||||
return data;
|
||||
}
|
||||
|
||||
base::string16 ReadText(ui::ClipboardType type) {
|
||||
base::string16 ReadText(mate::Arguments* args) {
|
||||
base::string16 data;
|
||||
ui::Clipboard::GetForCurrentThread()->ReadText(type, &data);
|
||||
ui::Clipboard::GetForCurrentThread()->ReadText(GetClipboardType(args), &data);
|
||||
return data;
|
||||
}
|
||||
|
||||
void WriteText(const base::string16& text, ui::ClipboardType type) {
|
||||
ui::ScopedClipboardWriter writer(type);
|
||||
void WriteText(const base::string16& text, mate::Arguments* args) {
|
||||
ui::ScopedClipboardWriter writer(GetClipboardType(args));
|
||||
writer.WriteText(text);
|
||||
}
|
||||
|
||||
gfx::Image ReadImage(ui::ClipboardType type) {
|
||||
SkBitmap bitmap = ui::Clipboard::GetForCurrentThread()->ReadImage(type);
|
||||
base::string16 ReadHtml(mate::Arguments* args) {
|
||||
base::string16 data;
|
||||
base::string16 html;
|
||||
std::string url;
|
||||
uint32 start;
|
||||
uint32 end;
|
||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||
clipboard->ReadHTML(GetClipboardType(args), &html, &url, &start, &end);
|
||||
data = html.substr(start, end - start);
|
||||
return data;
|
||||
}
|
||||
|
||||
void WriteHtml(const base::string16& html, mate::Arguments* args) {
|
||||
ui::ScopedClipboardWriter writer(GetClipboardType(args));
|
||||
writer.WriteHTML(html, std::string());
|
||||
}
|
||||
|
||||
gfx::Image ReadImage(mate::Arguments* args) {
|
||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||
SkBitmap bitmap = clipboard->ReadImage(GetClipboardType(args));
|
||||
return gfx::Image::CreateFrom1xBitmap(bitmap);
|
||||
}
|
||||
|
||||
void WriteImage(const gfx::Image& image, ui::ClipboardType type) {
|
||||
ui::ScopedClipboardWriter writer(type);
|
||||
void WriteImage(const gfx::Image& image, mate::Arguments* args) {
|
||||
ui::ScopedClipboardWriter writer(GetClipboardType(args));
|
||||
writer.WriteImage(image.AsBitmap());
|
||||
}
|
||||
|
||||
void Clear(ui::ClipboardType type) {
|
||||
ui::Clipboard::GetForCurrentThread()->Clear(type);
|
||||
void Clear(mate::Arguments* args) {
|
||||
ui::Clipboard::GetForCurrentThread()->Clear(GetClipboardType(args));
|
||||
}
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("_has", &Has);
|
||||
dict.SetMethod("_read", &Read);
|
||||
dict.SetMethod("_readText", &ReadText);
|
||||
dict.SetMethod("_writeText", &WriteText);
|
||||
dict.SetMethod("_readImage", &ReadImage);
|
||||
dict.SetMethod("_writeImage", &WriteImage);
|
||||
dict.SetMethod("_clear", &Clear);
|
||||
dict.SetMethod("availableFormats", &AvailableFormats);
|
||||
dict.SetMethod("has", &Has);
|
||||
dict.SetMethod("read", &Read);
|
||||
dict.SetMethod("readText", &ReadText);
|
||||
dict.SetMethod("writeText", &WriteText);
|
||||
dict.SetMethod("readHtml", &ReadHtml);
|
||||
dict.SetMethod("writeHtml", &WriteHtml);
|
||||
dict.SetMethod("readImage", &ReadImage);
|
||||
dict.SetMethod("writeImage", &WriteImage);
|
||||
dict.SetMethod("clear", &Clear);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -11,37 +11,52 @@
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
using crash_reporter::CrashReporter;
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<std::map<std::string, std::string> > {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
v8::Local<v8::Value> val,
|
||||
std::map<std::string, std::string>* out) {
|
||||
if (!val->IsObject())
|
||||
return false;
|
||||
|
||||
v8::Handle<v8::Object> dict = val->ToObject();
|
||||
v8::Handle<v8::Array> keys = dict->GetOwnPropertyNames();
|
||||
v8::Local<v8::Object> dict = val->ToObject();
|
||||
v8::Local<v8::Array> keys = dict->GetOwnPropertyNames();
|
||||
for (uint32_t i = 0; i < keys->Length(); ++i) {
|
||||
v8::Handle<v8::Value> key = keys->Get(i);
|
||||
v8::Local<v8::Value> key = keys->Get(i);
|
||||
(*out)[V8ToString(key)] = V8ToString(dict->Get(key));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<CrashReporter::UploadReportResult> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const CrashReporter::UploadReportResult& reports) {
|
||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||
dict.Set("date", v8::Date::New(isolate, reports.first*1000.0));
|
||||
dict.Set("id", reports.second);
|
||||
return dict.GetHandle();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
using crash_reporter::CrashReporter;
|
||||
|
||||
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);
|
||||
auto report = base::Unretained(CrashReporter::GetInstance());
|
||||
dict.SetMethod("start",
|
||||
base::Bind(&CrashReporter::Start,
|
||||
base::Unretained(CrashReporter::GetInstance())));
|
||||
base::Bind(&CrashReporter::Start, report));
|
||||
dict.SetMethod("_getUploadedReports",
|
||||
base::Bind(&CrashReporter::GetUploadedReports, report));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -23,7 +23,7 @@ IDWeakMap::IDWeakMap()
|
||||
IDWeakMap::~IDWeakMap() {
|
||||
}
|
||||
|
||||
int32_t IDWeakMap::Add(v8::Isolate* isolate, v8::Handle<v8::Object> object) {
|
||||
int32_t IDWeakMap::Add(v8::Isolate* isolate, v8::Local<v8::Object> object) {
|
||||
int32_t key = GetNextID();
|
||||
object->SetHiddenValue(mate::StringToV8(isolate, "IDWeakMapKey"),
|
||||
mate::Converter<int32_t>::ToV8(isolate, key));
|
||||
@@ -33,9 +33,9 @@ int32_t IDWeakMap::Add(v8::Isolate* isolate, v8::Handle<v8::Object> object) {
|
||||
return key;
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> IDWeakMap::Get(v8::Isolate* isolate, int32_t key) {
|
||||
v8::Local<v8::Value> IDWeakMap::Get(v8::Isolate* isolate, int32_t key) {
|
||||
if (!Has(key)) {
|
||||
node::ThrowError("Invalid key");
|
||||
node::ThrowError(isolate, "Invalid key");
|
||||
return v8::Undefined(isolate);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ int IDWeakMap::GetNextID() {
|
||||
|
||||
// static
|
||||
void IDWeakMap::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype) {
|
||||
v8::Local<v8::ObjectTemplate> prototype) {
|
||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||
.SetMethod("add", &IDWeakMap::Add)
|
||||
.SetMethod("get", &IDWeakMap::Get)
|
||||
@@ -91,8 +91,8 @@ void IDWeakMap::WeakCallback(
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
using atom::api::IDWeakMap;
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<IDWeakMap>(
|
||||
|
||||
@@ -23,13 +23,13 @@ class IDWeakMap : public mate::Wrappable {
|
||||
IDWeakMap();
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype);
|
||||
v8::Local<v8::ObjectTemplate> prototype);
|
||||
|
||||
private:
|
||||
virtual ~IDWeakMap();
|
||||
|
||||
int32_t Add(v8::Isolate* isolate, v8::Handle<v8::Object> object);
|
||||
v8::Handle<v8::Value> Get(v8::Isolate* isolate, int32_t key);
|
||||
int32_t Add(v8::Isolate* isolate, v8::Local<v8::Object> object);
|
||||
v8::Local<v8::Value> Get(v8::Isolate* isolate, int32_t key);
|
||||
bool Has(int32_t key) const;
|
||||
std::vector<int32_t> Keys() const;
|
||||
void Remove(int32_t key);
|
||||
|
||||
@@ -145,14 +145,14 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
|
||||
isolate, v8::Local<v8::ObjectTemplate>::New(isolate, template_));
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
|
||||
v8::Local<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
|
||||
scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
|
||||
return node::Buffer::New(isolate,
|
||||
reinterpret_cast<const char*>(png->front()),
|
||||
png->size());
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||
std::vector<unsigned char> output;
|
||||
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
||||
return node::Buffer::New(isolate,
|
||||
@@ -225,7 +225,7 @@ mate::Handle<NativeImage> NativeImage::CreateFromPath(
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
|
||||
mate::Arguments* args, v8::Handle<v8::Value> buffer) {
|
||||
mate::Arguments* args, v8::Local<v8::Value> buffer) {
|
||||
double scale_factor = 1.;
|
||||
args->GetNext(&scale_factor);
|
||||
|
||||
@@ -258,8 +258,8 @@ mate::Handle<NativeImage> NativeImage::CreateFromDataURL(
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("createEmpty", &atom::api::NativeImage::CreateEmpty);
|
||||
dict.SetMethod("createFromPath", &atom::api::NativeImage::CreateFromPath);
|
||||
|
||||
@@ -41,7 +41,7 @@ class NativeImage : public mate::Wrappable {
|
||||
static mate::Handle<NativeImage> CreateFromPath(
|
||||
v8::Isolate* isolate, const base::FilePath& path);
|
||||
static mate::Handle<NativeImage> CreateFromBuffer(
|
||||
mate::Arguments* args, v8::Handle<v8::Value> buffer);
|
||||
mate::Arguments* args, v8::Local<v8::Value> buffer);
|
||||
static mate::Handle<NativeImage> CreateFromDataURL(
|
||||
v8::Isolate* isolate, const GURL& url);
|
||||
|
||||
@@ -59,8 +59,8 @@ class NativeImage : public mate::Wrappable {
|
||||
v8::Isolate* isolate) override;
|
||||
|
||||
private:
|
||||
v8::Handle<v8::Value> ToPNG(v8::Isolate* isolate);
|
||||
v8::Handle<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
||||
v8::Local<v8::Value> ToPNG(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
||||
std::string ToDataURL();
|
||||
bool IsEmpty();
|
||||
gfx::Size GetSize();
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("showItemInFolder", &platform_util::ShowItemInFolder);
|
||||
dict.SetMethod("openItem", &platform_util::OpenItem);
|
||||
|
||||
@@ -10,41 +10,40 @@
|
||||
|
||||
namespace {
|
||||
|
||||
v8::Handle<v8::Object> CreateObjectWithName(v8::Isolate* isolate,
|
||||
v8::Handle<v8::String> name) {
|
||||
v8::Local<v8::Object> CreateObjectWithName(v8::Isolate* isolate,
|
||||
v8::Local<v8::String> name) {
|
||||
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
|
||||
t->SetClassName(name);
|
||||
return t->GetFunction()->NewInstance();
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> GetHiddenValue(v8::Handle<v8::Object> object,
|
||||
v8::Handle<v8::String> key) {
|
||||
v8::Local<v8::Value> GetHiddenValue(v8::Local<v8::Object> object,
|
||||
v8::Local<v8::String> key) {
|
||||
return object->GetHiddenValue(key);
|
||||
}
|
||||
|
||||
void SetHiddenValue(v8::Handle<v8::Object> object,
|
||||
v8::Handle<v8::String> key,
|
||||
v8::Handle<v8::Value> value) {
|
||||
void SetHiddenValue(v8::Local<v8::Object> object,
|
||||
v8::Local<v8::String> key,
|
||||
v8::Local<v8::Value> value) {
|
||||
object->SetHiddenValue(key, value);
|
||||
}
|
||||
|
||||
int32_t GetObjectHash(v8::Handle<v8::Object> object) {
|
||||
int32_t GetObjectHash(v8::Local<v8::Object> object) {
|
||||
return object->GetIdentityHash();
|
||||
}
|
||||
|
||||
void SetDestructor(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Object> object,
|
||||
v8::Handle<v8::Function> callback) {
|
||||
v8::Local<v8::Object> object,
|
||||
v8::Local<v8::Function> callback) {
|
||||
atom::ObjectLifeMonitor::BindTo(isolate, object, callback);
|
||||
}
|
||||
|
||||
void TakeHeapSnapshot(v8::Isolate* isolate) {
|
||||
isolate->GetHeapProfiler()->TakeHeapSnapshot(
|
||||
mate::StringToV8(isolate, "test"));
|
||||
isolate->GetHeapProfiler()->TakeHeapSnapshot();
|
||||
}
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
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("createObjectWithName", &CreateObjectWithName);
|
||||
dict.SetMethod("getHiddenValue", &GetHiddenValue);
|
||||
|
||||
@@ -49,7 +49,7 @@ AtomBindings::~AtomBindings() {
|
||||
}
|
||||
|
||||
void AtomBindings::BindTo(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Object> process) {
|
||||
v8::Local<v8::Object> process) {
|
||||
v8::V8::SetFatalErrorHandler(FatalErrorCallback);
|
||||
|
||||
mate::Dictionary dict(isolate, process);
|
||||
|
||||
@@ -24,7 +24,7 @@ class AtomBindings {
|
||||
|
||||
// Add process.atomBinding function, which behaves like process.binding but
|
||||
// load native code from atom-shell instead.
|
||||
void BindTo(v8::Isolate* isolate, v8::Handle<v8::Object> process);
|
||||
void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);
|
||||
|
||||
private:
|
||||
void ActivateUVLoop(v8::Isolate* isolate);
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
binding = process.atomBinding 'clipboard'
|
||||
module.exports =
|
||||
has: (format, type='standard') -> binding._has format, type
|
||||
read: (format, type='standard') -> binding._read format, type
|
||||
readText: (type='standard') -> binding._readText type
|
||||
writeText: (text, type='standard') -> binding._writeText text, type
|
||||
readImage: (type='standard') -> binding._readImage type
|
||||
writeImage: (image, type='standard') -> binding._writeImage image, type
|
||||
clear: (type='standard') -> binding._clear type
|
||||
if process.platform is 'linux' and process.type is 'renderer'
|
||||
# On Linux we could not access clipboard in renderer process.
|
||||
module.exports = require('remote').require 'clipboard'
|
||||
else
|
||||
module.exports = process.atomBinding 'clipboard'
|
||||
|
||||
@@ -41,19 +41,22 @@ class CrashReporter
|
||||
start()
|
||||
|
||||
getLastCrashReport: ->
|
||||
reports = this.getUploadedReports()
|
||||
if reports.length > 0 then reports[0] else null
|
||||
|
||||
getUploadedReports: ->
|
||||
tmpdir =
|
||||
if process.platform is 'win32'
|
||||
os.tmpdir()
|
||||
else
|
||||
'/tmp'
|
||||
log = path.join tmpdir, "#{@productName} Crashes", 'uploads.log'
|
||||
try
|
||||
reports = String(fs.readFileSync(log)).split('\n')
|
||||
return null unless reports.length > 1
|
||||
[time, id] = reports[reports.length - 2].split ','
|
||||
return {date: new Date(parseInt(time) * 1000), id}
|
||||
catch e
|
||||
return null
|
||||
log =
|
||||
if process.platform is 'darwin'
|
||||
path.join tmpdir, "#{@productName} Crashes"
|
||||
else
|
||||
path.join tmpdir, "#{@productName} Crashes", 'uploads.log'
|
||||
binding._getUploadedReports log
|
||||
|
||||
|
||||
crashRepoter = new CrashReporter
|
||||
module.exports = crashRepoter
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user