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 "stdafx.h" | 5 #include "stdafx.h" |
6 #include "win8/metro_driver/file_picker.h" | 6 #include "win8/metro_driver/file_picker.h" |
7 | 7 |
8 #include <windows.storage.pickers.h> | 8 #include <windows.storage.pickers.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 // IVector<HSTRING> implementation. | 40 // IVector<HSTRING> implementation. |
41 STDMETHOD(GetAt)(unsigned index, HSTRING* item) { | 41 STDMETHOD(GetAt)(unsigned index, HSTRING* item) { |
42 if (index >= strings_.size()) | 42 if (index >= strings_.size()) |
43 return E_INVALIDARG; | 43 return E_INVALIDARG; |
44 | 44 |
45 return ::WindowsDuplicateString(strings_[index], item); | 45 return ::WindowsDuplicateString(strings_[index], item); |
46 } | 46 } |
47 STDMETHOD(get_Size)(unsigned *size) { | 47 STDMETHOD(get_Size)(unsigned *size) { |
48 *size = strings_.size(); | 48 if (strings_.size() > UINT_MAX) |
| 49 return E_UNEXPECTED; |
| 50 *size = static_cast<unsigned>(strings_.size()); |
49 return S_OK; | 51 return S_OK; |
50 } | 52 } |
51 STDMETHOD(GetView)(winfoundtn::Collections::IVectorView<HSTRING> **view) { | 53 STDMETHOD(GetView)(winfoundtn::Collections::IVectorView<HSTRING> **view) { |
52 return E_NOTIMPL; | 54 return E_NOTIMPL; |
53 } | 55 } |
54 STDMETHOD(IndexOf)(HSTRING value, unsigned *index, boolean *found) { | 56 STDMETHOD(IndexOf)(HSTRING value, unsigned *index, boolean *found) { |
55 return E_NOTIMPL; | 57 return E_NOTIMPL; |
56 } | 58 } |
57 | 59 |
58 // write methods | 60 // write methods |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 if (file) { | 204 if (file) { |
203 mswr::ComPtr<winstorage::IStorageItem> storage_item; | 205 mswr::ComPtr<winstorage::IStorageItem> storage_item; |
204 if (SUCCEEDED(hr)) | 206 if (SUCCEEDED(hr)) |
205 hr = file.As(&storage_item); | 207 hr = file.As(&storage_item); |
206 | 208 |
207 mswrw::HString file_path; | 209 mswrw::HString file_path; |
208 if (SUCCEEDED(hr)) | 210 if (SUCCEEDED(hr)) |
209 hr = storage_item->get_Path(file_path.GetAddressOf()); | 211 hr = storage_item->get_Path(file_path.GetAddressOf()); |
210 | 212 |
211 if (SUCCEEDED(hr)) { | 213 if (SUCCEEDED(hr)) { |
212 size_t path_len = 0; | 214 UINT32 path_len = 0; |
213 const wchar_t* path_str = | 215 const wchar_t* path_str = |
214 ::WindowsGetStringRawBuffer(file_path.Get(), &path_len); | 216 ::WindowsGetStringRawBuffer(file_path.Get(), &path_len); |
215 | 217 |
216 // If the selected file name is longer than the supplied buffer, | 218 // If the selected file name is longer than the supplied buffer, |
217 // we return false as per GetOpenFileName documentation. | 219 // we return false as per GetOpenFileName documentation. |
218 if (path_len < open_file_name_->nMaxFile) { | 220 if (path_len < open_file_name_->nMaxFile) { |
219 base::wcslcpy(open_file_name_->lpstrFile, | 221 base::wcslcpy(open_file_name_->lpstrFile, |
220 path_str, | 222 path_str, |
221 open_file_name_->nMaxFile); | 223 open_file_name_->nMaxFile); |
222 success_ = true; | 224 success_ = true; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 } | 372 } |
371 | 373 |
372 HRESULT OpenFilePickerSession::ComposeMultiFileResult( | 374 HRESULT OpenFilePickerSession::ComposeMultiFileResult( |
373 StorageFileVectorCollection* files, string16* result) { | 375 StorageFileVectorCollection* files, string16* result) { |
374 DCHECK(files != NULL); | 376 DCHECK(files != NULL); |
375 DCHECK(result != NULL); | 377 DCHECK(result != NULL); |
376 | 378 |
377 // Empty the output string. | 379 // Empty the output string. |
378 result->clear(); | 380 result->clear(); |
379 | 381 |
380 size_t num_files = 0; | 382 unsigned int num_files = 0; |
381 HRESULT hr = files->get_Size(&num_files); | 383 HRESULT hr = files->get_Size(&num_files); |
382 if (FAILED(hr)) | 384 if (FAILED(hr)) |
383 return hr; | 385 return hr; |
384 | 386 |
385 // Make sure we return an error on an empty collection. | 387 // Make sure we return an error on an empty collection. |
386 if (num_files == 0) { | 388 if (num_files == 0) { |
387 DLOG(ERROR) << "Empty collection on input."; | 389 DLOG(ERROR) << "Empty collection on input."; |
388 return E_UNEXPECTED; | 390 return E_UNEXPECTED; |
389 } | 391 } |
390 | 392 |
391 // This stores the base path that should be the parent of all the files. | 393 // This stores the base path that should be the parent of all the files. |
392 FilePath base_path; | 394 FilePath base_path; |
393 | 395 |
394 // Iterate through the collection and append the file paths to the result. | 396 // Iterate through the collection and append the file paths to the result. |
395 for (size_t i = 0; i < num_files; ++i) { | 397 for (unsigned int i = 0; i < num_files; ++i) { |
396 mswr::ComPtr<winstorage::IStorageFile> file; | 398 mswr::ComPtr<winstorage::IStorageFile> file; |
397 hr = files->GetAt(i, file.GetAddressOf()); | 399 hr = files->GetAt(i, file.GetAddressOf()); |
398 if (FAILED(hr)) | 400 if (FAILED(hr)) |
399 return hr; | 401 return hr; |
400 | 402 |
401 mswr::ComPtr<winstorage::IStorageItem> storage_item; | 403 mswr::ComPtr<winstorage::IStorageItem> storage_item; |
402 hr = file.As(&storage_item); | 404 hr = file.As(&storage_item); |
403 if (FAILED(hr)) | 405 if (FAILED(hr)) |
404 return hr; | 406 return hr; |
405 | 407 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 OpenFilePickerSession session(open_file_name); | 611 OpenFilePickerSession session(open_file_name); |
610 | 612 |
611 return session.Run(); | 613 return session.Run(); |
612 } | 614 } |
613 | 615 |
614 BOOL MetroGetSaveFileName(OPENFILENAME* open_file_name) { | 616 BOOL MetroGetSaveFileName(OPENFILENAME* open_file_name) { |
615 SaveFilePickerSession session(open_file_name); | 617 SaveFilePickerSession session(open_file_name); |
616 | 618 |
617 return session.Run(); | 619 return session.Run(); |
618 } | 620 } |
OLD | NEW |