Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: content/browser/web_contents/web_drag_dest_mac.mm

Issue 18281002: Move WebDropData to content::DropData and split off conversion function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac build error. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "content/browser/web_contents/web_contents_impl.h" 11 #include "content/browser/web_contents/web_contents_impl.h"
12 #include "content/public/browser/web_contents_delegate.h" 12 #include "content/public/browser/web_contents_delegate.h"
13 #include "content/public/browser/web_drag_dest_delegate.h" 13 #include "content/public/browser/web_drag_dest_delegate.h"
14 #include "content/public/common/drop_data.h"
14 #import "third_party/mozilla/NSPasteboard+Utils.h" 15 #import "third_party/mozilla/NSPasteboard+Utils.h"
15 #include "third_party/WebKit/public/web/WebInputEvent.h" 16 #include "third_party/WebKit/public/web/WebInputEvent.h"
16 #include "ui/base/clipboard/custom_data_helper.h" 17 #include "ui/base/clipboard/custom_data_helper.h"
17 #import "ui/base/dragdrop/cocoa_dnd_util.h" 18 #import "ui/base/dragdrop/cocoa_dnd_util.h"
18 #include "ui/base/window_open_disposition.h" 19 #include "ui/base/window_open_disposition.h"
19 #include "webkit/common/webdropdata.h"
20 20
21 using WebKit::WebDragOperationsMask; 21 using WebKit::WebDragOperationsMask;
22 using content::DropData;
22 using content::OpenURLParams; 23 using content::OpenURLParams;
23 using content::Referrer; 24 using content::Referrer;
24 using content::WebContentsImpl; 25 using content::WebContentsImpl;
25 26
26 int GetModifierFlags() { 27 int GetModifierFlags() {
27 int modifier_state = 0; 28 int modifier_state = 0;
28 UInt32 currentModifiers = GetCurrentKeyModifiers(); 29 UInt32 currentModifiers = GetCurrentKeyModifiers();
29 if (currentModifiers & ::shiftKey) 30 if (currentModifiers & ::shiftKey)
30 modifier_state |= WebKit::WebInputEvent::ShiftKey; 31 modifier_state |= WebKit::WebInputEvent::ShiftKey;
31 if (currentModifiers & ::controlKey) 32 if (currentModifiers & ::controlKey)
(...skipping 11 matching lines...) Expand all
43 // drag&drop messages to WebCore and handle navigation on a successful drop 44 // drag&drop messages to WebCore and handle navigation on a successful drop
44 // (if necessary). 45 // (if necessary).
45 - (id)initWithWebContentsImpl:(WebContentsImpl*)contents { 46 - (id)initWithWebContentsImpl:(WebContentsImpl*)contents {
46 if ((self = [super init])) { 47 if ((self = [super init])) {
47 webContents_ = contents; 48 webContents_ = contents;
48 canceled_ = false; 49 canceled_ = false;
49 } 50 }
50 return self; 51 return self;
51 } 52 }
52 53
53 - (WebDropData*)currentDropData { 54 - (DropData*)currentDropData {
54 return dropData_.get(); 55 return dropData_.get();
55 } 56 }
56 57
57 - (void)setDragDelegate:(content::WebDragDestDelegate*)delegate { 58 - (void)setDragDelegate:(content::WebDragDestDelegate*)delegate {
58 delegate_ = delegate; 59 delegate_ = delegate;
59 } 60 }
60 61
61 // Call to set whether or not we should allow the drop. Takes effect the 62 // Call to set whether or not we should allow the drop. Takes effect the
62 // next time |-draggingUpdated:| is called. 63 // next time |-draggingUpdated:| is called.
63 - (void)setCurrentOperation:(NSDragOperation)operation { 64 - (void)setCurrentOperation:(NSDragOperation)operation {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 99
99 // Messages to send during the tracking of a drag, usually upon receiving 100 // Messages to send during the tracking of a drag, usually upon receiving
100 // calls from the view system. Communicates the drag messages to WebCore. 101 // calls from the view system. Communicates the drag messages to WebCore.
101 102
102 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info 103 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info
103 view:(NSView*)view { 104 view:(NSView*)view {
104 // Save off the RVH so we can tell if it changes during a drag. If it does, 105 // Save off the RVH so we can tell if it changes during a drag. If it does,
105 // we need to send a new enter message in draggingUpdated:. 106 // we need to send a new enter message in draggingUpdated:.
106 currentRVH_ = webContents_->GetRenderViewHost(); 107 currentRVH_ = webContents_->GetRenderViewHost();
107 108
108 // Fill out a WebDropData from pasteboard. 109 // Fill out a DropData from pasteboard.
109 scoped_ptr<WebDropData> dropData; 110 scoped_ptr<DropData> dropData;
110 dropData.reset(new WebDropData()); 111 dropData.reset(new DropData());
111 [self populateWebDropData:dropData.get() 112 [self populateDropData:dropData.get()
112 fromPasteboard:[info draggingPasteboard]]; 113 fromPasteboard:[info draggingPasteboard]];
113 114
114 NSDragOperation mask = [info draggingSourceOperationMask]; 115 NSDragOperation mask = [info draggingSourceOperationMask];
115 116
116 // Give the delegate an opportunity to cancel the drag. 117 // Give the delegate an opportunity to cancel the drag.
117 canceled_ = !webContents_->GetDelegate()->CanDragEnter( 118 canceled_ = !webContents_->GetDelegate()->CanDragEnter(
118 webContents_, 119 webContents_,
119 *dropData, 120 *dropData,
120 static_cast<WebDragOperationsMask>(mask)); 121 static_cast<WebDragOperationsMask>(mask));
121 if (canceled_) 122 if (canceled_)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 GetModifierFlags()); 240 GetModifierFlags());
240 241
241 dropData_.reset(); 242 dropData_.reset();
242 243
243 return YES; 244 return YES;
244 } 245 }
245 246
246 // 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
247 // 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
248 // with [WebContentsViewCocoa registerDragTypes]. 249 // with [WebContentsViewCocoa registerDragTypes].
249 - (void)populateWebDropData:(WebDropData*)data 250 - (void)populateDropData:(DropData*)data
250 fromPasteboard:(NSPasteboard*)pboard { 251 fromPasteboard:(NSPasteboard*)pboard {
251 DCHECK(data); 252 DCHECK(data);
252 DCHECK(pboard); 253 DCHECK(pboard);
253 NSArray* types = [pboard types]; 254 NSArray* types = [pboard types];
254 255
255 // Get URL if possible. To avoid exposing file system paths to web content, 256 // Get URL if possible. To avoid exposing file system paths to web content,
256 // filenames in the drag are not converted to file URLs. 257 // filenames in the drag are not converted to file URLs.
257 ui::PopulateURLAndTitleFromPasteboard(&data->url, 258 ui::PopulateURLAndTitleFromPasteboard(&data->url,
258 &data->url_title, 259 &data->url_title,
259 pboard, 260 pboard,
260 NO); 261 NO);
(...skipping 20 matching lines...) Expand all
281 // Get files. 282 // Get files.
282 if ([types containsObject:NSFilenamesPboardType]) { 283 if ([types containsObject:NSFilenamesPboardType]) {
283 NSArray* files = [pboard propertyListForType:NSFilenamesPboardType]; 284 NSArray* files = [pboard propertyListForType:NSFilenamesPboardType];
284 if ([files isKindOfClass:[NSArray class]] && [files count]) { 285 if ([files isKindOfClass:[NSArray class]] && [files count]) {
285 for (NSUInteger i = 0; i < [files count]; i++) { 286 for (NSUInteger i = 0; i < [files count]; i++) {
286 NSString* filename = [files objectAtIndex:i]; 287 NSString* filename = [files objectAtIndex:i];
287 BOOL exists = [[NSFileManager defaultManager] 288 BOOL exists = [[NSFileManager defaultManager]
288 fileExistsAtPath:filename]; 289 fileExistsAtPath:filename];
289 if (exists) { 290 if (exists) {
290 data->filenames.push_back( 291 data->filenames.push_back(
291 WebDropData::FileInfo( 292 DropData::FileInfo(
292 base::SysNSStringToUTF16(filename), string16())); 293 base::SysNSStringToUTF16(filename), string16()));
293 } 294 }
294 } 295 }
295 } 296 }
296 } 297 }
297 298
298 // TODO(pinkerton): Get file contents. http://crbug.com/34661 299 // TODO(pinkerton): Get file contents. http://crbug.com/34661
299 300
300 // Get custom MIME data. 301 // Get custom MIME data.
301 if ([types containsObject:ui::kWebCustomDataPboardType]) { 302 if ([types containsObject:ui::kWebCustomDataPboardType]) {
302 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; 303 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType];
303 ui::ReadCustomDataIntoMap([customData bytes], 304 ui::ReadCustomDataIntoMap([customData bytes],
304 [customData length], 305 [customData length],
305 &data->custom_data); 306 &data->custom_data);
306 } 307 }
307 } 308 }
308 309
309 @end 310 @end
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_drag_dest_mac.h ('k') | content/browser/web_contents/web_drag_dest_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698