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

Side by Side Diff: chrome/common/favicon/favicon_url_parser.cc

Issue 861333002: [Favicon] Minor code cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed DCHECK(). Created 5 years, 11 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 | « chrome/browser/ui/webui/favicon_source.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/common/favicon/favicon_url_parser.h" 5 #include "chrome/common/favicon/favicon_url_parser.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "components/favicon_base/favicon_types.h" 8 #include "components/favicon_base/favicon_types.h"
9 #include "net/url_request/url_request.h" 9 #include "net/url_request/url_request.h"
10 #include "ui/base/webui/web_ui_util.h" 10 #include "ui/base/webui/web_ui_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 icon_types == favicon_base::FAVICON) 89 icon_types == favicon_base::FAVICON)
90 return false; 90 return false;
91 91
92 parsed_index = slash + 1; 92 parsed_index = slash + 1;
93 } 93 }
94 94
95 if (HasSubstringAt(path, parsed_index, kIconURLParameter)) { 95 if (HasSubstringAt(path, parsed_index, kIconURLParameter)) {
96 parsed_index += strlen(kIconURLParameter); 96 parsed_index += strlen(kIconURLParameter);
97 parsed->is_icon_url = true; 97 parsed->is_icon_url = true;
98 parsed->url = path.substr(parsed_index); 98 parsed->url = path.substr(parsed_index);
99 } else { 99 } else if (HasSubstringAt(path, parsed_index, kOriginParameter)) {
100 // URL requests prefixed with "origin/" are converted to a form with an 100 // URL requests prefixed with "origin/" are converted to a form with an
101 // empty path and a valid scheme. (e.g., example.com --> 101 // empty path and a valid scheme. (e.g., example.com -->
102 // http://example.com/ or http://example.com/a --> http://example.com/) 102 // http://example.com/ or http://example.com/a --> http://example.com/)
103 if (HasSubstringAt(path, parsed_index, kOriginParameter)) { 103 parsed_index += strlen(kOriginParameter);
104 parsed_index += strlen(kOriginParameter); 104 std::string possibly_invalid_url = path.substr(parsed_index);
105 std::string possibly_invalid_url = path.substr(parsed_index);
106 105
107 // If the URL does not specify a scheme (e.g., example.com instead of 106 // If the URL does not specify a scheme (e.g., example.com instead of
108 // http://example.com), add "http://" as a default. 107 // http://example.com), add "http://" as a default.
109 if (!GURL(possibly_invalid_url).has_scheme()) 108 if (!GURL(possibly_invalid_url).has_scheme())
110 possibly_invalid_url = "http://" + possibly_invalid_url; 109 possibly_invalid_url = "http://" + possibly_invalid_url;
111 110
112 // Strip the path beyond the top-level domain. 111 // Strip the path beyond the top-level domain.
113 parsed->url = GURL(possibly_invalid_url).GetOrigin().spec(); 112 parsed->url = GURL(possibly_invalid_url).GetOrigin().spec();
114 } else { 113 } else {
115 parsed->url = path.substr(parsed_index); 114 parsed->url = path.substr(parsed_index);
116 }
117 } 115 }
118 116
119 // The parsed index needs to be returned in order to allow Instant Extended 117 // The parsed index needs to be returned in order to allow Instant Extended
120 // to translate favicon URLs using advanced parameters. 118 // to translate favicon URLs using advanced parameters.
121 // Example: 119 // Example:
122 // "chrome-search://favicon/size/16@2x/<renderer-id>/<most-visited-id>" 120 // "chrome-search://favicon/size/16@2x/<renderer-id>/<most-visited-id>"
123 // would be translated to: 121 // would be translated to:
124 // "chrome-search://favicon/size/16@2x/<most-visited-item-with-given-id>". 122 // "chrome-search://favicon/size/16@2x/<most-visited-item-with-given-id>".
125 parsed->path_index = parsed_index; 123 parsed->path_index = parsed_index;
126 return true; 124 return true;
127 } 125 }
128 126
129 } // namespace chrome 127 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/favicon_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698