| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | |
| 31 /** | 30 /** |
| 32 * @constructor | |
| 33 * @implements {WebInspector.Searchable} | 31 * @implements {WebInspector.Searchable} |
| 34 * @extends {WebInspector.Panel} | 32 * @unrestricted |
| 35 * @param {!WebInspector.ExtensionServer} server | 33 */ |
| 36 * @param {string} panelName | 34 WebInspector.ExtensionPanel = class extends WebInspector.Panel { |
| 37 * @param {string} id | 35 /** |
| 38 * @param {string} pageURL | 36 * @param {!WebInspector.ExtensionServer} server |
| 39 */ | 37 * @param {string} panelName |
| 40 WebInspector.ExtensionPanel = function(server, panelName, id, pageURL) | 38 * @param {string} id |
| 41 { | 39 * @param {string} pageURL |
| 42 WebInspector.Panel.call(this, panelName); | 40 */ |
| 41 constructor(server, panelName, id, pageURL) { |
| 42 super(panelName); |
| 43 this._server = server; | 43 this._server = server; |
| 44 this._id = id; | 44 this._id = id; |
| 45 this.setHideOnDetach(); | 45 this.setHideOnDetach(); |
| 46 this._panelToolbar = new WebInspector.Toolbar("hidden", this.element); | 46 this._panelToolbar = new WebInspector.Toolbar('hidden', this.element); |
| 47 | 47 |
| 48 this._searchableView = new WebInspector.SearchableView(this); | 48 this._searchableView = new WebInspector.SearchableView(this); |
| 49 this._searchableView.show(this.element); | 49 this._searchableView.show(this.element); |
| 50 | 50 |
| 51 var extensionView = new WebInspector.ExtensionView(server, this._id, pageURL
, "extension"); | 51 var extensionView = new WebInspector.ExtensionView(server, this._id, pageURL
, 'extension'); |
| 52 extensionView.show(this._searchableView.element); | 52 extensionView.show(this._searchableView.element); |
| 53 } |
| 54 |
| 55 /** |
| 56 * @param {!WebInspector.ToolbarItem} item |
| 57 */ |
| 58 addToolbarItem(item) { |
| 59 this._panelToolbar.element.classList.remove('hidden'); |
| 60 this._panelToolbar.appendToolbarItem(item); |
| 61 } |
| 62 |
| 63 /** |
| 64 * @override |
| 65 */ |
| 66 searchCanceled() { |
| 67 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.panels.S
earchAction.CancelSearch); |
| 68 this._searchableView.updateSearchMatchesCount(0); |
| 69 } |
| 70 |
| 71 /** |
| 72 * @override |
| 73 * @return {!WebInspector.SearchableView} |
| 74 */ |
| 75 searchableView() { |
| 76 return this._searchableView; |
| 77 } |
| 78 |
| 79 /** |
| 80 * @override |
| 81 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
| 82 * @param {boolean} shouldJump |
| 83 * @param {boolean=} jumpBackwards |
| 84 */ |
| 85 performSearch(searchConfig, shouldJump, jumpBackwards) { |
| 86 var query = searchConfig.query; |
| 87 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.panels.S
earchAction.PerformSearch, query); |
| 88 } |
| 89 |
| 90 /** |
| 91 * @override |
| 92 */ |
| 93 jumpToNextSearchResult() { |
| 94 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.panels.S
earchAction.NextSearchResult); |
| 95 } |
| 96 |
| 97 /** |
| 98 * @override |
| 99 */ |
| 100 jumpToPreviousSearchResult() { |
| 101 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.panels.S
earchAction.PreviousSearchResult); |
| 102 } |
| 103 |
| 104 /** |
| 105 * @override |
| 106 * @return {boolean} |
| 107 */ |
| 108 supportsCaseSensitiveSearch() { |
| 109 return false; |
| 110 } |
| 111 |
| 112 /** |
| 113 * @override |
| 114 * @return {boolean} |
| 115 */ |
| 116 supportsRegexSearch() { |
| 117 return false; |
| 118 } |
| 53 }; | 119 }; |
| 54 | 120 |
| 55 WebInspector.ExtensionPanel.prototype = { | 121 /** |
| 56 /** | 122 * @unrestricted |
| 57 * @param {!WebInspector.ToolbarItem} item | 123 */ |
| 58 */ | 124 WebInspector.ExtensionButton = class { |
| 59 addToolbarItem: function(item) | 125 /** |
| 60 { | 126 * @param {!WebInspector.ExtensionServer} server |
| 61 this._panelToolbar.element.classList.remove("hidden"); | 127 * @param {string} id |
| 62 this._panelToolbar.appendToolbarItem(item); | 128 * @param {string} iconURL |
| 63 }, | 129 * @param {string=} tooltip |
| 64 | 130 * @param {boolean=} disabled |
| 65 /** | 131 */ |
| 66 * @override | 132 constructor(server, id, iconURL, tooltip, disabled) { |
| 67 */ | 133 this._id = id; |
| 68 searchCanceled: function() | 134 |
| 69 { | 135 this._toolbarButton = new WebInspector.ToolbarButton('', ''); |
| 70 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.pane
ls.SearchAction.CancelSearch); | 136 this._toolbarButton.addEventListener('click', server.notifyButtonClicked.bin
d(server, this._id)); |
| 71 this._searchableView.updateSearchMatchesCount(0); | 137 this.update(iconURL, tooltip, disabled); |
| 72 }, | 138 } |
| 73 | 139 |
| 74 /** | 140 /** |
| 75 * @override | 141 * @param {string} iconURL |
| 76 * @return {!WebInspector.SearchableView} | 142 * @param {string=} tooltip |
| 77 */ | 143 * @param {boolean=} disabled |
| 78 searchableView: function() | 144 */ |
| 79 { | 145 update(iconURL, tooltip, disabled) { |
| 80 return this._searchableView; | 146 if (typeof iconURL === 'string') |
| 81 }, | 147 this._toolbarButton.setBackgroundImage(iconURL); |
| 82 | 148 if (typeof tooltip === 'string') |
| 83 /** | 149 this._toolbarButton.setTitle(tooltip); |
| 84 * @override | 150 if (typeof disabled === 'boolean') |
| 85 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig | 151 this._toolbarButton.setEnabled(!disabled); |
| 86 * @param {boolean} shouldJump | 152 } |
| 87 * @param {boolean=} jumpBackwards | 153 |
| 88 */ | 154 /** |
| 89 performSearch: function(searchConfig, shouldJump, jumpBackwards) | 155 * @return {!WebInspector.ToolbarButton} |
| 90 { | 156 */ |
| 91 var query = searchConfig.query; | 157 toolbarButton() { |
| 92 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.pane
ls.SearchAction.PerformSearch, query); | 158 return this._toolbarButton; |
| 93 }, | 159 } |
| 94 | |
| 95 /** | |
| 96 * @override | |
| 97 */ | |
| 98 jumpToNextSearchResult: function() | |
| 99 { | |
| 100 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.pane
ls.SearchAction.NextSearchResult); | |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * @override | |
| 105 */ | |
| 106 jumpToPreviousSearchResult: function() | |
| 107 { | |
| 108 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.pane
ls.SearchAction.PreviousSearchResult); | |
| 109 }, | |
| 110 | |
| 111 /** | |
| 112 * @override | |
| 113 * @return {boolean} | |
| 114 */ | |
| 115 supportsCaseSensitiveSearch: function() | |
| 116 { | |
| 117 return false; | |
| 118 }, | |
| 119 | |
| 120 /** | |
| 121 * @override | |
| 122 * @return {boolean} | |
| 123 */ | |
| 124 supportsRegexSearch: function() | |
| 125 { | |
| 126 return false; | |
| 127 }, | |
| 128 | |
| 129 __proto__: WebInspector.Panel.prototype | |
| 130 }; | 160 }; |
| 131 | 161 |
| 132 /** | 162 /** |
| 133 * @constructor | 163 * @unrestricted |
| 134 * @param {!WebInspector.ExtensionServer} server | 164 */ |
| 135 * @param {string} id | 165 WebInspector.ExtensionSidebarPane = class extends WebInspector.SimpleView { |
| 136 * @param {string} iconURL | 166 /** |
| 137 * @param {string=} tooltip | 167 * @param {!WebInspector.ExtensionServer} server |
| 138 * @param {boolean=} disabled | 168 * @param {string} panelName |
| 139 */ | 169 * @param {string} title |
| 140 WebInspector.ExtensionButton = function(server, id, iconURL, tooltip, disabled) | 170 * @param {string} id |
| 141 { | 171 */ |
| 142 this._id = id; | 172 constructor(server, panelName, title, id) { |
| 143 | 173 super(title); |
| 144 this._toolbarButton = new WebInspector.ToolbarButton("", ""); | 174 this.element.classList.add('fill'); |
| 145 this._toolbarButton.addEventListener("click", server.notifyButtonClicked.bin
d(server, this._id)); | |
| 146 this.update(iconURL, tooltip, disabled); | |
| 147 }; | |
| 148 | |
| 149 WebInspector.ExtensionButton.prototype = { | |
| 150 /** | |
| 151 * @param {string} iconURL | |
| 152 * @param {string=} tooltip | |
| 153 * @param {boolean=} disabled | |
| 154 */ | |
| 155 update: function(iconURL, tooltip, disabled) | |
| 156 { | |
| 157 if (typeof iconURL === "string") | |
| 158 this._toolbarButton.setBackgroundImage(iconURL); | |
| 159 if (typeof tooltip === "string") | |
| 160 this._toolbarButton.setTitle(tooltip); | |
| 161 if (typeof disabled === "boolean") | |
| 162 this._toolbarButton.setEnabled(!disabled); | |
| 163 }, | |
| 164 | |
| 165 /** | |
| 166 * @return {!WebInspector.ToolbarButton} | |
| 167 */ | |
| 168 toolbarButton: function() | |
| 169 { | |
| 170 return this._toolbarButton; | |
| 171 } | |
| 172 }; | |
| 173 | |
| 174 /** | |
| 175 * @constructor | |
| 176 * @extends {WebInspector.SimpleView} | |
| 177 * @param {!WebInspector.ExtensionServer} server | |
| 178 * @param {string} panelName | |
| 179 * @param {string} title | |
| 180 * @param {string} id | |
| 181 */ | |
| 182 WebInspector.ExtensionSidebarPane = function(server, panelName, title, id) | |
| 183 { | |
| 184 WebInspector.SimpleView.call(this, title); | |
| 185 this.element.classList.add("fill"); | |
| 186 this._panelName = panelName; | 175 this._panelName = panelName; |
| 187 this._server = server; | 176 this._server = server; |
| 188 this._id = id; | 177 this._id = id; |
| 178 } |
| 179 |
| 180 /** |
| 181 * @return {string} |
| 182 */ |
| 183 id() { |
| 184 return this._id; |
| 185 } |
| 186 |
| 187 /** |
| 188 * @return {string} |
| 189 */ |
| 190 panelName() { |
| 191 return this._panelName; |
| 192 } |
| 193 |
| 194 /** |
| 195 * @param {!Object} object |
| 196 * @param {string} title |
| 197 * @param {function(?string=)} callback |
| 198 */ |
| 199 setObject(object, title, callback) { |
| 200 this._createObjectPropertiesView(); |
| 201 this._setObject(WebInspector.RemoteObject.fromLocalObject(object), title, ca
llback); |
| 202 } |
| 203 |
| 204 /** |
| 205 * @param {string} expression |
| 206 * @param {string} title |
| 207 * @param {!Object} evaluateOptions |
| 208 * @param {string} securityOrigin |
| 209 * @param {function(?string=)} callback |
| 210 */ |
| 211 setExpression(expression, title, evaluateOptions, securityOrigin, callback) { |
| 212 this._createObjectPropertiesView(); |
| 213 this._server.evaluate( |
| 214 expression, true, false, evaluateOptions, securityOrigin, this._onEvalua
te.bind(this, title, callback)); |
| 215 } |
| 216 |
| 217 /** |
| 218 * @param {string} url |
| 219 */ |
| 220 setPage(url) { |
| 221 if (this._objectPropertiesView) { |
| 222 this._objectPropertiesView.detach(); |
| 223 delete this._objectPropertiesView; |
| 224 } |
| 225 if (this._extensionView) |
| 226 this._extensionView.detach(); |
| 227 |
| 228 this._extensionView = new WebInspector.ExtensionView(this._server, this._id,
url, 'extension fill'); |
| 229 this._extensionView.show(this.element); |
| 230 |
| 231 if (!this.element.style.height) |
| 232 this.setHeight('150px'); |
| 233 } |
| 234 |
| 235 /** |
| 236 * @param {string} height |
| 237 */ |
| 238 setHeight(height) { |
| 239 this.element.style.height = height; |
| 240 } |
| 241 |
| 242 /** |
| 243 * @param {string} title |
| 244 * @param {function(?string=)} callback |
| 245 * @param {?Protocol.Error} error |
| 246 * @param {?WebInspector.RemoteObject} result |
| 247 * @param {boolean=} wasThrown |
| 248 */ |
| 249 _onEvaluate(title, callback, error, result, wasThrown) { |
| 250 if (error) |
| 251 callback(error.toString()); |
| 252 else |
| 253 this._setObject(/** @type {!WebInspector.RemoteObject} */ (result), title,
callback); |
| 254 } |
| 255 |
| 256 _createObjectPropertiesView() { |
| 257 if (this._objectPropertiesView) |
| 258 return; |
| 259 if (this._extensionView) { |
| 260 this._extensionView.detach(); |
| 261 delete this._extensionView; |
| 262 } |
| 263 this._objectPropertiesView = new WebInspector.ExtensionNotifierView(this._se
rver, this._id); |
| 264 this._objectPropertiesView.show(this.element); |
| 265 } |
| 266 |
| 267 /** |
| 268 * @param {!WebInspector.RemoteObject} object |
| 269 * @param {string} title |
| 270 * @param {function(?string=)} callback |
| 271 */ |
| 272 _setObject(object, title, callback) { |
| 273 // This may only happen if setPage() was called while we were evaluating the
expression. |
| 274 if (!this._objectPropertiesView) { |
| 275 callback('operation cancelled'); |
| 276 return; |
| 277 } |
| 278 this._objectPropertiesView.element.removeChildren(); |
| 279 var section = new WebInspector.ObjectPropertiesSection(object, title); |
| 280 if (!title) |
| 281 section.titleLessMode(); |
| 282 section.expand(); |
| 283 section.editable = false; |
| 284 this._objectPropertiesView.element.appendChild(section.element); |
| 285 callback(); |
| 286 } |
| 189 }; | 287 }; |
| 190 | |
| 191 WebInspector.ExtensionSidebarPane.prototype = { | |
| 192 /** | |
| 193 * @return {string} | |
| 194 */ | |
| 195 id: function() | |
| 196 { | |
| 197 return this._id; | |
| 198 }, | |
| 199 | |
| 200 /** | |
| 201 * @return {string} | |
| 202 */ | |
| 203 panelName: function() | |
| 204 { | |
| 205 return this._panelName; | |
| 206 }, | |
| 207 | |
| 208 /** | |
| 209 * @param {!Object} object | |
| 210 * @param {string} title | |
| 211 * @param {function(?string=)} callback | |
| 212 */ | |
| 213 setObject: function(object, title, callback) | |
| 214 { | |
| 215 this._createObjectPropertiesView(); | |
| 216 this._setObject(WebInspector.RemoteObject.fromLocalObject(object), title
, callback); | |
| 217 }, | |
| 218 | |
| 219 /** | |
| 220 * @param {string} expression | |
| 221 * @param {string} title | |
| 222 * @param {!Object} evaluateOptions | |
| 223 * @param {string} securityOrigin | |
| 224 * @param {function(?string=)} callback | |
| 225 */ | |
| 226 setExpression: function(expression, title, evaluateOptions, securityOrigin,
callback) | |
| 227 { | |
| 228 this._createObjectPropertiesView(); | |
| 229 this._server.evaluate(expression, true, false, evaluateOptions, security
Origin, this._onEvaluate.bind(this, title, callback)); | |
| 230 }, | |
| 231 | |
| 232 /** | |
| 233 * @param {string} url | |
| 234 */ | |
| 235 setPage: function(url) | |
| 236 { | |
| 237 if (this._objectPropertiesView) { | |
| 238 this._objectPropertiesView.detach(); | |
| 239 delete this._objectPropertiesView; | |
| 240 } | |
| 241 if (this._extensionView) | |
| 242 this._extensionView.detach(); | |
| 243 | |
| 244 this._extensionView = new WebInspector.ExtensionView(this._server, this.
_id, url, "extension fill"); | |
| 245 this._extensionView.show(this.element); | |
| 246 | |
| 247 if (!this.element.style.height) | |
| 248 this.setHeight("150px"); | |
| 249 }, | |
| 250 | |
| 251 /** | |
| 252 * @param {string} height | |
| 253 */ | |
| 254 setHeight: function(height) | |
| 255 { | |
| 256 this.element.style.height = height; | |
| 257 }, | |
| 258 | |
| 259 /** | |
| 260 * @param {string} title | |
| 261 * @param {function(?string=)} callback | |
| 262 * @param {?Protocol.Error} error | |
| 263 * @param {?WebInspector.RemoteObject} result | |
| 264 * @param {boolean=} wasThrown | |
| 265 */ | |
| 266 _onEvaluate: function(title, callback, error, result, wasThrown) | |
| 267 { | |
| 268 if (error) | |
| 269 callback(error.toString()); | |
| 270 else | |
| 271 this._setObject(/** @type {!WebInspector.RemoteObject} */ (result),
title, callback); | |
| 272 }, | |
| 273 | |
| 274 _createObjectPropertiesView: function() | |
| 275 { | |
| 276 if (this._objectPropertiesView) | |
| 277 return; | |
| 278 if (this._extensionView) { | |
| 279 this._extensionView.detach(); | |
| 280 delete this._extensionView; | |
| 281 } | |
| 282 this._objectPropertiesView = new WebInspector.ExtensionNotifierView(this
._server, this._id); | |
| 283 this._objectPropertiesView.show(this.element); | |
| 284 }, | |
| 285 | |
| 286 /** | |
| 287 * @param {!WebInspector.RemoteObject} object | |
| 288 * @param {string} title | |
| 289 * @param {function(?string=)} callback | |
| 290 */ | |
| 291 _setObject: function(object, title, callback) | |
| 292 { | |
| 293 // This may only happen if setPage() was called while we were evaluating
the expression. | |
| 294 if (!this._objectPropertiesView) { | |
| 295 callback("operation cancelled"); | |
| 296 return; | |
| 297 } | |
| 298 this._objectPropertiesView.element.removeChildren(); | |
| 299 var section = new WebInspector.ObjectPropertiesSection(object, title); | |
| 300 if (!title) | |
| 301 section.titleLessMode(); | |
| 302 section.expand(); | |
| 303 section.editable = false; | |
| 304 this._objectPropertiesView.element.appendChild(section.element); | |
| 305 callback(); | |
| 306 }, | |
| 307 | |
| 308 __proto__: WebInspector.SimpleView.prototype | |
| 309 }; | |
| OLD | NEW |