Closed
Bug 82435
Opened 24 years ago
Closed 24 years ago
Need ability to force reload a specific image url from javascript
Categories
(Core :: Graphics: ImageLib, defect, P2)
Tracking
()
VERIFIED
FIXED
mozilla0.9.2
People
(Reporter: cmanske, Assigned: pavlov)
References
Details
(Keywords: regression, Whiteboard: r=cmanske sr=jst need a=)
Attachments
(2 files)
Reporter | ||
Comment 1•24 years ago
|
||
Use Composer and click on Image button to bring up dialog. Click on "Choose
File" button. (If it isn't visible, Cancel dialog and bring it up again --
that's a known XPFE problem.)
Select a local image file -- it displays in preview box and its "natural width
and height" are reported next to the image.
Click on "Choose File" button again and select a different image. Again, the
image displays correctly and shows the width and height.
But if you select an image that you've already selected before,
The "onload" handler is called, but "naturalWidth" and "naturalHeight" are
returned as "0" for both.
So it seems that a cached image is failing to return its size.
Note that this happens for any image once loaded, thus another way of showing
the bug is to simply load a page with an image in it. Double click on that
image and it will be shown in the preview window, but the witdth and height
are not reported, because GetNaturalWidth() and GetNaturalHeight() have
returned 0.)
This might be related to bug 7019.
Severity: normal → critical
Summary: Failure to get "naturalWidth" and "naturalHeight" 2nd time for an image (after being cached) → Failure to get "naturalWidth" and "naturalHeight" for any image already loaded in a page.
Reporter | ||
Comment 2•24 years ago
|
||
Johnny: Given the number of bugs that pav has, do you think you can fix this?
Blocks: 78351
Keywords: regression
Assignee | ||
Comment 3•24 years ago
|
||
bug 7019 is fixed (and has been since 0.9) so I don't think it is related. If
you can post a very simple testcase of this, I can probably get to it sooner.
Comment 4•24 years ago
|
||
Charles, I'm sorry but this one really is Pav's. This is a lowlevel problem in
the image loading code, the problem is that loading an image from cache ends up
fireing the onload event synchronously (from within nsImageFrame::LoadImage())
so mImageRequest in the image frame is null when the onload event fires, thus we
can't ask the image request for the size of the image.
Reporter | ||
Comment 5•24 years ago
|
||
Right, I did some serious debugging today and found that out as well.
This sucks!
Reporter | ||
Comment 6•24 years ago
|
||
A "simple test case" isn't going to make debugging any easy, imho.
Using the Image dialog's "Choose File" button as described in first bug
description is really the easiest way to show the problem.
Just break in imgLoader::LoadImageWithChannel() and at
nsImageFrame::GetNaturalImageSize() and you'll see what's going on.
After the first load, mImageRequest exists so we return the size info.
During the second load for same URL, GetNaturalImageSize() is called
synchronously as JST described, and mImageRequest null, so we can't get the size.
Target Milestone: --- → mozilla0.9.2
Assignee | ||
Comment 7•24 years ago
|
||
Please do not change the target milestones of bugs you don't own.
Reporter | ||
Comment 8•24 years ago
|
||
Sorry! Because of dependency, I thought it was ok to do that. I won't any more.
Reporter | ||
Comment 9•24 years ago
|
||
So the current problem is essentially the same as the request in bug 72922:
We need to be able to tell image loader to "ignore cache and always reload the
image." If that problem is solved, so will this bug.
From the editor context, we only deal with nsHTMLImageElement, so the
problem is selectively the flags on the nsILoadGroup used to load the image.
Putting this code in nsImageFrame::LoadImage()
PRUint32 flags = 0;
loadGroup->GetLoadFlags(&flags);
flags |= nsIRequest::LOAD_BYPASS_CACHE;
loadGroup->SetLoadFlags(flags);
just before
return il->LoadImage(uri, loadGroup, mListener, aPresContext, aRequest);
fixes the problem (and bug 72922) by always forcing a new image load.
I see two possible solutions to make this happen only for Editor image loads:
1. During parsing of tags for editor, put a "-moz-bypass-cache" attribute on
each <img> tag ("-moz..." attributes are always stripped out when writing
output). This attribute would be checked in nsHTMLImageElement to set a
class member flag, and this would have to be passed as a new parameter to
nsImageFrame::LoadImage().
2. Another solution might be to detect when we are in an editor (I think we
can do that from nsIPresContext) and always set the
nsIRequest::LOAD_BYPASS_CACHE flag when imgLoader::LoadImage is called.
That is probably easier, but wouln't that also ignore cache for UI images and
other images we use that aren't part of the page content?
I'm no expert in Image code, and I'm sure there's probably a better solution,
but I hope this stimulates finding it!
Reporter | ||
Comment 10•24 years ago
|
||
Note that using a "-moz-bypass-cache" attribute is a good idea only for *locale*
images. You probably wouldn't want that if SRC URI is a remote image!
This argues against ignoring cache for editor in general.
Reporter | ||
Comment 11•24 years ago
|
||
Reporter | ||
Comment 12•24 years ago
|
||
Why I think the suggested fix in 5/26/01 patch is the correct solution:
1. The "_moz-bypass-cache" attribute is set true only on the <img> tag in the
actual dialog. We do not have to do this on the img tags in the document, as I
suggested in original proposal. (Patch for changes to EdImageProps.xul to use
this attribute is attached to bug 78351.)
2. Normal image loading in Browser and Composer is not affected; the user's
image cache settings in prefs still control normal image loading. The test for
the "_moz-bypass-cache" attribute only happens in Composer Image dialog and in
DHTML uses where the SRC attribute is changed after initial page loading.
(In-house DHTML users might also find this attribute useful for forcing image
reloading.)
3. This also fixes bug 72922, a very annoying problem in Composer that prevents
users from seeing any changes they make to images while editing a page
that includes them (must delete cache, close program, restart!)
4. Fix is very simple and restricted to just nsImageFrame; nsHTMLImageElement
and cache code do not have to be changed.
The attached patch also contains JST's fix for bug 76177, which is required
as part of this fix. The removal of "mNaturalImageWidth" and
"mNaturalImageHeight" from nsImageFrame.h is cleanup -- they were not used
and should not be (we shouldn't store any size information in the frame
now that the SRC can be changed.)
Comment 13•24 years ago
|
||
I *really* dislike the idea of adding a _moz-bypass-cache attribute only to hack
around a real problem with imglib, which we can fix or get around with less
trouble, I'm sure. If we don't wanto fix imglib to not call its notification
methods synchronously when loading an image from the cache then we can fix this
in the image frame by setting the image request pointer in the notification
callbacks if we're called synchronously (which one can tell by checking if
mImageRequest == null in the notification callbacks). There are issues to be
sorted out here (such as potential leaks from poking a new value into a nsCOMPtr
when there's a getter_AddRefs() on the stack for the same nsCOMPtr), but nothing
too complicated, let's fix this the right way in stead of adding editor specific
hacks to the code (which only fixes this problem in the editor case, the same
problem can be demonstrated in web content as well).
Reporter | ||
Comment 14•24 years ago
|
||
I'd be much happy as well if we could fix the basic imglib problems, but that
still wouldn't fix 72922, would it? We would still need some way to ask for
an image load that bypasses the cache, right?
Comment 15•24 years ago
|
||
Comment 16•24 years ago
|
||
Rick, this is the bug about loading images from the cache ends up calling the
notification callbacks synchronously.
Reporter | ||
Comment 17•24 years ago
|
||
If the ImgLib work required as suggested by JST isn't done,
then I suggest we use the "_moz-bypass-cache" strategy at least for
an interim fix.
Assignee | ||
Comment 18•24 years ago
|
||
you could set mImageRequest in OnStartDecode, however, i'm not sure how you
could tell if this is the low source url or not. perhaps it doesn't matter.
Reporter | ||
Comment 19•24 years ago
|
||
I'm sure it does matter. The "natural" width and height are usually different
for the lowsrc. We need to get the final image's size.
Assignee | ||
Updated•24 years ago
|
Priority: -- → P2
Assignee | ||
Comment 20•24 years ago
|
||
Assignee | ||
Updated•24 years ago
|
Whiteboard: FIX IN HAND need r=, sr= → need r=, sr=, a=
Reporter | ||
Comment 21•24 years ago
|
||
r=cmanske
Tested and it works great.
Whiteboard: need r=, sr=, a= → need sr=, a=
Comment 22•24 years ago
|
||
Pavlov, why this change in imgCache.cpp:
@@ -197,9 +209,9 @@
PRBool imgCache::Remove(nsIURI *aKey)
{
LOG_STATIC_FUNC(gImgLog, "imgCache::Remove");
+ if (!aKey) return PR_FALSE;
nsresult rv;
The code that's called later on in this method doesn't properly handle a null
URI, so why remove the null check?
Assignee | ||
Comment 23•24 years ago
|
||
huh? i added the check for null there. the reason i don't check for null in
the other function is that the other callers of it all have null checks in other
places.
Comment 24•24 years ago
|
||
Eh, huh, duh! Stupid me, geez, man, how lame is that, I can't even read diff's
any more!
sr=jst (which obviously doesn't mean much any more ;-)
(feeling stupid)
Assignee | ||
Updated•24 years ago
|
Whiteboard: need sr=, a= → r=cmanske sr=jst need a=
Comment 25•24 years ago
|
||
a=tor for attachment 38322 [details] [diff] [review] checkin to trunk
Assignee | ||
Comment 26•24 years ago
|
||
marking fixed.
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Summary: Failure to get "naturalWidth" and "naturalHeight" for any image already loaded in a page. → Need ability to force reload a specific image url from javascript
You need to log in
before you can comment on or make changes to this bug.
Description
•