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

Unified Diff: content/browser/webui/shared_resources_data_source.cc

Issue 1932753006: Figure out the MIME type of shared WebUI resources more efficiently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: asdf Created 4 years, 8 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 | « content/browser/webui/shared_resources_data_source.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/webui/shared_resources_data_source.cc
diff --git a/content/browser/webui/shared_resources_data_source.cc b/content/browser/webui/shared_resources_data_source.cc
index d30e03f6c2ef21922a2c9020c969aea22fa9007a..aa1289c279e19cd9f3786f02f63971e66a4ca971 100644
--- a/content/browser/webui/shared_resources_data_source.cc
+++ b/content/browser/webui/shared_resources_data_source.cc
@@ -7,19 +7,22 @@
#include <stddef.h>
#include "base/containers/hash_tables.h"
+#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
-#include "base/threading/thread_restrictions.h"
#include "content/public/common/content_client.h"
#include "content/public/common/url_constants.h"
-#include "net/base/mime_util.h"
#include "ui/base/layout.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/resources/grit/webui_resources.h"
#include "ui/resources/grit/webui_resources_map.h"
+#if defined(OS_WIN)
+#include "base/strings/utf_string_conversions.h"
+#endif
+
namespace content {
namespace {
@@ -104,13 +107,45 @@ void SharedResourcesDataSource::StartDataRequest(
std::string SharedResourcesDataSource::GetMimeType(
const std::string& path) const {
- // Requests should not block on the disk! On POSIX this goes to disk.
- // http://code.google.com/p/chromium/issues/detail?id=59849
+ if (path.empty())
+ return "text/html";
+
+#if defined(OS_WIN)
+ base::FilePath file(base::UTF8ToWide(path));
+ std::string extension = base::WideToUTF8(file.FinalExtension()).substr(1);
+#else
+ base::FilePath file(path);
+ std::string extension = file.FinalExtension().substr(1);
+#endif
+
+ if (extension == "html")
+ return "text/html";
+
+ if (extension == "css")
+ return "text/css";
+
+ if (extension == "js")
+ return "application/javascript";
+
+ if (extension == "png")
+ return "image/png";
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- std::string mime_type;
- net::GetMimeTypeFromFile(base::FilePath().AppendASCII(path), &mime_type);
- return mime_type;
+ if (extension == "gif")
+ return "image/gif";
+
+ if (extension == "svg")
+ return "image/svg+xml";
+
+ if (extension == "woff2")
+ return "application/font-woff2";
+
+ CHECK(false) << path;
+ return "text/plain";
+}
+
+base::MessageLoop* SharedResourcesDataSource::MessageLoopForRequestPath(
+ const std::string& path) const {
+ return nullptr;
}
std::string
« no previous file with comments | « content/browser/webui/shared_resources_data_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698