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 "net/base/escape.h"
22 #include "net/base/net_errors.h"
23 #include "net/base/net_util.h"
24 #include "third_party/WebKit/public/platform/WebURLError.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/webui/web_ui_util.h"
29 #include "base/win/windows_version.h"
32 #if defined(OS_CHROMEOS)
33 #include "base/command_line.h"
34 #include "chrome/common/chrome_switches.h"
37 using blink::WebURLError
;
39 // Some error pages have no details.
40 const unsigned int kErrorPagesNoDetails
= 0;
44 static const char kRedirectLoopLearnMoreUrl
[] =
45 "https://support.google.com/chrome/answer/95626";
46 static const char kWeakDHKeyLearnMoreUrl
[] =
47 "https://www.chromium.org/administrators/"
48 "err_ssl_weak_server_ephemeral_dh_key";
49 static const char kCachedCopyButtonFieldTrial
[] =
50 "EnableGoogleCachedCopyTextExperiment";
51 static const char kCachedCopyButtonExpTypeControl
[] = "control";
52 static const char kCachedCopyButtonExpTypeCopy
[] = "copy";
53 static const int kGoogleCachedCopySuggestionType
= 0;
55 enum NAV_SUGGESTIONS
{
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
{
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
76 unsigned int details_resource_id
;
77 int suggestions
; // Bitmap of SUGGEST_* values.
80 const LocalizedErrorMap net_error_options
[] = {
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
|
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
|
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
333 // Special error page to be used in the case of navigating back to a page
334 // generated by a POST. LocalizedError::HasStrings expects this net error code
335 // to also appear in the array above.
336 const LocalizedErrorMap repost_error
= {
338 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
339 IDS_HTTP_POST_WARNING_TITLE
,
340 IDS_ERRORPAGES_HTTP_POST_WARNING
,
341 IDS_ERRORPAGES_DETAILS_CACHE_MISS
,
345 const LocalizedErrorMap http_error_options
[] = {
347 IDS_ERRORPAGES_TITLE_ACCESS_DENIED
,
348 IDS_ERRORPAGES_HEADING_ACCESS_DENIED
,
349 IDS_ERRORPAGES_SUMMARY_FORBIDDEN
,
350 IDS_ERRORPAGES_DETAILS_FORBIDDEN
,
354 IDS_ERRORPAGES_TITLE_NOT_FOUND
,
355 IDS_ERRORPAGES_HEADING_NOT_FOUND
,
356 IDS_ERRORPAGES_SUMMARY_GONE
,
357 IDS_ERRORPAGES_DETAILS_GONE
,
362 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
363 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
364 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR
,
365 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR
,
369 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
370 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
371 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE
,
372 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED
,
376 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
377 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
378 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY
,
379 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY
,
383 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
384 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
385 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE
,
386 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE
,
390 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
391 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
392 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT
,
393 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT
,
397 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
398 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
399 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE
,
400 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED
,
405 const LocalizedErrorMap dns_probe_error_options
[] = {
406 {chrome_common_net::DNS_PROBE_POSSIBLE
,
407 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
408 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
409 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING
,
410 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING
,
414 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
415 // error, which might be one of several DNS-related errors.
417 {chrome_common_net::DNS_PROBE_STARTED
,
418 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
419 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
420 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING
,
421 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING
,
422 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
426 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
427 // original error, which might be one of several DNS-related errors.
429 {chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET
,
430 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
431 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED
,
432 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED
,
433 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED
,
434 SUGGEST_RELOAD
| SUGGEST_CHECK_CONNECTION
| SUGGEST_FIREWALL_CONFIG
,
436 {chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG
,
437 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
438 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
439 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED
,
440 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED
,
441 SUGGEST_RELOAD
| SUGGEST_DNS_CONFIG
| SUGGEST_FIREWALL_CONFIG
,
443 {chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN
,
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
,
452 const LocalizedErrorMap
* FindErrorMapInArray(const LocalizedErrorMap
* maps
,
455 for (size_t i
= 0; i
< num_maps
; ++i
) {
456 if (maps
[i
].error_code
== error_code
)
462 const LocalizedErrorMap
* LookupErrorMap(const std::string
& error_domain
,
463 int error_code
, bool is_post
) {
464 if (error_domain
== net::kErrorDomain
) {
465 // Display a different page in the special case of navigating through the
466 // history to an uncached page created by a POST.
467 if (is_post
&& error_code
== net::ERR_CACHE_MISS
)
468 return &repost_error
;
469 return FindErrorMapInArray(net_error_options
,
470 arraysize(net_error_options
),
472 } else if (error_domain
== LocalizedError::kHttpErrorDomain
) {
473 return FindErrorMapInArray(http_error_options
,
474 arraysize(http_error_options
),
476 } else if (error_domain
== chrome_common_net::kDnsProbeErrorDomain
) {
477 const LocalizedErrorMap
* map
=
478 FindErrorMapInArray(dns_probe_error_options
,
479 arraysize(dns_probe_error_options
),
489 // Returns a dictionary containing the strings for the settings menu under the
490 // wrench, and the advanced settings button.
491 base::DictionaryValue
* GetStandardMenuItemsText() {
492 base::DictionaryValue
* standard_menu_items_text
= new base::DictionaryValue();
493 standard_menu_items_text
->SetString("settingsTitle",
494 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE
));
495 standard_menu_items_text
->SetString("advancedTitle",
496 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS
));
497 return standard_menu_items_text
;
500 // Gets the icon class for a given |error_domain| and |error_code|.
501 const char* GetIconClassForError(const std::string
& error_domain
,
503 if ((error_code
== net::ERR_INTERNET_DISCONNECTED
&&
504 error_domain
== net::kErrorDomain
) ||
505 (error_code
== chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET
&&
506 error_domain
== chrome_common_net::kDnsProbeErrorDomain
))
507 return "icon-offline";
509 return "icon-generic";
514 const char LocalizedError::kHttpErrorDomain
[] = "http";
516 void LocalizedError::GetStrings(int error_code
,
517 const std::string
& error_domain
,
518 const GURL
& failed_url
,
520 bool stale_copy_in_cache
,
521 bool can_show_network_diagnostics_dialog
,
522 const std::string
& locale
,
523 const std::string
& accept_languages
,
524 scoped_ptr
<error_page::ErrorPageParams
> params
,
525 base::DictionaryValue
* error_strings
) {
526 webui::SetLoadTimeDataDefaults(locale
, error_strings
);
528 // Grab the strings and settings that depend on the error type. Init
529 // options with default values.
530 LocalizedErrorMap options
= {
532 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
533 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
534 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE
,
535 kErrorPagesNoDetails
,
539 const LocalizedErrorMap
* error_map
= LookupErrorMap(error_domain
, error_code
,
542 options
= *error_map
;
544 // If we got "access denied" but the url was a file URL, then we say it was a
545 // file instead of just using the "not available" default message. Just adding
546 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
547 // generated by some OSs when the operation doesn't involve a file URL.
548 if (error_domain
== net::kErrorDomain
&&
549 error_code
== net::ERR_ACCESS_DENIED
&&
550 failed_url
.scheme() == "file") {
551 options
.title_resource_id
= IDS_ERRORPAGES_TITLE_ACCESS_DENIED
;
552 options
.heading_resource_id
= IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED
;
553 options
.summary_resource_id
= IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED
;
554 options
.details_resource_id
= IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED
;
555 options
.suggestions
= SUGGEST_NONE
;
558 base::string16
failed_url_string(net::FormatUrl(
559 failed_url
, accept_languages
, net::kFormatUrlOmitNothing
,
560 net::UnescapeRule::NORMAL
, NULL
, NULL
, NULL
));
561 // URLs are always LTR.
562 if (base::i18n::IsRTL())
563 base::i18n::WrapStringWithLTRFormatting(&failed_url_string
);
564 error_strings
->SetString("title",
565 l10n_util::GetStringFUTF16(options
.title_resource_id
, failed_url_string
));
566 error_strings
->SetString("heading",
567 l10n_util::GetStringUTF16(options
.heading_resource_id
));
569 std::string icon_class
= GetIconClassForError(error_domain
, error_code
);
570 error_strings
->SetString("iconClass", icon_class
);
572 base::DictionaryValue
* summary
= new base::DictionaryValue
;
574 // For offline show a summary message underneath the heading.
575 if (error_code
== net::ERR_INTERNET_DISCONNECTED
||
576 error_code
== chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET
) {
577 error_strings
->SetString("primaryParagraph",
578 l10n_util::GetStringUTF16(options
.summary_resource_id
));
580 #if defined(OS_CHROMEOS)
581 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
583 // Check if easter egg should be disabled.
584 if (command_line
->HasSwitch(switches::kDisableDinosaurEasterEgg
)) {
585 // The prescence of this string disables the easter egg. Acts as a flag.
586 error_strings
->SetString("disabledEasterEgg",
587 l10n_util::GetStringUTF16(IDS_ERRORPAGE_FUN_DISABLED
));
592 // Set summary message in the details.
593 summary
->SetString("msg",
594 l10n_util::GetStringUTF16(options
.summary_resource_id
));
596 summary
->SetString("failedUrl", failed_url_string
);
597 summary
->SetString("hostName", net::IDNToUnicode(failed_url
.host(),
599 summary
->SetString("productName",
600 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
));
602 error_strings
->SetString(
603 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS
));
604 error_strings
->SetString(
605 "hideDetails", l10n_util::GetStringUTF16(
606 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS
));
607 error_strings
->Set("summary", summary
);
609 if (options
.details_resource_id
!= kErrorPagesNoDetails
) {
610 error_strings
->SetString(
611 "errorDetails", l10n_util::GetStringUTF16(options
.details_resource_id
));
614 base::string16 error_string
;
615 if (error_domain
== net::kErrorDomain
) {
616 // Non-internationalized error string, for debugging Chrome itself.
617 error_string
= base::ASCIIToUTF16(net::ErrorToShortString(error_code
));
618 } else if (error_domain
== chrome_common_net::kDnsProbeErrorDomain
) {
619 std::string ascii_error_string
=
620 chrome_common_net::DnsProbeStatusToString(error_code
);
621 error_string
= base::ASCIIToUTF16(ascii_error_string
);
623 DCHECK_EQ(LocalizedError::kHttpErrorDomain
, error_domain
);
624 error_string
= base::IntToString16(error_code
);
626 error_strings
->SetString("errorCode",
627 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE
, error_string
));
629 // Platform specific information for diagnosing network issues on OSX and
631 #if defined(OS_MACOSX) || defined(OS_WIN)
632 if (error_domain
== net::kErrorDomain
&&
633 error_code
== net::ERR_INTERNET_DISCONNECTED
) {
634 int platform_string_id
=
635 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM
;
637 // Different versions of Windows have different instructions.
638 base::win::Version windows_version
= base::win::GetVersion();
639 if (windows_version
< base::win::VERSION_VISTA
) {
640 // XP, XP64, and Server 2003.
642 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP
;
643 } else if (windows_version
== base::win::VERSION_VISTA
) {
646 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA
;
648 #endif // defined(OS_WIN)
649 // Platform dependent portion of the summary section.
650 summary
->SetString("msg",
651 l10n_util::GetStringFUTF16(
652 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE
,
653 l10n_util::GetStringUTF16(platform_string_id
)));
655 #endif // defined(OS_MACOSX) || defined(OS_WIN)
657 // If no parameters were provided, use the defaults.
659 params
.reset(new error_page::ErrorPageParams());
660 params
->suggest_reload
= !!(options
.suggestions
& SUGGEST_RELOAD
);
663 base::ListValue
* suggestions
= NULL
;
664 bool use_default_suggestions
= true;
665 if (!params
->override_suggestions
) {
666 suggestions
= new base::ListValue();
668 suggestions
= params
->override_suggestions
.release();
669 use_default_suggestions
= false;
670 EnableGoogleCachedCopyButtonExperiment(suggestions
, error_strings
);
673 error_strings
->Set("suggestions", suggestions
);
675 if (params
->search_url
.is_valid()) {
676 error_strings
->SetString("searchHeader",
677 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH
));
678 error_strings
->SetString("searchUrl", params
->search_url
.spec());
679 error_strings
->SetString("searchTerms", params
->search_terms
);
680 error_strings
->SetInteger("searchTrackingId", params
->search_tracking_id
);
683 // Add the reload suggestion, if needed.
684 if (params
->suggest_reload
) {
686 base::DictionaryValue
* reload_button
= new base::DictionaryValue
;
687 reload_button
->SetString(
688 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD
));
689 reload_button
->SetString("reloadUrl", failed_url
.spec());
690 error_strings
->Set("reloadButton", reload_button
);
691 reload_button
->SetInteger("reloadTrackingId", params
->reload_tracking_id
);
693 // If the page was created by a post, it can't be reloaded in the same
694 // way, so just add a suggestion instead.
695 // TODO(mmenke): Make the reload button bring up the repost confirmation
696 // dialog for pages resulting from posts.
697 base::DictionaryValue
* suggest_reload_repost
= new base::DictionaryValue
;
698 suggest_reload_repost
->SetString("header",
699 l10n_util::GetStringUTF16(
700 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER
));
701 suggest_reload_repost
->SetString("body",
702 l10n_util::GetStringUTF16(
703 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY
));
704 // Add at the front, so it appears before other suggestions, in the case
705 // suggestions are being overridden by |params|.
706 suggestions
->Insert(0, suggest_reload_repost
);
710 // If not using the default suggestions, nothing else to do.
711 if (!use_default_suggestions
)
714 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
715 const std::string
& show_saved_copy_value
=
716 command_line
->GetSwitchValueASCII(switches::kShowSavedCopy
);
717 bool show_saved_copy_primary
= (show_saved_copy_value
==
718 switches::kEnableShowSavedCopyPrimary
);
719 bool show_saved_copy_secondary
= (show_saved_copy_value
==
720 switches::kEnableShowSavedCopySecondary
);
721 bool show_saved_copy_visible
=
722 (stale_copy_in_cache
&& !is_post
&&
723 (show_saved_copy_primary
|| show_saved_copy_secondary
));
725 if (show_saved_copy_visible
) {
726 base::DictionaryValue
* show_saved_copy_button
= new base::DictionaryValue
;
727 show_saved_copy_button
->SetString(
728 "msg", l10n_util::GetStringUTF16(
729 IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY
));
730 show_saved_copy_button
->SetString(
732 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY_HELP
));
733 if (show_saved_copy_primary
)
734 show_saved_copy_button
->SetString("primary", "true");
735 error_strings
->Set("showSavedCopyButton", show_saved_copy_button
);
738 #if defined(OS_CHROMEOS)
739 // ChromeOS has its own diagnostics extension, which doesn't rely on a
740 // browser-initiated dialog.
741 can_show_network_diagnostics_dialog
= true;
743 if (can_show_network_diagnostics_dialog
&& failed_url
.is_valid() &&
744 failed_url
.SchemeIsHTTPOrHTTPS()) {
745 error_strings
->SetString(
746 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE
));
749 if (options
.suggestions
& SUGGEST_CHECK_CONNECTION
) {
750 base::DictionaryValue
* suggest_check_connection
= new base::DictionaryValue
;
751 suggest_check_connection
->SetString("header",
752 l10n_util::GetStringUTF16(
753 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER
));
754 suggest_check_connection
->SetString("body",
755 l10n_util::GetStringUTF16(
756 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY
));
757 suggestions
->Append(suggest_check_connection
);
760 if (options
.suggestions
& SUGGEST_DNS_CONFIG
) {
761 base::DictionaryValue
* suggest_dns_config
= new base::DictionaryValue
;
762 suggest_dns_config
->SetString("header",
763 l10n_util::GetStringUTF16(
764 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER
));
765 suggest_dns_config
->SetString("body",
766 l10n_util::GetStringUTF16(
767 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY
));
768 suggestions
->Append(suggest_dns_config
);
770 base::DictionaryValue
* suggest_network_prediction
=
771 GetStandardMenuItemsText();
772 suggest_network_prediction
->SetString("header",
773 l10n_util::GetStringUTF16(
774 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER
));
775 suggest_network_prediction
->SetString("body",
776 l10n_util::GetStringUTF16(
777 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY
));
778 suggest_network_prediction
->SetString(
779 "noNetworkPredictionTitle",
780 l10n_util::GetStringUTF16(
781 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION
));
782 suggestions
->Append(suggest_network_prediction
);
785 if (options
.suggestions
& SUGGEST_FIREWALL_CONFIG
) {
786 base::DictionaryValue
* suggest_firewall_config
= new base::DictionaryValue
;
787 suggest_firewall_config
->SetString("header",
788 l10n_util::GetStringUTF16(
789 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER
));
790 suggest_firewall_config
->SetString("body",
791 l10n_util::GetStringUTF16(
792 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY
));
793 suggestions
->Append(suggest_firewall_config
);
796 if (options
.suggestions
& SUGGEST_PROXY_CONFIG
) {
797 base::DictionaryValue
* suggest_proxy_config
= GetStandardMenuItemsText();
798 suggest_proxy_config
->SetString("header",
799 l10n_util::GetStringUTF16(
800 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER
));
801 suggest_proxy_config
->SetString("body",
802 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY
,
803 l10n_util::GetStringUTF16(
804 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM
)));
805 suggest_proxy_config
->SetString("proxyTitle",
806 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON
));
808 suggestions
->Append(suggest_proxy_config
);
811 if (options
.suggestions
& SUGGEST_DISABLE_EXTENSION
) {
812 base::DictionaryValue
* suggest_disable_extension
=
813 new base::DictionaryValue
;
814 // There's only a header for this suggestion.
815 suggest_disable_extension
->SetString("header",
816 l10n_util::GetStringUTF16(
817 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER
));
818 suggestions
->Append(suggest_disable_extension
);
821 if (options
.suggestions
& SUGGEST_VIEW_POLICIES
) {
822 base::DictionaryValue
* suggest_view_policies
= new base::DictionaryValue
;
823 suggest_view_policies
->SetString(
825 l10n_util::GetStringUTF16(
826 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER
));
827 suggest_view_policies
->SetString(
829 l10n_util::GetStringUTF16(
830 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY
));
831 suggestions
->Append(suggest_view_policies
);
834 if (options
.suggestions
& SUGGEST_CONTACT_ADMINISTRATOR
) {
835 base::DictionaryValue
* suggest_contant_administrator
=
836 new base::DictionaryValue
;
837 suggest_contant_administrator
->SetString(
839 l10n_util::GetStringUTF16(
840 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY
));
841 suggestions
->Append(suggest_contant_administrator
);
844 if (options
.suggestions
& SUGGEST_LEARNMORE
) {
846 switch (options
.error_code
) {
847 case net::ERR_TOO_MANY_REDIRECTS
:
848 learn_more_url
= GURL(kRedirectLoopLearnMoreUrl
);
850 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY
:
851 learn_more_url
= GURL(kWeakDHKeyLearnMoreUrl
);
857 if (learn_more_url
.is_valid()) {
858 // Add the language parameter to the URL.
859 std::string query
= learn_more_url
.query() + "&hl=" + locale
;
860 GURL::Replacements repl
;
861 repl
.SetQueryStr(query
);
862 learn_more_url
= learn_more_url
.ReplaceComponents(repl
);
864 base::DictionaryValue
* suggest_learn_more
= new base::DictionaryValue
;
865 // There's only a body for this suggestion.
866 suggest_learn_more
->SetString("body",
867 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY
));
868 suggest_learn_more
->SetString("learnMoreUrl", learn_more_url
.spec());
869 suggestions
->Append(suggest_learn_more
);
874 base::string16
LocalizedError::GetErrorDetails(const blink::WebURLError
& error
,
876 const LocalizedErrorMap
* error_map
=
877 LookupErrorMap(error
.domain
.utf8(), error
.reason
, is_post
);
879 return l10n_util::GetStringUTF16(error_map
->details_resource_id
);
881 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN
);
884 bool LocalizedError::HasStrings(const std::string
& error_domain
,
886 // Whether or not the there are strings for an error does not depend on
887 // whether or not the page was be generated by a POST, so just claim it was
889 return LookupErrorMap(error_domain
, error_code
, /*is_post=*/false) != NULL
;
892 void LocalizedError::EnableGoogleCachedCopyButtonExperiment(
893 base::ListValue
* suggestions
,
894 base::DictionaryValue
* error_strings
) {
895 std::string field_trial_exp_type_
=
896 base::FieldTrialList::FindFullName(kCachedCopyButtonFieldTrial
);
898 // If the first suggestion is for a Google cache copy. Promote the
899 // suggestion to a separate set of strings for displaying as a button.
900 if (!suggestions
->empty() && !field_trial_exp_type_
.empty() &&
901 field_trial_exp_type_
!= kCachedCopyButtonExpTypeControl
) {
902 base::DictionaryValue
* suggestion
;
903 suggestions
->GetDictionary(0, &suggestion
);
905 suggestion
->GetInteger("type", &type
);
907 if (type
== kGoogleCachedCopySuggestionType
) {
908 base::string16 cache_url
;
909 suggestion
->GetString("urlCorrection", &cache_url
);
910 int cache_tracking_id
= -1;
911 suggestion
->GetInteger("trackingId", &cache_tracking_id
);
913 scoped_ptr
<base::DictionaryValue
> cache_button(new base::DictionaryValue
);
915 // Google cache copy button label experiment.
916 if (field_trial_exp_type_
== kCachedCopyButtonExpTypeCopy
) {
917 cache_button
->SetString(
919 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_CACHED_COPY
));
920 cache_button
->SetBoolean("defaultLabel", false);
922 // Default to "Show cached page" button label.
923 cache_button
->SetString(
925 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_CACHED_PAGE
));
926 cache_button
->SetBoolean("defaultLabel", true);
928 cache_button
->SetString("cacheUrl", cache_url
);
929 cache_button
->SetInteger("trackingId", cache_tracking_id
);
930 error_strings
->Set("cacheButton", cache_button
.release());
932 // Remove the item from suggestions dictionary so that it does not get
933 // displayed by the template in the details section.
934 suggestions
->Remove(0, nullptr);