Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(951)

Unified Diff: mojo/shell/local_fetcher.cc

Issue 1268993003: Support loading html file URLs in Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup, add other html extensions. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/local_fetcher.cc
diff --git a/mojo/shell/local_fetcher.cc b/mojo/shell/local_fetcher.cc
index bdb862edd2c508947947a5e995b42c2b5bb1c352..af0d5b76b2ff1626aa40c7c42b583ec6206f6ffd 100644
--- a/mojo/shell/local_fetcher.cc
+++ b/mojo/shell/local_fetcher.cc
@@ -8,6 +8,7 @@
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
#include "mojo/common/common_type_converters.h"
@@ -63,6 +64,7 @@ URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner,
header->value = base::StringPrintf("%" PRId64, file_size);
response->headers[0] = header.Pass();
}
+ response->mime_type = String::From(MimeType());
common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip,
task_runner, base::Bind(&IgnoreResult));
return response.Pass();
@@ -77,7 +79,16 @@ void LocalFetcher::AsPath(
}
std::string LocalFetcher::MimeType() {
- return "";
+ // TODO(msw): Expand support; use net::GetMimeTypeFromExtension or similar.
+ std::string extension(base::FilePath(path_.Extension()).AsUTF8Unsafe());
+ if (base::EqualsCaseInsensitiveASCII(extension, ".html") ||
+ base::EqualsCaseInsensitiveASCII(extension, ".htm") ||
+ base::EqualsCaseInsensitiveASCII(extension, ".shtml") ||
+ base::EqualsCaseInsensitiveASCII(extension, ".shtm") ||
+ base::EqualsCaseInsensitiveASCII(extension, ".ehtml")) {
+ return "text/html";
+ }
+ return std::string();
}
bool LocalFetcher::HasMojoMagic() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698