Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fix #10786 - Allow QuickView image preview for arbitrary URLs #10788

Merged
merged 3 commits into from
May 26, 2015

Conversation

humphd
Copy link
Contributor

@humphd humphd commented Mar 24, 2015

This leverages the img element's load and error events to try and load arbitrary images. It also expands the list of known image extensions to include .bmp, which browsers can display.

@humphd
Copy link
Contributor Author

humphd commented Mar 27, 2015

I've updated this with the suggestion made to examine extensions.

@marcelgerber
Copy link
Contributor

Could you take a look at the data provided by language.json/LanguageManager and see if you can use them? image is particularly interesting for whitelist (please concat "svg" yourself), audio and binary for blacklist (concat the ones you already have, plus maybe also "rss", "php").

@humphd
Copy link
Contributor Author

humphd commented Apr 13, 2015

I've rewritten this to use LanguageManager, good suggestion.

@humphd
Copy link
Contributor Author

humphd commented Apr 25, 2015

This is ready for review.

@nethip nethip self-assigned this Apr 28, 2015
@nethip
Copy link
Contributor

nethip commented Apr 30, 2015

@humphd Can you add some unit tests, if possible? Also run smoke tests with these changes, especially the one relating to editor and Extensions.

ePos = {line: pos.line, ch: token.end};
}

var imgPreview = "<div class='image-preview'>" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put in the imgPath check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already been dealt with in the if-block above from lines 475-483, returning early if we have no value for imgPath, and therefore not needing to do the check and indent all this code.

@nethip
Copy link
Contributor

nethip commented Apr 30, 2015

LGTM

@redmunds
Copy link
Contributor

The original Quick View implementation had support for arbitrary URLs, but it was removed due to concerns about performance (i.e. downloading external files on mousemove!). The code has been optimized since then so it now does not try to parse code in editor until mouse hasn't moved for 350ms, but people with a slow network or no network connection might see problems.

Be sure to test this with no internet connection!

You should consider:

  1. Making this a preference. It's probably OK to default to ON as long as there's a way to turn it OFF.
  2. Caching images. No need to re-download same image over and over. Maybe this already takes advantage of browser cache. Then there's the opposite problem of a stale cache :)

@humphd
Copy link
Contributor Author

humphd commented Apr 30, 2015

I've updated this again. New commit adds:

  • pref for enabling/disabling extensionless previews for URLs (on by default). Let me know if this is how you want such a pref to be done.
  • tests for everything that seemed obvious to me about what this patch is doing.

Regarding @redmunds' questions. First, with no network, you end up in the error path (net::ERR_INTERNET_DISCONNECTED exception or the like trying to load the resource) and it does the right thing. I think cache is best handled by the browser. Trying to build something more intelligent than what is already there for free seems like a waste of effort to me.

@@ -784,10 +812,15 @@ define(function (require, exports, module) {

// Setup initial UI state
setEnabled(prefs.get("enabled"), true);
setExtensionlessImagePreview(prefs.get("extensionlessImagePreview"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should never write to prefs on initial load. This is unnecessary and slows down startup. I can see that this is emulating the other pref here, so remove that also if possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, call to setEnabled(prefs.get("enabled"), true); on line above is not writing to prefs, so that should be ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the whole doNotSave dance was done for the initial load case? I'll echo that for this as well and avoid the write.

@redmunds
Copy link
Contributor

redmunds commented May 5, 2015

In general, this looks good. Be sure to turn on JSLint as I am seeing some JSLint errors in QuickView/main.js. Also, there is a merge conflict that needs to be resolved. Just 1 other comment.

@humphd
Copy link
Contributor Author

humphd commented May 5, 2015

@redmunds thanks for the review. I've rebased and pushed fixes. See if this approach satisfies what you wanted with the pref saving and startup.

@redmunds
Copy link
Contributor

redmunds commented May 6, 2015

@humphd

See if this approach satisfies what you wanted with the pref saving and startup.

Looks good.

@humphd
Copy link
Contributor Author

humphd commented May 8, 2015

Great, can someone land this then?

nethip added a commit that referenced this pull request May 26, 2015
Fix #10786 - Allow QuickView image preview for arbitrary URLs
@nethip nethip merged commit 654e750 into adobe:master May 26, 2015
@nethip
Copy link
Contributor

nethip commented May 26, 2015

Thanks @humphd for this fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants