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

Side by Side Diff: webkit/glue/simple_webmimeregistry_impl.cc

Issue 165178: Revert 22813 - Merge 22027 Fix a DCHECK we hit when a mime type isn't ASCII.... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Modified: svn:mergeinfo
Reverse-merged /trunk/src/webkit/glue/simple_webmimeregistry_impl.cc:r22027
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "webkit/glue/simple_webmimeregistry_impl.h" 5 #include "webkit/glue/simple_webmimeregistry_impl.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "net/base/mime_util.h" 9 #include "net/base/mime_util.h"
10 #include "webkit/api/public/WebString.h" 10 #include "webkit/api/public/WebString.h"
11 #include "webkit/glue/glue_util.h" 11 #include "webkit/glue/glue_util.h"
12 #include "webkit/glue/webkit_glue.h" 12 #include "webkit/glue/webkit_glue.h"
13 13
14 using WebKit::WebString; 14 using WebKit::WebString;
15 using WebKit::WebMimeRegistry; 15 using WebKit::WebMimeRegistry;
16 16
17 namespace {
18
19 // Convert a WebString to ASCII, falling back on an empty string in the case
20 // of a non-ASCII string.
21 const std::string& AsASCII(const WebString& string) {
22 if (!IsStringASCII(string))
23 return EmptyString();
24 return UTF16ToASCII(string);
25 }
26
27 } // namespace
28
29 namespace webkit_glue { 17 namespace webkit_glue {
30 18
31 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( 19 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType(
32 const WebString& mime_type) { 20 const WebString& mime_type) {
33 if (!net::IsSupportedImageMimeType(AsASCII(mime_type).c_str())) 21 if (!net::IsSupportedImageMimeType(UTF16ToASCII(mime_type).c_str()))
34 return WebMimeRegistry::IsNotSupported; 22 return WebMimeRegistry::IsNotSupported;
35 return WebMimeRegistry::IsSupported; 23 return WebMimeRegistry::IsSupported;
36 } 24 }
37 25
38 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMET ype( 26 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMET ype(
39 const WebString& mime_type) { 27 const WebString& mime_type) {
40 if (!net::IsSupportedJavascriptMimeType(AsASCII(mime_type).c_str())) 28 if (!net::IsSupportedJavascriptMimeType(UTF16ToASCII(mime_type).c_str()))
41 return WebMimeRegistry::IsNotSupported; 29 return WebMimeRegistry::IsNotSupported;
42 return WebMimeRegistry::IsSupported; 30 return WebMimeRegistry::IsSupported;
43 } 31 }
44 32
45 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( 33 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
46 const WebString& mime_type, const WebString& codecs) { 34 const WebString& mime_type, const WebString& codecs) {
47 // Not supporting the container is a flat-out no. 35 // Not supporting the container is a flat-out no.
48 if (!net::IsSupportedMediaMimeType(AsASCII(mime_type).c_str())) 36 if (!net::IsSupportedMediaMimeType(UTF16ToASCII(mime_type).c_str()))
49 return IsNotSupported; 37 return IsNotSupported;
50 38
51 // If we don't recognize the codec, it's possible we support it. 39 // If we don't recognize the codec, it's possible we support it.
52 std::vector<std::string> parsed_codecs; 40 std::vector<std::string> parsed_codecs;
53 net::ParseCodecString(AsASCII(codecs).c_str(), &parsed_codecs); 41 net::ParseCodecString(UTF16ToASCII(codecs).c_str(), &parsed_codecs);
54 if (!net::AreSupportedMediaCodecs(parsed_codecs)) 42 if (!net::AreSupportedMediaCodecs(parsed_codecs))
55 return MayBeSupported; 43 return MayBeSupported;
56 44
57 // Otherwise we have a perfect match. 45 // Otherwise we have a perfect match.
58 return IsSupported; 46 return IsSupported;
59 } 47 }
60 48
61 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsNonImageMIMETyp e( 49 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsNonImageMIMETyp e(
62 const WebString& mime_type) { 50 const WebString& mime_type) {
63 if (!net::IsSupportedNonImageMimeType(AsASCII(mime_type).c_str())) 51 if (!net::IsSupportedNonImageMimeType(UTF16ToASCII(mime_type).c_str()))
64 return WebMimeRegistry::IsNotSupported; 52 return WebMimeRegistry::IsNotSupported;
65 return WebMimeRegistry::IsSupported; 53 return WebMimeRegistry::IsSupported;
66 } 54 }
67 55
68 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( 56 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension(
69 const WebString& file_extension) { 57 const WebString& file_extension) {
70 std::string mime_type; 58 std::string mime_type;
71 net::GetMimeTypeFromExtension( 59 net::GetMimeTypeFromExtension(
72 WebStringToFilePathString(file_extension), &mime_type); 60 WebStringToFilePathString(file_extension), &mime_type);
73 return ASCIIToUTF16(mime_type); 61 return ASCIIToUTF16(mime_type);
74 } 62 }
75 63
76 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( 64 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile(
77 const WebString& file_path) { 65 const WebString& file_path) {
78 std::string mime_type; 66 std::string mime_type;
79 net::GetMimeTypeFromFile( 67 net::GetMimeTypeFromFile(
80 FilePath(WebStringToFilePathString(file_path)), &mime_type); 68 FilePath(WebStringToFilePathString(file_path)), &mime_type);
81 return ASCIIToUTF16(mime_type); 69 return ASCIIToUTF16(mime_type);
82 } 70 }
83 71
84 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( 72 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(
85 const WebString& mime_type) { 73 const WebString& mime_type) {
86 FilePath::StringType file_extension; 74 FilePath::StringType file_extension;
87 net::GetPreferredExtensionForMimeType(AsASCII(mime_type), 75 net::GetPreferredExtensionForMimeType(UTF16ToASCII(mime_type),
88 &file_extension); 76 &file_extension);
89 return FilePathStringToWebString(file_extension); 77 return FilePathStringToWebString(file_extension);
90 } 78 }
91 79
92 } // namespace webkit_glue 80 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698