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

Side by Side Diff: chrome/browser/ui/elide_url.cc

Issue 1240183002: Update SplitString calls in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/ui/elide_url.h" 5 #include "chrome/browser/ui/elide_url.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "net/base/escape.h" 10 #include "net/base/escape.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 base::string16 url_host; 149 base::string16 url_host;
150 base::string16 url_domain; 150 base::string16 url_domain;
151 base::string16 url_subdomain; 151 base::string16 url_subdomain;
152 SplitHost(url, &url_host, &url_domain, &url_subdomain); 152 SplitHost(url, &url_host, &url_domain, &url_subdomain);
153 153
154 // If this is a file type, the path is now defined as everything after ":". 154 // If this is a file type, the path is now defined as everything after ":".
155 // For example, "C:/aa/aa/bb", the path is "/aa/bb/cc". Interesting, the 155 // For example, "C:/aa/aa/bb", the path is "/aa/bb/cc". Interesting, the
156 // domain is now C: - this is a nice hack for eliding to work pleasantly. 156 // domain is now C: - this is a nice hack for eliding to work pleasantly.
157 if (url.SchemeIsFile()) { 157 if (url.SchemeIsFile()) {
158 // Split the path string using ":" 158 // Split the path string using ":"
159 std::vector<base::string16> file_path_split; 159 const base::string16 kColon(1, ':');
160 base::SplitString(url_path, ':', &file_path_split); 160 std::vector<base::string16> file_path_split = base::SplitString(
161 url_path, kColon, base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
161 if (file_path_split.size() > 1) { // File is of type "file:///C:/.." 162 if (file_path_split.size() > 1) { // File is of type "file:///C:/.."
162 url_host.clear(); 163 url_host.clear();
163 url_domain.clear(); 164 url_domain.clear();
164 url_subdomain.clear(); 165 url_subdomain.clear();
165 166
166 const base::string16 kColon = UTF8ToUTF16(":");
167 url_host = url_domain = file_path_split.at(0).substr(1) + kColon; 167 url_host = url_domain = file_path_split.at(0).substr(1) + kColon;
168 url_path_query_etc = url_path = file_path_split.at(1); 168 url_path_query_etc = url_path = file_path_split.at(1);
169 } 169 }
170 } 170 }
171 171
172 // Second Pass - remove scheme - the rest fits. 172 // Second Pass - remove scheme - the rest fits.
173 const float pixel_width_url_host = GetStringWidthF(url_host, font_list); 173 const float pixel_width_url_host = GetStringWidthF(url_host, font_list);
174 const float pixel_width_url_path = GetStringWidthF(url_path_query_etc, 174 const float pixel_width_url_path = GetStringWidthF(url_path_query_etc,
175 font_list); 175 font_list);
176 if (available_pixel_width >= 176 if (available_pixel_width >=
(...skipping 17 matching lines...) Expand all
194 url_query = UTF8ToUTF16("?") + url_string.substr(parsed.query.begin); 194 url_query = UTF8ToUTF16("?") + url_string.substr(parsed.query.begin);
195 if (available_pixel_width >= 195 if (available_pixel_width >=
196 (pixel_width_url_subdomain + pixel_width_url_domain + 196 (pixel_width_url_subdomain + pixel_width_url_domain +
197 pixel_width_url_path - GetStringWidthF(url_query, font_list))) { 197 pixel_width_url_path - GetStringWidthF(url_query, font_list))) {
198 return ElideText(url_subdomain + url_domain + url_path_query_etc, 198 return ElideText(url_subdomain + url_domain + url_path_query_etc,
199 font_list, available_pixel_width, gfx::ELIDE_TAIL); 199 font_list, available_pixel_width, gfx::ELIDE_TAIL);
200 } 200 }
201 } 201 }
202 202
203 // Parse url_path using '/'. 203 // Parse url_path using '/'.
204 std::vector<base::string16> url_path_elements; 204 std::vector<base::string16> url_path_elements = base::SplitString(
205 base::SplitString(url_path, kForwardSlash, &url_path_elements); 205 url_path, base::string16(1, kForwardSlash),
206 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
206 207
207 // Get filename - note that for a path ending with / 208 // Get filename - note that for a path ending with /
208 // such as www.google.com/intl/ads/, the file name is ads/. 209 // such as www.google.com/intl/ads/, the file name is ads/.
209 base::string16 url_filename( 210 base::string16 url_filename(
210 url_path_elements.empty() ? base::string16() : url_path_elements.back()); 211 url_path_elements.empty() ? base::string16() : url_path_elements.back());
211 size_t url_path_number_of_elements = url_path_elements.size(); 212 size_t url_path_number_of_elements = url_path_elements.size();
212 if (url_filename.empty() && (url_path_number_of_elements > 1)) { 213 if (url_filename.empty() && (url_path_number_of_elements > 1)) {
213 // Path ends with a '/'. 214 // Path ends with a '/'.
214 --url_path_number_of_elements; 215 --url_path_number_of_elements;
215 url_filename = url_path_elements[url_path_number_of_elements - 1] + 216 url_filename = url_path_elements[url_path_number_of_elements - 1] +
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 result += base::UTF8ToUTF16(host); 338 result += base::UTF8ToUTF16(host);
338 339
339 const int port = origin.IntPort(); 340 const int port = origin.IntPort();
340 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(), 341 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(),
341 origin.scheme().length()); 342 origin.scheme().length());
342 if (port != url::PORT_UNSPECIFIED && port != default_port) 343 if (port != url::PORT_UNSPECIFIED && port != default_port)
343 result += colon + base::UTF8ToUTF16(origin.port()); 344 result += colon + base::UTF8ToUTF16(origin.port());
344 345
345 return result; 346 return result;
346 } 347 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/generated_credit_card_bubble_controller.cc ('k') | chrome/browser/ui/libgtk2ui/gtk2_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698