Merge remote-tracking branch 'atom/master'

This commit is contained in:
Plusb Preco 2015-09-27 22:20:51 +09:00
commit 7923e19553
69 changed files with 908 additions and 213 deletions

View file

@ -665,7 +665,7 @@ Same as `webContents.loadUrl(url[, options])`.
Same as `webContents.reload`.
### `win.setMenu(menu)` _OS X_
### `win.setMenu(menu)` _Linux_ _Windows_
* `menu` Menu

View file

@ -87,6 +87,11 @@ Sets the `version` of the pepper flash plugin.
Enables net log events to be saved and writes them to `path`.
## --ssl-version-fallback-min=`version`
Set the minimum SSL/TLS version ("tls1", "tls1.1" or "tls1.2") that TLS
fallback will accept.
## --v=`log_level`
Gives the default maximal active V-logging level; 0 is the default. Normally

101
docs/api/download-item.md Normal file
View file

@ -0,0 +1,101 @@
# DownloadItem
`DownloadItem` is an EventEmitter represents a download item in Electron. It
is used in `will-download` event of `Session` module, and allows users to
control the download item.
```javascript
// In the main process.
win.webContents.session.on('will-download', function(event, item, webContents) {
// Set the save path, making Electron not to prompt a save dialog.
item.setSavePath('/tmp/save.pdf');
console.log(item.getMimeType());
console.log(item.getFilename());
console.log(item.getTotalBytes());
item.on('updated', function() {
console.log('Received bytes: ' + item.getReceivedBytes());
});
item.on('done', function(e, state) {
if (state == "completed") {
console.log("Download successfully");
} else {
console.log("Download is cancelled or interrupted that can't be resumed");
}
});
```
## Events
### Event: 'updated'
Emits when the `downloadItem` gets updated.
### Event: 'done'
* `event` Event
* `state` String
* `completed` - The download completed successfully.
* `cancelled` - The download has been cancelled.
* `interrupted` - An error broke the connection with the file server.
Emits when the download is in a terminal state. This includes a completed
download, a cancelled download(via `downloadItem.cancel()`), and interrupted
download that can't be resumed.
## Methods
The `downloadItem` object has the following methods:
### `downloadItem.setSavePath(path)`
* `path` String - Set the save file path of the download item.
The API is only available in session's `will-download` callback function.
If user doesn't set the save path via the API, Electron will use the original
routine to determine the save path(Usually prompts a save dialog).
### `downloadItem.pause()`
Pauses the download.
### `downloadItem.resume()`
Resumes the download that has been paused.
### `downloadItem.cancel()`
Cancels the download operation.
### `downloadItem.getUrl()`
Returns a `String` represents the origin url where the item is downloaded from.
### `downloadItem.getMimeType()`
Returns a `String` represents the mime type.
### `downloadItem.hasUserGesture()`
Returns a `Boolean` indicates whether the download has user gesture.
### `downloadItem.getFilename()`
Returns a `String` represents the file name of the download item.
**Note:** The file name is not always the same as the actual one saved in local
disk. If user changes the file name in a prompted download saving dialog, the
actual name of saved file will be different.
### `downloadItem.getTotalBytes()`
Returns a `Integer` represents the total size in bytes of the download item.
If the size is unknown, it returns 0.
### `downloadItem.getReceivedBytes()`
Returns a `Integer` represents the received bytes of the download item.
### `downloadItem.getContentDisposition()`
Returns a `String` represents the Content-Disposition field from the response
header.

View file

@ -18,11 +18,7 @@ var session = win.webContents.session
### Event: 'will-download'
* `event` Event
* `item` Object
* `url` String
* `filename` String
* `mimeType` String
* `hasUserGesture` Boolean
* `item` [DownloadItem](download-item.md)
* `webContents` [WebContents](web-contents.md)
Fired when Electron is about to download `item` in `webContents`.
@ -32,7 +28,7 @@ Calling `event.preventDefault()` will cancel the download.
```javascript
session.on('will-download', function(event, item, webContents) {
event.preventDefault();
require('request')(item.url, function(data) {
require('request')(item.getUrl(), function(data) {
require('fs').writeFileSync('/somewhere', data);
});
});

View file

@ -78,6 +78,10 @@ Returns:
* `oldUrl` String
* `newUrl` String
* `isMainFrame` Boolean
* `httpResponseCode` Integer
* `requestMethod` String
* `referrer` String
* `headers` Object
Emitted when a redirect is received while requesting a resource.
@ -107,6 +111,8 @@ Returns:
* `frameName` String
* `disposition` String - Can be `default`, `foreground-tab`, `background-tab`,
`new-window` and `other`.
* `options` Object - The options which will be used for creating the new
`BrowserWindow`.
Emitted when the page requests to open a new window for a `url`. It could be
requested by `window.open` or an external link like `<a target='_blank'>`.
@ -415,7 +421,7 @@ win.webContents.on("did-finish-load", function() {
win.webContents.printToPDF({}, function(error, data) {
if (error) throw error;
fs.writeFile("/tmp/print.pdf", data, function(error) {
if (err)
if (error)
throw error;
console.log("Write PDF successfully.");
})

View file

@ -83,4 +83,11 @@ attackers.
Resources will be loaded from this `scheme` regardless of the current page's
Content Security Policy.
### `webFrame.registerUrlSchemeAsPrivileged(scheme)`
* `scheme` String
Registers the `scheme` as secure, bypasses content security policy for resources and
allows registering ServiceWorker.
[spellchecker]: https://github.com/atom/node-spellchecker

View file

@ -149,6 +149,14 @@ This value can only be modified before the first navigation, since the session
of an active renderer process cannot change. Subsequent attempts to modify the
value will fail with a DOM exception.
### `allowpopups`
```html
<webview src="https://www.github.com/" allowpopups></webview>
```
If "on", the guest page will be allowed to open new windows.
## Methods
The `webview` tag has the following methods:
@ -496,7 +504,9 @@ Returns:
* `url` String
* `frameName` String
* `disposition` String - Can be `default`, `foreground-tab`, `background-tab`,
`new-window` and `other`
`new-window` and `other`.
* `options` Object - The options which should be used for creating the new
`BrowserWindow`.
Fired when the guest page attempts to open a new browser window.

View file

@ -8,6 +8,10 @@ The proxy has limited standard functionality implemented to be
compatible with traditional web pages. For full control of the new window
you should create a `BrowserWindow` directly.
The newly created `BrowserWindow` will inherit parent window's options by
default, to override inherited options you can set them in the `features`
string.
### `window.open(url[, frameName][, features])`
* `url` String
@ -16,6 +20,9 @@ you should create a `BrowserWindow` directly.
Creates a new window and returns an instance of `BrowserWindowProxy` class.
The `features` string follows the format of standard browser, but each feature
has to be a field of `BrowserWindow`'s options.
### `window.opener.postMessage(message, targetOrigin)`
* `message` String

View file

@ -124,6 +124,7 @@ Finally the `index.html` is the web page you want to show:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>

View file

@ -34,6 +34,19 @@ npm install --save-dev electron-rebuild
node ./node_modules/.bin/electron-rebuild
```
### The npm Way
You can also use `npm` to install modules. The steps are exactly the same with
Node modules, except that you need to setup some environment variables:
```bash
export npm_config_disturl=https://atom.io/download/atom-shell
export npm_config_target=0.33.1
export npm_config_arch=x64
export npm_config_runtime=electron
HOME=~/.electron-gyp npm install module-name
```
### The node-gyp Way
To build Node modules with headers of Electron, you need to tell `node-gyp`
@ -48,15 +61,3 @@ The `HOME=~/.electron-gyp` changes where to find development headers. The
`--target=0.29.1` is version of Electron. The `--dist-url=...` specifies
where to download the headers. The `--arch=x64` says the module is built for
64bit system.
### The npm Way
You can also use `npm` to install modules. The steps are exactly the same with
Node modules, except that you need to setup some environment variables:
```bash
export npm_config_disturl=https://atom.io/download/atom-shell
export npm_config_target=0.29.1
export npm_config_arch=x64
HOME=~/.electron-gyp npm install module-name
```