NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / experimental.offscreenTabs_custom_bindings.js
blob394f191f48ff3d07a9ef694fadfe9111f7aec742
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Custom binding for the experimental offscreenTabs API.
7 var binding = require('binding').Binding.create('experimental.offscreenTabs');
9 binding.registerCustomHook(
10 'experimental.offscreenTabs', function(api) {
11 var apiFunctions = api.apiFunctions;
13 function maybeCopy(src, prop, dest) {
14 if (src[prop] !== undefined)
15 dest[prop] = src[prop];
18 function keyboardEventFilter(e) {
19 var result = {
20 type: e.type,
21 ctrlKey: e.ctrlKey,
22 shiftKey: e.shiftKey,
23 altKey: e.altKey,
24 metaKey: e.metaKey,
26 maybeCopy(e, 'keyCode', result);
27 maybeCopy(e, 'charCode', result);
28 return result;
31 function mouseEventFilter(e) {
32 var result = {
33 type: e.type,
34 ctrlKey: e.ctrlKey,
35 shiftKey: e.shiftKey,
36 altKey: e.altKey,
37 metaKey: e.metaKey,
38 button: e.button,
40 maybeCopy(e, 'wheelDeltaX', result);
41 maybeCopy(e, 'wheelDeltaY', result);
42 return result;
45 // We are making a copy of |arr|, but applying |func| to index 1.
46 function validate(arr, func) {
47 var newArr = [];
48 for (var i = 0; i < arr.length; i++) {
49 $Array.push(newArr,
50 i == 1 && typeof(arr) == 'object' ? func(arr[i]) : arr[i]);
52 return newArr;
55 apiFunctions.setUpdateArgumentsPreValidate(
56 'sendKeyboardEvent',
57 function() { return validate(arguments, keyboardEventFilter); });
58 apiFunctions.setUpdateArgumentsPreValidate(
59 'sendMouseEvent',
60 function() { return validate(arguments, mouseEventFilter); });
61 });
63 exports.binding = binding.generate();