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 "ui/base/dragdrop/os_exchange_data_provider_win.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 return ClipboardUtil::GetPlainText(source_object_, data); | 404 return ClipboardUtil::GetPlainText(source_object_, data); |
405 } | 405 } |
406 | 406 |
407 bool OSExchangeDataProviderWin::GetURLAndTitle( | 407 bool OSExchangeDataProviderWin::GetURLAndTitle( |
408 OSExchangeData::FilenameToURLPolicy policy, | 408 OSExchangeData::FilenameToURLPolicy policy, |
409 GURL* url, | 409 GURL* url, |
410 base::string16* title) const { | 410 base::string16* title) const { |
411 base::string16 url_str; | 411 base::string16 url_str; |
412 bool success = ClipboardUtil::GetUrl( | 412 bool success = ClipboardUtil::GetUrl( |
413 source_object_, | 413 source_object_, |
414 &url_str, | 414 url, |
415 title, | 415 title, |
416 policy == OSExchangeData::CONVERT_FILENAMES ? true : false); | 416 policy == OSExchangeData::CONVERT_FILENAMES ? true : false); |
417 if (success) { | 417 if (success) { |
418 GURL test_url(url_str); | 418 DCHECK(url->is_valid()); |
419 if (test_url.is_valid()) { | 419 return true; |
420 *url = test_url; | |
421 return true; | |
422 } | |
423 } else if (GetPlainTextURL(source_object_, url)) { | 420 } else if (GetPlainTextURL(source_object_, url)) { |
424 if (url->is_valid()) | 421 if (url->is_valid()) |
425 *title = net::GetSuggestedFilename(*url, "", "", "", "", std::string()); | 422 *title = net::GetSuggestedFilename(*url, "", "", "", "", std::string()); |
426 else | 423 else |
427 title->clear(); | 424 title->clear(); |
428 return true; | 425 return true; |
429 } | 426 } |
430 return false; | 427 return false; |
431 } | 428 } |
432 | 429 |
(...skipping 19 matching lines...) Expand all Loading... |
452 | 449 |
453 bool OSExchangeDataProviderWin::GetPickledData( | 450 bool OSExchangeDataProviderWin::GetPickledData( |
454 const OSExchangeData::CustomFormat& format, | 451 const OSExchangeData::CustomFormat& format, |
455 Pickle* data) const { | 452 Pickle* data) const { |
456 DCHECK(data); | 453 DCHECK(data); |
457 bool success = false; | 454 bool success = false; |
458 STGMEDIUM medium; | 455 STGMEDIUM medium; |
459 FORMATETC format_etc = format.ToFormatEtc(); | 456 FORMATETC format_etc = format.ToFormatEtc(); |
460 if (SUCCEEDED(source_object_->GetData(&format_etc, &medium))) { | 457 if (SUCCEEDED(source_object_->GetData(&format_etc, &medium))) { |
461 if (medium.tymed & TYMED_HGLOBAL) { | 458 if (medium.tymed & TYMED_HGLOBAL) { |
462 base::win::ScopedHGlobal<char> c_data(medium.hGlobal); | 459 base::win::ScopedHGlobal<char*> c_data(medium.hGlobal); |
463 DCHECK_GT(c_data.Size(), 0u); | 460 DCHECK_GT(c_data.Size(), 0u); |
464 *data = Pickle(c_data.get(), static_cast<int>(c_data.Size())); | 461 *data = Pickle(c_data.get(), static_cast<int>(c_data.Size())); |
465 success = true; | 462 success = true; |
466 } | 463 } |
467 ReleaseStgMedium(&medium); | 464 ReleaseStgMedium(&medium); |
468 } | 465 } |
469 return success; | 466 return success; |
470 } | 467 } |
471 | 468 |
472 bool OSExchangeDataProviderWin::GetFileContents( | 469 bool OSExchangeDataProviderWin::GetFileContents( |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 base::RefCountedThreadSafe<DownloadFileObserver>::Release(); | 868 base::RefCountedThreadSafe<DownloadFileObserver>::Release(); |
872 return 0; | 869 return 0; |
873 } | 870 } |
874 | 871 |
875 /////////////////////////////////////////////////////////////////////////////// | 872 /////////////////////////////////////////////////////////////////////////////// |
876 // DataObjectImpl, private: | 873 // DataObjectImpl, private: |
877 | 874 |
878 static STGMEDIUM* GetStorageForBytes(const void* data, size_t bytes) { | 875 static STGMEDIUM* GetStorageForBytes(const void* data, size_t bytes) { |
879 HANDLE handle = GlobalAlloc(GPTR, static_cast<int>(bytes)); | 876 HANDLE handle = GlobalAlloc(GPTR, static_cast<int>(bytes)); |
880 if (handle) { | 877 if (handle) { |
881 base::win::ScopedHGlobal<uint8> scoped(handle); | 878 base::win::ScopedHGlobal<uint8*> scoped(handle); |
882 memcpy(scoped.get(), data, bytes); | 879 memcpy(scoped.get(), data, bytes); |
883 } | 880 } |
884 | 881 |
885 STGMEDIUM* storage = new STGMEDIUM; | 882 STGMEDIUM* storage = new STGMEDIUM; |
886 storage->hGlobal = handle; | 883 storage->hGlobal = handle; |
887 storage->tymed = TYMED_HGLOBAL; | 884 storage->tymed = TYMED_HGLOBAL; |
888 storage->pUnkForRelease = NULL; | 885 storage->pUnkForRelease = NULL; |
889 return storage; | 886 return storage; |
890 } | 887 } |
891 | 888 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 validated->erase(max_length); | 925 validated->erase(max_length); |
929 *validated += extension; | 926 *validated += extension; |
930 } | 927 } |
931 | 928 |
932 static STGMEDIUM* GetStorageForFileName(const base::FilePath& path) { | 929 static STGMEDIUM* GetStorageForFileName(const base::FilePath& path) { |
933 const size_t kDropSize = sizeof(DROPFILES); | 930 const size_t kDropSize = sizeof(DROPFILES); |
934 const size_t kTotalBytes = | 931 const size_t kTotalBytes = |
935 kDropSize + (path.value().length() + 2) * sizeof(wchar_t); | 932 kDropSize + (path.value().length() + 2) * sizeof(wchar_t); |
936 HANDLE hdata = GlobalAlloc(GMEM_MOVEABLE, kTotalBytes); | 933 HANDLE hdata = GlobalAlloc(GMEM_MOVEABLE, kTotalBytes); |
937 | 934 |
938 base::win::ScopedHGlobal<DROPFILES> locked_mem(hdata); | 935 base::win::ScopedHGlobal<DROPFILES*> locked_mem(hdata); |
939 DROPFILES* drop_files = locked_mem.get(); | 936 DROPFILES* drop_files = locked_mem.get(); |
940 drop_files->pFiles = sizeof(DROPFILES); | 937 drop_files->pFiles = sizeof(DROPFILES); |
941 drop_files->fWide = TRUE; | 938 drop_files->fWide = TRUE; |
942 wchar_t* data = reinterpret_cast<wchar_t*>( | 939 wchar_t* data = reinterpret_cast<wchar_t*>( |
943 reinterpret_cast<BYTE*>(drop_files) + kDropSize); | 940 reinterpret_cast<BYTE*>(drop_files) + kDropSize); |
944 const size_t copy_size = (path.value().length() + 1) * sizeof(wchar_t); | 941 const size_t copy_size = (path.value().length() + 1) * sizeof(wchar_t); |
945 memcpy(data, path.value().c_str(), copy_size); | 942 memcpy(data, path.value().c_str(), copy_size); |
946 data[path.value().length() + 1] = L'\0'; // Double NULL | 943 data[path.value().length() + 1] = L'\0'; // Double NULL |
947 | 944 |
948 STGMEDIUM* storage = new STGMEDIUM; | 945 STGMEDIUM* storage = new STGMEDIUM; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 // NULL here to indicate that the parent folder is the desktop, and the second | 1001 // NULL here to indicate that the parent folder is the desktop, and the second |
1005 // is the PIDL of |path|. | 1002 // is the PIDL of |path|. |
1006 const size_t kPIDLCountSize = sizeof(UINT); | 1003 const size_t kPIDLCountSize = sizeof(UINT); |
1007 const size_t kPIDLOffsetsSize = 2 * sizeof(UINT); | 1004 const size_t kPIDLOffsetsSize = 2 * sizeof(UINT); |
1008 const size_t kFirstPIDLOffset = kPIDLCountSize + kPIDLOffsetsSize; | 1005 const size_t kFirstPIDLOffset = kPIDLCountSize + kPIDLOffsetsSize; |
1009 const size_t kFirstPIDLSize = 2; // Empty PIDL - 2 NULL bytes. | 1006 const size_t kFirstPIDLSize = 2; // Empty PIDL - 2 NULL bytes. |
1010 const size_t kSecondPIDLSize = PIDLSize(pidl); | 1007 const size_t kSecondPIDLSize = PIDLSize(pidl); |
1011 const size_t kCIDASize = kFirstPIDLOffset + kFirstPIDLSize + kSecondPIDLSize; | 1008 const size_t kCIDASize = kFirstPIDLOffset + kFirstPIDLSize + kSecondPIDLSize; |
1012 HANDLE hdata = GlobalAlloc(GMEM_MOVEABLE, kCIDASize); | 1009 HANDLE hdata = GlobalAlloc(GMEM_MOVEABLE, kCIDASize); |
1013 | 1010 |
1014 base::win::ScopedHGlobal<CIDA> locked_mem(hdata); | 1011 base::win::ScopedHGlobal<CIDA*> locked_mem(hdata); |
1015 CIDA* cida = locked_mem.get(); | 1012 CIDA* cida = locked_mem.get(); |
1016 cida->cidl = 1; // We have one PIDL (not including the 0th root PIDL). | 1013 cida->cidl = 1; // We have one PIDL (not including the 0th root PIDL). |
1017 cida->aoffset[0] = kFirstPIDLOffset; | 1014 cida->aoffset[0] = kFirstPIDLOffset; |
1018 cida->aoffset[1] = kFirstPIDLOffset + kFirstPIDLSize; | 1015 cida->aoffset[1] = kFirstPIDLOffset + kFirstPIDLSize; |
1019 LPITEMIDLIST idl = GetNthPIDL(cida, 0); | 1016 LPITEMIDLIST idl = GetNthPIDL(cida, 0); |
1020 idl->mkid.cb = 0; | 1017 idl->mkid.cb = 0; |
1021 idl->mkid.abID[0] = 0; | 1018 idl->mkid.abID[0] = 0; |
1022 idl = GetNthPIDL(cida, 1); | 1019 idl = GetNthPIDL(cida, 1); |
1023 memcpy(idl, pidl, kSecondPIDLSize); | 1020 memcpy(idl, pidl, kSecondPIDLSize); |
1024 | 1021 |
1025 STGMEDIUM* storage = new STGMEDIUM; | 1022 STGMEDIUM* storage = new STGMEDIUM; |
1026 storage->tymed = TYMED_HGLOBAL; | 1023 storage->tymed = TYMED_HGLOBAL; |
1027 storage->hGlobal = hdata; | 1024 storage->hGlobal = hdata; |
1028 storage->pUnkForRelease = NULL; | 1025 storage->pUnkForRelease = NULL; |
1029 return storage; | 1026 return storage; |
1030 } | 1027 } |
1031 | 1028 |
1032 static STGMEDIUM* GetStorageForFileDescriptor( | 1029 static STGMEDIUM* GetStorageForFileDescriptor( |
1033 const base::FilePath& path) { | 1030 const base::FilePath& path) { |
1034 base::string16 file_name = path.value(); | 1031 base::string16 file_name = path.value(); |
1035 DCHECK(!file_name.empty()); | 1032 DCHECK(!file_name.empty()); |
1036 HANDLE hdata = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR)); | 1033 HANDLE hdata = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR)); |
1037 base::win::ScopedHGlobal<FILEGROUPDESCRIPTOR> locked_mem(hdata); | 1034 base::win::ScopedHGlobal<FILEGROUPDESCRIPTOR*> locked_mem(hdata); |
1038 | 1035 |
1039 FILEGROUPDESCRIPTOR* descriptor = locked_mem.get(); | 1036 FILEGROUPDESCRIPTOR* descriptor = locked_mem.get(); |
1040 descriptor->cItems = 1; | 1037 descriptor->cItems = 1; |
1041 descriptor->fgd[0].dwFlags = FD_LINKUI; | 1038 descriptor->fgd[0].dwFlags = FD_LINKUI; |
1042 wcsncpy_s(descriptor->fgd[0].cFileName, MAX_PATH, file_name.c_str(), | 1039 wcsncpy_s(descriptor->fgd[0].cFileName, MAX_PATH, file_name.c_str(), |
1043 std::min(file_name.size(), static_cast<size_t>(MAX_PATH - 1u))); | 1040 std::min(file_name.size(), static_cast<size_t>(MAX_PATH - 1u))); |
1044 | 1041 |
1045 STGMEDIUM* storage = new STGMEDIUM; | 1042 STGMEDIUM* storage = new STGMEDIUM; |
1046 storage->tymed = TYMED_HGLOBAL; | 1043 storage->tymed = TYMED_HGLOBAL; |
1047 storage->hGlobal = hdata; | 1044 storage->hGlobal = hdata; |
1048 storage->pUnkForRelease = NULL; | 1045 storage->pUnkForRelease = NULL; |
1049 return storage; | 1046 return storage; |
1050 } | 1047 } |
1051 | 1048 |
1052 /////////////////////////////////////////////////////////////////////////////// | 1049 /////////////////////////////////////////////////////////////////////////////// |
1053 // OSExchangeData, public: | 1050 // OSExchangeData, public: |
1054 | 1051 |
1055 // static | 1052 // static |
1056 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 1053 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
1057 return new OSExchangeDataProviderWin(); | 1054 return new OSExchangeDataProviderWin(); |
1058 } | 1055 } |
1059 | 1056 |
1060 } // namespace ui | 1057 } // namespace ui |
OLD | NEW |