| Index: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc
|
| diff --git a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc
|
| index 26c3db560f4e50625ccf73fa079cafbbdc6bb89f..488265b0fffc4b178bf688a610ee8476e2beccdd 100644
|
| --- a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc
|
| +++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc
|
| @@ -4,16 +4,92 @@
|
|
|
| #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h"
|
|
|
| -#include <vector>
|
| +#include <algorithm>
|
| +#include <utility>
|
|
|
| +#include "base/strings/string_split.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "net/base/escape.h"
|
| +#include "net/base/mime_util.h"
|
| #include "storage/browser/fileapi/file_system_url.h"
|
| #include "url/gurl.h"
|
|
|
| namespace arc {
|
|
|
| +namespace {
|
| +
|
| +struct MimeTypeToExtensions {
|
| + const char* mime_type;
|
| + const char* extensions;
|
| +};
|
| +
|
| +// The mapping from MIME types to file name extensions, taken from Android N.
|
| +// See: frameworks/base/media/java/android/media/MediaFile.java
|
| +constexpr MimeTypeToExtensions kAndroidMimeTypeMappings[] = {
|
| + {"application/mspowerpoint", "ppt"},
|
| + {"application/msword", "doc"},
|
| + {"application/ogg", "ogg,oga"},
|
| + {"application/pdf", "pdf"},
|
| + {"application/vnd.apple.mpegurl", "m3u8"},
|
| + {"application/vnd.ms-excel", "xls"},
|
| + {"application/vnd.ms-wpl", "wpl"},
|
| + {"application/x-android-drm-fl", "fl"},
|
| + {"application/x-mpegurl", "m3u"},
|
| + {"application/zip", "zip"},
|
| + {"audio/aac", "aac"},
|
| + {"audio/aac-adts", "aac"},
|
| + {"audio/amr", "amr"},
|
| + {"audio/amr-wb", "awb"},
|
| + {"audio/flac", "flac"},
|
| + {"audio/imelody", "imy"},
|
| + {"audio/midi", "mid,midi,xmf,rtttl,rtx,ota,mxmf"},
|
| + {"audio/mp4", "m4a"},
|
| + {"audio/mpeg", "mp3,mpga"},
|
| + {"audio/mpegurl", "m3u8"},
|
| + {"audio/ogg", "ogg"},
|
| + {"audio/sp-midi", "smf"},
|
| + {"audio/x-matroska", "mka"},
|
| + {"audio/x-mpegurl", "m3u,m3u8"},
|
| + {"audio/x-ms-wma", "wma"},
|
| + {"audio/x-scpls", "pls"},
|
| + {"audio/x-wav", "wav"},
|
| + {"image/gif", "gif"},
|
| + {"image/jpeg", "jpg,jpeg"},
|
| + {"image/png", "png"},
|
| + {"image/vnd.wap.wbmp", "wbmp"},
|
| + {"image/webp", "webp"},
|
| + {"image/x-adobe-dng", "dng"},
|
| + {"image/x-canon-cr2", "cr2"},
|
| + {"image/x-fuji-raf", "raf"},
|
| + {"image/x-ms-bmp", "bmp"},
|
| + {"image/x-nikon-nef", "nef"},
|
| + {"image/x-nikon-nrw", "nrw"},
|
| + {"image/x-olympus-orf", "orf"},
|
| + {"image/x-panasonic-rw2", "rw2"},
|
| + {"image/x-pentax-pef", "pef"},
|
| + {"image/x-samsung-srw", "srw"},
|
| + {"image/x-sony-arw", "arw"},
|
| + {"text/html", "html,htm"},
|
| + {"text/plain", "txt"},
|
| + {"video/3gpp", "3gp,3gpp"},
|
| + {"video/3gpp2", "3g2,3gpp2"},
|
| + {"video/avi", "avi"},
|
| + {"video/mp2p", "mpg,mpeg"},
|
| + {"video/mp2ts", "ts"},
|
| + {"video/mp4", "mp4,m4v"},
|
| + {"video/mpeg", "mpg,mpeg"},
|
| + {"video/quicktime", "mov"},
|
| + {"video/webm", "webm"},
|
| + {"video/x-matroska", "mkv"},
|
| + {"video/x-ms-asf", "asf"},
|
| + {"video/x-ms-wmv", "wmv"},
|
| +};
|
| +
|
| +constexpr char kApplicationOctetStreamMimeType[] = "application/octet-stream";
|
| +
|
| +} // namespace
|
| +
|
| // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape.
|
| // TODO(nya): Consider consolidating this function with EscapeFileSystemId() in
|
| // chrome/browser/chromeos/file_system_provider/mount_path_util.cc.
|
| @@ -99,4 +175,45 @@ GURL BuildDocumentUrl(const std::string& authority,
|
| net::EscapeQueryParamValue(document_id, false /* use_plus */).c_str()));
|
| }
|
|
|
| +std::vector<base::FilePath::StringType> GetExtensionsForArcMimeType(
|
| + const std::string& mime_type) {
|
| + // net::GetExtensionsForMimeType() returns unwanted extensions like
|
| + // "exe,com,bin" for application/octet-stream.
|
| + if (net::MatchesMimeType(kApplicationOctetStreamMimeType, mime_type))
|
| + return std::vector<base::FilePath::StringType>();
|
| +
|
| + // Attempt net::GetExtensionsForMimeType().
|
| + {
|
| + std::vector<base::FilePath::StringType> extensions;
|
| + net::GetExtensionsForMimeType(mime_type, &extensions);
|
| + if (!extensions.empty()) {
|
| + base::FilePath::StringType preferred_extension;
|
| + if (net::GetPreferredExtensionForMimeType(mime_type,
|
| + &preferred_extension)) {
|
| + auto iter = std::find(extensions.begin(), extensions.end(),
|
| + preferred_extension);
|
| + if (iter == extensions.end()) {
|
| + // This is unlikely to happen, but there is no guarantee.
|
| + extensions.insert(extensions.begin(), preferred_extension);
|
| + } else {
|
| + std::swap(extensions.front(), *iter);
|
| + }
|
| + }
|
| + return extensions;
|
| + }
|
| + }
|
| +
|
| + // Fallback to our hard-coded list.
|
| + for (const auto& entry : kAndroidMimeTypeMappings) {
|
| + if (net::MatchesMimeType(entry.mime_type, mime_type)) {
|
| + // We assume base::FilePath::StringType == std::string as this code is
|
| + // built only on Chrome OS.
|
| + return base::SplitString(entry.extensions, ",", base::TRIM_WHITESPACE,
|
| + base::SPLIT_WANT_ALL);
|
| + }
|
| + }
|
| +
|
| + return std::vector<base::FilePath::StringType>();
|
| +}
|
| +
|
| } // namespace arc
|
|
|