| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 4 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 5 * Copyright (C) 2009 Joseph Pecoraro | 5 * Copyright (C) 2009 Joseph Pecoraro |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * | 10 * |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 Common.Revealer.reveal(node); | 141 Common.Revealer.reveal(node); |
| 142 } | 142 } |
| 143 | 143 |
| 144 return root; | 144 return root; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * @param {!SDK.Target} target | 148 * @param {!SDK.Target} target |
| 149 * @param {string} originalImageURL | 149 * @param {string} originalImageURL |
| 150 * @param {boolean} showDimensions | 150 * @param {boolean} showDimensions |
| 151 * @param {function(!Element=)} userCallback | |
| 152 * @param {!Object=} precomputedFeatures | 151 * @param {!Object=} precomputedFeatures |
| 152 * @return {!Promise<?Element>} |
| 153 */ | 153 */ |
| 154 Components.DOMPresentationUtils.buildImagePreviewContents = function( | 154 Components.DOMPresentationUtils.buildImagePreviewContents = function( |
| 155 target, originalImageURL, showDimensions, userCallback, precomputedFeatures)
{ | 155 target, originalImageURL, showDimensions, precomputedFeatures) { |
| 156 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target); | 156 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target); |
| 157 if (!resourceTreeModel) { | 157 if (!resourceTreeModel) |
| 158 userCallback(); | 158 return Promise.resolve(/** @type {?Element} */ (null)); |
| 159 return; | |
| 160 } | |
| 161 var resource = resourceTreeModel.resourceForURL(originalImageURL); | 159 var resource = resourceTreeModel.resourceForURL(originalImageURL); |
| 162 var imageURL = originalImageURL; | 160 var imageURL = originalImageURL; |
| 163 if (!isImageResource(resource) && precomputedFeatures && precomputedFeatures.c
urrentSrc) { | 161 if (!isImageResource(resource) && precomputedFeatures && precomputedFeatures.c
urrentSrc) { |
| 164 imageURL = precomputedFeatures.currentSrc; | 162 imageURL = precomputedFeatures.currentSrc; |
| 165 resource = resourceTreeModel.resourceForURL(imageURL); | 163 resource = resourceTreeModel.resourceForURL(imageURL); |
| 166 } | 164 } |
| 167 if (!isImageResource(resource)) { | 165 if (!isImageResource(resource)) |
| 168 userCallback(); | 166 return Promise.resolve(/** @type {?Element} */ (null)); |
| 169 return; | |
| 170 } | |
| 171 | 167 |
| 168 var fulfill; |
| 169 var promise = new Promise(x => fulfill = x); |
| 172 var imageElement = createElement('img'); | 170 var imageElement = createElement('img'); |
| 173 imageElement.addEventListener('load', buildContent, false); | 171 imageElement.addEventListener('load', buildContent, false); |
| 174 imageElement.addEventListener('error', errorCallback, false); | 172 imageElement.addEventListener('error', () => fulfill(null), false); |
| 175 resource.populateImageSource(imageElement); | 173 resource.populateImageSource(imageElement); |
| 176 | 174 return promise; |
| 177 function errorCallback() { | |
| 178 // Drop the event parameter when invoking userCallback. | |
| 179 userCallback(); | |
| 180 } | |
| 181 | 175 |
| 182 /** | 176 /** |
| 183 * @param {?SDK.Resource} resource | 177 * @param {?SDK.Resource} resource |
| 184 * @return {boolean} | 178 * @return {boolean} |
| 185 */ | 179 */ |
| 186 function isImageResource(resource) { | 180 function isImageResource(resource) { |
| 187 return !!resource && resource.resourceType() === Common.resourceTypes.Image; | 181 return !!resource && resource.resourceType() === Common.resourceTypes.Image; |
| 188 } | 182 } |
| 189 | 183 |
| 190 function buildContent() { | 184 function buildContent() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 205 } | 199 } |
| 206 } | 200 } |
| 207 | 201 |
| 208 container.createChild('tr').createChild('td', 'image-container').appendChild
(imageElement); | 202 container.createChild('tr').createChild('td', 'image-container').appendChild
(imageElement); |
| 209 if (description) | 203 if (description) |
| 210 container.createChild('tr').createChild('td').createChild('span', 'descrip
tion').textContent = description; | 204 container.createChild('tr').createChild('td').createChild('span', 'descrip
tion').textContent = description; |
| 211 if (imageURL !== originalImageURL) { | 205 if (imageURL !== originalImageURL) { |
| 212 container.createChild('tr').createChild('td').createChild('span', 'descrip
tion').textContent = | 206 container.createChild('tr').createChild('td').createChild('span', 'descrip
tion').textContent = |
| 213 String.sprintf('currentSrc: %s', imageURL.trimMiddle(100)); | 207 String.sprintf('currentSrc: %s', imageURL.trimMiddle(100)); |
| 214 } | 208 } |
| 215 userCallback(container); | 209 fulfill(container); |
| 216 } | 210 } |
| 217 }; | 211 }; |
| 218 | 212 |
| 219 /** | 213 /** |
| 220 * @param {!SDK.Target} target | 214 * @param {!SDK.Target} target |
| 221 * @param {!Components.Linkifier} linkifier | 215 * @param {!Components.Linkifier} linkifier |
| 222 * @param {!Protocol.Runtime.StackTrace=} stackTrace | 216 * @param {!Protocol.Runtime.StackTrace=} stackTrace |
| 223 * @return {!Element} | 217 * @return {!Element} |
| 224 */ | 218 */ |
| 225 Components.DOMPresentationUtils.buildStackTracePreviewContents = function(target
, linkifier, stackTrace) { | 219 Components.DOMPresentationUtils.buildStackTracePreviewContents = function(target
, linkifier, stackTrace) { |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 | 635 |
| 642 /** | 636 /** |
| 643 * @override | 637 * @override |
| 644 * @param {!SDK.DOMNode} node | 638 * @param {!SDK.DOMNode} node |
| 645 * @return {?{title: string, color: string}} | 639 * @return {?{title: string, color: string}} |
| 646 */ | 640 */ |
| 647 decorate(node) { | 641 decorate(node) { |
| 648 return {title: this._title, color: this._color}; | 642 return {title: this._title, color: this._color}; |
| 649 } | 643 } |
| 650 }; | 644 }; |
| OLD | NEW |