Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/renderer/resources/extensions/experimental.offscreenTabs_custom_bindings.js

Issue 9234042: Re-land alexbost's experimental offscreenTabs API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: merge / rebase Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 function keyboardEventFilter(e) {
21 var result = {
22 type: e.type,
23 'char': e.char,
24 key: e.key,
25 location: e.location,
26 ctrlKey: e.ctrlKey,
27 shiftKey: e.shiftKey,
28 altKey: e.altKey,
29 metaKey: e.metaKey,
30 repeat: e.repeat,
31 locale: e.locale
32 };
33 maybeCopy(e, 'keyCode', result);
34 maybeCopy(e, 'charCode', result);
35 return result;
36 };
37
38 function mouseEventFilter(e) {
39 var result = {
40 type: e.type,
41 screenX: e.screenX,
42 screenY: e.screenY,
43 clientX: e.clientX,
44 clientY: e.clientY,
45 ctrlKey: e.ctrlKey,
46 shiftKey: e.shiftKey,
47 altKey: e.altKey,
48 metaKey: e.metaKey,
49 button: e.button,
50 buttons: e.buttons
51 };
52 maybeCopy(e, 'deltaX', result);
53 maybeCopy(e, 'deltaY', result);
54 maybeCopy(e, 'deltaZ', result);
55 maybeCopy(e, 'wheelDeltaX', result);
56 maybeCopy(e, 'wheelDeltaY', result);
57 return result;
58 };
59
60 // We are making a copy of |arr|, but applying |func| to index 1.
61 function validate(arr, func) {
62 var newArr = [];
63 for (var i = 0; i < arr.length; i++)
64 newArr.push(i == 1 && typeof(arr) == 'object' ? func(arr[i]) : arr[i]);
65 return newArr;
66 }
67
68 apiFunctions.setUpdateArgumentsPreValidate(
69 'experimental.offscreenTabs.sendKeyboardEvent',
70 function() { return validate(arguments, keyboardEventFilter); });
71 apiFunctions.setUpdateArgumentsPreValidate(
72 'experimental.offscreenTabs.sendMouseEvent',
73 function() { return validate(arguments, mouseEventFilter); });
74 });
75
76 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698