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

Side by Side Diff: content/child/simple_webmimeregistry_impl.cc

Issue 1110833003: Move the IsSupported* mime functions out of //net and into //components/mime_util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/simple_webmimeregistry_impl.h" 5 #include "content/child/simple_webmimeregistry_impl.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/mime_util/mime_util.h"
11 #include "net/base/mime_util.h" 12 #include "net/base/mime_util.h"
12 #include "third_party/WebKit/public/platform/WebString.h" 13 #include "third_party/WebKit/public/platform/WebString.h"
13 14
14 using blink::WebString; 15 using blink::WebString;
15 using blink::WebMimeRegistry; 16 using blink::WebMimeRegistry;
16 17
17 namespace content { 18 namespace content {
18 19
19 //static 20 //static
20 std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) { 21 std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) {
21 return base::IsStringASCII(string) ? base::UTF16ToASCII(string) 22 return base::IsStringASCII(string) ? base::UTF16ToASCII(string)
22 : std::string(); 23 : std::string();
23 } 24 }
24 25
25 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType( 26 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType(
26 const WebString& mime_type) { 27 const WebString& mime_type) {
27 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ? 28 return mime_util::IsSupportedMimeType(ToASCIIOrEmpty(mime_type))
28 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 29 ? WebMimeRegistry::IsSupported
30 : WebMimeRegistry::IsNotSupported;
29 } 31 }
30 32
31 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( 33 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType(
32 const WebString& mime_type) { 34 const WebString& mime_type) {
33 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ? 35 return mime_util::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type))
34 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 36 ? WebMimeRegistry::IsSupported
37 : WebMimeRegistry::IsNotSupported;
35 } 38 }
36 39
37 WebMimeRegistry::SupportsType 40 WebMimeRegistry::SupportsType
38 SimpleWebMimeRegistryImpl::supportsImagePrefixedMIMEType( 41 SimpleWebMimeRegistryImpl::supportsImagePrefixedMIMEType(
39 const WebString& mime_type) { 42 const WebString& mime_type) {
40 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type); 43 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type);
41 return (net::IsSupportedImageMimeType(ascii_mime_type) || 44 return (mime_util::IsSupportedImageMimeType(ascii_mime_type) ||
42 (StartsWithASCII(ascii_mime_type, "image/", true) && 45 (StartsWithASCII(ascii_mime_type, "image/", true) &&
43 net::IsSupportedNonImageMimeType(ascii_mime_type))) ? 46 mime_util::IsSupportedNonImageMimeType(ascii_mime_type)))
44 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 47 ? WebMimeRegistry::IsSupported
48 : WebMimeRegistry::IsNotSupported;
45 } 49 }
46 50
47 WebMimeRegistry::SupportsType 51 WebMimeRegistry::SupportsType
48 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( 52 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
49 const WebString& mime_type) { 53 const WebString& mime_type) {
50 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ? 54 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type))
51 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 55 ? WebMimeRegistry::IsSupported
56 : WebMimeRegistry::IsNotSupported;
52 } 57 }
53 58
54 // When debugging layout tests failures in the test shell, 59 // When debugging layout tests failures in the test shell,
55 // see TestShellWebMimeRegistryImpl. 60 // see TestShellWebMimeRegistryImpl.
56 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( 61 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
57 const WebString& mime_type, 62 const WebString& mime_type,
58 const WebString& codecs, 63 const WebString& codecs,
59 const WebString& key_system) { 64 const WebString& key_system) {
60 // Media features are only supported at the content/renderer/ layer. 65 // Media features are only supported at the content/renderer/ layer.
61 return IsNotSupported; 66 return IsNotSupported;
62 } 67 }
63 68
64 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( 69 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType(
65 const WebString& mime_type, 70 const WebString& mime_type,
66 const WebString& codecs) { 71 const WebString& codecs) {
67 // Media features are only supported at the content/renderer layer. 72 // Media features are only supported at the content/renderer layer.
68 return false; 73 return false;
69 } 74 }
70 75
71 WebMimeRegistry::SupportsType 76 WebMimeRegistry::SupportsType
72 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( 77 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
73 const WebString& mime_type) { 78 const WebString& mime_type) {
74 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? 79 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type))
75 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 80 ? WebMimeRegistry::IsSupported
81 : WebMimeRegistry::IsNotSupported;
76 } 82 }
77 83
78 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( 84 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension(
79 const WebString& file_extension) { 85 const WebString& file_extension) {
80 std::string mime_type; 86 std::string mime_type;
81 net::GetMimeTypeFromExtension( 87 net::GetMimeTypeFromExtension(
82 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); 88 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type);
83 return WebString::fromUTF8(mime_type); 89 return WebString::fromUTF8(mime_type);
84 } 90 }
85 91
86 WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension( 92 WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension(
87 const WebString& file_extension) { 93 const WebString& file_extension) {
88 std::string mime_type; 94 std::string mime_type;
89 net::GetWellKnownMimeTypeFromExtension( 95 net::GetWellKnownMimeTypeFromExtension(
90 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); 96 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type);
91 return WebString::fromUTF8(mime_type); 97 return WebString::fromUTF8(mime_type);
92 } 98 }
93 99
94 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( 100 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile(
95 const WebString& file_path) { 101 const WebString& file_path) {
96 std::string mime_type; 102 std::string mime_type;
97 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path), 103 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path),
98 &mime_type); 104 &mime_type);
99 return WebString::fromUTF8(mime_type); 105 return WebString::fromUTF8(mime_type);
100 } 106 }
101 107
102 } // namespace content 108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698