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_dest_mac.h" | 5 #import "content/browser/web_contents/web_drag_dest_mac.h" |
6 | 6 |
7 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
8 | 8 |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 // Given |data|, which should not be nil, fill it in using the contents of the | 247 // Given |data|, which should not be nil, fill it in using the contents of the |
248 // given pasteboard. The types handled by this method should be kept in sync | 248 // given pasteboard. The types handled by this method should be kept in sync |
249 // with [WebContentsViewCocoa registerDragTypes]. | 249 // with [WebContentsViewCocoa registerDragTypes]. |
250 - (void)populateDropData:(DropData*)data | 250 - (void)populateDropData:(DropData*)data |
251 fromPasteboard:(NSPasteboard*)pboard { | 251 fromPasteboard:(NSPasteboard*)pboard { |
252 DCHECK(data); | 252 DCHECK(data); |
253 DCHECK(pboard); | 253 DCHECK(pboard); |
254 NSArray* types = [pboard types]; | 254 NSArray* types = [pboard types]; |
255 | 255 |
| 256 const bool renderer_tainted = |
| 257 [types containsObject:ui::kChromeDragDummyPboardType]; |
| 258 |
256 // Get URL if possible. To avoid exposing file system paths to web content, | 259 // Get URL if possible. To avoid exposing file system paths to web content, |
257 // filenames in the drag are not converted to file URLs. | 260 // filenames in the drag are not converted to file URLs. |
258 ui::PopulateURLAndTitleFromPasteboard(&data->url, | 261 ui::PopulateURLAndTitleFromPasteboard(&data->url, |
259 &data->url_title, | 262 &data->url_title, |
260 pboard, | 263 pboard, |
261 NO); | 264 NO); |
262 | 265 |
263 // Get plain text. | 266 // Get plain text. |
264 if ([types containsObject:NSStringPboardType]) { | 267 if ([types containsObject:NSStringPboardType]) { |
265 data->text = base::NullableString16( | 268 data->text = base::NullableString16( |
266 base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]), | 269 base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]), |
267 false); | 270 false); |
268 } | 271 } |
269 | 272 |
270 // Get HTML. If there's no HTML, try RTF. | 273 // Get HTML. If there's no HTML, try RTF. |
271 if ([types containsObject:NSHTMLPboardType]) { | 274 if ([types containsObject:NSHTMLPboardType]) { |
272 NSString* html = [pboard stringForType:NSHTMLPboardType]; | 275 NSString* html = [pboard stringForType:NSHTMLPboardType]; |
273 data->html = base::NullableString16(base::SysNSStringToUTF16(html), false); | 276 data->html = base::NullableString16(base::SysNSStringToUTF16(html), false); |
274 } else if ([types containsObject:ui::kChromeDragImageHTMLPboardType]) { | 277 } else if ([types containsObject:ui::kChromeDragImageHTMLPboardType]) { |
275 NSString* html = [pboard stringForType:ui::kChromeDragImageHTMLPboardType]; | 278 NSString* html = [pboard stringForType:ui::kChromeDragImageHTMLPboardType]; |
276 data->html = base::NullableString16(base::SysNSStringToUTF16(html), false); | 279 data->html = base::NullableString16(base::SysNSStringToUTF16(html), false); |
277 } else if ([types containsObject:NSRTFPboardType]) { | 280 } else if ([types containsObject:NSRTFPboardType]) { |
278 NSString* html = [pboard htmlFromRtf]; | 281 NSString* html = [pboard htmlFromRtf]; |
279 data->html = base::NullableString16(base::SysNSStringToUTF16(html), false); | 282 data->html = base::NullableString16(base::SysNSStringToUTF16(html), false); |
280 } | 283 } |
281 | 284 |
282 // Get files. | 285 // Get files. |
283 if ([types containsObject:NSFilenamesPboardType]) { | 286 if ([types containsObject:NSFilenamesPboardType] && !renderer_tainted) { |
284 NSArray* files = [pboard propertyListForType:NSFilenamesPboardType]; | 287 NSArray* files = [pboard propertyListForType:NSFilenamesPboardType]; |
285 if ([files isKindOfClass:[NSArray class]] && [files count]) { | 288 if ([files isKindOfClass:[NSArray class]] && [files count]) { |
286 for (NSUInteger i = 0; i < [files count]; i++) { | 289 for (NSUInteger i = 0; i < [files count]; i++) { |
287 NSString* filename = [files objectAtIndex:i]; | 290 NSString* filename = [files objectAtIndex:i]; |
288 BOOL exists = [[NSFileManager defaultManager] | 291 BOOL exists = [[NSFileManager defaultManager] |
289 fileExistsAtPath:filename]; | 292 fileExistsAtPath:filename]; |
290 if (exists) { | 293 if (exists) { |
291 data->filenames.push_back( | 294 data->filenames.push_back( |
292 DropData::FileInfo( | 295 DropData::FileInfo( |
293 base::SysNSStringToUTF16(filename), base::string16())); | 296 base::SysNSStringToUTF16(filename), base::string16())); |
294 } | 297 } |
295 } | 298 } |
296 } | 299 } |
297 } | 300 } |
298 | 301 |
299 // TODO(pinkerton): Get file contents. http://crbug.com/34661 | 302 // TODO(pinkerton): Get file contents. http://crbug.com/34661 |
300 | 303 |
301 // Get custom MIME data. | 304 // Get custom MIME data. |
302 if ([types containsObject:ui::kWebCustomDataPboardType]) { | 305 if ([types containsObject:ui::kWebCustomDataPboardType]) { |
303 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; | 306 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; |
304 ui::ReadCustomDataIntoMap([customData bytes], | 307 ui::ReadCustomDataIntoMap([customData bytes], |
305 [customData length], | 308 [customData length], |
306 &data->custom_data); | 309 &data->custom_data); |
307 } | 310 } |
308 } | 311 } |
309 | 312 |
310 @end | 313 @end |
OLD | NEW |