| 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/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 hr = ComposeMultiFileResult(files.Get(), &result); | 170 hr = ComposeMultiFileResult(files.Get(), &result); |
| 171 | 171 |
| 172 if (SUCCEEDED(hr)) { | 172 if (SUCCEEDED(hr)) { |
| 173 success_ = true; | 173 success_ = true; |
| 174 // The code below has been copied from the | 174 // The code below has been copied from the |
| 175 // SelectFileDialogImpl::RunOpenMultiFileDialog function in | 175 // SelectFileDialogImpl::RunOpenMultiFileDialog function in |
| 176 // select_file_dialog_win.cc. | 176 // select_file_dialog_win.cc. |
| 177 // TODO(ananta) | 177 // TODO(ananta) |
| 178 // Consolidate this into a common place. | 178 // Consolidate this into a common place. |
| 179 const wchar_t* selection = result.c_str(); | 179 const wchar_t* selection = result.c_str(); |
| 180 std::vector<FilePath> files; | 180 std::vector<base::FilePath> files; |
| 181 | 181 |
| 182 while (*selection) { // Empty string indicates end of list. | 182 while (*selection) { // Empty string indicates end of list. |
| 183 files.push_back(FilePath(selection)); | 183 files.push_back(base::FilePath(selection)); |
| 184 // Skip over filename and null-terminator. | 184 // Skip over filename and null-terminator. |
| 185 selection += files.back().value().length() + 1; | 185 selection += files.back().value().length() + 1; |
| 186 } | 186 } |
| 187 if (files.empty()) { | 187 if (files.empty()) { |
| 188 success_ = false; | 188 success_ = false; |
| 189 } else if (files.size() == 1) { | 189 } else if (files.size() == 1) { |
| 190 // When there is one file, it contains the path and filename. | 190 // When there is one file, it contains the path and filename. |
| 191 filenames_ = files; | 191 filenames_ = files; |
| 192 } else if (files.size() > 1) { | 192 } else if (files.size() > 1) { |
| 193 // Otherwise, the first string is the path, and the remainder are | 193 // Otherwise, the first string is the path, and the remainder are |
| 194 // filenames. | 194 // filenames. |
| 195 std::vector<FilePath>::iterator path = files.begin(); | 195 std::vector<base::FilePath>::iterator path = files.begin(); |
| 196 for (std::vector<FilePath>::iterator file = path + 1; | 196 for (std::vector<base::FilePath>::iterator file = path + 1; |
| 197 file != files.end(); ++file) { | 197 file != files.end(); ++file) { |
| 198 filenames_.push_back(path->Append(*file)); | 198 filenames_.push_back(path->Append(*file)); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 } else { | 202 } else { |
| 203 LOG(ERROR) << "NULL StorageFileVectorCollection"; | 203 LOG(ERROR) << "NULL StorageFileVectorCollection"; |
| 204 } | 204 } |
| 205 } else { | 205 } else { |
| 206 LOG(ERROR) << "Unexpected async status " << status; | 206 LOG(ERROR) << "Unexpected async status " << status; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // Metro wants suffixes only, not patterns. | 250 // Metro wants suffixes only, not patterns. |
| 251 mswrw::HString extension; | 251 mswrw::HString extension; |
| 252 std::vector<string16> extensions; | 252 std::vector<string16> extensions; |
| 253 for (size_t i = 0; i < extensions_win32_style.size(); ++i) { | 253 for (size_t i = 0; i < extensions_win32_style.size(); ++i) { |
| 254 if (extensions_win32_style[i] == L"*.*") { | 254 if (extensions_win32_style[i] == L"*.*") { |
| 255 // The wildcard filter is "*" for Metro. The string "*.*" produces | 255 // The wildcard filter is "*" for Metro. The string "*.*" produces |
| 256 // an "invalid parameter" error. | 256 // an "invalid parameter" error. |
| 257 hr = extension.Set(L"*"); | 257 hr = extension.Set(L"*"); |
| 258 } else { | 258 } else { |
| 259 // Metro wants suffixes only, not patterns. | 259 // Metro wants suffixes only, not patterns. |
| 260 string16 ext = FilePath(extensions_win32_style[i]).Extension(); | 260 string16 ext = base::FilePath(extensions_win32_style[i]).Extension(); |
| 261 if ((ext.size() < 2) || | 261 if ((ext.size() < 2) || |
| 262 (ext.find_first_of(L"*?") != string16::npos)) { | 262 (ext.find_first_of(L"*?") != string16::npos)) { |
| 263 continue; | 263 continue; |
| 264 } | 264 } |
| 265 hr = extension.Set(ext.c_str()); | 265 hr = extension.Set(ext.c_str()); |
| 266 } | 266 } |
| 267 if (SUCCEEDED(hr)) | 267 if (SUCCEEDED(hr)) |
| 268 hr = filter->Append(extension.Get()); | 268 hr = filter->Append(extension.Get()); |
| 269 if (FAILED(hr)) | 269 if (FAILED(hr)) |
| 270 return hr; | 270 return hr; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 if (FAILED(hr)) | 322 if (FAILED(hr)) |
| 323 return hr; | 323 return hr; |
| 324 | 324 |
| 325 // Make sure we return an error on an empty collection. | 325 // Make sure we return an error on an empty collection. |
| 326 if (num_files == 0) { | 326 if (num_files == 0) { |
| 327 DLOG(ERROR) << "Empty collection on input."; | 327 DLOG(ERROR) << "Empty collection on input."; |
| 328 return E_UNEXPECTED; | 328 return E_UNEXPECTED; |
| 329 } | 329 } |
| 330 | 330 |
| 331 // This stores the base path that should be the parent of all the files. | 331 // This stores the base path that should be the parent of all the files. |
| 332 FilePath base_path; | 332 base::FilePath base_path; |
| 333 | 333 |
| 334 // Iterate through the collection and append the file paths to the result. | 334 // Iterate through the collection and append the file paths to the result. |
| 335 for (unsigned int i = 0; i < num_files; ++i) { | 335 for (unsigned int i = 0; i < num_files; ++i) { |
| 336 mswr::ComPtr<winstorage::IStorageFile> file; | 336 mswr::ComPtr<winstorage::IStorageFile> file; |
| 337 hr = files->GetAt(i, file.GetAddressOf()); | 337 hr = files->GetAt(i, file.GetAddressOf()); |
| 338 if (FAILED(hr)) | 338 if (FAILED(hr)) |
| 339 return hr; | 339 return hr; |
| 340 | 340 |
| 341 mswr::ComPtr<winstorage::IStorageItem> storage_item; | 341 mswr::ComPtr<winstorage::IStorageItem> storage_item; |
| 342 hr = file.As(&storage_item); | 342 hr = file.As(&storage_item); |
| 343 if (FAILED(hr)) | 343 if (FAILED(hr)) |
| 344 return hr; | 344 return hr; |
| 345 | 345 |
| 346 mswrw::HString file_path_str; | 346 mswrw::HString file_path_str; |
| 347 hr = storage_item->get_Path(file_path_str.GetAddressOf()); | 347 hr = storage_item->get_Path(file_path_str.GetAddressOf()); |
| 348 if (FAILED(hr)) | 348 if (FAILED(hr)) |
| 349 return hr; | 349 return hr; |
| 350 | 350 |
| 351 FilePath file_path(MakeStdWString(file_path_str.Get())); | 351 base::FilePath file_path(MakeStdWString(file_path_str.Get())); |
| 352 if (base_path.empty()) { | 352 if (base_path.empty()) { |
| 353 DCHECK(result->empty()); | 353 DCHECK(result->empty()); |
| 354 base_path = file_path.DirName(); | 354 base_path = file_path.DirName(); |
| 355 | 355 |
| 356 // Append the path, including the terminating zero. | 356 // Append the path, including the terminating zero. |
| 357 // We do this only for the first file. | 357 // We do this only for the first file. |
| 358 result->append(base_path.value().c_str(), base_path.value().size() + 1); | 358 result->append(base_path.value().c_str(), base_path.value().size() + 1); |
| 359 } | 359 } |
| 360 DCHECK(!result->empty()); | 360 DCHECK(!result->empty()); |
| 361 DCHECK(!base_path.empty()); | 361 DCHECK(!base_path.empty()); |
| 362 DCHECK(base_path == file_path.DirName()); | 362 DCHECK(base_path == file_path.DirName()); |
| 363 | 363 |
| 364 // Append the base name, including the terminating zero. | 364 // Append the base name, including the terminating zero. |
| 365 FilePath base_name = file_path.BaseName(); | 365 base::FilePath base_name = file_path.BaseName(); |
| 366 result->append(base_name.value().c_str(), base_name.value().size() + 1); | 366 result->append(base_name.value().c_str(), base_name.value().size() + 1); |
| 367 } | 367 } |
| 368 | 368 |
| 369 DCHECK(!result->empty()); | 369 DCHECK(!result->empty()); |
| 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, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 426 |
| 427 // There can be a single extension, or a list of semicolon-separated ones. | 427 // There can be a single extension, or a list of semicolon-separated ones. |
| 428 std::vector<string16> extensions_win32_style; | 428 std::vector<string16> extensions_win32_style; |
| 429 size_t extension_count = Tokenize(walk, L";", &extensions_win32_style); | 429 size_t extension_count = Tokenize(walk, L";", &extensions_win32_style); |
| 430 DCHECK_EQ(extension_count, extensions_win32_style.size()); | 430 DCHECK_EQ(extension_count, extensions_win32_style.size()); |
| 431 | 431 |
| 432 // Metro wants suffixes only, not patterns. Also, metro does not support | 432 // Metro wants suffixes only, not patterns. Also, metro does not support |
| 433 // the all files ("*") pattern in the save picker. | 433 // the all files ("*") pattern in the save picker. |
| 434 std::vector<string16> extensions; | 434 std::vector<string16> extensions; |
| 435 for (size_t i = 0; i < extensions_win32_style.size(); ++i) { | 435 for (size_t i = 0; i < extensions_win32_style.size(); ++i) { |
| 436 string16 ext = FilePath(extensions_win32_style[i]).Extension(); | 436 string16 ext = base::FilePath(extensions_win32_style[i]).Extension(); |
| 437 if ((ext.size() < 2) || | 437 if ((ext.size() < 2) || |
| 438 (ext.find_first_of(L"*?") != string16::npos)) | 438 (ext.find_first_of(L"*?") != string16::npos)) |
| 439 continue; | 439 continue; |
| 440 extensions.push_back(ext); | 440 extensions.push_back(ext); |
| 441 } | 441 } |
| 442 | 442 |
| 443 if (!extensions.empty()) { | 443 if (!extensions.empty()) { |
| 444 // Convert to a Metro collection class. | 444 // Convert to a Metro collection class. |
| 445 mswr::ComPtr<StringVectorItf> list; | 445 mswr::ComPtr<StringVectorItf> list; |
| 446 hr = mswr::MakeAndInitialize<StringVectorImpl>( | 446 hr = mswr::MakeAndInitialize<StringVectorImpl>( |
| (...skipping 90 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 |
| OLD | NEW |