Don't assume "text/" MIME types can be opened internally

Previously, dragging a Python script ("text/x-python-script") would
trigger an open/save dialog (at least on OS X), since Firefox was under
the impression that it couldn't read the file.
This commit is contained in:
Dan Stillman 2012-08-02 09:08:49 -04:00
parent 7dbe6d728a
commit 77f422039f
2 changed files with 5 additions and 24 deletions

View file

@ -89,6 +89,7 @@ Zotero.Attachments = new function(){
var mimeType = Zotero.MIME.getMIMETypeFromFile(newFile); var mimeType = Zotero.MIME.getMIMETypeFromFile(newFile);
attachmentItem.attachmentMIMEType = mimeType; attachmentItem.attachmentMIMEType = mimeType;
attachmentItem.attachmentPath = this.getPath(newFile, this.LINK_MODE_IMPORTED_FILE); attachmentItem.attachmentPath = this.getPath(newFile, this.LINK_MODE_IMPORTED_FILE);
attachmentItem.save(); attachmentItem.save();
@ -1325,8 +1326,7 @@ Zotero.Attachments = new function(){
} }
var ext = Zotero.File.getExtension(file); var ext = Zotero.File.getExtension(file);
if (mimeType.substr(0, 5)!='text/' || if (!Zotero.MIME.hasInternalHandler(mimeType, ext)) {
!Zotero.MIME.hasInternalHandler(mimeType, ext)){
return; return;
} }

View file

@ -25,7 +25,6 @@
Zotero.MIME = new function(){ Zotero.MIME = new function(){
this.isTextType = isTextType; this.isTextType = isTextType;
this.isExternalTextExtension = isExternalTextExtension;
this.getPrimaryExtension = getPrimaryExtension; this.getPrimaryExtension = getPrimaryExtension;
this.sniffForMIMEType = sniffForMIMEType; this.sniffForMIMEType = sniffForMIMEType;
this.sniffForBinary = sniffForBinary; this.sniffForBinary = sniffForBinary;
@ -92,14 +91,6 @@ Zotero.MIME = new function(){
} }
/*
* Check if file extension should be forced to open externally
*/
function isExternalTextExtension(ext){
return typeof _externalTextExtensions[ext] != 'undefined';
}
/* /*
* Our own wrapper around the MIME service's getPrimaryExtension() that * Our own wrapper around the MIME service's getPrimaryExtension() that
* works a little better * works a little better
@ -326,20 +317,11 @@ Zotero.MIME = new function(){
* do what we need * do what we need
*/ */
function hasNativeHandler(mimeType, ext) { function hasNativeHandler(mimeType, ext) {
if (mimeType.match(/^text\//)) {
if (isExternalTextExtension(ext)){
Zotero.debug(mimeType + " file has extension '" + ext + "' that should be handled externally");
return false;
}
return true;
}
if (_nativeMIMETypes[mimeType]){ if (_nativeMIMETypes[mimeType]){
Zotero.debug('MIME type ' + mimeType + ' can be handled natively'); Zotero.debug('MIME type ' + mimeType + ' can be handled natively');
return true; return true;
} }
return false;
return null;
} }
@ -350,9 +332,8 @@ Zotero.MIME = new function(){
* Similar to hasNativeHandler() but also includes plugins * Similar to hasNativeHandler() but also includes plugins
*/ */
function hasInternalHandler(mimeType, ext) { function hasInternalHandler(mimeType, ext) {
var isNative = hasNativeHandler(mimeType, ext); if (hasNativeHandler(mimeType, ext)) {
if (isNative !== null) { return true;
return isNative;
} }
if(mimeType === "application/pdf" if(mimeType === "application/pdf"