Reviewed by Ken.
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Mar 2005 18:53:42 +0000 (18:53 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Mar 2005 18:53:42 +0000 (18:53 +0000)
        - fixed <rdar://problem/4031826> REGRESSION (Mail): standalone images from
        Safari can't be pasted into Mail (WebKit part of fix)

        We were always declaring webarchive-related pasteboard types, even in the standalone
        image cases where we had no webarchive. Unfortunately, the WebView pasteboard-related
        API doesn't prevent this kind of thing from happening, because the code that
        declares the types isn't guaranteed to be anywhere near the code that writes
        the pasteboard data.

        After this fix, I discovered that pasting standalone images into Mail still doesn't
        work right, but the remaining issues seem to be entirely in Mail. I wrote up 4041671
        to cover these.

        * Misc.subproj/WebNSPasteboardExtras.h:
        (+[NSPasteboard _web_writableTypesForImageIncludingArchive:]):
        Added boolean parameter; clients must specify whether or not there's an
        archive involved, because the array of types is different if there is.

        * Misc.subproj/WebNSPasteboardExtras.m:
        (_web_writableTypesForImageWithoutArchive):
        new static function, constructs (once) and returns the array of types
        for images that don't have archives
        (_web_writableTypesForImageWithArchive):
        new static function, constructs (once) and returns the array of types
        for images that do have archives
        (+[NSPasteboard _web_writableTypesForImageIncludingArchive:]):
        added boolean parameter, now calls one of the two new static functions

        (-[NSPasteboard _web_writeImage:URL:title:archive:types:]):
        added asserts that we aren't declaring the archive types if we don't have archive data

        (-[NSPasteboard _web_declareAndWriteDragImage:URL:title:archive:source:]):
        updated to pass parameter to _web_writableTypesForImageIncludingArchive:

        * WebView.subproj/WebDefaultContextMenuDelegate.m:
        (-[WebDefaultUIDelegate copyImageToClipboard:]):
        updated to pass parameter to _web_writableTypesForImageIncludingArchive:

        * WebView.subproj/WebImageView.m:
        (-[WebImageView copy:]):
        updated to pass parameter to _web_writableTypesForImageIncludingArchive:

        * WebView.subproj/WebView.m:
        (-[WebView pasteboardTypesForElement:]):
        updated to pass parameter to _web_writableTypesForImageIncludingArchive:

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

WebKit/ChangeLog
WebKit/Misc.subproj/WebNSPasteboardExtras.h
WebKit/Misc.subproj/WebNSPasteboardExtras.m
WebKit/WebView.subproj/WebDefaultContextMenuDelegate.m
WebKit/WebView.subproj/WebImageView.m
WebKit/WebView.subproj/WebView.m

index 93ada3f32fea7d02f621e44496541a09e8da9cc5..e8c4eb9eac3c1f9c1f219314c166c795c40a3aa2 100644 (file)
@@ -1,3 +1,53 @@
+2005-03-08  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Ken.
+        
+        - fixed <rdar://problem/4031826> REGRESSION (Mail): standalone images from 
+        Safari can't be pasted into Mail (WebKit part of fix)
+        
+        We were always declaring webarchive-related pasteboard types, even in the standalone
+        image cases where we had no webarchive. Unfortunately, the WebView pasteboard-related
+        API doesn't prevent this kind of thing from happening, because the code that
+        declares the types isn't guaranteed to be anywhere near the code that writes
+        the pasteboard data.
+        
+        After this fix, I discovered that pasting standalone images into Mail still doesn't
+        work right, but the remaining issues seem to be entirely in Mail. I wrote up 4041671
+        to cover these.
+
+        * Misc.subproj/WebNSPasteboardExtras.h:
+        (+[NSPasteboard _web_writableTypesForImageIncludingArchive:]):
+        Added boolean parameter; clients must specify whether or not there's an
+        archive involved, because the array of types is different if there is.
+
+        * Misc.subproj/WebNSPasteboardExtras.m:
+        (_web_writableTypesForImageWithoutArchive):
+        new static function, constructs (once) and returns the array of types
+        for images that don't have archives
+        (_web_writableTypesForImageWithArchive):
+        new static function, constructs (once) and returns the array of types
+        for images that do have archives
+        (+[NSPasteboard _web_writableTypesForImageIncludingArchive:]):
+        added boolean parameter, now calls one of the two new static functions
+        
+        (-[NSPasteboard _web_writeImage:URL:title:archive:types:]):
+        added asserts that we aren't declaring the archive types if we don't have archive data
+        
+        (-[NSPasteboard _web_declareAndWriteDragImage:URL:title:archive:source:]):
+        updated to pass parameter to _web_writableTypesForImageIncludingArchive:
+        
+        * WebView.subproj/WebDefaultContextMenuDelegate.m:
+        (-[WebDefaultUIDelegate copyImageToClipboard:]):
+        updated to pass parameter to _web_writableTypesForImageIncludingArchive:
+
+        * WebView.subproj/WebImageView.m:
+        (-[WebImageView copy:]):
+        updated to pass parameter to _web_writableTypesForImageIncludingArchive:
+
+        * WebView.subproj/WebView.m:
+        (-[WebView pasteboardTypesForElement:]):
+        updated to pass parameter to _web_writableTypesForImageIncludingArchive:
+
 2005-03-07  Richard Williamson   <rjw@apple.com>
 
        More bullet proofing for <rdar://problem/4038304> CrashTracer: ....9 crashes at com.apple.WebKit: -[WebTextRenderer initWithFont:usingPrinterFont:] + 840
index c59fcbdf5a3c9f166533f5168e58af023294a7f7..ecd158d77962ab4af9bb855360711dfcec317589 100644 (file)
@@ -20,7 +20,7 @@ extern NSString *WebURLNamePboardType;
 + (NSArray *)_web_writableTypesForURL;
 
 // Returns the array of types that _web_writeImage::::: handles.
-+ (NSArray *)_web_writableTypesForImage;
++ (NSArray *)_web_writableTypesForImageIncludingArchive:(BOOL)hasArchive;
 
 // Returns the array of drag types that _web_bestURL handles; note that the presence
 // of one or more of these drag types on the pasteboard is not a guarantee that
index f6173c435ab440825f12b6d60bdcfbab3651a63c..49da56edef0ee2be4f8c738d59578ebb20959202 100644 (file)
@@ -65,20 +65,34 @@ NSString *WebURLNamePboardType = nil;
     return types;
 }
 
-+ (NSArray *)_web_writableTypesForImage
+static NSArray *_web_writableTypesForImageWithoutArchive ()
 {
     static NSMutableArray *types = nil;
-    if (!types) {
-        types = [[NSMutableArray alloc] initWithObjects:
-            NSTIFFPboardType, 
-            NSRTFDPboardType, 
-            WebArchivePboardType, 
-            nil];
+    if (types == nil) {
+        types = [[NSMutableArray alloc] initWithObjects:NSTIFFPboardType, nil];
         [types addObjectsFromArray:[NSPasteboard _web_writableTypesForURL]];
     }
     return types;
 }
 
+static NSArray *_web_writableTypesForImageWithArchive ()
+{
+    static NSMutableArray *types = nil;
+    if (types == nil) {
+        types = [[NSMutableArray alloc] initWithArray:_web_writableTypesForImageWithoutArchive()];
+        [types addObject:NSRTFDPboardType];
+        [types addObject:WebArchivePboardType];
+    }
+    return types;
+}
+
++ (NSArray *)_web_writableTypesForImageIncludingArchive:(BOOL)hasArchive
+{
+    return hasArchive 
+        ? _web_writableTypesForImageWithArchive()
+        : _web_writableTypesForImageWithoutArchive();
+}
+
 + (NSArray *)_web_dragTypesForURL
 {
     return [NSArray arrayWithObjects:
@@ -205,6 +219,10 @@ NSString *WebURLNamePboardType = nil;
         if ([types containsObject:WebArchivePboardType]) {
             [self setData:[archive data] forType:WebArchivePboardType];
         }
+    } else {
+        // We should not have declared types that we aren't going to write (4031826).
+        ASSERT(![types containsObject:NSRTFDPboardType]);
+        ASSERT(![types containsObject:WebArchivePboardType]);
     }
 }
 
@@ -216,7 +234,7 @@ NSString *WebURLNamePboardType = nil;
 {
     ASSERT(self == [NSPasteboard pasteboardWithName:NSDragPboard]);
     NSMutableArray *types = [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil];
-    [types addObjectsFromArray:[NSPasteboard _web_writableTypesForImage]];
+    [types addObjectsFromArray:[NSPasteboard _web_writableTypesForImageIncludingArchive:(archive != nil)]];
     [self declareTypes:types owner:source];    
     [self _web_writeImage:image URL:URL title:title archive:archive types:types];
     [types release];
index 753329b2e1fea7223b34bcde159480d44f66d6fc..0b5c5de1d44473b7cd4da747bade6017826e73e3 100644 (file)
@@ -369,7 +369,7 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
 {
     NSDictionary *element = [sender representedObject];
     NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
-    NSArray *types = [NSPasteboard _web_writableTypesForImage];
+    NSArray *types = [NSPasteboard _web_writableTypesForImageIncludingArchive:([element objectForKey:WebElementDOMNodeKey] != nil)];
     [pasteboard declareTypes:types owner:self];
     [[[element objectForKey:WebElementFrameKey] webView] _writeImageElement:element 
                                                         withPasteboardTypes:types 
index 5bc790d56b6736f7e66b9a139d3c6a1d9a90d055..ff97c7f7f1fe8b6e859db5a35eb4f5f56c8a4da7 100644 (file)
 
 - (void)copy:(id)sender
 {
-    [self writeImageToPasteboard:[NSPasteboard generalPasteboard] types:[NSPasteboard _web_writableTypesForImage]];
+    [self writeImageToPasteboard:[NSPasteboard generalPasteboard] types:[NSPasteboard _web_writableTypesForImageIncludingArchive:([rep archive] != nil)]];
 }
 
 - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types
index 24c28b00a75cea8c927dd8c7902e5ea9d06b41b4..ec0ad5a30b4fb901788027a7a3440d8e8bff397c 100644 (file)
@@ -2244,7 +2244,7 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
 - (NSArray *)pasteboardTypesForElement:(NSDictionary *)element
 {
     if ([element objectForKey:WebElementImageURLKey] != nil) {
-        return [NSPasteboard _web_writableTypesForImage];
+        return [NSPasteboard _web_writableTypesForImageIncludingArchive:([element objectForKey:WebElementDOMNodeKey] != nil)];
     } else if ([element objectForKey:WebElementLinkURLKey] != nil) {
         return [NSPasteboard _web_writableTypesForURL];
     } else if ([[element objectForKey:WebElementIsSelectedKey] boolValue]) {