Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/url_util.cc

Issue 23945002: file_manager: Move non-binding code to c/b/chromeos/file_manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/extensions/file_manager/url_util.h"
6
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/extensions/file_manager/app_id.h"
10 #include "net/base/escape.h"
11
12 namespace file_manager {
13 namespace util {
14 namespace {
15
16 // Returns a file manager URL for the given |path|.
17 GURL GetFileManagerUrl(const char* path) {
18 return GURL(std::string("chrome-extension://") + kFileManagerAppId + path);
19 }
20
21 // Converts a numeric dialog type to a string.
22 std::string GetDialogTypeAsString(
23 ui::SelectFileDialog::Type dialog_type) {
24 std::string type_str;
25 switch (dialog_type) {
26 case ui::SelectFileDialog::SELECT_NONE:
27 type_str = "full-page";
28 break;
29
30 case ui::SelectFileDialog::SELECT_FOLDER:
31 type_str = "folder";
32 break;
33
34 case ui::SelectFileDialog::SELECT_UPLOAD_FOLDER:
35 type_str = "upload-folder";
36 break;
37
38 case ui::SelectFileDialog::SELECT_SAVEAS_FILE:
39 type_str = "saveas-file";
40 break;
41
42 case ui::SelectFileDialog::SELECT_OPEN_FILE:
43 type_str = "open-file";
44 break;
45
46 case ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE:
47 type_str = "open-multi-file";
48 break;
49
50 default:
51 NOTREACHED();
52 }
53
54 return type_str;
55 }
56
57 } // namespace
58
59 GURL GetFileManagerBaseUrl() {
60 return GetFileManagerUrl("/");
61 }
62
63 GURL GetFileManagerMainPageUrl() {
64 return GetFileManagerUrl("/main.html");
65 }
66
67 GURL GetFileManagerMainPageUrlWithParams(
68 ui::SelectFileDialog::Type type,
69 const string16& title,
70 const base::FilePath& default_virtual_path,
71 const ui::SelectFileDialog::FileTypeInfo* file_types,
72 int file_type_index,
73 const base::FilePath::StringType& default_extension) {
74 base::DictionaryValue arg_value;
75 arg_value.SetString("type", GetDialogTypeAsString(type));
76 arg_value.SetString("title", title);
77 arg_value.SetString("defaultPath", default_virtual_path.value());
78 arg_value.SetString("defaultExtension", default_extension);
79
80 if (file_types) {
81 base::ListValue* types_list = new base::ListValue();
82 for (size_t i = 0; i < file_types->extensions.size(); ++i) {
83 base::ListValue* extensions_list = new base::ListValue();
84 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) {
85 extensions_list->Append(
86 new base::StringValue(file_types->extensions[i][j]));
87 }
88
89 base::DictionaryValue* dict = new base::DictionaryValue();
90 dict->Set("extensions", extensions_list);
91
92 if (i < file_types->extension_description_overrides.size()) {
93 string16 desc = file_types->extension_description_overrides[i];
94 dict->SetString("description", desc);
95 }
96
97 // file_type_index is 1-based. 0 means no selection at all.
98 dict->SetBoolean("selected",
99 (static_cast<size_t>(file_type_index) == (i + 1)));
100
101 types_list->Set(i, dict);
102 }
103 arg_value.Set("typeList", types_list);
104
105 arg_value.SetBoolean("includeAllFiles", file_types->include_all_files);
106 }
107
108 // If the caller cannot handle Drive path, the file chooser dialog need to
109 // return resolved local native paths to the selected files.
110 arg_value.SetBoolean("shouldReturnLocalPath",
111 !file_types || !file_types->support_drive);
112
113 std::string json_args;
114 base::JSONWriter::Write(&arg_value, &json_args);
115
116 // kChromeUIFileManagerURL could not be used since query parameters are not
117 // supported for it.
118 std::string url = GetFileManagerMainPageUrl().spec() + '?' +
119 net::EscapeUrlEncodedData(json_args,
120 false); // Space to %20 instead of +.
121 return GURL(url);
122 }
123
124 GURL GetActionChoiceUrl(const base::FilePath& virtual_path,
125 bool advanced_mode) {
126 std::string url = GetFileManagerUrl("/action_choice.html").spec();
127 if (advanced_mode)
128 url += "?advanced-mode";
129 url += "#/" + net::EscapeUrlEncodedData(virtual_path.value(),
130 false); // Space to %20 instead of +.
131 return GURL(url);
132 }
133
134 } // namespace util
135 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698