Commit c408431d authored by alice.liu@apple.com's avatar alice.liu@apple.com

WebCore:

2008-12-10  Alice Liu  <alice.liu@apple.com>

        fixed https://bugs.webkit.org/show_bug.cgi?id=20685

        Reviewed by Darin Adler.

        Manual test case is manual-tests/drag-image-to-desktop.html

        Added new files to projects
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:

        * page/DragController.cpp:
        (WebCore::DragController::startDrag):
        * platform/MIMETypeRegistry.cpp:
        (WebCore::initializeSupportedImageMIMETypes):
        (WebCore::initializeSupportedImageMIMETypesForEncoding):

        These changes add a method to obtain the extension for an image
        * platform/graphics/BitmapImage.cpp:
        (WebCore::BitmapImage::filenameExtension):
        * platform/graphics/BitmapImage.h:
        * platform/graphics/Image.h:
        (WebCore::Image::filenameExtension):
        * platform/graphics/ImageSource.h:
        * platform/graphics/cairo/ImageSourceCairo.cpp:
        (WebCore::ImageSource::filenameExtension):
        * platform/graphics/cg/ImageSourceCG.cpp:
        (WebCore::ImageSource::filenameExtension):

        These changes added a utility that returns the preferred extension for a UTI
        * platform/graphics/cg/ImageSourceCG.h: Added.
        * platform/graphics/cg/ImageSourceCGMac.mm: Added.
        (WebCore::MIMETypeForImageSourceType):
        (WebCore::preferredExtensionForImageSourceType):
        * platform/graphics/cg/ImageSourceCGWin.cpp: Added.
        (WebCore::MIMETypeForImageSourceType):
        (WebCore::preferredExtensionForImageSourceType):

        * platform/mac/MIMETypeRegistryMac.mm:
        moved getMIMETypeForUTI to ImageSourceCGMac.mm

        Ask image for its file extension instead of relying on MIME type and file path
        * platform/win/ClipboardWin.cpp:
        (WebCore::createGlobalImageFileDescriptor):

        Remove extraneous code from getPreferredExtensionForMIMEType.
        Also moved getMIMETypeForUTI to ImageSourceCGWin.cpp
        * platform/win/MIMETypeRegistryWin.cpp:
        (WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType):

WebKit/mac:

2008-12-10  Alice Liu  <alice.liu@apple.com>

        fixed https://bugs.webkit.org/show_bug.cgi?id=20685

        Reviewed by Darin Adler.

        * Misc/WebNSPasteboardExtras.mm:
        Ask image for its file extension instead of falling back on MIME type and file path.
        Also moved this code to before setting the pasteboard data so as not to set any if
        no extension can be determined.
        (-[NSPasteboard _web_declareAndWriteDragImageForElement:URL:title:archive:source:]):

        * WebView/WebHTMLView.mm:
        Fixed a separate but related long-standing bug of how the filename for the promised
        drag data is determined by asking the image for a proper file extension. 
        (-[WebHTMLView namesOfPromisedFilesDroppedAtDestination:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@39185 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 678c4cd1
2008-12-10 Alice Liu <alice.liu@apple.com>
fixed https://bugs.webkit.org/show_bug.cgi?id=20685
Reviewed by Darin Adler.
Manual test case is manual-tests/drag-image-to-desktop.html
Added new files to projects
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* page/DragController.cpp:
(WebCore::DragController::startDrag):
* platform/MIMETypeRegistry.cpp:
(WebCore::initializeSupportedImageMIMETypes):
(WebCore::initializeSupportedImageMIMETypesForEncoding):
These changes add a method to obtain the extension for an image
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::filenameExtension):
* platform/graphics/BitmapImage.h:
* platform/graphics/Image.h:
(WebCore::Image::filenameExtension):
* platform/graphics/ImageSource.h:
* platform/graphics/cairo/ImageSourceCairo.cpp:
(WebCore::ImageSource::filenameExtension):
* platform/graphics/cg/ImageSourceCG.cpp:
(WebCore::ImageSource::filenameExtension):
These changes added a utility that returns the preferred extension for a UTI
* platform/graphics/cg/ImageSourceCG.h: Added.
* platform/graphics/cg/ImageSourceCGMac.mm: Added.
(WebCore::MIMETypeForImageSourceType):
(WebCore::preferredExtensionForImageSourceType):
* platform/graphics/cg/ImageSourceCGWin.cpp: Added.
(WebCore::MIMETypeForImageSourceType):
(WebCore::preferredExtensionForImageSourceType):
* platform/mac/MIMETypeRegistryMac.mm:
moved getMIMETypeForUTI to ImageSourceCGMac.mm
Ask image for its file extension instead of relying on MIME type and file path
* platform/win/ClipboardWin.cpp:
(WebCore::createGlobalImageFileDescriptor):
Remove extraneous code from getPreferredExtensionForMIMEType.
Also moved getMIMETypeForUTI to ImageSourceCGWin.cpp
* platform/win/MIMETypeRegistryWin.cpp:
(WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType):
2008-12-10 Simon Fraser <simon.fraser@apple.com>
Potential build fix. The forward declaration of FloatPoint should
<?xml version="1.0" encoding="Windows-1252"?>
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
......@@ -4843,6 +4843,46 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\platform\graphics\cg\ImageSourceCG.h"
>
<FileConfiguration
Name="Debug_Cairo|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Cairo|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\platform\graphics\cg\ImageSourceCGWin.cpp"
>
<FileConfiguration
Name="Debug_Cairo|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Cairo|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\platform\graphics\cg\IntPointCG.cpp"
>
......
......@@ -583,6 +583,8 @@
4B3043C90AE0371D00A82647 /* SoundMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B3043C80AE0371D00A82647 /* SoundMac.mm */; };
4B3043CC0AE0373B00A82647 /* Editor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B3043CA0AE0373B00A82647 /* Editor.cpp */; };
4B3043CD0AE0373B00A82647 /* Editor.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3043CB0AE0373B00A82647 /* Editor.h */; settings = {ATTRIBUTES = (Private, ); }; };
4B3480930EEF50D400AC1B41 /* ImageSourceCGMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B3480910EEF50D400AC1B41 /* ImageSourceCGMac.mm */; };
4B3480940EEF50D400AC1B41 /* ImageSourceCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3480920EEF50D400AC1B41 /* ImageSourceCG.h */; };
4B5B7C8E0D945CFA00DDF3AB /* AccessibilityObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B5B7C8D0D945CFA00DDF3AB /* AccessibilityObject.cpp */; };
4B6FA6F40C39E48C00087011 /* SmartReplace.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6FA6F20C39E48C00087011 /* SmartReplace.h */; settings = {ATTRIBUTES = (Private, ); }; };
4B6FA6F50C39E48C00087011 /* SmartReplace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6FA6F30C39E48C00087011 /* SmartReplace.cpp */; };
......@@ -5410,6 +5412,8 @@
4B3043C80AE0371D00A82647 /* SoundMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = SoundMac.mm; sourceTree = "<group>"; };
4B3043CA0AE0373B00A82647 /* Editor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Editor.cpp; sourceTree = "<group>"; };
4B3043CB0AE0373B00A82647 /* Editor.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Editor.h; sourceTree = "<group>"; };
4B3480910EEF50D400AC1B41 /* ImageSourceCGMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ImageSourceCGMac.mm; sourceTree = "<group>"; };
4B3480920EEF50D400AC1B41 /* ImageSourceCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageSourceCG.h; sourceTree = "<group>"; };
4B5B7C8D0D945CFA00DDF3AB /* AccessibilityObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityObject.cpp; sourceTree = "<group>"; };
4B6FA6F20C39E48C00087011 /* SmartReplace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SmartReplace.h; sourceTree = "<group>"; };
4B6FA6F30C39E48C00087011 /* SmartReplace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SmartReplace.cpp; sourceTree = "<group>"; };
......@@ -12748,7 +12752,9 @@
A80D67070E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h */,
B2A10B930B3818D700099AA4 /* ImageBufferCG.cpp */,
B27535300B053814002CE64F /* ImageCG.cpp */,
4B3480920EEF50D400AC1B41 /* ImageSourceCG.h */,
B27535310B053814002CE64F /* ImageSourceCG.cpp */,
4B3480910EEF50D400AC1B41 /* ImageSourceCGMac.mm */,
B27535320B053814002CE64F /* IntPointCG.cpp */,
B27535330B053814002CE64F /* IntRectCG.cpp */,
B27535340B053814002CE64F /* IntSizeCG.cpp */,
......@@ -16396,6 +16402,7 @@
1A569D230D7E2B82007C3983 /* runtime_object.h in Headers */,
1A569D250D7E2B82007C3983 /* runtime_root.h in Headers */,
93309E1E099E64920056E581 /* visible_units.h in Headers */,
4B3480940EEF50D400AC1B41 /* ImageSourceCG.h in Headers */,
E12719C70EEEC16800F61213 /* NavigatorBase.h in Headers */,
E1271A0B0EEEC77A00F61213 /* WorkerNavigator.h in Headers */,
E1271A580EEECDE400F61213 /* JSWorkerNavigator.h in Headers */,
......@@ -18340,6 +18347,7 @@
1A569D220D7E2B82007C3983 /* runtime_object.cpp in Sources */,
1A569D240D7E2B82007C3983 /* runtime_root.cpp in Sources */,
93309E1D099E64920056E581 /* visible_units.cpp in Sources */,
4B3480930EEF50D400AC1B41 /* ImageSourceCGMac.mm in Sources */,
E12719CA0EEEC21300F61213 /* NavigatorBase.cpp in Sources */,
E1271A140EEEC80400F61213 /* WorkerNavigator.cpp in Sources */,
E1271A590EEECDE400F61213 /* JSWorkerNavigator.cpp in Sources */,
......@@ -629,9 +629,12 @@ bool DragController::startDrag(Frame* src, Clipboard* clipboard, DragOperation s
Node* node = dragSource.innerNonSharedNode();
if (!imageURL.isEmpty() && node && node->isElementNode()
&& getImage(static_cast<Element*>(node))
Image* image = getImage(static_cast<Element*>(node));
if (!imageURL.isEmpty() && node && node->isElementNode() && image
&& (m_dragSourceAction & DragSourceActionImage)) {
// We shouldn't be starting a drag for an image that can't provide an extension.
// This is an early detection for problems encountered later upon drop.
ASSERT(!image->filenameExtension().isEmpty());
Element* element = static_cast<Element*>(node);
if (!clipboard->hasData()) {
m_draggingImageURL = imageURL;
......
......@@ -35,6 +35,7 @@
#include <wtf/HashSet.h>
#if PLATFORM(CG)
#include "ImageSourceCG.h"
#include <ApplicationServices/ApplicationServices.h>
#include <wtf/RetainPtr.h>
#endif
......@@ -52,10 +53,6 @@ static HashSet<String>* supportedJavaScriptMIMETypes;
static HashSet<String>* supportedNonImageMIMETypes;
static HashSet<String>* supportedMediaMIMETypes;
#if PLATFORM(CG)
extern String getMIMETypeForUTI(const String& uti);
#endif
static void initializeSupportedImageMIMETypes()
{
#if PLATFORM(CG)
......@@ -63,7 +60,7 @@ static void initializeSupportedImageMIMETypes()
CFIndex count = CFArrayGetCount(supportedTypes.get());
for (CFIndex i = 0; i < count; i++) {
RetainPtr<CFStringRef> supportedType(AdoptCF, reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i)));
String mimeType = getMIMETypeForUTI(supportedType.get());
String mimeType = MIMETypeForImageSourceType(supportedType.get());
if (!mimeType.isEmpty()) {
supportedImageMIMETypes->add(mimeType);
supportedImageResourceMIMETypes->add(mimeType);
......@@ -132,7 +129,7 @@ static void initializeSupportedImageMIMETypesForEncoding()
CFIndex count = CFArrayGetCount(supportedTypes.get());
for (CFIndex i = 0; i < count; i++) {
RetainPtr<CFStringRef> supportedType(AdoptCF, reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i)));
String mimeType = getMIMETypeForUTI(supportedType.get());
String mimeType = MIMETypeForImageSourceType(supportedType.get());
if (!mimeType.isEmpty())
supportedImageMIMETypesForEncoding->add(mimeType);
}
......
......@@ -177,6 +177,11 @@ bool BitmapImage::dataChanged(bool allDataReceived)
return isSizeAvailable();
}
String BitmapImage::filenameExtension() const
{
return m_source.filenameExtension();
}
size_t BitmapImage::frameCount()
{
if (!m_haveFrameCount) {
......
......@@ -113,6 +113,7 @@ public:
IntSize currentFrameSize() const;
virtual bool dataChanged(bool allDataReceived);
virtual String filenameExtension() const;
// It may look unusual that there is no start animation call as public API. This is because
// we start and stop animating lazily. Animation begins whenever someone draws the image. It will
......
......@@ -107,6 +107,8 @@ public:
bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived);
virtual bool dataChanged(bool allDataReceived) { return false; }
virtual String filenameExtension() const { return String(); } // null string if unknown
virtual void destroyDecodedData(bool incremental = false, bool preserveNearbyFrames = false) = 0;
virtual unsigned decodedSize() const = 0;
......
......@@ -51,6 +51,7 @@ namespace WebCore {
class IntSize;
class SharedBuffer;
class String;
#if PLATFORM(WX)
class ImageDecoder;
......@@ -87,6 +88,7 @@ public:
bool initialized() const;
void setData(SharedBuffer* data, bool allDataReceived);
String filenameExtension() const;
bool isSizeAvailable();
IntSize size() const;
......
......@@ -126,6 +126,12 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
m_decoder->setData(data, allDataReceived);
}
String ImageSource::filenameExtension() const
{
// not implemented
return String();
}
bool ImageSource::isSizeAvailable()
{
if (!m_decoder)
......
......@@ -27,8 +27,10 @@
#include "ImageSource.h"
#if PLATFORM(CG)
#include "ImageSourceCG.h"
#include "IntSize.h"
#include "MIMETypeRegistry.h"
#include "SharedBuffer.h"
#include <ApplicationServices/ApplicationServices.h>
......@@ -89,6 +91,14 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
CFRelease(cfData);
}
String ImageSource::filenameExtension() const
{
if (!m_decoder)
return String();
CFStringRef imageSourceType = CGImageSourceGetType(m_decoder);
return WebCore::preferredExtensionForImageSourceType(imageSourceType);
}
bool ImageSource::isSizeAvailable()
{
bool result = false;
......
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ImageSourceCG_h
#define ImageSourceCG_h
#include "ImageSource.h"
namespace WebCore {
class String;
String preferredExtensionForImageSourceType(const String& type);
String MIMETypeForImageSourceType(const String& type);
}
#endif // ImageSourceCG_h
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "ImageSourceCG.h"
#import "PlatformString.h"
#import "wtf/RetainPtr.h"
namespace WebCore {
String MIMETypeForImageSourceType(const String& uti)
{
RetainPtr<CFStringRef> utiref(AdoptCF, uti.createCFString());
RetainPtr<CFStringRef> mime(AdoptCF, UTTypeCopyPreferredTagWithClass(utiref.get(), kUTTagClassMIMEType));
return mime.get();
}
String preferredExtensionForImageSourceType(const String& uti)
{
RetainPtr<CFStringRef> type(AdoptCF, uti.createCFString());
return UTTypeCopyPreferredTagWithClass(type.get(), kUTTagClassFilenameExtension);
}
} // namespace WebCore
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ImageSourceCG.h"
#include "StdLibExtras.h"
#include "StringHash.h"
#include <wtf/HashMap.h>
namespace WebCore {
String MIMETypeForImageSourceType(const String& type)
{
String mimeType;
// FIXME: This approach of taking a UTI like public.type and giving back
// a MIME type like image/type will work for common image UTIs like jpeg,
// png, tiff, gif but won't work for UTIs like: public.jpeg-2000,
// public.xbitmap-image, com.apple.quicktime-image, and others.
if (int dotLocation = type.reverseFind('.'))
mimeType = "image/" + type.substring(dotLocation + 1);
return mimeType;
}
String preferredExtensionForImageSourceType(const String& type)
{
if (type.isEmpty())
return String();
typedef HashMap<String, String> StringMap;
DEFINE_STATIC_LOCAL(StringMap, UTIMap, ());
if (UTIMap.isEmpty()) {
UTIMap.add("public.html", "html");
UTIMap.add("public.jpeg", "jpeg");
UTIMap.add("public.jpeg-2000", "jp2");
UTIMap.add("public.plain-text", "txt");
UTIMap.add("public.png", "png");
UTIMap.add("public.tiff", "tiff");
UTIMap.add("public.xbitmap-image", "xbm");
UTIMap.add("public.xml", "xml");
UTIMap.add("com.adobe.illustrator.ai-image", "ai");
UTIMap.add("com.adobe.pdf", "pdf");
UTIMap.add("com.adobe.photoshop-image", "psd");
UTIMap.add("com.adobe.postscript", "ps");
UTIMap.add("com.apple.icns", "icns");
UTIMap.add("com.apple.macpaint-image", "pntg");
UTIMap.add("com.apple.pict", "pict");
UTIMap.add("com.apple.quicktime-image", "qtif");
UTIMap.add("com.apple.webarchive", "webarchive");
UTIMap.add("com.compuserve.gif", "gif");
UTIMap.add("com.ilm.openexr-image", "exr");
UTIMap.add("com.kodak.flashpix-image", "fpx");
UTIMap.add("com.microsoft.bmp", "bmp");
UTIMap.add("com.microsoft.ico", "ico");
UTIMap.add("com.netscape.javascript-source", "js");
UTIMap.add("com.sgi.sgi-image", "sgi");
UTIMap.add("com.truevision.tga-image", "tga");
}
return UTIMap.get(type);
}
} // namespace WebCore
......@@ -31,16 +31,6 @@
namespace WebCore
{
String getMIMETypeForUTI(const String & uti)
{
CFStringRef utiref = uti.createCFString();
CFStringRef mime = UTTypeCopyPreferredTagWithClass(utiref, kUTTagClassMIMEType);
String mimeType = mime;
if (mime)
CFRelease(mime);
CFRelease(utiref);
return mimeType;
}
String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
{
......
......@@ -333,10 +333,15 @@ static HGLOBAL createGlobalImageFileDescriptor(const String& url, const String&
fgd->fgd[0].dwFlags = FD_FILESIZE;
fgd->fgd[0].nFileSizeLow = image->image()->data()->size();
String extension(".");
extension += WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType(image->response().mimeType());
const String& preferredTitle = title.isEmpty() ? image->response().suggestedFilename() : title;
fsPath = filesystemPathFromUrlOrTitle(url, preferredTitle, extension.length() ? (TCHAR*)extension.charactersWithNullTermination() : 0, false);
String extension = image->image()->filenameExtension();
if (extension.isEmpty()) {
// Do not continue processing in the rare and unusual case where a decoded image is not able
// to provide a filename extension. Something tricky (like a bait-n-switch) is going on
return 0;
}
extension.insert(".", 0);
fsPath = filesystemPathFromUrlOrTitle(url, preferredTitle, (TCHAR*)extension.charactersWithNullTermination(), false);
if (fsPath.length() <= 0) {
GlobalUnlock(memObj);
......
......@@ -32,16 +32,6 @@
namespace WebCore
{
String getMIMETypeForUTI(const String & uti)
{
String mimeType;
// FIXME: This is an ugly hack: public.type -> image/type mimetype
if (int dotLocation = uti.reverseFind('.')) {
mimeType = String("image/")+uti.substring(dotLocation + 1);
}
return mimeType;
}
static String mimeTypeForExtension(const String& extension)
{
String ext = "." + extension;
......@@ -59,14 +49,6 @@ static String mimeTypeForExtension(const String& extension)
String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type)
{
String mimeType;
int semiColonPos = type.find(';');
if (semiColonPos < 0)
mimeType = type;
else
mimeType = type.substring(0, semiColonPos);
String path = "MIME\\Database\\Content Type\\" + type;
WCHAR extStr[MAX_PATH];
DWORD extStrLen = sizeof(extStr);
......
2008-12-10 Alice Liu <alice.liu@apple.com>
fixed https://bugs.webkit.org/show_bug.cgi?id=20685
Reviewed by Darin Adler.
* Misc/WebNSPasteboardExtras.mm:
Ask image for its file extension instead of falling back on MIME type and file path.
Also moved this code to before setting the pasteboard data so as not to set any if
no extension can be determined.
(-[NSPasteboard _web_declareAndWriteDragImageForElement:URL:title:archive:source:]):
* WebView/WebHTMLView.mm:
Fixed a separate but related long-standing bug of how the filename for the promised
drag data is determined by asking the image for a proper file extension.
(-[WebHTMLView namesOfPromisedFilesDroppedAtDestination:]):
2008-12-09 Anders Carlsson <andersca@apple.com>
Reviewed by Darin Adler.
......
......@@ -263,18 +263,23 @@ CachedImage* imageFromElement(DOMElement *domElement) {
{
ASSERT(self == [NSPasteboard pasteboardWithName:NSDragPboard]);
NSString *extension = @"";
if (RenderObject* renderer = core(element)->renderer()) {
if (renderer->isImage()) {
if (CachedImage* image = static_cast<RenderImage*>(renderer)->cachedImage()) {
extension = image->image()->filenameExtension();
if (![extension length])
return 0;
}
}
}
NSMutableArray *types = [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil];
[types addObjectsFromArray:[NSPasteboard _web_writableTypesForImageIncludingArchive:(archive != nil)]];
[self declareTypes:types owner:source];
[self _web_writeImage:nil element:element URL:URL title:title archive:archive types:types source:source];
[types release];
NSString *extension = @"";
if (RenderObject* renderer = core(element)->renderer())
if (renderer->isImage())
if (CachedImage* image = static_cast<RenderImage*>(renderer)->cachedImage())
extension = WKGetPreferredExtensionForMIMEType(image->response().mimeType());
NSArray *extensions = [[NSArray alloc] initWithObjects:extension, nil];
[self setPropertyList:extensions forType:NSFilesPromisePboardType];
[extensions release];
......
......@@ -3228,9 +3228,9 @@ done:
NSFileWrapper *wrapper = nil;
NSURL *draggingImageURL = nil;
if (WebCore::CachedResource* tiffResource = [self promisedDragTIFFDataSource]) {
if (WebCore::CachedImage* tiffResource = [self promisedDragTIFFDataSource]) {
SharedBuffer *buffer = tiffResource->data();
SharedBuffer *buffer = static_cast<CachedResource*>(tiffResource)->data();
if (!buffer)
goto noPromisedData;
......@@ -3238,7 +3238,11 @@ done:
NSURLResponse *response = tiffResource->response().nsURLResponse();
draggingImageURL = [response URL];
wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
[wrapper setPreferredFilename:[response suggestedFilename]];
NSString* filename = [response suggestedFilename];
String trueExtension = tiffResource->image()->filenameExtension();
if (![filename hasSuffix:trueExtension])
filename = [[filename stringByAppendingString:@"."] stringByAppendingString:trueExtension];
[wrapper setPreferredFilename:filename];
}
noPromisedData:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment