replace redundant mimetype helper with net utility
This commit is contained in:
parent
578b717b5f
commit
0ab37da785
1 changed files with 5 additions and 27 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include "content/public/browser/web_ui_controller.h"
|
#include "content/public/browser/web_ui_controller.h"
|
||||||
#include "content/public/common/bindings_policy.h"
|
#include "content/public/common/bindings_policy.h"
|
||||||
#include "grit/pdf_viewer_resources_map.h"
|
#include "grit/pdf_viewer_resources_map.h"
|
||||||
|
#include "net/base/mime_util.h"
|
||||||
#include "ui/base/resource/resource_bundle.h"
|
#include "ui/base/resource/resource_bundle.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -30,32 +31,6 @@ std::string PathWithoutParams(const std::string& path) {
|
||||||
return GURL(std::string("chrome://pdf-viewer/") + path).path().substr(1);
|
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 {
|
class BundledDataSource : public content::URLDataSource {
|
||||||
public:
|
public:
|
||||||
BundledDataSource() {
|
BundledDataSource() {
|
||||||
|
@ -88,7 +63,10 @@ class BundledDataSource : public content::URLDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetMimeType(const std::string& path) const override {
|
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; }
|
bool ShouldAddContentSecurityPolicy() const override { return false; }
|
||||||
|
|
Loading…
Reference in a new issue