Merge remote-tracking branch 'refs/remotes/atom/master'

This commit is contained in:
Plusb Preco 2015-11-23 18:23:15 +09:00
commit 54f16a5568
28 changed files with 304 additions and 162 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.DS_Store
.tags*
/.idea/
/build/
/dist/

View file

@ -4,7 +4,7 @@
'product_name%': 'Electron',
'company_name%': 'GitHub, Inc',
'company_abbr%': 'github',
'version%': '0.35.0',
'version%': '0.35.1',
},
'includes': [
'filenames.gypi',

View file

@ -206,14 +206,6 @@ void App::OnWillFinishLaunching() {
}
void App::OnFinishLaunching() {
// Create the defaultSession.
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
auto browser_context = static_cast<AtomBrowserContext*>(
AtomBrowserMainParts::Get()->browser_context());
auto handle = Session::CreateFrom(isolate(), browser_context);
default_session_.Reset(isolate(), handle.ToV8());
Emit("ready");
}
@ -325,13 +317,6 @@ std::string App::GetLocale() {
return l10n_util::GetApplicationLocale("");
}
v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
if (default_session_.IsEmpty())
return v8::Null(isolate);
else
return v8::Local<v8::Value>::New(isolate, default_session_);
}
bool App::MakeSingleInstance(
const ProcessSingleton::NotificationCallback& callback) {
if (process_singleton_.get())
@ -382,8 +367,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
.SetMethod("allowNTLMCredentialsForAllDomains",
&App::AllowNTLMCredentialsForAllDomains)
.SetMethod("getLocale", &App::GetLocale)
.SetMethod("makeSingleInstance", &App::MakeSingleInstance)
.SetProperty("defaultSession", &App::DefaultSession);
.SetMethod("makeSingleInstance", &App::MakeSingleInstance);
}
// static

View file

@ -87,9 +87,6 @@ class App : public AtomBrowserClient::Delegate,
bool MakeSingleInstance(
const ProcessSingleton::NotificationCallback& callback);
std::string GetLocale();
v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
v8::Global<v8::Value> default_session_;
scoped_ptr<ProcessSingleton> process_singleton_;

View file

@ -261,13 +261,23 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
#endif
// static
mate::Wrappable* Window::New(v8::Isolate* isolate,
const mate::Dictionary& options) {
mate::Wrappable* Window::New(v8::Isolate* isolate, mate::Arguments* args) {
if (!Browser::Get()->is_ready()) {
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate, "Cannot create BrowserWindow before app is ready")));
return nullptr;
}
if (args->Length() > 1) {
args->ThrowError();
return nullptr;
}
mate::Dictionary options;
if (!(args->Length() == 1 && args->GetNext(&options))) {
options = mate::Dictionary::CreateEmpty(isolate);
}
return new Window(isolate, options);
}

View file

@ -38,8 +38,7 @@ class WebContents;
class Window : public mate::TrackableObject<Window>,
public NativeWindowObserver {
public:
static mate::Wrappable* New(v8::Isolate* isolate,
const mate::Dictionary& options);
static mate::Wrappable* New(v8::Isolate* isolate, mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);

View file

@ -1,18 +1,17 @@
electron = require 'electron'
{deprecate, session, Menu} = require 'electron'
{EventEmitter} = require 'events'
bindings = process.atomBinding 'app'
sessionBindings = process.atomBinding 'session'
downloadItemBindings = process.atomBinding 'download_item'
app = bindings.app
app.__proto__ = EventEmitter.prototype
app.setApplicationMenu = (menu) ->
electron.Menu.setApplicationMenu menu
Menu.setApplicationMenu menu
app.getApplicationMenu = ->
electron.Menu.getApplicationMenu()
Menu.getApplicationMenu()
app.commandLine =
appendSwitch: bindings.appendSwitch,
@ -35,9 +34,6 @@ app.setAppPath = (path) ->
app.getAppPath = ->
appPath
# Helpers.
app.resolveProxy = (url, callback) -> @defaultSession.resolveProxy url, callback
# Routes the events to webContents.
for name in ['login', 'certificate-error', 'select-client-certificate']
do (name) ->
@ -45,13 +41,14 @@ for name in ['login', 'certificate-error', 'select-client-certificate']
webContents.emit name, event, args...
# Deprecated.
{deprecate} = electron
app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', ->
@getPath 'home'
app.getDataPath = deprecate 'app.getDataPath', 'app.getPath', ->
@getPath 'userData'
app.setDataPath = deprecate 'app.setDataPath', 'app.setPath', (path) ->
@setPath 'userData', path
app.resolveProxy = deprecate 'app.resolveProxy', 'session.defaultSession.resolveProxy', (url, callback) ->
session.defaultSession.resolveProxy url, callback
deprecate.rename app, 'terminate', 'quit'
deprecate.event app, 'finish-launching', 'ready', ->
setImmediate => # give default app a chance to setup default menu.
@ -61,11 +58,6 @@ deprecate.event app, 'activate-with-no-open-windows', 'activate', (event, hasVis
deprecate.event app, 'select-certificate', 'select-client-certificate'
# Wrappers for native classes.
wrapSession = (session) ->
# session is an EventEmitter.
session.__proto__ = EventEmitter.prototype
sessionBindings._setWrapSession wrapSession
wrapDownloadItem = (downloadItem) ->
# downloadItem is an EventEmitter.
downloadItem.__proto__ = EventEmitter.prototype

View file

@ -1,10 +1,12 @@
{app, ipcMain, deprecate} = require 'electron'
{ipcMain, deprecate} = require 'electron'
{EventEmitter} = require 'events'
{BrowserWindow} = process.atomBinding 'window'
BrowserWindow::__proto__ = EventEmitter.prototype
BrowserWindow::_init = ->
{app} = require 'electron' # avoid recursive require.
# Simulate the application menu on platforms other than OS X.
if process.platform isnt 'darwin'
menu = app.getApplicationMenu()

View file

@ -42,6 +42,9 @@ Object.defineProperties module.exports,
screen:
enumerable: true
get: -> require '../screen'
session:
enumerable: true
get: -> require '../session'
Tray:
enumerable: true
get: -> require '../tray'

View file

@ -13,6 +13,11 @@ rolesMap =
minimize: 'minimize'
close: 'close'
# Maps methods that should be called directly on the BrowserWindow instance
methodInBrowserWindow =
minimize: true
close: true
class MenuItem
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
@ -42,8 +47,12 @@ class MenuItem
# Manually flip the checked flags when clicked.
@checked = !@checked if @type in ['checkbox', 'radio']
if @role and rolesMap[@role] and process.platform isnt 'darwin'
focusedWindow?[rolesMap[@role]]()
if @role and rolesMap[@role] and process.platform isnt 'darwin' and focusedWindow?
methodName = rolesMap[@role]
if methodInBrowserWindow[methodName]
focusedWindow[methodName]()
else
focusedWindow.webContents?[methodName]()
else if typeof click is 'function'
click this, focusedWindow
else if typeof @selector is 'string'

View file

@ -0,0 +1,23 @@
{EventEmitter} = require 'events'
bindings = process.atomBinding 'session'
PERSIST_PERFIX = 'persist:'
# Returns the Session from |partition| string.
exports.fromPartition = (partition='') ->
if partition.startsWith PERSIST_PERFIX
bindings.fromPartition partition.substr(PERSIST_PERFIX.length), false
else
bindings.fromPartition partition, true
# Returns the default session.
Object.defineProperty exports, 'defaultSession',
enumerable: true
get: -> exports.fromPartition ''
wrapSession = (session) ->
# session is an EventEmitter.
session.__proto__ = EventEmitter.prototype
bindings._setWrapSession wrapSession

View file

@ -1,5 +1,5 @@
{EventEmitter} = require 'events'
{deprecate, ipcMain, NavigationController, Menu} = require 'electron'
{deprecate, ipcMain, session, NavigationController, Menu} = require 'electron'
binding = process.atomBinding 'web_contents'

View file

@ -76,7 +76,11 @@
};
</script>
<h2 style="-webkit-app-region: drag">Welcome to Electron</h2>
<h2>
<script>
document.write(`Welcome to Electron (v${process.versions.electron})`)
</script>
</h2>
<p>
To run your app with Electron, execute the following command under your
@ -87,8 +91,18 @@
<p>
The <code>path-to-your-app</code> should be the path to your own Electron
app, you can read the <a href='https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md'>quick start</a>
guide in Electron's <a href='https://github.com/atom/electron/blob/master/docs'>docs</a>
app, you can read the
<script>
document.write(
`<a href='https://github.com/atom/electron/blob/v${process.versions.electron}/docs/tutorial/quick-start.md'>quick start</a>`
);
</script>
guide in Electron's
<script>
document.write(
`<a href='https://github.com/atom/electron/tree/v${process.versions.electron}/docs#readme'>docs</a>`
);
</script>
on how to write one.
</p>

View file

@ -148,7 +148,11 @@ app.once('ready', function() {
},
{
label: 'Documentation',
click: function() { shell.openExternal('https://github.com/atom/electron/tree/master/docs#readme') }
click: function() {
shell.openExternal(
`https://github.com/atom/electron/tree/v${process.versions.electron}/docs#readme`
)
}
},
{
label: 'Community Discussions',
@ -249,7 +253,11 @@ if (option.file && !option.webdriver) {
} catch(e) {
if (e.code == 'MODULE_NOT_FOUND') {
app.focus();
dialog.showErrorBox('Error opening app', 'The app provided is not a valid electron app, please read the docs on how to write one:\nhttps://github.com/atom/electron/tree/master/docs\n\n' + e.toString());
dialog.showErrorBox(
'Error opening app',
'The app provided is not a valid Electron app, please read the docs on how to write one:\n' +
`https://github.com/atom/electron/tree/v${process.versions.electron}/docs\n\n${e.toString()}`
);
process.exit(1);
} else {
console.error('App threw an error when running', e);

View file

@ -211,6 +211,8 @@ bool ScopedDisableResize::disable_resize_ = false;
}
@property BOOL acceptsFirstMouse;
@property BOOL disableAutoHideCursor;
@property BOOL disableKeyOrMainWindow;
- (void)setShell:(atom::NativeWindowMac*)shell;
- (void)setEnableLargerThanScreen:(bool)enable;
@end
@ -257,6 +259,14 @@ bool ScopedDisableResize::disable_resize_ = false;
return [children filteredArrayUsingPredicate:predicate];
}
- (BOOL)canBecomeMainWindow {
return !self.disableKeyOrMainWindow;
}
- (BOOL)canBecomeKeyWindow {
return !self.disableKeyOrMainWindow;
}
@end
@interface ControlRegionView : NSView
@ -330,8 +340,6 @@ NativeWindowMac::NativeWindowMac(
width,
height);
bool useStandardWindow = true;
options.Get(options::kStandardWindow, &useStandardWindow);
bool resizable = true;
options.Get(options::kResizable, &resizable);
@ -340,6 +348,17 @@ NativeWindowMac::NativeWindowMac(
if (base::mac::IsOSYosemiteOrLater())
options.Get(options::kTitleBarStyle, &titleBarStyle);
std::string windowType;
options.Get(options::kType, &windowType);
bool useStandardWindow = true;
// eventually deprecate separate "standardWindow" option in favor of
// standard / textured window types
options.Get(options::kStandardWindow, &useStandardWindow);
if (windowType == "textured") {
useStandardWindow = false;
}
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask;
if (!useStandardWindow || transparent() || !has_frame()) {
@ -371,6 +390,15 @@ NativeWindowMac::NativeWindowMac(
[window_ setBackgroundColor:[NSColor clearColor]];
}
if (windowType == "desktop") {
[window_ setLevel:kCGDesktopWindowLevel - 1];
[window_ setDisableKeyOrMainWindow:YES];
[window_ setCollectionBehavior:
(NSWindowCollectionBehaviorCanJoinAllSpaces |
NSWindowCollectionBehaviorStationary |
NSWindowCollectionBehaviorIgnoresCycle)];
}
// Remove non-transparent corners, see http://git.io/vfonD.
if (!has_frame())
[window_ setOpaque:NO];

View file

@ -17,9 +17,9 @@
<key>CFBundleIconFile</key>
<string>atom.icns</string>
<key>CFBundleVersion</key>
<string>0.35.0</string>
<string>0.35.1</string>
<key>CFBundleShortVersionString</key>
<string>0.35.0</string>
<string>0.35.1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>

View file

@ -56,8 +56,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,35,0,0
PRODUCTVERSION 0,35,0,0
FILEVERSION 0,35,1,0
PRODUCTVERSION 0,35,1,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -74,12 +74,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "GitHub, Inc."
VALUE "FileDescription", "Electron"
VALUE "FileVersion", "0.35.0"
VALUE "FileVersion", "0.35.1"
VALUE "InternalName", "electron.exe"
VALUE "LegalCopyright", "Copyright (C) 2015 GitHub, Inc. All rights reserved."
VALUE "OriginalFilename", "electron.exe"
VALUE "ProductName", "Electron"
VALUE "ProductVersion", "0.35.0"
VALUE "ProductVersion", "0.35.1"
VALUE "SquirrelAwareVersion", "1"
END
END

View file

@ -7,7 +7,7 @@
#define ATOM_MAJOR_VERSION 0
#define ATOM_MINOR_VERSION 35
#define ATOM_PATCH_VERSION 0
#define ATOM_PATCH_VERSION 1
#define ATOM_VERSION_IS_RELEASE 1

View file

@ -355,3 +355,4 @@ exports.wrapFsWithAsar = (fs) ->
overrideAPISync process, 'dlopen', 1
overrideAPISync require('module')._extensions, '.node', 1
overrideAPISync fs, 'openSync'
overrideAPISync child_process, 'execFileSync'

View file

@ -1,3 +1,12 @@
Please make sure that you use the documents that match your Electron version.
The version number should be a part of the page URL. If it's not, you are
probably using the documentation of a development branch which may contain API
changes that are not compatible with your Electron version. If that's the case,
you can switch to a different version of the documentation at the
[available versions](http://electron.atom.io/docs/) list on atom.io, or if
you're using the GitHub interface, open the "Switch branches/tags" dropdown and
select the tag that matches your version.
## Guides
* [Supported Platforms](tutorial/supported-platforms.md)

View file

@ -311,14 +311,6 @@ preferred over `name` by Electron.
Returns the current application locale.
### `app.resolveProxy(url, callback)`
* `url` URL
* `callback` Function
Resolves the proxy information for `url`. The `callback` will be called with
`callback(proxy)` when the request is performed.
### `app.addRecentDocument(path)` _OS X_ _Windows_
* `path` String

View file

@ -25,56 +25,70 @@ You can also create a window without chrome by using
It creates a new `BrowserWindow` with native properties as set by the `options`.
### `new BrowserWindow(options)`
### `new BrowserWindow([options])`
`options` Object, properties:
`options` Object (optional), properties:
* `width` Integer - Window's width.
* `height` Integer - Window's height.
* `x` Integer - Window's left offset from screen.
* `y` Integer - Window's top offset from screen.
* `width` Integer - Window's width in pixels. Default is `800`.
* `height` Integer - Window's height in pixels. Default is `600`.
* `x` Integer - Window's left offset from screen. Default is to center the
window.
* `y` Integer - Window's top offset from screen. Default is to center the
window.
* `useContentSize` Boolean - The `width` and `height` would be used as web
page's size, which means the actual window's size will include window
frame's size and be slightly larger.
frame's size and be slightly larger. Default is `false`.
* `center` Boolean - Show window in the center of the screen.
* `minWidth` Integer - Window's minimum width.
* `minHeight` Integer - Window's minimum height.
* `maxWidth` Integer - Window's maximum width.
* `maxHeight` Integer - Window's maximum height.
* `resizable` Boolean - Whether window is resizable.
* `minWidth` Integer - Window's minimum width. Default is `0`.
* `minHeight` Integer - Window's minimum height. Default is `0`.
* `maxWidth` Integer - Window's maximum width. Default is no limit.
* `maxHeight` Integer - Window's maximum height. Default is no limit.
* `resizable` Boolean - Whether window is resizable. Default is `true`.
* `alwaysOnTop` Boolean - Whether the window should always stay on top of
other windows.
other windows. Default is `false`.
* `fullscreen` Boolean - Whether the window should show in fullscreen. When
set to `false` the fullscreen button will be hidden or disabled on OS X.
* `skipTaskbar` Boolean - Whether to show the window in taskbar.
* `kiosk` Boolean - The kiosk mode.
* `title` String - Default window title.
Default is `false`.
* `skipTaskbar` Boolean - Whether to show the window in taskbar. Default is
`false`.
* `kiosk` Boolean - The kiosk mode. Default is `false`.
* `title` String - Default window title. Default is `"Electron"`.
* `icon` [NativeImage](native-image.md) - The window icon, when omitted on
Windows the executable's icon would be used as window icon.
* `show` Boolean - Whether window should be shown when created.
* `show` Boolean - Whether window should be shown when created. Default is
`true`.
* `frame` Boolean - Specify `false` to create a
[Frameless Window](frameless-window.md).
[Frameless Window](frameless-window.md). Default is `true`.
* `acceptFirstMouse` Boolean - Whether the web view accepts a single
mouse-down event that simultaneously activates the window.
* `disableAutoHideCursor` Boolean - Whether to hide cursor when typing.
mouse-down event that simultaneously activates the window. Default is `false`.
* `disableAutoHideCursor` Boolean - Whether to hide cursor when typing. Default
is `false`.
* `autoHideMenuBar` Boolean - Auto hide the menu bar unless the `Alt`
key is pressed.
key is pressed. Default is `false`.
* `enableLargerThanScreen` Boolean - Enable the window to be resized larger
than screen.
than screen. Default is `false`.
* `backgroundColor` String - Window's background color as Hexadecimal value,
like `#66CD00` or `#FFF`. This is only implemented on Linux and Windows.
Default is `#000` (black).
* `darkTheme` Boolean - Forces using dark theme for the window, only works on
some GTK+3 desktop environments.
some GTK+3 desktop environments. Default is `false`.
* `transparent` Boolean - Makes the window [transparent](frameless-window.md).
* `type` String - Specifies the type of the window, possible types are
`desktop`, `dock`, `toolbar`, `splash`, `notification`. This only works on
Linux.
* `standardWindow` Boolean - Uses the OS X's standard window instead of the
textured window. Defaults to `true`.
Default is `false`.
* `type` String - Specifies the type of the window, which applies
additional platform-specific properties. By default it's undefined and you'll
get a regular app window. Supported values:
* On Linux, possible types are `desktop`, `dock`, `toolbar`, `splash`,
`notification`.
* On OS X, possible types are `desktop`, `textured`. The `textured` type adds
metal gradient appearance (`NSTexturedBackgroundWindowMask`). The `desktop`
type places the window at the desktop background window level
(`kCGDesktopWindowLevel - 1`). Note that desktop window will not receive
focus, keyboard or mouse events, but you can use `globalShortcut` to receive
input sparingly.
* `titleBarStyle` String, OS X - specifies the style of window title bar.
This option is supported on OS X 10.10 Yosemite and newer. There are three
possible values:
* `default` or not specified results in the standard gray opaque Mac title
* `default` or not specified, results in the standard gray opaque Mac title
bar.
* `hidden` results in a hidden title bar and a full size content window, yet
the title bar still has the standard window controls ("traffic lights") in
@ -86,11 +100,10 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
is `true`.
* `preload` String - Specifies a script that will be loaded before other
scripts run in the page. This script will always have access to node APIs
no matter whether node integration is turned on or off. The value should
no matter whether node integration is turned on or off. The value should
be the absolute file path to the script.
When node integration is turned off, the preload script can reintroduce
Node global symbols back to the global scope. See example
When node integration is turned off, the preload script can reintroduce
Node global symbols back to the global scope. See example
[here](process.md#event-loaded).
* `partition` String - Sets the session used by the page. If `partition`
starts with `persist:`, the page will use a persistent session available to
@ -99,33 +112,38 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
`partition`, multiple pages can share the same session. If the `partition`
is unset then default session of the app will be used.
* `zoomFactor` Number - The default zoom factor of the page, `3.0` represents
`300%`.
* `javascript` Boolean
`300%`. Default is `1.0`.
* `javascript` Boolean - Enables JavaScript support. Default is `true`.
* `webSecurity` Boolean - When setting `false`, it will disable the
same-origin policy (Usually using testing websites by people), and set
`allowDisplayingInsecureContent` and `allowRunningInsecureContent` to
`true` if these two options are not set by user.
`true` if these two options are not set by user. Default is `true`.
* `allowDisplayingInsecureContent` Boolean - Allow an https page to display
content like images from http URLs.
content like images from http URLs. Default is `false`.
* `allowRunningInsecureContent` Boolean - Allow a https page to run
JavaScript, CSS or plugins from http URLs.
* `images` Boolean
* `java` Boolean
* `textAreasAreResizable` Boolean
* `webgl` Boolean
* `webaudio` Boolean
* `plugins` Boolean - Whether plugins should be enabled.
* `experimentalFeatures` Boolean
* `experimentalCanvasFeatures` Boolean
* `overlayScrollbars` Boolean
* `overlayFullscreenVideo` Boolean
* `sharedWorker` Boolean
* `directWrite` Boolean - Whether the DirectWrite font rendering system on
Windows is enabled.
JavaScript, CSS or plugins from http URLs. Default is `false`.
* `images` Boolean - Enables image support. Default is `true`.
* `java` Boolean - Enables Java support. Default is `false`.
* `textAreasAreResizable` Boolean - Make TextArea elements resizable. Default
is `true`.
* `webgl` Boolean - Enables WebGL support. Default is `true`.
* `webaudio` Boolean - Enables WebAudio support. Default is `true`.
* `plugins` Boolean - Whether plugins should be enabled. Default is `false`.
* `experimentalFeatures` Boolean - Enables Chromium's experimental features.
Default is `false`.
* `experimentalCanvasFeatures` Boolean - Enables Chromium's experimental
canvas features. Default is `false`.
* `overlayScrollbars` Boolean - Enables overlay scrollbars. Default is
`false`.
* `overlayFullscreenVideo` Boolean - Enables overlay fullscreen video. Default
is `false`
* `sharedWorker` Boolean - Enables Shared Worker support. Default is `false`.
* `directWrite` Boolean - Enables DirectWrite font rendering system on
Windows. Default is `true`.
* `pageVisibility` Boolean - Page would be forced to be always in visible
or hidden state once set, instead of reflecting current window's
visibility. Users can set it to `true` to prevent throttling of DOM
timers.
timers. Default is `false`.
## Events

View file

@ -1,8 +1,10 @@
# session
The `session` object is a property of [`webContents`](web-contents.md) which is
a property of [`BrowserWindow`](browser-window.md). You can access it through an
instance of `BrowserWindow`. For example:
The `session` module can be used to create new `Session` objects.
You can also access the `session` of existing pages by using the `session`
property of [`webContents`](web-contents.md) which is a property of
[`BrowserWindow`](browser-window.md).
```javascript
const BrowserWindow = require('electron').BrowserWindow;
@ -10,12 +12,47 @@ const BrowserWindow = require('electron').BrowserWindow;
var win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL("http://github.com");
var session = win.webContents.session
var ses = win.webContents.session
```
## Events
## Methods
### Event: 'will-download'
The `session` module has the following methods:
### session.fromPartition(partition)
* `partition` String
Returns a new `Session` instance from `partition` string.
If `partition` starts with `persist:`, the page will use a persistent session
available to all pages in the app with the same `partition`. if there is no
`persist:` prefix, the page will use an in-memory session. If the `partition` is
empty then default session of the app will be returned.
## Properties
The `session` module has the following properties:
### session.defaultSession
Returns the default session object of the app.
## Class: Session
You can create a `Session` object in the `session` module:
```javascript
const session = require('electron').session;
var ses = session.fromPartition('persist:name');
```
### Instance Events
The following events are available on instances of `Session`:
#### Event: 'will-download'
* `event` Event
* `item` [DownloadItem](download-item.md)
@ -34,11 +71,11 @@ session.on('will-download', function(event, item, webContents) {
});
```
## Methods
### Instance Methods
The `session` object has the following methods:
The following methods are available on instances of `Session`:
### `session.cookies`
#### `ses.cookies`
The `cookies` gives you ability to query and modify cookies. For example:
@ -74,7 +111,7 @@ win.webContents.on('did-finish-load', function() {
});
```
### `session.cookies.get(details, callback)`
#### `ses.cookies.get(details, callback)`
`details` Object, properties:
@ -102,7 +139,7 @@ win.webContents.on('did-finish-load', function() {
the number of seconds since the UNIX epoch. Not provided for session
cookies.
### `session.cookies.set(details, callback)`
#### `ses.cookies.set(details, callback)`
`details` Object, properties:
@ -121,23 +158,23 @@ win.webContents.on('did-finish-load', function() {
* `callback` Function - function(error)
* `error` Error
### `session.cookies.remove(details, callback)`
#### `ses.cookies.remove(details, callback)`
* `details` Object, proprties:
* `details` Object
* `url` String - The URL associated with the cookie
* `name` String - The name of cookie to remove
* `callback` Function - function(error)
* `error` Error
### `session.clearCache(callback)`
#### `ses.clearCache(callback)`
* `callback` Function - Called when operation is done
Clears the sessions HTTP cache.
### `session.clearStorageData([options, ]callback)`
#### `ses.clearStorageData([options, ]callback)`
* `options` Object (optional), proprties:
* `options` Object (optional)
* `origin` String - Should follow `window.location.origin`s representation
`scheme://host:port`.
* `storages` Array - The types of storages to clear, can contain:
@ -149,7 +186,7 @@ Clears the sessions HTTP cache.
Clears the data of web storages.
### `session.setProxy(config, callback)`
#### `ses.setProxy(config, callback)`
* `config` String
* `callback` Function - Called when operation is done.
@ -187,14 +224,22 @@ proxy-uri = [<proxy-scheme>"://"]<proxy-host>[":"<proxy-port>]
URLs.
```
### `session.setDownloadPath(path)`
### `ses.resolveProxy(url, callback)`
* `url` URL
* `callback` Function
Resolves the proxy information for `url`. The `callback` will be called with
`callback(proxy)` when the request is performed.
#### `ses.setDownloadPath(path)`
* `path` String - The download location
Sets download saving directory. By default, the download directory will be the
`Downloads` under the respective app folder.
### `session.enableNetworkEmulation(options)`
#### `ses.enableNetworkEmulation(options)`
* `options` Object
* `offline` Boolean - Whether to emulate network outage.
@ -216,12 +261,12 @@ window.webContents.session.enableNetworkEmulation({
window.webContents.session.enableNetworkEmulation({offline: true});
```
### `session.disableNetworkEmulation`
#### `ses.disableNetworkEmulation()`
Disables any network emulation already active for the `session`. Resets to
the original network configuration.
### `session.setCertificateVerifyProc(proc)`
#### `ses.setCertificateVerifyProc(proc)`
* `proc` Function

View file

@ -225,12 +225,6 @@ The usage is the same with [the `login` event of `app`](app.md#event-login).
The `webContents` object has the following instance methods:
### `webContents.session`
Returns the `session` object used by this webContents.
See [session documentation](session.md) for this object's methods.
### `webContents.loadURL(url[, options])`
* `url` URL
@ -355,7 +349,7 @@ this limitation.
### `webContents.setAudioMuted(muted)`
+ `muted` Boolean
* `muted` Boolean
Mute the audio on the current web page.
@ -678,17 +672,6 @@ is in 32bit ARGB format).
End subscribing for frame presentation events.
## Instance Properties
`WebContents` objects also have the following properties:
### `webContents.devToolsWebContents`
Get the `WebContents` of DevTools for this `WebContents`.
**Note:** Users should never store this object because it may become `null`
when the DevTools has been closed.
### `webContents.savePage(fullPath, saveType, callback)`
* `fullPath` String - The full file path.
@ -711,3 +694,18 @@ win.webContents.on('did-finish-load', function() {
});
});
```
## Instance Properties
`WebContents` objects also have the following properties:
### `webContents.session`
Returns the [session](session.md) object used by this webContents.
### `webContents.devToolsWebContents`
Get the `WebContents` of DevTools for this `WebContents`.
**Note:** Users should never store this object because it may become `null`
when the DevTools has been closed.

View file

@ -26,6 +26,7 @@
'atom/browser/api/lib/power-monitor.coffee',
'atom/browser/api/lib/power-save-blocker.coffee',
'atom/browser/api/lib/protocol.coffee',
'atom/browser/api/lib/session.coffee',
'atom/browser/api/lib/screen.coffee',
'atom/browser/api/lib/tray.coffee',
'atom/browser/api/lib/web-contents.coffee',

View file

@ -322,3 +322,11 @@ describe 'browser-window module', ->
done()
w.loadURL "file://#{fixtures}/pages/save_page/index.html"
describe 'BrowserWindow options argument is optional', ->
it 'should create a window with default size (800x600)', ->
w.destroy()
w = new BrowserWindow()
size = w.getSize()
assert.equal size[0], 800
assert.equal size[1], 600

View file

@ -4,7 +4,7 @@ path = require 'path'
fs = require 'fs'
{ipcRenderer, remote} = require 'electron'
{app, ipcMain, BrowserWindow} = remote.require 'electron'
{app, ipcMain, session, BrowserWindow} = remote
describe 'session module', ->
@timeout 10000
@ -35,9 +35,9 @@ describe 'session module', ->
done('Can not find cookie')
it 'should over-write the existent cookie', (done) ->
app.defaultSession.cookies.set {url: url, name: '1', value: '1'}, (error) ->
session.defaultSession.cookies.set {url: url, name: '1', value: '1'}, (error) ->
return done(error) if error
app.defaultSession.cookies.get {url: url}, (error, list) ->
session.defaultSession.cookies.get {url: url}, (error, list) ->
return done(error) if error
for cookie in list when cookie.name is '1'
if cookie.value is '1'
@ -47,11 +47,11 @@ describe 'session module', ->
done('Can not find cookie')
it 'should remove cookies', (done) ->
app.defaultSession.cookies.set {url: url, name: '2', value: '2'}, (error) ->
session.defaultSession.cookies.set {url: url, name: '2', value: '2'}, (error) ->
return done(error) if error
app.defaultSession.cookies.remove {url: url, name: '2'}, (error) ->
session.defaultSession.cookies.remove {url: url, name: '2'}, (error) ->
return done(error) if error
app.defaultSession.cookies.get {url: url}, (error, list) ->
session.defaultSession.cookies.get {url: url}, (error, list) ->
return done(error) if error
for cookie in list when cookie.name is '2'
return done('Cookie not deleted')

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit 57472ef51d5bd70c65c5e304ba4626395b5d92aa
Subproject commit d4fab33427eb728a553896527f1931887ce6d9d9