| 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 "chrome/browser/file_select_helper.h" | 5 #include "chrome/browser/file_select_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
| 12 #include "base/platform_file.h" | |
| 13 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/platform_util.h" | 15 #include "chrome/browser/platform_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/chrome_select_file_policy.h" | 19 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 // There is only one file-selection happening at any given time, | 41 // There is only one file-selection happening at any given time, |
| 43 // so we allocate an enumeration ID for that purpose. All IDs from | 42 // so we allocate an enumeration ID for that purpose. All IDs from |
| 44 // the renderer must start at 0 and increase. | 43 // the renderer must start at 0 and increase. |
| 45 const int kFileSelectEnumerationId = -1; | 44 const int kFileSelectEnumerationId = -1; |
| 46 | 45 |
| 47 void NotifyRenderViewHost(RenderViewHost* render_view_host, | 46 void NotifyRenderViewHost(RenderViewHost* render_view_host, |
| 48 const std::vector<ui::SelectedFileInfo>& files, | 47 const std::vector<ui::SelectedFileInfo>& files, |
| 49 ui::SelectFileDialog::Type dialog_type) { | 48 ui::SelectFileDialog::Type dialog_type) { |
| 50 const int kReadFilePermissions = | 49 RenderViewHost::FileSelectionPermissions permissions = |
| 51 base::PLATFORM_FILE_OPEN | | 50 RenderViewHost::FILE_PERMISSION_READ_ONLY; |
| 52 base::PLATFORM_FILE_READ | | |
| 53 base::PLATFORM_FILE_EXCLUSIVE_READ | | |
| 54 base::PLATFORM_FILE_ASYNC; | |
| 55 | |
| 56 const int kWriteFilePermissions = | |
| 57 base::PLATFORM_FILE_CREATE | | |
| 58 base::PLATFORM_FILE_CREATE_ALWAYS | | |
| 59 base::PLATFORM_FILE_OPEN | | |
| 60 base::PLATFORM_FILE_OPEN_ALWAYS | | |
| 61 base::PLATFORM_FILE_OPEN_TRUNCATED | | |
| 62 base::PLATFORM_FILE_WRITE | | |
| 63 base::PLATFORM_FILE_WRITE_ATTRIBUTES | | |
| 64 base::PLATFORM_FILE_ASYNC; | |
| 65 | |
| 66 int permissions = kReadFilePermissions; | |
| 67 if (dialog_type == ui::SelectFileDialog::SELECT_SAVEAS_FILE) | 51 if (dialog_type == ui::SelectFileDialog::SELECT_SAVEAS_FILE) |
| 68 permissions = kWriteFilePermissions; | 52 permissions = RenderViewHost::FILE_PERMISSION_WRITE; |
| 69 render_view_host->FilesSelectedInChooser(files, permissions); | 53 render_view_host->FilesSelectedInChooser(files, permissions); |
| 70 } | 54 } |
| 71 | 55 |
| 72 // Converts a list of FilePaths to a list of ui::SelectedFileInfo. | 56 // Converts a list of FilePaths to a list of ui::SelectedFileInfo. |
| 73 std::vector<ui::SelectedFileInfo> FilePathListToSelectedFileInfoList( | 57 std::vector<ui::SelectedFileInfo> FilePathListToSelectedFileInfoList( |
| 74 const std::vector<base::FilePath>& paths) { | 58 const std::vector<base::FilePath>& paths) { |
| 75 std::vector<ui::SelectedFileInfo> selected_files; | 59 std::vector<ui::SelectedFileInfo> selected_files; |
| 76 for (size_t i = 0; i < paths.size(); ++i) { | 60 for (size_t i = 0; i < paths.size(); ++i) { |
| 77 selected_files.push_back( | 61 selected_files.push_back( |
| 78 ui::SelectedFileInfo(paths[i], paths[i])); | 62 ui::SelectedFileInfo(paths[i], paths[i])); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 // A 1 character accept type will always be invalid (either a "." in the case | 479 // A 1 character accept type will always be invalid (either a "." in the case |
| 496 // of an extension or a "/" in the case of a MIME type). | 480 // of an extension or a "/" in the case of a MIME type). |
| 497 std::string unused; | 481 std::string unused; |
| 498 if (accept_type.length() <= 1 || | 482 if (accept_type.length() <= 1 || |
| 499 StringToLowerASCII(accept_type) != accept_type || | 483 StringToLowerASCII(accept_type) != accept_type || |
| 500 TrimWhitespaceASCII(accept_type, TRIM_ALL, &unused) != TRIM_NONE) { | 484 TrimWhitespaceASCII(accept_type, TRIM_ALL, &unused) != TRIM_NONE) { |
| 501 return false; | 485 return false; |
| 502 } | 486 } |
| 503 return true; | 487 return true; |
| 504 } | 488 } |
| OLD | NEW |