Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 // RFC2397. It just needs to be a token. | 64 // RFC2397. It just needs to be a token. |
| 65 if (!HttpUtil::IsToken(*charset)) | 65 if (!HttpUtil::IsToken(*charset)) |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (mime_type->empty()) { | 70 if (mime_type->empty()) { |
| 71 // Fallback to the default if nothing specified in the mediatype part as | 71 // Fallback to the default if nothing specified in the mediatype part as |
| 72 // specified in RFC2045. As specified in RFC2397, we use |charset| even if | 72 // specified in RFC2045. As specified in RFC2397, we use |charset| even if |
| 73 // |mime_type| is empty. | 73 // |mime_type| is empty. |
| 74 mime_type->assign("text/plain"); | 74 mime_type->assign("text/plain"); |
|
mmenke
2016/05/17 15:08:56
Per RFC2397, we should certainly be setting charse
| |
| 75 } else if (!ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) { | 75 } else if (!ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) { |
| 76 // Fallback to the default as recommended in RFC2045 when the mediatype | 76 // Fallback to the default as recommended in RFC2045 when the mediatype |
| 77 // value is invalid. For this case, we don't respect |charset| but force it | 77 // value is invalid. For this case, we don't respect |charset| but force it |
| 78 // set to "US-ASCII". | 78 // set to "US-ASCII". |
| 79 mime_type->assign("text/plain"); | 79 mime_type->assign("text/plain"); |
| 80 charset->assign("US-ASCII"); | |
| 81 } | 80 } |
| 82 if (charset->empty()) | |
| 83 charset->assign("US-ASCII"); | |
| 84 | 81 |
| 85 // The caller may not be interested in receiving the data. | 82 // The caller may not be interested in receiving the data. |
| 86 if (!data) | 83 if (!data) |
| 87 return true; | 84 return true; |
| 88 | 85 |
| 89 // Preserve spaces if dealing with text or xml input, same as mozilla: | 86 // Preserve spaces if dealing with text or xml input, same as mozilla: |
| 90 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052 | 87 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052 |
| 91 // but strip them otherwise: | 88 // but strip them otherwise: |
| 92 // https://bugzilla.mozilla.org/show_bug.cgi?id=37200 | 89 // https://bugzilla.mozilla.org/show_bug.cgi?id=37200 |
| 93 // (Spaces in a data URL should be escaped, which is handled below, so any | 90 // (Spaces in a data URL should be escaped, which is handled below, so any |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 temp_data.resize(length + padding_needed, '='); | 130 temp_data.resize(length + padding_needed, '='); |
| 134 } | 131 } |
| 135 return base::Base64Decode(temp_data, data); | 132 return base::Base64Decode(temp_data, data); |
| 136 } | 133 } |
| 137 | 134 |
| 138 temp_data.swap(*data); | 135 temp_data.swap(*data); |
| 139 return true; | 136 return true; |
| 140 } | 137 } |
| 141 | 138 |
| 142 } // namespace net | 139 } // namespace net |
| OLD | NEW |