| Index: chrome/browser/extensions/file_manager_util.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/file_manager_util.cc (revision 95624)
|
| +++ chrome/browser/extensions/file_manager_util.cc (working copy)
|
| @@ -14,7 +14,6 @@
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_list.h"
|
| -#include "chrome/common/url_constants.h"
|
| #include "content/browser/browser_thread.h"
|
| #include "content/browser/user_metrics.h"
|
| #include "grit/generated_resources.h"
|
| @@ -153,65 +152,25 @@
|
| const SelectFileDialog::FileTypeInfo* file_types,
|
| int file_type_index,
|
| const FilePath::StringType& default_extension) {
|
| - DictionaryValue arg_value;
|
| - arg_value.SetString("type", GetDialogTypeAsString(type));
|
| - arg_value.SetString("title", title);
|
| - arg_value.SetString("defaultPath", default_virtual_path.value());
|
| - arg_value.SetString("defaultExtension", default_extension);
|
| + std::string json = GetArgumentsJson(type, title, default_virtual_path,
|
| + file_types, file_type_index,
|
| + default_extension);
|
| + return GURL(FileManagerUtil::GetFileBrowserUrl().spec() + "?" +
|
| + EscapeUrlEncodedData(json, false));
|
|
|
| - if (file_types) {
|
| - ListValue* types_list = new ListValue();
|
| - for (size_t i = 0; i < file_types->extensions.size(); ++i) {
|
| - ListValue* extensions_list = new ListValue();
|
| - for (size_t j = 0; j < file_types->extensions[i].size(); ++j) {
|
| - extensions_list->Set(
|
| - i, Value::CreateStringValue(file_types->extensions[i][j]));
|
| - }
|
| -
|
| - DictionaryValue* dict = new DictionaryValue();
|
| - dict->Set("extensions", extensions_list);
|
| -
|
| - if (i < file_types->extension_description_overrides.size()) {
|
| - string16 desc = file_types->extension_description_overrides[i];
|
| - dict->SetString("description", desc);
|
| - }
|
| -
|
| - dict->SetBoolean("selected",
|
| - (static_cast<size_t>(file_type_index) == i));
|
| -
|
| - types_list->Set(i, dict);
|
| - }
|
| - arg_value.Set("typeList", types_list);
|
| - }
|
| -
|
| - std::string json_args;
|
| - base::JSONWriter::Write(&arg_value, false, &json_args);
|
| -
|
| - // kChromeUIFileManagerURL could not be used since query parameters are not
|
| - // supported for it.
|
| - std::string url = FileManagerUtil::GetFileBrowserUrl().spec() +
|
| - '?' + EscapeUrlEncodedData(json_args, false);
|
| - return GURL(url);
|
| -
|
| }
|
|
|
| // static
|
| void FileManagerUtil::ShowFullTabUrl(Profile*,
|
| - const FilePath& dir) {
|
| + const FilePath& default_path) {
|
| + std::string json = GetArgumentsJson(SelectFileDialog::SELECT_NONE, string16(),
|
| + default_path, NULL, 0, FilePath::StringType());
|
| + GURL url(std::string(kBaseFileBrowserUrl) + "?" +
|
| + EscapeUrlEncodedData(json, false));
|
| Browser* browser = BrowserList::GetLastActive();
|
| if (!browser)
|
| return;
|
|
|
| - FilePath virtual_path;
|
| - if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(),
|
| - dir,
|
| - &virtual_path)) {
|
| - return;
|
| - }
|
| -
|
| - std::string url = chrome::kChromeUIFileManagerURL;
|
| - url += '#' + EscapeUrlEncodedData(virtual_path.value(), false);
|
| -
|
| UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab"));
|
| browser->ShowSingletonTab(GURL(url));
|
| }
|
| @@ -268,6 +227,53 @@
|
| }
|
|
|
| // static
|
| +std::string FileManagerUtil::GetArgumentsJson(
|
| + SelectFileDialog::Type type,
|
| + const string16& title,
|
| + const FilePath& default_virtual_path,
|
| + const SelectFileDialog::FileTypeInfo* file_types,
|
| + int file_type_index,
|
| + const FilePath::StringType& default_extension) {
|
| + DictionaryValue arg_value;
|
| + arg_value.SetString("type", GetDialogTypeAsString(type));
|
| + arg_value.SetString("title", title);
|
| + // TODO(zelidrag): Convert local system path into virtual path for File API.
|
| + arg_value.SetString("defaultPath", default_virtual_path.value());
|
| + arg_value.SetString("defaultExtension", default_extension);
|
| +
|
| +
|
| + if (file_types) {
|
| + ListValue* types_list = new ListValue();
|
| + for (size_t i = 0; i < file_types->extensions.size(); ++i) {
|
| + ListValue* extensions_list = new ListValue();
|
| + for (size_t j = 0; j < file_types->extensions[i].size(); ++j) {
|
| + extensions_list->Set(
|
| + i, Value::CreateStringValue(file_types->extensions[i][j]));
|
| + }
|
| +
|
| + DictionaryValue* dict = new DictionaryValue();
|
| + dict->Set("extensions", extensions_list);
|
| +
|
| + if (i < file_types->extension_description_overrides.size()) {
|
| + string16 desc = file_types->extension_description_overrides[i];
|
| + dict->SetString("description", desc);
|
| + }
|
| +
|
| + dict->SetBoolean("selected",
|
| + (static_cast<size_t>(file_type_index) == i));
|
| +
|
| + types_list->Set(i, dict);
|
| + }
|
| + arg_value.Set("typeList", types_list);
|
| + }
|
| +
|
| + std::string rv;
|
| + base::JSONWriter::Write(&arg_value, false, &rv);
|
| +
|
| + return rv;
|
| +}
|
| +
|
| +// static
|
| std::string FileManagerUtil::GetDialogTypeAsString(
|
| SelectFileDialog::Type dialog_type) {
|
| std::string type_str;
|
|
|