2016-03-18 18:51:02 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-01-14 22:20:06 +00:00
|
|
|
const ipcRenderer = require('electron').ipcRenderer;
|
|
|
|
const webFrame = require('electron').webFrame;
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-18 18:51:02 +00:00
|
|
|
var requestId= 0;
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 22:20:06 +00:00
|
|
|
var WEB_VIEW_EVENTS = {
|
2016-01-12 02:40:23 +00:00
|
|
|
'load-commit': ['url', 'isMainFrame'],
|
|
|
|
'did-finish-load': [],
|
|
|
|
'did-fail-load': ['errorCode', 'errorDescription', 'validatedURL'],
|
|
|
|
'did-frame-finish-load': ['isMainFrame'],
|
|
|
|
'did-start-loading': [],
|
|
|
|
'did-stop-loading': [],
|
|
|
|
'did-get-response-details': ['status', 'newURL', 'originalURL', 'httpResponseCode', 'requestMethod', 'referrer', 'headers'],
|
|
|
|
'did-get-redirect-request': ['oldURL', 'newURL', 'isMainFrame'],
|
|
|
|
'dom-ready': [],
|
|
|
|
'console-message': ['level', 'message', 'line', 'sourceId'],
|
|
|
|
'devtools-opened': [],
|
|
|
|
'devtools-closed': [],
|
|
|
|
'devtools-focused': [],
|
|
|
|
'new-window': ['url', 'frameName', 'disposition', 'options'],
|
|
|
|
'will-navigate': ['url'],
|
|
|
|
'did-navigate': ['url'],
|
|
|
|
'did-navigate-in-page': ['url'],
|
|
|
|
'close': [],
|
|
|
|
'crashed': [],
|
|
|
|
'gpu-crashed': [],
|
|
|
|
'plugin-crashed': ['name', 'version'],
|
|
|
|
'media-started-playing': [],
|
|
|
|
'media-paused': [],
|
|
|
|
'did-change-theme-color': ['themeColor'],
|
|
|
|
'destroyed': [],
|
|
|
|
'page-title-updated': ['title', 'explicitSet'],
|
|
|
|
'page-favicon-updated': ['favicons'],
|
|
|
|
'enter-html-full-screen': [],
|
|
|
|
'leave-html-full-screen': [],
|
|
|
|
'found-in-page': ['result']
|
|
|
|
};
|
|
|
|
|
2016-01-14 22:20:06 +00:00
|
|
|
var DEPRECATED_EVENTS = {
|
2016-01-12 02:40:23 +00:00
|
|
|
'page-title-updated': 'page-title-set'
|
|
|
|
};
|
|
|
|
|
2016-03-18 18:51:02 +00:00
|
|
|
var dispatchEvent = function(webView, eventName, eventKey, ...args) {
|
|
|
|
var domEvent, f, i, j, len, ref1;
|
2016-01-12 02:40:23 +00:00
|
|
|
if (DEPRECATED_EVENTS[eventName] != null) {
|
2016-03-18 18:51:02 +00:00
|
|
|
dispatchEvent.apply(null, [webView, DEPRECATED_EVENTS[eventName], eventKey].concat(args));
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
domEvent = new Event(eventName);
|
|
|
|
ref1 = WEB_VIEW_EVENTS[eventKey];
|
|
|
|
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
|
|
|
f = ref1[i];
|
|
|
|
domEvent[f] = args[i];
|
|
|
|
}
|
|
|
|
webView.dispatchEvent(domEvent);
|
|
|
|
if (eventName === 'load-commit') {
|
|
|
|
return webView.onLoadCommit(domEvent);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
registerEvents: function(webView, viewInstanceId) {
|
2016-03-18 18:51:02 +00:00
|
|
|
ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-" + viewInstanceId, function(event, eventName, ...args) {
|
|
|
|
return dispatchEvent.apply(null, [webView, eventName, eventName].concat(args));
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
2016-03-18 18:51:02 +00:00
|
|
|
|
|
|
|
ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-" + viewInstanceId, function(event, channel, ...args) {
|
2016-01-19 22:49:40 +00:00
|
|
|
var domEvent = new Event('ipc-message');
|
2016-01-12 02:40:23 +00:00
|
|
|
domEvent.channel = channel;
|
2016-03-18 18:51:02 +00:00
|
|
|
domEvent.args = args;
|
2016-01-12 02:40:23 +00:00
|
|
|
return webView.dispatchEvent(domEvent);
|
|
|
|
});
|
2016-03-18 18:51:02 +00:00
|
|
|
|
|
|
|
return ipcRenderer.on("ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-" + viewInstanceId, function(event, ...args) {
|
|
|
|
var domEvent, f, i, j, len, ref1;
|
2016-01-12 02:40:23 +00:00
|
|
|
domEvent = new Event('size-changed');
|
|
|
|
ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight'];
|
|
|
|
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
|
|
|
f = ref1[i];
|
|
|
|
domEvent[f] = args[i];
|
|
|
|
}
|
|
|
|
return webView.onSizeChanged(domEvent);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
deregisterEvents: function(viewInstanceId) {
|
|
|
|
ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-" + viewInstanceId);
|
|
|
|
ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-" + viewInstanceId);
|
|
|
|
return ipcRenderer.removeAllListeners("ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-" + viewInstanceId);
|
|
|
|
},
|
|
|
|
createGuest: function(params, callback) {
|
|
|
|
requestId++;
|
|
|
|
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId);
|
|
|
|
return ipcRenderer.once("ATOM_SHELL_RESPONSE_" + requestId, callback);
|
|
|
|
},
|
|
|
|
attachGuest: function(elementInstanceId, guestInstanceId, params) {
|
|
|
|
ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params);
|
|
|
|
return webFrame.attachGuest(elementInstanceId);
|
|
|
|
},
|
|
|
|
destroyGuest: function(guestInstanceId) {
|
|
|
|
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId);
|
|
|
|
},
|
|
|
|
setSize: function(guestInstanceId, params) {
|
|
|
|
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params);
|
|
|
|
},
|
|
|
|
};
|