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

Unified Diff: mojo/shell/local_fetcher.cc

Issue 1274433003: Add GetMimeTypeFromFile to Mojo's network service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix string usage and NativeApplicationLoaderTest. 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 | « mojo/shell/local_fetcher.h ('k') | 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 af0d5b76b2ff1626aa40c7c42b583ec6206f6ffd..8da8ca9b5d4cef31a5fdfd03949a4d331ba64ffb 100644
--- a/mojo/shell/local_fetcher.cc
+++ b/mojo/shell/local_fetcher.cc
@@ -14,6 +14,7 @@
#include "mojo/common/common_type_converters.h"
#include "mojo/common/data_pipe_utils.h"
#include "mojo/common/url_type_converters.h"
+#include "mojo/services/network/public/interfaces/network_service.mojom.h"
#include "mojo/util/filename_util.h"
#include "url/url_util.h"
@@ -28,13 +29,27 @@ void IgnoreResult(bool result) {
} // namespace
// A loader for local files.
-LocalFetcher::LocalFetcher(const GURL& url,
+LocalFetcher::LocalFetcher(NetworkService* network_service,
+ const GURL& url,
const GURL& url_without_query,
const FetchCallback& loader_callback)
: Fetcher(loader_callback),
url_(url),
path_(util::UrlToFilePath(url_without_query)) {
TRACE_EVENT1("mojo_shell", "LocalFetcher::LocalFetcher", "url", url.spec());
+ const std::string ext(base::FilePath(path_.Extension()).AsUTF8Unsafe());
+ if (network_service && !base::EqualsCaseInsensitiveASCII(ext, ".mojo")) {
+ network_service->GetMimeTypeFromFile(
+ path_.AsUTF8Unsafe(),
+ base::Bind(&LocalFetcher::GetMimeTypeFromFileCallback,
+ base::Unretained(this)));
+ } else {
+ loader_callback_.Run(make_scoped_ptr(this));
+ }
+}
+
+void LocalFetcher::GetMimeTypeFromFileCallback(const mojo::String& mime_type) {
+ mime_type_ = mime_type.To<std::string>();
loader_callback_.Run(make_scoped_ptr(this));
}
@@ -79,16 +94,7 @@ void LocalFetcher::AsPath(
}
std::string LocalFetcher::MimeType() {
- // 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();
+ return mime_type_;
}
bool LocalFetcher::HasMojoMagic() {
« no previous file with comments | « mojo/shell/local_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698