diff options
-rw-r--r-- | content/browser/web_contents/web_drag_dest_mac.mm | 8 | ||||
-rw-r--r-- | content/browser/web_contents/web_drag_source_mac.mm | 45 | ||||
-rw-r--r-- | ui/base/dragdrop/cocoa_dnd_util.h | 7 | ||||
-rw-r--r-- | ui/base/dragdrop/cocoa_dnd_util.mm | 2 |
4 files changed, 40 insertions, 22 deletions
diff --git a/content/browser/web_contents/web_drag_dest_mac.mm b/content/browser/web_contents/web_drag_dest_mac.mm index 7aa4369..e3f7a0e 100644 --- a/content/browser/web_contents/web_drag_dest_mac.mm +++ b/content/browser/web_contents/web_drag_dest_mac.mm @@ -248,9 +248,11 @@ int GetModifierFlags() { // Get HTML. If there's no HTML, try RTF. if ([types containsObject:NSHTMLPboardType]) { - data->html = NullableString16( - base::SysNSStringToUTF16([pboard stringForType:NSHTMLPboardType]), - false); + NSString* html = [pboard stringForType:NSHTMLPboardType]; + data->html = NullableString16(base::SysNSStringToUTF16(html), false); + } else if ([types containsObject:ui::kChromeDragImageHTMLPboardType]) { + NSString* html = [pboard stringForType:ui::kChromeDragImageHTMLPboardType]; + data->html = NullableString16(base::SysNSStringToUTF16(html), false); } else if ([types containsObject:NSRTFPboardType]) { NSString* html = [pboard htmlFromRtf]; data->html = NullableString16(base::SysNSStringToUTF16(html), false); diff --git a/content/browser/web_contents/web_drag_source_mac.mm b/content/browser/web_contents/web_drag_source_mac.mm index fd8390c..5e3a4ea 100644 --- a/content/browser/web_contents/web_drag_source_mac.mm +++ b/content/browser/web_contents/web_drag_source_mac.mm @@ -156,11 +156,12 @@ void PromiseWriterHelper(const WebDropData& drop_data, } // HTML. - if ([type isEqualToString:NSHTMLPboardType]) { + if ([type isEqualToString:NSHTMLPboardType] || + [type isEqualToString:ui::kChromeDragImageHTMLPboardType]) { DCHECK(!dropData_->html.string().empty()); // See comment on |kHtmlHeader| above. [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->html.string()) - forType:NSHTMLPboardType]; + forType:type]; // URL. } else if ([type isEqualToString:NSURLPboardType]) { @@ -365,15 +366,14 @@ void PromiseWriterHelper(const WebDropData& drop_data, - (void)fillPasteboard { DCHECK(pasteboard_.get()); - [pasteboard_ - declareTypes:[NSArray arrayWithObject:ui::kChromeDragDummyPboardType] - owner:contentsView_]; + [pasteboard_ declareTypes:@[ui::kChromeDragDummyPboardType] + owner:contentsView_]; // URL (and title). - if (dropData_->url.is_valid()) - [pasteboard_ addTypes:[NSArray arrayWithObjects:NSURLPboardType, - kNSURLTitlePboardType, nil] + if (dropData_->url.is_valid()) { + [pasteboard_ addTypes:@[NSURLPboardType, kNSURLTitlePboardType] owner:contentsView_]; + } // MIME type. std::string mimeType; @@ -437,25 +437,32 @@ void PromiseWriterHelper(const WebDropData& drop_data, bool hasHTMLData = !dropData_->html.string().empty(); // Mail.app and TextEdit accept drags that have both HTML and image flavors on // them, but don't process them correctly <http://crbug.com/55879>. Therefore, - // omit the HTML flavor if there is an image flavor. (The only time that - // WebKit fills in the WebDropData::file_contents is with an image drop, but - // the MIME time is tested anyway for paranoia's sake.) + // if there is an image flavor, don't put the HTML data on as HTML, but rather + // put it on as this Chrome-only flavor. + // + // (The only time that Blink fills in the WebDropData::file_contents is with + // an image drop, but the MIME time is tested anyway for paranoia's sake.) bool hasImageData = !dropData_->file_contents.empty() && fileUTI_ && UTTypeConformsTo(fileUTI_.get(), kUTTypeImage); - if (hasHTMLData && !hasImageData) - [pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType] - owner:contentsView_]; + if (hasHTMLData) { + if (hasImageData) { + [pasteboard_ addTypes:@[ui::kChromeDragImageHTMLPboardType] + owner:contentsView_]; + } else { + [pasteboard_ addTypes:@[NSHTMLPboardType] owner:contentsView_]; + } + } // Plain text. - if (!dropData_->text.string().empty()) - [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] + if (!dropData_->text.string().empty()) { + [pasteboard_ addTypes:@[NSStringPboardType] owner:contentsView_]; + } if (!dropData_->custom_data.empty()) { - [pasteboard_ - addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] - owner:contentsView_]; + [pasteboard_ addTypes:@[ui::kWebCustomDataPboardType] + owner:contentsView_]; } } diff --git a/ui/base/dragdrop/cocoa_dnd_util.h b/ui/base/dragdrop/cocoa_dnd_util.h index 66ed1a2..8b4d116 100644 --- a/ui/base/dragdrop/cocoa_dnd_util.h +++ b/ui/base/dragdrop/cocoa_dnd_util.h @@ -22,6 +22,13 @@ namespace ui { // associated with it. UI_EXPORT extern NSString* const kChromeDragDummyPboardType; +// Mail.app and TextEdit accept drags that have both HTML and image flavors on +// them, but don't process them correctly <http://crbug.com/55879>. Therefore, +// if there is an image flavor, don't put the HTML data on as HTML, but rather +// put it on as this Chrome-only flavor. External apps won't see HTML but +// Chrome will know enough to read it as HTML. <http://crbug.com/55879> +UI_EXPORT extern NSString* const kChromeDragImageHTMLPboardType; + // Populates the |url| and |title| with URL data in |pboard|. There may be more // than one, but we only handle dropping the first. |url| must not be |NULL|; // |title| is an optional parameter. Returns |YES| if URL data was obtained from diff --git a/ui/base/dragdrop/cocoa_dnd_util.mm b/ui/base/dragdrop/cocoa_dnd_util.mm index 705d077..86c171d 100644 --- a/ui/base/dragdrop/cocoa_dnd_util.mm +++ b/ui/base/dragdrop/cocoa_dnd_util.mm @@ -13,6 +13,8 @@ namespace ui { NSString* const kChromeDragDummyPboardType = @"org.chromium.drag-dummy-type"; +NSString* const kChromeDragImageHTMLPboardType = @"org.chromium.image-html"; + BOOL PopulateURLAndTitleFromPasteboard(GURL* url, string16* title, NSPasteboard* pboard, |