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 // Mail.app and TextEdit don't accept drops with both HTML and file content on | |
| 433 // them <http://crbug.com/55879>. If there is both file content and HTML in | |
| 434 // |dropData_| (as in the case of dragging an image), only provide the file | |
| 435 // data. | |
|
Nico
2012/12/23 00:08:26
How does the HTML content for just an image look?
| |
| 436 if (!dropData_->html.string().empty() && dropData_->file_contents.empty()) | |
| 437 [pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType] | |
| 438 owner:contentsView_]; | |
| 439 | |
| 436 // Plain text. | 440 // Plain text. |
| 437 if (!dropData_->text.string().empty()) | 441 if (!dropData_->text.string().empty()) |
| 438 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] | 442 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] |
| 439 owner:contentsView_]; | 443 owner:contentsView_]; |
| 440 | 444 |
| 441 if (!dropData_->custom_data.empty()) { | 445 if (!dropData_->custom_data.empty()) { |
| 442 [pasteboard_ | 446 [pasteboard_ |
| 443 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] | 447 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] |
| 444 owner:contentsView_]; | 448 owner:contentsView_]; |
| 445 } | 449 } |
| 446 } | 450 } |
| 447 | 451 |
| 448 - (NSImage*)dragImage { | 452 - (NSImage*)dragImage { |
| 449 if (dragImage_) | 453 if (dragImage_) |
| 450 return dragImage_; | 454 return dragImage_; |
| 451 | 455 |
| 452 // Default to returning a generic image. | 456 // Default to returning a generic image. |
| 453 return content::GetContentClient()->GetNativeImageNamed( | 457 return content::GetContentClient()->GetNativeImageNamed( |
| 454 IDR_DEFAULT_FAVICON).ToNSImage(); | 458 IDR_DEFAULT_FAVICON).ToNSImage(); |
| 455 } | 459 } |
| 456 | 460 |
| 457 @end // @implementation WebDragSource (Private) | 461 @end // @implementation WebDragSource (Private) |
| OLD | NEW |