2015-11-19 13:03:42 +00:00
|
|
|
{ipcMain, deprecate} = require 'electron'
|
2015-11-12 10:28:04 +00:00
|
|
|
{EventEmitter} = require 'events'
|
2013-05-15 11:19:35 +00:00
|
|
|
|
2015-11-13 08:41:33 +00:00
|
|
|
{BrowserWindow} = process.atomBinding 'window'
|
2013-06-18 13:40:03 +00:00
|
|
|
BrowserWindow::__proto__ = EventEmitter.prototype
|
2013-05-17 08:09:12 +00:00
|
|
|
|
2013-10-05 13:05:59 +00:00
|
|
|
BrowserWindow::_init = ->
|
2015-11-19 13:03:42 +00:00
|
|
|
{app} = require 'electron' # avoid recursive require.
|
|
|
|
|
2013-10-05 13:05:59 +00:00
|
|
|
# Simulate the application menu on platforms other than OS X.
|
|
|
|
if process.platform isnt 'darwin'
|
|
|
|
menu = app.getApplicationMenu()
|
|
|
|
@setMenu menu if menu?
|
|
|
|
|
2014-10-27 15:46:25 +00:00
|
|
|
# Make new windows requested by links behave like "window.open"
|
2015-06-25 03:07:23 +00:00
|
|
|
@webContents.on '-new-window', (event, url, frameName) ->
|
2014-10-27 15:46:25 +00:00
|
|
|
options = show: true, width: 800, height: 600
|
2015-11-12 10:28:04 +00:00
|
|
|
ipcMain.emit 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options
|
2014-10-27 10:52:55 +00:00
|
|
|
|
2015-07-06 23:22:10 +00:00
|
|
|
# window.resizeTo(...)
|
|
|
|
# window.moveTo(...)
|
2015-06-25 03:07:23 +00:00
|
|
|
@webContents.on 'move', (event, size) =>
|
2015-07-06 23:22:10 +00:00
|
|
|
@setBounds size
|
2014-12-17 22:56:51 +00:00
|
|
|
|
2015-06-25 05:18:36 +00:00
|
|
|
# Hide the auto-hide menu when webContents is focused.
|
|
|
|
@webContents.on 'activate', =>
|
|
|
|
if process.platform isnt 'darwin' and @isMenuBarAutoHide() and @isMenuBarVisible()
|
|
|
|
@setMenuBarVisibility false
|
|
|
|
|
2015-07-14 22:13:41 +00:00
|
|
|
# Forward the crashed event.
|
|
|
|
@webContents.on 'crashed', =>
|
|
|
|
@emit 'crashed'
|
|
|
|
|
2015-12-01 09:51:09 +00:00
|
|
|
# Change window title to page title.
|
|
|
|
@webContents.on 'page-title-set', (event, title, explicitSet) =>
|
|
|
|
@emit 'page-title-updated', event, title
|
|
|
|
@setTitle title unless event.defaultPrevented
|
|
|
|
|
2015-07-24 05:00:03 +00:00
|
|
|
# Sometimes the webContents doesn't get focus when window is shown, so we have
|
|
|
|
# to force focusing on webContents in this case. The safest way is to focus it
|
|
|
|
# when we first start to load URL, if we do it earlier it won't have effect,
|
|
|
|
# if we do it later we might move focus in the page.
|
|
|
|
# Though this hack is only needed on OS X when the app is launched from
|
|
|
|
# Finder, we still do it on all platforms in case of other bugs we don't know.
|
|
|
|
@webContents.once 'load-url', ->
|
|
|
|
@focus()
|
|
|
|
|
2015-06-18 05:59:08 +00:00
|
|
|
# Redirect focus/blur event to app instance too.
|
|
|
|
@on 'blur', (event) =>
|
|
|
|
app.emit 'browser-window-blur', event, this
|
|
|
|
@on 'focus', (event) =>
|
|
|
|
app.emit 'browser-window-focus', event, this
|
|
|
|
|
2015-09-14 09:02:24 +00:00
|
|
|
# Notify the creation of the window.
|
|
|
|
app.emit 'browser-window-created', {}, this
|
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
# Be compatible with old APIs.
|
|
|
|
@webContents.on 'devtools-focused', => @emit 'devtools-focused'
|
|
|
|
@webContents.on 'devtools-opened', => @emit 'devtools-opened'
|
|
|
|
@webContents.on 'devtools-closed', => @emit 'devtools-closed'
|
|
|
|
Object.defineProperty this, 'devToolsWebContents',
|
|
|
|
enumerable: true,
|
|
|
|
configurable: false,
|
|
|
|
get: -> @webContents.devToolsWebContents
|
|
|
|
|
2013-06-18 13:40:03 +00:00
|
|
|
BrowserWindow.getFocusedWindow = ->
|
2013-12-26 10:41:21 +00:00
|
|
|
windows = BrowserWindow.getAllWindows()
|
2013-06-18 13:40:03 +00:00
|
|
|
return window for window in windows when window.isFocused()
|
2013-05-28 08:01:44 +00:00
|
|
|
|
2014-04-25 08:45:14 +00:00
|
|
|
BrowserWindow.fromWebContents = (webContents) ->
|
2013-12-26 10:41:21 +00:00
|
|
|
windows = BrowserWindow.getAllWindows()
|
2015-06-03 10:48:10 +00:00
|
|
|
return window for window in windows when window.webContents?.equal webContents
|
2013-05-16 15:00:43 +00:00
|
|
|
|
2014-04-25 08:45:14 +00:00
|
|
|
BrowserWindow.fromDevToolsWebContents = (webContents) ->
|
2014-04-04 14:28:18 +00:00
|
|
|
windows = BrowserWindow.getAllWindows()
|
2015-06-03 10:48:10 +00:00
|
|
|
return window for window in windows when window.devToolsWebContents?.equal webContents
|
2014-04-04 14:28:18 +00:00
|
|
|
|
2014-04-25 05:14:11 +00:00
|
|
|
# Helpers.
|
2015-11-13 08:03:40 +00:00
|
|
|
BrowserWindow::loadURL = -> @webContents.loadURL.apply @webContents, arguments
|
|
|
|
BrowserWindow::getURL = -> @webContents.getURL()
|
2014-11-12 02:28:50 +00:00
|
|
|
BrowserWindow::reload = -> @webContents.reload.apply @webContents, arguments
|
2015-11-09 13:18:57 +00:00
|
|
|
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
2015-06-05 09:01:17 +00:00
|
|
|
BrowserWindow::openDevTools = -> @webContents.openDevTools.apply @webContents, arguments
|
|
|
|
BrowserWindow::closeDevTools = -> @webContents.closeDevTools()
|
|
|
|
BrowserWindow::isDevToolsOpened = -> @webContents.isDevToolsOpened()
|
|
|
|
BrowserWindow::toggleDevTools = -> @webContents.toggleDevTools()
|
|
|
|
BrowserWindow::inspectElement = -> @webContents.inspectElement.apply @webContents, arguments
|
|
|
|
BrowserWindow::inspectServiceWorker = -> @webContents.inspectServiceWorker()
|
2015-11-09 13:18:57 +00:00
|
|
|
|
|
|
|
# Deprecated.
|
|
|
|
deprecate.member BrowserWindow, 'undo', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'redo', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'cut', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'copy', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'paste', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'selectAll', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'reloadIgnoringCache', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'isLoading', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'isWaitingForResponse', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'stop', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'isCrashed', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'print', 'webContents'
|
|
|
|
deprecate.member BrowserWindow, 'printToPDF', 'webContents'
|
2015-11-13 08:03:40 +00:00
|
|
|
deprecate.rename BrowserWindow, 'restart', 'reload'
|
|
|
|
deprecate.rename BrowserWindow, 'loadUrl', 'loadURL'
|
|
|
|
deprecate.rename BrowserWindow, 'getUrl', 'getURL'
|
2015-11-27 02:30:51 +00:00
|
|
|
BrowserWindow::executeJavaScriptInDevTools = deprecate 'executeJavaScriptInDevTools', 'devToolsWebContents.executeJavaScript', (code) ->
|
|
|
|
@devToolsWebContents?.executeJavaScript code
|
|
|
|
BrowserWindow::getPageTitle = deprecate 'getPageTitle', 'webContents.getTitle', ->
|
|
|
|
@webContents?.getTitle()
|
2014-04-24 09:00:41 +00:00
|
|
|
|
2013-06-18 13:40:03 +00:00
|
|
|
module.exports = BrowserWindow
|