Infobar material design refresh: bg color
[chromium-blink-merge.git] / chrome / common / localized_error.cc
blob1ed652b2865b1ee76598650c27db9ec7d3eeeac0
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
3 // found in the LICENSE file.
5 #include "chrome/common/localized_error.h"
7 #include "base/command_line.h"
8 #include "base/i18n/rtl.h"
9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/strings/string16.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/grit/chromium_strings.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "components/error_page/common/error_page_params.h"
20 #include "components/error_page/common/net_error_info.h"
21 #include "components/url_formatter/url_formatter.h"
22 #include "grit/components_chromium_strings.h"
23 #include "grit/components_google_chrome_strings.h"
24 #include "net/base/escape.h"
25 #include "net/base/net_errors.h"
26 #include "third_party/WebKit/public/platform/WebURLError.h"
27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/webui/web_ui_util.h"
30 #if defined(OS_WIN)
31 #include "base/win/windows_version.h"
32 #endif
34 #if defined(OS_CHROMEOS)
35 #include "base/command_line.h"
36 #include "chrome/common/chrome_switches.h"
37 #endif
39 using blink::WebURLError;
41 // Some error pages have no details.
42 const unsigned int kErrorPagesNoDetails = 0;
44 namespace {
46 static const char kRedirectLoopLearnMoreUrl[] =
47 "https://support.google.com/chrome/answer/95626";
48 static const char kWeakDHKeyLearnMoreUrl[] =
49 "https://www.chromium.org/administrators/"
50 "err_ssl_weak_server_ephemeral_dh_key";
51 static const char kCachedCopyButtonFieldTrial[] =
52 "EnableGoogleCachedCopyTextExperiment";
53 static const char kCachedCopyButtonExpTypeControl[] = "control";
54 static const int kGoogleCachedCopySuggestionType = 0;
56 enum NAV_SUGGESTIONS {
57 SUGGEST_NONE = 0,
58 SUGGEST_RELOAD = 1 << 0,
59 SUGGEST_CHECK_CONNECTION = 1 << 1,
60 SUGGEST_DNS_CONFIG = 1 << 2,
61 SUGGEST_FIREWALL_CONFIG = 1 << 3,
62 SUGGEST_PROXY_CONFIG = 1 << 4,
63 SUGGEST_DISABLE_EXTENSION = 1 << 5,
64 SUGGEST_LEARNMORE = 1 << 6,
65 SUGGEST_VIEW_POLICIES = 1 << 7,
66 SUGGEST_CONTACT_ADMINISTRATOR = 1 << 8,
69 struct LocalizedErrorMap {
70 int error_code;
71 unsigned int title_resource_id;
72 unsigned int heading_resource_id;
73 // Detailed summary used when the error is in the main frame.
74 unsigned int summary_resource_id;
75 // Short one sentence description shown on mouse over when the error is in
76 // a frame.
77 unsigned int details_resource_id;
78 int suggestions; // Bitmap of SUGGEST_* values.
81 const LocalizedErrorMap net_error_options[] = {
82 {net::ERR_TIMED_OUT,
83 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
84 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
85 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
86 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
87 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
88 SUGGEST_PROXY_CONFIG,
90 {net::ERR_CONNECTION_TIMED_OUT,
91 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
92 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
93 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
94 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
95 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
96 SUGGEST_PROXY_CONFIG,
98 {net::ERR_CONNECTION_CLOSED,
99 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
100 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
101 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
102 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
103 SUGGEST_RELOAD,
105 {net::ERR_CONNECTION_RESET,
106 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
107 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
108 IDS_ERRORPAGES_SUMMARY_CONNECTION_RESET,
109 IDS_ERRORPAGES_DETAILS_CONNECTION_RESET,
110 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
111 SUGGEST_PROXY_CONFIG,
113 {net::ERR_CONNECTION_REFUSED,
114 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
115 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
116 IDS_ERRORPAGES_SUMMARY_CONNECTION_REFUSED,
117 IDS_ERRORPAGES_DETAILS_CONNECTION_REFUSED,
118 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
119 SUGGEST_PROXY_CONFIG,
121 {net::ERR_CONNECTION_FAILED,
122 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
123 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
124 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
125 IDS_ERRORPAGES_DETAILS_CONNECTION_FAILED,
126 SUGGEST_RELOAD,
128 {net::ERR_NAME_NOT_RESOLVED,
129 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
130 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
131 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
132 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
133 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_DNS_CONFIG |
134 SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
136 {net::ERR_ICANN_NAME_COLLISION,
137 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
138 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
139 IDS_ERRORPAGES_SUMMARY_ICANN_NAME_COLLISION,
140 IDS_ERRORPAGES_DETAILS_ICANN_NAME_COLLISION,
141 SUGGEST_NONE,
143 {net::ERR_ADDRESS_UNREACHABLE,
144 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
145 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
146 IDS_ERRORPAGES_SUMMARY_ADDRESS_UNREACHABLE,
147 IDS_ERRORPAGES_DETAILS_ADDRESS_UNREACHABLE,
148 SUGGEST_RELOAD | SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
150 {net::ERR_NETWORK_ACCESS_DENIED,
151 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
152 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
153 IDS_ERRORPAGES_SUMMARY_NETWORK_ACCESS_DENIED,
154 IDS_ERRORPAGES_DETAILS_NETWORK_ACCESS_DENIED,
155 SUGGEST_FIREWALL_CONFIG,
157 {net::ERR_PROXY_CONNECTION_FAILED,
158 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
159 IDS_ERRORPAGES_HEADING_PROXY_CONNECTION_FAILED,
160 IDS_ERRORPAGES_SUMMARY_PROXY_CONNECTION_FAILED,
161 IDS_ERRORPAGES_DETAILS_PROXY_CONNECTION_FAILED,
162 SUGGEST_PROXY_CONFIG,
164 {net::ERR_INTERNET_DISCONNECTED,
165 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
166 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
167 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
168 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
169 SUGGEST_NONE,
171 {net::ERR_FILE_NOT_FOUND,
172 IDS_ERRORPAGES_TITLE_NOT_FOUND,
173 IDS_ERRORPAGES_HEADING_NOT_FOUND,
174 IDS_ERRORPAGES_SUMMARY_NOT_FOUND,
175 IDS_ERRORPAGES_DETAILS_FILE_NOT_FOUND,
176 SUGGEST_NONE,
178 {net::ERR_CACHE_MISS,
179 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
180 IDS_ERRORPAGES_HEADING_CACHE_MISS,
181 IDS_ERRORPAGES_SUMMARY_CACHE_MISS,
182 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
183 SUGGEST_RELOAD,
185 {net::ERR_CACHE_READ_FAILURE,
186 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
187 IDS_ERRORPAGES_HEADING_CACHE_READ_FAILURE,
188 IDS_ERRORPAGES_SUMMARY_CACHE_READ_FAILURE,
189 IDS_ERRORPAGES_DETAILS_CACHE_READ_FAILURE,
190 SUGGEST_RELOAD,
192 {net::ERR_NETWORK_IO_SUSPENDED,
193 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
194 IDS_ERRORPAGES_HEADING_NETWORK_IO_SUSPENDED,
195 IDS_ERRORPAGES_SUMMARY_NETWORK_IO_SUSPENDED,
196 IDS_ERRORPAGES_DETAILS_NETWORK_IO_SUSPENDED,
197 SUGGEST_RELOAD,
199 {net::ERR_TOO_MANY_REDIRECTS,
200 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
201 IDS_ERRORPAGES_HEADING_TOO_MANY_REDIRECTS,
202 IDS_ERRORPAGES_SUMMARY_TOO_MANY_REDIRECTS,
203 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS,
204 SUGGEST_RELOAD | SUGGEST_LEARNMORE,
206 {net::ERR_EMPTY_RESPONSE,
207 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
208 IDS_ERRORPAGES_HEADING_EMPTY_RESPONSE,
209 IDS_ERRORPAGES_SUMMARY_EMPTY_RESPONSE,
210 IDS_ERRORPAGES_DETAILS_EMPTY_RESPONSE,
211 SUGGEST_RELOAD,
213 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
214 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
215 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
216 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
217 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
218 SUGGEST_NONE,
220 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
221 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
222 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
223 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
224 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
225 SUGGEST_NONE,
227 {net::ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION,
228 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
229 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
230 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
231 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_LOCATION,
232 SUGGEST_NONE,
234 {net::ERR_CONTENT_LENGTH_MISMATCH,
235 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
236 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
237 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
238 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
239 SUGGEST_RELOAD,
241 {net::ERR_INCOMPLETE_CHUNKED_ENCODING,
242 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
243 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
244 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
245 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
246 SUGGEST_RELOAD,
248 {net::ERR_SSL_PROTOCOL_ERROR,
249 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
250 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
251 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
252 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
253 SUGGEST_NONE,
255 {net::ERR_BAD_SSL_CLIENT_AUTH_CERT,
256 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
257 IDS_ERRORPAGES_HEADING_BAD_SSL_CLIENT_AUTH_CERT,
258 IDS_ERRORPAGES_SUMMARY_BAD_SSL_CLIENT_AUTH_CERT,
259 IDS_ERRORPAGES_DETAILS_BAD_SSL_CLIENT_AUTH_CERT,
260 SUGGEST_NONE,
262 {net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY,
263 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
264 IDS_ERRORPAGES_HEADING_WEAK_SERVER_EPHEMERAL_DH_KEY,
265 IDS_ERRORPAGES_SUMMARY_WEAK_SERVER_EPHEMERAL_DH_KEY,
266 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
267 SUGGEST_LEARNMORE,
269 {net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN,
270 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
271 IDS_ERRORPAGES_HEADING_PINNING_FAILURE,
272 IDS_ERRORPAGES_SUMMARY_PINNING_FAILURE,
273 IDS_ERRORPAGES_DETAILS_PINNING_FAILURE,
274 SUGGEST_NONE,
276 {net::ERR_TEMPORARILY_THROTTLED,
277 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
278 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
279 IDS_ERRORPAGES_SUMMARY_TEMPORARILY_THROTTLED,
280 IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED,
281 SUGGEST_NONE,
283 {net::ERR_BLOCKED_BY_CLIENT,
284 IDS_ERRORPAGES_TITLE_BLOCKED,
285 IDS_ERRORPAGES_HEADING_BLOCKED,
286 IDS_ERRORPAGES_SUMMARY_BLOCKED,
287 IDS_ERRORPAGES_DETAILS_BLOCKED,
288 SUGGEST_RELOAD | SUGGEST_DISABLE_EXTENSION,
290 {net::ERR_NETWORK_CHANGED,
291 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
292 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
293 IDS_ERRORPAGES_SUMMARY_NETWORK_CHANGED,
294 IDS_ERRORPAGES_DETAILS_NETWORK_CHANGED,
295 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION,
297 {net::ERR_BLOCKED_BY_ADMINISTRATOR,
298 IDS_ERRORPAGES_TITLE_BLOCKED,
299 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
300 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR,
301 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR,
302 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR,
304 {net::ERR_BLOCKED_ENROLLMENT_CHECK_PENDING,
305 IDS_ERRORPAGES_TITLE_BLOCKED,
306 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
307 IDS_ERRORPAGES_SUMMARY_BLOCKED_ENROLLMENT_CHECK_PENDING,
308 IDS_ERRORPAGES_DETAILS_BLOCKED_ENROLLMENT_CHECK_PENDING,
309 SUGGEST_CHECK_CONNECTION,
311 {net::ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
312 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
313 IDS_ERRORPAGES_HEADING_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
314 IDS_ERRORPAGES_SUMMARY_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
315 IDS_ERRORPAGES_DETAILS_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
316 SUGGEST_NONE,
318 {net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH,
319 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
320 IDS_ERRORPAGES_HEADING_SSL_VERSION_OR_CIPHER_MISMATCH,
321 IDS_ERRORPAGES_SUMMARY_SSL_VERSION_OR_CIPHER_MISMATCH,
322 IDS_ERRORPAGES_DETAILS_SSL_VERSION_OR_CIPHER_MISMATCH,
323 SUGGEST_NONE,
325 {net::ERR_TEMPORARY_BACKOFF,
326 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
327 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
328 IDS_ERRORPAGES_SUMMARY_TEMPORARY_BACKOFF,
329 IDS_ERRORPAGES_DETAILS_TEMPORARY_BACKOFF,
330 SUGGEST_NONE,
332 {net::ERR_SSL_SERVER_CERT_BAD_FORMAT,
333 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
334 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
335 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
336 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
337 SUGGEST_NONE,
341 // Special error page to be used in the case of navigating back to a page
342 // generated by a POST. LocalizedError::HasStrings expects this net error code
343 // to also appear in the array above.
344 const LocalizedErrorMap repost_error = {
345 net::ERR_CACHE_MISS,
346 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
347 IDS_HTTP_POST_WARNING_TITLE,
348 IDS_ERRORPAGES_HTTP_POST_WARNING,
349 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
350 SUGGEST_RELOAD,
353 const LocalizedErrorMap http_error_options[] = {
354 {403,
355 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
356 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
357 IDS_ERRORPAGES_SUMMARY_FORBIDDEN,
358 IDS_ERRORPAGES_DETAILS_FORBIDDEN,
359 SUGGEST_NONE,
361 {410,
362 IDS_ERRORPAGES_TITLE_NOT_FOUND,
363 IDS_ERRORPAGES_HEADING_NOT_FOUND,
364 IDS_ERRORPAGES_SUMMARY_GONE,
365 IDS_ERRORPAGES_DETAILS_GONE,
366 SUGGEST_NONE,
369 {500,
370 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
371 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
372 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR,
373 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR,
374 SUGGEST_RELOAD,
376 {501,
377 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
378 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
379 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
380 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED,
381 SUGGEST_NONE,
383 {502,
384 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
385 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
386 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY,
387 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY,
388 SUGGEST_RELOAD,
390 {503,
391 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
392 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
393 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE,
394 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE,
395 SUGGEST_RELOAD,
397 {504,
398 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
399 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
400 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT,
401 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT,
402 SUGGEST_RELOAD,
404 {505,
405 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
406 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
407 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
408 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED,
409 SUGGEST_NONE,
413 const LocalizedErrorMap dns_probe_error_options[] = {
414 {error_page::DNS_PROBE_POSSIBLE,
415 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
416 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
417 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
418 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
419 SUGGEST_RELOAD,
422 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
423 // error, which might be one of several DNS-related errors.
425 {error_page::DNS_PROBE_STARTED,
426 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
427 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
428 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
429 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
430 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
431 SUGGEST_RELOAD,
434 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
435 // original error, which might be one of several DNS-related errors.
437 {error_page::DNS_PROBE_FINISHED_NO_INTERNET,
438 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
439 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
440 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
441 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
442 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG,
444 {error_page::DNS_PROBE_FINISHED_BAD_CONFIG,
445 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
446 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
447 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
448 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
449 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG,
451 {error_page::DNS_PROBE_FINISHED_NXDOMAIN,
452 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
453 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
454 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
455 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
456 SUGGEST_RELOAD,
460 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps,
461 size_t num_maps,
462 int error_code) {
463 for (size_t i = 0; i < num_maps; ++i) {
464 if (maps[i].error_code == error_code)
465 return &maps[i];
467 return NULL;
470 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain,
471 int error_code, bool is_post) {
472 if (error_domain == net::kErrorDomain) {
473 // Display a different page in the special case of navigating through the
474 // history to an uncached page created by a POST.
475 if (is_post && error_code == net::ERR_CACHE_MISS)
476 return &repost_error;
477 return FindErrorMapInArray(net_error_options,
478 arraysize(net_error_options),
479 error_code);
480 } else if (error_domain == LocalizedError::kHttpErrorDomain) {
481 return FindErrorMapInArray(http_error_options,
482 arraysize(http_error_options),
483 error_code);
484 } else if (error_domain == error_page::kDnsProbeErrorDomain) {
485 const LocalizedErrorMap* map =
486 FindErrorMapInArray(dns_probe_error_options,
487 arraysize(dns_probe_error_options),
488 error_code);
489 DCHECK(map);
490 return map;
491 } else {
492 NOTREACHED();
493 return NULL;
497 // Returns a dictionary containing the strings for the settings menu under the
498 // wrench, and the advanced settings button.
499 base::DictionaryValue* GetStandardMenuItemsText() {
500 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue();
501 standard_menu_items_text->SetString("settingsTitle",
502 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
503 standard_menu_items_text->SetString("advancedTitle",
504 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS));
505 return standard_menu_items_text;
508 // Gets the icon class for a given |error_domain| and |error_code|.
509 const char* GetIconClassForError(const std::string& error_domain,
510 int error_code) {
511 if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
512 error_domain == net::kErrorDomain) ||
513 (error_code == error_page::DNS_PROBE_FINISHED_NO_INTERNET &&
514 error_domain == error_page::kDnsProbeErrorDomain))
515 return "icon-offline";
517 return "icon-generic";
520 } // namespace
522 const char LocalizedError::kHttpErrorDomain[] = "http";
524 void LocalizedError::GetStrings(int error_code,
525 const std::string& error_domain,
526 const GURL& failed_url,
527 bool is_post,
528 bool stale_copy_in_cache,
529 bool can_show_network_diagnostics_dialog,
530 const std::string& locale,
531 const std::string& accept_languages,
532 scoped_ptr<error_page::ErrorPageParams> params,
533 base::DictionaryValue* error_strings) {
534 webui::SetLoadTimeDataDefaults(locale, error_strings);
536 // Grab the strings and settings that depend on the error type. Init
537 // options with default values.
538 LocalizedErrorMap options = {
540 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
541 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
542 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
543 kErrorPagesNoDetails,
544 SUGGEST_NONE,
547 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
548 is_post);
549 if (error_map)
550 options = *error_map;
552 // If we got "access denied" but the url was a file URL, then we say it was a
553 // file instead of just using the "not available" default message. Just adding
554 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
555 // generated by some OSs when the operation doesn't involve a file URL.
556 if (error_domain == net::kErrorDomain &&
557 error_code == net::ERR_ACCESS_DENIED &&
558 failed_url.scheme() == "file") {
559 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED;
560 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED;
561 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED;
562 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED;
563 options.suggestions = SUGGEST_NONE;
566 base::string16 failed_url_string(url_formatter::FormatUrl(
567 failed_url, accept_languages, url_formatter::kFormatUrlOmitNothing,
568 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr));
569 // URLs are always LTR.
570 if (base::i18n::IsRTL())
571 base::i18n::WrapStringWithLTRFormatting(&failed_url_string);
572 error_strings->SetString("title",
573 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string));
574 error_strings->SetString("heading",
575 l10n_util::GetStringUTF16(options.heading_resource_id));
577 std::string icon_class = GetIconClassForError(error_domain, error_code);
578 error_strings->SetString("iconClass", icon_class);
580 base::DictionaryValue* summary = new base::DictionaryValue;
582 // For offline show a summary message underneath the heading.
583 if (error_code == net::ERR_INTERNET_DISCONNECTED ||
584 error_code == error_page::DNS_PROBE_FINISHED_NO_INTERNET) {
585 error_strings->SetString("primaryParagraph",
586 l10n_util::GetStringUTF16(options.summary_resource_id));
588 #if defined(OS_CHROMEOS)
589 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
591 // Check if easter egg should be disabled.
592 if (command_line->HasSwitch(switches::kDisableDinosaurEasterEgg)) {
593 // The prescence of this string disables the easter egg. Acts as a flag.
594 error_strings->SetString("disabledEasterEgg",
595 l10n_util::GetStringUTF16(IDS_ERRORPAGE_FUN_DISABLED));
597 #endif
599 } else {
600 // Set summary message in the details.
601 summary->SetString("msg",
602 l10n_util::GetStringUTF16(options.summary_resource_id));
604 summary->SetString("failedUrl", failed_url_string);
605 summary->SetString("hostName", url_formatter::IDNToUnicode(failed_url.host(),
606 accept_languages));
607 summary->SetString("productName",
608 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
610 error_strings->SetString(
611 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS));
612 error_strings->SetString(
613 "hideDetails", l10n_util::GetStringUTF16(
614 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS));
615 error_strings->Set("summary", summary);
617 if (options.details_resource_id != kErrorPagesNoDetails) {
618 error_strings->SetString(
619 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id));
622 base::string16 error_string;
623 if (error_domain == net::kErrorDomain) {
624 // Non-internationalized error string, for debugging Chrome itself.
625 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
626 } else if (error_domain == error_page::kDnsProbeErrorDomain) {
627 std::string ascii_error_string =
628 error_page::DnsProbeStatusToString(error_code);
629 error_string = base::ASCIIToUTF16(ascii_error_string);
630 } else {
631 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
632 error_string = base::IntToString16(error_code);
634 error_strings->SetString("errorCode",
635 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string));
637 // Platform specific information for diagnosing network issues on OSX and
638 // Windows.
639 #if defined(OS_MACOSX) || defined(OS_WIN)
640 if (error_domain == net::kErrorDomain &&
641 error_code == net::ERR_INTERNET_DISCONNECTED) {
642 int platform_string_id =
643 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM;
644 #if defined(OS_WIN)
645 // Different versions of Windows have different instructions.
646 base::win::Version windows_version = base::win::GetVersion();
647 if (windows_version < base::win::VERSION_VISTA) {
648 // XP, XP64, and Server 2003.
649 platform_string_id =
650 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP;
651 } else if (windows_version == base::win::VERSION_VISTA) {
652 // Vista
653 platform_string_id =
654 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA;
656 #endif // defined(OS_WIN)
657 // Platform dependent portion of the summary section.
658 summary->SetString("msg",
659 l10n_util::GetStringFUTF16(
660 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE,
661 l10n_util::GetStringUTF16(platform_string_id)));
663 #endif // defined(OS_MACOSX) || defined(OS_WIN)
665 // If no parameters were provided, use the defaults.
666 if (!params) {
667 params.reset(new error_page::ErrorPageParams());
668 params->suggest_reload = !!(options.suggestions & SUGGEST_RELOAD);
671 base::ListValue* suggestions = NULL;
672 bool use_default_suggestions = true;
673 if (!params->override_suggestions) {
674 suggestions = new base::ListValue();
675 } else {
676 suggestions = params->override_suggestions.release();
677 use_default_suggestions = false;
678 EnableGoogleCachedCopyButtonExperiment(suggestions, error_strings);
681 error_strings->Set("suggestions", suggestions);
683 if (params->search_url.is_valid()) {
684 error_strings->SetString("searchHeader",
685 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH));
686 error_strings->SetString("searchUrl", params->search_url.spec());
687 error_strings->SetString("searchTerms", params->search_terms);
688 error_strings->SetInteger("searchTrackingId", params->search_tracking_id);
691 // Add the reload suggestion, if needed.
692 if (params->suggest_reload) {
693 if (!is_post) {
694 base::DictionaryValue* reload_button = new base::DictionaryValue;
695 reload_button->SetString(
696 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
697 reload_button->SetString("reloadUrl", failed_url.spec());
698 error_strings->Set("reloadButton", reload_button);
699 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id);
700 } else {
701 // If the page was created by a post, it can't be reloaded in the same
702 // way, so just add a suggestion instead.
703 // TODO(mmenke): Make the reload button bring up the repost confirmation
704 // dialog for pages resulting from posts.
705 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue;
706 suggest_reload_repost->SetString("header",
707 l10n_util::GetStringUTF16(
708 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
709 suggest_reload_repost->SetString("body",
710 l10n_util::GetStringUTF16(
711 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
712 // Add at the front, so it appears before other suggestions, in the case
713 // suggestions are being overridden by |params|.
714 suggestions->Insert(0, suggest_reload_repost);
718 // If not using the default suggestions, nothing else to do.
719 if (!use_default_suggestions)
720 return;
722 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
723 const std::string& show_saved_copy_value =
724 command_line->GetSwitchValueASCII(switches::kShowSavedCopy);
725 bool show_saved_copy_primary = (show_saved_copy_value ==
726 switches::kEnableShowSavedCopyPrimary);
727 bool show_saved_copy_secondary = (show_saved_copy_value ==
728 switches::kEnableShowSavedCopySecondary);
729 bool show_saved_copy_visible =
730 (stale_copy_in_cache && !is_post &&
731 (show_saved_copy_primary || show_saved_copy_secondary));
733 if (show_saved_copy_visible) {
734 base::DictionaryValue* show_saved_copy_button = new base::DictionaryValue;
735 show_saved_copy_button->SetString(
736 "msg", l10n_util::GetStringUTF16(
737 IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY));
738 show_saved_copy_button->SetString(
739 "title",
740 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY_HELP));
741 if (show_saved_copy_primary)
742 show_saved_copy_button->SetString("primary", "true");
743 error_strings->Set("showSavedCopyButton", show_saved_copy_button);
746 #if defined(OS_CHROMEOS)
747 // ChromeOS has its own diagnostics extension, which doesn't rely on a
748 // browser-initiated dialog.
749 can_show_network_diagnostics_dialog = true;
750 #endif
751 if (can_show_network_diagnostics_dialog && failed_url.is_valid() &&
752 failed_url.SchemeIsHTTPOrHTTPS()) {
753 error_strings->SetString(
754 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE));
757 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
758 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue;
759 suggest_check_connection->SetString("header",
760 l10n_util::GetStringUTF16(
761 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
762 suggest_check_connection->SetString("body",
763 l10n_util::GetStringUTF16(
764 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
765 suggestions->Append(suggest_check_connection);
768 if (options.suggestions & SUGGEST_DNS_CONFIG) {
769 base::DictionaryValue* suggest_dns_config = new base::DictionaryValue;
770 suggest_dns_config->SetString("header",
771 l10n_util::GetStringUTF16(
772 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER));
773 suggest_dns_config->SetString("body",
774 l10n_util::GetStringUTF16(
775 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY));
776 suggestions->Append(suggest_dns_config);
778 base::DictionaryValue* suggest_network_prediction =
779 GetStandardMenuItemsText();
780 suggest_network_prediction->SetString("header",
781 l10n_util::GetStringUTF16(
782 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER));
783 suggest_network_prediction->SetString("body",
784 l10n_util::GetStringUTF16(
785 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY));
786 suggest_network_prediction->SetString(
787 "noNetworkPredictionTitle",
788 l10n_util::GetStringUTF16(
789 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION));
790 suggestions->Append(suggest_network_prediction);
793 if (options.suggestions & SUGGEST_FIREWALL_CONFIG) {
794 base::DictionaryValue* suggest_firewall_config = new base::DictionaryValue;
795 suggest_firewall_config->SetString("header",
796 l10n_util::GetStringUTF16(
797 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER));
798 suggest_firewall_config->SetString("body",
799 l10n_util::GetStringUTF16(
800 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY));
801 suggestions->Append(suggest_firewall_config);
804 if (options.suggestions & SUGGEST_PROXY_CONFIG) {
805 base::DictionaryValue* suggest_proxy_config = GetStandardMenuItemsText();
806 suggest_proxy_config->SetString("header",
807 l10n_util::GetStringUTF16(
808 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER));
809 suggest_proxy_config->SetString("body",
810 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY,
811 l10n_util::GetStringUTF16(
812 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM)));
813 suggest_proxy_config->SetString("proxyTitle",
814 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
816 suggestions->Append(suggest_proxy_config);
819 if (options.suggestions & SUGGEST_DISABLE_EXTENSION) {
820 base::DictionaryValue* suggest_disable_extension =
821 new base::DictionaryValue;
822 // There's only a header for this suggestion.
823 suggest_disable_extension->SetString("header",
824 l10n_util::GetStringUTF16(
825 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER));
826 suggestions->Append(suggest_disable_extension);
829 if (options.suggestions & SUGGEST_VIEW_POLICIES) {
830 base::DictionaryValue* suggest_view_policies = new base::DictionaryValue;
831 suggest_view_policies->SetString(
832 "header",
833 l10n_util::GetStringUTF16(
834 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER));
835 suggest_view_policies->SetString(
836 "body",
837 l10n_util::GetStringUTF16(
838 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY));
839 suggestions->Append(suggest_view_policies);
842 if (options.suggestions & SUGGEST_CONTACT_ADMINISTRATOR) {
843 base::DictionaryValue* suggest_contant_administrator =
844 new base::DictionaryValue;
845 suggest_contant_administrator->SetString(
846 "body",
847 l10n_util::GetStringUTF16(
848 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY));
849 suggestions->Append(suggest_contant_administrator);
852 if (options.suggestions & SUGGEST_LEARNMORE) {
853 GURL learn_more_url;
854 switch (options.error_code) {
855 case net::ERR_TOO_MANY_REDIRECTS:
856 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
857 break;
858 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
859 learn_more_url = GURL(kWeakDHKeyLearnMoreUrl);
860 break;
861 default:
862 break;
865 if (learn_more_url.is_valid()) {
866 // Add the language parameter to the URL.
867 std::string query = learn_more_url.query() + "&hl=" + locale;
868 GURL::Replacements repl;
869 repl.SetQueryStr(query);
870 learn_more_url = learn_more_url.ReplaceComponents(repl);
872 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue;
873 // There's only a body for this suggestion.
874 suggest_learn_more->SetString("body",
875 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
876 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
877 suggestions->Append(suggest_learn_more);
882 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error,
883 bool is_post) {
884 const LocalizedErrorMap* error_map =
885 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
886 if (error_map)
887 return l10n_util::GetStringUTF16(error_map->details_resource_id);
888 else
889 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
892 bool LocalizedError::HasStrings(const std::string& error_domain,
893 int error_code) {
894 // Whether or not the there are strings for an error does not depend on
895 // whether or not the page was be generated by a POST, so just claim it was
896 // not.
897 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
900 void LocalizedError::EnableGoogleCachedCopyButtonExperiment(
901 base::ListValue* suggestions,
902 base::DictionaryValue* error_strings) {
903 std::string field_trial_exp_type_ =
904 base::FieldTrialList::FindFullName(kCachedCopyButtonFieldTrial);
906 // Google cache copy button experiment.
907 // If the first suggestion is for a Google cache copy. Promote the
908 // suggestion to a separate set of strings for displaying as a button.
909 if (!suggestions->empty() && !field_trial_exp_type_.empty() &&
910 field_trial_exp_type_ != kCachedCopyButtonExpTypeControl) {
911 base::DictionaryValue* suggestion;
912 suggestions->GetDictionary(0, &suggestion);
913 int type = -1;
914 suggestion->GetInteger("type", &type);
916 if (type == kGoogleCachedCopySuggestionType) {
917 base::string16 cache_url;
918 suggestion->GetString("urlCorrection", &cache_url);
919 int cache_tracking_id = -1;
920 suggestion->GetInteger("trackingId", &cache_tracking_id);
921 scoped_ptr<base::DictionaryValue> cache_button(new base::DictionaryValue);
922 cache_button->SetString(
923 "msg",
924 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY));
925 cache_button->SetString("cacheUrl", cache_url);
926 cache_button->SetInteger("trackingId", cache_tracking_id);
927 error_strings->Set("cacheButton", cache_button.release());
929 // Remove the item from suggestions dictionary so that it does not get
930 // displayed by the template in the details section.
931 suggestions->Remove(0, nullptr);