OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/tab_contents/tab_contents_drag_win.h" | 5 #include "chrome/browser/ui/views/tab_contents/tab_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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 string16 mime_type; | 189 string16 mime_type; |
190 FilePath file_name; | 190 FilePath file_name; |
191 GURL download_url; | 191 GURL download_url; |
192 if (!drag_download_util::ParseDownloadMetadata(drop_data.download_metadata, | 192 if (!drag_download_util::ParseDownloadMetadata(drop_data.download_metadata, |
193 &mime_type, | 193 &mime_type, |
194 &file_name, | 194 &file_name, |
195 &download_url)) | 195 &download_url)) |
196 return; | 196 return; |
197 | 197 |
198 // Generate the download filename. | 198 // Generate the download filename. |
199 std::string content_disposition = | |
200 "attachment; filename=" + UTF16ToUTF8(file_name.value()); | |
201 FilePath generated_file_name; | 199 FilePath generated_file_name; |
202 download_util::GenerateFileName(download_url, | 200 download_util::GenerateFileNameFromSuggestedName( |
203 content_disposition, | 201 download_url, |
204 std::string(), | 202 UTF16ToUTF8(file_name.value()), |
205 UTF16ToUTF8(mime_type), | 203 UTF16ToUTF8(mime_type), |
206 &generated_file_name); | 204 &generated_file_name); |
207 | 205 |
208 // Provide the data as file (CF_HDROP). A temporary download file with the | 206 // Provide the data as file (CF_HDROP). A temporary download file with the |
209 // Zone.Identifier ADS (Alternate Data Stream) attached will be created. | 207 // Zone.Identifier ADS (Alternate Data Stream) attached will be created. |
210 linked_ptr<net::FileStream> empty_file_stream; | 208 linked_ptr<net::FileStream> empty_file_stream; |
211 scoped_refptr<DragDownloadFile> download_file = | 209 scoped_refptr<DragDownloadFile> download_file = |
212 new DragDownloadFile(generated_file_name, | 210 new DragDownloadFile(generated_file_name, |
213 empty_file_stream, | 211 empty_file_stream, |
214 download_url, | 212 download_url, |
215 page_url, | 213 page_url, |
216 page_encoding, | 214 page_encoding, |
217 view_->GetTabContents()); | 215 view_->GetTabContents()); |
218 ui::OSExchangeData::DownloadFileInfo file_download(FilePath(), | 216 ui::OSExchangeData::DownloadFileInfo file_download(FilePath(), |
219 download_file.get()); | 217 download_file.get()); |
220 data->SetDownloadFileInfo(file_download); | 218 data->SetDownloadFileInfo(file_download); |
221 | 219 |
222 // Enable asynchronous operation. | 220 // Enable asynchronous operation. |
223 ui::OSExchangeDataProviderWin::GetIAsyncOperation(*data)->SetAsyncMode(TRUE); | 221 ui::OSExchangeDataProviderWin::GetIAsyncOperation(*data)->SetAsyncMode(TRUE); |
224 } | 222 } |
225 | 223 |
226 void TabContentsDragWin::PrepareDragForFileContents( | 224 void TabContentsDragWin::PrepareDragForFileContents( |
227 const WebDropData& drop_data, ui::OSExchangeData* data) { | 225 const WebDropData& drop_data, ui::OSExchangeData* data) { |
228 // Images without ALT text will only have a file extension so we need to | 226 // Images without ALT text will only have a file extension so we need to |
229 // synthesize one from the provided extension and URL. | 227 // synthesize one from the provided extension and URL. |
230 FilePath file_name(drop_data.file_description_filename); | 228 FilePath file_name(drop_data.file_description_filename); |
231 file_name = file_name.BaseName().RemoveExtension(); | 229 file_name = file_name.BaseName().RemoveExtension(); |
232 if (file_name.value().empty()) { | 230 if (file_name.value().empty()) { |
233 // Retrieve the name from the URL. | 231 // Retrieve the name from the URL. |
234 file_name = FilePath( | 232 file_name = FilePath( |
235 net::GetSuggestedFilename(drop_data.url, "", "", string16())); | 233 net::GetSuggestedFilename(drop_data.url, "", "", "", string16())); |
236 if (file_name.value().size() + drop_data.file_extension.size() + 1 > | 234 if (file_name.value().size() + drop_data.file_extension.size() + 1 > |
237 MAX_PATH) { | 235 MAX_PATH) { |
238 file_name = FilePath(file_name.value().substr( | 236 file_name = FilePath(file_name.value().substr( |
239 0, MAX_PATH - drop_data.file_extension.size() - 2)); | 237 0, MAX_PATH - drop_data.file_extension.size() - 2)); |
240 } | 238 } |
241 } | 239 } |
242 file_name = file_name.ReplaceExtension(drop_data.file_extension); | 240 file_name = file_name.ReplaceExtension(drop_data.file_extension); |
243 data->SetFileContents(file_name, drop_data.file_contents); | 241 data->SetFileContents(file_name, drop_data.file_contents); |
244 } | 242 } |
245 | 243 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 357 |
360 void TabContentsDragWin::OnDataObjectDisposed() { | 358 void TabContentsDragWin::OnDataObjectDisposed() { |
361 DCHECK(drag_drop_thread_id_ == base::PlatformThread::CurrentId()); | 359 DCHECK(drag_drop_thread_id_ == base::PlatformThread::CurrentId()); |
362 | 360 |
363 // The drag-and-drop thread is only closed after OLE is done with | 361 // The drag-and-drop thread is only closed after OLE is done with |
364 // DataObjectImpl. | 362 // DataObjectImpl. |
365 BrowserThread::PostTask( | 363 BrowserThread::PostTask( |
366 BrowserThread::UI, FROM_HERE, | 364 BrowserThread::UI, FROM_HERE, |
367 NewRunnableMethod(this, &TabContentsDragWin::CloseThread)); | 365 NewRunnableMethod(this, &TabContentsDragWin::CloseThread)); |
368 } | 366 } |
OLD | NEW |