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

Unified Diff: net/base/mime_extension_chromeos.cc

Issue 1134393002: Implement ChromeOS mime type extension mappings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Flag guard two test cases for ChromeOS. Created 5 years, 7 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
Index: net/base/mime_extension_chromeos.cc
diff --git a/net/base/mime_extension_chromeos.cc b/net/base/mime_extension_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ed32d3167e9eedc357b4e9377e161c81202bb2f9
--- /dev/null
+++ b/net/base/mime_extension_chromeos.cc
@@ -0,0 +1,39 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/mime_extension_chromeos.h"
+
+#include "base/logging.h"
+#include "net/base/mime_util.h"
+
+namespace chromeos {
+
+namespace {
+
+static const net::MimeInfo mimetype_extension_mapping[] = {
+ {"application/epub+zip", "epub"},
+ {"application/zip", "zip"},
+ {"text/calendar", "ics"},
+};
+} // namespace
+
+// On linux, chrome uses xdgmime to read extension-mimetype database (e.g.
+// /usr/share/mime) and estimate mime type from extension. However ChromeOS does
+// not have such database in it, we use |mimetype_extension_mapping| to resolve
+// mime type on ChromeOS.
+bool GetPlatformMimeTypeFromExtension(const base::FilePath::StringType& ext,
+ std::string* mime_type) {
+ base::FilePath path_ext(ext);
+ const std::string ext_narrow_str = path_ext.AsUTF8Unsafe();
+ const char* result = net::FindMimeType(mimetype_extension_mapping,
+ arraysize(mimetype_extension_mapping),
+ ext_narrow_str.c_str());
+ if (result) {
+ *mime_type = result;
+ return true;
+ }
+
+ return false;
+}
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698