OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_ash.h" | 6 #include "win8/metro_driver/file_picker_ash.h" |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 370 |
371 return S_OK; | 371 return S_OK; |
372 } | 372 } |
373 | 373 |
374 SaveFilePickerSession::SaveFilePickerSession( | 374 SaveFilePickerSession::SaveFilePickerSession( |
375 ChromeAppViewAsh* app_view, | 375 ChromeAppViewAsh* app_view, |
376 const MetroViewerHostMsg_SaveAsDialogParams& params) | 376 const MetroViewerHostMsg_SaveAsDialogParams& params) |
377 : FilePickerSessionBase(app_view, | 377 : FilePickerSessionBase(app_view, |
378 params.title, | 378 params.title, |
379 params.filter, | 379 params.filter, |
380 params.suggested_name), | 380 params.suggested_name.value()), |
381 filter_index_(params.filter_index) { | 381 filter_index_(params.filter_index) { |
382 } | 382 } |
383 | 383 |
384 int SaveFilePickerSession::filter_index() const { | 384 int SaveFilePickerSession::filter_index() const { |
385 // TODO(ananta) | 385 // TODO(ananta) |
386 // Add support for returning the correct filter index. This does not work in | 386 // Add support for returning the correct filter index. This does not work in |
387 // regular Chrome metro on trunk as well. | 387 // regular Chrome metro on trunk as well. |
388 // BUG: https://code.google.com/p/chromium/issues/detail?id=172704 | 388 // BUG: https://code.google.com/p/chromium/issues/detail?id=172704 |
389 return filter_index_; | 389 return filter_index_; |
390 } | 390 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } else { | 537 } else { |
538 LOG(ERROR) << "NULL IStorageItem"; | 538 LOG(ERROR) << "NULL IStorageItem"; |
539 } | 539 } |
540 } else { | 540 } else { |
541 LOG(ERROR) << "Unexpected async status " << status; | 541 LOG(ERROR) << "Unexpected async status " << status; |
542 } | 542 } |
543 app_view_->OnSaveFileCompleted(this, success_); | 543 app_view_->OnSaveFileCompleted(this, success_); |
544 return S_OK; | 544 return S_OK; |
545 } | 545 } |
546 | 546 |
| 547 FolderPickerSession::FolderPickerSession(ChromeAppViewAsh* app_view, |
| 548 const string16& title) |
| 549 : FilePickerSessionBase(app_view, title, L"", L"") {} |
| 550 |
| 551 HRESULT FolderPickerSession::StartFilePicker() { |
| 552 mswrw::HStringReference class_name( |
| 553 RuntimeClass_Windows_Storage_Pickers_FolderPicker); |
| 554 |
| 555 // Create the folder picker. |
| 556 mswr::ComPtr<winstorage::Pickers::IFolderPicker> picker; |
| 557 HRESULT hr = ::Windows::Foundation::ActivateInstance( |
| 558 class_name.Get(), picker.GetAddressOf()); |
| 559 CheckHR(hr); |
| 560 |
| 561 // Set the file type filter |
| 562 mswr::ComPtr<winfoundtn::Collections::IVector<HSTRING>> filter; |
| 563 hr = picker->get_FileTypeFilter(filter.GetAddressOf()); |
| 564 if (FAILED(hr)) |
| 565 return hr; |
| 566 |
| 567 hr = filter->Append(mswrw::HStringReference(L"*").Get()); |
| 568 if (FAILED(hr)) |
| 569 return hr; |
| 570 |
| 571 mswr::ComPtr<FolderPickerAsyncOp> completion; |
| 572 hr = picker->PickSingleFolderAsync(&completion); |
| 573 if (FAILED(hr)) |
| 574 return hr; |
| 575 |
| 576 // Create the callback method. |
| 577 typedef winfoundtn::IAsyncOperationCompletedHandler< |
| 578 winstorage::StorageFolder*> HandlerDoneType; |
| 579 mswr::ComPtr<HandlerDoneType> handler(mswr::Callback<HandlerDoneType>( |
| 580 this, &FolderPickerSession::FolderPickerDone)); |
| 581 DCHECK(handler.Get() != NULL); |
| 582 hr = completion->put_Completed(handler.Get()); |
| 583 return hr; |
| 584 } |
| 585 |
| 586 HRESULT FolderPickerSession::FolderPickerDone(FolderPickerAsyncOp* async, |
| 587 AsyncStatus status) { |
| 588 if (status == Completed) { |
| 589 mswr::ComPtr<winstorage::IStorageFolder> folder; |
| 590 HRESULT hr = async->GetResults(folder.GetAddressOf()); |
| 591 |
| 592 if (folder) { |
| 593 mswr::ComPtr<winstorage::IStorageItem> storage_item; |
| 594 if (SUCCEEDED(hr)) |
| 595 hr = folder.As(&storage_item); |
| 596 |
| 597 mswrw::HString file_path; |
| 598 if (SUCCEEDED(hr)) |
| 599 hr = storage_item->get_Path(file_path.GetAddressOf()); |
| 600 |
| 601 if (SUCCEEDED(hr)) { |
| 602 string16 path_str = MakeStdWString(file_path.Get()); |
| 603 result_ = path_str; |
| 604 success_ = true; |
| 605 } |
| 606 } else { |
| 607 LOG(ERROR) << "NULL IStorageItem"; |
| 608 } |
| 609 } else { |
| 610 LOG(ERROR) << "Unexpected async status " << status; |
| 611 } |
| 612 app_view_->OnFolderPickerCompleted(this, success_); |
| 613 return S_OK; |
| 614 } |
| 615 |
OLD | NEW |