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/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 336 |
337 @implementation WebDragSource (Private) | 337 @implementation WebDragSource (Private) |
338 | 338 |
339 - (void)fillPasteboard { | 339 - (void)fillPasteboard { |
340 DCHECK(pasteboard_.get()); | 340 DCHECK(pasteboard_.get()); |
341 | 341 |
342 [pasteboard_ | 342 [pasteboard_ |
343 declareTypes:[NSArray arrayWithObject:ui::kChromeDragDummyPboardType] | 343 declareTypes:[NSArray arrayWithObject:ui::kChromeDragDummyPboardType] |
344 owner:contentsView_]; | 344 owner:contentsView_]; |
345 | 345 |
346 // HTML. | |
347 if (!dropData_->html.string().empty()) | |
348 [pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType] | |
349 owner:contentsView_]; | |
350 | |
351 // URL (and title). | 346 // URL (and title). |
352 if (dropData_->url.is_valid()) { | 347 if (dropData_->url.is_valid()) { |
353 NSURL* url = [NSURL URLWithString:SysUTF8ToNSString(dropData_->url.spec())]; | 348 NSURL* url = [NSURL URLWithString:SysUTF8ToNSString(dropData_->url.spec())]; |
354 // If NSURL creation failed, check for a badly-escaped JavaScript URL. | 349 // If NSURL creation failed, check for a badly-escaped JavaScript URL. |
355 // Strip out any existing escapes and then re-escape uniformly. | 350 // Strip out any existing escapes and then re-escape uniformly. |
356 if (!url && dropData_->url.SchemeIs(chrome::kJavaScriptScheme)) { | 351 if (!url && dropData_->url.SchemeIs(chrome::kJavaScriptScheme)) { |
357 net::UnescapeRule::Type unescapeRules = | 352 net::UnescapeRule::Type unescapeRules = |
358 net::UnescapeRule::SPACES | | 353 net::UnescapeRule::SPACES | |
359 net::UnescapeRule::URL_SPECIAL_CHARS | | 354 net::UnescapeRule::URL_SPECIAL_CHARS | |
360 net::UnescapeRule::CONTROL_CHARS; | 355 net::UnescapeRule::CONTROL_CHARS; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 [pasteboard_ setPropertyList:@[SysUTF8ToNSString(fileExtension.substr(1))] | 421 [pasteboard_ setPropertyList:@[SysUTF8ToNSString(fileExtension.substr(1))] |
427 forType:NSFilesPromisePboardType]; | 422 forType:NSFilesPromisePboardType]; |
428 | 423 |
429 if (!dropData_->file_contents.empty()) { | 424 if (!dropData_->file_contents.empty()) { |
430 NSArray* types = @[base::mac::CFToNSCast(fileUTI_.get())]; | 425 NSArray* types = @[base::mac::CFToNSCast(fileUTI_.get())]; |
431 [pasteboard_ addTypes:types owner:contentsView_]; | 426 [pasteboard_ addTypes:types owner:contentsView_]; |
432 } | 427 } |
433 } | 428 } |
434 } | 429 } |
435 | 430 |
| 431 // HTML. |
| 432 bool hasHTMLData = !dropData_->html.string().empty(); |
| 433 // Mail.app and TextEdit accept drags that have both HTML and image flavors on |
| 434 // them, but don't process them correctly <http://crbug.com/55879>. Therefore, |
| 435 // omit the HTML flavor if there is an image flavor. (The only time that |
| 436 // WebKit fills in the WebDropData::file_contents is with an image drop, but |
| 437 // the MIME time is tested anyway for paranoia's sake.) |
| 438 bool hasImageData = !dropData_->file_contents.empty() && |
| 439 fileUTI_ && |
| 440 UTTypeConformsTo(fileUTI_.get(), kUTTypeImage); |
| 441 if (hasHTMLData && !hasImageData) |
| 442 [pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType] |
| 443 owner:contentsView_]; |
| 444 |
436 // Plain text. | 445 // Plain text. |
437 if (!dropData_->text.string().empty()) | 446 if (!dropData_->text.string().empty()) |
438 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] | 447 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] |
439 owner:contentsView_]; | 448 owner:contentsView_]; |
440 | 449 |
441 if (!dropData_->custom_data.empty()) { | 450 if (!dropData_->custom_data.empty()) { |
442 [pasteboard_ | 451 [pasteboard_ |
443 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] | 452 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] |
444 owner:contentsView_]; | 453 owner:contentsView_]; |
445 } | 454 } |
446 } | 455 } |
447 | 456 |
448 - (NSImage*)dragImage { | 457 - (NSImage*)dragImage { |
449 if (dragImage_) | 458 if (dragImage_) |
450 return dragImage_; | 459 return dragImage_; |
451 | 460 |
452 // Default to returning a generic image. | 461 // Default to returning a generic image. |
453 return content::GetContentClient()->GetNativeImageNamed( | 462 return content::GetContentClient()->GetNativeImageNamed( |
454 IDR_DEFAULT_FAVICON).ToNSImage(); | 463 IDR_DEFAULT_FAVICON).ToNSImage(); |
455 } | 464 } |
456 | 465 |
457 @end // @implementation WebDragSource (Private) | 466 @end // @implementation WebDragSource (Private) |
OLD | NEW |