summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorthorogood@chromium.org <thorogood@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-09 08:37:18 +0000
committerthorogood@chromium.org <thorogood@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-09 08:37:18 +0000
commitfc6b1e314cbb4b859d27676eb5bd0e2d1bfa920b (patch)
tree01ba4a617d93fcfa49b516f2e526a58611b0ceab /chrome/browser/extensions
parentd9615dfa37bf0026cfb1c18132c725a2aa64ee79 (diff)
downloadchromium_src-fc6b1e314cbb4b859d27676eb5bd0e2d1bfa920b.zip
chromium_src-fc6b1e314cbb4b859d27676eb5bd0e2d1bfa920b.tar.gz
chromium_src-fc6b1e314cbb4b859d27676eb5bd0e2d1bfa920b.tar.bz2
Prettify output from chrome.fileSystem.getDisplayPath for Windows profile directory
Modifies the getDisplayPath to allow for replacing specific prefixes with short, relative path names. Enables this for Windows-only for now, replacing the full path to the user's profile directory with "HOME/". BUG=135690 TEST= Review URL: https://chromiumcodereview.appspot.com/10693089 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/api/file_system/file_system_api.cc41
-rw-r--r--chrome/browser/extensions/api/file_system/file_system_apitest.cc15
2 files changed, 55 insertions, 1 deletions
diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc
index c6fc2ec..871125e0 100644
--- a/chrome/browser/extensions/api/file_system/file_system_api.cc
+++ b/chrome/browser/extensions/api/file_system/file_system_api.cc
@@ -7,6 +7,8 @@
#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
@@ -38,6 +40,44 @@ namespace ChooseFile = file_system::ChooseFile;
namespace {
+struct RewritePair {
+ int path_key;
+ const char* output;
+};
+
+const RewritePair g_rewrite_pairs[] = {
+#if defined(OS_WIN)
+ {base::DIR_PROFILE, "~"},
+#endif
+};
+
+FilePath PrettifyPath(const FilePath& file_path) {
+ // Note that when g_rewrite_pairs includes at least one value on all
+ // platforms, this code can be cleaned up.
+#if defined(OS_WIN)
+ size_t size = arraysize(g_rewrite_pairs);
+#else
+ size_t size = 0;
+#endif
+
+ for (size_t i = 0; i < size; ++i) {
+ FilePath candidate_path;
+ if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path))
+ continue; // We don't DCHECK this value, as Get will return false even
+ // if the path_key gives a blank string as a result.
+
+ FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output);
+ if (candidate_path.AppendRelativePath(file_path, &output)) {
+ // The output path must not be absolute, as it might collide with the
+ // real filesystem.
+ DCHECK(!output.IsAbsolute());
+ return output;
+ }
+ }
+
+ return file_path;
+}
+
bool g_skip_picker_for_test = false;
FilePath* g_path_to_be_picked_for_test;
@@ -107,6 +147,7 @@ bool FileSystemGetDisplayPathFunction::RunImpl() {
render_view_host_, &file_path, &error_))
return false;
+ file_path = PrettifyPath(file_path);
result_.reset(base::Value::CreateStringValue(file_path.value()));
return true;
}
diff --git a/chrome/browser/extensions/api/file_system/file_system_apitest.cc b/chrome/browser/extensions/api/file_system/file_system_apitest.cc
index 5142d99..5ef2a7f 100644
--- a/chrome/browser/extensions/api/file_system/file_system_apitest.cc
+++ b/chrome/browser/extensions/api/file_system/file_system_apitest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/file_util.h"
+#include "base/path_service.h"
#include "chrome/browser/extensions/api/file_system/file_system_api.h"
#include "chrome/browser/extensions/platform_app_browsertest_util.h"
@@ -47,6 +48,19 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) {
<< message_;
}
+#if defined(OS_WIN)
+IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) {
+ ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(base::DIR_PROFILE,
+ test_root_folder_, false));
+
+ FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
+ FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest(
+ &test_file);
+ ASSERT_TRUE(RunPlatformAppTest(
+ "api_test/file_system/get_display_path_prettify")) << message_;
+}
+#endif
+
IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenExistingFileTest) {
FilePath test_file = TempFilePath("open_existing.txt", true);
ASSERT_FALSE(test_file.empty());
@@ -174,4 +188,3 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
ASSERT_TRUE(RunPlatformAppTest(
"api_test/file_system/get_writable_file_entry_with_write")) << message_;
}
-