mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
Compare commits
629 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b27abd2011 | ||
|
|
bf1a4e12f1 | ||
|
|
20acead8be | ||
|
|
d07482c5f6 | ||
|
|
26ac34d0e0 | ||
|
|
b7816d85a1 | ||
|
|
c99b20206c | ||
|
|
d97155d7b0 | ||
|
|
10af87008d | ||
|
|
ed633b3250 | ||
|
|
e0fddcb7ce | ||
|
|
aa55e397d4 | ||
|
|
7943f7f7eb | ||
|
|
869e086a41 | ||
|
|
a96618e5cd | ||
|
|
02b2459db6 | ||
|
|
bef6909218 | ||
|
|
1ade8dcee7 | ||
|
|
e1e1c173fe | ||
|
|
5ee805e451 | ||
|
|
f2b91d5e1d | ||
|
|
1cd3918494 | ||
|
|
cb8f975528 | ||
|
|
42afc071eb | ||
|
|
79d4724a15 | ||
|
|
e699cac92c | ||
|
|
a3d2a490da | ||
|
|
58795eaa7e | ||
|
|
9f29f66768 | ||
|
|
14d01544d4 | ||
|
|
cf7cf098d8 | ||
|
|
e9636bb87b | ||
|
|
c82f5c8da8 | ||
|
|
246a145930 | ||
|
|
c9371bceec | ||
|
|
bd1f0e78a8 | ||
|
|
90c24de0f0 | ||
|
|
5cb97545fd | ||
|
|
db8361a0a9 | ||
|
|
57bfc63d23 | ||
|
|
fbd74c0e2d | ||
|
|
993c52dcd5 | ||
|
|
f5a8ec0cd3 | ||
|
|
747698fe9b | ||
|
|
e0dae4054a | ||
|
|
070d26e68e | ||
|
|
e6830e9ac8 | ||
|
|
aba3b721c5 | ||
|
|
62fd76f7e4 | ||
|
|
66e96f69fc | ||
|
|
9a825c5cbd | ||
|
|
02bcdc1c19 | ||
|
|
f13d8407ee | ||
|
|
739c432c98 | ||
|
|
94084639f2 | ||
|
|
e6f748d77f | ||
|
|
212cd67f08 | ||
|
|
90480fff4e | ||
|
|
4a1b6d76b2 | ||
|
|
6d663d1d01 | ||
|
|
e5e94ed437 | ||
|
|
621867e518 | ||
|
|
716037544a | ||
|
|
b92d5071fa | ||
|
|
ef255db069 | ||
|
|
24f8c51959 | ||
|
|
4b20ac3dc6 | ||
|
|
34521e5880 | ||
|
|
45fb3ec41d | ||
|
|
caa0634df8 | ||
|
|
15a05b3639 | ||
|
|
edcae49e52 | ||
|
|
81283db2da | ||
|
|
f56d1ea7b4 | ||
|
|
fea5559fbc | ||
|
|
b360122b35 | ||
|
|
185d3a7c02 | ||
|
|
f90fb8cc72 | ||
|
|
111dcbac25 | ||
|
|
e28bdcdd46 | ||
|
|
395b0c4224 | ||
|
|
217b1afe87 | ||
|
|
8d8bfcd120 | ||
|
|
2637cafda5 | ||
|
|
c764b7b023 | ||
|
|
522ae765ea | ||
|
|
9cf3811a56 | ||
|
|
6d2cc8aedf | ||
|
|
058046304d | ||
|
|
7ff0e0214e | ||
|
|
2be5393768 | ||
|
|
b54caccb22 | ||
|
|
c499dfbb22 | ||
|
|
f6ba308ff8 | ||
|
|
10e195a444 | ||
|
|
490a12d38a | ||
|
|
e004d53d2a | ||
|
|
4788323582 | ||
|
|
80d574482e | ||
|
|
d1724ad733 | ||
|
|
1fbe05b2d5 | ||
|
|
c5212b36f7 | ||
|
|
033212841d | ||
|
|
22c5720aa2 | ||
|
|
f29c7164f3 | ||
|
|
013593ccf8 | ||
|
|
77724345c4 | ||
|
|
4c12a4369d | ||
|
|
a3a21b5b88 | ||
|
|
48d54e8d3a | ||
|
|
4ebe58df57 | ||
|
|
accd08a2bf | ||
|
|
1731d609b7 | ||
|
|
cf9f249f07 | ||
|
|
92cfd96933 | ||
|
|
6c3f065147 | ||
|
|
45f4a25ac9 | ||
|
|
f43c227806 | ||
|
|
490efe69f4 | ||
|
|
368d23ef5b | ||
|
|
5e99c8f280 | ||
|
|
914dce6cc2 | ||
|
|
c6697f5f07 | ||
|
|
b6b6fc3bfd | ||
|
|
de49498102 | ||
|
|
14c9a2a087 | ||
|
|
a4a390b2cc | ||
|
|
0f5a058bdd | ||
|
|
7d15aa2321 | ||
|
|
9b1bcf51c6 | ||
|
|
b710cc3063 | ||
|
|
1c91b4888a | ||
|
|
996e2bdc69 | ||
|
|
9ed6ad8165 | ||
|
|
c0cd8fca80 | ||
|
|
25f69df341 | ||
|
|
35e5c2172f | ||
|
|
41b6f682d8 | ||
|
|
0c21c863d7 | ||
|
|
c71aa0995a | ||
|
|
8359c8e194 | ||
|
|
209dcd1aca | ||
|
|
eaa5e136b6 | ||
|
|
89990ec037 | ||
|
|
cc9ff77dd2 | ||
|
|
f44be28309 | ||
|
|
7f4d00fac0 | ||
|
|
bdad1d1753 | ||
|
|
64ce44d341 | ||
|
|
6f41598962 | ||
|
|
9c92f2e692 | ||
|
|
fefeb39757 | ||
|
|
389e56ce36 | ||
|
|
94818aef26 | ||
|
|
e9b344b200 | ||
|
|
fb864a8f23 | ||
|
|
cf4c2d02f3 | ||
|
|
b3dc0bc57e | ||
|
|
0839915538 | ||
|
|
9e32570dfa | ||
|
|
404e08c0e7 | ||
|
|
10a8f3c884 | ||
|
|
9f8ad36f30 | ||
|
|
8a4e0a64cf | ||
|
|
db071f8d8e | ||
|
|
24b4fcea15 | ||
|
|
e110f5c37c | ||
|
|
1a93babdbc | ||
|
|
22e3b9df44 | ||
|
|
d596a7427e | ||
|
|
81170d81b3 | ||
|
|
e7825da0f8 | ||
|
|
f629fa7b27 | ||
|
|
04f1860bf5 | ||
|
|
69bcc8e831 | ||
|
|
194ed3884c | ||
|
|
d8447524cb | ||
|
|
915a6196cc | ||
|
|
623e3ebc03 | ||
|
|
485bd7bbd3 | ||
|
|
218d69d288 | ||
|
|
d63f44cd07 | ||
|
|
2d56067819 | ||
|
|
a96cde254b | ||
|
|
e214ce6bc4 | ||
|
|
1f08d50e98 | ||
|
|
07a8a50861 | ||
|
|
46ed83a057 | ||
|
|
e95c1256a0 | ||
|
|
c0955eaa90 | ||
|
|
58a38d90b8 | ||
|
|
4ccb0cccf3 | ||
|
|
4f43c41577 | ||
|
|
6336edbe92 | ||
|
|
ce793ec86d | ||
|
|
993f66bd02 | ||
|
|
39e75574f4 | ||
|
|
2d8fe489a7 | ||
|
|
5b167e3684 | ||
|
|
dacbf7a042 | ||
|
|
81599f1535 | ||
|
|
a22a5c67bd | ||
|
|
d34cff2eef | ||
|
|
c72d769ff0 | ||
|
|
97139b7487 | ||
|
|
d26dcd5501 | ||
|
|
380de24f2e | ||
|
|
e7c7e086b1 | ||
|
|
645f81effd | ||
|
|
f39224a56b | ||
|
|
0d19e772e6 | ||
|
|
2844d3b358 | ||
|
|
fe3489b383 | ||
|
|
f6ff97cbeb | ||
|
|
779e5c2ea5 | ||
|
|
0d957cc68e | ||
|
|
4b75b10542 | ||
|
|
b09252f13e | ||
|
|
b06d59fcb2 | ||
|
|
5162275b9b | ||
|
|
f82de6528b | ||
|
|
593dce23a5 | ||
|
|
ef417cb8c2 | ||
|
|
ab652b738c | ||
|
|
53b83eba8c | ||
|
|
cbe52c58ac | ||
|
|
19c8864c32 | ||
|
|
141894aacd | ||
|
|
cb9bdbf247 | ||
|
|
4b5dd2ed4b | ||
|
|
85afa851dd | ||
|
|
57acdc1bf6 | ||
|
|
ae76657e17 | ||
|
|
4ca6ac34ac | ||
|
|
e4a71b86df | ||
|
|
4dd7848084 | ||
|
|
a95679c212 | ||
|
|
b41d356143 | ||
|
|
feb6a93881 | ||
|
|
940b40439f | ||
|
|
ed07bd202f | ||
|
|
8c29ffd084 | ||
|
|
dba2fa31b6 | ||
|
|
2de80571d8 | ||
|
|
51acba594b | ||
|
|
a194d45dfa | ||
|
|
9356296a84 | ||
|
|
2fa0b1117c | ||
|
|
49814e1919 | ||
|
|
74da83a0bb | ||
|
|
643d1dcdd1 | ||
|
|
b717add81b | ||
|
|
c36c4e36c5 | ||
|
|
0b48c3ea90 | ||
|
|
68e28159bb | ||
|
|
69a89303d0 | ||
|
|
9e87037d34 | ||
|
|
7cd4d35778 | ||
|
|
8296178e33 | ||
|
|
32dff999a5 | ||
|
|
13e5cf32d5 | ||
|
|
11d9e522d5 | ||
|
|
4aac0d6d1c | ||
|
|
ddf4f14dba | ||
|
|
b560176aeb | ||
|
|
802f964cd3 | ||
|
|
0c349c047d | ||
|
|
d4e3c39fa5 | ||
|
|
3a177d55f8 | ||
|
|
b2741a8316 | ||
|
|
909f1bcf3c | ||
|
|
009412d738 | ||
|
|
33c622ec86 | ||
|
|
05b602d0ce | ||
|
|
8519ea3299 | ||
|
|
aad46b0894 | ||
|
|
5dfbaebd4c | ||
|
|
b2b70bb37c | ||
|
|
35d37c3463 | ||
|
|
eea82efbf8 | ||
|
|
7659edd139 | ||
|
|
9f8a5a7af3 | ||
|
|
cc4897f8c1 | ||
|
|
ee5335ca6e | ||
|
|
dde8e47add | ||
|
|
0040f07097 | ||
|
|
64b2c9b36c | ||
|
|
d754b2bda7 | ||
|
|
9dd68c7add | ||
|
|
1499d44584 | ||
|
|
039903c6b2 | ||
|
|
5df1716144 | ||
|
|
f6d6a12c1a | ||
|
|
e316e4a267 | ||
|
|
9d84f139eb | ||
|
|
ad70cb27bd | ||
|
|
98fec2f317 | ||
|
|
72fc1e8dc6 | ||
|
|
301014e4a6 | ||
|
|
927ec6ab7a | ||
|
|
37d45e2881 | ||
|
|
915c1b19d3 | ||
|
|
b87dfb964c | ||
|
|
885ac53a48 | ||
|
|
d77bf0440c | ||
|
|
5a0be6672d | ||
|
|
724cae7de1 | ||
|
|
6c9769999b | ||
|
|
2bf2ad094c | ||
|
|
3eaf0fe82b | ||
|
|
013e7fb611 | ||
|
|
e24976c59f | ||
|
|
e3ae062c5c | ||
|
|
5e6e173d59 | ||
|
|
3fcd571db0 | ||
|
|
988fa73696 | ||
|
|
3c412e1cb8 | ||
|
|
a579f58454 | ||
|
|
35e867820e | ||
|
|
a757c62da5 | ||
|
|
370dd26745 | ||
|
|
e20697b870 | ||
|
|
4d01aa2772 | ||
|
|
4a485f9819 | ||
|
|
cebafeae40 | ||
|
|
150739e19e | ||
|
|
38f83cacf9 | ||
|
|
fc8ff314e2 | ||
|
|
8acf96d268 | ||
|
|
c49a44f944 | ||
|
|
390b804ca0 | ||
|
|
05317ad81e | ||
|
|
d559275711 | ||
|
|
909ff085ac | ||
|
|
dbbfef38b1 | ||
|
|
4006b6407c | ||
|
|
c95a93ef1c | ||
|
|
e5e1e207b6 | ||
|
|
e0c469183d | ||
|
|
4d2e4ed573 | ||
|
|
0cab034dab | ||
|
|
9f9d209e3d | ||
|
|
8740147aa2 | ||
|
|
9b755620d3 | ||
|
|
fa287c2422 | ||
|
|
b6cded379e | ||
|
|
8199ad2ae6 | ||
|
|
0d09143a77 | ||
|
|
7081f7799b | ||
|
|
b6583635d4 | ||
|
|
b01db4aa09 | ||
|
|
6d712da7e3 | ||
|
|
9b71117171 | ||
|
|
50ea0f0b45 | ||
|
|
fa8e158587 | ||
|
|
2768b1ff64 | ||
|
|
b3770bc407 | ||
|
|
8f44046f9a | ||
|
|
a717235212 | ||
|
|
805215be78 | ||
|
|
e7fbe84644 | ||
|
|
9653f20995 | ||
|
|
e959a40b49 | ||
|
|
d9ce3f0ca3 | ||
|
|
d8f57a0ecc | ||
|
|
c5e0b65cc7 | ||
|
|
b5e82dac6f | ||
|
|
1381d16f9c | ||
|
|
268508764f | ||
|
|
34109fa741 | ||
|
|
925ff2da5b | ||
|
|
b8a6658ba9 | ||
|
|
4a4814b41c | ||
|
|
f952dae0d0 | ||
|
|
cba155bcfb | ||
|
|
0f714c81cd | ||
|
|
92b5dab3f9 | ||
|
|
6ca238852a | ||
|
|
d2368d2d3b | ||
|
|
88269a613a | ||
|
|
5696fe8ec8 | ||
|
|
ba439b6824 | ||
|
|
c8a8576970 | ||
|
|
67cbecaba0 | ||
|
|
ec1db0c7bb | ||
|
|
4330d67e0d | ||
|
|
db8de9e60d | ||
|
|
9c9a306095 | ||
|
|
bda317b000 | ||
|
|
700510d63a | ||
|
|
ab2714fda9 | ||
|
|
33b94edcf0 | ||
|
|
44d3e58ddb | ||
|
|
f08c3f9134 | ||
|
|
8de90db429 | ||
|
|
81241b38eb | ||
|
|
1c07b9c85b | ||
|
|
1199224086 | ||
|
|
add4e3c6f5 | ||
|
|
eb55f1cf47 | ||
|
|
8367071dc6 | ||
|
|
68ac6b0cbb | ||
|
|
7fb1cb5b3d | ||
|
|
19b25c0d83 | ||
|
|
fd806f81ce | ||
|
|
d515404abd | ||
|
|
4509056d5e | ||
|
|
f604525b98 | ||
|
|
3afbb66b92 | ||
|
|
fadfd74923 | ||
|
|
222f8e1028 | ||
|
|
e3b6ea62d6 | ||
|
|
3795cc58b0 | ||
|
|
ed7d430f2b | ||
|
|
20f21b707b | ||
|
|
a584ca3678 | ||
|
|
ca881c5aaf | ||
|
|
2832708618 | ||
|
|
b00e56f587 | ||
|
|
d64f43da65 | ||
|
|
3e6d8ddbbd | ||
|
|
533548fdc7 | ||
|
|
3b95f49a14 | ||
|
|
d9d1d03d4d | ||
|
|
9546120ce4 | ||
|
|
48a5591508 | ||
|
|
a413935e91 | ||
|
|
241b07f763 | ||
|
|
d874ba80db | ||
|
|
3e46363ae1 | ||
|
|
d4a46fa35f | ||
|
|
134f8236cc | ||
|
|
55003716aa | ||
|
|
fe88330e87 | ||
|
|
ed68bd18b8 | ||
|
|
45228493eb | ||
|
|
80fb44b926 | ||
|
|
aa8f5e54df | ||
|
|
8134585578 | ||
|
|
a59388ecdd | ||
|
|
8051ad8b2a | ||
|
|
0a937cd2be | ||
|
|
db11c631f6 | ||
|
|
90bfd4bf0f | ||
|
|
39b98b0e4d | ||
|
|
b6c2e7ef76 | ||
|
|
fe96a9de33 | ||
|
|
b80f109524 | ||
|
|
cd40bdbec8 | ||
|
|
1533600720 | ||
|
|
263c4b9ab4 | ||
|
|
f1e72914f5 | ||
|
|
400d5cef3f | ||
|
|
af531d685e | ||
|
|
eb5f1f78bf | ||
|
|
c81a4bcafc | ||
|
|
1beeda170c | ||
|
|
9ad81c054d | ||
|
|
5604e75886 | ||
|
|
2e7ef7ea44 | ||
|
|
a0867fa7c5 | ||
|
|
31f5855001 | ||
|
|
0b24883649 | ||
|
|
4fda81a0b4 | ||
|
|
17c0888932 | ||
|
|
d20ec6952a | ||
|
|
e43b3309af | ||
|
|
d0c1b63064 | ||
|
|
a98e26a307 | ||
|
|
57d06c5241 | ||
|
|
f28e4574b0 | ||
|
|
c9b284d7f7 | ||
|
|
99a510701d | ||
|
|
eb3ecab6a8 | ||
|
|
11b9a06639 | ||
|
|
87d5b72b76 | ||
|
|
c95869e515 | ||
|
|
c2f7920068 | ||
|
|
cb7196a9c1 | ||
|
|
7de0f71a75 | ||
|
|
8dcb3726f9 | ||
|
|
d934526bb3 | ||
|
|
cab546cbb7 | ||
|
|
058d0bbe19 | ||
|
|
a32669ac0d | ||
|
|
cc4b3e9e6f | ||
|
|
fdcad1066e | ||
|
|
41d43920f9 | ||
|
|
fecc90e67c | ||
|
|
6e3b3fa5a2 | ||
|
|
c12c0363a0 | ||
|
|
1207dfde4c | ||
|
|
0f617c3d3c | ||
|
|
7b71ae6824 | ||
|
|
cfae3cd3af | ||
|
|
f470d21a55 | ||
|
|
af0a5744f2 | ||
|
|
2bcb7393c4 | ||
|
|
60dcb0e67f | ||
|
|
c88b691db7 | ||
|
|
27f07974e0 | ||
|
|
a840799b46 | ||
|
|
c8ef79817a | ||
|
|
29abba824d | ||
|
|
6ccec45c61 | ||
|
|
1dabd20d99 | ||
|
|
fedb08899c | ||
|
|
b8bfe8a9ad | ||
|
|
a230daa998 | ||
|
|
ba41634ad6 | ||
|
|
e9536508a5 | ||
|
|
965f2b1b6b | ||
|
|
e25417ab31 | ||
|
|
48c227c263 | ||
|
|
cbd6541e9a | ||
|
|
2a9f5a5fb8 | ||
|
|
78afa29ade | ||
|
|
73bb05e530 | ||
|
|
8cc23aca8d | ||
|
|
f96c6e4bd7 | ||
|
|
3afb4e017c | ||
|
|
54ee12308d | ||
|
|
fd09f13c9b | ||
|
|
86dd8e2dfa | ||
|
|
1b70ca2098 | ||
|
|
e8d1c69ea8 | ||
|
|
1883da463f | ||
|
|
e9879a3e4b | ||
|
|
dec05988f4 | ||
|
|
4087062798 | ||
|
|
31135321c0 | ||
|
|
226cbda7a6 | ||
|
|
66ef1a067d | ||
|
|
8a7efcdcd2 | ||
|
|
adb8fb59bd | ||
|
|
0ca9e8ee82 | ||
|
|
e7647ba183 | ||
|
|
be6599807d | ||
|
|
a8ca0329b4 | ||
|
|
6d9a88f415 | ||
|
|
0018d4b705 | ||
|
|
72e8b2882f | ||
|
|
89539ca15e | ||
|
|
175d052a28 | ||
|
|
d1a93a5135 | ||
|
|
f96485f950 | ||
|
|
79dfb2d2f3 | ||
|
|
de7ff0f944 | ||
|
|
80c77ef3a8 | ||
|
|
cad9580796 | ||
|
|
253789353f | ||
|
|
73262be2c2 | ||
|
|
0ad4c3ca93 | ||
|
|
b26e3a9629 | ||
|
|
c55f6d82d8 | ||
|
|
4b90c02420 | ||
|
|
d4fb1c1f8c | ||
|
|
445fe158cc | ||
|
|
a696f06a23 | ||
|
|
c019f13e8c | ||
|
|
b4f00f3b40 | ||
|
|
f60d8066f8 | ||
|
|
b8d5aa586e | ||
|
|
eeff20f1bc | ||
|
|
9035ffff55 | ||
|
|
ca522f06d3 | ||
|
|
7f534652a6 | ||
|
|
b93564894c | ||
|
|
54b8a62920 | ||
|
|
bcfba96d29 | ||
|
|
8e21530550 | ||
|
|
a4f59bc04e | ||
|
|
a378a719e9 | ||
|
|
441ee0d978 | ||
|
|
8d7a59161a | ||
|
|
d175a99811 | ||
|
|
724b29d6d4 | ||
|
|
336908eba0 | ||
|
|
0f5d929c09 | ||
|
|
c4b0170a0a | ||
|
|
936860edd5 | ||
|
|
1cadc9221a | ||
|
|
4890eebd3a | ||
|
|
3a65942b97 | ||
|
|
e06c558a86 | ||
|
|
0a0a408bf8 | ||
|
|
c9702b56e2 | ||
|
|
279eb23b38 | ||
|
|
8eb650ce03 | ||
|
|
7f9ac88c31 | ||
|
|
424a00cf29 | ||
|
|
3c078b4dab | ||
|
|
8cc49ffa80 | ||
|
|
58a09f6495 | ||
|
|
c2885f77c9 | ||
|
|
5d5a3138bc | ||
|
|
09f9d0729c | ||
|
|
3d989b6736 | ||
|
|
daa00e6539 | ||
|
|
382dbb500c | ||
|
|
92d6fd641f | ||
|
|
f219e7f0dd | ||
|
|
8a9e1824c3 | ||
|
|
b139d97f3d | ||
|
|
d29efb7f81 | ||
|
|
53cedc6e5d | ||
|
|
4f4aabef7a | ||
|
|
a888e4b960 | ||
|
|
15c31ad1ba | ||
|
|
196be5291d | ||
|
|
fe9f94555b | ||
|
|
47e0a61dd8 | ||
|
|
5ba324ca9a | ||
|
|
0721b34847 | ||
|
|
dc257f1f86 | ||
|
|
dfe111b95a | ||
|
|
a76ae8cd35 | ||
|
|
866e20b4be | ||
|
|
d25645ba67 | ||
|
|
ad1efa67bc | ||
|
|
cbb14f5ca2 | ||
|
|
a8cd101ff5 | ||
|
|
009e0790fe | ||
|
|
d31ebb71db | ||
|
|
2125a0be82 | ||
|
|
6dc01945af | ||
|
|
28b9df24a6 | ||
|
|
58c56ce7ae | ||
|
|
66983c7f67 |
@@ -1,4 +1,8 @@
|
||||
language: objective-c
|
||||
language: cpp
|
||||
compiler: clang
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
notifications:
|
||||
email:
|
||||
@@ -6,3 +10,6 @@ notifications:
|
||||
on_failure: change
|
||||
|
||||
script: './script/cibuild'
|
||||
|
||||
git:
|
||||
depth: 10
|
||||
|
||||
28
appveyor.yml
Normal file
28
appveyor.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
# appveyor file
|
||||
# http://www.appveyor.com/docs/appveyor-yml
|
||||
version: "{build}"
|
||||
|
||||
init:
|
||||
- git config --global core.autocrlf input
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: 0.10
|
||||
|
||||
platform:
|
||||
- x86
|
||||
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
- cmd: SET PATH=C:\Program Files (x86)\MSBuild\12.0\bin\;%PATH%
|
||||
- cmd: SET PATH=C:\python27;%PATH%
|
||||
- cmd: python script/bootstrap.py
|
||||
- cmd: python script/build.py -c Debug
|
||||
|
||||
test_script:
|
||||
- node --version
|
||||
- npm --version
|
||||
- cmd: python script/cpplint.py
|
||||
- cmd: python script/coffeelint.py
|
||||
|
||||
build: off
|
||||
187
atom.gyp
187
atom.gyp
@@ -28,6 +28,9 @@
|
||||
'atom/browser/api/lib/protocol.coffee',
|
||||
'atom/browser/api/lib/tray.coffee',
|
||||
'atom/browser/api/lib/web-contents.coffee',
|
||||
'atom/browser/lib/chrome-extension.coffee',
|
||||
'atom/browser/lib/guest-view-manager.coffee',
|
||||
'atom/browser/lib/guest-window-manager.coffee',
|
||||
'atom/browser/lib/init.coffee',
|
||||
'atom/browser/lib/objects-registry.coffee',
|
||||
'atom/browser/lib/rpc-server.coffee',
|
||||
@@ -35,17 +38,24 @@
|
||||
'atom/common/api/lib/clipboard.coffee',
|
||||
'atom/common/api/lib/crash-reporter.coffee',
|
||||
'atom/common/api/lib/id-weak-map.coffee',
|
||||
'atom/common/api/lib/original-fs.coffee',
|
||||
'atom/common/api/lib/screen.coffee',
|
||||
'atom/common/api/lib/shell.coffee',
|
||||
'atom/common/lib/init.coffee',
|
||||
'atom/common/lib/asar.coffee',
|
||||
'atom/renderer/lib/chrome-api.coffee',
|
||||
'atom/renderer/lib/guest-view-internal.coffee',
|
||||
'atom/renderer/lib/init.coffee',
|
||||
'atom/renderer/lib/inspector.coffee',
|
||||
'atom/renderer/lib/override.coffee',
|
||||
'atom/renderer/lib/web-view.coffee',
|
||||
'atom/renderer/api/lib/ipc.coffee',
|
||||
'atom/renderer/api/lib/remote.coffee',
|
||||
'atom/renderer/api/lib/web-view.coffee',
|
||||
'atom/renderer/api/lib/web-frame.coffee',
|
||||
],
|
||||
'lib_sources': [
|
||||
'atom/app/atom_content_client.cc',
|
||||
'atom/app/atom_content_client.h',
|
||||
'atom/app/atom_main_delegate.cc',
|
||||
'atom/app/atom_main_delegate.h',
|
||||
'atom/app/atom_main_delegate_mac.mm',
|
||||
@@ -83,15 +93,20 @@
|
||||
'atom/browser/auto_updater_linux.cc',
|
||||
'atom/browser/auto_updater_mac.mm',
|
||||
'atom/browser/auto_updater_win.cc',
|
||||
'atom/browser/atom_access_token_store.cc',
|
||||
'atom/browser/atom_access_token_store.h',
|
||||
'atom/browser/atom_browser_client.cc',
|
||||
'atom/browser/atom_browser_client.h',
|
||||
'atom/browser/atom_browser_context.cc',
|
||||
'atom/browser/atom_browser_context.h',
|
||||
'atom/browser/atom_browser_main_parts.cc',
|
||||
'atom/browser/atom_browser_main_parts.h',
|
||||
'atom/browser/atom_browser_main_parts_linux.cc',
|
||||
'atom/browser/atom_browser_main_parts_mac.mm',
|
||||
'atom/browser/atom_javascript_dialog_manager.cc',
|
||||
'atom/browser/atom_javascript_dialog_manager.h',
|
||||
'atom/browser/atom_speech_recognition_manager_delegate.cc',
|
||||
'atom/browser/atom_speech_recognition_manager_delegate.h',
|
||||
'atom/browser/browser.cc',
|
||||
'atom/browser/browser.h',
|
||||
'atom/browser/browser_linux.cc',
|
||||
@@ -113,12 +128,16 @@
|
||||
'atom/browser/native_window_observer.h',
|
||||
'atom/browser/net/adapter_request_job.cc',
|
||||
'atom/browser/net/adapter_request_job.h',
|
||||
'atom/browser/net/atom_url_request_context_getter.cc',
|
||||
'atom/browser/net/atom_url_request_context_getter.h',
|
||||
'atom/browser/net/asar/asar_protocol_handler.cc',
|
||||
'atom/browser/net/asar/asar_protocol_handler.h',
|
||||
'atom/browser/net/asar/url_request_asar_job.cc',
|
||||
'atom/browser/net/asar/url_request_asar_job.h',
|
||||
'atom/browser/net/atom_url_request_job_factory.cc',
|
||||
'atom/browser/net/atom_url_request_job_factory.h',
|
||||
'atom/browser/net/url_request_string_job.cc',
|
||||
'atom/browser/net/url_request_string_job.h',
|
||||
'atom/browser/node_debugger.cc',
|
||||
'atom/browser/node_debugger.h',
|
||||
'atom/browser/ui/accelerator_util.cc',
|
||||
'atom/browser/ui/accelerator_util.h',
|
||||
'atom/browser/ui/accelerator_util_mac.mm',
|
||||
@@ -152,17 +171,27 @@
|
||||
'atom/browser/ui/views/menu_delegate.h',
|
||||
'atom/browser/ui/views/menu_layout.cc',
|
||||
'atom/browser/ui/views/menu_layout.h',
|
||||
'atom/browser/ui/views/submenu_button.cc',
|
||||
'atom/browser/ui/views/submenu_button.h',
|
||||
'atom/browser/ui/views/win_frame_view.cc',
|
||||
'atom/browser/ui/views/win_frame_view.h',
|
||||
'atom/browser/ui/win/notify_icon_host.cc',
|
||||
'atom/browser/ui/win/notify_icon_host.h',
|
||||
'atom/browser/ui/win/notify_icon.cc',
|
||||
'atom/browser/ui/win/notify_icon.h',
|
||||
'atom/browser/ui/x/x_window_utils.cc',
|
||||
'atom/browser/ui/x/x_window_utils.h',
|
||||
'atom/browser/web_view/web_view_manager.cc',
|
||||
'atom/browser/web_view/web_view_manager.h',
|
||||
'atom/browser/web_view/web_view_renderer_state.cc',
|
||||
'atom/browser/web_view/web_view_renderer_state.h',
|
||||
'atom/browser/web_dialog_helper.cc',
|
||||
'atom/browser/web_dialog_helper.h',
|
||||
'atom/browser/window_list.cc',
|
||||
'atom/browser/window_list.h',
|
||||
'atom/browser/window_list_observer.h',
|
||||
'atom/common/api/api_messages.cc',
|
||||
'atom/common/api/api_messages.h',
|
||||
'atom/common/api/atom_api_asar.cc',
|
||||
'atom/common/api/atom_api_clipboard.cc',
|
||||
'atom/common/api/atom_api_crash_reporter.cc',
|
||||
'atom/common/api/atom_api_id_weak_map.cc',
|
||||
@@ -175,8 +204,12 @@
|
||||
'atom/common/api/atom_bindings.h',
|
||||
'atom/common/api/object_life_monitor.cc',
|
||||
'atom/common/api/object_life_monitor.h',
|
||||
'atom/common/browser_v8_locker.cc',
|
||||
'atom/common/browser_v8_locker.h',
|
||||
'atom/common/asar/archive.cc',
|
||||
'atom/common/asar/archive.h',
|
||||
'atom/common/asar/scoped_temporary_file.cc',
|
||||
'atom/common/asar/scoped_temporary_file.h',
|
||||
'atom/common/common_message_generator.cc',
|
||||
'atom/common/common_message_generator.h',
|
||||
'atom/common/crash_reporter/crash_reporter.cc',
|
||||
'atom/common/crash_reporter/crash_reporter.h',
|
||||
'atom/common/crash_reporter/crash_reporter_linux.cc',
|
||||
@@ -193,9 +226,12 @@
|
||||
'atom/common/crash_reporter/win/crash_service_main.h',
|
||||
'atom/common/draggable_region.cc',
|
||||
'atom/common/draggable_region.h',
|
||||
'atom/common/google_api_key.h',
|
||||
'atom/common/linux/application_info.cc',
|
||||
'atom/common/native_mate_converters/accelerator_converter.cc',
|
||||
'atom/common/native_mate_converters/accelerator_converter.h',
|
||||
'atom/common/native_mate_converters/file_path_converter.h',
|
||||
'atom/common/native_mate_converters/function_converter.h',
|
||||
'atom/common/native_mate_converters/gfx_converter.h',
|
||||
'atom/common/native_mate_converters/gurl_converter.h',
|
||||
'atom/common/native_mate_converters/image_converter.cc',
|
||||
'atom/common/native_mate_converters/image_converter.h',
|
||||
@@ -222,12 +258,15 @@
|
||||
'atom/renderer/api/atom_api_renderer_ipc.cc',
|
||||
'atom/renderer/api/atom_renderer_bindings.cc',
|
||||
'atom/renderer/api/atom_renderer_bindings.h',
|
||||
'atom/renderer/api/atom_api_web_view.cc',
|
||||
'atom/renderer/api/atom_api_web_view.h',
|
||||
'atom/renderer/api/atom_api_web_frame.cc',
|
||||
'atom/renderer/api/atom_api_web_frame.h',
|
||||
'atom/renderer/atom_render_view_observer.cc',
|
||||
'atom/renderer/atom_render_view_observer.h',
|
||||
'atom/renderer/atom_renderer_client.cc',
|
||||
'atom/renderer/atom_renderer_client.h',
|
||||
'chromium_src/chrome/browser/browser_process.cc',
|
||||
'chromium_src/chrome/browser/browser_process.h',
|
||||
'chromium_src/chrome/browser/chrome_notification_types.h',
|
||||
'chromium_src/chrome/browser/extensions/global_shortcut_listener.cc',
|
||||
'chromium_src/chrome/browser/extensions/global_shortcut_listener.h',
|
||||
'chromium_src/chrome/browser/extensions/global_shortcut_listener_mac.mm',
|
||||
@@ -236,6 +275,38 @@
|
||||
'chromium_src/chrome/browser/extensions/global_shortcut_listener_x11.h',
|
||||
'chromium_src/chrome/browser/extensions/global_shortcut_listener_win.cc',
|
||||
'chromium_src/chrome/browser/extensions/global_shortcut_listener_win.h',
|
||||
'chromium_src/chrome/browser/printing/print_job.cc',
|
||||
'chromium_src/chrome/browser/printing/print_job.h',
|
||||
'chromium_src/chrome/browser/printing/print_job_manager.cc',
|
||||
'chromium_src/chrome/browser/printing/print_job_manager.h',
|
||||
'chromium_src/chrome/browser/printing/print_job_worker.cc',
|
||||
'chromium_src/chrome/browser/printing/print_job_worker.h',
|
||||
'chromium_src/chrome/browser/printing/print_job_worker_owner.h',
|
||||
'chromium_src/chrome/browser/printing/print_view_manager_base.cc',
|
||||
'chromium_src/chrome/browser/printing/print_view_manager_base.h',
|
||||
'chromium_src/chrome/browser/printing/print_view_manager_basic.cc',
|
||||
'chromium_src/chrome/browser/printing/print_view_manager_basic.h',
|
||||
'chromium_src/chrome/browser/printing/print_view_manager_observer.h',
|
||||
'chromium_src/chrome/browser/printing/printer_query.cc',
|
||||
'chromium_src/chrome/browser/printing/printer_query.h',
|
||||
'chromium_src/chrome/browser/printing/printing_message_filter.cc',
|
||||
'chromium_src/chrome/browser/printing/printing_message_filter.h',
|
||||
'chromium_src/chrome/browser/printing/printing_ui_web_contents_observer.cc',
|
||||
'chromium_src/chrome/browser/printing/printing_ui_web_contents_observer.h',
|
||||
'chromium_src/chrome/browser/speech/tts_controller.h',
|
||||
'chromium_src/chrome/browser/speech/tts_controller_impl.cc',
|
||||
'chromium_src/chrome/browser/speech/tts_controller_impl.h',
|
||||
'chromium_src/chrome/browser/speech/tts_linux.cc',
|
||||
'chromium_src/chrome/browser/speech/tts_mac.mm',
|
||||
'chromium_src/chrome/browser/speech/tts_message_filter.cc',
|
||||
'chromium_src/chrome/browser/speech/tts_message_filter.h',
|
||||
'chromium_src/chrome/browser/speech/tts_platform.cc',
|
||||
'chromium_src/chrome/browser/speech/tts_platform.h',
|
||||
'chromium_src/chrome/browser/speech/tts_win.cc',
|
||||
'chromium_src/chrome/browser/ui/browser_dialogs.h',
|
||||
'chromium_src/chrome/browser/ui/cocoa/color_chooser_mac.mm',
|
||||
'chromium_src/chrome/browser/ui/views/color_chooser_aura.cc',
|
||||
'chromium_src/chrome/browser/ui/views/color_chooser_aura.h',
|
||||
'chromium_src/chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.cc',
|
||||
'chromium_src/chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.h',
|
||||
'chromium_src/chrome/browser/ui/libgtk2ui/gtk2_status_icon.cc',
|
||||
@@ -244,8 +315,29 @@
|
||||
'chromium_src/chrome/browser/ui/views/frame/global_menu_bar_registrar_x11.h',
|
||||
'chromium_src/chrome/browser/ui/views/status_icons/status_tray_state_changer_win.cc',
|
||||
'chromium_src/chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h',
|
||||
'chromium_src/chrome/common/print_messages.cc',
|
||||
'chromium_src/chrome/common/print_messages.h',
|
||||
'chromium_src/chrome/common/tts_messages.h',
|
||||
'chromium_src/chrome/common/tts_utterance_request.cc',
|
||||
'chromium_src/chrome/common/tts_utterance_request.h',
|
||||
'chromium_src/chrome/renderer/printing/print_web_view_helper.cc',
|
||||
'chromium_src/chrome/renderer/printing/print_web_view_helper_linux.cc',
|
||||
'chromium_src/chrome/renderer/printing/print_web_view_helper_mac.mm',
|
||||
'chromium_src/chrome/renderer/printing/print_web_view_helper_win.cc',
|
||||
'chromium_src/chrome/renderer/printing/print_web_view_helper.h',
|
||||
'chromium_src/chrome/renderer/tts_dispatcher.cc',
|
||||
'chromium_src/chrome/renderer/tts_dispatcher.h',
|
||||
'chromium_src/library_loaders/libgio_loader.cc',
|
||||
'chromium_src/library_loaders/libgio.h',
|
||||
'chromium_src/library_loaders/libspeechd_loader.cc',
|
||||
'chromium_src/library_loaders/libspeechd.h',
|
||||
'<@(native_mate_files)',
|
||||
],
|
||||
'lib_sources_win': [
|
||||
'chromium_src/chrome/browser/ui/views/color_chooser_dialog.cc',
|
||||
'chromium_src/chrome/browser/ui/views/color_chooser_dialog.h',
|
||||
'chromium_src/chrome/browser/ui/views/color_chooser_win.cc',
|
||||
],
|
||||
'framework_sources': [
|
||||
'atom/app/atom_library_main.cc',
|
||||
'atom/app/atom_library_main.h',
|
||||
@@ -434,6 +526,10 @@
|
||||
'vendor/brightray/brightray.gyp:brightray',
|
||||
'vendor/node/node.gyp:node_lib',
|
||||
],
|
||||
'defines': [
|
||||
# This is defined in skia/skia_common.gypi.
|
||||
'SK_SUPPORT_LEGACY_GETTOPDEVICE',
|
||||
],
|
||||
'sources': [
|
||||
'<@(lib_sources)',
|
||||
],
|
||||
@@ -461,6 +557,9 @@
|
||||
],
|
||||
'conditions': [
|
||||
['OS=="win"', {
|
||||
'sources': [
|
||||
'<@(lib_sources_win)',
|
||||
],
|
||||
'link_settings': {
|
||||
'libraries': [
|
||||
'-limm32.lib',
|
||||
@@ -488,6 +587,10 @@
|
||||
'-rpath \$$ORIGIN',
|
||||
# Make native module dynamic loading work.
|
||||
'-rdynamic',
|
||||
'<!@(pkg-config --libs-only-L --libs-only-other dbus-1 x11 xrandr xext gconf-2.0)',
|
||||
],
|
||||
'libraries': [
|
||||
'<!@(pkg-config --libs-only-l dbus-1 x11 xrandr xext gconf-2.0)',
|
||||
],
|
||||
},
|
||||
# Required settings of using breakpad.
|
||||
@@ -495,7 +598,10 @@
|
||||
'vendor/breakpad/src',
|
||||
],
|
||||
'cflags': [
|
||||
'<!@(pkg-config --cflags dbus-1)',
|
||||
'-Wno-deprecated-register',
|
||||
'-Wno-empty-body',
|
||||
'-Wno-reserved-user-defined-literal',
|
||||
],
|
||||
'dependencies': [
|
||||
'vendor/breakpad/breakpad.gyp:breakpad_client',
|
||||
@@ -635,12 +741,45 @@
|
||||
# Gyp action requires a output file, add a fake one here.
|
||||
'<(PRODUCT_DIR)/dummy_file',
|
||||
],
|
||||
'action': [ 'strip', '<@(_inputs)' ],
|
||||
'action': [
|
||||
'tools/posix/strip.sh',
|
||||
'<@(_inputs)',
|
||||
],
|
||||
},
|
||||
],
|
||||
}], # OS=="linux"
|
||||
],
|
||||
}, # target <(project_name>_dump_symbols
|
||||
{
|
||||
'target_name': 'copy_chromedriver',
|
||||
'type': 'none',
|
||||
'actions': [
|
||||
{
|
||||
'action_name': 'Copy ChromeDriver Binary',
|
||||
'variables': {
|
||||
'conditions': [
|
||||
['OS=="win"', {
|
||||
'chromedriver_binary': 'chromedriver.exe',
|
||||
},{
|
||||
'chromedriver_binary': 'chromedriver',
|
||||
}],
|
||||
],
|
||||
},
|
||||
'inputs': [
|
||||
'<(libchromiumcontent_library_dir)/<(chromedriver_binary)',
|
||||
],
|
||||
'outputs': [
|
||||
'<(PRODUCT_DIR)/<(chromedriver_binary)',
|
||||
],
|
||||
'action': [
|
||||
'python',
|
||||
'tools/copy_binary.py',
|
||||
'<@(_inputs)',
|
||||
'<@(_outputs)',
|
||||
],
|
||||
}
|
||||
],
|
||||
}, # copy_chromedriver
|
||||
],
|
||||
'conditions': [
|
||||
['OS=="mac"', {
|
||||
@@ -778,7 +917,7 @@
|
||||
{
|
||||
'action_name': 'Create node.lib',
|
||||
'inputs': [
|
||||
'<(PRODUCT_DIR)/atom.lib',
|
||||
'<(PRODUCT_DIR)/<(project_name).lib',
|
||||
'<(libchromiumcontent_library_dir)/chromiumcontent.dll.lib',
|
||||
],
|
||||
'outputs': [
|
||||
@@ -798,5 +937,31 @@
|
||||
}, # target generate_node_lib
|
||||
],
|
||||
}], # OS==win
|
||||
# Using Visual Studio Express.
|
||||
['msvs_express==1', {
|
||||
'target_defaults': {
|
||||
'defines!': [
|
||||
'_SECURE_ATL',
|
||||
],
|
||||
'msvs_settings': {
|
||||
'VCLibrarianTool': {
|
||||
'AdditionalLibraryDirectories': [
|
||||
'<(atom_source_root)/external_binaries/atl/lib',
|
||||
],
|
||||
},
|
||||
'VCLinkerTool': {
|
||||
'AdditionalLibraryDirectories': [
|
||||
'<(atom_source_root)/external_binaries/atl/lib',
|
||||
],
|
||||
'AdditionalDependencies': [
|
||||
'atls.lib',
|
||||
],
|
||||
},
|
||||
},
|
||||
'msvs_system_include_dirs': [
|
||||
'<(atom_source_root)/external_binaries/atl/include',
|
||||
],
|
||||
},
|
||||
}], # msvs_express==1
|
||||
],
|
||||
}
|
||||
|
||||
30
atom/app/atom_content_client.cc
Normal file
30
atom/app/atom_content_client.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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/app/atom_content_client.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/chrome_version.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
AtomContentClient::AtomContentClient() {
|
||||
}
|
||||
|
||||
AtomContentClient::~AtomContentClient() {
|
||||
}
|
||||
|
||||
std::string AtomContentClient::GetProduct() const {
|
||||
return "Chrome/" CHROME_VERSION_STRING;
|
||||
}
|
||||
|
||||
void AtomContentClient::AddAdditionalSchemes(
|
||||
std::vector<std::string>* standard_schemes,
|
||||
std::vector<std::string>* savable_schemes) {
|
||||
standard_schemes->push_back("chrome-extension");
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
33
atom/app/atom_content_client.h
Normal file
33
atom/app/atom_content_client.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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_APP_ATOM_CONTENT_CLIENT_H_
|
||||
#define ATOM_APP_ATOM_CONTENT_CLIENT_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "brightray/common/content_client.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomContentClient : public brightray::ContentClient {
|
||||
public:
|
||||
AtomContentClient();
|
||||
virtual ~AtomContentClient();
|
||||
|
||||
protected:
|
||||
// content::ContentClient:
|
||||
virtual std::string GetProduct() const OVERRIDE;
|
||||
virtual void AddAdditionalSchemes(
|
||||
std::vector<std::string>* standard_schemes,
|
||||
std::vector<std::string>* savable_schemes) OVERRIDE;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomContentClient);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_APP_ATOM_CONTENT_CLIENT_H_
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "atom/app/atom_main_delegate.h"
|
||||
#include "atom/common/crash_reporter/win/crash_service_main.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/win/registry.h"
|
||||
#include "content/public/app/startup_helper_win.h"
|
||||
#include "sandbox/win/src/sandbox_types.h"
|
||||
#include "ui/gfx/win/dpi.h"
|
||||
@@ -36,13 +35,6 @@ int Start(int argc, char *argv[]);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
namespace {
|
||||
|
||||
const wchar_t kRegistryProfilePath[] = L"SOFTWARE\\Google\\Chrome\\Profile";
|
||||
const wchar_t kHighDPISupportW[] = L"high-dpi-support";
|
||||
|
||||
} // namespace
|
||||
|
||||
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||
int argc = 0;
|
||||
wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
||||
@@ -109,10 +101,6 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||
atom::AtomMainDelegate delegate;
|
||||
|
||||
// Now chrome relies on a regkey to enable high dpi support.
|
||||
base::win::RegKey high_dpi_key(HKEY_CURRENT_USER);
|
||||
high_dpi_key.CreateKey(kRegistryProfilePath, KEY_SET_VALUE);
|
||||
high_dpi_key.WriteValue(kHighDPISupportW, 1);
|
||||
|
||||
gfx::EnableHighDPISupport();
|
||||
|
||||
content::ContentMainParams params(&delegate);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/app/atom_content_client.h"
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/common/google_api_key.h"
|
||||
#include "atom/renderer/atom_renderer_client.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/debug/stack_trace.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/logging.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
@@ -22,18 +25,6 @@ AtomMainDelegate::AtomMainDelegate() {
|
||||
AtomMainDelegate::~AtomMainDelegate() {
|
||||
}
|
||||
|
||||
void AtomMainDelegate::AddDataPackFromPath(
|
||||
ui::ResourceBundle* bundle, const base::FilePath& pak_dir) {
|
||||
#if defined(OS_WIN)
|
||||
bundle->AddDataPackFromPath(
|
||||
pak_dir.Append(FILE_PATH_LITERAL("ui_resources_200_percent.pak")),
|
||||
ui::SCALE_FACTOR_200P);
|
||||
bundle->AddDataPackFromPath(
|
||||
pak_dir.Append(FILE_PATH_LITERAL("webkit_resources_200_percent.pak")),
|
||||
ui::SCALE_FACTOR_200P);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
// Disable logging out to debug.log on Windows
|
||||
#if defined(OS_WIN)
|
||||
@@ -63,6 +54,11 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
void AtomMainDelegate::PreSandboxStartup() {
|
||||
brightray::MainDelegate::PreSandboxStartup();
|
||||
|
||||
// Set google API key.
|
||||
scoped_ptr<base::Environment> env(base::Environment::Create());
|
||||
if (!env->HasVar("GOOGLE_API_KEY"))
|
||||
env->SetVar("GOOGLE_API_KEY", GOOGLEAPIS_API_KEY);
|
||||
|
||||
CommandLine* command_line = CommandLine::ForCurrentProcess();
|
||||
std::string process_type = command_line->GetSwitchValueASCII(
|
||||
switches::kProcessType);
|
||||
@@ -74,9 +70,21 @@ void AtomMainDelegate::PreSandboxStartup() {
|
||||
// Add a flag to mark the start of switches added by atom-shell.
|
||||
command_line->AppendSwitch("atom-shell-switches-start");
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Disable the LegacyRenderWidgetHostHWND, it made frameless windows unable
|
||||
// to move and resize. We may consider enabling it again after upgraded to
|
||||
// Chrome 38, which should have fixed the problem.
|
||||
command_line->AppendSwitch(switches::kDisableLegacyIntermediateWindow);
|
||||
#endif
|
||||
|
||||
// Disable renderer sandbox for most of node's functions.
|
||||
command_line->AppendSwitch(switches::kNoSandbox);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
// Enable AVFoundation.
|
||||
command_line->AppendSwitch("enable-avfoundation");
|
||||
#endif
|
||||
|
||||
// Add a flag to mark the end of switches added by atom-shell.
|
||||
command_line->AppendSwitch("atom-shell-switches-end");
|
||||
}
|
||||
@@ -92,4 +100,20 @@ content::ContentRendererClient*
|
||||
return renderer_client_.get();
|
||||
}
|
||||
|
||||
scoped_ptr<brightray::ContentClient> AtomMainDelegate::CreateContentClient() {
|
||||
return scoped_ptr<brightray::ContentClient>(new AtomContentClient).Pass();
|
||||
}
|
||||
|
||||
void AtomMainDelegate::AddDataPackFromPath(
|
||||
ui::ResourceBundle* bundle, const base::FilePath& pak_dir) {
|
||||
#if defined(OS_WIN)
|
||||
bundle->AddDataPackFromPath(
|
||||
pak_dir.Append(FILE_PATH_LITERAL("ui_resources_200_percent.pak")),
|
||||
ui::SCALE_FACTOR_200P);
|
||||
bundle->AddDataPackFromPath(
|
||||
pak_dir.Append(FILE_PATH_LITERAL("webkit_resources_200_percent.pak")),
|
||||
ui::SCALE_FACTOR_200P);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -16,24 +16,23 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
||||
~AtomMainDelegate();
|
||||
|
||||
protected:
|
||||
// brightray::MainDelegate:
|
||||
virtual void AddDataPackFromPath(
|
||||
ui::ResourceBundle* bundle, const base::FilePath& pak_dir) OVERRIDE;
|
||||
|
||||
// content::ContentMainDelegate:
|
||||
virtual bool BasicStartupComplete(int* exit_code) OVERRIDE;
|
||||
virtual void PreSandboxStartup() OVERRIDE;
|
||||
virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE;
|
||||
virtual content::ContentRendererClient*
|
||||
CreateContentRendererClient() OVERRIDE;
|
||||
|
||||
// brightray::MainDelegate:
|
||||
virtual scoped_ptr<brightray::ContentClient> CreateContentClient() OVERRIDE;
|
||||
virtual void AddDataPackFromPath(
|
||||
ui::ResourceBundle* bundle, const base::FilePath& pak_dir) OVERRIDE;
|
||||
#if defined(OS_MACOSX)
|
||||
virtual void OverrideChildProcessPath() OVERRIDE;
|
||||
virtual void OverrideFrameworkBundlePath() OVERRIDE;
|
||||
#endif
|
||||
|
||||
private:
|
||||
virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE;
|
||||
virtual content::ContentRendererClient*
|
||||
CreateContentRendererClient() OVERRIDE;
|
||||
|
||||
brightray::ContentClient content_client_;
|
||||
scoped_ptr<content::ContentBrowserClient> browser_client_;
|
||||
scoped_ptr<content::ContentRendererClient> renderer_client_;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,25 +1,81 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/atom_api_app.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "base/values.h"
|
||||
#include "base/command_line.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/path_service.h"
|
||||
#include "native_mate/callback.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "net/base/load_flags.h"
|
||||
#include "net/proxy/proxy_service.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
#include "base/nix/xdg_util.h"
|
||||
#endif
|
||||
|
||||
using atom::Browser;
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
namespace {
|
||||
|
||||
class ResolveProxyHelper {
|
||||
public:
|
||||
ResolveProxyHelper(const GURL& url, App::ResolveProxyCallback callback)
|
||||
: callback_(callback) {
|
||||
net::ProxyService* proxy_service = AtomBrowserContext::Get()->
|
||||
url_request_context_getter()->GetURLRequestContext()->proxy_service();
|
||||
|
||||
// Start the request.
|
||||
int result = proxy_service->ResolveProxy(
|
||||
url, net::LOAD_NORMAL, &proxy_info_,
|
||||
base::Bind(&ResolveProxyHelper::OnResolveProxyCompleted,
|
||||
base::Unretained(this)),
|
||||
&pac_req_, nullptr, net::BoundNetLog());
|
||||
|
||||
// Completed synchronously.
|
||||
if (result != net::ERR_IO_PENDING)
|
||||
OnResolveProxyCompleted(result);
|
||||
}
|
||||
|
||||
void OnResolveProxyCompleted(int result) {
|
||||
std::string proxy;
|
||||
if (result == net::OK)
|
||||
proxy = proxy_info_.ToPacString();
|
||||
callback_.Run(proxy);
|
||||
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
App::ResolveProxyCallback callback_;
|
||||
net::ProxyInfo proxy_info_;
|
||||
net::ProxyService::PacRequest* pac_req_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ResolveProxyHelper);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
App::App() {
|
||||
Browser::Get()->AddObserver(this);
|
||||
}
|
||||
@@ -36,6 +92,10 @@ void App::OnWindowAllClosed() {
|
||||
Emit("window-all-closed");
|
||||
}
|
||||
|
||||
void App::OnQuit() {
|
||||
Emit("quit");
|
||||
}
|
||||
|
||||
void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
|
||||
base::ListValue args;
|
||||
args.AppendString(file_path);
|
||||
@@ -60,22 +120,46 @@ void App::OnFinishLaunching() {
|
||||
Emit("ready");
|
||||
}
|
||||
|
||||
base::FilePath App::GetDataPath() {
|
||||
base::FilePath path;
|
||||
#if defined(OS_LINUX)
|
||||
scoped_ptr<base::Environment> env(base::Environment::Create());
|
||||
path = base::nix::GetXDGDirectory(env.get(),
|
||||
base::nix::kXdgConfigHomeEnvVar,
|
||||
base::nix::kDotConfigDir);
|
||||
#else
|
||||
PathService::Get(base::DIR_APP_DATA, &path);
|
||||
#endif
|
||||
|
||||
return path.Append(base::FilePath::FromUTF8Unsafe(
|
||||
Browser::Get()->GetName()));
|
||||
}
|
||||
|
||||
void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
|
||||
new ResolveProxyHelper(url, callback);
|
||||
}
|
||||
|
||||
void App::SetDesktopName(const std::string& desktop_name) {
|
||||
#if defined(OS_LINUX)
|
||||
scoped_ptr<base::Environment> env(base::Environment::Create());
|
||||
env->SetVar("CHROME_DESKTOP", desktop_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
Browser* browser = Browser::Get();
|
||||
auto browser = base::Unretained(Browser::Get());
|
||||
return mate::ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("quit", base::Bind(&Browser::Quit,
|
||||
base::Unretained(browser)))
|
||||
.SetMethod("focus", base::Bind(&Browser::Focus,
|
||||
base::Unretained(browser)))
|
||||
.SetMethod("getVersion", base::Bind(&Browser::GetVersion,
|
||||
base::Unretained(browser)))
|
||||
.SetMethod("setVersion", base::Bind(&Browser::SetVersion,
|
||||
base::Unretained(browser)))
|
||||
.SetMethod("getName", base::Bind(&Browser::GetName,
|
||||
base::Unretained(browser)))
|
||||
.SetMethod("setName", base::Bind(&Browser::SetName,
|
||||
base::Unretained(browser)));
|
||||
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
|
||||
.SetMethod("focus", base::Bind(&Browser::Focus, browser))
|
||||
.SetMethod("getVersion", base::Bind(&Browser::GetVersion, browser))
|
||||
.SetMethod("setVersion", base::Bind(&Browser::SetVersion, browser))
|
||||
.SetMethod("getName", base::Bind(&Browser::GetName, browser))
|
||||
.SetMethod("setName", base::Bind(&Browser::SetName, browser))
|
||||
.SetMethod("isReady", base::Bind(&Browser::is_ready, browser))
|
||||
.SetMethod("getDataPath", &App::GetDataPath)
|
||||
.SetMethod("resolveProxy", &App::ResolveProxy)
|
||||
.SetMethod("setDesktopName", &App::SetDesktopName);
|
||||
}
|
||||
|
||||
// static
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -7,11 +7,17 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
#include "atom/browser/browser_observer.h"
|
||||
#include "base/callback.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
class GURL;
|
||||
|
||||
namespace base {
|
||||
class FilePath;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
@@ -19,6 +25,8 @@ namespace api {
|
||||
class App : public mate::EventEmitter,
|
||||
public BrowserObserver {
|
||||
public:
|
||||
typedef base::Callback<void(std::string)> ResolveProxyCallback;
|
||||
|
||||
static mate::Handle<App> Create(v8::Isolate* isolate);
|
||||
|
||||
protected:
|
||||
@@ -28,6 +36,7 @@ class App : public mate::EventEmitter,
|
||||
// BrowserObserver implementations:
|
||||
virtual void OnWillQuit(bool* prevent_default) OVERRIDE;
|
||||
virtual void OnWindowAllClosed() OVERRIDE;
|
||||
virtual void OnQuit() OVERRIDE;
|
||||
virtual void OnOpenFile(bool* prevent_default,
|
||||
const std::string& file_path) OVERRIDE;
|
||||
virtual void OnOpenURL(const std::string& url) OVERRIDE;
|
||||
@@ -40,6 +49,10 @@ class App : public mate::EventEmitter,
|
||||
v8::Isolate* isolate);
|
||||
|
||||
private:
|
||||
base::FilePath GetDataPath();
|
||||
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
||||
void SetDesktopName(const std::string& desktop_name);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(App);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// 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 <set>
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/function_converter.h"
|
||||
#include "base/bind.h"
|
||||
#include "content/public/browser/tracing_controller.h"
|
||||
#include "native_mate/callback.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
@@ -31,17 +32,30 @@ struct Converter<std::set<T> > {
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<TracingController::Options> {
|
||||
struct Converter<base::debug::CategoryFilter> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
TracingController::Options* out) {
|
||||
if (!val->IsNumber())
|
||||
base::debug::CategoryFilter* out) {
|
||||
std::string filter;
|
||||
if (!ConvertFromV8(isolate, val, &filter))
|
||||
return false;
|
||||
*out = static_cast<TracingController::Options>(val->IntegerValue());
|
||||
*out = base::debug::CategoryFilter(filter);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<base::debug::TraceOptions> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
base::debug::TraceOptions* out) {
|
||||
std::string options;
|
||||
if (!ConvertFromV8(isolate, val, &options))
|
||||
return false;
|
||||
return out->SetFromString(options);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/atom_api_window.h"
|
||||
@@ -10,12 +11,31 @@
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
#include "atom/browser/ui/message_box.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/function_converter.h"
|
||||
#include "base/bind.h"
|
||||
#include "native_mate/callback.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<file_dialog::Filter> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
file_dialog::Filter* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
if (!dict.Get("name", &(out->first)))
|
||||
return false;
|
||||
if (!dict.Get("extensions", &(out->second)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
namespace {
|
||||
|
||||
void ShowMessageBox(int type,
|
||||
@@ -41,6 +61,7 @@ void ShowMessageBox(int type,
|
||||
|
||||
void ShowOpenDialog(const std::string& title,
|
||||
const base::FilePath& default_path,
|
||||
const file_dialog::Filters& filters,
|
||||
int properties,
|
||||
atom::NativeWindow* window,
|
||||
mate::Arguments* args) {
|
||||
@@ -49,18 +70,19 @@ void ShowOpenDialog(const std::string& title,
|
||||
if (mate::Converter<file_dialog::OpenDialogCallback>::FromV8(args->isolate(),
|
||||
peek,
|
||||
&callback)) {
|
||||
file_dialog::ShowOpenDialog(window, title, default_path, properties,
|
||||
callback);
|
||||
file_dialog::ShowOpenDialog(window, title, default_path, filters,
|
||||
properties, callback);
|
||||
} else {
|
||||
std::vector<base::FilePath> paths;
|
||||
if (file_dialog::ShowOpenDialog(window, title, default_path, properties,
|
||||
&paths))
|
||||
if (file_dialog::ShowOpenDialog(window, title, default_path, filters,
|
||||
properties, &paths))
|
||||
args->Return(paths);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowSaveDialog(const std::string& title,
|
||||
const base::FilePath& default_path,
|
||||
const file_dialog::Filters& filters,
|
||||
atom::NativeWindow* window,
|
||||
mate::Arguments* args) {
|
||||
v8::Handle<v8::Value> peek = args->PeekNext();
|
||||
@@ -68,10 +90,11 @@ void ShowSaveDialog(const std::string& title,
|
||||
if (mate::Converter<file_dialog::SaveDialogCallback>::FromV8(args->isolate(),
|
||||
peek,
|
||||
&callback)) {
|
||||
file_dialog::ShowSaveDialog(window, title, default_path, callback);
|
||||
file_dialog::ShowSaveDialog(window, title, default_path, filters, callback);
|
||||
} else {
|
||||
base::FilePath path;
|
||||
if (file_dialog::ShowSaveDialog(window, title, default_path, &path))
|
||||
if (file_dialog::ShowSaveDialog(window, title, default_path, filters,
|
||||
&path))
|
||||
args->Return(path);
|
||||
}
|
||||
}
|
||||
@@ -80,6 +103,7 @@ void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
dict.SetMethod("showMessageBox", &ShowMessageBox);
|
||||
dict.SetMethod("showErrorBox", &atom::ShowErrorBox);
|
||||
dict.SetMethod("showOpenDialog", &ShowOpenDialog);
|
||||
dict.SetMethod("showSaveDialog", &ShowSaveDialog);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "atom/common/native_mate_converters/function_converter.h"
|
||||
#include "atom/common/native_mate_converters/accelerator_converter.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "native_mate/callback.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
@@ -36,68 +37,42 @@ void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) {
|
||||
accelerator_callback_map_[accelerator].Run();
|
||||
}
|
||||
|
||||
bool GlobalShortcut::Register(const std::string& keycode,
|
||||
const base::Closure& callback) {
|
||||
ui::Accelerator accelerator;
|
||||
if (!accelerator_util::StringToAccelerator(keycode, &accelerator)) {
|
||||
LOG(ERROR) << keycode << " is invalid.";
|
||||
return false;
|
||||
}
|
||||
bool GlobalShortcut::Register(const ui::Accelerator& accelerator,
|
||||
const base::Closure& callback) {
|
||||
if (!GlobalShortcutListener::GetInstance()->RegisterAccelerator(
|
||||
accelerator, this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
accelerator_callback_map_[accelerator] = callback;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GlobalShortcut::Unregister(const std::string& keycode) {
|
||||
ui::Accelerator accelerator;
|
||||
if (!accelerator_util::StringToAccelerator(keycode, &accelerator)) {
|
||||
LOG(ERROR) << "The keycode: " << keycode << " is invalid.";
|
||||
void GlobalShortcut::Unregister(const ui::Accelerator& accelerator) {
|
||||
if (!ContainsKey(accelerator_callback_map_, accelerator))
|
||||
return;
|
||||
}
|
||||
if (accelerator_callback_map_.find(accelerator) ==
|
||||
accelerator_callback_map_.end()) {
|
||||
LOG(ERROR) << "The keycode: " << keycode << " isn't registered yet!";
|
||||
return;
|
||||
}
|
||||
|
||||
accelerator_callback_map_.erase(accelerator);
|
||||
GlobalShortcutListener::GetInstance()->UnregisterAccelerator(
|
||||
accelerator, this);
|
||||
}
|
||||
|
||||
bool GlobalShortcut::IsRegistered(const ui::Accelerator& accelerator) {
|
||||
return ContainsKey(accelerator_callback_map_, accelerator);
|
||||
}
|
||||
|
||||
void GlobalShortcut::UnregisterAll() {
|
||||
accelerator_callback_map_.clear();
|
||||
GlobalShortcutListener::GetInstance()->UnregisterAccelerators(this);
|
||||
}
|
||||
|
||||
bool GlobalShortcut::IsRegistered(const std::string& keycode) {
|
||||
ui::Accelerator accelerator;
|
||||
if (!accelerator_util::StringToAccelerator(keycode, &accelerator)) {
|
||||
LOG(ERROR) << "The keycode: " << keycode << " is invalid.";
|
||||
return false;
|
||||
}
|
||||
return accelerator_callback_map_.find(accelerator) !=
|
||||
accelerator_callback_map_.end();
|
||||
}
|
||||
|
||||
// static
|
||||
mate::ObjectTemplateBuilder GlobalShortcut::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
return mate::ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("register",
|
||||
base::Bind(&GlobalShortcut::Register,
|
||||
base::Unretained(this)))
|
||||
.SetMethod("isRegistered",
|
||||
base::Bind(&GlobalShortcut::IsRegistered,
|
||||
base::Unretained(this)))
|
||||
.SetMethod("unregister",
|
||||
base::Bind(&GlobalShortcut::Unregister,
|
||||
base::Unretained(this)))
|
||||
.SetMethod("unregisterAll",
|
||||
base::Bind(&GlobalShortcut::UnregisterAll,
|
||||
base::Unretained(this)));
|
||||
.SetMethod("register", &GlobalShortcut::Register)
|
||||
.SetMethod("isRegistered", &GlobalShortcut::IsRegistered)
|
||||
.SetMethod("unregister", &GlobalShortcut::Unregister)
|
||||
.SetMethod("unregisterAll", &GlobalShortcut::UnregisterAll);
|
||||
}
|
||||
|
||||
// static
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -34,9 +34,10 @@ class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
|
||||
private:
|
||||
typedef std::map<ui::Accelerator, base::Closure> AcceleratorCallbackMap;
|
||||
|
||||
bool Register(const std::string& keycode, const base::Closure& callback);
|
||||
bool IsRegistered(const std::string& keycode);
|
||||
void Unregister(const std::string& keycode);
|
||||
bool Register(const ui::Accelerator& accelerator,
|
||||
const base::Closure& callback);
|
||||
bool IsRegistered(const ui::Accelerator& accelerator);
|
||||
void Unregister(const ui::Accelerator& accelerator);
|
||||
void UnregisterAll();
|
||||
|
||||
// GlobalShortcutListener::Observer implementation.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/atom_api_menu.h"
|
||||
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "atom/common/native_mate_converters/accelerator_converter.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
@@ -92,12 +92,7 @@ bool Menu::GetAcceleratorForCommandId(int command_id,
|
||||
GetWrapper(isolate),
|
||||
"getAcceleratorForCommandId",
|
||||
command_id);
|
||||
if (shortcut->IsString()) {
|
||||
std::string shortcut_str = mate::V8ToString(shortcut);
|
||||
return accelerator_util::StringToAccelerator(shortcut_str, accelerator);
|
||||
}
|
||||
|
||||
return false;
|
||||
return mate::ConvertFromV8(isolate, shortcut, accelerator);
|
||||
}
|
||||
|
||||
bool Menu::IsItemForCommandIdDynamic(int command_id) const {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -17,14 +17,15 @@ MenuViews::MenuViews() {
|
||||
|
||||
void MenuViews::Popup(Window* window) {
|
||||
gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
|
||||
views::MenuRunner menu_runner(model());
|
||||
views::MenuRunner menu_runner(
|
||||
model(),
|
||||
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
|
||||
ignore_result(menu_runner.RunMenuAt(
|
||||
static_cast<NativeWindowViews*>(window->window())->widget(),
|
||||
NULL,
|
||||
gfx::Rect(cursor, gfx::Size()),
|
||||
views::MENU_ANCHOR_TOPLEFT,
|
||||
ui::MENU_SOURCE_MOUSE,
|
||||
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
|
||||
ui::MENU_SOURCE_MOUSE));
|
||||
}
|
||||
|
||||
// static
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/atom_api_protocol.h"
|
||||
|
||||
#include "base/stl_util.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/net/adapter_request_job.h"
|
||||
#include "atom/browser/net/atom_url_request_context_getter.h"
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/function_converter.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/callback.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
|
||||
@@ -152,8 +150,9 @@ class CustomProtocolHandler : public ProtocolHandler {
|
||||
|
||||
} // namespace
|
||||
|
||||
Protocol::Protocol() : job_factory_(
|
||||
AtomBrowserContext::Get()->url_request_context_getter()->job_factory()) {
|
||||
Protocol::Protocol()
|
||||
: job_factory_(AtomBrowserContext::Get()->job_factory()) {
|
||||
CHECK(job_factory_);
|
||||
}
|
||||
|
||||
Protocol::JsProtocolHandler Protocol::GetProtocolHandler(
|
||||
@@ -324,10 +323,6 @@ namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
// Make sure the job factory has been created.
|
||||
atom::AtomBrowserContext::Get()->url_request_context_getter()->
|
||||
GetURLRequestContext();
|
||||
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("protocol", atom::api::Protocol::Create(isolate));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -36,6 +36,10 @@ void Tray::OnClicked() {
|
||||
Emit("clicked");
|
||||
}
|
||||
|
||||
void Tray::OnDoubleClicked() {
|
||||
Emit("double-clicked");
|
||||
}
|
||||
|
||||
void Tray::SetImage(const gfx::ImageSkia& image) {
|
||||
tray_icon_->SetImage(image);
|
||||
}
|
||||
@@ -48,6 +52,14 @@ void Tray::SetToolTip(const std::string& tool_tip) {
|
||||
tray_icon_->SetToolTip(tool_tip);
|
||||
}
|
||||
|
||||
void Tray::SetTitle(const std::string& title) {
|
||||
tray_icon_->SetTitle(title);
|
||||
}
|
||||
|
||||
void Tray::SetHighlightMode(bool highlight) {
|
||||
tray_icon_->SetHighlightMode(highlight);
|
||||
}
|
||||
|
||||
void Tray::SetContextMenu(Menu* menu) {
|
||||
tray_icon_->SetContextMenu(menu->model());
|
||||
}
|
||||
@@ -59,6 +71,8 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("setImage", &Tray::SetImage)
|
||||
.SetMethod("setPressedImage", &Tray::SetPressedImage)
|
||||
.SetMethod("setToolTip", &Tray::SetToolTip)
|
||||
.SetMethod("setTitle", &Tray::SetTitle)
|
||||
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
|
||||
.SetMethod("_setContextMenu", &Tray::SetContextMenu);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -37,10 +37,13 @@ class Tray : public mate::EventEmitter,
|
||||
|
||||
// TrayIcon implementations:
|
||||
virtual void OnClicked() OVERRIDE;
|
||||
virtual void OnDoubleClicked() OVERRIDE;
|
||||
|
||||
void SetImage(const gfx::ImageSkia& image);
|
||||
void SetPressedImage(const gfx::ImageSkia& image);
|
||||
void SetToolTip(const std::string& tool_tip);
|
||||
void SetTitle(const std::string& title);
|
||||
void SetHighlightMode(bool highlight);
|
||||
void SetContextMenu(Menu* menu);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,27 +1,139 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// 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/api/atom_api_web_contents.h"
|
||||
|
||||
#include "atom/browser/atom_browser_context.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/string16_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/inspectable_web_contents.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/site_instance.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
namespace {
|
||||
|
||||
v8::Persistent<v8::ObjectTemplate> template_;
|
||||
|
||||
} // namespace
|
||||
|
||||
WebContents::WebContents(content::WebContents* web_contents)
|
||||
: content::WebContentsObserver(web_contents),
|
||||
web_contents_(web_contents) {
|
||||
guest_instance_id_(-1),
|
||||
guest_opaque_(true),
|
||||
auto_size_enabled_(false) {
|
||||
}
|
||||
|
||||
WebContents::WebContents(const mate::Dictionary& options)
|
||||
: guest_instance_id_(-1),
|
||||
guest_opaque_(true),
|
||||
auto_size_enabled_(false) {
|
||||
options.Get("guestInstanceId", &guest_instance_id_);
|
||||
|
||||
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;
|
||||
|
||||
storage_.reset(brightray::InspectableWebContents::Create(params));
|
||||
Observe(storage_->GetWebContents());
|
||||
web_contents()->SetDelegate(this);
|
||||
}
|
||||
|
||||
WebContents::~WebContents() {
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool WebContents::AddMessageToConsole(content::WebContents* source,
|
||||
int32 level,
|
||||
const base::string16& message,
|
||||
int32 line_no,
|
||||
const base::string16& source_id) {
|
||||
base::ListValue args;
|
||||
args.AppendInteger(level);
|
||||
args.AppendString(message);
|
||||
args.AppendInteger(line_no);
|
||||
args.AppendString(source_id);
|
||||
Emit("console-message", args);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WebContents::ShouldCreateWebContents(
|
||||
content::WebContents* web_contents,
|
||||
int route_id,
|
||||
WindowContainerType window_container_type,
|
||||
const base::string16& frame_name,
|
||||
const GURL& target_url,
|
||||
const std::string& partition_id,
|
||||
content::SessionStorageNamespace* session_storage_namespace) {
|
||||
base::ListValue args;
|
||||
args.AppendString(target_url.spec());
|
||||
args.AppendString(frame_name);
|
||||
args.AppendInteger(NEW_FOREGROUND_TAB);
|
||||
Emit("-new-window", args);
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebContents::CloseContents(content::WebContents* source) {
|
||||
Emit("close");
|
||||
}
|
||||
|
||||
content::WebContents* WebContents::OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) {
|
||||
if (params.disposition != CURRENT_TAB) {
|
||||
base::ListValue args;
|
||||
args.AppendString(params.url.spec());
|
||||
args.AppendString("");
|
||||
args.AppendInteger(params.disposition);
|
||||
Emit("-new-window", args);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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::HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
if (!attached())
|
||||
return;
|
||||
|
||||
// Send the unhandled keyboard events back to the embedder to reprocess them.
|
||||
embedder_web_contents_->GetDelegate()->HandleKeyboardEvent(
|
||||
web_contents(), event);
|
||||
}
|
||||
|
||||
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||
@@ -35,10 +147,10 @@ void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
||||
Emit("crashed");
|
||||
}
|
||||
|
||||
void WebContents::DidFinishLoad(int64 frame_id,
|
||||
const GURL& validated_url,
|
||||
bool is_main_frame,
|
||||
content::RenderViewHost* render_view_host) {
|
||||
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& validated_url) {
|
||||
bool is_main_frame = !render_frame_host->GetParent();
|
||||
|
||||
base::ListValue args;
|
||||
args.AppendBoolean(is_main_frame);
|
||||
Emit("did-frame-finish-load", args);
|
||||
@@ -47,6 +159,16 @@ void WebContents::DidFinishLoad(int64 frame_id,
|
||||
Emit("did-finish-load");
|
||||
}
|
||||
|
||||
void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& validated_url,
|
||||
int error_code,
|
||||
const base::string16& error_description) {
|
||||
base::ListValue args;
|
||||
args.AppendInteger(error_code);
|
||||
args.AppendString(error_description);
|
||||
Emit("did-fail-load", args);
|
||||
}
|
||||
|
||||
void WebContents::DidStartLoading(content::RenderViewHost* render_view_host) {
|
||||
Emit("did-start-loading");
|
||||
}
|
||||
@@ -55,6 +177,17 @@ void WebContents::DidStopLoading(content::RenderViewHost* render_view_host) {
|
||||
Emit("did-stop-loading");
|
||||
}
|
||||
|
||||
void WebContents::DidGetRedirectForResourceRequest(
|
||||
content::RenderViewHost* render_view_host,
|
||||
const content::ResourceRedirectDetails& details) {
|
||||
base::ListValue args;
|
||||
args.AppendString(details.url.spec());
|
||||
args.AppendString(details.new_url.spec());
|
||||
args.AppendBoolean(
|
||||
details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME);
|
||||
Emit("did-get-redirect-request", args);
|
||||
}
|
||||
|
||||
bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(WebContents, message)
|
||||
@@ -67,18 +200,100 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||
return handled;
|
||||
}
|
||||
|
||||
void WebContents::RenderViewReady() {
|
||||
if (!is_guest())
|
||||
return;
|
||||
|
||||
// We don't want to accidentally set the opacity of an interstitial page.
|
||||
// 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.
|
||||
web_contents()->GetRenderViewHost()->GetView()->
|
||||
SetBackgroundOpaque(guest_opaque_);
|
||||
|
||||
content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
|
||||
if (auto_size_enabled_) {
|
||||
rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
|
||||
} else {
|
||||
rvh->DisableAutoResize(element_size_);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::WebContentsDestroyed() {
|
||||
// The RenderViewDeleted was not called when the WebContents is destroyed.
|
||||
RenderViewDeleted(web_contents_->GetRenderViewHost());
|
||||
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
||||
Emit("destroyed");
|
||||
}
|
||||
|
||||
void WebContents::WillAttach(content::WebContents* embedder_web_contents,
|
||||
const base::DictionaryValue& extra_params) {
|
||||
embedder_web_contents_ = embedder_web_contents;
|
||||
extra_params_.reset(extra_params.DeepCopy());
|
||||
}
|
||||
|
||||
content::WebContents* WebContents::CreateNewGuestWindow(
|
||||
const content::WebContents::CreateParams& create_params) {
|
||||
NOTREACHED() << "Should not create new window from guest";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void WebContents::DidAttach() {
|
||||
base::ListValue args;
|
||||
args.Append(extra_params_.release());
|
||||
Emit("did-attach", args);
|
||||
}
|
||||
|
||||
int WebContents::GetGuestInstanceID() const {
|
||||
return guest_instance_id_;
|
||||
}
|
||||
|
||||
void WebContents::ElementSizeChanged(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size) {
|
||||
element_size_ = new_size;
|
||||
}
|
||||
|
||||
void WebContents::GuestSizeChanged(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size) {
|
||||
if (!auto_size_enabled_)
|
||||
return;
|
||||
guest_size_ = new_size;
|
||||
GuestSizeChangedDueToAutoSize(old_size, new_size);
|
||||
}
|
||||
|
||||
void WebContents::RequestPointerLockPermission(
|
||||
bool user_gesture,
|
||||
bool last_unlocked_by_target,
|
||||
const base::Callback<void(bool enabled)>& callback) {
|
||||
callback.Run(true);
|
||||
}
|
||||
|
||||
void WebContents::RegisterDestructionCallback(
|
||||
const DestructionCallback& callback) {
|
||||
destruction_callback_ = callback;
|
||||
}
|
||||
|
||||
void WebContents::Destroy() {
|
||||
if (storage_) {
|
||||
if (!destruction_callback_.is_null())
|
||||
destruction_callback_.Run();
|
||||
|
||||
Observe(nullptr);
|
||||
storage_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool WebContents::IsAlive() const {
|
||||
return web_contents() != NULL;
|
||||
}
|
||||
|
||||
void WebContents::LoadURL(const GURL& url) {
|
||||
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||
content::NavigationController::LoadURLParams params(url);
|
||||
|
||||
GURL http_referrer;
|
||||
if (options.Get("httpreferrer", &http_referrer))
|
||||
params.referrer = content::Referrer(http_referrer.GetAsReferrer(),
|
||||
blink::WebReferrerPolicyDefault);
|
||||
|
||||
params.transition_type = content::PAGE_TRANSITION_TYPED;
|
||||
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
||||
web_contents()->GetController().LoadURLWithParams(params);
|
||||
@@ -104,15 +319,15 @@ void WebContents::Stop() {
|
||||
web_contents()->Stop();
|
||||
}
|
||||
|
||||
void WebContents::Reload() {
|
||||
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());
|
||||
LoadURL(GetURL(), options);
|
||||
}
|
||||
|
||||
void WebContents::ReloadIgnoringCache() {
|
||||
Reload();
|
||||
void WebContents::ReloadIgnoringCache(const mate::Dictionary& options) {
|
||||
Reload(options);
|
||||
}
|
||||
|
||||
bool WebContents::CanGoBack() const {
|
||||
@@ -155,45 +370,118 @@ bool WebContents::IsCrashed() const {
|
||||
return web_contents()->IsCrashed();
|
||||
}
|
||||
|
||||
void WebContents::SetUserAgent(const std::string& user_agent) {
|
||||
web_contents()->SetUserAgentOverride(user_agent);
|
||||
}
|
||||
|
||||
void WebContents::InsertCSS(const std::string& css) {
|
||||
web_contents()->InsertCSS(css);
|
||||
}
|
||||
|
||||
void WebContents::ExecuteJavaScript(const base::string16& code) {
|
||||
web_contents()->GetMainFrame()->ExecuteJavaScript(code);
|
||||
}
|
||||
|
||||
void WebContents::OpenDevTools() {
|
||||
storage_->SetCanDock(false);
|
||||
storage_->ShowDevTools();
|
||||
}
|
||||
|
||||
void WebContents::CloseDevTools() {
|
||||
storage_->CloseDevTools();
|
||||
}
|
||||
|
||||
bool WebContents::IsDevToolsOpened() {
|
||||
return storage_->IsDevToolsViewShowing();
|
||||
}
|
||||
|
||||
bool WebContents::SendIPCMessage(const base::string16& channel,
|
||||
const base::ListValue& args) {
|
||||
return Send(new AtomViewMsg_Message(routing_id(), channel, args));
|
||||
}
|
||||
|
||||
void WebContents::SetAutoSize(bool enabled,
|
||||
const gfx::Size& min_size,
|
||||
const gfx::Size& max_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;
|
||||
|
||||
content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
|
||||
if (auto_size_enabled_) {
|
||||
rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
|
||||
} else {
|
||||
rvh->DisableAutoResize(element_size_);
|
||||
guest_size_ = element_size_;
|
||||
GuestSizeChangedDueToAutoSize(guest_size_, element_size_);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::SetAllowTransparency(bool allow) {
|
||||
if (guest_opaque_ != allow)
|
||||
return;
|
||||
|
||||
guest_opaque_ = !allow;
|
||||
if (!web_contents()->GetRenderViewHost()->GetView())
|
||||
return;
|
||||
|
||||
web_contents()->GetRenderViewHost()->GetView()->SetBackgroundOpaque(!allow);
|
||||
}
|
||||
|
||||
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
return mate::ObjectTemplateBuilder(isolate)
|
||||
.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("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("getRoutingId", &WebContents::GetRoutingID)
|
||||
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
||||
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
||||
.SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript)
|
||||
.SetMethod("_send", &WebContents::SendIPCMessage);
|
||||
if (template_.IsEmpty())
|
||||
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
||||
.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("_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("getRoutingId", &WebContents::GetRoutingID)
|
||||
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
||||
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
||||
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
|
||||
.SetMethod("insertCSS", &WebContents::InsertCSS)
|
||||
.SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript)
|
||||
.SetMethod("_send", &WebContents::SendIPCMessage)
|
||||
.SetMethod("setAutoSize", &WebContents::SetAutoSize)
|
||||
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
|
||||
.SetMethod("isGuest", &WebContents::is_guest)
|
||||
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
||||
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
||||
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
|
||||
.Build());
|
||||
|
||||
return mate::ObjectTemplateBuilder(
|
||||
isolate, v8::Local<v8::ObjectTemplate>::New(isolate, template_));
|
||||
}
|
||||
|
||||
void WebContents::OnRendererMessage(const base::string16& channel,
|
||||
const base::ListValue& args) {
|
||||
// webContents.emit(channel, new Event(), args...);
|
||||
Emit(base::UTF16ToUTF8(channel), args, web_contents(), NULL);
|
||||
Emit(base::UTF16ToUTF8(channel), args);
|
||||
}
|
||||
|
||||
void WebContents::OnRendererMessageSync(const base::string16& channel,
|
||||
@@ -203,12 +491,42 @@ void WebContents::OnRendererMessageSync(const base::string16& channel,
|
||||
Emit(base::UTF16ToUTF8(channel), args, web_contents(), message);
|
||||
}
|
||||
|
||||
void WebContents::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size) {
|
||||
base::ListValue args;
|
||||
args.AppendInteger(old_size.width());
|
||||
args.AppendInteger(old_size.height());
|
||||
args.AppendInteger(new_size.width());
|
||||
args.AppendInteger(new_size.height());
|
||||
Emit("size-changed", args);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::Create(
|
||||
mate::Handle<WebContents> WebContents::CreateFrom(
|
||||
v8::Isolate* isolate, content::WebContents* web_contents) {
|
||||
return mate::CreateHandle(isolate, new WebContents(web_contents));
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<WebContents> WebContents::Create(
|
||||
v8::Isolate* isolate, const mate::Dictionary& options) {
|
||||
return mate::CreateHandle(isolate, new WebContents(options));
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||
v8::Handle<v8::Context> context, void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.SetMethod("create", &atom::api::WebContents::Create);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_web_contents, Initialize)
|
||||
|
||||
@@ -1,33 +1,54 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// 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_API_ATOM_API_WEB_CONTENTS_H_
|
||||
#define ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
#include "brightray/browser/default_web_contents_delegate.h"
|
||||
#include "content/public/browser/browser_plugin_guest_delegate.h"
|
||||
#include "content/public/browser/web_contents_delegate.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
namespace brightray {
|
||||
class InspectableWebContents;
|
||||
}
|
||||
|
||||
namespace mate {
|
||||
class Dictionary;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
class WebContents : public mate::EventEmitter,
|
||||
public content::BrowserPluginGuestDelegate,
|
||||
public content::WebContentsDelegate,
|
||||
public content::WebContentsObserver {
|
||||
public:
|
||||
static mate::Handle<WebContents> Create(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents);
|
||||
// Create from an existing WebContents.
|
||||
static mate::Handle<WebContents> CreateFrom(
|
||||
v8::Isolate* isolate, content::WebContents* web_contents);
|
||||
|
||||
// Create a new WebContents.
|
||||
static mate::Handle<WebContents> Create(
|
||||
v8::Isolate* isolate, const mate::Dictionary& options);
|
||||
|
||||
void Destroy();
|
||||
bool IsAlive() const;
|
||||
void LoadURL(const GURL& url);
|
||||
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();
|
||||
void ReloadIgnoringCache();
|
||||
void Reload(const mate::Dictionary& options);
|
||||
void ReloadIgnoringCache(const mate::Dictionary& options);
|
||||
bool CanGoBack() const;
|
||||
bool CanGoForward() const;
|
||||
bool CanGoToOffset(int offset) const;
|
||||
@@ -38,31 +59,101 @@ class WebContents : public mate::EventEmitter,
|
||||
int GetRoutingID() const;
|
||||
int GetProcessID() const;
|
||||
bool IsCrashed() const;
|
||||
void SetUserAgent(const std::string& user_agent);
|
||||
void InsertCSS(const std::string& css);
|
||||
void ExecuteJavaScript(const base::string16& code);
|
||||
void OpenDevTools();
|
||||
void CloseDevTools();
|
||||
bool IsDevToolsOpened();
|
||||
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);
|
||||
|
||||
// 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; }
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit WebContents(content::WebContents* web_contents);
|
||||
explicit WebContents(const mate::Dictionary& options);
|
||||
~WebContents();
|
||||
|
||||
// mate::Wrappable implementations:
|
||||
// mate::Wrappable:
|
||||
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) OVERRIDE;
|
||||
v8::Isolate* isolate) override;
|
||||
|
||||
// content::WebContentsObserver implementations:
|
||||
virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
|
||||
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
|
||||
virtual void DidFinishLoad(
|
||||
int64 frame_id,
|
||||
const GURL& validated_url,
|
||||
bool is_main_frame,
|
||||
content::RenderViewHost* render_view_host) OVERRIDE;
|
||||
// content::WebContentsDelegate:
|
||||
bool AddMessageToConsole(content::WebContents* source,
|
||||
int32 level,
|
||||
const base::string16& message,
|
||||
int32 line_no,
|
||||
const base::string16& source_id) override;
|
||||
bool ShouldCreateWebContents(
|
||||
content::WebContents* web_contents,
|
||||
int route_id,
|
||||
WindowContainerType window_container_type,
|
||||
const base::string16& frame_name,
|
||||
const GURL& target_url,
|
||||
const std::string& partition_id,
|
||||
content::SessionStorageNamespace* session_storage_namespace) override;
|
||||
void CloseContents(content::WebContents* source) override;
|
||||
content::WebContents* OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) override;
|
||||
void HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
virtual void RenderViewDeleted(content::RenderViewHost*) override;
|
||||
virtual void RenderProcessGone(base::TerminationStatus status) override;
|
||||
virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& validated_url) override;
|
||||
virtual void DidFailLoad(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& validated_url,
|
||||
int error_code,
|
||||
const base::string16& error_description) override;
|
||||
virtual void DidStartLoading(
|
||||
content::RenderViewHost* render_view_host) OVERRIDE;
|
||||
content::RenderViewHost* render_view_host) override;
|
||||
virtual void DidStopLoading(
|
||||
content::RenderViewHost* render_view_host) OVERRIDE;
|
||||
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
||||
virtual void WebContentsDestroyed() OVERRIDE;
|
||||
content::RenderViewHost* render_view_host) override;
|
||||
virtual void DidGetRedirectForResourceRequest(
|
||||
content::RenderViewHost* render_view_host,
|
||||
const content::ResourceRedirectDetails& details) override;
|
||||
virtual bool OnMessageReceived(const IPC::Message& message) override;
|
||||
virtual void RenderViewReady() override;
|
||||
virtual void WebContentsDestroyed() override;
|
||||
|
||||
// content::BrowserPluginGuestDelegate:
|
||||
virtual void WillAttach(content::WebContents* embedder_web_contents,
|
||||
const base::DictionaryValue& extra_params) override;
|
||||
virtual content::WebContents* CreateNewGuestWindow(
|
||||
const content::WebContents::CreateParams& create_params) override;
|
||||
virtual void DidAttach() override;
|
||||
virtual int GetGuestInstanceID() const override;
|
||||
virtual void ElementSizeChanged(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size) override;
|
||||
virtual void GuestSizeChanged(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size) override;
|
||||
virtual void RequestPointerLockPermission(
|
||||
bool user_gesture,
|
||||
bool last_unlocked_by_target,
|
||||
const base::Callback<void(bool enabled)>& callback) override;
|
||||
virtual void RegisterDestructionCallback(
|
||||
const DestructionCallback& callback) override;
|
||||
|
||||
private:
|
||||
// Called when received a message from renderer.
|
||||
@@ -74,7 +165,44 @@ class WebContents : public mate::EventEmitter,
|
||||
const base::ListValue& args,
|
||||
IPC::Message* message);
|
||||
|
||||
content::WebContents* web_contents_; // Weak.
|
||||
void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size);
|
||||
|
||||
// Unique ID for a guest WebContents.
|
||||
int guest_instance_id_;
|
||||
|
||||
DestructionCallback destruction_callback_;
|
||||
|
||||
// Stores whether the contents of the guest can be transparent.
|
||||
bool guest_opaque_;
|
||||
|
||||
// The extra parameters associated with this guest view passed
|
||||
// in from JavaScript. This will typically be the view instance ID,
|
||||
// the API to use, and view-specific parameters. These parameters
|
||||
// are passed along to new guests that are created from this guest.
|
||||
scoped_ptr<base::DictionaryValue> extra_params_;
|
||||
|
||||
// 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_;
|
||||
|
||||
// The size of the container element.
|
||||
gfx::Size element_size_;
|
||||
|
||||
// The size of the guest content. Note: In autosize mode, the container
|
||||
// element may not match the size of the guest.
|
||||
gfx::Size guest_size_;
|
||||
|
||||
// Indicates whether autosize mode is enabled or not.
|
||||
bool auto_size_enabled_;
|
||||
|
||||
// The maximum size constraints of the container element in autosize mode.
|
||||
gfx::Size max_auto_size_;
|
||||
|
||||
// The minimum size constraints of the container element in autosize mode.
|
||||
gfx::Size min_auto_size_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
||||
};
|
||||
|
||||
@@ -1,38 +1,40 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/atom_api_window.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/common/native_mate_converters/function_converter.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/callback.h"
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "native_mate/callback.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/gfx/point.h"
|
||||
#include "ui/gfx/rect.h"
|
||||
#include "ui/gfx/size.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace {
|
||||
|
||||
struct PrintSettings {
|
||||
bool silent;
|
||||
bool print_backgournd;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<gfx::Rect> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
gfx::Rect* out) {
|
||||
if (!val->IsObject())
|
||||
struct Converter<PrintSettings> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
PrintSettings* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
mate::Dictionary dict(isolate, val->ToObject());
|
||||
int x, y, width, height;
|
||||
if (!dict.Get("x", &x) || !dict.Get("y", &y) ||
|
||||
!dict.Get("width", &width) || !dict.Get("height", &height))
|
||||
return false;
|
||||
*out = gfx::Rect(x, y, width, height);
|
||||
dict.Get("silent", &(out->silent));
|
||||
dict.Get("printBackground", &(out->print_backgournd));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -81,6 +83,17 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
|
||||
*prevent_default = Emit("page-title-updated", args);
|
||||
}
|
||||
|
||||
void Window::WillCreatePopupWindow(const base::string16& frame_name,
|
||||
const GURL& target_url,
|
||||
const std::string& partition_id,
|
||||
WindowOpenDisposition disposition) {
|
||||
base::ListValue args;
|
||||
args.AppendString(target_url.spec());
|
||||
args.AppendString(frame_name);
|
||||
args.AppendInteger(disposition);
|
||||
Emit("-new-window", args);
|
||||
}
|
||||
|
||||
void Window::WillCloseWindow(bool* prevent_default) {
|
||||
*prevent_default = Emit("close");
|
||||
}
|
||||
@@ -108,8 +121,15 @@ void Window::OnRendererResponsive() {
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Wrappable* Window::New(const mate::Dictionary& options) {
|
||||
return new Window(options);
|
||||
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
||||
const mate::Dictionary& options) {
|
||||
if (Browser::Get()->is_ready()) {
|
||||
return new Window(options);
|
||||
} else {
|
||||
isolate->ThrowException(v8::Exception::TypeError(mate::StringToV8(
|
||||
isolate, "Can not create BrowserWindow before app is ready")));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Window::Destroy() {
|
||||
@@ -121,6 +141,10 @@ void Window::Close() {
|
||||
window_->Close();
|
||||
}
|
||||
|
||||
bool Window::IsClosed() {
|
||||
return window_->IsClosed();
|
||||
}
|
||||
|
||||
void Window::Focus() {
|
||||
window_->Focus(true);
|
||||
}
|
||||
@@ -133,6 +157,10 @@ void Window::Show() {
|
||||
window_->Show();
|
||||
}
|
||||
|
||||
void Window::ShowInactive() {
|
||||
window_->ShowInactive();
|
||||
}
|
||||
|
||||
void Window::Hide() {
|
||||
window_->Hide();
|
||||
}
|
||||
@@ -305,21 +333,6 @@ bool Window::IsWebViewFocused() {
|
||||
return window_->IsWebViewFocused();
|
||||
}
|
||||
|
||||
void Window::CapturePage(mate::Arguments* args) {
|
||||
gfx::Rect rect;
|
||||
base::Callback<void(v8::Handle<v8::Value>)> callback;
|
||||
|
||||
if (!(args->Length() == 1 && args->GetNext(&callback)) &&
|
||||
!(args->Length() == 2 && args->GetNext(&rect)
|
||||
&& args->GetNext(&callback))) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
|
||||
window_->CapturePage(
|
||||
rect, base::Bind(&OnCapturePageDone, args->isolate(), callback));
|
||||
}
|
||||
|
||||
void Window::SetRepresentedFilename(const std::string& filename) {
|
||||
window_->SetRepresentedFilename(filename);
|
||||
}
|
||||
@@ -336,13 +349,58 @@ bool Window::IsDocumentEdited() {
|
||||
return window_->IsDocumentEdited();
|
||||
}
|
||||
|
||||
void Window::CapturePage(mate::Arguments* args) {
|
||||
gfx::Rect rect;
|
||||
base::Callback<void(v8::Handle<v8::Value>)> callback;
|
||||
|
||||
if (!(args->Length() == 1 && args->GetNext(&callback)) &&
|
||||
!(args->Length() == 2 && args->GetNext(&rect)
|
||||
&& args->GetNext(&callback))) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
|
||||
window_->CapturePage(
|
||||
rect, base::Bind(&OnCapturePageDone, args->isolate(), callback));
|
||||
}
|
||||
|
||||
void Window::Print(mate::Arguments* args) {
|
||||
PrintSettings settings = { false, false };;
|
||||
if (args->Length() == 1 && !args->GetNext(&settings)) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
|
||||
window_->Print(settings.silent, settings.print_backgournd);
|
||||
}
|
||||
|
||||
void Window::SetProgressBar(double progress) {
|
||||
window_->SetProgressBar(progress);
|
||||
}
|
||||
|
||||
void Window::SetAutoHideMenuBar(bool auto_hide) {
|
||||
window_->SetAutoHideMenuBar(auto_hide);
|
||||
}
|
||||
|
||||
bool Window::IsMenuBarAutoHide() {
|
||||
return window_->IsMenuBarAutoHide();
|
||||
}
|
||||
|
||||
void Window::SetMenuBarVisibility(bool visible) {
|
||||
window_->SetMenuBarVisibility(visible);
|
||||
}
|
||||
|
||||
bool Window::IsMenuBarVisible() {
|
||||
return window_->IsMenuBarVisible();
|
||||
}
|
||||
|
||||
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
|
||||
return WebContents::Create(isolate, window_->GetWebContents());
|
||||
return WebContents::CreateFrom(isolate, window_->GetWebContents());
|
||||
}
|
||||
|
||||
mate::Handle<WebContents> Window::GetDevToolsWebContents(
|
||||
v8::Isolate* isolate) const {
|
||||
return WebContents::Create(isolate, window_->GetDevToolsWebContents());
|
||||
return WebContents::CreateFrom(isolate, window_->GetDevToolsWebContents());
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -351,9 +409,11 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||
.SetMethod("destroy", &Window::Destroy)
|
||||
.SetMethod("close", &Window::Close)
|
||||
.SetMethod("isClosed", &Window::IsClosed)
|
||||
.SetMethod("focus", &Window::Focus)
|
||||
.SetMethod("isFocused", &Window::IsFocused)
|
||||
.SetMethod("show", &Window::Show)
|
||||
.SetMethod("showInactive", &Window::ShowInactive)
|
||||
.SetMethod("hide", &Window::Hide)
|
||||
.SetMethod("isVisible", &Window::IsVisible)
|
||||
.SetMethod("maximize", &Window::Maximize)
|
||||
@@ -388,7 +448,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
|
||||
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
||||
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
||||
.SetMethod("IsDocumentEdited", &Window::IsDocumentEdited)
|
||||
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
|
||||
.SetMethod("_openDevTools", &Window::OpenDevTools)
|
||||
.SetMethod("closeDevTools", &Window::CloseDevTools)
|
||||
.SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened)
|
||||
@@ -397,6 +457,12 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("blurWebView", &Window::BlurWebView)
|
||||
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
|
||||
.SetMethod("capturePage", &Window::CapturePage)
|
||||
.SetMethod("print", &Window::Print)
|
||||
.SetMethod("setProgressBar", &Window::SetProgressBar)
|
||||
.SetMethod("setAutoHideMenuBar", &Window::SetAutoHideMenuBar)
|
||||
.SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide)
|
||||
.SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility)
|
||||
.SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible)
|
||||
.SetMethod("_getWebContents", &Window::GetWebContents)
|
||||
.SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -31,7 +31,8 @@ class WebContents;
|
||||
class Window : public mate::EventEmitter,
|
||||
public NativeWindowObserver {
|
||||
public:
|
||||
static mate::Wrappable* New(const mate::Dictionary& options);
|
||||
static mate::Wrappable* New(v8::Isolate* isolate,
|
||||
const mate::Dictionary& options);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Handle<v8::ObjectTemplate> prototype);
|
||||
@@ -43,22 +44,28 @@ class Window : public mate::EventEmitter,
|
||||
virtual ~Window();
|
||||
|
||||
// Implementations of NativeWindowObserver:
|
||||
virtual void OnPageTitleUpdated(bool* prevent_default,
|
||||
const std::string& title) OVERRIDE;
|
||||
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
|
||||
virtual void OnWindowClosed() OVERRIDE;
|
||||
virtual void OnWindowBlur() OVERRIDE;
|
||||
virtual void OnWindowFocus() OVERRIDE;
|
||||
virtual void OnRendererUnresponsive() OVERRIDE;
|
||||
virtual void OnRendererResponsive() OVERRIDE;
|
||||
void OnPageTitleUpdated(bool* prevent_default,
|
||||
const std::string& title) override;
|
||||
void WillCreatePopupWindow(const base::string16& frame_name,
|
||||
const GURL& target_url,
|
||||
const std::string& partition_id,
|
||||
WindowOpenDisposition disposition) override;
|
||||
void WillCloseWindow(bool* prevent_default) override;
|
||||
void OnWindowClosed() override;
|
||||
void OnWindowBlur() override;
|
||||
void OnWindowFocus() override;
|
||||
void OnRendererUnresponsive() override;
|
||||
void OnRendererResponsive() override;
|
||||
|
||||
private:
|
||||
// APIs for NativeWindow.
|
||||
void Destroy();
|
||||
void Close();
|
||||
bool IsClosed();
|
||||
void Focus();
|
||||
bool IsFocused();
|
||||
void Show();
|
||||
void ShowInactive();
|
||||
void Hide();
|
||||
bool IsVisible();
|
||||
void Maximize();
|
||||
@@ -97,11 +104,17 @@ class Window : public mate::EventEmitter,
|
||||
void FocusOnWebView();
|
||||
void BlurWebView();
|
||||
bool IsWebViewFocused();
|
||||
void CapturePage(mate::Arguments* args);
|
||||
void SetRepresentedFilename(const std::string& filename);
|
||||
std::string GetRepresentedFilename();
|
||||
void SetDocumentEdited(bool edited);
|
||||
bool IsDocumentEdited();
|
||||
void CapturePage(mate::Arguments* args);
|
||||
void Print(mate::Arguments* args);
|
||||
void SetProgressBar(double progress);
|
||||
void SetAutoHideMenuBar(bool auto_hide);
|
||||
bool IsMenuBarAutoHide();
|
||||
void SetMenuBarVisibility(bool visible);
|
||||
bool IsMenuBarVisible();
|
||||
|
||||
// APIs for WebContents.
|
||||
mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -11,19 +11,29 @@
|
||||
|
||||
namespace mate {
|
||||
|
||||
namespace {
|
||||
|
||||
v8::Persistent<v8::ObjectTemplate> template_;
|
||||
|
||||
} // namespace
|
||||
|
||||
Event::Event()
|
||||
: sender_(NULL),
|
||||
message_(NULL),
|
||||
prevent_default_(false) {
|
||||
message_(NULL) {
|
||||
}
|
||||
|
||||
Event::~Event() {
|
||||
}
|
||||
|
||||
ObjectTemplateBuilder Event::GetObjectTemplateBuilder(v8::Isolate* isolate) {
|
||||
return ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("preventDefault", &Event::PreventDefault)
|
||||
.SetMethod("sendReply", &Event::SendReply);
|
||||
if (template_.IsEmpty())
|
||||
template_.Reset(isolate, ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("preventDefault", &Event::PreventDefault)
|
||||
.SetMethod("sendReply", &Event::SendReply)
|
||||
.Build());
|
||||
|
||||
return ObjectTemplateBuilder(
|
||||
isolate, v8::Local<v8::ObjectTemplate>::New(isolate, template_));
|
||||
}
|
||||
|
||||
void Event::SetSenderAndMessage(content::WebContents* sender,
|
||||
@@ -41,8 +51,9 @@ void Event::WebContentsDestroyed() {
|
||||
message_ = NULL;
|
||||
}
|
||||
|
||||
void Event::PreventDefault() {
|
||||
prevent_default_ = true;
|
||||
void Event::PreventDefault(v8::Isolate* isolate) {
|
||||
GetWrapper(isolate)->Set(StringToV8(isolate, "defaultPrevented"),
|
||||
v8::True(isolate));
|
||||
}
|
||||
|
||||
bool Event::SendReply(const base::string16& json) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -24,14 +24,11 @@ class Event : public Wrappable,
|
||||
void SetSenderAndMessage(content::WebContents* sender, IPC::Message* message);
|
||||
|
||||
// event.PreventDefault().
|
||||
void PreventDefault();
|
||||
void PreventDefault(v8::Isolate* isolate);
|
||||
|
||||
// event.sendReply(json), used for replying synchronous message.
|
||||
bool SendReply(const base::string16& json);
|
||||
|
||||
// Whether event.preventDefault() is called.
|
||||
bool prevent_default() const { return prevent_default_; }
|
||||
|
||||
protected:
|
||||
Event();
|
||||
virtual ~Event();
|
||||
@@ -47,8 +44,6 @@ class Event : public Wrappable,
|
||||
content::WebContents* sender_;
|
||||
IPC::Message* message_;
|
||||
|
||||
bool prevent_default_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Event);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,20 +1,43 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// 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/api/event_emitter.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/event.h"
|
||||
#include "atom/common/native_mate_converters/v8_value_converter.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/values.h"
|
||||
#include "native_mate/arguments.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
namespace {
|
||||
|
||||
v8::Persistent<v8::ObjectTemplate> event_template;
|
||||
|
||||
void PreventDefault(mate::Arguments* args) {
|
||||
args->GetThis()->Set(StringToV8(args->isolate(), "defaultPrevented"),
|
||||
v8::True(args->isolate()));
|
||||
}
|
||||
|
||||
// Create a pure JavaScript Event object.
|
||||
v8::Local<v8::Object> CreateEventObject(v8::Isolate* isolate) {
|
||||
if (event_template.IsEmpty()) {
|
||||
event_template.Reset(isolate, ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("preventDefault", &PreventDefault)
|
||||
.Build());
|
||||
}
|
||||
|
||||
return v8::Local<v8::ObjectTemplate>::New(
|
||||
isolate, event_template)->NewInstance();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EventEmitter::EventEmitter() {
|
||||
}
|
||||
|
||||
@@ -38,26 +61,43 @@ bool EventEmitter::Emit(const base::StringPiece& name,
|
||||
v8::Handle<v8::Context> context = isolate->GetCurrentContext();
|
||||
scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
|
||||
|
||||
mate::Handle<mate::Event> event = mate::Event::Create(isolate);
|
||||
if (sender && message)
|
||||
event->SetSenderAndMessage(sender, message);
|
||||
|
||||
// v8_args = [name, event, args...];
|
||||
std::vector<v8::Handle<v8::Value>> v8_args;
|
||||
v8_args.reserve(args.GetSize() + 2);
|
||||
v8_args.push_back(mate::StringToV8(isolate, name));
|
||||
v8_args.push_back(event.ToV8());
|
||||
// v8_args = [args...];
|
||||
Arguments v8_args;
|
||||
v8_args.reserve(args.GetSize());
|
||||
for (size_t i = 0; i < args.GetSize(); i++) {
|
||||
const base::Value* value(NULL);
|
||||
if (args.Get(i, &value))
|
||||
v8_args.push_back(converter->ToV8Value(value, context));
|
||||
}
|
||||
|
||||
// this.emit.apply(this, v8_args);
|
||||
node::MakeCallback(isolate, GetWrapper(isolate), "emit", v8_args.size(),
|
||||
&v8_args[0]);
|
||||
return Emit(isolate, name, v8_args, sender, message);
|
||||
}
|
||||
|
||||
return event->prevent_default();
|
||||
bool EventEmitter::Emit(v8::Isolate* isolate,
|
||||
const base::StringPiece& name,
|
||||
Arguments args,
|
||||
content::WebContents* sender,
|
||||
IPC::Message* message) {
|
||||
v8::Handle<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());
|
||||
} else {
|
||||
event = CreateEventObject(isolate);
|
||||
}
|
||||
|
||||
// args = [name, event, args...];
|
||||
args.insert(args.begin(), event);
|
||||
args.insert(args.begin(), mate::StringToV8(isolate, name));
|
||||
|
||||
// this.emit.apply(this, args);
|
||||
node::MakeCallback(isolate, GetWrapper(isolate), "emit", args.size(),
|
||||
&args[0]);
|
||||
|
||||
return event->Get(StringToV8(isolate, "defaultPrevented"))->BooleanValue();
|
||||
}
|
||||
|
||||
} // namespace mate
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// 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_API_EVENT_EMITTER_H_
|
||||
#define ATOM_BROWSER_API_EVENT_EMITTER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "native_mate/wrappable.h"
|
||||
|
||||
namespace base {
|
||||
@@ -23,6 +25,9 @@ namespace mate {
|
||||
|
||||
// Provide helperers to emit event in JavaScript.
|
||||
class EventEmitter : public Wrappable {
|
||||
public:
|
||||
typedef std::vector<v8::Handle<v8::Value>> Arguments;
|
||||
|
||||
protected:
|
||||
EventEmitter();
|
||||
|
||||
@@ -36,6 +41,13 @@ class EventEmitter : public Wrappable {
|
||||
bool Emit(const base::StringPiece& name, const base::ListValue& args,
|
||||
content::WebContents* sender, IPC::Message* message);
|
||||
|
||||
// Lower level implementations.
|
||||
bool Emit(v8::Isolate* isolate,
|
||||
const base::StringPiece& name,
|
||||
Arguments args,
|
||||
content::WebContents* sender = nullptr,
|
||||
IPC::Message* message = nullptr);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(EventEmitter);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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
|
||||
@@ -23,6 +24,12 @@ BrowserWindow::_init = ->
|
||||
value: BrowserWindow.windows.add(this)
|
||||
enumerable: true
|
||||
|
||||
# Make new windows requested by links behave like "window.open"
|
||||
@on '-new-window', (event, url, frameName) =>
|
||||
event.sender = @webContents
|
||||
options = show: true, width: 800, height: 600
|
||||
ipc.emit 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options
|
||||
|
||||
# Remove the window from weak map immediately when it's destroyed, since we
|
||||
# could be iterating windows before GC happened.
|
||||
@once 'closed', =>
|
||||
@@ -35,6 +42,10 @@ BrowserWindow::openDevTools = ->
|
||||
@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()
|
||||
|
||||
@@ -79,8 +90,8 @@ BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
||||
# Be compatible with old API.
|
||||
BrowserWindow::restart = -> @webContents.reload()
|
||||
BrowserWindow::getUrl = -> @webContents.getUrl()
|
||||
BrowserWindow::reload = -> @webContents.reload()
|
||||
BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache()
|
||||
BrowserWindow::reload = -> @webContents.reload.apply @webContents, arguments
|
||||
BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache.apply @webContents, arguments
|
||||
BrowserWindow::getPageTitle = -> @webContents.getTitle()
|
||||
BrowserWindow::isLoading = -> @webContents.isLoading()
|
||||
BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
binding = process.atomBinding 'dialog'
|
||||
v8Util = process.atomBinding 'v8_util'
|
||||
app = require 'app'
|
||||
BrowserWindow = require 'browser-window'
|
||||
|
||||
fileDialogProperties =
|
||||
openFile: 1, openDirectory: 2, multiSelections: 4, createDirectory: 8
|
||||
openFile: 1 << 0
|
||||
openDirectory: 1 << 1
|
||||
multiSelections: 1 << 2
|
||||
createDirectory: 1 << 3
|
||||
|
||||
messageBoxTypes = ['none', 'info', 'warning']
|
||||
|
||||
parseArgs = (window, options, callback) ->
|
||||
unless window is null or window?.constructor is BrowserWindow
|
||||
# Shift.
|
||||
callback = options
|
||||
options = window
|
||||
window = null
|
||||
if not callback? and typeof options is 'function'
|
||||
# Shift.
|
||||
callback = options
|
||||
options = null
|
||||
[window, options, callback]
|
||||
|
||||
checkAppInitialized = ->
|
||||
throw new Error('dialog module can only be used after app is ready') unless app.isReady()
|
||||
|
||||
module.exports =
|
||||
showOpenDialog: (window, options, callback) ->
|
||||
unless window?.constructor is BrowserWindow
|
||||
# Shift.
|
||||
callback = options
|
||||
options = window
|
||||
window = null
|
||||
showOpenDialog: (args...) ->
|
||||
checkAppInitialized()
|
||||
[window, options, callback] = parseArgs args...
|
||||
|
||||
options ?= title: 'Open', properties: ['openFile']
|
||||
options.properties ?= ['openFile']
|
||||
@@ -25,6 +41,7 @@ module.exports =
|
||||
|
||||
options.title ?= ''
|
||||
options.defaultPath ?= ''
|
||||
options.filters ?= []
|
||||
|
||||
wrappedCallback =
|
||||
if typeof callback is 'function'
|
||||
@@ -34,20 +51,19 @@ module.exports =
|
||||
|
||||
binding.showOpenDialog String(options.title),
|
||||
String(options.defaultPath),
|
||||
options.filters
|
||||
properties,
|
||||
window,
|
||||
wrappedCallback
|
||||
|
||||
showSaveDialog: (window, options, callback) ->
|
||||
unless window?.constructor is BrowserWindow
|
||||
# Shift.
|
||||
callback = options
|
||||
options = window
|
||||
window = null
|
||||
showSaveDialog: (args...) ->
|
||||
checkAppInitialized()
|
||||
[window, options, callback] = parseArgs args...
|
||||
|
||||
options ?= title: 'Save'
|
||||
options.title ?= ''
|
||||
options.defaultPath ?= ''
|
||||
options.filters ?= []
|
||||
|
||||
wrappedCallback =
|
||||
if typeof callback is 'function'
|
||||
@@ -57,15 +73,13 @@ module.exports =
|
||||
|
||||
binding.showSaveDialog String(options.title),
|
||||
String(options.defaultPath),
|
||||
options.filters
|
||||
window,
|
||||
wrappedCallback
|
||||
|
||||
showMessageBox: (window, options, callback) ->
|
||||
unless window?.constructor is BrowserWindow
|
||||
# Shift.
|
||||
callback = options
|
||||
options = window
|
||||
window = null
|
||||
showMessageBox: (args...) ->
|
||||
checkAppInitialized()
|
||||
[window, options, callback] = parseArgs args...
|
||||
|
||||
options ?= type: 'none'
|
||||
options.type ?= 'none'
|
||||
@@ -86,5 +100,8 @@ module.exports =
|
||||
window,
|
||||
callback
|
||||
|
||||
showErrorBox: (args...) ->
|
||||
binding.showErrorBox args...
|
||||
|
||||
# Mark standard asynchronous functions.
|
||||
v8Util.setHiddenValue f, 'asynchronous', true for k, f of module.exports
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
app = require 'app'
|
||||
throw new Error('Can not initialize protocol module before app is ready') unless app.isReady()
|
||||
|
||||
protocol = process.atomBinding('protocol').protocol
|
||||
EventEmitter = require('events').EventEmitter
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
EventEmitter = require('events').EventEmitter
|
||||
binding = process.atomBinding 'web_contents'
|
||||
ipc = require 'ipc'
|
||||
|
||||
module.exports.wrap = (webContents) ->
|
||||
@@ -25,18 +26,37 @@ 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
|
||||
|
||||
# Translate |disposition| to string for 'new-window' event.
|
||||
webContents.on '-new-window', (args..., disposition) ->
|
||||
disposition =
|
||||
switch disposition
|
||||
when 2 then 'default'
|
||||
when 4 then 'foreground-tab'
|
||||
when 5 then 'background-tab'
|
||||
when 6, 7 then 'new-window'
|
||||
else 'other'
|
||||
@emit 'new-window', args..., disposition
|
||||
|
||||
# Tell the rpc server that a render view has been deleted and we need to
|
||||
# release all objects owned by it.
|
||||
webContents.on 'render-view-deleted', (event, processId, routingId) ->
|
||||
process.emit 'ATOM_BROWSER_RELEASE_RENDER_VIEW', "#{processId}-#{routingId}"
|
||||
|
||||
# Dispatch IPC messages to the ipc module.
|
||||
webContents.on 'ipc-message', (event, channel, args...) =>
|
||||
webContents.on 'ipc-message', (event, channel, args...) ->
|
||||
Object.defineProperty event, 'sender', value: webContents
|
||||
ipc.emit channel, event, args...
|
||||
webContents.on 'ipc-message-sync', (event, channel, args...) =>
|
||||
webContents.on 'ipc-message-sync', (event, channel, args...) ->
|
||||
Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value)
|
||||
Object.defineProperty event, 'sender', value: webContents
|
||||
ipc.emit channel, event, args...
|
||||
|
||||
webContents
|
||||
|
||||
module.exports.create = (options={}) ->
|
||||
@wrap binding.create(options)
|
||||
|
||||
50
atom/browser/atom_access_token_store.cc
Normal file
50
atom/browser/atom_access_token_store.cc
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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/atom_access_token_store.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/common/google_api_key.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
// Notice that we just combined the api key with the url together here, because
|
||||
// if we use the standard {url: key} format Chromium would override our key with
|
||||
// the predefined one in common.gypi of libchromiumcontent, which is empty.
|
||||
const char* kGeolocationProviderUrl =
|
||||
"https://www.googleapis.com/geolocation/v1/geolocate?key="
|
||||
GOOGLEAPIS_API_KEY;
|
||||
|
||||
} // namespace
|
||||
|
||||
AtomAccessTokenStore::AtomAccessTokenStore() {
|
||||
}
|
||||
|
||||
AtomAccessTokenStore::~AtomAccessTokenStore() {
|
||||
}
|
||||
|
||||
void AtomAccessTokenStore::LoadAccessTokens(
|
||||
const LoadAccessTokensCallbackType& callback) {
|
||||
AccessTokenSet access_token_set;
|
||||
|
||||
// Equivelent to access_token_set[kGeolocationProviderUrl].
|
||||
// Somehow base::string16 is causing compilation errors when used in a pair
|
||||
// of std::map on Linux, this can work around it.
|
||||
std::pair<GURL, base::string16> token_pair;
|
||||
token_pair.first = GURL(kGeolocationProviderUrl);
|
||||
access_token_set.insert(token_pair);
|
||||
|
||||
callback.Run(access_token_set,
|
||||
AtomBrowserContext::Get()->url_request_context_getter());
|
||||
}
|
||||
|
||||
void AtomAccessTokenStore::SaveAccessToken(const GURL& server_url,
|
||||
const base::string16& access_token) {
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
31
atom/browser/atom_access_token_store.h
Normal file
31
atom/browser/atom_access_token_store.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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_ATOM_ACCESS_TOKEN_STORE_H_
|
||||
#define ATOM_BROWSER_ATOM_ACCESS_TOKEN_STORE_H_
|
||||
|
||||
#include "content/public/browser/access_token_store.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
|
||||
class AtomAccessTokenStore : public content::AccessTokenStore {
|
||||
public:
|
||||
AtomAccessTokenStore();
|
||||
virtual ~AtomAccessTokenStore();
|
||||
|
||||
// content::AccessTokenStore:
|
||||
virtual void LoadAccessTokens(
|
||||
const LoadAccessTokensCallbackType& callback) OVERRIDE;
|
||||
virtual void SaveAccessToken(const GURL& server_url,
|
||||
const base::string16& access_token) OVERRIDE;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomAccessTokenStore);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_ATOM_ACCESS_TOKEN_STORE_H_
|
||||
@@ -1,20 +1,27 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 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_browser_client.h"
|
||||
|
||||
#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_speech_recognition_manager_delegate.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/net/atom_url_request_context_getter.h"
|
||||
#include "atom/browser/web_view/web_view_renderer_state.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "chrome/browser/printing/printing_message_filter.h"
|
||||
#include "chrome/browser/speech/tts_message_filter.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/site_instance.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "webkit/common/webpreferences.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -46,22 +53,30 @@ AtomBrowserClient::AtomBrowserClient()
|
||||
AtomBrowserClient::~AtomBrowserClient() {
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter* AtomBrowserClient::CreateRequestContext(
|
||||
content::BrowserContext* browser_context,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::ProtocolHandlerScopedVector protocol_interceptors) {
|
||||
return static_cast<AtomBrowserContext*>(browser_context)->
|
||||
CreateRequestContext(protocol_handlers);
|
||||
void AtomBrowserClient::RenderProcessWillLaunch(
|
||||
content::RenderProcessHost* host) {
|
||||
int id = host->GetID();
|
||||
host->AddFilter(new PrintingMessageFilter(host->GetID()));
|
||||
host->AddFilter(new TtsMessageFilter(id, host->GetBrowserContext()));
|
||||
}
|
||||
|
||||
content::SpeechRecognitionManagerDelegate*
|
||||
AtomBrowserClient::GetSpeechRecognitionManagerDelegate() {
|
||||
return new AtomSpeechRecognitionManagerDelegate;
|
||||
}
|
||||
|
||||
content::AccessTokenStore* AtomBrowserClient::CreateAccessTokenStore() {
|
||||
return new AtomAccessTokenStore;
|
||||
}
|
||||
|
||||
void AtomBrowserClient::OverrideWebkitPrefs(
|
||||
content::RenderViewHost* render_view_host,
|
||||
const GURL& url,
|
||||
WebPreferences* prefs) {
|
||||
content::WebPreferences* prefs) {
|
||||
prefs->javascript_enabled = true;
|
||||
prefs->web_security_enabled = true;
|
||||
prefs->javascript_can_open_windows_automatically = true;
|
||||
prefs->plugins_enabled = false;
|
||||
prefs->plugins_enabled = true;
|
||||
prefs->dom_paste_enabled = true;
|
||||
prefs->java_enabled = false;
|
||||
prefs->allow_scripts_to_close_windows = true;
|
||||
@@ -75,6 +90,12 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
||||
prefs->allow_displaying_insecure_content = true;
|
||||
prefs->allow_running_insecure_content = true;
|
||||
|
||||
// Turn off web security for devtools.
|
||||
if (url.SchemeIs("chrome-devtools")) {
|
||||
prefs->web_security_enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
NativeWindow* window = NativeWindow::FromRenderView(
|
||||
render_view_host->GetProcess()->GetID(),
|
||||
render_view_host->GetRoutingID());
|
||||
@@ -121,8 +142,26 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||
window = *iter;
|
||||
}
|
||||
|
||||
if (window != NULL)
|
||||
if (window != NULL) {
|
||||
window->AppendExtraCommandLineSwitches(command_line, child_process_id);
|
||||
} else {
|
||||
// Append commnad line arguments for guest web view.
|
||||
WebViewRendererState::WebViewInfo info;
|
||||
if (WebViewRendererState::GetInstance()->GetInfo(child_process_id, &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);
|
||||
}
|
||||
}
|
||||
|
||||
dying_render_process_ = NULL;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -18,24 +18,24 @@ class AtomBrowserClient : public brightray::BrowserClient {
|
||||
|
||||
protected:
|
||||
// content::ContentBrowserClient:
|
||||
net::URLRequestContextGetter* CreateRequestContext(
|
||||
content::BrowserContext* browser_context,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE;
|
||||
virtual void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
|
||||
const GURL& url,
|
||||
WebPreferences* prefs) OVERRIDE;
|
||||
virtual bool ShouldSwapBrowsingInstancesForNavigation(
|
||||
void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
|
||||
content::SpeechRecognitionManagerDelegate*
|
||||
GetSpeechRecognitionManagerDelegate() override;
|
||||
content::AccessTokenStore* CreateAccessTokenStore() 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;
|
||||
virtual std::string GetApplicationLocale() OVERRIDE;
|
||||
virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id) OVERRIDE;
|
||||
const GURL& new_url) override;
|
||||
std::string GetApplicationLocale() override;
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id) override;
|
||||
|
||||
private:
|
||||
virtual brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||
const content::MainFunctionParams&) OVERRIDE;
|
||||
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||
const content::MainFunctionParams&) override;
|
||||
|
||||
// The render process which would be swapped out soon.
|
||||
content::RenderProcessHost* dying_render_process_;
|
||||
|
||||
@@ -1,76 +1,78 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 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_browser_context.h"
|
||||
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/net/atom_url_request_context_getter.h"
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
||||
#include "atom/browser/web_view/web_view_manager.h"
|
||||
#include "base/threading/sequenced_worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/resource_context.h"
|
||||
#include "vendor/brightray/browser/network_delegate.h"
|
||||
|
||||
namespace atom {
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "net/url_request/data_protocol_handler.h"
|
||||
#include "net/url_request/file_protocol_handler.h"
|
||||
#include "net/url_request/url_request_intercepting_job_factory.h"
|
||||
#include "url/url_constants.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
class AtomResourceContext : public content::ResourceContext {
|
||||
public:
|
||||
AtomResourceContext() : getter_(NULL) {}
|
||||
namespace atom {
|
||||
|
||||
void set_url_request_context_getter(AtomURLRequestContextGetter* getter) {
|
||||
getter_ = getter;
|
||||
}
|
||||
namespace {
|
||||
|
||||
protected:
|
||||
virtual net::HostResolver* GetHostResolver() OVERRIDE {
|
||||
DCHECK(getter_);
|
||||
return getter_->host_resolver();
|
||||
}
|
||||
const char* kAsarScheme = "asar";
|
||||
|
||||
virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
|
||||
DCHECK(getter_);
|
||||
return getter_->GetURLRequestContext();
|
||||
}
|
||||
|
||||
virtual bool AllowMicAccess(const GURL& origin) OVERRIDE {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE {
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
AtomURLRequestContextGetter* getter_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomResourceContext);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
AtomBrowserContext::AtomBrowserContext()
|
||||
: resource_context_(new AtomResourceContext) {
|
||||
: fake_browser_process_(new BrowserProcess),
|
||||
job_factory_(new AtomURLRequestJobFactory) {
|
||||
}
|
||||
|
||||
AtomBrowserContext::~AtomBrowserContext() {
|
||||
}
|
||||
|
||||
AtomURLRequestContextGetter* AtomBrowserContext::CreateRequestContext(
|
||||
content::ProtocolHandlerMap* protocol_handlers) {
|
||||
DCHECK(!url_request_getter_);
|
||||
url_request_getter_ = new AtomURLRequestContextGetter(
|
||||
GetPath(),
|
||||
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
|
||||
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
|
||||
base::Bind(&AtomBrowserContext::CreateNetworkDelegate,
|
||||
base::Unretained(this)),
|
||||
protocol_handlers);
|
||||
net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* handlers,
|
||||
content::URLRequestInterceptorScopedVector* interceptors) {
|
||||
scoped_ptr<AtomURLRequestJobFactory> job_factory(job_factory_);
|
||||
|
||||
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
||||
return url_request_getter_.get();
|
||||
for (content::ProtocolHandlerMap::iterator it = handlers->begin();
|
||||
it != handlers->end(); ++it)
|
||||
job_factory->SetProtocolHandler(it->first, it->second.release());
|
||||
handlers->clear();
|
||||
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kDataScheme, new net::DataProtocolHandler);
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kFileScheme, new net::FileProtocolHandler(
|
||||
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
||||
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
|
||||
job_factory->SetProtocolHandler(
|
||||
kAsarScheme, new asar::AsarProtocolHandler(
|
||||
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
||||
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
|
||||
|
||||
// Set up interceptors in the reverse order.
|
||||
scoped_ptr<net::URLRequestJobFactory> top_job_factory =
|
||||
job_factory.PassAs<net::URLRequestJobFactory>();
|
||||
content::URLRequestInterceptorScopedVector::reverse_iterator it;
|
||||
for (it = interceptors->rbegin(); it != interceptors->rend(); ++it)
|
||||
top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
|
||||
top_job_factory.Pass(), make_scoped_ptr(*it)));
|
||||
interceptors->weak_clear();
|
||||
|
||||
return top_job_factory.release();
|
||||
}
|
||||
|
||||
content::ResourceContext* AtomBrowserContext::GetResourceContext() {
|
||||
return resource_context_.get();
|
||||
content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() {
|
||||
if (!guest_manager_)
|
||||
guest_manager_.reset(new WebViewManager(this));
|
||||
return guest_manager_.get();
|
||||
}
|
||||
|
||||
// static
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 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_BROWSER_CONTEXT_H_
|
||||
#define ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
|
||||
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "brightray/browser/browser_context.h"
|
||||
|
||||
class BrowserProcess;
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomResourceContext;
|
||||
class AtomURLRequestContextGetter;
|
||||
class AtomURLRequestJobFactory;
|
||||
class WebViewManager;
|
||||
|
||||
class AtomBrowserContext : public brightray::BrowserContext {
|
||||
public:
|
||||
@@ -21,22 +22,22 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||
// Returns the browser context singleton.
|
||||
static AtomBrowserContext* Get();
|
||||
|
||||
// Creates or returns the request context.
|
||||
AtomURLRequestContextGetter* CreateRequestContext(
|
||||
content::ProtocolHandlerMap*);
|
||||
// brightray::URLRequestContextGetter::Delegate:
|
||||
virtual net::URLRequestJobFactory* CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* handlers,
|
||||
content::URLRequestInterceptorScopedVector* interceptors) override;
|
||||
|
||||
AtomURLRequestContextGetter* url_request_context_getter() const {
|
||||
DCHECK(url_request_getter_);
|
||||
return url_request_getter_.get();
|
||||
}
|
||||
// content::BrowserContext:
|
||||
virtual content::BrowserPluginGuestManager* GetGuestManager() override;
|
||||
|
||||
protected:
|
||||
// content::BrowserContext implementations:
|
||||
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
|
||||
AtomURLRequestJobFactory* job_factory() const { return job_factory_; }
|
||||
|
||||
private:
|
||||
scoped_ptr<AtomResourceContext> resource_context_;
|
||||
scoped_refptr<AtomURLRequestContextGetter> url_request_getter_;
|
||||
// A fake BrowserProcess object that used to feed the source code from chrome.
|
||||
scoped_ptr<BrowserProcess> fake_browser_process_;
|
||||
scoped_ptr<WebViewManager> guest_manager_;
|
||||
|
||||
AtomURLRequestJobFactory* job_factory_; // Weak reference.
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -8,13 +8,11 @@
|
||||
#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"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "ui/gfx/win/dpi.h"
|
||||
#endif
|
||||
#include "v8/include/v8-debug.h"
|
||||
|
||||
#if defined(USE_X11)
|
||||
#include "chrome/browser/ui/libgtk2ui/gtk2_util.h"
|
||||
@@ -30,7 +28,8 @@ AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL;
|
||||
AtomBrowserMainParts::AtomBrowserMainParts()
|
||||
: browser_(new Browser),
|
||||
node_bindings_(NodeBindings::Create(true)),
|
||||
atom_bindings_(new AtomBindings) {
|
||||
atom_bindings_(new AtomBindings),
|
||||
gc_timer_(true, true) {
|
||||
DCHECK(!self_) << "Cannot have two AtomBrowserMainParts";
|
||||
self_ = this;
|
||||
}
|
||||
@@ -51,15 +50,26 @@ brightray::BrowserContext* AtomBrowserMainParts::CreateBrowserContext() {
|
||||
void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||
brightray::BrowserMainParts::PostEarlyInitialization();
|
||||
|
||||
#if defined(USE_X11)
|
||||
SetDPIFromGSettings();
|
||||
#endif
|
||||
|
||||
// The ProxyResolverV8 has setup a complete V8 environment, in order to avoid
|
||||
// conflicts we only initialize our V8 environment after that.
|
||||
js_env_.reset(new JavascriptEnvironment);
|
||||
|
||||
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());
|
||||
}
|
||||
@@ -70,16 +80,19 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
|
||||
node_bindings_->PrepareMessageLoop();
|
||||
node_bindings_->RunMessageLoop();
|
||||
|
||||
// Start idle gc.
|
||||
gc_timer_.Start(
|
||||
FROM_HERE, base::TimeDelta::FromMinutes(1),
|
||||
base::Bind(base::IgnoreResult(&v8::Isolate::IdleNotification),
|
||||
base::Unretained(js_env_->isolate()),
|
||||
1000));
|
||||
|
||||
brightray::BrowserMainParts::PreMainMessageLoopRun();
|
||||
|
||||
#if defined(USE_X11)
|
||||
libgtk2ui::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess());
|
||||
#endif
|
||||
|
||||
// Make sure the url request job factory is created before the ready event.
|
||||
static_cast<content::BrowserContext*>(AtomBrowserContext::Get())->
|
||||
GetRequestContext();
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
// The corresponding call in OS X is in AtomApplicationDelegate.
|
||||
Browser::Get()->WillFinishLaunching();
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 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_BROWSER_MAIN_PARTS_H_
|
||||
#define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
|
||||
|
||||
#include "base/timer/timer.h"
|
||||
#include "brightray/browser/browser_main_parts.h"
|
||||
|
||||
namespace atom {
|
||||
@@ -13,6 +14,7 @@ class AtomBindings;
|
||||
class Browser;
|
||||
class JavascriptEnvironment;
|
||||
class NodeBindings;
|
||||
class NodeDebugger;
|
||||
|
||||
class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
public:
|
||||
@@ -36,10 +38,17 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if defined(USE_X11)
|
||||
void SetDPIFromGSettings();
|
||||
#endif
|
||||
|
||||
scoped_ptr<Browser> browser_;
|
||||
scoped_ptr<JavascriptEnvironment> js_env_;
|
||||
scoped_ptr<NodeBindings> node_bindings_;
|
||||
scoped_ptr<AtomBindings> atom_bindings_;
|
||||
scoped_ptr<NodeDebugger> node_debugger_;
|
||||
|
||||
base::Timer gc_timer_;
|
||||
|
||||
static AtomBrowserMainParts* self_;
|
||||
|
||||
|
||||
82
atom/browser/atom_browser_main_parts_linux.cc
Normal file
82
atom/browser/atom_browser_main_parts_linux.cc
Normal file
@@ -0,0 +1,82 @@
|
||||
// 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/atom_browser_main_parts.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "library_loaders/libgio.h"
|
||||
#include "ui/gfx/switches.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
const char* kInterfaceSchema = "org.gnome.desktop.interface";
|
||||
const char* kScaleFactor = "scaling-factor";
|
||||
|
||||
bool SchemaExists(const LibGioLoader& libgio_loader, const char* schema_name) {
|
||||
const gchar* const* schemas = libgio_loader.g_settings_list_schemas();
|
||||
while (*schemas) {
|
||||
if (strcmp(schema_name, static_cast<const char*>(*schemas)) == 0)
|
||||
return true;
|
||||
schemas++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool KeyExists(const LibGioLoader& libgio_loader, GSettings* client,
|
||||
const char* key) {
|
||||
gchar** keys = libgio_loader.g_settings_list_keys(client);
|
||||
if (!keys)
|
||||
return false;
|
||||
|
||||
gchar** iter = keys;
|
||||
while (*iter) {
|
||||
if (strcmp(*iter, key) == 0)
|
||||
break;
|
||||
iter++;
|
||||
}
|
||||
|
||||
bool exists = *iter != NULL;
|
||||
g_strfreev(keys);
|
||||
return exists;
|
||||
}
|
||||
|
||||
void GetDPIFromGSettings(guint* scale_factor) {
|
||||
LibGioLoader libgio_loader;
|
||||
|
||||
// Try also without .0 at the end; on some systems this may be required.
|
||||
if (!libgio_loader.Load("libgio-2.0.so.0") &&
|
||||
!libgio_loader.Load("libgio-2.0.so")) {
|
||||
VLOG(1) << "Cannot load gio library. Will fall back to gconf.";
|
||||
return;
|
||||
}
|
||||
|
||||
GSettings* client = nullptr;
|
||||
if (!SchemaExists(libgio_loader, kInterfaceSchema) ||
|
||||
!(client = libgio_loader.g_settings_new(kInterfaceSchema))) {
|
||||
VLOG(1) << "Cannot create gsettings client.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (KeyExists(libgio_loader, client, kScaleFactor))
|
||||
*scale_factor = libgio_loader.g_settings_get_uint(client, kScaleFactor);
|
||||
|
||||
g_object_unref(client);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void AtomBrowserMainParts::SetDPIFromGSettings() {
|
||||
guint scale_factor = 1;
|
||||
GetDPIFromGSettings(&scale_factor);
|
||||
if (scale_factor == 0)
|
||||
scale_factor = 1;
|
||||
|
||||
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
||||
switches::kForceDeviceScaleFactor, base::UintToString(scale_factor));
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -21,7 +21,7 @@ void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
||||
NSApplication* application = [AtomApplication sharedApplication];
|
||||
|
||||
AtomApplicationDelegate* delegate = [AtomApplicationDelegate alloc];
|
||||
[NSApp setDelegate:delegate];
|
||||
[NSApp setDelegate:(id<NSFileManagerDelegate>)delegate];
|
||||
|
||||
base::FilePath frameworkPath = brightray::MainApplicationBundlePath()
|
||||
.Append("Contents")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
74
atom/browser/atom_speech_recognition_manager_delegate.cc
Normal file
74
atom/browser/atom_speech_recognition_manager_delegate.cc
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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/atom_speech_recognition_manager_delegate.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/callback.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
AtomSpeechRecognitionManagerDelegate::AtomSpeechRecognitionManagerDelegate() {
|
||||
}
|
||||
|
||||
AtomSpeechRecognitionManagerDelegate::~AtomSpeechRecognitionManagerDelegate() {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnRecognitionStart(int session_id) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnAudioStart(int session_id) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnEnvironmentEstimationComplete(
|
||||
int session_id) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnSoundStart(int session_id) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnSoundEnd(int session_id) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnAudioEnd(int session_id) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnRecognitionEnd(int session_id) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnRecognitionResults(
|
||||
int session_id, const content::SpeechRecognitionResults& result) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnRecognitionError(
|
||||
int session_id, const content::SpeechRecognitionError& error) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::OnAudioLevelsChange(
|
||||
int session_id, float volume, float noise_volume) {
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::GetDiagnosticInformation(
|
||||
bool* can_report_metrics, std::string* hardware_info) {
|
||||
*can_report_metrics = false;
|
||||
}
|
||||
|
||||
void AtomSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
|
||||
int session_id,
|
||||
base::Callback<void(bool ask_user, bool is_allowed)> callback) {
|
||||
callback.Run(true, true);
|
||||
}
|
||||
|
||||
content::SpeechRecognitionEventListener*
|
||||
AtomSpeechRecognitionManagerDelegate::GetEventListener() {
|
||||
return this;
|
||||
}
|
||||
|
||||
bool AtomSpeechRecognitionManagerDelegate::FilterProfanities(
|
||||
int render_process_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
52
atom/browser/atom_speech_recognition_manager_delegate.h
Normal file
52
atom/browser/atom_speech_recognition_manager_delegate.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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_ATOM_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
|
||||
#define ATOM_BROWSER_ATOM_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "content/public/browser/speech_recognition_event_listener.h"
|
||||
#include "content/public/browser/speech_recognition_manager_delegate.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomSpeechRecognitionManagerDelegate
|
||||
: public content::SpeechRecognitionManagerDelegate,
|
||||
public content::SpeechRecognitionEventListener {
|
||||
public:
|
||||
AtomSpeechRecognitionManagerDelegate();
|
||||
virtual ~AtomSpeechRecognitionManagerDelegate();
|
||||
|
||||
// content::SpeechRecognitionEventListener:
|
||||
virtual void OnRecognitionStart(int session_id) override;
|
||||
virtual void OnAudioStart(int session_id) override;
|
||||
virtual void OnEnvironmentEstimationComplete(int session_id) override;
|
||||
virtual void OnSoundStart(int session_id) override;
|
||||
virtual void OnSoundEnd(int session_id) override;
|
||||
virtual void OnAudioEnd(int session_id) override;
|
||||
virtual void OnRecognitionEnd(int session_id) override;
|
||||
virtual void OnRecognitionResults(
|
||||
int session_id, const content::SpeechRecognitionResults& result) override;
|
||||
virtual void OnRecognitionError(
|
||||
int session_id, const content::SpeechRecognitionError& error) override;
|
||||
virtual void OnAudioLevelsChange(int session_id, float volume,
|
||||
float noise_volume) override;
|
||||
|
||||
// content::SpeechRecognitionManagerDelegate:
|
||||
virtual void GetDiagnosticInformation(bool* can_report_metrics,
|
||||
std::string* hardware_info) override;
|
||||
virtual void CheckRecognitionIsAllowed(
|
||||
int session_id,
|
||||
base::Callback<void(bool ask_user, bool is_allowed)> callback) override;
|
||||
virtual content::SpeechRecognitionEventListener* GetEventListener() override;
|
||||
virtual bool FilterProfanities(int render_process_id) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomSpeechRecognitionManagerDelegate);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_ATOM_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -48,11 +48,13 @@ void AutoUpdater::SetFeedURL(const std::string& feed) {
|
||||
[[g_updater rac_valuesForKeyPath:@"state" observer:g_updater]
|
||||
subscribeNext:^(NSNumber *stateNumber) {
|
||||
int state = [stateNumber integerValue];
|
||||
if (state == SQRLUpdaterStateCheckingForUpdate) {
|
||||
delegate->OnCheckingForUpdate();
|
||||
} else if (state == SQRLUpdaterStateDownloadingUpdate) {
|
||||
delegate->OnUpdateAvailable();
|
||||
}
|
||||
// Dispatching the event on main thread.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (state == SQRLUpdaterStateCheckingForUpdate)
|
||||
delegate->OnCheckingForUpdate();
|
||||
else if (state == SQRLUpdaterStateDownloadingUpdate)
|
||||
delegate->OnUpdateAvailable();
|
||||
});
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -89,4 +91,5 @@ void AutoUpdater::CheckForUpdates() {
|
||||
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription));
|
||||
}];
|
||||
}
|
||||
|
||||
} // namespace auto_updater
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
namespace atom {
|
||||
|
||||
Browser::Browser()
|
||||
: is_quiting_(false) {
|
||||
: is_quiting_(false),
|
||||
is_ready_(false) {
|
||||
WindowList::AddObserver(this);
|
||||
}
|
||||
|
||||
@@ -37,6 +38,8 @@ void Browser::Quit() {
|
||||
}
|
||||
|
||||
void Browser::Shutdown() {
|
||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit());
|
||||
|
||||
is_quiting_ = true;
|
||||
base::MessageLoop::current()->Quit();
|
||||
}
|
||||
@@ -91,6 +94,7 @@ void Browser::WillFinishLaunching() {
|
||||
}
|
||||
|
||||
void Browser::DidFinishLaunching() {
|
||||
is_ready_ = true;
|
||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -84,6 +84,7 @@ class Browser : public WindowListObserver {
|
||||
}
|
||||
|
||||
bool is_quiting() const { return is_quiting_; }
|
||||
bool is_ready() const { return is_ready_; }
|
||||
|
||||
protected:
|
||||
// Returns the version of application bundle or executable file.
|
||||
@@ -105,6 +106,9 @@ class Browser : public WindowListObserver {
|
||||
// Observers of the browser.
|
||||
ObserverList<BrowserObserver> observers_;
|
||||
|
||||
// Whether "ready" event has been emitted.
|
||||
bool is_ready_;
|
||||
|
||||
std::string version_override_;
|
||||
std::string name_override_;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -29,7 +29,7 @@ std::string Browser::GetExecutableFileProductName() const {
|
||||
}
|
||||
|
||||
int Browser::DockBounce(BounceType type) {
|
||||
return [[AtomApplication sharedApplication] requestUserAttention:type];
|
||||
return [[AtomApplication sharedApplication] requestUserAttention:(NSRequestUserAttentionType)type];
|
||||
}
|
||||
|
||||
void Browser::DockCancelBounce(int rid) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -18,6 +18,9 @@ class BrowserObserver {
|
||||
// method will not be called, instead it will call OnWillQuit.
|
||||
virtual void OnWindowAllClosed() {}
|
||||
|
||||
// The browser is quitting.
|
||||
virtual void OnQuit() {}
|
||||
|
||||
// The browser has opened a file by double clicking in Finder or dragging the
|
||||
// file to the Dock icon. (OS X only)
|
||||
virtual void OnOpenFile(bool* prevent_default,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -12,15 +12,15 @@ app.on('window-all-closed', function() {
|
||||
});
|
||||
|
||||
app.on('ready', function() {
|
||||
app.commandLine.appendSwitch('js-flags', '--harmony_collections');
|
||||
|
||||
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 = [
|
||||
@@ -34,6 +34,13 @@ app.on('ready', function() {
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Services',
|
||||
submenu: []
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Hide Atom Shell',
|
||||
accelerator: 'Command+H',
|
||||
@@ -144,33 +151,33 @@ app.on('ready', function() {
|
||||
} else {
|
||||
var template = [
|
||||
{
|
||||
label: 'File',
|
||||
label: '&File',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Open',
|
||||
label: '&Open',
|
||||
accelerator: 'Ctrl+O',
|
||||
},
|
||||
{
|
||||
label: 'Close',
|
||||
label: '&Close',
|
||||
accelerator: 'Ctrl+W',
|
||||
click: function() { mainWindow.close(); }
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
label: '&View',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Reload',
|
||||
label: '&Reload',
|
||||
accelerator: 'Ctrl+R',
|
||||
click: function() { mainWindow.restart(); }
|
||||
},
|
||||
{
|
||||
label: 'Enter Fullscreen',
|
||||
label: '&Enter Fullscreen',
|
||||
click: function() { mainWindow.setFullScreen(true); }
|
||||
},
|
||||
{
|
||||
label: 'Toggle DevTools',
|
||||
label: '&Toggle DevTools',
|
||||
accelerator: 'Alt+Ctrl+I',
|
||||
click: function() { mainWindow.toggleDevTools(); }
|
||||
},
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
<head>
|
||||
<title>Atom Shell</title>
|
||||
<style>
|
||||
html {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
color: #555;
|
||||
font-family: 'Open Sans',Helvetica,Arial,sans-serif;
|
||||
|
||||
@@ -2,7 +2,6 @@ var app = require('app');
|
||||
var dialog = require('dialog');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var optimist = require('optimist');
|
||||
|
||||
// Quit when all windows are closed and no other one is listening to this.
|
||||
app.on('window-all-closed', function() {
|
||||
@@ -10,14 +9,29 @@ app.on('window-all-closed', function() {
|
||||
app.quit();
|
||||
});
|
||||
|
||||
var argv = optimist(process.argv.slice(1)).boolean('ci').argv;
|
||||
// Parse command line options.
|
||||
var argv = process.argv.slice(1);
|
||||
var option = { file: 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] == '--test-type=webdriver') {
|
||||
option.webdriver = true;
|
||||
} else if (argv[i][0] == '-') {
|
||||
continue;
|
||||
} else {
|
||||
option.file = argv[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Start the specified app if there is one specified in command line, otherwise
|
||||
// start the default app.
|
||||
if (argv._.length > 0) {
|
||||
if (option.file && !option.webdriver) {
|
||||
try {
|
||||
// Override app name and version.
|
||||
var packagePath = path.resolve(argv._[0]);
|
||||
var packagePath = path.resolve(option.file);
|
||||
var packageJsonPath = path.join(packagePath, 'package.json');
|
||||
if (fs.existsSync(packageJsonPath)) {
|
||||
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
|
||||
@@ -34,21 +48,14 @@ if (argv._.length > 0) {
|
||||
} catch(e) {
|
||||
if (e.code == 'MODULE_NOT_FOUND') {
|
||||
app.focus();
|
||||
console.error(e.stack);
|
||||
dialog.showMessageBox({
|
||||
type: 'warning',
|
||||
buttons: ['OK'],
|
||||
title: 'Error opening app',
|
||||
message: 'The app provided is not a valid atom-shell app, please read the docs on how to write one:',
|
||||
detail: 'https://github.com/atom/atom-shell/tree/master/docs'
|
||||
});
|
||||
dialog.showErrorBox('Error opening app', 'The app provided is not a valid atom-shell app, please read the docs on how to write one:\nhttps://github.com/atom/atom-shell/tree/master/docs');
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.error('App throwed an error when running', e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} else if (argv.version) {
|
||||
} else if (option.version) {
|
||||
console.log('v' + process.versions['atom-shell']);
|
||||
process.exit(0);
|
||||
} else {
|
||||
|
||||
@@ -2,8 +2,5 @@
|
||||
"name": "atom-shell-default-app",
|
||||
"productName": "Atom Shell Default App",
|
||||
"version": "0.1.0",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"optimist": "*"
|
||||
}
|
||||
"main": "main.js"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
namespace atom {
|
||||
|
||||
JavascriptEnvironment::JavascriptEnvironment()
|
||||
: isolate_(v8::Isolate::GetCurrent()),
|
||||
: isolate_holder_(gin::IsolateHolder::kNonStrictMode),
|
||||
isolate_(isolate_holder_.isolate()),
|
||||
isolate_scope_(isolate_),
|
||||
locker_(isolate_),
|
||||
handle_scope_(isolate_),
|
||||
context_(isolate_, v8::Context::New(isolate_)),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "v8/include/v8.h"
|
||||
#include "gin/public/isolate_holder.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -20,7 +20,9 @@ class JavascriptEnvironment {
|
||||
}
|
||||
|
||||
private:
|
||||
gin::IsolateHolder isolate_holder_;
|
||||
v8::Isolate* isolate_;
|
||||
v8::Isolate::Scope isolate_scope_;
|
||||
v8::Locker locker_;
|
||||
v8::HandleScope handle_scope_;
|
||||
v8::UniquePersistent<v8::Context> context_;
|
||||
|
||||
88
atom/browser/lib/chrome-extension.coffee
Normal file
88
atom/browser/lib/chrome-extension.coffee
Normal file
@@ -0,0 +1,88 @@
|
||||
app = require 'app'
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
url = require 'url'
|
||||
|
||||
# Mapping between hostname and file path.
|
||||
hostPathMap = {}
|
||||
hostPathMapNextKey = 0
|
||||
|
||||
getHostForPath = (path) ->
|
||||
key = "extension-#{++hostPathMapNextKey}"
|
||||
hostPathMap[key] = path
|
||||
key
|
||||
|
||||
getPathForHost = (host) ->
|
||||
hostPathMap[host]
|
||||
|
||||
# Cache extensionInfo.
|
||||
extensionInfoMap = {}
|
||||
|
||||
getExtensionInfoFromPath = (srcDirectory) ->
|
||||
manifest = JSON.parse fs.readFileSync(path.join(srcDirectory, 'manifest.json'))
|
||||
unless extensionInfoMap[manifest.name]?
|
||||
# We can not use 'file://' directly because all resources in the extension
|
||||
# will be treated as relative to the root in Chrome.
|
||||
page = url.format
|
||||
protocol: 'chrome-extension'
|
||||
slashes: true
|
||||
hostname: getHostForPath srcDirectory
|
||||
pathname: manifest.devtools_page
|
||||
extensionInfoMap[manifest.name] =
|
||||
startPage: page
|
||||
name: manifest.name
|
||||
srcDirectory: srcDirectory
|
||||
extensionInfoMap[manifest.name]
|
||||
|
||||
# Load persistented extensions.
|
||||
loadedExtensionsPath = path.join app.getDataPath(), 'DevTools Extensions'
|
||||
|
||||
try
|
||||
loadedExtensions = JSON.parse fs.readFileSync(loadedExtensionsPath)
|
||||
loadedExtensions = [] unless Array.isArray loadedExtensions
|
||||
# Preheat the extensionInfo cache.
|
||||
getExtensionInfoFromPath srcDirectory for srcDirectory in loadedExtensions
|
||||
catch e
|
||||
|
||||
# Persistent loaded extensions.
|
||||
app.on 'will-quit', ->
|
||||
try
|
||||
loadedExtensions = Object.keys(extensionInfoMap).map (key) -> extensionInfoMap[key].srcDirectory
|
||||
try
|
||||
fs.mkdirSync path.dirname(loadedExtensionsPath)
|
||||
catch e
|
||||
fs.writeFileSync loadedExtensionsPath, JSON.stringify(loadedExtensions)
|
||||
catch e
|
||||
|
||||
# We can not use protocol or BrowserWindow until app is ready.
|
||||
app.once 'ready', ->
|
||||
protocol = require 'protocol'
|
||||
BrowserWindow = require 'browser-window'
|
||||
|
||||
# The chrome-extension: can map a extension URL request to real file path.
|
||||
protocol.registerProtocol 'chrome-extension', (request) ->
|
||||
parsed = url.parse request.url
|
||||
return unless parsed.hostname and parsed.path?
|
||||
return unless /extension-\d+/.test parsed.hostname
|
||||
|
||||
directory = getPathForHost parsed.hostname
|
||||
return unless directory?
|
||||
return new protocol.RequestFileJob(path.join(directory, parsed.path))
|
||||
|
||||
BrowserWindow::_loadDevToolsExtensions = (extensionInfoArray) ->
|
||||
@devToolsWebContents?.executeJavaScript "WebInspector.addExtensions(#{JSON.stringify(extensionInfoArray)});"
|
||||
|
||||
BrowserWindow.addDevToolsExtension = (srcDirectory) ->
|
||||
extensionInfo = getExtensionInfoFromPath srcDirectory
|
||||
window._loadDevToolsExtensions [extensionInfo] for window in BrowserWindow.getAllWindows()
|
||||
extensionInfo.name
|
||||
|
||||
BrowserWindow.removeDevToolsExtension = (name) ->
|
||||
delete extensionInfoMap[name]
|
||||
|
||||
# Load persistented extensions when devtools is opened.
|
||||
init = BrowserWindow::_init
|
||||
BrowserWindow::_init = ->
|
||||
init.call this
|
||||
@on 'devtools-opened', ->
|
||||
@_loadDevToolsExtensions Object.keys(extensionInfoMap).map (key) -> extensionInfoMap[key]
|
||||
93
atom/browser/lib/guest-view-manager.coffee
Normal file
93
atom/browser/lib/guest-view-manager.coffee
Normal file
@@ -0,0 +1,93 @@
|
||||
ipc = require 'ipc'
|
||||
webContents = require 'web-contents'
|
||||
webViewManager = null # Doesn't exist in early initialization.
|
||||
|
||||
supportedWebViewEvents = [
|
||||
'did-finish-load'
|
||||
'did-fail-load'
|
||||
'did-frame-finish-load'
|
||||
'did-start-loading'
|
||||
'did-stop-loading'
|
||||
'did-get-redirect-request'
|
||||
'console-message'
|
||||
'new-window'
|
||||
'close'
|
||||
'crashed'
|
||||
'destroyed'
|
||||
]
|
||||
|
||||
nextInstanceId = 0
|
||||
guestInstances = {}
|
||||
|
||||
# Generate guestInstanceId.
|
||||
getNextInstanceId = (webContents) ->
|
||||
++nextInstanceId
|
||||
|
||||
# Create a new guest instance.
|
||||
createGuest = (embedder, params) ->
|
||||
webViewManager ?= process.atomBinding 'web_view_manager'
|
||||
|
||||
id = getNextInstanceId embedder
|
||||
guest = webContents.create
|
||||
isGuest: true
|
||||
guestInstanceId: id
|
||||
storagePartitionId: params.storagePartitionId
|
||||
guestInstances[id] = {guest, embedder}
|
||||
preload = params.preload ? ''
|
||||
webViewManager.addGuest id, embedder, guest, params.nodeIntegration, params.plugins, preload
|
||||
|
||||
# Destroy guest when the embedder is gone.
|
||||
embedder.once 'render-view-deleted', ->
|
||||
destroyGuest id if guestInstances[id]?
|
||||
|
||||
# Init guest web view after attached.
|
||||
guest.once 'did-attach', (event, params) ->
|
||||
@viewInstanceId = params.instanceId
|
||||
min = width: params.minwidth, height: params.minheight
|
||||
max = width: params.maxwidth, height: params.maxheight
|
||||
@setAutoSize params.autosize, min, max
|
||||
if params.src
|
||||
if params.httpreferrer
|
||||
@loadUrl params.src, {httpreferrer: params.httpreferrer}
|
||||
else
|
||||
@loadUrl params.src
|
||||
if params.allowtransparency?
|
||||
@setAllowTransparency params.allowtransparency
|
||||
|
||||
# Dispatch events to embedder.
|
||||
for event in supportedWebViewEvents
|
||||
do (event) ->
|
||||
guest.on event, (_, args...) ->
|
||||
embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{guest.viewInstanceId}", event, args...
|
||||
|
||||
# Autosize.
|
||||
guest.on 'size-changed', (_, args...) ->
|
||||
embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED", args...
|
||||
|
||||
id
|
||||
|
||||
# Destroy an existing guest instance.
|
||||
destroyGuest = (id) ->
|
||||
webViewManager.removeGuest id
|
||||
guestInstances[id].guest.destroy()
|
||||
delete guestInstances[id]
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, type, params, requestId) ->
|
||||
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, id) ->
|
||||
destroyGuest 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_ALLOW_TRANSPARENCY', (event, id, allowtransparency) ->
|
||||
guestInstances[id]?.guest.setAllowTransparency allowtransparency
|
||||
|
||||
# Returns WebContents from its guest id.
|
||||
exports.getGuest = (id) ->
|
||||
guestInstances[id]?.guest
|
||||
|
||||
# Returns the embedder of the guest.
|
||||
exports.getEmbedder = (id) ->
|
||||
guestInstances[id]?.embedder
|
||||
54
atom/browser/lib/guest-window-manager.coffee
Normal file
54
atom/browser/lib/guest-window-manager.coffee
Normal file
@@ -0,0 +1,54 @@
|
||||
ipc = require 'ipc'
|
||||
BrowserWindow = require 'browser-window'
|
||||
|
||||
frameToGuest = {}
|
||||
|
||||
# Create a new guest created by |embedder| with |options|.
|
||||
createGuest = (embedder, url, frameName, options) ->
|
||||
guest = frameToGuest[frameName]
|
||||
if frameName and guest?
|
||||
guest.loadUrl url
|
||||
return guest.id
|
||||
|
||||
guest = new BrowserWindow(options)
|
||||
guest.loadUrl url
|
||||
|
||||
# When |embedder| is destroyed we should also destroy attached guest, and if
|
||||
# guest is closed by user then we should prevent |embedder| from double
|
||||
# closing guest.
|
||||
closedByEmbedder = ->
|
||||
guest.removeListener 'closed', closedByUser
|
||||
guest.destroy() unless guest.isClosed()
|
||||
closedByUser = ->
|
||||
embedder.removeListener 'render-view-deleted', closedByEmbedder
|
||||
embedder.once 'render-view-deleted', closedByEmbedder
|
||||
guest.once 'closed', closedByUser
|
||||
|
||||
if frameName
|
||||
frameToGuest[frameName] = guest
|
||||
guest.frameName = frameName
|
||||
guest.once 'closed', ->
|
||||
delete frameToGuest[frameName]
|
||||
|
||||
guest.id
|
||||
|
||||
# Routed window.open messages.
|
||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
|
||||
[url, frameName, options] = args
|
||||
event.sender.emit '-new-window', event, url, frameName, 7
|
||||
if event.sender.isGuest() or event.defaultPrevented
|
||||
event.returnValue = null
|
||||
else
|
||||
event.returnValue = createGuest event.sender, args...
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', (event, guestId) ->
|
||||
return unless BrowserWindow.windows.has guestId
|
||||
BrowserWindow.windows.get(guestId).destroy()
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', (event, guestId, method, args...) ->
|
||||
return unless BrowserWindow.windows.has guestId
|
||||
BrowserWindow.windows.get(guestId)[method] args...
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) ->
|
||||
return unless BrowserWindow.windows.has guestId
|
||||
BrowserWindow.windows.get(guestId).webContents?[method] args...
|
||||
@@ -14,6 +14,8 @@ process.argv.splice 1, 1
|
||||
# Pick out switches appended by atom-shell.
|
||||
startMark = process.argv.indexOf '--atom-shell-switches-start'
|
||||
endMark = process.argv.indexOf '--atom-shell-switches-end'
|
||||
# And --force-device-scale-factor on Linux.
|
||||
endMark++ if process.platform is 'linux'
|
||||
process.argv.splice startMark, endMark - startMark + 1
|
||||
|
||||
# Add browser/api/lib to require's search paths,
|
||||
@@ -21,9 +23,8 @@ process.argv.splice startMark, endMark - startMark + 1
|
||||
globalPaths = module.globalPaths
|
||||
globalPaths.push path.join process.resourcesPath, 'atom', 'browser', 'api', 'lib'
|
||||
|
||||
# Do loading in next tick since we still need some initialize work before
|
||||
# native bindings can work.
|
||||
setImmediate ->
|
||||
# Following operations need extra bindings by AtomBindings.
|
||||
process.once 'BIND_DONE', ->
|
||||
# Import common settings.
|
||||
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init.js')
|
||||
|
||||
@@ -44,28 +45,34 @@ setImmediate ->
|
||||
# Don't quit on fatal error.
|
||||
process.on 'uncaughtException', (error) ->
|
||||
# Show error in GUI.
|
||||
message = error.stack ? "#{error.name}: #{error.message}"
|
||||
require('dialog').showMessageBox
|
||||
type: 'warning'
|
||||
title: 'An javascript error occured in the browser'
|
||||
message: 'uncaughtException'
|
||||
detail: message
|
||||
buttons: ['OK']
|
||||
stack = error.stack ? "#{error.name}: #{error.message}"
|
||||
message = "Uncaught Exception:\n#{stack}"
|
||||
require('dialog').showErrorBox 'A JavaScript error occured in the browser process', message
|
||||
|
||||
# Emit 'exit' event on quit.
|
||||
require('app').on 'quit', ->
|
||||
process.emit 'exit'
|
||||
|
||||
# Load the RPC server.
|
||||
require './rpc-server.js'
|
||||
require './rpc-server'
|
||||
|
||||
# Load the guest view manager.
|
||||
require './guest-view-manager'
|
||||
require './guest-window-manager'
|
||||
|
||||
# Now we try to load app's package.json.
|
||||
packageJson = null
|
||||
|
||||
packagePath = path.join process.resourcesPath, 'app'
|
||||
try
|
||||
# First we try to load process.resourcesPath/app
|
||||
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
|
||||
catch error
|
||||
# If not found then we load browser/default_app
|
||||
packagePath = path.join process.resourcesPath, 'default_app'
|
||||
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
|
||||
searchPaths = [ 'app', 'app.asar', 'default_app' ]
|
||||
for packagePath in searchPaths
|
||||
try
|
||||
packagePath = path.join process.resourcesPath, packagePath
|
||||
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
|
||||
break
|
||||
catch e
|
||||
continue
|
||||
|
||||
throw new Error("Unable to find a valid app") unless packageJson?
|
||||
|
||||
# Set application's version.
|
||||
app = require 'app'
|
||||
@@ -77,5 +84,14 @@ setImmediate ->
|
||||
else if packageJson.name?
|
||||
app.setName packageJson.name
|
||||
|
||||
# Set application's desktop name.
|
||||
if packageJson.desktopName?
|
||||
app.setDesktopName packageJson.desktopName
|
||||
else
|
||||
app.setDesktopName '#{app.getName()}.desktop'
|
||||
|
||||
# Load the chrome extension support.
|
||||
require './chrome-extension.js'
|
||||
|
||||
# Finally load app's main.js and transfer control to C++.
|
||||
module._load path.join(packagePath, packageJson.main), module, true
|
||||
|
||||
@@ -94,11 +94,15 @@ ipc.on 'ATOM_BROWSER_GLOBAL', (event, name) ->
|
||||
catch e
|
||||
event.returnValue = errorToMeta e
|
||||
|
||||
ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event) ->
|
||||
ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, guestInstanceId) ->
|
||||
try
|
||||
BrowserWindow = require 'browser-window'
|
||||
window = BrowserWindow.fromWebContents event.sender
|
||||
window = BrowserWindow.fromDevToolsWebContents event.sender unless window?
|
||||
if guestInstanceId?
|
||||
guestViewManager = require './guest-view-manager'
|
||||
window = BrowserWindow.fromWebContents guestViewManager.getEmbedder(guestInstanceId)
|
||||
else
|
||||
window = BrowserWindow.fromWebContents event.sender
|
||||
window = BrowserWindow.fromDevToolsWebContents event.sender unless window?
|
||||
event.returnValue = valueToMeta event.sender, window
|
||||
catch e
|
||||
event.returnValue = errorToMeta e
|
||||
@@ -157,3 +161,10 @@ ipc.on 'ATOM_BROWSER_MEMBER_GET', (event, id, name) ->
|
||||
|
||||
ipc.on 'ATOM_BROWSER_DEREFERENCE', (event, storeId) ->
|
||||
objectsRegistry.remove event.sender.getId(), storeId
|
||||
|
||||
ipc.on 'ATOM_BROWSER_GUEST_WEB_CONTENTS', (event, guestInstanceId) ->
|
||||
try
|
||||
guestViewManager = require './guest-view-manager'
|
||||
event.returnValue = valueToMeta event.sender, guestViewManager.getGuest(guestInstanceId)
|
||||
catch e
|
||||
event.returnValue = errorToMeta e
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#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"
|
||||
@@ -27,6 +28,10 @@
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#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/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/invalidate_type.h"
|
||||
#include "content/public/browser/navigation_entry.h"
|
||||
@@ -38,44 +43,76 @@
|
||||
#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/common/content_switches.h"
|
||||
#include "content/public/common/renderer_preferences.h"
|
||||
#include "content/public/common/user_agent.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/gfx/codec/png_codec.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
#include "ui/gfx/point.h"
|
||||
#include "ui/gfx/rect.h"
|
||||
#include "ui/gfx/size.h"
|
||||
#include "vendor/brightray/browser/inspectable_web_contents.h"
|
||||
#include "vendor/brightray/browser/inspectable_web_contents_view.h"
|
||||
#include "webkit/common/webpreferences.h"
|
||||
|
||||
using content::NavigationEntry;
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
// Array of available web runtime features.
|
||||
const char* kWebRuntimeFeatures[] = {
|
||||
switches::kExperimentalFeatures,
|
||||
switches::kExperimentalCanvasFeatures,
|
||||
switches::kSubpixelFontScaling,
|
||||
switches::kOverlayScrollbars,
|
||||
switches::kOverlayFullscreenVideo,
|
||||
switches::kSharedWorker,
|
||||
};
|
||||
|
||||
std::string RemoveWhitespace(const std::string& str) {
|
||||
std::string trimmed;
|
||||
if (base::RemoveChars(str, " ", &trimmed))
|
||||
return trimmed;
|
||||
else
|
||||
return str;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||
const mate::Dictionary& options)
|
||||
: content::WebContentsObserver(web_contents),
|
||||
has_frame_(true),
|
||||
enable_larger_than_screen_(false),
|
||||
is_closed_(false),
|
||||
node_integration_("except-iframe"),
|
||||
node_integration_(true),
|
||||
has_dialog_attached_(false),
|
||||
zoom_factor_(1.0),
|
||||
weak_factory_(this),
|
||||
inspectable_web_contents_(
|
||||
brightray::InspectableWebContents::Create(web_contents)) {
|
||||
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
||||
|
||||
options.Get(switches::kFrame, &has_frame_);
|
||||
options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
|
||||
options.Get(switches::kNodeIntegration, &node_integration_);
|
||||
|
||||
// Read icon before window is created.
|
||||
gfx::ImageSkia icon;
|
||||
if (options.Get(switches::kIcon, &icon))
|
||||
icon_.reset(new gfx::Image(icon));
|
||||
options.Get(switches::kIcon, &icon_);
|
||||
|
||||
// Read iframe security before any navigation.
|
||||
options.Get(switches::kNodeIntegration, &node_integration_);
|
||||
// The "preload" option must be absolute path.
|
||||
if (options.Get(switches::kPreloadScript, &preload_script_) &&
|
||||
!preload_script_.IsAbsolute()) {
|
||||
LOG(ERROR) << "Path of \"preload\" script must be absolute.";
|
||||
preload_script_.clear();
|
||||
}
|
||||
|
||||
// Be compatible with old API of "node-integration" option.
|
||||
std::string old_string_token;
|
||||
if (options.Get(switches::kNodeIntegration, &old_string_token) &&
|
||||
old_string_token != "disable")
|
||||
node_integration_ = true;
|
||||
|
||||
// Read the web preferences.
|
||||
options.Get(switches::kWebPreferences, &web_preferences_);
|
||||
@@ -91,8 +128,8 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||
// Override the user agent to contain application and atom-shell's version.
|
||||
Browser* browser = Browser::Get();
|
||||
std::string product_name = base::StringPrintf(
|
||||
"%s/%s Chrome/%s Atom-Shell/" ATOM_VERSION_STRING,
|
||||
browser->GetName().c_str(),
|
||||
"%s/%s Chrome/%s AtomShell/" ATOM_VERSION_STRING,
|
||||
RemoveWhitespace(browser->GetName()).c_str(),
|
||||
browser->GetVersion().c_str(),
|
||||
CHROME_VERSION_STRING);
|
||||
web_contents->GetMutableRendererPrefs()->user_agent_override =
|
||||
@@ -143,8 +180,8 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||
} else if (options.Get(switches::kCenter, ¢er) && center) {
|
||||
Center();
|
||||
}
|
||||
int min_height = -1, min_width = -1;
|
||||
if (options.Get(switches::kMinHeight, &min_height) &&
|
||||
int min_height = 0, min_width = 0;
|
||||
if (options.Get(switches::kMinHeight, &min_height) |
|
||||
options.Get(switches::kMinWidth, &min_width)) {
|
||||
SetMinimumSize(gfx::Size(min_width, min_height));
|
||||
}
|
||||
@@ -194,13 +231,32 @@ std::string NativeWindow::GetRepresentedFilename() {
|
||||
void NativeWindow::SetDocumentEdited(bool edited) {
|
||||
}
|
||||
|
||||
bool NativeWindow::IsDocumentEdited() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void NativeWindow::SetMenu(ui::MenuModel* menu) {
|
||||
}
|
||||
|
||||
bool NativeWindow::IsDocumentEdited() {
|
||||
void NativeWindow::Print(bool silent, bool print_background) {
|
||||
printing::PrintViewManagerBasic::FromWebContents(GetWebContents())->
|
||||
PrintNow(silent, print_background);
|
||||
}
|
||||
|
||||
void NativeWindow::SetAutoHideMenuBar(bool auto_hide) {
|
||||
}
|
||||
|
||||
bool NativeWindow::IsMenuBarAutoHide() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void NativeWindow::SetMenuBarVisibility(bool visible) {
|
||||
}
|
||||
|
||||
bool NativeWindow::IsMenuBarVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NativeWindow::HasModalDialog() {
|
||||
return has_dialog_attached_;
|
||||
}
|
||||
@@ -219,9 +275,8 @@ bool NativeWindow::IsDevToolsOpened() {
|
||||
|
||||
void NativeWindow::InspectElement(int x, int y) {
|
||||
OpenDevTools();
|
||||
content::RenderViewHost* rvh = GetWebContents()->GetRenderViewHost();
|
||||
scoped_refptr<content::DevToolsAgentHost> agent(
|
||||
content::DevToolsAgentHost::GetOrCreateFor(rvh));
|
||||
content::DevToolsAgentHost::GetOrCreateFor(GetWebContents()));
|
||||
agent->InspectElement(x, y);
|
||||
}
|
||||
|
||||
@@ -251,22 +306,14 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
|
||||
return;
|
||||
}
|
||||
|
||||
gfx::Rect flipped_y_rect = rect;
|
||||
flipped_y_rect.set_y(-rect.y());
|
||||
|
||||
gfx::Size size;
|
||||
if (flipped_y_rect.IsEmpty())
|
||||
size = render_widget_host_view->GetViewBounds().size();
|
||||
else
|
||||
size = flipped_y_rect.size();
|
||||
|
||||
GetWebContents()->GetRenderViewHost()->CopyFromBackingStore(
|
||||
flipped_y_rect,
|
||||
size,
|
||||
rect,
|
||||
rect.IsEmpty() ? render_widget_host_view->GetViewBounds().size() :
|
||||
rect.size(),
|
||||
base::Bind(&NativeWindow::OnCapturePageDone,
|
||||
weak_factory_.GetWeakPtr(),
|
||||
callback),
|
||||
SkBitmap::kARGB_8888_Config);
|
||||
kAlpha_8_SkColorType);
|
||||
}
|
||||
|
||||
void NativeWindow::DestroyWebContents() {
|
||||
@@ -321,39 +368,62 @@ void NativeWindow::AppendExtraCommandLineSwitches(
|
||||
base::CommandLine* command_line, int child_process_id) {
|
||||
// Append --node-integration to renderer process.
|
||||
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
||||
node_integration_);
|
||||
node_integration_ ? "true" : "false");
|
||||
|
||||
// Append --preload.
|
||||
if (!preload_script_.empty())
|
||||
command_line->AppendSwitchPath(switches::kPreloadScript, preload_script_);
|
||||
|
||||
// Append --zoom-factor.
|
||||
if (zoom_factor_ != 1.0)
|
||||
command_line->AppendSwitchASCII(switches::kZoomFactor,
|
||||
base::DoubleToString(zoom_factor_));
|
||||
|
||||
if (web_preferences_.IsEmpty())
|
||||
return;
|
||||
|
||||
bool b;
|
||||
#if defined(OS_WIN)
|
||||
// Check if DirectWrite is disabled.
|
||||
if (web_preferences_.Get(switches::kDirectWrite, &b) && !b)
|
||||
command_line->AppendSwitch(::switches::kDisableDirectWrite);
|
||||
#endif
|
||||
|
||||
// Check if plugins are enabled.
|
||||
if (web_preferences_.Get("plugins", &b) && b)
|
||||
command_line->AppendSwitch(switches::kEnablePlugins);
|
||||
|
||||
// This set of options are not availabe in WebPreferences, so we have to pass
|
||||
// them via command line and enable them in renderer procss.
|
||||
for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) {
|
||||
const char* feature = kWebRuntimeFeatures[i];
|
||||
if (web_preferences_.Get(feature, &b))
|
||||
command_line->AppendSwitchASCII(feature, b ? "true" : "false");
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) {
|
||||
void NativeWindow::OverrideWebkitPrefs(const GURL& url,
|
||||
content::WebPreferences* prefs) {
|
||||
if (web_preferences_.IsEmpty())
|
||||
return;
|
||||
|
||||
bool b;
|
||||
std::vector<base::FilePath> list;
|
||||
mate::Dictionary web_preferences(web_preferences_.isolate(),
|
||||
web_preferences_.NewHandle());
|
||||
if (web_preferences.Get("javascript", &b))
|
||||
if (web_preferences_.Get("javascript", &b))
|
||||
prefs->javascript_enabled = b;
|
||||
if (web_preferences.Get("web-security", &b))
|
||||
if (web_preferences_.Get("web-security", &b))
|
||||
prefs->web_security_enabled = b;
|
||||
if (web_preferences.Get("images", &b))
|
||||
if (web_preferences_.Get("images", &b))
|
||||
prefs->images_enabled = b;
|
||||
if (web_preferences.Get("java", &b))
|
||||
if (web_preferences_.Get("java", &b))
|
||||
prefs->java_enabled = b;
|
||||
if (web_preferences.Get("text-areas-are-resizable", &b))
|
||||
if (web_preferences_.Get("text-areas-are-resizable", &b))
|
||||
prefs->text_areas_are_resizable = b;
|
||||
if (web_preferences.Get("webgl", &b))
|
||||
if (web_preferences_.Get("webgl", &b))
|
||||
prefs->experimental_webgl_enabled = b;
|
||||
if (web_preferences.Get("webaudio", &b))
|
||||
if (web_preferences_.Get("webaudio", &b))
|
||||
prefs->webaudio_enabled = b;
|
||||
if (web_preferences.Get("plugins", &b))
|
||||
prefs->plugins_enabled = b;
|
||||
if (web_preferences.Get("extra-plugin-dirs", &list))
|
||||
if (web_preferences_.Get("extra-plugin-dirs", &list))
|
||||
for (size_t i = 0; i < list.size(); ++i)
|
||||
content::PluginService::GetInstance()->AddExtraPluginDir(list[i]);
|
||||
}
|
||||
@@ -380,6 +450,23 @@ void NativeWindow::NotifyWindowFocus() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowFocus());
|
||||
}
|
||||
|
||||
bool NativeWindow::ShouldCreateWebContents(
|
||||
content::WebContents* web_contents,
|
||||
int route_id,
|
||||
WindowContainerType window_container_type,
|
||||
const base::string16& frame_name,
|
||||
const GURL& target_url,
|
||||
const std::string& partition_id,
|
||||
content::SessionStorageNamespace* session_storage_namespace) {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||
observers_,
|
||||
WillCreatePopupWindow(frame_name,
|
||||
target_url,
|
||||
partition_id,
|
||||
NEW_FOREGROUND_TAB));
|
||||
return false;
|
||||
}
|
||||
|
||||
// In atom-shell all reloads and navigations started by renderer process would
|
||||
// be redirected to this method, so we can have precise control of how we
|
||||
// would open the url (in our case, is to restart the renderer process). See
|
||||
@@ -387,8 +474,15 @@ void NativeWindow::NotifyWindowFocus() {
|
||||
content::WebContents* NativeWindow::OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) {
|
||||
if (params.disposition != CURRENT_TAB)
|
||||
return NULL;
|
||||
if (params.disposition != CURRENT_TAB) {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||
observers_,
|
||||
WillCreatePopupWindow(base::string16(),
|
||||
params.url,
|
||||
"",
|
||||
params.disposition));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
content::NavigationController::LoadURLParams load_url_params(params.url);
|
||||
load_url_params.referrer = params.referrer;
|
||||
@@ -424,6 +518,28 @@ 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) {
|
||||
@@ -528,8 +644,9 @@ void NativeWindow::DevToolsSaveToFile(const std::string& 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, &path)) {
|
||||
if (!file_dialog::ShowSaveDialog(this, url, default_path, filters, &path)) {
|
||||
base::StringValue url_value(url);
|
||||
CallDevToolsFunction("InspectorFrontendAPI.canceledSaveURL", &url_value);
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -9,22 +9,19 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "base/cancelable_callback.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/browser/ui/accelerator_util.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 "native_mate/scoped_persistent.h"
|
||||
#include "vendor/brightray/browser/default_web_contents_delegate.h"
|
||||
#include "vendor/brightray/browser/inspectable_web_contents_delegate.h"
|
||||
#include "vendor/brightray/browser/inspectable_web_contents_impl.h"
|
||||
|
||||
struct WebPreferences;
|
||||
#include "native_mate/persistent_dictionary.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
|
||||
namespace base {
|
||||
class CommandLine;
|
||||
@@ -33,10 +30,10 @@ class CommandLine;
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
class WebContents;
|
||||
struct WebPreferences;
|
||||
}
|
||||
|
||||
namespace gfx {
|
||||
class Image;
|
||||
class Point;
|
||||
class Rect;
|
||||
class Size;
|
||||
@@ -54,6 +51,7 @@ namespace atom {
|
||||
|
||||
class AtomJavaScriptDialogManager;
|
||||
struct DraggableRegion;
|
||||
class WebDialogHelper;
|
||||
|
||||
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
public brightray::InspectableWebContentsDelegate,
|
||||
@@ -104,6 +102,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
virtual void Focus(bool focus) = 0;
|
||||
virtual bool IsFocused() = 0;
|
||||
virtual void Show() = 0;
|
||||
virtual void ShowInactive() = 0;
|
||||
virtual void Hide() = 0;
|
||||
virtual bool IsVisible() = 0;
|
||||
virtual void Maximize() = 0;
|
||||
@@ -138,10 +137,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
virtual void SetRepresentedFilename(const std::string& filename);
|
||||
virtual std::string GetRepresentedFilename();
|
||||
virtual void SetDocumentEdited(bool edited);
|
||||
virtual void SetMenu(ui::MenuModel* menu);
|
||||
virtual bool IsDocumentEdited();
|
||||
virtual void SetMenu(ui::MenuModel* menu);
|
||||
virtual bool HasModalDialog();
|
||||
virtual gfx::NativeWindow GetNativeWindow() = 0;
|
||||
virtual void SetProgressBar(double progress) = 0;
|
||||
|
||||
virtual bool IsClosed() const { return is_closed_; }
|
||||
virtual void OpenDevTools();
|
||||
@@ -158,6 +158,15 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
virtual void CapturePage(const gfx::Rect& rect,
|
||||
const CapturePageCallback& callback);
|
||||
|
||||
// Print current page.
|
||||
virtual void Print(bool silent, bool print_background);
|
||||
|
||||
// Toggle the menu bar.
|
||||
virtual void SetAutoHideMenuBar(bool auto_hide);
|
||||
virtual bool IsMenuBarAutoHide();
|
||||
virtual void SetMenuBarVisibility(bool visible);
|
||||
virtual bool IsMenuBarVisible();
|
||||
|
||||
// The same with closing a tab in a real browser.
|
||||
//
|
||||
// Should be called by platform code when user want to close the window.
|
||||
@@ -176,7 +185,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
// Called when renderer process is going to be started.
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id);
|
||||
void OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs);
|
||||
void OverrideWebkitPrefs(const GURL& url, content::WebPreferences* prefs);
|
||||
|
||||
// Public API used by platform-dependent delegates and observers to send UI
|
||||
// related notifications.
|
||||
@@ -212,49 +221,68 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
const std::vector<DraggableRegion>& regions) = 0;
|
||||
|
||||
// Implementations of content::WebContentsDelegate.
|
||||
virtual content::WebContents* OpenURLFromTab(
|
||||
bool ShouldCreateWebContents(
|
||||
content::WebContents* web_contents,
|
||||
int route_id,
|
||||
WindowContainerType window_container_type,
|
||||
const base::string16& frame_name,
|
||||
const GURL& target_url,
|
||||
const std::string& partition_id,
|
||||
content::SessionStorageNamespace* session_storage_namespace) override;
|
||||
content::WebContents* OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) OVERRIDE;
|
||||
virtual content::JavaScriptDialogManager*
|
||||
GetJavaScriptDialogManager() OVERRIDE;
|
||||
virtual void BeforeUnloadFired(content::WebContents* tab,
|
||||
bool proceed,
|
||||
bool* proceed_to_fire_unload) OVERRIDE;
|
||||
virtual void RequestToLockMouse(content::WebContents* web_contents,
|
||||
bool user_gesture,
|
||||
bool last_unlocked_by_target) OVERRIDE;
|
||||
virtual bool CanOverscrollContent() const OVERRIDE;
|
||||
virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
|
||||
virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
|
||||
virtual void MoveContents(content::WebContents* source,
|
||||
const gfx::Rect& pos) OVERRIDE;
|
||||
virtual void CloseContents(content::WebContents* source) OVERRIDE;
|
||||
virtual bool IsPopupOrPanel(
|
||||
const content::WebContents* source) const OVERRIDE;
|
||||
virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE;
|
||||
virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
|
||||
const content::OpenURLParams& params) override;
|
||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager() 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;
|
||||
|
||||
// Implementations of content::WebContentsObserver.
|
||||
virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE;
|
||||
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
||||
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
|
||||
// Implementations of content::NotificationObserver.
|
||||
virtual void Observe(int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) OVERRIDE;
|
||||
void Observe(int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) override;
|
||||
|
||||
// Implementations of brightray::InspectableWebContentsDelegate.
|
||||
virtual void DevToolsSaveToFile(const std::string& url,
|
||||
const std::string& content,
|
||||
bool save_as) OVERRIDE;
|
||||
virtual void DevToolsAppendToFile(const std::string& url,
|
||||
const std::string& content) OVERRIDE;
|
||||
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;
|
||||
|
||||
// Whether window has standard frame.
|
||||
bool has_frame_;
|
||||
|
||||
// Whether window can be resized larger than screen.
|
||||
bool enable_larger_than_screen_;
|
||||
|
||||
// Window icon.
|
||||
scoped_ptr<gfx::Image> icon_;
|
||||
gfx::ImageSkia icon_;
|
||||
|
||||
private:
|
||||
// Schedule a notification unresponsive event.
|
||||
@@ -283,8 +311,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
// The windows has been closed.
|
||||
bool is_closed_;
|
||||
|
||||
// The security token of iframe.
|
||||
std::string node_integration_;
|
||||
// Whether node integration is enabled.
|
||||
bool node_integration_;
|
||||
|
||||
// There is a dialog that has been attached to window.
|
||||
bool has_dialog_attached_;
|
||||
@@ -294,13 +322,17 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
base::CancelableClosure window_unresposive_closure_;
|
||||
|
||||
// Web preferences.
|
||||
mate::ScopedPersistent<v8::Object> web_preferences_;
|
||||
mate::PersistentDictionary web_preferences_;
|
||||
|
||||
// The script to load before page's JavaScript starts to run.
|
||||
base::FilePath preload_script_;
|
||||
|
||||
// Page's default zoom factor.
|
||||
double zoom_factor_;
|
||||
|
||||
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_,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -28,6 +28,7 @@ class NativeWindowMac : public NativeWindow {
|
||||
virtual void Focus(bool focus) OVERRIDE;
|
||||
virtual bool IsFocused() OVERRIDE;
|
||||
virtual void Show() OVERRIDE;
|
||||
virtual void ShowInactive() OVERRIDE;
|
||||
virtual void Hide() OVERRIDE;
|
||||
virtual bool IsVisible() OVERRIDE;
|
||||
virtual void Maximize() OVERRIDE;
|
||||
@@ -65,6 +66,7 @@ class NativeWindowMac : public NativeWindow {
|
||||
virtual bool IsDocumentEdited() OVERRIDE;
|
||||
virtual bool HasModalDialog() OVERRIDE;
|
||||
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
||||
virtual void SetProgressBar(double progress) OVERRIDE;
|
||||
|
||||
// Returns true if |point| in local Cocoa coordinate system falls within
|
||||
// the draggable region.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -108,10 +108,12 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
@end
|
||||
|
||||
@interface AtomNSWindow : EventProcessingWindow {
|
||||
@protected
|
||||
@private
|
||||
atom::NativeWindowMac* shell_;
|
||||
bool enable_larger_than_screen_;
|
||||
}
|
||||
- (void)setShell:(atom::NativeWindowMac*)shell;
|
||||
- (void)setEnableLargerThanScreen:(bool)enable;
|
||||
@end
|
||||
|
||||
@implementation AtomNSWindow
|
||||
@@ -120,14 +122,42 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
shell_ = shell;
|
||||
}
|
||||
|
||||
- (void)setEnableLargerThanScreen:(bool)enable {
|
||||
enable_larger_than_screen_ = enable;
|
||||
}
|
||||
|
||||
// Enable the window to be larger than screen.
|
||||
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen {
|
||||
if (enable_larger_than_screen_)
|
||||
return frameRect;
|
||||
else
|
||||
return [super constrainFrameRect:frameRect toScreen:screen];
|
||||
}
|
||||
|
||||
- (IBAction)reload:(id)sender {
|
||||
shell_->GetWebContents()->GetController().ReloadIgnoringCache(false);
|
||||
content::WebContents* web_contents = shell_->GetWebContents();
|
||||
content::NavigationController::LoadURLParams params(web_contents->GetURL());
|
||||
web_contents->GetController().LoadURLWithParams(params);
|
||||
}
|
||||
|
||||
- (IBAction)showDevTools:(id)sender {
|
||||
shell_->OpenDevTools();
|
||||
}
|
||||
|
||||
// Returns an empty array for AXChildren attribute, this will force the
|
||||
// SpeechSynthesisServer to use its classical way of speaking the selected text:
|
||||
// by invoking the "Command+C" for current application and then speak out
|
||||
// what's in the clipboard. Otherwise the "Text to Speech" would always speak
|
||||
// out window's title.
|
||||
// This behavior is taken by both FireFox and Chrome, see also FireFox's bug on
|
||||
// more of how SpeechSynthesisServer chose which text to read:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=674612
|
||||
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
||||
if ([attribute isEqualToString:@"AXChildren"])
|
||||
return [NSArray array];
|
||||
return [super accessibilityAttributeValue:attribute];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface ControlRegionView : NSView {
|
||||
@@ -165,6 +195,39 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||
|
||||
@end
|
||||
|
||||
@interface AtomProgressBar : NSProgressIndicator
|
||||
@end
|
||||
|
||||
@implementation AtomProgressBar
|
||||
|
||||
- (void)drawRect:(NSRect)dirtyRect {
|
||||
if (self.style != NSProgressIndicatorBarStyle)
|
||||
return;
|
||||
// Draw edges of rounded rect.
|
||||
NSRect rect = NSInsetRect([self bounds], 1.0, 1.0);
|
||||
CGFloat radius = rect.size.height / 2;
|
||||
NSBezierPath* bezier_path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
|
||||
[bezier_path setLineWidth:2.0];
|
||||
[[NSColor grayColor] set];
|
||||
[bezier_path stroke];
|
||||
|
||||
// Fill the rounded rect.
|
||||
rect = NSInsetRect(rect, 2.0, 2.0);
|
||||
radius = rect.size.height / 2;
|
||||
bezier_path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
|
||||
[bezier_path setLineWidth:1.0];
|
||||
[bezier_path addClip];
|
||||
|
||||
// Calculate the progress width.
|
||||
rect.size.width = floor(rect.size.width * ([self doubleValue] / [self maxValue]));
|
||||
|
||||
// Fill the progress bar with color blue.
|
||||
[[NSColor colorWithSRGBRed:0.2 green:0.6 blue:1 alpha:1] set];
|
||||
NSRectFill(rect);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace atom {
|
||||
|
||||
NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||
@@ -194,6 +257,7 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||
defer:YES];
|
||||
|
||||
[atomWindow setShell:this];
|
||||
[atomWindow setEnableLargerThanScreen:enable_larger_than_screen_];
|
||||
window_.reset(atomWindow);
|
||||
|
||||
AtomNSWindowDelegate* delegate =
|
||||
@@ -275,6 +339,10 @@ void NativeWindowMac::Show() {
|
||||
[window_ makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
void NativeWindowMac::ShowInactive() {
|
||||
[window_ orderFrontRegardless];
|
||||
}
|
||||
|
||||
void NativeWindowMac::Hide() {
|
||||
[window_ orderOut:nil];
|
||||
}
|
||||
@@ -488,6 +556,42 @@ gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
|
||||
return window_;
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetProgressBar(double progress) {
|
||||
NSDockTile* dock_tile = [NSApp dockTile];
|
||||
|
||||
// For the first time API invoked, we need to create a ContentView in DockTile.
|
||||
if (dock_tile.contentView == NULL) {
|
||||
NSImageView* image_view = [[NSImageView alloc] init];
|
||||
[image_view setImage:[NSApp applicationIconImage]];
|
||||
[dock_tile setContentView:image_view];
|
||||
|
||||
NSProgressIndicator* progress_indicator = [[AtomProgressBar alloc]
|
||||
initWithFrame:NSMakeRect(0.0f, 0.0f, dock_tile.size.width, 15.0)];
|
||||
[progress_indicator setStyle:NSProgressIndicatorBarStyle];
|
||||
[progress_indicator setIndeterminate:NO];
|
||||
[progress_indicator setBezeled:YES];
|
||||
[progress_indicator setMinValue:0];
|
||||
[progress_indicator setMaxValue:1];
|
||||
[progress_indicator setHidden:NO];
|
||||
[image_view addSubview:progress_indicator];
|
||||
}
|
||||
|
||||
NSProgressIndicator* progress_indicator =
|
||||
static_cast<NSProgressIndicator*>([[[dock_tile contentView] subviews]
|
||||
objectAtIndex:0]);
|
||||
if (progress < 0) {
|
||||
[progress_indicator setHidden:YES];
|
||||
} else if (progress > 1) {
|
||||
[progress_indicator setHidden:NO];
|
||||
[progress_indicator setIndeterminate:YES];
|
||||
[progress_indicator setDoubleValue:1];
|
||||
} else {
|
||||
[progress_indicator setHidden:NO];
|
||||
[progress_indicator setDoubleValue:progress];
|
||||
}
|
||||
[dock_tile display];
|
||||
}
|
||||
|
||||
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
||||
if (!draggable_region_)
|
||||
return false;
|
||||
@@ -500,8 +604,10 @@ bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
||||
}
|
||||
|
||||
void NativeWindowMac::HandleMouseEvent(NSEvent* event) {
|
||||
NSPoint current_mouse_location =
|
||||
[window_ convertBaseToScreen:[event locationInWindow]];
|
||||
NSPoint eventLoc = [event locationInWindow];
|
||||
NSRect mouseRect = [window_ convertRectToScreen:NSMakeRect(eventLoc.x, eventLoc.y, 0, 0)];
|
||||
NSPoint current_mouse_location = mouseRect.origin;
|
||||
|
||||
|
||||
if ([event type] == NSLeftMouseDown) {
|
||||
NSPoint frame_origin = [window_ frame].origin;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/strings/string16.h"
|
||||
#include "ui/base/window_open_disposition.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class NativeWindowObserver {
|
||||
@@ -17,6 +21,12 @@ class NativeWindowObserver {
|
||||
virtual void OnPageTitleUpdated(bool* prevent_default,
|
||||
const std::string& title) {}
|
||||
|
||||
// Called when the web page in window wants to create a popup window.
|
||||
virtual void WillCreatePopupWindow(const base::string16& frame_name,
|
||||
const GURL& target_url,
|
||||
const std::string& partition_id,
|
||||
WindowOpenDisposition disposition) {}
|
||||
|
||||
// Called when the window is gonna closed.
|
||||
virtual void WillCloseWindow(bool* prevent_default) {}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -8,12 +8,6 @@
|
||||
#include <shobjidl.h>
|
||||
#endif
|
||||
|
||||
#if defined(USE_X11)
|
||||
#include <X11/extensions/XInput2.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -28,8 +22,6 @@
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/aura/window_tree_host.h"
|
||||
#include "ui/base/hit_test.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
#include "ui/views/background.h"
|
||||
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
|
||||
#include "ui/views/controls/webview/webview.h"
|
||||
@@ -37,14 +29,26 @@
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
||||
#if defined(USE_X11)
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/ui/views/global_menu_bar_x11.h"
|
||||
#include "atom/browser/ui/views/frameless_view.h"
|
||||
#include "atom/browser/ui/x/x_window_utils.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/nix/xdg_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "chrome/browser/ui/libgtk2ui/unity_service.h"
|
||||
#include "dbus/bus.h"
|
||||
#include "dbus/object_proxy.h"
|
||||
#include "dbus/message.h"
|
||||
#include "ui/base/x/x11_util.h"
|
||||
#include "ui/gfx/x/x11_types.h"
|
||||
#include "ui/views/window/native_frame_view.h"
|
||||
#elif defined(OS_WIN)
|
||||
#include "atom/browser/ui/views/win_frame_view.h"
|
||||
#include "base/win/scoped_comptr.h"
|
||||
#include "base/win/windows_version.h"
|
||||
#include "ui/base/win/shell.h"
|
||||
#include "ui/views/win/hwnd_util.h"
|
||||
#endif
|
||||
|
||||
namespace atom {
|
||||
@@ -58,6 +62,65 @@ const int kMenuBarHeight = 20;
|
||||
const int kMenuBarHeight = 25;
|
||||
#endif
|
||||
|
||||
#if defined(USE_X11)
|
||||
// Counts how many window has already been created, it will be used to set the
|
||||
// window role for X11.
|
||||
int kWindowsCreated = 0;
|
||||
|
||||
// Returns true if the bus name "com.canonical.AppMenu.Registrar" is available.
|
||||
bool ShouldUseGlobalMenuBar() {
|
||||
dbus::Bus::Options options;
|
||||
scoped_refptr<dbus::Bus> bus(new dbus::Bus(options));
|
||||
|
||||
dbus::ObjectProxy* object_proxy =
|
||||
bus->GetObjectProxy(DBUS_SERVICE_DBUS, dbus::ObjectPath(DBUS_PATH_DBUS));
|
||||
dbus::MethodCall method_call(DBUS_INTERFACE_DBUS, "ListNames");
|
||||
scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
|
||||
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
|
||||
if (!response) {
|
||||
bus->ShutdownAndBlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
dbus::MessageReader reader(response.get());
|
||||
dbus::MessageReader array_reader(NULL);
|
||||
if (!reader.PopArray(&array_reader)) {
|
||||
bus->ShutdownAndBlock();
|
||||
return false;
|
||||
}
|
||||
while (array_reader.HasMoreData()) {
|
||||
std::string name;
|
||||
if (array_reader.PopString(&name) &&
|
||||
name == "com.canonical.AppMenu.Registrar") {
|
||||
bus->ShutdownAndBlock();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bus->ShutdownAndBlock();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool IsAltKey(const content::NativeWebKeyboardEvent& event) {
|
||||
#if defined(USE_X11)
|
||||
// 164 and 165 represent VK_LALT and VK_RALT.
|
||||
return event.windowsKeyCode == 164 || event.windowsKeyCode == 165;
|
||||
#else
|
||||
return event.windowsKeyCode == ui::VKEY_MENU;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsAltModifier(const content::NativeWebKeyboardEvent& event) {
|
||||
typedef content::NativeWebKeyboardEvent::Modifiers Modifiers;
|
||||
int modifiers = event.modifiers;
|
||||
modifiers &= ~Modifiers::NumLockOn;
|
||||
modifiers &= ~Modifiers::CapsLockOn;
|
||||
return (modifiers == Modifiers::AltKey) ||
|
||||
(modifiers == (Modifiers::AltKey | Modifiers::IsLeft)) ||
|
||||
(modifiers == (Modifiers::AltKey | Modifiers::IsRight));
|
||||
}
|
||||
|
||||
class NativeWindowClientView : public views::ClientView {
|
||||
public:
|
||||
NativeWindowClientView(views::Widget* widget,
|
||||
@@ -81,13 +144,28 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
|
||||
const mate::Dictionary& options)
|
||||
: NativeWindow(web_contents, options),
|
||||
window_(new views::Widget),
|
||||
menu_bar_(NULL),
|
||||
web_view_(inspectable_web_contents()->GetView()->GetView()),
|
||||
menu_bar_autohide_(false),
|
||||
menu_bar_visible_(false),
|
||||
menu_bar_alt_pressed_(false),
|
||||
keyboard_event_handler_(new views::UnhandledKeyboardEventHandler),
|
||||
use_content_size_(false),
|
||||
resizable_(true) {
|
||||
options.Get(switches::kResizable, &resizable_);
|
||||
options.Get(switches::kTitle, &title_);
|
||||
options.Get(switches::kAutoHideMenuBar, &menu_bar_autohide_);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// On Windows we rely on the CanResize() to indicate whether window can be
|
||||
// resized, and it should be set before window is created.
|
||||
options.Get(switches::kResizable, &resizable_);
|
||||
#endif
|
||||
|
||||
if (enable_larger_than_screen_)
|
||||
// We need to set a default maximum window size here otherwise Windows
|
||||
// will not allow us to resize the window larger than scree.
|
||||
// Setting directly to INT_MAX somehow doesn't work, so we just devide
|
||||
// by 10, which should still be large enough.
|
||||
maximum_size_.SetSize(INT_MAX / 10, INT_MAX / 10);
|
||||
|
||||
int width = 800, height = 600;
|
||||
options.Get(switches::kWidth, &width);
|
||||
@@ -101,18 +179,44 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
|
||||
params.bounds = bounds;
|
||||
params.delegate = this;
|
||||
params.type = views::Widget::InitParams::TYPE_WINDOW;
|
||||
params.top_level = true;
|
||||
params.remove_standard_frame = !has_frame_;
|
||||
|
||||
#if defined(USE_X11)
|
||||
// FIXME Find out how to do this dynamically on Linux.
|
||||
bool skip_taskbar = false;
|
||||
if (options.Get(switches::kSkipTaskbar, &skip_taskbar) && skip_taskbar)
|
||||
params.type = views::Widget::InitParams::TYPE_BUBBLE;
|
||||
// Set WM_WINDOW_ROLE.
|
||||
params.wm_role_name = base::StringPrintf(
|
||||
"%s/%s/%d", "Atom Shell", Browser::Get()->GetName().c_str(),
|
||||
++kWindowsCreated);
|
||||
// Set WM_CLASS.
|
||||
params.wm_class_name = "atom";
|
||||
params.wm_class_class = "Atom";
|
||||
#endif
|
||||
|
||||
window_->Init(params);
|
||||
|
||||
#if defined(USE_X11)
|
||||
// Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set.
|
||||
bool use_dark_theme = false;
|
||||
if (options.Get(switches::kDarkTheme, &use_dark_theme) && use_dark_theme) {
|
||||
XDisplay* xdisplay = gfx::GetXDisplay();
|
||||
XChangeProperty(xdisplay, GetAcceleratedWidget(),
|
||||
XInternAtom(xdisplay, "_GTK_THEME_VARIANT", False),
|
||||
XInternAtom(xdisplay, "UTF8_STRING", False),
|
||||
8, PropModeReplace,
|
||||
reinterpret_cast<const unsigned char*>("dark"),
|
||||
4);
|
||||
}
|
||||
|
||||
// Before the window is mapped the SetWMSpecState can not work, so we have
|
||||
// to manually set the _NET_WM_STATE.
|
||||
bool skip_taskbar = false;
|
||||
if (options.Get(switches::kSkipTaskbar, &skip_taskbar) && skip_taskbar) {
|
||||
std::vector<::Atom> state_atom_list;
|
||||
state_atom_list.push_back(GetAtom("_NET_WM_STATE_SKIP_TASKBAR"));
|
||||
ui::SetAtomArrayProperty(GetAcceleratedWidget(), "_NET_WM_STATE", "ATOM",
|
||||
state_atom_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Add web view.
|
||||
SetLayoutManager(new MenuLayout(kMenuBarHeight));
|
||||
set_background(views::Background::CreateStandardPanelBackground());
|
||||
@@ -123,6 +227,23 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
|
||||
use_content_size_)
|
||||
bounds = ContentBoundsToWindowBounds(bounds);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
if (!has_frame_) {
|
||||
// Set Window style so that we get a minimize and maximize animation when
|
||||
// frameless.
|
||||
DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
|
||||
WS_CAPTION;
|
||||
::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style);
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO(zcbenz): This was used to force using native frame on Windows 2003, we
|
||||
// should check whether setting it in InitParams can work.
|
||||
if (has_frame_) {
|
||||
window_->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE);
|
||||
window_->FrameTypeChanged();
|
||||
}
|
||||
|
||||
window_->UpdateWindowIcon();
|
||||
window_->CenterWindow(bounds.size());
|
||||
Layout();
|
||||
@@ -159,6 +280,10 @@ void NativeWindowViews::Show() {
|
||||
window_->Show();
|
||||
}
|
||||
|
||||
void NativeWindowViews::ShowInactive() {
|
||||
window_->ShowInactive();
|
||||
}
|
||||
|
||||
void NativeWindowViews::Hide() {
|
||||
window_->Hide();
|
||||
}
|
||||
@@ -200,6 +325,15 @@ bool NativeWindowViews::IsFullscreen() {
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetSize(const gfx::Size& size) {
|
||||
#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);
|
||||
}
|
||||
#endif
|
||||
|
||||
window_->SetSize(size);
|
||||
}
|
||||
|
||||
@@ -219,8 +353,7 @@ void NativeWindowViews::SetContentSize(const gfx::Size& size) {
|
||||
}
|
||||
|
||||
gfx::Rect bounds = window_->GetWindowBoundsInScreen();
|
||||
bounds.set_size(size);
|
||||
window_->SetBounds(ContentBoundsToWindowBounds(bounds));
|
||||
SetSize(ContentBoundsToWindowBounds(gfx::Rect(bounds.origin(), size)).size());
|
||||
}
|
||||
|
||||
gfx::Size NativeWindowViews::GetContentSize() {
|
||||
@@ -229,7 +362,7 @@ gfx::Size NativeWindowViews::GetContentSize() {
|
||||
|
||||
gfx::Size content_size =
|
||||
window_->non_client_view()->frame_view()->GetBoundsForClientView().size();
|
||||
if (menu_bar_)
|
||||
if (menu_bar_ && menu_bar_visible_)
|
||||
content_size.set_height(content_size.height() - kMenuBarHeight);
|
||||
return content_size;
|
||||
}
|
||||
@@ -267,8 +400,33 @@ gfx::Size NativeWindowViews::GetMaximumSize() {
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetResizable(bool resizable) {
|
||||
#if defined(OS_WIN)
|
||||
if (has_frame_) {
|
||||
// WS_MAXIMIZEBOX => Maximize button
|
||||
// WS_MINIMIZEBOX => Minimize button
|
||||
// WS_THICKFRAME => Resize handle
|
||||
DWORD style = ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE);
|
||||
if (resizable)
|
||||
style |= WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_THICKFRAME;
|
||||
else
|
||||
style = (style & ~(WS_MAXIMIZEBOX | WS_THICKFRAME)) | WS_MINIMIZEBOX;
|
||||
::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, style);
|
||||
}
|
||||
#elif defined(USE_X11)
|
||||
if (resizable != resizable_) {
|
||||
// On Linux there is no "resizable" property of a window, we have to set
|
||||
// both the minimum and maximum size to the window size to achieve it.
|
||||
if (resizable) {
|
||||
SetMaximumSize(gfx::Size());
|
||||
SetMinimumSize(gfx::Size());
|
||||
} else {
|
||||
SetMaximumSize(GetSize());
|
||||
SetMinimumSize(GetSize());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
resizable_ = resizable;
|
||||
// FIXME Implement me for X11.
|
||||
}
|
||||
|
||||
bool NativeWindowViews::IsResizable() {
|
||||
@@ -324,6 +482,9 @@ void NativeWindowViews::SetSkipTaskbar(bool skip) {
|
||||
taskbar->DeleteTab(GetAcceleratedWidget());
|
||||
else
|
||||
taskbar->AddTab(GetAcceleratedWidget());
|
||||
#elif defined(USE_X11)
|
||||
SetWMSpecState(GetAcceleratedWidget(), skip,
|
||||
GetAtom("_NET_WM_STATE_SKIP_TASKBAR"));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -339,7 +500,7 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
|
||||
RegisterAccelerators(menu_model);
|
||||
|
||||
#if defined(USE_X11)
|
||||
if (unity::IsRunning() && !global_menu_bar_)
|
||||
if (!global_menu_bar_ && ShouldUseGlobalMenuBar())
|
||||
global_menu_bar_.reset(new GlobalMenuBarX11(this));
|
||||
|
||||
// Use global application menu bar when possible.
|
||||
@@ -355,11 +516,14 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
|
||||
|
||||
if (!menu_bar_) {
|
||||
gfx::Size content_size = GetContentSize();
|
||||
menu_bar_ = new MenuBar;
|
||||
AddChildViewAt(menu_bar_, 0);
|
||||
menu_bar_.reset(new MenuBar);
|
||||
menu_bar_->set_owned_by_client();
|
||||
|
||||
if (use_content_size_)
|
||||
SetContentSize(content_size);
|
||||
if (!menu_bar_autohide_) {
|
||||
SetMenuBarVisibility(true);
|
||||
if (use_content_size_)
|
||||
SetContentSize(content_size);
|
||||
}
|
||||
}
|
||||
|
||||
menu_bar_->SetMenu(menu_model);
|
||||
@@ -370,6 +534,65 @@ gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
|
||||
return window_->GetNativeWindow();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetProgressBar(double progress) {
|
||||
#if defined(OS_WIN)
|
||||
if (base::win::GetVersion() < base::win::VERSION_WIN7)
|
||||
return;
|
||||
base::win::ScopedComPtr<ITaskbarList3> taskbar;
|
||||
if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList, NULL,
|
||||
CLSCTX_INPROC_SERVER) ||
|
||||
FAILED(taskbar->HrInit()))) {
|
||||
return;
|
||||
}
|
||||
HWND frame = views::HWNDForNativeWindow(GetNativeWindow());
|
||||
if (progress > 1.0) {
|
||||
taskbar->SetProgressState(frame, TBPF_INDETERMINATE);
|
||||
} else if (progress < 0) {
|
||||
taskbar->SetProgressState(frame, TBPF_NOPROGRESS);
|
||||
} else if (progress >= 0) {
|
||||
taskbar->SetProgressValue(frame,
|
||||
static_cast<int>(progress * 100),
|
||||
100);
|
||||
}
|
||||
#elif defined(USE_X11)
|
||||
if (unity::IsRunning()) {
|
||||
unity::SetProgressFraction(progress);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetAutoHideMenuBar(bool auto_hide) {
|
||||
menu_bar_autohide_ = auto_hide;
|
||||
}
|
||||
|
||||
bool NativeWindowViews::IsMenuBarAutoHide() {
|
||||
return menu_bar_autohide_;
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetMenuBarVisibility(bool visible) {
|
||||
if (!menu_bar_ || menu_bar_visible_ == visible)
|
||||
return;
|
||||
|
||||
// Always show the accelerator when the auto-hide menu bar shows.
|
||||
if (menu_bar_autohide_)
|
||||
menu_bar_->SetAcceleratorVisibility(visible);
|
||||
|
||||
menu_bar_visible_ = visible;
|
||||
if (visible) {
|
||||
DCHECK_EQ(child_count(), 1);
|
||||
AddChildView(menu_bar_.get());
|
||||
} else {
|
||||
DCHECK_EQ(child_count(), 2);
|
||||
RemoveChildView(menu_bar_.get());
|
||||
}
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
bool NativeWindowViews::IsMenuBarVisible() {
|
||||
return menu_bar_visible_;
|
||||
}
|
||||
|
||||
gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
|
||||
return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
|
||||
}
|
||||
@@ -406,6 +629,13 @@ void NativeWindowViews::OnWidgetActivationChanged(
|
||||
NotifyWindowFocus();
|
||||
else
|
||||
NotifyWindowBlur();
|
||||
|
||||
if (active && GetWebContents() && !IsDevToolsOpened())
|
||||
GetWebContents()->Focus();
|
||||
|
||||
// Hide menu bar when window is blured.
|
||||
if (!active && menu_bar_autohide_ && menu_bar_visible_)
|
||||
SetMenuBarVisibility(false);
|
||||
}
|
||||
|
||||
void NativeWindowViews::DeleteDelegate() {
|
||||
@@ -433,10 +663,7 @@ bool NativeWindowViews::ShouldHandleSystemCommands() const {
|
||||
}
|
||||
|
||||
gfx::ImageSkia NativeWindowViews::GetWindowAppIcon() {
|
||||
if (icon_)
|
||||
return *(icon_->ToImageSkia());
|
||||
else
|
||||
return gfx::ImageSkia();
|
||||
return icon_;
|
||||
}
|
||||
|
||||
gfx::ImageSkia NativeWindowViews::GetWindowIcon() {
|
||||
@@ -480,26 +707,72 @@ views::ClientView* NativeWindowViews::CreateClientView(views::Widget* widget) {
|
||||
views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView(
|
||||
views::Widget* widget) {
|
||||
#if defined(OS_WIN)
|
||||
WinFrameView* frame_view = new WinFrameView;
|
||||
WinFrameView* frame_view = new WinFrameView;
|
||||
frame_view->Init(this, widget);
|
||||
return frame_view;
|
||||
#elif defined(OS_LINUX)
|
||||
#else
|
||||
if (has_frame_) {
|
||||
return new views::NativeFrameView(widget);
|
||||
} else {
|
||||
FramelessView* frame_view = new FramelessView;
|
||||
FramelessView* frame_view = new FramelessView;
|
||||
frame_view->Init(this, widget);
|
||||
return frame_view;
|
||||
}
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
gfx::ImageSkia NativeWindowViews::GetDevToolsWindowIcon() {
|
||||
return GetWindowAppIcon();
|
||||
}
|
||||
|
||||
void NativeWindowViews::HandleMouseDown() {
|
||||
// Hide menu bar when web view is clicked.
|
||||
if (menu_bar_autohide_ && menu_bar_visible_)
|
||||
SetMenuBarVisibility(false);
|
||||
}
|
||||
|
||||
void NativeWindowViews::HandleKeyboardEvent(
|
||||
content::WebContents*,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
keyboard_event_handler_->HandleKeyboardEvent(event, GetFocusManager());
|
||||
|
||||
if (!menu_bar_)
|
||||
return;
|
||||
|
||||
// Show accelerator when "Alt" is pressed.
|
||||
if (menu_bar_visible_ && IsAltKey(event))
|
||||
menu_bar_->SetAcceleratorVisibility(
|
||||
event.type == blink::WebInputEvent::RawKeyDown);
|
||||
|
||||
// Show the submenu when "Alt+Key" is pressed.
|
||||
if (event.type == blink::WebInputEvent::RawKeyDown && !IsAltKey(event) &&
|
||||
IsAltModifier(event)) {
|
||||
if (!menu_bar_visible_ &&
|
||||
(menu_bar_->GetAcceleratorIndex(event.windowsKeyCode) != -1))
|
||||
SetMenuBarVisibility(true);
|
||||
menu_bar_->ActivateAccelerator(event.windowsKeyCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!menu_bar_autohide_)
|
||||
return;
|
||||
|
||||
// Toggle the menu bar only when a single Alt is released.
|
||||
if (event.type == blink::WebInputEvent::RawKeyDown && IsAltKey(event)) {
|
||||
// When a single Alt is pressed:
|
||||
menu_bar_alt_pressed_ = true;
|
||||
} else if (event.type == blink::WebInputEvent::KeyUp && IsAltKey(event) &&
|
||||
#if defined(USE_X11)
|
||||
event.modifiers == 0 &&
|
||||
#endif
|
||||
menu_bar_alt_pressed_) {
|
||||
// When a single Alt is released right after a Alt is pressed:
|
||||
menu_bar_alt_pressed_ = false;
|
||||
SetMenuBarVisibility(!menu_bar_visible_);
|
||||
} else {
|
||||
// When any other keys except single Alt have been pressed/released:
|
||||
menu_bar_alt_pressed_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
||||
@@ -528,7 +801,7 @@ gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
|
||||
const gfx::Rect& bounds) {
|
||||
gfx::Rect window_bounds =
|
||||
window_->non_client_view()->GetWindowBoundsForClientBounds(bounds);
|
||||
if (menu_bar_)
|
||||
if (menu_bar_ && menu_bar_visible_)
|
||||
window_bounds.set_height(window_bounds.height() + kMenuBarHeight);
|
||||
return window_bounds;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
namespace views {
|
||||
class UnhandledKeyboardEventHandler;
|
||||
class Widget;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
@@ -33,45 +32,51 @@ class NativeWindowViews : public NativeWindow,
|
||||
virtual ~NativeWindowViews();
|
||||
|
||||
// NativeWindow:
|
||||
virtual void Close() OVERRIDE;
|
||||
virtual void CloseImmediately() OVERRIDE;
|
||||
virtual void Move(const gfx::Rect& pos) OVERRIDE;
|
||||
virtual void Focus(bool focus) OVERRIDE;
|
||||
virtual bool IsFocused() OVERRIDE;
|
||||
virtual void Show() OVERRIDE;
|
||||
virtual void Hide() OVERRIDE;
|
||||
virtual bool IsVisible() OVERRIDE;
|
||||
virtual void Maximize() OVERRIDE;
|
||||
virtual void Unmaximize() OVERRIDE;
|
||||
virtual bool IsMaximized() OVERRIDE;
|
||||
virtual void Minimize() OVERRIDE;
|
||||
virtual void Restore() OVERRIDE;
|
||||
virtual bool IsMinimized() OVERRIDE;
|
||||
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
|
||||
virtual bool IsFullscreen() OVERRIDE;
|
||||
virtual void SetSize(const gfx::Size& size) OVERRIDE;
|
||||
virtual gfx::Size GetSize() OVERRIDE;
|
||||
virtual void SetContentSize(const gfx::Size& size) OVERRIDE;
|
||||
virtual gfx::Size GetContentSize() OVERRIDE;
|
||||
virtual void SetMinimumSize(const gfx::Size& size) OVERRIDE;
|
||||
virtual gfx::Size GetMinimumSize() OVERRIDE;
|
||||
virtual void SetMaximumSize(const gfx::Size& size) OVERRIDE;
|
||||
virtual gfx::Size GetMaximumSize() OVERRIDE;
|
||||
virtual void SetResizable(bool resizable) OVERRIDE;
|
||||
virtual bool IsResizable() OVERRIDE;
|
||||
virtual void SetAlwaysOnTop(bool top) OVERRIDE;
|
||||
virtual bool IsAlwaysOnTop() OVERRIDE;
|
||||
virtual void Center() OVERRIDE;
|
||||
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
|
||||
virtual gfx::Point GetPosition() OVERRIDE;
|
||||
virtual void SetTitle(const std::string& title) OVERRIDE;
|
||||
virtual std::string GetTitle() OVERRIDE;
|
||||
virtual void FlashFrame(bool flash) OVERRIDE;
|
||||
virtual void SetSkipTaskbar(bool skip) OVERRIDE;
|
||||
virtual void SetKiosk(bool kiosk) OVERRIDE;
|
||||
virtual bool IsKiosk() OVERRIDE;
|
||||
virtual void SetMenu(ui::MenuModel* menu_model) OVERRIDE;
|
||||
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
||||
void Close() override;
|
||||
void CloseImmediately() override;
|
||||
void Move(const gfx::Rect& pos) override;
|
||||
void Focus(bool focus) override;
|
||||
bool IsFocused() override;
|
||||
void Show() override;
|
||||
void ShowInactive() override;
|
||||
void Hide() override;
|
||||
bool IsVisible() override;
|
||||
void Maximize() override;
|
||||
void Unmaximize() override;
|
||||
bool IsMaximized() override;
|
||||
void Minimize() override;
|
||||
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;
|
||||
void SetContentSize(const gfx::Size& size) override;
|
||||
gfx::Size GetContentSize() override;
|
||||
void SetMinimumSize(const gfx::Size& size) override;
|
||||
gfx::Size GetMinimumSize() override;
|
||||
void SetMaximumSize(const gfx::Size& size) override;
|
||||
gfx::Size GetMaximumSize() override;
|
||||
void SetResizable(bool resizable) override;
|
||||
bool IsResizable() override;
|
||||
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;
|
||||
void SetSkipTaskbar(bool skip) override;
|
||||
void SetKiosk(bool kiosk) override;
|
||||
bool IsKiosk() override;
|
||||
void SetMenu(ui::MenuModel* menu_model) override;
|
||||
gfx::NativeWindow GetNativeWindow() override;
|
||||
void SetProgressBar(double value) override;
|
||||
void SetAutoHideMenuBar(bool auto_hide) override;
|
||||
bool IsMenuBarAutoHide() override;
|
||||
void SetMenuBarVisibility(bool visible) override;
|
||||
bool IsMenuBarVisible() override;
|
||||
|
||||
gfx::AcceleratedWidget GetAcceleratedWidget();
|
||||
|
||||
@@ -80,39 +85,43 @@ class NativeWindowViews : public NativeWindow,
|
||||
|
||||
private:
|
||||
// NativeWindow:
|
||||
virtual void UpdateDraggableRegions(
|
||||
const std::vector<DraggableRegion>& regions) OVERRIDE;
|
||||
void UpdateDraggableRegions(
|
||||
const std::vector<DraggableRegion>& regions) override;
|
||||
|
||||
// views::WidgetObserver:
|
||||
virtual void OnWidgetActivationChanged(
|
||||
views::Widget* widget, bool active) OVERRIDE;
|
||||
void OnWidgetActivationChanged(
|
||||
views::Widget* widget, bool active) override;
|
||||
|
||||
// views::WidgetDelegate:
|
||||
virtual void DeleteDelegate() OVERRIDE;
|
||||
virtual views::View* GetInitiallyFocusedView() OVERRIDE;
|
||||
virtual bool CanResize() const OVERRIDE;
|
||||
virtual bool CanMaximize() const OVERRIDE;
|
||||
virtual base::string16 GetWindowTitle() const OVERRIDE;
|
||||
virtual bool ShouldHandleSystemCommands() const OVERRIDE;
|
||||
virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
|
||||
virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
|
||||
virtual views::Widget* GetWidget() OVERRIDE;
|
||||
virtual const views::Widget* GetWidget() const OVERRIDE;
|
||||
virtual views::View* GetContentsView() OVERRIDE;
|
||||
virtual bool ShouldDescendIntoChildForEventHandling(
|
||||
void DeleteDelegate() override;
|
||||
views::View* GetInitiallyFocusedView() override;
|
||||
bool CanResize() const override;
|
||||
bool CanMaximize() const override;
|
||||
base::string16 GetWindowTitle() const override;
|
||||
bool ShouldHandleSystemCommands() const override;
|
||||
gfx::ImageSkia GetWindowAppIcon() override;
|
||||
gfx::ImageSkia GetWindowIcon() override;
|
||||
views::Widget* GetWidget() override;
|
||||
const views::Widget* GetWidget() const override;
|
||||
views::View* GetContentsView() override;
|
||||
bool ShouldDescendIntoChildForEventHandling(
|
||||
gfx::NativeView child,
|
||||
const gfx::Point& location) OVERRIDE;
|
||||
virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
|
||||
virtual views::NonClientFrameView* CreateNonClientFrameView(
|
||||
views::Widget* widget) OVERRIDE;
|
||||
const gfx::Point& location) override;
|
||||
views::ClientView* CreateClientView(views::Widget* widget) override;
|
||||
views::NonClientFrameView* CreateNonClientFrameView(
|
||||
views::Widget* widget) override;
|
||||
|
||||
// brightray::InspectableWebContentsDelegate:
|
||||
gfx::ImageSkia GetDevToolsWindowIcon() override;
|
||||
|
||||
// content::WebContentsDelegate:
|
||||
virtual void HandleKeyboardEvent(
|
||||
void HandleMouseDown() override;
|
||||
void HandleKeyboardEvent(
|
||||
content::WebContents*,
|
||||
const content::NativeWebKeyboardEvent& event) OVERRIDE;
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
|
||||
// views::View:
|
||||
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
|
||||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||
|
||||
// Register accelerators supported by the menu model.
|
||||
void RegisterAccelerators(ui::MenuModel* menu_model);
|
||||
@@ -122,9 +131,13 @@ class NativeWindowViews : public NativeWindow,
|
||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& content_bounds);
|
||||
|
||||
scoped_ptr<views::Widget> window_;
|
||||
MenuBar* menu_bar_;
|
||||
views::View* web_view_; // Managed by inspectable_web_contents_.
|
||||
|
||||
scoped_ptr<MenuBar> menu_bar_;
|
||||
bool menu_bar_autohide_;
|
||||
bool menu_bar_visible_;
|
||||
bool menu_bar_alt_pressed_;
|
||||
|
||||
#if defined(USE_X11)
|
||||
scoped_ptr<GlobalMenuBarX11> global_menu_bar_;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
91
atom/browser/net/asar/asar_protocol_handler.cc
Normal file
91
atom/browser/net/asar/asar_protocol_handler.cc
Normal file
@@ -0,0 +1,91 @@
|
||||
// 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/net/asar/asar_protocol_handler.h"
|
||||
|
||||
#include "atom/browser/net/asar/url_request_asar_job.h"
|
||||
#include "atom/common/asar/archive.h"
|
||||
#include "net/base/filename_util.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/url_request/url_request_error_job.h"
|
||||
#include "net/url_request/url_request_file_job.h"
|
||||
|
||||
namespace asar {
|
||||
|
||||
namespace {
|
||||
|
||||
const base::FilePath::CharType kAsarExtension[] = FILE_PATH_LITERAL(".asar");
|
||||
|
||||
// Get the relative path in asar archive.
|
||||
bool GetAsarPath(const base::FilePath& full_path,
|
||||
base::FilePath* asar_path,
|
||||
base::FilePath* relative_path) {
|
||||
base::FilePath iter = full_path;
|
||||
while (true) {
|
||||
base::FilePath dirname = iter.DirName();
|
||||
if (iter.MatchesExtension(kAsarExtension))
|
||||
break;
|
||||
else if (iter == dirname)
|
||||
return false;
|
||||
iter = dirname;
|
||||
}
|
||||
|
||||
base::FilePath tail;
|
||||
if (!iter.AppendRelativePath(full_path, &tail))
|
||||
return false;
|
||||
|
||||
*asar_path = iter;
|
||||
*relative_path = tail;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AsarProtocolHandler::AsarProtocolHandler(
|
||||
const scoped_refptr<base::TaskRunner>& file_task_runner)
|
||||
: file_task_runner_(file_task_runner) {}
|
||||
|
||||
AsarProtocolHandler::~AsarProtocolHandler() {
|
||||
}
|
||||
|
||||
Archive* AsarProtocolHandler::GetOrCreateAsarArchive(
|
||||
const base::FilePath& path) const {
|
||||
if (!archives_.contains(path)) {
|
||||
scoped_ptr<Archive> archive(new Archive(path));
|
||||
if (!archive->Init())
|
||||
return nullptr;
|
||||
|
||||
archives_.set(path, archive.Pass());
|
||||
}
|
||||
|
||||
return archives_.get(path);
|
||||
}
|
||||
|
||||
net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const {
|
||||
base::FilePath full_path;
|
||||
net::FileURLToFilePath(request->url(), &full_path);
|
||||
|
||||
// Create asar:// job when the path contains "xxx.asar/", otherwise treat the
|
||||
// URL request as file://.
|
||||
base::FilePath asar_path, relative_path;
|
||||
if (!GetAsarPath(full_path, &asar_path, &relative_path))
|
||||
return new net::URLRequestFileJob(request, network_delegate, full_path,
|
||||
file_task_runner_);
|
||||
|
||||
Archive* archive = GetOrCreateAsarArchive(asar_path);
|
||||
if (!archive)
|
||||
return new net::URLRequestErrorJob(request, network_delegate,
|
||||
net::ERR_FILE_NOT_FOUND);
|
||||
|
||||
return new URLRequestAsarJob(request, network_delegate, archive,
|
||||
relative_path, file_task_runner_);
|
||||
}
|
||||
|
||||
bool AsarProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
45
atom/browser/net/asar/asar_protocol_handler.h
Normal file
45
atom/browser/net/asar/asar_protocol_handler.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_
|
||||
#define ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_
|
||||
|
||||
#include "base/containers/scoped_ptr_hash_map.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "net/url_request/url_request_job_factory.h"
|
||||
|
||||
namespace base {
|
||||
class TaskRunner;
|
||||
}
|
||||
|
||||
namespace asar {
|
||||
|
||||
class Archive;
|
||||
|
||||
class AsarProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
|
||||
public:
|
||||
explicit AsarProtocolHandler(
|
||||
const scoped_refptr<base::TaskRunner>& file_task_runner);
|
||||
virtual ~AsarProtocolHandler();
|
||||
|
||||
Archive* GetOrCreateAsarArchive(const base::FilePath& path) const;
|
||||
|
||||
// net::URLRequestJobFactory::ProtocolHandler:
|
||||
virtual net::URLRequestJob* MaybeCreateJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const OVERRIDE;
|
||||
virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE;
|
||||
|
||||
private:
|
||||
const scoped_refptr<base::TaskRunner> file_task_runner_;
|
||||
|
||||
mutable base::ScopedPtrHashMap<base::FilePath, Archive> archives_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AsarProtocolHandler);
|
||||
};
|
||||
|
||||
} // namespace asar
|
||||
|
||||
#endif // ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_
|
||||
142
atom/browser/net/asar/url_request_asar_job.cc
Normal file
142
atom/browser/net/asar/url_request_asar_job.cc
Normal file
@@ -0,0 +1,142 @@
|
||||
// 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/net/asar/url_request_asar_job.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "net/base/file_stream.h"
|
||||
#include "net/base/io_buffer.h"
|
||||
#include "net/base/mime_util.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/url_request/url_request_status.h"
|
||||
|
||||
namespace asar {
|
||||
|
||||
URLRequestAsarJob::URLRequestAsarJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate,
|
||||
Archive* archive,
|
||||
const base::FilePath& file_path,
|
||||
const scoped_refptr<base::TaskRunner>& file_task_runner)
|
||||
: net::URLRequestJob(request, network_delegate),
|
||||
archive_(archive),
|
||||
file_path_(file_path),
|
||||
stream_(new net::FileStream(file_task_runner)),
|
||||
remaining_bytes_(0),
|
||||
file_task_runner_(file_task_runner),
|
||||
weak_ptr_factory_(this) {}
|
||||
|
||||
URLRequestAsarJob::~URLRequestAsarJob() {}
|
||||
|
||||
void URLRequestAsarJob::Start() {
|
||||
if (!archive_ || !archive_->GetFileInfo(file_path_, &file_info_)) {
|
||||
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
||||
net::ERR_FILE_NOT_FOUND));
|
||||
return;
|
||||
}
|
||||
|
||||
remaining_bytes_ = static_cast<int64>(file_info_.size);
|
||||
|
||||
int flags = base::File::FLAG_OPEN |
|
||||
base::File::FLAG_READ |
|
||||
base::File::FLAG_ASYNC;
|
||||
int rv = stream_->Open(archive_->path(), flags,
|
||||
base::Bind(&URLRequestAsarJob::DidOpen,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
if (rv != net::ERR_IO_PENDING)
|
||||
DidOpen(rv);
|
||||
}
|
||||
|
||||
void URLRequestAsarJob::Kill() {
|
||||
weak_ptr_factory_.InvalidateWeakPtrs();
|
||||
URLRequestJob::Kill();
|
||||
}
|
||||
|
||||
bool URLRequestAsarJob::ReadRawData(net::IOBuffer* dest,
|
||||
int dest_size,
|
||||
int* bytes_read) {
|
||||
if (remaining_bytes_ < dest_size)
|
||||
dest_size = static_cast<int>(remaining_bytes_);
|
||||
|
||||
// If we should copy zero bytes because |remaining_bytes_| is zero, short
|
||||
// circuit here.
|
||||
if (!dest_size) {
|
||||
*bytes_read = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int rv = stream_->Read(dest,
|
||||
dest_size,
|
||||
base::Bind(&URLRequestAsarJob::DidRead,
|
||||
weak_ptr_factory_.GetWeakPtr(),
|
||||
make_scoped_refptr(dest)));
|
||||
if (rv >= 0) {
|
||||
// Data is immediately available.
|
||||
*bytes_read = rv;
|
||||
remaining_bytes_ -= rv;
|
||||
DCHECK_GE(remaining_bytes_, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, a read error occured. We may just need to wait...
|
||||
if (rv == net::ERR_IO_PENDING) {
|
||||
SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
|
||||
} else {
|
||||
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, rv));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool URLRequestAsarJob::GetMimeType(std::string* mime_type) const {
|
||||
return net::GetMimeTypeFromFile(file_path_, mime_type);
|
||||
}
|
||||
|
||||
void URLRequestAsarJob::DidOpen(int result) {
|
||||
if (result != net::OK) {
|
||||
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
|
||||
return;
|
||||
}
|
||||
|
||||
int rv = stream_->Seek(base::File::FROM_BEGIN,
|
||||
file_info_.offset,
|
||||
base::Bind(&URLRequestAsarJob::DidSeek,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
if (rv != net::ERR_IO_PENDING) {
|
||||
// stream_->Seek() failed, so pass an intentionally erroneous value
|
||||
// into DidSeek().
|
||||
DidSeek(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void URLRequestAsarJob::DidSeek(int64 result) {
|
||||
if (result != static_cast<int64>(file_info_.offset)) {
|
||||
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
||||
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
set_expected_content_size(remaining_bytes_);
|
||||
NotifyHeadersComplete();
|
||||
}
|
||||
|
||||
void URLRequestAsarJob::DidRead(scoped_refptr<net::IOBuffer> buf, int result) {
|
||||
if (result > 0) {
|
||||
SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status
|
||||
remaining_bytes_ -= result;
|
||||
DCHECK_GE(remaining_bytes_, 0);
|
||||
}
|
||||
|
||||
buf = NULL;
|
||||
|
||||
if (result == 0) {
|
||||
NotifyDone(net::URLRequestStatus());
|
||||
} else if (result < 0) {
|
||||
NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
|
||||
}
|
||||
|
||||
NotifyReadComplete(result);
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
72
atom/browser/net/asar/url_request_asar_job.h
Normal file
72
atom/browser/net/asar/url_request_asar_job.h
Normal file
@@ -0,0 +1,72 @@
|
||||
// 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_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
|
||||
#define ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/asar/archive.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "net/url_request/url_request_job.h"
|
||||
|
||||
namespace base {
|
||||
class TaskRunner;
|
||||
}
|
||||
|
||||
namespace net {
|
||||
class FileStream;
|
||||
}
|
||||
|
||||
namespace asar {
|
||||
|
||||
class URLRequestAsarJob : public net::URLRequestJob {
|
||||
public:
|
||||
URLRequestAsarJob(net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate,
|
||||
Archive* archive,
|
||||
const base::FilePath& file_path,
|
||||
const scoped_refptr<base::TaskRunner>& file_task_runner);
|
||||
|
||||
// net::URLRequestJob:
|
||||
virtual void Start() OVERRIDE;
|
||||
virtual void Kill() OVERRIDE;
|
||||
virtual bool ReadRawData(net::IOBuffer* buf,
|
||||
int buf_size,
|
||||
int* bytes_read) OVERRIDE;
|
||||
virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual ~URLRequestAsarJob();
|
||||
|
||||
private:
|
||||
// Callback after opening file on a background thread.
|
||||
void DidOpen(int result);
|
||||
|
||||
// Callback after seeking to the beginning of |byte_range_| in the file
|
||||
// on a background thread.
|
||||
void DidSeek(int64 result);
|
||||
|
||||
// Callback after data is asynchronously read from the file into |buf|.
|
||||
void DidRead(scoped_refptr<net::IOBuffer> buf, int result);
|
||||
|
||||
Archive* archive_;
|
||||
Archive::FileInfo file_info_;
|
||||
base::FilePath file_path_;
|
||||
|
||||
scoped_ptr<net::FileStream> stream_;
|
||||
int64 remaining_bytes_;
|
||||
|
||||
const scoped_refptr<base::TaskRunner> file_task_runner_;
|
||||
|
||||
base::WeakPtrFactory<URLRequestAsarJob> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(URLRequestAsarJob);
|
||||
};
|
||||
|
||||
} // namespace asar
|
||||
|
||||
#endif // ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
|
||||
@@ -1,186 +0,0 @@
|
||||
// Copyright (c) 2013 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/net/atom_url_request_context_getter.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/threading/sequenced_worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/cookie_store_factory.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "net/cert/cert_verifier.h"
|
||||
#include "net/cookies/cookie_monster.h"
|
||||
#include "net/http/http_auth_handler_factory.h"
|
||||
#include "net/http/http_cache.h"
|
||||
#include "net/http/http_server_properties_impl.h"
|
||||
#include "net/proxy/dhcp_proxy_script_fetcher_factory.h"
|
||||
#include "net/proxy/proxy_config_service.h"
|
||||
#include "net/proxy/proxy_script_fetcher_impl.h"
|
||||
#include "net/proxy/proxy_service.h"
|
||||
#include "net/proxy/proxy_service_v8.h"
|
||||
#include "net/ssl/default_server_bound_cert_store.h"
|
||||
#include "net/ssl/server_bound_cert_service.h"
|
||||
#include "net/ssl/ssl_config_service_defaults.h"
|
||||
#include "net/url_request/data_protocol_handler.h"
|
||||
#include "net/url_request/file_protocol_handler.h"
|
||||
#include "net/url_request/static_http_user_agent_settings.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_storage.h"
|
||||
#include "vendor/brightray/browser/network_delegate.h"
|
||||
#include "webkit/browser/quota/special_storage_policy.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
AtomURLRequestContextGetter::AtomURLRequestContextGetter(
|
||||
const base::FilePath& base_path,
|
||||
base::MessageLoop* io_loop,
|
||||
base::MessageLoop* file_loop,
|
||||
base::Callback<scoped_ptr<brightray::NetworkDelegate>(void)> factory,
|
||||
content::ProtocolHandlerMap* protocol_handlers)
|
||||
: base_path_(base_path),
|
||||
io_loop_(io_loop),
|
||||
file_loop_(file_loop),
|
||||
job_factory_(NULL),
|
||||
network_delegate_factory_(factory) {
|
||||
// Must first be created on the UI thread.
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||
|
||||
std::swap(protocol_handlers_, *protocol_handlers);
|
||||
|
||||
// We must create the proxy config service on the UI loop on Linux because it
|
||||
// must synchronously run on the glib message loop. This will be passed to
|
||||
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
|
||||
proxy_config_service_.reset(
|
||||
net::ProxyService::CreateSystemProxyConfigService(
|
||||
io_loop_->message_loop_proxy(),
|
||||
file_loop_));
|
||||
}
|
||||
|
||||
AtomURLRequestContextGetter::~AtomURLRequestContextGetter() {
|
||||
}
|
||||
|
||||
net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() {
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
||||
|
||||
base::AutoLock auto_lock(lock_);
|
||||
if (!url_request_context_.get()) {
|
||||
url_request_context_.reset(new net::URLRequestContext());
|
||||
network_delegate_ = network_delegate_factory_.Run().Pass();
|
||||
url_request_context_->set_network_delegate(network_delegate_.get());
|
||||
storage_.reset(
|
||||
new net::URLRequestContextStorage(url_request_context_.get()));
|
||||
auto cookie_config = content::CookieStoreConfig(
|
||||
base_path_.Append(FILE_PATH_LITERAL("Cookies")),
|
||||
content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
|
||||
nullptr,
|
||||
nullptr);
|
||||
storage_->set_cookie_store(content::CreateCookieStore(cookie_config));
|
||||
storage_->set_server_bound_cert_service(new net::ServerBoundCertService(
|
||||
new net::DefaultServerBoundCertStore(NULL),
|
||||
base::WorkerPool::GetTaskRunner(true)));
|
||||
storage_->set_http_user_agent_settings(
|
||||
new net::StaticHttpUserAgentSettings(
|
||||
"en-us,en", base::EmptyString()));
|
||||
|
||||
scoped_ptr<net::HostResolver> host_resolver(
|
||||
net::HostResolver::CreateDefaultResolver(NULL));
|
||||
net::DhcpProxyScriptFetcherFactory dhcp_factory;
|
||||
|
||||
storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
|
||||
storage_->set_transport_security_state(new net::TransportSecurityState);
|
||||
storage_->set_proxy_service(
|
||||
net::CreateProxyServiceUsingV8ProxyResolver(
|
||||
proxy_config_service_.release(),
|
||||
new net::ProxyScriptFetcherImpl(url_request_context_.get()),
|
||||
dhcp_factory.Create(url_request_context_.get()),
|
||||
host_resolver.get(),
|
||||
NULL,
|
||||
url_request_context_->network_delegate()));
|
||||
storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
|
||||
storage_->set_http_auth_handler_factory(
|
||||
net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get()));
|
||||
scoped_ptr<net::HttpServerProperties> server_properties(
|
||||
new net::HttpServerPropertiesImpl);
|
||||
storage_->set_http_server_properties(server_properties.Pass());
|
||||
|
||||
base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache"));
|
||||
net::HttpCache::DefaultBackend* main_backend =
|
||||
new net::HttpCache::DefaultBackend(
|
||||
net::DISK_CACHE,
|
||||
net::CACHE_BACKEND_DEFAULT,
|
||||
cache_path,
|
||||
0,
|
||||
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
|
||||
|
||||
net::HttpNetworkSession::Params network_session_params;
|
||||
network_session_params.cert_verifier =
|
||||
url_request_context_->cert_verifier();
|
||||
network_session_params.transport_security_state =
|
||||
url_request_context_->transport_security_state();
|
||||
network_session_params.server_bound_cert_service =
|
||||
url_request_context_->server_bound_cert_service();
|
||||
network_session_params.proxy_service =
|
||||
url_request_context_->proxy_service();
|
||||
network_session_params.ssl_config_service =
|
||||
url_request_context_->ssl_config_service();
|
||||
network_session_params.http_auth_handler_factory =
|
||||
url_request_context_->http_auth_handler_factory();
|
||||
network_session_params.network_delegate =
|
||||
url_request_context_->network_delegate();
|
||||
network_session_params.http_server_properties =
|
||||
url_request_context_->http_server_properties();
|
||||
network_session_params.ignore_certificate_errors = false;
|
||||
|
||||
// Give |storage_| ownership at the end in case it's |mapped_host_resolver|.
|
||||
storage_->set_host_resolver(host_resolver.Pass());
|
||||
network_session_params.host_resolver =
|
||||
url_request_context_->host_resolver();
|
||||
|
||||
net::HttpCache* main_cache = new net::HttpCache(
|
||||
network_session_params, main_backend);
|
||||
storage_->set_http_transaction_factory(main_cache);
|
||||
|
||||
DCHECK(!job_factory_);
|
||||
job_factory_ = new AtomURLRequestJobFactory;
|
||||
for (content::ProtocolHandlerMap::iterator it = protocol_handlers_.begin();
|
||||
it != protocol_handlers_.end();
|
||||
++it) {
|
||||
bool set_protocol = job_factory_->SetProtocolHandler(
|
||||
it->first,
|
||||
it->second.release());
|
||||
DCHECK(set_protocol);
|
||||
}
|
||||
protocol_handlers_.clear();
|
||||
|
||||
scoped_ptr<net::FileProtocolHandler> file_protocol_handler(
|
||||
new net::FileProtocolHandler(
|
||||
content::BrowserThread::GetBlockingPool()->
|
||||
GetTaskRunnerWithShutdownBehavior(
|
||||
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
|
||||
job_factory_->SetProtocolHandler(content::kDataScheme,
|
||||
new net::DataProtocolHandler);
|
||||
job_factory_->SetProtocolHandler(content::kFileScheme,
|
||||
file_protocol_handler.release());
|
||||
storage_->set_job_factory(job_factory_);
|
||||
}
|
||||
|
||||
return url_request_context_.get();
|
||||
}
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner>
|
||||
AtomURLRequestContextGetter::GetNetworkTaskRunner() const {
|
||||
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
|
||||
}
|
||||
|
||||
net::HostResolver* AtomURLRequestContextGetter::host_resolver() {
|
||||
return url_request_context_->host_resolver();
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
@@ -1,76 +0,0 @@
|
||||
// Copyright (c) 2013 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_NET_ATOM_URL_REQUEST_CONTEXT_GETTER_H_
|
||||
#define ATOM_BROWSER_NET_ATOM_URL_REQUEST_CONTEXT_GETTER_H_
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "content/public/browser/content_browser_client.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
|
||||
namespace base {
|
||||
class MessageLoop;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
class NetworkDelegate;
|
||||
}
|
||||
|
||||
namespace net {
|
||||
class HostResolver;
|
||||
class ProxyConfigService;
|
||||
class URLRequestContextStorage;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomURLRequestJobFactory;
|
||||
|
||||
class AtomURLRequestContextGetter : public net::URLRequestContextGetter {
|
||||
public:
|
||||
AtomURLRequestContextGetter(
|
||||
const base::FilePath& base_path,
|
||||
base::MessageLoop* io_loop,
|
||||
base::MessageLoop* file_loop,
|
||||
base::Callback<scoped_ptr<brightray::NetworkDelegate>(void)>,
|
||||
content::ProtocolHandlerMap* protocol_handlers);
|
||||
|
||||
// net::URLRequestContextGetter implementations:
|
||||
virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
|
||||
virtual scoped_refptr<base::SingleThreadTaskRunner>
|
||||
GetNetworkTaskRunner() const OVERRIDE;
|
||||
|
||||
net::HostResolver* host_resolver();
|
||||
net::URLRequestContextStorage* storage() const { return storage_.get(); }
|
||||
AtomURLRequestJobFactory* job_factory() const { return job_factory_; }
|
||||
|
||||
protected:
|
||||
virtual ~AtomURLRequestContextGetter();
|
||||
|
||||
private:
|
||||
base::FilePath base_path_;
|
||||
base::MessageLoop* io_loop_;
|
||||
base::MessageLoop* file_loop_;
|
||||
|
||||
AtomURLRequestJobFactory* job_factory_;
|
||||
base::Callback<scoped_ptr<brightray::NetworkDelegate>(void)>
|
||||
network_delegate_factory_;
|
||||
|
||||
base::Lock lock_;
|
||||
|
||||
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
|
||||
scoped_ptr<brightray::NetworkDelegate> network_delegate_;
|
||||
scoped_ptr<net::URLRequestContextStorage> storage_;
|
||||
scoped_ptr<net::URLRequestContext> url_request_context_;
|
||||
content::ProtocolHandlerMap protocol_handlers_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomURLRequestContextGetter);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_NET_ATOM_URL_REQUEST_CONTEXT_GETTER_H_
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user