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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 view:(NSView*)view { | 123 view:(NSView*)view { |
124 // Save off the RVH so we can tell if it changes during a drag. If it does, | 124 // Save off the RVH so we can tell if it changes during a drag. If it does, |
125 // we need to send a new enter message in draggingUpdated:. | 125 // we need to send a new enter message in draggingUpdated:. |
126 currentRVH_ = webContents_->GetRenderViewHost(); | 126 currentRVH_ = webContents_->GetRenderViewHost(); |
127 | 127 |
128 // Fill out a DropData from pasteboard. | 128 // Fill out a DropData from pasteboard. |
129 std::unique_ptr<DropData> dropData; | 129 std::unique_ptr<DropData> dropData; |
130 dropData.reset(new DropData()); | 130 dropData.reset(new DropData()); |
131 [self populateDropData:dropData.get() | 131 [self populateDropData:dropData.get() |
132 fromPasteboard:[info draggingPasteboard]]; | 132 fromPasteboard:[info draggingPasteboard]]; |
| 133 currentRVH_->FilterDropData(dropData.get()); |
133 | 134 |
134 NSDragOperation mask = [info draggingSourceOperationMask]; | 135 NSDragOperation mask = [info draggingSourceOperationMask]; |
135 | 136 |
136 // Give the delegate an opportunity to cancel the drag. | 137 // Give the delegate an opportunity to cancel the drag. |
137 canceled_ = !webContents_->GetDelegate()->CanDragEnter( | 138 canceled_ = !webContents_->GetDelegate()->CanDragEnter( |
138 webContents_, | 139 webContents_, |
139 *dropData, | 140 *dropData, |
140 static_cast<WebDragOperationsMask>(mask)); | 141 static_cast<WebDragOperationsMask>(mask)); |
141 if (canceled_) | 142 if (canceled_) |
142 return NSDragOperationNone; | 143 return NSDragOperationNone; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 delegate_->OnDrop(); | 248 delegate_->OnDrop(); |
248 | 249 |
249 currentRVH_ = NULL; | 250 currentRVH_ = NULL; |
250 | 251 |
251 // Create the appropriate mouse locations for WebCore. The draggingLocation | 252 // Create the appropriate mouse locations for WebCore. The draggingLocation |
252 // is in window coordinates. Both need to be flipped. | 253 // is in window coordinates. Both need to be flipped. |
253 NSPoint windowPoint = [info draggingLocation]; | 254 NSPoint windowPoint = [info draggingLocation]; |
254 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 255 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
255 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 256 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
256 webContents_->GetRenderViewHost()->DragTargetDrop( | 257 webContents_->GetRenderViewHost()->DragTargetDrop( |
257 gfx::Point(viewPoint.x, viewPoint.y), | 258 *dropData_, gfx::Point(viewPoint.x, viewPoint.y), |
258 gfx::Point(screenPoint.x, screenPoint.y), | 259 gfx::Point(screenPoint.x, screenPoint.y), GetModifierFlags()); |
259 GetModifierFlags()); | |
260 | 260 |
261 dropData_.reset(); | 261 dropData_.reset(); |
262 | 262 |
263 return YES; | 263 return YES; |
264 } | 264 } |
265 | 265 |
266 // Given |data|, which should not be nil, fill it in using the contents of the | 266 // 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 | 267 // given pasteboard. The types handled by this method should be kept in sync |
268 // with [WebContentsViewCocoa registerDragTypes]. | 268 // with [WebContentsViewCocoa registerDragTypes]. |
269 - (void)populateDropData:(DropData*)data | 269 - (void)populateDropData:(DropData*)data |
270 fromPasteboard:(NSPasteboard*)pboard { | 270 fromPasteboard:(NSPasteboard*)pboard { |
271 DCHECK(data); | 271 DCHECK(data); |
272 DCHECK(pboard); | 272 DCHECK(pboard); |
273 NSArray* types = [pboard types]; | 273 NSArray* types = [pboard types]; |
274 | 274 |
275 data->did_originate_from_renderer = | 275 data->did_originate_from_renderer = |
276 [types containsObject:ui::kChromeDragDummyPboardType]; | 276 [types containsObject:ui::kChromeDragDummyPboardType]; |
277 | 277 |
278 // Get URL if possible. To avoid exposing file system paths to web content, | 278 // Get URL if possible. To avoid exposing file system paths to web content, |
279 // filenames in the drag are not converted to file URLs. | 279 // filenames in the drag are not converted to file URLs. |
280 ui::PopulateURLAndTitleFromPasteboard(&data->url, | 280 ui::PopulateURLAndTitleFromPasteboard(&data->url, |
281 &data->url_title, | 281 &data->url_title, |
282 pboard, | 282 pboard, |
283 NO); | 283 NO); |
284 | 284 |
| 285 if (data->url.is_valid()) { |
| 286 data->has_url = true; |
| 287 } |
| 288 |
285 // Get plain text. | 289 // Get plain text. |
286 if ([types containsObject:NSStringPboardType]) { | 290 if ([types containsObject:NSStringPboardType]) { |
287 data->text = base::NullableString16( | 291 data->text = base::NullableString16( |
288 base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]), | 292 base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]), |
289 false); | 293 false); |
290 } | 294 } |
291 | 295 |
292 // Get HTML. If there's no HTML, try RTF. | 296 // Get HTML. If there's no HTML, try RTF. |
293 if ([types containsObject:NSHTMLPboardType]) { | 297 if ([types containsObject:NSHTMLPboardType]) { |
294 NSString* html = [pboard stringForType:NSHTMLPboardType]; | 298 NSString* html = [pboard stringForType:NSHTMLPboardType]; |
(...skipping 28 matching lines...) Expand all Loading... |
323 // Get custom MIME data. | 327 // Get custom MIME data. |
324 if ([types containsObject:ui::kWebCustomDataPboardType]) { | 328 if ([types containsObject:ui::kWebCustomDataPboardType]) { |
325 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; | 329 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; |
326 ui::ReadCustomDataIntoMap([customData bytes], | 330 ui::ReadCustomDataIntoMap([customData bytes], |
327 [customData length], | 331 [customData length], |
328 &data->custom_data); | 332 &data->custom_data); |
329 } | 333 } |
330 } | 334 } |
331 | 335 |
332 @end | 336 @end |
OLD | NEW |