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/chromeos/file_manager/url_util.h" | 5 #include "chrome/browser/chromeos/file_manager/url_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/chromeos/file_manager/app_id.h" | 12 #include "chrome/browser/chromeos/file_manager/app_id.h" |
12 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
13 | 14 |
14 namespace file_manager { | 15 namespace file_manager { |
15 namespace util { | 16 namespace util { |
16 namespace { | 17 namespace { |
17 | 18 |
18 const char kAllowedPaths[] = "allowedPaths"; | 19 const char kAllowedPaths[] = "allowedPaths"; |
19 const char kNativePath[] = "nativePath"; | 20 const char kNativePath[] = "nativePath"; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 const base::FilePath::StringType& default_extension) { | 79 const base::FilePath::StringType& default_extension) { |
79 base::DictionaryValue arg_value; | 80 base::DictionaryValue arg_value; |
80 arg_value.SetString("type", GetDialogTypeAsString(type)); | 81 arg_value.SetString("type", GetDialogTypeAsString(type)); |
81 arg_value.SetString("title", title); | 82 arg_value.SetString("title", title); |
82 arg_value.SetString("currentDirectoryURL", current_directory_url.spec()); | 83 arg_value.SetString("currentDirectoryURL", current_directory_url.spec()); |
83 arg_value.SetString("selectionURL", selection_url.spec()); | 84 arg_value.SetString("selectionURL", selection_url.spec()); |
84 arg_value.SetString("targetName", target_name); | 85 arg_value.SetString("targetName", target_name); |
85 arg_value.SetString("defaultExtension", default_extension); | 86 arg_value.SetString("defaultExtension", default_extension); |
86 | 87 |
87 if (file_types) { | 88 if (file_types) { |
88 base::ListValue* types_list = new base::ListValue(); | 89 auto types_list = base::MakeUnique<base::ListValue>(); |
89 for (size_t i = 0; i < file_types->extensions.size(); ++i) { | 90 for (size_t i = 0; i < file_types->extensions.size(); ++i) { |
90 base::ListValue* extensions_list = new base::ListValue(); | 91 base::ListValue* extensions_list = new base::ListValue(); |
91 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { | 92 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { |
92 extensions_list->AppendString(file_types->extensions[i][j]); | 93 extensions_list->AppendString(file_types->extensions[i][j]); |
93 } | 94 } |
94 | 95 |
95 base::DictionaryValue* dict = new base::DictionaryValue(); | 96 auto dict = base::MakeUnique<base::DictionaryValue>(); |
96 dict->Set("extensions", extensions_list); | 97 dict->Set("extensions", std::move(extensions_list)); |
97 | 98 |
98 if (i < file_types->extension_description_overrides.size()) { | 99 if (i < file_types->extension_description_overrides.size()) { |
99 base::string16 desc = file_types->extension_description_overrides[i]; | 100 base::string16 desc = file_types->extension_description_overrides[i]; |
100 dict->SetString("description", desc); | 101 dict->SetString("description", desc); |
101 } | 102 } |
102 | 103 |
103 // file_type_index is 1-based. 0 means no selection at all. | 104 // file_type_index is 1-based. 0 means no selection at all. |
104 dict->SetBoolean("selected", | 105 dict->SetBoolean("selected", |
105 (static_cast<size_t>(file_type_index) == (i + 1))); | 106 (static_cast<size_t>(file_type_index) == (i + 1))); |
106 | 107 |
107 types_list->Set(i, dict); | 108 types_list->Set(i, std::move(dict)); |
108 } | 109 } |
109 arg_value.Set("typeList", types_list); | 110 arg_value.Set("typeList", std::move(types_list)); |
110 | 111 |
111 arg_value.SetBoolean("includeAllFiles", file_types->include_all_files); | 112 arg_value.SetBoolean("includeAllFiles", file_types->include_all_files); |
112 } | 113 } |
113 | 114 |
114 // If the caller cannot handle Drive path, the file chooser dialog need to | 115 // If the caller cannot handle Drive path, the file chooser dialog need to |
115 // return resolved local native paths to the selected files. | 116 // return resolved local native paths to the selected files. |
116 if (file_types) { | 117 if (file_types) { |
117 switch (file_types->allowed_paths) { | 118 switch (file_types->allowed_paths) { |
118 case ui::SelectFileDialog::FileTypeInfo::NATIVE_PATH: | 119 case ui::SelectFileDialog::FileTypeInfo::NATIVE_PATH: |
119 arg_value.SetString(kAllowedPaths, kNativePath); | 120 arg_value.SetString(kAllowedPaths, kNativePath); |
(...skipping 13 matching lines...) Expand all Loading... |
133 base::JSONWriter::Write(arg_value, &json_args); | 134 base::JSONWriter::Write(arg_value, &json_args); |
134 | 135 |
135 std::string url = GetFileManagerMainPageUrl().spec() + '?' + | 136 std::string url = GetFileManagerMainPageUrl().spec() + '?' + |
136 net::EscapeUrlEncodedData(json_args, | 137 net::EscapeUrlEncodedData(json_args, |
137 false); // Space to %20 instead of +. | 138 false); // Space to %20 instead of +. |
138 return GURL(url); | 139 return GURL(url); |
139 } | 140 } |
140 | 141 |
141 } // namespace util | 142 } // namespace util |
142 } // namespace file_manager | 143 } // namespace file_manager |
OLD | NEW |