mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
Compare commits
83 Commits
v1.8.2-bet
...
v1.6.15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a44e7c058 | ||
|
|
bee5a70fbf | ||
|
|
73c4fe626b | ||
|
|
befa1d9c79 | ||
|
|
40e37c68d5 | ||
|
|
0c37f633b8 | ||
|
|
1723c302f7 | ||
|
|
f41051fe60 | ||
|
|
396a49e349 | ||
|
|
482a1d2e2b | ||
|
|
ca6127c802 | ||
|
|
588f906fba | ||
|
|
14bdbbcc10 | ||
|
|
a0cec63c91 | ||
|
|
233fdeaef0 | ||
|
|
54b12ba15d | ||
|
|
cfa4fbc9c1 | ||
|
|
4b03f5b87e | ||
|
|
acf6518317 | ||
|
|
f7e07205b4 | ||
|
|
248c1e1118 | ||
|
|
cb251892c2 | ||
|
|
5fcf20a7aa | ||
|
|
2e38f9ca1c | ||
|
|
ece433f766 | ||
|
|
f6005ce28d | ||
|
|
93cea48d04 | ||
|
|
4fb6bef8ed | ||
|
|
f4fd62db47 | ||
|
|
2ede7d9ec9 | ||
|
|
7a67c36cdb | ||
|
|
1131b5ae2f | ||
|
|
9429eea12c | ||
|
|
a0b04005a9 | ||
|
|
a7d3cea6e8 | ||
|
|
f2fe287b34 | ||
|
|
47242064ba | ||
|
|
da73284515 | ||
|
|
9b74f25770 | ||
|
|
dcb5a34922 | ||
|
|
df55c1e717 | ||
|
|
a62f13856b | ||
|
|
c83ff61fdf | ||
|
|
2b83512c44 | ||
|
|
c12f7d3132 | ||
|
|
9c0a8ab168 | ||
|
|
8842b04567 | ||
|
|
0573919fd3 | ||
|
|
5253c0a816 | ||
|
|
05b412313d | ||
|
|
0428632a4e | ||
|
|
855d2c4b20 | ||
|
|
f0402be869 | ||
|
|
5a1e3fc0f3 | ||
|
|
01c31ee924 | ||
|
|
c29316b568 | ||
|
|
21f15fa87e | ||
|
|
ab95ecda42 | ||
|
|
456e83f286 | ||
|
|
1612ebc539 | ||
|
|
1ddb8a8bf1 | ||
|
|
bbcdbc2e7c | ||
|
|
d94bbd1573 | ||
|
|
583e14efcd | ||
|
|
b96803e3a0 | ||
|
|
c03cb11aaf | ||
|
|
5de881e668 | ||
|
|
964505398d | ||
|
|
16f2958ad7 | ||
|
|
332b92ebab | ||
|
|
b9f66a342c | ||
|
|
23ce796450 | ||
|
|
df6d316dc2 | ||
|
|
82a93ce645 | ||
|
|
5ceaca66f5 | ||
|
|
4c0e35776b | ||
|
|
cc1f213d84 | ||
|
|
4c18037e6a | ||
|
|
7f0ccdadcd | ||
|
|
8ac9499b45 | ||
|
|
8094d68acc | ||
|
|
80066c22b2 | ||
|
|
8f78f3b253 |
@@ -9,9 +9,7 @@ jobs:
|
||||
resource_class: xlarge
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Setup for headless testing
|
||||
command: sh -e /etc/init.d/xvfb start
|
||||
- run: sh -e /etc/init.d/xvfb start
|
||||
- run:
|
||||
name: Check for release
|
||||
command: |
|
||||
@@ -24,67 +22,10 @@ jobs:
|
||||
command: |
|
||||
if [ "$ELECTRON_RELEASE" == "1" ]; then
|
||||
echo 'Bootstrapping Electron for release build'
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH -v
|
||||
else
|
||||
echo 'Bootstrapping Electron for debug build'
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH --dev
|
||||
fi
|
||||
- run: npm run lint
|
||||
- run:
|
||||
name: Build
|
||||
command: |
|
||||
if [ "$ELECTRON_RELEASE" == "1" ]; then
|
||||
echo 'Building Electron for release'
|
||||
script/build.py -c R
|
||||
else
|
||||
echo 'Building Electron for debug'
|
||||
script/build.py -c D
|
||||
fi
|
||||
- run:
|
||||
name: Create distribution
|
||||
command: |
|
||||
if [ "$ELECTRON_RELEASE" == "1" ]; then
|
||||
echo 'Creating Electron release distribution'
|
||||
script/create-dist.py
|
||||
else
|
||||
echo 'Skipping create distribution because build is not for release'
|
||||
fi
|
||||
- run:
|
||||
name: Upload distribution
|
||||
command: |
|
||||
if [ "$ELECTRON_RELEASE" == "1" ]; then
|
||||
echo 'Uploading Electron release distribution'
|
||||
script/upload.py
|
||||
else
|
||||
echo 'Skipping upload distribution because build is not for release'
|
||||
fi
|
||||
electron-linux-arm64:
|
||||
docker:
|
||||
- image: electronbuilds/electron:0.0.3
|
||||
environment:
|
||||
TARGET_ARCH: arm64
|
||||
resource_class: xlarge
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Setup for headless testing
|
||||
command: sh -e /etc/init.d/xvfb start
|
||||
- run:
|
||||
name: Check for release
|
||||
command: |
|
||||
MESSAGE="$(git log --format=%B -n 1 HEAD)"
|
||||
case ${MESSAGE} in
|
||||
Bump* ) echo 'export ELECTRON_RELEASE=1' >> $BASH_ENV
|
||||
esac
|
||||
- run:
|
||||
name: Bootstrap
|
||||
command: |
|
||||
if [ "$ELECTRON_RELEASE" == "1" ]; then
|
||||
echo 'Bootstrapping Electron for release build'
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH
|
||||
else
|
||||
echo 'Bootstrapping Electron for debug build'
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH --dev
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH -v --dev
|
||||
fi
|
||||
- run: npm run lint
|
||||
- run:
|
||||
@@ -115,6 +56,7 @@ jobs:
|
||||
else
|
||||
echo 'Skipping upload distribution because build is not for release'
|
||||
fi
|
||||
|
||||
electron-linux-ia32:
|
||||
docker:
|
||||
- image: electronbuilds/electron:0.0.3
|
||||
@@ -123,9 +65,7 @@ jobs:
|
||||
resource_class: xlarge
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Setup for headless testing
|
||||
command: sh -e /etc/init.d/xvfb start
|
||||
- run: sh -e /etc/init.d/xvfb start
|
||||
- run:
|
||||
name: Check for release
|
||||
command: |
|
||||
@@ -138,10 +78,10 @@ jobs:
|
||||
command: |
|
||||
if [ "$ELECTRON_RELEASE" == "1" ]; then
|
||||
echo 'Bootstrapping Electron for release build'
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH -v
|
||||
else
|
||||
echo 'Bootstrapping Electron for debug build'
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH --dev
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH -v --dev
|
||||
fi
|
||||
- run: npm run lint
|
||||
- run:
|
||||
@@ -181,9 +121,7 @@ jobs:
|
||||
resource_class: xlarge
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Setup for headless testing
|
||||
command: sh -e /etc/init.d/xvfb start
|
||||
- run: sh -e /etc/init.d/xvfb start
|
||||
- run:
|
||||
name: Check for release
|
||||
command: |
|
||||
@@ -196,10 +134,10 @@ jobs:
|
||||
command: |
|
||||
if [ "$ELECTRON_RELEASE" == "1" ]; then
|
||||
echo 'Bootstrapping Electron for release build'
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH -v
|
||||
else
|
||||
echo 'Bootstrapping Electron for debug build'
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH --dev
|
||||
script/bootstrap.py --target_arch=$TARGET_ARCH -v --dev
|
||||
fi
|
||||
- run: npm run lint
|
||||
- run:
|
||||
@@ -232,14 +170,10 @@ jobs:
|
||||
fi
|
||||
- run:
|
||||
name: Test
|
||||
environment:
|
||||
MOCHA_FILE: junit/test-results.xml
|
||||
MOCHA_REPORTER: mocha-junit-reporter
|
||||
command: |
|
||||
if [ "$ELECTRON_RELEASE" != "1" ]; then
|
||||
echo 'Testing Electron debug build'
|
||||
mkdir junit
|
||||
script/test.py --ci --rebuild_native_modules
|
||||
script/test.py --ci
|
||||
else
|
||||
echo 'Skipping testing on release build'
|
||||
fi
|
||||
@@ -252,19 +186,12 @@ jobs:
|
||||
else
|
||||
echo 'Skipping verify ffmpeg on release build'
|
||||
fi
|
||||
- store_test_results:
|
||||
path: junit
|
||||
- store_artifacts:
|
||||
path: junit
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
build-arm:
|
||||
jobs:
|
||||
- electron-linux-arm
|
||||
build-arm64:
|
||||
jobs:
|
||||
- electron-linux-arm64
|
||||
build-ia32:
|
||||
jobs:
|
||||
- electron-linux-ia32
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!tools/xvfb-init.sh
|
||||
21
.github/CODEOWNERS
vendored
21
.github/CODEOWNERS
vendored
@@ -1,21 +0,0 @@
|
||||
# Order is important. The LAST matching pattern has the MOST precedence.
|
||||
# gitignore style patterns are used, not globs.
|
||||
# https://help.github.com/articles/about-codeowners
|
||||
# https://git-scm.com/docs/gitignore
|
||||
|
||||
# Everything that falls through the cracks:
|
||||
* @electron/reviewers
|
||||
|
||||
# filename patterns
|
||||
*browser_view* @electron/browserview
|
||||
*notification* @electron/notifications
|
||||
*pdf* @electron/printing
|
||||
*printing* @electron/printing
|
||||
*updater* @electron/updater
|
||||
|
||||
# directories
|
||||
/.github/ @electron/hubbers
|
||||
/default_app/ @electron/docs
|
||||
/docs/ @electron/docs
|
||||
/docs-translations/ @electron/i18n
|
||||
/npm/ @electron/hubbers
|
||||
29
.github/config.yml
vendored
29
.github/config.yml
vendored
@@ -1,29 +0,0 @@
|
||||
# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome
|
||||
|
||||
# Comment to be posted to on first time issues
|
||||
newIssueWelcomeComment: |
|
||||
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
|
||||
|
||||
To help make it easier for us to investigate your issue, please follow the [contributing guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md#submitting-issues).
|
||||
|
||||
# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
|
||||
|
||||
# Comment to be posted to on PRs from first time contributors in your repository
|
||||
newPRWelcomeComment: |
|
||||
💖 Thanks for opening this pull request! 💖
|
||||
|
||||
Here is a list of things that will help get it across the finish line:
|
||||
- Follow the JavaScript, C++, and Python [coding style](https://github.com/electron/electron/blob/master/docs/development/coding-style.md).
|
||||
- Run `npm run lint` locally to catch formatting errors earlier.
|
||||
- Document any user-facing changes you've made following the [documentation styleguide](https://github.com/electron/electron/blob/master/docs/styleguide.md).
|
||||
- Include tests when adding/changing behavior.
|
||||
- Include screenshots and animated GIFs whenever possible.
|
||||
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.
|
||||
|
||||
# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
|
||||
|
||||
# Comment to be posted to on pull requests merged by a first time user
|
||||
firstPRMergeComment: >
|
||||
Congrats on merging your first pull request! 🎉🎉🎉
|
||||
|
||||
# It is recommend to include as many gifs and emojis as possiblec
|
||||
25
.github/stale.yml
vendored
25
.github/stale.yml
vendored
@@ -1,25 +0,0 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 45
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 7
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- fixme/bug
|
||||
- fixme/crash
|
||||
- fixme/regression
|
||||
- fixme/security
|
||||
- blocked
|
||||
- blocking-stable
|
||||
- needs-review
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: stale
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity and is not currently prioritized. It will be closed
|
||||
in a week if no further activity occurs :)
|
||||
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: >
|
||||
If you still think this issue is relevant, please ping a maintainer or
|
||||
leave a comment!
|
||||
50
.gitignore
vendored
50
.gitignore
vendored
@@ -1,45 +1,29 @@
|
||||
.DS_Store
|
||||
.env
|
||||
.gclient_done
|
||||
.npmrc
|
||||
.tags*
|
||||
.vs/
|
||||
.vscode/
|
||||
*.log
|
||||
*.pyc
|
||||
*.sln
|
||||
*.swp
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
*.vcxproj.user
|
||||
*.xcodeproj
|
||||
/.idea/
|
||||
/brightray/brightray.opensdf
|
||||
/brightray/brightray.sdf
|
||||
/brightray/brightray.sln
|
||||
/brightray/brightray.suo
|
||||
/brightray/brightray.v12.suo
|
||||
/brightray/brightray.vcxproj*
|
||||
/brightray/brightray.xcodeproj/
|
||||
/build/
|
||||
/dist/
|
||||
/external_binaries/
|
||||
/out/
|
||||
/vendor/.gclient
|
||||
/vendor/debian_jessie_amd64-sysroot/
|
||||
/vendor/debian_jessie_arm-sysroot/
|
||||
/vendor/debian_jessie_arm64-sysroot/
|
||||
/vendor/debian_jessie_i386-sysroot/
|
||||
/vendor/brightray/vendor/download/
|
||||
/vendor/debian_wheezy_amd64-sysroot/
|
||||
/vendor/debian_wheezy_arm-sysroot/
|
||||
/vendor/debian_wheezy_i386-sysroot/
|
||||
/vendor/download/
|
||||
/vendor/llvm-build/
|
||||
/vendor/llvm/
|
||||
/vendor/node/deps/node-inspect/.npmrc
|
||||
/vendor/npm/
|
||||
/vendor/python_26/
|
||||
/vendor/npm/
|
||||
/vendor/llvm/
|
||||
/vendor/llvm-build/
|
||||
/vendor/.gclient
|
||||
node_modules/
|
||||
SHASUMS256.txt
|
||||
*.xcodeproj
|
||||
*.swp
|
||||
*.pyc
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
.vs/
|
||||
.vscode/
|
||||
*.vcxproj
|
||||
*.vcxproj.user
|
||||
*.vcxproj.filters
|
||||
*.sln
|
||||
*.log
|
||||
|
||||
9
.gitmodules
vendored
9
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "vendor/brightray"]
|
||||
path = vendor/brightray
|
||||
url = https://github.com/electron/brightray.git
|
||||
[submodule "vendor/node"]
|
||||
path = vendor/node
|
||||
url = https://github.com/electron/node.git
|
||||
@@ -22,9 +25,3 @@
|
||||
[submodule "vendor/pdf_viewer"]
|
||||
path = vendor/pdf_viewer
|
||||
url = https://github.com/electron/pdf-viewer.git
|
||||
[submodule "vendor/gyp"]
|
||||
path = vendor/gyp
|
||||
url = https://github.com/electron/gyp
|
||||
[submodule "vendor/libchromiumcontent"]
|
||||
path = vendor/libchromiumcontent
|
||||
url = https://github.com/electron/libchromiumcontent
|
||||
|
||||
@@ -1 +1 @@
|
||||
v8.2.1
|
||||
v7.4.0
|
||||
|
||||
@@ -3,9 +3,6 @@ git:
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
before_install:
|
||||
- export BOTO_CONFIG=/dev/null
|
||||
|
||||
language: node_js
|
||||
node_js:
|
||||
- "4"
|
||||
@@ -22,8 +19,6 @@ matrix:
|
||||
env: TARGET_ARCH=arm
|
||||
- os: linux
|
||||
env: TARGET_ARCH=ia32
|
||||
- os: linux
|
||||
env: TARGET_ARCH=arm64
|
||||
allow_failures:
|
||||
- os: osx
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md).
|
||||
By participating, you are expected to uphold this code. Please report unacceptable
|
||||
behavior to electron@github.com.
|
||||
behavior to atom@github.com.
|
||||
|
||||
The following is a set of guidelines for contributing to Electron.
|
||||
These are just guidelines, not rules, use your best judgment and feel free to
|
||||
@@ -14,7 +14,6 @@ propose changes to this document in a pull request.
|
||||
|
||||
## Submitting Issues
|
||||
|
||||
### Creating Issues
|
||||
* You can create an issue [here](https://github.com/electron/electron/issues/new),
|
||||
but before doing that please read the notes below and include as many details as
|
||||
possible with your report. If you can, please include:
|
||||
@@ -28,15 +27,6 @@ possible with your report. If you can, please include:
|
||||
* Perform a [cursory search](https://github.com/electron/electron/issues?utf8=✓&q=is%3Aissue+)
|
||||
to see if a similar issue has already been submitted
|
||||
|
||||
### Issue Maintenance and Closure
|
||||
* If an issue is inactive for 45 days (no activity of any kind), it will be
|
||||
marked for closure with `stale`.
|
||||
* If after this label is applied, no further activity occurs in the next 7 days,
|
||||
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!
|
||||
|
||||
|
||||
## Submitting Pull Requests
|
||||
|
||||
* Include screenshots and animated GIFs in your pull request whenever possible.
|
||||
|
||||
18
Dockerfile
18
Dockerfile
@@ -1,18 +0,0 @@
|
||||
FROM electronbuilds/libchromiumcontent:0.0.4
|
||||
|
||||
USER root
|
||||
|
||||
# Set up HOME directory
|
||||
ENV HOME=/home
|
||||
RUN chmod a+rwx /home
|
||||
|
||||
# Install node.js
|
||||
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
|
||||
RUN apt-get update && apt-get install -y --force-yes nodejs
|
||||
|
||||
# Install wget used by crash reporter
|
||||
RUN apt-get install -y --force-yes wget
|
||||
|
||||
# Add xvfb init script
|
||||
ADD tools/xvfb-init.sh /etc/init.d/xvfb
|
||||
RUN chmod a+x /etc/init.d/xvfb
|
||||
@@ -1,17 +0,0 @@
|
||||
FROM electronbuilds/libchromiumcontent:0.0.4
|
||||
|
||||
USER root
|
||||
|
||||
# Install node.js
|
||||
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
|
||||
RUN apt-get update && apt-get install -y --force-yes nodejs
|
||||
|
||||
# Install wget used by crash reporter
|
||||
RUN apt-get install -y --force-yes wget
|
||||
|
||||
# Add xvfb init script
|
||||
ADD tools/xvfb-init.sh /etc/init.d/xvfb
|
||||
RUN chmod a+x /etc/init.d/xvfb
|
||||
|
||||
USER builduser
|
||||
WORKDIR /home/builduser
|
||||
81
README.md
81
README.md
@@ -5,7 +5,7 @@
|
||||
[](https://david-dm.org/electron/electron?type=dev)
|
||||
[](http://atom-slack.herokuapp.com/)
|
||||
|
||||
:memo: Available Translations: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/README.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/README.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/README.md) | [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW/project/README.md) | [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es/project/README.md) | [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR/project/README.md) | [German](https://github.com/electron/electron/tree/master/docs-translations/de-DE/project/README.md)
|
||||
:memo: Available Translations: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/README.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/README.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/README.md) | [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW/project/README.md) | [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es/project/README.md) | [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR/project/README.md)
|
||||
|
||||
The Electron framework lets you write cross-platform desktop applications
|
||||
using JavaScript, HTML and CSS. It is based on [Node.js](https://nodejs.org/) and
|
||||
@@ -15,71 +15,36 @@ editor](https://github.com/atom/atom) and many other [apps](https://electron.ato
|
||||
Follow [@ElectronJS](https://twitter.com/electronjs) on Twitter for important
|
||||
announcements.
|
||||
|
||||
This project adheres to the Contributor Covenant
|
||||
[code of conduct](https://github.com/electron/electron/tree/master/CODE_OF_CONDUCT.md).
|
||||
This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md).
|
||||
By participating, you are expected to uphold this code. Please report unacceptable
|
||||
behavior to [electron@github.com](mailto:electron@github.com).
|
||||
behavior to electron@github.com.
|
||||
|
||||
## Installation
|
||||
## Downloads
|
||||
|
||||
To install prebuilt Electron binaries, use [`npm`](https://docs.npmjs.com/).
|
||||
The preferred method is to install Electron as a development dependency in your
|
||||
app:
|
||||
To install prebuilt Electron binaries, use
|
||||
[`npm`](https://docs.npmjs.com/):
|
||||
|
||||
```sh
|
||||
npm install electron --save-dev --save-exact
|
||||
# Install as a development dependency
|
||||
npm install electron --save-dev
|
||||
|
||||
# Install the `electron` command globally in your $PATH
|
||||
npm install electron -g
|
||||
```
|
||||
|
||||
The `--save-exact` flag is recommended as Electron does not follow semantic
|
||||
versioning. For info on how to manage Electron versions in your apps, see
|
||||
[Electron versioning](https://electron.atom.io/docs/tutorial/electron-versioning/).
|
||||
|
||||
For more installation options and troubleshooting tips, see
|
||||
[installation](https://electron.atom.io/docs/tutorial/installation/).
|
||||
|
||||
## Quick Start
|
||||
|
||||
Clone and run the
|
||||
[electron/electron-quick-start](https://github.com/electron/electron-quick-start)
|
||||
repository to see a minimal Electron app in action:
|
||||
|
||||
```
|
||||
git clone https://github.com/electron/electron-quick-start
|
||||
cd electron-quick-start
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
## Resources for Learning Electron
|
||||
|
||||
- [electron.atom.io/docs](http://electron.atom.io/docs) - all of Electron's documentation
|
||||
- [electron/electron-quick-start](https://github.com/electron/electron-quick-start) - a very basic starter Electron app
|
||||
- [electron.atom.io/community/#boilerplates](http://electron.atom.io/community/#boilerplates) - sample starter apps created by the community
|
||||
- [electron/simple-samples](https://github.com/electron/simple-samples) - small applications with ideas for taking them further
|
||||
- [electron/electron-api-demos](https://github.com/electron/electron-api-demos) - an Electron app that teaches you how to use Electron
|
||||
- [hokein/electron-sample-apps](https://github.com/hokein/electron-sample-apps) - small demo apps for the various Electron APIs
|
||||
|
||||
## Programmatic usage
|
||||
|
||||
Most people use Electron from the command line, but if you require `electron` inside
|
||||
your **Node app** (not your Electron app) it will return the file path to the
|
||||
binary. Use this to spawn Electron from Node scripts:
|
||||
|
||||
```javascript
|
||||
const electron = require('electron')
|
||||
const proc = require('child_process')
|
||||
|
||||
// will print something similar to /Users/maf/.../Electron
|
||||
console.log(electron)
|
||||
|
||||
// spawn Electron
|
||||
const child = proc.spawn(electron)
|
||||
```
|
||||
See the [releases page](https://github.com/electron/electron/releases) for
|
||||
prebuilt binaries, debug symbols, and more.
|
||||
|
||||
### Mirrors
|
||||
|
||||
- [China](https://npm.taobao.org/mirrors/electron)
|
||||
|
||||
## Documentation
|
||||
|
||||
Guides and the API reference are located in the
|
||||
[docs](https://github.com/electron/electron/tree/master/docs) directory. It also
|
||||
contains documents describing how to build and contribute to Electron.
|
||||
|
||||
## Documentation Translations
|
||||
|
||||
- [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR)
|
||||
@@ -89,11 +54,15 @@ const child = proc.spawn(electron)
|
||||
- [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN)
|
||||
- [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW)
|
||||
- [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR)
|
||||
- [Thai](https://github.com/electron/electron/tree/master/docs-translations/th-TH)
|
||||
- [Thai](https://github.com/electron/electron/tree/master/docs-Translations/th-TH)
|
||||
- [Ukrainian](https://github.com/electron/electron/tree/master/docs-translations/uk-UA)
|
||||
- [Russian](https://github.com/electron/electron/tree/master/docs-translations/ru-RU)
|
||||
- [French](https://github.com/electron/electron/tree/master/docs-translations/fr-FR)
|
||||
- [Indonesian](https://github.com/electron/electron/tree/master/docs-translations/id)
|
||||
|
||||
## Quick Start
|
||||
|
||||
Clone and run the [`electron/electron-quick-start`](https://github.com/electron/electron-quick-start)
|
||||
repository to see a minimal Electron app in action.
|
||||
|
||||
## Community
|
||||
|
||||
|
||||
@@ -20,6 +20,6 @@ branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
# disable build and test phases
|
||||
# disable build and test pahses
|
||||
build: off
|
||||
test: off
|
||||
|
||||
@@ -93,9 +93,9 @@ content::PepperPluginInfo CreateWidevineCdmInfo(const base::FilePath& path,
|
||||
std::vector<std::string> codecs;
|
||||
codecs.push_back(kCdmSupportedCodecVp8);
|
||||
codecs.push_back(kCdmSupportedCodecVp9);
|
||||
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
|
||||
#if defined(USE_PROPRIETARY_CODECS)
|
||||
codecs.push_back(kCdmSupportedCodecAvc1);
|
||||
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
|
||||
#endif // defined(USE_PROPRIETARY_CODECS)
|
||||
std::string codec_string = base::JoinString(
|
||||
codecs, std::string(1, kCdmSupportedCodecsValueDelimiter));
|
||||
widevine_cdm_mime_type.additional_param_names.push_back(
|
||||
@@ -198,19 +198,11 @@ base::string16 AtomContentClient::GetLocalizedString(int message_id) const {
|
||||
return l10n_util::GetStringUTF16(message_id);
|
||||
}
|
||||
|
||||
void AtomContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
||||
schemes->standard_schemes.push_back("chrome-extension");
|
||||
|
||||
std::vector<std::string> splited;
|
||||
ConvertStringWithSeparatorToVector(&splited, ",",
|
||||
switches::kRegisterServiceWorkerSchemes);
|
||||
for (const std::string& scheme : splited)
|
||||
schemes->service_worker_schemes.push_back(scheme);
|
||||
schemes->service_worker_schemes.push_back(url::kFileScheme);
|
||||
|
||||
ConvertStringWithSeparatorToVector(&splited, ",", switches::kSecureSchemes);
|
||||
for (const std::string& scheme : splited)
|
||||
schemes->secure_schemes.push_back(scheme);
|
||||
void AtomContentClient::AddAdditionalSchemes(
|
||||
std::vector<url::SchemeWithType>* standard_schemes,
|
||||
std::vector<url::SchemeWithType>* referrer_schemes,
|
||||
std::vector<std::string>* savable_schemes) {
|
||||
standard_schemes->push_back({"chrome-extension", url::SCHEME_WITHOUT_PORT});
|
||||
}
|
||||
|
||||
void AtomContentClient::AddPepperPlugins(
|
||||
@@ -222,4 +214,25 @@ void AtomContentClient::AddPepperPlugins(
|
||||
ComputeBuiltInPlugins(plugins);
|
||||
}
|
||||
|
||||
void AtomContentClient::AddServiceWorkerSchemes(
|
||||
std::set<std::string>* service_worker_schemes) {
|
||||
std::vector<std::string> schemes;
|
||||
ConvertStringWithSeparatorToVector(&schemes, ",",
|
||||
switches::kRegisterServiceWorkerSchemes);
|
||||
for (const std::string& scheme : schemes)
|
||||
service_worker_schemes->insert(scheme);
|
||||
|
||||
service_worker_schemes->insert(url::kFileScheme);
|
||||
}
|
||||
|
||||
void AtomContentClient::AddSecureSchemesAndOrigins(
|
||||
std::set<std::string>* secure_schemes,
|
||||
std::set<GURL>* secure_origins) {
|
||||
std::vector<std::string> schemes;
|
||||
ConvertStringWithSeparatorToVector(&schemes, ",", switches::kSecureSchemes);
|
||||
for (const std::string& scheme : schemes)
|
||||
secure_schemes->insert(scheme);
|
||||
}
|
||||
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -23,9 +23,17 @@ class AtomContentClient : public brightray::ContentClient {
|
||||
std::string GetProduct() const override;
|
||||
std::string GetUserAgent() const override;
|
||||
base::string16 GetLocalizedString(int message_id) const override;
|
||||
void AddAdditionalSchemes(Schemes* schemes) override;
|
||||
void AddAdditionalSchemes(
|
||||
std::vector<url::SchemeWithType>* standard_schemes,
|
||||
std::vector<url::SchemeWithType>* referrer_schemes,
|
||||
std::vector<std::string>* savable_schemes) override;
|
||||
void AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) override;
|
||||
void AddServiceWorkerSchemes(
|
||||
std::set<std::string>* service_worker_schemes) override;
|
||||
void AddSecureSchemesAndOrigins(
|
||||
std::set<std::string>* secure_schemes,
|
||||
std::set<GURL>* secure_origins) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomContentClient);
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#if defined(OS_WIN)
|
||||
#include <windows.h> // windows.h must be included first
|
||||
|
||||
#include <atlbase.h> // ensures that ATL statics like `_AtlWinModule` are initialized (it's an issue in static debug build)
|
||||
#include <shellapi.h>
|
||||
#include <shellscalingapi.h>
|
||||
#include <tchar.h>
|
||||
@@ -35,7 +34,7 @@
|
||||
|
||||
namespace {
|
||||
|
||||
const auto kRunAsNode = "ELECTRON_RUN_AS_NODE";
|
||||
const char* kRunAsNode = "ELECTRON_RUN_AS_NODE";
|
||||
|
||||
bool IsEnvSet(const char* name) {
|
||||
#if defined(OS_WIN)
|
||||
@@ -57,30 +56,6 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||
|
||||
bool run_as_node = IsEnvSet(kRunAsNode);
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Don't display assert dialog boxes in CI test runs
|
||||
static const auto kCI = "ELECTRON_CI";
|
||||
bool is_ci = IsEnvSet(kCI);
|
||||
if (!is_ci) {
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
if (!_wcsicmp(wargv[i], L"--ci")) {
|
||||
is_ci = true;
|
||||
_putenv_s(kCI, "1"); // set flag for child processes
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_ci) {
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||
|
||||
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
|
||||
|
||||
_set_error_mode(_OUT_TO_STDERR);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Make sure the output is printed to console.
|
||||
if (run_as_node || !IsEnvSet("ELECTRON_NO_ATTACH_CONSOLE"))
|
||||
base::RouteStdioToConsole(false);
|
||||
@@ -119,25 +94,6 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef DEBUG
|
||||
// Chromium has its own TLS subsystem which supports automatic destruction
|
||||
// of thread-local data, and also depends on memory allocation routines
|
||||
// provided by the CRT. The problem is that the auto-destruction mechanism
|
||||
// uses a hidden feature of the OS loader which calls a callback on thread
|
||||
// exit, but only after all loaded DLLs have been detached. Since the CRT is
|
||||
// also a DLL, it happens that by the time Chromium's `OnThreadExit` function
|
||||
// is called, the heap functions, though still in memory, no longer perform
|
||||
// their duties, and when Chromium calls `free` on its buffer, it triggers
|
||||
// an access violation error.
|
||||
// We work around this problem by invoking Chromium's `OnThreadExit` in time
|
||||
// from within the CRT's atexit facility, ensuring the heap functions are
|
||||
// still active. The second invocation from the OS loader will be a no-op.
|
||||
extern void NTAPI OnThreadExit(PVOID module, DWORD reason, PVOID reserved);
|
||||
atexit([]() {
|
||||
OnThreadExit(nullptr, DLL_THREAD_DETACH, nullptr);
|
||||
});
|
||||
#endif
|
||||
|
||||
if (run_as_node) {
|
||||
// Now that argv conversion is done, we can finally start.
|
||||
base::AtExitManager atexit_manager;
|
||||
|
||||
@@ -126,15 +126,13 @@ void AtomMainDelegate::PreSandboxStartup() {
|
||||
if (!IsBrowserProcess(command_line))
|
||||
return;
|
||||
|
||||
if (!command_line->HasSwitch(switches::kEnableMixedSandbox)) {
|
||||
if (command_line->HasSwitch(switches::kEnableSandbox)) {
|
||||
// Disable setuid sandbox since it is not longer required on
|
||||
// linux(namespace sandbox is available on most distros).
|
||||
command_line->AppendSwitch(::switches::kDisableSetuidSandbox);
|
||||
} else {
|
||||
// Disable renderer sandbox for most of node's functions.
|
||||
command_line->AppendSwitch(::switches::kNoSandbox);
|
||||
}
|
||||
if (command_line->HasSwitch(switches::kEnableSandbox)) {
|
||||
// Disable setuid sandbox since it is not longer required on linux(namespace
|
||||
// sandbox is available on most distros).
|
||||
command_line->AppendSwitch(::switches::kDisableSetuidSandbox);
|
||||
} else {
|
||||
// Disable renderer sandbox for most of node's functions.
|
||||
command_line->AppendSwitch(::switches::kNoSandbox);
|
||||
}
|
||||
|
||||
// Allow file:// URIs to read other file:// URIs by default.
|
||||
@@ -154,9 +152,7 @@ content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
|
||||
content::ContentRendererClient*
|
||||
AtomMainDelegate::CreateContentRendererClient() {
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kEnableSandbox) ||
|
||||
!base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
::switches::kNoSandbox)) {
|
||||
switches::kEnableSandbox)) {
|
||||
renderer_client_.reset(new AtomSandboxedRendererClient);
|
||||
} else {
|
||||
renderer_client_.reset(new AtomRendererClient);
|
||||
|
||||
@@ -51,9 +51,10 @@ int NodeMain(int argc, char *argv[]) {
|
||||
&isolate_data, gin_env.context(), argc, argv,
|
||||
exec_argc, exec_argv);
|
||||
|
||||
// Enable support for v8 inspector.
|
||||
NodeDebugger node_debugger(env);
|
||||
node_debugger.Start();
|
||||
// Start our custom debugger implementation.
|
||||
NodeDebugger node_debugger(gin_env.isolate());
|
||||
if (node_debugger.IsRunning())
|
||||
env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate()));
|
||||
|
||||
mate::Dictionary process(gin_env.isolate(), env->process_object());
|
||||
#if defined(OS_WIN)
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/app/uv_task_runner.h"
|
||||
|
||||
#include "base/stl_util.h"
|
||||
@@ -21,13 +19,13 @@ UvTaskRunner::~UvTaskRunner() {
|
||||
}
|
||||
|
||||
bool UvTaskRunner::PostDelayedTask(const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
const base::Closure& task,
|
||||
base::TimeDelta delay) {
|
||||
auto* timer = new uv_timer_t;
|
||||
timer->data = this;
|
||||
uv_timer_init(loop_, timer);
|
||||
uv_timer_start(timer, UvTaskRunner::OnTimeout, delay.InMilliseconds(), 0);
|
||||
tasks_[timer] = std::move(task);
|
||||
tasks_[timer] = task;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,9 +35,9 @@ bool UvTaskRunner::RunsTasksOnCurrentThread() const {
|
||||
|
||||
bool UvTaskRunner::PostNonNestableDelayedTask(
|
||||
const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
const base::Closure& task,
|
||||
base::TimeDelta delay) {
|
||||
return PostDelayedTask(from_here, std::move(task), delay);
|
||||
return PostDelayedTask(from_here, task, delay);
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -48,7 +46,7 @@ void UvTaskRunner::OnTimeout(uv_timer_t* timer) {
|
||||
if (!ContainsKey(self->tasks_, timer))
|
||||
return;
|
||||
|
||||
std::move(self->tasks_[timer]).Run();
|
||||
self->tasks_[timer].Run();
|
||||
self->tasks_.erase(timer);
|
||||
uv_timer_stop(timer);
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(timer), UvTaskRunner::OnClose);
|
||||
|
||||
@@ -21,12 +21,12 @@ class UvTaskRunner : public base::SingleThreadTaskRunner {
|
||||
|
||||
// base::SingleThreadTaskRunner:
|
||||
bool PostDelayedTask(const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
const base::Closure& task,
|
||||
base::TimeDelta delay) override;
|
||||
bool RunsTasksOnCurrentThread() const override;
|
||||
bool PostNonNestableDelayedTask(
|
||||
const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
const base::Closure& task,
|
||||
base::TimeDelta delay) override;
|
||||
|
||||
private:
|
||||
@@ -35,7 +35,7 @@ class UvTaskRunner : public base::SingleThreadTaskRunner {
|
||||
|
||||
uv_loop_t* loop_;
|
||||
|
||||
std::map<uv_timer_t*, base::OnceClosure> tasks_;
|
||||
std::map<uv_timer_t*, base::Closure> tasks_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(UvTaskRunner);
|
||||
};
|
||||
|
||||
@@ -29,16 +29,12 @@
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/sys_info.h"
|
||||
#include "brightray/browser/brightray_paths.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/icon_manager.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "content/browser/gpu/compositor_util.h"
|
||||
#include "content/browser/gpu/gpu_data_manager_impl.h"
|
||||
#include "content/public/browser/browser_accessibility_state.h"
|
||||
#include "content/public/browser/browser_child_process_host.h"
|
||||
#include "content/public/browser/child_process_data.h"
|
||||
#include "content/public/browser/client_certificate_delegate.h"
|
||||
#include "content/public/browser/gpu_data_manager.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
@@ -54,10 +50,6 @@
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include "atom/browser/ui/cocoa/atom_bundle_mover.h"
|
||||
#endif
|
||||
|
||||
using atom::Browser;
|
||||
|
||||
namespace mate {
|
||||
@@ -375,8 +367,6 @@ int GetPathConstant(const std::string& name) {
|
||||
return brightray::DIR_CACHE;
|
||||
else if (name == "userCache")
|
||||
return brightray::DIR_USER_CACHE;
|
||||
else if (name == "logs")
|
||||
return brightray::DIR_APP_LOGS;
|
||||
else if (name == "home")
|
||||
return base::DIR_HOME;
|
||||
else if (name == "temp")
|
||||
@@ -474,8 +464,8 @@ int ImportIntoCertStore(
|
||||
|
||||
if (!cert_path.empty()) {
|
||||
if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) {
|
||||
auto module = model->cert_db()->GetPrivateSlot();
|
||||
rv = model->ImportFromPKCS12(module.get(),
|
||||
auto module = model->cert_db()->GetPublicModule();
|
||||
rv = model->ImportFromPKCS12(module,
|
||||
file_data,
|
||||
password,
|
||||
true,
|
||||
@@ -515,14 +505,6 @@ App::App(v8::Isolate* isolate) {
|
||||
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->set_delegate(this);
|
||||
Browser::Get()->AddObserver(this);
|
||||
content::GpuDataManager::GetInstance()->AddObserver(this);
|
||||
content::BrowserChildProcessObserver::Add(this);
|
||||
base::ProcessId pid = base::GetCurrentProcId();
|
||||
std::unique_ptr<atom::ProcessMetric> process_metric(
|
||||
new atom::ProcessMetric(
|
||||
content::PROCESS_TYPE_BROWSER,
|
||||
pid,
|
||||
base::ProcessMetrics::CreateCurrentProcessMetrics()));
|
||||
app_metrics_[pid] = std::move(process_metric);
|
||||
Init(isolate);
|
||||
}
|
||||
|
||||
@@ -531,7 +513,6 @@ App::~App() {
|
||||
nullptr);
|
||||
Browser::Get()->RemoveObserver(this);
|
||||
content::GpuDataManager::GetInstance()->RemoveObserver(this);
|
||||
content::BrowserChildProcessObserver::Remove(this);
|
||||
}
|
||||
|
||||
void App::OnBeforeQuit(bool* prevent_default) {
|
||||
@@ -581,52 +562,17 @@ void App::OnFinishLaunching(const base::DictionaryValue& launch_info) {
|
||||
Emit("ready", launch_info);
|
||||
}
|
||||
|
||||
void App::OnPreMainMessageLoopRun() {
|
||||
if (process_singleton_) {
|
||||
process_singleton_->OnBrowserReady();
|
||||
}
|
||||
}
|
||||
|
||||
void App::OnAccessibilitySupportChanged() {
|
||||
Emit("accessibility-support-changed", IsAccessibilitySupportEnabled());
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
void App::OnWillContinueUserActivity(
|
||||
bool* prevent_default,
|
||||
const std::string& type) {
|
||||
*prevent_default = Emit("will-continue-activity", type);
|
||||
}
|
||||
|
||||
void App::OnDidFailToContinueUserActivity(
|
||||
const std::string& type,
|
||||
const std::string& error) {
|
||||
Emit("continue-activity-error", type, error);
|
||||
}
|
||||
|
||||
void App::OnContinueUserActivity(
|
||||
bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) {
|
||||
*prevent_default = Emit("continue-activity", type, user_info);
|
||||
}
|
||||
|
||||
void App::OnUserActivityWasContinued(
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) {
|
||||
Emit("activity-was-continued", type, user_info);
|
||||
}
|
||||
|
||||
void App::OnUpdateUserActivityState(
|
||||
bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) {
|
||||
*prevent_default = Emit("update-activity-state", type, user_info);
|
||||
}
|
||||
|
||||
void App::OnNewWindowForTab() {
|
||||
Emit("new-window-for-tab");
|
||||
}
|
||||
#endif
|
||||
|
||||
void App::OnLogin(LoginHandler* login_handler,
|
||||
@@ -720,54 +666,6 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) {
|
||||
status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
|
||||
}
|
||||
|
||||
void App::BrowserChildProcessLaunchedAndConnected(
|
||||
const content::ChildProcessData& data) {
|
||||
ChildProcessLaunched(data.process_type, data.handle);
|
||||
}
|
||||
|
||||
void App::BrowserChildProcessHostDisconnected(
|
||||
const content::ChildProcessData& data) {
|
||||
ChildProcessDisconnected(base::GetProcId(data.handle));
|
||||
}
|
||||
|
||||
void App::BrowserChildProcessCrashed(const content::ChildProcessData& data,
|
||||
int exit_code) {
|
||||
ChildProcessDisconnected(base::GetProcId(data.handle));
|
||||
}
|
||||
|
||||
void App::BrowserChildProcessKilled(const content::ChildProcessData& data,
|
||||
int exit_code) {
|
||||
ChildProcessDisconnected(base::GetProcId(data.handle));
|
||||
}
|
||||
|
||||
void App::RenderProcessReady(content::RenderProcessHost* host) {
|
||||
ChildProcessLaunched(content::PROCESS_TYPE_RENDERER, host->GetHandle());
|
||||
}
|
||||
|
||||
void App::RenderProcessDisconnected(base::ProcessId host_pid) {
|
||||
ChildProcessDisconnected(host_pid);
|
||||
}
|
||||
|
||||
void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) {
|
||||
auto pid = base::GetProcId(handle);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
base::ProcessMetrics::CreateProcessMetrics(
|
||||
handle, content::BrowserChildProcessHost::GetPortProvider()));
|
||||
#else
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
base::ProcessMetrics::CreateProcessMetrics(handle));
|
||||
#endif
|
||||
std::unique_ptr<atom::ProcessMetric> process_metric(
|
||||
new atom::ProcessMetric(process_type, pid, std::move(metrics)));
|
||||
app_metrics_[pid] = std::move(process_metric);
|
||||
}
|
||||
|
||||
void App::ChildProcessDisconnected(base::ProcessId pid) {
|
||||
app_metrics_.erase(pid);
|
||||
}
|
||||
|
||||
base::FilePath App::GetAppPath() const {
|
||||
return app_path_;
|
||||
}
|
||||
@@ -889,32 +787,11 @@ void App::DisableHardwareAcceleration(mate::Arguments* args) {
|
||||
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
|
||||
}
|
||||
|
||||
void App::DisableDomainBlockingFor3DAPIs(mate::Arguments* args) {
|
||||
if (Browser::Get()->is_ready()) {
|
||||
args->ThrowError(
|
||||
"app.disableDomainBlockingFor3DAPIs() can only be called "
|
||||
"before app is ready");
|
||||
return;
|
||||
}
|
||||
content::GpuDataManagerImpl::GetInstance()
|
||||
->DisableDomainBlockingFor3DAPIsForTesting();
|
||||
}
|
||||
|
||||
bool App::IsAccessibilitySupportEnabled() {
|
||||
auto ax_state = content::BrowserAccessibilityState::GetInstance();
|
||||
return ax_state->IsAccessibleBrowser();
|
||||
}
|
||||
|
||||
void App::SetAccessibilitySupportEnabled(bool enabled) {
|
||||
auto ax_state = content::BrowserAccessibilityState::GetInstance();
|
||||
if (enabled) {
|
||||
ax_state->OnScreenReaderDetected();
|
||||
} else {
|
||||
ax_state->DisableAccessibility();
|
||||
}
|
||||
Browser::Get()->OnAccessibilitySupportChanged();
|
||||
}
|
||||
|
||||
Browser::LoginItemSettings App::GetLoginItemSettings(mate::Arguments* args) {
|
||||
Browser::LoginItemSettings options;
|
||||
args->GetNext(&options);
|
||||
@@ -1046,88 +923,47 @@ void App::GetFileIcon(const base::FilePath& path,
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<mate::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
|
||||
std::vector<mate::Dictionary> App::GetAppMemoryInfo(v8::Isolate* isolate) {
|
||||
AppIdProcessIterator process_iterator;
|
||||
auto process_entry = process_iterator.NextProcessEntry();
|
||||
std::vector<mate::Dictionary> result;
|
||||
int processor_count = base::SysInfo::NumberOfProcessors();
|
||||
|
||||
for (const auto& process_metric : app_metrics_) {
|
||||
while (process_entry != nullptr) {
|
||||
int64_t pid = process_entry->pid();
|
||||
auto process = base::Process::OpenWithExtraPrivileges(pid);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
base::ProcessMetrics::CreateProcessMetrics(
|
||||
process.Handle(), content::BrowserChildProcessHost::GetPortProvider()));
|
||||
#else
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
base::ProcessMetrics::CreateProcessMetrics(process.Handle()));
|
||||
#endif
|
||||
|
||||
mate::Dictionary pid_dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
mate::Dictionary memory_dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
mate::Dictionary cpu_dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
|
||||
memory_dict.Set("workingSetSize",
|
||||
static_cast<double>(
|
||||
process_metric.second->metrics->GetWorkingSetSize() >> 10));
|
||||
static_cast<double>(metrics->GetWorkingSetSize() >> 10));
|
||||
memory_dict.Set("peakWorkingSetSize",
|
||||
static_cast<double>(
|
||||
process_metric.second->metrics->GetPeakWorkingSetSize() >> 10));
|
||||
static_cast<double>(metrics->GetPeakWorkingSetSize() >> 10));
|
||||
|
||||
size_t private_bytes, shared_bytes;
|
||||
if (process_metric.second->metrics->GetMemoryBytes(&private_bytes,
|
||||
&shared_bytes)) {
|
||||
if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) {
|
||||
memory_dict.Set("privateBytes", static_cast<double>(private_bytes >> 10));
|
||||
memory_dict.Set("sharedBytes", static_cast<double>(shared_bytes >> 10));
|
||||
}
|
||||
|
||||
pid_dict.Set("memory", memory_dict);
|
||||
cpu_dict.Set("percentCPUUsage",
|
||||
process_metric.second->metrics->GetPlatformIndependentCPUUsage()
|
||||
/ processor_count);
|
||||
cpu_dict.Set("idleWakeupsPerSecond",
|
||||
process_metric.second->metrics->GetIdleWakeupsPerSecond());
|
||||
pid_dict.Set("cpu", cpu_dict);
|
||||
pid_dict.Set("pid", process_metric.second->pid);
|
||||
pid_dict.Set("type",
|
||||
content::GetProcessTypeNameInEnglish(process_metric.second->type));
|
||||
pid_dict.Set("pid", pid);
|
||||
result.push_back(pid_dict);
|
||||
process_entry = process_iterator.NextProcessEntry();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> App::GetGPUFeatureStatus(v8::Isolate* isolate) {
|
||||
auto status = content::GetFeatureStatus();
|
||||
return mate::ConvertToV8(isolate,
|
||||
status ? *status : base::DictionaryValue());
|
||||
}
|
||||
|
||||
void App::EnableMixedSandbox(mate::Arguments* args) {
|
||||
if (Browser::Get()->is_ready()) {
|
||||
args->ThrowError("app.enableMixedSandbox() can only be called "
|
||||
"before app is ready");
|
||||
return;
|
||||
}
|
||||
|
||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (command_line->HasSwitch(::switches::kNoSandbox)) {
|
||||
#if defined(OS_WIN)
|
||||
const base::CommandLine::CharType* noSandboxArg = L"--no-sandbox";
|
||||
#else
|
||||
const base::CommandLine::CharType* noSandboxArg = "--no-sandbox";
|
||||
#endif
|
||||
|
||||
// Remove the --no-sandbox switch
|
||||
base::CommandLine::StringVector modified_command_line;
|
||||
for (auto& arg : command_line->argv()) {
|
||||
if (arg.compare(noSandboxArg) != 0) {
|
||||
modified_command_line.push_back(arg);
|
||||
}
|
||||
}
|
||||
command_line->InitFromArgv(modified_command_line);
|
||||
}
|
||||
command_line->AppendSwitch(switches::kEnableMixedSandbox);
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
bool App::MoveToApplicationsFolder(mate::Arguments* args) {
|
||||
return ui::cocoa::AtomBundleMover::Move(args);
|
||||
}
|
||||
|
||||
bool App::IsInApplicationsFolder() {
|
||||
return ui::cocoa::AtomBundleMover::IsCurrentAppInApplicationsFolder();
|
||||
}
|
||||
#endif
|
||||
|
||||
// static
|
||||
mate::Handle<App> App::Create(v8::Isolate* isolate) {
|
||||
return mate::CreateHandle(isolate, new App(isolate));
|
||||
@@ -1171,10 +1007,6 @@ void App::BuildPrototype(
|
||||
base::Bind(&Browser::SetUserActivity, browser))
|
||||
.SetMethod("getCurrentActivityType",
|
||||
base::Bind(&Browser::GetCurrentActivityType, browser))
|
||||
.SetMethod("invalidateCurrentActivity",
|
||||
base::Bind(&Browser::InvalidateCurrentActivity, browser))
|
||||
.SetMethod("updateCurrentActivity",
|
||||
base::Bind(&Browser::UpdateCurrentActivity, browser))
|
||||
.SetMethod("setAboutPanelOptions",
|
||||
base::Bind(&Browser::SetAboutPanelOptions, browser))
|
||||
#endif
|
||||
@@ -1201,22 +1033,10 @@ void App::BuildPrototype(
|
||||
.SetMethod("relaunch", &App::Relaunch)
|
||||
.SetMethod("isAccessibilitySupportEnabled",
|
||||
&App::IsAccessibilitySupportEnabled)
|
||||
.SetMethod("setAccessibilitySupportEnabled",
|
||||
&App::SetAccessibilitySupportEnabled)
|
||||
.SetMethod("disableHardwareAcceleration",
|
||||
&App::DisableHardwareAcceleration)
|
||||
.SetMethod("disableDomainBlockingFor3DAPIs",
|
||||
&App::DisableDomainBlockingFor3DAPIs)
|
||||
.SetMethod("getFileIcon", &App::GetFileIcon)
|
||||
.SetMethod("getAppMetrics", &App::GetAppMetrics)
|
||||
.SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus)
|
||||
.SetMethod("enableMixedSandbox", &App::EnableMixedSandbox)
|
||||
// TODO(juturu): Remove in 2.0, deprecate before then with warnings
|
||||
#if defined(OS_MACOSX)
|
||||
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
||||
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
||||
#endif
|
||||
.SetMethod("getAppMemoryInfo", &App::GetAppMetrics);
|
||||
.SetMethod("getAppMemoryInfo", &App::GetAppMemoryInfo);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
#ifndef ATOM_BROWSER_API_ATOM_API_APP_H_
|
||||
#define ATOM_BROWSER_API_ATOM_API_APP_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
@@ -19,9 +17,7 @@
|
||||
#include "base/task/cancelable_task_tracker.h"
|
||||
#include "chrome/browser/icon_manager.h"
|
||||
#include "chrome/browser/process_singleton.h"
|
||||
#include "content/public/browser/browser_child_process_observer.h"
|
||||
#include "content/public/browser/gpu_data_manager_observer.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "net/base/completion_callback.h"
|
||||
@@ -44,27 +40,12 @@ namespace atom {
|
||||
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) {
|
||||
this->type = type;
|
||||
this->pid = pid;
|
||||
this->metrics = std::move(metrics);
|
||||
}
|
||||
};
|
||||
|
||||
namespace api {
|
||||
|
||||
class App : public AtomBrowserClient::Delegate,
|
||||
public mate::EventEmitter<App>,
|
||||
public BrowserObserver,
|
||||
public content::GpuDataManagerObserver,
|
||||
public content::BrowserChildProcessObserver {
|
||||
public content::GpuDataManagerObserver {
|
||||
public:
|
||||
using FileIconCallback = base::Callback<void(v8::Local<v8::Value>,
|
||||
const gfx::Image&)>;
|
||||
@@ -92,9 +73,6 @@ class App : public AtomBrowserClient::Delegate,
|
||||
#endif
|
||||
|
||||
base::FilePath GetAppPath() const;
|
||||
void RenderProcessReady(content::RenderProcessHost* host);
|
||||
void RenderProcessDisconnected(base::ProcessId host_pid);
|
||||
void PreMainMessageLoopRun();
|
||||
|
||||
protected:
|
||||
explicit App(v8::Isolate* isolate);
|
||||
@@ -113,26 +91,11 @@ class App : public AtomBrowserClient::Delegate,
|
||||
void OnLogin(LoginHandler* login_handler,
|
||||
const base::DictionaryValue& request_details) override;
|
||||
void OnAccessibilitySupportChanged() override;
|
||||
void OnPreMainMessageLoopRun() override;
|
||||
#if defined(OS_MACOSX)
|
||||
void OnWillContinueUserActivity(
|
||||
bool* prevent_default,
|
||||
const std::string& type) override;
|
||||
void OnDidFailToContinueUserActivity(
|
||||
const std::string& type,
|
||||
const std::string& error) override;
|
||||
void OnContinueUserActivity(
|
||||
bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) override;
|
||||
void OnUserActivityWasContinued(
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) override;
|
||||
void OnUpdateUserActivityState(
|
||||
bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) override;
|
||||
void OnNewWindowForTab() override;
|
||||
#endif
|
||||
|
||||
// content::ContentBrowserClient:
|
||||
@@ -155,20 +118,8 @@ class App : public AtomBrowserClient::Delegate,
|
||||
// content::GpuDataManagerObserver:
|
||||
void OnGpuProcessCrashed(base::TerminationStatus status) override;
|
||||
|
||||
// content::BrowserChildProcessObserver:
|
||||
void BrowserChildProcessLaunchedAndConnected(
|
||||
const content::ChildProcessData& data) override;
|
||||
void BrowserChildProcessHostDisconnected(
|
||||
const content::ChildProcessData& data) override;
|
||||
void BrowserChildProcessCrashed(
|
||||
const content::ChildProcessData& data, int exit_code) override;
|
||||
void BrowserChildProcessKilled(
|
||||
const content::ChildProcessData& data, int exit_code) override;
|
||||
|
||||
private:
|
||||
void SetAppPath(const base::FilePath& app_path);
|
||||
void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
|
||||
void ChildProcessDisconnected(base::ProcessId pid);
|
||||
|
||||
// Get/Set the pre-defined path in PathService.
|
||||
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
|
||||
@@ -183,9 +134,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||
void ReleaseSingleInstance();
|
||||
bool Relaunch(mate::Arguments* args);
|
||||
void DisableHardwareAcceleration(mate::Arguments* args);
|
||||
void DisableDomainBlockingFor3DAPIs(mate::Arguments* args);
|
||||
bool IsAccessibilitySupportEnabled();
|
||||
void SetAccessibilitySupportEnabled(bool enabled);
|
||||
Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
|
||||
#if defined(USE_NSS_CERTS)
|
||||
void ImportCertificate(const base::DictionaryValue& options,
|
||||
@@ -194,14 +143,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||
void GetFileIcon(const base::FilePath& path,
|
||||
mate::Arguments* args);
|
||||
|
||||
std::vector<mate::Dictionary> GetAppMetrics(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
|
||||
void EnableMixedSandbox(mate::Arguments* args);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
bool MoveToApplicationsFolder(mate::Arguments* args);
|
||||
bool IsInApplicationsFolder();
|
||||
#endif
|
||||
std::vector<mate::Dictionary> GetAppMemoryInfo(v8::Isolate* isolate);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Get the current Jump List settings.
|
||||
@@ -222,11 +164,6 @@ class App : public AtomBrowserClient::Delegate,
|
||||
|
||||
base::FilePath app_path_;
|
||||
|
||||
using ProcessMetricMap =
|
||||
std::unordered_map<base::ProcessId,
|
||||
std::unique_ptr<atom::ProcessMetric>>;
|
||||
ProcessMetricMap app_metrics_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(App);
|
||||
};
|
||||
|
||||
|
||||
@@ -57,23 +57,6 @@ void AutoUpdater::OnError(const std::string& message) {
|
||||
message);
|
||||
}
|
||||
|
||||
void AutoUpdater::OnError(const std::string& message,
|
||||
const int code, const std::string& domain) {
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
|
||||
auto errorObject = error->ToObject(
|
||||
isolate()->GetCurrentContext()).ToLocalChecked();
|
||||
|
||||
// add two new params for better error handling
|
||||
errorObject->Set(mate::StringToV8(isolate(), "code"),
|
||||
v8::Integer::New(isolate(), code));
|
||||
errorObject->Set(mate::StringToV8(isolate(), "domain"),
|
||||
mate::StringToV8(isolate(), domain));
|
||||
|
||||
mate::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
|
||||
}
|
||||
|
||||
void AutoUpdater::OnCheckingForUpdate() {
|
||||
Emit("checking-for-update");
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
|
||||
|
||||
// Delegate implementations.
|
||||
void OnError(const std::string& error) override;
|
||||
void OnError(const std::string& message, const int code,
|
||||
const std::string& domain);
|
||||
void OnCheckingForUpdate() override;
|
||||
void OnUpdateAvailable() override;
|
||||
void OnUpdateNotAvailable() override;
|
||||
|
||||
@@ -152,8 +152,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
mate::Dictionary browser_view(
|
||||
isolate, BrowserView::GetConstructor(isolate)->GetFunction());
|
||||
browser_view.SetMethod("fromId",
|
||||
&mate::TrackableObject<BrowserView>::FromWeakMapID);
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("BrowserView", browser_view);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ class BrowserView : public mate::TrackableObject<BrowserView> {
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
WebContents* web_contents() const { return api_web_contents_; }
|
||||
NativeBrowserView* view() const { return view_.get(); }
|
||||
|
||||
int32_t ID() const;
|
||||
|
||||
@@ -62,10 +62,6 @@ struct Converter<net::CookieStore::ChangeCause> {
|
||||
switch (val) {
|
||||
case net::CookieStore::ChangeCause::INSERTED:
|
||||
case net::CookieStore::ChangeCause::EXPLICIT:
|
||||
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_BETWEEN:
|
||||
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_PREDICATE:
|
||||
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_SINGLE:
|
||||
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_CANONICAL:
|
||||
return mate::StringToV8(isolate, "explicit");
|
||||
case net::CookieStore::ChangeCause::OVERWRITE:
|
||||
return mate::StringToV8(isolate, "overwrite");
|
||||
@@ -232,8 +228,8 @@ void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
GetCookieStore(getter)->SetCookieWithDetailsAsync(
|
||||
GURL(url), name, value, domain, path, creation_time,
|
||||
expiration_time, last_access_time, secure, http_only,
|
||||
net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT,
|
||||
base::Bind(OnSetCookie, callback));
|
||||
net::CookieSameSite::DEFAULT_MODE, false,
|
||||
net::COOKIE_PRIORITY_DEFAULT, base::Bind(OnSetCookie, callback));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "atom/browser/api/atom_api_desktop_capturer.h"
|
||||
|
||||
using base::PlatformThreadRef;
|
||||
|
||||
#include "atom/common/api/atom_api_native_image.h"
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/atom_api_notification.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_menu.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/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/browser_client.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace mate {
|
||||
template<>
|
||||
struct Converter<brightray::NotificationAction> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
brightray::NotificationAction* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
||||
if (!dict.Get("type", &(out->type))) {
|
||||
return false;
|
||||
}
|
||||
dict.Get("text", &(out->text));
|
||||
return true;
|
||||
}
|
||||
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
brightray::NotificationAction val) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("text", val.text);
|
||||
dict.Set("type", val.type);
|
||||
return dict.GetHandle();
|
||||
}
|
||||
};
|
||||
} // namespace mate
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
Notification::Notification(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> wrapper,
|
||||
mate::Arguments* args) {
|
||||
InitWith(isolate, wrapper);
|
||||
|
||||
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
|
||||
|
||||
mate::Dictionary opts;
|
||||
if (args->GetNext(&opts)) {
|
||||
opts.Get("title", &title_);
|
||||
opts.Get("subtitle", &subtitle_);
|
||||
opts.Get("body", &body_);
|
||||
has_icon_ = opts.Get("icon", &icon_);
|
||||
if (has_icon_) {
|
||||
opts.Get("icon", &icon_path_);
|
||||
}
|
||||
opts.Get("silent", &silent_);
|
||||
opts.Get("replyPlaceholder", &reply_placeholder_);
|
||||
opts.Get("hasReply", &has_reply_);
|
||||
opts.Get("actions", &actions_);
|
||||
opts.Get("sound", &sound_);
|
||||
}
|
||||
}
|
||||
|
||||
Notification::~Notification() {
|
||||
if (notification_)
|
||||
notification_->set_delegate(nullptr);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::WrappableBase* Notification::New(mate::Arguments* args) {
|
||||
if (!Browser::Get()->is_ready()) {
|
||||
args->ThrowError("Cannot create Notification before app is ready");
|
||||
return nullptr;
|
||||
}
|
||||
return new Notification(args->isolate(), args->GetThis(), args);
|
||||
}
|
||||
|
||||
// Getters
|
||||
base::string16 Notification::GetTitle() const {
|
||||
return title_;
|
||||
}
|
||||
|
||||
base::string16 Notification::GetSubtitle() const {
|
||||
return subtitle_;
|
||||
}
|
||||
|
||||
base::string16 Notification::GetBody() const {
|
||||
return body_;
|
||||
}
|
||||
|
||||
bool Notification::GetSilent() const {
|
||||
return silent_;
|
||||
}
|
||||
|
||||
base::string16 Notification::GetReplyPlaceholder() const {
|
||||
return reply_placeholder_;
|
||||
}
|
||||
|
||||
bool Notification::GetHasReply() const {
|
||||
return has_reply_;
|
||||
}
|
||||
|
||||
std::vector<brightray::NotificationAction> Notification::GetActions() const {
|
||||
return actions_;
|
||||
}
|
||||
|
||||
base::string16 Notification::GetSound() const {
|
||||
return sound_;
|
||||
}
|
||||
|
||||
// Setters
|
||||
void Notification::SetTitle(const base::string16& new_title) {
|
||||
title_ = new_title;
|
||||
}
|
||||
|
||||
void Notification::SetSubtitle(const base::string16& new_subtitle) {
|
||||
subtitle_ = new_subtitle;
|
||||
}
|
||||
|
||||
void Notification::SetBody(const base::string16& new_body) {
|
||||
body_ = new_body;
|
||||
}
|
||||
|
||||
void Notification::SetSilent(bool new_silent) {
|
||||
silent_ = new_silent;
|
||||
}
|
||||
|
||||
void Notification::SetReplyPlaceholder(const base::string16& new_placeholder) {
|
||||
reply_placeholder_ = new_placeholder;
|
||||
}
|
||||
|
||||
void Notification::SetHasReply(bool new_has_reply) {
|
||||
has_reply_ = new_has_reply;
|
||||
}
|
||||
|
||||
void Notification::SetActions(
|
||||
const std::vector<brightray::NotificationAction>& actions) {
|
||||
actions_ = actions;
|
||||
}
|
||||
|
||||
void Notification::SetSound(const base::string16& new_sound) {
|
||||
sound_ = new_sound;
|
||||
}
|
||||
|
||||
void Notification::NotificationAction(int index) {
|
||||
Emit("action", index);
|
||||
}
|
||||
|
||||
void Notification::NotificationClick() {
|
||||
Emit("click");
|
||||
}
|
||||
|
||||
void Notification::NotificationReplied(const std::string& reply) {
|
||||
Emit("reply", reply);
|
||||
}
|
||||
|
||||
void Notification::NotificationDisplayed() {
|
||||
Emit("show");
|
||||
}
|
||||
|
||||
void Notification::NotificationDestroyed() {
|
||||
Emit("close");
|
||||
}
|
||||
|
||||
void Notification::NotificationClosed() {
|
||||
}
|
||||
|
||||
// Showing notifications
|
||||
void Notification::Show() {
|
||||
if (presenter_) {
|
||||
notification_ = presenter_->CreateNotification(this);
|
||||
if (notification_) {
|
||||
brightray::NotificationOptions options;
|
||||
options.title = title_;
|
||||
options.subtitle = subtitle_;
|
||||
options.msg = body_;
|
||||
options.icon_url = GURL();
|
||||
options.icon = icon_.AsBitmap();
|
||||
options.silent = silent_;
|
||||
options.has_reply = has_reply_;
|
||||
options.reply_placeholder = reply_placeholder_;
|
||||
options.actions = actions_;
|
||||
options.sound = sound_;
|
||||
notification_->Show(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Notification::IsSupported() {
|
||||
return !!brightray::BrowserClient::Get()->GetNotificationPresenter();
|
||||
}
|
||||
|
||||
// static
|
||||
void Notification::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "Notification"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.MakeDestroyable()
|
||||
.SetMethod("show", &Notification::Show)
|
||||
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
|
||||
.SetProperty("subtitle", &Notification::GetSubtitle,
|
||||
&Notification::SetSubtitle)
|
||||
.SetProperty("body", &Notification::GetBody, &Notification::SetBody)
|
||||
.SetProperty("silent", &Notification::GetSilent, &Notification::SetSilent)
|
||||
.SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder,
|
||||
&Notification::SetReplyPlaceholder)
|
||||
.SetProperty("hasReply", &Notification::GetHasReply,
|
||||
&Notification::SetHasReply)
|
||||
.SetProperty("actions", &Notification::GetActions,
|
||||
&Notification::SetActions)
|
||||
.SetProperty("sound", &Notification::GetSound,
|
||||
&Notification::SetSound);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
||||
namespace {
|
||||
|
||||
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::Bind(&Notification::New));
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
dict.Set("Notification",
|
||||
Notification::GetConstructor(isolate)->GetFunction());
|
||||
|
||||
dict.SetMethod("isSupported", &Notification::IsSupported);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_notification, Initialize)
|
||||
@@ -1,93 +0,0 @@
|
||||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_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 "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/notification.h"
|
||||
#include "brightray/browser/notification_delegate.h"
|
||||
#include "brightray/browser/notification_presenter.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
class Notification : public mate::TrackableObject<Notification>,
|
||||
public brightray::NotificationDelegate {
|
||||
public:
|
||||
static mate::WrappableBase* New(mate::Arguments* args);
|
||||
static bool IsSupported();
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
// NotificationDelegate:
|
||||
void NotificationAction(int index) override;
|
||||
void NotificationClick() override;
|
||||
void NotificationReplied(const std::string& reply) override;
|
||||
void NotificationDisplayed() override;
|
||||
void NotificationDestroyed() override;
|
||||
void NotificationClosed() override;
|
||||
|
||||
protected:
|
||||
Notification(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> wrapper,
|
||||
mate::Arguments* args);
|
||||
~Notification() override;
|
||||
|
||||
void Show();
|
||||
|
||||
// Prop Getters
|
||||
base::string16 GetTitle() const;
|
||||
base::string16 GetSubtitle() const;
|
||||
base::string16 GetBody() const;
|
||||
bool GetSilent() const;
|
||||
base::string16 GetReplyPlaceholder() const;
|
||||
bool GetHasReply() const;
|
||||
std::vector<brightray::NotificationAction> GetActions() const;
|
||||
base::string16 GetSound() const;
|
||||
|
||||
// Prop Setters
|
||||
void SetTitle(const base::string16& new_title);
|
||||
void SetSubtitle(const base::string16& new_subtitle);
|
||||
void SetBody(const base::string16& new_body);
|
||||
void SetSilent(bool new_silent);
|
||||
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
|
||||
void SetHasReply(bool new_has_reply);
|
||||
void SetActions(const std::vector<brightray::NotificationAction>& actions);
|
||||
void SetSound(const base::string16& sound);
|
||||
|
||||
private:
|
||||
base::string16 title_;
|
||||
base::string16 subtitle_;
|
||||
base::string16 body_;
|
||||
gfx::Image icon_;
|
||||
base::string16 icon_path_;
|
||||
bool has_icon_ = false;
|
||||
bool silent_ = false;
|
||||
base::string16 reply_placeholder_;
|
||||
bool has_reply_ = false;
|
||||
std::vector<brightray::NotificationAction> actions_;
|
||||
base::string16 sound_;
|
||||
|
||||
brightray::NotificationPresenter* presenter_;
|
||||
|
||||
base::WeakPtr<brightray::Notification> notification_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Notification);
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_API_ATOM_API_NOTIFICATION_H_
|
||||
@@ -50,25 +50,20 @@ void RegisterStandardSchemes(const std::vector<std::string>& schemes,
|
||||
mate::Arguments* args) {
|
||||
g_standard_schemes = schemes;
|
||||
|
||||
mate::Dictionary opts;
|
||||
bool secure = false;
|
||||
args->GetNext(&opts) && opts.Get("secure", &secure);
|
||||
|
||||
// Dynamically register the schemes.
|
||||
auto* policy = content::ChildProcessSecurityPolicy::GetInstance();
|
||||
for (const std::string& scheme : schemes) {
|
||||
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
|
||||
if (secure) {
|
||||
url::AddSecureScheme(scheme.c_str());
|
||||
}
|
||||
policy->RegisterWebSafeScheme(scheme);
|
||||
}
|
||||
|
||||
// Add the schemes to command line switches, so child processes can also
|
||||
// register them.
|
||||
// add switches to register as standard
|
||||
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
||||
atom::switches::kStandardSchemes, base::JoinString(schemes, ","));
|
||||
if (secure) {
|
||||
|
||||
mate::Dictionary opts;
|
||||
bool secure = false;
|
||||
if (args->GetNext(&opts) && opts.Get("secure", &secure) && secure) {
|
||||
// add switches to register as secure
|
||||
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
||||
atom::switches::kSecureSchemes, base::JoinString(schemes, ","));
|
||||
}
|
||||
|
||||
@@ -120,9 +120,6 @@ void Screen::BuildPrototype(
|
||||
.SetMethod("getPrimaryDisplay", &Screen::GetPrimaryDisplay)
|
||||
.SetMethod("getAllDisplays", &Screen::GetAllDisplays)
|
||||
.SetMethod("getDisplayNearestPoint", &Screen::GetDisplayNearestPoint)
|
||||
#if defined(OS_MACOSX)
|
||||
.SetMethod("getMenuBarHeight", &Screen::getMenuBarHeight)
|
||||
#endif
|
||||
.SetMethod("getDisplayMatching", &Screen::GetDisplayMatching);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +40,6 @@ class Screen : public mate::EventEmitter<Screen>,
|
||||
display::Display GetDisplayNearestPoint(const gfx::Point& point);
|
||||
display::Display GetDisplayMatching(const gfx::Rect& match_rect);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
int getMenuBarHeight();
|
||||
#endif
|
||||
|
||||
// display::DisplayObserver:
|
||||
void OnDisplayAdded(const display::Display& new_display) override;
|
||||
void OnDisplayRemoved(const display::Display& old_display) override;
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// 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 "atom/browser/api/atom_api_screen.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
int Screen::getMenuBarHeight() {
|
||||
return [[NSApp mainMenu] menuBarHeight];
|
||||
}
|
||||
|
||||
}// namespace api
|
||||
|
||||
}// namespace atom
|
||||
@@ -212,7 +212,6 @@ struct Converter<atom::VerifyRequestParams> {
|
||||
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();
|
||||
}
|
||||
};
|
||||
@@ -433,9 +432,7 @@ void DownloadIdCallback(content::DownloadManager* download_manager,
|
||||
last_modified, offset, length, std::string(),
|
||||
content::DownloadItem::INTERRUPTED,
|
||||
content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
|
||||
content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, false,
|
||||
base::Time(), false,
|
||||
std::vector<content::DownloadItem::ReceivedSlice>());
|
||||
content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, false);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -67,7 +67,6 @@ void SystemPreferences::BuildPrototype(
|
||||
&SystemPreferences::UnsubscribeLocalNotification)
|
||||
.SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
|
||||
.SetMethod("setUserDefault", &SystemPreferences::SetUserDefault)
|
||||
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
||||
.SetMethod("isSwipeTrackingFromScrollEventsEnabled",
|
||||
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
|
||||
#endif
|
||||
|
||||
@@ -76,7 +76,6 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||
void SetUserDefault(const std::string& name,
|
||||
const std::string& type,
|
||||
mate::Arguments* args);
|
||||
void RemoveUserDefault(const std::string& name);
|
||||
bool IsSwipeTrackingFromScrollEventsEnabled();
|
||||
#endif
|
||||
bool IsDarkMode();
|
||||
|
||||
@@ -229,11 +229,6 @@ void SystemPreferences::SetUserDefault(const std::string& name,
|
||||
}
|
||||
}
|
||||
|
||||
void SystemPreferences::RemoveUserDefault(const std::string& name) {
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults removeObjectForKey:base::SysUTF8ToNSString(name)];
|
||||
}
|
||||
|
||||
bool SystemPreferences::IsDarkMode() {
|
||||
NSString* mode = [[NSUserDefaults standardUserDefaults]
|
||||
stringForKey:@"AppleInterfaceStyle"];
|
||||
|
||||
@@ -86,10 +86,8 @@ mate::WrappableBase* Tray::New(mate::Handle<NativeImage> image,
|
||||
return new Tray(args->isolate(), args->GetThis(), image);
|
||||
}
|
||||
|
||||
void Tray::OnClicked(const gfx::Rect& bounds,
|
||||
const gfx::Point& location,
|
||||
int modifiers) {
|
||||
EmitWithFlags("click", modifiers, bounds, location);
|
||||
void Tray::OnClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
EmitWithFlags("click", modifiers, bounds);
|
||||
}
|
||||
|
||||
void Tray::OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
@@ -124,18 +122,6 @@ void Tray::OnDropText(const std::string& text) {
|
||||
Emit("drop-text", text);
|
||||
}
|
||||
|
||||
void Tray::OnMouseEntered(const gfx::Point& location, int modifiers) {
|
||||
EmitWithFlags("mouse-enter", modifiers, location);
|
||||
}
|
||||
|
||||
void Tray::OnMouseExited(const gfx::Point& location, int modifiers) {
|
||||
EmitWithFlags("mouse-leave", modifiers, location);
|
||||
}
|
||||
|
||||
void Tray::OnMouseMoved(const gfx::Point& location, int modifiers) {
|
||||
EmitWithFlags("mouse-move", modifiers, location);
|
||||
}
|
||||
|
||||
void Tray::OnDragEntered() {
|
||||
Emit("drag-enter");
|
||||
}
|
||||
|
||||
@@ -47,9 +47,7 @@ class Tray : public mate::TrackableObject<Tray>,
|
||||
~Tray() override;
|
||||
|
||||
// TrayIconObserver:
|
||||
void OnClicked(const gfx::Rect& bounds,
|
||||
const gfx::Point& location,
|
||||
int modifiers) override;
|
||||
void OnClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnBalloonShow() override;
|
||||
@@ -61,9 +59,6 @@ class Tray : public mate::TrackableObject<Tray>,
|
||||
void OnDragEntered() override;
|
||||
void OnDragExited() override;
|
||||
void OnDragEnded() override;
|
||||
void OnMouseEntered(const gfx::Point& location, int modifiers) override;
|
||||
void OnMouseExited(const gfx::Point& location, int modifiers) override;
|
||||
void OnMouseMoved(const gfx::Point& location, int modifiers) override;
|
||||
|
||||
void SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
||||
void SetPressedImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
||||
|
||||
@@ -13,16 +13,12 @@
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||
#include "atom/browser/child_web_contents_tracker.h"
|
||||
#include "atom/browser/lib/bluetooth_chooser.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/net/atom_network_delegate.h"
|
||||
#if defined(ENABLE_OSR)
|
||||
#include "atom/browser/osr/osr_output_device.h"
|
||||
#include "atom/browser/osr/osr_render_widget_host_view.h"
|
||||
#include "atom/browser/osr/osr_web_contents_view.h"
|
||||
#endif
|
||||
#include "atom/browser/ui/drag_util.h"
|
||||
#include "atom/browser/web_contents_permission_helper.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
@@ -43,25 +39,25 @@
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/process/process_handle.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "base/values.h"
|
||||
#include "brightray/browser/inspectable_web_contents.h"
|
||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||
#include "chrome/browser/printing/print_preview_message_handler.h"
|
||||
#include "chrome/browser/printing/print_view_manager_basic.h"
|
||||
#include "chrome/browser/ssl/security_state_tab_helper.h"
|
||||
#include "content/browser/frame_host/navigation_entry_impl.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_view_base.h"
|
||||
#include "content/browser/web_contents/web_contents_impl.h"
|
||||
#include "content/common/view_messages.h"
|
||||
#include "content/public/browser/child_process_security_policy.h"
|
||||
#include "content/public/browser/favicon_status.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "content/public/browser/navigation_details.h"
|
||||
#include "content/public/browser/navigation_entry.h"
|
||||
#include "content/public/browser/navigation_handle.h"
|
||||
#include "content/public/browser/notification_details.h"
|
||||
#include "content/public/browser/notification_source.h"
|
||||
#include "content/public/browser/notification_types.h"
|
||||
#include "content/public/browser/plugin_service.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
@@ -74,15 +70,12 @@
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/context_menu_params.h"
|
||||
#include "native_mate/converter.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "third_party/WebKit/public/platform/WebInputEvent.h"
|
||||
#include "third_party/WebKit/public/web/WebFindOptions.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/events/base_event_utils.h"
|
||||
#include "ui/latency/latency_info.h"
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
#include "ui/aura/window.h"
|
||||
@@ -95,7 +88,6 @@ namespace {
|
||||
struct PrintSettings {
|
||||
bool silent;
|
||||
bool print_background;
|
||||
base::string16 device_name;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -133,25 +125,10 @@ struct Converter<PrintSettings> {
|
||||
return false;
|
||||
dict.Get("silent", &(out->silent));
|
||||
dict.Get("printBackground", &(out->print_background));
|
||||
dict.Get("deviceName", &(out->device_name));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<printing::PrinterBasicInfo> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const printing::PrinterBasicInfo& val) {
|
||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||
dict.Set("name", val.printer_name);
|
||||
dict.Set("description", val.printer_description);
|
||||
dict.Set("status", val.printer_status);
|
||||
dict.Set("isDefault", val.is_default ? true : false);
|
||||
dict.Set("options", val.options);
|
||||
return dict.GetHandle();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<WindowOpenDisposition> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
@@ -232,10 +209,8 @@ struct Converter<atom::api::WebContents::Type> {
|
||||
*out = Type::BROWSER_VIEW;
|
||||
} else if (type == "webview") {
|
||||
*out = Type::WEB_VIEW;
|
||||
#if defined(ENABLE_OSR)
|
||||
} else if (type == "offscreen") {
|
||||
*out = Type::OFF_SCREEN;
|
||||
#endif
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -274,6 +249,22 @@ void OnCapturePageDone(const base::Callback<void(const gfx::Image&)>& callback,
|
||||
callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||
}
|
||||
|
||||
// Set the background color of RenderWidgetHostView.
|
||||
void SetBackgroundColor(content::WebContents* web_contents) {
|
||||
const auto view = web_contents->GetRenderWidgetHostView();
|
||||
if (view) {
|
||||
WebContentsPreferences* web_preferences =
|
||||
WebContentsPreferences::FromWebContents(web_contents);
|
||||
std::string color_name;
|
||||
if (web_preferences->web_preferences()->GetString(options::kBackgroundColor,
|
||||
&color_name)) {
|
||||
view->SetBackgroundColor(ParseHexColor(color_name));
|
||||
} else {
|
||||
view->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
WebContents::WebContents(v8::Isolate* isolate,
|
||||
@@ -305,10 +296,6 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
|
||||
request_id_(0),
|
||||
background_throttling_(true),
|
||||
enable_devtools_(true) {
|
||||
// WebContents may need to emit events when it is garbage collected, so it
|
||||
// has to be deleted in the first gc callback.
|
||||
MarkHighMemoryUsage();
|
||||
|
||||
// Read options.
|
||||
options.Get("backgroundThrottling", &background_throttling_);
|
||||
|
||||
@@ -324,13 +311,8 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
|
||||
type_ = BACKGROUND_PAGE;
|
||||
else if (options.Get("isBrowserView", &b) && b)
|
||||
type_ = BROWSER_VIEW;
|
||||
#if defined(ENABLE_OSR)
|
||||
else if (options.Get("offscreen", &b) && b)
|
||||
type_ = OFF_SCREEN;
|
||||
#endif
|
||||
|
||||
// Init embedder earlier
|
||||
options.Get("embedder", &embedder_);
|
||||
|
||||
// Whether to enable DevTools.
|
||||
options.Get("devTools", &enable_devtools_);
|
||||
@@ -356,21 +338,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
|
||||
session->browser_context(), site_instance);
|
||||
guest_delegate_.reset(new WebViewGuestDelegate);
|
||||
params.guest_delegate = guest_delegate_.get();
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
if (embedder_ && embedder_->IsOffScreen()) {
|
||||
auto* view = new OffScreenWebContentsView(false,
|
||||
base::Bind(&WebContents::OnPaint, base::Unretained(this)));
|
||||
params.view = view;
|
||||
params.delegate_view = view;
|
||||
|
||||
web_contents = content::WebContents::Create(params);
|
||||
view->SetWebContents(web_contents);
|
||||
} else {
|
||||
#endif
|
||||
web_contents = content::WebContents::Create(params);
|
||||
#if defined(ENABLE_OSR)
|
||||
}
|
||||
web_contents = content::WebContents::Create(params);
|
||||
} else if (IsOffScreen()) {
|
||||
bool transparent = false;
|
||||
options.Get("transparent", &transparent);
|
||||
@@ -383,7 +351,6 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
|
||||
|
||||
web_contents = content::WebContents::Create(params);
|
||||
view->SetWebContents(web_contents);
|
||||
#endif
|
||||
} else {
|
||||
content::WebContents::CreateParams params(session->browser_context());
|
||||
web_contents = content::WebContents::Create(params);
|
||||
@@ -396,7 +363,7 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||
content::WebContents *web_contents,
|
||||
mate::Handle<api::Session> session,
|
||||
const mate::Dictionary& options) {
|
||||
Observe(web_contents);
|
||||
content::WebContentsObserver::Observe(web_contents);
|
||||
InitWithWebContents(web_contents, session->browser_context());
|
||||
|
||||
managed_web_contents()->GetView()->SetDelegate(this);
|
||||
@@ -421,7 +388,7 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||
guest_delegate_->Initialize(this);
|
||||
|
||||
NativeWindow* owner_window = nullptr;
|
||||
if (embedder_) {
|
||||
if (options.Get("embedder", &embedder_) && embedder_) {
|
||||
// New WebContents's owner_window is the embedder's owner_window.
|
||||
auto relay =
|
||||
NativeWindowRelay::FromWebContents(embedder_->web_contents());
|
||||
@@ -432,6 +399,11 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||
SetOwnerWindow(owner_window);
|
||||
}
|
||||
|
||||
const content::NavigationController* controller =
|
||||
&web_contents->GetController();
|
||||
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
|
||||
content::Source<content::NavigationController>(controller));
|
||||
|
||||
Init(isolate);
|
||||
AttachAsUserData(web_contents);
|
||||
}
|
||||
@@ -512,7 +484,6 @@ void WebContents::AddNewContents(content::WebContents* source,
|
||||
const gfx::Rect& initial_rect,
|
||||
bool user_gesture,
|
||||
bool* was_blocked) {
|
||||
new ChildWebContentsTracker(new_contents);
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
auto api_web_contents = CreateFrom(isolate(), new_contents);
|
||||
@@ -592,18 +563,15 @@ void WebContents::HandleKeyboardEvent(
|
||||
}
|
||||
}
|
||||
|
||||
content::KeyboardEventProcessingResult WebContents::PreHandleKeyboardEvent(
|
||||
bool WebContents::PreHandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown ||
|
||||
event.GetType() == blink::WebInputEvent::Type::kKeyUp) {
|
||||
bool prevent_default = Emit("before-input-event", event);
|
||||
if (prevent_default) {
|
||||
return content::KeyboardEventProcessingResult::HANDLED;
|
||||
}
|
||||
}
|
||||
|
||||
return content::KeyboardEventProcessingResult::NOT_HANDLED;
|
||||
const content::NativeWebKeyboardEvent& event,
|
||||
bool* is_keyboard_shortcut) {
|
||||
if (event.type == blink::WebInputEvent::Type::RawKeyDown
|
||||
|| event.type == blink::WebInputEvent::Type::KeyUp)
|
||||
return Emit("before-input-event", event);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebContents::EnterFullscreenModeForTab(content::WebContents* source,
|
||||
@@ -712,15 +680,6 @@ std::unique_ptr<content::BluetoothChooser> WebContents::RunBluetoothChooser(
|
||||
return std::move(bluetooth_chooser);
|
||||
}
|
||||
|
||||
content::JavaScriptDialogManager*
|
||||
WebContents::GetJavaScriptDialogManager(
|
||||
content::WebContents* source) {
|
||||
if (!dialog_manager_)
|
||||
dialog_manager_.reset(new AtomJavaScriptDialogManager(this));
|
||||
|
||||
return dialog_manager_.get();
|
||||
}
|
||||
|
||||
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
||||
// Do nothing, we override this method just to avoid compilation error since
|
||||
// there are two virtual functions named BeforeUnloadFired.
|
||||
@@ -761,11 +720,7 @@ void WebContents::MediaStoppedPlaying(const MediaPlayerInfo& video_type,
|
||||
}
|
||||
|
||||
void WebContents::DidChangeThemeColor(SkColor theme_color) {
|
||||
if (theme_color != SK_ColorTRANSPARENT) {
|
||||
Emit("did-change-theme-color", atom::ToRGBHex(theme_color));
|
||||
} else {
|
||||
Emit("did-change-theme-color", nullptr);
|
||||
}
|
||||
Emit("did-change-theme-color", atom::ToRGBHex(theme_color));
|
||||
}
|
||||
|
||||
void WebContents::DocumentLoadedInFrame(
|
||||
@@ -825,12 +780,36 @@ void WebContents::DidGetRedirectForResourceRequest(
|
||||
details.headers.get());
|
||||
}
|
||||
|
||||
void WebContents::DidStartNavigation(
|
||||
content::NavigationHandle* navigation_handle) {
|
||||
if (!navigation_handle->IsInMainFrame() || navigation_handle->IsSamePage())
|
||||
return;
|
||||
|
||||
if (deferred_load_url_.id) {
|
||||
auto web_contents = navigation_handle->GetWebContents();
|
||||
auto& controller = web_contents->GetController();
|
||||
int id = controller.GetPendingEntry()->GetUniqueID();
|
||||
if (id == deferred_load_url_.id) {
|
||||
if (!deferred_load_url_.params.url.is_empty()) {
|
||||
auto params = deferred_load_url_.params;
|
||||
deferred_load_url_.id = 0;
|
||||
deferred_load_url_.params =
|
||||
content::NavigationController::LoadURLParams(GURL());
|
||||
controller.LoadURLWithParams(params);
|
||||
SetBackgroundColor(web_contents);
|
||||
} else {
|
||||
deferred_load_url_.id = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::DidFinishNavigation(
|
||||
content::NavigationHandle* navigation_handle) {
|
||||
bool is_main_frame = navigation_handle->IsInMainFrame();
|
||||
if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
|
||||
auto url = navigation_handle->GetURL();
|
||||
bool is_in_page = navigation_handle->IsSameDocument();
|
||||
bool is_in_page = navigation_handle->IsSamePage();
|
||||
if (is_main_frame && !is_in_page) {
|
||||
Emit("did-navigate", url);
|
||||
} else if (is_in_page) {
|
||||
@@ -867,6 +846,41 @@ void WebContents::DidUpdateFaviconURL(
|
||||
Emit("page-favicon-updated", unique_urls);
|
||||
}
|
||||
|
||||
void WebContents::Observe(int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) {
|
||||
switch (type) {
|
||||
case content::NOTIFICATION_NAV_ENTRY_PENDING: {
|
||||
content::NavigationEntry* entry =
|
||||
content::Details<content::NavigationEntry>(details).ptr();
|
||||
content::NavigationEntryImpl* entry_impl =
|
||||
static_cast<content::NavigationEntryImpl*>(entry);
|
||||
// In NavigatorImpl::DidStartMainFrameNavigation when there is no
|
||||
// browser side pending entry available it creates a new one based
|
||||
// on existing pending entry, hence we track the unique id here
|
||||
// instead in WebContents::LoadURL with controller.GetPendingEntry()
|
||||
// TODO(deepak1556): Remove once we have
|
||||
// https://codereview.chromium.org/2661743002.
|
||||
if (entry_impl->frame_tree_node_id() == -1) {
|
||||
deferred_load_url_.id = entry->GetUniqueID();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
NOTREACHED();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::BeforeUnloadDialogCancelled() {
|
||||
if (deferred_load_url_.id) {
|
||||
auto& controller = web_contents()->GetController();
|
||||
if (!controller.GetPendingEntry()) {
|
||||
deferred_load_url_.id = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::DevToolsReloadPage() {
|
||||
Emit("devtools-reload-page");
|
||||
}
|
||||
@@ -883,7 +897,7 @@ void WebContents::DevToolsOpened() {
|
||||
devtools_web_contents_.Reset(isolate(), handle.ToV8());
|
||||
|
||||
// Set inspected tabID.
|
||||
base::Value tab_id(ID());
|
||||
base::FundamentalValue tab_id(ID());
|
||||
managed_web_contents()->CallClientFunction(
|
||||
"DevToolsAPI.setInspectedTabId", &tab_id, nullptr, nullptr);
|
||||
|
||||
@@ -921,23 +935,6 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool WebContents::OnMessageReceived(const IPC::Message& message,
|
||||
content::RenderFrameHost* frame_host) {
|
||||
bool handled = true;
|
||||
auto relay = NativeWindowRelay::FromWebContents(web_contents());
|
||||
if (!relay)
|
||||
return false;
|
||||
IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(NativeWindow, message, frame_host)
|
||||
IPC_MESSAGE_FORWARD(AtomAutofillFrameHostMsg_ShowPopup,
|
||||
relay->window.get(), NativeWindow::ShowAutofillPopup)
|
||||
IPC_MESSAGE_FORWARD(AtomAutofillFrameHostMsg_HidePopup,
|
||||
relay->window.get(), NativeWindow::HideAutofillPopup)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
// There are three ways of destroying a webContents:
|
||||
// 1. call webContents.destroy();
|
||||
// 2. garbage collection;
|
||||
@@ -973,7 +970,7 @@ void WebContents::NavigationEntryCommitted(
|
||||
|
||||
int64_t WebContents::GetID() const {
|
||||
int64_t process_id = web_contents()->GetRenderProcessHost()->GetID();
|
||||
int64_t routing_id = web_contents()->GetRenderViewHost()->GetRoutingID();
|
||||
int64_t routing_id = web_contents()->GetRoutingID();
|
||||
int64_t rv = (process_id << 32) + routing_id;
|
||||
return rv;
|
||||
}
|
||||
@@ -982,11 +979,6 @@ int WebContents::GetProcessID() const {
|
||||
return web_contents()->GetRenderProcessHost()->GetID();
|
||||
}
|
||||
|
||||
base::ProcessId WebContents::GetOSProcessID() const {
|
||||
auto process_handle = web_contents()->GetRenderProcessHost()->GetHandle();
|
||||
return base::GetProcId(process_handle);
|
||||
}
|
||||
|
||||
WebContents::Type WebContents::GetType() const {
|
||||
return type_;
|
||||
}
|
||||
@@ -1005,16 +997,12 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (guest_delegate_ && !guest_delegate_->IsAttached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
content::NavigationController::LoadURLParams params(url);
|
||||
|
||||
GURL http_referrer;
|
||||
if (options.Get("httpReferrer", &http_referrer))
|
||||
params.referrer = content::Referrer(http_referrer.GetAsReferrer(),
|
||||
blink::kWebReferrerPolicyDefault);
|
||||
blink::WebReferrerPolicyDefault);
|
||||
|
||||
std::string user_agent;
|
||||
if (options.Get("userAgent", &user_agent))
|
||||
@@ -1039,23 +1027,16 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||
params.transition_type = ui::PAGE_TRANSITION_TYPED;
|
||||
params.should_clear_history_list = true;
|
||||
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
||||
web_contents()->GetController().LoadURLWithParams(params);
|
||||
|
||||
// Set the background color of RenderWidgetHostView.
|
||||
if (deferred_load_url_.id) {
|
||||
deferred_load_url_.params = params;
|
||||
return;
|
||||
}
|
||||
|
||||
web_contents()->GetController().LoadURLWithParams(params);
|
||||
// We have to call it right after LoadURL because the RenderViewHost is only
|
||||
// created after loading a page.
|
||||
const auto view = web_contents()->GetRenderWidgetHostView();
|
||||
if (view) {
|
||||
WebContentsPreferences* web_preferences =
|
||||
WebContentsPreferences::FromWebContents(web_contents());
|
||||
std::string color_name;
|
||||
if (web_preferences->web_preferences()->GetString(options::kBackgroundColor,
|
||||
&color_name)) {
|
||||
view->SetBackgroundColor(ParseHexColor(color_name));
|
||||
} else {
|
||||
view->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||
}
|
||||
}
|
||||
SetBackgroundColor(web_contents());
|
||||
}
|
||||
|
||||
void WebContents::DownloadURL(const GURL& url) {
|
||||
@@ -1252,22 +1233,9 @@ void WebContents::HasServiceWorker(
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
struct WrappedCallback {
|
||||
base::Callback<void(bool)> callback_;
|
||||
explicit WrappedCallback(const base::Callback<void(bool)>& callback)
|
||||
: callback_(callback) {}
|
||||
void Run(content::ServiceWorkerCapability capability) {
|
||||
callback_.Run(capability !=
|
||||
content::ServiceWorkerCapability::NO_SERVICE_WORKER);
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
|
||||
auto wrapped_callback = new WrappedCallback(callback);
|
||||
|
||||
context->CheckHasServiceWorker(
|
||||
web_contents()->GetLastCommittedURL(), GURL::EmptyGURL(),
|
||||
base::Bind(&WrappedCallback::Run, base::Unretained(wrapped_callback)));
|
||||
context->CheckHasServiceWorker(web_contents()->GetLastCommittedURL(),
|
||||
GURL::EmptyGURL(),
|
||||
callback);
|
||||
}
|
||||
|
||||
void WebContents::UnregisterServiceWorker(
|
||||
@@ -1280,10 +1248,6 @@ void WebContents::UnregisterServiceWorker(
|
||||
callback);
|
||||
}
|
||||
|
||||
void WebContents::SetIgnoreMenuShortcuts(bool ignore) {
|
||||
set_ignore_menu_shortcuts(ignore);
|
||||
}
|
||||
|
||||
void WebContents::SetAudioMuted(bool muted) {
|
||||
web_contents()->SetAudioMuted(muted);
|
||||
}
|
||||
@@ -1293,32 +1257,16 @@ bool WebContents::IsAudioMuted() {
|
||||
}
|
||||
|
||||
void WebContents::Print(mate::Arguments* args) {
|
||||
PrintSettings settings = { false, false, base::string16() };
|
||||
if (args->Length() >= 1 && !args->GetNext(&settings)) {
|
||||
PrintSettings settings = { false, false };
|
||||
if (args->Length() == 1 && !args->GetNext(&settings)) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
auto print_view_manager_basic_ptr =
|
||||
printing::PrintViewManagerBasic::FromWebContents(web_contents());
|
||||
if (args->Length() == 2) {
|
||||
base::Callback<void(bool)> callback;
|
||||
if (!args->GetNext(&callback)) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
print_view_manager_basic_ptr->SetCallback(callback);
|
||||
}
|
||||
print_view_manager_basic_ptr->PrintNow(web_contents()->GetMainFrame(),
|
||||
settings.silent,
|
||||
settings.print_background,
|
||||
settings.device_name);
|
||||
}
|
||||
|
||||
std::vector<printing::PrinterBasicInfo> WebContents::GetPrinterList() {
|
||||
std::vector<printing::PrinterBasicInfo> printers;
|
||||
auto print_backend = printing::PrintBackend::CreateInstance(nullptr);
|
||||
print_backend->EnumeratePrinters(&printers);
|
||||
return printers;
|
||||
printing::PrintViewManagerBasic::FromWebContents(web_contents())->
|
||||
PrintNow(web_contents()->GetMainFrame(),
|
||||
settings.silent,
|
||||
settings.print_background);
|
||||
}
|
||||
|
||||
void WebContents::PrintToPDF(const base::DictionaryValue& setting,
|
||||
@@ -1378,7 +1326,7 @@ void WebContents::SelectAll() {
|
||||
}
|
||||
|
||||
void WebContents::Unselect() {
|
||||
web_contents()->CollapseSelection();
|
||||
web_contents()->Unselect();
|
||||
}
|
||||
|
||||
void WebContents::Replace(const base::string16& word) {
|
||||
@@ -1453,31 +1401,30 @@ bool WebContents::SendIPCMessage(bool all_frames,
|
||||
|
||||
void WebContents::SendInputEvent(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> input_event) {
|
||||
const auto view = static_cast<content::RenderWidgetHostViewBase*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
const auto view = web_contents()->GetRenderWidgetHostView();
|
||||
if (!view)
|
||||
return;
|
||||
const auto host = view->GetRenderWidgetHost();
|
||||
if (!host)
|
||||
return;
|
||||
|
||||
int type = mate::GetWebInputEventType(isolate, input_event);
|
||||
if (blink::WebInputEvent::IsMouseEventType(type)) {
|
||||
if (blink::WebInputEvent::isMouseEventType(type)) {
|
||||
blink::WebMouseEvent mouse_event;
|
||||
if (mate::ConvertFromV8(isolate, input_event, &mouse_event)) {
|
||||
view->ProcessMouseEvent(mouse_event, ui::LatencyInfo());
|
||||
host->ForwardMouseEvent(mouse_event);
|
||||
return;
|
||||
}
|
||||
} else if (blink::WebInputEvent::IsKeyboardEventType(type)) {
|
||||
content::NativeWebKeyboardEvent keyboard_event(
|
||||
blink::WebKeyboardEvent::kRawKeyDown,
|
||||
blink::WebInputEvent::kNoModifiers,
|
||||
ui::EventTimeForNow());
|
||||
} else if (blink::WebInputEvent::isKeyboardEventType(type)) {
|
||||
content::NativeWebKeyboardEvent keyboard_event;
|
||||
if (mate::ConvertFromV8(isolate, input_event, &keyboard_event)) {
|
||||
view->ProcessKeyboardEvent(keyboard_event);
|
||||
host->ForwardKeyboardEvent(keyboard_event);
|
||||
return;
|
||||
}
|
||||
} else if (type == blink::WebInputEvent::kMouseWheel) {
|
||||
} else if (type == blink::WebInputEvent::MouseWheel) {
|
||||
blink::WebMouseWheelEvent mouse_wheel_event;
|
||||
if (mate::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) {
|
||||
view->ProcessMouseWheelEvent(mouse_wheel_event, ui::LatencyInfo());
|
||||
host->ForwardWheelEvent(mouse_wheel_event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1559,7 +1506,8 @@ void WebContents::CapturePage(mate::Arguments* args) {
|
||||
}
|
||||
|
||||
const auto view = web_contents()->GetRenderWidgetHostView();
|
||||
if (!view) {
|
||||
const auto host = view ? view->GetRenderWidgetHost() : nullptr;
|
||||
if (!view || !host) {
|
||||
callback.Run(gfx::Image());
|
||||
return;
|
||||
}
|
||||
@@ -1574,19 +1522,19 @@ void WebContents::CapturePage(mate::Arguments* args) {
|
||||
gfx::Size bitmap_size = view_size;
|
||||
const gfx::NativeView native_view = view->GetNativeView();
|
||||
const float scale =
|
||||
display::Screen::GetScreen()->GetDisplayNearestView(native_view)
|
||||
display::Screen::GetScreen()->GetDisplayNearestWindow(native_view)
|
||||
.device_scale_factor();
|
||||
if (scale > 1.0f)
|
||||
bitmap_size = gfx::ScaleToCeiledSize(view_size, scale);
|
||||
|
||||
view->CopyFromSurface(gfx::Rect(rect.origin(), view_size),
|
||||
bitmap_size,
|
||||
base::Bind(&OnCapturePageDone, callback),
|
||||
kBGRA_8888_SkColorType);
|
||||
host->CopyFromBackingStore(gfx::Rect(rect.origin(), view_size),
|
||||
bitmap_size,
|
||||
base::Bind(&OnCapturePageDone, callback),
|
||||
kBGRA_8888_SkColorType);
|
||||
}
|
||||
|
||||
void WebContents::OnCursorChange(const content::WebCursor& cursor) {
|
||||
content::CursorInfo info;
|
||||
content::WebCursor::CursorInfo info;
|
||||
cursor.GetCursorInfo(&info);
|
||||
|
||||
if (cursor.IsCustom()) {
|
||||
@@ -1610,91 +1558,69 @@ bool WebContents::IsGuest() const {
|
||||
}
|
||||
|
||||
bool WebContents::IsOffScreen() const {
|
||||
#if defined(ENABLE_OSR)
|
||||
return type_ == OFF_SCREEN;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool WebContents::IsOffScreenOrEmbedderOffscreen() const {
|
||||
return IsOffScreen() || (embedder_ && embedder_->IsOffScreen());
|
||||
}
|
||||
|
||||
void WebContents::OnPaint(const gfx::Rect& dirty_rect, const SkBitmap& bitmap) {
|
||||
Emit("paint", dirty_rect, gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||
mate::Handle<NativeImage> image =
|
||||
NativeImage::Create(isolate(), gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||
Emit("paint", dirty_rect, image);
|
||||
}
|
||||
|
||||
void WebContents::StartPainting() {
|
||||
if (!IsOffScreen())
|
||||
return;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->SetPainting(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebContents::StopPainting() {
|
||||
if (!IsOffScreen())
|
||||
return;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->SetPainting(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool WebContents::IsPainting() const {
|
||||
if (!IsOffScreen())
|
||||
return false;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
return osr_rwhv && osr_rwhv->IsPainting();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebContents::SetFrameRate(int frame_rate) {
|
||||
if (!IsOffScreen())
|
||||
return;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->SetFrameRate(frame_rate);
|
||||
#endif
|
||||
}
|
||||
|
||||
int WebContents::GetFrameRate() const {
|
||||
if (!IsOffScreen())
|
||||
return 0;
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
return osr_rwhv ? osr_rwhv->GetFrameRate() : 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebContents::Invalidate() {
|
||||
if (IsOffScreen()) {
|
||||
#if defined(ENABLE_OSR)
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->Invalidate();
|
||||
#endif
|
||||
} else {
|
||||
const auto window = owner_window();
|
||||
if (window)
|
||||
@@ -1702,18 +1628,6 @@ void WebContents::Invalidate() {
|
||||
}
|
||||
}
|
||||
|
||||
gfx::Size WebContents::GetSizeForNewRenderView(
|
||||
content::WebContents* wc) const {
|
||||
if (IsOffScreen() && wc == web_contents()) {
|
||||
auto relay = NativeWindowRelay::FromWebContents(web_contents());
|
||||
if (relay) {
|
||||
return relay->window->GetSize();
|
||||
}
|
||||
}
|
||||
|
||||
return gfx::Size();
|
||||
}
|
||||
|
||||
void WebContents::SetZoomLevel(double level) {
|
||||
zoom_controller_->SetZoomLevel(level);
|
||||
}
|
||||
@@ -1791,16 +1705,6 @@ void WebContents::SetEmbedder(const WebContents* embedder) {
|
||||
}
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> WebContents::GetNativeView() const {
|
||||
gfx::NativeView ptr = web_contents()->GetNativeView();
|
||||
auto buffer = node::Buffer::Copy(
|
||||
isolate(), reinterpret_cast<char*>(&ptr), sizeof(gfx::NativeView));
|
||||
if (buffer.IsEmpty())
|
||||
return v8::Null(isolate());
|
||||
else
|
||||
return buffer.ToLocalChecked();
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> WebContents::DevToolsWebContents(v8::Isolate* isolate) {
|
||||
if (devtools_web_contents_.IsEmpty())
|
||||
return v8::Null(isolate);
|
||||
@@ -1816,12 +1720,6 @@ v8::Local<v8::Value> WebContents::Debugger(v8::Isolate* isolate) {
|
||||
return v8::Local<v8::Value>::New(isolate, debugger_);
|
||||
}
|
||||
|
||||
void WebContents::GrantOriginAccess(const GURL& url) {
|
||||
content::ChildProcessSecurityPolicy::GetInstance()->GrantOrigin(
|
||||
web_contents()->GetMainFrame()->GetProcess()->GetID(),
|
||||
url::Origin(url));
|
||||
}
|
||||
|
||||
// static
|
||||
void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
@@ -1830,7 +1728,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
.MakeDestroyable()
|
||||
.SetMethod("getId", &WebContents::GetID)
|
||||
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
||||
.SetMethod("getOSProcessId", &WebContents::GetOSProcessID)
|
||||
.SetMethod("equal", &WebContents::Equal)
|
||||
.SetMethod("_loadURL", &WebContents::LoadURL)
|
||||
.SetMethod("downloadURL", &WebContents::DownloadURL)
|
||||
@@ -1851,12 +1748,12 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
||||
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
|
||||
.SetMethod("isDevToolsFocused", &WebContents::IsDevToolsFocused)
|
||||
.SetMethod("enableDeviceEmulation", &WebContents::EnableDeviceEmulation)
|
||||
.SetMethod("disableDeviceEmulation", &WebContents::DisableDeviceEmulation)
|
||||
.SetMethod("enableDeviceEmulation",
|
||||
&WebContents::EnableDeviceEmulation)
|
||||
.SetMethod("disableDeviceEmulation",
|
||||
&WebContents::DisableDeviceEmulation)
|
||||
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
|
||||
.SetMethod("inspectElement", &WebContents::InspectElement)
|
||||
.SetMethod("setIgnoreMenuShortcuts",
|
||||
&WebContents::SetIgnoreMenuShortcuts)
|
||||
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
|
||||
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
|
||||
.SetMethod("undo", &WebContents::Undo)
|
||||
@@ -1877,14 +1774,13 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("tabTraverse", &WebContents::TabTraverse)
|
||||
.SetMethod("_send", &WebContents::SendIPCMessage)
|
||||
.SetMethod("sendInputEvent", &WebContents::SendInputEvent)
|
||||
.SetMethod("beginFrameSubscription", &WebContents::BeginFrameSubscription)
|
||||
.SetMethod("beginFrameSubscription",
|
||||
&WebContents::BeginFrameSubscription)
|
||||
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
|
||||
.SetMethod("startDrag", &WebContents::StartDrag)
|
||||
.SetMethod("setSize", &WebContents::SetSize)
|
||||
.SetMethod("isGuest", &WebContents::IsGuest)
|
||||
#if defined(ENABLE_OSR)
|
||||
.SetMethod("isOffscreen", &WebContents::IsOffScreen)
|
||||
#endif
|
||||
.SetMethod("startPainting", &WebContents::StartPainting)
|
||||
.SetMethod("stopPainting", &WebContents::StopPainting)
|
||||
.SetMethod("isPainting", &WebContents::IsPainting)
|
||||
@@ -1903,7 +1799,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
&WebContents::UnregisterServiceWorker)
|
||||
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
|
||||
.SetMethod("print", &WebContents::Print)
|
||||
.SetMethod("getPrinters", &WebContents::GetPrinterList)
|
||||
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
||||
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
||||
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
||||
@@ -1912,12 +1807,10 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("copyImageAt", &WebContents::CopyImageAt)
|
||||
.SetMethod("capturePage", &WebContents::CapturePage)
|
||||
.SetMethod("setEmbedder", &WebContents::SetEmbedder)
|
||||
.SetMethod("getNativeView", &WebContents::GetNativeView)
|
||||
.SetMethod("setWebRTCIPHandlingPolicy",
|
||||
&WebContents::SetWebRTCIPHandlingPolicy)
|
||||
.SetMethod("getWebRTCIPHandlingPolicy",
|
||||
&WebContents::GetWebRTCIPHandlingPolicy)
|
||||
.SetMethod("_grantOriginAccess", &WebContents::GrantOriginAccess)
|
||||
.SetProperty("id", &WebContents::ID)
|
||||
.SetProperty("session", &WebContents::Session)
|
||||
.SetProperty("hostWebContents", &WebContents::HostWebContents)
|
||||
|
||||
@@ -12,13 +12,12 @@
|
||||
#include "atom/browser/api/save_page_handler.h"
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/common_web_contents_delegate.h"
|
||||
#include "atom/browser/ui/autofill_popup.h"
|
||||
#include "content/common/cursors/webcursor.h"
|
||||
#include "content/public/browser/keyboard_event_processing_result.h"
|
||||
#include "content/public/browser/notification_observer.h"
|
||||
#include "content/public/browser/notification_registrar.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/common/favicon_url.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "printing/backend/print_backend.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
namespace blink {
|
||||
@@ -42,7 +41,6 @@ namespace atom {
|
||||
|
||||
struct SetSizeParams;
|
||||
class AtomBrowserContext;
|
||||
class AtomJavaScriptDialogManager;
|
||||
class WebContentsZoomController;
|
||||
class WebViewGuestDelegate;
|
||||
|
||||
@@ -50,7 +48,8 @@ namespace api {
|
||||
|
||||
class WebContents : public mate::TrackableObject<WebContents>,
|
||||
public CommonWebContentsDelegate,
|
||||
public content::WebContentsObserver {
|
||||
public content::WebContentsObserver,
|
||||
public content::NotificationObserver {
|
||||
public:
|
||||
enum Type {
|
||||
BACKGROUND_PAGE, // A DevTools extension background page.
|
||||
@@ -83,7 +82,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
|
||||
int64_t GetID() const;
|
||||
int GetProcessID() const;
|
||||
base::ProcessId GetOSProcessID() const;
|
||||
Type GetType() const;
|
||||
bool Equal(const WebContents* web_contents) const;
|
||||
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
||||
@@ -116,16 +114,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void DisableDeviceEmulation();
|
||||
void InspectElement(int x, int y);
|
||||
void InspectServiceWorker();
|
||||
void HasServiceWorker(
|
||||
const base::Callback<void(bool)>&);
|
||||
void HasServiceWorker(const base::Callback<void(bool)>&);
|
||||
void UnregisterServiceWorker(const base::Callback<void(bool)>&);
|
||||
void SetIgnoreMenuShortcuts(bool ignore);
|
||||
void SetAudioMuted(bool muted);
|
||||
bool IsAudioMuted();
|
||||
void Print(mate::Arguments* args);
|
||||
std::vector<printing::PrinterBasicInfo> GetPrinterList();
|
||||
void SetEmbedder(const WebContents* embedder);
|
||||
v8::Local<v8::Value> GetNativeView() const;
|
||||
|
||||
// Print current page as PDF.
|
||||
void PrintToPDF(const base::DictionaryValue& setting,
|
||||
@@ -182,7 +176,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
|
||||
// Methods for offscreen rendering
|
||||
bool IsOffScreen() const;
|
||||
bool IsOffScreenOrEmbedderOffscreen() const;
|
||||
void OnPaint(const gfx::Rect& dirty_rect, const SkBitmap& bitmap);
|
||||
void StartPainting();
|
||||
void StopPainting();
|
||||
@@ -190,7 +183,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void SetFrameRate(int frame_rate);
|
||||
int GetFrameRate() const;
|
||||
void Invalidate();
|
||||
gfx::Size GetSizeForNewRenderView(content::WebContents*) const override;
|
||||
|
||||
// Methods for zoom handling.
|
||||
void SetZoomLevel(double level);
|
||||
@@ -217,10 +209,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
// Returns the owner window.
|
||||
v8::Local<v8::Value> GetOwnerBrowserWindow();
|
||||
|
||||
// Grants the child process the capability to access URLs with the origin of
|
||||
// the specified URL.
|
||||
void GrantOriginAccess(const GURL& url);
|
||||
|
||||
// Properties.
|
||||
int32_t ID() const;
|
||||
v8::Local<v8::Value> Session(v8::Isolate* isolate);
|
||||
@@ -275,9 +263,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
content::KeyboardEventProcessingResult PreHandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
bool PreHandleKeyboardEvent(content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event,
|
||||
bool* is_keyboard_shortcut) override;
|
||||
void EnterFullscreenModeForTab(content::WebContents* source,
|
||||
const GURL& origin) override;
|
||||
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
||||
@@ -308,8 +296,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
std::unique_ptr<content::BluetoothChooser> RunBluetoothChooser(
|
||||
content::RenderFrameHost* frame,
|
||||
const content::BluetoothChooser::EventHandler& handler) override;
|
||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
||||
content::WebContents* source) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
||||
@@ -331,11 +317,11 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
const content::ResourceRequestDetails& details) override;
|
||||
void DidGetRedirectForResourceRequest(
|
||||
const content::ResourceRedirectDetails& details) override;
|
||||
void DidStartNavigation(
|
||||
content::NavigationHandle* navigation_handle) override;
|
||||
void DidFinishNavigation(
|
||||
content::NavigationHandle* navigation_handle) override;
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
bool OnMessageReceived(const IPC::Message& message,
|
||||
content::RenderFrameHost* frame_host) override;
|
||||
void WebContentsDestroyed() override;
|
||||
void NavigationEntryCommitted(
|
||||
const content::LoadCommittedDetails& load_details) override;
|
||||
@@ -350,6 +336,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
const MediaPlayerId& id) override;
|
||||
void DidChangeThemeColor(SkColor theme_color) override;
|
||||
|
||||
// content::NotificationObserver:
|
||||
void Observe(int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) override;
|
||||
void BeforeUnloadDialogCancelled() override;
|
||||
|
||||
// brightray::InspectableWebContentsDelegate:
|
||||
void DevToolsReloadPage() override;
|
||||
|
||||
@@ -359,6 +351,13 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void DevToolsClosed() override;
|
||||
|
||||
private:
|
||||
struct LoadURLParams {
|
||||
LoadURLParams() : params(GURL()), id(0) {}
|
||||
|
||||
content::NavigationController::LoadURLParams params;
|
||||
int id;
|
||||
};
|
||||
|
||||
AtomBrowserContext* GetBrowserContext() const;
|
||||
|
||||
uint32_t GetNextRequestId() {
|
||||
@@ -389,7 +388,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
v8::Global<v8::Value> devtools_web_contents_;
|
||||
v8::Global<v8::Value> debugger_;
|
||||
|
||||
std::unique_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||
std::unique_ptr<WebViewGuestDelegate> guest_delegate_;
|
||||
|
||||
// The host webcontents that may contain this webcontents.
|
||||
@@ -410,6 +408,11 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
// Whether to enable devtools.
|
||||
bool enable_devtools_;
|
||||
|
||||
// Container to hold url parms for deferred load when
|
||||
// there is a pending navigation entry.
|
||||
LoadURLParams deferred_load_url_;
|
||||
content::NotificationRegistrar registrar_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/web_contents_preferences.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"
|
||||
@@ -78,43 +77,28 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||
Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
||||
const mate::Dictionary& options) {
|
||||
mate::Handle<class WebContents> web_contents;
|
||||
// If no WebContents was passed to the constructor, create it from options.
|
||||
if (!options.Get("webContents", &web_contents)) {
|
||||
// Use options.webPreferences to create WebContents.
|
||||
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
||||
options.Get(options::kWebPreferences, &web_preferences);
|
||||
|
||||
// Use options.webPreferences in WebContents.
|
||||
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
||||
options.Get(options::kWebPreferences, &web_preferences);
|
||||
// Copy the backgroundColor to webContents.
|
||||
v8::Local<v8::Value> value;
|
||||
if (options.Get(options::kBackgroundColor, &value))
|
||||
web_preferences.Set(options::kBackgroundColor, value);
|
||||
|
||||
// Copy the backgroundColor to webContents.
|
||||
v8::Local<v8::Value> value;
|
||||
if (options.Get(options::kBackgroundColor, &value))
|
||||
web_preferences.Set(options::kBackgroundColor, value);
|
||||
v8::Local<v8::Value> transparent;
|
||||
if (options.Get("transparent", &transparent))
|
||||
web_preferences.Set("transparent", transparent);
|
||||
|
||||
v8::Local<v8::Value> transparent;
|
||||
if (options.Get("transparent", &transparent))
|
||||
web_preferences.Set("transparent", transparent);
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
// Offscreen windows are always created frameless.
|
||||
bool offscreen;
|
||||
if (web_preferences.Get("offscreen", &offscreen) && offscreen) {
|
||||
auto window_options = const_cast<mate::Dictionary&>(options);
|
||||
window_options.Set(options::kFrame, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (options.Get("webContents", &web_contents)) {
|
||||
// Set webPreferences from options if using an existing webContents.
|
||||
// These preferences will be used when the webContent launches new
|
||||
// render processes.
|
||||
auto* existing_preferences =
|
||||
WebContentsPreferences::FromWebContents(web_contents->web_contents());
|
||||
base::DictionaryValue web_preferences_dict;
|
||||
if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(),
|
||||
&web_preferences_dict)) {
|
||||
existing_preferences->web_preferences()->Clear();
|
||||
existing_preferences->Merge(web_preferences_dict);
|
||||
// Offscreen windows are always created frameless.
|
||||
bool offscreen;
|
||||
if (web_preferences.Get("offscreen", &offscreen) && offscreen) {
|
||||
auto window_options = const_cast<mate::Dictionary&>(options);
|
||||
window_options.Set(options::kFrame, false);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Creates the WebContents used by BrowserWindow.
|
||||
web_contents = WebContents::Create(isolate, web_preferences);
|
||||
}
|
||||
@@ -202,8 +186,6 @@ void Window::OnWindowClosed() {
|
||||
|
||||
RemoveFromParentChildWindows();
|
||||
|
||||
ResetBrowserView();
|
||||
|
||||
// Destroy the native class when window is closed.
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE, GetDestroyClosure());
|
||||
@@ -318,10 +300,6 @@ void Window::OnTouchBarItemResult(const std::string& item_id,
|
||||
Emit("-touch-bar-interaction", item_id, details);
|
||||
}
|
||||
|
||||
void Window::OnNewWindowForTab() {
|
||||
Emit("new-window-for-tab");
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
|
||||
if (IsWindowMessageHooked(message)) {
|
||||
@@ -603,14 +581,6 @@ void Window::SetSkipTaskbar(bool skip) {
|
||||
window_->SetSkipTaskbar(skip);
|
||||
}
|
||||
|
||||
void Window::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||
window_->SetSimpleFullScreen(simple_fullscreen);
|
||||
}
|
||||
|
||||
bool Window::IsSimpleFullScreen() {
|
||||
return window_->IsSimpleFullScreen();
|
||||
}
|
||||
|
||||
void Window::SetKiosk(bool kiosk) {
|
||||
window_->SetKiosk(kiosk);
|
||||
}
|
||||
@@ -631,14 +601,6 @@ bool Window::HasShadow() {
|
||||
return window_->HasShadow();
|
||||
}
|
||||
|
||||
void Window::SetOpacity(const double opacity) {
|
||||
window_->SetOpacity(opacity);
|
||||
}
|
||||
|
||||
double Window::GetOpacity() {
|
||||
return window_->GetOpacity();
|
||||
}
|
||||
|
||||
void Window::FocusOnWebView() {
|
||||
window_->FocusOnWebView();
|
||||
}
|
||||
@@ -667,11 +629,8 @@ bool Window::IsDocumentEdited() {
|
||||
return window_->IsDocumentEdited();
|
||||
}
|
||||
|
||||
void Window::SetIgnoreMouseEvents(bool ignore, mate::Arguments* args) {
|
||||
mate::Dictionary options;
|
||||
bool forward = false;
|
||||
args->GetNext(&options) && options.Get("forward", &forward);
|
||||
return window_->SetIgnoreMouseEvents(ignore, forward);
|
||||
void Window::SetIgnoreMouseEvents(bool ignore) {
|
||||
return window_->SetIgnoreMouseEvents(ignore);
|
||||
}
|
||||
|
||||
void Window::SetContentProtection(bool enable) {
|
||||
@@ -879,31 +838,16 @@ v8::Local<v8::Value> Window::GetBrowserView() const {
|
||||
}
|
||||
|
||||
void Window::SetBrowserView(v8::Local<v8::Value> value) {
|
||||
ResetBrowserView();
|
||||
|
||||
mate::Handle<BrowserView> browser_view;
|
||||
if (value->IsNull()) {
|
||||
window_->SetBrowserView(nullptr);
|
||||
browser_view_.Reset();
|
||||
} else if (mate::ConvertFromV8(isolate(), value, &browser_view)) {
|
||||
window_->SetBrowserView(browser_view->view());
|
||||
browser_view->web_contents()->SetOwnerWindow(window_.get());
|
||||
browser_view_.Reset(isolate(), value);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::ResetBrowserView() {
|
||||
if (browser_view_.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mate::Handle<BrowserView> browser_view;
|
||||
if (mate::ConvertFromV8(isolate(), GetBrowserView(), &browser_view)) {
|
||||
browser_view->web_contents()->SetOwnerWindow(nullptr);
|
||||
}
|
||||
|
||||
browser_view_.Reset();
|
||||
}
|
||||
|
||||
bool Window::IsModal() const {
|
||||
return window_->is_modal();
|
||||
}
|
||||
@@ -926,30 +870,6 @@ void Window::SetAutoHideCursor(bool auto_hide) {
|
||||
window_->SetAutoHideCursor(auto_hide);
|
||||
}
|
||||
|
||||
void Window::SelectPreviousTab() {
|
||||
window_->SelectPreviousTab();
|
||||
}
|
||||
|
||||
void Window::SelectNextTab() {
|
||||
window_->SelectNextTab();
|
||||
}
|
||||
|
||||
void Window::MergeAllWindows() {
|
||||
window_->MergeAllWindows();
|
||||
}
|
||||
|
||||
void Window::MoveTabToNewWindow() {
|
||||
window_->MoveTabToNewWindow();
|
||||
}
|
||||
|
||||
void Window::ToggleTabBar() {
|
||||
window_->ToggleTabBar();
|
||||
}
|
||||
|
||||
void Window::AddTabbedWindow(NativeWindow* window) {
|
||||
window_->AddTabbedWindow(window);
|
||||
}
|
||||
|
||||
void Window::SetVibrancy(mate::Arguments* args) {
|
||||
std::string type;
|
||||
|
||||
@@ -1061,15 +981,11 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("getTitle", &Window::GetTitle)
|
||||
.SetMethod("flashFrame", &Window::FlashFrame)
|
||||
.SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
|
||||
.SetMethod("setSimpleFullScreen", &Window::SetSimpleFullScreen)
|
||||
.SetMethod("isSimpleFullScreen", &Window::IsSimpleFullScreen)
|
||||
.SetMethod("setKiosk", &Window::SetKiosk)
|
||||
.SetMethod("isKiosk", &Window::IsKiosk)
|
||||
.SetMethod("setBackgroundColor", &Window::SetBackgroundColor)
|
||||
.SetMethod("setHasShadow", &Window::SetHasShadow)
|
||||
.SetMethod("hasShadow", &Window::HasShadow)
|
||||
.SetMethod("setOpacity", &Window::SetOpacity)
|
||||
.SetMethod("getOpacity", &Window::GetOpacity)
|
||||
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
|
||||
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
||||
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
||||
@@ -1094,12 +1010,6 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||
&Window::IsVisibleOnAllWorkspaces)
|
||||
#if defined(OS_MACOSX)
|
||||
.SetMethod("setAutoHideCursor", &Window::SetAutoHideCursor)
|
||||
.SetMethod("mergeAllWindows", &Window::MergeAllWindows)
|
||||
.SetMethod("selectPreviousTab", &Window::SelectPreviousTab)
|
||||
.SetMethod("selectNextTab", &Window::SelectNextTab)
|
||||
.SetMethod("moveTabToNewWindow", &Window::MoveTabToNewWindow)
|
||||
.SetMethod("toggleTabBar", &Window::ToggleTabBar)
|
||||
.SetMethod("addTabbedWindow", &Window::AddTabbedWindow)
|
||||
#endif
|
||||
.SetMethod("setVibrancy", &Window::SetVibrancy)
|
||||
.SetMethod("_setTouchBarItems", &Window::SetTouchBar)
|
||||
|
||||
@@ -91,7 +91,6 @@ class Window : public mate::TrackableObject<Window>,
|
||||
void OnExecuteWindowsCommand(const std::string& command_name) override;
|
||||
void OnTouchBarItemResult(const std::string& item_id,
|
||||
const base::DictionaryValue& details) override;
|
||||
void OnNewWindowForTab() override;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override;
|
||||
@@ -154,15 +153,11 @@ class Window : public mate::TrackableObject<Window>,
|
||||
std::string GetTitle();
|
||||
void FlashFrame(bool flash);
|
||||
void SetSkipTaskbar(bool skip);
|
||||
void SetSimpleFullScreen(bool simple_fullscreen);
|
||||
bool IsSimpleFullScreen();
|
||||
void SetKiosk(bool kiosk);
|
||||
bool IsKiosk();
|
||||
void SetBackgroundColor(const std::string& color_name);
|
||||
void SetHasShadow(bool has_shadow);
|
||||
bool HasShadow();
|
||||
void SetOpacity(const double opacity);
|
||||
double GetOpacity();
|
||||
void FocusOnWebView();
|
||||
void BlurWebView();
|
||||
bool IsWebViewFocused();
|
||||
@@ -170,7 +165,7 @@ class Window : public mate::TrackableObject<Window>,
|
||||
std::string GetRepresentedFilename();
|
||||
void SetDocumentEdited(bool edited);
|
||||
bool IsDocumentEdited();
|
||||
void SetIgnoreMouseEvents(bool ignore, mate::Arguments* args);
|
||||
void SetIgnoreMouseEvents(bool ignore);
|
||||
void SetContentProtection(bool enable);
|
||||
void SetFocusable(bool focusable);
|
||||
void SetProgressBar(double progress, mate::Arguments* args);
|
||||
@@ -190,7 +185,6 @@ class Window : public mate::TrackableObject<Window>,
|
||||
std::vector<v8::Local<v8::Object>> GetChildWindows() const;
|
||||
v8::Local<v8::Value> GetBrowserView() const;
|
||||
void SetBrowserView(v8::Local<v8::Value> value);
|
||||
void ResetBrowserView();
|
||||
bool IsModal() const;
|
||||
v8::Local<v8::Value> GetNativeWindowHandle();
|
||||
|
||||
@@ -216,13 +210,6 @@ class Window : public mate::TrackableObject<Window>,
|
||||
|
||||
void SetAutoHideCursor(bool auto_hide);
|
||||
|
||||
void SelectPreviousTab();
|
||||
void SelectNextTab();
|
||||
void MergeAllWindows();
|
||||
void MoveTabToNewWindow();
|
||||
void ToggleTabBar();
|
||||
void AddTabbedWindow(NativeWindow* window);
|
||||
|
||||
void SetVibrancy(mate::Arguments* args);
|
||||
void SetTouchBar(const std::vector<mate::PersistentDictionary>& items);
|
||||
void RefreshTouchBarItem(const std::string& item_id);
|
||||
|
||||
@@ -24,7 +24,6 @@ FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
||||
view_(view),
|
||||
callback_(callback),
|
||||
only_dirty_(only_dirty),
|
||||
source_id_for_copy_request_(base::UnguessableToken::Create()),
|
||||
weak_factory_(this) {
|
||||
}
|
||||
|
||||
@@ -33,7 +32,8 @@ bool FrameSubscriber::ShouldCaptureFrame(
|
||||
base::TimeTicks present_time,
|
||||
scoped_refptr<media::VideoFrame>* storage,
|
||||
DeliverFrameCallback* callback) {
|
||||
if (!view_)
|
||||
const auto host = view_ ? view_->GetRenderWidgetHost() : nullptr;
|
||||
if (!view_ || !host)
|
||||
return false;
|
||||
|
||||
if (dirty_rect.IsEmpty())
|
||||
@@ -45,16 +45,16 @@ bool FrameSubscriber::ShouldCaptureFrame(
|
||||
|
||||
gfx::Size view_size = rect.size();
|
||||
gfx::Size bitmap_size = view_size;
|
||||
gfx::NativeView native_view = view_->GetNativeView();
|
||||
const gfx::NativeView native_view = view_->GetNativeView();
|
||||
const float scale =
|
||||
display::Screen::GetScreen()->GetDisplayNearestView(native_view)
|
||||
display::Screen::GetScreen()->GetDisplayNearestWindow(native_view)
|
||||
.device_scale_factor();
|
||||
if (scale > 1.0f)
|
||||
bitmap_size = gfx::ScaleToCeiledSize(view_size, scale);
|
||||
|
||||
rect = gfx::Rect(rect.origin(), bitmap_size);
|
||||
|
||||
view_->CopyFromSurface(
|
||||
host->CopyFromBackingStore(
|
||||
rect,
|
||||
rect.size(),
|
||||
base::Bind(&FrameSubscriber::OnFrameDelivered,
|
||||
@@ -64,10 +64,6 @@ bool FrameSubscriber::ShouldCaptureFrame(
|
||||
return false;
|
||||
}
|
||||
|
||||
const base::UnguessableToken& FrameSubscriber::GetSourceIdForCopyRequest() {
|
||||
return source_id_for_copy_request_;
|
||||
}
|
||||
|
||||
void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||
const gfx::Rect& damage_rect,
|
||||
const SkBitmap& bitmap,
|
||||
@@ -78,32 +74,20 @@ void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||
v8::Locker locker(isolate_);
|
||||
v8::HandleScope handle_scope(isolate_);
|
||||
|
||||
size_t rgb_row_size = bitmap.width() * bitmap.bytesPerPixel();
|
||||
|
||||
v8::MaybeLocal<v8::Object> buffer =
|
||||
node::Buffer::New(isolate_, rgb_row_size * bitmap.height());
|
||||
|
||||
size_t rgb_arr_size = bitmap.width() * bitmap.height() *
|
||||
bitmap.bytesPerPixel();
|
||||
v8::MaybeLocal<v8::Object> buffer = node::Buffer::New(isolate_, rgb_arr_size);
|
||||
if (buffer.IsEmpty())
|
||||
return;
|
||||
|
||||
auto local_buffer = buffer.ToLocalChecked();
|
||||
|
||||
{
|
||||
SkAutoLockPixels lock(bitmap);
|
||||
auto source = static_cast<const unsigned char*>(bitmap.getPixels());
|
||||
auto target = node::Buffer::Data(local_buffer);
|
||||
|
||||
for (int y = 0; y < bitmap.height(); ++y) {
|
||||
memcpy(target, source, rgb_row_size);
|
||||
source += bitmap.rowBytes();
|
||||
target += rgb_row_size;
|
||||
}
|
||||
}
|
||||
bitmap.copyPixelsTo(
|
||||
reinterpret_cast<uint8_t*>(node::Buffer::Data(buffer.ToLocalChecked())),
|
||||
rgb_arr_size);
|
||||
|
||||
v8::Local<v8::Value> damage =
|
||||
mate::Converter<gfx::Rect>::ToV8(isolate_, damage_rect);
|
||||
|
||||
callback_.Run(local_buffer, damage);
|
||||
callback_.Run(buffer.ToLocalChecked(), damage);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_view_frame_subscriber.h"
|
||||
#include "content/public/browser/readback_types.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "v8/include/v8.h"
|
||||
@@ -32,7 +32,6 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
|
||||
base::TimeTicks present_time,
|
||||
scoped_refptr<media::VideoFrame>* storage,
|
||||
DeliverFrameCallback* callback) override;
|
||||
const base::UnguessableToken& GetSourceIdForCopyRequest() override;
|
||||
|
||||
private:
|
||||
void OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||
@@ -45,8 +44,6 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
|
||||
FrameCaptureCallback callback_;
|
||||
bool only_dirty_;
|
||||
|
||||
base::UnguessableToken source_id_for_copy_request_;
|
||||
|
||||
base::WeakPtrFactory<FrameSubscriber> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/supports_user_data.h"
|
||||
|
||||
namespace mate {
|
||||
@@ -47,19 +46,16 @@ void TrackableObjectBase::Destroy() {
|
||||
}
|
||||
|
||||
void TrackableObjectBase::AttachAsUserData(base::SupportsUserData* wrapped) {
|
||||
wrapped->SetUserData(kTrackedObjectKey,
|
||||
base::MakeUnique<IDUserData>(weak_map_id_));
|
||||
wrapped->SetUserData(kTrackedObjectKey, new IDUserData(weak_map_id_));
|
||||
}
|
||||
|
||||
// static
|
||||
int32_t TrackableObjectBase::GetIDFromWrappedClass(
|
||||
base::SupportsUserData* wrapped) {
|
||||
if (wrapped) {
|
||||
auto id = static_cast<IDUserData*>(wrapped->GetUserData(kTrackedObjectKey));
|
||||
if (id)
|
||||
return *id;
|
||||
}
|
||||
return 0;
|
||||
int32_t TrackableObjectBase::GetIDFromWrappedClass(base::SupportsUserData* w) {
|
||||
auto id = static_cast<IDUserData*>(w->GetUserData(kTrackedObjectKey));
|
||||
if (id)
|
||||
return *id;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// static
|
||||
|
||||
@@ -30,15 +30,15 @@ class TrackableObjectBase {
|
||||
// Wrap TrackableObject into a class that SupportsUserData.
|
||||
void AttachAsUserData(base::SupportsUserData* wrapped);
|
||||
|
||||
// Get the weak_map_id from SupportsUserData.
|
||||
static int32_t GetIDFromWrappedClass(base::SupportsUserData* wrapped);
|
||||
|
||||
protected:
|
||||
virtual ~TrackableObjectBase();
|
||||
|
||||
// Returns a closure that can destroy the native class.
|
||||
base::Closure GetDestroyClosure();
|
||||
|
||||
// Get the weak_map_id from SupportsUserData.
|
||||
static int32_t GetIDFromWrappedClass(base::SupportsUserData* wrapped);
|
||||
|
||||
// Register a callback that should be destroyed before JavaScript environment
|
||||
// gets destroyed.
|
||||
static base::Closure RegisterDestructionCallback(const base::Closure& c);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "atom/browser/atom_quota_permission_context.h"
|
||||
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
||||
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
||||
#include "atom/browser/child_web_contents_tracker.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/web_contents_permission_helper.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
@@ -38,7 +37,6 @@
|
||||
#include "content/public/browser/resource_dispatcher_host.h"
|
||||
#include "content/public/browser/site_instance.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "net/ssl/ssl_cert_request_info.h"
|
||||
@@ -79,10 +77,9 @@ AtomBrowserClient::~AtomBrowserClient() {
|
||||
|
||||
content::WebContents* AtomBrowserClient::GetWebContentsFromProcessID(
|
||||
int process_id) {
|
||||
// If the process is a pending process, we should use the web contents
|
||||
// for the frame host passed into OverrideSiteInstanceForNavigation.
|
||||
// If the process is a pending process, we should use the old one.
|
||||
if (base::ContainsKey(pending_processes_, process_id))
|
||||
return pending_processes_[process_id];
|
||||
process_id = pending_processes_[process_id];
|
||||
|
||||
// Certain render process will be created with no associated render view,
|
||||
// for example: ServiceWorker.
|
||||
@@ -90,31 +87,17 @@ content::WebContents* AtomBrowserClient::GetWebContentsFromProcessID(
|
||||
}
|
||||
|
||||
bool AtomBrowserClient::ShouldCreateNewSiteInstance(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
content::BrowserContext* browser_context,
|
||||
content::SiteInstance* current_instance,
|
||||
const GURL& url) {
|
||||
|
||||
if (url.SchemeIs(url::kJavaScriptScheme))
|
||||
// "javacript:" scheme should always use same SiteInstance
|
||||
return false;
|
||||
|
||||
int process_id = current_instance->GetProcess()->GetID();
|
||||
if (!IsRendererSandboxed(process_id)) {
|
||||
if (!RendererUsesNativeWindowOpen(process_id)) {
|
||||
// non-sandboxed renderers without native window.open should always create
|
||||
// a new SiteInstance
|
||||
return true;
|
||||
}
|
||||
auto web_contents =
|
||||
content::WebContents::FromRenderFrameHost(render_frame_host);
|
||||
if (!ChildWebContentsTracker::IsChildWebContents(web_contents)) {
|
||||
// Root WebContents should always create new process to make sure
|
||||
// native addons are loaded correctly after reload / navigation.
|
||||
// (Non-root WebContents opened by window.open() should try to
|
||||
// reuse process to allow synchronous cross-window scripting.)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!IsRendererSandboxed(current_instance->GetProcess()->GetID()))
|
||||
// non-sandboxed renderers should always create a new SiteInstance
|
||||
return true;
|
||||
|
||||
// Create new a SiteInstance if navigating to a different site.
|
||||
auto src_url = current_instance->GetSiteURL();
|
||||
@@ -126,33 +109,19 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance(
|
||||
content::SiteInstance::GetSiteForURL(browser_context, url) != src_url;
|
||||
}
|
||||
|
||||
void AtomBrowserClient::AddProcessPreferences(
|
||||
int process_id, AtomBrowserClient::ProcessPreferences prefs) {
|
||||
base::AutoLock auto_lock(process_preferences_lock_);
|
||||
process_preferences_[process_id] = prefs;
|
||||
void AtomBrowserClient::AddSandboxedRendererId(int process_id) {
|
||||
base::AutoLock auto_lock(sandboxed_renderers_lock_);
|
||||
sandboxed_renderers_.insert(process_id);
|
||||
}
|
||||
|
||||
void AtomBrowserClient::RemoveProcessPreferences(int process_id) {
|
||||
base::AutoLock auto_lock(process_preferences_lock_);
|
||||
process_preferences_.erase(process_id);
|
||||
void AtomBrowserClient::RemoveSandboxedRendererId(int process_id) {
|
||||
base::AutoLock auto_lock(sandboxed_renderers_lock_);
|
||||
sandboxed_renderers_.erase(process_id);
|
||||
}
|
||||
|
||||
bool AtomBrowserClient::IsRendererSandboxed(int process_id) {
|
||||
base::AutoLock auto_lock(process_preferences_lock_);
|
||||
auto it = process_preferences_.find(process_id);
|
||||
return it != process_preferences_.end() && it->second.sandbox;
|
||||
}
|
||||
|
||||
bool AtomBrowserClient::RendererUsesNativeWindowOpen(int process_id) {
|
||||
base::AutoLock auto_lock(process_preferences_lock_);
|
||||
auto it = process_preferences_.find(process_id);
|
||||
return it != process_preferences_.end() && it->second.native_window_open;
|
||||
}
|
||||
|
||||
bool AtomBrowserClient::RendererDisablesPopups(int process_id) {
|
||||
base::AutoLock auto_lock(process_preferences_lock_);
|
||||
auto it = process_preferences_.find(process_id);
|
||||
return it != process_preferences_.end() && it->second.disable_popups;
|
||||
base::AutoLock auto_lock(sandboxed_renderers_lock_);
|
||||
return sandboxed_renderers_.count(process_id);
|
||||
}
|
||||
|
||||
void AtomBrowserClient::RenderProcessWillLaunch(
|
||||
@@ -164,15 +133,11 @@ void AtomBrowserClient::RenderProcessWillLaunch(
|
||||
new WidevineCdmMessageFilter(process_id, host->GetBrowserContext()));
|
||||
|
||||
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
|
||||
ProcessPreferences process_prefs;
|
||||
process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents);
|
||||
process_prefs.native_window_open
|
||||
= WebContentsPreferences::UsesNativeWindowOpen(web_contents);
|
||||
process_prefs.disable_popups
|
||||
= WebContentsPreferences::DisablePopups(web_contents);
|
||||
AddProcessPreferences(host->GetID(), process_prefs);
|
||||
// ensure the ProcessPreferences is removed later
|
||||
host->AddObserver(this);
|
||||
if (WebContentsPreferences::IsSandboxed(web_contents)) {
|
||||
AddSandboxedRendererId(host->GetID());
|
||||
// ensure the sandboxed renderer id is removed later
|
||||
host->AddObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
content::SpeechRecognitionManagerDelegate*
|
||||
@@ -217,8 +182,7 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ShouldCreateNewSiteInstance(render_frame_host, browser_context,
|
||||
current_instance, url))
|
||||
if (!ShouldCreateNewSiteInstance(browser_context, current_instance, url))
|
||||
return;
|
||||
|
||||
scoped_refptr<content::SiteInstance> site_instance =
|
||||
@@ -232,20 +196,19 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||
content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&Noop, base::RetainedRef(site_instance)));
|
||||
|
||||
// Remember the original web contents for the pending renderer process.
|
||||
// Remember the original renderer process of the pending renderer process.
|
||||
auto current_process = current_instance->GetProcess();
|
||||
auto pending_process = (*new_instance)->GetProcess();
|
||||
pending_processes_[pending_process->GetID()] =
|
||||
content::WebContents::FromRenderFrameHost(render_frame_host);;
|
||||
pending_processes_[pending_process->GetID()] = current_process->GetID();
|
||||
// Clear the entry in map when process ends.
|
||||
pending_process->AddObserver(this);
|
||||
current_process->AddObserver(this);
|
||||
}
|
||||
|
||||
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||
base::CommandLine* command_line,
|
||||
int process_id) {
|
||||
std::string process_type =
|
||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
||||
if (process_type != ::switches::kRendererProcess)
|
||||
std::string process_type = command_line->GetSwitchValueASCII("type");
|
||||
if (process_type != "renderer")
|
||||
return;
|
||||
|
||||
// Copy following switches to child process.
|
||||
@@ -278,9 +241,11 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||
}
|
||||
|
||||
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
|
||||
if (web_contents)
|
||||
WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||
web_contents, command_line);
|
||||
if (!web_contents)
|
||||
return;
|
||||
|
||||
WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||
web_contents, command_line);
|
||||
}
|
||||
|
||||
void AtomBrowserClient::DidCreatePpapiPlugin(
|
||||
@@ -331,41 +296,31 @@ void AtomBrowserClient::ResourceDispatcherHostCreated() {
|
||||
}
|
||||
|
||||
bool AtomBrowserClient::CanCreateWindow(
|
||||
int opener_render_process_id,
|
||||
int opener_render_frame_id,
|
||||
const GURL& opener_url,
|
||||
const GURL& opener_top_level_frame_url,
|
||||
const GURL& source_origin,
|
||||
content::mojom::WindowContainerType container_type,
|
||||
WindowContainerType container_type,
|
||||
const GURL& target_url,
|
||||
const content::Referrer& referrer,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::mojom::WindowFeatures& features,
|
||||
const blink::WebWindowFeatures& features,
|
||||
const std::vector<std::string>& additional_features,
|
||||
const scoped_refptr<content::ResourceRequestBodyImpl>& body,
|
||||
bool user_gesture,
|
||||
bool opener_suppressed,
|
||||
content::ResourceContext* context,
|
||||
int render_process_id,
|
||||
int opener_render_view_id,
|
||||
int opener_render_frame_id,
|
||||
bool* no_javascript_access) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
|
||||
|
||||
if (IsRendererSandboxed(opener_render_process_id)) {
|
||||
if (IsRendererSandboxed(render_process_id)) {
|
||||
*no_javascript_access = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RendererUsesNativeWindowOpen(opener_render_process_id)) {
|
||||
if (RendererDisablesPopups(opener_render_process_id)) {
|
||||
// <webview> without allowpopups attribute should return
|
||||
// null from window.open calls
|
||||
return false;
|
||||
} else {
|
||||
*no_javascript_access = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (delegate_) {
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&api::App::OnCreateWindow,
|
||||
@@ -375,7 +330,7 @@ bool AtomBrowserClient::CanCreateWindow(
|
||||
disposition,
|
||||
additional_features,
|
||||
body,
|
||||
opener_render_process_id,
|
||||
render_process_id,
|
||||
opener_render_frame_id));
|
||||
}
|
||||
|
||||
@@ -420,28 +375,13 @@ void AtomBrowserClient::WebNotificationAllowed(
|
||||
void AtomBrowserClient::RenderProcessHostDestroyed(
|
||||
content::RenderProcessHost* host) {
|
||||
int process_id = host->GetID();
|
||||
pending_processes_.erase(process_id);
|
||||
RemoveProcessPreferences(process_id);
|
||||
}
|
||||
|
||||
void AtomBrowserClient::RenderProcessReady(content::RenderProcessHost* host) {
|
||||
render_process_host_pids_[host->GetID()] = base::GetProcId(host->GetHandle());
|
||||
if (delegate_) {
|
||||
static_cast<api::App*>(delegate_)->RenderProcessReady(host);
|
||||
}
|
||||
}
|
||||
|
||||
void AtomBrowserClient::RenderProcessExited(content::RenderProcessHost* host,
|
||||
base::TerminationStatus status,
|
||||
int exit_code) {
|
||||
auto host_pid = render_process_host_pids_.find(host->GetID());
|
||||
if (host_pid != render_process_host_pids_.end()) {
|
||||
if (delegate_) {
|
||||
static_cast<api::App*>(delegate_)->RenderProcessDisconnected(
|
||||
host_pid->second);
|
||||
for (const auto& entry : pending_processes_) {
|
||||
if (entry.first == process_id || entry.second == process_id) {
|
||||
pending_processes_.erase(entry.first);
|
||||
break;
|
||||
}
|
||||
render_process_host_pids_.erase(host_pid);
|
||||
}
|
||||
RemoveSandboxedRendererId(process_id);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -80,22 +80,23 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||
std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
|
||||
void ResourceDispatcherHostCreated() override;
|
||||
bool CanCreateWindow(
|
||||
int opener_render_process_id,
|
||||
int opener_render_frame_id,
|
||||
const GURL& opener_url,
|
||||
const GURL& opener_top_level_frame_url,
|
||||
const GURL& source_origin,
|
||||
content::mojom::WindowContainerType container_type,
|
||||
WindowContainerType container_type,
|
||||
const GURL& target_url,
|
||||
const content::Referrer& referrer,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::mojom::WindowFeatures& features,
|
||||
const blink::WebWindowFeatures& features,
|
||||
const std::vector<std::string>& additional_features,
|
||||
const scoped_refptr<content::ResourceRequestBodyImpl>& body,
|
||||
bool user_gesture,
|
||||
bool opener_suppressed,
|
||||
content::ResourceContext* context,
|
||||
int render_process_id,
|
||||
int opener_render_view_id,
|
||||
int opener_render_frame_id,
|
||||
bool* no_javascript_access) override;
|
||||
void GetAdditionalAllowedSchemesForFileSystem(
|
||||
std::vector<std::string>* schemes) override;
|
||||
@@ -109,33 +110,21 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||
|
||||
// content::RenderProcessHostObserver:
|
||||
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
|
||||
void RenderProcessReady(content::RenderProcessHost* host) override;
|
||||
void RenderProcessExited(content::RenderProcessHost* host,
|
||||
base::TerminationStatus status,
|
||||
int exit_code) override;
|
||||
|
||||
private:
|
||||
bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host,
|
||||
content::BrowserContext* browser_context,
|
||||
bool ShouldCreateNewSiteInstance(content::BrowserContext* browser_context,
|
||||
content::SiteInstance* current_instance,
|
||||
const GURL& dest_url);
|
||||
struct ProcessPreferences {
|
||||
bool sandbox;
|
||||
bool native_window_open;
|
||||
bool disable_popups;
|
||||
};
|
||||
void AddProcessPreferences(int process_id, ProcessPreferences prefs);
|
||||
void RemoveProcessPreferences(int process_id);
|
||||
// Add/remove a process id to `sandboxed_renderers_`.
|
||||
void AddSandboxedRendererId(int process_id);
|
||||
void RemoveSandboxedRendererId(int process_id);
|
||||
bool IsRendererSandboxed(int process_id);
|
||||
bool RendererUsesNativeWindowOpen(int process_id);
|
||||
bool RendererDisablesPopups(int process_id);
|
||||
|
||||
// pending_render_process => web contents.
|
||||
std::map<int, content::WebContents*> pending_processes_;
|
||||
|
||||
std::map<int, ProcessPreferences> process_preferences_;
|
||||
std::map<int, base::ProcessId> render_process_host_pids_;
|
||||
base::Lock process_preferences_lock_;
|
||||
// pending_render_process => current_render_process.
|
||||
std::map<int, int> pending_processes_;
|
||||
// Set that contains the process ids of all sandboxed renderers
|
||||
std::set<int> sandboxed_renderers_;
|
||||
base::Lock sandboxed_renderers_lock_;
|
||||
|
||||
std::unique_ptr<AtomResourceDispatcherHostDelegate>
|
||||
resource_dispatcher_host_delegate_;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_app.h"
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/atom_access_token_store.h"
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
@@ -130,14 +129,17 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||
|
||||
node_bindings_->Initialize();
|
||||
|
||||
// Support the "--debug" switch.
|
||||
node_debugger_.reset(new NodeDebugger(js_env_->isolate()));
|
||||
|
||||
// Create the global environment.
|
||||
node::Environment* env =
|
||||
node_bindings_->CreateEnvironment(js_env_->context());
|
||||
node_env_.reset(new NodeEnvironment(env));
|
||||
|
||||
// Enable support for v8 inspector
|
||||
node_debugger_.reset(new NodeDebugger(env));
|
||||
node_debugger_->Start();
|
||||
// Make sure node can get correct environment when debugging.
|
||||
if (node_debugger_->IsRunning())
|
||||
env->AssignToContext(v8::Debug::GetDebugContext(js_env_->isolate()));
|
||||
|
||||
// Add Electron extended APIs.
|
||||
atom_bindings_->BindTo(js_env_->isolate(), env->process_object());
|
||||
@@ -184,8 +186,6 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
|
||||
std::unique_ptr<base::DictionaryValue> empty_info(new base::DictionaryValue);
|
||||
Browser::Get()->DidFinishLaunching(*empty_info);
|
||||
#endif
|
||||
|
||||
Browser::Get()->PreMainMessageLoopRun();
|
||||
}
|
||||
|
||||
bool AtomBrowserMainParts::MainMessageLoopRun(int* result_code) {
|
||||
|
||||
@@ -115,10 +115,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||
// If user cancels the file save dialog, run the callback with empty FilePath.
|
||||
callback.Run(path,
|
||||
content::DownloadItem::TARGET_DISPOSITION_PROMPT,
|
||||
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path,
|
||||
path.empty() ?
|
||||
content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED :
|
||||
content::DOWNLOAD_INTERRUPT_REASON_NONE);
|
||||
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path);
|
||||
}
|
||||
|
||||
void AtomDownloadManagerDelegate::Shutdown() {
|
||||
@@ -135,8 +132,7 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget(
|
||||
callback.Run(download->GetForcedFilePath(),
|
||||
content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
|
||||
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
|
||||
download->GetForcedFilePath(),
|
||||
content::DOWNLOAD_INTERRUPT_REASON_NONE);
|
||||
download->GetForcedFilePath());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -147,7 +143,7 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget(
|
||||
callback.Run(save_path,
|
||||
content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
|
||||
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
|
||||
save_path, content::DOWNLOAD_INTERRUPT_REASON_NONE);
|
||||
save_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,37 +7,33 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/ui/message_box.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
|
||||
using content::JavaScriptDialogType;
|
||||
using content::JavaScriptMessageType;
|
||||
|
||||
namespace atom {
|
||||
|
||||
AtomJavaScriptDialogManager::AtomJavaScriptDialogManager(
|
||||
api::WebContents* api_web_contents)
|
||||
: api_web_contents_(api_web_contents) {}
|
||||
|
||||
void AtomJavaScriptDialogManager::RunJavaScriptDialog(
|
||||
content::WebContents* web_contents,
|
||||
const GURL& origin_url,
|
||||
JavaScriptDialogType dialog_type,
|
||||
JavaScriptMessageType message_type,
|
||||
const base::string16& message_text,
|
||||
const base::string16& default_prompt_text,
|
||||
const DialogClosedCallback& callback,
|
||||
bool* did_suppress_message) {
|
||||
if (dialog_type != JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_ALERT &&
|
||||
dialog_type != JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_CONFIRM) {
|
||||
|
||||
if (message_type != JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_ALERT &&
|
||||
message_type != JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) {
|
||||
callback.Run(false, base::string16());
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> buttons = {"OK"};
|
||||
if (dialog_type == JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_CONFIRM) {
|
||||
if (message_type == JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) {
|
||||
buttons.push_back("Cancel");
|
||||
}
|
||||
|
||||
@@ -53,13 +49,13 @@ void AtomJavaScriptDialogManager::RunBeforeUnloadDialog(
|
||||
content::WebContents* web_contents,
|
||||
bool is_reload,
|
||||
const DialogClosedCallback& callback) {
|
||||
bool default_prevented = api_web_contents_->Emit("will-prevent-unload");
|
||||
callback.Run(default_prevented, base::string16());
|
||||
return;
|
||||
// FIXME(zcbenz): the |message_text| is removed, figure out what should we do.
|
||||
callback.Run(false, base::ASCIIToUTF16("This should not be displayed"));
|
||||
}
|
||||
|
||||
void AtomJavaScriptDialogManager::CancelDialogs(
|
||||
content::WebContents* web_contents,
|
||||
bool suppress_callbacks,
|
||||
bool reset_state) {
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,13 @@
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
class WebContents;
|
||||
}
|
||||
|
||||
class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager {
|
||||
public:
|
||||
explicit AtomJavaScriptDialogManager(api::WebContents* api_web_contents);
|
||||
|
||||
// content::JavaScriptDialogManager implementations.
|
||||
void RunJavaScriptDialog(
|
||||
content::WebContents* web_contents,
|
||||
const GURL& origin_url,
|
||||
content::JavaScriptDialogType dialog_type,
|
||||
content::JavaScriptMessageType javascript_message_type,
|
||||
const base::string16& message_text,
|
||||
const base::string16& default_prompt_text,
|
||||
const DialogClosedCallback& callback,
|
||||
@@ -33,13 +27,13 @@ class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager {
|
||||
bool is_reload,
|
||||
const DialogClosedCallback& callback) override;
|
||||
void CancelDialogs(content::WebContents* web_contents,
|
||||
bool suppress_callbacks,
|
||||
bool reset_state) override;
|
||||
|
||||
private:
|
||||
static void OnMessageBoxCallback(const DialogClosedCallback& callback,
|
||||
int code,
|
||||
bool checkbox_checked);
|
||||
api::WebContents* api_web_contents_;
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -131,7 +131,7 @@ int AtomPermissionManager::RequestPermissions(
|
||||
|
||||
auto web_contents =
|
||||
content::WebContents::FromRenderFrameHost(render_frame_host);
|
||||
int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>(
|
||||
int request_id = pending_requests_.Add(new PendingRequest(
|
||||
render_frame_host, permissions, response_callback));
|
||||
|
||||
for (size_t i = 0; i < permissions.size(); ++i) {
|
||||
@@ -187,6 +187,12 @@ blink::mojom::PermissionStatus AtomPermissionManager::GetPermissionStatus(
|
||||
return blink::mojom::PermissionStatus::GRANTED;
|
||||
}
|
||||
|
||||
void AtomPermissionManager::RegisterPermissionUsage(
|
||||
content::PermissionType permission,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin) {
|
||||
}
|
||||
|
||||
int AtomPermissionManager::SubscribePermissionStatusChange(
|
||||
content::PermissionType permission,
|
||||
const GURL& requesting_origin,
|
||||
|
||||
@@ -66,6 +66,9 @@ class AtomPermissionManager : public content::PermissionManager {
|
||||
content::PermissionType permission,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin) override;
|
||||
void RegisterPermissionUsage(content::PermissionType permission,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin) override;
|
||||
int SubscribePermissionStatusChange(
|
||||
content::PermissionType permission,
|
||||
const GURL& requesting_origin,
|
||||
@@ -76,7 +79,7 @@ class AtomPermissionManager : public content::PermissionManager {
|
||||
|
||||
private:
|
||||
class PendingRequest;
|
||||
using PendingRequestsMap = IDMap<std::unique_ptr<PendingRequest>>;
|
||||
using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>;
|
||||
|
||||
RequestHandler request_handler_;
|
||||
|
||||
|
||||
@@ -87,11 +87,8 @@ void OnPdfResourceIntercepted(
|
||||
// by the webui page.
|
||||
// chrome://pdf-viewer/index.html?src=https://somepage/123.pdf
|
||||
content::NavigationController::LoadURLParams params(
|
||||
GURL(base::StringPrintf(
|
||||
"%sindex.html?%s=%s",
|
||||
kPdfViewerUIOrigin,
|
||||
kPdfPluginSrc,
|
||||
net::EscapeUrlEncodedData(original_url.spec(), false).c_str())));
|
||||
GURL(base::StringPrintf("%sindex.html?%s=%s", kPdfViewerUIOrigin,
|
||||
kPdfPluginSrc, original_url.spec().c_str())));
|
||||
web_contents->GetController().LoadURLWithParams(params);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "net/base/escape.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -53,20 +52,11 @@ AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
|
||||
base::StringPairs toplevel_params;
|
||||
base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params);
|
||||
std::string stream_id, src;
|
||||
|
||||
const net::UnescapeRule::Type unescape_rules =
|
||||
net::UnescapeRule::SPACES | net::UnescapeRule::PATH_SEPARATORS |
|
||||
net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS |
|
||||
net::UnescapeRule::REPLACE_PLUS_WITH_SPACE;
|
||||
|
||||
for (const auto& param : toplevel_params) {
|
||||
if (param.first == kPdfPluginSrc) {
|
||||
src = net::UnescapeURLComponent(param.second, unescape_rules);
|
||||
src = param.second;
|
||||
}
|
||||
}
|
||||
if (url.has_ref()) {
|
||||
src = src + '#' + url.ref();
|
||||
}
|
||||
auto browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
||||
return new PdfViewerUI(browser_context, web_ui, src);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,6 @@ class Delegate {
|
||||
// An error happened.
|
||||
virtual void OnError(const std::string& error) {}
|
||||
|
||||
virtual void OnError(const std::string& error, const int code,
|
||||
const std::string& domain) {}
|
||||
|
||||
// Checking to see if there is an update
|
||||
virtual void OnCheckingForUpdate() {}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ void AutoUpdater::CheckForUpdates() {
|
||||
delegate->OnUpdateNotAvailable();
|
||||
}
|
||||
} error:^(NSError *error) {
|
||||
NSMutableString *failureString =
|
||||
NSMutableString* failureString =
|
||||
[NSMutableString stringWithString:error.localizedDescription];
|
||||
if (error.localizedFailureReason) {
|
||||
[failureString appendString:@": "];
|
||||
@@ -116,8 +116,7 @@ void AutoUpdater::CheckForUpdates() {
|
||||
[failureString appendString:@" "];
|
||||
[failureString appendString:error.localizedRecoverySuggestion];
|
||||
}
|
||||
delegate->OnError(base::SysNSStringToUTF8(failureString), error.code,
|
||||
base::SysNSStringToUTF8(error.domain));
|
||||
delegate->OnError(base::SysNSStringToUTF8(failureString));
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -126,8 +125,7 @@ void AutoUpdater::QuitAndInstall() {
|
||||
if (g_update_available) {
|
||||
[[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) {
|
||||
if (delegate)
|
||||
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription),
|
||||
error.code, base::SysNSStringToUTF8(error.domain));
|
||||
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription));
|
||||
}];
|
||||
} else {
|
||||
if (delegate)
|
||||
|
||||
@@ -11,28 +11,27 @@ namespace atom {
|
||||
void BridgeTaskRunner::MessageLoopIsReady() {
|
||||
auto message_loop = base::MessageLoop::current();
|
||||
CHECK(message_loop);
|
||||
for (TaskPair& task : tasks_) {
|
||||
for (const TaskPair& task : tasks_) {
|
||||
message_loop->task_runner()->PostDelayedTask(
|
||||
std::get<0>(task), std::move(std::get<1>(task)), std::get<2>(task));
|
||||
base::get<0>(task), base::get<1>(task), base::get<2>(task));
|
||||
}
|
||||
for (TaskPair& task : non_nestable_tasks_) {
|
||||
for (const TaskPair& task : non_nestable_tasks_) {
|
||||
message_loop->task_runner()->PostNonNestableDelayedTask(
|
||||
std::get<0>(task), std::move(std::get<1>(task)), std::get<2>(task));
|
||||
base::get<0>(task), base::get<1>(task), base::get<2>(task));
|
||||
}
|
||||
}
|
||||
|
||||
bool BridgeTaskRunner::PostDelayedTask(
|
||||
const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
const base::Closure& task,
|
||||
base::TimeDelta delay) {
|
||||
auto message_loop = base::MessageLoop::current();
|
||||
if (!message_loop) {
|
||||
tasks_.push_back(std::make_tuple(from_here, std::move(task), delay));
|
||||
tasks_.push_back(std::make_tuple(from_here, task, delay));
|
||||
return true;
|
||||
}
|
||||
|
||||
return message_loop->task_runner()->PostDelayedTask(
|
||||
from_here, std::move(task), delay);
|
||||
return message_loop->task_runner()->PostDelayedTask(from_here, task, delay);
|
||||
}
|
||||
|
||||
bool BridgeTaskRunner::RunsTasksOnCurrentThread() const {
|
||||
@@ -45,17 +44,16 @@ bool BridgeTaskRunner::RunsTasksOnCurrentThread() const {
|
||||
|
||||
bool BridgeTaskRunner::PostNonNestableDelayedTask(
|
||||
const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
const base::Closure& task,
|
||||
base::TimeDelta delay) {
|
||||
auto message_loop = base::MessageLoop::current();
|
||||
if (!message_loop) {
|
||||
non_nestable_tasks_.push_back(std::make_tuple(
|
||||
from_here, std::move(task), delay));
|
||||
non_nestable_tasks_.push_back(std::make_tuple(from_here, task, delay));
|
||||
return true;
|
||||
}
|
||||
|
||||
return message_loop->task_runner()->PostNonNestableDelayedTask(
|
||||
from_here, std::move(task), delay);
|
||||
from_here, task, delay);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -25,17 +25,17 @@ class BridgeTaskRunner : public base::SingleThreadTaskRunner {
|
||||
|
||||
// base::SingleThreadTaskRunner:
|
||||
bool PostDelayedTask(const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
const base::Closure& task,
|
||||
base::TimeDelta delay) override;
|
||||
bool RunsTasksOnCurrentThread() const override;
|
||||
bool PostNonNestableDelayedTask(
|
||||
const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
const base::Closure& task,
|
||||
base::TimeDelta delay) override;
|
||||
|
||||
private:
|
||||
using TaskPair = std::tuple<
|
||||
tracked_objects::Location, base::OnceClosure, base::TimeDelta>;
|
||||
tracked_objects::Location, base::Closure, base::TimeDelta>;
|
||||
std::vector<TaskPair> tasks_;
|
||||
std::vector<TaskPair> non_nestable_tasks_;
|
||||
|
||||
|
||||
@@ -171,12 +171,6 @@ void Browser::RequestLogin(
|
||||
observer.OnLogin(login_handler, *(request_details.get()));
|
||||
}
|
||||
|
||||
void Browser::PreMainMessageLoopRun() {
|
||||
for (BrowserObserver& observer : observers_) {
|
||||
observer.OnPreMainMessageLoopRun();
|
||||
}
|
||||
}
|
||||
|
||||
void Browser::NotifyAndShutdown() {
|
||||
if (is_shutdown_)
|
||||
return;
|
||||
@@ -219,11 +213,4 @@ void Browser::OnWindowAllClosed() {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
void Browser::NewWindowForTab() {
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnNewWindowForTab();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -119,32 +119,10 @@ class Browser : public WindowListObserver {
|
||||
// Returns the type name of the current user activity.
|
||||
std::string GetCurrentActivityType();
|
||||
|
||||
// Invalidates the current user activity.
|
||||
void InvalidateCurrentActivity();
|
||||
|
||||
// Updates the current user activity
|
||||
void UpdateCurrentActivity(const std::string& type,
|
||||
const base::DictionaryValue& user_info);
|
||||
|
||||
// Indicates that an user activity is about to be resumed.
|
||||
bool WillContinueUserActivity(const std::string& type);
|
||||
|
||||
// Indicates a failure to resume a Handoff activity.
|
||||
void DidFailToContinueUserActivity(const std::string& type,
|
||||
const std::string& error);
|
||||
|
||||
// Resumes an activity via hand-off.
|
||||
bool ContinueUserActivity(const std::string& type,
|
||||
const base::DictionaryValue& user_info);
|
||||
|
||||
// Indicates that an activity was continued on another device.
|
||||
void UserActivityWasContinued(const std::string& type,
|
||||
const base::DictionaryValue& user_info);
|
||||
|
||||
// Gives an oportunity to update the Handoff payload.
|
||||
bool UpdateUserActivityState(const std::string& type,
|
||||
const base::DictionaryValue& user_info);
|
||||
|
||||
// Bounce the dock icon.
|
||||
enum BounceType {
|
||||
BOUNCE_CRITICAL = 0,
|
||||
@@ -205,11 +183,6 @@ class Browser : public WindowListObserver {
|
||||
// Tell the application to open a url.
|
||||
void OpenURL(const std::string& url);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
// Tell the application to create a new window for a tab.
|
||||
void NewWindowForTab();
|
||||
#endif // defined(OS_MACOSX)
|
||||
|
||||
// Tell the application that application is activated with visible/invisible
|
||||
// windows.
|
||||
void Activate(bool has_visible_windows);
|
||||
@@ -224,8 +197,6 @@ class Browser : public WindowListObserver {
|
||||
void RequestLogin(LoginHandler* login_handler,
|
||||
std::unique_ptr<base::DictionaryValue> request_details);
|
||||
|
||||
void PreMainMessageLoopRun();
|
||||
|
||||
void AddObserver(BrowserObserver* obs) {
|
||||
observers_.AddObserver(obs);
|
||||
}
|
||||
|
||||
@@ -4,62 +4,16 @@
|
||||
|
||||
#include "atom/browser/browser.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/atom_version.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/process/launch.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
|
||||
#if defined(USE_X11)
|
||||
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
||||
#include "chrome/browser/ui/libgtkui/unity_service.h"
|
||||
#endif
|
||||
|
||||
namespace atom {
|
||||
|
||||
const char kXdgSettings[] = "xdg-settings";
|
||||
const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler";
|
||||
|
||||
bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code) {
|
||||
*exit_code = EXIT_FAILURE;
|
||||
int devnull = open("/dev/null", O_RDONLY);
|
||||
if (devnull < 0) return false;
|
||||
|
||||
base::LaunchOptions options;
|
||||
|
||||
base::FileHandleMappingVector remap;
|
||||
remap.push_back(std::make_pair(devnull, STDIN_FILENO));
|
||||
options.fds_to_remap = &remap;
|
||||
|
||||
base::Process process = base::LaunchProcess(argv, options);
|
||||
close(devnull);
|
||||
|
||||
if (!process.IsValid()) return false;
|
||||
return process.WaitForExit(exit_code);
|
||||
}
|
||||
|
||||
bool SetDefaultWebClient(const std::string& protocol) {
|
||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||
|
||||
std::vector<std::string> argv;
|
||||
argv.push_back(kXdgSettings);
|
||||
argv.push_back("set");
|
||||
if (!protocol.empty()) {
|
||||
argv.push_back(kXdgSettingsDefaultSchemeHandler);
|
||||
argv.push_back(protocol);
|
||||
}
|
||||
argv.push_back(libgtkui::GetDesktopName(env.get()));
|
||||
|
||||
int exit_code;
|
||||
bool ran_ok = LaunchXdgUtility(argv, &exit_code);
|
||||
return ran_ok && exit_code == EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void Browser::Focus() {
|
||||
// Focus on the first visible window.
|
||||
for (const auto& window : WindowList::GetWindows()) {
|
||||
@@ -79,40 +33,18 @@ void Browser::ClearRecentDocuments() {
|
||||
void Browser::SetAppUserModelID(const base::string16& name) {
|
||||
}
|
||||
|
||||
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
||||
mate::Arguments* args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
|
||||
mate::Arguments* args) {
|
||||
return SetDefaultWebClient(protocol);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Browser::IsDefaultProtocolClient(const std::string& protocol,
|
||||
mate::Arguments* args) {
|
||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||
|
||||
if (protocol.empty()) return false;
|
||||
|
||||
std::vector<std::string> argv;
|
||||
argv.push_back(kXdgSettings);
|
||||
argv.push_back("check");
|
||||
argv.push_back(kXdgSettingsDefaultSchemeHandler);
|
||||
argv.push_back(protocol);
|
||||
argv.push_back(libgtkui::GetDesktopName(env.get()));
|
||||
|
||||
std::string reply;
|
||||
int success_code;
|
||||
bool ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv),
|
||||
&reply, &success_code);
|
||||
|
||||
if (!ran_ok || success_code != EXIT_SUCCESS) return false;
|
||||
|
||||
// Allow any reply that starts with "yes".
|
||||
return base::StartsWith(reply, "yes", base::CompareCase::SENSITIVE)
|
||||
? true
|
||||
: false;
|
||||
}
|
||||
|
||||
// Todo implement
|
||||
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
||||
mate::Arguments* args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,30 +144,6 @@ std::string Browser::GetCurrentActivityType() {
|
||||
return base::SysNSStringToUTF8(userActivity.activityType);
|
||||
}
|
||||
|
||||
void Browser::InvalidateCurrentActivity() {
|
||||
[[AtomApplication sharedApplication] invalidateCurrentActivity];
|
||||
}
|
||||
|
||||
void Browser::UpdateCurrentActivity(const std::string& type,
|
||||
const base::DictionaryValue& user_info) {
|
||||
[[AtomApplication sharedApplication]
|
||||
updateCurrentActivity:base::SysUTF8ToNSString(type)
|
||||
withUserInfo:DictionaryValueToNSDictionary(user_info)];
|
||||
}
|
||||
|
||||
bool Browser::WillContinueUserActivity(const std::string& type) {
|
||||
bool prevent_default = false;
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnWillContinueUserActivity(&prevent_default, type);
|
||||
return prevent_default;
|
||||
}
|
||||
|
||||
void Browser::DidFailToContinueUserActivity(const std::string& type,
|
||||
const std::string& error) {
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnDidFailToContinueUserActivity(type, error);
|
||||
}
|
||||
|
||||
bool Browser::ContinueUserActivity(const std::string& type,
|
||||
const base::DictionaryValue& user_info) {
|
||||
bool prevent_default = false;
|
||||
@@ -176,20 +152,6 @@ bool Browser::ContinueUserActivity(const std::string& type,
|
||||
return prevent_default;
|
||||
}
|
||||
|
||||
void Browser::UserActivityWasContinued(const std::string& type,
|
||||
const base::DictionaryValue& user_info) {
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnUserActivityWasContinued(type, user_info);
|
||||
}
|
||||
|
||||
bool Browser::UpdateUserActivityState(const std::string& type,
|
||||
const base::DictionaryValue& user_info) {
|
||||
bool prevent_default = false;
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnUpdateUserActivityState(&prevent_default, type, user_info);
|
||||
return prevent_default;
|
||||
}
|
||||
|
||||
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
||||
const LoginItemSettings& options) {
|
||||
LoginItemSettings settings;
|
||||
|
||||
@@ -55,34 +55,12 @@ class BrowserObserver {
|
||||
// The browser's accessibility suppport has changed.
|
||||
virtual void OnAccessibilitySupportChanged() {}
|
||||
|
||||
// The app message loop is ready
|
||||
virtual void OnPreMainMessageLoopRun() {}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
// The browser wants to report that an user activity will resume. (macOS only)
|
||||
virtual void OnWillContinueUserActivity(
|
||||
bool* prevent_default,
|
||||
const std::string& type) {}
|
||||
// The browser wants to report an user activity resuming error. (macOS only)
|
||||
virtual void OnDidFailToContinueUserActivity(
|
||||
const std::string& type,
|
||||
const std::string& error) {}
|
||||
// The browser wants to resume a user activity via handoff. (macOS only)
|
||||
virtual void OnContinueUserActivity(
|
||||
bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) {}
|
||||
// The browser wants to notify that an user activity was resumed. (macOS only)
|
||||
virtual void OnUserActivityWasContinued(
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) {}
|
||||
// The browser wants to update an user activity payload. (macOS only)
|
||||
virtual void OnUpdateUserActivityState(
|
||||
bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) {}
|
||||
// User clicked the native macOS new tab button. (macOS only)
|
||||
virtual void OnNewWindowForTab() {}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (c) 2017 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/child_web_contents_tracker.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
std::unordered_set<content::WebContents*> g_child_web_contents;
|
||||
|
||||
} // namespace
|
||||
|
||||
ChildWebContentsTracker::ChildWebContentsTracker(
|
||||
content::WebContents* web_contents)
|
||||
: content::WebContentsObserver(web_contents) {
|
||||
g_child_web_contents.insert(web_contents);
|
||||
}
|
||||
|
||||
bool ChildWebContentsTracker::IsChildWebContents(
|
||||
content::WebContents* web_contents) {
|
||||
return g_child_web_contents.find(web_contents) != g_child_web_contents.end();
|
||||
}
|
||||
|
||||
void ChildWebContentsTracker::WebContentsDestroyed() {
|
||||
g_child_web_contents.erase(web_contents());
|
||||
delete this;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) 2017 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_
|
||||
#define ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_
|
||||
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
// ChildWebContentsTracker tracks child WebContents
|
||||
// created by native `window.open()`
|
||||
class ChildWebContentsTracker : public content::WebContentsObserver {
|
||||
public:
|
||||
explicit ChildWebContentsTracker(content::WebContents* web_contents);
|
||||
static bool IsChildWebContents(content::WebContents* web_contents);
|
||||
|
||||
protected:
|
||||
void WebContentsDestroyed() override;
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_
|
||||
@@ -9,12 +9,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
#include "atom/browser/web_dialog_helper.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "chrome/browser/printing/print_preview_message_handler.h"
|
||||
#include "chrome/browser/printing/print_view_manager_basic.h"
|
||||
#include "chrome/browser/ssl/security_state_tab_helper.h"
|
||||
@@ -150,8 +150,7 @@ bool IsDevToolsFileSystemAdded(
|
||||
} // namespace
|
||||
|
||||
CommonWebContentsDelegate::CommonWebContentsDelegate()
|
||||
: ignore_menu_shortcuts_(false),
|
||||
html_fullscreen_(false),
|
||||
: html_fullscreen_(false),
|
||||
native_fullscreen_(false),
|
||||
devtools_file_system_indexer_(new DevToolsFileSystemIndexer) {
|
||||
}
|
||||
@@ -231,6 +230,15 @@ bool CommonWebContentsDelegate::CanOverscrollContent() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
content::JavaScriptDialogManager*
|
||||
CommonWebContentsDelegate::GetJavaScriptDialogManager(
|
||||
content::WebContents* source) {
|
||||
if (!dialog_manager_)
|
||||
dialog_manager_.reset(new AtomJavaScriptDialogManager);
|
||||
|
||||
return dialog_manager_.get();
|
||||
}
|
||||
|
||||
content::ColorChooser* CommonWebContentsDelegate::OpenColorChooser(
|
||||
content::WebContents* web_contents,
|
||||
SkColor color,
|
||||
@@ -301,7 +309,7 @@ void CommonWebContentsDelegate::DevToolsSaveToFile(
|
||||
settings.title = url;
|
||||
settings.default_path = base::FilePath::FromUTF8Unsafe(url);
|
||||
if (!file_dialog::ShowSaveDialog(settings, &path)) {
|
||||
base::Value url_value(url);
|
||||
base::StringValue url_value(url);
|
||||
web_contents_->CallClientFunction(
|
||||
"DevToolsAPI.canceledSaveURL", &url_value, nullptr, nullptr);
|
||||
return;
|
||||
@@ -385,7 +393,7 @@ void CommonWebContentsDelegate::DevToolsAddFileSystem(
|
||||
auto pref_service = GetPrefService(GetDevToolsWebContents());
|
||||
DictionaryPrefUpdate update(pref_service, prefs::kDevToolsFileSystemPaths);
|
||||
update.Get()->SetWithoutPathExpansion(
|
||||
path.AsUTF8Unsafe(), base::MakeUnique<base::Value>());
|
||||
path.AsUTF8Unsafe(), base::Value::CreateNullValue());
|
||||
|
||||
web_contents_->CallClientFunction("DevToolsAPI.fileSystemAdded",
|
||||
file_system_value.get(),
|
||||
@@ -405,7 +413,7 @@ void CommonWebContentsDelegate::DevToolsRemoveFileSystem(
|
||||
DictionaryPrefUpdate update(pref_service, prefs::kDevToolsFileSystemPaths);
|
||||
update.Get()->RemoveWithoutPathExpansion(path, nullptr);
|
||||
|
||||
base::Value file_system_path_value(path);
|
||||
base::StringValue file_system_path_value(path);
|
||||
web_contents_->CallClientFunction("DevToolsAPI.fileSystemRemoved",
|
||||
&file_system_path_value,
|
||||
nullptr, nullptr);
|
||||
@@ -469,7 +477,7 @@ void CommonWebContentsDelegate::DevToolsSearchInPath(
|
||||
void CommonWebContentsDelegate::OnDevToolsSaveToFile(
|
||||
const std::string& url) {
|
||||
// Notify DevTools.
|
||||
base::Value url_value(url);
|
||||
base::StringValue url_value(url);
|
||||
web_contents_->CallClientFunction(
|
||||
"DevToolsAPI.savedURL", &url_value, nullptr, nullptr);
|
||||
}
|
||||
@@ -477,7 +485,7 @@ void CommonWebContentsDelegate::OnDevToolsSaveToFile(
|
||||
void CommonWebContentsDelegate::OnDevToolsAppendToFile(
|
||||
const std::string& url) {
|
||||
// Notify DevTools.
|
||||
base::Value url_value(url);
|
||||
base::StringValue url_value(url);
|
||||
web_contents_->CallClientFunction(
|
||||
"DevToolsAPI.appendedToURL", &url_value, nullptr, nullptr);
|
||||
}
|
||||
@@ -486,9 +494,9 @@ void CommonWebContentsDelegate::OnDevToolsIndexingWorkCalculated(
|
||||
int request_id,
|
||||
const std::string& file_system_path,
|
||||
int total_work) {
|
||||
base::Value request_id_value(request_id);
|
||||
base::Value file_system_path_value(file_system_path);
|
||||
base::Value total_work_value(total_work);
|
||||
base::FundamentalValue request_id_value(request_id);
|
||||
base::StringValue file_system_path_value(file_system_path);
|
||||
base::FundamentalValue total_work_value(total_work);
|
||||
web_contents_->CallClientFunction("DevToolsAPI.indexingTotalWorkCalculated",
|
||||
&request_id_value,
|
||||
&file_system_path_value,
|
||||
@@ -499,9 +507,9 @@ void CommonWebContentsDelegate::OnDevToolsIndexingWorked(
|
||||
int request_id,
|
||||
const std::string& file_system_path,
|
||||
int worked) {
|
||||
base::Value request_id_value(request_id);
|
||||
base::Value file_system_path_value(file_system_path);
|
||||
base::Value worked_value(worked);
|
||||
base::FundamentalValue request_id_value(request_id);
|
||||
base::StringValue file_system_path_value(file_system_path);
|
||||
base::FundamentalValue worked_value(worked);
|
||||
web_contents_->CallClientFunction("DevToolsAPI.indexingWorked",
|
||||
&request_id_value,
|
||||
&file_system_path_value,
|
||||
@@ -512,8 +520,8 @@ void CommonWebContentsDelegate::OnDevToolsIndexingDone(
|
||||
int request_id,
|
||||
const std::string& file_system_path) {
|
||||
devtools_indexing_jobs_.erase(request_id);
|
||||
base::Value request_id_value(request_id);
|
||||
base::Value file_system_path_value(file_system_path);
|
||||
base::FundamentalValue request_id_value(request_id);
|
||||
base::StringValue file_system_path_value(file_system_path);
|
||||
web_contents_->CallClientFunction("DevToolsAPI.indexingDone",
|
||||
&request_id_value,
|
||||
&file_system_path_value,
|
||||
@@ -528,8 +536,8 @@ void CommonWebContentsDelegate::OnDevToolsSearchCompleted(
|
||||
for (const auto& file_path : file_paths) {
|
||||
file_paths_value.AppendString(file_path);
|
||||
}
|
||||
base::Value request_id_value(request_id);
|
||||
base::Value file_system_path_value(file_system_path);
|
||||
base::FundamentalValue request_id_value(request_id);
|
||||
base::StringValue file_system_path_value(file_system_path);
|
||||
web_contents_->CallClientFunction("DevToolsAPI.searchCompleted",
|
||||
&request_id_value,
|
||||
&file_system_path_value,
|
||||
|
||||
@@ -20,6 +20,7 @@ using brightray::DevToolsFileSystemIndexer;
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
class AtomJavaScriptDialogManager;
|
||||
class NativeWindow;
|
||||
class WebDialogHelper;
|
||||
|
||||
@@ -53,10 +54,6 @@ class CommonWebContentsDelegate
|
||||
|
||||
NativeWindow* owner_window() const { return owner_window_.get(); }
|
||||
|
||||
void set_ignore_menu_shortcuts(bool ignore) {
|
||||
ignore_menu_shortcuts_ = ignore;
|
||||
}
|
||||
|
||||
bool is_html_fullscreen() const { return html_fullscreen_; }
|
||||
|
||||
protected:
|
||||
@@ -65,6 +62,8 @@ class CommonWebContentsDelegate
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) override;
|
||||
bool CanOverscrollContent() const override;
|
||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
||||
content::WebContents* source) override;
|
||||
content::ColorChooser* OpenColorChooser(
|
||||
content::WebContents* web_contents,
|
||||
SkColor color,
|
||||
@@ -141,8 +140,6 @@ class CommonWebContentsDelegate
|
||||
// The window that this WebContents belongs to.
|
||||
base::WeakPtr<NativeWindow> owner_window_;
|
||||
|
||||
bool ignore_menu_shortcuts_;
|
||||
|
||||
// Whether window is fullscreened by HTML5 api.
|
||||
bool html_fullscreen_;
|
||||
|
||||
@@ -150,6 +147,7 @@ class CommonWebContentsDelegate
|
||||
bool native_fullscreen_;
|
||||
|
||||
std::unique_ptr<WebDialogHelper> web_dialog_helper_;
|
||||
std::unique_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||
scoped_refptr<DevToolsFileSystemIndexer> devtools_file_system_indexer_;
|
||||
|
||||
// Make sure BrowserContext is alwasys destroyed after WebContents.
|
||||
|
||||
@@ -20,23 +20,21 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
if (event.skip_in_browser ||
|
||||
event.GetType() == content::NativeWebKeyboardEvent::kChar)
|
||||
event.type == content::NativeWebKeyboardEvent::Char)
|
||||
return;
|
||||
|
||||
// Escape exits tabbed fullscreen mode.
|
||||
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
|
||||
if (event.windowsKeyCode == ui::VKEY_ESCAPE && is_html_fullscreen())
|
||||
ExitFullscreenModeForTab(source);
|
||||
|
||||
if (!ignore_menu_shortcuts_) {
|
||||
// Send the event to the menu before sending it to the window
|
||||
if (event.os_event.type == NSKeyDown &&
|
||||
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
|
||||
return;
|
||||
// Send the event to the menu before sending it to the window
|
||||
if (event.os_event.type == NSKeyDown &&
|
||||
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
|
||||
return;
|
||||
|
||||
if (event.os_event.window &&
|
||||
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
|
||||
[event.os_event.window redispatchKeyEvent:event.os_event];
|
||||
}
|
||||
if (event.os_event.window &&
|
||||
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
|
||||
[event.os_event.window redispatchKeyEvent:event.os_event];
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -19,11 +19,11 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
// Escape exits tabbed fullscreen mode.
|
||||
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
|
||||
if (event.windowsKeyCode == ui::VKEY_ESCAPE && is_html_fullscreen())
|
||||
ExitFullscreenModeForTab(source);
|
||||
|
||||
// Let the NativeWindow handle other parts.
|
||||
if (!ignore_menu_shortcuts_ && owner_window())
|
||||
if (owner_window())
|
||||
owner_window()->HandleKeyboardEvent(source, event);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "gin/array_buffer.h"
|
||||
#include "gin/v8_initializer.h"
|
||||
@@ -19,7 +18,6 @@ namespace atom {
|
||||
|
||||
JavascriptEnvironment::JavascriptEnvironment()
|
||||
: initialized_(Initialize()),
|
||||
isolate_holder_(base::ThreadTaskRunnerHandle::Get()),
|
||||
isolate_(isolate_holder_.isolate()),
|
||||
isolate_scope_(isolate_),
|
||||
locker_(isolate_),
|
||||
|
||||
@@ -33,7 +33,7 @@ class BluetoothChooser : public content::BluetoothChooser {
|
||||
bool is_gatt_connected,
|
||||
bool is_paired,
|
||||
int signal_strength_level) override;
|
||||
void RemoveDevice(const std::string& device_id);
|
||||
void RemoveDevice(const std::string& device_id) override;
|
||||
|
||||
private:
|
||||
std::vector<DeviceInfo> device_list_;
|
||||
|
||||
@@ -15,12 +15,12 @@ LayeredResourceHandler::LayeredResourceHandler(
|
||||
|
||||
LayeredResourceHandler::~LayeredResourceHandler() {}
|
||||
|
||||
void LayeredResourceHandler::OnResponseStarted(
|
||||
bool LayeredResourceHandler::OnResponseStarted(
|
||||
content::ResourceResponse* response,
|
||||
std::unique_ptr<content::ResourceController> controller) {
|
||||
bool* defer) {
|
||||
if (delegate_)
|
||||
delegate_->OnResponseStarted(response);
|
||||
next_handler_->OnResponseStarted(response, std::move(controller));
|
||||
return next_handler_->OnResponseStarted(response, defer);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -26,9 +26,8 @@ class LayeredResourceHandler : public content::LayeredResourceHandler {
|
||||
~LayeredResourceHandler() override;
|
||||
|
||||
// content::LayeredResourceHandler:
|
||||
void OnResponseStarted(
|
||||
content::ResourceResponse* response,
|
||||
std::unique_ptr<content::ResourceController> controller) override;
|
||||
bool OnResponseStarted(content::ResourceResponse* response,
|
||||
bool* defer) override;
|
||||
|
||||
private:
|
||||
Delegate* delegate_;
|
||||
|
||||
@@ -6,13 +6,10 @@
|
||||
#import "base/mac/scoped_nsobject.h"
|
||||
|
||||
@interface AtomApplication : NSApplication<CrAppProtocol,
|
||||
CrAppControlProtocol,
|
||||
NSUserActivityDelegate> {
|
||||
CrAppControlProtocol> {
|
||||
@private
|
||||
BOOL handlingSendEvent_;
|
||||
base::scoped_nsobject<NSUserActivity> currentActivity_;
|
||||
NSCondition* handoffLock_;
|
||||
BOOL updateReceived_;
|
||||
}
|
||||
|
||||
+ (AtomApplication*)sharedApplication;
|
||||
@@ -27,8 +24,5 @@
|
||||
- (void)setCurrentActivity:(NSString*)type
|
||||
withUserInfo:(NSDictionary*)userInfo
|
||||
withWebpageURL:(NSURL*)webpageURL;
|
||||
- (void)invalidateCurrentActivity;
|
||||
- (void)updateCurrentActivity:(NSString*)type
|
||||
withUserInfo:(NSDictionary*)userInfo;
|
||||
|
||||
@end
|
||||
|
||||
@@ -4,23 +4,11 @@
|
||||
|
||||
#import "atom/browser/mac/atom_application.h"
|
||||
|
||||
#include "atom/browser/mac/dict_util.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "base/auto_reset.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "content/public/browser/browser_accessibility_state.h"
|
||||
|
||||
namespace {
|
||||
|
||||
inline void dispatch_sync_main(dispatch_block_t block) {
|
||||
if ([NSThread isMainThread])
|
||||
block();
|
||||
else
|
||||
dispatch_sync(dispatch_get_main_queue(), block);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@implementation AtomApplication
|
||||
|
||||
+ (AtomApplication*)sharedApplication {
|
||||
@@ -47,78 +35,19 @@ inline void dispatch_sync_main(dispatch_block_t block) {
|
||||
[[NSUserActivity alloc] initWithActivityType:type]);
|
||||
[currentActivity_ setUserInfo:userInfo];
|
||||
[currentActivity_ setWebpageURL:webpageURL];
|
||||
[currentActivity_ setDelegate:self];
|
||||
[currentActivity_ becomeCurrent];
|
||||
[currentActivity_ setNeedsSave:YES];
|
||||
}
|
||||
|
||||
- (NSUserActivity*)getCurrentActivity {
|
||||
return currentActivity_.get();
|
||||
}
|
||||
|
||||
- (void)invalidateCurrentActivity {
|
||||
if (currentActivity_) {
|
||||
[currentActivity_ invalidate];
|
||||
currentActivity_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateCurrentActivity:(NSString*)type
|
||||
withUserInfo:(NSDictionary*)userInfo {
|
||||
if (currentActivity_) {
|
||||
[currentActivity_ addUserInfoEntriesFromDictionary:userInfo];
|
||||
}
|
||||
|
||||
[handoffLock_ lock];
|
||||
updateReceived_ = YES;
|
||||
[handoffLock_ signal];
|
||||
[handoffLock_ unlock];
|
||||
}
|
||||
|
||||
- (void)userActivityWillSave:(NSUserActivity *)userActivity {
|
||||
__block BOOL shouldWait = NO;
|
||||
dispatch_sync_main(^{
|
||||
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
|
||||
std::unique_ptr<base::DictionaryValue> user_info =
|
||||
atom::NSDictionaryToDictionaryValue(userActivity.userInfo);
|
||||
|
||||
atom::Browser* browser = atom::Browser::Get();
|
||||
shouldWait = browser->UpdateUserActivityState(activity_type, *user_info) ? YES : NO;
|
||||
});
|
||||
|
||||
if (shouldWait) {
|
||||
[handoffLock_ lock];
|
||||
updateReceived_ = NO;
|
||||
while (!updateReceived_) {
|
||||
BOOL isSignaled = [handoffLock_ waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
|
||||
if (!isSignaled) break;
|
||||
}
|
||||
[handoffLock_ unlock];
|
||||
}
|
||||
|
||||
[userActivity setNeedsSave:YES];
|
||||
}
|
||||
|
||||
- (void)userActivityWasContinued:(NSUserActivity *)userActivity {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
|
||||
std::unique_ptr<base::DictionaryValue> user_info =
|
||||
atom::NSDictionaryToDictionaryValue(userActivity.userInfo);
|
||||
|
||||
atom::Browser* browser = atom::Browser::Get();
|
||||
browser->UserActivityWasContinued(activity_type, *user_info);
|
||||
});
|
||||
[userActivity setNeedsSave:YES];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib {
|
||||
[[NSAppleEventManager sharedAppleEventManager]
|
||||
setEventHandler:self
|
||||
andSelector:@selector(handleURLEvent:withReplyEvent:)
|
||||
forEventClass:kInternetEventClass
|
||||
andEventID:kAEGetURL];
|
||||
|
||||
handoffLock_ = [NSCondition new];
|
||||
}
|
||||
|
||||
- (void)handleURLEvent:(NSAppleEventDescriptor*)event
|
||||
@@ -143,9 +72,6 @@ inline void dispatch_sync_main(dispatch_block_t block) {
|
||||
bool enableAccessibility = ([self voiceOverEnabled] && [value boolValue]);
|
||||
[self updateAccessibilityEnabled:enableAccessibility];
|
||||
}
|
||||
else if ([attribute isEqualToString:@"AXManualAccessibility"]) {
|
||||
[self updateAccessibilityEnabled:[value boolValue]];
|
||||
}
|
||||
return [super accessibilitySetValue:value forAttribute:attribute];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,36 +7,9 @@
|
||||
#import "atom/browser/mac/atom_application.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/mac/dict_util.h"
|
||||
#include "base/allocator/allocator_shim.h"
|
||||
#include "base/allocator/features.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
#include "base/mac/scoped_objc_class_swizzler.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
|
||||
#if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
|
||||
// On macOS 10.12, the IME system attempts to allocate a 2^64 size buffer,
|
||||
// which would typically cause an OOM crash. To avoid this, the problematic
|
||||
// method is swizzled out and the make-OOM-fatal bit is disabled for the
|
||||
// duration of the original call. https://crbug.com/654695
|
||||
static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
|
||||
@interface OOMDisabledIMKInputSession : NSObject
|
||||
@end
|
||||
@implementation OOMDisabledIMKInputSession
|
||||
- (void)_coreAttributesFromRange:(NSRange)range
|
||||
whichAttributes:(long long)attributes
|
||||
completionHandler:(void (^)(void))block {
|
||||
// The allocator flag is per-process, so other threads may temporarily
|
||||
// not have fatal OOM occur while this method executes, but it is better
|
||||
// than crashing when using IME.
|
||||
base::allocator::SetCallNewHandlerOnMallocFailure(false);
|
||||
g_swizzle_imk_input_session->GetOriginalImplementation()(self, _cmd, range,
|
||||
attributes, block);
|
||||
base::allocator::SetCallNewHandlerOnMallocFailure(true);
|
||||
}
|
||||
@end
|
||||
#endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
|
||||
|
||||
@implementation AtomApplicationDelegate
|
||||
|
||||
- (void)setApplicationDockMenu:(atom::AtomMenuModel*)model {
|
||||
@@ -62,16 +35,6 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
|
||||
std::unique_ptr<base::DictionaryValue> empty_info(new base::DictionaryValue);
|
||||
atom::Browser::Get()->DidFinishLaunching(*empty_info);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
|
||||
// Disable fatal OOM to hack around an OS bug https://crbug.com/654695.
|
||||
if (base::mac::IsOS10_12()) {
|
||||
g_swizzle_imk_input_session = new base::mac::ScopedObjCClassSwizzler(
|
||||
NSClassFromString(@"IMKInputSession"),
|
||||
[OOMDisabledIMKInputSession class],
|
||||
@selector(_coreAttributesFromRange:whichAttributes:completionHandler:));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
|
||||
@@ -118,23 +81,4 @@ continueUserActivity:(NSUserActivity*)userActivity
|
||||
return browser->ContinueUserActivity(activity_type, *user_info) ? YES : NO;
|
||||
}
|
||||
|
||||
- (BOOL)application:(NSApplication*)application willContinueUserActivityWithType:(NSString*)userActivityType {
|
||||
std::string activity_type(base::SysNSStringToUTF8(userActivityType));
|
||||
|
||||
atom::Browser* browser = atom::Browser::Get();
|
||||
return browser->WillContinueUserActivity(activity_type) ? YES : NO;
|
||||
}
|
||||
|
||||
- (void)application:(NSApplication*)application didFailToContinueUserActivityWithType:(NSString*)userActivityType error:(NSError*)error {
|
||||
std::string activity_type(base::SysNSStringToUTF8(userActivityType));
|
||||
std::string error_message(base::SysNSStringToUTF8([error localizedDescription]));
|
||||
|
||||
atom::Browser* browser = atom::Browser::Get();
|
||||
browser->DidFailToContinueUserActivity(activity_type, error_message);
|
||||
}
|
||||
|
||||
- (IBAction)newWindowForTab:(id)sender {
|
||||
atom::Browser::Get()->NewWindowForTab();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "atom/browser/mac/dict_util.h"
|
||||
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
|
||||
@@ -46,14 +45,14 @@ std::unique_ptr<base::ListValue> NSArrayToListValue(NSArray* arr) {
|
||||
if (sub_arr)
|
||||
result->Append(std::move(sub_arr));
|
||||
else
|
||||
result->Append(base::MakeUnique<base::Value>());
|
||||
result->Append(base::Value::CreateNullValue());
|
||||
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
||||
std::unique_ptr<base::DictionaryValue> sub_dict =
|
||||
NSDictionaryToDictionaryValue(value);
|
||||
if (sub_dict)
|
||||
result->Append(std::move(sub_dict));
|
||||
else
|
||||
result->Append(base::MakeUnique<base::Value>());
|
||||
result->Append(base::Value::CreateNullValue());
|
||||
} else {
|
||||
result->AppendString(base::SysNSStringToUTF8([value description]));
|
||||
}
|
||||
@@ -105,7 +104,7 @@ std::unique_ptr<base::DictionaryValue> NSDictionaryToDictionaryValue(
|
||||
result->SetWithoutPathExpansion(str_key, std::move(sub_arr));
|
||||
else
|
||||
result->SetWithoutPathExpansion(str_key,
|
||||
base::MakeUnique<base::Value>());
|
||||
base::Value::CreateNullValue());
|
||||
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
||||
std::unique_ptr<base::DictionaryValue> sub_dict =
|
||||
NSDictionaryToDictionaryValue(value);
|
||||
@@ -113,7 +112,7 @@ std::unique_ptr<base::DictionaryValue> NSDictionaryToDictionaryValue(
|
||||
result->SetWithoutPathExpansion(str_key, std::move(sub_dict));
|
||||
else
|
||||
result->SetWithoutPathExpansion(str_key,
|
||||
base::MakeUnique<base::Value>());
|
||||
base::Value::CreateNullValue());
|
||||
} else {
|
||||
result->SetStringWithoutPathExpansion(
|
||||
str_key,
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/native_browser_view.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
#ifndef ATOM_BROWSER_NATIVE_BROWSER_VIEW_H_
|
||||
#define ATOM_BROWSER_NATIVE_BROWSER_VIEW_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "base/macros.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
||||
@@ -21,6 +18,10 @@ class Rect;
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
class WebContents;
|
||||
}
|
||||
|
||||
enum AutoResizeFlags {
|
||||
kAutoResizeWidth = 0x1,
|
||||
kAutoResizeHeight = 0x2,
|
||||
@@ -41,10 +42,6 @@ class NativeBrowserView {
|
||||
virtual void SetBounds(const gfx::Rect& bounds) = 0;
|
||||
virtual void SetBackgroundColor(SkColor color) = 0;
|
||||
|
||||
// Called when the window needs to update its draggable region.
|
||||
virtual void UpdateDraggableRegions(
|
||||
const std::vector<gfx::Rect>& system_drag_exclude_areas) {}
|
||||
|
||||
protected:
|
||||
explicit NativeBrowserView(
|
||||
brightray::InspectableWebContentsView* web_contents_view);
|
||||
|
||||
@@ -6,11 +6,8 @@
|
||||
#define ATOM_BROWSER_NATIVE_BROWSER_VIEW_MAC_H_
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/native_browser_view.h"
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -23,8 +20,6 @@ class NativeBrowserViewMac : public NativeBrowserView {
|
||||
void SetAutoResizeFlags(uint8_t flags) override;
|
||||
void SetBounds(const gfx::Rect& bounds) override;
|
||||
void SetBackgroundColor(SkColor color) override;
|
||||
void UpdateDraggableRegions(
|
||||
const std::vector<gfx::Rect>& system_drag_exclude_areas) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(NativeBrowserViewMac);
|
||||
|
||||
@@ -12,147 +12,6 @@
|
||||
const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||
NSViewMaxXMargin | NSViewMinYMargin;
|
||||
|
||||
@interface DragRegionView : NSView
|
||||
|
||||
@property (assign) NSPoint initialLocation;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSWindow ()
|
||||
- (void)performWindowDragWithEvent:(NSEvent *)event;
|
||||
@end
|
||||
|
||||
@implementation DragRegionView
|
||||
|
||||
- (BOOL)mouseDownCanMoveWindow
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSView *)hitTest:(NSPoint)aPoint
|
||||
{
|
||||
// Pass-through events that don't hit one of the exclusion zones
|
||||
for (NSView *exlusion_zones in [self subviews]) {
|
||||
if ([exlusion_zones hitTest:aPoint])
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent *)event
|
||||
{
|
||||
if ([self.window respondsToSelector:@selector(performWindowDragWithEvent)]) {
|
||||
// According to Google, using performWindowDragWithEvent:
|
||||
// does not generate a NSWindowWillMoveNotification. Hence post one.
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:NSWindowWillMoveNotification
|
||||
object:self];
|
||||
|
||||
[self.window performWindowDragWithEvent:event];
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.window.styleMask & NSFullScreenWindowMask) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.initialLocation = [event locationInWindow];
|
||||
}
|
||||
|
||||
- (void)mouseDragged:(NSEvent *)theEvent
|
||||
{
|
||||
if ([self.window respondsToSelector:@selector(performWindowDragWithEvent)]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.window.styleMask & NSFullScreenWindowMask) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSPoint currentLocation = [NSEvent mouseLocation];
|
||||
NSPoint newOrigin;
|
||||
|
||||
NSRect screenFrame = [[NSScreen mainScreen] frame];
|
||||
NSSize screenSize = screenFrame.size;
|
||||
NSRect windowFrame = [self.window frame];
|
||||
NSSize windowSize = windowFrame.size;
|
||||
|
||||
newOrigin.x = currentLocation.x - self.initialLocation.x;
|
||||
newOrigin.y = currentLocation.y - self.initialLocation.y;
|
||||
|
||||
BOOL inMenuBar = (newOrigin.y + windowSize.height) > (screenFrame.origin.y + screenSize.height);
|
||||
BOOL screenAboveMainScreen = false;
|
||||
|
||||
if (inMenuBar) {
|
||||
for (NSScreen *screen in [NSScreen screens]) {
|
||||
NSRect currentScreenFrame = [screen frame];
|
||||
BOOL isHigher = currentScreenFrame.origin.y > screenFrame.origin.y;
|
||||
|
||||
// If there's another screen that is generally above the current screen,
|
||||
// we'll draw a new rectangle that is just above the current screen. If the
|
||||
// "higher" screen intersects with this rectangle, we'll allow drawing above
|
||||
// the menubar.
|
||||
if (isHigher) {
|
||||
NSRect aboveScreenRect = NSMakeRect(
|
||||
screenFrame.origin.x,
|
||||
screenFrame.origin.y + screenFrame.size.height - 10,
|
||||
screenFrame.size.width,
|
||||
200
|
||||
);
|
||||
|
||||
BOOL screenAboveIntersects = NSIntersectsRect(currentScreenFrame, aboveScreenRect);
|
||||
|
||||
if (screenAboveIntersects) {
|
||||
screenAboveMainScreen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't let window get dragged up under the menu bar
|
||||
if (inMenuBar && !screenAboveMainScreen) {
|
||||
newOrigin.y = screenFrame.origin.y + (screenFrame.size.height - windowFrame.size.height);
|
||||
}
|
||||
|
||||
// Move the window to the new location
|
||||
[self.window setFrameOrigin:newOrigin];
|
||||
}
|
||||
|
||||
// Debugging tips:
|
||||
// Uncomment the following four lines to color DragRegionView bright red
|
||||
// #ifdef DEBUG_DRAG_REGIONS
|
||||
// - (void)drawRect:(NSRect)aRect
|
||||
// {
|
||||
// [[NSColor redColor] set];
|
||||
// NSRectFill([self bounds]);
|
||||
// }
|
||||
// #endif
|
||||
|
||||
@end
|
||||
|
||||
@interface ExcludeDragRegionView : NSView
|
||||
@end
|
||||
|
||||
@implementation ExcludeDragRegionView
|
||||
|
||||
- (BOOL)mouseDownCanMoveWindow {
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Debugging tips:
|
||||
// Uncomment the following four lines to color ExcludeDragRegionView bright red
|
||||
// #ifdef DEBUG_DRAG_REGIONS
|
||||
// - (void)drawRect:(NSRect)aRect
|
||||
// {
|
||||
// [[NSColor greenColor] set];
|
||||
// NSRectFill([self bounds]);
|
||||
// }
|
||||
// #endif
|
||||
|
||||
@end
|
||||
|
||||
namespace atom {
|
||||
|
||||
NativeBrowserViewMac::NativeBrowserViewMac(
|
||||
@@ -192,59 +51,6 @@ void NativeBrowserViewMac::SetBackgroundColor(SkColor color) {
|
||||
view.layer.backgroundColor = skia::CGColorCreateFromSkColor(color);
|
||||
}
|
||||
|
||||
void NativeBrowserViewMac::UpdateDraggableRegions(
|
||||
const std::vector<gfx::Rect>& system_drag_exclude_areas) {
|
||||
NSView* webView = GetInspectableWebContentsView()->GetNativeView();
|
||||
|
||||
NSInteger superViewHeight = NSHeight([webView.superview bounds]);
|
||||
NSInteger webViewHeight = NSHeight([webView bounds]);
|
||||
NSInteger webViewWidth = NSWidth([webView bounds]);
|
||||
NSInteger webViewX = NSMinX([webView frame]);
|
||||
NSInteger webViewY = 0;
|
||||
|
||||
// Apple's NSViews have their coordinate system originate at the bottom left,
|
||||
// meaning that we need to be a bit smarter when it comes to calculating our
|
||||
// current top offset
|
||||
if (webViewHeight > superViewHeight) {
|
||||
webViewY = std::abs(webViewHeight - superViewHeight - (std::abs(NSMinY([webView frame]))));
|
||||
} else {
|
||||
webViewY = superViewHeight - NSMaxY([webView frame]);
|
||||
}
|
||||
|
||||
// Remove all DraggableRegionViews that are added last time.
|
||||
// Note that [webView subviews] returns the view's mutable internal array and
|
||||
// it should be copied to avoid mutating the original array while enumerating
|
||||
// it.
|
||||
base::scoped_nsobject<NSArray> subviews([[webView subviews] copy]);
|
||||
for (NSView* subview in subviews.get())
|
||||
if ([subview isKindOfClass:[DragRegionView class]])
|
||||
[subview removeFromSuperview];
|
||||
|
||||
// Create one giant NSView that is draggable.
|
||||
base::scoped_nsobject<NSView> dragRegion(
|
||||
[[DragRegionView alloc] initWithFrame:NSZeroRect]);
|
||||
[dragRegion setFrame:NSMakeRect(0,
|
||||
0,
|
||||
webViewWidth,
|
||||
webViewHeight)];
|
||||
|
||||
// Then, on top of that, add "exclusion zones"
|
||||
for (auto iter = system_drag_exclude_areas.begin();
|
||||
iter != system_drag_exclude_areas.end();
|
||||
++iter) {
|
||||
base::scoped_nsobject<NSView> controlRegion(
|
||||
[[ExcludeDragRegionView alloc] initWithFrame:NSZeroRect]);
|
||||
[controlRegion setFrame:NSMakeRect(iter->x() - webViewX,
|
||||
webViewHeight - iter->bottom() + webViewY,
|
||||
iter->width(),
|
||||
iter->height())];
|
||||
[dragRegion addSubview:controlRegion];
|
||||
}
|
||||
|
||||
// Add the DragRegion to the WebView
|
||||
[webView addSubview:dragRegion];
|
||||
}
|
||||
|
||||
// static
|
||||
NativeBrowserView* NativeBrowserView::Create(
|
||||
brightray::InspectableWebContentsView* web_contents_view) {
|
||||
|
||||
@@ -159,10 +159,6 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||
if (options.Get(options::kHasShadow, &has_shadow)) {
|
||||
SetHasShadow(has_shadow);
|
||||
}
|
||||
double opacity;
|
||||
if (options.Get(options::kOpacity, &opacity)) {
|
||||
SetOpacity(opacity);
|
||||
}
|
||||
bool top;
|
||||
if (options.Get(options::kAlwaysOnTop, &top) && top) {
|
||||
SetAlwaysOnTop(true);
|
||||
@@ -255,7 +251,7 @@ void NativeWindow::SetSizeConstraints(
|
||||
SetContentSizeConstraints(content_constraints);
|
||||
}
|
||||
|
||||
extensions::SizeConstraints NativeWindow::GetSizeConstraints() const {
|
||||
extensions::SizeConstraints NativeWindow::GetSizeConstraints() {
|
||||
extensions::SizeConstraints content_constraints = GetContentSizeConstraints();
|
||||
extensions::SizeConstraints window_constraints;
|
||||
if (content_constraints.HasMaximumSize()) {
|
||||
@@ -276,7 +272,7 @@ void NativeWindow::SetContentSizeConstraints(
|
||||
size_constraints_ = size_constraints;
|
||||
}
|
||||
|
||||
extensions::SizeConstraints NativeWindow::GetContentSizeConstraints() const {
|
||||
extensions::SizeConstraints NativeWindow::GetContentSizeConstraints() {
|
||||
return size_constraints_;
|
||||
}
|
||||
|
||||
@@ -286,7 +282,7 @@ void NativeWindow::SetMinimumSize(const gfx::Size& size) {
|
||||
SetSizeConstraints(size_constraints);
|
||||
}
|
||||
|
||||
gfx::Size NativeWindow::GetMinimumSize() const {
|
||||
gfx::Size NativeWindow::GetMinimumSize() {
|
||||
return GetSizeConstraints().GetMinimumSize();
|
||||
}
|
||||
|
||||
@@ -296,7 +292,7 @@ void NativeWindow::SetMaximumSize(const gfx::Size& size) {
|
||||
SetSizeConstraints(size_constraints);
|
||||
}
|
||||
|
||||
gfx::Size NativeWindow::GetMaximumSize() const {
|
||||
gfx::Size NativeWindow::GetMaximumSize() {
|
||||
return GetSizeConstraints().GetMaximumSize();
|
||||
}
|
||||
|
||||
@@ -340,24 +336,6 @@ void NativeWindow::SetParentWindow(NativeWindow* parent) {
|
||||
void NativeWindow::SetAutoHideCursor(bool auto_hide) {
|
||||
}
|
||||
|
||||
void NativeWindow::SelectPreviousTab() {
|
||||
}
|
||||
|
||||
void NativeWindow::SelectNextTab() {
|
||||
}
|
||||
|
||||
void NativeWindow::MergeAllWindows() {
|
||||
}
|
||||
|
||||
void NativeWindow::MoveTabToNewWindow() {
|
||||
}
|
||||
|
||||
void NativeWindow::ToggleTabBar() {
|
||||
}
|
||||
|
||||
void NativeWindow::AddTabbedWindow(NativeWindow* window) {
|
||||
}
|
||||
|
||||
void NativeWindow::SetVibrancy(const std::string& filename) {
|
||||
}
|
||||
|
||||
@@ -619,11 +597,6 @@ void NativeWindow::NotifyTouchBarItemInteraction(
|
||||
observer.OnTouchBarItemResult(item_id, details);
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyNewWindowForTab() {
|
||||
for (NativeWindowObserver &observer : observers_)
|
||||
observer.OnNewWindowForTab();
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void NativeWindow::NotifyWindowMessage(
|
||||
UINT message, WPARAM w_param, LPARAM l_param) {
|
||||
|
||||
@@ -18,12 +18,10 @@
|
||||
#include "base/observer_list.h"
|
||||
#include "base/supports_user_data.h"
|
||||
#include "content/public/browser/readback_types.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
#include "extensions/browser/app_window/size_constraints.h"
|
||||
#include "native_mate/persistent_dictionary.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
|
||||
@@ -100,14 +98,14 @@ class NativeWindow : public base::SupportsUserData,
|
||||
virtual gfx::Rect GetContentBounds();
|
||||
virtual void SetSizeConstraints(
|
||||
const extensions::SizeConstraints& size_constraints);
|
||||
virtual extensions::SizeConstraints GetSizeConstraints() const;
|
||||
virtual extensions::SizeConstraints GetSizeConstraints();
|
||||
virtual void SetContentSizeConstraints(
|
||||
const extensions::SizeConstraints& size_constraints);
|
||||
virtual extensions::SizeConstraints GetContentSizeConstraints() const;
|
||||
virtual extensions::SizeConstraints GetContentSizeConstraints();
|
||||
virtual void SetMinimumSize(const gfx::Size& size);
|
||||
virtual gfx::Size GetMinimumSize() const;
|
||||
virtual gfx::Size GetMinimumSize();
|
||||
virtual void SetMaximumSize(const gfx::Size& size);
|
||||
virtual gfx::Size GetMaximumSize() const;
|
||||
virtual gfx::Size GetMaximumSize();
|
||||
virtual void SetSheetOffset(const double offsetX, const double offsetY);
|
||||
virtual double GetSheetOffsetX();
|
||||
virtual double GetSheetOffsetY();
|
||||
@@ -134,28 +132,23 @@ class NativeWindow : public base::SupportsUserData,
|
||||
virtual std::string GetTitle() = 0;
|
||||
virtual void FlashFrame(bool flash) = 0;
|
||||
virtual void SetSkipTaskbar(bool skip) = 0;
|
||||
virtual void SetSimpleFullScreen(bool simple_fullscreen) = 0;
|
||||
virtual bool IsSimpleFullScreen() = 0;
|
||||
virtual void SetKiosk(bool kiosk) = 0;
|
||||
virtual bool IsKiosk() = 0;
|
||||
virtual void SetBackgroundColor(const std::string& color_name) = 0;
|
||||
virtual void SetHasShadow(bool has_shadow) = 0;
|
||||
virtual bool HasShadow() = 0;
|
||||
virtual void SetOpacity(const double opacity) = 0;
|
||||
virtual double GetOpacity() = 0;
|
||||
virtual void SetRepresentedFilename(const std::string& filename);
|
||||
virtual std::string GetRepresentedFilename();
|
||||
virtual void SetDocumentEdited(bool edited);
|
||||
virtual bool IsDocumentEdited();
|
||||
virtual void SetIgnoreMouseEvents(bool ignore, bool forward) = 0;
|
||||
virtual void SetIgnoreMouseEvents(bool ignore) = 0;
|
||||
virtual void SetContentProtection(bool enable) = 0;
|
||||
virtual void SetFocusable(bool focusable);
|
||||
virtual void SetMenu(AtomMenuModel* menu);
|
||||
virtual void SetParentWindow(NativeWindow* parent);
|
||||
virtual void SetBrowserView(NativeBrowserView* browser_view) = 0;
|
||||
virtual gfx::NativeView GetNativeView() const = 0;
|
||||
virtual gfx::NativeWindow GetNativeWindow() const = 0;
|
||||
virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;
|
||||
virtual gfx::NativeWindow GetNativeWindow() = 0;
|
||||
virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
|
||||
|
||||
// Taskbar/Dock APIs.
|
||||
enum ProgressState {
|
||||
@@ -186,14 +179,6 @@ class NativeWindow : public base::SupportsUserData,
|
||||
virtual void RefreshTouchBarItem(const std::string& item_id);
|
||||
virtual void SetEscapeTouchBarItem(const mate::PersistentDictionary& item);
|
||||
|
||||
// Native Tab API
|
||||
virtual void SelectPreviousTab();
|
||||
virtual void SelectNextTab();
|
||||
virtual void MergeAllWindows();
|
||||
virtual void MoveTabToNewWindow();
|
||||
virtual void ToggleTabBar();
|
||||
virtual void AddTabbedWindow(NativeWindow* window);
|
||||
|
||||
// Webview APIs.
|
||||
virtual void FocusOnWebView();
|
||||
virtual void BlurWebView();
|
||||
@@ -229,12 +214,6 @@ class NativeWindow : public base::SupportsUserData,
|
||||
virtual void HandleKeyboardEvent(
|
||||
content::WebContents*,
|
||||
const content::NativeWebKeyboardEvent& event) {}
|
||||
virtual void ShowAutofillPopup(
|
||||
content::RenderFrameHost* frame_host,
|
||||
const gfx::RectF& bounds,
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels) {}
|
||||
virtual void HideAutofillPopup(content::RenderFrameHost* frame_host) {}
|
||||
|
||||
// Public API used by platform-dependent delegates and observers to send UI
|
||||
// related notifications.
|
||||
@@ -264,7 +243,6 @@ class NativeWindow : public base::SupportsUserData,
|
||||
void NotifyWindowExecuteWindowsCommand(const std::string& command);
|
||||
void NotifyTouchBarItemInteraction(const std::string& item_id,
|
||||
const base::DictionaryValue& details);
|
||||
void NotifyNewWindowForTab();
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void NotifyWindowMessage(UINT message, WPARAM w_param, LPARAM l_param);
|
||||
@@ -302,10 +280,8 @@ class NativeWindow : public base::SupportsUserData,
|
||||
const std::vector<DraggableRegion>& regions);
|
||||
|
||||
// Converts between content bounds and window bounds.
|
||||
virtual gfx::Rect ContentBoundsToWindowBounds(
|
||||
const gfx::Rect& bounds) const = 0;
|
||||
virtual gfx::Rect WindowBoundsToContentBounds(
|
||||
const gfx::Rect& bounds) const = 0;
|
||||
virtual gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) = 0;
|
||||
virtual gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) = 0;
|
||||
|
||||
// Called when the window needs to update its draggable region.
|
||||
virtual void UpdateDraggableRegions(
|
||||
|
||||
@@ -76,26 +76,21 @@ class NativeWindowMac : public NativeWindow,
|
||||
std::string GetTitle() override;
|
||||
void FlashFrame(bool flash) override;
|
||||
void SetSkipTaskbar(bool skip) override;
|
||||
void SetSimpleFullScreen(bool simple_fullscreen) override;
|
||||
bool IsSimpleFullScreen() override;
|
||||
void SetKiosk(bool kiosk) override;
|
||||
bool IsKiosk() override;
|
||||
void SetBackgroundColor(const std::string& color_name) override;
|
||||
void SetHasShadow(bool has_shadow) override;
|
||||
bool HasShadow() override;
|
||||
void SetOpacity(const double opacity) override;
|
||||
double GetOpacity() override;
|
||||
void SetRepresentedFilename(const std::string& filename) override;
|
||||
std::string GetRepresentedFilename() override;
|
||||
void SetDocumentEdited(bool edited) override;
|
||||
bool IsDocumentEdited() override;
|
||||
void SetIgnoreMouseEvents(bool ignore, bool) override;
|
||||
void SetIgnoreMouseEvents(bool ignore) override;
|
||||
void SetContentProtection(bool enable) override;
|
||||
void SetBrowserView(NativeBrowserView* browser_view) override;
|
||||
void SetParentWindow(NativeWindow* parent) override;
|
||||
gfx::NativeView GetNativeView() const override;
|
||||
gfx::NativeWindow GetNativeWindow() const override;
|
||||
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
|
||||
gfx::NativeWindow GetNativeWindow() override;
|
||||
gfx::AcceleratedWidget GetAcceleratedWidget() override;
|
||||
void SetProgressBar(double progress, const ProgressState state) override;
|
||||
void SetOverlayIcon(const gfx::Image& overlay,
|
||||
const std::string& description) override;
|
||||
@@ -105,13 +100,6 @@ class NativeWindowMac : public NativeWindow,
|
||||
|
||||
void SetAutoHideCursor(bool auto_hide) override;
|
||||
|
||||
void SelectPreviousTab() override;
|
||||
void SelectNextTab() override;
|
||||
void MergeAllWindows() override;
|
||||
void MoveTabToNewWindow() override;
|
||||
void ToggleTabBar() override;
|
||||
void AddTabbedWindow(NativeWindow* window) override;
|
||||
|
||||
void SetVibrancy(const std::string& type) override;
|
||||
void SetTouchBar(
|
||||
const std::vector<mate::PersistentDictionary>& items) override;
|
||||
@@ -138,16 +126,11 @@ class NativeWindowMac : public NativeWindow,
|
||||
NORMAL,
|
||||
HIDDEN,
|
||||
HIDDEN_INSET,
|
||||
CUSTOM_BUTTONS_ON_HOVER,
|
||||
};
|
||||
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
||||
|
||||
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
||||
|
||||
bool fullscreen_window_title() const { return fullscreen_window_title_; }
|
||||
|
||||
bool simple_fullscreen() const { return always_simple_fullscreen_; }
|
||||
|
||||
protected:
|
||||
// Return a vector of non-draggable regions that fill a window of size
|
||||
// |width| by |height|, but leave gaps where the window should be draggable.
|
||||
@@ -156,19 +139,18 @@ class NativeWindowMac : public NativeWindow,
|
||||
|
||||
private:
|
||||
// NativeWindow:
|
||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const;
|
||||
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const;
|
||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds);
|
||||
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds);
|
||||
void UpdateDraggableRegions(
|
||||
const std::vector<DraggableRegion>& regions) override;
|
||||
|
||||
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
||||
void ShowWindowButton(NSWindowButton button);
|
||||
|
||||
void InstallView();
|
||||
void UninstallView();
|
||||
|
||||
// Install the drag view, which will cover the whole window and decides
|
||||
// whether we can drag.
|
||||
// whehter we can drag.
|
||||
void UpdateDraggableRegionViews(const std::vector<DraggableRegion>& regions);
|
||||
|
||||
void RegisterInputEventObserver(content::RenderViewHost* host);
|
||||
@@ -193,8 +175,6 @@ class NativeWindowMac : public NativeWindow,
|
||||
|
||||
bool zoom_to_page_width_;
|
||||
|
||||
bool fullscreen_window_title_;
|
||||
|
||||
NSInteger attention_request_id_; // identifier from requestUserAttention
|
||||
|
||||
// The presentation options before entering kiosk mode.
|
||||
@@ -203,17 +183,6 @@ class NativeWindowMac : public NativeWindow,
|
||||
// The "titleBarStyle" option.
|
||||
TitleBarStyle title_bar_style_;
|
||||
|
||||
// Simple (pre-Lion) Fullscreen Settings
|
||||
bool always_simple_fullscreen_;
|
||||
bool is_simple_fullscreen_;
|
||||
bool was_maximizable_;
|
||||
bool was_movable_;
|
||||
NSRect original_frame_;
|
||||
NSUInteger simple_fullscreen_mask_;
|
||||
|
||||
// The presentation options before entering simple fullscreen mode.
|
||||
NSApplicationPresentationOptions simple_fullscreen_options_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
|
||||
#include "atom/browser/native_window_mac.h"
|
||||
|
||||
#include <AvailabilityMacros.h>
|
||||
#include <Quartz/Quartz.h>
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_browser_view_mac.h"
|
||||
#include "atom/browser/ui/cocoa/atom_touch_bar.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
@@ -48,102 +46,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
|
||||
} // namespace
|
||||
|
||||
// Custom Quit, Minimize and Full Screen button container for frameless
|
||||
// windows.
|
||||
@interface CustomWindowButtonView : NSView {
|
||||
@private
|
||||
BOOL mouse_inside_;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CustomWindowButtonView
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
|
||||
NSButton* close_button = [NSWindow standardWindowButton:NSWindowCloseButton
|
||||
forStyleMask:NSTitledWindowMask];
|
||||
NSButton* miniaturize_button =
|
||||
[NSWindow standardWindowButton:NSWindowMiniaturizeButton
|
||||
forStyleMask:NSTitledWindowMask];
|
||||
NSButton* zoom_button = [NSWindow standardWindowButton:NSWindowZoomButton
|
||||
forStyleMask:NSTitledWindowMask];
|
||||
|
||||
CGFloat x = 0;
|
||||
const CGFloat space_between = 20;
|
||||
|
||||
[close_button setFrameOrigin:NSMakePoint(x, 0)];
|
||||
x += space_between;
|
||||
[self addSubview:close_button];
|
||||
|
||||
[miniaturize_button setFrameOrigin:NSMakePoint(x, 0)];
|
||||
x += space_between;
|
||||
[self addSubview:miniaturize_button];
|
||||
|
||||
[zoom_button setFrameOrigin:NSMakePoint(x, 0)];
|
||||
x += space_between;
|
||||
[self addSubview:zoom_button];
|
||||
|
||||
const auto last_button_frame = zoom_button.frame;
|
||||
[self setFrameSize:NSMakeSize(last_button_frame.origin.x +
|
||||
last_button_frame.size.width,
|
||||
last_button_frame.size.height)];
|
||||
|
||||
mouse_inside_ = NO;
|
||||
[self setNeedsDisplayForButtons];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidMoveToWindow {
|
||||
if (!self.window) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stay in upper left corner.
|
||||
const CGFloat top_margin = 3;
|
||||
const CGFloat left_margin = 7;
|
||||
[self setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
|
||||
[self setFrameOrigin:NSMakePoint(left_margin, self.window.frame.size.height -
|
||||
self.frame.size.height -
|
||||
top_margin)];
|
||||
}
|
||||
|
||||
- (BOOL)_mouseInGroup:(NSButton*)button {
|
||||
return mouse_inside_;
|
||||
}
|
||||
|
||||
- (void)updateTrackingAreas {
|
||||
auto tracking_area = [[[NSTrackingArea alloc]
|
||||
initWithRect:NSZeroRect
|
||||
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways |
|
||||
NSTrackingInVisibleRect
|
||||
owner:self
|
||||
userInfo:nil] autorelease];
|
||||
[self addTrackingArea:tracking_area];
|
||||
}
|
||||
|
||||
- (void)mouseEntered:(NSEvent*)event {
|
||||
[super mouseEntered:event];
|
||||
mouse_inside_ = YES;
|
||||
[self setNeedsDisplayForButtons];
|
||||
}
|
||||
|
||||
- (void)mouseExited:(NSEvent*)event {
|
||||
[super mouseExited:event];
|
||||
mouse_inside_ = NO;
|
||||
[self setNeedsDisplayForButtons];
|
||||
}
|
||||
|
||||
- (void)setNeedsDisplayForButtons {
|
||||
for (NSView* subview in self.subviews) {
|
||||
[subview setHidden:!mouse_inside_];
|
||||
[subview setNeedsDisplay:YES];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// This view always takes the size of its superview. It is intended to be used
|
||||
// as a NSWindow's contentView. It is needed because NSWindow's implementation
|
||||
// explicitly resizes the contentView at inopportune times.
|
||||
@@ -173,8 +75,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
@private
|
||||
atom::NativeWindowMac* shell_;
|
||||
bool is_zooming_;
|
||||
int level_;
|
||||
bool is_resizable_;
|
||||
}
|
||||
- (id)initWithShell:(atom::NativeWindowMac*)shell;
|
||||
@end
|
||||
@@ -185,7 +85,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
if ((self = [super init])) {
|
||||
shell_ = shell;
|
||||
is_zooming_ = false;
|
||||
level_ = [shell_->GetNativeWindow() level];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -305,19 +204,11 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
shell_->NotifyWindowMoved();
|
||||
}
|
||||
|
||||
- (void)windowWillMiniaturize:(NSNotification*)notification {
|
||||
NSWindow* window = shell_->GetNativeWindow();
|
||||
// store the current status window level to be restored in windowDidDeminiaturize
|
||||
level_ = [window level];
|
||||
[window setLevel:NSNormalWindowLevel];
|
||||
}
|
||||
|
||||
- (void)windowDidMiniaturize:(NSNotification*)notification {
|
||||
shell_->NotifyWindowMinimize();
|
||||
}
|
||||
|
||||
- (void)windowDidDeminiaturize:(NSNotification*)notification {
|
||||
[shell_->GetNativeWindow() setLevel:level_];
|
||||
shell_->NotifyWindowRestore();
|
||||
}
|
||||
|
||||
@@ -337,9 +228,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
}
|
||||
|
||||
- (void)windowWillEnterFullScreen:(NSNotification*)notification {
|
||||
// Setting resizable to true before entering fullscreen
|
||||
is_resizable_ = shell_->IsResizable();
|
||||
shell_->SetResizable(true);
|
||||
// Hide the native toolbar before entering fullscreen, so there is no visual
|
||||
// artifacts.
|
||||
if (base::mac::IsAtLeastOS10_10() &&
|
||||
@@ -360,9 +248,7 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
base::mac::IsAtLeastOS10_10() &&
|
||||
// FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under
|
||||
// fullscreen mode.
|
||||
// Show title if fullscreen_window_title flag is set
|
||||
(shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET ||
|
||||
shell_->fullscreen_window_title())) {
|
||||
shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET) {
|
||||
[window setTitleVisibility:NSWindowTitleVisible];
|
||||
}
|
||||
|
||||
@@ -386,8 +272,7 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
NSWindow* window = shell_->GetNativeWindow();
|
||||
if ((shell_->transparent() || !shell_->has_frame()) &&
|
||||
base::mac::IsAtLeastOS10_10() &&
|
||||
(shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET ||
|
||||
shell_->fullscreen_window_title())) {
|
||||
shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET) {
|
||||
[window setTitleVisibility:NSWindowTitleHidden];
|
||||
}
|
||||
|
||||
@@ -399,7 +284,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
}
|
||||
|
||||
- (void)windowDidExitFullScreen:(NSNotification*)notification {
|
||||
shell_->SetResizable(is_resizable_);
|
||||
shell_->NotifyWindowLeaveFullScreen();
|
||||
}
|
||||
|
||||
@@ -415,7 +299,7 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
- (BOOL)windowShouldClose:(id)window {
|
||||
// When user tries to close the window by clicking the close button, we do
|
||||
// not close the window immediately, instead we try to close the web page
|
||||
// first, and when the web page is closed the window will also be closed.
|
||||
// fisrt, and when the web page is closed the window will also be closed.
|
||||
shell_->RequestToClosePage();
|
||||
return NO;
|
||||
}
|
||||
@@ -437,11 +321,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
shell_->NotifyWindowSheetEnd();
|
||||
}
|
||||
|
||||
- (IBAction)newWindowForTab:(id)sender {
|
||||
shell_->NotifyNewWindowForTab();
|
||||
atom::Browser::Get()->NewWindowForTab();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface AtomPreviewItem : NSObject <QLPreviewItem>
|
||||
@@ -466,7 +345,7 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
|
||||
@end
|
||||
|
||||
#if !defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
||||
#if !defined(MAC_OS_X_VERSION_10_12)
|
||||
|
||||
enum {
|
||||
NSWindowTabbingModeDisallowed = 2
|
||||
@@ -475,15 +354,9 @@ enum {
|
||||
@interface NSWindow (SierraSDK)
|
||||
- (void)setTabbingMode:(NSInteger)mode;
|
||||
- (void)setTabbingIdentifier:(NSString*)identifier;
|
||||
- (void)addTabbedWindow:(NSWindow*)window ordered:(NSWindowOrderingMode)ordered;
|
||||
- (IBAction)selectPreviousTab:(id)sender;
|
||||
- (IBAction)selectNextTab:(id)sender;
|
||||
- (IBAction)mergeAllWindows:(id)sender;
|
||||
- (IBAction)moveTabToNewWindow:(id)sender;
|
||||
- (IBAction)toggleTabBar:(id)sender;
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif // MAC_OS_X_VERSION_10_12
|
||||
|
||||
@interface AtomNSWindow : EventDispatchingWindow<QLPreviewPanelDataSource, QLPreviewPanelDelegate, NSTouchBarDelegate> {
|
||||
@private
|
||||
@@ -723,29 +596,6 @@ enum {
|
||||
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
// Custom window button methods
|
||||
|
||||
- (void)performClose:(id)sender {
|
||||
if (shell_->title_bar_style() == atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER)
|
||||
[[self delegate] windowShouldClose:self];
|
||||
else
|
||||
[super performClose:sender];
|
||||
}
|
||||
|
||||
- (void)toggleFullScreen:(id)sender {
|
||||
if (shell_->simple_fullscreen())
|
||||
shell_->SetSimpleFullScreen(!shell_->IsSimpleFullScreen());
|
||||
else
|
||||
[super toggleFullScreen:sender];
|
||||
}
|
||||
|
||||
- (void)performMiniaturize:(id)sender {
|
||||
if (shell_->title_bar_style() == atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER)
|
||||
[self miniaturize:self];
|
||||
else
|
||||
[super performMiniaturize:sender];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface ControlRegionView : NSView
|
||||
@@ -811,11 +661,9 @@ struct Converter<atom::NativeWindowMac::TitleBarStyle> {
|
||||
return false;
|
||||
if (title_bar_style == "hidden") {
|
||||
*out = atom::NativeWindowMac::HIDDEN;
|
||||
} else if (title_bar_style == "hidden-inset" || // TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
|
||||
} else if (title_bar_style == "hidden-inset" || // Deprecate this after 2.0
|
||||
title_bar_style == "hiddenInset") {
|
||||
*out = atom::NativeWindowMac::HIDDEN_INSET;
|
||||
} else if (title_bar_style == "customButtonsOnHover") {
|
||||
*out = atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -836,11 +684,8 @@ NativeWindowMac::NativeWindowMac(
|
||||
is_kiosk_(false),
|
||||
was_fullscreen_(false),
|
||||
zoom_to_page_width_(false),
|
||||
fullscreen_window_title_(false),
|
||||
attention_request_id_(0),
|
||||
title_bar_style_(NORMAL),
|
||||
always_simple_fullscreen_(false),
|
||||
is_simple_fullscreen_(false) {
|
||||
title_bar_style_(NORMAL) {
|
||||
int width = 800, height = 600;
|
||||
options.Get(options::kWidth, &width);
|
||||
options.Get(options::kHeight, &height);
|
||||
@@ -881,11 +726,6 @@ NativeWindowMac::NativeWindowMac(
|
||||
}
|
||||
|
||||
NSUInteger styleMask = NSTitledWindowMask;
|
||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER &&
|
||||
base::mac::IsAtLeastOS10_10() &&
|
||||
(!useStandardWindow || transparent() || !has_frame())) {
|
||||
styleMask = NSFullSizeContentViewWindowMask;
|
||||
}
|
||||
if (minimizable) {
|
||||
styleMask |= NSMiniaturizableWindowMask;
|
||||
}
|
||||
@@ -940,7 +780,6 @@ NativeWindowMac::NativeWindowMac(
|
||||
if (transparent() || !has_frame()) {
|
||||
if (base::mac::IsAtLeastOS10_10()) {
|
||||
// Don't show title bar.
|
||||
[window_ setTitlebarAppearsTransparent:YES];
|
||||
[window_ setTitleVisibility:NSWindowTitleHidden];
|
||||
}
|
||||
// Remove non-transparent corners, see http://git.io/vfonD.
|
||||
@@ -984,10 +823,6 @@ NativeWindowMac::NativeWindowMac(
|
||||
|
||||
options.Get(options::kZoomToPageWidth, &zoom_to_page_width_);
|
||||
|
||||
options.Get(options::kFullscreenWindowTitle, &fullscreen_window_title_);
|
||||
|
||||
options.Get(options::kSimpleFullScreen, &always_simple_fullscreen_);
|
||||
|
||||
// Enable the NSView to accept first mouse event.
|
||||
bool acceptsFirstMouse = false;
|
||||
options.Get(options::kAcceptFirstMouse, &acceptsFirstMouse);
|
||||
@@ -1088,10 +923,6 @@ void NativeWindowMac::Show() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reattach the window to the parent to actually show it.
|
||||
if (parent())
|
||||
InternalSetParentWindow(parent(), true);
|
||||
|
||||
// This method is supposed to put focus on window, however if the app does not
|
||||
// have focus then "makeKeyAndOrderFront" will only show the window.
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
@@ -1100,10 +931,6 @@ void NativeWindowMac::Show() {
|
||||
}
|
||||
|
||||
void NativeWindowMac::ShowInactive() {
|
||||
// Reattach the window to the parent to actually show it.
|
||||
if (parent())
|
||||
InternalSetParentWindow(parent(), true);
|
||||
|
||||
[window_ orderFrontRegardless];
|
||||
}
|
||||
|
||||
@@ -1114,10 +941,6 @@ void NativeWindowMac::Hide() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Deattach the window from the parent before.
|
||||
if (parent())
|
||||
InternalSetParentWindow(parent(), false);
|
||||
|
||||
[window_ orderOut:nil];
|
||||
}
|
||||
|
||||
@@ -1386,80 +1209,6 @@ void NativeWindowMac::FlashFrame(bool flash) {
|
||||
void NativeWindowMac::SetSkipTaskbar(bool skip) {
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||
NSWindow* window = GetNativeWindow();
|
||||
|
||||
if (simple_fullscreen && !is_simple_fullscreen_) {
|
||||
is_simple_fullscreen_ = true;
|
||||
|
||||
// Take note of the current window size
|
||||
original_frame_ = [window frame];
|
||||
|
||||
simple_fullscreen_options_ = [NSApp currentSystemPresentationOptions];
|
||||
simple_fullscreen_mask_ = [window styleMask];
|
||||
|
||||
// We can simulate the pre-Lion fullscreen by auto-hiding the dock and menu bar
|
||||
NSApplicationPresentationOptions options =
|
||||
NSApplicationPresentationAutoHideDock +
|
||||
NSApplicationPresentationAutoHideMenuBar;
|
||||
[NSApp setPresentationOptions:options];
|
||||
|
||||
was_maximizable_ = IsMaximizable();
|
||||
was_movable_ = IsMovable();
|
||||
|
||||
NSRect fullscreenFrame = [window.screen frame];
|
||||
|
||||
if ( !fullscreen_window_title() ) {
|
||||
// Hide the titlebar
|
||||
SetStyleMask(false, NSTitledWindowMask);
|
||||
|
||||
// Resize the window to accomodate the _entire_ screen size
|
||||
fullscreenFrame.size.height -= [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
|
||||
} else {
|
||||
// No need to hide the title, but we should still hide the window buttons
|
||||
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
||||
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
||||
[[window standardWindowButton:NSWindowCloseButton] setHidden:YES];
|
||||
}
|
||||
|
||||
[window setFrame:fullscreenFrame display: YES animate: YES];
|
||||
|
||||
// Fullscreen windows can't be resized, minimized, maximized, or moved
|
||||
SetMinimizable(false);
|
||||
SetResizable(false);
|
||||
SetMaximizable(false);
|
||||
SetMovable(false);
|
||||
} else if (!simple_fullscreen && is_simple_fullscreen_) {
|
||||
is_simple_fullscreen_ = false;
|
||||
|
||||
if ( !fullscreen_window_title() ) {
|
||||
// Restore the titlebar
|
||||
SetStyleMask(true, NSTitledWindowMask);
|
||||
} else {
|
||||
// Show the window buttons
|
||||
[[window standardWindowButton:NSWindowZoomButton] setHidden:NO];
|
||||
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:NO];
|
||||
[[window standardWindowButton:NSWindowCloseButton] setHidden:NO];
|
||||
}
|
||||
|
||||
[window setFrame:original_frame_ display: YES animate: YES];
|
||||
|
||||
[NSApp setPresentationOptions:simple_fullscreen_options_];
|
||||
|
||||
// Restore original style mask
|
||||
ScopedDisableResize disable_resize;
|
||||
[window_ setStyleMask:simple_fullscreen_mask_];
|
||||
|
||||
// Restore window manipulation abilities
|
||||
SetMaximizable(was_maximizable_);
|
||||
SetMovable(was_movable_);
|
||||
}
|
||||
}
|
||||
|
||||
bool NativeWindowMac::IsSimpleFullScreen() {
|
||||
return is_simple_fullscreen_;
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetKiosk(bool kiosk) {
|
||||
if (kiosk && !is_kiosk_) {
|
||||
kiosk_options_ = [NSApp currentSystemPresentationOptions];
|
||||
@@ -1505,14 +1254,6 @@ bool NativeWindowMac::HasShadow() {
|
||||
return [window_ hasShadow];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetOpacity(const double opacity) {
|
||||
[window_ setAlphaValue:opacity];
|
||||
}
|
||||
|
||||
double NativeWindowMac::GetOpacity() {
|
||||
return [window_ alphaValue];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
|
||||
[window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)];
|
||||
}
|
||||
@@ -1529,7 +1270,7 @@ bool NativeWindowMac::IsDocumentEdited() {
|
||||
return [window_ isDocumentEdited];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetIgnoreMouseEvents(bool ignore, bool) {
|
||||
void NativeWindowMac::SetIgnoreMouseEvents(bool ignore) {
|
||||
[window_ setIgnoresMouseEvents:ignore];
|
||||
}
|
||||
|
||||
@@ -1559,18 +1300,25 @@ void NativeWindowMac::SetBrowserView(NativeBrowserView* browser_view) {
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetParentWindow(NativeWindow* parent) {
|
||||
InternalSetParentWindow(parent, IsVisible());
|
||||
if (is_modal())
|
||||
return;
|
||||
|
||||
NativeWindow::SetParentWindow(parent);
|
||||
|
||||
// Remove current parent window.
|
||||
if ([window_ parentWindow])
|
||||
[[window_ parentWindow] removeChildWindow:window_];
|
||||
|
||||
// Set new current window.
|
||||
if (parent)
|
||||
[parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove];
|
||||
}
|
||||
|
||||
gfx::NativeView NativeWindowMac::GetNativeView() const {
|
||||
return inspectable_web_contents()->GetView()->GetNativeView();
|
||||
}
|
||||
|
||||
gfx::NativeWindow NativeWindowMac::GetNativeWindow() const {
|
||||
gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
|
||||
return window_;
|
||||
}
|
||||
|
||||
gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() const {
|
||||
gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() {
|
||||
return inspectable_web_contents()->GetView()->GetNativeView();
|
||||
}
|
||||
|
||||
@@ -1629,42 +1377,6 @@ void NativeWindowMac::SetAutoHideCursor(bool auto_hide) {
|
||||
[window_ setDisableAutoHideCursor:!auto_hide];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SelectPreviousTab() {
|
||||
if ([window_ respondsToSelector:@selector(selectPreviousTab:)]) {
|
||||
[window_ selectPreviousTab:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowMac::SelectNextTab() {
|
||||
if ([window_ respondsToSelector:@selector(selectNextTab:)]) {
|
||||
[window_ selectNextTab:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowMac::MergeAllWindows() {
|
||||
if ([window_ respondsToSelector:@selector(mergeAllWindows:)]) {
|
||||
[window_ mergeAllWindows:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowMac::MoveTabToNewWindow() {
|
||||
if ([window_ respondsToSelector:@selector(moveTabToNewWindow:)]) {
|
||||
[window_ moveTabToNewWindow:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowMac::ToggleTabBar() {
|
||||
if ([window_ respondsToSelector:@selector(toggleTabBar:)]) {
|
||||
[window_ toggleTabBar:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
|
||||
if ([window_ respondsToSelector:@selector(addTabbedWindow:ordered:)]) {
|
||||
[window_ addTabbedWindow:window->GetNativeWindow() ordered:NSWindowAbove];
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||
if (!base::mac::IsAtLeastOS10_10()) return;
|
||||
|
||||
@@ -1746,10 +1458,10 @@ void NativeWindowMac::SetEscapeTouchBarItem(const mate::PersistentDictionary& it
|
||||
}
|
||||
|
||||
void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
|
||||
switch (event.GetType()) {
|
||||
case blink::WebInputEvent::kGestureScrollBegin:
|
||||
case blink::WebInputEvent::kGestureScrollUpdate:
|
||||
case blink::WebInputEvent::kGestureScrollEnd:
|
||||
switch (event.type) {
|
||||
case blink::WebInputEvent::GestureScrollBegin:
|
||||
case blink::WebInputEvent::GestureScrollUpdate:
|
||||
case blink::WebInputEvent::GestureScrollEnd:
|
||||
this->NotifyWindowScrollTouchEdge();
|
||||
break;
|
||||
default:
|
||||
@@ -1782,7 +1494,7 @@ std::vector<gfx::Rect> NativeWindowMac::CalculateNonDraggableRegions(
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
|
||||
const gfx::Rect& bounds) const {
|
||||
const gfx::Rect& bounds) {
|
||||
if (has_frame()) {
|
||||
gfx::Rect window_bounds(
|
||||
[window_ frameRectForContentRect:bounds.ToCGRect()]);
|
||||
@@ -1795,7 +1507,7 @@ gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowMac::WindowBoundsToContentBounds(
|
||||
const gfx::Rect& bounds) const {
|
||||
const gfx::Rect& bounds) {
|
||||
if (has_frame()) {
|
||||
gfx::Rect content_bounds(
|
||||
[window_ contentRectForFrameRect:bounds.ToCGRect()]);
|
||||
@@ -1814,26 +1526,6 @@ void NativeWindowMac::UpdateDraggableRegions(
|
||||
UpdateDraggableRegionViews(regions);
|
||||
}
|
||||
|
||||
void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent, bool attach) {
|
||||
if (is_modal())
|
||||
return;
|
||||
|
||||
NativeWindow::SetParentWindow(parent);
|
||||
|
||||
// Do not remove/add if we are already properly attached.
|
||||
if (attach && parent && [window_ parentWindow] == parent->GetNativeWindow())
|
||||
return;
|
||||
|
||||
// Remove current parent window.
|
||||
if ([window_ parentWindow])
|
||||
[[window_ parentWindow] removeChildWindow:window_];
|
||||
|
||||
// Set new parent window.
|
||||
// Note that this method will force the window to become visible.
|
||||
if (parent && attach)
|
||||
[parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove];
|
||||
}
|
||||
|
||||
void NativeWindowMac::ShowWindowButton(NSWindowButton button) {
|
||||
auto view = [window_ standardWindowButton:button];
|
||||
[view.superview addSubview:view positioned:NSWindowAbove relativeTo:nil];
|
||||
@@ -1867,26 +1559,21 @@ void NativeWindowMac::InstallView() {
|
||||
// The fullscreen button should always be hidden for frameless window.
|
||||
[[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
|
||||
|
||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
||||
NSView* window_button_view = [[[CustomWindowButtonView alloc]
|
||||
initWithFrame:NSZeroRect] autorelease];
|
||||
[content_view_ addSubview:window_button_view];
|
||||
} else {
|
||||
if (title_bar_style_ != NORMAL) {
|
||||
if (base::mac::IsOS10_9()) {
|
||||
ShowWindowButton(NSWindowZoomButton);
|
||||
ShowWindowButton(NSWindowMiniaturizeButton);
|
||||
ShowWindowButton(NSWindowCloseButton);
|
||||
}
|
||||
return;
|
||||
if (title_bar_style_ != NORMAL) {
|
||||
if (base::mac::IsOS10_9()) {
|
||||
ShowWindowButton(NSWindowZoomButton);
|
||||
ShowWindowButton(NSWindowMiniaturizeButton);
|
||||
ShowWindowButton(NSWindowCloseButton);
|
||||
}
|
||||
|
||||
// Hide the window buttons.
|
||||
[[window_ standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
||||
[[window_ standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
||||
[[window_ standardWindowButton:NSWindowCloseButton] setHidden:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide the window buttons.
|
||||
[[window_ standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
||||
[[window_ standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
||||
[[window_ standardWindowButton:NSWindowCloseButton] setHidden:YES];
|
||||
|
||||
// Some third-party macOS utilities check the zoom button's enabled state to
|
||||
// determine whether to show custom UI on hover, so we disable it here to
|
||||
// prevent them from doing so in a frameless app window.
|
||||
@@ -1929,10 +1616,6 @@ void NativeWindowMac::UpdateDraggableRegionViews(
|
||||
std::vector<gfx::Rect> system_drag_exclude_areas =
|
||||
CalculateNonDraggableRegions(regions, webViewWidth, webViewHeight);
|
||||
|
||||
if (browser_view_) {
|
||||
browser_view_->UpdateDraggableRegions(system_drag_exclude_areas);
|
||||
}
|
||||
|
||||
// Create and add a ControlRegionView for each region that needs to be
|
||||
// excluded from the dragging.
|
||||
for (std::vector<gfx::Rect>::const_iterator iter =
|
||||
|
||||
@@ -78,7 +78,6 @@ class NativeWindowObserver {
|
||||
virtual void OnWindowLeaveHtmlFullScreen() {}
|
||||
virtual void OnTouchBarItemResult(const std::string& item_id,
|
||||
const base::DictionaryValue& details) {}
|
||||
virtual void OnNewWindowForTab() {}
|
||||
|
||||
// Called when window message received
|
||||
#if defined(OS_WIN)
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/browser/native_browser_view_views.h"
|
||||
#include "atom/browser/ui/views/menu_bar.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
@@ -82,17 +81,17 @@ void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
|
||||
#endif
|
||||
|
||||
bool IsAltKey(const content::NativeWebKeyboardEvent& event) {
|
||||
return event.windows_key_code == ui::VKEY_MENU;
|
||||
return event.windowsKeyCode == ui::VKEY_MENU;
|
||||
}
|
||||
|
||||
bool IsAltModifier(const content::NativeWebKeyboardEvent& event) {
|
||||
typedef content::NativeWebKeyboardEvent::Modifiers Modifiers;
|
||||
int modifiers = event.GetModifiers();
|
||||
modifiers &= ~Modifiers::kNumLockOn;
|
||||
modifiers &= ~Modifiers::kCapsLockOn;
|
||||
return (modifiers == Modifiers::kAltKey) ||
|
||||
(modifiers == (Modifiers::kAltKey | Modifiers::kIsLeft)) ||
|
||||
(modifiers == (Modifiers::kAltKey | Modifiers::kIsRight));
|
||||
int modifiers = event.modifiers;
|
||||
modifiers &= ~Modifiers::NumLockOn;
|
||||
modifiers &= ~Modifiers::CapsLockOn;
|
||||
return (modifiers == Modifiers::AltKey) ||
|
||||
(modifiers == (Modifiers::AltKey | Modifiers::IsLeft)) ||
|
||||
(modifiers == (Modifiers::AltKey | Modifiers::IsRight));
|
||||
}
|
||||
|
||||
#if defined(USE_X11)
|
||||
@@ -304,16 +303,11 @@ NativeWindowViews::NativeWindowViews(
|
||||
::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
|
||||
#endif
|
||||
|
||||
// TODO(zcbenz): This was used to force using native frame on Windows 2003, we
|
||||
// should check whether setting it in InitParams can work.
|
||||
if (has_frame()) {
|
||||
// TODO(zcbenz): This was used to force using native frame on Windows 2003,
|
||||
// we should check whether setting it in InitParams can work.
|
||||
window_->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE);
|
||||
window_->FrameTypeChanged();
|
||||
#if defined(OS_WIN)
|
||||
// thickFrame also works for normal window.
|
||||
if (!thick_frame_)
|
||||
FlipWindowStyle(GetAcceleratedWidget(), false, WS_THICKFRAME);
|
||||
#endif
|
||||
}
|
||||
|
||||
gfx::Size size = bounds.size();
|
||||
@@ -325,8 +319,6 @@ NativeWindowViews::NativeWindowViews(
|
||||
window_->CenterWindow(size);
|
||||
Layout();
|
||||
|
||||
autofill_popup_.reset(new AutofillPopup(GetNativeView()));
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Save initial window state.
|
||||
if (fullscreen)
|
||||
@@ -339,11 +331,6 @@ NativeWindowViews::NativeWindowViews(
|
||||
|
||||
NativeWindowViews::~NativeWindowViews() {
|
||||
window_->RemoveObserver(this);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Disable mouse forwarding to relinquish resources, should any be held.
|
||||
SetForwardMouseMessages(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::Close() {
|
||||
@@ -384,8 +371,7 @@ bool NativeWindowViews::IsFocused() {
|
||||
}
|
||||
|
||||
void NativeWindowViews::Show() {
|
||||
if (is_modal() && NativeWindow::parent() &&
|
||||
!window_->native_widget_private()->IsVisible())
|
||||
if (is_modal() && NativeWindow::parent())
|
||||
static_cast<NativeWindowViews*>(NativeWindow::parent())->SetEnabled(false);
|
||||
|
||||
window_->native_widget_private()->ShowWithWindowState(GetRestoredState());
|
||||
@@ -491,8 +477,6 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) {
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// There is no native fullscreen state on Windows.
|
||||
bool leaving_fullscreen = IsFullscreen() && !fullscreen;
|
||||
|
||||
if (fullscreen) {
|
||||
last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
|
||||
NotifyWindowEnterFullScreen();
|
||||
@@ -518,13 +502,6 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) {
|
||||
// We set the new value after notifying, so we can handle the size event
|
||||
// correctly.
|
||||
window_->SetFullscreen(fullscreen);
|
||||
|
||||
// If restoring from fullscreen and the window isn't visible, force visible,
|
||||
// else a non-responsive window shell could be rendered.
|
||||
// (this situation may arise when app starts with fullscreen: true)
|
||||
// Note: the following must be after "window_->SetFullscreen(fullscreen);"
|
||||
if (leaving_fullscreen && !IsVisible())
|
||||
FlipWindowStyle(GetAcceleratedWidget(), true, WS_VISIBLE);
|
||||
#else
|
||||
if (IsVisible())
|
||||
window_->SetFullscreen(fullscreen);
|
||||
@@ -582,12 +559,6 @@ gfx::Size NativeWindowViews::GetContentSize() {
|
||||
void NativeWindowViews::SetContentSizeConstraints(
|
||||
const extensions::SizeConstraints& size_constraints) {
|
||||
NativeWindow::SetContentSizeConstraints(size_constraints);
|
||||
#if defined(OS_WIN)
|
||||
// Changing size constraints would force adding the WS_THICKFRAME style, so
|
||||
// do nothing if thickFrame is false.
|
||||
if (!thick_frame_)
|
||||
return;
|
||||
#endif
|
||||
// widget_delegate() is only available after Init() is called, we make use of
|
||||
// this to determine whether native widget has initialized.
|
||||
if (window_ && window_->widget_delegate())
|
||||
@@ -600,7 +571,7 @@ void NativeWindowViews::SetContentSizeConstraints(
|
||||
|
||||
void NativeWindowViews::SetResizable(bool resizable) {
|
||||
#if defined(OS_WIN)
|
||||
if (has_frame() && thick_frame_)
|
||||
if (has_frame())
|
||||
FlipWindowStyle(GetAcceleratedWidget(), resizable, WS_THICKFRAME);
|
||||
#elif defined(USE_X11)
|
||||
if (resizable != resizable_) {
|
||||
@@ -770,14 +741,6 @@ void NativeWindowViews::SetSkipTaskbar(bool skip) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||
SetFullScreen(simple_fullscreen);
|
||||
}
|
||||
|
||||
bool NativeWindowViews::IsSimpleFullScreen() {
|
||||
return IsFullscreen();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetKiosk(bool kiosk) {
|
||||
SetFullScreen(kiosk);
|
||||
}
|
||||
@@ -804,51 +767,23 @@ void NativeWindowViews::SetBackgroundColor(const std::string& color_name) {
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetHasShadow(bool has_shadow) {
|
||||
wm::SetShadowElevation(
|
||||
wm::SetShadowType(
|
||||
GetNativeWindow(),
|
||||
has_shadow ? wm::ShadowElevation::MEDIUM : wm::ShadowElevation::NONE);
|
||||
has_shadow ? wm::SHADOW_TYPE_RECTANGULAR : wm::SHADOW_TYPE_NONE);
|
||||
}
|
||||
|
||||
bool NativeWindowViews::HasShadow() {
|
||||
return GetNativeWindow()->GetProperty(wm::kShadowElevationKey)
|
||||
!= wm::ShadowElevation::NONE;
|
||||
return wm::GetShadowType(GetNativeWindow()) != wm::SHADOW_TYPE_NONE;
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetOpacity(const double opacity) {
|
||||
#if defined(OS_WIN)
|
||||
HWND hwnd = GetAcceleratedWidget();
|
||||
if (!layered_) {
|
||||
LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||
ex_style |= WS_EX_LAYERED;
|
||||
::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
|
||||
layered_ = true;
|
||||
}
|
||||
::SetLayeredWindowAttributes(hwnd, 0, opacity * 255, LWA_ALPHA);
|
||||
#endif
|
||||
opacity_ = opacity;
|
||||
}
|
||||
|
||||
double NativeWindowViews::GetOpacity() {
|
||||
return opacity_;
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
|
||||
void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) {
|
||||
#if defined(OS_WIN)
|
||||
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
|
||||
if (ignore)
|
||||
ex_style |= (WS_EX_TRANSPARENT | WS_EX_LAYERED);
|
||||
else
|
||||
ex_style &= ~(WS_EX_TRANSPARENT | WS_EX_LAYERED);
|
||||
if (layered_)
|
||||
ex_style |= WS_EX_LAYERED;
|
||||
::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
|
||||
|
||||
// Forwarding is always disabled when not ignoring mouse messages.
|
||||
if (!ignore) {
|
||||
SetForwardMouseMessages(false);
|
||||
} else {
|
||||
SetForwardMouseMessages(forward);
|
||||
}
|
||||
#elif defined(USE_X11)
|
||||
if (ignore) {
|
||||
XRectangle r = {0, 0, 1, 1};
|
||||
@@ -988,11 +923,7 @@ void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
|
||||
#endif
|
||||
}
|
||||
|
||||
gfx::NativeView NativeWindowViews::GetNativeView() const {
|
||||
return window_->GetNativeView();
|
||||
}
|
||||
|
||||
gfx::NativeWindow NativeWindowViews::GetNativeWindow() const {
|
||||
gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
|
||||
return window_->GetNativeWindow();
|
||||
}
|
||||
|
||||
@@ -1063,7 +994,7 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
|
||||
return false;
|
||||
}
|
||||
|
||||
gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() const {
|
||||
gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
|
||||
return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
|
||||
}
|
||||
|
||||
@@ -1141,31 +1072,9 @@ void NativeWindowViews::OnWidgetBoundsChanged(
|
||||
if (widget != window_.get())
|
||||
return;
|
||||
|
||||
// Note: We intentionally use `GetBounds()` instead of `bounds` to properly
|
||||
// handle minimized windows on Windows.
|
||||
const auto new_bounds = GetBounds();
|
||||
if (widget_size_ != new_bounds.size()) {
|
||||
if (browser_view_) {
|
||||
const auto flags = static_cast<NativeBrowserViewViews*>(browser_view_)
|
||||
->GetAutoResizeFlags();
|
||||
int width_delta = 0;
|
||||
int height_delta = 0;
|
||||
if (flags & kAutoResizeWidth) {
|
||||
width_delta = new_bounds.width() - widget_size_.width();
|
||||
}
|
||||
if (flags & kAutoResizeHeight) {
|
||||
height_delta = new_bounds.height() - widget_size_.height();
|
||||
}
|
||||
|
||||
auto* view = browser_view_->GetInspectableWebContentsView()->GetView();
|
||||
auto new_view_size = view->size();
|
||||
new_view_size.set_width(new_view_size.width() + width_delta);
|
||||
new_view_size.set_height(new_view_size.height() + height_delta);
|
||||
view->SetSize(new_view_size);
|
||||
}
|
||||
|
||||
if (widget_size_ != bounds.size()) {
|
||||
NotifyWindowResize();
|
||||
widget_size_ = new_bounds.size();
|
||||
widget_size_ = bounds.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1266,7 +1175,7 @@ void NativeWindowViews::OnWidgetMove() {
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
|
||||
const gfx::Rect& bounds) const {
|
||||
const gfx::Rect& bounds) {
|
||||
if (!has_frame())
|
||||
return bounds;
|
||||
|
||||
@@ -1287,7 +1196,7 @@ gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowViews::WindowBoundsToContentBounds(
|
||||
const gfx::Rect& bounds) const {
|
||||
const gfx::Rect& bounds) {
|
||||
if (!has_frame())
|
||||
return bounds;
|
||||
|
||||
@@ -1325,15 +1234,15 @@ void NativeWindowViews::HandleKeyboardEvent(
|
||||
// Show accelerator when "Alt" is pressed.
|
||||
if (menu_bar_visible_ && IsAltKey(event))
|
||||
menu_bar_->SetAcceleratorVisibility(
|
||||
event.GetType() == blink::WebInputEvent::kRawKeyDown);
|
||||
event.type == blink::WebInputEvent::RawKeyDown);
|
||||
|
||||
// Show the submenu when "Alt+Key" is pressed.
|
||||
if (event.GetType() == blink::WebInputEvent::kRawKeyDown &&
|
||||
!IsAltKey(event) && IsAltModifier(event)) {
|
||||
if (event.type == blink::WebInputEvent::RawKeyDown && !IsAltKey(event) &&
|
||||
IsAltModifier(event)) {
|
||||
if (!menu_bar_visible_ &&
|
||||
(menu_bar_->GetAcceleratorIndex(event.windows_key_code) != -1))
|
||||
(menu_bar_->GetAcceleratorIndex(event.windowsKeyCode) != -1))
|
||||
SetMenuBarVisibility(true);
|
||||
menu_bar_->ActivateAccelerator(event.windows_key_code);
|
||||
menu_bar_->ActivateAccelerator(event.windowsKeyCode);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1341,11 +1250,11 @@ void NativeWindowViews::HandleKeyboardEvent(
|
||||
return;
|
||||
|
||||
// Toggle the menu bar only when a single Alt is released.
|
||||
if (event.GetType() == blink::WebInputEvent::kRawKeyDown && IsAltKey(event)) {
|
||||
if (event.type == blink::WebInputEvent::RawKeyDown && IsAltKey(event)) {
|
||||
// When a single Alt is pressed:
|
||||
menu_bar_alt_pressed_ = true;
|
||||
} else if (event.GetType() == blink::WebInputEvent::kKeyUp &&
|
||||
IsAltKey(event) && menu_bar_alt_pressed_) {
|
||||
} else if (event.type == blink::WebInputEvent::KeyUp && IsAltKey(event) &&
|
||||
menu_bar_alt_pressed_) {
|
||||
// When a single Alt is released right after a Alt is pressed:
|
||||
menu_bar_alt_pressed_ = false;
|
||||
SetMenuBarVisibility(!menu_bar_visible_);
|
||||
@@ -1355,26 +1264,6 @@ void NativeWindowViews::HandleKeyboardEvent(
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowViews::ShowAutofillPopup(
|
||||
content::RenderFrameHost* frame_host,
|
||||
const gfx::RectF& bounds,
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels) {
|
||||
auto wc = atom::api::WebContents::FromWrappedClass(
|
||||
v8::Isolate::GetCurrent(), web_contents());
|
||||
autofill_popup_->CreateView(
|
||||
frame_host,
|
||||
wc->IsOffScreenOrEmbedderOffscreen(),
|
||||
widget(),
|
||||
bounds);
|
||||
autofill_popup_->SetItems(values, labels);
|
||||
}
|
||||
|
||||
void NativeWindowViews::HideAutofillPopup(
|
||||
content::RenderFrameHost* frame_host) {
|
||||
autofill_popup_->Hide();
|
||||
}
|
||||
|
||||
void NativeWindowViews::Layout() {
|
||||
const auto size = GetContentsBounds().size();
|
||||
const auto menu_bar_bounds =
|
||||
@@ -1384,18 +1273,39 @@ void NativeWindowViews::Layout() {
|
||||
menu_bar_->SetBoundsRect(menu_bar_bounds);
|
||||
}
|
||||
|
||||
const auto old_web_view_size = web_view_ ? web_view_->size() : gfx::Size();
|
||||
if (web_view_) {
|
||||
web_view_->SetBoundsRect(
|
||||
gfx::Rect(0, menu_bar_bounds.height(), size.width(),
|
||||
size.height() - menu_bar_bounds.height()));
|
||||
}
|
||||
const auto new_web_view_size = web_view_ ? web_view_->size() : gfx::Size();
|
||||
|
||||
if (browser_view_) {
|
||||
const auto flags = static_cast<NativeBrowserViewViews*>(browser_view_)
|
||||
->GetAutoResizeFlags();
|
||||
int width_delta = 0;
|
||||
int height_delta = 0;
|
||||
if (flags & kAutoResizeWidth) {
|
||||
width_delta = new_web_view_size.width() - old_web_view_size.width();
|
||||
}
|
||||
if (flags & kAutoResizeHeight) {
|
||||
height_delta = new_web_view_size.height() - old_web_view_size.height();
|
||||
}
|
||||
|
||||
auto* view = browser_view_->GetInspectableWebContentsView()->GetView();
|
||||
auto new_view_size = view->size();
|
||||
new_view_size.set_width(new_view_size.width() + width_delta);
|
||||
new_view_size.set_height(new_view_size.height() + height_delta);
|
||||
view->SetSize(new_view_size);
|
||||
}
|
||||
}
|
||||
|
||||
gfx::Size NativeWindowViews::GetMinimumSize() const {
|
||||
gfx::Size NativeWindowViews::GetMinimumSize() {
|
||||
return NativeWindow::GetMinimumSize();
|
||||
}
|
||||
|
||||
gfx::Size NativeWindowViews::GetMaximumSize() const {
|
||||
gfx::Size NativeWindowViews::GetMaximumSize() {
|
||||
return NativeWindow::GetMaximumSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,10 @@
|
||||
|
||||
#include "atom/browser/native_window.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "atom/browser/ui/autofill_popup.h"
|
||||
#include "ui/views/widget/widget_delegate.h"
|
||||
#include "ui/views/widget/widget_observer.h"
|
||||
|
||||
@@ -97,23 +95,18 @@ class NativeWindowViews : public NativeWindow,
|
||||
std::string GetTitle() override;
|
||||
void FlashFrame(bool flash) override;
|
||||
void SetSkipTaskbar(bool skip) override;
|
||||
void SetSimpleFullScreen(bool simple_fullscreen) override;
|
||||
bool IsSimpleFullScreen() override;
|
||||
void SetKiosk(bool kiosk) override;
|
||||
bool IsKiosk() override;
|
||||
void SetBackgroundColor(const std::string& color_name) override;
|
||||
void SetHasShadow(bool has_shadow) override;
|
||||
bool HasShadow() override;
|
||||
void SetOpacity(const double opacity) override;
|
||||
double GetOpacity() override;
|
||||
void SetIgnoreMouseEvents(bool ignore, bool forward) override;
|
||||
void SetIgnoreMouseEvents(bool ignore) override;
|
||||
void SetContentProtection(bool enable) override;
|
||||
void SetFocusable(bool focusable) override;
|
||||
void SetMenu(AtomMenuModel* menu_model) override;
|
||||
void SetBrowserView(NativeBrowserView* browser_view) override;
|
||||
void SetParentWindow(NativeWindow* parent) override;
|
||||
gfx::NativeView GetNativeView() const override;
|
||||
gfx::NativeWindow GetNativeWindow() const override;
|
||||
gfx::NativeWindow GetNativeWindow() override;
|
||||
void SetOverlayIcon(const gfx::Image& overlay,
|
||||
const std::string& description) override;
|
||||
void SetProgressBar(double progress, const ProgressState state) override;
|
||||
@@ -124,7 +117,7 @@ class NativeWindowViews : public NativeWindow,
|
||||
void SetVisibleOnAllWorkspaces(bool visible) override;
|
||||
bool IsVisibleOnAllWorkspaces() override;
|
||||
|
||||
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
|
||||
gfx::AcceleratedWidget GetAcceleratedWidget() override;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void SetIcon(HICON small_icon, HICON app_icon);
|
||||
@@ -174,31 +167,19 @@ class NativeWindowViews : public NativeWindow,
|
||||
bool PreHandleMSG(
|
||||
UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) override;
|
||||
void HandleSizeEvent(WPARAM w_param, LPARAM l_param);
|
||||
void SetForwardMouseMessages(bool forward);
|
||||
static LRESULT CALLBACK SubclassProc(
|
||||
HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param, UINT_PTR subclass_id,
|
||||
DWORD_PTR ref_data);
|
||||
static LRESULT CALLBACK MouseHookProc(
|
||||
int n_code, WPARAM w_param, LPARAM l_param);
|
||||
#endif
|
||||
|
||||
// NativeWindow:
|
||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
|
||||
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
|
||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) override;
|
||||
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) override;
|
||||
void HandleKeyboardEvent(
|
||||
content::WebContents*,
|
||||
const content::NativeWebKeyboardEvent& event) override;
|
||||
void ShowAutofillPopup(
|
||||
content::RenderFrameHost* frame_host,
|
||||
const gfx::RectF& bounds,
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels) override;
|
||||
void HideAutofillPopup(content::RenderFrameHost* frame_host) override;
|
||||
|
||||
// views::View:
|
||||
void Layout() override;
|
||||
gfx::Size GetMinimumSize() const override;
|
||||
gfx::Size GetMaximumSize() const override;
|
||||
gfx::Size GetMinimumSize() override;
|
||||
gfx::Size GetMaximumSize() override;
|
||||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||
|
||||
// Register accelerators supported by the menu model.
|
||||
@@ -212,8 +193,6 @@ class NativeWindowViews : public NativeWindow,
|
||||
|
||||
NativeBrowserView* browser_view_;
|
||||
|
||||
std::unique_ptr<AutofillPopup> autofill_popup_;
|
||||
|
||||
std::unique_ptr<MenuBar> menu_bar_;
|
||||
bool menu_bar_autohide_;
|
||||
bool menu_bar_visible_;
|
||||
@@ -270,13 +249,6 @@ class NativeWindowViews : public NativeWindow,
|
||||
// The icons of window and taskbar.
|
||||
base::win::ScopedHICON window_icon_;
|
||||
base::win::ScopedHICON app_icon_;
|
||||
|
||||
// The set of windows currently forwarding mouse messages.
|
||||
static std::set<NativeWindowViews*> forwarding_windows_;
|
||||
static HHOOK mouse_hook_;
|
||||
bool forwarding_mouse_messages_ = false;
|
||||
HWND legacy_window_ = NULL;
|
||||
bool layered_ = false;
|
||||
#endif
|
||||
|
||||
// Handles unhandled keyboard messages coming back from the renderer process.
|
||||
@@ -296,7 +268,6 @@ class NativeWindowViews : public NativeWindow,
|
||||
bool fullscreenable_;
|
||||
std::string title_;
|
||||
gfx::Size widget_size_;
|
||||
double opacity_ = 1.0;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);
|
||||
};
|
||||
|
||||
@@ -80,9 +80,6 @@ bool IsScreenReaderActive() {
|
||||
|
||||
} // namespace
|
||||
|
||||
std::set<NativeWindowViews*> NativeWindowViews::forwarding_windows_;
|
||||
HHOOK NativeWindowViews::mouse_hook_ = NULL;
|
||||
|
||||
bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
|
||||
std::string command = AppCommandToString(command_id);
|
||||
NotifyWindowExecuteWindowsCommand(command);
|
||||
@@ -154,16 +151,6 @@ bool NativeWindowViews::PreHandleMSG(
|
||||
if (w_param) {
|
||||
NotifyWindowEndSession();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case WM_PARENTNOTIFY: {
|
||||
if (LOWORD(w_param) == WM_CREATE) {
|
||||
// Because of reasons regarding legacy drivers and stuff, a window that
|
||||
// matches the client area is created and used internally by Chromium.
|
||||
// This is used when forwarding mouse messages.
|
||||
legacy_window_ = reinterpret_cast<HWND>(l_param);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
@@ -220,86 +207,4 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetForwardMouseMessages(bool forward) {
|
||||
if (forward && !forwarding_mouse_messages_) {
|
||||
forwarding_mouse_messages_ = true;
|
||||
forwarding_windows_.insert(this);
|
||||
|
||||
// Subclassing is used to fix some issues when forwarding mouse messages;
|
||||
// see comments in |SubclassProc|.
|
||||
SetWindowSubclass(
|
||||
legacy_window_, SubclassProc, 1, reinterpret_cast<DWORD_PTR>(this));
|
||||
|
||||
if (!mouse_hook_) {
|
||||
mouse_hook_ = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0);
|
||||
}
|
||||
} else if (!forward && forwarding_mouse_messages_) {
|
||||
forwarding_mouse_messages_ = false;
|
||||
forwarding_windows_.erase(this);
|
||||
|
||||
RemoveWindowSubclass(legacy_window_, SubclassProc, 1);
|
||||
|
||||
if (forwarding_windows_.size() == 0) {
|
||||
UnhookWindowsHookEx(mouse_hook_);
|
||||
mouse_hook_ = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CALLBACK NativeWindowViews::SubclassProc(
|
||||
HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param, UINT_PTR subclass_id,
|
||||
DWORD_PTR ref_data) {
|
||||
NativeWindowViews* window = reinterpret_cast<NativeWindowViews*>(ref_data);
|
||||
switch (msg) {
|
||||
case WM_MOUSELEAVE: {
|
||||
// When input is forwarded to underlying windows, this message is posted.
|
||||
// If not handled, it interferes with Chromium logic, causing for example
|
||||
// mouseleave events to fire. If those events are used to exit forward
|
||||
// mode, excessive flickering on for example hover items in underlying
|
||||
// windows can occur due to rapidly entering and leaving forwarding mode.
|
||||
// By consuming and ignoring the message, we're essentially telling
|
||||
// Chromium that we have not left the window despite somebody else getting
|
||||
// the messages. As to why this is catched for the legacy window and not
|
||||
// the actual browser window is simply that the legacy window somehow
|
||||
// makes use of these events; posting to the main window didn't work.
|
||||
if (window->forwarding_mouse_messages_) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return DefSubclassProc(hwnd, msg, w_param, l_param);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK NativeWindowViews::MouseHookProc(
|
||||
int n_code, WPARAM w_param, LPARAM l_param) {
|
||||
if (n_code < 0) {
|
||||
return CallNextHookEx(NULL, n_code, w_param, l_param);
|
||||
}
|
||||
|
||||
// Post a WM_MOUSEMOVE message for those windows whose client area contains
|
||||
// the cursor since they are in a state where they would otherwise ignore all
|
||||
// mouse input.
|
||||
if (w_param == WM_MOUSEMOVE) {
|
||||
for (auto window : forwarding_windows_) {
|
||||
// At first I considered enumerating windows to check whether the cursor
|
||||
// was directly above the window, but since nothing bad seems to happen
|
||||
// if we post the message even if some other window occludes it I have
|
||||
// just left it as is.
|
||||
RECT client_rect;
|
||||
GetClientRect(window->legacy_window_, &client_rect);
|
||||
POINT p = reinterpret_cast<MSLLHOOKSTRUCT*>(l_param)->pt;
|
||||
ScreenToClient(window->legacy_window_, &p);
|
||||
if (PtInRect(&client_rect, p)) {
|
||||
WPARAM w = 0; // No virtual keys pressed for our purposes
|
||||
LPARAM l = MAKELPARAM(p.x, p.y);
|
||||
PostMessage(window->legacy_window_, WM_MOUSEMOVE, w, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CallNextHookEx(NULL, n_code, w_param, l_param);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "base/task_runner.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "net/base/file_stream.h"
|
||||
#include "net/base/filename_util.h"
|
||||
#include "net/base/io_buffer.h"
|
||||
@@ -120,11 +119,8 @@ void URLRequestAsarJob::Start() {
|
||||
weak_ptr_factory_.GetWeakPtr(),
|
||||
base::Owned(meta_info)));
|
||||
} else {
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&URLRequestAsarJob::DidOpen,
|
||||
weak_ptr_factory_.GetWeakPtr(),
|
||||
net::ERR_FILE_NOT_FOUND));
|
||||
NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
||||
net::ERR_FILE_NOT_FOUND));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ class URLRequestAsarJob : public net::URLRequestJob {
|
||||
// Callback after fetching file info on a background thread.
|
||||
void DidFetchMetaInfo(const FileMetaInfo* meta_info);
|
||||
|
||||
|
||||
// Callback after opening file on a background thread.
|
||||
void DidOpen(int result);
|
||||
|
||||
|
||||
@@ -92,7 +92,6 @@ class CertVerifierRequest : public AtomCertVerifier::Request {
|
||||
std::unique_ptr<VerifyRequestParams> request(new VerifyRequestParams());
|
||||
request->hostname = params_.hostname();
|
||||
request->default_result = net::ErrorToString(error);
|
||||
request->error_code = error;
|
||||
request->certificate = params_.certificate();
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::UI, FROM_HERE,
|
||||
|
||||
@@ -19,7 +19,6 @@ class CertVerifierRequest;
|
||||
struct VerifyRequestParams {
|
||||
std::string hostname;
|
||||
std::string default_result;
|
||||
int error_code;
|
||||
scoped_refptr<net::X509Certificate> certificate;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,13 +6,11 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "brightray/browser/net/devtools_network_transaction.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
|
||||
using brightray::DevToolsNetworkTransaction;
|
||||
@@ -76,23 +74,10 @@ void ToDictionary(base::DictionaryValue* details, net::URLRequest* request) {
|
||||
FillRequestDetails(details, request);
|
||||
details->SetInteger("id", request->identifier());
|
||||
details->SetDouble("timestamp", base::Time::Now().ToDoubleT() * 1000);
|
||||
const auto* info = content::ResourceRequestInfo::ForRequest(request);
|
||||
if (info) {
|
||||
int process_id = info->GetChildID();
|
||||
int frame_id = info->GetRenderFrameID();
|
||||
auto* webContents = content::WebContents::FromRenderFrameHost(
|
||||
content::RenderFrameHost::FromID(process_id, frame_id));
|
||||
int webContentsId = atom::api::WebContents::GetIDFromWrappedClass(
|
||||
webContents);
|
||||
|
||||
// webContentsId must be greater than zero
|
||||
if (webContentsId)
|
||||
details->SetInteger("webContentsId", webContentsId);
|
||||
details->SetString("resourceType",
|
||||
ResourceTypeToString(info->GetResourceType()));
|
||||
} else {
|
||||
details->SetString("resourceType", "other");
|
||||
}
|
||||
auto info = content::ResourceRequestInfo::ForRequest(request);
|
||||
details->SetString("resourceType",
|
||||
info ? ResourceTypeToString(info->GetResourceType())
|
||||
: "other");
|
||||
}
|
||||
|
||||
void ToDictionary(base::DictionaryValue* details,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user