summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/DEPS1
-rw-r--r--app/clipboard/clipboard_mac.mm16
-rw-r--r--chrome/browser/cocoa/web_drop_target.mm7
-rw-r--r--third_party/mozilla/NSPasteboard+Utils.h7
-rw-r--r--third_party/mozilla/NSPasteboard+Utils.mm25
-rw-r--r--third_party/mozilla/README.chromium1
6 files changed, 52 insertions, 5 deletions
diff --git a/app/DEPS b/app/DEPS
index 2b51fbb..27ac0d7 100644
--- a/app/DEPS
+++ b/app/DEPS
@@ -4,4 +4,5 @@ include_rules = [
"+grit/app_strings.h",
"+net",
"+skia",
+ "+third_party/mozilla",
]
diff --git a/app/clipboard/clipboard_mac.mm b/app/clipboard/clipboard_mac.mm
index 4673e6e..7ae3a1b 100644
--- a/app/clipboard/clipboard_mac.mm
+++ b/app/clipboard/clipboard_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,6 +14,7 @@
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "gfx/size.h"
+#import "third_party/mozilla/NSPasteboard+Utils.h"
namespace {
@@ -165,6 +166,12 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format,
NSPasteboard* pb = GetPasteboard();
NSArray* types = [pb types];
+ // Safari only places RTF on the pasteboard, never HTML. We can convert RTF
+ // to HTML, so the presence of either indicates success when looking for HTML.
+ if ([format_ns isEqualToString:NSHTMLPboardType]) {
+ return [types containsObject:NSHTMLPboardType] ||
+ [types containsObject:NSRTFPboardType];
+ }
return [types containsObject:format_ns];
}
@@ -195,11 +202,14 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup,
DCHECK_EQ(buffer, BUFFER_STANDARD);
if (markup) {
NSPasteboard* pb = GetPasteboard();
- NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType,
+ NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType,
+ NSRTFPboardType,
NSStringPboardType,
nil];
- NSString *bestType = [pb availableTypeFromArray:supportedTypes];
+ NSString* bestType = [pb availableTypeFromArray:supportedTypes];
NSString* contents = [pb stringForType:bestType];
+ if ([bestType isEqualToString:NSRTFPboardType])
+ contents = [pb htmlFromRtf];
UTF8ToUTF16([contents UTF8String],
[contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
markup);
diff --git a/chrome/browser/cocoa/web_drop_target.mm b/chrome/browser/cocoa/web_drop_target.mm
index 68c0b79..915990a 100644
--- a/chrome/browser/cocoa/web_drop_target.mm
+++ b/chrome/browser/cocoa/web_drop_target.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -253,10 +253,13 @@ using WebKit::WebDragOperationsMask;
base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]);
}
- // Get HTML.
+ // Get HTML. If there's no HTML, try RTF.
if ([types containsObject:NSHTMLPboardType]) {
data->text_html =
base::SysNSStringToUTF16([pboard stringForType:NSHTMLPboardType]);
+ } else if ([types containsObject:NSRTFPboardType]) {
+ NSString* html = [pboard htmlFromRtf];
+ data->text_html = base::SysNSStringToUTF16(html);
}
// Get files.
diff --git a/third_party/mozilla/NSPasteboard+Utils.h b/third_party/mozilla/NSPasteboard+Utils.h
index c75de6a..79d3bfb 100644
--- a/third_party/mozilla/NSPasteboard+Utils.h
+++ b/third_party/mozilla/NSPasteboard+Utils.h
@@ -58,3 +58,10 @@ extern NSString* const kWebURLsWithTitlesPboardType;
@end
+@interface NSPasteboard(ChromiumHTMLUtils)
+
+// Returns the HTML converted from RTF data on the pasteboard. If there is
+// none, returns an empty string.
+- (NSString*)htmlFromRtf;
+
+@end
diff --git a/third_party/mozilla/NSPasteboard+Utils.mm b/third_party/mozilla/NSPasteboard+Utils.mm
index 8ac1ba5..0af5c48 100644
--- a/third_party/mozilla/NSPasteboard+Utils.mm
+++ b/third_party/mozilla/NSPasteboard+Utils.mm
@@ -279,3 +279,28 @@ NSString* const kWebURLsWithTitlesPboardType = @"WebURLsWithTitlesPboardType";
return NO;
}
@end
+
+@implementation NSPasteboard(ChromiumHTMLUtils)
+
+// Convert the RTF to HTML via an NSAttributedString.
+- (NSString*)htmlFromRtf {
+ if (![[self types] containsObject:NSRTFPboardType])
+ return @"";
+
+ NSAttributedString* attributed =
+ [[[NSAttributedString alloc]
+ initWithRTF:[self dataForType:NSRTFPboardType]
+ documentAttributes:nil] autorelease];
+ NSDictionary* attributeDict =
+ [NSDictionary dictionaryWithObject:NSHTMLTextDocumentType
+ forKey:NSDocumentTypeDocumentAttribute];
+ NSData* htmlData =
+ [attributed dataFromRange:NSMakeRange(0, [attributed length])
+ documentAttributes:attributeDict
+ error:nil];
+ // According to the docs, NSHTMLTextDocumentType is UTF8.
+ return [[[NSString alloc]
+ initWithData:htmlData encoding:NSUTF8StringEncoding] autorelease];
+}
+
+@end
diff --git a/third_party/mozilla/README.chromium b/third_party/mozilla/README.chromium
index fc5779c..fe93bb8 100644
--- a/third_party/mozilla/README.chromium
+++ b/third_party/mozilla/README.chromium
@@ -19,3 +19,4 @@ Local modifications:
- NSPasteboard+Utils.mm was modified to add an argument to
-[NSPasteboard getURLs:andTitles:] to determine whether or not filenames in
the drag should be converted to file URLs.
+ -[NSPasteboard htmlFromRtf] added to do rtf->html conversion.