| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 } | 520 } |
| 521 }, | 521 }, |
| 522 | 522 |
| 523 /** | 523 /** |
| 524 * @param {!Object} nativeCommandLineAPI | 524 * @param {!Object} nativeCommandLineAPI |
| 525 * @return {!Object} | 525 * @return {!Object} |
| 526 */ | 526 */ |
| 527 installCommandLineAPI: function(nativeCommandLineAPI) | 527 installCommandLineAPI: function(nativeCommandLineAPI) |
| 528 { | 528 { |
| 529 // NOTE: This list contains only not native Command Line API methods. Fo
r full list: V8Console. | 529 // NOTE: This list contains only not native Command Line API methods. Fo
r full list: V8Console. |
| 530 // NOTE: Argument names of these methods will be printed in the console,
so use pretty names! | 530 nativeCommandLineAPI["getEventListeners"] = CommandLineAPIImpl["getEvent
Listeners"]; |
| 531 var members = [ "monitorEvents", "unmonitorEvents", "getEventListeners"
]; | |
| 532 for (var member of members) | |
| 533 nativeCommandLineAPI[member] = CommandLineAPIImpl[member]; | |
| 534 var functionToStringMap = new Map([ | |
| 535 ["monitorEvents", "function monitorEvents(object, [types]) { [Comm
and Line API] }"], | |
| 536 ["unmonitorEvents", "function unmonitorEvents(object, [types]) { [Co
mmand Line API] }"], | |
| 537 ["getEventListeners", "function getEventListeners(node) { [Command L
ine API] }"] | |
| 538 ]); | |
| 539 for (let entry of functionToStringMap) | |
| 540 nativeCommandLineAPI[entry[0]].toString = (() => entry[1]); | |
| 541 return nativeCommandLineAPI; | 531 return nativeCommandLineAPI; |
| 542 }, | 532 }, |
| 543 | 533 |
| 544 /** | 534 /** |
| 545 * @param {*} object | 535 * @param {*} object |
| 546 * @return {boolean} | 536 * @return {boolean} |
| 547 */ | 537 */ |
| 548 _isDefined: function(object) | 538 _isDefined: function(object) |
| 549 { | 539 { |
| 550 return !!object || this._isHTMLAllCollection(object); | 540 return !!object || this._isHTMLAllCollection(object); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 } | 1013 } |
| 1024 return string.substr(0, maxLength) + "\u2026"; | 1014 return string.substr(0, maxLength) + "\u2026"; |
| 1025 }, | 1015 }, |
| 1026 | 1016 |
| 1027 __proto__: null | 1017 __proto__: null |
| 1028 } | 1018 } |
| 1029 | 1019 |
| 1030 var CommandLineAPIImpl = { __proto__: null } | 1020 var CommandLineAPIImpl = { __proto__: null } |
| 1031 | 1021 |
| 1032 /** | 1022 /** |
| 1033 * @param {!Object} object | |
| 1034 * @param {!Array.<string>|string=} opt_types | |
| 1035 */ | |
| 1036 CommandLineAPIImpl.monitorEvents = function(object, opt_types) | |
| 1037 { | |
| 1038 if (!object || !object.addEventListener || !object.removeEventListener) | |
| 1039 return; | |
| 1040 var types = CommandLineAPIImpl._normalizeEventTypes(opt_types); | |
| 1041 for (var i = 0; i < types.length; ++i) { | |
| 1042 object.removeEventListener(types[i], CommandLineAPIImpl._logEvent, false
); | |
| 1043 object.addEventListener(types[i], CommandLineAPIImpl._logEvent, false); | |
| 1044 } | |
| 1045 } | |
| 1046 | |
| 1047 /** | |
| 1048 * @param {!Object} object | |
| 1049 * @param {!Array.<string>|string=} opt_types | |
| 1050 */ | |
| 1051 CommandLineAPIImpl.unmonitorEvents = function(object, opt_types) | |
| 1052 { | |
| 1053 if (!object || !object.addEventListener || !object.removeEventListener) | |
| 1054 return; | |
| 1055 var types = CommandLineAPIImpl._normalizeEventTypes(opt_types); | |
| 1056 for (var i = 0; i < types.length; ++i) | |
| 1057 object.removeEventListener(types[i], CommandLineAPIImpl._logEvent, false
); | |
| 1058 } | |
| 1059 | |
| 1060 /** | |
| 1061 * @param {!Node} node | 1023 * @param {!Node} node |
| 1062 * @return {!Object|undefined} | 1024 * @return {!Object|undefined} |
| 1063 */ | 1025 */ |
| 1064 CommandLineAPIImpl.getEventListeners = function(node) | 1026 CommandLineAPIImpl.getEventListeners = function(node) |
| 1065 { | 1027 { |
| 1066 var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(node)); | 1028 var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(node)); |
| 1067 if (!result) | 1029 if (!result) |
| 1068 return; | 1030 return; |
| 1069 | 1031 |
| 1070 // TODO(dtapuska): Remove this one closure compiler is updated | 1032 // TODO(dtapuska): Remove this one closure compiler is updated |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1098 for (var type in result) { | 1060 for (var type in result) { |
| 1099 var listeners = result[type]; | 1061 var listeners = result[type]; |
| 1100 for (var i = 0, listener; listener = listeners[i]; ++i) { | 1062 for (var i = 0, listener; listener = listeners[i]; ++i) { |
| 1101 listener["type"] = type; | 1063 listener["type"] = type; |
| 1102 listener["remove"] = removeFunc; | 1064 listener["remove"] = removeFunc; |
| 1103 } | 1065 } |
| 1104 } | 1066 } |
| 1105 return result; | 1067 return result; |
| 1106 } | 1068 } |
| 1107 | 1069 |
| 1108 /** | 1070 CommandLineAPIImpl.getEventListeners.toString = (() => "function getEventListene
rs(node) { [Command Line API] }"); |
| 1109 * @param {!Array.<string>|string=} types | |
| 1110 * @return {!Array.<string>} | |
| 1111 */ | |
| 1112 CommandLineAPIImpl._normalizeEventTypes = function(types) | |
| 1113 { | |
| 1114 if (typeof types === "undefined") | |
| 1115 types = ["mouse", "key", "touch", "pointer", "control", "load", "unload"
, "abort", "error", "select", "input", "change", "submit", "reset", "focus", "bl
ur", "resize", "scroll", "search", "devicemotion", "deviceorientation"]; | |
| 1116 else if (typeof types === "string") | |
| 1117 types = [types]; | |
| 1118 | |
| 1119 var result = []; | |
| 1120 for (var i = 0; i < types.length; ++i) { | |
| 1121 if (types[i] === "mouse") | |
| 1122 push(result, "click", "dblclick", "mousedown", "mouseeenter", "mouse
leave", "mousemove", "mouseout", "mouseover", "mouseup", "mouseleave", "mousewhe
el"); | |
| 1123 else if (types[i] === "key") | |
| 1124 push(result, "keydown", "keyup", "keypress", "textInput"); | |
| 1125 else if (types[i] === "touch") | |
| 1126 push(result, "touchstart", "touchmove", "touchend", "touchcancel"); | |
| 1127 else if (types[i] === "pointer") | |
| 1128 push(result, "pointerover", "pointerout", "pointerenter", "pointerle
ave", "pointerdown", "pointerup", "pointermove", "pointercancel", "gotpointercap
ture", "lostpointercapture"); | |
| 1129 else if (types[i] === "control") | |
| 1130 push(result, "resize", "scroll", "zoom", "focus", "blur", "select",
"input", "change", "submit", "reset"); | |
| 1131 else | |
| 1132 push(result, types[i]); | |
| 1133 } | |
| 1134 return result; | |
| 1135 } | |
| 1136 | |
| 1137 /** | |
| 1138 * @param {!Event} event | |
| 1139 */ | |
| 1140 CommandLineAPIImpl._logEvent = function(event) | |
| 1141 { | |
| 1142 inspectedGlobalObject.console.log(event.type, event); | |
| 1143 } | |
| 1144 | 1071 |
| 1145 return injectedScript; | 1072 return injectedScript; |
| 1146 }) | 1073 }) |
| OLD | NEW |