| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/extensions/file_manager_util.h" | 4 #include "chrome/browser/extensions/file_manager_util.h" |
| 5 | 5 |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/media/media_player.h" | 11 #include "chrome/browser/chromeos/media/media_player.h" |
| 12 #include "chrome/browser/platform_util.h" | 12 #include "chrome/browser/platform_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
| 17 #include "content/browser/user_metrics.h" | 17 #include "content/browser/user_metrics.h" |
| 18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 #include "third_party/libjingle/source/talk/base/urlencode.h" | 19 #include "net/base/escape.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "webkit/fileapi/file_system_context.h" | 21 #include "webkit/fileapi/file_system_context.h" |
| 22 #include "webkit/fileapi/file_system_mount_point_provider.h" | 22 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 23 #include "webkit/fileapi/file_system_util.h" | 23 #include "webkit/fileapi/file_system_util.h" |
| 24 | 24 |
| 25 #define FILEBROWSER_URL(PATH) \ | 25 #define FILEBROWSER_URL(PATH) \ |
| 26 ("chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/" PATH) | 26 ("chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/" PATH) |
| 27 // This is the "well known" url for the file manager extension from | 27 // This is the "well known" url for the file manager extension from |
| 28 // browser/resources/file_manager. In the future we may provide a way to swap | 28 // browser/resources/file_manager. In the future we may provide a way to swap |
| 29 // out this file manager for an aftermarket part, but not yet. | 29 // out this file manager for an aftermarket part, but not yet. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 GURL FileManagerUtil::GetFileBrowserUrlWithParams( | 105 GURL FileManagerUtil::GetFileBrowserUrlWithParams( |
| 106 SelectFileDialog::Type type, | 106 SelectFileDialog::Type type, |
| 107 const string16& title, | 107 const string16& title, |
| 108 const FilePath& default_path, | 108 const FilePath& default_path, |
| 109 const SelectFileDialog::FileTypeInfo* file_types, | 109 const SelectFileDialog::FileTypeInfo* file_types, |
| 110 int file_type_index, | 110 int file_type_index, |
| 111 const FilePath::StringType& default_extension) { | 111 const FilePath::StringType& default_extension) { |
| 112 std::string json = GetArgumentsJson(type, title, default_path, file_types, | 112 std::string json = GetArgumentsJson(type, title, default_path, file_types, |
| 113 file_type_index, default_extension); | 113 file_type_index, default_extension); |
| 114 return GURL(FileManagerUtil::GetFileBrowserUrl().spec() + "?" + | 114 return GURL(FileManagerUtil::GetFileBrowserUrl().spec() + "?" + |
| 115 UrlEncodeStringWithoutEncodingSpaceAsPlus(json)); | 115 EscapeUrlEncodedData(json, false)); |
| 116 | 116 |
| 117 } | 117 } |
| 118 |
| 118 // static | 119 // static |
| 119 void FileManagerUtil::ShowFullTabUrl(Profile*, | 120 void FileManagerUtil::ShowFullTabUrl(Profile*, |
| 120 const FilePath& default_path) { | 121 const FilePath& default_path) { |
| 121 std::string json = GetArgumentsJson(SelectFileDialog::SELECT_NONE, string16(), | 122 std::string json = GetArgumentsJson(SelectFileDialog::SELECT_NONE, string16(), |
| 122 default_path, NULL, 0, FilePath::StringType()); | 123 default_path, NULL, 0, FilePath::StringType()); |
| 123 GURL url(std::string(kBaseFileBrowserUrl) + "?" + | 124 GURL url(std::string(kBaseFileBrowserUrl) + "?" + |
| 124 UrlEncodeStringWithoutEncodingSpaceAsPlus(json)); | 125 EscapeUrlEncodedData(json, false)); |
| 125 Browser* browser = BrowserList::GetLastActive(); | 126 Browser* browser = BrowserList::GetLastActive(); |
| 126 if (!browser) | 127 if (!browser) |
| 127 return; | 128 return; |
| 128 | 129 |
| 129 UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); | 130 UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); |
| 130 browser->ShowSingletonTab(GURL(url)); | 131 browser->ShowSingletonTab(GURL(url)); |
| 131 } | 132 } |
| 132 | 133 |
| 133 | |
| 134 void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) { | 134 void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) { |
| 135 std::string ext = full_path.Extension(); | 135 std::string ext = full_path.Extension(); |
| 136 // For things supported natively by the browser, we should open it | 136 // For things supported natively by the browser, we should open it |
| 137 // in a tab. | 137 // in a tab. |
| 138 if (IsSupportedBrowserExtension(ext.data())) { | 138 if (IsSupportedBrowserExtension(ext.data())) { |
| 139 std::string path; | 139 std::string path; |
| 140 path = "file://"; | 140 path = "file://"; |
| 141 path.append(full_path.value()); | 141 path.append(EscapeUrlEncodedData(full_path.value(), false)); |
| 142 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 142 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 143 bool result = BrowserThread::PostTask( | 143 bool result = BrowserThread::PostTask( |
| 144 BrowserThread::UI, FROM_HERE, | 144 BrowserThread::UI, FROM_HERE, |
| 145 NewRunnableFunction(&ViewItem, full_path, enqueue)); | 145 NewRunnableFunction(&ViewItem, full_path, enqueue)); |
| 146 DCHECK(result); | 146 DCHECK(result); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 Browser* browser = BrowserList::GetLastActive(); | 149 Browser* browser = BrowserList::GetLastActive(); |
| 150 if (browser) | 150 if (browser) |
| 151 browser->AddSelectedTabWithURL(GURL(path), PageTransition::LINK); | 151 browser->AddSelectedTabWithURL(GURL(path), PageTransition::LINK); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 const SelectFileDialog::FileTypeInfo* file_types, | 183 const SelectFileDialog::FileTypeInfo* file_types, |
| 184 int file_type_index, | 184 int file_type_index, |
| 185 const FilePath::StringType& default_extension) { | 185 const FilePath::StringType& default_extension) { |
| 186 DictionaryValue arg_value; | 186 DictionaryValue arg_value; |
| 187 arg_value.SetString("type", GetDialogTypeAsString(type)); | 187 arg_value.SetString("type", GetDialogTypeAsString(type)); |
| 188 arg_value.SetString("title", title); | 188 arg_value.SetString("title", title); |
| 189 // TODO(zelidrag): Convert local system path into virtual path for File API. | 189 // TODO(zelidrag): Convert local system path into virtual path for File API. |
| 190 arg_value.SetString("defaultPath", default_path.value()); | 190 arg_value.SetString("defaultPath", default_path.value()); |
| 191 arg_value.SetString("defaultExtension", default_extension); | 191 arg_value.SetString("defaultExtension", default_extension); |
| 192 | 192 |
| 193 ListValue* types_list = new ListValue(); | |
| 194 | 193 |
| 195 if (file_types) { | 194 if (file_types) { |
| 195 ListValue* types_list = new ListValue(); |
| 196 for (size_t i = 0; i < file_types->extensions.size(); ++i) { | 196 for (size_t i = 0; i < file_types->extensions.size(); ++i) { |
| 197 ListValue* extensions_list = new ListValue(); | 197 ListValue* extensions_list = new ListValue(); |
| 198 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { | 198 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { |
| 199 extensions_list->Set( | 199 extensions_list->Set( |
| 200 i, Value::CreateStringValue(file_types->extensions[i][j])); | 200 i, Value::CreateStringValue(file_types->extensions[i][j])); |
| 201 } | 201 } |
| 202 | 202 |
| 203 DictionaryValue* dict = new DictionaryValue(); | 203 DictionaryValue* dict = new DictionaryValue(); |
| 204 dict->Set("extensions", extensions_list); | 204 dict->Set("extensions", extensions_list); |
| 205 | 205 |
| 206 if (i < file_types->extension_description_overrides.size()) { | 206 if (i < file_types->extension_description_overrides.size()) { |
| 207 string16 desc = file_types->extension_description_overrides[i]; | 207 string16 desc = file_types->extension_description_overrides[i]; |
| 208 dict->SetString("description", desc); | 208 dict->SetString("description", desc); |
| 209 } | 209 } |
| 210 | 210 |
| 211 dict->SetBoolean("selected", | 211 dict->SetBoolean("selected", |
| 212 (static_cast<size_t>(file_type_index) == i)); | 212 (static_cast<size_t>(file_type_index) == i)); |
| 213 | 213 |
| 214 types_list->Set(i, dict); | 214 types_list->Set(i, dict); |
| 215 } | 215 } |
| 216 arg_value.Set("typeList", types_list); |
| 216 } | 217 } |
| 217 | 218 |
| 218 std::string rv; | 219 std::string rv; |
| 219 base::JSONWriter::Write(&arg_value, false, &rv); | 220 base::JSONWriter::Write(&arg_value, false, &rv); |
| 220 | 221 |
| 221 return rv; | 222 return rv; |
| 222 } | 223 } |
| 223 | 224 |
| 224 // static | 225 // static |
| 225 std::string FileManagerUtil::GetDialogTypeAsString( | 226 std::string FileManagerUtil::GetDialogTypeAsString( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 245 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: | 246 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: |
| 246 type_str = "open-multi-file"; | 247 type_str = "open-multi-file"; |
| 247 break; | 248 break; |
| 248 | 249 |
| 249 default: | 250 default: |
| 250 NOTREACHED(); | 251 NOTREACHED(); |
| 251 } | 252 } |
| 252 | 253 |
| 253 return type_str; | 254 return type_str; |
| 254 } | 255 } |
| OLD | NEW |