| 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 13 matching lines...) Expand all Loading... |
| 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 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.HandlerRegistry = class extends WebInspector.Object { | 34 Components.HandlerRegistry = class extends Common.Object { |
| 35 constructor(setting) { | 35 constructor(setting) { |
| 36 super(); | 36 super(); |
| 37 this._handlers = {}; | 37 this._handlers = {}; |
| 38 this._setting = setting; | 38 this._setting = setting; |
| 39 this._activeHandler = this._setting.get(); | 39 this._activeHandler = this._setting.get(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 get handlerNames() { | 42 get handlerNames() { |
| 43 return Object.getOwnPropertyNames(this._handlers); | 43 return Object.getOwnPropertyNames(this._handlers); |
| 44 } | 44 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 * @return {boolean} | 66 * @return {boolean} |
| 67 */ | 67 */ |
| 68 dispatchToHandler(name, data) { | 68 dispatchToHandler(name, data) { |
| 69 var handler = this._handlers[name]; | 69 var handler = this._handlers[name]; |
| 70 var result = handler && handler(data); | 70 var result = handler && handler(data); |
| 71 return !!result; | 71 return !!result; |
| 72 } | 72 } |
| 73 | 73 |
| 74 registerHandler(name, handler) { | 74 registerHandler(name, handler) { |
| 75 this._handlers[name] = handler; | 75 this._handlers[name] = handler; |
| 76 this.dispatchEventToListeners(WebInspector.HandlerRegistry.Events.HandlersUp
dated); | 76 this.dispatchEventToListeners(Components.HandlerRegistry.Events.HandlersUpda
ted); |
| 77 } | 77 } |
| 78 | 78 |
| 79 unregisterHandler(name) { | 79 unregisterHandler(name) { |
| 80 delete this._handlers[name]; | 80 delete this._handlers[name]; |
| 81 this.dispatchEventToListeners(WebInspector.HandlerRegistry.Events.HandlersUp
dated); | 81 this.dispatchEventToListeners(Components.HandlerRegistry.Events.HandlersUpda
ted); |
| 82 } | 82 } |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * @param {string} url | 85 * @param {string} url |
| 86 */ | 86 */ |
| 87 _openInNewTab(url) { | 87 _openInNewTab(url) { |
| 88 InspectorFrontendHost.openInNewTab(url); | 88 InspectorFrontendHost.openInNewTab(url); |
| 89 } | 89 } |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * @param {!WebInspector.ContextMenu} contextMenu | 92 * @param {!UI.ContextMenu} contextMenu |
| 93 * @param {!Object} target | 93 * @param {!Object} target |
| 94 */ | 94 */ |
| 95 _appendContentProviderItems(contextMenu, target) { | 95 _appendContentProviderItems(contextMenu, target) { |
| 96 if (!(target instanceof WebInspector.UISourceCode || target instanceof WebIn
spector.Resource || | 96 if (!(target instanceof Workspace.UISourceCode || target instanceof SDK.Reso
urce || |
| 97 target instanceof WebInspector.NetworkRequest)) | 97 target instanceof SDK.NetworkRequest)) |
| 98 return; | 98 return; |
| 99 var contentProvider = /** @type {!WebInspector.ContentProvider} */ (target); | 99 var contentProvider = /** @type {!Common.ContentProvider} */ (target); |
| 100 if (!contentProvider.contentURL()) | 100 if (!contentProvider.contentURL()) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 contextMenu.appendItem( | 103 contextMenu.appendItem( |
| 104 WebInspector.openLinkExternallyLabel(), this._openInNewTab.bind(this, co
ntentProvider.contentURL())); | 104 UI.openLinkExternallyLabel(), this._openInNewTab.bind(this, contentProvi
der.contentURL())); |
| 105 // Skip 0th handler, as it's 'Use default panel' one. | 105 // Skip 0th handler, as it's 'Use default panel' one. |
| 106 for (var i = 1; i < this.handlerNames.length; ++i) { | 106 for (var i = 1; i < this.handlerNames.length; ++i) { |
| 107 var handler = this.handlerNames[i]; | 107 var handler = this.handlerNames[i]; |
| 108 contextMenu.appendItem( | 108 contextMenu.appendItem( |
| 109 WebInspector.UIString.capitalize('Open ^using %s', handler), | 109 Common.UIString.capitalize('Open ^using %s', handler), |
| 110 this.dispatchToHandler.bind(this, handler, {url: contentProvider.conte
ntURL()})); | 110 this.dispatchToHandler.bind(this, handler, {url: contentProvider.conte
ntURL()})); |
| 111 } | 111 } |
| 112 | 112 |
| 113 if (!contentProvider.contentURL() || contentProvider instanceof WebInspector
.NetworkRequest) | 113 if (!contentProvider.contentURL() || contentProvider instanceof SDK.NetworkR
equest) |
| 114 return; | 114 return; |
| 115 | 115 |
| 116 contextMenu.appendItem( | 116 contextMenu.appendItem( |
| 117 WebInspector.copyLinkAddressLabel(), | 117 UI.copyLinkAddressLabel(), |
| 118 InspectorFrontendHost.copyText.bind(InspectorFrontendHost, contentProvid
er.contentURL())); | 118 InspectorFrontendHost.copyText.bind(InspectorFrontendHost, contentProvid
er.contentURL())); |
| 119 | 119 |
| 120 if (!contentProvider.contentType().isDocumentOrScriptOrStyleSheet()) | 120 if (!contentProvider.contentType().isDocumentOrScriptOrStyleSheet()) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * @param {boolean} forceSaveAs | 124 * @param {boolean} forceSaveAs |
| 125 * @param {?string} content | 125 * @param {?string} content |
| 126 */ | 126 */ |
| 127 function doSave(forceSaveAs, content) { | 127 function doSave(forceSaveAs, content) { |
| 128 var url = contentProvider.contentURL(); | 128 var url = contentProvider.contentURL(); |
| 129 WebInspector.fileManager.save(url, /** @type {string} */ (content), forceS
aveAs); | 129 Workspace.fileManager.save(url, /** @type {string} */ (content), forceSave
As); |
| 130 WebInspector.fileManager.close(url); | 130 Workspace.fileManager.close(url); |
| 131 } | 131 } |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * @param {boolean} forceSaveAs | 134 * @param {boolean} forceSaveAs |
| 135 */ | 135 */ |
| 136 function save(forceSaveAs) { | 136 function save(forceSaveAs) { |
| 137 if (contentProvider instanceof WebInspector.UISourceCode) { | 137 if (contentProvider instanceof Workspace.UISourceCode) { |
| 138 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (contentPro
vider); | 138 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvid
er); |
| 139 if (forceSaveAs) | 139 if (forceSaveAs) |
| 140 uiSourceCode.saveAs(); | 140 uiSourceCode.saveAs(); |
| 141 else | 141 else |
| 142 uiSourceCode.commitWorkingCopy(); | 142 uiSourceCode.commitWorkingCopy(); |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 contentProvider.requestContent().then(doSave.bind(null, forceSaveAs)); | 145 contentProvider.requestContent().then(doSave.bind(null, forceSaveAs)); |
| 146 } | 146 } |
| 147 | 147 |
| 148 contextMenu.appendSeparator(); | 148 contextMenu.appendSeparator(); |
| 149 contextMenu.appendItem(WebInspector.UIString('Save'), save.bind(null, false)
); | 149 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); |
| 150 | 150 |
| 151 if (contentProvider instanceof WebInspector.UISourceCode) { | 151 if (contentProvider instanceof Workspace.UISourceCode) { |
| 152 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (contentProvi
der); | 152 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider
); |
| 153 if (uiSourceCode.project().type() !== WebInspector.projectTypes.FileSystem
&& | 153 if (uiSourceCode.project().type() !== Workspace.projectTypes.FileSystem && |
| 154 uiSourceCode.project().type() !== WebInspector.projectTypes.Snippets) | 154 uiSourceCode.project().type() !== Workspace.projectTypes.Snippets) |
| 155 contextMenu.appendItem(WebInspector.UIString.capitalize('Save ^as...'),
save.bind(null, true)); | 155 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b
ind(null, true)); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * @param {!WebInspector.ContextMenu} contextMenu | 160 * @param {!UI.ContextMenu} contextMenu |
| 161 * @param {!Object} target | 161 * @param {!Object} target |
| 162 */ | 162 */ |
| 163 _appendHrefItems(contextMenu, target) { | 163 _appendHrefItems(contextMenu, target) { |
| 164 if (!(target instanceof Node)) | 164 if (!(target instanceof Node)) |
| 165 return; | 165 return; |
| 166 var targetNode = /** @type {!Node} */ (target); | 166 var targetNode = /** @type {!Node} */ (target); |
| 167 | 167 |
| 168 var anchorElement = targetNode.enclosingNodeOrSelfWithClass('webkit-html-res
ource-link') || | 168 var anchorElement = targetNode.enclosingNodeOrSelfWithClass('webkit-html-res
ource-link') || |
| 169 targetNode.enclosingNodeOrSelfWithClass('webkit-html-external-link'); | 169 targetNode.enclosingNodeOrSelfWithClass('webkit-html-external-link'); |
| 170 if (!anchorElement) | 170 if (!anchorElement) |
| 171 return; | 171 return; |
| 172 | 172 |
| 173 var uiLocation = WebInspector.Linkifier.uiLocationByAnchor(anchorElement); | 173 var uiLocation = Components.Linkifier.uiLocationByAnchor(anchorElement); |
| 174 var resourceURL = uiLocation ? uiLocation.uiSourceCode.contentURL() : anchor
Element.href; | 174 var resourceURL = uiLocation ? uiLocation.uiSourceCode.contentURL() : anchor
Element.href; |
| 175 var uiSourceCode = uiLocation ? | 175 var uiSourceCode = uiLocation ? |
| 176 uiLocation.uiSourceCode : | 176 uiLocation.uiSourceCode : |
| 177 (resourceURL ? WebInspector.networkMapping.uiSourceCodeForURLForAnyTarge
t(resourceURL) : null); | 177 (resourceURL ? Bindings.networkMapping.uiSourceCodeForURLForAnyTarget(re
sourceURL) : null); |
| 178 function open() { | 178 function open() { |
| 179 WebInspector.Revealer.reveal(uiSourceCode); | 179 Common.Revealer.reveal(uiSourceCode); |
| 180 } | 180 } |
| 181 if (uiSourceCode) | 181 if (uiSourceCode) |
| 182 contextMenu.appendItem('Open', open); | 182 contextMenu.appendItem('Open', open); |
| 183 | 183 |
| 184 if (!resourceURL) | 184 if (!resourceURL) |
| 185 return; | 185 return; |
| 186 // Add resource-related actions. | 186 // Add resource-related actions. |
| 187 contextMenu.appendItem(WebInspector.openLinkExternallyLabel(), this._openInN
ewTab.bind(this, resourceURL)); | 187 contextMenu.appendItem(UI.openLinkExternallyLabel(), this._openInNewTab.bind
(this, resourceURL)); |
| 188 | 188 |
| 189 /** | 189 /** |
| 190 * @param {string} resourceURL | 190 * @param {string} resourceURL |
| 191 */ | 191 */ |
| 192 function openInResourcesPanel(resourceURL) { | 192 function openInResourcesPanel(resourceURL) { |
| 193 var resource = WebInspector.resourceForURL(resourceURL); | 193 var resource = Bindings.resourceForURL(resourceURL); |
| 194 if (resource) | 194 if (resource) |
| 195 WebInspector.Revealer.reveal(resource); | 195 Common.Revealer.reveal(resource); |
| 196 else | 196 else |
| 197 InspectorFrontendHost.openInNewTab(resourceURL); | 197 InspectorFrontendHost.openInNewTab(resourceURL); |
| 198 } | 198 } |
| 199 if (!targetNode.enclosingNodeOrSelfWithClassList(['resources', 'panel']) && | 199 if (!targetNode.enclosingNodeOrSelfWithClassList(['resources', 'panel']) && |
| 200 WebInspector.resourceForURL(resourceURL)) | 200 Bindings.resourceForURL(resourceURL)) |
| 201 contextMenu.appendItem( | 201 contextMenu.appendItem( |
| 202 WebInspector.UIString.capitalize('Open ^link in Application ^panel'), | 202 Common.UIString.capitalize('Open ^link in Application ^panel'), |
| 203 openInResourcesPanel.bind(null, resourceURL)); | 203 openInResourcesPanel.bind(null, resourceURL)); |
| 204 | 204 |
| 205 contextMenu.appendItem( | 205 contextMenu.appendItem( |
| 206 WebInspector.copyLinkAddressLabel(), InspectorFrontendHost.copyText.bind
(InspectorFrontendHost, resourceURL)); | 206 UI.copyLinkAddressLabel(), InspectorFrontendHost.copyText.bind(Inspector
FrontendHost, resourceURL)); |
| 207 } | 207 } |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 /** @enum {symbol} */ | 210 /** @enum {symbol} */ |
| 211 WebInspector.HandlerRegistry.Events = { | 211 Components.HandlerRegistry.Events = { |
| 212 HandlersUpdated: Symbol('HandlersUpdated') | 212 HandlersUpdated: Symbol('HandlersUpdated') |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 /** | 215 /** |
| 216 * @unrestricted | 216 * @unrestricted |
| 217 */ | 217 */ |
| 218 WebInspector.HandlerSelector = class { | 218 Components.HandlerSelector = class { |
| 219 constructor(handlerRegistry) { | 219 constructor(handlerRegistry) { |
| 220 this._handlerRegistry = handlerRegistry; | 220 this._handlerRegistry = handlerRegistry; |
| 221 this.element = createElementWithClass('select', 'chrome-select'); | 221 this.element = createElementWithClass('select', 'chrome-select'); |
| 222 this.element.addEventListener('change', this._onChange.bind(this), false); | 222 this.element.addEventListener('change', this._onChange.bind(this), false); |
| 223 this._update(); | 223 this._update(); |
| 224 this._handlerRegistry.addEventListener( | 224 this._handlerRegistry.addEventListener( |
| 225 WebInspector.HandlerRegistry.Events.HandlersUpdated, this._update.bind(t
his)); | 225 Components.HandlerRegistry.Events.HandlersUpdated, this._update.bind(thi
s)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 _update() { | 228 _update() { |
| 229 this.element.removeChildren(); | 229 this.element.removeChildren(); |
| 230 var names = this._handlerRegistry.handlerNames; | 230 var names = this._handlerRegistry.handlerNames; |
| 231 var activeHandler = this._handlerRegistry.activeHandler; | 231 var activeHandler = this._handlerRegistry.activeHandler; |
| 232 | 232 |
| 233 for (var i = 0; i < names.length; ++i) { | 233 for (var i = 0; i < names.length; ++i) { |
| 234 var option = createElement('option'); | 234 var option = createElement('option'); |
| 235 option.textContent = names[i]; | 235 option.textContent = names[i]; |
| 236 option.selected = activeHandler === names[i]; | 236 option.selected = activeHandler === names[i]; |
| 237 this.element.appendChild(option); | 237 this.element.appendChild(option); |
| 238 } | 238 } |
| 239 this.element.disabled = names.length <= 1; | 239 this.element.disabled = names.length <= 1; |
| 240 } | 240 } |
| 241 | 241 |
| 242 _onChange(event) { | 242 _onChange(event) { |
| 243 var value = event.target.value; | 243 var value = event.target.value; |
| 244 this._handlerRegistry.activeHandler = value; | 244 this._handlerRegistry.activeHandler = value; |
| 245 } | 245 } |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 /** | 248 /** |
| 249 * @implements {WebInspector.ContextMenu.Provider} | 249 * @implements {UI.ContextMenu.Provider} |
| 250 * @unrestricted | 250 * @unrestricted |
| 251 */ | 251 */ |
| 252 WebInspector.HandlerRegistry.ContextMenuProvider = class { | 252 Components.HandlerRegistry.ContextMenuProvider = class { |
| 253 /** | 253 /** |
| 254 * @override | 254 * @override |
| 255 * @param {!Event} event | 255 * @param {!Event} event |
| 256 * @param {!WebInspector.ContextMenu} contextMenu | 256 * @param {!UI.ContextMenu} contextMenu |
| 257 * @param {!Object} target | 257 * @param {!Object} target |
| 258 */ | 258 */ |
| 259 appendApplicableItems(event, contextMenu, target) { | 259 appendApplicableItems(event, contextMenu, target) { |
| 260 WebInspector.openAnchorLocationRegistry._appendContentProviderItems(contextM
enu, target); | 260 Components.openAnchorLocationRegistry._appendContentProviderItems(contextMen
u, target); |
| 261 WebInspector.openAnchorLocationRegistry._appendHrefItems(contextMenu, target
); | 261 Components.openAnchorLocationRegistry._appendHrefItems(contextMenu, target); |
| 262 } | 262 } |
| 263 }; | 263 }; |
| 264 | 264 |
| 265 /** | 265 /** |
| 266 * @implements {WebInspector.Linkifier.LinkHandler} | 266 * @implements {Components.Linkifier.LinkHandler} |
| 267 * @unrestricted | 267 * @unrestricted |
| 268 */ | 268 */ |
| 269 WebInspector.HandlerRegistry.LinkHandler = class { | 269 Components.HandlerRegistry.LinkHandler = class { |
| 270 /** | 270 /** |
| 271 * @override | 271 * @override |
| 272 * @param {string} url | 272 * @param {string} url |
| 273 * @param {number=} lineNumber | 273 * @param {number=} lineNumber |
| 274 * @return {boolean} | 274 * @return {boolean} |
| 275 */ | 275 */ |
| 276 handleLink(url, lineNumber) { | 276 handleLink(url, lineNumber) { |
| 277 return WebInspector.openAnchorLocationRegistry.dispatch({url: url, lineNumbe
r: lineNumber}); | 277 return Components.openAnchorLocationRegistry.dispatch({url: url, lineNumber:
lineNumber}); |
| 278 } | 278 } |
| 279 }; | 279 }; |
| 280 | 280 |
| 281 /** | 281 /** |
| 282 * @implements {WebInspector.SettingUI} | 282 * @implements {UI.SettingUI} |
| 283 * @unrestricted | 283 * @unrestricted |
| 284 */ | 284 */ |
| 285 WebInspector.HandlerRegistry.OpenAnchorLocationSettingUI = class { | 285 Components.HandlerRegistry.OpenAnchorLocationSettingUI = class { |
| 286 /** | 286 /** |
| 287 * @override | 287 * @override |
| 288 * @return {?Element} | 288 * @return {?Element} |
| 289 */ | 289 */ |
| 290 settingElement() { | 290 settingElement() { |
| 291 if (!WebInspector.openAnchorLocationRegistry.handlerNames.length) | 291 if (!Components.openAnchorLocationRegistry.handlerNames.length) |
| 292 return null; | 292 return null; |
| 293 | 293 |
| 294 var handlerSelector = new WebInspector.HandlerSelector(WebInspector.openAnch
orLocationRegistry); | 294 var handlerSelector = new Components.HandlerSelector(Components.openAnchorLo
cationRegistry); |
| 295 return WebInspector.SettingsUI.createCustomSetting( | 295 return UI.SettingsUI.createCustomSetting( |
| 296 WebInspector.UIString('Link handling:'), handlerSelector.element); | 296 Common.UIString('Link handling:'), handlerSelector.element); |
| 297 } | 297 } |
| 298 }; | 298 }; |
| 299 | 299 |
| 300 /** | 300 /** |
| 301 * @type {!WebInspector.HandlerRegistry} | 301 * @type {!Components.HandlerRegistry} |
| 302 */ | 302 */ |
| 303 WebInspector.openAnchorLocationRegistry; | 303 Components.openAnchorLocationRegistry; |
| OLD | NEW |