Commit c0a85c7d authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[Native File System] Report "well known" mime types for returned blobs.

It probably would be nice to support more than just chrome's set of well
known types, but this at least is better than nothing.

Bug: 962306
Change-Id: Ie337742f4c105fd83b1a8cb30dedba9d47ce97e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1700332
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677128}
parent 0e59d434
......@@ -5,6 +5,7 @@
#include "content/browser/native_file_system/native_file_system_file_handle_impl.h"
#include "base/guid.h"
#include "net/base/mime_util.h"
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_impl.h"
#include "storage/browser/blob/blob_storage_context.h"
......@@ -119,6 +120,18 @@ void NativeFileSystemFileHandleImpl::DidGetMetaDataForBlob(
// backed by a file on disk.
blob_builder->AppendFileSystemFile(url().ToGURL(), 0, -1, info.last_modified,
file_system_context());
base::FilePath::StringType extension = url().path().Extension();
if (!extension.empty()) {
std::string mime_type;
// TODO(https://crbug.com/962306): Using GetMimeTypeFromExtension and
// including platform defined mime type mappings might be nice/make sense,
// however that method can potentially block and thus can't be called from
// the IO thread.
if (net::GetWellKnownMimeTypeFromExtension(extension.substr(1), &mime_type))
blob_builder->set_content_type(mime_type);
}
std::unique_ptr<BlobDataHandle> blob_handle =
blob_context()->AddFinishedBlob(std::move(blob_builder));
if (blob_handle->IsBroken()) {
......@@ -127,16 +140,14 @@ void NativeFileSystemFileHandleImpl::DidGetMetaDataForBlob(
return;
}
std::string content_type = blob_handle->content_type();
blink::mojom::BlobPtr blob_ptr;
BlobImpl::Create(std::move(blob_handle), mojo::MakeRequest(&blob_ptr));
// TODO(mek): Figure out what mime-type to use for these files. The old
// file system API implementation uses net::GetWellKnownMimeTypeFromExtension
// to figure out a reasonable mime type based on the extension.
std::move(callback).Run(
NativeFileSystemError::New(base::File::FILE_OK),
blink::mojom::SerializedBlob::New(uuid, "application/octet-stream",
info.size, blob_ptr.PassInterface()));
blink::mojom::SerializedBlob::New(uuid, content_type, info.size,
blob_ptr.PassInterface()));
}
void NativeFileSystemFileHandleImpl::RemoveImpl(RemoveCallback callback) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment