WebCore:
authorbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Feb 2007 06:00:26 +0000 (06:00 +0000)
committerbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Feb 2007 06:00:26 +0000 (06:00 +0000)
        Reviewed by Maciej.

        Implement writeImage() on Pasteboard so that the context menus can
        call into the editor for the "Copy image" command instead of
        calling across the clients.

        * WebCore.exp:
        * WebCore.xcodeproj/project.pbxproj:
        * editing/Editor.cpp:
        (WebCore::Editor::copyImage): Call into the Pasteboard.
        * editing/Editor.h:
        * loader/mac/LoaderNSURLExtras.h: A new NSURL extra needed inside
        WebCore.
        * loader/mac/LoaderNSURLExtras.m: Made this file Objective-C++
        (from Objective-C) since the call into the MIMETypeRegistry will
        return a Vector.
        (urlByRemovingComponent): Cast to build as Obj-C++
        (urlWithDataRelativeToURL): Same.
        (vectorContainsString): Helper.
        (suggestedFilenameWithMIMEType): New function.
        * page/ContextMenuClient.h: Remove copyImageToClipboard()
        * page/ContextMenuController.cpp:
        (WebCore::ContextMenuController::contextMenuItemSelected): Call
        into the editor instead of the client.
        * page/mac/WebCoreViewFactory.h: New localized String.
        * platform/LocalizedStrings.h: Same.
        * platform/MimeTypeRegistry.h: Expose two additional functions for
        MIMEType information from WebCore System Interface.
        * platform/Pasteboard.h:
        * platform/SharedBuffer.h: Make platformData() and platformDataSize
        () public since they are needed to write the image to the
        pasteboard.
        * platform/mac/LocalizedStringsMac.mm: New localized string.
        (WebCore::copyImageUnknownFileLabel):
        * platform/mac/MimeTypeRegistryMac.mm:
        (WebCore::MimeTypeRegistry::getExtensionsForMIMEType):
        (WebCore::MimeTypeRegistry::getPreferredExtensionForMIMEType):
        * platform/mac/PasteboardMac.mm:
        (WebCore::writableTypesForImage):
        (WebCore::Pasteboard::writeURL): Write the correct types if the url
        is for an image.
        (WebCore::fileWrapperForImage):
        (WebCore::Pasteboard::writeFileWrapperAsRTFDAttachment):
        (WebCore::Pasteboard::writeImage):
        * platform/mac/WebCoreNSStringExtras.h: Added. Some the the
        NSStringExtras that were in WebKit are now needed by WebCore. To
        avoid having two copies of these functions, I just moved the
        implementations to WebCore. The WebKit functions just call into
        WebCore.
        * platform/mac/WebCoreNSStringExtras.mm: Added.
        (hasCaseInsensitiveSuffix):
        (hasCaseInsensitiveSubstring):
        (filenameByFixingIllegalCharacters):
        * platform/mac/WebCoreSystemInterface.h:
        wkGetPreferredExtensionForMIMEType and wkGetExtensionsForMIMEType
        are now needed in WebCore as well as WebKit.
        * platform/mac/WebCoreSystemInterface.mm:

WebKit:
        Reviewed by Maciej.

        WebKit changes needed to implement writeImage() in WebCore's
        Pasteboard class.

        * Misc/WebKitNSStringExtras.m: Call into WebCore for these
        implementations.
        (-[NSString _webkit_hasCaseInsensitiveSuffix:]):
        (-[NSString _webkit_hasCaseInsensitiveSubstring:]):
        (-[NSString _webkit_filenameByFixingIllegalCharacters]):
        * Misc/WebNSURLExtras.m: Same.
        (-[NSURL _webkit_suggestedFilenameWithMIMEType:]):
        * WebCoreSupport/WebContextMenuClient.h: Remove
        copyImageToClipboard()
        * WebCoreSupport/WebContextMenuClient.mm:
        * WebCoreSupport/WebSystemInterface.m: Expose
        GetExtensionsForMIMEType and GetPreferredExtensionForMIMEType to
        WebCore.
        (InitWebCoreSystemInterface):
        * WebCoreSupport/WebViewFactory.mm: New localized string for
        WebCore.
        (-[WebViewFactory copyImageUnknownFileLabel]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@19764 268f45cc-cd09-0410-ab3c-d52691b4dbfc

28 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/editing/Editor.cpp
WebCore/editing/Editor.h
WebCore/loader/mac/LoaderNSURLExtras.h
WebCore/loader/mac/LoaderNSURLExtras.m
WebCore/page/ContextMenuClient.h
WebCore/page/ContextMenuController.cpp
WebCore/page/mac/WebCoreViewFactory.h
WebCore/platform/LocalizedStrings.h
WebCore/platform/MimeTypeRegistry.h
WebCore/platform/Pasteboard.h
WebCore/platform/SharedBuffer.h
WebCore/platform/mac/LocalizedStringsMac.mm
WebCore/platform/mac/MimeTypeRegistryMac.mm
WebCore/platform/mac/PasteboardMac.mm
WebCore/platform/mac/WebCoreNSStringExtras.h [new file with mode: 0644]
WebCore/platform/mac/WebCoreNSStringExtras.mm [new file with mode: 0644]
WebCore/platform/mac/WebCoreSystemInterface.h
WebCore/platform/mac/WebCoreSystemInterface.mm
WebKit/ChangeLog
WebKit/Misc/WebKitNSStringExtras.m
WebKit/Misc/WebNSURLExtras.m
WebKit/WebCoreSupport/WebContextMenuClient.h
WebKit/WebCoreSupport/WebContextMenuClient.mm
WebKit/WebCoreSupport/WebSystemInterface.m
WebKit/WebCoreSupport/WebViewFactory.mm

index e3817313d28826f25ca9dd71a89880921d0852de..05ea5d61866e4ebaf10ce17844ab098cd2a6311d 100644 (file)
@@ -1,3 +1,63 @@
+2007-02-20  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Maciej.
+
+        Implement writeImage() on Pasteboard so that the context menus can 
+        call into the editor for the "Copy image" command instead of 
+        calling across the clients.
+
+        * WebCore.exp:
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/Editor.cpp:
+        (WebCore::Editor::copyImage): Call into the Pasteboard.
+        * editing/Editor.h:
+        * loader/mac/LoaderNSURLExtras.h: A new NSURL extra needed inside 
+        WebCore.
+        * loader/mac/LoaderNSURLExtras.m: Made this file Objective-C++ 
+        (from Objective-C) since the call into the MIMETypeRegistry will 
+        return a Vector.
+        (urlByRemovingComponent): Cast to build as Obj-C++
+        (urlWithDataRelativeToURL): Same.
+        (vectorContainsString): Helper.
+        (suggestedFilenameWithMIMEType): New function.
+        * page/ContextMenuClient.h: Remove copyImageToClipboard()
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::contextMenuItemSelected): Call 
+        into the editor instead of the client.
+        * page/mac/WebCoreViewFactory.h: New localized String.
+        * platform/LocalizedStrings.h: Same.
+        * platform/MimeTypeRegistry.h: Expose two additional functions for 
+        MIMEType information from WebCore System Interface.
+        * platform/Pasteboard.h:
+        * platform/SharedBuffer.h: Make platformData() and platformDataSize
+        () public since they are needed to write the image to the 
+        pasteboard.
+        * platform/mac/LocalizedStringsMac.mm: New localized string.
+        (WebCore::copyImageUnknownFileLabel):
+        * platform/mac/MimeTypeRegistryMac.mm:
+        (WebCore::MimeTypeRegistry::getExtensionsForMIMEType):
+        (WebCore::MimeTypeRegistry::getPreferredExtensionForMIMEType):
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::writableTypesForImage):
+        (WebCore::Pasteboard::writeURL): Write the correct types if the url 
+        is for an image.
+        (WebCore::fileWrapperForImage):
+        (WebCore::Pasteboard::writeFileWrapperAsRTFDAttachment):
+        (WebCore::Pasteboard::writeImage):
+        * platform/mac/WebCoreNSStringExtras.h: Added. Some the the 
+        NSStringExtras that were in WebKit are now needed by WebCore. To 
+        avoid having two copies of these functions, I just moved the 
+        implementations to WebCore. The WebKit functions just call into 
+        WebCore.
+        * platform/mac/WebCoreNSStringExtras.mm: Added.
+        (hasCaseInsensitiveSuffix):
+        (hasCaseInsensitiveSubstring):
+        (filenameByFixingIllegalCharacters):
+        * platform/mac/WebCoreSystemInterface.h: 
+        wkGetPreferredExtensionForMIMEType and wkGetExtensionsForMIMEType 
+        are now needed in WebCore as well as WebKit.
+        * platform/mac/WebCoreSystemInterface.mm:
+
 2007-02-20  Adam Roben  <aroben@apple.com>
 
         Build fix.
index b19e218eb7d4a61e5d2d1a24a4fd0e4a7caec497..48cd537e79077f3cb088039ffc42f916ecb9a5ed 100644 (file)
@@ -601,7 +601,11 @@ __ZNK7WebCore9Selection23isContentRichlyEditableEv
 __ZNK7WebCore9Selection7toRangeEv
 __ZNK7WebCore9TimerBase8isActiveEv
 _canonicalURL
+_filenameByFixingIllegalCharacters
+_hasCaseInsensitiveSubstring
+_hasCaseInsensitiveSuffix
 _stringIsFileURL
+_suggestedFilenameWithMIMEType
 _urlByRemovingComponent
 _urlByRemovingFragment
 _urlByRemovingResourceSpecifier
@@ -626,6 +630,7 @@ _wkFontSmoothingModeIsLCD
 _wkGetATSStyleGroup
 _wkGetCGFontFromNSFont
 _wkGetDefaultGlyphForChar
+_wkGetExtensionsForMIMEType
 _wkGetFontInLanguageForCharacter
 _wkGetFontInLanguageForRange
 _wkGetFontMetrics
@@ -638,6 +643,7 @@ _wkGetNSFontATSUFontId
 _wkGetNSURLResponseCalculatedExpiration
 _wkGetNSURLResponseLastModifiedDate
 _wkGetNSURLResponseMustRevalidate
+_wkGetPreferredExtensionForMIMEType
 _wkInitializeGlyphVector
 _wkNSURLProtocolClassForReqest
 _wkPathFromFont
index 139b99bf46c2439475b01264b7504a256b0fbac0..dd5b3abfbf3e08f6c61776a9951172cdbac81e04 100644 (file)
                933A14B80B7D1D5200A53FFD /* JSTextEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 933A14B60B7D1D5200A53FFD /* JSTextEvent.cpp */; };
                933A14B90B7D1D5200A53FFD /* JSTextEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 933A14B70B7D1D5200A53FFD /* JSTextEvent.h */; };
                934706AB0AACD809002C1D43 /* TextDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 932CA7420AAA198E00AD1FAD /* TextDecoder.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               934D9BA50B8C116B007B42A9 /* WebCoreNSStringExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 934D9BA40B8C116B007B42A9 /* WebCoreNSStringExtras.mm */; };
+               934D9BA70B8C1175007B42A9 /* WebCoreNSStringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 934D9BA60B8C1175007B42A9 /* WebCoreNSStringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
                934FE9E50B5CA539003E4A73 /* FileChooser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 934FE9E40B5CA539003E4A73 /* FileChooser.cpp */; };
                9352071909BD3BA500F2038D /* StaticConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = 9352071709BD3BA500F2038D /* StaticConstructors.h */; };
                9352071A09BD3BA500F2038D /* TextBoundaries.h in Headers */ = {isa = PBXBuildFile; fileRef = 9352071809BD3BA500F2038D /* TextBoundaries.h */; };
                656B84EA0AEA1DDA00A095B4 /* ResourceHandleMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceHandleMac.mm; sourceTree = "<group>"; };
                656B85370AEA1F9A00A095B4 /* ResourceHandle.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceHandle.h; sourceTree = "<group>"; };
                656D371A0ADBA5DE00A4554D /* LoaderNSURLExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LoaderNSURLExtras.h; sourceTree = "<group>"; };
-               656D371B0ADBA5DE00A4554D /* LoaderNSURLExtras.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = LoaderNSURLExtras.m; sourceTree = "<group>"; };
+               656D371B0ADBA5DE00A4554D /* LoaderNSURLExtras.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = LoaderNSURLExtras.m; sourceTree = "<group>"; };
                656D371E0ADBA5DE00A4554D /* DocumentLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DocumentLoader.h; sourceTree = "<group>"; };
                656D371F0ADBA5DE00A4554D /* DocumentLoaderMac.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = DocumentLoaderMac.mm; sourceTree = "<group>"; };
                656D37220ADBA5DE00A4554D /* FormState.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FormState.h; sourceTree = "<group>"; };
                933A14A90B7D1D0900A53FFD /* DOMTextEvent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMTextEvent.mm; sourceTree = "<group>"; };
                933A14B60B7D1D5200A53FFD /* JSTextEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTextEvent.cpp; sourceTree = "<group>"; };
                933A14B70B7D1D5200A53FFD /* JSTextEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTextEvent.h; sourceTree = "<group>"; };
+               934D9BA40B8C116B007B42A9 /* WebCoreNSStringExtras.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSStringExtras.mm; sourceTree = "<group>"; };
+               934D9BA60B8C1175007B42A9 /* WebCoreNSStringExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebCoreNSStringExtras.h; sourceTree = "<group>"; };
                934FE9E40B5CA539003E4A73 /* FileChooser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileChooser.cpp; sourceTree = "<group>"; };
                9352071709BD3BA500F2038D /* StaticConstructors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticConstructors.h; sourceTree = "<group>"; };
                9352071809BD3BA500F2038D /* TextBoundaries.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextBoundaries.h; sourceTree = "<group>"; };
                                F5517DC3031AB56301A80180 /* WebCoreHistory.m */,
                                84B2B1F7056BEF3A00D2B771 /* WebCoreKeyGenerator.h */,
                                84B2B1F8056BEF3A00D2B771 /* WebCoreKeyGenerator.m */,
+                               934D9BA60B8C1175007B42A9 /* WebCoreNSStringExtras.h */,
+                               934D9BA40B8C116B007B42A9 /* WebCoreNSStringExtras.mm */,
                                DD05FE0B0B8BA3C6009ACDFE /* WebCoreObjCExtras.h */,
                                DD05FE0C0B8BA3C6009ACDFE /* WebCoreObjCExtras.c */,
                                93EB169609F880C00091F8FF /* WebCoreSystemInterface.h */,
                                37919C240B7D188600A56998 /* PositionIterator.h in Headers */,
                                DD05FE0D0B8BA3C6009ACDFE /* WebCoreObjCExtras.h in Headers */,
                                06A6A73D0B8BA44800DF1703 /* StringTruncator.h in Headers */,
+                               934D9BA70B8C1175007B42A9 /* WebCoreNSStringExtras.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                37919C230B7D188600A56998 /* PositionIterator.cpp in Sources */,
                                DD05FE0E0B8BA3C6009ACDFE /* WebCoreObjCExtras.c in Sources */,
                                06A6A73C0B8BA44800DF1703 /* StringTruncator.cpp in Sources */,
+                               934D9BA50B8C116B007B42A9 /* WebCoreNSStringExtras.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index b3c97d066703fa3f398a29884a7cb6dfdd55f8bd..c05302b6e306ff3708746ff0a939948632af4eeb 100644 (file)
@@ -1382,6 +1382,11 @@ void Editor::copyURL(const KURL& url, const String& title)
     Pasteboard::generalPasteboard()->writeURL(url, title, m_frame);
 }
 
+void Editor::copyImage(const HitTestResult& result)
+{
+    Pasteboard::generalPasteboard()->writeImage(result);
+}
+
 bool Editor::isContinuousSpellCheckingEnabled()
 {
     if (client())
index ff1ffc2be7eab00b289ddfcdce691aa7bf12606d..2f42cbed8554ec3daf5886d1887e31a628e9de60 100644 (file)
@@ -90,6 +90,7 @@ public:
     void performDelete();
 
     void copyURL(const KURL&, const String&);
+    void copyImage(const HitTestResult&);
 
     void indent();
     void outdent();
index 41e4667d8e0efeb6da19b400c9486f20368c5016..39ef2226b93eb2665f30b94f4df144ea5e3ddbef 100644 (file)
@@ -43,6 +43,7 @@ BOOL urlIsFileURL(NSURL *url);
 BOOL stringIsFileURL(NSString *urlString);
 BOOL urlIsEmpty(NSURL *url);
 NSURL *canonicalURL(NSURL *url);
+NSString *suggestedFilenameWithMIMEType(NSURL *url, NSString *MIMEType);
 
 #ifdef __cplusplus
 }
index 1ad6db2e75c1f28ec821ae3682a83fc84793839c..8aaf6b3d7e4e00de00f8683e7ed6d23abd240453 100644 (file)
 #import "LoaderNSURLExtras.h"
 
 #import <wtf/Assertions.h>
+#import <wtf/Vector.h>
+#import "KURL.h"
+#import "LocalizedStrings.h"
+#import "MimeTypeRegistry.h"
+#import "PlatformString.h"
+#import "WebCoreNSStringExtras.h"
 #import "WebCoreSystemInterface.h"
 
+using namespace WebCore;
+
 NSURL *urlByRemovingComponent(NSURL *url, CFURLComponentType component)
 {
     if (!url)
@@ -47,7 +55,7 @@ NSURL *urlByRemovingComponent(NSURL *url, CFURLComponentType component)
     CFIndex numBytes = CFURLGetBytes((CFURLRef)url, buffer, 2048);
     if (numBytes == -1) {
         numBytes = CFURLGetBytes((CFURLRef)url, NULL, 0);
-        urlBytes = malloc(numBytes);
+        urlBytes = static_cast<UInt8*>(malloc(numBytes));
         CFURLGetBytes((CFURLRef)url, urlBytes, numBytes);
     } else
         urlBytes = buffer;
@@ -124,7 +132,7 @@ NSURL *urlWithDataRelativeToURL(NSData *data, NSURL *baseURL)
         // work around <rdar://4470771>: CFURLCreateAbsoluteURLWithBytes(.., TRUE) doesn't remove non-path components.
         baseURL = urlByRemovingResourceSpecifier(baseURL);
         
-        const UInt8 *bytes = [data bytes];
+        const UInt8 *bytes = static_cast<const UInt8*>([data bytes]);
         // NOTE: We use UTF-8 here since this encoding is used when computing strings when returning URL components
         // (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which
         // could either be a malformed string or bytes in a different encoding, like shift-jis, so we fall back
@@ -186,3 +194,64 @@ NSURL *canonicalURL(NSURL *url)
     
     return result;
 }
+
+static bool vectorContainsString(Vector<String> vector, String string)
+{
+    int size = vector.size();
+    for (int i = 0; i < size; i++)
+        if (vector[i] == string)
+            return true;
+    return false;
+}
+
+NSString *suggestedFilenameWithMIMEType(NSURL *url, NSString *MIMEType)
+{
+    // Get the filename from the URL. Try the lastPathComponent first.
+    NSString *lastPathComponent = [[url path] lastPathComponent];
+    NSString *filename = filenameByFixingIllegalCharacters(lastPathComponent);
+    NSString *extension = nil;
+
+    if ([filename length] == 0 || [lastPathComponent isEqualToString:@"/"]) {
+        // lastPathComponent is no good, try the host.
+        NSString *host = (NSString *)(KURL(url).host());
+        filename = filenameByFixingIllegalCharacters(host);
+        if ([filename length] == 0) {
+            // Can't make a filename using this URL, use "unknown".
+            filename = copyImageUnknownFileLabel();
+        }
+    } else {
+        // Save the extension for later correction. Only correct the extension of the lastPathComponent.
+        // For example, if the filename ends up being the host, we wouldn't want to correct ".com" in "www.apple.com".
+        extension = [filename pathExtension];
+    }
+
+    // No mime type reported. Just return the filename we have now.
+    if (!MIMEType) {
+        return filename;
+    }
+
+    // Do not correct filenames that are reported with a mime type of tar, and 
+    // have a filename which has .tar in it or ends in .tgz
+    if (([MIMEType isEqualToString:@"application/tar"] || [MIMEType isEqualToString:@"application/x-tar"]) 
+        && (hasCaseInsensitiveSubstring(filename, @".tar")
+        || hasCaseInsensitiveSuffix(filename, @".tgz"))) {
+        return filename;
+    }
+
+    // I don't think we need to worry about this for the image case
+    // If the type is known, check the extension and correct it if necessary.
+    if (![MIMEType isEqualToString:@"application/octet-stream"] && ![MIMEType isEqualToString:@"text/plain"]) {
+        Vector<String> extensions = MimeTypeRegistry::getExtensionsForMIMEType(MIMEType);
+
+        if (!extensions.size() || (extensions && !vectorContainsString(extensions, extension))) {
+            // The extension doesn't match the MIME type. Correct this.
+            NSString *correctExtension = MimeTypeRegistry::getPreferredExtensionForMIMEType(MIMEType);
+            if ([correctExtension length] != 0) {
+                // Append the correct extension.
+                filename = [filename stringByAppendingPathExtension:correctExtension];
+            }
+        }
+    }
+
+    return filename;
+}
index 2e62b0cfff6339b14b7807c9ace3d0ac469aa357..775adc50300473adda6d2e73877f2f0444f8ae3e 100644 (file)
@@ -45,7 +45,6 @@ namespace WebCore {
         virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*) = 0;
 
         virtual void downloadURL(const KURL& url) = 0;
-        virtual void copyImageToClipboard(const HitTestResult&) = 0;
         virtual void searchWithGoogle(const Frame*) = 0;
         virtual void lookUpInDictionary(Frame*) = 0;
         virtual void speak(const String&) = 0;
index 3816eb070d5bcd9888304eab66f05db6da88191c..e48da77d6a333835ba93583ce43d28f2fa893d93 100644 (file)
@@ -134,7 +134,7 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
         case ContextMenuItemTagCopyImageToClipboard:
             // FIXME: The Pasteboard class is not written yet
             // For now, call into the client. This is temporary!
-            m_client->copyImageToClipboard(result);
+            frame->editor()->copyImage(result);
             break;
         case ContextMenuItemTagOpenFrameInNewWindow: {
             KURL url = frame->loader()->documentLoader()->unreachableURL();
index 4401bb434df8d4cbe0a16ad7c0a68d332052cd9e..696933d85d075fa515902a9527fd801f132b337d 100644 (file)
@@ -44,6 +44,7 @@
 - (NSString *)submitButtonDefaultLabel;
 - (NSString *)fileButtonChooseFileLabel;
 - (NSString *)fileButtonNoFileSelectedLabel;
+- (NSString *)copyImageUnknownFileLabel;
 
 // Context menu item titles
 - (NSString *)contextMenuItemTagOpenLinkInNewWindow;
index 2885b849880d56682d33b7556c60aa36467124f9..b4a5b9b83770b02b0a4542aa069241da7548dfe4 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore {
     String submitButtonDefaultLabel();
     String fileButtonChooseFileLabel();
     String fileButtonNoFileSelectedLabel();
+    String copyImageUnknownFileLabel();
     String contextMenuItemTagOpenLinkInNewWindow();
     String contextMenuItemTagDownloadLinkToDisk();
     String contextMenuItemTagCopyLinkToClipboard();
index 9342da433587bcb293e44b70c9656ee43a8be660..9cd36342d1a609fd32b3d57b91b81553757b91fa 100644 (file)
 #include "PlatformString.h"
 #include "StringHash.h"
 #include <wtf/HashSet.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
 class MimeTypeRegistry {
 public:
     static String getMIMETypeForExtension(const String& ext);
+    static Vector<String> getExtensionsForMIMEType(const String& type);
+    static String getPreferredExtensionForMIMEType(const String& type);
     static String getMIMETypeForPath(const String& path);
     
     // Check to see if a mime type is suitable for being loaded inline as an
index 37dc940df878127421cfcae4c9b80683ee74b1ac..75c34ce47501a0fbdacf10ed3391c14c678f7eee 100644 (file)
@@ -35,6 +35,7 @@
 // knowledge of the frame and editor or moved into the editing directory.
 
 #if PLATFORM(MAC)
+class NSFileWrapper;
 class NSPasteboard;
 class NSArray;
 #endif
@@ -57,6 +58,7 @@ extern NSString *WebURLsWithTitlesPboardType;
 class CString;
 class DocumentFragment;
 class Frame;
+class HitTestResult;
 class KURL;
 class Range;
 class String;
@@ -66,12 +68,16 @@ public:
 #if PLATFORM(MAC)
     //Helper functions to allow Clipboard to share code
     static void writeSelection(NSPasteboard* pasteboard, Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame);
-    static void writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame);
+    static void writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame, bool isImage = false);
 #endif
     
     static Pasteboard* generalPasteboard();
     void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*);
-    void writeURL(const KURL&, const String&, Frame* = 0);
+    void writeURL(const KURL&, const String&, Frame* = 0, bool isImage = false);
+    void writeImage(const HitTestResult&);
+#if PLATFORM(MAC)
+    void writeFileWrapperAsRTFDAttachment(NSFileWrapper*);
+#endif
     void clear();
     bool canSmartReplace();
     PassRefPtr<DocumentFragment> documentFragment(Frame*, PassRefPtr<Range>, bool allowPlainText, bool& chosePlainText);
index 8284532179176b69f38237ec0575630922425efa..23e9333c018d8aee3ecd9c9d55a97f27cd80662e 100644 (file)
@@ -56,13 +56,13 @@ public:
 
     void append(const char*, int);
     void clear();
+    const char* platformData() const;
+    unsigned platformDataSize() const;
 
 private:
     void clearPlatformData();
     void maybeTransferPlatformData();
     bool hasPlatformData() const;
-    const char* platformData() const;
-    unsigned platformDataSize() const;
     
     Vector<char> m_buffer;
 #if PLATFORM(MAC)
index 0b47310be985be3f3d9759c819ae63c7de8b393c..12d4aedf8f7fdde4fa1bec7daaf1f7434e6495c2 100644 (file)
@@ -80,6 +80,14 @@ String fileButtonNoFileSelectedLabel()
     return String();
 }
 
+String copyImageUnknownFileLabel()
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    return [[WebCoreViewFactory sharedFactory] copyImageUnknownFileLabel];
+    END_BLOCK_OBJC_EXCEPTIONS;
+    return String();
+}
+
 String contextMenuItemTagOpenLinkInNewWindow()
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
index b75ebb7d259576d3ed4326e198b8384d09401909..d36e4c279bdfe97fdd6b431491ddc8cc70f7aa8a 100644 (file)
@@ -46,4 +46,23 @@ String MimeTypeRegistry::getMIMETypeForExtension(const String &ext)
     return wkGetMIMETypeForExtension(ext);
 }
 
+Vector<String> MimeTypeRegistry::getExtensionsForMIMEType(const String& type)
+{
+    NSArray *stringsArray = wkGetExtensionsForMIMEType(type);
+    Vector<String> stringsVector = Vector<String>();
+    unsigned count = [stringsArray count];
+    if (count > 0) {
+        NSEnumerator* enumerator = [stringsArray objectEnumerator];
+        NSString* string;
+        while ((string = [enumerator nextObject]) != nil)
+            stringsVector.append(string);
+    }
+    return stringsVector;
+}
+
+String MimeTypeRegistry::getPreferredExtensionForMIMEType(const String& type)
+{
+    return wkGetPreferredExtensionForMIMEType(type);
+}
+
 }
index 2334d55d9c9c6e24e7ecf044f051b1bfce0fcdfe..810cb076acd6085ee0451b1f625f3f3bb4ef7cf1 100644 (file)
 #import "config.h"
 #import "Pasteboard.h"
 
+#import "Cache.h"
+#import "CachedResource.h"
 #import "CharacterNames.h"
 #import "DOMRangeInternal.h"
+#import "Document.h"
 #import "DocumentFragment.h"
 #import "Editor.h"
 #import "EditorClient.h"
+#import "HitTestResult.h"
+#import "Image.h"
 #import "KURL.h"
+#import "LoaderNSURLExtras.h"
+#import "MimeTypeRegistry.h"
 #import "RetainPtr.h"
+#import "WebCoreNSStringExtras.h"
 #import "WebCoreSystemInterface.h"
 #import "markup.h"
 
@@ -80,6 +88,17 @@ static NSArray* writableTypesForURL()
     return types;
 }
 
+static NSArray* writableTypesForImage()
+{
+    static NSMutableArray *types = nil;
+    if (!types) {
+        types = [[NSMutableArray alloc] initWithObjects:NSTIFFPboardType, nil];
+        [types addObjectsFromArray:writableTypesForURL()];
+        [types addObject:NSRTFDPboardType];
+    }
+    return types;
+}
+
 Pasteboard* Pasteboard::generalPasteboard() 
 {
     static Pasteboard* pasteboard = new Pasteboard([NSPasteboard generalPasteboard]);
@@ -181,13 +200,16 @@ void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete,
     Pasteboard::writeSelection(m_pasteboard, selectedRange, canSmartCopyOrDelete, frame);
 }
 
-void Pasteboard::writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame)
+void Pasteboard::writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame, bool isImage)
 {
     if (WebArchivePboardType == nil)
         Pasteboard::generalPasteboard(); //Initialises pasteboard types
    
     if (types == nil) {
-        types = writableTypesForURL();
+        if (isImage)
+            types = writableTypesForImage();
+        else
+            types = writableTypesForURL();
         [pasteboard declareTypes:types owner:nil];
     }
     
@@ -218,11 +240,63 @@ void Pasteboard::writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL&
         [pasteboard setString:userVisibleString forType:NSStringPboardType];
 }
     
-void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame)
+void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame, bool isImage)
+{
+    Pasteboard::writeURL(m_pasteboard, nil, url, titleStr, frame, isImage);
+}
+
+static NSFileWrapper* fileWrapperForImage(CachedResource* resource, NSURL *URL)
+{
+    SharedBuffer* coreData = resource->allData();
+    NSData *data = [[[NSData alloc] initWithBytes:coreData->platformData() 
+        length:coreData->platformDataSize()] autorelease];
+    NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
+    String coreMIMEType = resource->response().mimeType();
+    NSString *MIMEType = nil;
+    if (!coreMIMEType.isNull())
+        MIMEType = coreMIMEType;
+    [wrapper setPreferredFilename:suggestedFilenameWithMIMEType(URL, MIMEType)];
+    return wrapper;
+}
+
+void Pasteboard::writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper)
 {
-    Pasteboard::writeURL(m_pasteboard, nil, url, titleStr, frame);
+    NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:wrapper];
+    
+    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attachment];
+    [attachment release];
+    
+    NSData *RTFDData = [string RTFDFromRange:NSMakeRange(0, [string length]) documentAttributes:nil];
+    [m_pasteboard setData:RTFDData forType:NSRTFDPboardType];
 }
 
+void Pasteboard::writeImage(const HitTestResult& result)
+{    
+    KURL coreURL = result.absoluteLinkURL();
+    if (coreURL.isEmpty())
+        coreURL = result.absoluteImageURL();
+    NSURL *URL = coreURL.getNSURL();
+    ASSERT(URL);
+
+    NSString *title = result.altDisplayString().isNull() ? nil : (NSString*)(result.altDisplayString());
+    Frame* frame = result.innerNonSharedNode()->document()->frame();
+
+    writeURL(URL, title, frame, true);
+    NSArray *types = [m_pasteboard types];
+    [m_pasteboard declareTypes:types owner:nil];
+
+    NSImage *image = (NSImage *)(result.image() ? result.image()->getNSImage() : nil);
+    ASSERT(image);
+    [m_pasteboard setData:[image TIFFRepresentation] forType:NSTIFFPboardType];
+
+    CachedResource* imageResource = WebCore::cache()->resourceForURL(result.absoluteImageURL().url());
+    ASSERT(imageResource);
+    String MIMEType = imageResource->response().mimeType();
+    ASSERT(MimeTypeRegistry::isSupportedImageResourceMIMEType(MIMEType));
+
+    if (imageResource)
+        writeFileWrapperAsRTFDAttachment(fileWrapperForImage(imageResource, URL));
+}
 
 bool Pasteboard::canSmartReplace()
 {
diff --git a/WebCore/platform/mac/WebCoreNSStringExtras.h b/WebCore/platform/mac/WebCoreNSStringExtras.h
new file mode 100644 (file)
index 0000000..95d2031
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2005, 2007 Apple Computer, 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. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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 <Cocoa/Cocoa.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+BOOL hasCaseInsensitiveSuffix(NSString *string, NSString *suffix);
+BOOL hasCaseInsensitiveSubstring(NSString *string, NSString *substring);
+NSString *filenameByFixingIllegalCharacters(NSString *string);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/WebCore/platform/mac/WebCoreNSStringExtras.mm b/WebCore/platform/mac/WebCoreNSStringExtras.mm
new file mode 100644 (file)
index 0000000..a2b0a28
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2005, 2007 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. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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 "WebCoreNSStringExtras.h"
+
+BOOL hasCaseInsensitiveSuffix(NSString *string, NSString *suffix)
+{
+    return [string rangeOfString:suffix options:(NSCaseInsensitiveSearch | NSBackwardsSearch | NSAnchoredSearch)].location != NSNotFound;
+}
+
+BOOL hasCaseInsensitiveSubstring(NSString *string, NSString *substring)
+{
+    return [string rangeOfString:substring options:NSCaseInsensitiveSearch].location != NSNotFound;
+}
+
+NSString *filenameByFixingIllegalCharacters(NSString *string)
+{
+    NSMutableString *filename = [[string mutableCopy] autorelease];
+
+    // Strip null characters.
+    unichar nullChar = 0;
+    [filename replaceOccurrencesOfString:[NSString stringWithCharacters:&nullChar length:0] withString:@"" options:0 range:NSMakeRange(0, [filename length])];
+
+    // Replace "/" with "-".
+    [filename replaceOccurrencesOfString:@"/" withString:@"-" options:0 range:NSMakeRange(0, [filename length])];
+
+    // Replace ":" with "-".
+    [filename replaceOccurrencesOfString:@":" withString:@"-" options:0 range:NSMakeRange(0, [filename length])];
+    
+    // Strip leading dots.
+    while ([filename hasPrefix:@"."]) {
+        [filename deleteCharactersInRange:NSMakeRange(0,1)];
+    }
+    
+    return filename;
+}
index 2fc6164750ffc60bbe9c77110be9550dd342268a..b732d024acc94654dbb690a3b365c0b4841943aa 100644 (file)
@@ -44,6 +44,7 @@ typedef struct _NSRect NSRect;
 @class NSMutableURLRequest;
 @class NSURLRequest;
 #else
+typedef struct NSArray NSArray;
 typedef struct NSDate NSDate;
 typedef struct NSFont NSFont;
 typedef struct NSImage NSImage;
@@ -96,6 +97,8 @@ extern BOOL (*wkGetGlyphTransformedAdvances)(NSFont*, CGAffineTransform*, ATSGly
 extern ATSLayoutRecord* (*wkGetGlyphVectorFirstRecord)(void* glyphVector);
 extern int (*wkGetGlyphVectorNumGlyphs)(void* glyphVector);
 extern size_t (*wkGetGlyphVectorRecordSize)(void* glyphVector);
+extern NSString* (*wkGetPreferredExtensionForMIMEType)(NSString*);
+extern NSArray* (*wkGetExtensionsForMIMEType)(NSString*);
 extern NSString* (*wkGetMIMETypeForExtension)(NSString*);
 extern ATSUFontID (*wkGetNSFontATSUFontId)(NSFont*);
 extern double (*wkGetNSURLResponseCalculatedExpiration)(NSURLResponse *response);
index 9826af1b4cdba446a7156a50eb7dde7c6f004ce9..c7a947796e19d08c899c7c1f06ea0018c13178c6 100644 (file)
@@ -46,6 +46,8 @@ BOOL (*wkGetGlyphTransformedAdvances)(NSFont*, CGAffineTransform*, ATSGlyphRef*,
 ATSLayoutRecord* (*wkGetGlyphVectorFirstRecord)(void* glyphVector);
 int (*wkGetGlyphVectorNumGlyphs)(void* glyphVector);
 size_t (*wkGetGlyphVectorRecordSize)(void* glyphVector);
+NSString* (*wkGetPreferredExtensionForMIMEType)(NSString*);
+NSArray* (*wkGetExtensionsForMIMEType)(NSString*);
 NSString* (*wkGetMIMETypeForExtension)(NSString*);
 ATSUFontID (*wkGetNSFontATSUFontId)(NSFont*);
 NSTimeInterval (*wkGetNSURLResponseCalculatedExpiration)(NSURLResponse *response);
index a76864d3f49817b4458aad2d4417dd9296e83678..2f199afbd2c9b2bfcdadacdde12f71a937e8f503 100644 (file)
@@ -1,3 +1,28 @@
+2007-02-20  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Maciej.
+
+        WebKit changes needed to implement writeImage() in WebCore's 
+        Pasteboard class.
+
+        * Misc/WebKitNSStringExtras.m: Call into WebCore for these 
+        implementations.
+        (-[NSString _webkit_hasCaseInsensitiveSuffix:]):
+        (-[NSString _webkit_hasCaseInsensitiveSubstring:]):
+        (-[NSString _webkit_filenameByFixingIllegalCharacters]):
+        * Misc/WebNSURLExtras.m: Same.
+        (-[NSURL _webkit_suggestedFilenameWithMIMEType:]):
+        * WebCoreSupport/WebContextMenuClient.h: Remove 
+        copyImageToClipboard()
+        * WebCoreSupport/WebContextMenuClient.mm:
+        * WebCoreSupport/WebSystemInterface.m: Expose 
+        GetExtensionsForMIMEType and GetPreferredExtensionForMIMEType to 
+        WebCore.
+        (InitWebCoreSystemInterface):
+        * WebCoreSupport/WebViewFactory.mm: New localized string for 
+        WebCore. 
+        (-[WebViewFactory copyImageUnknownFileLabel]):
+
 2007-02-20  Adam Roben  <aroben@apple.com>
 
         Reviewed by Darin and Anders.
index 09385558111e7c984eef3691fbc9567871dc0b6b..940e63cd42eed648f5f8f84d2445aadcc3c9111a 100644 (file)
@@ -31,6 +31,7 @@
 #import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSFileManagerExtras.h>
 
+#import <WebCore/WebCoreNSStringExtras.h>
 #import <WebCore/WebCoreTextRenderer.h>
 
 #import <unicode/uchar.h>
@@ -199,34 +200,17 @@ static BOOL canUseFastRenderer(const UniChar *buffer, unsigned length)
 
 -(BOOL)_webkit_hasCaseInsensitiveSuffix:(NSString *)suffix
 {
-    return [self rangeOfString:suffix options:(NSCaseInsensitiveSearch | NSBackwardsSearch | NSAnchoredSearch)].location != NSNotFound;
+    return hasCaseInsensitiveSuffix(self, suffix);
 }
 
 -(BOOL)_webkit_hasCaseInsensitiveSubstring:(NSString *)substring
 {
-    return [self rangeOfString:substring options:NSCaseInsensitiveSearch].location != NSNotFound;
+    return hasCaseInsensitiveSubstring(self, substring);
 }
 
 -(NSString *)_webkit_filenameByFixingIllegalCharacters
 {
-    NSMutableString *filename = [[self mutableCopy] autorelease];
-
-    // Strip null characters.
-    unichar nullChar = 0;
-    [filename replaceOccurrencesOfString:[NSString stringWithCharacters:&nullChar length:0] withString:@"" options:0 range:NSMakeRange(0, [filename length])];
-
-    // Replace "/" with "-".
-    [filename replaceOccurrencesOfString:@"/" withString:@"-" options:0 range:NSMakeRange(0, [filename length])];
-
-    // Replace ":" with "-".
-    [filename replaceOccurrencesOfString:@":" withString:@"-" options:0 range:NSMakeRange(0, [filename length])];
-    
-    // Strip leading dots.
-    while ([filename hasPrefix:@"."]) {
-        [filename deleteCharactersInRange:NSMakeRange(0,1)];
-    }
-    
-    return filename;
+    return filenameByFixingIllegalCharacters(self);
 }
 
 -(NSString *)_webkit_stringByTrimmingWhitespace
index a1ab226164c9366fc70918a8c456583d8ab8dfef..bc41a84ed22d29758d7c892dda0f35663af6dd52 100644 (file)
@@ -681,51 +681,7 @@ typedef struct {
 
 - (NSString *)_webkit_suggestedFilenameWithMIMEType:(NSString *)MIMEType
 {
-    // Get the filename from the URL. Try the lastPathComponent first.
-    NSString *lastPathComponent = [[self path] lastPathComponent];
-    NSString *filename = [lastPathComponent _webkit_filenameByFixingIllegalCharacters];
-    NSString *extension = nil;
-
-    if ([filename length] == 0 || [lastPathComponent isEqualToString:@"/"]) {
-        // lastPathComponent is no good, try the host.
-        filename = [[self _web_hostString] _webkit_filenameByFixingIllegalCharacters];
-        if ([filename length] == 0) {
-            // Can't make a filename using this URL, use "unknown".
-            filename = UI_STRING("unknown", "Unknown filename");
-        }
-    } else {
-        // Save the extension for later correction. Only correct the extension of the lastPathComponent.
-        // For example, if the filename ends up being the host, we wouldn't want to correct ".com" in "www.apple.com".
-        extension = [filename pathExtension];
-    }
-
-    // No mime type reported. Just return the filename we have now.
-    if (!MIMEType) {
-        return filename;
-    }
-
-    // Do not correct filenames that are reported with a mime type of tar, and 
-    // have a filename which has .tar in it or ends in .tgz
-    if (([MIMEType isEqualToString:@"application/tar"] || [MIMEType isEqualToString:@"application/x-tar"]) &&
-        ([filename _webkit_hasCaseInsensitiveSubstring:@".tar"] || [filename _webkit_hasCaseInsensitiveSuffix:@".tgz"])) {
-        return filename;
-    }
-
-    // If the type is known, check the extension and correct it if necessary.
-    if (![MIMEType isEqualToString:@"application/octet-stream"] && ![MIMEType isEqualToString:@"text/plain"]) {
-        NSArray *extensions = WKGetExtensionsForMIMEType(MIMEType);
-
-        if (![extension length] || (extensions && ![extensions containsObject:extension])) {
-            // The extension doesn't match the MIME type. Correct this.
-            NSString *correctExtension = WKGetPreferredExtensionForMIMEType(MIMEType);
-            if ([correctExtension length] != 0) {
-                // Append the correct extension.
-                filename = [filename stringByAppendingPathExtension:correctExtension];
-            }
-        }
-    }
-
-    return filename;
+    return suggestedFilenameWithMIMEType(self, MIMEType);
 }
 
 @end
index 60c3b140e53be42f24eebdd2e7c5c7034ea980d0..f3c70c56e7e4fb8b44f1bb6b87a986af99c8e42e 100644 (file)
@@ -42,7 +42,6 @@ public:
     virtual void contextMenuItemSelected(WebCore::ContextMenuItem*, const WebCore::ContextMenu*);
     
     virtual void downloadURL(const WebCore::KURL&);
-    virtual void copyImageToClipboard(const WebCore::HitTestResult&);
     virtual void searchWithGoogle(const WebCore::Frame*);
     virtual void lookUpInDictionary(WebCore::Frame*);
     virtual void speak(const WebCore::String&);
index 66b72a33ec23acbf67e138821101b536d5e67967..b76fd3a257243e103c11614f95caa63bf1505a66 100644 (file)
@@ -241,15 +241,6 @@ void WebContextMenuClient::downloadURL(const KURL& url)
     [m_webView _downloadURL:url.getNSURL()];
 }
 
-void WebContextMenuClient::copyImageToClipboard(const HitTestResult& hitTestResult)
-{
-    NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:hitTestResult] autorelease];
-    NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
-    NSArray *types = [NSPasteboard _web_writableTypesForImageIncludingArchive:(hitTestResult.innerNonSharedNode() != 0)];
-    [pasteboard declareTypes:types owner:m_webView];
-    [m_webView _writeImageForElement:element withPasteboardTypes:types toPasteboard:pasteboard];
-}
-
 void WebContextMenuClient::searchWithSpotlight()
 {
     [m_webView _searchWithSpotlightFromMenu:nil];
index 5741e221940035f5846e9d5e649da217e7cac58a..5e7255531d80994a79fc02fabbd8b247a0bcb125 100644 (file)
@@ -44,16 +44,17 @@ void InitWebCoreSystemInterface(void)
     INIT(ConvertCharToGlyphs);
     INIT(CreateCustomCFReadStream);
     INIT(CreateNSURLConnectionDelegateProxy);
-    INIT(CreateURLPasteboardFlavorTypeName);
     INIT(CreateURLNPasteboardFlavorTypeName);
+    INIT(CreateURLPasteboardFlavorTypeName);
     INIT(DrawBezeledTextArea);
     INIT(DrawBezeledTextFieldCell);
-    INIT(DrawTextFieldCellFocusRing);
     INIT(DrawFocusRing);
+    INIT(DrawTextFieldCellFocusRing);
     INIT(FontSmoothingModeIsLCD);
     INIT(GetATSStyleGroup);
     INIT(GetCGFontFromNSFont);
     INIT(GetDefaultGlyphForChar);
+    INIT(GetExtensionsForMIMEType);
     INIT(GetFontInLanguageForCharacter);
     INIT(GetFontInLanguageForRange);
     INIT(GetFontMetrics);
@@ -66,10 +67,13 @@ void InitWebCoreSystemInterface(void)
     INIT(GetNSURLResponseCalculatedExpiration);
     INIT(GetNSURLResponseLastModifiedDate);
     INIT(GetNSURLResponseMustRevalidate);
+    INIT(GetPreferredExtensionForMIMEType);
     INIT(InitializeGlyphVector);
+    INIT(NSURLProtocolClassForReqest);
     INIT(PathFromFont);
     INIT(PopupMenu);
     INIT(ReleaseStyleGroup);
+    INIT(SecondsSinceLastInputEvent);
     INIT(SetCGFontRenderingMode);
     INIT(SetDragImage);
     INIT(SetNSURLConnectionDefersCallbacks);
@@ -79,8 +83,7 @@ void InitWebCoreSystemInterface(void)
     INIT(SignalCFReadStreamError);
     INIT(SignalCFReadStreamHasBytes);
     INIT(SupportsMultipartXMixedReplace);
-    INIT(NSURLProtocolClassForReqest);
-    INIT(SecondsSinceLastInputEvent);
+
     
     didInit = true;
 }
index 8f169dff20fa88431cd970ad20c03088fb391da0..ad5123e0d316e196b78de33c11f33f453e2fb079 100644 (file)
     return UI_STRING("no file selected", "text to display in file button used in HTML forms when no file is selected");
 }
 
+- (NSString *)copyImageUnknownFileLabel
+{
+    return UI_STRING("unknown", "Unknown filename");
+}
+
 - (NSMenu *)cellMenuForSearchField
 {
     NSMenu* cellMenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];