Closed Bug 231886 Opened 21 years ago Closed 21 years ago

Allow extensions to add extension->type mappings

Categories

(Core Graveyard :: File Handling, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla1.7alpha

People

(Reporter: Biesinger, Assigned: Biesinger)

References

Details

Attachments

(1 file)

(especially useful for image decoders)

It would be nice if there was a way for extensions to add a extension->mimetype
mapping, so that mozilla can find the right content type for local files.

I have a patch that allows adding an entry in the mimetype-mapping category,
name is the extension, value the mime type.

would be used by getTypeFromExtension when the other methods fail.
No longer blocks: 41333
Attached patch patchSplinter Review
note that this makes GetTypeFromExtension return NS_ERROR_NOT_AVAILABLE in all
cases when it can't find a mapping.
Attachment #139696 - Flags: review?(bz-vacation)
Status: NEW → ASSIGNED
OS: Linux → All
Hardware: PC → All
Target Milestone: --- → mozilla1.7alpha
Comment on attachment 139696 [details] [diff] [review]
patch

r=bzbarsky if you rename the category to "ext-to-type-mapping".

I wish we could make plugins use this so we don't have to special-case them
earlier in this code...
Attachment #139696 - Flags: review?(bz-vacation) → review+
Comment on attachment 139696 [details] [diff] [review]
patch

hm, that sounds like a good idea... I'll file a new bug to make plugins use
this code, once I checked this in
Attachment #139696 - Flags: superreview?(darin)
Comment on attachment 139696 [details] [diff] [review]
patch

>Index: nsExternalHelperAppService.cpp

>+  if (NS_SUCCEEDED(rv)) {
>+    return info->GetMIMEType(aContentType);
>+  }
>+  // Let's see if an extension added something
>+  nsCOMPtr<nsICategoryManager> catMan(do_GetService("@mozilla.org/categorymanager;1"));
>+  if (!catMan)
>+    return NS_ERROR_NOT_AVAILABLE;
> 
>+  return catMan->GetCategoryEntry("mimetype-mapping", aFileExt, aContentType);
> }

how about writing this like so:

  ...
    if (NS_SUCCEEDED(rv))
      rv = info->GetMIMEType(aContentType);
    else {
      // Let's see if an extension added something
      nsCOMPtr<nsICategoryManager>
catMan(do_GetService("@mozilla.org/categorymanager;1"));
      if (!catMan)
	rv = NS_ERROR_NOT_AVAILABLE;
      else
	rv = catMan->GetCategoryEntry("mimetype-mapping", aFileExt,
aContentType);
    }
    return rv;
  }

i think this is plenty clear, and it'll help GCC reduce codesize.  you can do
what
you like with the braces... the file doesn't seem to be very consistent :-/

sr=darin
Attachment #139696 - Flags: superreview?(darin) → superreview+
hmm.. should the category name use some sort of namespace?  nsICategoryManager
is frozen and technically embeddors can come up with whatever category names
they like.  i don't think we have much of a convention in our source code, but
it seems like we should.  <== this probably deserves another bug
ok, patch checked in with the changes from comment 2 and comment 4 done.

Bug 233289 filed for the plugin question from comment 2.
Bug 233290 filed re comment 5.
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
The description claims that this mapping is to help find the right content type
for local files-- should it also work for files served up remotely without a
MIME type?

If not, is there a way to provide default mappings for those?
Or perhaps what I'm running up against is the situation where something is
getting served up with MIME type 'text' because of the Apache default settings
and Moz is detecting that it's not really text and kicking it back to the user.

I'm guessing that process doesn't check against this list?  Is there some way
for an extension to get involved in that process and claim the file?
yes, files sent without a mime type should also be covered by this.

content sent as text/plain but sniffed as non-text will never get handled by the
browser.
Blocks: 508030
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: