| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"); | 144 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"); |
| 145 | 145 |
| 146 // Be extra paranoid; avoid crashing. | 146 // Be extra paranoid; avoid crashing. |
| 147 if (!dropData_.get()) { | 147 if (!dropData_.get()) { |
| 148 NOTREACHED(); | 148 NOTREACHED(); |
| 149 return; | 149 return; |
| 150 } | 150 } |
| 151 | 151 |
| 152 // HTML. | 152 // HTML. |
| 153 if ([type isEqualToString:NSHTMLPboardType]) { | 153 if ([type isEqualToString:NSHTMLPboardType]) { |
| 154 DCHECK(!dropData_->text_html.empty()); | 154 DCHECK(!dropData_->html.string().empty()); |
| 155 // See comment on |kHtmlHeader| above. | 155 // See comment on |kHtmlHeader| above. |
| 156 [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->text_html) | 156 [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->html.string()) |
| 157 forType:NSHTMLPboardType]; | 157 forType:NSHTMLPboardType]; |
| 158 | 158 |
| 159 // URL. | 159 // URL. |
| 160 } else if ([type isEqualToString:NSURLPboardType]) { | 160 } else if ([type isEqualToString:NSURLPboardType]) { |
| 161 DCHECK(dropData_->url.is_valid()); | 161 DCHECK(dropData_->url.is_valid()); |
| 162 NSURL* url = [NSURL URLWithString:SysUTF8ToNSString(dropData_->url.spec())]; | 162 NSURL* url = [NSURL URLWithString:SysUTF8ToNSString(dropData_->url.spec())]; |
| 163 // If NSURL creation failed, check for a badly-escaped JavaScript URL. | 163 // If NSURL creation failed, check for a badly-escaped JavaScript URL. |
| 164 // Strip out any existing escapes and then re-escape uniformly. | 164 // Strip out any existing escapes and then re-escape uniformly. |
| 165 if (!url && dropData_->url.SchemeIs(chrome::kJavaScriptScheme)) { | 165 if (!url && dropData_->url.SchemeIs(chrome::kJavaScriptScheme)) { |
| 166 net::UnescapeRule::Type unescapeRules = | 166 net::UnescapeRule::Type unescapeRules = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // our image into a TIFF. This is also suboptimal since this is all done | 199 // our image into a TIFF. This is also suboptimal since this is all done |
| 200 // synchronously. I'm not sure there's much we can easily do about it. | 200 // synchronously. I'm not sure there's much we can easily do about it. |
| 201 scoped_nsobject<NSImage> image( | 201 scoped_nsobject<NSImage> image( |
| 202 [[NSImage alloc] initWithData:[NSData | 202 [[NSImage alloc] initWithData:[NSData |
| 203 dataWithBytes:dropData_->file_contents.data() | 203 dataWithBytes:dropData_->file_contents.data() |
| 204 length:dropData_->file_contents.length()]]); | 204 length:dropData_->file_contents.length()]]); |
| 205 [pboard setData:[image TIFFRepresentation] forType:NSTIFFPboardType]; | 205 [pboard setData:[image TIFFRepresentation] forType:NSTIFFPboardType]; |
| 206 | 206 |
| 207 // Plain text. | 207 // Plain text. |
| 208 } else if ([type isEqualToString:NSStringPboardType]) { | 208 } else if ([type isEqualToString:NSStringPboardType]) { |
| 209 DCHECK(!dropData_->plain_text.empty()); | 209 DCHECK(!dropData_->text.string().empty()); |
| 210 [pboard setString:SysUTF16ToNSString(dropData_->plain_text) | 210 [pboard setString:SysUTF16ToNSString(dropData_->text.string()) |
| 211 forType:NSStringPboardType]; | 211 forType:NSStringPboardType]; |
| 212 | 212 |
| 213 // Custom MIME data. | 213 // Custom MIME data. |
| 214 } else if ([type isEqualToString:ui::kWebCustomDataPboardType]) { | 214 } else if ([type isEqualToString:ui::kWebCustomDataPboardType]) { |
| 215 Pickle pickle; | 215 Pickle pickle; |
| 216 ui::WriteCustomDataToPickle(dropData_->custom_data, &pickle); | 216 ui::WriteCustomDataToPickle(dropData_->custom_data, &pickle); |
| 217 [pboard setData:[NSData dataWithBytes:pickle.data() length:pickle.size()] | 217 [pboard setData:[NSData dataWithBytes:pickle.data() length:pickle.size()] |
| 218 forType:ui::kWebCustomDataPboardType]; | 218 forType:ui::kWebCustomDataPboardType]; |
| 219 | 219 |
| 220 // Oops! | 220 // Oops! |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 @implementation WebDragSource (Private) | 368 @implementation WebDragSource (Private) |
| 369 | 369 |
| 370 - (void)fillPasteboard { | 370 - (void)fillPasteboard { |
| 371 DCHECK(pasteboard_.get()); | 371 DCHECK(pasteboard_.get()); |
| 372 | 372 |
| 373 [pasteboard_ | 373 [pasteboard_ |
| 374 declareTypes:[NSArray arrayWithObject:ui::kChromeDragDummyPboardType] | 374 declareTypes:[NSArray arrayWithObject:ui::kChromeDragDummyPboardType] |
| 375 owner:contentsView_]; | 375 owner:contentsView_]; |
| 376 | 376 |
| 377 // HTML. | 377 // HTML. |
| 378 if (!dropData_->text_html.empty()) | 378 if (!dropData_->html.string().empty()) |
| 379 [pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType] | 379 [pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType] |
| 380 owner:contentsView_]; | 380 owner:contentsView_]; |
| 381 | 381 |
| 382 // URL (and title). | 382 // URL (and title). |
| 383 if (dropData_->url.is_valid()) | 383 if (dropData_->url.is_valid()) |
| 384 [pasteboard_ addTypes:[NSArray arrayWithObjects:NSURLPboardType, | 384 [pasteboard_ addTypes:[NSArray arrayWithObjects:NSURLPboardType, |
| 385 kNSURLTitlePboardType, nil] | 385 kNSURLTitlePboardType, nil] |
| 386 owner:contentsView_]; | 386 owner:contentsView_]; |
| 387 | 387 |
| 388 std::string fileExtension; | 388 std::string fileExtension; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 owner:contentsView_]; | 432 owner:contentsView_]; |
| 433 } | 433 } |
| 434 | 434 |
| 435 // For the file promise, we need to specify the extension. | 435 // For the file promise, we need to specify the extension. |
| 436 [pasteboard_ setPropertyList:[NSArray arrayWithObject:fileExtension_] | 436 [pasteboard_ setPropertyList:[NSArray arrayWithObject:fileExtension_] |
| 437 forType:NSFilesPromisePboardType]; | 437 forType:NSFilesPromisePboardType]; |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 // Plain text. | 441 // Plain text. |
| 442 if (!dropData_->plain_text.empty()) | 442 if (!dropData_->text.string().empty()) |
| 443 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] | 443 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] |
| 444 owner:contentsView_]; | 444 owner:contentsView_]; |
| 445 | 445 |
| 446 if (!dropData_->custom_data.empty()) { | 446 if (!dropData_->custom_data.empty()) { |
| 447 [pasteboard_ | 447 [pasteboard_ |
| 448 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] | 448 addTypes:[NSArray arrayWithObject:ui::kWebCustomDataPboardType] |
| 449 owner:contentsView_]; | 449 owner:contentsView_]; |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 - (NSImage*)dragImage { | 453 - (NSImage*)dragImage { |
| 454 if (dragImage_) | 454 if (dragImage_) |
| 455 return dragImage_; | 455 return dragImage_; |
| 456 | 456 |
| 457 // Default to returning a generic image. | 457 // Default to returning a generic image. |
| 458 return gfx::GetCachedImageWithName(@"nav.pdf"); | 458 return gfx::GetCachedImageWithName(@"nav.pdf"); |
| 459 } | 459 } |
| 460 | 460 |
| 461 @end // @implementation WebDragSource (Private) | 461 @end // @implementation WebDragSource (Private) |
| OLD | NEW |