OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(message.lineNum
ber, 0)); | 372 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(message.lineNum
ber, 0)); |
373 return this._status.OK(); | 373 return this._status.OK(); |
374 } | 374 } |
375 | 375 |
376 var resource = WebInspector.resourceForURL(message.url); | 376 var resource = WebInspector.resourceForURL(message.url); |
377 if (resource) { | 377 if (resource) { |
378 WebInspector.Revealer.reveal(resource, message.lineNumber); | 378 WebInspector.Revealer.reveal(resource, message.lineNumber); |
379 return this._status.OK(); | 379 return this._status.OK(); |
380 } | 380 } |
381 | 381 |
382 var request = WebInspector.networkLog.requestForURL(message.url); | 382 var request = WebInspector.NetworkLog.requestForURL(message.url); |
383 if (request) { | 383 if (request) { |
384 WebInspector.Revealer.reveal(request); | 384 WebInspector.Revealer.reveal(request); |
385 return this._status.OK(); | 385 return this._status.OK(); |
386 } | 386 } |
387 | 387 |
388 return this._status.E_NOTFOUND(message.url); | 388 return this._status.E_NOTFOUND(message.url); |
389 }, | 389 }, |
390 | 390 |
391 _onSetOpenResourceHandler: function(message, port) | 391 _onSetOpenResourceHandler: function(message, port) |
392 { | 392 { |
(...skipping 24 matching lines...) Expand all Loading... |
417 | 417 |
418 _onReload: function(message) | 418 _onReload: function(message) |
419 { | 419 { |
420 var options = /** @type {!ExtensionReloadOptions} */ (message.options ||
{}); | 420 var options = /** @type {!ExtensionReloadOptions} */ (message.options ||
{}); |
421 | 421 |
422 WebInspector.multitargetNetworkManager.setUserAgentOverride(typeof optio
ns.userAgent === "string" ? options.userAgent : ""); | 422 WebInspector.multitargetNetworkManager.setUserAgentOverride(typeof optio
ns.userAgent === "string" ? options.userAgent : ""); |
423 var injectedScript; | 423 var injectedScript; |
424 if (options.injectedScript) | 424 if (options.injectedScript) |
425 injectedScript = "(function(){" + options.injectedScript + "})()"; | 425 injectedScript = "(function(){" + options.injectedScript + "})()"; |
426 var preprocessingScript = options.preprocessingScript; | 426 var preprocessingScript = options.preprocessingScript; |
427 WebInspector.resourceTreeModel.reloadPage(!!options.ignoreCache, injecte
dScript, preprocessingScript); | 427 // Reload main frame. |
| 428 var target = WebInspector.targetManager.mainTarget(); |
| 429 target.resourceTreeModel.reloadPage(!!options.ignoreCache, injectedScrip
t, preprocessingScript); |
428 return this._status.OK(); | 430 return this._status.OK(); |
429 }, | 431 }, |
430 | 432 |
431 _onEvaluateOnInspectedPage: function(message, port) | 433 _onEvaluateOnInspectedPage: function(message, port) |
432 { | 434 { |
433 /** | 435 /** |
434 * @param {?Protocol.Error} error | 436 * @param {?Protocol.Error} error |
435 * @param {?RuntimeAgent.RemoteObject} resultPayload | 437 * @param {?WebInspector.RemoteObject} remoteObject |
436 * @param {boolean=} wasThrown | 438 * @param {boolean=} wasThrown |
437 * @this {WebInspector.ExtensionServer} | 439 * @this {WebInspector.ExtensionServer} |
438 */ | 440 */ |
439 function callback(error, resultPayload, wasThrown) | 441 function callback(error, remoteObject, wasThrown) |
440 { | 442 { |
441 var result; | 443 var result; |
442 if (error || !resultPayload) | 444 if (error || !remoteObject) |
443 result = this._status.E_PROTOCOLERROR(error.toString()); | 445 result = this._status.E_PROTOCOLERROR(error.toString()); |
444 else if (wasThrown) | 446 else if (wasThrown) |
445 result = { isException: true, value: resultPayload.description }
; | 447 result = { isException: true, value: remoteObject.description }; |
446 else | 448 else |
447 result = { value: resultPayload.value }; | 449 result = { value: remoteObject.value }; |
448 | 450 |
449 this._dispatchCallback(message.requestId, port, result); | 451 this._dispatchCallback(message.requestId, port, result); |
450 } | 452 } |
451 return this.evaluate(message.expression, true, true, message.evaluateOpt
ions, port._extensionOrigin, callback.bind(this)); | 453 return this.evaluate(message.expression, true, true, message.evaluateOpt
ions, port._extensionOrigin, callback.bind(this)); |
452 }, | 454 }, |
453 | 455 |
454 _onGetHAR: function() | 456 _onGetHAR: function() |
455 { | 457 { |
456 var requests = WebInspector.networkLog.requests; | 458 var requests = WebInspector.NetworkLog.requests(); |
457 var harLog = (new WebInspector.HARLog(requests)).build(); | 459 var harLog = (new WebInspector.HARLog(requests)).build(); |
458 for (var i = 0; i < harLog.entries.length; ++i) | 460 for (var i = 0; i < harLog.entries.length; ++i) |
459 harLog.entries[i]._requestId = this._requestId(requests[i]); | 461 harLog.entries[i]._requestId = this._requestId(requests[i]); |
460 return harLog; | 462 return harLog; |
461 }, | 463 }, |
462 | 464 |
463 /** | 465 /** |
464 * @param {!WebInspector.ContentProvider} contentProvider | 466 * @param {!WebInspector.ContentProvider} contentProvider |
465 */ | 467 */ |
466 _makeResource: function(contentProvider) | 468 _makeResource: function(contentProvider) |
(...skipping 15 matching lines...) Expand all Loading... |
482 * @this {WebInspector.ExtensionServer} | 484 * @this {WebInspector.ExtensionServer} |
483 */ | 485 */ |
484 function pushResourceData(contentProvider) | 486 function pushResourceData(contentProvider) |
485 { | 487 { |
486 if (!resources[contentProvider.contentURL()]) | 488 if (!resources[contentProvider.contentURL()]) |
487 resources[contentProvider.contentURL()] = this._makeResource(con
tentProvider); | 489 resources[contentProvider.contentURL()] = this._makeResource(con
tentProvider); |
488 } | 490 } |
489 var uiSourceCodes = WebInspector.workspace.uiSourceCodesForProjectType(W
ebInspector.projectTypes.Network); | 491 var uiSourceCodes = WebInspector.workspace.uiSourceCodesForProjectType(W
ebInspector.projectTypes.Network); |
490 uiSourceCodes = uiSourceCodes.concat(WebInspector.workspace.uiSourceCode
sForProjectType(WebInspector.projectTypes.ContentScripts)); | 492 uiSourceCodes = uiSourceCodes.concat(WebInspector.workspace.uiSourceCode
sForProjectType(WebInspector.projectTypes.ContentScripts)); |
491 uiSourceCodes.forEach(pushResourceData.bind(this)); | 493 uiSourceCodes.forEach(pushResourceData.bind(this)); |
492 WebInspector.resourceTreeModel.forAllResources(pushResourceData.bind(thi
s)); | 494 for (var target of WebInspector.targetManager.targets()) |
| 495 target.resourceTreeModel.forAllResources(pushResourceData.bind(this)
); |
493 return Object.values(resources); | 496 return Object.values(resources); |
494 }, | 497 }, |
495 | 498 |
496 /** | 499 /** |
497 * @param {!WebInspector.ContentProvider} contentProvider | 500 * @param {!WebInspector.ContentProvider} contentProvider |
498 * @param {!Object} message | 501 * @param {!Object} message |
499 * @param {!MessagePort} port | 502 * @param {!MessagePort} port |
500 */ | 503 */ |
501 _getResourceContent: function(contentProvider, message, port) | 504 _getResourceContent: function(contentProvider, message, port) |
502 { | 505 { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 */ | 549 */ |
547 function callbackWrapper(error) | 550 function callbackWrapper(error) |
548 { | 551 { |
549 var response = error ? this._status.E_FAILED(error) : this._status.O
K(); | 552 var response = error ? this._status.E_FAILED(error) : this._status.O
K(); |
550 this._dispatchCallback(message.requestId, port, response); | 553 this._dispatchCallback(message.requestId, port, response); |
551 } | 554 } |
552 | 555 |
553 var url = /** @type {string} */ (message.url); | 556 var url = /** @type {string} */ (message.url); |
554 var uiSourceCode = WebInspector.workspace.uiSourceCodeForOriginURL(url); | 557 var uiSourceCode = WebInspector.workspace.uiSourceCodeForOriginURL(url); |
555 if (!uiSourceCode) { | 558 if (!uiSourceCode) { |
556 var resource = WebInspector.resourceTreeModel.resourceForURL(url); | 559 var resource = WebInspector.ResourceTreeModel.resourceForURL(url); |
557 if (!resource) | 560 if (!resource) |
558 return this._status.E_NOTFOUND(url); | 561 return this._status.E_NOTFOUND(url); |
559 return this._status.E_NOTSUPPORTED("Resource is not editable"); | 562 return this._status.E_NOTSUPPORTED("Resource is not editable"); |
560 } | 563 } |
561 uiSourceCode.setWorkingCopy(message.content); | 564 uiSourceCode.setWorkingCopy(message.content); |
562 if (message.commit) | 565 if (message.commit) |
563 uiSourceCode.commitWorkingCopy(); | 566 uiSourceCode.commitWorkingCopy(); |
564 callbackWrapper.call(this, null); | 567 callbackWrapper.call(this, null); |
565 }, | 568 }, |
566 | 569 |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 } | 905 } |
903 return "/" + result.join("/"); | 906 return "/" + result.join("/"); |
904 }, | 907 }, |
905 | 908 |
906 /** | 909 /** |
907 * @param {string} expression | 910 * @param {string} expression |
908 * @param {boolean} exposeCommandLineAPI | 911 * @param {boolean} exposeCommandLineAPI |
909 * @param {boolean} returnByValue | 912 * @param {boolean} returnByValue |
910 * @param {?Object} options | 913 * @param {?Object} options |
911 * @param {string} securityOrigin | 914 * @param {string} securityOrigin |
912 * @param {function(?string, !RuntimeAgent.RemoteObject, boolean=)} callback | 915 * @param {function(?string, ?WebInspector.RemoteObject, boolean=)} callback |
913 * @return {!WebInspector.ExtensionStatus.Record|undefined} | 916 * @return {!WebInspector.ExtensionStatus.Record|undefined} |
914 */ | 917 */ |
915 evaluate: function(expression, exposeCommandLineAPI, returnByValue, options,
securityOrigin, callback) | 918 evaluate: function(expression, exposeCommandLineAPI, returnByValue, options,
securityOrigin, callback) |
916 { | 919 { |
917 var contextId; | 920 var contextId; |
918 | 921 |
919 /** | 922 /** |
920 * @param {string} url | 923 * @param {string} url |
921 * @return {boolean} | 924 * @return {boolean} |
922 */ | 925 */ |
923 function resolveURLToFrame(url) | 926 function resolveURLToFrame(url) |
924 { | 927 { |
925 var found; | 928 var found; |
926 function hasMatchingURL(frame) | 929 function hasMatchingURL(frame) |
927 { | 930 { |
928 found = (frame.url === url) ? frame : null; | 931 found = (frame.url === url) ? frame : null; |
929 return found; | 932 return found; |
930 } | 933 } |
931 WebInspector.resourceTreeModel.frames().some(hasMatchingURL); | 934 WebInspector.ResourceTreeModel.frames().some(hasMatchingURL); |
932 return found; | 935 return found; |
933 } | 936 } |
934 | 937 |
935 if (typeof options === "object") { | 938 if (typeof options === "object") { |
936 var frame = options.frameURL ? resolveURLToFrame(options.frameURL) :
WebInspector.resourceTreeModel.mainFrame; | 939 var frame = options.frameURL ? resolveURLToFrame(options.frameURL) :
WebInspector.targetManager.mainTarget().resourceTreeModel.mainFrame; |
937 if (!frame) { | 940 if (!frame) { |
938 if (options.frameURL) | 941 if (options.frameURL) |
939 console.warn("evaluate: there is no frame with URL " + optio
ns.frameURL); | 942 console.warn("evaluate: there is no frame with URL " + optio
ns.frameURL); |
940 else | 943 else |
941 console.warn("evaluate: the main frame is not yet available"
); | 944 console.warn("evaluate: the main frame is not yet available"
); |
942 return this._status.E_NOTFOUND(options.frameURL || "<top>"); | 945 return this._status.E_NOTFOUND(options.frameURL || "<top>"); |
943 } | 946 } |
944 | 947 |
945 var contextSecurityOrigin; | 948 var contextSecurityOrigin; |
946 if (options.useContentScriptContext) | 949 if (options.useContentScriptContext) |
(...skipping 21 matching lines...) Expand all Loading... |
968 context = executionContext; | 971 context = executionContext; |
969 | 972 |
970 } | 973 } |
971 if (!context) | 974 if (!context) |
972 return this._status.E_FAILED(frame.url + " has no execution
context"); | 975 return this._status.E_FAILED(frame.url + " has no execution
context"); |
973 } | 976 } |
974 | 977 |
975 contextId = context.id; | 978 contextId = context.id; |
976 } | 979 } |
977 var target = target ? target : WebInspector.targetManager.mainTarget(); | 980 var target = target ? target : WebInspector.targetManager.mainTarget(); |
978 if (target) | 981 if (!target) |
979 target.runtimeAgent().evaluate(expression, "extension", exposeComman
dLineAPI, true, contextId, returnByValue, false, callback); | 982 return; |
| 983 |
| 984 target.runtimeAgent().evaluate(expression, "extension", exposeCommandLin
eAPI, true, contextId, returnByValue, false, onEvalute); |
| 985 |
| 986 /** |
| 987 * @param {?Protocol.Error} error |
| 988 * @param {!RuntimeAgent.RemoteObject} result |
| 989 * @param {boolean=} wasThrown |
| 990 */ |
| 991 function onEvalute(error, result, wasThrown) |
| 992 { |
| 993 if (error) { |
| 994 callback(error, null, wasThrown); |
| 995 return; |
| 996 } |
| 997 callback(error, target.runtimeModel.createRemoteObject(result), wasT
hrown); |
| 998 } |
980 }, | 999 }, |
981 | 1000 |
982 __proto__: WebInspector.Object.prototype | 1001 __proto__: WebInspector.Object.prototype |
983 } | 1002 } |
984 | 1003 |
985 /** | 1004 /** |
986 * @constructor | 1005 * @constructor |
987 * @param {string} name | 1006 * @param {string} name |
988 * @param {string} title | 1007 * @param {string} title |
989 * @param {!WebInspector.Panel} panel | 1008 * @param {!WebInspector.Panel} panel |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s"); | 1075 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s"); |
1057 } | 1076 } |
1058 | 1077 |
1059 /** | 1078 /** |
1060 * @typedef {{code: string, description: string, details: !Array.<*>}} | 1079 * @typedef {{code: string, description: string, details: !Array.<*>}} |
1061 */ | 1080 */ |
1062 WebInspector.ExtensionStatus.Record; | 1081 WebInspector.ExtensionStatus.Record; |
1063 | 1082 |
1064 WebInspector.extensionAPI = {}; | 1083 WebInspector.extensionAPI = {}; |
1065 defineCommonExtensionSymbols(WebInspector.extensionAPI); | 1084 defineCommonExtensionSymbols(WebInspector.extensionAPI); |
OLD | NEW |