From 0ab37da785b8853644211d46f7d800932824cec8 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Fri, 20 Jan 2017 19:09:37 +0530 Subject: [PATCH] replace redundant mimetype helper with net utility --- .../browser/atom_web_ui_controller_factory.cc | 32 +++---------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/atom/browser/atom_web_ui_controller_factory.cc b/atom/browser/atom_web_ui_controller_factory.cc index 0d80b07a6e07..a53eac354db4 100644 --- a/atom/browser/atom_web_ui_controller_factory.cc +++ b/atom/browser/atom_web_ui_controller_factory.cc @@ -18,6 +18,7 @@ #include "content/public/browser/web_ui_controller.h" #include "content/public/common/bindings_policy.h" #include "grit/pdf_viewer_resources_map.h" +#include "net/base/mime_util.h" #include "ui/base/resource/resource_bundle.h" namespace atom { @@ -30,32 +31,6 @@ std::string PathWithoutParams(const std::string& path) { return GURL(std::string("chrome://pdf-viewer/") + path).path().substr(1); } -std::string GetMimeTypeForPath(const std::string& path) { - std::string filename = PathWithoutParams(path); - if (base::EndsWith(filename, ".html", base::CompareCase::INSENSITIVE_ASCII)) { - return "text/html"; - } else if (base::EndsWith(filename, ".css", - base::CompareCase::INSENSITIVE_ASCII)) { - return "text/css"; - } else if (base::EndsWith(filename, ".js", - base::CompareCase::INSENSITIVE_ASCII)) { - return "application/javascript"; - } else if (base::EndsWith(filename, ".png", - base::CompareCase::INSENSITIVE_ASCII)) { - return "image/png"; - } else if (base::EndsWith(filename, ".gif", - base::CompareCase::INSENSITIVE_ASCII)) { - return "image/gif"; - } else if (base::EndsWith(filename, ".svg", - base::CompareCase::INSENSITIVE_ASCII)) { - return "image/svg+xml"; - } else if (base::EndsWith(filename, ".manifest", - base::CompareCase::INSENSITIVE_ASCII)) { - return "text/cache-manifest"; - } - return "text/html"; -} - class BundledDataSource : public content::URLDataSource { public: BundledDataSource() { @@ -88,7 +63,10 @@ class BundledDataSource : public content::URLDataSource { } std::string GetMimeType(const std::string& path) const override { - return GetMimeTypeForPath(path); + std::string filename = PathWithoutParams(path); + std::string mime_type; + net::GetMimeTypeFromFile(base::FilePath(filename), &mime_type); + return mime_type; } bool ShouldAddContentSecurityPolicy() const override { return false; }