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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 delegate_->OnDrop(); | 247 delegate_->OnDrop(); |
248 | 248 |
249 currentRVH_ = NULL; | 249 currentRVH_ = NULL; |
250 | 250 |
251 // Create the appropriate mouse locations for WebCore. The draggingLocation | 251 // Create the appropriate mouse locations for WebCore. The draggingLocation |
252 // is in window coordinates. Both need to be flipped. | 252 // is in window coordinates. Both need to be flipped. |
253 NSPoint windowPoint = [info draggingLocation]; | 253 NSPoint windowPoint = [info draggingLocation]; |
254 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 254 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
255 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 255 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
256 webContents_->GetRenderViewHost()->DragTargetDrop( | 256 webContents_->GetRenderViewHost()->DragTargetDrop( |
257 gfx::Point(viewPoint.x, viewPoint.y), | 257 *dropData_, gfx::Point(viewPoint.x, viewPoint.y), |
258 gfx::Point(screenPoint.x, screenPoint.y), | 258 gfx::Point(screenPoint.x, screenPoint.y), GetModifierFlags()); |
259 GetModifierFlags()); | |
260 | 259 |
261 dropData_.reset(); | 260 dropData_.reset(); |
262 | 261 |
263 return YES; | 262 return YES; |
264 } | 263 } |
265 | 264 |
266 // Given |data|, which should not be nil, fill it in using the contents of the | 265 // Given |data|, which should not be nil, fill it in using the contents of the |
267 // given pasteboard. The types handled by this method should be kept in sync | 266 // given pasteboard. The types handled by this method should be kept in sync |
268 // with [WebContentsViewCocoa registerDragTypes]. | 267 // with [WebContentsViewCocoa registerDragTypes]. |
269 - (void)populateDropData:(DropData*)data | 268 - (void)populateDropData:(DropData*)data |
270 fromPasteboard:(NSPasteboard*)pboard { | 269 fromPasteboard:(NSPasteboard*)pboard { |
271 DCHECK(data); | 270 DCHECK(data); |
272 DCHECK(pboard); | 271 DCHECK(pboard); |
273 NSArray* types = [pboard types]; | 272 NSArray* types = [pboard types]; |
274 | 273 |
275 data->did_originate_from_renderer = | 274 data->did_originate_from_renderer = |
276 [types containsObject:ui::kChromeDragDummyPboardType]; | 275 [types containsObject:ui::kChromeDragDummyPboardType]; |
277 | 276 |
278 // Get URL if possible. To avoid exposing file system paths to web content, | 277 // Get URL if possible. To avoid exposing file system paths to web content, |
279 // filenames in the drag are not converted to file URLs. | 278 // filenames in the drag are not converted to file URLs. |
280 ui::PopulateURLAndTitleFromPasteboard(&data->url, | 279 ui::PopulateURLAndTitleFromPasteboard(&data->url, |
281 &data->url_title, | 280 &data->url_title, |
282 pboard, | 281 pboard, |
283 NO); | 282 NO); |
| 283 if (data->url.is_valid()) { |
| 284 data->has_url = true; |
| 285 } |
284 | 286 |
285 // Get plain text. | 287 // Get plain text. |
286 if ([types containsObject:NSStringPboardType]) { | 288 if ([types containsObject:NSStringPboardType]) { |
287 data->text = base::NullableString16( | 289 data->text = base::NullableString16( |
288 base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]), | 290 base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]), |
289 false); | 291 false); |
290 } | 292 } |
291 | 293 |
292 // Get HTML. If there's no HTML, try RTF. | 294 // Get HTML. If there's no HTML, try RTF. |
293 if ([types containsObject:NSHTMLPboardType]) { | 295 if ([types containsObject:NSHTMLPboardType]) { |
(...skipping 29 matching lines...) Expand all Loading... |
323 // Get custom MIME data. | 325 // Get custom MIME data. |
324 if ([types containsObject:ui::kWebCustomDataPboardType]) { | 326 if ([types containsObject:ui::kWebCustomDataPboardType]) { |
325 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; | 327 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; |
326 ui::ReadCustomDataIntoMap([customData bytes], | 328 ui::ReadCustomDataIntoMap([customData bytes], |
327 [customData length], | 329 [customData length], |
328 &data->custom_data); | 330 &data->custom_data); |
329 } | 331 } |
330 } | 332 } |
331 | 333 |
332 @end | 334 @end |
OLD | NEW |