- 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
+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
+ (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
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:
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]);
}
}
{
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];
{
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
- (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
- (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]) {