OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 charset->assign(it + sizeof(kCharsetTag)-1, comma); | 53 charset->assign(it + sizeof(kCharsetTag)-1, comma); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 // fallback to defaults if nothing specified in the URL: | 57 // fallback to defaults if nothing specified in the URL: |
58 if (mime_type->empty()) | 58 if (mime_type->empty()) |
59 mime_type->assign("text/plain"); | 59 mime_type->assign("text/plain"); |
60 if (charset->empty()) | 60 if (charset->empty()) |
61 charset->assign("US-ASCII"); | 61 charset->assign("US-ASCII"); |
62 | 62 |
| 63 // The caller may not be interested in receiving the data. |
| 64 if (!data) |
| 65 return true; |
| 66 |
63 // Preserve spaces if dealing with text or xml input, same as mozilla: | 67 // Preserve spaces if dealing with text or xml input, same as mozilla: |
64 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052 | 68 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052 |
65 // but strip them otherwise: | 69 // but strip them otherwise: |
66 // https://bugzilla.mozilla.org/show_bug.cgi?id=37200 | 70 // https://bugzilla.mozilla.org/show_bug.cgi?id=37200 |
67 // (Spaces in a data URL should be escaped, which is handled below, so any | 71 // (Spaces in a data URL should be escaped, which is handled below, so any |
68 // spaces now are wrong. People expect to be able to enter them in the URL | 72 // spaces now are wrong. People expect to be able to enter them in the URL |
69 // bar for text, and it can't hurt, so we allow it.) | 73 // bar for text, and it can't hurt, so we allow it.) |
70 std::string temp_data = std::string(comma + 1, end); | 74 std::string temp_data = std::string(comma + 1, end); |
71 | 75 |
72 // For base64, we may have url-escaped whitespace which is not part | 76 // For base64, we may have url-escaped whitespace which is not part |
(...skipping 20 matching lines...) Expand all Loading... |
93 } | 97 } |
94 | 98 |
95 if (base64_encoded) | 99 if (base64_encoded) |
96 return base::Base64Decode(temp_data, data); | 100 return base::Base64Decode(temp_data, data); |
97 | 101 |
98 temp_data.swap(*data); | 102 temp_data.swap(*data); |
99 return true; | 103 return true; |
100 } | 104 } |
101 | 105 |
102 } // namespace net | 106 } // namespace net |
OLD | NEW |