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 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 | 1129 |
1130 return className; | 1130 return className; |
1131 }, | 1131 }, |
1132 | 1132 |
1133 /** | 1133 /** |
1134 * @param {boolean} enabled | 1134 * @param {boolean} enabled |
1135 */ | 1135 */ |
1136 setCustomObjectFormatterEnabled: function(enabled) | 1136 setCustomObjectFormatterEnabled: function(enabled) |
1137 { | 1137 { |
1138 this._customObjectFormatterEnabled = enabled; | 1138 this._customObjectFormatterEnabled = enabled; |
| 1139 }, |
| 1140 |
| 1141 /** |
| 1142 * @param {string} prefix |
| 1143 * @param {!Error} error |
| 1144 */ |
| 1145 _logError: function(prefix, error) |
| 1146 { |
| 1147 Promise.resolve().then(inspectedGlobalObject.console.error.bind(inspecte
dGlobalObject.console, prefix + error.message)); |
| 1148 }, |
| 1149 |
| 1150 /** |
| 1151 * @param {!Object} object |
| 1152 * @return {!Array<!{type: string, listener: function(), useCapture: boolean
}>} |
| 1153 */ |
| 1154 frameworkUserEventListeners: function(object) |
| 1155 { |
| 1156 return this._callCustomGettersOnGlobalObject("devtoolsFrameworkUserEvent
Listeners", object, "Getting framework user event listeners failed: "); |
| 1157 }, |
| 1158 |
| 1159 /** |
| 1160 * @param {!Object} object |
| 1161 * @return {!Set<function()>} |
| 1162 */ |
| 1163 frameworkInternalEventHandlers: function(object) |
| 1164 { |
| 1165 return new Set(/** @type {!Array<function()>} */(this._callCustomGetters
OnGlobalObject("devtoolsFrameworkInternalEventHandlers", object, "Getting framew
ork internal event handlers failed: "))); |
| 1166 }, |
| 1167 |
| 1168 /** |
| 1169 * @param {string} gettersName |
| 1170 * @param {!Object} argument |
| 1171 * @param {string} errorPrefix |
| 1172 * @return {!Array<*>} |
| 1173 */ |
| 1174 _callCustomGettersOnGlobalObject: function(gettersName, argument, errorPrefi
x) |
| 1175 { |
| 1176 var getters = inspectedGlobalObject[gettersName]; |
| 1177 if (!getters || !isArrayLike(getters)) |
| 1178 return []; |
| 1179 |
| 1180 var results = []; |
| 1181 for (var i = 0; i < getters.length; ++i) { |
| 1182 try { |
| 1183 if (typeof getters[i] === "function") |
| 1184 results = concat(results, getters[i](argument)); |
| 1185 } catch (e) { |
| 1186 this._logError(errorPrefix, e); |
| 1187 return []; |
| 1188 } |
| 1189 } |
| 1190 return results; |
1139 } | 1191 } |
1140 } | 1192 } |
1141 | 1193 |
1142 /** | 1194 /** |
1143 * @type {!InjectedScript} | 1195 * @type {!InjectedScript} |
1144 * @const | 1196 * @const |
1145 */ | 1197 */ |
1146 var injectedScript = new InjectedScript(); | 1198 var injectedScript = new InjectedScript(); |
1147 | 1199 |
1148 /** | 1200 /** |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 InjectedScript.RemoteObject.prototype = { | 1266 InjectedScript.RemoteObject.prototype = { |
1215 | 1267 |
1216 /** | 1268 /** |
1217 * @param {*} object | 1269 * @param {*} object |
1218 * @param {string=} objectGroupName | 1270 * @param {string=} objectGroupName |
1219 * @param {*=} customObjectConfig | 1271 * @param {*=} customObjectConfig |
1220 * @return {?RuntimeAgent.CustomPreview} | 1272 * @return {?RuntimeAgent.CustomPreview} |
1221 */ | 1273 */ |
1222 _customPreview: function(object, objectGroupName, customObjectConfig) | 1274 _customPreview: function(object, objectGroupName, customObjectConfig) |
1223 { | 1275 { |
1224 /** | |
1225 * @param {!Error} error | |
1226 */ | |
1227 function logError(error) | |
1228 { | |
1229 Promise.resolve().then(inspectedGlobalObject.console.error.bind(insp
ectedGlobalObject.console, "Custom Formatter Failed: " + error.message)); | |
1230 } | |
1231 | |
1232 try { | 1276 try { |
1233 var formatters = inspectedGlobalObject["devtoolsFormatters"]; | 1277 var formatters = inspectedGlobalObject["devtoolsFormatters"]; |
1234 if (!formatters || !isArrayLike(formatters)) | 1278 if (!formatters || !isArrayLike(formatters)) |
1235 return null; | 1279 return null; |
1236 | 1280 |
1237 for (var i = 0; i < formatters.length; ++i) { | 1281 for (var i = 0; i < formatters.length; ++i) { |
1238 try { | 1282 try { |
1239 var formatted = formatters[i].header(object, customObjectCon
fig); | 1283 var formatted = formatters[i].header(object, customObjectCon
fig); |
1240 if (!formatted) | 1284 if (!formatted) |
1241 continue; | 1285 continue; |
1242 | 1286 |
1243 var hasBody = formatters[i].hasBody(object, customObjectConf
ig); | 1287 var hasBody = formatters[i].hasBody(object, customObjectConf
ig); |
1244 injectedScript._substituteObjectTagsInCustomPreview(objectGr
oupName, formatted); | 1288 injectedScript._substituteObjectTagsInCustomPreview(objectGr
oupName, formatted); |
1245 var formatterObjectId = injectedScript._bind(formatters[i],
objectGroupName); | 1289 var formatterObjectId = injectedScript._bind(formatters[i],
objectGroupName); |
1246 var result = {header: JSON.stringify(formatted), hasBody: !!
hasBody, formatterObjectId: formatterObjectId}; | 1290 var result = {header: JSON.stringify(formatted), hasBody: !!
hasBody, formatterObjectId: formatterObjectId}; |
1247 if (customObjectConfig) | 1291 if (customObjectConfig) |
1248 result["configObjectId"] = injectedScript._bind(customOb
jectConfig, objectGroupName); | 1292 result["configObjectId"] = injectedScript._bind(customOb
jectConfig, objectGroupName); |
1249 return result; | 1293 return result; |
1250 } catch (e) { | 1294 } catch (e) { |
1251 logError(e); | 1295 injectedScript._logError("Custom Formatter Failed: ", e); |
1252 } | 1296 } |
1253 } | 1297 } |
1254 } catch (e) { | 1298 } catch (e) { |
1255 logError(e); | 1299 injectedScript._logError("Custom Formatter Failed: ", e); |
1256 } | 1300 } |
1257 return null; | 1301 return null; |
1258 }, | 1302 }, |
1259 | 1303 |
1260 /** | 1304 /** |
1261 * @return {!RuntimeAgent.ObjectPreview} preview | 1305 * @return {!RuntimeAgent.ObjectPreview} preview |
1262 */ | 1306 */ |
1263 _createEmptyPreview: function() | 1307 _createEmptyPreview: function() |
1264 { | 1308 { |
1265 var preview = { | 1309 var preview = { |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1842 | 1886 |
1843 /** | 1887 /** |
1844 * @param {!Node} node | 1888 * @param {!Node} node |
1845 * @return {!Array.<!{type: string, listener: function(), useCapture: boolea
n, remove: function()}>|undefined} | 1889 * @return {!Array.<!{type: string, listener: function(), useCapture: boolea
n, remove: function()}>|undefined} |
1846 */ | 1890 */ |
1847 getEventListeners: function(node) | 1891 getEventListeners: function(node) |
1848 { | 1892 { |
1849 var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(nod
e)); | 1893 var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(nod
e)); |
1850 if (!result) | 1894 if (!result) |
1851 return result; | 1895 return result; |
| 1896 |
| 1897 var jQueryListeners = injectedScript.frameworkUserEventListeners(node); |
| 1898 for (var i = 0; i < jQueryListeners.length; ++i) { |
| 1899 result[jQueryListeners[i].type] = result[jQueryListeners[i].type] ||
[]; |
| 1900 result[jQueryListeners[i].type].push(jQueryListeners[i]); |
| 1901 } |
| 1902 |
1852 /** @this {{type: string, listener: function(), useCapture: boolean}} */ | 1903 /** @this {{type: string, listener: function(), useCapture: boolean}} */ |
1853 var removeFunc = function() | 1904 var removeFunc = function() |
1854 { | 1905 { |
1855 node.removeEventListener(this.type, this.listener, this.useCapture); | 1906 node.removeEventListener(this.type, this.listener, this.useCapture); |
1856 } | 1907 } |
1857 for (var type in result) { | 1908 for (var type in result) { |
1858 var listeners = result[type]; | 1909 var listeners = result[type]; |
1859 for (var i = 0, listener; listener = listeners[i]; ++i) { | 1910 for (var i = 0, listener; listener = listeners[i]; ++i) { |
1860 listener["type"] = type; | 1911 listener["type"] = type; |
1861 listener["remove"] = removeFunc; | 1912 listener["remove"] = removeFunc; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 */ | 1982 */ |
1932 _logEvent: function(event) | 1983 _logEvent: function(event) |
1933 { | 1984 { |
1934 inspectedGlobalObject.console.log(event.type, event); | 1985 inspectedGlobalObject.console.log(event.type, event); |
1935 } | 1986 } |
1936 } | 1987 } |
1937 | 1988 |
1938 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1989 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
1939 return injectedScript; | 1990 return injectedScript; |
1940 }) | 1991 }) |
OLD | NEW |