This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from brave/chrome-focus-changed
add extension chrome.windows.onFocusChanged
- Loading branch information
Showing
2 changed files
with
105 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,104 @@ | ||
var binding = require('binding').Binding.create('windows') | ||
|
||
var ipc = require('ipc_utils') | ||
|
||
var id = 1; | ||
|
||
var binding = { | ||
getCurrent: function () { | ||
var cb, getInfo; | ||
if (arguments.length == 1) { | ||
binding.registerCustomHook(function (bindingsAPI, extensionId) { | ||
var apiFunctions = bindingsAPI.apiFunctions | ||
var windows = bindingsAPI.compiledApi | ||
|
||
apiFunctions.setHandleRequest('getLastFocused', function (getInfo, cb) { | ||
console.warn('chrome.windows.getLastFocused is not supported yet') | ||
}) | ||
|
||
apiFunctions.setHandleRequest('remove', function (windowId, cb) { | ||
console.warn('chrome.windows.remove is not supported yet') | ||
}) | ||
|
||
apiFunctions.setHandleRequest('get', function (windowId, getInfo, cb) { | ||
console.warn('chrome.windows.get is not supported yet') | ||
}) | ||
|
||
apiFunctions.setHandleRequest('create', function (createData, cb) { | ||
console.warn('chrome.windows.create is not supported yet') | ||
}) | ||
|
||
apiFunctions.setHandleRequest('getCurrent', function () { | ||
var cb, getInfo | ||
if (arguments.length === 1) { | ||
cb = arguments[0] | ||
} else { | ||
getInfo = arguments[0] | ||
cb = arguments[1] | ||
} | ||
|
||
var responseId = ++id | ||
ipc.once('chrome-windows-get-current-response-' + responseId, function(evt, win) { | ||
ipc.once('chrome-windows-get-current-response-' + responseId, function (evt, win) { | ||
cb(win) | ||
}) | ||
ipc.send('chrome-windows-get-current', responseId, getInfo) | ||
}, | ||
}) | ||
|
||
getAll: function (getInfo, cb) { | ||
if (arguments.length == 1) { | ||
apiFunctions.setHandleRequest('getAll', function (getInfo, cb) { | ||
if (arguments.length === 1) { | ||
cb = arguments[0] | ||
} else { | ||
getInfo = arguments[0] | ||
cb = arguments[1] | ||
} | ||
|
||
var responseId = ++id | ||
ipc.once('chrome-windows-get-all-response-' + responseId, function(evt, win) { | ||
ipc.once('chrome-windows-get-all-response-' + responseId, function (evt, win) { | ||
cb(win) | ||
}) | ||
ipc.send('chrome-windows-get-all', responseId, getInfo) | ||
}, | ||
}) | ||
|
||
create: function (createData, cb) { | ||
console.warn('chrome.windows.create is not supported yet') | ||
}, | ||
|
||
update: function (windowId, updateInfo, cb) { | ||
apiFunctions.setHandleRequest('update', function (windowId, updateInfo, cb) { | ||
var responseId = ++id | ||
cb && ipc.once('chrome-windows-update-response-' + responseId, function (evt, win) { | ||
cb(win) | ||
}) | ||
ipc.send('chrome-windows-update', responseId, windowId, updateInfo) | ||
}, | ||
}) | ||
|
||
windows.onCreated = { | ||
addListener: function (callback) { | ||
console.warn('chrome.windows.onCreated is not supported yet') | ||
}, | ||
|
||
Filters: function () { | ||
console.warn('chrome.windows.onCreated filters are not supported yet') | ||
} | ||
} | ||
|
||
windows.onRemoved = { | ||
addListener: function (callback) { | ||
console.warn('chrome.windows.onRemoved is not supported yet') | ||
}, | ||
|
||
Filters: function () { | ||
console.warn('chrome.windows.onRemoved filters are not supported yet') | ||
} | ||
} | ||
|
||
windows.onFocusChanged = { | ||
addListener: function (cb) { | ||
ipc.send('register-chrome-window-focus', extensionId) | ||
ipc.on('chrome-window-focus', function (evt, windowId) { | ||
cb(windowId) | ||
}) | ||
}, | ||
|
||
Filters: function () { | ||
console.warn('chrome.windows.onFocusChanged filters are not supported yet') | ||
} | ||
} | ||
|
||
windows.WINDOW_ID_NONE = -1 | ||
windows.WINDOW_ID_CURRENT = -2 | ||
}) | ||
|
||
WINDOW_ID_NONE: -1, | ||
WINDOW_ID_CURRENT: -2 | ||
}; | ||
exports.$set('binding', binding.generate()) | ||
|
||
exports.binding = binding; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters