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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/mime/WebMimeRegistryImpl.h"
6
7 #include "base/files/file_path.h"
8 #include "base/strings/string_util.h"
9 #include "components/mime_util/mime_util.h"
10 #include "media/base/mime_util.h"
11 #include "media/filters/stream_parser_factory.h"
12 #include "net/base/mime_util.h"
13 #include "public/platform/FilePathConversion.h"
14 #include "public/platform/InterfaceProvider.h"
15 #include "public/platform/Platform.h"
16 #include "public/platform/WebString.h"
17 #include "wtf/text/WTFString.h"
18
19 namespace blink {
20
21 namespace {
22
23 // Convert a String to ASCII, falling back on an empty string in the case
24 // of a non-ASCII string.
25 // TODO(kinuko): Make mime_util methods take StringPiece instead.
26 std::string ToASCIIOrEmpty(const String& str) {
27 if (str.isEmpty() || !str.containsOnlyASCII())
28 return std::string();
29
30 if (str.is8Bit()) {
31 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
32 str.length());
33 }
34
35 base::StringPiece16 stringPiece16(str.characters16(), str.length());
36 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.
37 }
38
39 } // namespace
40
41 WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMIMEType(
42 const WebString& mimeType) {
43 return mime_util::IsSupportedMimeType(ToASCIIOrEmpty(mimeType))
44 ? WebMimeRegistry::IsSupported
45 : WebMimeRegistry::IsNotSupported;
46 }
47
48 WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsImageMIMEType(
49 const WebString& mimeType) {
50 return mime_util::IsSupportedImageMimeType(ToASCIIOrEmpty(mimeType))
51 ? WebMimeRegistry::IsSupported
52 : WebMimeRegistry::IsNotSupported;
53 }
54
55 WebMimeRegistry::SupportsType
56 WebMimeRegistryImpl::supportsImagePrefixedMIMEType(const WebString& mimeType) {
57 std::string asciiMimeType = ToASCIIOrEmpty(mimeType);
58 return (mime_util::IsSupportedImageMimeType(asciiMimeType) ||
59 (base::StartsWith(asciiMimeType, "image/",
60 base::CompareCase::SENSITIVE) &&
61 mime_util::IsSupportedNonImageMimeType(asciiMimeType)))
62 ? WebMimeRegistry::IsSupported
63 : WebMimeRegistry::IsNotSupported;
64 }
65
66 WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsJavaScriptMIMEType(
67 const WebString& mimeType) {
68 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mimeType))
69 ? WebMimeRegistry::IsSupported
70 : WebMimeRegistry::IsNotSupported;
71 }
72
73 WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMediaMIMEType(
74 const WebString& mimeType,
75 const WebString& codecs) {
76 const std::string asciiMimeType = ToASCIIOrEmpty(mimeType);
77 std::vector<std::string> codecVector;
78 media::ParseCodecString(ToASCIIOrEmpty(codecs), &codecVector, false);
79 return static_cast<WebMimeRegistry::SupportsType>(
80 media::IsSupportedMediaFormat(asciiMimeType, codecVector));
81 }
82
83 bool WebMimeRegistryImpl::supportsMediaSourceMIMEType(const WebString& mimeType,
84 const WebString& codecs) {
85 const std::string asciiMimeType = ToASCIIOrEmpty(mimeType);
86 std::vector<std::string> parsedCodecIds;
87 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsedCodecIds, false);
88 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.
89 return false;
90 return media::StreamParserFactory::IsTypeSupported(asciiMimeType,
91 parsedCodecIds);
92 }
93
94 WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsNonImageMIMEType(
95 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.
96 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mimeType))
97 ? WebMimeRegistry::IsSupported
98 : WebMimeRegistry::IsNotSupported;
99 }
100
101 WebString WebMimeRegistryImpl::mimeTypeForExtension(
102 const WebString& fileExtension) {
103 // The sandbox restricts our access to the registry, so we need to proxy
104 // these calls over to the browser process.
105 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
106 if (!m_mimeRegistry) {
107 Platform::current()->interfaceProvider()->getInterface(
108 mojo::GetProxy(&m_mimeRegistry));
109 }
110 String mimeType;
111 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
112 return WebString();
113 return mimeType;
114 }
115
116 WebString WebMimeRegistryImpl::wellKnownMimeTypeForExtension(
117 const WebString& fileExtension) {
118 std::string mimeType;
119 net::GetWellKnownMimeTypeFromExtension(
120 blink::WebStringToFilePath(fileExtension).value(), &mimeType);
121 return WebString::fromUTF8(mimeType);
122 }
123
124 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698