Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Implements chrome.windows.create #295

Merged
merged 5 commits into from
Oct 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions atom/common/api/resources/browser_action_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var manifest = runtimeNatives.GetManifest();
var process = requireNative('process');
var extensionId = process.GetExtensionId();

var id = 0

var binding = {
onClicked: {
addListener: function (cb) {
Expand All @@ -22,7 +20,7 @@ var binding = {
ipc.send('chrome-browser-action-set-popup', extensionId, details)
},
getPopup: function (details, cb) {
var responseId = ++id
var responseId = ipc.guid()
ipc.once('chrome-browser-action-get-popup-response-' + responseId, function(evt, details) {
cb(details)
})
Expand All @@ -32,7 +30,7 @@ var binding = {
ipc.send('chrome-browser-action-set-title', extensionId, details)
},
getTitle: function (details, cb) {
var responseId = ++id
var responseId = ipc.guid()
ipc.once('chrome-browser-action-get-title-response-' + responseId, function(evt, result) {
cb(result)
})
Expand All @@ -44,7 +42,7 @@ var binding = {
console.warn('chrome.browserAction.setIcon imageData is not supported yet')
return
}
var responseId = ++id
var responseId = ipc.guid()
ipc.once('chrome-browser-action-set-icon-response-' + responseId, function(evt) {
cb && cb()
})
Expand All @@ -54,7 +52,7 @@ var binding = {
ipc.send('chrome-browser-action-set-badge-text', extensionId, details)
},
getBadgeText: function (details, cb) {
var responseId = ++id
var responseId = ipc.guid()
ipc.once('chrome-browser-action-get-badge-text-response-' + responseId, function(evt, details) {
cb(details)
})
Expand All @@ -64,7 +62,7 @@ var binding = {
ipc.send('chrome-browser-action-set-badge-background-color', extensionId, details)
},
getBadgeBackgroundColor: function (details, cb) {
var responseId = ++id
var responseId = ipc.guid()
ipc.once('chrome-browser-action-get-badge-text-response-' + responseId, function(evt, details) {
cb(details)
})
Expand Down
6 changes: 2 additions & 4 deletions atom/common/api/resources/context_menus_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ var process = requireNative('process')
var extensionId = process.GetExtensionId()
var runtime = require('runtime').binding

var id = 0

var createMenuItemId = () => {
return 'context-menus-' + extensionId + id++
return 'context-menus-' + extensionId + ipc.guid()
}

var createResponseId = () => {
return extensionId + id++
return extensionId + ipc.guid()
}

var binding = {
Expand Down
19 changes: 13 additions & 6 deletions atom/common/api/resources/windows_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ var binding = require('binding').Binding.create('windows')

var ipc = require('ipc_utils')

var id = 1;

binding.registerCustomHook(function (bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions
var windows = bindingsAPI.compiledApi
Expand All @@ -21,7 +19,16 @@ binding.registerCustomHook(function (bindingsAPI, extensionId) {
})

apiFunctions.setHandleRequest('create', function (createData, cb) {
console.warn('chrome.windows.create is not supported yet')
var responseId = ipc.guid()
cb && ipc.once('chrome-windows-create-response-' + responseId, function (evt, win, error) {
if (error) {
lastError.run('windows.create', error, '', cb)
} else {
cb(win)
}
})

ipc.send('chrome-windows-create', responseId, createData)
})

apiFunctions.setHandleRequest('getCurrent', function () {
Expand All @@ -33,7 +40,7 @@ binding.registerCustomHook(function (bindingsAPI, extensionId) {
cb = arguments[1]
}

var responseId = ++id
var responseId = ipc.guid()
ipc.once('chrome-windows-get-current-response-' + responseId, function (evt, win) {
cb(win)
})
Expand All @@ -48,15 +55,15 @@ binding.registerCustomHook(function (bindingsAPI, extensionId) {
cb = arguments[1]
}

var responseId = ++id
var responseId = ipc.guid()
ipc.once('chrome-windows-get-all-response-' + responseId, function (evt, win) {
cb(win)
})
ipc.send('chrome-windows-get-all', responseId, getInfo)
})

apiFunctions.setHandleRequest('update', function (windowId, updateInfo, cb) {
var responseId = ++id
var responseId = ipc.guid()
cb && ipc.once('chrome-windows-update-response-' + responseId, function (evt, win) {
cb(win)
})
Expand Down
4 changes: 4 additions & 0 deletions lib/browser/api/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ var windowInfo = function (win, populateTabs) {
}
}

ipcMain.on('chrome-windows-create', function (evt, responseId, createData) {
process.emit('chrome-windows-create-action', responseId, createData, evt)
})

ipcMain.on('chrome-windows-get-current', function (evt, responseId, getInfo) {
var response = {
id: -1,
Expand Down