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

Side by Side Diff: net/base/data_url.cc

Issue 338503006: Allow data urls to have a fragment part. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: check for "data" scheme Created 6 years, 6 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
« no previous file with comments | « no previous file | net/base/data_url_unittest.cc » ('j') | net/base/data_url_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "net/base/escape.h" 15 #include "net/base/escape.h"
16 #include "net/base/mime_util.h" 16 #include "net/base/mime_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 DCHECK(mime_type->empty()); 24 DCHECK(mime_type->empty());
25 DCHECK(charset->empty()); 25 DCHECK(charset->empty());
26 std::string::const_iterator begin = url.spec().begin();
27 std::string::const_iterator end = url.spec().end();
28 26
29 std::string::const_iterator after_colon = std::find(begin, end, ':'); 27 if (!url.SchemeIs("data"))
asanka 2014/06/16 17:45:48 Make this a DCHECK instead.
Erik Dahlström (inactive) 2014/06/17 13:10:21 Done.
30 if (after_colon == end)
31 return false; 28 return false;
32 ++after_colon;
33 29
34 std::string::const_iterator comma = std::find(after_colon, end, ','); 30 const std::string path = url.path();
31 std::string::const_iterator begin = path.begin();
32 std::string::const_iterator end = path.end();
33
34 std::string::const_iterator comma = std::find(begin, end, ',');
35 if (comma == end) 35 if (comma == end)
36 return false; 36 return false;
37 37
38 std::vector<std::string> meta_data; 38 std::vector<std::string> meta_data;
39 std::string unparsed_meta_data(after_colon, comma); 39 std::string unparsed_meta_data(begin, comma);
40 base::SplitString(unparsed_meta_data, ';', &meta_data); 40 base::SplitString(unparsed_meta_data, ';', &meta_data);
41 41
42 std::vector<std::string>::iterator iter = meta_data.begin(); 42 std::vector<std::string>::iterator iter = meta_data.begin();
43 if (iter != meta_data.end()) { 43 if (iter != meta_data.end()) {
44 mime_type->swap(*iter); 44 mime_type->swap(*iter);
45 StringToLowerASCII(mime_type); 45 StringToLowerASCII(mime_type);
46 ++iter; 46 ++iter;
47 } 47 }
48 48
49 static const char kBase64Tag[] = "base64"; 49 static const char kBase64Tag[] = "base64";
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 temp_data.resize(length + padding_needed, '='); 118 temp_data.resize(length + padding_needed, '=');
119 } 119 }
120 return base::Base64Decode(temp_data, data); 120 return base::Base64Decode(temp_data, data);
121 } 121 }
122 122
123 temp_data.swap(*data); 123 temp_data.swap(*data);
124 return true; 124 return true;
125 } 125 }
126 126
127 } // namespace net 127 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/data_url_unittest.cc » ('j') | net/base/data_url_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698