| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 // Custom bindings for the experimental offscreenTabs API. |
| 6 |
| 7 (function() { |
| 8 |
| 9 native function GetChromeHidden(); |
| 10 |
| 11 GetChromeHidden().registerCustomHook( |
| 12 'experimental.offscreenTabs', function(api) { |
| 13 var apiFunctions = api.apiFunctions; |
| 14 |
| 15 function maybeCopy(src, prop, dest) { |
| 16 if (src[prop] != undefined) { |
| 17 dest[prop] = src[prop]; |
| 18 } |
| 19 }; |
| 20 |
| 21 function keyboardEventFilter(e) { |
| 22 var result = { |
| 23 "type": e.type, |
| 24 "char": e.char, |
| 25 "key": e.key, |
| 26 "location": e.location, |
| 27 "ctrlKey": e.ctrlKey, |
| 28 "shiftKey": e.shiftKey, |
| 29 "altKey": e.altKey, |
| 30 "metaKey": e.metaKey, |
| 31 "repeat": e.repeat, |
| 32 "locale": e.locale |
| 33 }; |
| 34 maybeCopy(e, "keyCode", result); |
| 35 maybeCopy(e, "charCode", result); |
| 36 return result; |
| 37 }; |
| 38 |
| 39 function mouseEventFilter(e) { |
| 40 var result = { |
| 41 "type": e.type, |
| 42 "screenX": e.screenX, |
| 43 "screenY": e.screenY, |
| 44 "clientX": e.clientX, |
| 45 "clientY": e.clientY, |
| 46 "ctrlKey": e.ctrlKey, |
| 47 "shiftKey": e.shiftKey, |
| 48 "altKey": e.altKey, |
| 49 "metaKey": e.metaKey, |
| 50 "button": e.button, |
| 51 "buttons": e.buttons |
| 52 }; |
| 53 maybeCopy(e, "deltaX", result); |
| 54 maybeCopy(e, "deltaY", result); |
| 55 maybeCopy(e, "deltaZ", result); |
| 56 maybeCopy(e, "wheelDeltaX", result); |
| 57 maybeCopy(e, "wheelDeltaY", result); |
| 58 return result; |
| 59 }; |
| 60 |
| 61 function validateFunc(args, filter) { |
| 62 var newArgs = []; |
| 63 |
| 64 for (var ii = 0; ii < args.length; ++ii) { |
| 65 var arg = args[ii]; |
| 66 if (ii == 1 && typeof(arg) == 'object') { |
| 67 arg = filter(arg); |
| 68 } |
| 69 newArgs.push(arg); |
| 70 } |
| 71 |
| 72 return newArgs; |
| 73 }; |
| 74 |
| 75 function validateKeyboardEvent() { |
| 76 return validateFunc(arguments, keyboardEventFilter); |
| 77 } |
| 78 |
| 79 function validateMouseEvent() { |
| 80 return validateFunc(arguments, mouseEventFilter); |
| 81 } |
| 82 |
| 83 apiFunctions.setUpdateArgumentsPreValidate( |
| 84 "experimental.offscreenTabs.sendKeyboardEvent", validateKeyboardEvent); |
| 85 apiFunctions.setUpdateArgumentsPreValidate( |
| 86 "experimental.offscreenTabs.sendMouseEvent", validateMouseEvent); |
| 87 }); |
| 88 |
| 89 })(); |
| OLD | NEW |