Chromium Code Reviews| 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 UTTypeConformsTo(fileUTI_.get(), kUTTypeImage); | |
|
Nico
2012/12/26 21:52:55
fileUTI_ is only set if !mimeType.empty(). Since t
Avi (use Gerrit)
2012/12/26 22:22:10
True. Fixed. I don't want to trace through webkit
| |
| 440 if (hasHTMLData && !hasImageData) | |
| 441 [pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType] | |
| 442 owner:contentsView_]; | |
| 443 | |
| 436 // Plain text. | 444 // Plain text. |
| 437 if (!dropData_->text.string().empty()) | 445 if (!dropData_->text.string().empty()) |
| 438 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] | 446 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] |
| 439 owner:contentsView_]; | 447 owner:contentsView_]; |
| 440 | 448 |
| 441 if (!dropData_->custom_data.empty()) { | 449 if (!dropData_->custom_data.empty()) { |
| 442 [pasteboard_ | 450 [pasteboard_ |
| 443 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] | 451 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] |
| 444 owner:contentsView_]; | 452 owner:contentsView_]; |
| 445 } | 453 } |
| 446 } | 454 } |
| 447 | 455 |
| 448 - (NSImage*)dragImage { | 456 - (NSImage*)dragImage { |
| 449 if (dragImage_) | 457 if (dragImage_) |
| 450 return dragImage_; | 458 return dragImage_; |
| 451 | 459 |
| 452 // Default to returning a generic image. | 460 // Default to returning a generic image. |
| 453 return content::GetContentClient()->GetNativeImageNamed( | 461 return content::GetContentClient()->GetNativeImageNamed( |
| 454 IDR_DEFAULT_FAVICON).ToNSImage(); | 462 IDR_DEFAULT_FAVICON).ToNSImage(); |
| 455 } | 463 } |
| 456 | 464 |
| 457 @end // @implementation WebDragSource (Private) | 465 @end // @implementation WebDragSource (Private) |
| OLD | NEW |