Compare commits

..

381 Commits

Author SHA1 Message Date
Electron Bot
a5b474e824 Bump v6.1.4 2019-11-04 16:13:02 -08:00
Robo
1591e1320a fix: backport patch for webaudio (#20924)
* fix: backport patch for webaudio

* chore: update patches
2019-11-01 16:34:07 -07:00
Electron Bot
4c25b619a6 Bump v6.1.3 2019-11-01 08:58:29 -07:00
trop[bot]
c2c25f1ee3 build: do not try to run non existent VSTS release builds (#20876) 2019-10-31 10:55:28 -04:00
John Kleinschmidt
8cf8c8fe63 docs: Update the sccache name (#20462) (#20862)
(cherry picked from commit b3e7657159)
2019-10-31 09:55:39 +09:00
Birunthan Mohanathas
61fdda3e8f fix: Disable compositor recycling only for attached views (6-1-x) (#20834)
Backport of #20829

Notes: Fix flicker when switching between `BrowserView`s
2019-10-30 16:55:30 -04:00
Milan Burda
4a5f89d5c7 fix: properly generate requestID in webContents.printToPDF() (#20769) (#20811) 2019-10-30 14:38:09 +09:00
Milan Burda
36fd0e9b37 fix: pass frameId to v8Util.setRemoteCallbackFreer() (#20732) (#20815) 2019-10-30 14:36:06 +09:00
Milan Burda
512736542b fix: send ELECTRON_BROWSER_CONTEXT_RELEASE asynchronously (#20632) (#20716) 2019-10-29 11:34:11 +09:00
Shelley Vohr
b144900c00 fix: prevent menu gc during popup (#20786) 2019-10-28 18:35:58 -07:00
Electron Bot
dabaa7557a Bump v6.1.2 2019-10-24 12:06:16 -07:00
trop[bot]
c6a794d738 chore: update build_bring_back_node_with_ltcg_configuration.patch (#20709)
* chore: update build_bring_back_node_with_ltcg_configuration.patch

set default value for node_with_ltcg=true

* fix: move ltcg definition to Release configuration
2019-10-23 16:33:38 -07:00
Electron Bot
aa863bc323 Bump v6.1.1 2019-10-23 11:13:59 -07:00
Jeremy Apthorp
e3a79d6c52 fix: properly free remote objects (6-1-x) (#20694) 2019-10-23 10:31:59 -07:00
loc
14ba3ac63e chore: remove unused member variable (#20690) 2019-10-23 09:12:18 +09:00
loc
6a07825c47 fix: don't hang on SendSync if ElectronBrowser receiver is destroyed (6-0-x) (#20547) 2019-10-22 14:29:10 -07:00
Electron Bot
70b5e673bb Bump v6.1.0 2019-10-21 15:45:49 -07:00
trop[bot]
6359db712a fix: backport libuv patch for fs.mkdir/mkdirSync on invlaid names (#20665)
Backports https://github.com/libuv/libuv/pull/2375
2019-10-21 15:44:05 -07:00
Samuel Attard
268cd3939c feat: add a new contextBridge module (#20639)
* feat: add a new contextBridge module (#20307)

* feat: add a new contextBridge module

* chore: fix docs linting

* feat: add support for function arguments being proxied

* chore: ensure that contextBridge can only be used when contextIsolation is enabled

* docs: getReverseBinding can be null

* docs: fix broken links in md file

* feat: add support for promises in function parameters

* fix: linting failure for explicit constructor

* Update atom_api_context_bridge.cc

* chore: update docs and API design as per feedback

* refactor: remove reverse bindings and handle GC'able functions across the bridge

* chore: only expose debugGC in testing builds

* fix: do not proxy promises as objects

* spec: add complete spec coverage for contextBridge

* spec: add tests for null/undefined and the anti-overwrite logic

* chore: fix linting

* spec: add complex nested back-and-forth function calling

* fix: expose contextBridge in sandboxed renderers

* refactor: improve security of default_app using the new contextBridge module

* s/bindAPIInMainWorld/exposeInMainWorld

* chore: sorry for this commit, its a big one, I fixed like everything and refactored a lot

* chore: remove PassedValueCache as it is unused now

Values transferred from context A to context B are now cachde in the RenderFramePersistenceStore

* chore: move to anonymous namespace

* refactor: remove PassValueToOtherContextWithCache

* chore: remove commented unused code blocks

* chore: remove .only

* chore: remote commented code

* refactor: extract RenderFramePersistenceStore

* spec: ensure it works with numbered keys

* fix: handle number keys correctly

* fix: sort out the linter

* spec: update default_app asar spec for removed file

* refactor: change signatures to return v8 objects directly rather than the mate dictionary handle

* refactor: use the v8 serializer to support cloneable buffers and other object types

* chore: fix linting

* fix: handle hash collisions with a linked list in the map

* fix: enforce a recursion limit on the context bridge

* chore: fix linting

* chore: remove TODO

* chore: adapt for PR feedback

* chore: remove .only

* chore: clean up docs and clean up the proxy map when objects are released

* chore: ensure we cache object values that are cloned through the V8 serializer

* docs: mark contextBridge as experimental (#20638)

* docs: mark contextBridge as experimental

This commit didn't make it to the original PR, quick addition here

* Update context-bridge.md

* chore: touch up the differences between master and 6-0-x

* chore: add v8 serializer converter, cherry picked from 2fad53e66b

* chore: support converting OnceCallback to V8 (#17941)

* chore: fixup tests

* chore: fix linting

* chore: add patch for mojo message constructor
2019-10-21 13:58:03 -07:00
Samuel Attard
3ca62d9432 chore: manually bump version to 6.1.0-beta.0 in prep for 6.1.0 2019-10-21 13:01:18 -07:00
Milan Burda
9901700a91 test: skip desktopCapturer / remote module tests when the features are disabled (#20566) (#20577) 2019-10-21 15:40:21 -04:00
Robo
d5b088bc26 fix: add patch to node for native module size issue on windows (#20614) (#20627) 2019-10-18 12:57:08 -04:00
trop[bot]
a12de693b0 ci: add macOS debug builds (#20572)
* ci: add macOS debug builds

* Fix mac debug builds

* Remove ninja status as it is not available in 6-0-x
2019-10-15 09:14:25 -07:00
trop[bot]
e257981a6d spec: allow "Yu Gothic" as a Japanese sans-serif font on Windows (#20569) 2019-10-14 12:38:01 -07:00
Milan Burda
ffb96acab0 fix: when building with enable_plugins=false (#20354) (#20508) 2019-10-10 14:12:28 +02:00
Robo
fd0b57f219 fix: backport chromium patches to fix touchpad scrolling on windows (#20488)
Backports https://chromium-review.googlesource.com/c/chromium/src/+/1689922
and https://chromium-review.googlesource.com/c/chromium/src/+/1753661
2019-10-09 13:41:06 -07:00
Electron Bot
1e50380fab Bump v6.0.12 2019-10-08 12:43:31 -07:00
trop[bot]
31ba6c203e fix: properly free IsolateData in node_main (#20475) 2019-10-08 15:33:32 -04:00
Shelley Vohr
03d16f37d2 fix: enable worker threads in ELECTRON_RUN_AS_NODE (#20457) 2019-10-08 11:59:28 -04:00
Robo
e501930d38 fix: fs.watch() behavior change in node >= 10.16.0 (#20429)
This reverts the patch from https://github.com/electron/node/pull/100
which never got merged due to reasons outlined in https://github.com/libuv/libuv/pull/2313

* Adds new patches that backports https://github.com/libuv/libuv/pull/2459
  and https://github.com/libuv/libuv/pull/2460

Based on https://github.com/nodejs/node/issues/29460
2019-10-07 13:05:14 -07:00
Joshua Westerheide
28eb7b0532 feat: add env variable to skip binary download on npm install (backport) (#20438)
* feat: add env variable to skip binary download on npm install

* docs: add "Skip binary download" section to install tutorial
2019-10-07 13:04:00 -04:00
Shelley Vohr
15e611a0ff docs: clarify dock.bounce usage (#20458) 2019-10-07 17:15:48 +02:00
trop[bot]
3176e323e4 fix: recentDocuments menu role on macOS (#20409) 2019-10-03 08:59:09 +02:00
Milan Burda
99a0581d0d fix: allow paths to asar archives to contain the .asar extension in directories (#20342) (#20402) 2019-10-02 18:03:18 +09:00
Electron Bot
4e417e21b8 Bump v6.0.11 2019-10-01 12:08:35 -07:00
trop[bot]
e472efbea2 fix: correctly crash when there is no crashReporter (#20396)
* fix: correctly crash when there is no crashReporter

* test: correctly crash when there is crashReporter
2019-10-01 15:06:23 -04:00
Birunthan Mohanathas
886e636b13 fix: Make the --disable-color-correct-rendering switch work again (backport) (#20358) 2019-09-30 10:46:41 -07:00
trop[bot]
0450ee9524 fix: correct 'Entire screen' to ' Entire Screen' (#20301) 2019-09-20 07:44:21 -07:00
trop[bot]
ce31dc3591 ci: actually kill leftover processes on WOA testing (#20292)
* ci: only kill WOA processes if they are running

(cherry picked from commit 844752cd97)

* ci: actually kill leftover processes on WOA testing

(cherry picked from commit a76d2d8e53)
2019-09-20 10:20:19 -04:00
Shelley Vohr
15c89c8262 fix: crash when exiting simple fullscreen on macOS (#20144) (#20282) 2019-09-19 14:29:35 -04:00
Shelley Vohr
dbd72b2265 docs: improve and add examples for clipboard (#20224) (#20283)
* docs: improve and add examples for clipboard

* address feedback from jkleinsc review
2019-09-19 09:57:09 -04:00
Electron Bot
10a9e9c043 Bump v6.0.10 2019-09-18 12:48:43 -07:00
trop[bot]
690271e38c build: add WOA node headers to checksum file (#20260) 2019-09-18 10:21:46 -07:00
trop[bot]
fc7ef4cc1c fix: strip chrome-sandbox typo (#20257) 2019-09-18 09:43:52 -07:00
Samuel Attard
f2d1abd0e3 fix: Add more checks in MojoCdmService. (#20219)
Applies b7b305f338%5E%21/
2019-09-17 13:53:04 -04:00
Samuel Attard
e3be323962 docs: remove dash that broke the return type parser (#20246) 2019-09-17 10:49:07 -04:00
Electron Bot
407747b48c Bump v6.0.9 2019-09-11 10:30:11 -07:00
trop[bot]
17b8b551ac build: handle arm64 node headers (#20194)
* build: handle arm64 node headers

(cherry picked from commit ff1f224d96)

* node.lib for arm64 needs to go to specific dir
2019-09-10 21:56:07 -04:00
Electron Bot
4bcbe55828 Bump v6.0.8 2019-09-09 09:12:33 -07:00
trop[bot]
8f84626531 build: get all the release assets when looking for one to delete (#20165)
* build: get all the release assets when looking for one to delete

yeah we totally have more than 30....

* Update upload-to-github.js
2019-09-09 09:10:04 -07:00
Electron Bot
69d3a694f4 chore: bump chromium in DEPS to 76.0.3809.146 (#20149) 2019-09-06 09:11:54 -07:00
trop[bot]
3925c098fb fix: ensure modeL_ exists before calling delegate methods (#20115)
This is a speculative fix for a crash we are seeing in `menuDidClose`.  We
can't repro the crash but the traces have it happening in this method
and just by reading through the impl the only part that jumps out as
Might Crash is this `model_` call.  Other methods in the menu controller
check `model_` before using it so it probably makes sense to do that here
as well.
2019-09-06 07:54:38 -07:00
trop[bot]
75dd6e5a71 build: don't wait until job requests return in case some jobs fail to return (#20135) 2019-09-05 14:01:25 -04:00
Electron Bot
204c111da1 chore: bump chromium in DEPS to 76.0.3809.145 (#20130) 2019-09-05 10:30:17 -07:00
John Kleinschmidt
ed9b96ce9e ci: test on woa hardware (6-0-x) (#20092)
* ci: test on woa hardware

* ci: run tests on WOA hardware (#20031)

* ci: run tests on WOA hardware

* Temporarily disable test until #20008 is resolved

* deterministically run tests in sorted order

(cherry picked from commit bedc5f7da9)

* Disable test on WOA until #20008 is resolved

* use request instead of blur to detect openExternal success

* use blur event on mac, sigh

* oh, right, still gotta open an actual url

* Try to track down GPUinfo failure

* Make function async

* Check exitCode

* Try to resolve bad exit code on GPUInfo test

* Add logging to figure out failures on BrowserWindow.moveTop()

* Revert "Add logging to figure out failures on BrowserWindow.moveTop()"

This reverts commit e21ace30dc.

* Disable test until #20110 is resolved

* fix lint issue
2019-09-04 19:22:38 -04:00
Eugene
0f27712e8f fix: allow unsandboxed renderers to request new privileges (6-0-x) (#20023) 2019-09-04 14:53:19 -07:00
trop[bot]
b2da0b883d build: add WOA release to list of releases (#20113)
* build: add WOA release to list of releases

* Add job count info for sudowoodo

* Add verification of all assets

* Fix linting and add logic to wait before printing out results
2019-09-04 14:32:50 -07:00
Robo
4662ab9b63 fix: crash with --inspect-brk when running under ELECTRON_RUN_AS_NODE (#20098)
* fix: ensure that the node env is not bootstrapped before running inspector

* fix: ensure we wait for the inspect to disconnect

This re-orders our node clean up so that we free the environment before
the task runner is cleaned up as node uses the task runner during clean
up.  It also calls WaitForDisconnect() to ensure that inspector agents
are notified that the context is going down.

* chore: update spec to catch SIGABRT
2019-09-04 12:45:50 -07:00
Electron Bot
e070bd7bdb chore: bump chromium in DEPS to 76.0.3809.144 (#20108) 2019-09-04 08:24:33 -07:00
trop[bot]
a8ec0de153 Revert "fix: make sure that menu bar gets focus even when you click an item to focus it first (#19710)" (#20035)
This reverts commit 27b2747b61.
2019-09-03 23:19:26 -07:00
Electron Bot
34c6e05a82 chore: bump chromium to 76.0.3809.143 (6-0-x) (#20061)
* chore: bump chromium in DEPS to 76.0.3809.140

* chore: bump chromium in DEPS to 76.0.3809.141

* chore: bump chromium in DEPS to 76.0.3809.142

* chore: bump chromium in DEPS to 76.0.3809.143
2019-09-03 17:01:43 -07:00
trop[bot]
97798a4aad fix: strip chrome_sandbox executable (#20081) 2019-09-03 09:49:07 -07:00
trop[bot]
837948759f fix: honor cursor blink rate (#20046)
* fix: honor cursor blink rate on macOS

* fix: honor cursor blink rate on Linux

* fix: honor cursor blink rate on Windows

* refactor: clean up os_win cursor blink logic

* remove unneeded include
2019-09-03 16:22:25 +09:00
Electron Bot
8b6fa783f4 Bump v6.0.7 2019-08-30 16:48:26 -07:00
trop[bot]
ed7ae42c10 fix: ensure that the "top" coordinate of the inner frame is correct (#20052)
On multi-monitor setups where the monitors are not all origined at 0 on
the Y coordinate (E.g. vertical stacked monitors) the maximize
calculation was incorrect as it assumed top was "0".  This instead
adjusts the math to calculate the correct top value.
2019-08-30 16:44:51 -07:00
Electron Bot
828038d5f6 chore: bump chromium in DEPS to 76.0.3809.139 (#20042) 2019-08-30 15:15:54 -07:00
Electron Bot
f1a914c0ba Bump v6.0.6 2019-08-29 13:38:36 -07:00
Electron Bot
5eff97c890 chore: bump chromium in DEPS to 76.0.3809.138 (#20024) 2019-08-29 08:59:51 -07:00
Charles Kerr
0039e604a2 fix: i18n of gtk msgbox buttons (#20007)
* fix: i18n of gtk msgbox buttons

Manually backport #19904. See that PR for details.

* fix: make linter happy

* fix: make linter happy
2019-08-29 15:54:31 +09:00
Electron Bot
26176eb108 chore: bump chromium in DEPS to 76.0.3809.137 (#20004) 2019-08-28 08:11:47 -07:00
Heilig Benedek
fb82bfa707 fix: handle WM_GETMINMAXINFO instead of letting chromium do it (#19928) (#20001)
* fix: remove WM_GETMINMAXINFO workaround since it's no longer needed

* fix: handle WM_GETMINMAXINFO ourselves

* fix: remove part of the chromium WM_GETMINMAXINFO handler
2019-08-28 09:32:26 -05:00
Electron Bot
9b724dca49 Bump v6.0.5 2019-08-27 11:39:08 -07:00
Shelley Vohr
b52a2aedf1 fix: add default media usage strings to info.plist (#19949) 2019-08-27 11:37:04 -07:00
Electron Bot
8e671dafc1 chore: bump chromium in DEPS to 76.0.3809.136 (#19981) 2019-08-27 08:33:46 -07:00
Richard Townsend
0491abf4cc fix: work around a null scoped_ptr dereference (#19366)
This happens occasionally when running the test suite and indicates
that the callback's been reset or the underlying reference has been
released. To workaround, print a warning.
2019-08-27 10:57:18 -04:00
Jaime Bernardo
1655976841 fix: extern Parse impl for Windows debug builds (#19958)
Applies a patch to node.
Externs node::options_parser::Parse implementation for
node::DebugOptions to fix the Windows Debug build.
2019-08-27 07:53:52 -07:00
trop[bot]
0b5a7379f2 fix: don't call SetBounds on restore (#19956) 2019-08-27 07:51:59 -07:00
trop[bot]
a5ed8fb65e fix: ensure that reloads retain modified window background colors (#19973) 2019-08-27 07:50:39 -07:00
Richard Townsend
bb631892b2 fix: crash reporting on Windows on Arm (#19391)
* feat: cherry-pick V8 unwinding support

This commit backports [1] (originally written by @ThomsonTan) into V8
7.6. With this patch in place, calls made from JS into the atom core
which crash electron.exe will now generate crash dumps on Windows on
Arm rather than silently dying.

[1] https://chromium-review.googlesource.com/c/v8/v8/+/1701133/11

* feat: backport crashpad cpu capture context

Backport of [1] (originally written by @kaadam) to Chromium 76's
crashpad. This lets you see the register values within the crash dump.

[1]
https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1632749

* build: make win on arm patches only apply for win on arm builds

* Update .patches

* Update .patches

* Update DEPS

* fix: update the patch to the as-landed version

* fix: remove accidental revert of crashpad_pid_check.patch
2019-08-27 10:43:27 -04:00
Heilig Benedek
64026ded95 fix: adjust window size in NCCALCSIZE instead of adding insets (#19944) 2019-08-26 10:07:35 -07:00
Electron Bot
e6178f83fe chore: bump chromium to 76.0.3809.135 (6-0-x) (#19935)
* chore: bump chromium in DEPS to 76.0.3809.134

* chore: bump chromium in DEPS to 76.0.3809.135
2019-08-26 12:54:19 -04:00
John Kleinschmidt
ee5403d3ec build: start building Windows on Arm builds (#19910)
* build: start building Windows on Arm builds (#19780)

(cherry picked from commit 4bc7b3b1a4)

* Update manifest to include 6-0-x file
2019-08-26 09:54:32 -04:00
trop[bot]
6b77e2ee14 fix: command-line scheme switch values' spillover (#19940) 2019-08-25 23:03:19 -07:00
Electron Bot
075b085cb4 chore: bump chromium in DEPS to 76.0.3809.133 (#19922) 2019-08-25 00:30:02 -07:00
Electron Bot
cbd017572a Bump v6.0.4 2019-08-23 14:06:09 -07:00
Samuel Attard
3f0c863225 Revert "Bump v6.0.4"
This reverts commit 783614a94c.
2019-08-23 14:04:46 -07:00
trop[bot]
a459cee938 build: use a lower process count for publish builds with no sccache (#19915) 2019-08-23 14:01:55 -07:00
Electron Bot
783614a94c Bump v6.0.4 2019-08-23 12:05:24 -07:00
Cheng Zhao
db1395628a fix: notify views of content view size change (#19888) 2019-08-23 12:02:54 -07:00
Shelley Vohr
5e33a5e778 fix: ensure child_process.fork() doesn't modify main process env (#19845) 2019-08-23 12:01:46 -07:00
Electron Bot
ce502b19ba chore: bump chromium in DEPS to 76.0.3809.131 (#19909) 2019-08-23 12:41:29 -04:00
Samuel Attard
1cfd7160dc fix: remove white screen flicker by disabling compositor recycling (#19900) 2019-08-23 01:14:39 -07:00
Electron Bot
339174dca0 chore: bump chromium in DEPS to 76.0.3809.130 (#19885) 2019-08-22 10:54:35 -07:00
Electron Bot
6964a8cd72 chore: bump chromium in DEPS to 76.0.3809.129 (#19864) 2019-08-21 11:18:27 -07:00
trop[bot]
51a97917e0 build: ninja count should be 2*cores + 2 (#19867) 2019-08-21 08:53:03 -07:00
trop[bot]
3ca1cd4dd4 fix: trim branch name before comparing to master (#19856) 2019-08-20 20:11:52 -07:00
trop[bot]
c2c0ee7a73 docs: update documentation under tutorials (#19843) 2019-08-20 11:08:51 -07:00
Electron Bot
739f620152 chore: bump chromium in DEPS to 76.0.3809.128 (#19840) 2019-08-20 08:28:04 -07:00
Electron Bot
fb379c3b6a Bump v6.0.3 2019-08-19 14:23:16 -07:00
Electron Bot
237688abb3 chore: bump chromium to 76.0.3809.126 (6-0-x) (#19791)
* chore: bump chromium in DEPS to 76.0.3809.123

* chore: bump chromium in DEPS to 76.0.3809.124

* chore: bump chromium in DEPS to 76.0.3809.125

* chore: bump chromium in DEPS to 76.0.3809.126
2019-08-19 14:20:15 -07:00
Shelley Vohr
94070cec53 ci: upgrades-wg owns DEPS (#19834) 2019-08-19 14:12:33 -07:00
Pedro Pontes
e8ef52bc1d fix: always use new site instance for a new navigation (backport). (#19826) 2019-08-19 13:20:22 -07:00
Micha Hanselmann
2f9876a3f9 docs: add exemplary fiddle for launch in fiddle feat (#19759) (#19786)
* add fit-screen

* new url format

* nit
2019-08-19 13:10:29 -07:00
Samuel Attard
5ca94a8715 fix: disable LayoutNG to prevent random crashes in selection calcuations (#19808)
* fix: disable LayoutNG to prevent random crashes in selection calcuations

* Update atom_browser_main_parts.cc
2019-08-16 17:01:29 -07:00
trop[bot]
ffd1d6d8ad docs: add missing return desc (#19799) 2019-08-16 13:26:19 -07:00
trop[bot]
33c86527e8 MessageBoxOptions.icon should allow string (#19798) 2019-08-16 13:25:41 -07:00
Charles Kerr
871f123080 fix: i18n gtk dialog buttons (#19760)
manual backport of https://github.com/electron/electron/pull/19756
2019-08-16 08:57:54 -07:00
trop[bot]
3dcf66839e fix: make sure that menu bar gets focus even when you click an item to focus it first (#19764) 2019-08-15 10:30:05 -07:00
Electron Bot
78a2237add chore: bump chromium in DEPS to 76.0.3809.120 (#19774) 2019-08-15 10:03:19 -07:00
Richard Townsend
be68c062d7 chore: update the compiler again (#19383)
This WoA-specific change updates the compiler to one that produces
CodeView debug symbols, which means that Visual Studio can display the
values of variables whilst debugging.
2019-08-15 10:08:37 -04:00
Erick Zhao
dbf8872817 fix: normalize behavior of win.setOpacity() for invalid number values across operating systems (#19723)
* fix: normalize behavior of `win.setOpacity()` for invalid number values across operating systems

* expect -> assert

* assert 2

* fix `this` scoping

* fix equality

* tests
2019-08-14 18:10:06 -07:00
Electron Bot
a50e3b3f5f chore: bump chromium in DEPS to 76.0.3809.119 (#19754) 2019-08-14 18:01:18 -07:00
Cheng Zhao
063bcb68f2 chore: revert activation if the uv_loop on incoming IPC messages (#19739)
This reverts commit c0e9761b4b.
2019-08-14 07:55:39 -07:00
Electron Bot
364e8b1a1d chore: bump chromium to 76.0.3809.118 (6-0-x) (#19696)
* chore: bump chromium in DEPS to 76.0.3809.113

* chore: bump chromium in DEPS to 76.0.3809.114

* chore: bump chromium in DEPS to 76.0.3809.115

* chore: bump chromium in DEPS to 76.0.3809.116

* chore: bump chromium in DEPS to 76.0.3809.118
2019-08-13 20:23:28 -07:00
trop[bot]
779f285777 fix: avoid losing focus on inputs when opening menu (Windows/Linux) (#19708)
* remove cause of issue

* remove comment
2019-08-12 20:58:10 -07:00
Electron Bot
4e1a5a210a Bump v6.0.2 2019-08-12 12:53:48 -07:00
Cheng Zhao
98d78f2fb5 fix: don't handle browser messages before document element is created (6-0-x) (#19719)
* fix: don't handle browser messages before document element is created

* fix: bind ElectronApiServiceImpl later

DidCreateDocumentElement is called before the ElectronApiServiceImpl
gets bound.

* chore: add comment
2019-08-12 10:45:36 -07:00
Shelley Vohr
a8e70a8546 docs: update hasShadow for win and linux (#19675) (#19692) 2019-08-12 09:46:02 -07:00
Micha Hanselmann
1ca76e8e74 fix: return correct bounds on will-resize (#19639) (#19704) 2019-08-09 14:51:09 -07:00
Electron Bot
16757d16e7 chore: bump chromium to 76.0.3809.110 (6-0-x) (#19684)
* chore: bump chromium in DEPS to 76.0.3809.110

* Update patches
2019-08-08 13:50:24 -07:00
Shelley Vohr
d2b2b97c29 fix: crash on window.print() (#19677) 2019-08-08 07:52:06 -07:00
Electron Bot
6bc7bc11d8 chore: bump chromium in DEPS to 76.0.3809.108 (#19665) 2019-08-07 13:24:24 -04:00
Electron Bot
f3d4daa9e5 Bump v6.0.1 2019-08-06 14:10:50 -07:00
Erick Zhao
6c0157aa29 fix: handle edge behavior for about panel on Linux (#19635) 2019-08-06 12:45:16 -07:00
Electron Bot
a9e0aa22a4 chore: bump chromium in DEPS to 76.0.3809.102 (#19649) 2019-08-06 11:53:41 -07:00
trop[bot]
56160e990e fix: clearRecentDocuments role on Windows (#19637)
* fix: clear recent documents on windows

* chore: don't check for version < win 7
2019-08-05 20:56:23 -07:00
trop[bot]
ab83309c7a fix: make child windows not crash when ipc messages are received (#19633)
* fix: make child windows not crash when ipc messages are received

This also adds a path forward for apps using child windows with
nodeIntegration to migrate into a non-leaky way of doing it.

1. Ensure that if ipcNative is missing we don't crash rather log that it
is missing
2. Add a hidden option `--enable-node-leakage-in-renderers` (temporary
measure) to allow app devs to opt in to leaking node in child windows
3. Bypasses the Opener() check if renderer process reuse is enabled
(which would prevent the leak anyway)

So the path forward is: it no longer crashes --> folks use the hidden
option --> folks opt in to renderer process reuse.

* Apply suggestions from code review

Co-Authored-By: Jeremy Apthorp <jeremya@chromium.org>

* Update shell/renderer/atom_renderer_client.cc

Co-Authored-By: Jeremy Apthorp <jeremya@chromium.org>
2019-08-05 15:10:52 -07:00
Electron Bot
c474ff101c chore: bump chromium to 76.0.3809.98 (6-0-x) (#19593)
* chore: bump chromium in DEPS to 76.0.3809.95

* chore: bump chromium in DEPS to 76.0.3809.96

* chore: bump chromium in DEPS to 76.0.3809.97

* chore: bump chromium in DEPS to 76.0.3809.98
2019-08-05 12:55:34 -04:00
trop[bot]
54902e848f fix zoom button when alwaysOnTop set (#19351) 2019-08-05 09:06:23 -07:00
Shelley Vohr
7bec7e6cee doc: add missing MenuItem roles (#19329) (#19573) 2019-08-01 14:05:32 -07:00
Shelley Vohr
55224e385e fix: set size of GTK about panel icon (#18957) (#19572) 2019-08-01 14:04:02 -07:00
Shelley Vohr
75fecf4e4f fix: throw on invalid webRequest filters (#19337) (#19570)
Closes #11371.

Previously, we didn't consider the return value of the webRequest URLPattern mate converter, which meant that when the pattern wasn't correctly parsed owing to invalid filter specification users would not be made aware of that fact and would just think that the filtering itself had failed. This corrects that error by moving the business logic of url pattern parsing out of the converter and into the function itself so that granular and specific errors can be thrown.

There's also no real reason that i'm aware of not to allow wider breadth of filters by letting users use a wildcard for effective TLD, so I also overrode that (default for the 1-arg Parse is not to allow that).

Finally, I added some examples of url filter types for users to reference.
2019-08-01 14:03:27 -07:00
Micha Hanselmann
f2f483fedb test: add test for invalid cookie url (#19568) 2019-08-01 14:02:41 -07:00
Micha Hanselmann
5614ae4241 fix: make process.uptime() return the correct time (#19567) 2019-08-01 14:02:24 -07:00
Electron Bot
55abf1f3a1 chore: bump chromium in DEPS to 76.0.3809.94 (#19564) 2019-08-01 12:17:38 -04:00
John Kleinschmidt
0f78f8a66c fix: use WeakPtr to detect deletion (#19560)
(cherry picked from commit 77c24d8b66)
2019-08-01 08:05:45 -07:00
Shelley Vohr
fa4a26a1db fix: throw better error on getPath('logs') (#19514) (#19545) 2019-07-31 15:52:47 -07:00
trop[bot]
7ba29f1fa8 fix: set default dock bounce type (#19546) 2019-07-31 09:42:07 -07:00
Electron Bot
2f148fdaf4 chore: bump chromium in DEPS to 76.0.3809.91 (#19540) 2019-07-31 12:11:11 -04:00
Erick Zhao
19c31c684a docs: update badges (#18955) (#19537) 2019-07-31 08:07:04 -04:00
Electron Bot
c61a20c390 chore: bump chromium in DEPS to 76.0.3809.90 (#19531) 2019-07-30 13:24:55 -07:00
trop[bot]
4ae3031faf fix: remove TLS destruction (#19428)
Building with dchecks_always_on=true in release configuration seems to
introduce flakiness because the TLS is double-freed. Amending the check
seems to fix the flakiness.
2019-07-30 13:12:13 -07:00
Shelley Vohr
72fee2ed78 fix: correctly emit BrowserWindow alwaysOnTop status (#19534) 2019-07-30 11:24:35 -07:00
trop[bot]
cba1a946d5 fix: tray.displayBalloon() does not work with custom icon on Windows (#19528) 2019-07-30 09:22:10 -07:00
trop[bot]
c55bc8106f chore: omit superceded Chromium updates from notes (#19406)
* feat: omit superceded Chromium updates from notes

* chore: simplify changed code
2019-07-29 19:42:06 -07:00
Micha Hanselmann
261f7fd3be i really wanna do this (#19517) 2019-07-29 16:57:14 -07:00
trop[bot]
53894d5ac2 add desc (#19508) 2019-07-29 14:51:36 -07:00
trop[bot]
c006a6db66 fix: clearing of the backgroundColor property on TouchBarButton (#19471) 2019-07-29 14:51:13 -07:00
trop[bot]
a306fdf512 fix: emit swipe event on macOS (#19354) 2019-07-29 14:50:03 -07:00
Electron Bot
825bd6d45e Bump v6.0.0 2019-07-29 11:15:07 -07:00
Milan Burda
922a4d9ba6 fix: refactoring regression in LocationProxy (#19494) 2019-07-29 11:13:00 -07:00
Electron Bot
f20d497f1c chore: bump chromium to 76.0.3809.88 (6-0-x) (#19487)
* chore: bump chromium in DEPS to 76.0.3809.85

* chore: bump chromium in DEPS to 76.0.3809.87

* chore: bump chromium in DEPS to 76.0.3809.88
2019-07-29 10:09:43 -07:00
trop[bot]
855bd92f6e fix: use GetAuraColor to get theme dependant menu bg color (#19505) 2019-07-29 12:52:57 -04:00
trop[bot]
60d36e1b74 fix: remove .pdb from symbol file names (#19504)
* fix: remove .pdb from symbol file names

* Update dump_syms.py
2019-07-29 09:36:48 -07:00
Electron Bot
9788089efb chore: bump chromium to 76.0.3809.83 (6-0-x) (#19450)
* chore: bump chromium in DEPS to 76.0.3809.82

* chore: bump chromium in DEPS to 76.0.3809.83
2019-07-26 16:12:41 -07:00
trop[bot]
c0e9761b4b fix: activate the uv_loop on incoming IPC messages (#19467)
* fix: activate the uv_loop on incoming IPC messages

* chore: guess at a fix for process not being defined
2019-07-26 15:28:49 -07:00
trop[bot]
7e6617be18 spec: don't run codesigning spec on forks (#19433) 2019-07-26 09:33:31 -04:00
John Kleinschmidt
38b6a7bf4f build: unify YARN_VERSION variable usage and ensure CI uses yarn not npm (#19404)
* ci: Use yarn instead of npm for lint

* build: unify YARN_VERSION variable usage and ensure CI uses yarn not npm (#18607)

* build: unify YARN_VERSION variable usage and ensure CI uses yarn not npm

* chore: use a JS helper so that it can work on windows

* chore: make script/yarn without node_modules installed

(cherry picked from commit a45afddb75)
2019-07-24 14:00:43 -04:00
Electron Bot
0aec64960b chore: bump chromium to 76.0.3809.80 (6-0-x) (#19381)
* chore: bump chromium in DEPS to 76.0.3809.78

* chore: update patches

* [Mac] Create a new helper process variant for the GPU.

https://chromium-review.googlesource.com/c/chromium/src/+/1709936

* chore: bump chromium in DEPS to 76.0.3809.80
2019-07-24 10:49:37 -07:00
Electron Bot
eab462f7cf chore: bump chromium to 76.0.3809.77 (6-0-x) (#19357)
* chore: bump chromium in DEPS to 76.0.3809.75

* chore: bump chromium in DEPS to 76.0.3809.76

* chore: bump chromium in DEPS to 76.0.3809.77
2019-07-22 13:09:29 -07:00
Electron Bot
5ccdb8c7cd Bump v6.0.0-beta.15 2019-07-19 13:42:43 -07:00
Electron Bot
dc38746b24 chore: bump chromium in DEPS to 76.0.3809.74 (#19343) 2019-07-19 13:41:16 -07:00
Electron Bot
66c2bd2a02 chore: bump chromium to 76.0.3809.73 (6-0-x) (#19324)
* chore: bump chromium in DEPS to 76.0.3809.73

* build: handle new helper apps for renderer and plugin bundles

* build: update symbol generation logic for all helpers
2019-07-18 21:43:56 -07:00
Samuel Attard
cbfd276917 fix: bootstrap the node environment after we setup the InspectorAgent (#19317) (#19332) 2019-07-18 18:12:28 -07:00
Micha Hanselmann
450a83d0f7 refactor: use NativeTheme dark mode detection on macOS 10.14+ (#19309) 2019-07-17 14:32:11 -07:00
Electron Bot
b7408e61d2 chore: bump chromium in DEPS to 76.0.3809.70 (#19304) 2019-07-17 08:21:23 -07:00
Electron Bot
9d333a72e1 Bump v6.0.0-beta.14 2019-07-17 08:19:14 -07:00
Milan Burda
c5f4fe09aa fix: don't execute preload scripts for internal <iframe> in <webview> (#19260) (#19298) 2019-07-17 08:17:57 -07:00
Samuel Attard
38f2d11c39 feat: update to node 12.4 (#19270) (#19281)
* feat: update to node 12.4 (#19270)

This points our node repo at upstream (nodejs/node) and uses the base node tag as the target ref.  We then use our existing patch system and patch files to apply our changes on top of node.  This unifies how we patch upstream repos and makes our node patches easier to reason, view, understand and most importantly reduce.

This also upgrades Electron 6 to Node 12.4

Notes: Upgraded to Node 12.4

* chore: cherry pick changes required for node 12.4 from #18924
2019-07-16 12:46:12 -07:00
Electron Bot
3c852e79e6 chore: bump chromium in DEPS to 76.0.3809.68 (#19278) 2019-07-16 07:54:42 -07:00
trop[bot]
019e60517f fix: serialize messages being sent over chrome message ports (#19252)
Chrome appears to serialize these messages (see #19070) so we should as
well to be consistent and to avoid bugs with Uint8/16 arrays

Fixes #19070
2019-07-15 22:15:31 -07:00
trop[bot]
fb51509153 fix: <webview> not working in scriptable popups (#19218) 2019-07-16 11:40:51 +09:00
Electron Bot
f3b9f58b7f chore: bump chromium to 76.0.3809.67 (6-0-x) (#19225)
* chore: bump chromium in DEPS to 76.0.3809.64

* chore: bump chromium in DEPS to 76.0.3809.65

* chore: bump chromium in DEPS to 76.0.3809.66

* chore: bump chromium in DEPS to 76.0.3809.67
2019-07-15 14:39:48 -07:00
trop[bot]
a49307bc55 fix: exit non-silently when running as root on Linux (#19255)
* check for sandbox param on root

* add IsSandboxEnabled
2019-07-15 14:26:56 -05:00
Cheng Zhao
742292f082 fix: do not wait on promise returned by remote APIs (6-0-x) (#19190)
* fix: make <webview>.loadURL async

* docs: webview.loadURL returns Promise
2019-07-15 13:15:17 -05:00
trop[bot]
bb0f4fdbdf fix: add support for prefers-color-scheme CSS query (#19250)
The wiring to update prefs when you toggle between dark mode and light mode exists in the content layer but the actual value setting is done in either //chrome or in shell.  We need to set the preferred_color_scheme pref value in order for the CSS query to work correctly.  The DarkModeObserver in content will automatically regenerate prefs when dark mode is toggled.

Fixes #15540
2019-07-15 07:58:51 -07:00
trop[bot]
5e2ca967c9 chore: revert key -> main change in window delegate listener (#19221)
* chore: revert key -> main

* chore: comment out test that will fail

* more context on commented out test

* remove commented test
2019-07-14 10:55:36 +09:00
trop[bot]
c8029d1696 docs: specify possible values for ProcessMetric.type (#19224) 2019-07-12 17:46:41 -05:00
Electron Bot
08aa86e55e chore: bump chromium to 76.0.3809.63 (6-0-x) (#19195)
* chore: bump chromium in DEPS to 76.0.3809.62

* chore: bump chromium in DEPS to 76.0.3809.63
2019-07-11 14:05:13 -05:00
Micha Hanselmann
825c082535 chore: deprecate setHighlightMode (#19211) 2019-07-11 13:48:39 -05:00
Micha Hanselmann
4a073e4f7e refactor: improve function deprecation module (#19012) (#19199)
* add removeFunction to deprecation module

* clarify deprecate api

* throw error

* change error msg
2019-07-11 17:10:52 +09:00
Electron Bot
adffa99e05 Bump v6.0.0-beta.13 2019-07-10 11:04:56 -07:00
Alexandre Lacheze
51f03033a4 docs: precise that node integration is enabled in natively opened window if nodeIntegrationInSubFrames is true (#19142) 2019-07-10 10:37:28 -05:00
trop[bot]
733251866c fix: use binding.ipc instead of binding.sendTo which is undefined (#19106) 2019-07-10 10:35:55 -05:00
trop[bot]
41a7d9e42b ci: do not use the MOCHA_FILE env variable (#19180)
It is not used in a expected way anyway.
2019-07-10 10:35:35 -05:00
trop[bot]
ddbbf34433 remove non-existent event (#19169) 2019-07-10 10:34:27 -05:00
Milan Burda
6f65dec6a2 ci: add check for dist zip file changes (#19172) 2019-07-09 16:01:16 -05:00
Electron Bot
a66657112c chore: bump chromium in DEPS to 76.0.3809.60 (#19165) 2019-07-09 12:54:07 -07:00
Jeremy Apthorp
f5c3394930 fix: dump correct breakpad symbols on macOS (#19155) 2019-07-09 09:47:11 +09:00
Electron Bot
84bae64def chore: bump chromium to 76.0.3809.59 (6-0-x) (#19134) 2019-07-08 16:03:40 -07:00
Milan Burda
4185b93abb Revert "feat: only allow bundled preload scripts (#17308)" (#19132)
This reverts commit 8cf15cc931.
2019-07-08 11:33:54 +09:00
trop[bot]
b1e9f50fad fix: check parent-child relationship in canAccessWindow (#19118) 2019-07-05 11:20:08 -07:00
Electron Bot
6bd901d9ca chore: bump chromium to 76.0.3809.56 (6-0-x) (#19111)
* chore: bump chromium in DEPS to 76.0.3809.55

* chore: bump chromium in DEPS to 76.0.3809.56
2019-07-05 11:13:16 -07:00
trop[bot]
1c2b8f8d9a fix: handle no env in externsion world set up (#19105)
Previously when GetEnvironment returned null this extension setup
crashed.
2019-07-03 16:36:30 -07:00
Electron Bot
cb9b288d8b Bump v6.0.0-beta.12 2019-07-03 14:08:45 -07:00
Shelley Vohr
69fe33a2b1 Revert "Bump v6.0.0-beta.12"
This reverts commit 8a285f29ed.
2019-07-03 14:06:12 -07:00
Electron Bot
52b42546ed chore: bump chromium in DEPS to 76.0.3809.54 (#19095) 2019-07-03 08:36:42 -07:00
Electron Bot
8a285f29ed Bump v6.0.0-beta.12 2019-07-02 11:25:31 -07:00
Shelley Vohr
92df6cc36c fix: only check darkMode effectiveAppearance in 10.15 (#19013) 2019-07-02 11:04:30 -07:00
Electron Bot
ab91656148 chore: bump chromium in DEPS to 76.0.3809.52 (#19079) 2019-07-02 10:44:16 -07:00
Electron Bot
1fb1e5b2b2 Revert "Bump v6.0.0-beta.12"
This reverts commit 54908b56e5.
2019-07-02 10:17:31 -07:00
Electron Bot
54908b56e5 Bump v6.0.0-beta.12 2019-07-02 10:11:38 -07:00
Shelley Vohr
48bc247ef7 fix: silent printing mode (#19037) 2019-07-02 10:03:00 -07:00
trop[bot]
19d9955125 fix: Correct modal focus behavior on macOS (#19062)
* wip: wish i could hack the main window focus away

* main -> key

* remove useless code

* test: Add focus event spec

* test: more robust spec

* test: simplify test

* duplicate non-firing macOS event listener 😳

* destroy 🚨
2019-07-01 16:39:45 -07:00
Electron Bot
24d79d9e5c chore: bump chromium in DEPS to 76.0.3809.51 (#19057) 2019-07-01 12:14:15 -07:00
Electron Bot
27d0a4d33d chore: bump chromium in DEPS to 76.0.3809.50 (#19054) 2019-06-30 21:38:51 -07:00
Electron Bot
48226f71ad chore: bump chromium to 76.0.3809.49 (6-0-x) (#19030)
* chore: bump chromium in DEPS to 76.0.3809.48

* chore: bump chromium in DEPS to 76.0.3809.49
2019-06-29 18:46:41 -07:00
Shelley Vohr
a4acc16e10 fix: make tray not block main process (#18880) (#18969)
* fix: make tray not block main process

* make AtomMenuModel refcounted
2019-06-28 14:10:45 -05:00
trop[bot]
d8dd94e3a3 fix: delay emitting screen events by a tick to avoid re-entrancy crash (#19022) 2019-06-28 16:23:19 +09:00
Electron Bot
eb48dcf0a3 chore: bump chromium in DEPS to 76.0.3809.47 (#19010) 2019-06-27 16:34:00 -07:00
Samuel Attard
adfe537e32 docs: fix heading level for power-monitor docs (#19015) 2019-06-27 13:21:09 -07:00
Electron Bot
0d5d54cbae chore: bump chromium in DEPS to 76.0.3809.45 (#18991) 2019-06-26 08:47:25 -07:00
Electron Bot
988ad92415 chore: bump chromium in DEPS to 76.0.3809.43 (#18974) 2019-06-25 23:57:02 -07:00
Electron Bot
5dbcdbc3d8 Bump v6.0.0-beta.11 2019-06-25 14:13:13 -07:00
trop[bot]
212c6b1266 fix: override the timers module impls to activate the uv loop (#18961) 2019-06-24 14:22:57 -07:00
trop[bot]
74b06ab677 fix: make isDarkMode correctly detect dark mode in the auto setting on catalina (#18958) 2019-06-24 13:27:35 -07:00
Electron Bot
9a1c952ab6 chore: bump chromium to 76.0.3809.42 (6-0-x) (#18919)
* chore: bump chromium in DEPS to 76.0.3809.38

* chore: bump chromium in DEPS to 76.0.3809.39

* chore: bump chromium in DEPS to 76.0.3809.40

* chore: bump chromium in DEPS to 76.0.3809.42
2019-06-24 15:15:27 -04:00
Electron Bot
f36f90b60f Bump v6.0.0-beta.10 2019-06-21 15:05:57 -07:00
Micha Hanselmann
a603a4dde8 fix: sanitize invalid custom protocol headers (#18927)
* fix: sanitize invalid custom protocol headers (#18854)

* lint fix
2019-06-21 15:00:05 -07:00
trop[bot]
3e033b4f27 chore: account for remotes in branch parsing (#18931) 2019-06-21 14:03:40 -07:00
trop[bot]
03be4c67d5 fix: delay handling occlusion events to avoid flicker on macOS (#18885)
* chore: add debounce on the updateWebContentsVisibility method to ensure quick changes in occlusion do not result in flickering

* chore: update old patch headers

* chore: update patches for E6 without host refactor
2019-06-21 09:20:08 -07:00
John Kleinschmidt
b20fe76db7 chore: use manual invocation of npx yarn (#18902)
* chore: Revert "build: use yarn to install arm modules (#18802)"

This reverts commit 97bec607fe.
script/yarn.js doesn't exist in 5-0-x or 6-0-x

* chore: use manual invocation of npx yarn
2019-06-21 08:57:05 -07:00
trop[bot]
503da640f7 fix: app.getAppPath() returning default-app path for files or directories without package.json (#18888) 2019-06-21 08:54:21 -07:00
trop[bot]
bd48dfe3cc chore: fix branch trimming for blast-off releases (#18909) 2019-06-21 01:02:54 -07:00
Jeremy Apthorp
9b47f587a6 fix: bundle swiftshader and ANGLE libraries on mac (#18904) 2019-06-20 11:12:02 -07:00
trop[bot]
3a186dad5d refactor: session.{clearCache,getCacheSize} nws13n (#18897) 2019-06-20 10:11:13 -07:00
Electron Bot
7959f2e887 chore: bump chromium to 76.0.3809.37 (6-0-x) (#18828)
* chore: bump chromium in DEPS to 76.0.3809.32

* chore: bump chromium in DEPS to 76.0.3809.33

* chore: update patches

* chore: bump chromium in DEPS to 76.0.3809.37

* chore: fix render_view_host_view_base.patch
2019-06-20 09:58:56 -07:00
trop[bot]
4868c95425 fix: building with enable_run_as_node disabled (#18892) 2019-06-19 23:48:04 -07:00
Samuel Attard
7fa41e3302 chore: roll node to fix http2 memory leak (#18882) 2019-06-19 12:33:05 -07:00
Electron Bot
f3346437be Bump v6.0.0-beta.9 2019-06-18 13:21:18 -07:00
Shelley Vohr
6de6d7f6c0 docs: add example on handling the webPrefs change (#18856)
* docs: add example on handling the webPrefs change

Fixes #17967

* Update breaking-changes.md
2019-06-18 10:35:27 -07:00
Shelley Vohr
eb15be06e3 fix: use is_valid for cookie url validation (#18770) (#18843)
Use is_valid instead of is_empty to validate url on cookies.set().
2019-06-18 09:53:10 -07:00
trop[bot]
7748decc60 chore: fix current branch fetch on master (#18862) 2019-06-18 08:34:50 -07:00
Shelley Vohr
d75750ab01 fix: use effectiveAppearance to check dark mode on mojave and above (#18666) (#18845)
* fix: use effectiveAppearance to check dark mode on mojave and above

* chore: add forward declarations for dark appearance
2019-06-17 15:54:31 -07:00
Shelley Vohr
152781226e fix: callback values for printing cancellation and success (#18803) 2019-06-17 11:33:30 -07:00
trop[bot]
7e3bbb6ace build: get current release branch from commit (#18833)
* chore: get current release branch from commit

* love too lint
2019-06-17 07:54:17 -07:00
Shelley Vohr
3c3eb2f65d docs: better explain supported release line levels (#18800) (#18838) 2019-06-17 07:53:24 -07:00
trop[bot]
5a83d9e64d feat: provide the frame URL with permission requests and checks (#18772)
* feat: provide the frame URL with permission requests and checks

Also provides a handy isMainFrame property to determine if it is an
iframe making the request

* chore: refactor to use base::Value

* chore: use Set<Type>Key over SetPath

* chore: fix lint
2019-06-15 16:26:21 +09:00
trop[bot]
97bec607fe build: use yarn to install arm modules (#18802) 2019-06-15 16:16:13 +09:00
trop[bot]
b56ca98b72 docs: add specific options for MenuItem.role (#18807) 2019-06-14 23:29:34 -07:00
Electron Bot
eeccdc2d5c Bump v6.0.0-beta.8 2019-06-14 09:22:25 -07:00
Milan Burda
47827ed45c fix: crash in BrowserWindow destructor after win.webContents.destroy() (#18686) (#18793) 2019-06-14 09:18:38 -07:00
Cheng Zhao
d3f7bdd0b3 fix: use crashpad on Windows (#18483) (#18766) 2019-06-13 18:51:56 -07:00
trop[bot]
438c50bf14 docs: fully document MenuItem instance properties (#18784)
* document menuItem instance properties

* correct some types

* add correct click documentation
2019-06-13 18:45:05 -07:00
trop[bot]
33d860bcea fix: reject the executeJavaScript promise when it fails to execute the script (#18714)
* fix: reject the executeJavaScript promise when it fails to execute the script

Closes #9102

* Update atom/renderer/api/atom_api_web_frame.cc

Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net>

* Update atom/renderer/api/atom_api_web_frame.cc

Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net>

* fix: missing semicolon
2019-06-13 16:13:06 -07:00
trop[bot]
2401a2afe9 fix: HTML fullscreen request for sub frames (#18775)
Don't re-enter fullscreen if there is a pending operation,
for subframe fullscreen request `EnterFullScreenModeForTab`
will be called for both the frame in question as well as
the outer webContents hosting it.
2019-06-13 15:23:43 -07:00
Electron Bot
852f0be0b2 chore: bump chromium in DEPS to 76.0.3809.26 (#18768) 2019-06-13 13:47:13 -07:00
Samuel Attard
18ec438eaf feat: Add option to conditionally disable site instance patches (#18554)
* feat: Add option to conditionally disable site instance patches (#18396)

* chore: allow conditional disable of the site instance override patches at runtime

* feat: add app.allowRendererProcessReuse property to allow runtime disable of site instance overrides

spec: add tests for the new allowRendererProcessReuse property

feat: add console warnings / errors for loading non context-aware native modules
  * Only error if the patch is disabled
  * Warn all the time, this will ship in Electron 7

* chore: do not warn in about context aware in v6

* chore: update patches
2019-06-13 10:23:02 -07:00
trop[bot]
f7042c8d1b fix: correct isDownloadable docs to match impl (#18747) 2019-06-12 14:16:50 -07:00
Electron Bot
bc73f93e6c chore: bump chromium in DEPS to 76.0.3809.23 (#18742) 2019-06-12 13:21:35 -07:00
trop[bot]
7091508678 fix: remove lingering data when notifications autodismiss on Windows 7 (#18740) 2019-06-12 21:43:30 +09:00
Alexandre Lacheze
6d9d66b88a fix: lost window.opener after cross-origin navigation (#18624)
* SiteInstance::CreateRelatedSiteInstance and use it

* Introduce and use a NetworkSandbox and introduce a test for window.opener on x-site navigation
2019-06-11 14:34:52 -07:00
Electron Bot
fc35b0f1be Bump v6.0.0-beta.7 2019-06-11 12:59:05 -07:00
Electron Bot
17f86b1223 chore: bump chromium in DEPS to 76.0.3809.22 (#18730) 2019-06-11 10:25:24 -07:00
Samuel Attard
271531f5ff fix: modify new promise object for dialog methods to match old callback api (#18724)
This was an unexpected and undocumented breaking change, the deprecated
callback method should have the same signature it used to have.
2019-06-11 10:24:36 -07:00
Jeremy Spiegel
9ef83cd8a0 fix: properly pass openExternal activate option (#18722)
A reference to an OpenExternalOptions structure was being captured by an Objective-C block that
outlived the object that was being referenced.
2019-06-11 10:23:48 -07:00
trop[bot]
f33517dfa7 chore: fix logging to stderr (#18717) 2019-06-10 15:34:18 -07:00
Electron Bot
c69f5d9366 chore: bump chromium to 76.0.3809.20 (6-0-x) (#18684) 2019-06-10 11:42:32 -07:00
Milan Burda
7902c3ced4 fix: set nativeWindowOpen when sandboxed (#18273) (#18556) 2019-06-07 19:08:16 -07:00
trop[bot]
21f033474d fix: use isEqual instead of pointer equality to convert NSAppearance (#18690) 2019-06-07 11:32:25 -07:00
Electron Bot
549ac1ed48 chore: bump chromium in DEPS to 76.0.3809.13 (#18669) 2019-06-06 12:57:19 -07:00
Electron Bot
2dd8d1f150 chore: bump chromium in DEPS to 76.0.3809.12 (#18662) 2019-06-05 19:33:58 -07:00
Electron Bot
26ee461c32 chore: bump chromium in DEPS to 76.0.3809.10 (#18647) 2019-06-05 15:40:41 -07:00
trop[bot]
9905a4c328 ci: fix issues downloading from CircleCI (#18654)
Make sure we pass along token to download from CircleCI
Also, add back off period for retries on downloads.
2019-06-05 10:54:58 -07:00
Richard Townsend
09a22143d6 build: bring in a later compiler for Windows on Arm (#18625)
* build: allow pulling in a later version of Clang

Due to a code-generation defect related to virtual method thunks in the
official compiler used for Chromium M76, it's necessary to build for WoA
with a later version of Clang. When running gclient sync, setting
ELECTRON_BUILD_WOA=1 in the environment will download a corrected
compiler which doesn't have this defect.

* docs: add a note about building for Windows on Arm
2019-06-05 11:18:44 -04:00
Electron Bot
81e8f5c6c2 chore: bump chromium to 76.0.3809.6 (6-0-x) (#18573)
* chore: bump chromium in DEPS to 76.0.3809.4

* chore: bump chromium in DEPS to 76.0.3809.5

* chore: bump chromium in DEPS to 76.0.3809.6
2019-06-04 15:52:34 -07:00
Electron Bot
3c322b7349 Bump v6.0.0-beta.6 2019-06-04 14:52:22 -07:00
Milan Burda
b2ea1bc517 fix: don't export private V8 symbols that can cause native node modules to crash (#18281) (#18619) 2019-06-04 10:09:07 -05:00
trop[bot]
16250493b8 build: move Windows release builds to AppVeyor cloud (#18603)
* build: move Windows release builds to AppVeyor cloud

* Use new env variable for AppVeyor cloud server
2019-06-04 10:30:31 -04:00
trop[bot]
08887e016c doc: change pyobjc link in macos build instruction (#18616) 2019-06-03 22:03:06 -07:00
trop[bot]
aadcce0907 docs: Fix incorrect dialog docs (#18606)
* docs: Fix incorrect dialog docs

We had multiple definitions for `showSaveDialog`.

* docs: Update, take two
2019-06-03 15:04:26 -07:00
trop[bot]
9b5353309d build: strip swiftshader binaries (#18600) 2019-06-03 14:32:18 -07:00
trop[bot]
76303502a6 build: install python-dbusmock via pip for a Docker container (#18597)
* build: use python-dbusmock v0.18.1 on Linux

To prevent timeout errors with some other python-dbusmock versions.

* Don't use a fixed version of python-dbusmock

Co-Authored-By: John Kleinschmidt <jkleinsc@github.com>
2019-06-03 17:20:55 -04:00
Milan Burda
cf07904338 build: remove Vulkan mock ICD (#18596) 2019-06-03 17:18:33 -04:00
trop[bot]
8f1e28b59c fix: don't package mojom{,-lite}.js files in dist.zip (#18486) 2019-06-03 11:44:30 -07:00
Electron Bot
10d0268070 chore: bump chromium to 76.0.3809.3 (6-0-x) (#18504)
* chore: bump chromium in DEPS to 76.0.3807.2

* chore: update patches

* fix: Don't leak system network context when nw service is disabled

https://chromium-review.googlesource.com/c/chromium/src/+/1632494
NetworkService is now deleted by using SequnceLocalStorageSlot
on the IO thread when the service is disabled, which expects
all associated NetworkContexts on that sequence to be destroyed.

* chore: bump chromium in DEPS to 76.0.3808.1

* fix: Destroy all network contexts before primary network context

* chore: update patches

* Simplify out-of-process service registration

https://chromium-review.googlesource.com/c/chromium/src/+/1615882

* [ThreadPool] Rename base::ThreadPool to base::ThreadPoolInstance

https://chromium-review.googlesource.com/c/chromium/src/+/1634851

* fix: -Winconsistent-missing-override warnings

* chore: bump chromium in DEPS to 76.0.3809.1

* chore: update patches

* Change CreateBrowserMainParts to return unique_ptrs

https://chromium-review.googlesource.com/c/chromium/src/+/1632532

* chore: bump chromium in DEPS to 76.0.3809.3
2019-06-01 13:19:00 -04:00
trop[bot]
7871e18232 fix: handle gzipped chrome WebUI resources (#18552)
Fixes: #18503
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1576232

For whatever reason Chromium made this change and then made the default
//content behavior to return false for all IsDataResourceGzipped
requests.  This PR updates our ContentClient impl to return the correct
values.

Notes: Fixed issues where some `chrome://*` URLs would not render
correctly
2019-05-31 15:47:42 -07:00
trop[bot]
ceb3792f3c fix: contractions handling in spellchecker (#18538) 2019-05-31 10:52:18 -07:00
trop[bot]
65a4bdd87a ci: add retries to downloads for arm testing (#18535) 2019-05-30 21:08:44 -07:00
trop[bot]
7094870a44 docs: specify use case for the 'services' role (#18528)
* docs: specify use case for the 'services' role

* update based on @caesar's recommendation

Co-Authored-By: Caesar Schinas <caesar@caesarschinas.com>
2019-05-30 15:15:16 -07:00
trop[bot]
cee99b5f2d fix: reverse dialog cancel bool for openDialog (#18509) 2019-05-30 15:32:08 -04:00
Electron Bot
ac86d362ba Bump v6.0.0-beta.5 2019-05-29 08:10:59 -07:00
Shelley Vohr
2233a9eb5a Revert "Bump v6.0.0-beta.5"
This reverts commit 80fa2449a1.
2019-05-28 20:18:02 -07:00
Shelley Vohr
af24a4f364 build: fix breakpad symbol generation on linux arm (#18491) 2019-05-28 20:17:37 -07:00
trop[bot]
a78692f5b8 fix: create missing directories with app.setPath (#18480) 2019-05-28 19:30:49 -07:00
trop[bot]
335178098d fix: ensure the webContents is not destroyed before communicating (#18487) 2019-05-28 19:30:32 -07:00
trop[bot]
ddc0e8f7ba chore: remove leftover docs/api/structures/memory-info.md (#18430) 2019-05-28 14:20:46 -07:00
Electron Bot
80fa2449a1 Bump v6.0.0-beta.5 2019-05-28 13:31:35 -07:00
Shelley Vohr
476abafefe fix: respect minimizable/closable for customButtonsOnHover (#18478) 2019-05-28 13:29:43 -07:00
Felix Rieseberg
f7d4d51261 feat: Backport setting of global fallback user agent (#18473) 2019-05-28 12:25:07 -07:00
Electron Bot
7b08510075 chore: bump chromium to 76.0.3805.4 (6-0-x) (#18439)
* chore: bump chromium in DEPS to 76.0.3804.1

* chore: update patches

* chore: update v8 patches

* chore: bump chromium in DEPS to 76.0.3805.1

* chore: bump chromium in DEPS to 76.0.3805.2

* chore: bump chromium in DEPS to 76.0.3805.3

* chore: update patches

* Remove content_packaged_services

https://chromium-review.googlesource.com/c/chromium/src/+/1604203

* chore: fix false positive lint error

* views: wireup widget name to crash data

https://chromium-review.googlesource.com/c/chromium/src/+/1626640

* chore: bump chromium in DEPS to 76.0.3805.4
2019-05-28 11:29:10 -07:00
Jeremy Apthorp
14b62b28ce Merge pull request #18327 from electron/roller/chromium/6-0-x
chore: bump chromium to 76.0.3803.1 (6-0-x)
2019-05-23 17:08:56 -07:00
Jeremy Apthorp
1c44ed0912 Replace views_bridge_mac with remote_cocoa
https://chromium-review.googlesource.com/c/chromium/src/+/1623573
2019-05-23 15:00:02 -07:00
Jeremy Apthorp
de1edf3f4d Update function signatures for focused element change notifications
https://chromium-review.googlesource.com/c/chromium/src/+/1609749
2019-05-23 13:47:49 -07:00
deepak1556
a21ffa027a chore: update patches 2019-05-23 12:46:44 -07:00
Nitish Sakhawalkar
899d42563c Chrome changed the devtools url
chrome-devtools:// to devtools://
28b21a67f0
2019-05-23 12:36:16 -07:00
Electron Bot
6eecbb5edd chore: bump chromium in DEPS to 76.0.3803.1 2019-05-23 12:36:16 -07:00
Nitish Sakhawalkar
6a8e7a10ea Update views visible API
visible() -> GetVisible() as per c9ecec130e
2019-05-23 12:36:16 -07:00
Nitish Sakhawalkar
85bb488732 Update linux/win menu_bar.h
Chromium Commit 6a2f2686a9
2019-05-23 12:36:16 -07:00
Jeremy Apthorp
c957215854 pin user32 on startup
https://chromium-review.googlesource.com/c/chromium/src/+/1551709

Loading it later causes a blocking call where blocking calls aren't allowed.
2019-05-23 12:36:16 -07:00
Nitish Sakhawalkar
2ba3a26785 Disable custom libcxx patch 2019-05-23 12:36:16 -07:00
Jeremy Apthorp
f0dc3bc79f Manual follow-up rename in comments and variable names.
https://chromium-review.googlesource.com/c/chromium/src/+/1591429
2019-05-23 12:36:16 -07:00
Nitish Sakhawalkar
28d3edcd92 Update gpuinfo enumerator api
Related chromium change is here => 4178e190e9
2019-05-23 12:36:16 -07:00
Jeremy Apthorp
8026dee591 storage::IsolatedContext API changed
https://chromium-review.googlesource.com/c/chromium/src/+/1603486
2019-05-23 12:36:16 -07:00
Jeremy Apthorp
197cda9e45 GetNetCaptureModeFromCommandLine moved to net
https://chromium-review.googlesource.com/c/chromium/src/+/1614697
2019-05-23 12:36:16 -07:00
Jeremy Apthorp
903fd4e5e9 use base::Owned instead of base::Passed for repeating handler 2019-05-23 12:36:16 -07:00
Jeremy Apthorp
621c86b4cf Convert Callbacks to OnceCallbacks in permissions APIs.
https://chromium-review.googlesource.com/c/chromium/src/+/1592356
2019-05-23 12:36:16 -07:00
Nitish Sakhawalkar
deda7c700f Update for changed APIs
Update AllowCertificateError API (c5b8df91d1)
2019-05-23 12:36:15 -07:00
Jeremy Apthorp
d225304370 use unique_ptr instead of shared_ptr for SpellcheckRequest 2019-05-23 12:36:15 -07:00
Nitish Sakhawalkar
fd22b7ec2a Update Spellcheck API
Update WebTexhCheckingCompletion as per chromium 0e8c828e02
2019-05-23 12:36:15 -07:00
Nitish Sakhawalkar
a2b1d394b5 Update changed APIs/deps
Use brotli by default (36d58dd325)

Update Mac ui headers (897636c9f8)

Update AtomBrowserClient::HandleExternalProtocol API (cb656e1fd1)
2019-05-23 12:36:15 -07:00
Jeremy Apthorp
7d4c78e73e DelegatedFrameHost API changed
https://chromium-review.googlesource.com/c/chromium/src/+/1594924
2019-05-23 12:36:15 -07:00
Jeremy Apthorp
b37ff2b822 //ui/views_bridge_mac => //components/remote_cocoa/app_shim
https://chromium-review.googlesource.com/c/chromium/src/+/1590958
2019-05-23 12:36:15 -07:00
deepak1556
5887f5aa4f Move snapshot_toolchain.gni to gni/
https://chromium-review.googlesource.com/c/v8/v8/+/1612903
2019-05-23 12:36:15 -07:00
deepak1556
a9176a2ac8 chore: update patches 2019-05-23 12:36:15 -07:00
Electron Bot
6ceb431942 chore: bump chromium in DEPS to 76.0.3802.1 2019-05-23 12:36:15 -07:00
Electron Bot
508d131c95 chore: bump chromium in DEPS to 76.0.3801.1 2019-05-23 12:36:15 -07:00
Electron Bot
ae36659f7a chore: bump chromium in DEPS to 76.0.3800.1 2019-05-23 12:36:15 -07:00
Electron Bot
f970660766 chore: bump chromium in DEPS to 76.0.3799.1 2019-05-23 12:36:15 -07:00
Electron Bot
43c5837cda chore: bump chromium in DEPS to 76.0.3798.1 2019-05-23 12:36:15 -07:00
Electron Bot
a87e88df20 chore: bump chromium in DEPS to 76.0.3797.1 2019-05-23 12:36:15 -07:00
Electron Bot
5a5d4b06b3 chore: bump chromium in DEPS to 76.0.3796.1 2019-05-23 12:36:15 -07:00
trop[bot]
28ba88ba70 docs: rename 'API Contract' as 'Breaking Changes' (#18399)
* Use "Breaking Changes" as the changes doc's title.

Multiple people have commented that this important page is difficult
to find, in part because people search for "Breaking" or "Changes" or
"Breaking Changes" rather than "API Contract".

This PR changes the name to "Breaking Changes" so that it'll show up
on electronjs.org/docs/.

It also adds a backwards-friendly link so people still searching for
"API Contract" will get a redirect. I'm not sure if this is necessary --
the actual URL of https://electronjs.org/docs/api/breaking-changes is
unchanged -- would especially welcome feedback on this part.

* fixup! Use "Breaking Changes" as the changes doc's title.

* fixup! Use "Breaking Changes" as the changes doc's title.
2019-05-23 15:02:16 -04:00
trop[bot]
4f8ffe934e docs: clarify that 'second-instance' is only emitted when the second instance calls app.requestSingleInstanceLock() (#18385) 2019-05-21 16:25:50 -05:00
Electron Bot
c5c0a7abc5 Bump v6.0.0-beta.4 2019-05-21 11:28:46 -07:00
trop[bot]
84b762f0b3 fix: reverse saveDialog cancellation bool (#18383) 2019-05-21 13:09:35 -05:00
trop[bot]
043838f9b6 fix: set window to null when no window is passed (#18381)
Fixes #18236.

Our options parsing for dialogs correctly set options if no window was passed, but then did not correctly set the window back to null and it was then left as an object equal to options. This caused a crash when passed to native code as there is no valid circumstance where the window would be an object.
2019-05-21 08:34:40 -07:00
trop[bot]
a824e92628 fix: 'page-title-updated' event forwarding + documentation (#18319) 2019-05-21 16:21:50 +09:00
Samuel Attard
1843411e79 fix: update the FileSelectHelper to support the new promise API (#18288) (#18341)
* fix: update the FileSelectHelper to support the new promise API

Fixes #18254

So it turns out we've successfully introduced a way to write
non-typesafe C++.

This fixes two things:
* Uses the object the promise resolves
* Ensures we attach the Then handler before moving the promise

* fix: also fix misuse of Promise::Then in the download manager
2019-05-21 15:52:48 +09:00
trop[bot]
da76c4d7c5 fix: leave space for autohide taskbar for frameless maximized window (#18373) 2019-05-21 15:35:39 +09:00
trop[bot]
4468b86a81 feat: allow setting working directory in app.setUserTasks() / app.setJumpList() (#18291) 2019-05-16 09:13:30 -04:00
Electron Bot
8acbb9a3ad Bump v6.0.0-beta.3 2019-05-14 12:10:18 -07:00
trop[bot]
f5e28bc999 fix: default enable_negotiate_port to false (#18285) 2019-05-14 12:51:41 -05:00
trop[bot]
b45ad7f74e fix: destroy tray on current tick (#18218)
* fix: destroy tray on current tick

* test: add tray destroy specs

* use more idiomatic destructor syntax
2019-05-09 14:42:34 -04:00
trop[bot]
9e9238454e build: linux needs java on GN (#18217) 2019-05-09 11:05:33 -04:00
Electron Bot
3f2aba69ee Bump v6.0.0-beta.2 2019-05-07 19:51:34 -07:00
Shelley Vohr
371e804c6b Revert "Bump v6.0.0-beta.2"
This reverts commit c54b67300e.
2019-05-07 19:49:30 -07:00
trop[bot]
6131e89aa9 build: remove deprecated octokit auth calls (#18206) 2019-05-07 19:48:34 -07:00
Electron Bot
c54b67300e Bump v6.0.0-beta.2 2019-05-07 15:41:03 -07:00
John Kleinschmidt
e847f048d7 build: only delete .git directory on Mac builds (#18200) 2019-05-07 15:39:43 -07:00
Shelley Vohr
b5955fa663 Revert "Bump v6.0.0-beta.2"
This reverts commit a648e6c06d.
2019-05-07 15:00:14 -07:00
Electron Bot
a648e6c06d Bump v6.0.0-beta.2 2019-05-07 12:43:19 -07:00
Nitish Sakhawalkar
e6216da031 chore: Add patch to partially revert chromium crashpad change (#18198)
This adds a patch to support functionality that we were using but chromium changed it. Electron uses breakpad on windows, chromium uses crashpad (which is newer). So this patch is needed until we update electron to use crashpad for windows.
2019-05-07 12:35:10 -07:00
Jeremy Apthorp
5b7bd56367 chore: deprecate the 'options' argument to clearAuthCache (#18131)
The network service APIs do not support the fine-grained clearing of the auth cache. In preparation for switching to the network service in 7.x, log a warning that the options argument is deprecated. Ref #17970.

This might not be quite right as we could also potentially expose the new options that are available: namely, start and end time. #17970 does not expose those options, but it would in theory be possible to support them with the existing network service APIs. The current options object does not offer time-based cache clearing.
2019-05-07 09:55:15 -07:00
trop[bot]
01b1c0ca8b fix: crash on systemPreferences.getAccentColor() (#18195) 2019-05-07 09:51:36 -07:00
Shelley Vohr
05ced19f9f chore: deprecate shell.openExternalSync (#18179) 2019-05-07 08:19:52 -07:00
trop[bot]
b8ef669905 refactor: allow embedder overriding of internal FS calls (#17906) (#18192) 2019-05-07 08:00:40 -07:00
trop[bot]
212ce1840f docs: clarify clipboard type options (#18175) 2019-05-06 09:29:42 -07:00
trop[bot]
e090fa94d0 fix: do not mark navigations interupted with same-document navigations as aborted (#18143)
* fix: do not mark navigations interupted with same-document navigations as aborted

* spec: add tests for the loadURL promise
2019-05-03 23:08:57 -07:00
trop[bot]
a431f1a663 fix: correctly parse default_app path on windows (#18102) 2019-05-03 08:16:57 -07:00
trop[bot]
ea6815c0f7 fix: fs.promises does not work with asar paths (#18114) 2019-05-02 22:34:19 -07:00
Electron Bot
40e05eef23 chore: bump chromium to 76.0.3783.1 (6-0-x) (#18116) 2019-05-02 16:31:29 -07:00
trop[bot]
a790e702f5 build: free up space before running macos ci (#18099)
* build: free up space before running macos ci

* build: also delete 14GB of src/.git for bonus space
2019-05-01 13:48:25 -07:00
trop[bot]
be16a195fb fix: ensure the inspector agent is shutdown before cleaning up the node env (#18077)
* fix: ensure the inspector agent is shutdown before cleaning up the node env

* spec: add tests to ensure clean shutdown with connected inspector agent

* Update node_debugger.cc
2019-05-01 13:47:22 -07:00
trop[bot]
2f10c0fd6d docs: fix webContents 'new-window' event handler sample (#18098) 2019-05-01 13:44:47 -07:00
trop[bot]
276c07d3d7 docs: remove incorrectly added let for the win variable (#18095) 2019-05-01 12:41:59 -07:00
Samuel Attard
57f7c8b6b9 build: ensure consistent lock files across multiple machines (#17955) (#18071)
* build: ensure consistent package-lock across multiple machines

* build: fix linting errors and use npm ci instead of npm install

* build: use a yarn.lock and yarn instead of package-lock and npm

* chore: replace package-lock.json files with yarn.lock

* chore: replace last instance of `npm install`
2019-05-01 11:11:52 -07:00
trop[bot]
2ce22ba0e9 fix: explicitly focus window on win.show() (#18081) 2019-05-01 10:44:30 -07:00
Electron Bot
7186c62a27 Bump v6.0.0-beta.1 2019-04-30 14:46:01 -07:00
Electron Bot
bf88a13f1e Revert "Bump v6.0.0-beta.1"
This reverts commit 6e9c540baf.
2019-04-30 13:16:51 -07:00
Electron Bot
6e9c540baf Bump v6.0.0-beta.1 2019-04-30 13:11:22 -07:00
Electron Bot
24b14d55ef Revert "Bump v6.0.0-beta.1"
This reverts commit 3b8eb6c061.
2019-04-30 13:09:29 -07:00
Electron Bot
3b8eb6c061 Bump v6.0.0-beta.1 2019-04-30 13:04:14 -07:00
Electron Bot
f9b7f6389e Revert "Bump v6.0.0-beta.1"
This reverts commit 8f30faacf8.
2019-04-30 13:02:36 -07:00
Electron Bot
8f30faacf8 Bump v6.0.0-beta.1 2019-04-30 12:59:08 -07:00
trop[bot]
f631890237 chore: disable Vulkan validation layers (#18062) 2019-04-30 12:49:43 -07:00
trop[bot]
8982889a8d build: fix issues for stable release we fixed in 5-0-x (#18068)
* build: fix release notes generation

* build: fix bump-version script for stable releases
2019-04-30 12:49:25 -07:00
trop[bot]
cd3539aaf8 refactor: rewire the desktop capturer API to remove race conditions (#18042)
We now create a new instance of atom::api::DesktopCapturer for every
request instead of weirdly re-using the same instance and queuing
requests.  This means there is now a 1:1 relationship between request
and DesktopCapturer so there isn't a race condition between the observer
for one request calling back before the observer of another.  This is an
issue ever since the backing APIs moved to worker threads.

This also does a few things to ensure memory management
* Only ever listen to one event per-request, after that we wipe the emit
function to ignore all future events
* Ensures we clean up the window_capturer_, screen_capturer_ and
captured_sources_ in native land once the request is over.

This _in theory_ fixes a flake we've been seeing on CI where we try to
resolve the promise for a request that no longerr exists.
2019-04-30 07:07:56 -07:00
Samuel Attard
275e277721 feat: upgrade to Node 12 (#17838) (#18044)
* fix: add boringssl backport to support node upgrade

* fix: Update node_includes.h, add DCHECK macros

* fix: Update node Debug Options parser usage

* fix: Fix asar setup

* fix: using v8Util in isolated context

* fix: make "process" available in preload scripts

* fix: use proper options parser and remove setting of _breakFirstLine

_breakFirstLine was being set on the process, but that has changed in node 12 and so is no longer needed. Node will handle it properly when --inspect-brk is provided

* chore: update node dep sha

* fix: process.binding => _linkedBinding in sandboxed isolated preload

* fix: make original-fs work with streams

* build: override node module version

* fix: use _linkedBinding in content_script/init.js

* chore: update node ref in DEPS

* build: node_module_version should be 73
2019-04-29 15:52:31 -07:00
trop[bot]
283b1241d5 docs: Correct doc for registerFileProtocol (#18050)
In the registerFileProtocol docs the "headers" argument of the callback was described as being a list.
In fact is has to be an Object mapping header-entries to values. This can be seen in Line 326 of `/spec/api-protocol-spec.js` [fe618631f1/spec/api-protocol-spec.js (L326)].
2019-04-29 15:30:34 -07:00
trop[bot]
7bdea26085 docs: update nodeIntegration section for new defaults (#18047)
* docs: update nodeIntegration section for new defaults

* docs: update docs/tutorial/first-app.md

* Update docs/tutorial/security.md

Co-Authored-By: miniak <milan.burda@gmail.com>
2019-04-29 15:18:23 -07:00
Samuel Attard
f1fa589779 chore: upgrade chromium to 76 (#17921) 2019-04-29 12:48:28 -07:00
trop[bot]
7226ad1eba fix: crash when failed to get devices in desktopCapturer (#17973)
* fix: crash when failed to get devices in desktopCapturer

* return after emit
2019-04-26 08:05:12 -07:00
trop[bot]
d92743f0f3 docs: remove outdated refs to protocol.registerStandardSchemes (#17977) 2019-04-26 08:05:03 -07:00
trop[bot]
2c309efef4 docs: add azure vm spinup tutorial (#17975) 2019-04-25 15:49:21 -07:00
trop[bot]
0b418315a3 docs: clean up the native module tutorial (#17951) 2019-04-24 11:25:34 -07:00
trop[bot]
2f474867c7 fix: permission handler regression in default app (#17950) 2019-04-24 11:25:17 -07:00
trop[bot]
0b5acd9569 refactor: add missing constants for options (#17919) 2019-04-24 10:16:53 -07:00
Jeremy Apthorp
3419c3c730 chore: bump chromium to 75.0.3770.3 (#17883) 2019-04-23 14:29:16 -07:00
trop[bot]
754200f1b1 fix: crash when run from SMB network share (#17909) 2019-04-23 09:03:51 -07:00
Samuel Attard
37f4bd4dd0 build: reset version to 6.0.0-beta.0 in prep for 6.0.0-beta.1 2019-04-19 15:35:46 -07:00
1589 changed files with 129002 additions and 58046 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,4 @@
*
!tools/xvfb-init.sh
!tools/run-electron.sh
!build/install-build-deps.sh

View File

@@ -6,11 +6,9 @@
"browser": true
},
"rules": {
"semi": ["error", "always"],
"no-var": "error",
"no-unused-vars": 0,
"no-global-assign": 0,
"guard-for-in": 2,
"@typescript-eslint/no-unused-vars": ["error", {
"vars": "all",
"args": "after-used",

4
.github/CODEOWNERS vendored
View File

@@ -13,10 +13,10 @@
/patches/ @electron/wg-upgrades
DEPS @electron/wg-upgrades
# Docs & Tooling WG
/default_app/ @electron/wg-docs-tools
/default_app/ @electron/wg-docs-tools
/docs/ @electron/wg-docs-tools
# Releases WG
/npm/ @electron/wg-releases
/script/release @electron/wg-releases

View File

@@ -20,7 +20,7 @@ about: Create a report to help us improve Electron
* <!-- (output of `node_modules/.bin/electron --version`) e.g. 4.0.3 -->
* **Operating System:**
* <!-- (Platform and Version) e.g. macOS 10.13.6 / Windows 10 (1803) / Ubuntu 18.04 x64 -->
* **Last Known Working Electron version:**
* **Last Known Working Electron version:**:
* <!-- (if applicable) e.g. 3.1.0 -->
### Expected Behavior
@@ -31,15 +31,11 @@ about: Create a report to help us improve Electron
### To Reproduce
<!--
Your best chance of getting this bug looked at quickly is to provide an example.
Your best chance of getting this bug looked at quickly is to provide a REPOSITORY that can be cloned and run.
-->
<!--
For bugs that can be encapsulated in a small experiment, you can use Electron Fiddle (https://github.com/electron/fiddle) to publish your example to a GitHub Gist and link it your bug report.
-->
<!--
If Fiddle is insufficient to produce an example, please provide an example REPOSITORY that can be cloned and run. You can fork electron-quick-start (https://github.com/electron/electron-quick-start) and include a link to the branch with your changes.
You can fork electron-quick-start (https://github.com/electron/electron-quick-start) and include a link to the branch with your changes.
-->
<!--

10
.github/main.workflow vendored
View File

@@ -1,10 +0,0 @@
workflow "Clerk" {
#TODO(codebytere): make this work properly on pull_request
on = "repository_dispatch"
resolves = "Check release notes"
}
action "Check release notes" {
uses = "electron/clerk@master"
secrets = [ "GITHUB_TOKEN" ]
}

3
.gitignore vendored
View File

@@ -62,6 +62,3 @@ spec/.hash
# If someone runs tsc this is where stuff will end up
ts-gen
# Used to accelerate CI builds
.depshash

409
BUILD.gn
View File

@@ -12,10 +12,9 @@ import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
import("//v8/gni/snapshot_toolchain.gni")
import("build/asar.gni")
import("build/extract_symbols.gni")
import("build/js_wrap.gni")
import("build/npm.gni")
import("build/templated_file.gni")
import("build/tsc.gni")
import("build/webpack/webpack.gni")
import("buildflags/buildflags.gni")
import("electron_paks.gni")
import("filenames.auto.gni")
@@ -26,7 +25,6 @@ if (is_mac) {
import("//third_party/icu/config.gni")
import("//ui/gl/features.gni")
import("//v8/gni/v8.gni")
import("build/rules.gni")
}
if (is_linux) {
@@ -44,7 +42,7 @@ if (is_linux) {
}
}
branding = read_file("shell/app/BRANDING.json", "json")
branding = read_file("atom/app/BRANDING.json", "json")
electron_project_name = branding.project_name
electron_product_name = branding.product_name
electron_mac_bundle_id = branding.mac_bundle_id
@@ -56,8 +54,8 @@ if (is_mas_build) {
config("branding") {
defines = [
"ELECTRON_PRODUCT_NAME=\"$electron_product_name\"",
"ELECTRON_PROJECT_NAME=\"$electron_project_name\"",
"ATOM_PRODUCT_NAME=\"$electron_product_name\"",
"ATOM_PROJECT_NAME=\"$electron_project_name\"",
]
}
@@ -76,70 +74,135 @@ npm_action("build_electron_definitions") {
]
}
webpack_build("electron_browser_bundle") {
npm_action("atom_browserify_sandbox_unwrapped") {
script = "browserify"
deps = [
":build_electron_definitions",
]
inputs = auto_filenames.browser_bundle_deps
inputs = auto_filenames.sandbox_browserify_deps
config_file = "//electron/build/webpack/webpack.config.browser.js"
out_file = "$target_gen_dir/js2c/browser_init.js"
outputs = [
"$target_gen_dir/js2c/sandbox_bundle_unwrapped.js",
]
args = [
"lib/sandboxed_renderer/init.js",
"-r",
"./lib/sandboxed_renderer/api/exports/electron.js:electron",
"-t",
"aliasify",
"-p",
"[",
"tsify",
"-p",
"tsconfig.electron.json",
"]",
"--standalone",
"sandboxed_preload",
"-o",
rebase_path(outputs[0]),
]
}
webpack_build("electron_renderer_bundle") {
npm_action("atom_browserify_isolated_unwrapped") {
script = "browserify"
deps = [
":build_electron_definitions",
]
inputs = auto_filenames.renderer_bundle_deps
inputs = auto_filenames.isolated_browserify_deps
config_file = "//electron/build/webpack/webpack.config.renderer.js"
out_file = "$target_gen_dir/js2c/renderer_init.js"
outputs = [
"$target_gen_dir/js2c/isolated_bundle_unwrapped.js",
]
args = [
"lib/isolated_renderer/init.js",
"-t",
"aliasify",
"-p",
"[",
"tsify",
"-p",
"tsconfig.electron.json",
"]",
"--standalone",
"isolated_preload",
"-o",
rebase_path(outputs[0]),
]
}
webpack_build("electron_worker_bundle") {
npm_action("atom_browserify_content_script_unwrapped") {
script = "browserify"
deps = [
":build_electron_definitions",
]
inputs = auto_filenames.worker_bundle_deps
inputs = auto_filenames.context_script_browserify_deps
config_file = "//electron/build/webpack/webpack.config.worker.js"
out_file = "$target_gen_dir/js2c/worker_init.js"
outputs = [
"$target_gen_dir/js2c/content_script_bundle_unwrapped.js",
]
args = [
"lib/content_script/init.js",
"-t",
"aliasify",
"-p",
"[",
"tsify",
"-p",
"tsconfig.electron.json",
"]",
"--standalone",
"content_script_preload",
"-o",
rebase_path(outputs[0]),
]
}
webpack_build("electron_sandboxed_renderer_bundle") {
js_wrap("atom_browserify_content_script") {
deps = [
":build_electron_definitions",
":atom_browserify_content_script_unwrapped",
]
inputs = auto_filenames.sandbox_bundle_deps
inputs = [
"$target_gen_dir/js2c/content_script_bundle_unwrapped.js",
]
config_file = "//electron/build/webpack/webpack.config.sandboxed_renderer.js"
out_file = "$target_gen_dir/js2c/sandbox_bundle.js"
outputs = [
"$target_gen_dir/js2c/content_script_bundle.js",
]
}
webpack_build("electron_isolated_renderer_bundle") {
js_wrap("atom_browserify_isolated") {
deps = [
":build_electron_definitions",
":atom_browserify_isolated_unwrapped",
]
inputs = auto_filenames.isolated_bundle_deps
inputs = [
"$target_gen_dir/js2c/isolated_bundle_unwrapped.js",
]
config_file = "//electron/build/webpack/webpack.config.isolated_renderer.js"
out_file = "$target_gen_dir/js2c/isolated_bundle.js"
outputs = [
"$target_gen_dir/js2c/isolated_bundle.js",
]
}
webpack_build("electron_content_script_bundle") {
js_wrap("atom_browserify_sandbox") {
deps = [
":build_electron_definitions",
":atom_browserify_sandbox_unwrapped",
]
inputs = auto_filenames.content_script_bundle_deps
inputs = [
"$target_gen_dir/js2c/sandbox_bundle_unwrapped.js",
]
config_file = "//electron/build/webpack/webpack.config.content_script.js"
out_file = "$target_gen_dir/js2c/content_script_bundle.js"
outputs = [
"$target_gen_dir/js2c/sandbox_bundle.js",
]
}
copy("atom_js2c_copy") {
@@ -154,25 +217,19 @@ copy("atom_js2c_copy") {
action("atom_js2c") {
deps = [
":atom_browserify_content_script",
":atom_browserify_isolated",
":atom_browserify_sandbox",
":atom_js2c_copy",
":electron_browser_bundle",
":electron_content_script_bundle",
":electron_isolated_renderer_bundle",
":electron_renderer_bundle",
":electron_sandboxed_renderer_bundle",
":electron_worker_bundle",
]
webpack_sources = [
"$target_gen_dir/js2c/browser_init.js",
"$target_gen_dir/js2c/renderer_init.js",
"$target_gen_dir/js2c/worker_init.js",
browserify_sources = [
"$target_gen_dir/js2c/content_script_bundle.js",
"$target_gen_dir/js2c/isolated_bundle.js",
"$target_gen_dir/js2c/sandbox_bundle.js",
]
sources = webpack_sources + [
sources = browserify_sources + [
"$target_gen_dir/js2c/asar.js",
"$target_gen_dir/js2c/asar_init.js",
]
@@ -188,8 +245,51 @@ action("atom_js2c") {
rebase_path(sources, root_build_dir)
}
target_gen_electron_js = "$target_gen_dir/js/electron"
target_gen_default_app_js = "$target_gen_dir/js/default_app"
typescript_build("lib_js") {
deps = [
":build_electron_definitions",
]
type_root = rebase_path("$target_gen_dir/tsc/electron/typings")
sources = filenames.js_sources
if (enable_desktop_capturer) {
sources += [
"lib/browser/desktop-capturer.js",
"lib/renderer/api/desktop-capturer.js",
]
}
if (enable_view_api) {
sources += [
"lib/browser/api/views/box-layout.js",
"lib/browser/api/views/button.js",
"lib/browser/api/views/label-button.js",
"lib/browser/api/views/layout-manager.js",
"lib/browser/api/views/md-text-button.js",
"lib/browser/api/views/resize-area.js",
"lib/browser/api/views/text-field.js",
]
}
output_gen_dir = target_gen_electron_js
output_dir_name = "lib"
tsconfig = "tsconfig.electron.json"
}
asar("electron_asar") {
deps = [
":lib_js",
]
root = "$target_gen_electron_js/electron/lib"
sources = get_target_outputs(":lib_js")
outputs = [
"$root_out_dir/resources/electron.asar",
]
}
typescript_build("default_app_js") {
deps = [
":build_electron_definitions",
@@ -290,46 +390,29 @@ if (is_linux) {
source_set("manifests") {
sources = [
"//electron/shell/app/manifests.cc",
"//electron/shell/app/manifests.h",
"//electron/atom/app/manifests.cc",
"//electron/atom/app/manifests.h",
]
include_dirs = [ "//electron" ]
deps = [
"//electron/shell/common/api:mojo",
"//electron/atom/common/api:mojo",
"//printing/buildflags",
"//services/proxy_resolver/public/cpp:manifest",
"//services/service_manager/public/cpp",
]
if (enable_basic_printing) {
deps += [ "//components/services/pdf_compositor/public/cpp:manifest" ]
}
if (enable_print_preview) {
deps += [ "//chrome/services/printing/public/cpp:manifest" ]
}
}
npm_action("electron_version_args") {
script = "generate-version-json"
outputs = [
"$target_gen_dir/electron_version.args",
]
args = rebase_path(outputs)
inputs = [
"ELECTRON_VERSION",
"script/generate-version-json.js",
]
}
templated_file("electron_version_header") {
deps = [
":electron_version_args",
]
template = "build/templates/electron_version.tmpl"
output = "$target_gen_dir/electron_version.h"
args_files = get_target_outputs(":electron_version_args")
}
source_set("electron_lib") {
static_library("electron_lib") {
configs += [ "//v8:external_startup_data" ]
configs += [ "//third_party/electron_node:node_internals" ]
@@ -337,21 +420,17 @@ source_set("electron_lib") {
deps = [
":atom_js2c",
":electron_version_header",
":manifests",
":resources",
"atom/common/api:mojo",
"buildflags",
"chromium_src:chrome",
"native_mate",
"shell/common/api:mojo",
"//base:base_static",
"//base/allocator:buildflags",
"//chrome/app/resources:platform_locale_settings",
"//chrome/services/printing/public/mojom",
"//components/certificate_transparency",
"//components/net_log",
"//components/network_hints/common",
"//components/network_hints/renderer",
"//components/network_session_configurator/common",
"//components/prefs",
"//components/spellcheck/renderer",
@@ -360,14 +439,12 @@ source_set("electron_lib") {
"//content/public/browser",
"//content/public/child",
"//content/public/common:service_names",
"//content/public/gpu",
"//content/public/renderer",
"//content/public/utility",
"//device/bluetooth",
"//device/bluetooth/public/cpp",
"//gin",
"//media/capture/mojom:video_capture",
"//media/mojo/mojom",
"//media/mojo/interfaces",
"//net:extras",
"//net:net_resources",
"//net:net_with_v8",
@@ -380,7 +457,7 @@ source_set("electron_lib") {
"//services/device/public/mojom",
"//services/proxy_resolver:lib",
"//services/video_capture/public/mojom:constants",
"//services/viz/privileged/mojom/compositing",
"//services/viz/privileged/interfaces/compositing",
"//skia",
"//third_party/blink/public:blink",
"//third_party/boringssl",
@@ -464,8 +541,8 @@ source_set("electron_lib") {
if (enable_fake_location_provider) {
sources += [
"shell/browser/fake_location_provider.cc",
"shell/browser/fake_location_provider.h",
"atom/browser/fake_location_provider.cc",
"atom/browser/fake_location_provider.h",
]
}
@@ -476,15 +553,15 @@ source_set("electron_lib") {
"//ui/accelerated_widget_mac",
]
sources += [
"shell/browser/ui/views/autofill_popup_view.cc",
"shell/browser/ui/views/autofill_popup_view.h",
"atom/browser/ui/views/autofill_popup_view.cc",
"atom/browser/ui/views/autofill_popup_view.h",
]
if (is_mas_build) {
sources += [ "shell/browser/api/atom_api_app_mas.mm" ]
sources += [ "atom/browser/api/atom_api_app_mas.mm" ]
sources -= [
"shell/browser/auto_updater_mac.mm",
"shell/common/crash_reporter/crash_reporter_mac.h",
"shell/common/crash_reporter/crash_reporter_mac.mm",
"atom/browser/auto_updater_mac.mm",
"atom/common/crash_reporter/crash_reporter_mac.h",
"atom/common/crash_reporter/crash_reporter_mac.mm",
]
defines += [ "MAS_BUILD" ]
} else {
@@ -517,7 +594,6 @@ source_set("electron_lib") {
]
configs += [ ":gio_unix" ]
include_dirs += [ "//third_party/breakpad" ]
configs += [ "//build/config/linux:x11" ]
defines += [
# Disable warnings for g_settings_list_schemas.
"GLIB_DISABLE_DEPRECATION_WARNINGS",
@@ -541,8 +617,8 @@ source_set("electron_lib") {
if ((is_mac && !is_mas_build) || is_win) {
sources += [
"shell/common/crash_reporter/crash_reporter_crashpad.cc",
"shell/common/crash_reporter/crash_reporter_crashpad.h",
"atom/common/crash_reporter/crash_reporter_crashpad.cc",
"atom/common/crash_reporter/crash_reporter_crashpad.h",
]
deps += [ "//third_party/crashpad/crashpad/client" ]
}
@@ -553,91 +629,74 @@ source_set("electron_lib") {
if (enable_run_as_node) {
sources += [
"shell/app/node_main.cc",
"shell/app/node_main.h",
"atom/app/node_main.cc",
"atom/app/node_main.h",
]
}
if (enable_osr) {
sources += [
"shell/browser/osr/osr_host_display_client.cc",
"shell/browser/osr/osr_host_display_client.h",
"shell/browser/osr/osr_host_display_client_mac.mm",
"shell/browser/osr/osr_render_widget_host_view.cc",
"shell/browser/osr/osr_render_widget_host_view.h",
"shell/browser/osr/osr_video_consumer.cc",
"shell/browser/osr/osr_video_consumer.h",
"shell/browser/osr/osr_view_proxy.cc",
"shell/browser/osr/osr_view_proxy.h",
"shell/browser/osr/osr_web_contents_view.cc",
"shell/browser/osr/osr_web_contents_view.h",
"shell/browser/osr/osr_web_contents_view_mac.mm",
"atom/browser/osr/osr_host_display_client.cc",
"atom/browser/osr/osr_host_display_client.h",
"atom/browser/osr/osr_host_display_client_mac.mm",
"atom/browser/osr/osr_render_widget_host_view.cc",
"atom/browser/osr/osr_render_widget_host_view.h",
"atom/browser/osr/osr_video_consumer.cc",
"atom/browser/osr/osr_video_consumer.h",
"atom/browser/osr/osr_view_proxy.cc",
"atom/browser/osr/osr_view_proxy.h",
"atom/browser/osr/osr_web_contents_view.cc",
"atom/browser/osr/osr_web_contents_view.h",
"atom/browser/osr/osr_web_contents_view_mac.mm",
]
deps += [
"//components/viz/service",
"//services/viz/public/mojom",
"//services/viz/public/interfaces",
"//ui/compositor",
]
}
if (enable_desktop_capturer) {
if (is_component_build && !is_linux) {
# On windows the implementation relies on unexported
# DxgiDuplicatorController class. On macOS the implementation
# relies on unexported webrtc::GetWindowOwnerPid method.
deps += [ "//third_party/webrtc/modules/desktop_capture" ]
}
sources += [
"shell/browser/api/atom_api_desktop_capturer.cc",
"shell/browser/api/atom_api_desktop_capturer.h",
"atom/browser/api/atom_api_desktop_capturer.cc",
"atom/browser/api/atom_api_desktop_capturer.h",
]
}
if (enable_view_api) {
sources += [
"shell/browser/api/views/atom_api_box_layout.cc",
"shell/browser/api/views/atom_api_box_layout.h",
"shell/browser/api/views/atom_api_button.cc",
"shell/browser/api/views/atom_api_button.h",
"shell/browser/api/views/atom_api_label_button.cc",
"shell/browser/api/views/atom_api_label_button.h",
"shell/browser/api/views/atom_api_layout_manager.cc",
"shell/browser/api/views/atom_api_layout_manager.h",
"shell/browser/api/views/atom_api_md_text_button.cc",
"shell/browser/api/views/atom_api_md_text_button.h",
"shell/browser/api/views/atom_api_resize_area.cc",
"shell/browser/api/views/atom_api_resize_area.h",
"shell/browser/api/views/atom_api_text_field.cc",
"shell/browser/api/views/atom_api_text_field.h",
"atom/browser/api/views/atom_api_box_layout.cc",
"atom/browser/api/views/atom_api_box_layout.h",
"atom/browser/api/views/atom_api_button.cc",
"atom/browser/api/views/atom_api_button.h",
"atom/browser/api/views/atom_api_label_button.cc",
"atom/browser/api/views/atom_api_label_button.h",
"atom/browser/api/views/atom_api_layout_manager.cc",
"atom/browser/api/views/atom_api_layout_manager.h",
"atom/browser/api/views/atom_api_md_text_button.cc",
"atom/browser/api/views/atom_api_md_text_button.h",
"atom/browser/api/views/atom_api_resize_area.cc",
"atom/browser/api/views/atom_api_resize_area.h",
"atom/browser/api/views/atom_api_text_field.cc",
"atom/browser/api/views/atom_api_text_field.h",
]
}
if (enable_basic_printing) {
sources += [
"shell/browser/printing/print_preview_message_handler.cc",
"shell/browser/printing/print_preview_message_handler.h",
"shell/renderer/printing/print_render_frame_helper_delegate.cc",
"shell/renderer/printing/print_render_frame_helper_delegate.h",
"atom/browser/printing/print_preview_message_handler.cc",
"atom/browser/printing/print_preview_message_handler.h",
"atom/renderer/printing/print_render_frame_helper_delegate.cc",
"atom/renderer/printing/print_render_frame_helper_delegate.h",
]
}
if (enable_pepper_flash) {
deps += [ "components/pepper_flash" ]
}
public_deps += [ "shell/common/extensions/api:extensions_features" ]
deps += [
"//components/pref_registry",
"//components/user_prefs",
"//extensions/browser",
"//extensions/browser:core_api_provider",
"//extensions/common",
"//extensions/common:core_api_provider",
"//extensions/renderer",
]
if (enable_electron_extensions) {
sources += filenames.lib_sources_extensions
}
}
electron_paks("packed_resources") {
@@ -658,7 +717,7 @@ if (is_mac) {
mac_xib_bundle_data("electron_xibs") {
sources = [
"shell/common/resources/mac/MainMenu.xib",
"atom/common/resources/mac/MainMenu.xib",
]
}
@@ -781,10 +840,10 @@ if (is_mac) {
if (!is_mas_build) {
deps += [ ":electron_crashpad_helper" ]
}
info_plist = "shell/common/resources/mac/Info.plist"
info_plist = "atom/common/resources/mac/Info.plist"
extra_substitutions = [
"ELECTRON_BUNDLE_ID=$electron_mac_bundle_id.framework",
"ATOM_BUNDLE_ID=$electron_mac_bundle_id.framework",
"ELECTRON_VERSION=$electron_version",
]
@@ -835,11 +894,10 @@ if (is_mac) {
}
defines = [ "HELPER_EXECUTABLE" ]
sources = filenames.app_sources
sources += [ "shell/common/atom_constants.cc" ]
sources += [ "atom/common/atom_constants.cc" ]
include_dirs = [ "." ]
info_plist = "shell/renderer/resources/mac/Info.plist"
extra_substitutions =
[ "ELECTRON_BUNDLE_ID=$electron_mac_bundle_id.helper" ]
info_plist = "atom/renderer/resources/mac/Info.plist"
extra_substitutions = [ "ATOM_BUNDLE_ID=$electron_mac_bundle_id.helper" ]
ldflags = [
"-rpath",
"@executable_path/../../..",
@@ -892,9 +950,9 @@ if (is_mac) {
sources = filenames.login_helper_sources
include_dirs = [ "." ]
libs = [ "AppKit.framework" ]
info_plist = "shell/app/resources/mac/loginhelper-Info.plist"
info_plist = "atom/app/resources/mac/loginhelper-Info.plist"
extra_substitutions =
[ "ELECTRON_BUNDLE_ID=$electron_mac_bundle_id.loginhelper" ]
[ "ATOM_BUNDLE_ID=$electron_mac_bundle_id.loginhelper" ]
}
bundle_data("electron_login_helper_app") {
@@ -943,10 +1001,12 @@ if (is_mac) {
public_deps = [
":default_app_asar",
":electron_app_strings_bundle_data",
":electron_asar",
]
sources = [
"$root_out_dir/resources/default_app.asar",
"shell/browser/resources/mac/electron.icns",
"$root_out_dir/resources/electron.asar",
"atom/browser/resources/mac/electron.icns",
]
outputs = [
"{{bundle_resources_dir}}/{{source_file_part}}",
@@ -956,7 +1016,7 @@ if (is_mac) {
mac_app_bundle("electron_app") {
output_name = electron_product_name
sources = filenames.app_sources
sources += [ "shell/common/atom_constants.cc" ]
sources += [ "atom/common/atom_constants.cc" ]
include_dirs = [ "." ]
deps = [
":electron_app_framework_bundle_data",
@@ -965,11 +1025,8 @@ if (is_mac) {
if (is_mas_build) {
deps += [ ":electron_login_helper_app" ]
}
info_plist = "shell/browser/resources/mac/Info.plist"
extra_substitutions = [
"ELECTRON_BUNDLE_ID=$electron_mac_bundle_id",
"ELECTRON_VERSION=$electron_version",
]
info_plist = "atom/browser/resources/mac/Info.plist"
extra_substitutions = [ "ATOM_BUNDLE_ID=$electron_mac_bundle_id" ]
ldflags = [
"-rpath",
"@executable_path/../Frameworks",
@@ -1057,8 +1114,8 @@ if (is_mac) {
} else {
windows_manifest("electron_app_manifest") {
sources = [
"shell/browser/resources/win/disable_window_filtering.manifest",
"shell/browser/resources/win/dpi_aware.manifest",
"atom/browser/resources/win/disable_window_filtering.manifest",
"atom/browser/resources/win/dpi_aware.manifest",
as_invoker_manifest,
common_controls_manifest,
default_compatibility_manifest,
@@ -1072,6 +1129,7 @@ if (is_mac) {
deps = [
":default_app_asar",
":electron_app_manifest",
":electron_asar",
":electron_lib",
":packed_resources",
"//content:sandbox_helper_win",
@@ -1092,6 +1150,7 @@ if (is_mac) {
if (!is_mac) {
data += [ "$root_out_dir/resources/default_app.asar" ]
data += [ "$root_out_dir/resources/electron.asar" ]
}
public_deps = [
@@ -1101,8 +1160,9 @@ if (is_mac) {
if (is_win) {
sources += [
# TODO: we should be generating our .rc files more like how chrome does
"shell/browser/resources/win/atom.rc",
"shell/browser/resources/win/resource.h",
"atom/browser/resources/win/atom.ico",
"atom/browser/resources/win/atom.rc",
"atom/browser/resources/win/resource.h",
]
libs = [
@@ -1128,7 +1188,6 @@ if (is_mac) {
# See https://github.com/nodejs/node-gyp/commit/52ceec3a6d15de3a8f385f43dbe5ecf5456ad07a
ldflags += [ "/DEF:" + rebase_path("build/electron.def", root_build_dir) ]
inputs = [
"shell/browser/resources/win/atom.ico",
"build/electron.def",
]
}
@@ -1289,18 +1348,12 @@ dist_zip("electron_chromedriver_zip") {
]
}
mksnapshot_deps = [
":licenses",
"//tools/v8_context_snapshot:v8_context_snapshot_generator",
"//v8:mksnapshot($v8_snapshot_toolchain)",
]
group("electron_mksnapshot") {
public_deps = mksnapshot_deps
}
dist_zip("electron_mksnapshot_zip") {
data_deps = mksnapshot_deps
data_deps = [
"//v8:mksnapshot($v8_snapshot_toolchain)",
"//tools/v8_context_snapshot:v8_context_snapshot_generator",
":licenses",
]
outputs = [
"$root_build_dir/mksnapshot.zip",
]

View File

@@ -28,18 +28,6 @@ the issue will be closed.
* If an issue has been closed and you still feel it's relevant, feel free to
ping a maintainer or add a comment!
### Languages
We accept issues in *any* language.
When an issue is posted in a language besides English, it is acceptable and encouraged to post an English-translated copy as a reply.
Anyone may post the translated reply.
In most cases, a quick pass through translation software is sufficient.
Having the original text _as well as_ the translation can help mitigate translation errors.
Responses to posted issues may or may not be in the original language.
**Please note** that using non-English as an attempt to circumvent our [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) will be an immediate, and possibly indefinite, ban from the project.
## [Pull Requests](https://electronjs.org/docs/development/pull-requests)
Pull Requests are the way concrete changes are made to the code, documentation,
@@ -69,4 +57,4 @@ See [Coding Style](https://electronjs.org/docs/development/coding-style) for inf
## Further Reading
For more in-depth guides on developing Electron, see
[/docs/development](/docs/development/README.md)
[/docs/development](/docs/development/README.md)

54
DEPS
View File

@@ -5,17 +5,14 @@ gclient_gn_args = [
'checkout_android_native_support',
'checkout_libaom',
'checkout_nacl',
'checkout_oculus_sdk',
'checkout_openxr'
'checkout_oculus_sdk'
]
vars = {
'chromium_version':
'78.0.3904.130',
'76.0.3809.146',
'node_version':
'v12.8.1',
'nan_version':
'2ee313aaca52e2b478965ac50eb5082520380d1b',
'v12.4.0',
'boto_version': 'f7574aa6cc2c819430c1f05e9a1a1a666ef8169b',
'pyyaml_version': '3.12',
@@ -28,19 +25,21 @@ vars = {
'requests_git': 'https://github.com/kennethreitz',
'yaml_git': 'https://github.com/yaml',
# KEEP IN SYNC WITH utils.js FILE
# KEEP IN SYNC WITH spec-runner FILE
'yarn_version': '1.15.2',
# To be able to build clean Chromium from sources.
'apply_patches': True,
# Apply the patches specific to windows on arm64
'apply_win_arm64_patches': False,
# Python interface to Amazon Web Services. Is used for releases only.
'checkout_boto': False,
# To allow in-house builds to checkout those manually.
'checkout_chromium': True,
'checkout_node': True,
'checkout_nan': True,
# It's only needed to parse the native tests configurations.
'checkout_pyyaml': False,
@@ -48,9 +47,6 @@ vars = {
# Python "requests" module is used for releases only.
'checkout_requests': False,
# To allow running hooks without parsing the DEPS tree
'process_deps': True,
# It is always needed for normal Electron builds,
# but might be impossible for custom in-house builds.
'download_external_binaries': True,
@@ -61,8 +57,6 @@ vars = {
True,
'checkout_oculus_sdk':
False,
'checkout_openxr':
False,
'build_with_chromium':
True,
'checkout_android':
@@ -74,39 +68,45 @@ vars = {
deps = {
'src': {
'url': (Var("chromium_git")) + '/chromium/src.git@' + (Var("chromium_version")),
'condition': 'checkout_chromium and process_deps',
},
'src/third_party/nan': {
'url': (Var("nodejs_git")) + '/nan.git@' + (Var("nan_version")),
'condition': 'checkout_nan and process_deps',
'condition': 'checkout_chromium',
},
'src/third_party/electron_node': {
'url': (Var("nodejs_git")) + '/node.git@' + (Var("node_version")),
'condition': 'checkout_node and process_deps',
'condition': 'checkout_node',
},
'src/electron/vendor/pyyaml': {
'url': (Var("yaml_git")) + '/pyyaml.git@' + (Var("pyyaml_version")),
'condition': 'checkout_pyyaml and process_deps',
'condition': 'checkout_pyyaml',
},
'src/electron/vendor/boto': {
'url': Var('boto_git') + '/boto.git' + '@' + Var('boto_version'),
'condition': 'checkout_boto and process_deps',
'condition': 'checkout_boto',
},
'src/electron/vendor/requests': {
'url': Var('requests_git') + '/requests.git' + '@' + Var('requests_version'),
'condition': 'checkout_requests and process_deps',
'condition': 'checkout_requests',
},
}
hooks = [
{
'name': 'patch_chromium',
'condition': '(checkout_chromium and apply_patches) and process_deps',
'condition': 'checkout_chromium and apply_patches',
'pattern': 'src/electron',
'action': [
'python',
'src/electron/script/apply_all_patches.py',
'src/electron/patches/config.json',
'src/electron/patches/common/config.json',
],
},
{
'name': 'patch_chromium',
'condition': '(checkout_chromium and apply_patches) and apply_win_arm64_patches',
'pattern': 'src/electron',
'action': [
'python',
'src/electron/script/apply_all_patches.py',
'src/electron/patches/win_arm64/config.json',
],
},
{
@@ -114,7 +114,7 @@ hooks = [
'pattern': 'src/electron/script/update-external-binaries.py',
'condition': 'download_external_binaries',
'action': [
'python3',
'python',
'src/electron/script/update-external-binaries.py',
],
},
@@ -130,7 +130,7 @@ hooks = [
{
'name': 'setup_boto',
'pattern': 'src/electron',
'condition': 'checkout_boto and process_deps',
'condition': 'checkout_boto',
'action': [
'python',
'-c',
@@ -140,7 +140,7 @@ hooks = [
{
'name': 'setup_requests',
'pattern': 'src/electron',
'condition': 'checkout_requests and process_deps',
'condition': 'checkout_requests',
'action': [
'python',
'-c',

View File

@@ -10,7 +10,6 @@ RUN chmod a+rwx /tmp
# Install Linux packages
ADD build/install-build-deps.sh /setup/install-build-deps.sh
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN dpkg --add-architecture i386
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
curl \
libnotify-bin \
@@ -23,8 +22,6 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
sudo \
vim-nox \
wget \
g++-multilib \
libgl1:i386 \
&& /setup/install-build-deps.sh --syms --no-prompt --no-chromeos-fonts --lib32 --arm \
&& rm -rf /var/lib/apt/lists/*

View File

@@ -19,6 +19,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
libcap-dev \
libcups2-dev \
libdbus-1-dev \
libgconf-2-4 \
libgconf2-dev \
libgnome-keyring-dev \
libgtk2.0-0 \
libgtk2.0-dev \

View File

@@ -1,4 +1,4 @@
FROM arm64v8/ubuntu:18.04
FROM arm64v8/ubuntu:16.04
RUN groupadd --gid 1000 builduser \
&& useradd --uid 1000 --gid builduser --shell /bin/bash --create-home builduser
@@ -22,6 +22,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
libcap-dev \
libcups2-dev \
libdbus-1-dev \
libgconf-2-4 \
libgconf2-dev \
libgnome-keyring-dev \
libgtk2.0-0 \
libgtk2.0-dev \
@@ -39,6 +41,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
nano \
python-setuptools \
python-pip \
python-dbusmock \
sudo \
unzip \
wget \
@@ -53,9 +56,6 @@ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
# crcmod is required by gsutil, which is used for filling the gclient git cache
RUN pip install -U crcmod
# dbusmock is needed for Electron tests
RUN pip install python-dbusmock
ADD tools/xvfb-init.sh /etc/init.d/xvfb
RUN chmod a+x /etc/init.d/xvfb

View File

@@ -1 +1 @@
7.2.0
6.1.4

View File

@@ -91,10 +91,6 @@ const child = proc.spawn(electron)
Find documentation translations in [electron/i18n](https://github.com/electron/i18n).
## Contributing
If you are interested in reporting/fixing issues and contributing directly to the code base, please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information on what we're looking for and how to get started.
## Community
Info on reporting bugs, getting help, finding third-party tools and sample apps,

View File

@@ -23,29 +23,13 @@
# https://www.appveyor.com/docs/build-configuration/#secure-variables
# https://www.appveyor.com/docs/build-configuration/#custom-environment-variables
# Uncomment these lines to enable RDP
#on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
version: 1.0.{build}
build_cloud: libcc-20
image: vs2017-15.9-10.0.18362
image: libcc-20-vs2017-15.9
environment:
GIT_CACHE_PATH: C:\Users\electron\libcc_cache
ELECTRON_OUT_DIR: Default
ELECTRON_ENABLE_STACK_DUMPING: 1
MOCHA_REPORTER: mocha-multi-reporters
MOCHA_MULTI_REPORTERS: mocha-appveyor-reporter, tap
notifications:
- provider: Webhook
url: https://electron-mission-control.herokuapp.com/rest/appveyor-hook
method: POST
headers:
x-mission-control-secret:
secure: 90BLVPcqhJPG7d24v0q/RRray6W3wDQ8uVQlQjOHaBWkw1i8FoA1lsjr2C/v1dVok+tS2Pi6KxDctPUkwIb4T27u4RhvmcPzQhVpfwVJAG9oNtq+yKN7vzHfg7k/pojEzVdJpQLzeJGcSrZu7VY39Q==
on_build_success: false
on_build_failure: true
on_build_status_changed: false
build_script:
- ps: >-
if(($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME -split "/")[0] -eq ($env:APPVEYOR_REPO_NAME -split "/")[0]) {
@@ -54,15 +38,13 @@ build_script:
- echo "Building $env:GN_CONFIG build"
- git config --global core.longpaths true
- cd ..
- mkdir src
- ps: if (Test-Path src\electron) { Remove-Item src\electron -Recurse }
- ps: Move-Item $env:APPVEYOR_BUILD_FOLDER -Destination src\electron
- ps: $env:CHROMIUM_BUILDTOOLS_PATH="$pwd\src\buildtools"
- ps: $env:SCCACHE_PATH="$pwd\src\electron\external_binaries\sccache.exe"
- ps: >-
if ($env:GN_CONFIG -eq 'release') {
$env:GCLIENT_EXTRA_ARGS="$env:GCLIENT_EXTRA_ARGS --custom-var=checkout_boto=True --custom-var=checkout_requests=True"
} else {
$env:NINJA_STATUS="[%r processes, %f/%t @ %o/s : %es] "
}
- >-
gclient config
@@ -77,9 +59,8 @@ build_script:
- gn check out/Default //electron:electron_lib
- gn check out/Default //electron:electron_app
- gn check out/Default //electron:manifests
- gn check out/Default //electron/shell/common/api:mojo
- gn check out/Default //electron/atom/common/api:mojo
- ninja -C out/Default electron:electron_app
- if "%GN_CONFIG%"=="testing" ( python C:\Users\electron\depot_tools\post_build_ninja_summary.py -C out\Default )
- gn gen out/ffmpeg "--args=import(\"//electron/build/args/ffmpeg.gn\") %GN_EXTRA_ARGS%"
- ninja -C out/ffmpeg electron:electron_ffmpeg_zip
- ninja -C out/Default electron:electron_dist_zip
@@ -132,11 +113,11 @@ deploy_script:
if (Test-Path Env:\ELECTRON_RELEASE) {
if (Test-Path Env:\UPLOAD_TO_S3) {
Write-Output "Uploading Electron release distribution to s3"
& python script\release\uploaders\upload.py --upload_to_s3
& python script\upload.py --upload_to_s3
} else {
Write-Output "Uploading Electron release distribution to github releases"
& python script\release\uploaders\upload.py
& python script\upload.py
}
} elseif (Test-Path Env:\TEST_WOA) {
node script/release/ci-release-build.js --job=electron-woa-testing --ci=VSTS --armTest --appveyorJobId=$env:APPVEYOR_JOB_ID $env:APPVEYOR_REPO_BRANCH
node script/ci-release-build.js --job=electron-woa-testing --ci=VSTS --armTest --appveyorJobId=$env:APPVEYOR_JOB_ID $env:APPVEYOR_REPO_BRANCH
}

View File

@@ -2,23 +2,21 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/atom_content_client.h"
#include "atom/app/atom_content_client.h"
#include <string>
#include <utility>
#include <vector>
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/common/content_constants.h"
#include "electron/buildflags/buildflags.h"
#include "ppapi/buildflags/buildflags.h"
#include "shell/browser/atom_paths.h"
#include "shell/common/options_switches.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "url/url_constants.h"
@@ -32,8 +30,8 @@
#endif // defined(WIDEVINE_CDM_AVAILABLE)
#if BUILDFLAG(ENABLE_PDF_VIEWER)
#include "atom/common/atom_constants.h"
#include "pdf/pdf.h"
#include "shell/common/atom_constants.h"
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
#if BUILDFLAG(ENABLE_PLUGINS)
@@ -41,7 +39,7 @@
#include "ppapi/shared_impl/ppapi_permissions.h"
#endif // BUILDFLAG(ENABLE_PLUGINS)
namespace electron {
namespace atom {
namespace {
@@ -191,24 +189,24 @@ AtomContentClient::AtomContentClient() {}
AtomContentClient::~AtomContentClient() {}
base::string16 AtomContentClient::GetLocalizedString(int message_id) {
base::string16 AtomContentClient::GetLocalizedString(int message_id) const {
return l10n_util::GetStringUTF16(message_id);
}
base::StringPiece AtomContentClient::GetDataResource(
int resource_id,
ui::ScaleFactor scale_factor) {
ui::ScaleFactor scale_factor) const {
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
resource_id, scale_factor);
}
gfx::Image& AtomContentClient::GetNativeImageNamed(int resource_id) {
gfx::Image& AtomContentClient::GetNativeImageNamed(int resource_id) const {
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
resource_id);
}
base::RefCountedMemory* AtomContentClient::GetDataResourceBytes(
int resource_id) {
int resource_id) const {
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
resource_id);
}
@@ -273,4 +271,8 @@ void AtomContentClient::AddContentDecryptionModules(
}
}
} // namespace electron
bool AtomContentClient::IsDataResourceGzipped(int resource_id) const {
return ui::ResourceBundle::GetSharedInstance().IsGzipped(resource_id);
}
} // namespace atom

View File

@@ -2,17 +2,16 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_ATOM_CONTENT_CLIENT_H_
#define SHELL_APP_ATOM_CONTENT_CLIENT_H_
#ifndef ATOM_APP_ATOM_CONTENT_CLIENT_H_
#define ATOM_APP_ATOM_CONTENT_CLIENT_H_
#include <set>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "content/public/common/content_client.h"
namespace electron {
namespace atom {
class AtomContentClient : public content::ContentClient {
public:
@@ -21,21 +20,23 @@ class AtomContentClient : public content::ContentClient {
protected:
// content::ContentClient:
base::string16 GetLocalizedString(int message_id) override;
base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) override;
gfx::Image& GetNativeImageNamed(int resource_id) override;
base::RefCountedMemory* GetDataResourceBytes(int resource_id) override;
base::string16 GetLocalizedString(int message_id) const override;
base::StringPiece GetDataResource(int resource_id,
ui::ScaleFactor) const override;
gfx::Image& GetNativeImageNamed(int resource_id) const override;
base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override;
void AddAdditionalSchemes(Schemes* schemes) override;
void AddPepperPlugins(
std::vector<content::PepperPluginInfo>* plugins) override;
void AddContentDecryptionModules(
std::vector<content::CdmInfo>* cdms,
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) override;
bool IsDataResourceGzipped(int resource_id) const override;
private:
DISALLOW_COPY_AND_ASSIGN(AtomContentClient);
};
} // namespace electron
} // namespace atom
#endif // SHELL_APP_ATOM_CONTENT_CLIENT_H_
#endif // ATOM_APP_ATOM_CONTENT_CLIENT_H_

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_ATOM_LIBRARY_MAIN_H_
#define SHELL_APP_ATOM_LIBRARY_MAIN_H_
#ifndef ATOM_APP_ATOM_LIBRARY_MAIN_H_
#define ATOM_APP_ATOM_LIBRARY_MAIN_H_
#include "build/build_config.h"
#include "electron/buildflags/buildflags.h"
@@ -20,4 +20,4 @@ __attribute__((visibility("default"))) int AtomInitializeICUandStartNode(
}
#endif // OS_MACOSX
#endif // SHELL_APP_ATOM_LIBRARY_MAIN_H_
#endif // ATOM_APP_ATOM_LIBRARY_MAIN_H_

View File

@@ -2,24 +2,24 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/atom_library_main.h"
#include "atom/app/atom_library_main.h"
#include "atom/app/atom_main_delegate.h"
#include "atom/app/node_main.h"
#include "atom/common/atom_command_line.h"
#include "atom/common/mac/main_application_bundle.h"
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "content/public/app/content_main.h"
#include "shell/app/atom_main_delegate.h"
#include "shell/app/node_main.h"
#include "shell/common/atom_command_line.h"
#include "shell/common/mac/main_application_bundle.h"
int AtomMain(int argc, char* argv[]) {
electron::AtomMainDelegate delegate;
atom::AtomMainDelegate delegate;
content::ContentMainParams params(&delegate);
params.argc = argc;
params.argv = const_cast<const char**>(argv);
electron::AtomCommandLine::Init(argc, argv);
atom::AtomCommandLine::Init(argc, argv);
return content::ContentMain(params);
}
@@ -28,11 +28,11 @@ int AtomInitializeICUandStartNode(int argc, char* argv[]) {
base::AtExitManager atexit_manager;
base::mac::ScopedNSAutoreleasePool pool;
base::mac::SetOverrideFrameworkBundlePath(
electron::MainApplicationBundlePath()
atom::MainApplicationBundlePath()
.Append("Contents")
.Append("Frameworks")
.Append(ELECTRON_PRODUCT_NAME " Framework.framework"));
.Append(ATOM_PRODUCT_NAME " Framework.framework"));
base::i18n::InitializeICU();
return electron::NodeMain(argc, argv);
return atom::NodeMain(argc, argv);
}
#endif

View File

@@ -1,7 +1,3 @@
// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
int main(int argc, char* argv[]) {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/atom_main.h"
#include "atom/app/atom_main.h"
#include <algorithm>
#include <cstdlib>
@@ -17,33 +17,33 @@
#include <shellscalingapi.h>
#include <tchar.h>
#include "atom/app/atom_main_delegate.h"
#include "atom/app/command_line_args.h"
#include "atom/common/crash_reporter/win/crash_service_main.h"
#include "base/environment.h"
#include "base/process/launch.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/windows_version.h"
#include "content/public/app/sandbox_helper_win.h"
#include "sandbox/win/src/sandbox_types.h"
#include "shell/app/atom_main_delegate.h"
#include "shell/app/command_line_args.h"
#include "shell/common/crash_reporter/win/crash_service_main.h"
#elif defined(OS_LINUX) // defined(OS_WIN)
#include <unistd.h>
#include <cstdio>
#include "atom/app/atom_main_delegate.h" // NOLINT
#include "content/public/app/content_main.h"
#include "shell/app/atom_main_delegate.h" // NOLINT
#else // defined(OS_LINUX)
#else // defined(OS_LINUX)
#include <mach-o/dyld.h>
#include <unistd.h>
#include <cstdio>
#include "shell/app/atom_library_main.h"
#include "atom/app/atom_library_main.h"
#endif // defined(OS_MACOSX)
#include "atom/app/node_main.h"
#include "atom/common/atom_command_line.h"
#include "atom/common/atom_constants.h"
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "electron/buildflags/buildflags.h"
#include "shell/app/node_main.h"
#include "shell/common/atom_command_line.h"
#include "shell/common/atom_constants.h"
#if defined(HELPER_EXECUTABLE) && !defined(MAS_BUILD)
#include "sandbox/mac/seatbelt_exec.h" // nogncheck
@@ -125,7 +125,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
#endif
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
bool run_as_node = IsEnvSet(electron::kRunAsNode);
bool run_as_node = IsEnvSet(atom::kRunAsNode);
#else
bool run_as_node = false;
#endif
@@ -141,7 +141,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
if (run_as_node) {
base::AtExitManager atexit_manager;
base::i18n::InitializeICU();
auto ret = electron::NodeMain(argv.size(), argv.data());
auto ret = atom::NodeMain(argv.size(), argv.data());
std::for_each(argv.begin(), argv.end(), free);
return ret;
}
@@ -154,17 +154,17 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
return crash_service::Main(&argv);
}
if (!electron::CheckCommandLineArguments(arguments.argc, arguments.argv))
if (!atom::CheckCommandLineArguments(arguments.argc, arguments.argv))
return -1;
sandbox::SandboxInterfaceInfo sandbox_info = {0};
content::InitializeSandboxInfo(&sandbox_info);
electron::AtomMainDelegate delegate;
atom::AtomMainDelegate delegate;
content::ContentMainParams params(&delegate);
params.instance = instance;
params.sandbox_info = &sandbox_info;
electron::AtomCommandLine::Init(arguments.argc, arguments.argv);
atom::AtomCommandLine::Init(arguments.argc, arguments.argv);
return content::ContentMain(params);
}
@@ -174,18 +174,18 @@ int main(int argc, char* argv[]) {
FixStdioStreams();
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
if (IsEnvSet(electron::kRunAsNode)) {
if (IsEnvSet(atom::kRunAsNode)) {
base::i18n::InitializeICU();
base::AtExitManager atexit_manager;
return electron::NodeMain(argc, argv);
return atom::NodeMain(argc, argv);
}
#endif
electron::AtomMainDelegate delegate;
atom::AtomMainDelegate delegate;
content::ContentMainParams params(&delegate);
params.argc = argc;
params.argv = const_cast<const char**>(argv);
electron::AtomCommandLine::Init(argc, argv);
atom::AtomCommandLine::Init(argc, argv);
return content::ContentMain(params);
}
@@ -195,7 +195,7 @@ int main(int argc, char* argv[]) {
FixStdioStreams();
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
if (IsEnvSet(electron::kRunAsNode)) {
if (IsEnvSet(atom::kRunAsNode)) {
return AtomInitializeICUandStartNode(argc, argv);
}
#endif

View File

@@ -2,9 +2,9 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_ATOM_MAIN_H_
#define SHELL_APP_ATOM_MAIN_H_
#ifndef ATOM_APP_ATOM_MAIN_H_
#define ATOM_APP_ATOM_MAIN_H_
#include "content/public/app/content_main.h"
#endif // SHELL_APP_ATOM_MAIN_H_
#endif // ATOM_APP_ATOM_MAIN_H_

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/atom_main_delegate.h"
#include "atom/app/atom_main_delegate.h"
#include <iostream>
#include <memory>
@@ -12,6 +12,13 @@
#include <glib.h> // for g_setenv()
#endif
#include "atom/app/atom_content_client.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/browser/relauncher.h"
#include "atom/common/options_switches.h"
#include "atom/renderer/atom_renderer_client.h"
#include "atom/renderer/atom_sandboxed_renderer_client.h"
#include "atom/utility/atom_content_utility_client.h"
#include "base/command_line.h"
#include "base/debug/stack_trace.h"
#include "base/environment.h"
@@ -24,32 +31,30 @@
#include "ipc/ipc_buildflags.h"
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/sandbox/switches.h"
#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
#include "shell/app/atom_content_client.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/atom_gpu_client.h"
#include "shell/browser/feature_list.h"
#include "shell/browser/relauncher.h"
#include "shell/common/options_switches.h"
#include "shell/renderer/atom_renderer_client.h"
#include "shell/renderer/atom_sandboxed_renderer_client.h"
#include "shell/utility/atom_content_utility_client.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"
#if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED)
#define IPC_MESSAGE_MACROS_LOG_ENABLED
#include "content/public/common/content_ipc_logging.h"
#define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \
content::RegisterIPCLogger(msg_id, logger)
#include "atom/common/common_message_generator.h"
#endif
#if defined(OS_MACOSX)
#include "shell/app/atom_main_delegate_mac.h"
#include "atom/app/atom_main_delegate_mac.h"
#endif
#if defined(OS_WIN)
#include "base/win/win_util.h"
#if defined(_WIN64)
#include "shell/common/crash_reporter/crash_reporter_win.h"
#include "atom/common/crash_reporter/crash_reporter_win.h"
#endif
#endif
namespace electron {
namespace atom {
namespace {
@@ -147,10 +152,7 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
#if defined(DEBUG)
// Print logging to debug.log on Windows
settings.logging_dest = logging::LOG_TO_ALL;
base::FilePath log_filename;
base::PathService::Get(base::DIR_EXE, &log_filename);
log_filename = log_filename.AppendASCII("debug.log");
settings.log_file_path = log_filename.value().c_str();
settings.log_file = L"debug.log";
settings.lock_log = logging::LOCK_LOG_FILE;
settings.delete_old = logging::DELETE_OLD_LOG_FILE;
#else
@@ -183,9 +185,6 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
if (env->HasVar("ELECTRON_DISABLE_SANDBOX"))
command_line->AppendSwitch(service_manager::switches::kNoSandbox);
tracing_sampler_profiler_ =
tracing::TracingSamplerProfiler::CreateOnMainThread();
chrome::RegisterPathProvider();
#if defined(OS_MACOSX)
@@ -213,21 +212,6 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
<< " is not supported. See https://crbug.com/638180.";
#endif
#if defined(MAS_BUILD)
// In MAS build we are using --disable-remote-core-animation.
//
// According to ccameron:
// If you're running with --disable-remote-core-animation, you may want to
// also run with --disable-gpu-memory-buffer-compositor-resources as well.
// That flag makes it so we use regular GL textures instead of IOSurfaces
// for compositor resources. IOSurfaces are very heavyweight to
// create/destroy, but they can be displayed directly by CoreAnimation (and
// --disable-remote-core-animation makes it so we don't use this property,
// so they're just heavyweight with no upside).
command_line->AppendSwitch(
::switches::kDisableGpuMemoryBufferCompositorResources);
#endif
content_client_ = std::make_unique<AtomContentClient>();
SetContentClient(content_client_.get());
@@ -292,10 +276,6 @@ void AtomMainDelegate::PreSandboxStartup() {
}
void AtomMainDelegate::PreCreateMainMessageLoop() {
// This is initialized early because the service manager reads some feature
// flags and we need to make sure the feature list is initialized before the
// service manager reads the features.
InitializeFeatureList();
#if defined(OS_MACOSX)
RegisterAtomCrApp();
#endif
@@ -306,11 +286,6 @@ content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
return browser_client_.get();
}
content::ContentGpuClient* AtomMainDelegate::CreateContentGpuClient() {
gpu_client_.reset(new AtomGpuClient);
return gpu_client_.get();
}
content::ContentRendererClient*
AtomMainDelegate::CreateContentRendererClient() {
auto* command_line = base::CommandLine::ForCurrentProcess();
@@ -339,6 +314,10 @@ int AtomMainDelegate::RunProcess(
}
#if defined(OS_MACOSX)
bool AtomMainDelegate::ShouldSendMachPort(const std::string& process_type) {
return process_type != kRelauncherProcess;
}
bool AtomMainDelegate::DelaySandboxInitialization(
const std::string& process_type) {
return process_type == kRelauncherProcess;
@@ -353,4 +332,4 @@ bool AtomMainDelegate::ShouldCreateFeatureList() {
return false;
}
} // namespace electron
} // namespace atom

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_ATOM_MAIN_DELEGATE_H_
#define SHELL_APP_ATOM_MAIN_DELEGATE_H_
#ifndef ATOM_APP_ATOM_MAIN_DELEGATE_H_
#define ATOM_APP_ATOM_MAIN_DELEGATE_H_
#include <memory>
#include <string>
@@ -11,11 +11,7 @@
#include "content/public/app/content_main_delegate.h"
#include "content/public/common/content_client.h"
namespace tracing {
class TracingSamplerProfiler;
}
namespace electron {
namespace atom {
void LoadResourceBundle(const std::string& locale);
@@ -31,13 +27,13 @@ class AtomMainDelegate : public content::ContentMainDelegate {
void PreCreateMainMessageLoop() override;
void PostEarlyInitialization(bool is_running_tests) override;
content::ContentBrowserClient* CreateContentBrowserClient() override;
content::ContentGpuClient* CreateContentGpuClient() override;
content::ContentRendererClient* CreateContentRendererClient() override;
content::ContentUtilityClient* CreateContentUtilityClient() override;
int RunProcess(
const std::string& process_type,
const content::MainFunctionParams& main_function_params) override;
#if defined(OS_MACOSX)
bool ShouldSendMachPort(const std::string& process_type) override;
bool DelaySandboxInitialization(const std::string& process_type) override;
#endif
bool ShouldLockSchemeRegistry() override;
@@ -52,14 +48,12 @@ class AtomMainDelegate : public content::ContentMainDelegate {
std::unique_ptr<content::ContentBrowserClient> browser_client_;
std::unique_ptr<content::ContentClient> content_client_;
std::unique_ptr<content::ContentGpuClient> gpu_client_;
std::unique_ptr<content::ContentRendererClient> renderer_client_;
std::unique_ptr<content::ContentUtilityClient> utility_client_;
std::unique_ptr<tracing::TracingSamplerProfiler> tracing_sampler_profiler_;
DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate);
};
} // namespace electron
} // namespace atom
#endif // SHELL_APP_ATOM_MAIN_DELEGATE_H_
#endif // ATOM_APP_ATOM_MAIN_DELEGATE_H_

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_ATOM_MAIN_DELEGATE_MAC_H_
#define SHELL_APP_ATOM_MAIN_DELEGATE_MAC_H_
#ifndef ATOM_APP_ATOM_MAIN_DELEGATE_MAC_H_
#define ATOM_APP_ATOM_MAIN_DELEGATE_MAC_H_
namespace electron {
namespace atom {
// Initializes NSApplication.
void RegisterAtomCrApp();
} // namespace electron
} // namespace atom
#endif // SHELL_APP_ATOM_MAIN_DELEGATE_MAC_H_
#endif // ATOM_APP_ATOM_MAIN_DELEGATE_MAC_H_

View File

@@ -2,10 +2,11 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/atom_main_delegate.h"
#include <string>
#include "atom/app/atom_main_delegate.h"
#include "atom/browser/mac/atom_application.h"
#include "atom/common/application_info.h"
#include "atom/common/mac/main_application_bundle.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/mac/bundle_locations.h"
@@ -15,11 +16,8 @@
#include "base/strings/sys_string_conversions.h"
#include "content/common/mac_helpers.h"
#include "content/public/common/content_paths.h"
#include "shell/browser/mac/atom_application.h"
#include "shell/common/application_info.h"
#include "shell/common/mac/main_application_bundle.h"
namespace electron {
namespace atom {
namespace {
@@ -55,13 +53,13 @@ base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path,
void AtomMainDelegate::OverrideFrameworkBundlePath() {
base::mac::SetOverrideFrameworkBundlePath(
GetFrameworksPath().Append(ELECTRON_PRODUCT_NAME " Framework.framework"));
GetFrameworksPath().Append(ATOM_PRODUCT_NAME " Framework.framework"));
}
void AtomMainDelegate::OverrideChildProcessPath() {
base::FilePath frameworks_path = GetFrameworksPath();
base::FilePath helper_path =
GetHelperAppPath(frameworks_path, ELECTRON_PRODUCT_NAME);
GetHelperAppPath(frameworks_path, ATOM_PRODUCT_NAME);
if (!base::PathExists(helper_path))
helper_path = GetHelperAppPath(frameworks_path, GetApplicationName());
if (!base::PathExists(helper_path))
@@ -85,4 +83,4 @@ void RegisterAtomCrApp() {
[AtomApplication sharedApplication];
}
} // namespace electron
} // namespace atom

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/command_line_args.h"
#include "atom/app/command_line_args.h"
namespace {
@@ -33,7 +33,7 @@ bool IsUrlArg(const base::CommandLine::CharType* arg) {
} // namespace
namespace electron {
namespace atom {
bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) {
const base::CommandLine::StringType dashdash(2, '-');
@@ -50,4 +50,4 @@ bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) {
return true;
}
} // namespace electron
} // namespace atom

View File

@@ -2,15 +2,15 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_COMMAND_LINE_ARGS_H_
#define SHELL_APP_COMMAND_LINE_ARGS_H_
#ifndef ATOM_APP_COMMAND_LINE_ARGS_H_
#define ATOM_APP_COMMAND_LINE_ARGS_H_
#include "base/command_line.h"
namespace electron {
namespace atom {
bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv);
} // namespace electron
} // namespace atom
#endif // SHELL_APP_COMMAND_LINE_ARGS_H_
#endif // ATOM_APP_COMMAND_LINE_ARGS_H_

65
atom/app/manifests.cc Normal file
View File

@@ -0,0 +1,65 @@
// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/app/manifests.h"
#include "base/no_destructor.h"
#include "electron/atom/common/api/api.mojom.h"
#include "printing/buildflags/buildflags.h"
#include "services/proxy_resolver/public/cpp/manifest.h"
#include "services/service_manager/public/cpp/manifest_builder.h"
#if BUILDFLAG(ENABLE_PRINTING)
#include "components/services/pdf_compositor/public/cpp/manifest.h"
#endif
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
#include "chrome/services/printing/public/cpp/manifest.h"
#endif
namespace {
// TODO(https://crbug.com/781334): Remove these helpers and just update the
// manifest definitions to be marked out-of-process. This is here only to avoid
// extra churn when transitioning away from content_packaged_services.
service_manager::Manifest MakeOutOfProcess(
const service_manager::Manifest& manifest) {
// cpplint.py emits a false positive [build/include_what_you_use]
service_manager::Manifest copy(manifest); // NOLINT
copy.options.execution_mode =
service_manager::Manifest::ExecutionMode::kOutOfProcessBuiltin;
return copy;
}
} // namespace
const service_manager::Manifest& GetElectronContentBrowserOverlayManifest() {
static base::NoDestructor<service_manager::Manifest> manifest{
service_manager::ManifestBuilder()
.WithDisplayName("Electron (browser process)")
.RequireCapability("device", "device:geolocation_control")
.RequireCapability("proxy_resolver", "factory")
.RequireCapability("chrome_printing", "converter")
.RequireCapability("pdf_compositor", "compositor")
.ExposeInterfaceFilterCapability_Deprecated(
"navigation:frame", "renderer",
service_manager::Manifest::InterfaceList<
atom::mojom::ElectronBrowser>())
.Build()};
return *manifest;
}
const std::vector<service_manager::Manifest>&
GetElectronBuiltinServiceManifests() {
static base::NoDestructor<std::vector<service_manager::Manifest>> manifests{{
MakeOutOfProcess(proxy_resolver::GetManifest()),
#if BUILDFLAG(ENABLE_PRINTING)
MakeOutOfProcess(printing::GetPdfCompositorManifest()),
#endif
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
MakeOutOfProcess(GetChromePrintingManifest()),
#endif
}};
return *manifests;
}

View File

@@ -1,14 +1,16 @@
// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_MANIFESTS_H_
#define SHELL_APP_MANIFESTS_H_
#include <vector>
#include "services/service_manager/public/cpp/manifest.h"
const service_manager::Manifest& GetElectronContentBrowserOverlayManifest();
#endif // SHELL_APP_MANIFESTS_H_
// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_APP_MANIFESTS_H_
#define ATOM_APP_MANIFESTS_H_
#include <vector>
#include "services/service_manager/public/cpp/manifest.h"
const service_manager::Manifest& GetElectronContentBrowserOverlayManifest();
const std::vector<service_manager::Manifest>&
GetElectronBuiltinServiceManifests();
#endif // ATOM_APP_MANIFESTS_H_

View File

@@ -2,45 +2,34 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/node_main.h"
#include "atom/app/node_main.h"
#include <memory>
#include <string>
#include <utility>
#include "atom/app/uv_task_runner.h"
#include "atom/browser/javascript_environment.h"
#include "atom/browser/node_debugger.h"
#include "atom/common/api/electron_bindings.h"
#include "atom/common/atom_version.h"
#include "atom/common/crash_reporter/crash_reporter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_bindings.h"
#include "atom/common/node_includes.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/task/thread_pool/thread_pool.h"
#include "base/threading/thread_task_runner_handle.h"
#include "electron/electron_version.h"
#include "gin/array_buffer.h"
#include "gin/public/isolate_holder.h"
#include "gin/v8_initializer.h"
#include "native_mate/dictionary.h"
#include "shell/app/uv_task_runner.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/node_debugger.h"
#include "shell/common/api/electron_bindings.h"
#include "shell/common/crash_reporter/crash_reporter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/node_bindings.h"
#include "shell/common/node_includes.h"
#if defined(_WIN64)
#include "shell/common/crash_reporter/crash_reporter_win.h"
#include "atom/common/crash_reporter/crash_reporter_win.h"
#endif
namespace electron {
#if !defined(OS_LINUX)
void AddExtraParameter(const std::string& key, const std::string& value) {
crash_reporter::CrashReporter::GetInstance()->AddExtraParameter(key, value);
}
void RemoveExtraParameter(const std::string& key) {
crash_reporter::CrashReporter::GetInstance()->RemoveExtraParameter(key);
}
#endif
namespace atom {
int NodeMain(int argc, char* argv[]) {
base::CommandLine::Init(argc, argv);
@@ -103,17 +92,11 @@ int NodeMain(int argc, char* argv[]) {
// Setup process.crashReporter.start in child node processes
auto reporter = mate::Dictionary::CreateEmpty(gin_env.isolate());
reporter.SetMethod("start", &crash_reporter::CrashReporter::StartInstance);
#if !defined(OS_LINUX)
reporter.SetMethod("addExtraParameter", &AddExtraParameter);
reporter.SetMethod("removeExtraParameter", &RemoveExtraParameter);
#endif
process.Set("crashReporter", reporter);
mate::Dictionary versions;
if (process.Get("versions", &versions)) {
versions.SetReadOnly(ELECTRON_PROJECT_NAME, ELECTRON_VERSION_STRING);
versions.SetReadOnly(ATOM_PROJECT_NAME, ATOM_VERSION_STRING);
}
node::LoadEnvironment(env);
@@ -159,4 +142,4 @@ int NodeMain(int argc, char* argv[]) {
return exit_code;
}
} // namespace electron
} // namespace atom

View File

@@ -2,13 +2,13 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_NODE_MAIN_H_
#define SHELL_APP_NODE_MAIN_H_
#ifndef ATOM_APP_NODE_MAIN_H_
#define ATOM_APP_NODE_MAIN_H_
namespace electron {
namespace atom {
int NodeMain(int argc, char* argv[]);
} // namespace electron
} // namespace atom
#endif // SHELL_APP_NODE_MAIN_H_
#endif // ATOM_APP_NODE_MAIN_H_

View File

@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>${ELECTRON_BUNDLE_ID}</string>
<string>${ATOM_BUNDLE_ID}</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>

View File

@@ -4,11 +4,11 @@
#include <utility>
#include "shell/app/uv_task_runner.h"
#include "atom/app/uv_task_runner.h"
#include "base/stl_util.h"
namespace electron {
namespace atom {
UvTaskRunner::UvTaskRunner(uv_loop_t* loop) : loop_(loop) {}
@@ -43,7 +43,7 @@ bool UvTaskRunner::PostNonNestableDelayedTask(const base::Location& from_here,
// static
void UvTaskRunner::OnTimeout(uv_timer_t* timer) {
UvTaskRunner* self = static_cast<UvTaskRunner*>(timer->data);
if (!base::Contains(self->tasks_, timer))
if (!ContainsKey(self->tasks_, timer))
return;
std::move(self->tasks_[timer]).Run();
@@ -57,4 +57,4 @@ void UvTaskRunner::OnClose(uv_handle_t* handle) {
delete reinterpret_cast<uv_timer_t*>(handle);
}
} // namespace electron
} // namespace atom

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_APP_UV_TASK_RUNNER_H_
#define SHELL_APP_UV_TASK_RUNNER_H_
#ifndef ATOM_APP_UV_TASK_RUNNER_H_
#define ATOM_APP_UV_TASK_RUNNER_H_
#include <map>
@@ -12,7 +12,7 @@
#include "base/single_thread_task_runner.h"
#include "uv.h" // NOLINT(build/include)
namespace electron {
namespace atom {
// TaskRunner implementation that posts tasks into libuv's default loop.
class UvTaskRunner : public base::SingleThreadTaskRunner {
@@ -40,6 +40,6 @@ class UvTaskRunner : public base::SingleThreadTaskRunner {
DISALLOW_COPY_AND_ASSIGN(UvTaskRunner);
};
} // namespace electron
} // namespace atom
#endif // SHELL_APP_UV_TASK_RUNNER_H_
#endif // ATOM_APP_UV_TASK_RUNNER_H_

View File

@@ -2,16 +2,35 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_app.h"
#include "atom/browser/api/atom_api_app.h"
#include <string>
#include <vector>
#include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/api/atom_api_session.h"
#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/browser/api/gpuinfo_manager.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/atom_paths.h"
#include "atom/browser/login_handler.h"
#include "atom/browser/relauncher.h"
#include "atom/common/application_info.h"
#include "atom/common/atom_command_line.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/native_mate_converters/network_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/optional.h"
#include "base/path_service.h"
#include "base/system/sys_info.h"
#include "chrome/browser/browser_process.h"
@@ -31,64 +50,24 @@
#include "net/ssl/client_cert_identity.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "services/service_manager/sandbox/switches.h"
#include "shell/browser/api/atom_api_menu.h"
#include "shell/browser/api/atom_api_session.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/api/gpuinfo_manager.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/browser/atom_paths.h"
#include "shell/browser/login_handler.h"
#include "shell/browser/relauncher.h"
#include "shell/common/application_info.h"
#include "shell/common/atom_command_line.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/net_converter.h"
#include "shell/common/native_mate_converters/network_converter.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
#if defined(OS_WIN)
#include "atom/browser/ui/win/jump_list.h"
#include "base/strings/utf_string_conversions.h"
#include "shell/browser/ui/win/jump_list.h"
#endif
#if defined(OS_MACOSX)
#include <CoreFoundation/CoreFoundation.h>
#include "shell/browser/ui/cocoa/atom_bundle_mover.h"
#include "atom/browser/ui/cocoa/atom_bundle_mover.h"
#endif
using electron::Browser;
using atom::Browser;
namespace mate {
#if defined(OS_WIN)
template <>
struct Converter<electron::ProcessIntegrityLevel> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::ProcessIntegrityLevel value) {
switch (value) {
case electron::ProcessIntegrityLevel::Untrusted:
return mate::StringToV8(isolate, "untrusted");
case electron::ProcessIntegrityLevel::Low:
return mate::StringToV8(isolate, "low");
case electron::ProcessIntegrityLevel::Medium:
return mate::StringToV8(isolate, "medium");
case electron::ProcessIntegrityLevel::High:
return mate::StringToV8(isolate, "high");
default:
return mate::StringToV8(isolate, "unknown");
}
}
};
template <>
struct Converter<Browser::UserTask> {
static bool FromV8(v8::Isolate* isolate,
@@ -110,9 +89,9 @@ struct Converter<Browser::UserTask> {
}
};
using electron::JumpListCategory;
using electron::JumpListItem;
using electron::JumpListResult;
using atom::JumpListCategory;
using atom::JumpListItem;
using atom::JumpListResult;
template <>
struct Converter<JumpListItem::Type> {
@@ -375,12 +354,33 @@ struct Converter<content::CertificateRequestResultType> {
} // namespace mate
namespace electron {
namespace atom {
ProcessMetric::ProcessMetric(int type,
base::ProcessId pid,
std::unique_ptr<base::ProcessMetrics> metrics) {
this->type = type;
this->pid = pid;
this->metrics = std::move(metrics);
}
ProcessMetric::~ProcessMetric() = default;
namespace api {
namespace {
class AppIdProcessIterator : public base::ProcessIterator {
public:
AppIdProcessIterator() : base::ProcessIterator(nullptr) {}
protected:
bool IncludeEntry() override {
return (entry().parent_pid() == base::GetCurrentProcId() ||
entry().pid() == base::GetCurrentProcId());
}
};
IconLoader::IconSize GetIconSizeByString(const std::string& size) {
if (size == "small") {
return IconLoader::IconSize::SMALL;
@@ -429,7 +429,7 @@ int GetPathConstant(const std::string& name) {
}
bool NotificationCallbackWrapper(
const base::RepeatingCallback<
const base::Callback<
void(const base::CommandLine::StringVector& command_line,
const base::FilePath& current_directory)>& callback,
const base::CommandLine::StringVector& cmd,
@@ -488,13 +488,22 @@ void OnClientCertificateSelected(
if (cert->EqualsExcludingChain((*identities)[i]->certificate())) {
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
std::move((*identities)[i]),
base::BindRepeating(&GotPrivateKey, delegate, std::move(cert)));
base::Bind(&GotPrivateKey, delegate, std::move(cert)));
break;
}
}
}
}
void PassLoginInformation(scoped_refptr<LoginHandler> login_handler,
mate::Arguments* args) {
base::string16 username, password;
if (args->GetNext(&username) && args->GetNext(&password))
login_handler->Login(username, password);
else
login_handler->CancelAuth();
}
#if defined(USE_NSS_CERTS)
int ImportIntoCertStore(CertificateManagerModel* model,
const base::DictionaryValue& options) {
@@ -539,8 +548,8 @@ App::App(v8::Isolate* isolate) {
content::GpuDataManager::GetInstance()->AddObserver(this);
base::ProcessId pid = base::GetCurrentProcId();
auto process_metric = std::make_unique<electron::ProcessMetric>(
content::PROCESS_TYPE_BROWSER, base::GetCurrentProcessHandle(),
auto process_metric = std::make_unique<atom::ProcessMetric>(
content::PROCESS_TYPE_BROWSER, pid,
base::ProcessMetrics::CreateCurrentProcessMetrics());
app_metrics_[pid] = std::move(process_metric);
Init(isolate);
@@ -657,6 +666,24 @@ void App::OnNewWindowForTab() {
}
#endif
void App::OnLogin(scoped_refptr<LoginHandler> login_handler,
const base::DictionaryValue& request_details) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
bool prevent_default = false;
content::WebContents* web_contents = login_handler->GetWebContents();
if (web_contents) {
prevent_default = Emit(
"login", WebContents::FromOrCreate(isolate(), web_contents),
request_details, *login_handler->auth_info(),
base::Bind(&PassLoginInformation, base::RetainedRef(login_handler)));
}
// Default behavior is to always cancel the auth.
if (!prevent_default)
login_handler->CancelAuth();
}
bool App::CanCreateWindow(
content::RenderFrameHost* opener,
const GURL& opener_url,
@@ -696,7 +723,8 @@ void App::AllowCertificateError(
const GURL& request_url,
bool is_main_frame_request,
bool strict_enforcement,
const base::RepeatingCallback<void(content::CertificateRequestResultType)>&
bool expired_previous_decision,
const base::Callback<void(content::CertificateRequestResultType)>&
callback) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
@@ -709,7 +737,7 @@ void App::AllowCertificateError(
callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
}
base::OnceClosure App::SelectClientCertificate(
void App::SelectClientCertificate(
content::WebContents* web_contents,
net::SSLCertRequestInfo* cert_request_info,
net::ClientCertIdentityList identities,
@@ -730,8 +758,8 @@ base::OnceClosure App::SelectClientCertificate(
Emit("select-client-certificate",
WebContents::FromOrCreate(isolate(), web_contents),
cert_request_info->host_and_port.ToString(), std::move(client_certs),
base::BindOnce(&OnClientCertificateSelected, isolate(),
shared_delegate, shared_identities));
base::Bind(&OnClientCertificateSelected, isolate(), shared_delegate,
shared_identities));
// Default to first certificate from the platform store.
if (!prevent_default) {
@@ -739,13 +767,8 @@ base::OnceClosure App::SelectClientCertificate(
(*shared_identities)[0]->certificate();
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
std::move((*shared_identities)[0]),
base::BindRepeating(&GotPrivateKey, shared_delegate, std::move(cert)));
base::Bind(&GotPrivateKey, shared_delegate, std::move(cert)));
}
return base::OnceClosure();
}
void App::OnGpuInfoUpdate() {
Emit("gpu-info-update");
}
void App::OnGpuProcessCrashed(base::TerminationStatus status) {
@@ -778,14 +801,6 @@ void App::BrowserChildProcessKilled(
void App::RenderProcessReady(content::RenderProcessHost* host) {
ChildProcessLaunched(content::PROCESS_TYPE_RENDERER,
host->GetProcess().Handle());
// TODO(jeremy): this isn't really the right place to be creating
// `WebContents` instances, but this was implicitly happening before in
// `RenderProcessPreferences`, so this is at least more explicit...
content::WebContents* web_contents =
AtomBrowserClient::Get()->GetWebContentsFromProcessID(host->GetID());
if (web_contents)
WebContents::FromOrCreate(v8::Isolate::GetCurrent(), web_contents);
}
void App::RenderProcessDisconnected(base::ProcessId host_pid) {
@@ -796,13 +811,15 @@ void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) {
auto pid = base::GetProcId(handle);
#if defined(OS_MACOSX)
auto metrics = base::ProcessMetrics::CreateProcessMetrics(
handle, content::BrowserChildProcessHost::GetPortProvider());
std::unique_ptr<base::ProcessMetrics> metrics(
base::ProcessMetrics::CreateProcessMetrics(
handle, content::BrowserChildProcessHost::GetPortProvider()));
#else
auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle);
std::unique_ptr<base::ProcessMetrics> metrics(
base::ProcessMetrics::CreateProcessMetrics(handle));
#endif
app_metrics_[pid] = std::make_unique<electron::ProcessMetric>(
process_type, handle, std::move(metrics));
app_metrics_[pid] = std::make_unique<atom::ProcessMetric>(process_type, pid,
std::move(metrics));
}
void App::ChildProcessDisconnected(base::ProcessId pid) {
@@ -818,14 +835,14 @@ void App::SetAppPath(const base::FilePath& app_path) {
}
#if !defined(OS_MACOSX)
void App::SetAppLogsPath(base::Optional<base::FilePath> custom_path,
mate::Arguments* args) {
if (custom_path.has_value()) {
if (!custom_path->IsAbsolute()) {
void App::SetAppLogsPath(mate::Arguments* args) {
base::FilePath custom_path;
if (args->GetNext(&custom_path)) {
if (!custom_path.IsAbsolute()) {
args->ThrowError("Path must be absolute");
return;
}
base::PathService::Override(DIR_APP_LOGS, custom_path.value());
base::PathService::Override(DIR_APP_LOGS, custom_path);
} else {
base::FilePath path;
if (base::PathService::Get(DIR_USER_DATA, &path)) {
@@ -840,22 +857,18 @@ void App::SetAppLogsPath(base::Optional<base::FilePath> custom_path,
base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) {
bool succeed = false;
base::FilePath path;
int key = GetPathConstant(name);
if (key >= 0) {
if (key >= 0)
succeed = base::PathService::Get(key, &path);
// If users try to get the logs path before setting a logs path,
// set the path to a sensible default and then try to get it again
if (!succeed && name == "logs") {
base::ThreadRestrictions::ScopedAllowIO allow_io;
SetAppLogsPath(base::Optional<base::FilePath>(), args);
succeed = base::PathService::Get(key, &path);
if (!succeed) {
if (name == "logs") {
args->ThrowError("Failed to get '" + name +
"' path: setAppLogsPath() must be called first.");
} else {
args->ThrowError("Failed to get '" + name + "' path");
}
}
if (!succeed)
args->ThrowError("Failed to get '" + name + "' path");
return path;
}
@@ -944,10 +957,10 @@ bool App::RequestSingleInstanceLock() {
base::FilePath user_dir;
base::PathService::Get(DIR_USER_DATA, &user_dir);
auto cb = base::BindRepeating(&App::OnSecondInstance, base::Unretained(this));
auto cb = base::Bind(&App::OnSecondInstance, base::Unretained(this));
process_singleton_.reset(new ProcessSingleton(
user_dir, base::BindRepeating(NotificationCallbackWrapper, cb)));
user_dir, base::Bind(NotificationCallbackWrapper, cb)));
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
case ProcessSingleton::NotifyResult::LOCK_ERROR:
@@ -982,7 +995,7 @@ bool App::Relaunch(mate::Arguments* js_args) {
}
if (!override_argv) {
const relauncher::StringVector& argv = electron::AtomCommandLine::argv();
const relauncher::StringVector& argv = atom::AtomCommandLine::argv();
return relauncher::RelaunchApp(argv);
}
@@ -1060,9 +1073,8 @@ void App::ImportCertificate(const base::DictionaryValue& options,
base::Value::ToUniquePtrValue(options.Clone()));
CertificateManagerModel::Create(
browser_context.get(),
base::BindRepeating(&App::OnCertificateManagerModelCreated,
base::Unretained(this), base::Passed(&copy),
callback));
base::Bind(&App::OnCertificateManagerModelCreated,
base::Unretained(this), base::Passed(&copy), callback));
return;
}
@@ -1195,40 +1207,9 @@ std::vector<mate::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
#endif
pid_dict.Set("cpu", cpu_dict);
pid_dict.Set("pid", process_metric.second->process.Pid());
pid_dict.Set("pid", process_metric.second->pid);
pid_dict.Set("type", content::GetProcessTypeNameInEnglish(
process_metric.second->type));
pid_dict.Set("creationTime",
process_metric.second->process.CreationTime().ToJsTime());
#if !defined(OS_LINUX)
auto memory_info = process_metric.second->GetMemoryInfo();
mate::Dictionary memory_dict = mate::Dictionary::CreateEmpty(isolate);
memory_dict.SetHidden("simple", true);
memory_dict.Set("workingSetSize",
static_cast<double>(memory_info.working_set_size >> 10));
memory_dict.Set(
"peakWorkingSetSize",
static_cast<double>(memory_info.peak_working_set_size >> 10));
#if defined(OS_WIN)
memory_dict.Set("privateBytes",
static_cast<double>(memory_info.private_bytes >> 10));
#endif
pid_dict.Set("memory", memory_dict);
#endif
#if defined(OS_MACOSX)
pid_dict.Set("sandboxed", process_metric.second->IsSandboxed());
#elif defined(OS_WIN)
auto integrity_level = process_metric.second->GetIntegrityLevel();
auto sandboxed = ProcessMetric::IsSandboxed(integrity_level);
pid_dict.Set("integrityLevel", integrity_level);
pid_dict.Set("sandboxed", sandboxed);
#endif
result.push_back(pid_dict);
}
@@ -1327,13 +1308,13 @@ int DockBounce(mate::Arguments* args) {
args->GetNext(&type);
if (type == "critical")
request_id = Browser::Get()->DockBounce(Browser::BounceType::CRITICAL);
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_CRITICAL);
else if (type == "informational")
request_id = Browser::Get()->DockBounce(Browser::BounceType::INFORMATIONAL);
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_INFORMATIONAL);
return request_id;
}
void DockSetMenu(electron::api::Menu* menu) {
void DockSetMenu(atom::api::Menu* menu) {
Browser::Get()->DockSetMenu(menu->model());
}
@@ -1344,25 +1325,20 @@ v8::Local<v8::Value> App::GetDockAPI(v8::Isolate* isolate) {
auto browser = base::Unretained(Browser::Get());
mate::Dictionary dock_obj = mate::Dictionary::CreateEmpty(isolate);
dock_obj.SetMethod("bounce", &DockBounce);
dock_obj.SetMethod(
"cancelBounce",
base::BindRepeating(&Browser::DockCancelBounce, browser));
dock_obj.SetMethod(
"downloadFinished",
base::BindRepeating(&Browser::DockDownloadFinished, browser));
dock_obj.SetMethod(
"setBadge", base::BindRepeating(&Browser::DockSetBadgeText, browser));
dock_obj.SetMethod(
"getBadge", base::BindRepeating(&Browser::DockGetBadgeText, browser));
dock_obj.SetMethod("hide",
base::BindRepeating(&Browser::DockHide, browser));
dock_obj.SetMethod("show",
base::BindRepeating(&Browser::DockShow, browser));
dock_obj.SetMethod("cancelBounce",
base::Bind(&Browser::DockCancelBounce, browser));
dock_obj.SetMethod("downloadFinished",
base::Bind(&Browser::DockDownloadFinished, browser));
dock_obj.SetMethod("setBadge",
base::Bind(&Browser::DockSetBadgeText, browser));
dock_obj.SetMethod("getBadge",
base::Bind(&Browser::DockGetBadgeText, browser));
dock_obj.SetMethod("hide", base::Bind(&Browser::DockHide, browser));
dock_obj.SetMethod("show", base::Bind(&Browser::DockShow, browser));
dock_obj.SetMethod("isVisible",
base::BindRepeating(&Browser::DockIsVisible, browser));
base::Bind(&Browser::DockIsVisible, browser));
dock_obj.SetMethod("setMenu", &DockSetMenu);
dock_obj.SetMethod("setIcon",
base::BindRepeating(&Browser::DockSetIcon, browser));
dock_obj.SetMethod("setIcon", base::Bind(&Browser::DockSetIcon, browser));
dock_.Reset(isolate, dock_obj.GetHandle());
}
@@ -1381,85 +1357,70 @@ void App::BuildPrototype(v8::Isolate* isolate,
prototype->SetClassName(mate::StringToV8(isolate, "App"));
auto browser = base::Unretained(Browser::Get());
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("quit", base::BindRepeating(&Browser::Quit, browser))
.SetMethod("exit", base::BindRepeating(&Browser::Exit, browser))
.SetMethod("focus", base::BindRepeating(&Browser::Focus, browser))
.SetMethod("getVersion",
base::BindRepeating(&Browser::GetVersion, browser))
.SetMethod("setVersion",
base::BindRepeating(&Browser::SetVersion, browser))
.SetMethod("_getName", base::BindRepeating(&Browser::GetName, browser))
.SetMethod("_setName", base::BindRepeating(&Browser::SetName, browser))
.SetMethod("isReady", base::BindRepeating(&Browser::is_ready, browser))
.SetMethod("whenReady", base::BindRepeating(&Browser::WhenReady, browser))
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
.SetMethod("exit", base::Bind(&Browser::Exit, 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("whenReady", base::Bind(&Browser::WhenReady, browser))
.SetMethod("addRecentDocument",
base::BindRepeating(&Browser::AddRecentDocument, browser))
base::Bind(&Browser::AddRecentDocument, browser))
.SetMethod("clearRecentDocuments",
base::BindRepeating(&Browser::ClearRecentDocuments, browser))
base::Bind(&Browser::ClearRecentDocuments, browser))
.SetMethod("setAppUserModelId",
base::BindRepeating(&Browser::SetAppUserModelID, browser))
.SetMethod(
"isDefaultProtocolClient",
base::BindRepeating(&Browser::IsDefaultProtocolClient, browser))
.SetMethod(
"setAsDefaultProtocolClient",
base::BindRepeating(&Browser::SetAsDefaultProtocolClient, browser))
.SetMethod(
"removeAsDefaultProtocolClient",
base::BindRepeating(&Browser::RemoveAsDefaultProtocolClient, browser))
.SetMethod("_setBadgeCount",
base::BindRepeating(&Browser::SetBadgeCount, browser))
.SetMethod("_getBadgeCount",
base::BindRepeating(&Browser::GetBadgeCount, browser))
base::Bind(&Browser::SetAppUserModelID, browser))
.SetMethod("isDefaultProtocolClient",
base::Bind(&Browser::IsDefaultProtocolClient, browser))
.SetMethod("setAsDefaultProtocolClient",
base::Bind(&Browser::SetAsDefaultProtocolClient, browser))
.SetMethod("removeAsDefaultProtocolClient",
base::Bind(&Browser::RemoveAsDefaultProtocolClient, browser))
.SetMethod("setBadgeCount", base::Bind(&Browser::SetBadgeCount, browser))
.SetMethod("getBadgeCount", base::Bind(&Browser::GetBadgeCount, browser))
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
.SetMethod("setLoginItemSettings",
base::BindRepeating(&Browser::SetLoginItemSettings, browser))
base::Bind(&Browser::SetLoginItemSettings, browser))
.SetMethod("isEmojiPanelSupported",
base::BindRepeating(&Browser::IsEmojiPanelSupported, browser))
.SetProperty("badgeCount",
base::BindRepeating(&Browser::GetBadgeCount, browser),
base::BindRepeating(&Browser::SetBadgeCount, browser))
.SetProperty("name", base::BindRepeating(&Browser::GetName, browser),
base::BindRepeating(&Browser::SetName, browser))
base::Bind(&Browser::IsEmojiPanelSupported, browser))
#if defined(OS_MACOSX)
.SetMethod("hide", base::BindRepeating(&Browser::Hide, browser))
.SetMethod("show", base::BindRepeating(&Browser::Show, browser))
.SetMethod("hide", base::Bind(&Browser::Hide, browser))
.SetMethod("show", base::Bind(&Browser::Show, browser))
.SetMethod("setUserActivity",
base::BindRepeating(&Browser::SetUserActivity, browser))
base::Bind(&Browser::SetUserActivity, browser))
.SetMethod("getCurrentActivityType",
base::BindRepeating(&Browser::GetCurrentActivityType, browser))
.SetMethod(
"invalidateCurrentActivity",
base::BindRepeating(&Browser::InvalidateCurrentActivity, browser))
.SetMethod("resignCurrentActivity",
base::BindRepeating(&Browser::ResignCurrentActivity, browser))
base::Bind(&Browser::GetCurrentActivityType, browser))
.SetMethod("invalidateCurrentActivity",
base::Bind(&Browser::InvalidateCurrentActivity, browser))
.SetMethod("updateCurrentActivity",
base::BindRepeating(&Browser::UpdateCurrentActivity, browser))
base::Bind(&Browser::UpdateCurrentActivity, browser))
// TODO(juturu): Remove in 2.0, deprecate before then with warnings
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
#endif
#if defined(OS_MACOSX) || defined(OS_LINUX)
.SetMethod("setAboutPanelOptions",
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
base::Bind(&Browser::SetAboutPanelOptions, browser))
.SetMethod("showAboutPanel",
base::BindRepeating(&Browser::ShowAboutPanel, browser))
base::Bind(&Browser::ShowAboutPanel, browser))
#endif
#if defined(OS_MACOSX) || defined(OS_WIN)
.SetMethod("showEmojiPanel",
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
base::Bind(&Browser::ShowEmojiPanel, browser))
.SetProperty("accessibilitySupportEnabled",
&App::IsAccessibilitySupportEnabled,
&App::SetAccessibilitySupportEnabled)
#endif
#if defined(OS_WIN)
.SetMethod("setUserTasks",
base::BindRepeating(&Browser::SetUserTasks, browser))
.SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser))
.SetMethod("getJumpListSettings", &App::GetJumpListSettings)
.SetMethod("setJumpList", &App::SetJumpList)
#endif
#if defined(OS_LINUX)
.SetMethod("isUnityRunning",
base::BindRepeating(&Browser::IsUnityRunning, browser))
base::Bind(&Browser::IsUnityRunning, browser))
#endif
.SetMethod("setAppPath", &App::SetAppPath)
.SetMethod("getAppPath", &App::GetAppPath)
@@ -1505,7 +1466,7 @@ void App::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
@@ -1515,10 +1476,10 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("App", electron::api::App::GetConstructor(isolate)
dict.Set("App", atom::api::App::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());
dict.Set("app", electron::api::App::Create(isolate));
dict.Set("app", atom::api::App::Create(isolate));
}
} // namespace

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_APP_H_
#define SHELL_BROWSER_API_ATOM_API_APP_H_
#ifndef ATOM_BROWSER_API_ATOM_API_APP_H_
#define ATOM_BROWSER_API_ATOM_API_APP_H_
#include <memory>
#include <string>
@@ -11,6 +11,14 @@
#include <utility>
#include <vector>
#include "atom/browser/api/event_emitter.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/browser/browser.h"
#include "atom/browser/browser_observer.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/promise_util.h"
#include "base/process/process_iterator.h"
#include "base/process/process_metrics.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/icon_manager.h"
#include "chrome/browser/process_singleton.h"
@@ -22,13 +30,6 @@
#include "net/base/completion_once_callback.h"
#include "net/base/completion_repeating_callback.h"
#include "net/ssl/client_cert_identity.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/browser/api/process_metric.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/browser.h"
#include "shell/browser/browser_observer.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/promise_util.h"
#if defined(USE_NSS_CERTS)
#include "chrome/browser/certificate_manager_model.h"
@@ -42,12 +43,23 @@ namespace mate {
class Arguments;
} // namespace mate
namespace electron {
namespace atom {
#if defined(OS_WIN)
enum class JumpListResult : int;
#endif
struct ProcessMetric {
int type;
base::ProcessId pid;
std::unique_ptr<base::ProcessMetrics> metrics;
ProcessMetric(int type,
base::ProcessId pid,
std::unique_ptr<base::ProcessMetrics> metrics);
~ProcessMetric();
};
namespace api {
class App : public AtomBrowserClient::Delegate,
@@ -57,7 +69,7 @@ class App : public AtomBrowserClient::Delegate,
public content::BrowserChildProcessObserver {
public:
using FileIconCallback =
base::RepeatingCallback<void(v8::Local<v8::Value>, const gfx::Image&)>;
base::Callback<void(v8::Local<v8::Value>, const gfx::Image&)>;
static mate::Handle<App> Create(v8::Isolate* isolate);
@@ -90,6 +102,8 @@ class App : public AtomBrowserClient::Delegate,
void OnActivate(bool has_visible_windows) override;
void OnWillFinishLaunching() override;
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
void OnLogin(scoped_refptr<LoginHandler> login_handler,
const base::DictionaryValue& request_details) override;
void OnAccessibilitySupportChanged() override;
void OnPreMainMessageLoopRun() override;
#if defined(OS_MACOSX)
@@ -118,9 +132,10 @@ class App : public AtomBrowserClient::Delegate,
const GURL& request_url,
bool is_main_frame_request,
bool strict_enforcement,
const base::RepeatingCallback<
void(content::CertificateRequestResultType)>& callback) override;
base::OnceClosure SelectClientCertificate(
bool expired_previous_decision,
const base::Callback<void(content::CertificateRequestResultType)>&
callback) override;
void SelectClientCertificate(
content::WebContents* web_contents,
net::SSLCertRequestInfo* cert_request_info,
net::ClientCertIdentityList client_certs,
@@ -142,7 +157,6 @@ class App : public AtomBrowserClient::Delegate,
bool* no_javascript_access) override;
// content::GpuDataManagerObserver:
void OnGpuInfoUpdate() override;
void OnGpuProcessCrashed(base::TerminationStatus status) override;
// content::BrowserChildProcessObserver:
@@ -162,8 +176,7 @@ class App : public AtomBrowserClient::Delegate,
void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
void ChildProcessDisconnected(base::ProcessId pid);
void SetAppLogsPath(base::Optional<base::FilePath> custom_path,
mate::Arguments* args);
void SetAppLogsPath(mate::Arguments* args);
// Get/Set the pre-defined path in PathService.
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
@@ -210,7 +223,7 @@ class App : public AtomBrowserClient::Delegate,
#endif
#if defined(MAS_BUILD)
base::RepeatingCallback<void()> StartAccessingSecurityScopedResource(
base::Callback<void()> StartAccessingSecurityScopedResource(
mate::Arguments* args);
#endif
@@ -234,8 +247,7 @@ class App : public AtomBrowserClient::Delegate,
base::FilePath app_path_;
using ProcessMetricMap =
std::unordered_map<base::ProcessId,
std::unique_ptr<electron::ProcessMetric>>;
std::unordered_map<base::ProcessId, std::unique_ptr<atom::ProcessMetric>>;
ProcessMetricMap app_metrics_;
DISALLOW_COPY_AND_ASSIGN(App);
@@ -243,6 +255,6 @@ class App : public AtomBrowserClient::Delegate,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_APP_H_
#endif // ATOM_BROWSER_API_ATOM_API_APP_H_

View File

@@ -2,25 +2,25 @@
// 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 "atom/browser/atom_paths.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "base/path_service.h"
#include "shell/browser/api/atom_api_app.h"
#include "shell/browser/atom_paths.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#import <Cocoa/Cocoa.h>
namespace electron {
namespace atom {
namespace api {
void App::SetAppLogsPath(base::Optional<base::FilePath> custom_path,
mate::Arguments* args) {
if (custom_path.has_value()) {
if (!custom_path->IsAbsolute()) {
void App::SetAppLogsPath(mate::Arguments* args) {
base::FilePath custom_path;
if (args->GetNext(&custom_path)) {
if (!custom_path.IsAbsolute()) {
args->ThrowError("Path must be absolute");
return;
}
base::PathService::Override(DIR_APP_LOGS, custom_path.value());
base::PathService::Override(DIR_APP_LOGS, custom_path);
} else {
NSString* bundle_name =
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
@@ -33,6 +33,6 @@ void App::SetAppLogsPath(base::Optional<base::FilePath> custom_path,
}
}
} // namespace api
} // namespace atom
} // namespace electron
} // namespace api

View File

@@ -2,15 +2,13 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_app.h"
#include <string>
#include "atom/browser/api/atom_api_app.h"
#import <Cocoa/Cocoa.h>
#include "base/strings/sys_string_conversions.h"
namespace electron {
namespace atom {
namespace api {
@@ -21,13 +19,13 @@ void OnStopAccessingSecurityScopedResource(NSURL* bookmarkUrl) {
}
// Get base64 encoded NSData, create a bookmark for it and start accessing it.
base::RepeatingCallback<void()> App::StartAccessingSecurityScopedResource(
base::Callback<void()> App::StartAccessingSecurityScopedResource(
mate::Arguments* args) {
std::string data;
args->GetNext(&data);
NSString* base64str = base::SysUTF8ToNSString(data);
NSData* bookmarkData = [[NSData alloc] initWithBase64EncodedString:base64str
options:0];
NSData* bookmarkData =
[[NSData alloc] initWithBase64EncodedString:base64str options:0];
// Create bookmarkUrl from NSData.
BOOL isStale = false;
@@ -57,10 +55,9 @@ base::RepeatingCallback<void()> App::StartAccessingSecurityScopedResource(
[bookmarkUrl retain];
// Return a js callback which will close the bookmark.
return base::BindRepeating(&OnStopAccessingSecurityScopedResource,
bookmarkUrl);
return base::Bind(&OnStopAccessingSecurityScopedResource, bookmarkUrl);
}
} // namespace api
} // namespace atom
} // namespace electron
} // namespace api

View File

@@ -2,17 +2,17 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_auto_updater.h"
#include "atom/browser/api/atom_api_auto_updater.h"
#include "atom/browser/browser.h"
#include "atom/browser/native_window.h"
#include "atom/browser/window_list.h"
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/node_includes.h"
#include "base/time/time.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "shell/browser/browser.h"
#include "shell/browser/native_window.h"
#include "shell/browser/window_list.h"
#include "shell/common/api/event_emitter_caller.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/node_includes.h"
namespace mate {
@@ -31,7 +31,7 @@ struct Converter<base::Time> {
} // namespace mate
namespace electron {
namespace atom {
namespace api {
@@ -97,8 +97,7 @@ void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes,
const std::string& url) {
Emit("update-downloaded", release_notes, release_name, release_date, url,
// Keep compatibility with old APIs.
base::BindRepeating(&AutoUpdater::QuitAndInstall,
base::Unretained(this)));
base::Bind(&AutoUpdater::QuitAndInstall, base::Unretained(this)));
}
void AutoUpdater::OnWindowAllClosed() {
@@ -141,11 +140,11 @@ void AutoUpdater::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::AutoUpdater;
using atom::api::AutoUpdater;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,

View File

@@ -2,18 +2,18 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_AUTO_UPDATER_H_
#define SHELL_BROWSER_API_ATOM_API_AUTO_UPDATER_H_
#ifndef ATOM_BROWSER_API_ATOM_API_AUTO_UPDATER_H_
#define ATOM_BROWSER_API_ATOM_API_AUTO_UPDATER_H_
#include <string>
#include "atom/browser/api/event_emitter.h"
#include "atom/browser/auto_updater.h"
#include "atom/browser/window_list_observer.h"
#include "native_mate/arguments.h"
#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/browser/auto_updater.h"
#include "shell/browser/window_list_observer.h"
namespace electron {
namespace atom {
namespace api {
@@ -56,6 +56,6 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_AUTO_UPDATER_H_
#endif // ATOM_BROWSER_API_ATOM_API_AUTO_UPDATER_H_

View File

@@ -2,27 +2,27 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_browser_view.h"
#include "atom/browser/api/atom_api_browser_view.h"
#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/browser/browser.h"
#include "atom/browser/native_browser_view.h"
#include "atom/common/color_util.h"
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/browser.h"
#include "shell/browser/native_browser_view.h"
#include "shell/common/color_util.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "ui/gfx/geometry/rect.h"
namespace mate {
template <>
struct Converter<electron::AutoResizeFlags> {
struct Converter<atom::AutoResizeFlags> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::AutoResizeFlags* auto_resize_flags) {
atom::AutoResizeFlags* auto_resize_flags) {
mate::Dictionary params;
if (!ConvertFromV8(isolate, val, &params)) {
return false;
@@ -31,29 +31,29 @@ struct Converter<electron::AutoResizeFlags> {
uint8_t flags = 0;
bool width = false;
if (params.Get("width", &width) && width) {
flags |= electron::kAutoResizeWidth;
flags |= atom::kAutoResizeWidth;
}
bool height = false;
if (params.Get("height", &height) && height) {
flags |= electron::kAutoResizeHeight;
flags |= atom::kAutoResizeHeight;
}
bool horizontal = false;
if (params.Get("horizontal", &horizontal) && horizontal) {
flags |= electron::kAutoResizeHorizontal;
flags |= atom::kAutoResizeHorizontal;
}
bool vertical = false;
if (params.Get("vertical", &vertical) && vertical) {
flags |= electron::kAutoResizeVertical;
flags |= atom::kAutoResizeVertical;
}
*auto_resize_flags = static_cast<electron::AutoResizeFlags>(flags);
*auto_resize_flags = static_cast<atom::AutoResizeFlags>(flags);
return true;
}
};
} // namespace mate
namespace electron {
namespace atom {
namespace api {
@@ -68,7 +68,7 @@ void BrowserView::Init(v8::Isolate* isolate,
const mate::Dictionary& options) {
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
web_preferences.Set("type", "browserView");
web_preferences.Set("isBrowserView", true);
mate::Handle<class WebContents> web_contents =
WebContents::Create(isolate, web_preferences);
@@ -102,8 +102,15 @@ mate::WrappableBase* BrowserView::New(mate::Arguments* args) {
return nullptr;
}
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
args->GetNext(&options);
if (args->Length() > 1) {
args->ThrowError("Too many arguments");
return nullptr;
}
mate::Dictionary options;
if (!(args->Length() == 1 && args->GetNext(&options))) {
options = mate::Dictionary::CreateEmpty(args->isolate());
}
return new BrowserView(args->isolate(), args->GetThis(), options);
}
@@ -120,10 +127,6 @@ void BrowserView::SetBounds(const gfx::Rect& bounds) {
view_->SetBounds(bounds);
}
gfx::Rect BrowserView::GetBounds() {
return view_->GetBounds();
}
void BrowserView::SetBackgroundColor(const std::string& color_name) {
view_->SetBackgroundColor(ParseHexColor(color_name));
}
@@ -144,7 +147,6 @@ void BrowserView::BuildPrototype(v8::Isolate* isolate,
.MakeDestroyable()
.SetMethod("setAutoResize", &BrowserView::SetAutoResize)
.SetMethod("setBounds", &BrowserView::SetBounds)
.SetMethod("getBounds", &BrowserView::GetBounds)
.SetMethod("setBackgroundColor", &BrowserView::SetBackgroundColor)
.SetProperty("webContents", &BrowserView::GetWebContents)
.SetProperty("id", &BrowserView::ID);
@@ -152,18 +154,18 @@ void BrowserView::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::BrowserView;
using atom::api::BrowserView;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
BrowserView::SetConstructor(isolate, base::BindRepeating(&BrowserView::New));
BrowserView::SetConstructor(isolate, base::Bind(&BrowserView::New));
mate::Dictionary browser_view(isolate, BrowserView::GetConstructor(isolate)
->GetFunction(context)

View File

@@ -2,16 +2,16 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_BROWSER_VIEW_H_
#define SHELL_BROWSER_API_ATOM_API_BROWSER_VIEW_H_
#ifndef ATOM_BROWSER_API_ATOM_API_BROWSER_VIEW_H_
#define ATOM_BROWSER_API_ATOM_API_BROWSER_VIEW_H_
#include <memory>
#include <string>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/native_browser_view.h"
#include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/native_browser_view.h"
namespace gfx {
class Rect;
@@ -22,7 +22,7 @@ class Arguments;
class Dictionary;
} // namespace mate
namespace electron {
namespace atom {
class NativeBrowserView;
@@ -59,7 +59,6 @@ class BrowserView : public mate::TrackableObject<BrowserView>,
void SetAutoResize(AutoResizeFlags flags);
void SetBounds(const gfx::Rect& bounds);
gfx::Rect GetBounds();
void SetBackgroundColor(const std::string& color_name);
v8::Local<v8::Value> GetWebContents();
@@ -74,6 +73,6 @@ class BrowserView : public mate::TrackableObject<BrowserView>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_BROWSER_VIEW_H_
#endif // ATOM_BROWSER_API_ATOM_API_BROWSER_VIEW_H_

View File

@@ -2,31 +2,31 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_browser_window.h"
#include "atom/browser/api/atom_api_browser_window.h"
#include <memory>
#include "atom/browser/browser.h"
#include "atom/browser/unresponsive_suppressor.h"
#include "atom/browser/web_contents_preferences.h"
#include "atom/browser/window_list.h"
#include "atom/common/api/api_messages.h"
#include "atom/common/api/constructor.h"
#include "atom/common/color_util.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/browser/renderer_host/render_widget_host_impl.h" // nogncheck
#include "content/browser/renderer_host/render_widget_host_owner_delegate.h" // nogncheck
#include "content/browser/web_contents/web_contents_impl.h" // nogncheck
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "gin/converter.h"
#include "native_mate/dictionary.h"
#include "shell/browser/browser.h"
#include "shell/browser/unresponsive_suppressor.h"
#include "shell/browser/web_contents_preferences.h"
#include "shell/browser/window_list.h"
#include "shell/common/api/constructor.h"
#include "shell/common/color_util.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "ui/gl/gpu_switching_manager.h"
namespace electron {
namespace atom {
namespace api {
@@ -45,21 +45,10 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate,
if (options.Get(options::kBackgroundColor, &value))
web_preferences.Set(options::kBackgroundColor, value);
// Copy the transparent setting to webContents
v8::Local<v8::Value> transparent;
if (options.Get("transparent", &transparent))
web_preferences.Set("transparent", transparent);
// Copy the show setting to webContents, but only if we don't want to paint
// when initially hidden
bool paint_when_initially_hidden = true;
options.Get("paintWhenInitiallyHidden", &paint_when_initially_hidden);
if (!paint_when_initially_hidden) {
bool show = true;
options.Get(options::kShow, &show);
web_preferences.Set(options::kShow, show);
}
if (options.Get("webContents", &web_contents) && !web_contents.IsEmpty()) {
// Set webPreferences from options if using an existing webContents.
// These preferences will be used when the webContent launches new
@@ -182,6 +171,17 @@ void BrowserWindow::OnRendererUnresponsive(content::RenderProcessHost*) {
ScheduleUnresponsiveEvent(50);
}
bool BrowserWindow::OnMessageReceived(const IPC::Message& message,
content::RenderFrameHost* rfh) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BrowserWindow, message, rfh)
IPC_MESSAGE_HANDLER(AtomFrameHostMsg_UpdateDraggableRegions,
UpdateDraggableRegions)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void BrowserWindow::OnCloseContents() {
// On some machines it may happen that the window gets destroyed for twice,
// checking web_contents() can effectively guard against that.
@@ -217,11 +217,6 @@ void BrowserWindow::OnRendererResponsive() {
Emit("responsive");
}
void BrowserWindow::OnDraggableRegionsUpdated(
const std::vector<mojom::DraggableRegionPtr>& regions) {
UpdateDraggableRegions(regions);
}
void BrowserWindow::RequestPreferredWidth(int* width) {
*width = web_contents()->GetPreferredSize().width();
}
@@ -282,7 +277,7 @@ void BrowserWindow::OnWindowFocus() {
void BrowserWindow::OnWindowResize() {
#if defined(OS_MACOSX)
if (!draggable_regions_.empty())
UpdateDraggableRegions(draggable_regions_);
UpdateDraggableRegions(nullptr, draggable_regions_);
#endif
TopLevelWindow::OnWindowResize();
}
@@ -330,28 +325,28 @@ void BrowserWindow::SetBrowserView(v8::Local<v8::Value> value) {
TopLevelWindow::ResetBrowserViews();
TopLevelWindow::AddBrowserView(value);
#if defined(OS_MACOSX)
UpdateDraggableRegions(draggable_regions_);
UpdateDraggableRegions(nullptr, draggable_regions_);
#endif
}
void BrowserWindow::AddBrowserView(v8::Local<v8::Value> value) {
TopLevelWindow::AddBrowserView(value);
#if defined(OS_MACOSX)
UpdateDraggableRegions(draggable_regions_);
UpdateDraggableRegions(nullptr, draggable_regions_);
#endif
}
void BrowserWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
TopLevelWindow::RemoveBrowserView(value);
#if defined(OS_MACOSX)
UpdateDraggableRegions(draggable_regions_);
UpdateDraggableRegions(nullptr, draggable_regions_);
#endif
}
void BrowserWindow::ResetBrowserViews() {
TopLevelWindow::ResetBrowserViews();
#if defined(OS_MACOSX)
UpdateDraggableRegions(draggable_regions_);
UpdateDraggableRegions(nullptr, draggable_regions_);
#endif
}
@@ -393,13 +388,13 @@ v8::Local<v8::Value> BrowserWindow::GetWebContents(v8::Isolate* isolate) {
// Convert draggable regions in raw format to SkRegion format.
std::unique_ptr<SkRegion> BrowserWindow::DraggableRegionsToSkRegion(
const std::vector<mojom::DraggableRegionPtr>& regions) {
const std::vector<DraggableRegion>& regions) {
auto sk_region = std::make_unique<SkRegion>();
for (const auto& region : regions) {
for (const DraggableRegion& region : regions) {
sk_region->op(
{region->bounds.x(), region->bounds.y(), region->bounds.right(),
region->bounds.bottom()},
region->draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
region.bounds.x(), region.bounds.y(), region.bounds.right(),
region.bounds.bottom(),
region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
}
return sk_region;
}
@@ -408,8 +403,8 @@ void BrowserWindow::ScheduleUnresponsiveEvent(int ms) {
if (!window_unresponsive_closure_.IsCancelled())
return;
window_unresponsive_closure_.Reset(base::BindRepeating(
&BrowserWindow::NotifyWindowUnresponsive, GetWeakPtr()));
window_unresponsive_closure_.Reset(
base::Bind(&BrowserWindow::NotifyWindowUnresponsive, GetWeakPtr()));
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, window_unresponsive_closure_.callback(),
base::TimeDelta::FromMilliseconds(ms));
@@ -434,16 +429,6 @@ void BrowserWindow::Cleanup() {
Observe(nullptr);
}
void BrowserWindow::OnWindowShow() {
web_contents()->WasShown();
TopLevelWindow::OnWindowShow();
}
void BrowserWindow::OnWindowHide() {
web_contents()->WasOccluded();
TopLevelWindow::OnWindowHide();
}
// static
mate::WrappableBase* BrowserWindow::New(mate::Arguments* args) {
if (!Browser::Get()->is_ready()) {
@@ -487,12 +472,12 @@ v8::Local<v8::Value> BrowserWindow::From(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::BrowserWindow;
using electron::api::TopLevelWindow;
using atom::api::BrowserWindow;
using atom::api::TopLevelWindow;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
@@ -500,9 +485,8 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("BrowserWindow",
mate::CreateConstructor<BrowserWindow>(
isolate, base::BindRepeating(&BrowserWindow::New)));
dict.Set("BrowserWindow", mate::CreateConstructor<BrowserWindow>(
isolate, base::Bind(&BrowserWindow::New)));
}
} // namespace

View File

@@ -2,18 +2,18 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
#define SHELL_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
#ifndef ATOM_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
#define ATOM_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
#include <memory>
#include <string>
#include <vector>
#include "atom/browser/api/atom_api_top_level_window.h"
#include "atom/browser/api/atom_api_web_contents.h"
#include "base/cancelable_callback.h"
#include "shell/browser/api/atom_api_top_level_window.h"
#include "shell/browser/api/atom_api_web_contents.h"
namespace electron {
namespace atom {
namespace api {
@@ -51,12 +51,12 @@ class BrowserWindow : public TopLevelWindow,
void DidFirstVisuallyNonEmptyPaint() override;
void BeforeUnloadDialogCancelled() override;
void OnRendererUnresponsive(content::RenderProcessHost*) override;
bool OnMessageReceived(const IPC::Message& message,
content::RenderFrameHost* rfh) override;
// ExtendedWebContentsObserver:
void OnCloseContents() override;
void OnRendererResponsive() override;
void OnDraggableRegionsUpdated(
const std::vector<mojom::DraggableRegionPtr>& regions) override;
// NativeWindowObserver:
void RequestPreferredWidth(int* width) override;
@@ -76,8 +76,6 @@ class BrowserWindow : public TopLevelWindow,
void RemoveBrowserView(v8::Local<v8::Value> value) override;
void ResetBrowserViews() override;
void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value) override;
void OnWindowShow() override;
void OnWindowHide() override;
// BrowserWindow APIs.
void FocusOnWebView();
@@ -93,12 +91,12 @@ class BrowserWindow : public TopLevelWindow,
// Helpers.
// Called when the window needs to update its draggable region.
void UpdateDraggableRegions(
const std::vector<mojom::DraggableRegionPtr>& regions);
void UpdateDraggableRegions(content::RenderFrameHost* rfh,
const std::vector<DraggableRegion>& regions);
// Convert draggable regions in raw format to SkRegion format.
std::unique_ptr<SkRegion> DraggableRegionsToSkRegion(
const std::vector<mojom::DraggableRegionPtr>& regions);
const std::vector<DraggableRegion>& regions);
// Schedule a notification unresponsive event.
void ScheduleUnresponsiveEvent(int ms);
@@ -114,7 +112,7 @@ class BrowserWindow : public TopLevelWindow,
base::CancelableClosure window_unresponsive_closure_;
#if defined(OS_MACOSX)
std::vector<mojom::DraggableRegionPtr> draggable_regions_;
std::vector<DraggableRegion> draggable_regions_;
#endif
v8::Global<v8::Value> web_contents_;
@@ -127,6 +125,6 @@ class BrowserWindow : public TopLevelWindow,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
#endif // ATOM_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_

View File

@@ -2,17 +2,15 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_browser_window.h"
#include <memory>
#include <vector>
#include "atom/browser/api/atom_api_browser_window.h"
#import <Cocoa/Cocoa.h>
#include "atom/browser/native_browser_view.h"
#include "atom/browser/native_window_mac.h"
#include "atom/browser/ui/inspectable_web_contents_view.h"
#include "atom/common/draggable_region.h"
#include "base/mac/scoped_nsobject.h"
#include "shell/browser/native_browser_view.h"
#include "shell/browser/native_window_mac.h"
#include "shell/browser/ui/inspectable_web_contents_view.h"
@interface NSView (WebContentsView)
- (void)setMouseDownCanMoveWindow:(BOOL)can_move;
@@ -33,7 +31,7 @@
@end
namespace electron {
namespace atom {
namespace api {
@@ -47,7 +45,7 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
int height) {
std::vector<gfx::Rect> result;
SkRegion non_draggable;
non_draggable.op({0, 0, width, height}, SkRegion::kUnion_Op);
non_draggable.op(0, 0, width, height, SkRegion::kUnion_Op);
non_draggable.op(*draggable, SkRegion::kDifference_Op);
for (SkRegion::Iterator it(non_draggable); !it.done(); it.next()) {
result.push_back(gfx::SkIRectToRect(it.rect()));
@@ -75,13 +73,11 @@ void BrowserWindow::OverrideNSWindowContentView(InspectableWebContents* iwc) {
}
void BrowserWindow::UpdateDraggableRegions(
const std::vector<mojom::DraggableRegionPtr>& regions) {
content::RenderFrameHost* rfh,
const std::vector<DraggableRegion>& regions) {
if (window_->has_frame())
return;
if (!web_contents())
return;
// All ControlRegionViews should be added as children of the WebContentsView,
// because WebContentsView will be removed and re-added when entering and
// leaving fullscreen mode.
@@ -104,11 +100,7 @@ void BrowserWindow::UpdateDraggableRegions(
// Draggable regions is implemented by having the whole web view draggable
// (mouseDownCanMoveWindow) and overlaying regions that are not draggable.
if (&draggable_regions_ != &regions) {
draggable_regions_.clear();
for (const auto& r : regions)
draggable_regions_.push_back(r.Clone());
}
draggable_regions_ = regions;
std::vector<gfx::Rect> drag_exclude_rects;
if (regions.empty()) {
drag_exclude_rects.push_back(gfx::Rect(0, 0, webViewWidth, webViewHeight));
@@ -119,7 +111,7 @@ void BrowserWindow::UpdateDraggableRegions(
auto browser_views = window_->browser_views();
for (NativeBrowserView* view : browser_views) {
view->UpdateDraggableRegions(drag_exclude_rects);
(view)->UpdateDraggableRegions(drag_exclude_rects);
}
// Create and add a ControlRegionView for each region that needs to be
@@ -142,4 +134,4 @@ void BrowserWindow::UpdateDraggableRegions(
} // namespace api
} // namespace electron
} // namespace atom

View File

@@ -2,16 +2,17 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_browser_window.h"
#include "atom/browser/api/atom_api_browser_window.h"
#include "shell/browser/native_window_views.h"
#include "atom/browser/native_window_views.h"
namespace electron {
namespace atom {
namespace api {
void BrowserWindow::UpdateDraggableRegions(
const std::vector<mojom::DraggableRegionPtr>& regions) {
content::RenderFrameHost* rfh,
const std::vector<DraggableRegion>& regions) {
if (window_->has_frame())
return;
static_cast<NativeWindowViews*>(window_.get())
@@ -20,4 +21,4 @@ void BrowserWindow::UpdateDraggableRegions(
} // namespace api
} // namespace electron
} // namespace atom

View File

@@ -4,19 +4,17 @@
#include <set>
#include <string>
#include <utility>
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/promise_util.h"
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/optional.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/browser/tracing_controller.h"
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/promise_util.h"
using content::TracingController;
@@ -55,57 +53,45 @@ struct Converter<base::trace_event::TraceConfig> {
namespace {
using CompletionCallback = base::OnceCallback<void(const base::FilePath&)>;
using CompletionCallback = base::Callback<void(const base::FilePath&)>;
base::Optional<base::FilePath> CreateTemporaryFileOnIO() {
base::FilePath temp_file_path;
if (!base::CreateTemporaryFile(&temp_file_path))
return base::nullopt;
return base::make_optional(std::move(temp_file_path));
scoped_refptr<TracingController::TraceDataEndpoint> GetTraceDataEndpoint(
const base::FilePath& path,
const CompletionCallback& callback) {
base::FilePath result_file_path = path;
// base::CreateTemporaryFile prevents blocking so we need to allow it
// for now since offloading this to a different sequence would require
// changing the api shape
base::ThreadRestrictions::ScopedAllowIO allow_io;
if (result_file_path.empty() && !base::CreateTemporaryFile(&result_file_path))
LOG(ERROR) << "Creating temporary file failed";
return TracingController::CreateFileEndpoint(
result_file_path, base::Bind(callback, result_file_path));
}
void StopTracing(electron::util::Promise promise,
base::Optional<base::FilePath> file_path) {
if (file_path) {
auto endpoint = TracingController::CreateFileEndpoint(
*file_path,
base::AdaptCallbackForRepeating(base::BindOnce(
&electron::util::Promise::ResolvePromise<base::FilePath>,
std::move(promise), *file_path)));
TracingController::GetInstance()->StopTracing(endpoint);
} else {
promise.RejectWithErrorMessage(
"Failed to create temporary file for trace data");
}
}
v8::Local<v8::Promise> StopRecording(mate::Arguments* args) {
electron::util::Promise promise(args->isolate());
v8::Local<v8::Promise> StopRecording(v8::Isolate* isolate,
const base::FilePath& path) {
atom::util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
base::FilePath path;
if (args->GetNext(&path) && !path.empty()) {
StopTracing(std::move(promise), base::make_optional(path));
} else {
// use a temporary file.
base::PostTaskAndReplyWithResult(
FROM_HERE,
{base::ThreadPool(), base::MayBlock(),
base::TaskPriority::USER_VISIBLE},
base::BindOnce(CreateTemporaryFileOnIO),
base::BindOnce(StopTracing, std::move(promise)));
}
// TODO(zcbenz): Remove the use of CopyablePromise when the
// CreateFileEndpoint API accepts OnceCallback.
TracingController::GetInstance()->StopTracing(GetTraceDataEndpoint(
path, base::Bind(atom::util::CopyablePromise::ResolveCopyablePromise<
const base::FilePath&>,
atom::util::CopyablePromise(promise))));
return handle;
}
v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
electron::util::Promise promise(isolate);
atom::util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
// Note: This method always succeeds.
TracingController::GetInstance()->GetCategories(base::BindOnce(
electron::util::Promise::ResolvePromise<const std::set<std::string>&>,
atom::util::Promise::ResolvePromise<const std::set<std::string>&>,
std::move(promise)));
return handle;
@@ -114,23 +100,17 @@ v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
v8::Local<v8::Promise> StartTracing(
v8::Isolate* isolate,
const base::trace_event::TraceConfig& trace_config) {
electron::util::Promise promise(isolate);
atom::util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
if (!TracingController::GetInstance()->StartTracing(
trace_config,
base::BindOnce(electron::util::Promise::ResolveEmptyPromise,
std::move(promise)))) {
// If StartTracing returns false, that means it didn't invoke its callback.
// Return an already-resolved promise and abandon the previous promise (it
// was std::move()d into the StartTracing callback and has been deleted by
// this point).
return electron::util::Promise::ResolvedPromise(isolate);
}
// Note: This method always succeeds.
TracingController::GetInstance()->StartTracing(
trace_config, base::BindOnce(atom::util::Promise::ResolveEmptyPromise,
std::move(promise)));
return handle;
}
void OnTraceBufferUsageAvailable(electron::util::Promise promise,
void OnTraceBufferUsageAvailable(atom::util::Promise promise,
float percent_full,
size_t approximate_count) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
@@ -141,7 +121,7 @@ void OnTraceBufferUsageAvailable(electron::util::Promise promise,
}
v8::Local<v8::Promise> GetTraceBufferUsage(v8::Isolate* isolate) {
electron::util::Promise promise(isolate);
atom::util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
// Note: This method always succeeds.

View File

@@ -0,0 +1,407 @@
// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/api/atom_api_cookies.h"
#include <memory>
#include <utility>
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/cookie_change_notifier.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/task/post_task.h"
#include "base/time/time.h"
#include "base/values.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_util.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
using content::BrowserThread;
namespace mate {
template <>
struct Converter<atom::api::Cookies::Error> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
atom::api::Cookies::Error val) {
if (val == atom::api::Cookies::SUCCESS)
return v8::Null(isolate);
else
return v8::Exception::Error(StringToV8(isolate, "Setting cookie failed"));
}
};
template <>
struct Converter<net::CanonicalCookie> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const net::CanonicalCookie& val) {
mate::Dictionary dict(isolate, v8::Object::New(isolate));
dict.Set("name", val.Name());
dict.Set("value", val.Value());
dict.Set("domain", val.Domain());
dict.Set("hostOnly", net::cookie_util::DomainIsHostOnly(val.Domain()));
dict.Set("path", val.Path());
dict.Set("secure", val.IsSecure());
dict.Set("httpOnly", val.IsHttpOnly());
dict.Set("session", !val.IsPersistent());
if (val.IsPersistent())
dict.Set("expirationDate", val.ExpiryDate().ToDoubleT());
return dict.GetHandle();
}
};
template <>
struct Converter<network::mojom::CookieChangeCause> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const network::mojom::CookieChangeCause& val) {
switch (val) {
case network::mojom::CookieChangeCause::INSERTED:
case network::mojom::CookieChangeCause::EXPLICIT:
return mate::StringToV8(isolate, "explicit");
case network::mojom::CookieChangeCause::OVERWRITE:
return mate::StringToV8(isolate, "overwrite");
case network::mojom::CookieChangeCause::EXPIRED:
return mate::StringToV8(isolate, "expired");
case network::mojom::CookieChangeCause::EVICTED:
return mate::StringToV8(isolate, "evicted");
case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE:
return mate::StringToV8(isolate, "expired-overwrite");
default:
return mate::StringToV8(isolate, "unknown");
}
}
};
} // namespace mate
namespace atom {
namespace api {
namespace {
// Returns whether |domain| matches |filter|.
bool MatchesDomain(std::string filter, const std::string& domain) {
// Add a leading '.' character to the filter domain if it doesn't exist.
if (net::cookie_util::DomainIsHostOnly(filter))
filter.insert(0, ".");
std::string sub_domain(domain);
// Strip any leading '.' character from the input cookie domain.
if (!net::cookie_util::DomainIsHostOnly(sub_domain))
sub_domain = sub_domain.substr(1);
// Now check whether the domain argument is a subdomain of the filter domain.
for (sub_domain.insert(0, "."); sub_domain.length() >= filter.length();) {
if (sub_domain == filter)
return true;
const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot.
sub_domain.erase(0, next_dot);
}
return false;
}
// Returns whether |cookie| matches |filter|.
bool MatchesCookie(const base::DictionaryValue* filter,
const net::CanonicalCookie& cookie) {
std::string str;
bool b;
if (filter->GetString("name", &str) && str != cookie.Name())
return false;
if (filter->GetString("path", &str) && str != cookie.Path())
return false;
if (filter->GetString("domain", &str) && !MatchesDomain(str, cookie.Domain()))
return false;
if (filter->GetBoolean("secure", &b) && b != cookie.IsSecure())
return false;
if (filter->GetBoolean("session", &b) && b != !cookie.IsPersistent())
return false;
return true;
}
// Helper to returns the CookieStore.
inline net::CookieStore* GetCookieStore(
scoped_refptr<net::URLRequestContextGetter> getter) {
return getter->GetURLRequestContext()->cookie_store();
}
// Remove cookies from |list| not matching |filter|, and pass it to |callback|.
void FilterCookies(std::unique_ptr<base::DictionaryValue> filter,
util::Promise promise,
const net::CookieList& list,
const net::CookieStatusList& excluded_list) {
net::CookieList result;
for (const auto& cookie : list) {
if (MatchesCookie(filter.get(), cookie))
result.push_back(cookie);
}
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(util::Promise::ResolvePromise<const net::CookieList&>,
std::move(promise), std::move(result)));
}
// Receives cookies matching |filter| in IO thread.
void GetCookiesOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
std::unique_ptr<base::DictionaryValue> filter,
util::Promise promise) {
std::string url;
filter->GetString("url", &url);
auto filtered_callback =
base::BindOnce(FilterCookies, std::move(filter), std::move(promise));
// Empty url will match all url cookies.
if (url.empty())
GetCookieStore(getter)->GetAllCookiesAsync(std::move(filtered_callback));
else
GetCookieStore(getter)->GetAllCookiesForURLAsync(
GURL(url), std::move(filtered_callback));
}
// Removes cookie with |url| and |name| in IO thread.
void RemoveCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
const GURL& url,
const std::string& name,
util::Promise promise) {
net::CookieDeletionInfo cookie_info;
cookie_info.url = url;
cookie_info.name = name;
GetCookieStore(getter)->DeleteAllMatchingInfoAsync(
std::move(cookie_info),
base::BindOnce(
[](util::Promise promise, uint32_t num_deleted) {
util::Promise::ResolveEmptyPromise(std::move(promise));
},
std::move(promise)));
}
// Callback of SetCookie.
void OnSetCookie(util::Promise promise,
net::CanonicalCookie::CookieInclusionStatus status) {
std::string errmsg;
switch (status) {
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_HTTP_ONLY:
errmsg = "Failed to create httponly cookie";
break;
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_SECURE_ONLY:
errmsg = "Cannot create a secure cookie from an insecure URL";
break;
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE:
errmsg = "Failed to parse cookie";
break;
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_INVALID_DOMAIN:
errmsg = "Failed to get cookie domain";
break;
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_INVALID_PREFIX:
errmsg = "Failed because the cookie violated prefix rules.";
break;
case net::CanonicalCookie::CookieInclusionStatus::
EXCLUDE_NONCOOKIEABLE_SCHEME:
errmsg = "Cannot set cookie for current scheme";
break;
case net::CanonicalCookie::CookieInclusionStatus::INCLUDE:
errmsg = "";
break;
default:
errmsg = "Setting cookie failed";
break;
}
if (errmsg.empty()) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
} else {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(util::Promise::RejectPromise, std::move(promise),
std::move(errmsg)));
}
}
// Flushes cookie store in IO thread.
void FlushCookieStoreOnIOThread(
scoped_refptr<net::URLRequestContextGetter> getter,
util::Promise promise) {
GetCookieStore(getter)->FlushStore(
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
}
// Sets cookie with |details| in IO thread.
void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
std::unique_ptr<base::DictionaryValue> details,
util::Promise promise) {
std::string url_string, name, value, domain, path;
bool secure = false;
bool http_only = false;
double creation_date;
double expiration_date;
double last_access_date;
details->GetString("url", &url_string);
details->GetString("name", &name);
details->GetString("value", &value);
details->GetString("domain", &domain);
details->GetString("path", &path);
details->GetBoolean("secure", &secure);
details->GetBoolean("httpOnly", &http_only);
base::Time creation_time;
if (details->GetDouble("creationDate", &creation_date)) {
creation_time = (creation_date == 0)
? base::Time::UnixEpoch()
: base::Time::FromDoubleT(creation_date);
}
base::Time expiration_time;
if (details->GetDouble("expirationDate", &expiration_date)) {
expiration_time = (expiration_date == 0)
? base::Time::UnixEpoch()
: base::Time::FromDoubleT(expiration_date);
}
base::Time last_access_time;
if (details->GetDouble("lastAccessDate", &last_access_date)) {
last_access_time = (last_access_date == 0)
? base::Time::UnixEpoch()
: base::Time::FromDoubleT(last_access_date);
}
GURL url(url_string);
std::unique_ptr<net::CanonicalCookie> canonical_cookie(
net::CanonicalCookie::CreateSanitizedCookie(
url, name, value, domain, path, creation_time, expiration_time,
last_access_time, secure, http_only,
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT));
auto completion_callback = base::BindOnce(OnSetCookie, std::move(promise));
if (!canonical_cookie || !canonical_cookie->IsCanonical()) {
std::move(completion_callback)
.Run(net::CanonicalCookie::CookieInclusionStatus::
EXCLUDE_FAILURE_TO_STORE);
return;
}
if (!url.is_valid()) {
std::move(completion_callback)
.Run(net::CanonicalCookie::CookieInclusionStatus::
EXCLUDE_INVALID_DOMAIN);
return;
}
if (name.empty()) {
std::move(completion_callback)
.Run(net::CanonicalCookie::CookieInclusionStatus::
EXCLUDE_FAILURE_TO_STORE);
return;
}
net::CookieOptions options;
if (http_only) {
options.set_include_httponly();
}
GetCookieStore(getter)->SetCanonicalCookieAsync(
std::move(canonical_cookie), url.scheme(), options,
std::move(completion_callback));
}
} // namespace
Cookies::Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context)
: browser_context_(browser_context) {
Init(isolate);
cookie_change_subscription_ =
browser_context_->cookie_change_notifier()->RegisterCookieChangeCallback(
base::Bind(&Cookies::OnCookieChanged, base::Unretained(this)));
}
Cookies::~Cookies() {}
v8::Local<v8::Promise> Cookies::Get(const base::DictionaryValue& filter) {
util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
auto copy = base::DictionaryValue::From(
base::Value::ToUniquePtrValue(filter.Clone()));
auto* getter = browser_context_->GetRequestContext();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(GetCookiesOnIO, base::RetainedRef(getter), std::move(copy),
std::move(promise)));
return handle;
}
v8::Local<v8::Promise> Cookies::Remove(const GURL& url,
const std::string& name) {
util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
auto* getter = browser_context_->GetRequestContext();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(RemoveCookieOnIO, base::RetainedRef(getter), url, name,
std::move(promise)));
return handle;
}
v8::Local<v8::Promise> Cookies::Set(const base::DictionaryValue& details) {
util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
auto copy = base::DictionaryValue::From(
base::Value::ToUniquePtrValue(details.Clone()));
auto* getter = browser_context_->GetRequestContext();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(SetCookieOnIO, base::RetainedRef(getter), std::move(copy),
std::move(promise)));
return handle;
}
v8::Local<v8::Promise> Cookies::FlushStore() {
util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
auto* getter = browser_context_->GetRequestContext();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(FlushCookieStoreOnIOThread, base::RetainedRef(getter),
std::move(promise)));
return handle;
}
void Cookies::OnCookieChanged(const CookieDetails* details) {
Emit("changed", *(details->cookie), details->cause, details->removed);
}
// static
mate::Handle<Cookies> Cookies::Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
return mate::CreateHandle(isolate, new Cookies(isolate, browser_context));
}
// static
void Cookies::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Cookies"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("get", &Cookies::Get)
.SetMethod("remove", &Cookies::Remove)
.SetMethod("set", &Cookies::Set)
.SetMethod("flushStore", &Cookies::FlushStore);
}
} // namespace api
} // namespace atom

View File

@@ -2,32 +2,28 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_COOKIES_H_
#define SHELL_BROWSER_API_ATOM_API_COOKIES_H_
#ifndef ATOM_BROWSER_API_ATOM_API_COOKIES_H_
#define ATOM_BROWSER_API_ATOM_API_COOKIES_H_
#include <memory>
#include <string>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/net/cookie_details.h"
#include "atom/common/promise_util.h"
#include "base/callback_list.h"
#include "gin/handle.h"
#include "native_mate/handle.h"
#include "net/cookies/canonical_cookie.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/net/cookie_details.h"
#include "shell/common/promise_util.h"
namespace base {
class DictionaryValue;
}
namespace mate {
class Dictionary;
}
namespace net {
class URLRequestContextGetter;
}
namespace electron {
namespace atom {
class AtomBrowserContext;
@@ -35,8 +31,13 @@ namespace api {
class Cookies : public mate::TrackableObject<Cookies> {
public:
static gin::Handle<Cookies> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
enum Error {
SUCCESS,
FAILED,
};
static mate::Handle<Cookies> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
// mate::TrackableObject:
static void BuildPrototype(v8::Isolate* isolate,
@@ -46,7 +47,7 @@ class Cookies : public mate::TrackableObject<Cookies> {
Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);
~Cookies() override;
v8::Local<v8::Promise> Get(const mate::Dictionary& filter);
v8::Local<v8::Promise> Get(const base::DictionaryValue& filter);
v8::Local<v8::Promise> Set(const base::DictionaryValue& details);
v8::Local<v8::Promise> Remove(const GURL& url, const std::string& name);
v8::Local<v8::Promise> FlushStore();
@@ -64,6 +65,6 @@ class Cookies : public mate::TrackableObject<Cookies> {
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_COOKIES_H_
#endif // ATOM_BROWSER_API_ATOM_API_COOKIES_H_

View File

@@ -2,24 +2,24 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_debugger.h"
#include "atom/browser/api/atom_api_debugger.h"
#include <memory>
#include <string>
#include <utility>
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/web_contents.h"
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
using content::DevToolsAgentHost;
namespace electron {
namespace atom {
namespace api {
@@ -65,7 +65,7 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
if (it == pending_requests_.end())
return;
electron::util::Promise promise = std::move(it->second);
atom::util::Promise promise = std::move(it->second);
pending_requests_.erase(it);
base::DictionaryValue* error = nullptr;
@@ -129,7 +129,7 @@ void Debugger::Detach() {
}
v8::Local<v8::Promise> Debugger::SendCommand(mate::Arguments* args) {
electron::util::Promise promise(isolate());
atom::util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
if (!agent_host_) {
@@ -186,11 +186,11 @@ void Debugger::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::Debugger;
using atom::api::Debugger;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,

View File

@@ -2,19 +2,19 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_DEBUGGER_H_
#define SHELL_BROWSER_API_ATOM_API_DEBUGGER_H_
#ifndef ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_
#define ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_
#include <map>
#include <string>
#include "atom/browser/api/trackable_object.h"
#include "atom/common/promise_util.h"
#include "base/callback.h"
#include "base/values.h"
#include "content/public/browser/devtools_agent_host_client.h"
#include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/common/promise_util.h"
namespace content {
class DevToolsAgentHost;
@@ -25,7 +25,7 @@ namespace mate {
class Arguments;
}
namespace electron {
namespace atom {
namespace api {
@@ -54,7 +54,7 @@ class Debugger : public mate::TrackableObject<Debugger>,
content::RenderFrameHost* new_rfh) override;
private:
using PendingRequestMap = std::map<int, electron::util::Promise>;
using PendingRequestMap = std::map<int, atom::util::Promise>;
void Attach(mate::Arguments* args);
bool IsAttached();
@@ -73,6 +73,6 @@ class Debugger : public mate::TrackableObject<Debugger>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_DEBUGGER_H_
#endif // ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_

View File

@@ -2,12 +2,15 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_desktop_capturer.h"
#include "atom/browser/api/atom_api_desktop_capturer.h"
#include <memory>
#include <utility>
#include <vector>
#include "atom/common/api/atom_api_native_image.h"
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/node_includes.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
@@ -15,9 +18,6 @@
#include "chrome/browser/media/webrtc/window_icon_util.h"
#include "content/public/browser/desktop_capture.h"
#include "native_mate/dictionary.h"
#include "shell/common/api/atom_api_native_image.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/node_includes.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
@@ -30,22 +30,22 @@
namespace mate {
template <>
struct Converter<electron::api::DesktopCapturer::Source> {
struct Converter<atom::api::DesktopCapturer::Source> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const electron::api::DesktopCapturer::Source& source) {
const atom::api::DesktopCapturer::Source& source) {
mate::Dictionary dict(isolate, v8::Object::New(isolate));
content::DesktopMediaID id = source.media_list_source.id;
dict.Set("name", base::UTF16ToUTF8(source.media_list_source.name));
dict.Set("id", id.ToString());
dict.Set("thumbnail",
electron::api::NativeImage::Create(
atom::api::NativeImage::Create(
isolate, gfx::Image(source.media_list_source.thumbnail)));
dict.Set("display_id", source.display_id);
if (source.fetch_icon) {
dict.Set(
"appIcon",
electron::api::NativeImage::Create(
atom::api::NativeImage::Create(
isolate, gfx::Image(GetWindowIcon(source.media_list_source.id))));
}
return ConvertToV8(isolate, dict);
@@ -54,7 +54,7 @@ struct Converter<electron::api::DesktopCapturer::Source> {
} // namespace mate
namespace electron {
namespace atom {
namespace api {
@@ -216,7 +216,7 @@ void DesktopCapturer::BuildPrototype(
} // namespace api
} // namespace electron
} // namespace atom
namespace {
@@ -226,8 +226,7 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.SetMethod("createDesktopCapturer",
&electron::api::DesktopCapturer::Create);
dict.SetMethod("createDesktopCapturer", &atom::api::DesktopCapturer::Create);
}
} // namespace

View File

@@ -2,19 +2,19 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_DESKTOP_CAPTURER_H_
#define SHELL_BROWSER_API_ATOM_API_DESKTOP_CAPTURER_H_
#ifndef ATOM_BROWSER_API_ATOM_API_DESKTOP_CAPTURER_H_
#define ATOM_BROWSER_API_ATOM_API_DESKTOP_CAPTURER_H_
#include <memory>
#include <string>
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "chrome/browser/media/webrtc/desktop_media_list_observer.h"
#include "chrome/browser/media/webrtc/native_desktop_media_list.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
namespace electron {
namespace atom {
namespace api {
@@ -73,6 +73,6 @@ class DesktopCapturer : public mate::TrackableObject<DesktopCapturer>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_DESKTOP_CAPTURER_H_
#endif // ATOM_BROWSER_API_ATOM_API_DESKTOP_CAPTURER_H_

View File

@@ -0,0 +1,132 @@
// 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_browser_window.h"
#include "atom/browser/native_window.h"
#include "atom/browser/ui/certificate_trust.h"
#include "atom/browser/ui/file_dialog.h"
#include "atom/browser/ui/message_box.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_dialog_converter.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/promise_util.h"
#include "native_mate/dictionary.h"
namespace {
int ShowMessageBoxSync(int type,
const std::vector<std::string>& buttons,
int default_id,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,
const std::string& checkbox_label,
bool checkbox_checked,
const gfx::ImageSkia& icon,
atom::NativeWindow* window) {
return atom::ShowMessageBoxSync(
window, static_cast<atom::MessageBoxType>(type), buttons, default_id,
cancel_id, options, title, message, detail, icon);
}
void ResolvePromiseObject(atom::util::Promise promise,
int result,
bool checkbox_checked) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
dict.Set("response", result);
dict.Set("checkboxChecked", checkbox_checked);
promise.Resolve(dict.GetHandle());
}
v8::Local<v8::Promise> ShowMessageBox(int type,
const std::vector<std::string>& buttons,
int default_id,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,
const std::string& checkbox_label,
bool checkbox_checked,
const gfx::ImageSkia& icon,
atom::NativeWindow* window,
mate::Arguments* args) {
v8::Isolate* isolate = args->isolate();
atom::util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
atom::ShowMessageBox(
window, static_cast<atom::MessageBoxType>(type), buttons, default_id,
cancel_id, options, title, message, detail, checkbox_label,
checkbox_checked, icon,
base::BindOnce(&ResolvePromiseObject, std::move(promise)));
return handle;
}
void ShowOpenDialogSync(const file_dialog::DialogSettings& settings,
mate::Arguments* args) {
std::vector<base::FilePath> paths;
if (file_dialog::ShowOpenDialogSync(settings, &paths))
args->Return(paths);
}
v8::Local<v8::Promise> ShowOpenDialog(
const file_dialog::DialogSettings& settings,
mate::Arguments* args) {
atom::util::Promise promise(args->isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
file_dialog::ShowOpenDialog(settings, std::move(promise));
return handle;
}
void ShowSaveDialogSync(const file_dialog::DialogSettings& settings,
mate::Arguments* args) {
base::FilePath path;
if (file_dialog::ShowSaveDialogSync(settings, &path))
args->Return(path);
}
v8::Local<v8::Promise> ShowSaveDialog(
const file_dialog::DialogSettings& settings,
mate::Arguments* args) {
atom::util::Promise promise(args->isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
file_dialog::ShowSaveDialog(settings, std::move(promise));
return handle;
}
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("showMessageBoxSync", &ShowMessageBoxSync);
dict.SetMethod("showMessageBox", &ShowMessageBox);
dict.SetMethod("showErrorBox", &atom::ShowErrorBox);
dict.SetMethod("showOpenDialogSync", &ShowOpenDialogSync);
dict.SetMethod("showOpenDialog", &ShowOpenDialog);
dict.SetMethod("showSaveDialogSync", &ShowSaveDialogSync);
dict.SetMethod("showSaveDialog", &ShowSaveDialog);
#if defined(OS_MACOSX) || defined(OS_WIN)
dict.SetMethod("showCertificateTrustDialog",
&certificate_trust::ShowCertificateTrust);
#endif
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_dialog, Initialize)

View File

@@ -2,20 +2,20 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_download_item.h"
#include "atom/browser/api/atom_api_download_item.h"
#include <map>
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_dialog_converter.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/node_includes.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "native_mate/dictionary.h"
#include "net/base/filename_util.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/file_dialog_converter.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/node_includes.h"
namespace mate {
@@ -47,7 +47,7 @@ struct Converter<download::DownloadItem::DownloadState> {
} // namespace mate
namespace electron {
namespace atom {
namespace api {
@@ -209,8 +209,6 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isDone", &DownloadItem::IsDone)
.SetMethod("setSavePath", &DownloadItem::SetSavePath)
.SetMethod("getSavePath", &DownloadItem::GetSavePath)
.SetProperty("savePath", &DownloadItem::GetSavePath,
&DownloadItem::SetSavePath)
.SetMethod("setSaveDialogOptions", &DownloadItem::SetSaveDialogOptions)
.SetMethod("getSaveDialogOptions", &DownloadItem::GetSaveDialogOptions)
.SetMethod("getLastModifiedTime", &DownloadItem::GetLastModifiedTime)
@@ -235,7 +233,7 @@ mate::Handle<DownloadItem> DownloadItem::Create(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
@@ -245,7 +243,7 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary(isolate, exports)
.Set("DownloadItem", electron::api::DownloadItem::GetConstructor(isolate)
.Set("DownloadItem", atom::api::DownloadItem::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());
}

View File

@@ -2,20 +2,20 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_DOWNLOAD_ITEM_H_
#define SHELL_BROWSER_API_ATOM_API_DOWNLOAD_ITEM_H_
#ifndef ATOM_BROWSER_API_ATOM_API_DOWNLOAD_ITEM_H_
#define ATOM_BROWSER_API_ATOM_API_DOWNLOAD_ITEM_H_
#include <string>
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/ui/file_dialog.h"
#include "base/files/file_path.h"
#include "components/download/public/common/download_item.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/ui/file_dialog.h"
#include "url/gurl.h"
namespace electron {
namespace atom {
namespace api {
@@ -69,6 +69,6 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_DOWNLOAD_ITEM_H_
#endif // ATOM_BROWSER_API_ATOM_API_DOWNLOAD_ITEM_H_

View File

@@ -2,9 +2,9 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/api/event_emitter.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/common/node_includes.h"
namespace {
@@ -13,17 +13,12 @@ v8::Local<v8::Object> CreateWithSender(v8::Isolate* isolate,
return mate::internal::CreateJSEvent(isolate, sender, nullptr, base::nullopt);
}
v8::Local<v8::Object> CreateEmpty(v8::Isolate* isolate) {
return mate::internal::CreateEmptyJSEvent(isolate);
}
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("createWithSender", &CreateWithSender);
dict.SetMethod("createEmpty", &CreateEmpty);
}
} // namespace

View File

@@ -2,18 +2,18 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_global_shortcut.h"
#include "atom/browser/api/atom_api_global_shortcut.h"
#include <string>
#include <vector>
#include "atom/browser/api/atom_api_system_preferences.h"
#include "atom/common/native_mate_converters/accelerator_converter.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/node_includes.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_system_preferences.h"
#include "shell/common/native_mate_converters/accelerator_converter.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/node_includes.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
@@ -33,7 +33,7 @@ bool RegisteringMediaKeyForUntrustedClient(const ui::Accelerator& accelerator) {
if (std::find(std::begin(mediaKeys), std::end(mediaKeys),
accelerator.key_code()) != std::end(mediaKeys)) {
bool trusted =
electron::api::SystemPreferences::IsTrustedAccessibilityClient(false);
atom::api::SystemPreferences::IsTrustedAccessibilityClient(false);
if (!trusted)
return true;
}
@@ -44,7 +44,7 @@ bool RegisteringMediaKeyForUntrustedClient(const ui::Accelerator& accelerator) {
} // namespace
namespace electron {
namespace atom {
namespace api {
@@ -73,13 +73,19 @@ bool GlobalShortcut::RegisterAll(
std::vector<ui::Accelerator> registered;
for (auto& accelerator : accelerators) {
if (!Register(accelerator, callback)) {
#if defined(OS_MACOSX)
if (RegisteringMediaKeyForUntrustedClient(accelerator))
return false;
GlobalShortcutListener* listener = GlobalShortcutListener::GetInstance();
if (!listener->RegisterAccelerator(accelerator, this)) {
// unregister all shortcuts if any failed
UnregisterSome(registered);
return false;
}
#endif
registered.push_back(accelerator);
accelerator_callback_map_[accelerator] = callback;
}
return true;
}
@@ -101,7 +107,7 @@ bool GlobalShortcut::Register(const ui::Accelerator& accelerator,
}
void GlobalShortcut::Unregister(const ui::Accelerator& accelerator) {
if (!base::Contains(accelerator_callback_map_, accelerator))
if (!ContainsKey(accelerator_callback_map_, accelerator))
return;
accelerator_callback_map_.erase(accelerator);
@@ -117,7 +123,7 @@ void GlobalShortcut::UnregisterSome(
}
bool GlobalShortcut::IsRegistered(const ui::Accelerator& accelerator) {
return base::Contains(accelerator_callback_map_, accelerator);
return ContainsKey(accelerator_callback_map_, accelerator);
}
void GlobalShortcut::UnregisterAll() {
@@ -144,7 +150,7 @@ void GlobalShortcut::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
@@ -154,7 +160,7 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("globalShortcut", electron::api::GlobalShortcut::Create(isolate));
dict.Set("globalShortcut", atom::api::GlobalShortcut::Create(isolate));
}
} // namespace

View File

@@ -2,20 +2,20 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_
#define SHELL_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_
#ifndef ATOM_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_
#define ATOM_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_
#include <map>
#include <string>
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "base/callback.h"
#include "chrome/browser/extensions/global_shortcut_listener.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "ui/base/accelerators/accelerator.h"
namespace electron {
namespace atom {
namespace api {
@@ -53,6 +53,6 @@ class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_
#endif // ATOM_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_

View File

@@ -2,15 +2,15 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_in_app_purchase.h"
#include "atom/browser/api/atom_api_in_app_purchase.h"
#include <string>
#include <utility>
#include <vector>
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/node_includes.h"
namespace mate {
@@ -69,7 +69,7 @@ struct Converter<in_app_purchase::Product> {
} // namespace mate
namespace electron {
namespace atom {
namespace api {
@@ -104,7 +104,7 @@ v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
const std::string& product_id,
mate::Arguments* args) {
v8::Isolate* isolate = args->isolate();
electron::util::Promise promise(isolate);
atom::util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
int quantity = 1;
@@ -112,7 +112,7 @@ v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
in_app_purchase::PurchaseProduct(
product_id, quantity,
base::BindOnce(electron::util::Promise::ResolvePromise<bool>,
base::BindOnce(atom::util::Promise::ResolvePromise<bool>,
std::move(promise)));
return handle;
@@ -122,11 +122,11 @@ v8::Local<v8::Promise> InAppPurchase::GetProducts(
const std::vector<std::string>& productIDs,
mate::Arguments* args) {
v8::Isolate* isolate = args->isolate();
electron::util::Promise promise(isolate);
atom::util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
in_app_purchase::GetProducts(
productIDs, base::BindOnce(electron::util::Promise::ResolvePromise<
productIDs, base::BindOnce(atom::util::Promise::ResolvePromise<
std::vector<in_app_purchase::Product>>,
std::move(promise)));
@@ -141,11 +141,11 @@ void InAppPurchase::OnTransactionsUpdated(
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::InAppPurchase;
using atom::api::InAppPurchase;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,

View File

@@ -2,20 +2,20 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_IN_APP_PURCHASE_H_
#define SHELL_BROWSER_API_ATOM_API_IN_APP_PURCHASE_H_
#ifndef ATOM_BROWSER_API_ATOM_API_IN_APP_PURCHASE_H_
#define ATOM_BROWSER_API_ATOM_API_IN_APP_PURCHASE_H_
#include <string>
#include <vector>
#include "atom/browser/api/event_emitter.h"
#include "atom/browser/mac/in_app_purchase.h"
#include "atom/browser/mac/in_app_purchase_observer.h"
#include "atom/browser/mac/in_app_purchase_product.h"
#include "atom/common/promise_util.h"
#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/browser/mac/in_app_purchase.h"
#include "shell/browser/mac/in_app_purchase_observer.h"
#include "shell/browser/mac/in_app_purchase_product.h"
#include "shell/common/promise_util.h"
namespace electron {
namespace atom {
namespace api {
@@ -47,6 +47,6 @@ class InAppPurchase : public mate::EventEmitter<InAppPurchase>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_IN_APP_PURCHASE_H_
#endif // ATOM_BROWSER_API_ATOM_API_IN_APP_PURCHASE_H_

View File

@@ -2,29 +2,19 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_menu.h"
#include <map>
#include <utility>
#include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/native_window.h"
#include "atom/common/native_mate_converters/accelerator_converter.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_includes.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "shell/browser/native_window.h"
#include "shell/common/native_mate_converters/accelerator_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/node_includes.h"
namespace {
// We need this map to keep references to currently opened menus.
// Without this menus would be destroyed by js garbage collector
// even when they are still displayed.
std::map<uint32_t, v8::Global<v8::Object>> g_menus;
} // unnamed namespace
namespace electron {
namespace atom {
namespace api {
@@ -151,10 +141,6 @@ void Menu::SetSublabel(int index, const base::string16& sublabel) {
model_->SetSublabel(index, sublabel);
}
void Menu::SetToolTip(int index, const base::string16& toolTip) {
model_->SetToolTip(index, toolTip);
}
void Menu::SetRole(int index, const base::string16& role) {
model_->SetRole(index, role);
}
@@ -183,10 +169,6 @@ base::string16 Menu::GetSublabelAt(int index) const {
return model_->GetSublabelAt(index);
}
base::string16 Menu::GetToolTipAt(int index) const {
return model_->GetToolTipAt(index);
}
base::string16 Menu::GetAcceleratorTextAt(int index) const {
ui::Accelerator accelerator;
model_->GetAcceleratorAtWithParams(index, true, &accelerator);
@@ -210,25 +192,13 @@ bool Menu::WorksWhenHiddenAt(int index) const {
}
void Menu::OnMenuWillClose() {
g_menus.erase(weak_map_id());
Emit("menu-will-close");
}
void Menu::OnMenuWillShow() {
g_menus[weak_map_id()] = v8::Global<v8::Object>(isolate(), GetWrapper());
Emit("menu-will-show");
}
base::OnceClosure Menu::BindSelfToClosure(base::OnceClosure callback) {
// return ((callback, ref) => { callback() }).bind(null, callback, this)
v8::Global<v8::Value> ref(isolate(), GetWrapper());
return base::BindOnce(
[](base::OnceClosure callback, v8::Global<v8::Value> ref) {
std::move(callback).Run();
},
std::move(callback), std::move(ref));
}
// static
void Menu::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
@@ -242,7 +212,6 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
.SetMethod("insertSubMenu", &Menu::InsertSubMenuAt)
.SetMethod("setIcon", &Menu::SetIcon)
.SetMethod("setSublabel", &Menu::SetSublabel)
.SetMethod("setToolTip", &Menu::SetToolTip)
.SetMethod("setRole", &Menu::SetRole)
.SetMethod("clear", &Menu::Clear)
.SetMethod("getIndexOfCommandId", &Menu::GetIndexOfCommandId)
@@ -250,7 +219,6 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
.SetMethod("getCommandIdAt", &Menu::GetCommandIdAt)
.SetMethod("getLabelAt", &Menu::GetLabelAt)
.SetMethod("getSublabelAt", &Menu::GetSublabelAt)
.SetMethod("getToolTipAt", &Menu::GetToolTipAt)
.SetMethod("getAcceleratorTextAt", &Menu::GetAcceleratorTextAt)
.SetMethod("isItemCheckedAt", &Menu::IsItemCheckedAt)
.SetMethod("isEnabledAt", &Menu::IsEnabledAt)
@@ -262,18 +230,18 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::Menu;
using atom::api::Menu;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
Menu::SetConstructor(isolate, base::BindRepeating(&Menu::New));
Menu::SetConstructor(isolate, base::Bind(&Menu::New));
mate::Dictionary dict(isolate, exports);
dict.Set(

View File

@@ -2,18 +2,19 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_MENU_H_
#define SHELL_BROWSER_API_ATOM_API_MENU_H_
#ifndef ATOM_BROWSER_API_ATOM_API_MENU_H_
#define ATOM_BROWSER_API_ATOM_API_MENU_H_
#include <memory>
#include <string>
#include "atom/browser/api/atom_api_top_level_window.h"
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/ui/atom_menu_model.h"
#include "atom/common/api/locker.h"
#include "base/callback.h"
#include "shell/browser/api/atom_api_top_level_window.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/ui/atom_menu_model.h"
namespace electron {
namespace atom {
namespace api {
@@ -60,7 +61,7 @@ class Menu : public mate::TrackableObject<Menu>,
int x,
int y,
int positioning_item,
base::OnceClosure callback) = 0;
const base::Closure& callback) = 0;
virtual void ClosePopupAt(int32_t window_id) = 0;
std::unique_ptr<AtomMenuModel> model_;
@@ -70,11 +71,6 @@ class Menu : public mate::TrackableObject<Menu>,
void OnMenuWillClose() override;
void OnMenuWillShow() override;
protected:
// Returns a new callback which keeps references of the JS wrapper until the
// passed |callback| is called.
base::OnceClosure BindSelfToClosure(base::OnceClosure callback);
private:
void InsertItemAt(int index, int command_id, const base::string16& label);
void InsertSeparatorAt(int index);
@@ -91,7 +87,6 @@ class Menu : public mate::TrackableObject<Menu>,
Menu* menu);
void SetIcon(int index, const gfx::Image& image);
void SetSublabel(int index, const base::string16& sublabel);
void SetToolTip(int index, const base::string16& toolTip);
void SetRole(int index, const base::string16& role);
void Clear();
int GetIndexOfCommandId(int command_id);
@@ -99,7 +94,6 @@ class Menu : public mate::TrackableObject<Menu>,
int GetCommandIdAt(int index) const;
base::string16 GetLabelAt(int index) const;
base::string16 GetSublabelAt(int index) const;
base::string16 GetToolTipAt(int index) const;
base::string16 GetAcceleratorTextAt(int index) const;
bool IsItemCheckedAt(int index) const;
bool IsEnabledAt(int index) const;
@@ -107,40 +101,39 @@ class Menu : public mate::TrackableObject<Menu>,
bool WorksWhenHiddenAt(int index) const;
// Stored delegate methods.
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)> is_checked_;
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)> is_enabled_;
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)> is_visible_;
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)> works_when_hidden_;
base::RepeatingCallback<v8::Local<v8::Value>(v8::Local<v8::Value>, int, bool)>
base::Callback<bool(v8::Local<v8::Value>, int)> is_checked_;
base::Callback<bool(v8::Local<v8::Value>, int)> is_enabled_;
base::Callback<bool(v8::Local<v8::Value>, int)> is_visible_;
base::Callback<bool(v8::Local<v8::Value>, int)> works_when_hidden_;
base::Callback<v8::Local<v8::Value>(v8::Local<v8::Value>, int, bool)>
get_accelerator_;
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)>
should_register_accelerator_;
base::RepeatingCallback<void(v8::Local<v8::Value>, v8::Local<v8::Value>, int)>
base::Callback<bool(v8::Local<v8::Value>, int)> should_register_accelerator_;
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>, int)>
execute_command_;
base::RepeatingCallback<void(v8::Local<v8::Value>)> menu_will_show_;
base::Callback<void(v8::Local<v8::Value>)> menu_will_show_;
DISALLOW_COPY_AND_ASSIGN(Menu);
};
} // namespace api
} // namespace electron
} // namespace atom
namespace mate {
template <>
struct Converter<electron::AtomMenuModel*> {
struct Converter<atom::AtomMenuModel*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::AtomMenuModel** out) {
atom::AtomMenuModel** out) {
// null would be tranfered to NULL.
if (val->IsNull()) {
*out = nullptr;
return true;
}
electron::api::Menu* menu;
if (!Converter<electron::api::Menu*>::FromV8(isolate, val, &menu))
atom::api::Menu* menu;
if (!Converter<atom::api::Menu*>::FromV8(isolate, val, &menu))
return false;
*out = menu->model();
return true;
@@ -149,4 +142,4 @@ struct Converter<electron::AtomMenuModel*> {
} // namespace mate
#endif // SHELL_BROWSER_API_ATOM_API_MENU_H_
#endif // ATOM_BROWSER_API_ATOM_API_MENU_H_

View File

@@ -2,19 +2,19 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_MENU_MAC_H_
#define SHELL_BROWSER_API_ATOM_API_MENU_MAC_H_
#ifndef ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_
#define ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_
#include "shell/browser/api/atom_api_menu.h"
#include "atom/browser/api/atom_api_menu.h"
#include <map>
#include <string>
#import "shell/browser/ui/cocoa/atom_menu_controller.h"
#import "atom/browser/ui/cocoa/atom_menu_controller.h"
using base::scoped_nsobject;
namespace electron {
namespace atom {
namespace api {
@@ -27,19 +27,19 @@ class MenuMac : public Menu {
int x,
int y,
int positioning_item,
base::OnceClosure callback) override;
const base::Closure& callback) override;
void PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
int32_t window_id,
int x,
int y,
int positioning_item,
base::OnceClosure callback);
base::Closure callback);
void ClosePopupAt(int32_t window_id) override;
private:
friend class Menu;
void OnClosed(int32_t window_id, base::OnceClosure callback);
void OnClosed(int32_t window_id, base::Closure callback);
scoped_nsobject<AtomMenuController> menu_controller_;
@@ -53,6 +53,6 @@ class MenuMac : public Menu {
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_MENU_MAC_H_
#endif // ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_

View File

@@ -2,21 +2,18 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#import "shell/browser/api/atom_api_menu_mac.h"
#include <string>
#include <utility>
#import "atom/browser/api/atom_api_menu_mac.h"
#include "atom/browser/native_window.h"
#include "atom/browser/unresponsive_suppressor.h"
#include "atom/common/node_includes.h"
#include "base/mac/scoped_sending_event.h"
#include "base/message_loop/message_loop_current.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "shell/browser/native_window.h"
#include "shell/browser/unresponsive_suppressor.h"
#include "shell/common/node_includes.h"
using content::BrowserThread;
@@ -26,7 +23,7 @@ static scoped_nsobject<NSMenu> applicationMenu_;
} // namespace
namespace electron {
namespace atom {
namespace api {
@@ -39,20 +36,15 @@ void MenuMac::PopupAt(TopLevelWindow* window,
int x,
int y,
int positioning_item,
base::OnceClosure callback) {
const base::Closure& callback) {
NativeWindow* native_window = window->window();
if (!native_window)
return;
// Make sure the Menu object would not be garbage-collected until the callback
// has run.
base::OnceClosure callback_with_ref = BindSelfToClosure(std::move(callback));
auto popup =
base::BindOnce(&MenuMac::PopupOnUI, weak_factory_.GetWeakPtr(),
native_window->GetWeakPtr(), window->weak_map_id(), x, y,
positioning_item, std::move(callback_with_ref));
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, std::move(popup));
auto popup = base::Bind(&MenuMac::PopupOnUI, weak_factory_.GetWeakPtr(),
native_window->GetWeakPtr(), window->weak_map_id(), x,
y, positioning_item, callback);
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, popup);
}
void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
@@ -60,14 +52,16 @@ void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
int x,
int y,
int positioning_item,
base::OnceClosure callback) {
base::Closure callback) {
mate::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
if (!native_window)
return;
NSWindow* nswindow = native_window->GetNativeWindow().GetNativeNSWindow();
base::OnceClosure close_callback =
base::BindOnce(&MenuMac::OnClosed, weak_factory_.GetWeakPtr(), window_id,
std::move(callback));
auto close_callback = base::Bind(
&MenuMac::OnClosed, weak_factory_.GetWeakPtr(), window_id, callback);
popup_controllers_[window_id] = base::scoped_nsobject<AtomMenuController>(
[[AtomMenuController alloc] initWithModel:model()
useDefaultAccelerator:NO]);
@@ -105,7 +99,7 @@ void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
if (rightmostMenuPoint > screenRight)
position.x = position.x - [menu size].width;
[popup_controllers_[window_id] setCloseCallback:std::move(close_callback)];
[popup_controllers_[window_id] setCloseCallback:close_callback];
// Make sure events can be pumped while the menu is up.
base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
@@ -117,7 +111,7 @@ void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
base::mac::ScopedSendingEvent sendingEventScoper;
// Don't emit unresponsive event when showing menu.
electron::UnresponsiveSuppressor suppressor;
atom::UnresponsiveSuppressor suppressor;
[menu popUpMenuPositioningItem:item atLocation:position inView:view];
}
@@ -136,9 +130,9 @@ void MenuMac::ClosePopupAt(int32_t window_id) {
}
}
void MenuMac::OnClosed(int32_t window_id, base::OnceClosure callback) {
void MenuMac::OnClosed(int32_t window_id, base::Closure callback) {
popup_controllers_.erase(window_id);
std::move(callback).Run();
callback.Run();
}
// static
@@ -177,4 +171,4 @@ mate::WrappableBase* Menu::New(mate::Arguments* args) {
} // namespace api
} // namespace electron
} // namespace atom

View File

@@ -2,18 +2,17 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_menu_views.h"
#include "atom/browser/api/atom_api_menu_views.h"
#include <memory>
#include <utility>
#include "shell/browser/native_window_views.h"
#include "shell/browser/unresponsive_suppressor.h"
#include "atom/browser/native_window_views.h"
#include "atom/browser/unresponsive_suppressor.h"
#include "ui/display/screen.h"
using views::MenuRunner;
namespace electron {
namespace atom {
namespace api {
@@ -26,7 +25,10 @@ void MenuViews::PopupAt(TopLevelWindow* window,
int x,
int y,
int positioning_item,
base::OnceClosure callback) {
const base::Closure& callback) {
mate::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
auto* native_window = static_cast<NativeWindowViews*>(window->window());
if (!native_window)
return;
@@ -43,23 +45,14 @@ void MenuViews::PopupAt(TopLevelWindow* window,
int flags = MenuRunner::CONTEXT_MENU | MenuRunner::HAS_MNEMONICS;
// Don't emit unresponsive event when showing menu.
electron::UnresponsiveSuppressor suppressor;
// Make sure the Menu object would not be garbage-collected until the callback
// has run.
base::OnceClosure callback_with_ref = BindSelfToClosure(std::move(callback));
atom::UnresponsiveSuppressor suppressor;
// Show the menu.
//
// Note that while views::MenuRunner accepts RepeatingCallback as close
// callback, it is fine passing OnceCallback to it because we reset the
// menu runner immediately when the menu is closed.
int32_t window_id = window->weak_map_id();
auto close_callback = base::AdaptCallbackForRepeating(
base::BindOnce(&MenuViews::OnClosed, weak_factory_.GetWeakPtr(),
window_id, std::move(callback_with_ref)));
auto close_callback = base::Bind(
&MenuViews::OnClosed, weak_factory_.GetWeakPtr(), window_id, callback);
menu_runners_[window_id] =
std::make_unique<MenuRunner>(model(), flags, std::move(close_callback));
std::make_unique<MenuRunner>(model(), flags, close_callback);
menu_runners_[window_id]->RunMenuAt(
native_window->widget(), NULL, gfx::Rect(location, gfx::Size()),
views::MenuAnchorPosition::kTopLeft, ui::MENU_SOURCE_MOUSE);
@@ -79,9 +72,9 @@ void MenuViews::ClosePopupAt(int32_t window_id) {
}
}
void MenuViews::OnClosed(int32_t window_id, base::OnceClosure callback) {
void MenuViews::OnClosed(int32_t window_id, base::Closure callback) {
menu_runners_.erase(window_id);
std::move(callback).Run();
callback.Run();
}
// static
@@ -91,4 +84,4 @@ mate::WrappableBase* Menu::New(mate::Arguments* args) {
} // namespace api
} // namespace electron
} // namespace atom

View File

@@ -2,18 +2,18 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#define SHELL_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#ifndef ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#define ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#include <map>
#include <memory>
#include "atom/browser/api/atom_api_menu.h"
#include "base/memory/weak_ptr.h"
#include "shell/browser/api/atom_api_menu.h"
#include "ui/display/screen.h"
#include "ui/views/controls/menu/menu_runner.h"
namespace electron {
namespace atom {
namespace api {
@@ -27,11 +27,11 @@ class MenuViews : public Menu {
int x,
int y,
int positioning_item,
base::OnceClosure callback) override;
const base::Closure& callback) override;
void ClosePopupAt(int32_t window_id) override;
private:
void OnClosed(int32_t window_id, base::OnceClosure callback);
void OnClosed(int32_t window_id, base::Closure callback);
// window ID -> open context menu
std::map<int32_t, std::unique_ptr<views::MenuRunner>> menu_runners_;
@@ -43,6 +43,6 @@ class MenuViews : public Menu {
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#endif // ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_

View File

@@ -2,18 +2,12 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_net.h"
#include <string>
#include "atom/browser/api/atom_api_net.h"
#include "atom/browser/api/atom_api_url_request.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "services/network/public/cpp/features.h"
#include "shell/browser/api/atom_api_url_loader.h"
#include "shell/common/node_includes.h"
namespace electron {
namespace atom {
namespace api {
@@ -33,32 +27,23 @@ void Net::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Net"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetProperty("URLLoader", &Net::URLLoader);
.SetProperty("URLRequest", &Net::URLRequest);
}
v8::Local<v8::Value> Net::URLLoader(v8::Isolate* isolate) {
v8::Local<v8::FunctionTemplate> constructor;
constructor = SimpleURLLoaderWrapper::GetConstructor(isolate);
return constructor->GetFunction(isolate->GetCurrentContext())
v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
return URLRequest::GetConstructor(isolate)
->GetFunction(isolate->GetCurrentContext())
.ToLocalChecked();
}
} // namespace api
} // namespace electron
} // namespace atom
namespace {
bool IsValidHeaderName(std::string header_name) {
return net::HttpUtil::IsValidHeaderName(header_name);
}
bool IsValidHeaderValue(std::string header_value) {
return net::HttpUtil::IsValidHeaderValue(header_value);
}
using electron::api::Net;
using electron::api::SimpleURLLoaderWrapper;
using atom::api::Net;
using atom::api::URLRequest;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
@@ -66,15 +51,12 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
SimpleURLLoaderWrapper::SetConstructor(
isolate, base::BindRepeating(SimpleURLLoaderWrapper::New));
URLRequest::SetConstructor(isolate, base::Bind(URLRequest::New));
mate::Dictionary dict(isolate, exports);
dict.Set("net", Net::Create(isolate));
dict.Set("Net",
Net::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
dict.SetMethod("_isValidHeaderName", &IsValidHeaderName);
dict.SetMethod("_isValidHeaderValue", &IsValidHeaderValue);
}
} // namespace

View File

@@ -2,12 +2,12 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_NET_H_
#define SHELL_BROWSER_API_ATOM_API_NET_H_
#ifndef ATOM_BROWSER_API_ATOM_API_NET_H_
#define ATOM_BROWSER_API_ATOM_API_NET_H_
#include "shell/browser/api/event_emitter.h"
#include "atom/browser/api/event_emitter.h"
namespace electron {
namespace atom {
namespace api {
@@ -18,7 +18,7 @@ class Net : public mate::EventEmitter<Net> {
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
v8::Local<v8::Value> URLLoader(v8::Isolate* isolate);
v8::Local<v8::Value> URLRequest(v8::Isolate* isolate);
protected:
explicit Net(v8::Isolate* isolate);
@@ -30,6 +30,6 @@ class Net : public mate::EventEmitter<Net> {
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_NET_H_
#endif // ATOM_BROWSER_API_ATOM_API_NET_H_

View File

@@ -0,0 +1,140 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/api/atom_api_net_log.h"
#include <utility>
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/net/system_network_context_manager.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/node_includes.h"
#include "base/command_line.h"
#include "chrome/browser/browser_process.h"
#include "components/net_log/chrome_net_log.h"
#include "content/public/browser/storage_partition.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "net/url_request/url_request_context_getter.h"
namespace atom {
namespace api {
NetLog::NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context)
: browser_context_(browser_context) {
Init(isolate);
net_log_writer_ = g_browser_process->system_network_context_manager()
->GetNetExportFileWriter();
net_log_writer_->AddObserver(this);
}
NetLog::~NetLog() {
net_log_writer_->RemoveObserver(this);
}
void NetLog::StartLogging(mate::Arguments* args) {
base::FilePath log_path;
if (!args->GetNext(&log_path) || log_path.empty()) {
args->ThrowError("The first parameter must be a valid string");
return;
}
auto* network_context =
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
->GetNetworkContext();
// TODO(deepak1556): Provide more flexibility to this module
// by allowing customizations on the capturing options.
net_log_writer_->StartNetLog(
log_path, net::NetLogCaptureMode::Default(),
net_log::NetExportFileWriter::kNoLimit /* file size limit */,
base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
std::string(), network_context);
}
std::string NetLog::GetLoggingState() const {
if (!net_log_state_)
return std::string();
const base::Value* current_log_state =
net_log_state_->FindKeyOfType("state", base::Value::Type::STRING);
if (!current_log_state)
return std::string();
return current_log_state->GetString();
}
bool NetLog::IsCurrentlyLogging() const {
const std::string log_state = GetLoggingState();
return (log_state == "STARTING_LOG") || (log_state == "LOGGING");
}
std::string NetLog::GetCurrentlyLoggingPath() const {
// Net log exporter has a default path which will be used
// when no log path is provided, but since we don't allow
// net log capture without user provided file path, this
// check is completely safe.
if (IsCurrentlyLogging()) {
const base::Value* current_log_path =
net_log_state_->FindKeyOfType("file", base::Value::Type::STRING);
if (current_log_path)
return current_log_path->GetString();
}
return std::string();
}
v8::Local<v8::Promise> NetLog::StopLogging(mate::Arguments* args) {
util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
if (IsCurrentlyLogging()) {
stop_callback_queue_.emplace_back(std::move(promise));
net_log_writer_->StopNetLog(nullptr);
} else {
promise.Resolve(base::FilePath());
}
return handle;
}
void NetLog::OnNewState(const base::DictionaryValue& state) {
net_log_state_ = state.CreateDeepCopy();
if (stop_callback_queue_.empty())
return;
if (GetLoggingState() == "NOT_LOGGING") {
for (auto& promise : stop_callback_queue_) {
// TODO(zcbenz): Remove the use of CopyablePromise when the
// GetFilePathToCompletedLog API accepts OnceCallback.
net_log_writer_->GetFilePathToCompletedLog(base::Bind(
util::CopyablePromise::ResolveCopyablePromise<const base::FilePath&>,
util::CopyablePromise(promise)));
}
stop_callback_queue_.clear();
}
}
// static
mate::Handle<NetLog> NetLog::Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
return mate::CreateHandle(isolate, new NetLog(isolate, browser_context));
}
// static
void NetLog::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "NetLog"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetProperty("currentlyLogging", &NetLog::IsCurrentlyLogging)
.SetProperty("currentlyLoggingPath", &NetLog::GetCurrentlyLoggingPath)
.SetMethod("startLogging", &NetLog::StartLogging)
.SetMethod("stopLogging", &NetLog::StopLogging);
}
} // namespace api
} // namespace atom

View File

@@ -0,0 +1,60 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_API_ATOM_API_NET_LOG_H_
#define ATOM_BROWSER_API_ATOM_API_NET_LOG_H_
#include <list>
#include <memory>
#include <string>
#include "atom/browser/api/trackable_object.h"
#include "atom/common/promise_util.h"
#include "base/callback.h"
#include "base/values.h"
#include "components/net_log/net_export_file_writer.h"
#include "native_mate/handle.h"
namespace atom {
class AtomBrowserContext;
namespace api {
class NetLog : public mate::TrackableObject<NetLog>,
public net_log::NetExportFileWriter::StateObserver {
public:
static mate::Handle<NetLog> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
void StartLogging(mate::Arguments* args);
std::string GetLoggingState() const;
bool IsCurrentlyLogging() const;
std::string GetCurrentlyLoggingPath() const;
v8::Local<v8::Promise> StopLogging(mate::Arguments* args);
protected:
explicit NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context);
~NetLog() override;
// net_log::NetExportFileWriter::StateObserver implementation
void OnNewState(const base::DictionaryValue& state) override;
private:
AtomBrowserContext* browser_context_;
net_log::NetExportFileWriter* net_log_writer_;
std::list<atom::util::Promise> stop_callback_queue_;
std::unique_ptr<base::DictionaryValue> net_log_state_;
DISALLOW_COPY_AND_ASSIGN(NetLog);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_NET_LOG_H_

View File

@@ -2,28 +2,28 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_notification.h"
#include "atom/browser/api/atom_api_notification.h"
#include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/browser/browser.h"
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_includes.h"
#include "base/guid.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "shell/browser/api/atom_api_menu.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/browser.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/node_includes.h"
#include "url/gurl.h"
namespace mate {
template <>
struct Converter<electron::NotificationAction> {
struct Converter<atom::NotificationAction> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::NotificationAction* out) {
atom::NotificationAction* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
@@ -36,7 +36,7 @@ struct Converter<electron::NotificationAction> {
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::NotificationAction val) {
atom::NotificationAction val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("text", val.text);
dict.Set("type", val.type);
@@ -45,7 +45,7 @@ struct Converter<electron::NotificationAction> {
};
} // namespace mate
namespace electron {
namespace atom {
namespace api {
@@ -118,7 +118,7 @@ base::string16 Notification::GetSound() const {
return sound_;
}
std::vector<electron::NotificationAction> Notification::GetActions() const {
std::vector<atom::NotificationAction> Notification::GetActions() const {
return actions_;
}
@@ -156,7 +156,7 @@ void Notification::SetSound(const base::string16& new_sound) {
}
void Notification::SetActions(
const std::vector<electron::NotificationAction>& actions) {
const std::vector<atom::NotificationAction>& actions) {
actions_ = actions;
}
@@ -189,7 +189,6 @@ void Notification::NotificationClosed() {
void Notification::Close() {
if (notification_) {
notification_->Dismiss();
notification_->set_delegate(nullptr);
notification_.reset();
}
}
@@ -200,7 +199,7 @@ void Notification::Show() {
if (presenter_) {
notification_ = presenter_->CreateNotification(this, base::GenerateGUID());
if (notification_) {
electron::NotificationOptions options;
atom::NotificationOptions options;
options.title = title_;
options.subtitle = subtitle_;
options.msg = body_;
@@ -248,19 +247,18 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::Notification;
using atom::api::Notification;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
Notification::SetConstructor(isolate,
base::BindRepeating(&Notification::New));
Notification::SetConstructor(isolate, base::Bind(&Notification::New));
mate::Dictionary dict(isolate, exports);
dict.Set("Notification", Notification::GetConstructor(isolate)

View File

@@ -2,22 +2,22 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_NOTIFICATION_H_
#define SHELL_BROWSER_API_ATOM_API_NOTIFICATION_H_
#ifndef ATOM_BROWSER_API_ATOM_API_NOTIFICATION_H_
#define ATOM_BROWSER_API_ATOM_API_NOTIFICATION_H_
#include <memory>
#include <string>
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/notifications/notification.h"
#include "atom/browser/notifications/notification_delegate.h"
#include "atom/browser/notifications/notification_presenter.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/notifications/notification.h"
#include "shell/browser/notifications/notification_delegate.h"
#include "shell/browser/notifications/notification_presenter.h"
#include "ui/gfx/image/image.h"
namespace electron {
namespace atom {
namespace api {
@@ -55,7 +55,7 @@ class Notification : public mate::TrackableObject<Notification>,
bool GetHasReply() const;
base::string16 GetReplyPlaceholder() const;
base::string16 GetSound() const;
std::vector<electron::NotificationAction> GetActions() const;
std::vector<atom::NotificationAction> GetActions() const;
base::string16 GetCloseButtonText() const;
// Prop Setters
@@ -66,7 +66,7 @@ class Notification : public mate::TrackableObject<Notification>,
void SetHasReply(bool new_has_reply);
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
void SetSound(const base::string16& sound);
void SetActions(const std::vector<electron::NotificationAction>& actions);
void SetActions(const std::vector<atom::NotificationAction>& actions);
void SetCloseButtonText(const base::string16& text);
private:
@@ -80,18 +80,18 @@ class Notification : public mate::TrackableObject<Notification>,
bool has_reply_ = false;
base::string16 reply_placeholder_;
base::string16 sound_;
std::vector<electron::NotificationAction> actions_;
std::vector<atom::NotificationAction> actions_;
base::string16 close_button_text_;
electron::NotificationPresenter* presenter_;
atom::NotificationPresenter* presenter_;
base::WeakPtr<electron::Notification> notification_;
base::WeakPtr<atom::Notification> notification_;
DISALLOW_COPY_AND_ASSIGN(Notification);
};
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_NOTIFICATION_H_
#endif // ATOM_BROWSER_API_ATOM_API_NOTIFICATION_H_

View File

@@ -2,14 +2,14 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_power_monitor.h"
#include "atom/browser/api/atom_api_power_monitor.h"
#include "atom/browser/browser.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/node_includes.h"
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_device_source.h"
#include "native_mate/dictionary.h"
#include "shell/browser/browser.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/node_includes.h"
namespace mate {
template <>
@@ -31,19 +31,19 @@ struct Converter<ui::IdleState> {
};
} // namespace mate
namespace electron {
namespace atom {
namespace api {
PowerMonitor::PowerMonitor(v8::Isolate* isolate) {
#if defined(OS_LINUX)
SetShutdownHandler(base::BindRepeating(&PowerMonitor::ShouldShutdown,
base::Unretained(this)));
SetShutdownHandler(
base::Bind(&PowerMonitor::ShouldShutdown, base::Unretained(this)));
#elif defined(OS_MACOSX)
Browser::Get()->SetShutdownHandler(base::BindRepeating(
&PowerMonitor::ShouldShutdown, base::Unretained(this)));
Browser::Get()->SetShutdownHandler(
base::Bind(&PowerMonitor::ShouldShutdown, base::Unretained(this)));
#endif
base::PowerMonitor::AddObserver(this);
base::PowerMonitor::Get()->AddObserver(this);
Init(isolate);
#if defined(OS_MACOSX) || defined(OS_WIN)
InitPlatformSpecificMonitors();
@@ -51,7 +51,7 @@ PowerMonitor::PowerMonitor(v8::Isolate* isolate) {
}
PowerMonitor::~PowerMonitor() {
base::PowerMonitor::RemoveObserver(this);
base::PowerMonitor::Get()->RemoveObserver(this);
}
bool PowerMonitor::ShouldShutdown() {
@@ -101,10 +101,9 @@ int PowerMonitor::GetSystemIdleTime() {
// static
v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
if (!Browser::Get()->is_ready()) {
isolate->ThrowException(v8::Exception::Error(
mate::StringToV8(isolate,
"The 'powerMonitor' module can't be used before the "
"app 'ready' event")));
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate,
"Cannot require \"powerMonitor\" module before app is ready")));
return v8::Null(isolate);
}
@@ -128,11 +127,11 @@ void PowerMonitor::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::PowerMonitor;
using atom::api::PowerMonitor;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
@@ -140,8 +139,7 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("createPowerMonitor",
base::BindRepeating(&PowerMonitor::Create, isolate));
dict.Set("powerMonitor", PowerMonitor::Create(isolate));
dict.Set("PowerMonitor", PowerMonitor::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());

View File

@@ -2,16 +2,16 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#define SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#ifndef ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#define ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/lib/power_observer.h"
#include "base/compiler_specific.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/lib/power_observer.h"
#include "ui/base/idle/idle.h"
namespace electron {
namespace atom {
namespace api {
@@ -76,6 +76,6 @@ class PowerMonitor : public mate::TrackableObject<PowerMonitor>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#endif // ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_

View File

@@ -2,19 +2,17 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_power_monitor.h"
#include "atom/browser/api/atom_api_power_monitor.h"
#include <vector>
#import <ApplicationServices/ApplicationServices.h>
#include <ApplicationServices/ApplicationServices.h>
#import <Cocoa/Cocoa.h>
@interface MacLockMonitor : NSObject {
@private
std::vector<electron::api::PowerMonitor*> emitters;
std::vector<atom::api::PowerMonitor*> emitters;
}
- (void)addEmitter:(electron::api::PowerMonitor*)monitor_;
- (void)addEmitter:(atom::api::PowerMonitor*)monitor_;
@end
@@ -41,7 +39,7 @@
[super dealloc];
}
- (void)addEmitter:(electron::api::PowerMonitor*)monitor_ {
- (void)addEmitter:(atom::api::PowerMonitor*)monitor_ {
self->emitters.push_back(monitor_);
}
@@ -59,7 +57,7 @@
@end
namespace electron {
namespace atom {
namespace api {
@@ -73,4 +71,4 @@ void PowerMonitor::InitPlatformSpecificMonitors() {
} // namespace api
} // namespace electron
} // namespace atom

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_power_monitor.h"
#include "atom/browser/api/atom_api_power_monitor.h"
#include <windows.h>
#include <wtsapi32.h>
@@ -11,7 +11,7 @@
#include "ui/base/win/shell.h"
#include "ui/gfx/win/hwnd_util.h"
namespace electron {
namespace atom {
namespace {
@@ -69,4 +69,4 @@ LRESULT CALLBACK PowerMonitor::WndProc(HWND hwnd,
} // namespace api
} // namespace electron
} // namespace atom

View File

@@ -2,22 +2,20 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_power_save_blocker.h"
#include "atom/browser/api/atom_api_power_save_blocker.h"
#include <string>
#include "base/bind_helpers.h"
#include "atom/common/node_includes.h"
#include "base/task/post_task.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/common/service_manager_connection.h"
#include "gin/dictionary.h"
#include "gin/function_template.h"
#include "native_mate/dictionary.h"
#include "services/device/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "shell/common/node_includes.h"
namespace gin {
namespace mate {
template <>
struct Converter<device::mojom::WakeLockType> {
@@ -37,17 +35,17 @@ struct Converter<device::mojom::WakeLockType> {
}
};
} // namespace gin
} // namespace mate
namespace electron {
namespace atom {
namespace api {
gin::WrapperInfo PowerSaveBlocker::kWrapperInfo = {gin::kEmbedderNativeGin};
PowerSaveBlocker::PowerSaveBlocker(v8::Isolate* isolate)
: current_lock_type_(device::mojom::WakeLockType::kPreventAppSuspension),
is_wake_lock_active_(false) {}
is_wake_lock_active_(false) {
Init(isolate);
}
PowerSaveBlocker::~PowerSaveBlocker() {}
@@ -96,7 +94,7 @@ device::mojom::WakeLock* PowerSaveBlocker::GetWakeLock() {
wake_lock_provider->GetWakeLockWithoutContext(
device::mojom::WakeLockType::kPreventAppSuspension,
device::mojom::WakeLockReason::kOther, ELECTRON_PRODUCT_NAME,
device::mojom::WakeLockReason::kOther, ATOM_PRODUCT_NAME,
mojo::MakeRequest(&wake_lock_));
}
return wake_lock_.get();
@@ -120,13 +118,16 @@ bool PowerSaveBlocker::IsStarted(int id) {
}
// static
gin::Handle<PowerSaveBlocker> PowerSaveBlocker::Create(v8::Isolate* isolate) {
return gin::CreateHandle(isolate, new PowerSaveBlocker(isolate));
mate::Handle<PowerSaveBlocker> PowerSaveBlocker::Create(v8::Isolate* isolate) {
return mate::CreateHandle(isolate, new PowerSaveBlocker(isolate));
}
gin::ObjectTemplateBuilder PowerSaveBlocker::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return gin::Wrappable<PowerSaveBlocker>::GetObjectTemplateBuilder(isolate)
// static
void PowerSaveBlocker::BuildPrototype(
v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "PowerSaveBlocker"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("start", &PowerSaveBlocker::Start)
.SetMethod("stop", &PowerSaveBlocker::Stop)
.SetMethod("isStarted", &PowerSaveBlocker::IsStarted);
@@ -134,7 +135,7 @@ gin::ObjectTemplateBuilder PowerSaveBlocker::GetObjectTemplateBuilder(
} // namespace api
} // namespace electron
} // namespace atom
namespace {
@@ -143,9 +144,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
gin::Dictionary dict(isolate, exports);
dict.Set("powerSaveBlocker",
electron::api::PowerSaveBlocker::Create(isolate));
mate::Dictionary dict(isolate, exports);
dict.Set("powerSaveBlocker", atom::api::PowerSaveBlocker::Create(isolate));
}
} // namespace

View File

@@ -2,30 +2,30 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_POWER_SAVE_BLOCKER_H_
#define SHELL_BROWSER_API_ATOM_API_POWER_SAVE_BLOCKER_H_
#ifndef ATOM_BROWSER_API_ATOM_API_POWER_SAVE_BLOCKER_H_
#define ATOM_BROWSER_API_ATOM_API_POWER_SAVE_BLOCKER_H_
#include <map>
#include <memory>
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
#include "atom/browser/api/trackable_object.h"
#include "native_mate/handle.h"
#include "services/device/public/mojom/wake_lock.mojom.h"
namespace electron {
namespace mate {
class Dictionary;
}
namespace atom {
namespace api {
class PowerSaveBlocker : public gin::Wrappable<PowerSaveBlocker> {
class PowerSaveBlocker : public mate::TrackableObject<PowerSaveBlocker> {
public:
static gin::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
static mate::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
// gin::Wrappable
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) override;
static gin::WrapperInfo kWrapperInfo;
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit PowerSaveBlocker(v8::Isolate* isolate);
@@ -56,6 +56,6 @@ class PowerSaveBlocker : public gin::Wrappable<PowerSaveBlocker> {
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_POWER_SAVE_BLOCKER_H_
#endif // ATOM_BROWSER_API_ATOM_API_POWER_SAVE_BLOCKER_H_

View File

@@ -0,0 +1,316 @@
// 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 "atom/browser/atom_browser_client.h"
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/browser.h"
#include "atom/browser/net/url_request_async_asar_job.h"
#include "atom/browser/net/url_request_buffer_job.h"
#include "atom/browser/net/url_request_fetch_job.h"
#include "atom/browser/net/url_request_stream_job.h"
#include "atom/browser/net/url_request_string_job.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "content/public/browser/child_process_security_policy.h"
#include "native_mate/dictionary.h"
#include "url/url_util.h"
using content::BrowserThread;
namespace {
// List of registered custom standard schemes.
std::vector<std::string> g_standard_schemes;
struct SchemeOptions {
bool standard = false;
bool secure = false;
bool bypassCSP = false;
bool allowServiceWorkers = false;
bool supportFetchAPI = false;
bool corsEnabled = false;
};
struct CustomScheme {
std::string scheme;
SchemeOptions options;
};
} // namespace
namespace mate {
template <>
struct Converter<CustomScheme> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
CustomScheme* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!dict.Get("scheme", &(out->scheme)))
return false;
mate::Dictionary opt;
// options are optional. Default values specified in SchemeOptions are used
if (dict.Get("privileges", &opt)) {
opt.Get("standard", &(out->options.standard));
opt.Get("supportFetchAPI", &(out->options.supportFetchAPI));
opt.Get("secure", &(out->options.secure));
opt.Get("bypassCSP", &(out->options.bypassCSP));
opt.Get("allowServiceWorkers", &(out->options.allowServiceWorkers));
opt.Get("supportFetchAPI", &(out->options.supportFetchAPI));
opt.Get("corsEnabled", &(out->options.corsEnabled));
}
return true;
}
};
} // namespace mate
namespace atom {
namespace api {
std::vector<std::string> GetStandardSchemes() {
return g_standard_schemes;
}
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
mate::Arguments* args) {
std::vector<CustomScheme> custom_schemes;
if (!mate::ConvertFromV8(args->isolate(), val, &custom_schemes)) {
args->ThrowError("Argument must be an array of custom schemes.");
return;
}
std::vector<std::string> secure_schemes, cspbypassing_schemes, fetch_schemes,
service_worker_schemes, cors_schemes;
for (const auto& custom_scheme : custom_schemes) {
// Register scheme to privileged list (https, wss, data, chrome-extension)
if (custom_scheme.options.standard) {
auto* policy = content::ChildProcessSecurityPolicy::GetInstance();
url::AddStandardScheme(custom_scheme.scheme.c_str(),
url::SCHEME_WITH_HOST);
g_standard_schemes.push_back(custom_scheme.scheme);
policy->RegisterWebSafeScheme(custom_scheme.scheme);
}
if (custom_scheme.options.secure) {
secure_schemes.push_back(custom_scheme.scheme);
url::AddSecureScheme(custom_scheme.scheme.c_str());
}
if (custom_scheme.options.bypassCSP) {
cspbypassing_schemes.push_back(custom_scheme.scheme);
url::AddCSPBypassingScheme(custom_scheme.scheme.c_str());
}
if (custom_scheme.options.corsEnabled) {
cors_schemes.push_back(custom_scheme.scheme);
url::AddCorsEnabledScheme(custom_scheme.scheme.c_str());
}
if (custom_scheme.options.supportFetchAPI) {
fetch_schemes.push_back(custom_scheme.scheme);
}
if (custom_scheme.options.allowServiceWorkers) {
service_worker_schemes.push_back(custom_scheme.scheme);
}
}
const auto AppendSchemesToCmdLine = [](const char* switch_name,
std::vector<std::string> schemes) {
// Add the schemes to command line switches, so child processes can also
// register them.
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switch_name, base::JoinString(schemes, ","));
};
AppendSchemesToCmdLine(atom::switches::kSecureSchemes, secure_schemes);
AppendSchemesToCmdLine(atom::switches::kBypassCSPSchemes,
cspbypassing_schemes);
AppendSchemesToCmdLine(atom::switches::kCORSSchemes, cors_schemes);
AppendSchemesToCmdLine(atom::switches::kFetchSchemes, fetch_schemes);
AppendSchemesToCmdLine(atom::switches::kServiceWorkerSchemes,
service_worker_schemes);
AppendSchemesToCmdLine(atom::switches::kStandardSchemes, g_standard_schemes);
}
Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
: browser_context_(browser_context), weak_factory_(this) {
Init(isolate);
}
Protocol::~Protocol() {}
void Protocol::UnregisterProtocol(const std::string& scheme,
mate::Arguments* args) {
CompletionCallback callback;
args->GetNext(&callback);
auto* getter = static_cast<URLRequestContextGetter*>(
browser_context_->GetRequestContext());
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&Protocol::UnregisterProtocolInIO,
base::RetainedRef(getter), scheme),
base::BindOnce(&Protocol::OnIOCompleted, GetWeakPtr(), callback));
}
// static
Protocol::ProtocolError Protocol::UnregisterProtocolInIO(
scoped_refptr<URLRequestContextGetter> request_context_getter,
const std::string& scheme) {
auto* job_factory = request_context_getter->job_factory();
if (!job_factory->HasProtocolHandler(scheme))
return PROTOCOL_NOT_REGISTERED;
job_factory->SetProtocolHandler(scheme, nullptr);
return PROTOCOL_OK;
}
bool IsProtocolHandledInIO(
scoped_refptr<URLRequestContextGetter> request_context_getter,
const std::string& scheme) {
bool is_handled =
request_context_getter->job_factory()->IsHandledProtocol(scheme);
return is_handled;
}
v8::Local<v8::Promise> Protocol::IsProtocolHandled(const std::string& scheme) {
util::Promise promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
auto* getter = static_cast<URLRequestContextGetter*>(
browser_context_->GetRequestContext());
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&IsProtocolHandledInIO, base::RetainedRef(getter), scheme),
base::BindOnce(util::Promise::ResolvePromise<bool>, std::move(promise)));
return handle;
}
void Protocol::UninterceptProtocol(const std::string& scheme,
mate::Arguments* args) {
CompletionCallback callback;
args->GetNext(&callback);
auto* getter = static_cast<URLRequestContextGetter*>(
browser_context_->GetRequestContext());
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&Protocol::UninterceptProtocolInIO,
base::RetainedRef(getter), scheme),
base::BindOnce(&Protocol::OnIOCompleted, GetWeakPtr(), callback));
}
// static
Protocol::ProtocolError Protocol::UninterceptProtocolInIO(
scoped_refptr<URLRequestContextGetter> request_context_getter,
const std::string& scheme) {
return request_context_getter->job_factory()->UninterceptProtocol(scheme)
? PROTOCOL_OK
: PROTOCOL_NOT_INTERCEPTED;
}
void Protocol::OnIOCompleted(const CompletionCallback& callback,
ProtocolError error) {
// The completion callback is optional.
if (callback.is_null())
return;
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
if (error == PROTOCOL_OK) {
callback.Run(v8::Null(isolate()));
} else {
std::string str = ErrorCodeToString(error);
callback.Run(v8::Exception::Error(mate::StringToV8(isolate(), str)));
}
}
std::string Protocol::ErrorCodeToString(ProtocolError error) {
switch (error) {
case PROTOCOL_FAIL:
return "Failed to manipulate protocol factory";
case PROTOCOL_REGISTERED:
return "The scheme has been registered";
case PROTOCOL_NOT_REGISTERED:
return "The scheme has not been registered";
case PROTOCOL_INTERCEPTED:
return "The scheme has been intercepted";
case PROTOCOL_NOT_INTERCEPTED:
return "The scheme has not been intercepted";
default:
return "Unexpected error";
}
}
// static
mate::Handle<Protocol> Protocol::Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
return mate::CreateHandle(isolate, new Protocol(isolate, browser_context));
}
// static
void Protocol::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Protocol"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("registerStringProtocol",
&Protocol::RegisterProtocol<URLRequestStringJob>)
.SetMethod("registerBufferProtocol",
&Protocol::RegisterProtocol<URLRequestBufferJob>)
.SetMethod("registerFileProtocol",
&Protocol::RegisterProtocol<URLRequestAsyncAsarJob>)
.SetMethod("registerHttpProtocol",
&Protocol::RegisterProtocol<URLRequestFetchJob>)
.SetMethod("registerStreamProtocol",
&Protocol::RegisterProtocol<URLRequestStreamJob>)
.SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol)
.SetMethod("isProtocolHandled", &Protocol::IsProtocolHandled)
.SetMethod("interceptStringProtocol",
&Protocol::InterceptProtocol<URLRequestStringJob>)
.SetMethod("interceptBufferProtocol",
&Protocol::InterceptProtocol<URLRequestBufferJob>)
.SetMethod("interceptFileProtocol",
&Protocol::InterceptProtocol<URLRequestAsyncAsarJob>)
.SetMethod("interceptHttpProtocol",
&Protocol::InterceptProtocol<URLRequestFetchJob>)
.SetMethod("interceptStreamProtocol",
&Protocol::InterceptProtocol<URLRequestStreamJob>)
.SetMethod("uninterceptProtocol", &Protocol::UninterceptProtocol);
}
} // namespace api
} // namespace atom
namespace {
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
mate::Arguments* args) {
if (atom::Browser::Get()->is_ready()) {
args->ThrowError(
"protocol.registerSchemesAsPrivileged should be called before "
"app is ready");
return;
}
atom::api::RegisterSchemesAsPrivileged(val, args);
}
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.SetMethod("registerSchemesAsPrivileged", &RegisterSchemesAsPrivileged);
dict.SetMethod("getStandardSchemes", &atom::api::GetStandardSchemes);
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_protocol, Initialize)

View File

@@ -0,0 +1,197 @@
// 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_API_ATOM_API_PROTOCOL_H_
#define ATOM_BROWSER_API_ATOM_API_PROTOCOL_H_
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/net/atom_url_request_job_factory.h"
#include "atom/common/promise_util.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/arguments.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "net/url_request/url_request_context.h"
namespace base {
class DictionaryValue;
}
namespace atom {
namespace api {
std::vector<std::string> GetStandardSchemes();
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
mate::Arguments* args);
class Protocol : public mate::TrackableObject<Protocol> {
public:
using Handler =
base::Callback<void(const base::DictionaryValue&, v8::Local<v8::Value>)>;
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
static mate::Handle<Protocol> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context);
~Protocol() override;
private:
// Possible errors.
enum ProtocolError {
PROTOCOL_OK, // no error
PROTOCOL_FAIL, // operation failed, should never occur
PROTOCOL_REGISTERED,
PROTOCOL_NOT_REGISTERED,
PROTOCOL_INTERCEPTED,
PROTOCOL_NOT_INTERCEPTED,
};
// The protocol handler that will create a protocol handler for certain
// request job.
template <typename RequestJob>
class CustomProtocolHandler
: public net::URLRequestJobFactory::ProtocolHandler {
public:
CustomProtocolHandler(v8::Isolate* isolate,
net::URLRequestContextGetter* request_context,
const Handler& handler)
: isolate_(isolate),
request_context_(request_context),
handler_(handler) {}
~CustomProtocolHandler() override {}
net::URLRequestJob* MaybeCreateJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override {
RequestJob* request_job = new RequestJob(request, network_delegate);
request_job->SetHandlerInfo(isolate_, request_context_, handler_);
return request_job;
}
private:
v8::Isolate* isolate_;
net::URLRequestContextGetter* request_context_;
Protocol::Handler handler_;
DISALLOW_COPY_AND_ASSIGN(CustomProtocolHandler);
};
// Register the protocol with certain request job.
template <typename RequestJob>
void RegisterProtocol(const std::string& scheme,
const Handler& handler,
mate::Arguments* args) {
CompletionCallback callback;
args->GetNext(&callback);
auto* getter = static_cast<URLRequestContextGetter*>(
browser_context_->GetRequestContext());
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&Protocol::RegisterProtocolInIO<RequestJob>,
base::RetainedRef(getter), isolate(), scheme, handler),
base::BindOnce(&Protocol::OnIOCompleted, GetWeakPtr(), callback));
}
template <typename RequestJob>
static ProtocolError RegisterProtocolInIO(
scoped_refptr<URLRequestContextGetter> request_context_getter,
v8::Isolate* isolate,
const std::string& scheme,
const Handler& handler) {
auto* job_factory = request_context_getter->job_factory();
if (job_factory->IsHandledProtocol(scheme))
return PROTOCOL_REGISTERED;
auto protocol_handler = std::make_unique<CustomProtocolHandler<RequestJob>>(
isolate, request_context_getter.get(), handler);
if (job_factory->SetProtocolHandler(scheme, std::move(protocol_handler)))
return PROTOCOL_OK;
else
return PROTOCOL_FAIL;
}
// Unregister the protocol handler that handles |scheme|.
void UnregisterProtocol(const std::string& scheme, mate::Arguments* args);
static ProtocolError UnregisterProtocolInIO(
scoped_refptr<URLRequestContextGetter> request_context_getter,
const std::string& scheme);
// Whether the protocol has handler registered.
v8::Local<v8::Promise> IsProtocolHandled(const std::string& scheme);
// Replace the protocol handler with a new one.
template <typename RequestJob>
void InterceptProtocol(const std::string& scheme,
const Handler& handler,
mate::Arguments* args) {
CompletionCallback callback;
args->GetNext(&callback);
auto* getter = static_cast<URLRequestContextGetter*>(
browser_context_->GetRequestContext());
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&Protocol::InterceptProtocolInIO<RequestJob>,
base::RetainedRef(getter), isolate(), scheme, handler),
base::BindOnce(&Protocol::OnIOCompleted, GetWeakPtr(), callback));
}
template <typename RequestJob>
static ProtocolError InterceptProtocolInIO(
scoped_refptr<URLRequestContextGetter> request_context_getter,
v8::Isolate* isolate,
const std::string& scheme,
const Handler& handler) {
auto* job_factory = request_context_getter->job_factory();
if (!job_factory->IsHandledProtocol(scheme))
return PROTOCOL_NOT_REGISTERED;
// It is possible a protocol is handled but can not be intercepted.
if (!job_factory->HasProtocolHandler(scheme))
return PROTOCOL_FAIL;
auto protocol_handler = std::make_unique<CustomProtocolHandler<RequestJob>>(
isolate, request_context_getter.get(), handler);
if (!job_factory->InterceptProtocol(scheme, std::move(protocol_handler)))
return PROTOCOL_INTERCEPTED;
return PROTOCOL_OK;
}
// Restore the |scheme| to its original protocol handler.
void UninterceptProtocol(const std::string& scheme, mate::Arguments* args);
static ProtocolError UninterceptProtocolInIO(
scoped_refptr<URLRequestContextGetter> request_context_getter,
const std::string& scheme);
// Convert error code to JS exception and call the callback.
void OnIOCompleted(const CompletionCallback& callback, ProtocolError error);
// Convert error code to string.
std::string ErrorCodeToString(ProtocolError error);
base::WeakPtr<Protocol> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
scoped_refptr<AtomBrowserContext> browser_context_;
base::WeakPtrFactory<Protocol> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(Protocol);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_PROTOCOL_H_

View File

@@ -0,0 +1,90 @@
// Copyright (c) 2016 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_render_process_preferences.h"
#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "content/public/browser/render_process_host.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
namespace atom {
namespace api {
namespace {
bool IsWebContents(v8::Isolate* isolate, content::RenderProcessHost* process) {
content::WebContents* web_contents =
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
->GetWebContentsFromProcessID(process->GetID());
if (!web_contents)
return false;
auto api_web_contents = WebContents::FromOrCreate(isolate, web_contents);
auto type = api_web_contents->GetType();
return type == WebContents::Type::BROWSER_WINDOW ||
type == WebContents::Type::WEB_VIEW;
}
} // namespace
RenderProcessPreferences::RenderProcessPreferences(
v8::Isolate* isolate,
const atom::RenderProcessPreferences::Predicate& predicate)
: preferences_(predicate) {
Init(isolate);
}
RenderProcessPreferences::~RenderProcessPreferences() {}
int RenderProcessPreferences::AddEntry(const base::DictionaryValue& entry) {
return preferences_.AddEntry(entry);
}
void RenderProcessPreferences::RemoveEntry(int id) {
preferences_.RemoveEntry(id);
}
// static
void RenderProcessPreferences::BuildPrototype(
v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(
mate::StringToV8(isolate, "RenderProcessPreferences"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("addEntry", &RenderProcessPreferences::AddEntry)
.SetMethod("removeEntry", &RenderProcessPreferences::RemoveEntry);
}
// static
mate::Handle<RenderProcessPreferences>
RenderProcessPreferences::ForAllWebContents(v8::Isolate* isolate) {
return mate::CreateHandle(isolate,
new RenderProcessPreferences(
isolate, base::Bind(&IsWebContents, isolate)));
}
} // namespace api
} // namespace atom
namespace {
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("forAllWebContents",
&atom::api::RenderProcessPreferences::ForAllWebContents);
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_render_process_preferences,
Initialize)

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2016 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_RENDER_PROCESS_PREFERENCES_H_
#define ATOM_BROWSER_API_ATOM_API_RENDER_PROCESS_PREFERENCES_H_
#include "atom/browser/render_process_preferences.h"
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"
namespace atom {
namespace api {
class RenderProcessPreferences
: public mate::Wrappable<RenderProcessPreferences> {
public:
static mate::Handle<RenderProcessPreferences> ForAllWebContents(
v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
int AddEntry(const base::DictionaryValue& entry);
void RemoveEntry(int id);
protected:
RenderProcessPreferences(
v8::Isolate* isolate,
const atom::RenderProcessPreferences::Predicate& predicate);
~RenderProcessPreferences() override;
private:
atom::RenderProcessPreferences preferences_;
DISALLOW_COPY_AND_ASSIGN(RenderProcessPreferences);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_RENDER_PROCESS_PREFERENCES_H_

View File

@@ -2,18 +2,18 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_screen.h"
#include "atom/browser/api/atom_api_screen.h"
#include <algorithm>
#include <string>
#include "atom/browser/api/atom_api_browser_window.h"
#include "atom/browser/browser.h"
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/node_includes.h"
#include "base/bind.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "shell/browser/api/atom_api_browser_window.h"
#include "shell/browser/browser.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/node_includes.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/point.h"
@@ -22,7 +22,7 @@
#include "ui/display/win/screen_win.h"
#endif
namespace electron {
namespace atom {
namespace api {
@@ -52,13 +52,13 @@ std::vector<std::string> MetricsToArray(uint32_t metrics) {
}
void DelayEmit(Screen* screen,
base::StringPiece name,
const base::StringPiece& name,
const display::Display& display) {
screen->Emit(name, display);
}
void DelayEmitWithMetrics(Screen* screen,
base::StringPiece name,
const base::StringPiece& name,
const display::Display& display,
const std::vector<std::string>& metrics) {
screen->Emit(name, display, metrics);
@@ -98,13 +98,13 @@ display::Display Screen::GetDisplayMatching(const gfx::Rect& match_rect) {
#if defined(OS_WIN)
static gfx::Rect ScreenToDIPRect(electron::NativeWindow* window,
static gfx::Rect ScreenToDIPRect(atom::NativeWindow* window,
const gfx::Rect& rect) {
HWND hwnd = window ? window->GetAcceleratedWidget() : nullptr;
return display::win::ScreenWin::ScreenToDIPRect(hwnd, rect);
}
static gfx::Rect DIPToScreenRect(electron::NativeWindow* window,
static gfx::Rect DIPToScreenRect(atom::NativeWindow* window,
const gfx::Rect& rect) {
HWND hwnd = window ? window->GetAcceleratedWidget() : nullptr;
return display::win::ScreenWin::DIPToScreenRect(hwnd, rect);
@@ -136,8 +136,7 @@ void Screen::OnDisplayMetricsChanged(const display::Display& display,
v8::Local<v8::Value> Screen::Create(v8::Isolate* isolate) {
if (!Browser::Get()->is_ready()) {
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate,
"The 'screen' module can't be used before the app 'ready' event")));
isolate, "Cannot require \"screen\" module before app is ready")));
return v8::Null(isolate);
}
@@ -171,11 +170,11 @@ void Screen::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::Screen;
using atom::api::Screen;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
@@ -183,7 +182,7 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("createScreen", base::BindRepeating(&Screen::Create, isolate));
dict.Set("screen", Screen::Create(isolate));
dict.Set(
"Screen",
Screen::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());

View File

@@ -2,13 +2,13 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_SCREEN_H_
#define SHELL_BROWSER_API_ATOM_API_SCREEN_H_
#ifndef ATOM_BROWSER_API_ATOM_API_SCREEN_H_
#define ATOM_BROWSER_API_ATOM_API_SCREEN_H_
#include <vector>
#include "atom/browser/api/event_emitter.h"
#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "ui/display/display_observer.h"
#include "ui/display/screen.h"
@@ -18,7 +18,7 @@ class Rect;
class Screen;
} // namespace gfx
namespace electron {
namespace atom {
namespace api {
@@ -54,6 +54,6 @@ class Screen : public mate::EventEmitter<Screen>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_SCREEN_H_
#endif // ATOM_BROWSER_API_ATOM_API_SCREEN_H_

View File

@@ -2,16 +2,33 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_session.h"
#include "atom/browser/api/atom_api_session.h"
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "atom/browser/api/atom_api_cookies.h"
#include "atom/browser/api/atom_api_download_item.h"
#include "atom/browser/api/atom_api_net_log.h"
#include "atom/browser/api/atom_api_protocol.h"
#include "atom/browser/api/atom_api_web_request.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/atom_permission_manager.h"
#include "atom/browser/browser.h"
#include "atom/browser/media/media_device_id_salt.h"
#include "atom/browser/net/atom_cert_verifier.h"
#include "atom/browser/session_preferences.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/content_converter.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "base/files/file_path.h"
#include "base/guid.h"
#include "base/strings/string_number_conversions.h"
@@ -28,10 +45,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager_delegate.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/storage_partition.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "net/base/completion_repeating_callback.h"
@@ -39,35 +53,12 @@
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_auth_preferences.h"
#include "net/http/http_cache.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/features.h"
#include "shell/browser/api/atom_api_cookies.h"
#include "shell/browser/api/atom_api_data_pipe_holder.h"
#include "shell/browser/api/atom_api_download_item.h"
#include "shell/browser/api/atom_api_net_log.h"
#include "shell/browser/api/atom_api_protocol_ns.h"
#include "shell/browser/api/atom_api_web_request_ns.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/browser/atom_permission_manager.h"
#include "shell/browser/browser.h"
#include "shell/browser/media/media_device_id_salt.h"
#include "shell/browser/net/cert_verifier_client.h"
#include "shell/browser/session_preferences.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/content_converter.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/net_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "net/http/http_transaction_factory.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_getter.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
#include "shell/browser/extensions/atom_extension_system.h"
#endif
using content::BrowserThread;
using content::StoragePartition;
@@ -79,6 +70,15 @@ struct ClearStorageDataOptions {
uint32_t quota_types = StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL;
};
struct ClearAuthCacheOptions {
std::string type;
GURL origin;
std::string realm;
base::string16 username;
base::string16 password;
net::HttpAuth::Scheme auth_scheme;
};
uint32_t GetStorageMask(const std::vector<std::string>& storage_types) {
uint32_t storage_mask = 0;
for (const auto& it : storage_types) {
@@ -119,6 +119,27 @@ uint32_t GetQuotaMask(const std::vector<std::string>& quota_types) {
return quota_mask;
}
net::HttpAuth::Scheme GetAuthSchemeFromString(const std::string& scheme) {
if (scheme == "basic")
return net::HttpAuth::AUTH_SCHEME_BASIC;
if (scheme == "digest")
return net::HttpAuth::AUTH_SCHEME_DIGEST;
if (scheme == "ntlm")
return net::HttpAuth::AUTH_SCHEME_NTLM;
if (scheme == "negotiate")
return net::HttpAuth::AUTH_SCHEME_NEGOTIATE;
return net::HttpAuth::AUTH_SCHEME_MAX;
}
void SetUserAgentInIO(scoped_refptr<net::URLRequestContextGetter> getter,
const std::string& accept_lang,
const std::string& user_agent) {
getter->GetURLRequestContext()->set_http_user_agent_settings(
new net::StaticHttpUserAgentSettings(
net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang),
user_agent));
}
} // namespace
namespace mate {
@@ -141,9 +162,42 @@ struct Converter<ClearStorageDataOptions> {
}
};
template <>
struct Converter<ClearAuthCacheOptions> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
ClearAuthCacheOptions* out) {
mate::Dictionary options;
if (!ConvertFromV8(isolate, val, &options))
return false;
options.Get("type", &out->type);
options.Get("origin", &out->origin);
options.Get("realm", &out->realm);
options.Get("username", &out->username);
options.Get("password", &out->password);
std::string scheme;
if (options.Get("scheme", &scheme))
out->auth_scheme = GetAuthSchemeFromString(scheme);
return true;
}
};
template <>
struct Converter<atom::VerifyRequestParams> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
atom::VerifyRequestParams val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("hostname", val.hostname);
dict.Set("certificate", val.certificate);
dict.Set("verificationResult", val.default_result);
dict.Set("errorCode", val.error_code);
return dict.GetHandle();
}
};
} // namespace mate
namespace electron {
namespace atom {
namespace api {
@@ -154,6 +208,69 @@ const char kPersistPrefix[] = "persist:";
// Referenced session objects.
std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
void SetCertVerifyProcInIO(
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
const AtomCertVerifier::VerifyProc& proc) {
auto* request_context = context_getter->GetURLRequestContext();
static_cast<AtomCertVerifier*>(request_context->cert_verifier())
->SetVerifyProc(proc);
}
void ClearHostResolverCacheInIO(
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
util::Promise promise) {
auto* request_context = context_getter->GetURLRequestContext();
auto* cache = request_context->host_resolver()->GetHostCache();
if (cache) {
cache->clear();
DCHECK_EQ(0u, cache->size());
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
}
}
void ClearAuthCacheInIO(
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
const ClearAuthCacheOptions& options,
util::Promise promise) {
auto* request_context = context_getter->GetURLRequestContext();
auto* network_session =
request_context->http_transaction_factory()->GetSession();
if (network_session) {
if (options.type == "password") {
auto* auth_cache = network_session->http_auth_cache();
if (!options.origin.is_empty()) {
auth_cache->Remove(
options.origin, options.realm, options.auth_scheme,
net::AuthCredentials(options.username, options.password));
} else {
auth_cache->ClearAllEntries();
}
} else if (options.type == "clientCertificate") {
auto* client_auth_cache = network_session->ssl_client_auth_cache();
client_auth_cache->Remove(net::HostPortPair::FromURL(options.origin));
}
network_session->CloseAllConnections();
}
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
}
void AllowNTLMCredentialsForDomainsInIO(
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
const std::string& domains) {
auto* request_context = context_getter->GetURLRequestContext();
auto* auth_handler = request_context->http_auth_handler_factory();
if (auth_handler) {
auto* auth_preferences = const_cast<net::HttpAuthPreferences*>(
auth_handler->http_auth_preferences());
if (auth_preferences)
auth_preferences->SetServerWhitelist(domains);
}
}
void DownloadIdCallback(content::DownloadManager* download_manager,
const base::FilePath& path,
const std::vector<GURL>& url_chain,
@@ -210,10 +327,8 @@ Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context)
Session::~Session() {
content::BrowserContext::GetDownloadManager(browser_context())
->RemoveObserver(this);
// TODO(zcbenz): Now since URLRequestContextGetter is gone, is this still
// needed?
// Refs https://github.com/electron/electron/pull/12305.
DestroyGlobalHandle(isolate(), cookies_);
DestroyGlobalHandle(isolate(), web_request_);
DestroyGlobalHandle(isolate(), protocol_);
DestroyGlobalHandle(isolate(), net_log_);
g_sessions.erase(weak_map_id());
@@ -247,8 +362,9 @@ v8::Local<v8::Promise> Session::ResolveProxy(mate::Arguments* args) {
args->GetNext(&url);
browser_context_->GetResolveProxyHelper()->ResolveProxy(
url, base::BindOnce(util::Promise::ResolvePromise<std::string>,
std::move(promise)));
url,
base::Bind(util::CopyablePromise::ResolveCopyablePromise<std::string>,
util::CopyablePromise(promise)));
return handle;
}
@@ -309,7 +425,8 @@ v8::Local<v8::Promise> Session::ClearStorageData(mate::Arguments* args) {
storage_partition->ClearData(
options.storage_types, options.quota_types, options.origin, base::Time(),
base::Time::Max(),
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
base::Bind(util::CopyablePromise::ResolveEmptyCopyablePromise,
util::CopyablePromise(promise)));
return handle;
}
@@ -391,27 +508,32 @@ void Session::DisableNetworkEmulation() {
network_emulation_token_, network::mojom::NetworkConditions::New());
}
void WrapVerifyProc(base::Callback<void(const VerifyRequestParams& request,
base::Callback<void(int)>)> proc,
const VerifyRequestParams& request,
base::OnceCallback<void(int)> cb) {
if (proc.is_null()) {
LOG(ERROR) << "WrapVerifyProc (proc=null)";
return;
}
proc.Run(request, base::AdaptCallbackForRepeating(std::move(cb)));
}
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
mate::Arguments* args) {
CertVerifierClient::CertVerifyProc proc;
base::Callback<void(const VerifyRequestParams& request,
base::Callback<void(int)>)>
proc;
if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &proc))) {
args->ThrowError("Must pass null or function");
return;
}
mojo::PendingRemote<network::mojom::CertVerifierClient>
cert_verifier_client_remote;
if (proc) {
mojo::MakeSelfOwnedReceiver(
std::make_unique<CertVerifierClient>(proc),
cert_verifier_client_remote.InitWithNewPipeAndPassReceiver());
}
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
->GetNetworkContext()
->SetCertVerifierClient(std::move(cert_verifier_client_remote));
// This causes the cert verifier cache to be cleared.
content::GetNetworkService()->OnCertDBChanged();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&SetCertVerifyProcInIO,
WrapRefCounted(browser_context_->GetRequestContext()),
base::Bind(&WrapVerifyProc, proc)));
}
void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,
@@ -423,14 +545,18 @@ void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,
AtomPermissionManager::RequestHandler());
return;
}
auto handler = std::make_unique<AtomPermissionManager::RequestHandler>();
using StatusCallback =
base::RepeatingCallback<void(blink::mojom::PermissionStatus)>;
using RequestHandler =
base::Callback<void(content::WebContents*, content::PermissionType,
StatusCallback, const base::Value&)>;
auto handler = std::make_unique<RequestHandler>();
if (!mate::ConvertFromV8(args->isolate(), val, handler.get())) {
args->ThrowError("Must pass null or function");
return;
}
permission_manager->SetPermissionRequestHandler(base::BindRepeating(
[](AtomPermissionManager::RequestHandler* handler,
content::WebContents* web_contents,
[](RequestHandler* handler, content::WebContents* web_contents,
content::PermissionType permission_type,
AtomPermissionManager::StatusCallback callback,
const base::Value& details) {
@@ -458,46 +584,53 @@ v8::Local<v8::Promise> Session::ClearHostResolverCache(mate::Arguments* args) {
util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
->GetNetworkContext()
->ClearHostCache(nullptr,
base::BindOnce(util::Promise::ResolveEmptyPromise,
std::move(promise)));
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&ClearHostResolverCacheInIO,
WrapRefCounted(browser_context_->GetRequestContext()),
std::move(promise)));
return handle;
}
v8::Local<v8::Promise> Session::ClearAuthCache() {
auto* isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Promise> Session::ClearAuthCache(mate::Arguments* args) {
v8::Isolate* isolate = args->isolate();
util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
->GetNetworkContext()
->ClearHttpAuthCache(base::Time(),
base::BindOnce(util::Promise::ResolveEmptyPromise,
std::move(promise)));
ClearAuthCacheOptions options;
if (!args->GetNext(&options)) {
promise.RejectWithErrorMessage("Must specify options object");
return handle;
}
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&ClearAuthCacheInIO,
WrapRefCounted(browser_context_->GetRequestContext()),
options, std::move(promise)));
return handle;
}
void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
network::mojom::HttpAuthDynamicParamsPtr auth_dynamic_params =
network::mojom::HttpAuthDynamicParams::New();
auth_dynamic_params->server_allowlist = domains;
auth_dynamic_params->enable_negotiate_port =
base::CommandLine::ForCurrentProcess()->HasSwitch(
electron::switches::kEnableAuthNegotiatePort);
content::GetNetworkService()->ConfigureHttpAuthPrefs(
std::move(auth_dynamic_params));
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&AllowNTLMCredentialsForDomainsInIO,
WrapRefCounted(browser_context_->GetRequestContext()),
domains));
}
void Session::SetUserAgent(const std::string& user_agent,
mate::Arguments* args) {
browser_context_->SetUserAgent(user_agent);
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
->GetNetworkContext()
->SetUserAgent(user_agent);
std::string accept_lang = g_browser_process->GetApplicationLocale();
args->GetNext(&accept_lang);
scoped_refptr<net::URLRequestContextGetter> getter(
browser_context_->GetRequestContext());
getter->GetNetworkTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&SetUserAgentInIO, getter, accept_lang, user_agent));
}
std::string Session::GetUserAgent() {
@@ -506,14 +639,15 @@ std::string Session::GetUserAgent() {
v8::Local<v8::Promise> Session::GetBlobData(v8::Isolate* isolate,
const std::string& uuid) {
gin::Handle<DataPipeHolder> holder = DataPipeHolder::From(isolate, uuid);
if (holder.IsEmpty()) {
util::Promise promise(isolate);
promise.RejectWithErrorMessage("Could not get blob data handle");
return promise.GetHandle();
}
util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
return holder->ReadAll(isolate);
AtomBlobReader* blob_reader = browser_context()->GetBlobReader();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&AtomBlobReader::StartReading,
base::Unretained(blob_reader), uuid, std::move(promise)));
return handle;
}
void Session::CreateInterruptedDownload(const mate::Dictionary& options) {
@@ -542,7 +676,7 @@ void Session::CreateInterruptedDownload(const mate::Dictionary& options) {
}
auto* download_manager =
content::BrowserContext::GetDownloadManager(browser_context());
download_manager->GetDelegate()->GetNextId(base::BindRepeating(
download_manager->GetDelegate()->GetNextId(base::Bind(
&DownloadIdCallback, download_manager, path, url_chain, mime_type, offset,
length, last_modified, etag, base::Time::FromDoubleT(start_time)));
}
@@ -560,14 +694,6 @@ std::vector<base::FilePath::StringType> Session::GetPreloads() const {
return prefs->preloads();
}
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
void Session::LoadChromeExtension(const base::FilePath extension_path) {
auto* extension_system = static_cast<extensions::AtomExtensionSystem*>(
extensions::ExtensionSystem::Get(browser_context()));
extension_system->LoadExtension(extension_path);
}
#endif
v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
if (cookies_.IsEmpty()) {
auto handle = Cookies::Create(isolate, browser_context());
@@ -578,66 +704,28 @@ v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
v8::Local<v8::Value> Session::Protocol(v8::Isolate* isolate) {
if (protocol_.IsEmpty()) {
v8::Local<v8::Value> handle;
handle = ProtocolNS::Create(isolate, browser_context()).ToV8();
protocol_.Reset(isolate, handle);
auto handle = atom::api::Protocol::Create(isolate, browser_context());
protocol_.Reset(isolate, handle.ToV8());
}
return v8::Local<v8::Value>::New(isolate, protocol_);
}
v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) {
if (web_request_.IsEmpty()) {
v8::Local<v8::Value> handle;
handle = WebRequestNS::Create(isolate, browser_context()).ToV8();
web_request_.Reset(isolate, handle);
auto handle = atom::api::WebRequest::Create(isolate, browser_context());
web_request_.Reset(isolate, handle.ToV8());
}
return v8::Local<v8::Value>::New(isolate, web_request_);
}
v8::Local<v8::Value> Session::NetLog(v8::Isolate* isolate) {
if (net_log_.IsEmpty()) {
auto handle = electron::api::NetLog::Create(isolate, browser_context());
auto handle = atom::api::NetLog::Create(isolate, browser_context());
net_log_.Reset(isolate, handle.ToV8());
}
return v8::Local<v8::Value>::New(isolate, net_log_);
}
static void StartPreconnectOnUI(
scoped_refptr<AtomBrowserContext> browser_context,
const GURL& url,
int num_sockets_to_preconnect) {
std::vector<predictors::PreconnectRequest> requests = {
{url.GetOrigin(), num_sockets_to_preconnect, net::NetworkIsolationKey()}};
browser_context->GetPreconnectManager()->Start(url, requests);
}
void Session::Preconnect(const mate::Dictionary& options,
mate::Arguments* args) {
GURL url;
if (!options.Get("url", &url) || !url.is_valid()) {
args->ThrowError("Must pass non-empty valid url to session.preconnect.");
return;
}
int num_sockets_to_preconnect = 1;
if (options.Get("numSockets", &num_sockets_to_preconnect)) {
const int kMinSocketsToPreconnect = 1;
const int kMaxSocketsToPreconnect = 6;
if (num_sockets_to_preconnect < kMinSocketsToPreconnect ||
num_sockets_to_preconnect > kMaxSocketsToPreconnect) {
args->ThrowError(
base::StringPrintf("numSocketsToPreconnect is outside range [%d,%d]",
kMinSocketsToPreconnect, kMaxSocketsToPreconnect));
return;
}
}
DCHECK_GT(num_sockets_to_preconnect, 0);
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&StartPreconnectOnUI, base::RetainedRef(browser_context_),
url, num_sockets_to_preconnect));
}
// static
mate::Handle<Session> Session::CreateFrom(v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
@@ -705,10 +793,6 @@ void Session::BuildPrototype(v8::Isolate* isolate,
&Session::CreateInterruptedDownload)
.SetMethod("setPreloads", &Session::SetPreloads)
.SetMethod("getPreloads", &Session::GetPreloads)
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
.SetMethod("loadChromeExtension", &Session::LoadChromeExtension)
#endif
.SetMethod("preconnect", &Session::Preconnect)
.SetProperty("cookies", &Session::Cookies)
.SetProperty("netLog", &Session::NetLog)
.SetProperty("protocol", &Session::Protocol)
@@ -717,18 +801,18 @@ void Session::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::Cookies;
using electron::api::NetLog;
using electron::api::ProtocolNS;
using electron::api::Session;
using atom::api::Cookies;
using atom::api::NetLog;
using atom::api::Protocol;
using atom::api::Session;
v8::Local<v8::Value> FromPartition(const std::string& partition,
mate::Arguments* args) {
if (!electron::Browser::Get()->is_ready()) {
if (!atom::Browser::Get()->is_ready()) {
args->ThrowError("Session can only be received when app is ready");
return v8::Null(args->isolate());
}
@@ -752,9 +836,9 @@ void Initialize(v8::Local<v8::Object> exports,
dict.Set(
"NetLog",
NetLog::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
dict.Set("Protocol", ProtocolNS::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());
dict.Set(
"Protocol",
Protocol::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
dict.SetMethod("fromPartition", &FromPartition);
}

View File

@@ -2,19 +2,19 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_SESSION_H_
#define SHELL_BROWSER_API_ATOM_API_SESSION_H_
#ifndef ATOM_BROWSER_API_ATOM_API_SESSION_H_
#define ATOM_BROWSER_API_ATOM_API_SESSION_H_
#include <string>
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/atom_blob_reader.h"
#include "atom/browser/net/resolve_proxy_helper.h"
#include "atom/common/promise_util.h"
#include "base/values.h"
#include "content/public/browser/download_manager.h"
#include "electron/buildflags/buildflags.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/net/resolve_proxy_helper.h"
#include "shell/common/promise_util.h"
class GURL;
@@ -31,7 +31,7 @@ namespace net {
class ProxyConfig;
}
namespace electron {
namespace atom {
class AtomBrowserContext;
@@ -40,6 +40,11 @@ namespace api {
class Session : public mate::TrackableObject<Session>,
public content::DownloadManager::Observer {
public:
enum class CacheAction {
CLEAR,
STATS,
};
// Gets or creates Session from the |browser_context|.
static mate::Handle<Session> CreateFrom(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
@@ -72,7 +77,7 @@ class Session : public mate::TrackableObject<Session>,
void SetPermissionCheckHandler(v8::Local<v8::Value> val,
mate::Arguments* args);
v8::Local<v8::Promise> ClearHostResolverCache(mate::Arguments* args);
v8::Local<v8::Promise> ClearAuthCache();
v8::Local<v8::Promise> ClearAuthCache(mate::Arguments* args);
void AllowNTLMCredentialsForDomains(const std::string& domains);
void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
std::string GetUserAgent();
@@ -85,11 +90,6 @@ class Session : public mate::TrackableObject<Session>,
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
v8::Local<v8::Value> NetLog(v8::Isolate* isolate);
void Preconnect(const mate::Dictionary& options, mate::Arguments* args);
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
void LoadChromeExtension(const base::FilePath extension_path);
#endif
protected:
Session(v8::Isolate* isolate, AtomBrowserContext* browser_context);
@@ -100,13 +100,11 @@ class Session : public mate::TrackableObject<Session>,
download::DownloadItem* item) override;
private:
// Cached mate::Wrappable objects.
// Cached object.
v8::Global<v8::Value> cookies_;
v8::Global<v8::Value> protocol_;
v8::Global<v8::Value> net_log_;
// Cached object.
v8::Global<v8::Value> web_request_;
v8::Global<v8::Value> net_log_;
// The client id to enable the network throttler.
base::UnguessableToken network_emulation_token_;
@@ -118,6 +116,6 @@ class Session : public mate::TrackableObject<Session>,
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_SESSION_H_
#endif // ATOM_BROWSER_API_ATOM_API_SESSION_H_

View File

@@ -2,17 +2,16 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_system_preferences.h"
#include "atom/browser/api/atom_api_system_preferences.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/color_utils.h"
#include "ui/native_theme/native_theme.h"
namespace electron {
namespace atom {
namespace api {
@@ -31,7 +30,7 @@ SystemPreferences::~SystemPreferences() {
#if !defined(OS_MACOSX)
bool SystemPreferences::IsDarkMode() {
return ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors();
return false;
}
#endif
@@ -39,9 +38,11 @@ bool SystemPreferences::IsInvertedColorScheme() {
return color_utils::IsInvertedColorScheme();
}
#if !defined(OS_WIN)
bool SystemPreferences::IsHighContrastColorScheme() {
return ui::NativeTheme::GetInstanceForNativeUi()->UsesHighContrastColors();
return false;
}
#endif // !defined(OS_WIN)
v8::Local<v8::Value> SystemPreferences::GetAnimationSettings(
v8::Isolate* isolate) {
@@ -99,17 +100,12 @@ void SystemPreferences::BuildPrototype(
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
.SetMethod("isSwipeTrackingFromScrollEventsEnabled",
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
.SetMethod("_getEffectiveAppearance",
.SetMethod("getEffectiveAppearance",
&SystemPreferences::GetEffectiveAppearance)
.SetMethod("_getAppLevelAppearance",
.SetMethod("getAppLevelAppearance",
&SystemPreferences::GetAppLevelAppearance)
.SetMethod("_setAppLevelAppearance",
.SetMethod("setAppLevelAppearance",
&SystemPreferences::SetAppLevelAppearance)
.SetProperty("appLevelAppearance",
&SystemPreferences::GetAppLevelAppearance,
&SystemPreferences::SetAppLevelAppearance)
.SetProperty("effectiveAppearance",
&SystemPreferences::GetEffectiveAppearance)
.SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
.SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID)
.SetMethod("promptTouchID", &SystemPreferences::PromptTouchID)
@@ -130,11 +126,11 @@ void SystemPreferences::BuildPrototype(
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::SystemPreferences;
using atom::api::SystemPreferences;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,

View File

@@ -2,21 +2,21 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
#define SHELL_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
#ifndef ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
#define ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
#include <memory>
#include <string>
#include "atom/browser/api/event_emitter.h"
#include "atom/common/promise_util.h"
#include "base/callback.h"
#include "base/values.h"
#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/common/promise_util.h"
#if defined(OS_WIN)
#include "shell/browser/browser.h"
#include "shell/browser/browser_observer.h"
#include "atom/browser/browser.h"
#include "atom/browser/browser_observer.h"
#include "ui/gfx/sys_color_change_listener.h"
#endif
@@ -24,7 +24,7 @@ namespace base {
class DictionaryValue;
}
namespace electron {
namespace atom {
namespace api {
@@ -66,9 +66,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
#elif defined(OS_MACOSX)
using NotificationCallback =
base::RepeatingCallback<void(const std::string&,
const base::DictionaryValue&,
const std::string&)>;
base::Callback<void(const std::string&, const base::DictionaryValue&)>;
void PostNotification(const std::string& name,
const base::DictionaryValue& user_info,
@@ -167,6 +165,6 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
#endif // ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_

View File

@@ -2,18 +2,20 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_system_preferences.h"
#include "atom/browser/api/atom_api_system_preferences.h"
#include <map>
#include <memory>
#include <string>
#include <utility>
#import <AVFoundation/AVFoundation.h>
#import <Cocoa/Cocoa.h>
#import <LocalAuthentication/LocalAuthentication.h>
#import <Security/Security.h>
#include "atom/browser/mac/atom_application.h"
#include "atom/browser/mac/dict_util.h"
#include "atom/browser/ui/cocoa/NSColor+Hex.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/sdk_forward_declarations.h"
#include "base/sequenced_task_runner.h"
@@ -23,11 +25,6 @@
#include "base/values.h"
#include "native_mate/object_template_builder.h"
#include "net/base/mac/url_conversions.h"
#include "shell/browser/mac/atom_application.h"
#include "shell/browser/mac/dict_util.h"
#include "shell/browser/ui/cocoa/NSColor+Hex.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "ui/native_theme/native_theme.h"
namespace mate {
@@ -80,7 +77,7 @@ struct Converter<NSAppearance*> {
};
} // namespace mate
namespace electron {
namespace atom {
namespace api {
@@ -211,20 +208,13 @@ int SystemPreferences::DoSubscribeNotification(
usingBlock:^(NSNotification* notification) {
std::unique_ptr<base::DictionaryValue> user_info =
NSDictionaryToDictionaryValue(notification.userInfo);
std::string object = "";
if ([notification.object isKindOfClass:[NSString class]]) {
object = base::SysNSStringToUTF8(notification.object);
}
if (user_info) {
copied_callback.Run(
base::SysNSStringToUTF8(notification.name), *user_info,
object);
base::SysNSStringToUTF8(notification.name), *user_info);
} else {
copied_callback.Run(
base::SysNSStringToUTF8(notification.name),
base::DictionaryValue(), object);
base::DictionaryValue());
}
}];
return request_id;
@@ -636,8 +626,8 @@ void SystemPreferences::RemoveUserDefault(const std::string& name) {
}
bool SystemPreferences::IsDarkMode() {
if (@available(macOS 10.14, *)) {
return ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors();
if (@available(macOS 10.15, *)) {
return ui::NativeTheme::GetInstanceForNativeUi()->SystemDarkModeEnabled();
}
NSString* mode = [[NSUserDefaults standardUserDefaults]
stringForKey:@"AppleInterfaceStyle"];
@@ -679,4 +669,4 @@ void SystemPreferences::SetAppLevelAppearance(mate::Arguments* args) {
} // namespace api
} // namespace electron
} // namespace atom

View File

@@ -5,21 +5,33 @@
#include <dwmapi.h>
#include <iomanip>
#include "shell/browser/api/atom_api_system_preferences.h"
#include "atom/browser/api/atom_api_system_preferences.h"
#include "atom/common/color_util.h"
#include "base/win/wrapped_window_proc.h"
#include "shell/common/color_util.h"
#include "ui/base/win/shell.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/win/hwnd_util.h"
namespace electron {
namespace atom {
namespace {
const wchar_t kSystemPreferencesWindowClass[] =
L"Electron_SystemPreferencesHostWindow";
bool g_is_high_contract_color_scheme = false;
bool g_is_high_contract_color_scheme_initialized = false;
void UpdateHighContrastColorScheme() {
HIGHCONTRAST high_contrast = {0};
high_contrast.cbSize = sizeof(HIGHCONTRAST);
g_is_high_contract_color_scheme =
SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &high_contrast, 0) &&
((high_contrast.dwFlags & HCF_HIGHCONTRASTON) != 0);
g_is_high_contract_color_scheme_initialized = true;
}
} // namespace
namespace api {
@@ -28,6 +40,12 @@ bool SystemPreferences::IsAeroGlassEnabled() {
return ui::win::IsAeroGlassEnabled();
}
bool SystemPreferences::IsHighContrastColorScheme() {
if (!g_is_high_contract_color_scheme_initialized)
UpdateHighContrastColorScheme();
return g_is_high_contract_color_scheme;
}
std::string hexColorDWORDToRGBA(DWORD color) {
DWORD rgba = color << 8 | color >> 24;
std::ostringstream stream;
@@ -170,6 +188,9 @@ LRESULT CALLBACK SystemPreferences::WndProc(HWND hwnd,
Emit("accent-color-changed", hexColorDWORDToRGBA(new_color));
current_color_ = new_color_string;
}
} else if (message == WM_SYSCOLORCHANGE ||
(message == WM_SETTINGCHANGE && wparam == SPI_SETHIGHCONTRAST)) {
UpdateHighContrastColorScheme();
}
return ::DefWindowProc(hwnd, message, wparam, lparam);
}
@@ -197,4 +218,4 @@ void SystemPreferences::OnFinishLaunching(
} // namespace api
} // namespace electron
} // namespace atom

View File

@@ -2,35 +2,35 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_top_level_window.h"
#include "atom/browser/api/atom_api_top_level_window.h"
#include <string>
#include <vector>
#include "atom/browser/api/atom_api_browser_view.h"
#include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/api/atom_api_view.h"
#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/common/color_util.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "electron/buildflags/buildflags.h"
#include "gin/converter.h"
#include "native_mate/handle.h"
#include "native_mate/persistent_dictionary.h"
#include "shell/browser/api/atom_api_browser_view.h"
#include "shell/browser/api/atom_api_menu.h"
#include "shell/browser/api/atom_api_view.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/common/color_util.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#if defined(TOOLKIT_VIEWS)
#include "shell/browser/native_window_views.h"
#include "atom/browser/native_window_views.h"
#endif
#if defined(OS_WIN)
#include "shell/browser/ui/win/taskbar_host.h"
#include "atom/browser/ui/win/taskbar_host.h"
#include "ui/base/win/shell.h"
#endif
@@ -38,10 +38,10 @@
namespace mate {
template <>
struct Converter<electron::TaskbarHost::ThumbarButton> {
struct Converter<atom::TaskbarHost::ThumbarButton> {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
electron::TaskbarHost::ThumbarButton* out) {
atom::TaskbarHost::ThumbarButton* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
@@ -55,7 +55,7 @@ struct Converter<electron::TaskbarHost::ThumbarButton> {
} // namespace mate
#endif
namespace electron {
namespace atom {
namespace api {
@@ -246,10 +246,6 @@ void TopLevelWindow::OnWindowSwipe(const std::string& direction) {
Emit("swipe", direction);
}
void TopLevelWindow::OnWindowRotateGesture(float rotation) {
Emit("rotate-gesture", rotation);
}
void TopLevelWindow::OnWindowSheetBegin() {
Emit("sheet-begin");
}
@@ -523,16 +519,14 @@ void TopLevelWindow::SetAlwaysOnTop(bool top, mate::Arguments* args) {
args->GetNext(&relative_level);
std::string error;
ui::ZOrderLevel z_order =
top ? ui::ZOrderLevel::kFloatingWindow : ui::ZOrderLevel::kNormal;
window_->SetAlwaysOnTop(z_order, level, relative_level, &error);
window_->SetAlwaysOnTop(top, level, relative_level, &error);
if (!error.empty())
args->ThrowError(error);
}
bool TopLevelWindow::IsAlwaysOnTop() {
return window_->GetZOrderLevel() != ui::ZOrderLevel::kNormal;
return window_->IsAlwaysOnTop();
}
void TopLevelWindow::Center() {
@@ -743,15 +737,15 @@ void TopLevelWindow::SetProgressBar(double progress, mate::Arguments* args) {
std::string mode;
args->GetNext(&options) && options.Get("mode", &mode);
NativeWindow::ProgressState state = NativeWindow::ProgressState::kNormal;
NativeWindow::ProgressState state = NativeWindow::PROGRESS_NORMAL;
if (mode == "error")
state = NativeWindow::ProgressState::kError;
state = NativeWindow::PROGRESS_ERROR;
else if (mode == "paused")
state = NativeWindow::ProgressState::kPaused;
state = NativeWindow::PROGRESS_PAUSED;
else if (mode == "indeterminate")
state = NativeWindow::ProgressState::kIndeterminate;
state = NativeWindow::PROGRESS_INDETERMINATE;
else if (mode == "none")
state = NativeWindow::ProgressState::kNone;
state = NativeWindow::PROGRESS_NONE;
window_->SetProgressBar(progress, state);
}
@@ -866,10 +860,6 @@ void TopLevelWindow::CloseFilePreview() {
window_->CloseFilePreview();
}
void TopLevelWindow::SetGTKDarkThemeEnabled(bool use_dark_theme) {
window_->SetGTKDarkThemeEnabled(use_dark_theme);
}
v8::Local<v8::Value> TopLevelWindow::GetContentView() const {
if (content_view_.IsEmpty())
return v8::Null(isolate());
@@ -953,14 +943,14 @@ bool TopLevelWindow::HookWindowMessage(UINT message,
}
void TopLevelWindow::UnhookWindowMessage(UINT message) {
if (!base::Contains(messages_callback_map_, message))
if (!ContainsKey(messages_callback_map_, message))
return;
messages_callback_map_.erase(message);
}
bool TopLevelWindow::IsWindowMessageHooked(UINT message) {
return base::Contains(messages_callback_map_, message);
return ContainsKey(messages_callback_map_, message);
}
void TopLevelWindow::UnhookAllWindowMessages() {
@@ -1034,9 +1024,9 @@ void TopLevelWindow::RemoveFromParentChildWindows() {
// static
mate::WrappableBase* TopLevelWindow::New(mate::Arguments* args) {
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
args->GetNext(&options);
mate::Dictionary options;
if (!(args->Length() == 1 && args->GetNext(&options)))
options = mate::Dictionary::CreateEmpty(args->isolate());
return new TopLevelWindow(args->isolate(), args->GetThis(), options);
}
@@ -1080,31 +1070,19 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setMaximumSize", &TopLevelWindow::SetMaximumSize)
.SetMethod("getMaximumSize", &TopLevelWindow::GetMaximumSize)
.SetMethod("setSheetOffset", &TopLevelWindow::SetSheetOffset)
.SetMethod("setResizable", &TopLevelWindow::SetResizable)
.SetMethod("isResizable", &TopLevelWindow::IsResizable)
.SetMethod("setMovable", &TopLevelWindow::SetMovable)
.SetMethod("moveTop", &TopLevelWindow::MoveTop)
.SetMethod("_setResizable", &TopLevelWindow::SetResizable)
.SetMethod("_isResizable", &TopLevelWindow::IsResizable)
.SetProperty("resizable", &TopLevelWindow::IsResizable,
&TopLevelWindow::SetResizable)
.SetMethod("_setMovable", &TopLevelWindow::SetMovable)
.SetMethod("_isMovable", &TopLevelWindow::IsMovable)
.SetProperty("movable", &TopLevelWindow::IsMovable,
&TopLevelWindow::SetMovable)
.SetMethod("_setMinimizable", &TopLevelWindow::SetMinimizable)
.SetMethod("_isMinimizable", &TopLevelWindow::IsMinimizable)
.SetProperty("minimizable", &TopLevelWindow::IsMinimizable,
&TopLevelWindow::SetMinimizable)
.SetMethod("_setMaximizable", &TopLevelWindow::SetMaximizable)
.SetMethod("_isMaximizable", &TopLevelWindow::IsMaximizable)
.SetProperty("maximizable", &TopLevelWindow::IsMaximizable,
&TopLevelWindow::SetMaximizable)
.SetMethod("_setFullScreenable", &TopLevelWindow::SetFullScreenable)
.SetMethod("_isFullScreenable", &TopLevelWindow::IsFullScreenable)
.SetProperty("fullScreenable", &TopLevelWindow::IsFullScreenable,
&TopLevelWindow::SetFullScreenable)
.SetMethod("_setClosable", &TopLevelWindow::SetClosable)
.SetMethod("_isClosable", &TopLevelWindow::IsClosable)
.SetProperty("closable", &TopLevelWindow::IsClosable,
&TopLevelWindow::SetClosable)
.SetMethod("isMovable", &TopLevelWindow::IsMovable)
.SetMethod("setMinimizable", &TopLevelWindow::SetMinimizable)
.SetMethod("isMinimizable", &TopLevelWindow::IsMinimizable)
.SetMethod("setMaximizable", &TopLevelWindow::SetMaximizable)
.SetMethod("isMaximizable", &TopLevelWindow::IsMaximizable)
.SetMethod("setFullScreenable", &TopLevelWindow::SetFullScreenable)
.SetMethod("isFullScreenable", &TopLevelWindow::IsFullScreenable)
.SetMethod("setClosable", &TopLevelWindow::SetClosable)
.SetMethod("isClosable", &TopLevelWindow::IsClosable)
.SetMethod("setAlwaysOnTop", &TopLevelWindow::SetAlwaysOnTop)
.SetMethod("isAlwaysOnTop", &TopLevelWindow::IsAlwaysOnTop)
.SetMethod("center", &TopLevelWindow::Center)
@@ -1168,10 +1146,8 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
&TopLevelWindow::IsExcludedFromShownWindowsMenu,
&TopLevelWindow::SetExcludedFromShownWindowsMenu)
#endif
.SetMethod("_setAutoHideMenuBar", &TopLevelWindow::SetAutoHideMenuBar)
.SetMethod("_isMenuBarAutoHide", &TopLevelWindow::IsMenuBarAutoHide)
.SetProperty("autoHideMenuBar", &TopLevelWindow::IsMenuBarAutoHide,
&TopLevelWindow::SetAutoHideMenuBar)
.SetMethod("setAutoHideMenuBar", &TopLevelWindow::SetAutoHideMenuBar)
.SetMethod("isMenuBarAutoHide", &TopLevelWindow::IsMenuBarAutoHide)
.SetMethod("setMenuBarVisibility", &TopLevelWindow::SetMenuBarVisibility)
.SetMethod("isMenuBarVisible", &TopLevelWindow::IsMenuBarVisible)
.SetMethod("setAspectRatio", &TopLevelWindow::SetAspectRatio)
@@ -1203,19 +1179,18 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::TopLevelWindow;
using atom::api::TopLevelWindow;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
TopLevelWindow::SetConstructor(isolate,
base::BindRepeating(&TopLevelWindow::New));
TopLevelWindow::SetConstructor(isolate, base::Bind(&TopLevelWindow::New));
mate::Dictionary constructor(isolate, TopLevelWindow::GetConstructor(isolate)
->GetFunction(context)

View File

@@ -2,24 +2,24 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_TOP_LEVEL_WINDOW_H_
#define SHELL_BROWSER_API_ATOM_API_TOP_LEVEL_WINDOW_H_
#ifndef ATOM_BROWSER_API_ATOM_API_TOP_LEVEL_WINDOW_H_
#define ATOM_BROWSER_API_ATOM_API_TOP_LEVEL_WINDOW_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/native_window.h"
#include "atom/browser/native_window_observer.h"
#include "atom/common/api/atom_api_native_image.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/native_window.h"
#include "shell/browser/native_window_observer.h"
#include "shell/common/api/atom_api_native_image.h"
namespace electron {
namespace atom {
namespace api {
@@ -73,7 +73,6 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
void OnWindowScrollTouchBegin() override;
void OnWindowScrollTouchEnd() override;
void OnWindowSwipe(const std::string& direction) override;
void OnWindowRotateGesture(float rotation) override;
void OnWindowSheetBegin() override;
void OnWindowSheetEnd() override;
void OnWindowEnterFullScreen() override;
@@ -198,7 +197,6 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
void PreviewFile(const std::string& path, mate::Arguments* args);
void CloseFilePreview();
void SetGTKDarkThemeEnabled(bool use_dark_theme);
// Public getters of NativeWindow.
v8::Local<v8::Value> GetContentView() const;
@@ -213,8 +211,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
void SetIcon(mate::Handle<NativeImage> icon);
#endif
#if defined(OS_WIN)
typedef base::RepeatingCallback<void(v8::Local<v8::Value>,
v8::Local<v8::Value>)>
typedef base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>
MessageCallback;
bool HookWindowMessage(UINT message, const MessageCallback& callback);
bool IsWindowMessageHooked(UINT message);
@@ -260,24 +257,23 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
} // namespace api
} // namespace electron
} // namespace atom
namespace mate {
template <>
struct Converter<electron::NativeWindow*> {
struct Converter<atom::NativeWindow*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::NativeWindow** out) {
atom::NativeWindow** out) {
// null would be tranfered to NULL.
if (val->IsNull()) {
*out = NULL;
return true;
}
electron::api::TopLevelWindow* window;
if (!Converter<electron::api::TopLevelWindow*>::FromV8(isolate, val,
&window))
atom::api::TopLevelWindow* window;
if (!Converter<atom::api::TopLevelWindow*>::FromV8(isolate, val, &window))
return false;
*out = window->window();
return true;
@@ -286,4 +282,4 @@ struct Converter<electron::NativeWindow*> {
} // namespace mate
#endif // SHELL_BROWSER_API_ATOM_API_TOP_LEVEL_WINDOW_H_
#endif // ATOM_BROWSER_API_ATOM_API_TOP_LEVEL_WINDOW_H_

View File

@@ -2,23 +2,50 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/atom_api_tray.h"
#include "atom/browser/api/atom_api_tray.h"
#include <string>
#include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/browser.h"
#include "atom/common/api/atom_api_native_image.h"
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_includes.h"
#include "base/threading/thread_task_runner_handle.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_menu.h"
#include "shell/browser/browser.h"
#include "shell/common/api/atom_api_native_image.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/node_includes.h"
#include "ui/gfx/image/image.h"
namespace electron {
namespace mate {
template <>
struct Converter<atom::TrayIcon::HighlightMode> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
atom::TrayIcon::HighlightMode* out) {
std::string mode;
if (ConvertFromV8(isolate, val, &mode)) {
if (mode == "always") {
*out = atom::TrayIcon::HighlightMode::ALWAYS;
return true;
}
if (mode == "selection") {
*out = atom::TrayIcon::HighlightMode::SELECTION;
return true;
}
if (mode == "never") {
*out = atom::TrayIcon::HighlightMode::NEVER;
return true;
}
}
return false;
}
};
} // namespace mate
namespace atom {
namespace api {
@@ -141,6 +168,10 @@ std::string Tray::GetTitle() {
#endif
}
void Tray::SetHighlightMode(TrayIcon::HighlightMode mode) {
tray_icon_->SetHighlightMode(mode);
}
void Tray::SetIgnoreDoubleClickEvents(bool ignore) {
#if defined(OS_MACOSX)
tray_icon_->SetIgnoreDoubleClickEvents(ignore);
@@ -203,6 +234,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setToolTip", &Tray::SetToolTip)
.SetMethod("setTitle", &Tray::SetTitle)
.SetMethod("getTitle", &Tray::GetTitle)
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
.SetMethod("setIgnoreDoubleClickEvents",
&Tray::SetIgnoreDoubleClickEvents)
.SetMethod("getIgnoreDoubleClickEvents",
@@ -215,18 +247,18 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
} // namespace api
} // namespace electron
} // namespace atom
namespace {
using electron::api::Tray;
using atom::api::Tray;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
Tray::SetConstructor(isolate, base::BindRepeating(&Tray::New));
Tray::SetConstructor(isolate, base::Bind(&Tray::New));
mate::Dictionary dict(isolate, exports);
dict.Set(

View File

@@ -2,17 +2,17 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_TRAY_H_
#define SHELL_BROWSER_API_ATOM_API_TRAY_H_
#ifndef ATOM_BROWSER_API_ATOM_API_TRAY_H_
#define ATOM_BROWSER_API_ATOM_API_TRAY_H_
#include <memory>
#include <string>
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/ui/tray_icon.h"
#include "atom/browser/ui/tray_icon_observer.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/ui/tray_icon.h"
#include "shell/browser/ui/tray_icon_observer.h"
namespace gfx {
class Image;
@@ -23,7 +23,7 @@ class Arguments;
class Dictionary;
} // namespace mate
namespace electron {
namespace atom {
class TrayIcon;
@@ -70,6 +70,7 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
void SetToolTip(const std::string& tool_tip);
void SetTitle(const std::string& title);
std::string GetTitle();
void SetHighlightMode(TrayIcon::HighlightMode mode);
void SetIgnoreDoubleClickEvents(bool ignore);
bool GetIgnoreDoubleClickEvents();
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
@@ -86,6 +87,6 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
} // namespace api
} // namespace electron
} // namespace atom
#endif // SHELL_BROWSER_API_ATOM_API_TRAY_H_
#endif // ATOM_BROWSER_API_ATOM_API_TRAY_H_

View File

@@ -0,0 +1,496 @@
// Copyright (c) 2016 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_url_request.h"
#include <string>
#include "atom/browser/api/atom_api_session.h"
#include "atom/browser/net/atom_url_request.h"
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace mate {
template <>
struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
scoped_refptr<const net::IOBufferWithSize> buffer) {
return node::Buffer::Copy(isolate, buffer->data(), buffer->size())
.ToLocalChecked();
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<const net::IOBufferWithSize>* out) {
auto size = node::Buffer::Length(val);
if (size == 0) {
// Support conversion from empty buffer. A use case is
// a GET request without body.
// Since zero-sized IOBuffer(s) are not supported, we set the
// out pointer to null.
*out = nullptr;
return true;
}
auto* data = node::Buffer::Data(val);
if (!data) {
// This is an error as size is positive but data is null.
return false;
}
*out = new net::IOBufferWithSize(size);
// We do a deep copy. We could have used Buffer's internal memory
// but that is much more complicated to be properly handled.
memcpy((*out)->data(), data, size);
return true;
}
};
} // namespace mate
namespace atom {
namespace api {
template <typename Flags>
URLRequest::StateBase<Flags>::StateBase(Flags initialState)
: state_(initialState) {}
template <typename Flags>
void URLRequest::StateBase<Flags>::SetFlag(Flags flag) {
state_ =
static_cast<Flags>(static_cast<int>(state_) | static_cast<int>(flag));
}
template <typename Flags>
bool URLRequest::StateBase<Flags>::operator==(Flags flag) const {
return state_ == flag;
}
template <typename Flags>
bool URLRequest::StateBase<Flags>::IsFlagSet(Flags flag) const {
return static_cast<int>(state_) & static_cast<int>(flag);
}
URLRequest::RequestState::RequestState()
: StateBase(RequestStateFlags::kNotStarted) {}
bool URLRequest::RequestState::NotStarted() const {
return *this == RequestStateFlags::kNotStarted;
}
bool URLRequest::RequestState::Started() const {
return IsFlagSet(RequestStateFlags::kStarted);
}
bool URLRequest::RequestState::Finished() const {
return IsFlagSet(RequestStateFlags::kFinished);
}
bool URLRequest::RequestState::Canceled() const {
return IsFlagSet(RequestStateFlags::kCanceled);
}
bool URLRequest::RequestState::Failed() const {
return IsFlagSet(RequestStateFlags::kFailed);
}
bool URLRequest::RequestState::Closed() const {
return IsFlagSet(RequestStateFlags::kClosed);
}
URLRequest::ResponseState::ResponseState()
: StateBase(ResponseStateFlags::kNotStarted) {}
bool URLRequest::ResponseState::NotStarted() const {
return *this == ResponseStateFlags::kNotStarted;
}
bool URLRequest::ResponseState::Started() const {
return IsFlagSet(ResponseStateFlags::kStarted);
}
bool URLRequest::ResponseState::Ended() const {
return IsFlagSet(ResponseStateFlags::kEnded);
}
bool URLRequest::ResponseState::Failed() const {
return IsFlagSet(ResponseStateFlags::kFailed);
}
mate::Dictionary URLRequest::GetUploadProgress(v8::Isolate* isolate) {
mate::Dictionary progress = mate::Dictionary::CreateEmpty(isolate);
if (atom_request_) {
progress.Set("active", true);
atom_request_->GetUploadProgress(&progress);
} else {
progress.Set("active", false);
}
return progress;
}
URLRequest::URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) {
InitWith(isolate, wrapper);
}
URLRequest::~URLRequest() {
// A request has been created in JS, it was not used and then
// it got collected, no close event to cleanup, only destructor
// is called.
if (atom_request_) {
atom_request_->Terminate();
}
}
// static
mate::WrappableBase* URLRequest::New(mate::Arguments* args) {
auto* isolate = args->isolate();
v8::Local<v8::Object> options;
args->GetNext(&options);
mate::Dictionary dict(isolate, options);
std::string method;
dict.Get("method", &method);
std::string url;
dict.Get("url", &url);
std::string redirect_policy;
dict.Get("redirect", &redirect_policy);
std::string partition;
mate::Handle<api::Session> session;
if (dict.Get("session", &session)) {
} else if (dict.Get("partition", &partition)) {
session = Session::FromPartition(isolate, partition);
} else {
// Use the default session if not specified.
session = Session::FromPartition(isolate, "");
}
auto* browser_context = session->browser_context();
auto* api_url_request = new URLRequest(args->isolate(), args->GetThis());
auto atom_url_request = AtomURLRequest::Create(
browser_context, method, url, redirect_policy, api_url_request);
api_url_request->atom_request_ = atom_url_request;
return api_url_request;
}
// static
void URLRequest::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "URLRequest"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
// Request API
.MakeDestroyable()
.SetMethod("write", &URLRequest::Write)
.SetMethod("cancel", &URLRequest::Cancel)
.SetMethod("setExtraHeader", &URLRequest::SetExtraHeader)
.SetMethod("removeExtraHeader", &URLRequest::RemoveExtraHeader)
.SetMethod("setChunkedUpload", &URLRequest::SetChunkedUpload)
.SetMethod("followRedirect", &URLRequest::FollowRedirect)
.SetMethod("_setLoadFlags", &URLRequest::SetLoadFlags)
.SetMethod("getUploadProgress", &URLRequest::GetUploadProgress)
.SetProperty("notStarted", &URLRequest::NotStarted)
.SetProperty("finished", &URLRequest::Finished)
// Response APi
.SetProperty("statusCode", &URLRequest::StatusCode)
.SetProperty("statusMessage", &URLRequest::StatusMessage)
.SetProperty("rawResponseHeaders", &URLRequest::RawResponseHeaders)
.SetProperty("httpVersionMajor", &URLRequest::ResponseHttpVersionMajor)
.SetProperty("httpVersionMinor", &URLRequest::ResponseHttpVersionMinor);
}
bool URLRequest::NotStarted() const {
return request_state_.NotStarted();
}
bool URLRequest::Finished() const {
return request_state_.Finished();
}
bool URLRequest::Canceled() const {
return request_state_.Canceled();
}
bool URLRequest::Write(scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last) {
if (request_state_.Canceled() || request_state_.Failed() ||
request_state_.Finished() || request_state_.Closed()) {
return false;
}
if (request_state_.NotStarted()) {
request_state_.SetFlag(RequestStateFlags::kStarted);
// Pin on first write.
Pin();
}
if (is_last) {
request_state_.SetFlag(RequestStateFlags::kFinished);
EmitRequestEvent(true, "finish");
}
DCHECK(atom_request_);
if (atom_request_) {
return atom_request_->Write(buffer, is_last);
}
return false;
}
void URLRequest::Cancel() {
if (request_state_.Canceled() || request_state_.Closed()) {
// Cancel only once.
return;
}
// Mark as canceled.
request_state_.SetFlag(RequestStateFlags::kCanceled);
DCHECK(atom_request_);
if (atom_request_ && request_state_.Started()) {
// Really cancel if it was started.
atom_request_->Cancel();
}
EmitRequestEvent(true, "abort");
if (response_state_.Started() && !response_state_.Ended()) {
EmitResponseEvent(true, "aborted");
}
Close();
}
void URLRequest::FollowRedirect() {
if (request_state_.Canceled() || request_state_.Closed()) {
return;
}
DCHECK(atom_request_);
if (atom_request_) {
atom_request_->FollowRedirect();
}
}
bool URLRequest::SetExtraHeader(const std::string& name,
const std::string& value) {
// Request state must be in the initial non started state.
if (!request_state_.NotStarted()) {
// Cannot change headers after send.
return false;
}
if (!net::HttpUtil::IsValidHeaderName(name)) {
return false;
}
if (!net::HttpUtil::IsValidHeaderValue(value)) {
return false;
}
DCHECK(atom_request_);
if (atom_request_) {
atom_request_->SetExtraHeader(name, value);
}
return true;
}
void URLRequest::RemoveExtraHeader(const std::string& name) {
// State must be equal to not started.
if (!request_state_.NotStarted()) {
// Cannot change headers after send.
return;
}
DCHECK(atom_request_);
if (atom_request_) {
atom_request_->RemoveExtraHeader(name);
}
}
void URLRequest::SetChunkedUpload(bool is_chunked_upload) {
// State must be equal to not started.
if (!request_state_.NotStarted()) {
// Cannot change headers after send.
return;
}
DCHECK(atom_request_);
if (atom_request_) {
atom_request_->SetChunkedUpload(is_chunked_upload);
}
}
void URLRequest::SetLoadFlags(int flags) {
// State must be equal to not started.
if (!request_state_.NotStarted()) {
// Cannot change load flags after start.
return;
}
DCHECK(atom_request_);
if (atom_request_) {
atom_request_->SetLoadFlags(flags);
}
}
void URLRequest::OnReceivedRedirect(
int status_code,
const std::string& method,
const GURL& url,
scoped_refptr<net::HttpResponseHeaders> response_headers) {
if (request_state_.Canceled() || request_state_.Closed()) {
return;
}
DCHECK(atom_request_);
if (!atom_request_) {
return;
}
EmitRequestEvent(false, "redirect", status_code, method, url,
response_headers.get());
}
void URLRequest::OnAuthenticationRequired(
const net::AuthChallengeInfo& auth_info) {
if (request_state_.Canceled() || request_state_.Closed()) {
return;
}
DCHECK(atom_request_);
if (!atom_request_) {
return;
}
Emit("login", auth_info,
base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_));
}
void URLRequest::OnResponseStarted(
scoped_refptr<net::HttpResponseHeaders> response_headers) {
if (request_state_.Canceled() || request_state_.Failed() ||
request_state_.Closed()) {
// Don't emit any event after request cancel.
return;
}
response_headers_ = response_headers;
response_state_.SetFlag(ResponseStateFlags::kStarted);
Emit("response");
}
void URLRequest::OnResponseData(
scoped_refptr<const net::IOBufferWithSize> buffer) {
if (request_state_.Canceled() || request_state_.Closed() ||
request_state_.Failed() || response_state_.Failed()) {
// In case we received an unexpected event from Chromium net,
// don't emit any data event after request cancel/error/close.
return;
}
if (!buffer || !buffer->data() || !buffer->size()) {
return;
}
Emit("data", buffer);
}
void URLRequest::OnResponseCompleted() {
if (request_state_.Canceled() || request_state_.Closed() ||
request_state_.Failed() || response_state_.Failed()) {
// In case we received an unexpected event from Chromium net,
// don't emit any data event after request cancel/error/close.
return;
}
response_state_.SetFlag(ResponseStateFlags::kEnded);
Emit("end");
Close();
}
void URLRequest::OnError(const std::string& error, bool isRequestError) {
auto error_object = v8::Exception::Error(mate::StringToV8(isolate(), error));
if (isRequestError) {
request_state_.SetFlag(RequestStateFlags::kFailed);
EmitRequestEvent(false, "error", error_object);
} else {
response_state_.SetFlag(ResponseStateFlags::kFailed);
EmitResponseEvent(false, "error", error_object);
}
Close();
}
int URLRequest::StatusCode() const {
if (response_headers_) {
return response_headers_->response_code();
}
return -1;
}
std::string URLRequest::StatusMessage() const {
std::string result;
if (response_headers_) {
result = response_headers_->GetStatusText();
}
return result;
}
net::HttpResponseHeaders* URLRequest::RawResponseHeaders() const {
return response_headers_.get();
}
uint32_t URLRequest::ResponseHttpVersionMajor() const {
if (response_headers_) {
return response_headers_->GetHttpVersion().major_value();
}
return 0;
}
uint32_t URLRequest::ResponseHttpVersionMinor() const {
if (response_headers_) {
return response_headers_->GetHttpVersion().minor_value();
}
return 0;
}
void URLRequest::Close() {
if (!request_state_.Closed()) {
request_state_.SetFlag(RequestStateFlags::kClosed);
if (response_state_.Started()) {
// Emit a close event if we really have a response object.
EmitResponseEvent(true, "close");
}
EmitRequestEvent(true, "close");
}
Unpin();
if (atom_request_) {
// A request has been created in JS, used and then it ended.
// We release unneeded net resources.
atom_request_->Terminate();
}
atom_request_ = nullptr;
}
void URLRequest::Pin() {
if (wrapper_.IsEmpty()) {
wrapper_.Reset(isolate(), GetWrapper());
}
}
void URLRequest::Unpin() {
wrapper_.Reset();
}
template <typename... Args>
void URLRequest::EmitRequestEvent(Args... args) {
v8::HandleScope handle_scope(isolate());
mate::CustomEmit(isolate(), GetWrapper(), "_emitRequestEvent", args...);
}
template <typename... Args>
void URLRequest::EmitResponseEvent(Args... args) {
v8::HandleScope handle_scope(isolate());
mate::CustomEmit(isolate(), GetWrapper(), "_emitResponseEvent", args...);
}
} // namespace api
} // namespace atom

View File

@@ -0,0 +1,214 @@
// Copyright (c) 2016 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_URL_REQUEST_H_
#define ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_
#include <array>
#include <string>
#include "atom/browser/api/event_emitter.h"
#include "atom/browser/api/trackable_object.h"
#include "base/memory/weak_ptr.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "native_mate/wrappable_base.h"
#include "net/base/auth.h"
#include "net/base/io_buffer.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request_context.h"
namespace atom {
class AtomURLRequest;
namespace api {
//
// The URLRequest class implements the V8 binding between the JavaScript API
// and Chromium native net library. It is responsible for handling HTTP/HTTPS
// requests.
//
// The current class provides only the binding layer. Two other JavaScript
// classes (ClientRequest and IncomingMessage) in the net module provide the
// final API, including some state management and arguments validation.
//
// URLRequest's methods fall into two main categories: command and event
// methods. They are always executed on the Browser's UI thread.
// Command methods are called directly from JavaScript code via the API defined
// in BuildPrototype. A command method is generally implemented by forwarding
// the call to a corresponding method on AtomURLRequest which does the
// synchronization on the Browser IO thread. The latter then calls into Chromium
// net library. On the other hand, net library events originate on the IO
// thread in AtomURLRequest and are synchronized back on the UI thread, then
// forwarded to a corresponding event method in URLRequest and then to
// JavaScript via the EmitRequestEvent/EmitResponseEvent helpers.
//
// URLRequest lifetime management: we followed the Wrapper/Wrappable pattern
// defined in native_mate. However, we augment that pattern with a pin/unpin
// mechanism. The main reason is that we want the JS API to provide a similar
// lifetime guarantees as the XMLHttpRequest.
// https://xhr.spec.whatwg.org/#garbage-collection
//
// The primary motivation is to not garbage collect a URLInstance as long as the
// object is emitting network events. For instance, in the following JS code
//
// (function() {
// let request = new URLRequest(...);
// request.on('response', (response)=>{
// response.on('data', (data) = > {
// console.log(data.toString());
// });
// });
// })();
//
// we still want data to be logged even if the response/request objects are n
// more referenced in JavaScript.
//
// Binding by simply following the native_mate Wrapper/Wrappable pattern will
// delete the URLRequest object when the corresponding JS object is collected.
// The v8 handle is a private member in WrappableBase and it is always weak,
// there is no way to make it strong without changing native_mate.
// The solution we implement consists of maintaining some kind of state that
// prevents collection of JS wrappers as long as the request is emitting network
// events. At initialization, the object is unpinned. When the request starts,
// it is pinned. When no more events would be emitted, the object is unpinned
// and lifetime is again managed by the standard native mate Wrapper/Wrappable
// pattern.
//
// pin/unpin: are implemented by constructing/reseting a V8 strong persistent
// handle.
//
// The URLRequest/AtmURLRequest interaction could have been implemented in a
// single class. However, it implies that the resulting class lifetime will be
// managed by two conflicting mechanisms: JavaScript garbage collection and
// Chromium reference counting. Reasoning about lifetime issues become much
// more complex.
//
// We chose to split the implementation into two classes linked via a
// reference counted/raw pointers. A URLRequest instance is deleted if it is
// unpinned and the corresponding JS wrapper object is garbage collected. On the
// other hand, an AtmURLRequest instance lifetime is totally governed by
// reference counting.
//
class URLRequest : public mate::EventEmitter<URLRequest> {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
// Methods for reporting events into JavaScript.
void OnReceivedRedirect(
int status_code,
const std::string& method,
const GURL& url,
scoped_refptr<net::HttpResponseHeaders> response_headers);
void OnAuthenticationRequired(const net::AuthChallengeInfo& auth_info);
void OnResponseStarted(
scoped_refptr<net::HttpResponseHeaders> response_headers);
void OnResponseData(scoped_refptr<const net::IOBufferWithSize> data);
void OnResponseCompleted();
void OnError(const std::string& error, bool isRequestError);
mate::Dictionary GetUploadProgress(v8::Isolate* isolate);
protected:
explicit URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
~URLRequest() override;
private:
template <typename Flags>
class StateBase {
public:
void SetFlag(Flags flag);
protected:
explicit StateBase(Flags initialState);
bool operator==(Flags flag) const;
bool IsFlagSet(Flags flag) const;
private:
Flags state_;
};
enum class RequestStateFlags {
kNotStarted = 0x0,
kStarted = 0x1,
kFinished = 0x2,
kCanceled = 0x4,
kFailed = 0x8,
kClosed = 0x10
};
class RequestState : public StateBase<RequestStateFlags> {
public:
RequestState();
bool NotStarted() const;
bool Started() const;
bool Finished() const;
bool Canceled() const;
bool Failed() const;
bool Closed() const;
};
enum class ResponseStateFlags {
kNotStarted = 0x0,
kStarted = 0x1,
kEnded = 0x2,
kFailed = 0x4
};
class ResponseState : public StateBase<ResponseStateFlags> {
public:
ResponseState();
bool NotStarted() const;
bool Started() const;
bool Ended() const;
bool Canceled() const;
bool Failed() const;
bool Closed() const;
};
bool NotStarted() const;
bool Finished() const;
bool Canceled() const;
bool Failed() const;
bool Write(scoped_refptr<const net::IOBufferWithSize> buffer, bool is_last);
void Cancel();
void FollowRedirect();
bool SetExtraHeader(const std::string& name, const std::string& value);
void RemoveExtraHeader(const std::string& name);
void SetChunkedUpload(bool is_chunked_upload);
void SetLoadFlags(int flags);
int StatusCode() const;
std::string StatusMessage() const;
net::HttpResponseHeaders* RawResponseHeaders() const;
uint32_t ResponseHttpVersionMajor() const;
uint32_t ResponseHttpVersionMinor() const;
void Close();
void Pin();
void Unpin();
template <typename... Args>
void EmitRequestEvent(Args... args);
template <typename... Args>
void EmitResponseEvent(Args... args);
scoped_refptr<AtomURLRequest> atom_request_;
RequestState request_state_;
ResponseState response_state_;
// Used to implement pin/unpin.
v8::Global<v8::Object> wrapper_;
scoped_refptr<net::HttpResponseHeaders> response_headers_;
DISALLOW_COPY_AND_ASSIGN(URLRequest);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_

Some files were not shown because too many files have changed in this diff Show More