Closed Bug 196380 Opened 21 years ago Closed 20 years ago

Image location copying code should use nsIImageLoadingContent

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.8alpha2

People

(Reporter: jst, Assigned: Biesinger)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 3 obsolete files)

This came up in bug 182700 where code was added to be able to copy the image
location of other images than HTML IMG elements. That code currently has
specific code for different types of images when it should use
nsIImageLoadingContent once it's available.
Depends on: 83774
Priority: -- → P1
Target Milestone: --- → mozilla1.4beta
taking...
Assignee: bzbarsky → cbiesinger
Priority: P1 → --
Target Milestone: mozilla1.4beta → mozilla1.6alpha
Target Milestone: mozilla1.6alpha → mozilla1.6beta
Blocks: 130087
OK. so, to fix this, I'll add an readonly attribute nsIURI currentURI; attribute
to nsIImageLoadingContent, with the following behaviour:
o) If mCurrentRequest != null, returns its uri
o) otherwise, it returns the last uri for which ImageURIChanged was called

afaict that will always result in "the url of the image that's currently displayed".

bz, did I understand this code right?
Target Milestone: mozilla1.6beta → mozilla1.8beta
Sounds like you did, yes.

I assume the "mCurrentRequest == null" case is meant to cover blocked images? 
That is, I'd sort of like us to not be keeping the URI around unless
mCurrentRequest is in fact null....

Note that I think some existing consumers of nsIImageLoadingContent may benefit
from this change.
(In reply to comment #3)
> I assume the "mCurrentRequest == null" case is meant to cover blocked images? 

that too; the actual use case I was thinking of is when LoadImage fails (i.e.
when AsyncOpen fails)

> That is, I'd sort of like us to not be keeping the URI around unless
> mCurrentRequest is in fact null....

sure, seems doable
So....

consider:
data:text/html,<img src="foo">
(that exact uri. not a document with same contents from file:)

What do you expect when you do "copy link location"
o) as a user?
o) as a developer who knows you can't get an nsIURI for the image uri? (about:
has no relative links)
hmm... also, what about malformed uris?

maybe nsImageLoadingContent should store the uri as string, and give it back as
such...
Attached patch patch v0 (obsolete) — Splinter Review
this is what I have so far; but it can't copy urls for which StringToURI fails.


It also moves nsCopySupport from layout to content - I feel it belongs there
better; it also doesn't really need any layout stuff. I'll attach a patch that
shows the changes I made to it in a second.

And I eliminated the CopyImageLocation and DoCopyImageContents functions from
nsIPresShell.
> hmm... also, what about malformed uris?

We won't be showing the image for those, now would we?  In my opinion, the
isImage bool in the context menu code should just be false for broken images....
So how should the context menu go about detecting an image?
QI to nsIImageLoadingContent and see whether it has a non-failed request.

We can expose functionality on nsIImageLoadingContent as needed to ease this, I
think.
Attached patch xpfe patch (obsolete) — Splinter Review
ok, together with this patch, I'm happy with the other patch. it only shows
image-related context menu items if the image has an nsIURI-compatible uri.
Attachment #148986 - Flags: superreview?(bzbarsky)
Attachment #148986 - Flags: review?(bzbarsky)
Attachment #149081 - Flags: review?(neil.parkwaycc.co.uk)
Status: NEW → ASSIGNED
Comment on attachment 148986 [details] [diff] [review]
patch v0

>Index: accessible/src/base/Makefile.in
>+			imglib2 \

Fix the indent?

>Index: content/base/public/nsCopySupport.h
>+#ifndef nsCopySupport_h_
>+#define nsCopySupport_h_

I think our convention is two underscores after the 'h' there.

>Index: content/base/public/nsIImageLoadingContent.idl

>+   * Otherwise, returns the URI that was last attempted to load,
>+   * or null if no url was attempted to load yet.

  "Otherwise, returns the last URI that this content tried to load, or
   null if there haven't been any such attempts."

>Index: content/base/src/nsCopySupport.cpp

Note bug 197375.  With this patch and that one, nsCopySupport may well not
depend on layout at all...

I assume you're getting someone to move the file in CVS so as to preserve the
history?  Please coordinate with smontagu so he checks into the right one,
unless he checks in before you start doing your stuff.

>Index: content/base/src/nsImageLoadingContent.cpp

>+#ifdef DEBUG_chb
>+#endif

/* DEBUG_chb */, right? 

>+nsImageLoadingContent::GetCurrentURI(nsIURI** aURI) {

Put the '{' on the next line, per style in the file.

>+  // If this succeeded and we affected the current request, then we don't need
>+  // the URI anymore; release it to save memory.

I think "to save memory" can be dropped here... ;)

>+  if ((&req == &mCurrentRequest) && NS_SUCCEEDED(rv)) {
>+    mCurrentURI = nsnull;
>+  }

Just testing |if (mCurrentRequest)| should be enough, no?  If we got this far
_and_ we have an mCurrentRequest, we shouldn't need the mCurrentURI.

>Index: modules/libpref/src/init/all.js

This seems to have diluted the purity of the patch unnecessarily.  Didn't you
land this part already?  ;)

r+sr=bzbarsky with above comments addressed.
Attachment #148986 - Flags: superreview?(bzbarsky)
Attachment #148986 - Flags: superreview+
Attachment #148986 - Flags: review?(bzbarsky)
Attachment #148986 - Flags: review+
Comment on attachment 149081 [details] [diff] [review]
xpfe patch

It's a pity that a bug to clean up nsContextMenu.js wouldn't make a good first
bug :-(
Attachment #149081 - Flags: review?(neil.parkwaycc.co.uk) → review+
Oh, and please do make sure you file bugs on tbird and firefox to fix their
context menu code up too...
Comment on attachment 149081 [details] [diff] [review]
xpfe patch

I'll file those bugs once I check this in
Attachment #149081 - Flags: superreview?(bzbarsky)
Comment on attachment 149081 [details] [diff] [review]
xpfe patch

sr=bzbarsky; file followups on making imagemaps work too?
Attachment #149081 - Flags: superreview?(bzbarsky) → superreview+
(In reply to comment #17)
> (From update of attachment 149081 [details] [diff] [review])
> sr=bzbarsky; file followups on making imagemaps work too?

I filed that followup bug already ;) (bug 60561 - which is a duplicate of bug 33583)
Blocks: 240903
Blocks: 244859
Attached patch final patchSplinter Review
leaf copied the file in cvs

This is a final patch, applies against trunk, and addresses bz's comments
Attachment #148986 - Attachment is obsolete: true
Attachment #148987 - Attachment is obsolete: true
Attachment #149081 - Attachment is obsolete: true
filed Bug 245661 and Bug 245660 for thunderbird and firefox
checked in
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Target Milestone: mozilla1.8beta → mozilla1.8alpha2
This looks like it cause a ~0.5% pageload time regression on btek.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: