diff options
author | qinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-18 17:21:26 +0000 |
---|---|---|
committer | qinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-18 17:21:26 +0000 |
commit | c0fdf8af4d44f65b90561db2630034575463383e (patch) | |
tree | 8ccd88ef8b09be66fb6012b5250fc84cc613664a /base/files | |
parent | 855ab43da4bd0342e2b8c9592b52ef80ac0b773f (diff) | |
download | chromium_src-c0fdf8af4d44f65b90561db2630034575463383e.zip chromium_src-c0fdf8af4d44f65b90561db2630034575463383e.tar.gz chromium_src-c0fdf8af4d44f65b90561db2630034575463383e.tar.bz2 |
Fix chrome upload with content uri
For android, the upload file dialog returns files with content uri scheme(content://).
This CL makes it possible for upload to work with this new file type.
It fixes both the form and fileapi based uploads.
The CL follows the same code path used by regular file upload and the content url is encompassed by a FilePath object.
R=jar@chromium.org, joth@chromium.org, kinuko@chromium.org, mmenke@chromium.org, tsepez@chromium.org
TBR=yfriedman
BUG=278640
Review URL: https://codereview.chromium.org/46303005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235752 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/files')
-rw-r--r-- | base/files/file_path.cc | 6 | ||||
-rw-r--r-- | base/files/file_path.h | 9 | ||||
-rw-r--r-- | base/files/file_path_unittest.cc | 29 |
3 files changed, 44 insertions, 0 deletions
diff --git a/base/files/file_path.cc b/base/files/file_path.cc index cfae3a5..4cfa2e6 100644 --- a/base/files/file_path.cc +++ b/base/files/file_path.cc @@ -1280,6 +1280,12 @@ FilePath FilePath::NormalizePathSeparators() const { #endif } +#if defined(OS_ANDROID) +bool FilePath::IsContentUri() const { + return StartsWithASCII(path_, "content://", false /*case_sensitive*/); +} +#endif + } // namespace base void PrintTo(const base::FilePath& path, std::ostream* out) { diff --git a/base/files/file_path.h b/base/files/file_path.h index 4d03da4..33beb0b 100644 --- a/base/files/file_path.h +++ b/base/files/file_path.h @@ -387,6 +387,15 @@ class BASE_EXPORT FilePath { const StringType& string2); #endif +#if defined(OS_ANDROID) + // On android, file selection dialog can return a file with content uri + // scheme(starting with content://). Content uri needs to be opened with + // ContentResolver to guarantee that the app has appropriate permissions + // to access it. + // Returns true if the path is a content uri, or false otherwise. + bool IsContentUri() const; +#endif + private: // Remove trailing separators from this object. If the path is absolute, it // will never be stripped any more than to refer to the absolute root diff --git a/base/files/file_path_unittest.cc b/base/files/file_path_unittest.cc index 8b2fcf5..1b6e465 100644 --- a/base/files/file_path_unittest.cc +++ b/base/files/file_path_unittest.cc @@ -1228,4 +1228,33 @@ TEST_F(FilePathTest, AsEndingWithSeparator) { } } +#if defined(OS_ANDROID) +TEST_F(FilePathTest, ContentUriTest) { + const struct UnaryBooleanTestData cases[] = { + { FPL("content://foo.bar"), true }, + { FPL("content://foo.bar/"), true }, + { FPL("content://foo/bar"), true }, + { FPL("CoNTenT://foo.bar"), true }, + { FPL("content://"), true }, + { FPL("content:///foo.bar"), true }, + { FPL("content://3foo/bar"), true }, + { FPL("content://_foo/bar"), true }, + { FPL(".. "), false }, + { FPL("foo.bar"), false }, + { FPL("content:foo.bar"), false }, + { FPL("content:/foo.ba"), false }, + { FPL("content:/dir/foo.bar"), false }, + { FPL("content: //foo.bar"), false }, + { FPL("content%2a%2f%2f"), false }, + }; + + for (size_t i = 0; i < arraysize(cases); ++i) { + FilePath input(cases[i].input); + bool observed = input.IsContentUri(); + EXPECT_EQ(cases[i].expected, observed) << + "i: " << i << ", input: " << input.value(); + } +} +#endif + } // namespace base |