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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // Metro wants suffixes only, not patterns. | 312 // Metro wants suffixes only, not patterns. |
313 mswrw::HString extension; | 313 mswrw::HString extension; |
314 std::vector<string16> extensions; | 314 std::vector<string16> extensions; |
315 for (size_t i = 0; i < extensions_win32_style.size(); ++i) { | 315 for (size_t i = 0; i < extensions_win32_style.size(); ++i) { |
316 if (extensions_win32_style[i] == L"*.*") { | 316 if (extensions_win32_style[i] == L"*.*") { |
317 // The wildcard filter is "*" for Metro. The string "*.*" produces | 317 // The wildcard filter is "*" for Metro. The string "*.*" produces |
318 // an "invalid parameter" error. | 318 // an "invalid parameter" error. |
319 hr = extension.Set(L"*"); | 319 hr = extension.Set(L"*"); |
320 } else { | 320 } else { |
321 // Metro wants suffixes only, not patterns. | 321 // Metro wants suffixes only, not patterns. |
322 string16 ext = FilePath(extensions_win32_style[i]).Extension(); | 322 string16 ext = base::FilePath(extensions_win32_style[i]).Extension(); |
323 if ((ext.size() < 2) || | 323 if ((ext.size() < 2) || |
324 (ext.find_first_of(L"*?") != string16::npos)) { | 324 (ext.find_first_of(L"*?") != string16::npos)) { |
325 continue; | 325 continue; |
326 } | 326 } |
327 hr = extension.Set(ext.c_str()); | 327 hr = extension.Set(ext.c_str()); |
328 } | 328 } |
329 if (SUCCEEDED(hr)) | 329 if (SUCCEEDED(hr)) |
330 hr = filter->Append(extension.Get()); | 330 hr = filter->Append(extension.Get()); |
331 if (FAILED(hr)) | 331 if (FAILED(hr)) |
332 return hr; | 332 return hr; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 if (FAILED(hr)) | 384 if (FAILED(hr)) |
385 return hr; | 385 return hr; |
386 | 386 |
387 // Make sure we return an error on an empty collection. | 387 // Make sure we return an error on an empty collection. |
388 if (num_files == 0) { | 388 if (num_files == 0) { |
389 DLOG(ERROR) << "Empty collection on input."; | 389 DLOG(ERROR) << "Empty collection on input."; |
390 return E_UNEXPECTED; | 390 return E_UNEXPECTED; |
391 } | 391 } |
392 | 392 |
393 // 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. |
394 FilePath base_path; | 394 base::FilePath base_path; |
395 | 395 |
396 // 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. |
397 for (unsigned int i = 0; i < num_files; ++i) { | 397 for (unsigned int i = 0; i < num_files; ++i) { |
398 mswr::ComPtr<winstorage::IStorageFile> file; | 398 mswr::ComPtr<winstorage::IStorageFile> file; |
399 hr = files->GetAt(i, file.GetAddressOf()); | 399 hr = files->GetAt(i, file.GetAddressOf()); |
400 if (FAILED(hr)) | 400 if (FAILED(hr)) |
401 return hr; | 401 return hr; |
402 | 402 |
403 mswr::ComPtr<winstorage::IStorageItem> storage_item; | 403 mswr::ComPtr<winstorage::IStorageItem> storage_item; |
404 hr = file.As(&storage_item); | 404 hr = file.As(&storage_item); |
405 if (FAILED(hr)) | 405 if (FAILED(hr)) |
406 return hr; | 406 return hr; |
407 | 407 |
408 mswrw::HString file_path_str; | 408 mswrw::HString file_path_str; |
409 hr = storage_item->get_Path(file_path_str.GetAddressOf()); | 409 hr = storage_item->get_Path(file_path_str.GetAddressOf()); |
410 if (FAILED(hr)) | 410 if (FAILED(hr)) |
411 return hr; | 411 return hr; |
412 | 412 |
413 FilePath file_path(MakeStdWString(file_path_str.Get())); | 413 base::FilePath file_path(MakeStdWString(file_path_str.Get())); |
414 if (base_path.empty()) { | 414 if (base_path.empty()) { |
415 DCHECK(result->empty()); | 415 DCHECK(result->empty()); |
416 base_path = file_path.DirName(); | 416 base_path = file_path.DirName(); |
417 | 417 |
418 // Append the path, including the terminating zero. | 418 // Append the path, including the terminating zero. |
419 // We do this only for the first file. | 419 // We do this only for the first file. |
420 result->append(base_path.value().c_str(), base_path.value().size() + 1); | 420 result->append(base_path.value().c_str(), base_path.value().size() + 1); |
421 } | 421 } |
422 DCHECK(!result->empty()); | 422 DCHECK(!result->empty()); |
423 DCHECK(!base_path.empty()); | 423 DCHECK(!base_path.empty()); |
424 DCHECK(base_path == file_path.DirName()); | 424 DCHECK(base_path == file_path.DirName()); |
425 | 425 |
426 // Append the base name, including the terminating zero. | 426 // Append the base name, including the terminating zero. |
427 FilePath base_name = file_path.BaseName(); | 427 base::FilePath base_name = file_path.BaseName(); |
428 result->append(base_name.value().c_str(), base_name.value().size() + 1); | 428 result->append(base_name.value().c_str(), base_name.value().size() + 1); |
429 } | 429 } |
430 | 430 |
431 DCHECK(!result->empty()); | 431 DCHECK(!result->empty()); |
432 | 432 |
433 return S_OK; | 433 return S_OK; |
434 } | 434 } |
435 | 435 |
436 SaveFilePickerSession::SaveFilePickerSession(OPENFILENAME* open_file_name) | 436 SaveFilePickerSession::SaveFilePickerSession(OPENFILENAME* open_file_name) |
437 : FilePickerSessionBase(open_file_name) { | 437 : FilePickerSessionBase(open_file_name) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 477 |
478 // There can be a single extension, or a list of semicolon-separated ones. | 478 // There can be a single extension, or a list of semicolon-separated ones. |
479 std::vector<string16> extensions_win32_style; | 479 std::vector<string16> extensions_win32_style; |
480 size_t extension_count = Tokenize(walk, L";", &extensions_win32_style); | 480 size_t extension_count = Tokenize(walk, L";", &extensions_win32_style); |
481 DCHECK_EQ(extension_count, extensions_win32_style.size()); | 481 DCHECK_EQ(extension_count, extensions_win32_style.size()); |
482 | 482 |
483 // Metro wants suffixes only, not patterns. Also, metro does not support | 483 // Metro wants suffixes only, not patterns. Also, metro does not support |
484 // the all files ("*") pattern in the save picker. | 484 // the all files ("*") pattern in the save picker. |
485 std::vector<string16> extensions; | 485 std::vector<string16> extensions; |
486 for (size_t i = 0; i < extensions_win32_style.size(); ++i) { | 486 for (size_t i = 0; i < extensions_win32_style.size(); ++i) { |
487 string16 ext = FilePath(extensions_win32_style[i]).Extension(); | 487 string16 ext = base::FilePath(extensions_win32_style[i]).Extension(); |
488 if ((ext.size() < 2) || | 488 if ((ext.size() < 2) || |
489 (ext.find_first_of(L"*?") != string16::npos)) | 489 (ext.find_first_of(L"*?") != string16::npos)) |
490 continue; | 490 continue; |
491 extensions.push_back(ext); | 491 extensions.push_back(ext); |
492 } | 492 } |
493 | 493 |
494 if (!extensions.empty()) { | 494 if (!extensions.empty()) { |
495 // Convert to a Metro collection class. | 495 // Convert to a Metro collection class. |
496 mswr::ComPtr<StringVectorItf> list; | 496 mswr::ComPtr<StringVectorItf> list; |
497 hr = mswr::MakeAndInitialize<StringVectorImpl>( | 497 hr = mswr::MakeAndInitialize<StringVectorImpl>( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 OpenFilePickerSession session(open_file_name); | 611 OpenFilePickerSession session(open_file_name); |
612 | 612 |
613 return session.Run(); | 613 return session.Run(); |
614 } | 614 } |
615 | 615 |
616 BOOL MetroGetSaveFileName(OPENFILENAME* open_file_name) { | 616 BOOL MetroGetSaveFileName(OPENFILENAME* open_file_name) { |
617 SaveFilePickerSession session(open_file_name); | 617 SaveFilePickerSession session(open_file_name); |
618 | 618 |
619 return session.Run(); | 619 return session.Run(); |
620 } | 620 } |
OLD | NEW |