Remove content-less string IDS_ERRORPAGES_ERROR_CODE.
[chromium-blink-merge.git] / chrome / common / localized_error.cc
blobd04dc4be17e46d8e03e418612538a80998ad2aaf
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://support.google.com/chrome?p=dh_error";
50 static const char kCachedCopyButtonFieldTrial[] =
51 "EnableGoogleCachedCopyTextExperiment";
52 static const char kCachedCopyButtonExpTypeControl[] = "control";
53 static const int kGoogleCachedCopySuggestionType = 0;
55 enum NAV_SUGGESTIONS {
56 SUGGEST_NONE = 0,
57 SUGGEST_RELOAD = 1 << 0,
58 SUGGEST_CHECK_CONNECTION = 1 << 1,
59 SUGGEST_DNS_CONFIG = 1 << 2,
60 SUGGEST_FIREWALL_CONFIG = 1 << 3,
61 SUGGEST_PROXY_CONFIG = 1 << 4,
62 SUGGEST_DISABLE_EXTENSION = 1 << 5,
63 SUGGEST_LEARNMORE = 1 << 6,
64 SUGGEST_VIEW_POLICIES = 1 << 7,
65 SUGGEST_CONTACT_ADMINISTRATOR = 1 << 8,
68 struct LocalizedErrorMap {
69 int error_code;
70 unsigned int title_resource_id;
71 unsigned int heading_resource_id;
72 // Detailed summary used when the error is in the main frame.
73 unsigned int summary_resource_id;
74 // Short one sentence description shown on mouse over when the error is in
75 // a frame.
76 unsigned int details_resource_id;
77 int suggestions; // Bitmap of SUGGEST_* values.
80 const LocalizedErrorMap net_error_options[] = {
81 {net::ERR_TIMED_OUT,
82 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
83 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
84 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
85 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
86 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
87 SUGGEST_PROXY_CONFIG,
89 {net::ERR_CONNECTION_TIMED_OUT,
90 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
91 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
92 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
93 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
94 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
95 SUGGEST_PROXY_CONFIG,
97 {net::ERR_CONNECTION_CLOSED,
98 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
99 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
100 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
101 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
102 SUGGEST_RELOAD,
104 {net::ERR_CONNECTION_RESET,
105 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
106 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
107 IDS_ERRORPAGES_SUMMARY_CONNECTION_RESET,
108 IDS_ERRORPAGES_DETAILS_CONNECTION_RESET,
109 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
110 SUGGEST_PROXY_CONFIG,
112 {net::ERR_CONNECTION_REFUSED,
113 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
114 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
115 IDS_ERRORPAGES_SUMMARY_CONNECTION_REFUSED,
116 IDS_ERRORPAGES_DETAILS_CONNECTION_REFUSED,
117 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
118 SUGGEST_PROXY_CONFIG,
120 {net::ERR_CONNECTION_FAILED,
121 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
122 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
123 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
124 IDS_ERRORPAGES_DETAILS_CONNECTION_FAILED,
125 SUGGEST_RELOAD,
127 {net::ERR_NAME_NOT_RESOLVED,
128 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
129 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
130 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
131 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
132 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_DNS_CONFIG |
133 SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
135 {net::ERR_ICANN_NAME_COLLISION,
136 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
137 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
138 IDS_ERRORPAGES_SUMMARY_ICANN_NAME_COLLISION,
139 IDS_ERRORPAGES_DETAILS_ICANN_NAME_COLLISION,
140 SUGGEST_NONE,
142 {net::ERR_ADDRESS_UNREACHABLE,
143 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
144 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
145 IDS_ERRORPAGES_SUMMARY_ADDRESS_UNREACHABLE,
146 IDS_ERRORPAGES_DETAILS_ADDRESS_UNREACHABLE,
147 SUGGEST_RELOAD | SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
149 {net::ERR_NETWORK_ACCESS_DENIED,
150 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
151 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
152 IDS_ERRORPAGES_SUMMARY_NETWORK_ACCESS_DENIED,
153 IDS_ERRORPAGES_DETAILS_NETWORK_ACCESS_DENIED,
154 SUGGEST_FIREWALL_CONFIG,
156 {net::ERR_PROXY_CONNECTION_FAILED,
157 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
158 IDS_ERRORPAGES_HEADING_PROXY_CONNECTION_FAILED,
159 IDS_ERRORPAGES_SUMMARY_PROXY_CONNECTION_FAILED,
160 IDS_ERRORPAGES_DETAILS_PROXY_CONNECTION_FAILED,
161 SUGGEST_PROXY_CONFIG,
163 {net::ERR_INTERNET_DISCONNECTED,
164 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
165 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
166 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
167 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
168 SUGGEST_NONE,
170 {net::ERR_FILE_NOT_FOUND,
171 IDS_ERRORPAGES_TITLE_NOT_FOUND,
172 IDS_ERRORPAGES_HEADING_NOT_FOUND,
173 IDS_ERRORPAGES_SUMMARY_NOT_FOUND,
174 IDS_ERRORPAGES_DETAILS_FILE_NOT_FOUND,
175 SUGGEST_NONE,
177 {net::ERR_CACHE_MISS,
178 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
179 IDS_ERRORPAGES_HEADING_CACHE_MISS,
180 IDS_ERRORPAGES_SUMMARY_CACHE_MISS,
181 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
182 SUGGEST_RELOAD,
184 {net::ERR_CACHE_READ_FAILURE,
185 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
186 IDS_ERRORPAGES_HEADING_CACHE_READ_FAILURE,
187 IDS_ERRORPAGES_SUMMARY_CACHE_READ_FAILURE,
188 IDS_ERRORPAGES_DETAILS_CACHE_READ_FAILURE,
189 SUGGEST_RELOAD,
191 {net::ERR_NETWORK_IO_SUSPENDED,
192 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
193 IDS_ERRORPAGES_HEADING_NETWORK_IO_SUSPENDED,
194 IDS_ERRORPAGES_SUMMARY_NETWORK_IO_SUSPENDED,
195 IDS_ERRORPAGES_DETAILS_NETWORK_IO_SUSPENDED,
196 SUGGEST_RELOAD,
198 {net::ERR_TOO_MANY_REDIRECTS,
199 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
200 IDS_ERRORPAGES_HEADING_TOO_MANY_REDIRECTS,
201 IDS_ERRORPAGES_SUMMARY_TOO_MANY_REDIRECTS,
202 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS,
203 SUGGEST_RELOAD | SUGGEST_LEARNMORE,
205 {net::ERR_EMPTY_RESPONSE,
206 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
207 IDS_ERRORPAGES_HEADING_EMPTY_RESPONSE,
208 IDS_ERRORPAGES_SUMMARY_EMPTY_RESPONSE,
209 IDS_ERRORPAGES_DETAILS_EMPTY_RESPONSE,
210 SUGGEST_RELOAD,
212 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
213 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
214 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
215 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
216 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
217 SUGGEST_NONE,
219 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
220 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
221 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
222 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
223 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
224 SUGGEST_NONE,
226 {net::ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION,
227 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
228 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
229 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
230 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_LOCATION,
231 SUGGEST_NONE,
233 {net::ERR_CONTENT_LENGTH_MISMATCH,
234 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
235 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
236 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
237 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
238 SUGGEST_RELOAD,
240 {net::ERR_INCOMPLETE_CHUNKED_ENCODING,
241 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
242 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
243 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
244 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
245 SUGGEST_RELOAD,
247 {net::ERR_SSL_PROTOCOL_ERROR,
248 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
249 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
250 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
251 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
252 SUGGEST_NONE,
254 {net::ERR_BAD_SSL_CLIENT_AUTH_CERT,
255 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
256 IDS_ERRORPAGES_HEADING_BAD_SSL_CLIENT_AUTH_CERT,
257 IDS_ERRORPAGES_SUMMARY_BAD_SSL_CLIENT_AUTH_CERT,
258 IDS_ERRORPAGES_DETAILS_BAD_SSL_CLIENT_AUTH_CERT,
259 SUGGEST_NONE,
261 {net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY,
262 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
263 IDS_ERRORPAGES_HEADING_WEAK_SERVER_EPHEMERAL_DH_KEY,
264 IDS_ERRORPAGES_SUMMARY_WEAK_SERVER_EPHEMERAL_DH_KEY,
265 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
266 SUGGEST_LEARNMORE,
268 {net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN,
269 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
270 IDS_ERRORPAGES_HEADING_PINNING_FAILURE,
271 IDS_ERRORPAGES_SUMMARY_PINNING_FAILURE,
272 IDS_ERRORPAGES_DETAILS_PINNING_FAILURE,
273 SUGGEST_NONE,
275 {net::ERR_TEMPORARILY_THROTTLED,
276 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
277 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
278 IDS_ERRORPAGES_SUMMARY_TEMPORARILY_THROTTLED,
279 IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED,
280 SUGGEST_NONE,
282 {net::ERR_BLOCKED_BY_CLIENT,
283 IDS_ERRORPAGES_TITLE_BLOCKED,
284 IDS_ERRORPAGES_HEADING_BLOCKED,
285 IDS_ERRORPAGES_SUMMARY_BLOCKED,
286 IDS_ERRORPAGES_DETAILS_BLOCKED,
287 SUGGEST_RELOAD | SUGGEST_DISABLE_EXTENSION,
289 {net::ERR_NETWORK_CHANGED,
290 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
291 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
292 IDS_ERRORPAGES_SUMMARY_NETWORK_CHANGED,
293 IDS_ERRORPAGES_DETAILS_NETWORK_CHANGED,
294 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION,
296 {net::ERR_BLOCKED_BY_ADMINISTRATOR,
297 IDS_ERRORPAGES_TITLE_BLOCKED,
298 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
299 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR,
300 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR,
301 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR,
303 {net::ERR_BLOCKED_ENROLLMENT_CHECK_PENDING,
304 IDS_ERRORPAGES_TITLE_BLOCKED,
305 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
306 IDS_ERRORPAGES_SUMMARY_BLOCKED_ENROLLMENT_CHECK_PENDING,
307 IDS_ERRORPAGES_DETAILS_BLOCKED_ENROLLMENT_CHECK_PENDING,
308 SUGGEST_CHECK_CONNECTION,
310 {net::ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
311 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
312 IDS_ERRORPAGES_HEADING_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
313 IDS_ERRORPAGES_SUMMARY_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
314 IDS_ERRORPAGES_DETAILS_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
315 SUGGEST_NONE,
317 {net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH,
318 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
319 IDS_ERRORPAGES_HEADING_SSL_VERSION_OR_CIPHER_MISMATCH,
320 IDS_ERRORPAGES_SUMMARY_SSL_VERSION_OR_CIPHER_MISMATCH,
321 IDS_ERRORPAGES_DETAILS_SSL_VERSION_OR_CIPHER_MISMATCH,
322 SUGGEST_NONE,
324 {net::ERR_TEMPORARY_BACKOFF,
325 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
326 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
327 IDS_ERRORPAGES_SUMMARY_TEMPORARY_BACKOFF,
328 IDS_ERRORPAGES_DETAILS_TEMPORARY_BACKOFF,
329 SUGGEST_NONE,
331 {net::ERR_SSL_SERVER_CERT_BAD_FORMAT,
332 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
333 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
334 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
335 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
336 SUGGEST_NONE,
340 // Special error page to be used in the case of navigating back to a page
341 // generated by a POST. LocalizedError::HasStrings expects this net error code
342 // to also appear in the array above.
343 const LocalizedErrorMap repost_error = {
344 net::ERR_CACHE_MISS,
345 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
346 IDS_HTTP_POST_WARNING_TITLE,
347 IDS_ERRORPAGES_HTTP_POST_WARNING,
348 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
349 SUGGEST_RELOAD,
352 const LocalizedErrorMap http_error_options[] = {
353 {403,
354 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
355 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
356 IDS_ERRORPAGES_SUMMARY_FORBIDDEN,
357 IDS_ERRORPAGES_DETAILS_FORBIDDEN,
358 SUGGEST_NONE,
360 {410,
361 IDS_ERRORPAGES_TITLE_NOT_FOUND,
362 IDS_ERRORPAGES_HEADING_NOT_FOUND,
363 IDS_ERRORPAGES_SUMMARY_GONE,
364 IDS_ERRORPAGES_DETAILS_GONE,
365 SUGGEST_NONE,
368 {500,
369 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
370 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
371 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR,
372 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR,
373 SUGGEST_RELOAD,
375 {501,
376 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
377 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
378 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
379 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED,
380 SUGGEST_NONE,
382 {502,
383 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
384 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
385 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY,
386 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY,
387 SUGGEST_RELOAD,
389 {503,
390 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
391 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
392 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE,
393 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE,
394 SUGGEST_RELOAD,
396 {504,
397 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
398 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
399 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT,
400 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT,
401 SUGGEST_RELOAD,
403 {505,
404 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
405 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
406 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
407 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED,
408 SUGGEST_NONE,
412 const LocalizedErrorMap dns_probe_error_options[] = {
413 {error_page::DNS_PROBE_POSSIBLE,
414 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
415 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
416 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
417 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
418 SUGGEST_RELOAD,
421 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
422 // error, which might be one of several DNS-related errors.
424 {error_page::DNS_PROBE_STARTED,
425 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
426 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
427 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
428 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
429 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
430 SUGGEST_RELOAD,
433 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
434 // original error, which might be one of several DNS-related errors.
436 {error_page::DNS_PROBE_FINISHED_NO_INTERNET,
437 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
438 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
439 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
440 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
441 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG,
443 {error_page::DNS_PROBE_FINISHED_BAD_CONFIG,
444 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
445 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
446 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
447 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
448 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG,
450 {error_page::DNS_PROBE_FINISHED_NXDOMAIN,
451 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
452 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
453 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
454 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
455 SUGGEST_RELOAD,
459 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps,
460 size_t num_maps,
461 int error_code) {
462 for (size_t i = 0; i < num_maps; ++i) {
463 if (maps[i].error_code == error_code)
464 return &maps[i];
466 return NULL;
469 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain,
470 int error_code, bool is_post) {
471 if (error_domain == net::kErrorDomain) {
472 // Display a different page in the special case of navigating through the
473 // history to an uncached page created by a POST.
474 if (is_post && error_code == net::ERR_CACHE_MISS)
475 return &repost_error;
476 return FindErrorMapInArray(net_error_options,
477 arraysize(net_error_options),
478 error_code);
479 } else if (error_domain == LocalizedError::kHttpErrorDomain) {
480 return FindErrorMapInArray(http_error_options,
481 arraysize(http_error_options),
482 error_code);
483 } else if (error_domain == error_page::kDnsProbeErrorDomain) {
484 const LocalizedErrorMap* map =
485 FindErrorMapInArray(dns_probe_error_options,
486 arraysize(dns_probe_error_options),
487 error_code);
488 DCHECK(map);
489 return map;
490 } else {
491 NOTREACHED();
492 return NULL;
496 // Returns a dictionary containing the strings for the settings menu under the
497 // wrench, and the advanced settings button.
498 base::DictionaryValue* GetStandardMenuItemsText() {
499 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue();
500 standard_menu_items_text->SetString("settingsTitle",
501 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
502 standard_menu_items_text->SetString("advancedTitle",
503 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS));
504 return standard_menu_items_text;
507 // Gets the icon class for a given |error_domain| and |error_code|.
508 const char* GetIconClassForError(const std::string& error_domain,
509 int error_code) {
510 if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
511 error_domain == net::kErrorDomain) ||
512 (error_code == error_page::DNS_PROBE_FINISHED_NO_INTERNET &&
513 error_domain == error_page::kDnsProbeErrorDomain))
514 return "icon-offline";
516 return "icon-generic";
519 } // namespace
521 const char LocalizedError::kHttpErrorDomain[] = "http";
523 void LocalizedError::GetStrings(int error_code,
524 const std::string& error_domain,
525 const GURL& failed_url,
526 bool is_post,
527 bool stale_copy_in_cache,
528 bool can_show_network_diagnostics_dialog,
529 const std::string& locale,
530 const std::string& accept_languages,
531 scoped_ptr<error_page::ErrorPageParams> params,
532 base::DictionaryValue* error_strings) {
533 webui::SetLoadTimeDataDefaults(locale, error_strings);
535 // Grab the strings and settings that depend on the error type. Init
536 // options with default values.
537 LocalizedErrorMap options = {
539 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
540 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
541 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
542 kErrorPagesNoDetails,
543 SUGGEST_NONE,
546 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
547 is_post);
548 if (error_map)
549 options = *error_map;
551 // If we got "access denied" but the url was a file URL, then we say it was a
552 // file instead of just using the "not available" default message. Just adding
553 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
554 // generated by some OSs when the operation doesn't involve a file URL.
555 if (error_domain == net::kErrorDomain &&
556 error_code == net::ERR_ACCESS_DENIED &&
557 failed_url.scheme() == "file") {
558 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED;
559 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED;
560 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED;
561 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED;
562 options.suggestions = SUGGEST_NONE;
565 base::string16 failed_url_string(url_formatter::FormatUrl(
566 failed_url, accept_languages, url_formatter::kFormatUrlOmitNothing,
567 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr));
568 // URLs are always LTR.
569 if (base::i18n::IsRTL())
570 base::i18n::WrapStringWithLTRFormatting(&failed_url_string);
571 error_strings->SetString("title",
572 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string));
573 error_strings->SetString("heading",
574 l10n_util::GetStringUTF16(options.heading_resource_id));
576 std::string icon_class = GetIconClassForError(error_domain, error_code);
577 error_strings->SetString("iconClass", icon_class);
579 base::DictionaryValue* summary = new base::DictionaryValue;
581 // For offline show a summary message underneath the heading.
582 if (error_code == net::ERR_INTERNET_DISCONNECTED ||
583 error_code == error_page::DNS_PROBE_FINISHED_NO_INTERNET) {
584 error_strings->SetString("primaryParagraph",
585 l10n_util::GetStringUTF16(options.summary_resource_id));
587 #if defined(OS_CHROMEOS)
588 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
590 // Check if easter egg should be disabled.
591 if (command_line->HasSwitch(switches::kDisableDinosaurEasterEgg)) {
592 // The prescence of this string disables the easter egg. Acts as a flag.
593 error_strings->SetString("disabledEasterEgg",
594 l10n_util::GetStringUTF16(IDS_ERRORPAGE_FUN_DISABLED));
596 #endif
598 } else {
599 // Set summary message in the details.
600 summary->SetString("msg",
601 l10n_util::GetStringUTF16(options.summary_resource_id));
603 summary->SetString("failedUrl", failed_url_string);
604 summary->SetString("hostName", url_formatter::IDNToUnicode(failed_url.host(),
605 accept_languages));
606 summary->SetString("productName",
607 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
609 error_strings->SetString(
610 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS));
611 error_strings->SetString(
612 "hideDetails", l10n_util::GetStringUTF16(
613 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS));
614 error_strings->Set("summary", summary);
616 if (options.details_resource_id != kErrorPagesNoDetails) {
617 error_strings->SetString(
618 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id));
621 base::string16 error_string;
622 if (error_domain == net::kErrorDomain) {
623 // Non-internationalized error string, for debugging Chrome itself.
624 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
625 } else if (error_domain == error_page::kDnsProbeErrorDomain) {
626 std::string ascii_error_string =
627 error_page::DnsProbeStatusToString(error_code);
628 error_string = base::ASCIIToUTF16(ascii_error_string);
629 } else {
630 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
631 error_string = base::IntToString16(error_code);
633 error_strings->SetString("errorCode", error_string);
635 // Platform specific information for diagnosing network issues on OSX and
636 // Windows.
637 #if defined(OS_MACOSX) || defined(OS_WIN)
638 if (error_domain == net::kErrorDomain &&
639 error_code == net::ERR_INTERNET_DISCONNECTED) {
640 int platform_string_id =
641 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM;
642 #if defined(OS_WIN)
643 // Different versions of Windows have different instructions.
644 base::win::Version windows_version = base::win::GetVersion();
645 if (windows_version < base::win::VERSION_VISTA) {
646 // XP, XP64, and Server 2003.
647 platform_string_id =
648 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP;
649 } else if (windows_version == base::win::VERSION_VISTA) {
650 // Vista
651 platform_string_id =
652 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA;
654 #endif // defined(OS_WIN)
655 // Platform dependent portion of the summary section.
656 summary->SetString("msg",
657 l10n_util::GetStringFUTF16(
658 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE,
659 l10n_util::GetStringUTF16(platform_string_id)));
661 #endif // defined(OS_MACOSX) || defined(OS_WIN)
663 // If no parameters were provided, use the defaults.
664 if (!params) {
665 params.reset(new error_page::ErrorPageParams());
666 params->suggest_reload = !!(options.suggestions & SUGGEST_RELOAD);
669 base::ListValue* suggestions = NULL;
670 bool use_default_suggestions = true;
671 if (!params->override_suggestions) {
672 suggestions = new base::ListValue();
673 } else {
674 suggestions = params->override_suggestions.release();
675 use_default_suggestions = false;
676 EnableGoogleCachedCopyButtonExperiment(suggestions, error_strings);
679 error_strings->Set("suggestions", suggestions);
681 if (params->search_url.is_valid()) {
682 error_strings->SetString("searchHeader",
683 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH));
684 error_strings->SetString("searchUrl", params->search_url.spec());
685 error_strings->SetString("searchTerms", params->search_terms);
686 error_strings->SetInteger("searchTrackingId", params->search_tracking_id);
689 // Add the reload suggestion, if needed.
690 if (params->suggest_reload) {
691 if (!is_post) {
692 base::DictionaryValue* reload_button = new base::DictionaryValue;
693 reload_button->SetString(
694 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
695 reload_button->SetString("reloadUrl", failed_url.spec());
696 error_strings->Set("reloadButton", reload_button);
697 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id);
698 } else {
699 // If the page was created by a post, it can't be reloaded in the same
700 // way, so just add a suggestion instead.
701 // TODO(mmenke): Make the reload button bring up the repost confirmation
702 // dialog for pages resulting from posts.
703 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue;
704 suggest_reload_repost->SetString("header",
705 l10n_util::GetStringUTF16(
706 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
707 suggest_reload_repost->SetString("body",
708 l10n_util::GetStringUTF16(
709 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
710 // Add at the front, so it appears before other suggestions, in the case
711 // suggestions are being overridden by |params|.
712 suggestions->Insert(0, suggest_reload_repost);
716 // If not using the default suggestions, nothing else to do.
717 if (!use_default_suggestions)
718 return;
720 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
721 const std::string& show_saved_copy_value =
722 command_line->GetSwitchValueASCII(switches::kShowSavedCopy);
723 bool show_saved_copy_primary = (show_saved_copy_value ==
724 switches::kEnableShowSavedCopyPrimary);
725 bool show_saved_copy_secondary = (show_saved_copy_value ==
726 switches::kEnableShowSavedCopySecondary);
727 bool show_saved_copy_visible =
728 (stale_copy_in_cache && !is_post &&
729 (show_saved_copy_primary || show_saved_copy_secondary));
731 if (show_saved_copy_visible) {
732 base::DictionaryValue* show_saved_copy_button = new base::DictionaryValue;
733 show_saved_copy_button->SetString(
734 "msg", l10n_util::GetStringUTF16(
735 IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY));
736 show_saved_copy_button->SetString(
737 "title",
738 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY_HELP));
739 if (show_saved_copy_primary)
740 show_saved_copy_button->SetString("primary", "true");
741 error_strings->Set("showSavedCopyButton", show_saved_copy_button);
744 #if defined(OS_CHROMEOS)
745 // ChromeOS has its own diagnostics extension, which doesn't rely on a
746 // browser-initiated dialog.
747 can_show_network_diagnostics_dialog = true;
748 #endif
749 if (can_show_network_diagnostics_dialog && failed_url.is_valid() &&
750 failed_url.SchemeIsHTTPOrHTTPS()) {
751 error_strings->SetString(
752 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE));
755 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
756 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue;
757 suggest_check_connection->SetString("header",
758 l10n_util::GetStringUTF16(
759 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
760 suggest_check_connection->SetString("body",
761 l10n_util::GetStringUTF16(
762 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
763 suggestions->Append(suggest_check_connection);
766 if (options.suggestions & SUGGEST_DNS_CONFIG) {
767 base::DictionaryValue* suggest_dns_config = new base::DictionaryValue;
768 suggest_dns_config->SetString("header",
769 l10n_util::GetStringUTF16(
770 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER));
771 suggest_dns_config->SetString("body",
772 l10n_util::GetStringUTF16(
773 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY));
774 suggestions->Append(suggest_dns_config);
776 base::DictionaryValue* suggest_network_prediction =
777 GetStandardMenuItemsText();
778 suggest_network_prediction->SetString("header",
779 l10n_util::GetStringUTF16(
780 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER));
781 suggest_network_prediction->SetString("body",
782 l10n_util::GetStringUTF16(
783 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY));
784 suggest_network_prediction->SetString(
785 "noNetworkPredictionTitle",
786 l10n_util::GetStringUTF16(
787 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION));
788 suggestions->Append(suggest_network_prediction);
791 if (options.suggestions & SUGGEST_FIREWALL_CONFIG) {
792 base::DictionaryValue* suggest_firewall_config = new base::DictionaryValue;
793 suggest_firewall_config->SetString("header",
794 l10n_util::GetStringUTF16(
795 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER));
796 suggest_firewall_config->SetString("body",
797 l10n_util::GetStringUTF16(
798 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY));
799 suggestions->Append(suggest_firewall_config);
802 if (options.suggestions & SUGGEST_PROXY_CONFIG) {
803 base::DictionaryValue* suggest_proxy_config = GetStandardMenuItemsText();
804 suggest_proxy_config->SetString("header",
805 l10n_util::GetStringUTF16(
806 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER));
807 suggest_proxy_config->SetString("body",
808 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY,
809 l10n_util::GetStringUTF16(
810 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM)));
811 suggest_proxy_config->SetString("proxyTitle",
812 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
814 suggestions->Append(suggest_proxy_config);
817 if (options.suggestions & SUGGEST_DISABLE_EXTENSION) {
818 base::DictionaryValue* suggest_disable_extension =
819 new base::DictionaryValue;
820 // There's only a header for this suggestion.
821 suggest_disable_extension->SetString("header",
822 l10n_util::GetStringUTF16(
823 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER));
824 suggestions->Append(suggest_disable_extension);
827 if (options.suggestions & SUGGEST_VIEW_POLICIES) {
828 base::DictionaryValue* suggest_view_policies = new base::DictionaryValue;
829 suggest_view_policies->SetString(
830 "header",
831 l10n_util::GetStringUTF16(
832 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER));
833 suggest_view_policies->SetString(
834 "body",
835 l10n_util::GetStringUTF16(
836 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY));
837 suggestions->Append(suggest_view_policies);
840 if (options.suggestions & SUGGEST_CONTACT_ADMINISTRATOR) {
841 base::DictionaryValue* suggest_contant_administrator =
842 new base::DictionaryValue;
843 suggest_contant_administrator->SetString(
844 "body",
845 l10n_util::GetStringUTF16(
846 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY));
847 suggestions->Append(suggest_contant_administrator);
850 if (options.suggestions & SUGGEST_LEARNMORE) {
851 GURL learn_more_url;
852 switch (options.error_code) {
853 case net::ERR_TOO_MANY_REDIRECTS:
854 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
855 break;
856 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
857 learn_more_url = GURL(kWeakDHKeyLearnMoreUrl);
858 break;
859 default:
860 break;
863 if (learn_more_url.is_valid()) {
864 // Add the language parameter to the URL.
865 std::string query = learn_more_url.query() + "&hl=" + locale;
866 GURL::Replacements repl;
867 repl.SetQueryStr(query);
868 learn_more_url = learn_more_url.ReplaceComponents(repl);
870 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue;
871 // There's only a body for this suggestion.
872 suggest_learn_more->SetString("body",
873 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
874 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
875 suggestions->Append(suggest_learn_more);
880 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error,
881 bool is_post) {
882 const LocalizedErrorMap* error_map =
883 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
884 if (error_map)
885 return l10n_util::GetStringUTF16(error_map->details_resource_id);
886 else
887 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
890 bool LocalizedError::HasStrings(const std::string& error_domain,
891 int error_code) {
892 // Whether or not the there are strings for an error does not depend on
893 // whether or not the page was be generated by a POST, so just claim it was
894 // not.
895 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
898 void LocalizedError::EnableGoogleCachedCopyButtonExperiment(
899 base::ListValue* suggestions,
900 base::DictionaryValue* error_strings) {
901 std::string field_trial_exp_type_ =
902 base::FieldTrialList::FindFullName(kCachedCopyButtonFieldTrial);
904 // Google cache copy button experiment.
905 // If the first suggestion is for a Google cache copy. Promote the
906 // suggestion to a separate set of strings for displaying as a button.
907 if (!suggestions->empty() && !field_trial_exp_type_.empty() &&
908 field_trial_exp_type_ != kCachedCopyButtonExpTypeControl) {
909 base::DictionaryValue* suggestion;
910 suggestions->GetDictionary(0, &suggestion);
911 int type = -1;
912 suggestion->GetInteger("type", &type);
914 if (type == kGoogleCachedCopySuggestionType) {
915 base::string16 cache_url;
916 suggestion->GetString("urlCorrection", &cache_url);
917 int cache_tracking_id = -1;
918 suggestion->GetInteger("trackingId", &cache_tracking_id);
919 scoped_ptr<base::DictionaryValue> cache_button(new base::DictionaryValue);
920 cache_button->SetString(
921 "msg",
922 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY));
923 cache_button->SetString("cacheUrl", cache_url);
924 cache_button->SetInteger("trackingId", cache_tracking_id);
925 error_strings->Set("cacheButton", cache_button.release());
927 // Remove the item from suggestions dictionary so that it does not get
928 // displayed by the template in the details section.
929 suggestions->Remove(0, nullptr);