diff options
Diffstat (limited to 'WebCore/inspector/front-end/ExtensionAPI.js')
-rw-r--r-- | WebCore/inspector/front-end/ExtensionAPI.js | 167 |
1 files changed, 93 insertions, 74 deletions
diff --git a/WebCore/inspector/front-end/ExtensionAPI.js b/WebCore/inspector/front-end/ExtensionAPI.js index e526cf5..0234994 100644 --- a/WebCore/inspector/front-end/ExtensionAPI.js +++ b/WebCore/inspector/front-end/ExtensionAPI.js @@ -104,109 +104,130 @@ InspectorExtensionAPI.prototype = { function Resources() { - this.onFinished = new EventSink("resource-finished"); + function resourceDispatch(request) + { + var resource = request.arguments[1]; + resource.__proto__ = new Resource(request.arguments[0]); + this._fire(resource); + } + this.onFinished = new EventSink("resource-finished", resourceDispatch); } Resources.prototype = { - getAll: function(callback) - { - return extensionServer.sendRequest({ command: "getResources" }, callback); - }, - - get: function(id, callback) + getHAR: function(callback) { - return extensionServer.sendRequest({ command: "getResources", id: id }, callback); - }, + function callbackWrapper(result) + { + var entries = (result && result.entries) || []; + for (var i = 0; i < entries.length; ++i) { + entries[i].__proto__ = new Resource(entries[i]._resourceId); + delete entries[i]._resourceId; + } + callback(result); + } + return extensionServer.sendRequest({ command: "getHAR" }, callback && callbackWrapper); + } +} - getPageTimings: function(callback) - { - return extensionServer.sendRequest({ command: "getPageTimings" }, callback); - }, +function ResourceImpl(id) +{ + this._id = id; +} - getContent: function(ids, callback) +ResourceImpl.prototype = { + getContent: function(callback) { - return extensionServer.sendRequest({ command: "getResourceContent", ids: ids }, callback); + function callbackWrapper(response) + { + callback(response.content, response.encoding); + } + extensionServer.sendRequest({ command: "getResourceContent", id: this._id }, callback && callbackWrapper); } -} - -var wellKnownPanelNames = [ - "elements", - "scripts" -]; +}; function Panels() { - var panels = []; + var panels = { + elements: new ElementsPanel() + }; + function panelGetter(name) { return panels[name]; } - - for (var i = 0; i < wellKnownPanelNames.length; ++i) { - var name = wellKnownPanelNames[i]; - panels[name] = new Panel(name); - this.__defineGetter__(name, bind(panelGetter, null, name)); - } + for (var panel in panels) + this.__defineGetter__(panel, bind(panelGetter, null, panel)); } Panels.prototype = { - create: function(label, pageURL, iconURL, callback) + create: function(title, iconURL, pageURL, callback) { var id = "extension-panel-" + extensionServer.nextObjectId(); - function callbackWrapper(result) - { - if (result.isError) - callback(result); - else { - panel = new ExtensionPanel(id); - callback(panel); - } - } var request = { command: "createPanel", id: id, - label: label, - url: expandURL(pageURL), - icon: expandURL(iconURL) + title: title, + icon: expandURL(iconURL), + url: expandURL(pageURL) }; - extensionServer.sendRequest(request, callback && bind(callbackWrapper, this)); + extensionServer.sendRequest(request, callback && bind(callback, this, new ExtensionPanel(id))); } } function PanelImpl(id) { this._id = id; - this.onSelectionChanged = new EventSink("panel-objectSelected-" + id); } -PanelImpl.prototype = { +function PanelWithSidebarImpl(id) +{ + PanelImpl.call(this, id); +} + +PanelWithSidebarImpl.prototype = { createSidebarPane: function(title, url, callback) { var id = "extension-sidebar-" + extensionServer.nextObjectId(); - function callbackWrapper(result) + var request = { + command: "createSidebarPane", + panel: this._id, + id: id, + title: title, + url: expandURL(url) + }; + function callbackWrapper() { - if (result.isError) - callback(result); - else - callback(new ExtensionSidebarPane(id)); + callback(new ExtensionSidebarPane(id)); } - extensionServer.sendRequest({ command: "createSidebarPane", panel: this._id, id: id, title: title, url: expandURL(url) }, callback && callbackWrapper); + extensionServer.sendRequest(request, callback && callbackWrapper); }, createWatchExpressionSidebarPane: function(title, callback) { var id = "watch-sidebar-" + extensionServer.nextObjectId(); - function callbackWrapper(result) + var request = { + command: "createWatchExpressionSidebarPane", + panel: this._id, + id: id, + title: title + }; + function callbackWrapper() { - if (result.isError) - callback(result); - else - callback(new WatchExpressionSidebarPane(id)); + callback(new WatchExpressionSidebarPane(id)); } - extensionServer.sendRequest({ command: "createWatchExpressionSidebarPane", panel: this._id, id: id, title: title }, callback && callbackWrapper); + extensionServer.sendRequest(request, callback && callbackWrapper); } } +PanelWithSidebarImpl.prototype.__proto__ = PanelImpl.prototype; + +function ElementsPanel() +{ + var id = "elements"; + PanelWithSidebar.call(this, id); + this.onSelectionChanged = new EventSink("panel-objectSelected-" + id); +} + function ExtensionPanel(id) { Panel.call(this, id); @@ -222,11 +243,6 @@ ExtensionSidebarPaneImpl.prototype = { setHeight: function(height) { extensionServer.sendRequest({ command: "setSidebarHeight", id: this._id, height: height }); - }, - - setExpanded: function(expanded) - { - extensionServer.sendRequest({ command: "setSidebarExpanded", id: this._id, expanded: expanded }); } } @@ -261,17 +277,17 @@ function Audits() } Audits.prototype = { - addCategory: function(displayName, ruleCount) + addCategory: function(displayName, resultCount) { var id = "extension-audit-category-" + extensionServer.nextObjectId(); - extensionServer.sendRequest({ command: "addAuditCategory", id: id, displayName: displayName, ruleCount: ruleCount }); + extensionServer.sendRequest({ command: "addAuditCategory", id: id, displayName: displayName, resultCount: resultCount }); return new AuditCategory(id); } } function AuditCategoryImpl(id) { - function customDispatch(request) + function auditResultDispatch(request) { var auditResult = new AuditResult(request.arguments[0]); try { @@ -282,7 +298,7 @@ function AuditCategoryImpl(id) } } this._id = id; - this.onAuditStarted = new EventSink("audit-started-" + id, customDispatch); + this.onAuditStarted = new EventSink("audit-started-" + id, auditResultDispatch); } function AuditResultImpl(id) @@ -330,7 +346,7 @@ AuditResultImpl.prototype = { get Severity() { - return private.audits.Severity; + return apiPrivate.audits.Severity; }, _nodeFactory: function(type) @@ -360,9 +376,9 @@ AuditResultNode.prototype = { function InspectedWindow() { + this.onDOMContentLoaded = new EventSink("inspectedPageDOMContentLoaded"); this.onLoaded = new EventSink("inspectedPageLoaded"); this.onNavigated = new EventSink("inspectedURLChanged"); - this.onDOMContentLoaded = new EventSink("DOMContentLoaded"); } InspectedWindow.prototype = { @@ -371,13 +387,14 @@ InspectedWindow.prototype = { return extensionServer.sendRequest({ command: "reload" }); }, - evaluate: function(expression, callback) + eval: function(expression, callback) { function callbackWrapper(result) { - if (result && !result.isException) - result.value = result.value === "undefined" ? undefined : JSON.parse(result.value); - callback(result); + var value = result.value; + if (!result.isException) + value = value === "undefined" ? undefined : JSON.parse(value); + callback(value, result.isException); } return extensionServer.sendRequest({ command: "evaluateOnInspectedPage", expression: expression }, callback && callbackWrapper); } @@ -481,12 +498,14 @@ function declareInterfaceClass(implConstructor) } } +var AuditCategory = declareInterfaceClass(AuditCategoryImpl); +var AuditResult = declareInterfaceClass(AuditResultImpl); var EventSink = declareInterfaceClass(EventSinkImpl); -var Panel = declareInterfaceClass(PanelImpl); var ExtensionSidebarPane = declareInterfaceClass(ExtensionSidebarPaneImpl); +var Panel = declareInterfaceClass(PanelImpl); +var PanelWithSidebar = declareInterfaceClass(PanelWithSidebarImpl); +var Resource = declareInterfaceClass(ResourceImpl); var WatchExpressionSidebarPane = declareInterfaceClass(WatchExpressionSidebarPaneImpl); -var AuditCategory = declareInterfaceClass(AuditCategoryImpl); -var AuditResult = declareInterfaceClass(AuditResultImpl); var extensionServer = new ExtensionServerClient(); |