Closed Bug 325177 Opened 19 years ago Closed 18 years ago

Make the unknowndecoder implement nsIContentSniffer

Categories

(Core :: Networking, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: Biesinger, Assigned: Biesinger)

References

Details

(Keywords: fixed1.8.1)

Attachments

(2 files, 4 obsolete files)

...and make basechannel use that interface to get a content type.

this will be necessary once basechannel implements stuff like nsIEncodedChannel, because applyDecoding can only be set during onStartRequest, and the stream converter in the middle has its own concept of onStartRequest.
Attached patch patch (obsolete) — Splinter Review
had to change nsIInputStreamPump for this... see comments in the patch as for why.
Attachment #210099 - Flags: review?(darin)
Status: NEW → ASSIGNED
Priority: -- → P3
Target Milestone: --- → mozilla1.9alpha
Attached patch patch (obsolete) — Splinter Review
er, this time, the right file
Attachment #210099 - Attachment is obsolete: true
Attachment #210101 - Flags: review?(darin)
Attachment #210099 - Flags: review?(darin)
Comment on attachment 210101 [details] [diff] [review]
patch

Perhaps nsIInputStreamPump::stream should just return nsIAsyncInputStream.  The comments on nsIInputStreamPump talk about nsIAsyncInputStream, and  that's what mAsyncStream implements, so we might as well reveal that here.

Instead of hard-coding 1024, you might want to use the #define from nsNetSegmentUtils.h (NET_DEFAULT_SEGMENT_SIZE).
Attachment #210101 - Flags: review?(darin) → review+
Attached patch with those changes (obsolete) — Splinter Review
Attachment #210101 - Attachment is obsolete: true
Attachment #210284 - Flags: superreview?(bzbarsky)
Comment on attachment 210284 [details] [diff] [review]
with those changes

>Index: netwerk/base/public/nsIContentSniffer.idl

>  * Content sniffer interface. Components implementing this interface can
>  * determine a MIME type from a chunk of bytes.

Should this mention whether aRequest can be used for the sniffing?

>+   * @param aRequest The request where this data came from. May be null.

Or would that be better to mention here?

In particular, should we talk about whether aData should "take precedence" over aRequest, whatever that means?  Or at least document that it's undefined?

>Index: netwerk/base/public/nsIInputStreamPump.idl

>+    readonly attribute nsIAsyncInputStream stream;

This should probably document that callers are not allowed to actually read data from the stream, right?  Or otherwise change the state of the stream (e.g. seek, setEOF, etc)?  In general, exposing the actual async stream here worries me a little bit; would it be safer to just return a shim object here that would disallow stream state changes on the underlying stream while allowing what you want?  Or are we ok with just documenting this well?

>Index: netwerk/streamconv/converters/nsUnknownDecoder.cpp
>+// nsIStreamListener methods...

You mean nsIContentSniffer methods, right?

sr=bzbarsky with those nits fixed
Attachment #210284 - Flags: superreview?(bzbarsky) → superreview+
Perhaps what we really want is a way to peek at the next chunk of data to be pumped.
mmm... we could make the pump implement nsIInputStream maybe?
(and implement it in a way that doesn't consume the data)
Hmm... maybe a better answer is to expose a private interface that is used internally by Necko to communicate this detail.  We could even have the nsBaseChannel QI the nsIInputStreamPump to "nsInputStreamPump" (e.g., make nsInputStreamPump::QueryInterface return a pointer to nsInputStreamPump when aIID equals NS_INPUTSTREAMPUMP_CID).  Then, we could put a friendly method on nsInputStreamPump that reveals the first chunk of data.

  class nsInputStreamPump : ... {
  public:
    ...
    typedef void (*PeekSegmentFun)(void *closure, const char *buf,
                                   PRUint32 bufLen);
    void PeekStream(PeekSegmentFun callback, void *closure);
  };

We could move this construct out onto an actual interface, but I'm not sure that that is really worth it since it would be non-scriptable.
hm... should baseChannel then maybe also create the pump using "new nsInputStreamPump" so that it can be sure that that function will be available? (It'd also avoid the qi'ing)
Yes, that sounds like a fine idea.
Attached patch the new approach (obsolete) — Splinter Review
Attachment #210284 - Attachment is obsolete: true
Attachment #211626 - Flags: review?(darin)
So how would someone implementing a channel class (in an extension, say) do something similar?
I'd like to fix that by exposing basechannel to extensions and JS.
Sounds like a plan!
No longer blocks: 324985
Comment on attachment 211626 [details] [diff] [review]
the new approach

>Index: netwerk/base/src/nsBaseChannel.cpp

> #include "nsIChannelEventSink.h"
> #include "nsIStreamConverterService.h"
> 
>+#include "nsIContentSniffer.h"

nit: please kill the newline here.


>+static void
>+CallTypeSniffers(void *aClosure, const PRUint8 *aData, PRUint32 aCount)
>+{
>+  nsIChannel* chan = NS_STATIC_CAST(nsIChannel*, aClosure);
>+
>+  nsCOMPtr<nsIContentSniffer> sniffer(do_CreateInstance(NS_GENERIC_CONTENT_SNIFFER));

nit: please break lines at 80 chars.

nit: use a consistent style for the "*" ... this code uses "nsIChannel *chan"


>+#ifdef DEBUG_chb
>+  printf("### Detecting content type %s\n", detected.get());
>+#endif

nit: prefer DEBUG_BASECHANNEL instead of user specific debug output.
I would even prefer no #ifdef's scatter through the code.  Maybe just
declare DEBUG_PRINTF as a macro at the top of the file.


>Index: netwerk/base/src/nsInputStreamPump.cpp

>+CallPeekFunc(nsIInputStream *aInStream, void *aClosure,
...
>+}
>+
>+

nit: kill extra newline


r=darin
Attachment #211626 - Flags: review?(darin) → review+
Attached patch nits fixedSplinter Review
I just removed the debug printfs
Attachment #211626 - Attachment is obsolete: true
Attachment #211754 - Flags: superreview?(bzbarsky)
Comment on attachment 211754 [details] [diff] [review]
nits fixed

>diff --git browser/components/bookmarks/content/bookmarks.js browser/components/bookmarks/content/bookmarks.js

Hey, I'm all cool with you using git, but please do have more context and some equiv of the -p diff option, ok?  ;)

Code itself's ok.  sr=bzbarsky
Attachment #211754 - Flags: superreview?(bzbarsky) → superreview+
Comment on attachment 211754 [details] [diff] [review]
nits fixed

er, this does use the -p option (which is in fact the default with git)

sorry about the context, will fix.
fixed on trunk. leaving open because I want to do a branch version of this, for bug 324985
Attached patch branch patchSplinter Review
I'm using nsIContentSniffer_MOZILLA_1_8_BRANCH for the interface name, to make it clear that it's branch-only
Attachment #212777 - Flags: approval-branch-1.8.1?(darin)
> I'm using nsIContentSniffer_MOZILLA_1_8_BRANCH for the interface name, to make
> it clear that it's branch-only

I don't understand.  The interface is exactly the same on the trunk.
yeah, true. But I can't name it nsIContentSniffer on branch because it exists there already. I don't really want to name it nsIContentSniffer2 because that'd sound like trunk is behind branch.
so yeah, "branch-only" was a bad word to use.
OK, my apologies for being dense.  I forgot that we were changing this interface.  We should get consensus on naming convention for situations like this.  Can you post a question to a mailing list or at least to a wide enough audience to make sure that everyone is on the same page with this solution?
ok, sent to bonecho + m.d.general
Comment on attachment 212777 [details] [diff] [review]
branch patch

a=darin given that there is precidence for the MOZILLA_1_8_BRANCH interface name suffix.  If your posting results in any changes to this policy, then we'd want to make a blanket change, and that could include changing this post-facto.
Attachment #212777 - Flags: approval-branch-1.8.1?(darin) → approval-branch-1.8.1+
fixed on branch.
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Keywords: fixed1.8.1
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: