diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-08 18:53:13 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-08 18:53:13 +0000 |
commit | 1d405f743b63398096344c04197ec832449d7f40 (patch) | |
tree | 83cf4b541a525a9d978d5ead3a702a034e9c1109 /content | |
parent | a13b3218e94039d8c1b03b3194e1e061c89d3b50 (diff) | |
download | chromium_src-1d405f743b63398096344c04197ec832449d7f40.zip chromium_src-1d405f743b63398096344c04197ec832449d7f40.tar.gz chromium_src-1d405f743b63398096344c04197ec832449d7f40.tar.bz2 |
Fix dropping images into content editable divs.
Mail.app and TextEdit accept drags that have both HTML and image flavors on them, but don't process them correctly. Therefore,
if there is an image flavor, don't put the HTML data on as HTML, but rather put it on as a special flavor. External apps won't see HTML but Chrome will know enough to read it as HTML.
BUG=55879,225710
TEST=as in bug 225710, doesn't regress bug 55879
Review URL: https://chromiumcodereview.appspot.com/13758002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192853 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-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 |
2 files changed, 31 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_]; } } |