| 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 #include "content/browser/web_contents/web_contents_drag_win.h" | 5 #include "content/browser/web_contents/web_contents_drag_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 void WebContentsDragWin::PrepareDragForDownload( | 221 void WebContentsDragWin::PrepareDragForDownload( |
| 222 const WebDropData& drop_data, | 222 const WebDropData& drop_data, |
| 223 ui::OSExchangeData* data, | 223 ui::OSExchangeData* data, |
| 224 const GURL& page_url, | 224 const GURL& page_url, |
| 225 const std::string& page_encoding) { | 225 const std::string& page_encoding) { |
| 226 // Parse the download metadata. | 226 // Parse the download metadata. |
| 227 string16 mime_type; | 227 string16 mime_type; |
| 228 FilePath file_name; | 228 base::FilePath file_name; |
| 229 GURL download_url; | 229 GURL download_url; |
| 230 if (!ParseDownloadMetadata(drop_data.download_metadata, | 230 if (!ParseDownloadMetadata(drop_data.download_metadata, |
| 231 &mime_type, | 231 &mime_type, |
| 232 &file_name, | 232 &file_name, |
| 233 &download_url)) | 233 &download_url)) |
| 234 return; | 234 return; |
| 235 | 235 |
| 236 // Generate the file name based on both mime type and proposed file name. | 236 // Generate the file name based on both mime type and proposed file name. |
| 237 std::string default_name = | 237 std::string default_name = |
| 238 GetContentClient()->browser()->GetDefaultDownloadName(); | 238 GetContentClient()->browser()->GetDefaultDownloadName(); |
| 239 FilePath generated_download_file_name = | 239 base::FilePath generated_download_file_name = |
| 240 net::GenerateFileName(download_url, | 240 net::GenerateFileName(download_url, |
| 241 std::string(), | 241 std::string(), |
| 242 std::string(), | 242 std::string(), |
| 243 UTF16ToUTF8(file_name.value()), | 243 UTF16ToUTF8(file_name.value()), |
| 244 UTF16ToUTF8(mime_type), | 244 UTF16ToUTF8(mime_type), |
| 245 default_name); | 245 default_name); |
| 246 FilePath temp_dir_path; | 246 base::FilePath temp_dir_path; |
| 247 if (!file_util::CreateNewTempDirectory( | 247 if (!file_util::CreateNewTempDirectory( |
| 248 FILE_PATH_LITERAL("chrome_drag"), &temp_dir_path)) | 248 FILE_PATH_LITERAL("chrome_drag"), &temp_dir_path)) |
| 249 return; | 249 return; |
| 250 FilePath download_path = temp_dir_path.Append(generated_download_file_name); | 250 base::FilePath download_path = |
| 251 temp_dir_path.Append(generated_download_file_name); |
| 251 | 252 |
| 252 // We cannot know when the target application will be done using the temporary | 253 // We cannot know when the target application will be done using the temporary |
| 253 // file, so schedule it to be deleted after rebooting. | 254 // file, so schedule it to be deleted after rebooting. |
| 254 file_util::DeleteAfterReboot(download_path); | 255 file_util::DeleteAfterReboot(download_path); |
| 255 file_util::DeleteAfterReboot(temp_dir_path); | 256 file_util::DeleteAfterReboot(temp_dir_path); |
| 256 | 257 |
| 257 // Provide the data as file (CF_HDROP). A temporary download file with the | 258 // Provide the data as file (CF_HDROP). A temporary download file with the |
| 258 // Zone.Identifier ADS (Alternate Data Stream) attached will be created. | 259 // Zone.Identifier ADS (Alternate Data Stream) attached will be created. |
| 259 scoped_refptr<DragDownloadFile> download_file = | 260 scoped_refptr<DragDownloadFile> download_file = |
| 260 new DragDownloadFile( | 261 new DragDownloadFile( |
| 261 download_path, | 262 download_path, |
| 262 scoped_ptr<net::FileStream>(NULL), | 263 scoped_ptr<net::FileStream>(NULL), |
| 263 download_url, | 264 download_url, |
| 264 Referrer(page_url, drop_data.referrer_policy), | 265 Referrer(page_url, drop_data.referrer_policy), |
| 265 page_encoding, | 266 page_encoding, |
| 266 web_contents_); | 267 web_contents_); |
| 267 ui::OSExchangeData::DownloadFileInfo file_download(FilePath(), | 268 ui::OSExchangeData::DownloadFileInfo file_download(base::FilePath(), |
| 268 download_file.get()); | 269 download_file.get()); |
| 269 data->SetDownloadFileInfo(file_download); | 270 data->SetDownloadFileInfo(file_download); |
| 270 | 271 |
| 271 // Enable asynchronous operation. | 272 // Enable asynchronous operation. |
| 272 ui::OSExchangeDataProviderWin::GetIAsyncOperation(*data)->SetAsyncMode(TRUE); | 273 ui::OSExchangeDataProviderWin::GetIAsyncOperation(*data)->SetAsyncMode(TRUE); |
| 273 } | 274 } |
| 274 | 275 |
| 275 void WebContentsDragWin::PrepareDragForFileContents( | 276 void WebContentsDragWin::PrepareDragForFileContents( |
| 276 const WebDropData& drop_data, ui::OSExchangeData* data) { | 277 const WebDropData& drop_data, ui::OSExchangeData* data) { |
| 277 static const int kMaxFilenameLength = 255; // FAT and NTFS | 278 static const int kMaxFilenameLength = 255; // FAT and NTFS |
| 278 FilePath file_name(drop_data.file_description_filename); | 279 base::FilePath file_name(drop_data.file_description_filename); |
| 279 | 280 |
| 280 // Images without ALT text will only have a file extension so we need to | 281 // Images without ALT text will only have a file extension so we need to |
| 281 // synthesize one from the provided extension and URL. | 282 // synthesize one from the provided extension and URL. |
| 282 if (file_name.BaseName().RemoveExtension().empty()) { | 283 if (file_name.BaseName().RemoveExtension().empty()) { |
| 283 const string16 extension = file_name.Extension(); | 284 const string16 extension = file_name.Extension(); |
| 284 // Retrieve the name from the URL. | 285 // Retrieve the name from the URL. |
| 285 file_name = FilePath( | 286 file_name = base::FilePath( |
| 286 net::GetSuggestedFilename(drop_data.url, "", "", "", "", "")); | 287 net::GetSuggestedFilename(drop_data.url, "", "", "", "", "")); |
| 287 if (file_name.value().size() + extension.size() > kMaxFilenameLength) { | 288 if (file_name.value().size() + extension.size() > kMaxFilenameLength) { |
| 288 file_name = FilePath(file_name.value().substr( | 289 file_name = base::FilePath(file_name.value().substr( |
| 289 0, kMaxFilenameLength - extension.size())); | 290 0, kMaxFilenameLength - extension.size())); |
| 290 } | 291 } |
| 291 file_name = file_name.ReplaceExtension(extension); | 292 file_name = file_name.ReplaceExtension(extension); |
| 292 } | 293 } |
| 293 data->SetFileContents(file_name, drop_data.file_contents); | 294 data->SetFileContents(file_name, drop_data.file_contents); |
| 294 } | 295 } |
| 295 | 296 |
| 296 void WebContentsDragWin::PrepareDragForUrl(const WebDropData& drop_data, | 297 void WebContentsDragWin::PrepareDragForUrl(const WebDropData& drop_data, |
| 297 ui::OSExchangeData* data) { | 298 ui::OSExchangeData* data) { |
| 298 if (drag_dest_->delegate() && | 299 if (drag_dest_->delegate() && |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 | 423 |
| 423 // The drag-and-drop thread is only closed after OLE is done with | 424 // The drag-and-drop thread is only closed after OLE is done with |
| 424 // DataObjectImpl. | 425 // DataObjectImpl. |
| 425 BrowserThread::PostTask( | 426 BrowserThread::PostTask( |
| 426 BrowserThread::UI, | 427 BrowserThread::UI, |
| 427 FROM_HERE, | 428 FROM_HERE, |
| 428 base::Bind(&WebContentsDragWin::CloseThread, this)); | 429 base::Bind(&WebContentsDragWin::CloseThread, this)); |
| 429 } | 430 } |
| 430 | 431 |
| 431 } // namespace content | 432 } // namespace content |
| OLD | NEW |