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

Side by Side Diff: components/error_page/renderer/net_error_helper_core.cc

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in elide_url.cc Created 4 years, 8 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 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 "components/error_page/renderer/net_error_helper_core.h" 5 #include "components/error_page/renderer/net_error_helper_core.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 params->SetString("clickType", correction.click_type); 253 params->SetString("clickType", correction.click_type);
254 params->SetString("clickData", correction.click_data); 254 params->SetString("clickData", correction.click_data);
255 255
256 params->SetString("eventId", response.event_id); 256 params->SetString("eventId", response.event_id);
257 params->SetString("fingerprint", response.fingerprint); 257 params->SetString("fingerprint", response.fingerprint);
258 258
259 return CreateRequestBody("linkdoctor.fixurl.clicktracking", error_param, 259 return CreateRequestBody("linkdoctor.fixurl.clicktracking", error_param,
260 correction_params, std::move(params)); 260 correction_params, std::move(params));
261 } 261 }
262 262
263 base::string16 FormatURLForDisplay(const GURL& url, bool is_rtl, 263 base::string16 FormatURLForDisplay(const GURL& url, bool is_rtl) {
264 const std::string accept_languages) {
265 // Translate punycode into UTF8, unescape UTF8 URLs. 264 // Translate punycode into UTF8, unescape UTF8 URLs.
266 base::string16 url_for_display(url_formatter::FormatUrl( 265 base::string16 url_for_display(url_formatter::FormatUrl(
267 url, accept_languages, url_formatter::kFormatUrlOmitNothing, 266 url, url_formatter::kFormatUrlOmitNothing,
268 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr)); 267 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr));
269 // URLs are always LTR. 268 // URLs are always LTR.
270 if (is_rtl) 269 if (is_rtl)
271 base::i18n::WrapStringWithLTRFormatting(&url_for_display); 270 base::i18n::WrapStringWithLTRFormatting(&url_for_display);
272 return url_for_display; 271 return url_for_display;
273 } 272 }
274 273
275 scoped_ptr<NavigationCorrectionResponse> ParseNavigationCorrectionResponse( 274 scoped_ptr<NavigationCorrectionResponse> ParseNavigationCorrectionResponse(
276 const std::string raw_response) { 275 const std::string raw_response) {
277 // TODO(mmenke): Open source related protocol buffers and use them directly. 276 // TODO(mmenke): Open source related protocol buffers and use them directly.
278 scoped_ptr<base::Value> parsed = base::JSONReader::Read(raw_response); 277 scoped_ptr<base::Value> parsed = base::JSONReader::Read(raw_response);
279 scoped_ptr<NavigationCorrectionResponse> response( 278 scoped_ptr<NavigationCorrectionResponse> response(
280 new NavigationCorrectionResponse()); 279 new NavigationCorrectionResponse());
281 base::JSONValueConverter<NavigationCorrectionResponse> converter; 280 base::JSONValueConverter<NavigationCorrectionResponse> converter;
282 if (!parsed || !converter.Convert(*parsed, response.get())) 281 if (!parsed || !converter.Convert(*parsed, response.get()))
283 response.reset(); 282 response.reset();
284 return response; 283 return response;
285 } 284 }
286 285
287 void LogCorrectionTypeShown(int type_id) { 286 void LogCorrectionTypeShown(int type_id) {
288 UMA_HISTOGRAM_ENUMERATION( 287 UMA_HISTOGRAM_ENUMERATION(
289 "Net.ErrorPageCounts.NavigationCorrectionLinksShown", type_id, 288 "Net.ErrorPageCounts.NavigationCorrectionLinksShown", type_id,
290 kWebSearchQueryUMAId + 1); 289 kWebSearchQueryUMAId + 1);
291 } 290 }
292 291
293 scoped_ptr<ErrorPageParams> CreateErrorPageParams( 292 scoped_ptr<ErrorPageParams> CreateErrorPageParams(
294 const NavigationCorrectionResponse& response, 293 const NavigationCorrectionResponse& response,
295 const blink::WebURLError& error, 294 const blink::WebURLError& error,
296 const NetErrorHelperCore::NavigationCorrectionParams& correction_params, 295 const NetErrorHelperCore::NavigationCorrectionParams& correction_params,
297 const std::string& accept_languages,
298 bool is_rtl) { 296 bool is_rtl) {
299 // Version of URL for display in suggestions. It has to be sanitized first 297 // Version of URL for display in suggestions. It has to be sanitized first
300 // because any received suggestions will be relative to the sanitized URL. 298 // because any received suggestions will be relative to the sanitized URL.
301 base::string16 original_url_for_display = 299 base::string16 original_url_for_display =
302 FormatURLForDisplay(SanitizeURL(GURL(error.unreachableURL)), is_rtl, 300 FormatURLForDisplay(SanitizeURL(GURL(error.unreachableURL)), is_rtl);
303 accept_languages);
304 301
305 scoped_ptr<ErrorPageParams> params(new ErrorPageParams()); 302 scoped_ptr<ErrorPageParams> params(new ErrorPageParams());
306 params->override_suggestions.reset(new base::ListValue()); 303 params->override_suggestions.reset(new base::ListValue());
307 scoped_ptr<base::ListValue> parsed_corrections(new base::ListValue()); 304 scoped_ptr<base::ListValue> parsed_corrections(new base::ListValue());
308 for (ScopedVector<NavigationCorrection>::const_iterator it = 305 for (ScopedVector<NavigationCorrection>::const_iterator it =
309 response.corrections.begin(); 306 response.corrections.begin();
310 it != response.corrections.end(); ++it) { 307 it != response.corrections.end(); ++it) {
311 // Doesn't seem like a good idea to show these. 308 // Doesn't seem like a good idea to show these.
312 if ((*it)->is_porn || (*it)->is_soft_porn) 309 if ((*it)->is_porn || (*it)->is_soft_porn)
313 continue; 310 continue;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 kCorrectionResourceTable[correction_index].correction_type) { 344 kCorrectionResourceTable[correction_index].correction_type) {
348 continue; 345 continue;
349 } 346 }
350 base::DictionaryValue* suggest = new base::DictionaryValue(); 347 base::DictionaryValue* suggest = new base::DictionaryValue();
351 suggest->SetString("summary", 348 suggest->SetString("summary",
352 l10n_util::GetStringUTF16( 349 l10n_util::GetStringUTF16(
353 kCorrectionResourceTable[correction_index].resource_id)); 350 kCorrectionResourceTable[correction_index].resource_id));
354 suggest->SetString("urlCorrection", (*it)->url_correction); 351 suggest->SetString("urlCorrection", (*it)->url_correction);
355 suggest->SetString( 352 suggest->SetString(
356 "urlCorrectionForDisplay", 353 "urlCorrectionForDisplay",
357 FormatURLForDisplay(GURL((*it)->url_correction), is_rtl, 354 FormatURLForDisplay(GURL((*it)->url_correction), is_rtl));
358 accept_languages));
359 suggest->SetString("originalUrlForDisplay", original_url_for_display); 355 suggest->SetString("originalUrlForDisplay", original_url_for_display);
360 suggest->SetInteger("trackingId", tracking_id); 356 suggest->SetInteger("trackingId", tracking_id);
361 suggest->SetInteger("type", static_cast<int>(correction_index)); 357 suggest->SetInteger("type", static_cast<int>(correction_index));
362 358
363 params->override_suggestions->Append(suggest); 359 params->override_suggestions->Append(suggest);
364 LogCorrectionTypeShown(static_cast<int>(correction_index)); 360 LogCorrectionTypeShown(static_cast<int>(correction_index));
365 break; 361 break;
366 } 362 }
367 } 363 }
368 364
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 // by a DNS error update. 809 // by a DNS error update.
814 delegate_->UpdateErrorPage( 810 delegate_->UpdateErrorPage(
815 GetUpdatedError(committed_error_page_info_->error), 811 GetUpdatedError(committed_error_page_info_->error),
816 committed_error_page_info_->was_failed_post, 812 committed_error_page_info_->was_failed_post,
817 can_show_network_diagnostics_dialog_, 813 can_show_network_diagnostics_dialog_,
818 HasOfflinePages()); 814 HasOfflinePages());
819 } 815 }
820 816
821 void NetErrorHelperCore::OnNavigationCorrectionsFetched( 817 void NetErrorHelperCore::OnNavigationCorrectionsFetched(
822 const std::string& corrections, 818 const std::string& corrections,
823 const std::string& accept_languages,
824 bool is_rtl) { 819 bool is_rtl) {
825 // Loading suggestions only starts when a blank error page finishes loading, 820 // Loading suggestions only starts when a blank error page finishes loading,
826 // and is cancelled with a new load. 821 // and is cancelled with a new load.
827 DCHECK(!pending_error_page_info_); 822 DCHECK(!pending_error_page_info_);
828 DCHECK(committed_error_page_info_->is_finished_loading); 823 DCHECK(committed_error_page_info_->is_finished_loading);
829 DCHECK(committed_error_page_info_->needs_load_navigation_corrections); 824 DCHECK(committed_error_page_info_->needs_load_navigation_corrections);
830 DCHECK(committed_error_page_info_->navigation_correction_params); 825 DCHECK(committed_error_page_info_->navigation_correction_params);
831 826
832 pending_error_page_info_.reset(new ErrorPageInfo( 827 pending_error_page_info_.reset(new ErrorPageInfo(
833 committed_error_page_info_->error, 828 committed_error_page_info_->error,
834 committed_error_page_info_->was_failed_post, 829 committed_error_page_info_->was_failed_post,
835 committed_error_page_info_->was_ignoring_cache)); 830 committed_error_page_info_->was_ignoring_cache));
836 pending_error_page_info_->navigation_correction_response = 831 pending_error_page_info_->navigation_correction_response =
837 ParseNavigationCorrectionResponse(corrections); 832 ParseNavigationCorrectionResponse(corrections);
838 833
839 std::string error_html; 834 std::string error_html;
840 scoped_ptr<ErrorPageParams> params; 835 scoped_ptr<ErrorPageParams> params;
841 if (pending_error_page_info_->navigation_correction_response) { 836 if (pending_error_page_info_->navigation_correction_response) {
842 // Copy navigation correction parameters used for the request, so tracking 837 // Copy navigation correction parameters used for the request, so tracking
843 // requests can still be sent if the configuration changes. 838 // requests can still be sent if the configuration changes.
844 pending_error_page_info_->navigation_correction_params.reset( 839 pending_error_page_info_->navigation_correction_params.reset(
845 new NavigationCorrectionParams( 840 new NavigationCorrectionParams(
846 *committed_error_page_info_->navigation_correction_params)); 841 *committed_error_page_info_->navigation_correction_params));
847 params = CreateErrorPageParams( 842 params = CreateErrorPageParams(
848 *pending_error_page_info_->navigation_correction_response, 843 *pending_error_page_info_->navigation_correction_response,
849 pending_error_page_info_->error, 844 pending_error_page_info_->error,
850 *pending_error_page_info_->navigation_correction_params, 845 *pending_error_page_info_->navigation_correction_params, is_rtl);
851 accept_languages, is_rtl);
852 delegate_->GenerateLocalizedErrorPage( 846 delegate_->GenerateLocalizedErrorPage(
853 pending_error_page_info_->error, 847 pending_error_page_info_->error,
854 pending_error_page_info_->was_failed_post, 848 pending_error_page_info_->was_failed_post,
855 can_show_network_diagnostics_dialog_, HasOfflinePages(), 849 can_show_network_diagnostics_dialog_, HasOfflinePages(),
856 std::move(params), &pending_error_page_info_->reload_button_in_page, 850 std::move(params), &pending_error_page_info_->reload_button_in_page,
857 &pending_error_page_info_->show_saved_copy_button_in_page, 851 &pending_error_page_info_->show_saved_copy_button_in_page,
858 &pending_error_page_info_->show_cached_copy_button_in_page, 852 &pending_error_page_info_->show_cached_copy_button_in_page,
859 &pending_error_page_info_->show_offline_pages_button_in_page, 853 &pending_error_page_info_->show_offline_pages_button_in_page,
860 &error_html); 854 &error_html);
861 } else { 855 } else {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1065
1072 bool NetErrorHelperCore::HasOfflinePages() const { 1066 bool NetErrorHelperCore::HasOfflinePages() const {
1073 #if defined(OS_ANDROID) 1067 #if defined(OS_ANDROID)
1074 return has_offline_pages_; 1068 return has_offline_pages_;
1075 #else 1069 #else
1076 return false; 1070 return false;
1077 #endif // defined(OS_ANDROID) 1071 #endif // defined(OS_ANDROID)
1078 } 1072 }
1079 1073
1080 } // namespace error_page 1074 } // namespace error_page
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698