Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js

Issue 2747553002: [DevTools] Rework Popover API (Closed)
Patch Set: rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js
diff --git a/third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js b/third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js
index 69a347272ca3a09fe09a012ade9faa168a4111e4..cd0c0c92fc66bc389bcbbe496b6df3ac51b0ad38 100644
--- a/third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js
+++ b/third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js
@@ -148,36 +148,30 @@ Components.DOMPresentationUtils.linkifyDeferredNodeReference = function(deferred
* @param {!SDK.Target} target
* @param {string} originalImageURL
* @param {boolean} showDimensions
- * @param {function(!Element=)} userCallback
* @param {!Object=} precomputedFeatures
+ * @return {!Promise<?Element>}
*/
Components.DOMPresentationUtils.buildImagePreviewContents = function(
- target, originalImageURL, showDimensions, userCallback, precomputedFeatures) {
+ target, originalImageURL, showDimensions, precomputedFeatures) {
var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target);
- if (!resourceTreeModel) {
- userCallback();
- return;
- }
+ if (!resourceTreeModel)
+ return Promise.resolve(/** @type {?Element} */ (null));
var resource = resourceTreeModel.resourceForURL(originalImageURL);
var imageURL = originalImageURL;
if (!isImageResource(resource) && precomputedFeatures && precomputedFeatures.currentSrc) {
imageURL = precomputedFeatures.currentSrc;
resource = resourceTreeModel.resourceForURL(imageURL);
}
- if (!isImageResource(resource)) {
- userCallback();
- return;
- }
+ if (!isImageResource(resource))
+ return Promise.resolve(/** @type {?Element} */ (null));
+ var fulfill;
+ var promise = new Promise(x => fulfill = x);
var imageElement = createElement('img');
imageElement.addEventListener('load', buildContent, false);
- imageElement.addEventListener('error', errorCallback, false);
+ imageElement.addEventListener('error', () => fulfill(null), false);
resource.populateImageSource(imageElement);
-
- function errorCallback() {
- // Drop the event parameter when invoking userCallback.
- userCallback();
- }
+ return promise;
/**
* @param {?SDK.Resource} resource
@@ -212,7 +206,7 @@ Components.DOMPresentationUtils.buildImagePreviewContents = function(
container.createChild('tr').createChild('td').createChild('span', 'description').textContent =
String.sprintf('currentSrc: %s', imageURL.trimMiddle(100));
}
- userCallback(container);
+ fulfill(container);
}
};

Powered by Google App Engine
This is Rietveld 408576698