OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // NOTE: based loosely on mozilla's nsDataChannel.cpp | 5 // NOTE: based loosely on mozilla's nsDataChannel.cpp |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "net/base/data_url.h" | 9 #include "net/base/data_url.h" |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 } else if (charset->empty() && | 58 } else if (charset->empty() && |
59 iter->compare(0, kCharsetTagLength, kCharsetTag) == 0) { | 59 iter->compare(0, kCharsetTagLength, kCharsetTag) == 0) { |
60 charset->assign(iter->substr(kCharsetTagLength)); | 60 charset->assign(iter->substr(kCharsetTagLength)); |
61 // The grammar for charset is not specially defined in RFC2045 and | 61 // The grammar for charset is not specially defined in RFC2045 and |
62 // RFC2397. It just needs to be a token. | 62 // RFC2397. It just needs to be a token. |
63 if (!net::HttpUtil::IsToken(*charset)) | 63 if (!net::HttpUtil::IsToken(*charset)) |
64 return false; | 64 return false; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 if (mime_type->empty()) { | 68 if (mime_type->empty() || |
69 // fallback to defaults if nothing specified in the URL: | 69 !ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) { |
70 // Fallback to the default if nothing specified in the mediatype part as | |
71 // specified in RFC2045. We also fallback to the default when the mediatype | |
72 // value is invalid as recommended in the RFC. | |
70 mime_type->assign("text/plain"); | 73 mime_type->assign("text/plain"); |
asanka
2014/09/30 18:35:51
If you are setting the mime_type, also set the cha
tyoshino (SeeGerritForStatus)
2014/10/01 01:03:54
As specified in RFC2397, when the mime type is emp
| |
71 } else if (!ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) { | |
72 return false; | |
73 } | 74 } |
74 if (charset->empty()) | 75 if (charset->empty()) |
75 charset->assign("US-ASCII"); | 76 charset->assign("US-ASCII"); |
76 | 77 |
77 // The caller may not be interested in receiving the data. | 78 // The caller may not be interested in receiving the data. |
78 if (!data) | 79 if (!data) |
79 return true; | 80 return true; |
80 | 81 |
81 // Preserve spaces if dealing with text or xml input, same as mozilla: | 82 // Preserve spaces if dealing with text or xml input, same as mozilla: |
82 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052 | 83 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 temp_data.resize(length + padding_needed, '='); | 124 temp_data.resize(length + padding_needed, '='); |
124 } | 125 } |
125 return base::Base64Decode(temp_data, data); | 126 return base::Base64Decode(temp_data, data); |
126 } | 127 } |
127 | 128 |
128 temp_data.swap(*data); | 129 temp_data.swap(*data); |
129 return true; | 130 return true; |
130 } | 131 } |
131 | 132 |
132 } // namespace net | 133 } // namespace net |
OLD | NEW |