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 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
15 #include "net/base/mime_util.h" | 15 #include "net/base/mime_util.h" |
16 #include "net/http/http_util.h" | 16 #include "net/http/http_util.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 // static | 21 // static |
22 bool DataURL::Parse(const GURL& url, std::string* mime_type, | 22 bool DataURL::Parse(const GURL& url, std::string* mime_type, |
23 std::string* charset, std::string* data) { | 23 std::string* charset, std::string* data) { |
| 24 if (!url.is_valid()) |
| 25 return false; |
| 26 |
24 DCHECK(mime_type->empty()); | 27 DCHECK(mime_type->empty()); |
25 DCHECK(charset->empty()); | 28 DCHECK(charset->empty()); |
26 std::string::const_iterator begin = url.spec().begin(); | 29 std::string::const_iterator begin = url.spec().begin(); |
27 std::string::const_iterator end = url.spec().end(); | 30 std::string::const_iterator end = url.spec().end(); |
28 | 31 |
29 std::string::const_iterator after_colon = std::find(begin, end, ':'); | 32 std::string::const_iterator after_colon = std::find(begin, end, ':'); |
30 if (after_colon == end) | 33 if (after_colon == end) |
31 return false; | 34 return false; |
32 ++after_colon; | 35 ++after_colon; |
33 | 36 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 temp_data.resize(length + padding_needed, '='); | 131 temp_data.resize(length + padding_needed, '='); |
129 } | 132 } |
130 return base::Base64Decode(temp_data, data); | 133 return base::Base64Decode(temp_data, data); |
131 } | 134 } |
132 | 135 |
133 temp_data.swap(*data); | 136 temp_data.swap(*data); |
134 return true; | 137 return true; |
135 } | 138 } |
136 | 139 |
137 } // namespace net | 140 } // namespace net |
OLD | NEW |