OLD | NEW |
1 // Copyright 2008, Google Inc. | 1 // Copyright 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 size()); | 187 size()); |
188 std::wstring url_filename; | 188 std::wstring url_filename; |
189 if ((url_path_elements.at(url_path_number_of_elements - 1)).length() > 0) { | 189 if ((url_path_elements.at(url_path_number_of_elements - 1)).length() > 0) { |
190 url_filename = *(url_path_elements.end()-1); | 190 url_filename = *(url_path_elements.end()-1); |
191 } else if (url_path_number_of_elements > 1) { // Path ends with a '/'. | 191 } else if (url_path_number_of_elements > 1) { // Path ends with a '/'. |
192 url_filename = url_path_elements.at(url_path_number_of_elements - 2) + | 192 url_filename = url_path_elements.at(url_path_number_of_elements - 2) + |
193 L"/"; | 193 L"/"; |
194 url_path_number_of_elements--; | 194 url_path_number_of_elements--; |
195 } | 195 } |
196 | 196 |
| 197 const int kMaxNumberOfUrlPathElementsAllowed = 1024; |
| 198 if (url_path_number_of_elements <= 1 || |
| 199 url_path_number_of_elements > kMaxNumberOfUrlPathElementsAllowed) { |
| 200 // No path to elide, or too long of a path (could overflow in loop below) |
| 201 // Just elide this as a text string. |
| 202 return ElideText(url_subdomain + url_domain + url_path_query_etc, font, |
| 203 available_pixel_width); |
| 204 } |
| 205 |
197 // Start eliding the path and replacing elements by "../". | 206 // Start eliding the path and replacing elements by "../". |
198 std::wstring an_ellipsis_and_a_slash(kEllipsis); | 207 std::wstring an_ellipsis_and_a_slash(kEllipsis); |
199 an_ellipsis_and_a_slash += '/'; | 208 an_ellipsis_and_a_slash += '/'; |
200 int pixel_width_url_filename = font.GetStringWidth(url_filename); | 209 int pixel_width_url_filename = font.GetStringWidth(url_filename); |
201 int pixel_width_dot_dot_slash = font.GetStringWidth(an_ellipsis_and_a_slash); | 210 int pixel_width_dot_dot_slash = font.GetStringWidth(an_ellipsis_and_a_slash); |
202 int pixel_width_slash = font.GetStringWidth(L"/"); | 211 int pixel_width_slash = font.GetStringWidth(L"/"); |
203 int pixel_width_url_path_elements[256]; // Declared static for speed. | 212 int pixel_width_url_path_elements[kMaxNumberOfUrlPathElementsAllowed]; |
204 for (int i = 0; i < url_path_number_of_elements; i++) { | 213 for (int i = 0; i < url_path_number_of_elements; i++) { |
205 pixel_width_url_path_elements[i] = | 214 pixel_width_url_path_elements[i] = |
206 font.GetStringWidth(url_path_elements.at(i)); | 215 font.GetStringWidth(url_path_elements.at(i)); |
207 } | 216 } |
208 | 217 |
209 if (url_path_number_of_elements <= 1) { | |
210 // Nothing FITS - return domain and rest. | |
211 return ElideText(url_subdomain + url_domain + url_path_query_etc, font, | |
212 available_pixel_width); | |
213 } | |
214 | |
215 // Check with both subdomain and domain. | 218 // Check with both subdomain and domain. |
216 std::wstring elided_path; | 219 std::wstring elided_path; |
217 int pixel_width_elided_path; | 220 int pixel_width_elided_path; |
218 for (int i = url_path_number_of_elements - 1; i >= 1; i--) { | 221 for (int i = url_path_number_of_elements - 1; i >= 1; i--) { |
219 // Add the initial elements of the path. | 222 // Add the initial elements of the path. |
220 elided_path.clear(); | 223 elided_path.clear(); |
221 pixel_width_elided_path = 0; | 224 pixel_width_elided_path = 0; |
222 for (int j = 0; j < i; j++) { | 225 for (int j = 0; j < i; j++) { |
223 elided_path += url_path_elements.at(j) + L"/"; | 226 elided_path += url_path_elements.at(j) + L"/"; |
224 pixel_width_elided_path += pixel_width_url_path_elements[j] + | 227 pixel_width_elided_path += pixel_width_url_path_elements[j] + |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 url_string.push_back('#'); | 429 url_string.push_back('#'); |
427 if (parsed.ref.len > 0) | 430 if (parsed.ref.len > 0) |
428 url_string.append(UTF8ToWide(std::string(&spec[parsed.ref.begin], | 431 url_string.append(UTF8ToWide(std::string(&spec[parsed.ref.begin], |
429 parsed.ref.len))); | 432 parsed.ref.len))); |
430 } | 433 } |
431 | 434 |
432 return url_string; | 435 return url_string; |
433 } | 436 } |
434 | 437 |
435 } // namespace gfx. | 438 } // namespace gfx. |
OLD | NEW |