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

Unified Diff: third_party/WebKit/Source/platform/mime/WebMimeRegistryImpl.cpp

Issue 2444873002: Move WebMIMERegistry impl from //content to blink:platform/network/mime (Closed)
Patch Set: Created 4 years, 2 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: third_party/WebKit/Source/platform/mime/WebMimeRegistryImpl.cpp
diff --git a/third_party/WebKit/Source/platform/mime/WebMimeRegistryImpl.cpp b/third_party/WebKit/Source/platform/mime/WebMimeRegistryImpl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0541aa90cd6d73f1456cf95add0adeec8a7a5355
--- /dev/null
+++ b/third_party/WebKit/Source/platform/mime/WebMimeRegistryImpl.cpp
@@ -0,0 +1,124 @@
+// Copyright 2016 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 "platform/mime/WebMimeRegistryImpl.h"
+
+#include "base/files/file_path.h"
+#include "base/strings/string_util.h"
+#include "components/mime_util/mime_util.h"
+#include "media/base/mime_util.h"
+#include "media/filters/stream_parser_factory.h"
+#include "net/base/mime_util.h"
+#include "public/platform/FilePathConversion.h"
+#include "public/platform/InterfaceProvider.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebString.h"
+#include "wtf/text/WTFString.h"
+
+namespace blink {
+
+namespace {
+
+// Convert a String to ASCII, falling back on an empty string in the case
+// of a non-ASCII string.
+// TODO(kinuko): Make mime_util methods take StringPiece instead.
+std::string ToASCIIOrEmpty(const String& str) {
+ if (str.isEmpty() || !str.containsOnlyASCII())
+ return std::string();
+
+ if (str.is8Bit()) {
+ return std::string(reinterpret_cast<const char*>(str.characters8()),
esprehn 2016/10/25 00:28:11 This is already better than what the old code was
+ str.length());
+ }
+
+ base::StringPiece16 stringPiece16(str.characters16(), str.length());
+ return std::string(stringPiece16.begin(), stringPiece16.end());
esprehn 2016/10/25 00:28:11 You could do std::string(str.characters16(), str.c
kinuko 2016/10/27 04:34:34 Done.
+}
+
+} // namespace
+
+WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMIMEType(
+ const WebString& mimeType) {
+ return mime_util::IsSupportedMimeType(ToASCIIOrEmpty(mimeType))
+ ? WebMimeRegistry::IsSupported
+ : WebMimeRegistry::IsNotSupported;
+}
+
+WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsImageMIMEType(
+ const WebString& mimeType) {
+ return mime_util::IsSupportedImageMimeType(ToASCIIOrEmpty(mimeType))
+ ? WebMimeRegistry::IsSupported
+ : WebMimeRegistry::IsNotSupported;
+}
+
+WebMimeRegistry::SupportsType
+WebMimeRegistryImpl::supportsImagePrefixedMIMEType(const WebString& mimeType) {
+ std::string asciiMimeType = ToASCIIOrEmpty(mimeType);
+ return (mime_util::IsSupportedImageMimeType(asciiMimeType) ||
+ (base::StartsWith(asciiMimeType, "image/",
+ base::CompareCase::SENSITIVE) &&
+ mime_util::IsSupportedNonImageMimeType(asciiMimeType)))
+ ? WebMimeRegistry::IsSupported
+ : WebMimeRegistry::IsNotSupported;
+}
+
+WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsJavaScriptMIMEType(
+ const WebString& mimeType) {
+ return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mimeType))
+ ? WebMimeRegistry::IsSupported
+ : WebMimeRegistry::IsNotSupported;
+}
+
+WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMediaMIMEType(
+ const WebString& mimeType,
+ const WebString& codecs) {
+ const std::string asciiMimeType = ToASCIIOrEmpty(mimeType);
+ std::vector<std::string> codecVector;
+ media::ParseCodecString(ToASCIIOrEmpty(codecs), &codecVector, false);
+ return static_cast<WebMimeRegistry::SupportsType>(
+ media::IsSupportedMediaFormat(asciiMimeType, codecVector));
+}
+
+bool WebMimeRegistryImpl::supportsMediaSourceMIMEType(const WebString& mimeType,
+ const WebString& codecs) {
+ const std::string asciiMimeType = ToASCIIOrEmpty(mimeType);
+ std::vector<std::string> parsedCodecIds;
+ media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsedCodecIds, false);
+ if (asciiMimeType.empty())
esprehn 2016/10/25 00:28:11 we can do this before calling ParseCodecString?
kinuko 2016/10/27 04:34:34 Done.
+ return false;
+ return media::StreamParserFactory::IsTypeSupported(asciiMimeType,
+ parsedCodecIds);
+}
+
+WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsNonImageMIMEType(
+ const WebString& mimeType) {
esprehn 2016/10/25 00:28:11 These should all take WTF::String instead of WebSt
kinuko 2016/10/27 04:34:34 Done.
+ return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mimeType))
+ ? WebMimeRegistry::IsSupported
+ : WebMimeRegistry::IsNotSupported;
+}
+
+WebString WebMimeRegistryImpl::mimeTypeForExtension(
+ const WebString& fileExtension) {
+ // The sandbox restricts our access to the registry, so we need to proxy
+ // these calls over to the browser process.
+ LOG(ERROR) << "**** MOJO MIME CALLED!!!";
esprehn 2016/10/25 00:28:11 Why is this an error? It doesn't seem like it shou
kinuko 2016/10/27 04:34:34 *facepalm* sure, it was just for local logging
+ if (!m_mimeRegistry) {
+ Platform::current()->interfaceProvider()->getInterface(
+ mojo::GetProxy(&m_mimeRegistry));
+ }
+ String mimeType;
+ if (!m_mimeRegistry->GetMimeTypeFromExtension(fileExtension, &mimeType))
esprehn 2016/10/25 00:28:11 This is a mojo interface, is this doing a sync IPC
kinuko 2016/10/27 04:34:34 Yes, apparently that is what we do in the existing
+ return WebString();
+ return mimeType;
+}
+
+WebString WebMimeRegistryImpl::wellKnownMimeTypeForExtension(
+ const WebString& fileExtension) {
+ std::string mimeType;
+ net::GetWellKnownMimeTypeFromExtension(
+ blink::WebStringToFilePath(fileExtension).value(), &mimeType);
+ return WebString::fromUTF8(mimeType);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698