OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "content/browser/web_contents/web_drag_source_mac.h" | 5 #import "content/browser/web_contents/web_drag_source_mac.h" |
6 | 6 |
7 #include <sys/param.h> | 7 #include <sys/param.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 const string16 kHtmlHeader = ASCIIToUTF16( | 149 const string16 kHtmlHeader = ASCIIToUTF16( |
150 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"); | 150 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"); |
151 | 151 |
152 // Be extra paranoid; avoid crashing. | 152 // Be extra paranoid; avoid crashing. |
153 if (!dropData_.get()) { | 153 if (!dropData_.get()) { |
154 NOTREACHED(); | 154 NOTREACHED(); |
155 return; | 155 return; |
156 } | 156 } |
157 | 157 |
158 // HTML. | 158 // HTML. |
159 if ([type isEqualToString:NSHTMLPboardType]) { | 159 if ([type isEqualToString:NSHTMLPboardType] || |
| 160 [type isEqualToString:ui::kChromeDragImageHTMLPboardType]) { |
160 DCHECK(!dropData_->html.string().empty()); | 161 DCHECK(!dropData_->html.string().empty()); |
161 // See comment on |kHtmlHeader| above. | 162 // See comment on |kHtmlHeader| above. |
162 [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->html.string()) | 163 [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->html.string()) |
163 forType:NSHTMLPboardType]; | 164 forType:type]; |
164 | 165 |
165 // URL. | 166 // URL. |
166 } else if ([type isEqualToString:NSURLPboardType]) { | 167 } else if ([type isEqualToString:NSURLPboardType]) { |
167 DCHECK(dropData_->url.is_valid()); | 168 DCHECK(dropData_->url.is_valid()); |
168 NSURL* url = [NSURL URLWithString:SysUTF8ToNSString(dropData_->url.spec())]; | 169 NSURL* url = [NSURL URLWithString:SysUTF8ToNSString(dropData_->url.spec())]; |
169 // If NSURL creation failed, check for a badly-escaped JavaScript URL. | 170 // If NSURL creation failed, check for a badly-escaped JavaScript URL. |
170 // Strip out any existing escapes and then re-escape uniformly. | 171 // Strip out any existing escapes and then re-escape uniformly. |
171 if (!url && dropData_->url.SchemeIs(chrome::kJavaScriptScheme)) { | 172 if (!url && dropData_->url.SchemeIs(chrome::kJavaScriptScheme)) { |
172 net::UnescapeRule::Type unescapeRules = | 173 net::UnescapeRule::Type unescapeRules = |
173 net::UnescapeRule::SPACES | | 174 net::UnescapeRule::SPACES | |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 359 } |
359 | 360 |
360 @end // @implementation WebDragSource | 361 @end // @implementation WebDragSource |
361 | 362 |
362 | 363 |
363 @implementation WebDragSource (Private) | 364 @implementation WebDragSource (Private) |
364 | 365 |
365 - (void)fillPasteboard { | 366 - (void)fillPasteboard { |
366 DCHECK(pasteboard_.get()); | 367 DCHECK(pasteboard_.get()); |
367 | 368 |
368 [pasteboard_ | 369 [pasteboard_ declareTypes:@[ui::kChromeDragDummyPboardType] |
369 declareTypes:[NSArray arrayWithObject:ui::kChromeDragDummyPboardType] | 370 owner:contentsView_]; |
370 owner:contentsView_]; | |
371 | 371 |
372 // URL (and title). | 372 // URL (and title). |
373 if (dropData_->url.is_valid()) | 373 if (dropData_->url.is_valid()) { |
374 [pasteboard_ addTypes:[NSArray arrayWithObjects:NSURLPboardType, | 374 [pasteboard_ addTypes:@[NSURLPboardType, kNSURLTitlePboardType] |
375 kNSURLTitlePboardType, nil] | |
376 owner:contentsView_]; | 375 owner:contentsView_]; |
| 376 } |
377 | 377 |
378 // MIME type. | 378 // MIME type. |
379 std::string mimeType; | 379 std::string mimeType; |
380 | 380 |
381 // File extension. | 381 // File extension. |
382 std::string fileExtension; | 382 std::string fileExtension; |
383 | 383 |
384 // File. | 384 // File. |
385 if (!dropData_->file_contents.empty() || | 385 if (!dropData_->file_contents.empty() || |
386 !dropData_->download_metadata.empty()) { | 386 !dropData_->download_metadata.empty()) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 NSArray* types = @[base::mac::CFToNSCast(fileUTI_.get())]; | 430 NSArray* types = @[base::mac::CFToNSCast(fileUTI_.get())]; |
431 [pasteboard_ addTypes:types owner:contentsView_]; | 431 [pasteboard_ addTypes:types owner:contentsView_]; |
432 } | 432 } |
433 } | 433 } |
434 } | 434 } |
435 | 435 |
436 // HTML. | 436 // HTML. |
437 bool hasHTMLData = !dropData_->html.string().empty(); | 437 bool hasHTMLData = !dropData_->html.string().empty(); |
438 // Mail.app and TextEdit accept drags that have both HTML and image flavors on | 438 // Mail.app and TextEdit accept drags that have both HTML and image flavors on |
439 // them, but don't process them correctly <http://crbug.com/55879>. Therefore, | 439 // them, but don't process them correctly <http://crbug.com/55879>. Therefore, |
440 // omit the HTML flavor if there is an image flavor. (The only time that | 440 // if there is an image flavor, don't put the HTML data on as HTML, but rather |
441 // WebKit fills in the WebDropData::file_contents is with an image drop, but | 441 // put it on as this Chrome-only flavor. |
442 // the MIME time is tested anyway for paranoia's sake.) | 442 // |
| 443 // (The only time that Blink fills in the WebDropData::file_contents is with |
| 444 // an image drop, but the MIME time is tested anyway for paranoia's sake.) |
443 bool hasImageData = !dropData_->file_contents.empty() && | 445 bool hasImageData = !dropData_->file_contents.empty() && |
444 fileUTI_ && | 446 fileUTI_ && |
445 UTTypeConformsTo(fileUTI_.get(), kUTTypeImage); | 447 UTTypeConformsTo(fileUTI_.get(), kUTTypeImage); |
446 if (hasHTMLData && !hasImageData) | 448 if (hasHTMLData) { |
447 [pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType] | 449 if (hasImageData) { |
448 owner:contentsView_]; | 450 [pasteboard_ addTypes:@[ui::kChromeDragImageHTMLPboardType] |
| 451 owner:contentsView_]; |
| 452 } else { |
| 453 [pasteboard_ addTypes:@[NSHTMLPboardType] owner:contentsView_]; |
| 454 } |
| 455 } |
449 | 456 |
450 // Plain text. | 457 // Plain text. |
451 if (!dropData_->text.string().empty()) | 458 if (!dropData_->text.string().empty()) { |
452 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] | 459 [pasteboard_ addTypes:@[NSStringPboardType] |
453 owner:contentsView_]; | 460 owner:contentsView_]; |
| 461 } |
454 | 462 |
455 if (!dropData_->custom_data.empty()) { | 463 if (!dropData_->custom_data.empty()) { |
456 [pasteboard_ | 464 [pasteboard_ addTypes:@[ui::kWebCustomDataPboardType] |
457 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] | 465 owner:contentsView_]; |
458 owner:contentsView_]; | |
459 } | 466 } |
460 } | 467 } |
461 | 468 |
462 - (NSImage*)dragImage { | 469 - (NSImage*)dragImage { |
463 if (dragImage_) | 470 if (dragImage_) |
464 return dragImage_; | 471 return dragImage_; |
465 | 472 |
466 // Default to returning a generic image. | 473 // Default to returning a generic image. |
467 return content::GetContentClient()->GetNativeImageNamed( | 474 return content::GetContentClient()->GetNativeImageNamed( |
468 IDR_DEFAULT_FAVICON).ToNSImage(); | 475 IDR_DEFAULT_FAVICON).ToNSImage(); |
469 } | 476 } |
470 | 477 |
471 @end // @implementation WebDragSource (Private) | 478 @end // @implementation WebDragSource (Private) |
OLD | NEW |