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/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/chromeos/file_manager/app_id.h" | 11 #include "chrome/browser/chromeos/file_manager/app_id.h" |
12 #include "net/base/escape.h" | 12 #include "net/base/escape.h" |
13 | 13 |
14 namespace file_manager { | 14 namespace file_manager { |
15 namespace util { | 15 namespace util { |
16 namespace { | 16 namespace { |
17 | 17 |
18 const char kShouldReturnLocalPath[] = "shouldReturnLocalPath"; | 18 const char kAllowedPaths[] = "allowedPaths"; |
| 19 const char kNativePath[] = "nativePath"; |
| 20 const char kNativeOrDrivePath[] = "nativeOrDrivePath"; |
| 21 const char kAnyPath[] = "anyPath"; |
19 | 22 |
20 // Returns a file manager URL for the given |path|. | 23 // Returns a file manager URL for the given |path|. |
21 GURL GetFileManagerUrl(const char* path) { | 24 GURL GetFileManagerUrl(const char* path) { |
22 return GURL(std::string("chrome-extension://") + kFileManagerAppId + path); | 25 return GURL(std::string("chrome-extension://") + kFileManagerAppId + path); |
23 } | 26 } |
24 | 27 |
25 // Converts a numeric dialog type to a string. | 28 // Converts a numeric dialog type to a string. |
26 std::string GetDialogTypeAsString( | 29 std::string GetDialogTypeAsString( |
27 ui::SelectFileDialog::Type dialog_type) { | 30 ui::SelectFileDialog::Type dialog_type) { |
28 std::string type_str; | 31 std::string type_str; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 107 |
105 types_list->Set(i, dict); | 108 types_list->Set(i, dict); |
106 } | 109 } |
107 arg_value.Set("typeList", types_list); | 110 arg_value.Set("typeList", types_list); |
108 | 111 |
109 arg_value.SetBoolean("includeAllFiles", file_types->include_all_files); | 112 arg_value.SetBoolean("includeAllFiles", file_types->include_all_files); |
110 } | 113 } |
111 | 114 |
112 // 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 |
113 // return resolved local native paths to the selected files. | 116 // return resolved local native paths to the selected files. |
114 // TODO(hirono): Turns the boolean into enum to pass support virtual path info | |
115 // to Javascript. | |
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.SetBoolean(kShouldReturnLocalPath, true); | 120 arg_value.SetString(kAllowedPaths, kNativePath); |
120 break; | 121 break; |
121 case ui::SelectFileDialog::FileTypeInfo::NATIVE_OR_DRIVE_PATH: | 122 case ui::SelectFileDialog::FileTypeInfo::NATIVE_OR_DRIVE_PATH: |
122 arg_value.SetBoolean(kShouldReturnLocalPath, false); | 123 arg_value.SetString(kAllowedPaths, kNativeOrDrivePath); |
123 break; | 124 break; |
124 case ui::SelectFileDialog::FileTypeInfo::ANY_PATH: | 125 case ui::SelectFileDialog::FileTypeInfo::ANY_PATH: |
125 arg_value.SetBoolean(kShouldReturnLocalPath, false); | 126 arg_value.SetString(kAllowedPaths, kAnyPath); |
126 break; | 127 break; |
127 } | 128 } |
128 } else { | 129 } else { |
129 arg_value.SetBoolean(kShouldReturnLocalPath, true); | 130 arg_value.SetString(kAllowedPaths, kNativePath); |
130 } | 131 } |
131 | 132 |
132 std::string json_args; | 133 std::string json_args; |
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 |