| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return dragOperationMask_; | 143 return dragOperationMask_; |
| 144 } | 144 } |
| 145 | 145 |
| 146 - (void)lazyWriteToPasteboard:(NSPasteboard*)pboard forType:(NSString*)type { | 146 - (void)lazyWriteToPasteboard:(NSPasteboard*)pboard forType:(NSString*)type { |
| 147 // NSHTMLPboardType requires the character set to be declared. Otherwise, it | 147 // NSHTMLPboardType requires the character set to be declared. Otherwise, it |
| 148 // assumes US-ASCII. Awesome. | 148 // assumes US-ASCII. Awesome. |
| 149 const string16 kHtmlHeader = ASCIIToUTF16( | 149 const string16 kHtmlHeader = ASCIIToUTF16( |
| 150 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"); | 150 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"); |
| 151 | 151 |
| 152 // Be extra paranoid; avoid crashing. | 152 // Be extra paranoid; avoid crashing. |
| 153 if (!dropData_.get()) { | 153 if (!dropData_) { |
| 154 NOTREACHED(); | 154 NOTREACHED(); |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // HTML. | 158 // HTML. |
| 159 if ([type isEqualToString:NSHTMLPboardType] || | 159 if ([type isEqualToString:NSHTMLPboardType] || |
| 160 [type isEqualToString:ui::kChromeDragImageHTMLPboardType]) { | 160 [type isEqualToString:ui::kChromeDragImageHTMLPboardType]) { |
| 161 DCHECK(!dropData_->html.string().empty()); | 161 DCHECK(!dropData_->html.string().empty()); |
| 162 // See comment on |kHtmlHeader| above. | 162 // See comment on |kHtmlHeader| above. |
| 163 [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->html.string()) | 163 [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->html.string()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 180 net::EscapeUrlEncodedData(unescapedUrlString, false); | 180 net::EscapeUrlEncodedData(unescapedUrlString, false); |
| 181 url = [NSURL URLWithString:SysUTF8ToNSString(escapedUrlString)]; | 181 url = [NSURL URLWithString:SysUTF8ToNSString(escapedUrlString)]; |
| 182 } | 182 } |
| 183 [url writeToPasteboard:pboard]; | 183 [url writeToPasteboard:pboard]; |
| 184 // URL title. | 184 // URL title. |
| 185 } else if ([type isEqualToString:kNSURLTitlePboardType]) { | 185 } else if ([type isEqualToString:kNSURLTitlePboardType]) { |
| 186 [pboard setString:SysUTF16ToNSString(dropData_->url_title) | 186 [pboard setString:SysUTF16ToNSString(dropData_->url_title) |
| 187 forType:kNSURLTitlePboardType]; | 187 forType:kNSURLTitlePboardType]; |
| 188 | 188 |
| 189 // File contents. | 189 // File contents. |
| 190 } else if ([type isEqualToString:base::mac::CFToNSCast(fileUTI_.get())]) { | 190 } else if ([type isEqualToString:base::mac::CFToNSCast(fileUTI_)]) { |
| 191 [pboard setData:[NSData dataWithBytes:dropData_->file_contents.data() | 191 [pboard setData:[NSData dataWithBytes:dropData_->file_contents.data() |
| 192 length:dropData_->file_contents.length()] | 192 length:dropData_->file_contents.length()] |
| 193 forType:base::mac::CFToNSCast(fileUTI_.get())]; | 193 forType:base::mac::CFToNSCast(fileUTI_.get())]; |
| 194 | 194 |
| 195 // Plain text. | 195 // Plain text. |
| 196 } else if ([type isEqualToString:NSStringPboardType]) { | 196 } else if ([type isEqualToString:NSStringPboardType]) { |
| 197 DCHECK(!dropData_->text.string().empty()); | 197 DCHECK(!dropData_->text.string().empty()); |
| 198 [pboard setString:SysUTF16ToNSString(dropData_->text.string()) | 198 [pboard setString:SysUTF16ToNSString(dropData_->text.string()) |
| 199 forType:NSStringPboardType]; | 199 forType:NSStringPboardType]; |
| 200 | 200 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 NSRect screenFrame = [[[contentsView_ window] screen] frame]; | 308 NSRect screenFrame = [[[contentsView_ window] screen] frame]; |
| 309 screenPoint.y = screenFrame.size.height - screenPoint.y; | 309 screenPoint.y = screenFrame.size.height - screenPoint.y; |
| 310 | 310 |
| 311 rvh->DragSourceMovedTo(localPoint.x, localPoint.y, | 311 rvh->DragSourceMovedTo(localPoint.x, localPoint.y, |
| 312 screenPoint.x, screenPoint.y); | 312 screenPoint.x, screenPoint.y); |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 | 315 |
| 316 - (NSString*)dragPromisedFileTo:(NSString*)path { | 316 - (NSString*)dragPromisedFileTo:(NSString*)path { |
| 317 // Be extra paranoid; avoid crashing. | 317 // Be extra paranoid; avoid crashing. |
| 318 if (!dropData_.get()) { | 318 if (!dropData_) { |
| 319 NOTREACHED() << "No drag-and-drop data available for promised file."; | 319 NOTREACHED() << "No drag-and-drop data available for promised file."; |
| 320 return nil; | 320 return nil; |
| 321 } | 321 } |
| 322 | 322 |
| 323 base::FilePath fileName = downloadFileName_.empty() ? | 323 base::FilePath fileName = downloadFileName_.empty() ? |
| 324 GetFileNameFromDragData(*dropData_) : downloadFileName_; | 324 GetFileNameFromDragData(*dropData_) : downloadFileName_; |
| 325 base::FilePath filePath(SysNSStringToUTF8(path)); | 325 base::FilePath filePath(SysNSStringToUTF8(path)); |
| 326 filePath = filePath.Append(fileName); | 326 filePath = filePath.Append(fileName); |
| 327 | 327 |
| 328 // CreateFileStreamForDrop() will call file_util::PathExists(), | 328 // CreateFileStreamForDrop() will call file_util::PathExists(), |
| 329 // which is blocking. Since this operation is already blocking the | 329 // which is blocking. Since this operation is already blocking the |
| 330 // UI thread on OSX, it should be reasonable to let it happen. | 330 // UI thread on OSX, it should be reasonable to let it happen. |
| 331 base::ThreadRestrictions::ScopedAllowIO allowIO; | 331 base::ThreadRestrictions::ScopedAllowIO allowIO; |
| 332 scoped_ptr<FileStream> fileStream(content::CreateFileStreamForDrop( | 332 scoped_ptr<FileStream> fileStream(content::CreateFileStreamForDrop( |
| 333 &filePath, content::GetContentClient()->browser()->GetNetLog())); | 333 &filePath, content::GetContentClient()->browser()->GetNetLog())); |
| 334 if (!fileStream.get()) | 334 if (!fileStream) |
| 335 return nil; | 335 return nil; |
| 336 | 336 |
| 337 if (downloadURL_.is_valid()) { | 337 if (downloadURL_.is_valid()) { |
| 338 scoped_refptr<DragDownloadFile> dragFileDownloader(new DragDownloadFile( | 338 scoped_refptr<DragDownloadFile> dragFileDownloader(new DragDownloadFile( |
| 339 filePath, | 339 filePath, |
| 340 fileStream.Pass(), | 340 fileStream.Pass(), |
| 341 downloadURL_, | 341 downloadURL_, |
| 342 content::Referrer(contents_->GetURL(), dropData_->referrer_policy), | 342 content::Referrer(contents_->GetURL(), dropData_->referrer_policy), |
| 343 contents_->GetEncoding(), | 343 contents_->GetEncoding(), |
| 344 contents_)); | 344 contents_)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 - (NSImage*)dragImage { | 469 - (NSImage*)dragImage { |
| 470 if (dragImage_) | 470 if (dragImage_) |
| 471 return dragImage_; | 471 return dragImage_; |
| 472 | 472 |
| 473 // Default to returning a generic image. | 473 // Default to returning a generic image. |
| 474 return content::GetContentClient()->GetNativeImageNamed( | 474 return content::GetContentClient()->GetNativeImageNamed( |
| 475 IDR_DEFAULT_FAVICON).ToNSImage(); | 475 IDR_DEFAULT_FAVICON).ToNSImage(); |
| 476 } | 476 } |
| 477 | 477 |
| 478 @end // @implementation WebDragSource (Private) | 478 @end // @implementation WebDragSource (Private) |
| OLD | NEW |