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/i18n/rtl.h"
8 #include "base/logging.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h"
14 #include "chrome/common/extensions/extension_constants.h"
15 #include "chrome/common/extensions/extension_icon_set.h"
16 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
17 #include "chrome/common/net/net_error_info.h"
18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h"
20 #include "net/base/escape.h"
21 #include "net/base/net_errors.h"
22 #include "net/base/net_util.h"
23 #include "third_party/WebKit/public/platform/WebURLError.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/webui/web_ui_util.h"
28 #include "base/win/windows_version.h"
31 using blink::WebURLError
;
33 // Some error pages have no details.
34 const unsigned int kErrorPagesNoDetails
= 0;
38 static const char kRedirectLoopLearnMoreUrl
[] =
39 "https://www.google.com/support/chrome/bin/answer.py?answer=95626";
40 static const char kWeakDHKeyLearnMoreUrl
[] =
41 "http://sites.google.com/a/chromium.org/dev/"
42 "err_ssl_weak_server_ephemeral_dh_key";
43 #if defined(OS_CHROMEOS)
44 static const char kAppWarningLearnMoreUrl
[] =
45 "chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"
47 #endif // defined(OS_CHROMEOS)
49 enum NAV_SUGGESTIONS
{
51 SUGGEST_RELOAD
= 1 << 0,
52 SUGGEST_CHECK_CONNECTION
= 1 << 1,
53 SUGGEST_DNS_CONFIG
= 1 << 2,
54 SUGGEST_FIREWALL_CONFIG
= 1 << 3,
55 SUGGEST_PROXY_CONFIG
= 1 << 4,
56 SUGGEST_DISABLE_EXTENSION
= 1 << 5,
57 SUGGEST_LEARNMORE
= 1 << 6,
58 SUGGEST_VIEW_POLICIES
= 1 << 7,
59 SUGGEST_CONTACT_ADMINISTRATOR
= 1 << 8,
62 struct LocalizedErrorMap
{
64 unsigned int title_resource_id
;
65 unsigned int heading_resource_id
;
66 // Detailed summary used when the error is in the main frame.
67 unsigned int summary_resource_id
;
68 // Short one sentence description shown on mouse over when the error is in
70 unsigned int details_resource_id
;
71 int suggestions
; // Bitmap of SUGGEST_* values.
74 const LocalizedErrorMap net_error_options
[] = {
76 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
77 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
78 IDS_ERRORPAGES_SUMMARY_TIMED_OUT
,
79 IDS_ERRORPAGES_DETAILS_TIMED_OUT
,
80 SUGGEST_RELOAD
| SUGGEST_CHECK_CONNECTION
| SUGGEST_FIREWALL_CONFIG
|
83 {net::ERR_CONNECTION_TIMED_OUT
,
84 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
85 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
86 IDS_ERRORPAGES_SUMMARY_TIMED_OUT
,
87 IDS_ERRORPAGES_DETAILS_TIMED_OUT
,
88 SUGGEST_RELOAD
| SUGGEST_CHECK_CONNECTION
| SUGGEST_FIREWALL_CONFIG
|
91 {net::ERR_CONNECTION_CLOSED
,
92 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
93 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
94 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE
,
95 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED
,
98 {net::ERR_CONNECTION_RESET
,
99 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
100 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
101 IDS_ERRORPAGES_SUMMARY_CONNECTION_RESET
,
102 IDS_ERRORPAGES_DETAILS_CONNECTION_RESET
,
103 SUGGEST_RELOAD
| SUGGEST_CHECK_CONNECTION
| SUGGEST_FIREWALL_CONFIG
|
104 SUGGEST_PROXY_CONFIG
,
106 {net::ERR_CONNECTION_REFUSED
,
107 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
108 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
109 IDS_ERRORPAGES_SUMMARY_CONNECTION_REFUSED
,
110 IDS_ERRORPAGES_DETAILS_CONNECTION_REFUSED
,
111 SUGGEST_RELOAD
| SUGGEST_CHECK_CONNECTION
| SUGGEST_FIREWALL_CONFIG
|
112 SUGGEST_PROXY_CONFIG
,
114 {net::ERR_CONNECTION_FAILED
,
115 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
116 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
117 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE
,
118 IDS_ERRORPAGES_DETAILS_CONNECTION_FAILED
,
121 {net::ERR_NAME_NOT_RESOLVED
,
122 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
123 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
124 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED
,
125 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED
,
126 SUGGEST_RELOAD
| SUGGEST_CHECK_CONNECTION
| SUGGEST_DNS_CONFIG
|
127 SUGGEST_FIREWALL_CONFIG
| SUGGEST_PROXY_CONFIG
,
129 {net::ERR_ADDRESS_UNREACHABLE
,
130 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
131 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
132 IDS_ERRORPAGES_SUMMARY_ADDRESS_UNREACHABLE
,
133 IDS_ERRORPAGES_DETAILS_ADDRESS_UNREACHABLE
,
134 SUGGEST_RELOAD
| SUGGEST_FIREWALL_CONFIG
| SUGGEST_PROXY_CONFIG
,
136 {net::ERR_NETWORK_ACCESS_DENIED
,
137 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
138 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED
,
139 IDS_ERRORPAGES_SUMMARY_NETWORK_ACCESS_DENIED
,
140 IDS_ERRORPAGES_DETAILS_NETWORK_ACCESS_DENIED
,
141 SUGGEST_FIREWALL_CONFIG
,
143 {net::ERR_PROXY_CONNECTION_FAILED
,
144 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
145 IDS_ERRORPAGES_HEADING_PROXY_CONNECTION_FAILED
,
146 IDS_ERRORPAGES_SUMMARY_PROXY_CONNECTION_FAILED
,
147 IDS_ERRORPAGES_DETAILS_PROXY_CONNECTION_FAILED
,
148 SUGGEST_PROXY_CONFIG
,
150 {net::ERR_INTERNET_DISCONNECTED
,
151 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
152 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED
,
153 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED
,
154 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED
,
157 {net::ERR_FILE_NOT_FOUND
,
158 IDS_ERRORPAGES_TITLE_NOT_FOUND
,
159 IDS_ERRORPAGES_HEADING_NOT_FOUND
,
160 IDS_ERRORPAGES_SUMMARY_NOT_FOUND
,
161 IDS_ERRORPAGES_DETAILS_FILE_NOT_FOUND
,
164 {net::ERR_CACHE_MISS
,
165 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
166 IDS_ERRORPAGES_HEADING_CACHE_MISS
,
167 IDS_ERRORPAGES_SUMMARY_CACHE_MISS
,
168 IDS_ERRORPAGES_DETAILS_CACHE_MISS
,
171 {net::ERR_CACHE_READ_FAILURE
,
172 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
173 IDS_ERRORPAGES_HEADING_CACHE_READ_FAILURE
,
174 IDS_ERRORPAGES_SUMMARY_CACHE_READ_FAILURE
,
175 IDS_ERRORPAGES_DETAILS_CACHE_READ_FAILURE
,
178 {net::ERR_NETWORK_IO_SUSPENDED
,
179 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
180 IDS_ERRORPAGES_HEADING_NETWORK_IO_SUSPENDED
,
181 IDS_ERRORPAGES_SUMMARY_NETWORK_IO_SUSPENDED
,
182 IDS_ERRORPAGES_DETAILS_NETWORK_IO_SUSPENDED
,
185 {net::ERR_TOO_MANY_REDIRECTS
,
186 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
187 IDS_ERRORPAGES_HEADING_TOO_MANY_REDIRECTS
,
188 IDS_ERRORPAGES_SUMMARY_TOO_MANY_REDIRECTS
,
189 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS
,
190 SUGGEST_RELOAD
| SUGGEST_LEARNMORE
,
192 {net::ERR_EMPTY_RESPONSE
,
193 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
194 IDS_ERRORPAGES_HEADING_EMPTY_RESPONSE
,
195 IDS_ERRORPAGES_SUMMARY_EMPTY_RESPONSE
,
196 IDS_ERRORPAGES_DETAILS_EMPTY_RESPONSE
,
199 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH
,
200 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
201 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS
,
202 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS
,
203 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH
,
206 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
,
207 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
208 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS
,
209 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS
,
210 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
,
213 {net::ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION
,
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_LOCATION
,
220 {net::ERR_CONTENT_LENGTH_MISMATCH
,
221 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
222 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
223 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE
,
224 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED
,
227 {net::ERR_INCOMPLETE_CHUNKED_ENCODING
,
228 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
229 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
230 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE
,
231 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED
,
234 {net::ERR_SSL_PROTOCOL_ERROR
,
235 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
236 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR
,
237 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR
,
238 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR
,
241 {net::ERR_SSL_UNSAFE_NEGOTIATION
,
242 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
243 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR
,
244 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR
,
245 IDS_ERRORPAGES_DETAILS_SSL_UNSAFE_NEGOTIATION
,
248 {net::ERR_BAD_SSL_CLIENT_AUTH_CERT
,
249 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
250 IDS_ERRORPAGES_HEADING_BAD_SSL_CLIENT_AUTH_CERT
,
251 IDS_ERRORPAGES_SUMMARY_BAD_SSL_CLIENT_AUTH_CERT
,
252 IDS_ERRORPAGES_DETAILS_BAD_SSL_CLIENT_AUTH_CERT
,
255 {net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY
,
256 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
257 IDS_ERRORPAGES_HEADING_WEAK_SERVER_EPHEMERAL_DH_KEY
,
258 IDS_ERRORPAGES_SUMMARY_WEAK_SERVER_EPHEMERAL_DH_KEY
,
259 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR
,
262 {net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN
,
263 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
264 IDS_ERRORPAGES_HEADING_PINNING_FAILURE
,
265 IDS_ERRORPAGES_SUMMARY_PINNING_FAILURE
,
266 IDS_ERRORPAGES_DETAILS_PINNING_FAILURE
,
269 {net::ERR_TEMPORARILY_THROTTLED
,
270 IDS_ERRORPAGES_TITLE_ACCESS_DENIED
,
271 IDS_ERRORPAGES_HEADING_ACCESS_DENIED
,
272 IDS_ERRORPAGES_SUMMARY_TEMPORARILY_THROTTLED
,
273 IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED
,
276 {net::ERR_BLOCKED_BY_CLIENT
,
277 IDS_ERRORPAGES_TITLE_BLOCKED
,
278 IDS_ERRORPAGES_HEADING_BLOCKED
,
279 IDS_ERRORPAGES_SUMMARY_BLOCKED
,
280 IDS_ERRORPAGES_DETAILS_BLOCKED
,
281 SUGGEST_RELOAD
| SUGGEST_DISABLE_EXTENSION
,
283 {net::ERR_NETWORK_CHANGED
,
284 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
285 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED
,
286 IDS_ERRORPAGES_SUMMARY_NETWORK_CHANGED
,
287 IDS_ERRORPAGES_DETAILS_NETWORK_CHANGED
,
288 SUGGEST_RELOAD
| SUGGEST_CHECK_CONNECTION
,
290 {net::ERR_BLOCKED_BY_ADMINISTRATOR
,
291 IDS_ERRORPAGES_TITLE_BLOCKED
,
292 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR
,
293 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR
,
294 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR
,
295 SUGGEST_VIEW_POLICIES
| SUGGEST_CONTACT_ADMINISTRATOR
,
299 // Special error page to be used in the case of navigating back to a page
300 // generated by a POST. LocalizedError::HasStrings expects this net error code
301 // to also appear in the array above.
302 const LocalizedErrorMap repost_error
= {
304 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
305 IDS_HTTP_POST_WARNING_TITLE
,
306 IDS_ERRORPAGES_HTTP_POST_WARNING
,
307 IDS_ERRORPAGES_DETAILS_CACHE_MISS
,
311 const LocalizedErrorMap http_error_options
[] = {
313 IDS_ERRORPAGES_TITLE_ACCESS_DENIED
,
314 IDS_ERRORPAGES_HEADING_ACCESS_DENIED
,
315 IDS_ERRORPAGES_SUMMARY_FORBIDDEN
,
316 IDS_ERRORPAGES_DETAILS_FORBIDDEN
,
320 IDS_ERRORPAGES_TITLE_NOT_FOUND
,
321 IDS_ERRORPAGES_HEADING_NOT_FOUND
,
322 IDS_ERRORPAGES_SUMMARY_GONE
,
323 IDS_ERRORPAGES_DETAILS_GONE
,
328 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
329 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
330 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR
,
331 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR
,
335 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
336 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
337 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE
,
338 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED
,
342 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
343 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
344 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY
,
345 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY
,
349 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
350 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
351 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE
,
352 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE
,
356 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
357 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
358 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT
,
359 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT
,
363 IDS_ERRORPAGES_TITLE_LOAD_FAILED
,
364 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR
,
365 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE
,
366 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED
,
371 const LocalizedErrorMap dns_probe_error_options
[] = {
372 {chrome_common_net::DNS_PROBE_POSSIBLE
,
373 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
374 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
375 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING
,
376 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING
,
380 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
381 // error, which might be one of several DNS-related errors.
383 {chrome_common_net::DNS_PROBE_STARTED
,
384 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
385 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
386 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING
,
387 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING
,
388 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
392 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
393 // original error, which might be one of several DNS-related errors.
395 {chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET
,
396 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
397 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED
,
398 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED
,
399 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED
,
400 SUGGEST_RELOAD
| SUGGEST_CHECK_CONNECTION
| SUGGEST_FIREWALL_CONFIG
,
402 {chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG
,
403 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
404 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
405 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED
,
406 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED
,
407 SUGGEST_RELOAD
| SUGGEST_DNS_CONFIG
| SUGGEST_FIREWALL_CONFIG
,
409 {chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN
,
410 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
411 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
412 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED
,
413 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED
,
418 const LocalizedErrorMap
* FindErrorMapInArray(const LocalizedErrorMap
* maps
,
421 for (size_t i
= 0; i
< num_maps
; ++i
) {
422 if (maps
[i
].error_code
== error_code
)
428 const LocalizedErrorMap
* LookupErrorMap(const std::string
& error_domain
,
429 int error_code
, bool is_post
) {
430 if (error_domain
== net::kErrorDomain
) {
431 // Display a different page in the special case of navigating through the
432 // history to an uncached page created by a POST.
433 if (is_post
&& error_code
== net::ERR_CACHE_MISS
)
434 return &repost_error
;
435 return FindErrorMapInArray(net_error_options
,
436 arraysize(net_error_options
),
438 } else if (error_domain
== LocalizedError::kHttpErrorDomain
) {
439 return FindErrorMapInArray(http_error_options
,
440 arraysize(http_error_options
),
442 } else if (error_domain
== chrome_common_net::kDnsProbeErrorDomain
) {
443 const LocalizedErrorMap
* map
=
444 FindErrorMapInArray(dns_probe_error_options
,
445 arraysize(dns_probe_error_options
),
456 #if defined(TOOLKIT_GTK)
457 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within
458 // the renderer sandbox.
459 return base::i18n::ICUIsRTL();
461 return base::i18n::IsRTL();
465 // Returns a dictionary containing the strings for the settings menu under the
466 // wrench, and the advanced settings button.
467 base::DictionaryValue
* GetStandardMenuItemsText() {
468 base::DictionaryValue
* standard_menu_items_text
= new base::DictionaryValue();
469 standard_menu_items_text
->SetString("settingsTitle",
470 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE
));
471 standard_menu_items_text
->SetString("advancedTitle",
472 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS
));
473 return standard_menu_items_text
;
476 // Gets the icon class for a given |error_domain| and |error_code|.
477 const char* GetIconClassForError(const std::string
& error_domain
,
479 if ((error_code
== net::ERR_INTERNET_DISCONNECTED
&&
480 error_domain
== net::kErrorDomain
) ||
481 (error_code
== chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET
&&
482 error_domain
== chrome_common_net::kDnsProbeErrorDomain
))
483 return "icon-offline";
485 return "icon-generic";
490 const char LocalizedError::kHttpErrorDomain
[] = "http";
492 LocalizedError::ErrorPageParams::ErrorPageParams() : suggest_reload(false) {
495 LocalizedError::ErrorPageParams::~ErrorPageParams() {
498 void LocalizedError::GetStrings(int error_code
,
499 const std::string
& error_domain
,
500 const GURL
& failed_url
,
502 bool stale_copy_in_cache
,
503 const std::string
& locale
,
504 const std::string
& accept_languages
,
505 scoped_ptr
<ErrorPageParams
> params
,
506 base::DictionaryValue
* error_strings
) {
507 bool rtl
= LocaleIsRTL();
508 error_strings
->SetString("textdirection", rtl
? "rtl" : "ltr");
510 // Grab the strings and settings that depend on the error type. Init
511 // options with default values.
512 LocalizedErrorMap options
= {
514 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
515 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE
,
516 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE
,
517 kErrorPagesNoDetails
,
521 const LocalizedErrorMap
* error_map
= LookupErrorMap(error_domain
, error_code
,
524 options
= *error_map
;
526 // If we got "access denied" but the url was a file URL, then we say it was a
527 // file instead of just using the "not available" default message. Just adding
528 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
529 // generated by some OSs when the operation doesn't involve a file URL.
530 if (error_domain
== net::kErrorDomain
&&
531 error_code
== net::ERR_ACCESS_DENIED
&&
532 failed_url
.scheme() == "file") {
533 options
.title_resource_id
= IDS_ERRORPAGES_TITLE_ACCESS_DENIED
;
534 options
.heading_resource_id
= IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED
;
535 options
.summary_resource_id
= IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED
;
536 options
.details_resource_id
= IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED
;
537 options
.suggestions
= SUGGEST_NONE
;
540 base::string16
failed_url_string(net::FormatUrl(
541 failed_url
, accept_languages
, net::kFormatUrlOmitNothing
,
542 net::UnescapeRule::NORMAL
, NULL
, NULL
, NULL
));
543 // URLs are always LTR.
545 base::i18n::WrapStringWithLTRFormatting(&failed_url_string
);
546 error_strings
->SetString("title",
547 l10n_util::GetStringFUTF16(options
.title_resource_id
, failed_url_string
));
548 error_strings
->SetString("heading",
549 l10n_util::GetStringUTF16(options
.heading_resource_id
));
551 std::string icon_class
= GetIconClassForError(error_domain
, error_code
);
552 error_strings
->SetString("iconClass", icon_class
);
554 base::DictionaryValue
* summary
= new base::DictionaryValue
;
555 summary
->SetString("msg",
556 l10n_util::GetStringUTF16(options
.summary_resource_id
));
557 summary
->SetString("failedUrl", failed_url_string
);
558 summary
->SetString("hostName", net::IDNToUnicode(failed_url
.host(),
560 summary
->SetString("productName",
561 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
));
563 error_strings
->SetString(
564 "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE
));
565 error_strings
->SetString(
566 "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS
));
567 error_strings
->Set("summary", summary
);
569 if (options
.details_resource_id
!= kErrorPagesNoDetails
) {
570 error_strings
->SetString(
571 "errorDetails", l10n_util::GetStringUTF16(options
.details_resource_id
));
574 base::string16 error_string
;
575 if (error_domain
== net::kErrorDomain
) {
576 // Non-internationalized error string, for debugging Chrome itself.
577 std::string ascii_error_string
= net::ErrorToString(error_code
);
578 // Remove the leading "net::" from the returned string.
579 base::RemoveChars(ascii_error_string
, "net:", &ascii_error_string
);
580 error_string
= base::ASCIIToUTF16(ascii_error_string
);
581 } else if (error_domain
== chrome_common_net::kDnsProbeErrorDomain
) {
582 std::string ascii_error_string
=
583 chrome_common_net::DnsProbeStatusToString(error_code
);
584 error_string
= base::ASCIIToUTF16(ascii_error_string
);
586 DCHECK_EQ(LocalizedError::kHttpErrorDomain
, error_domain
);
587 error_string
= base::IntToString16(error_code
);
589 error_strings
->SetString("errorCode",
590 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE
, error_string
));
592 // Platform specific information for diagnosing network issues on OSX and
594 #if defined(OS_MACOSX) || defined(OS_WIN)
595 if (error_domain
== net::kErrorDomain
&&
596 error_code
== net::ERR_INTERNET_DISCONNECTED
) {
597 int platform_string_id
=
598 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM
;
600 // Different versions of Windows have different instructions.
601 base::win::Version windows_version
= base::win::GetVersion();
602 if (windows_version
< base::win::VERSION_VISTA
) {
603 // XP, XP64, and Server 2003.
605 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP
;
606 } else if (windows_version
== base::win::VERSION_VISTA
) {
609 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA
;
611 #endif // defined(OS_WIN)
612 // Lead with the general error description, and suffix with the platform
613 // dependent portion of the summary section.
614 summary
->SetString("msg",
615 l10n_util::GetStringFUTF16(
616 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE
,
617 l10n_util::GetStringUTF16(options
.summary_resource_id
),
618 l10n_util::GetStringUTF16(platform_string_id
)));
620 #endif // defined(OS_MACOSX) || defined(OS_WIN)
622 // If no parameters were provided, use the defaults.
624 params
.reset(new ErrorPageParams());
625 params
->suggest_reload
= !!(options
.suggestions
& SUGGEST_RELOAD
);
628 base::ListValue
* suggestions
= NULL
;
629 bool use_default_suggestions
= true;
630 if (!params
->override_suggestions
) {
631 suggestions
= new base::ListValue();
633 suggestions
= params
->override_suggestions
.release();
634 use_default_suggestions
= false;
637 error_strings
->Set("suggestions", suggestions
);
639 if (params
->search_url
.is_valid()) {
640 error_strings
->SetString("searchHeader",
641 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH
));
642 error_strings
->SetString("searchUrl", params
->search_url
.spec());
643 error_strings
->SetString("searchTerms", params
->search_terms
);
646 // Add the reload suggestion, if needed.
647 if (params
->suggest_reload
) {
649 base::DictionaryValue
* reload_button
= new base::DictionaryValue
;
650 reload_button
->SetString("msg",
651 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD
));
652 reload_button
->SetString("reloadUrl", failed_url
.spec());
653 error_strings
->Set("reload", reload_button
);
655 // If the page was created by a post, it can't be reloaded in the same
656 // way, so just add a suggestion instead.
657 // TODO(mmenke): Make the reload button bring up the repost confirmation
658 // dialog for pages resulting from posts.
659 base::DictionaryValue
* suggest_reload_repost
= new base::DictionaryValue
;
660 suggest_reload_repost
->SetString("header",
661 l10n_util::GetStringUTF16(
662 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER
));
663 suggest_reload_repost
->SetString("body",
664 l10n_util::GetStringUTF16(
665 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY
));
666 // Add at the front, so it appears before other suggestions, in the case
667 // suggestions are being overridden by |params|.
668 suggestions
->Insert(0, suggest_reload_repost
);
672 // If not using the default suggestions, nothing else to do.
673 if (!use_default_suggestions
)
676 error_strings
->SetBoolean("staleCopyInCache", stale_copy_in_cache
);
678 #if defined(OS_CHROMEOS)
679 error_strings
->SetString(
680 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE
));
681 #endif // defined(OS_CHROMEOS)
683 if (options
.suggestions
& SUGGEST_CHECK_CONNECTION
) {
684 base::DictionaryValue
* suggest_check_connection
= new base::DictionaryValue
;
685 suggest_check_connection
->SetString("header",
686 l10n_util::GetStringUTF16(
687 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER
));
688 suggest_check_connection
->SetString("body",
689 l10n_util::GetStringUTF16(
690 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY
));
691 suggestions
->Append(suggest_check_connection
);
694 if (options
.suggestions
& SUGGEST_DNS_CONFIG
) {
695 base::DictionaryValue
* suggest_dns_config
= new base::DictionaryValue
;
696 suggest_dns_config
->SetString("header",
697 l10n_util::GetStringUTF16(
698 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER
));
699 suggest_dns_config
->SetString("body",
700 l10n_util::GetStringUTF16(
701 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY
));
702 suggestions
->Append(suggest_dns_config
);
704 base::DictionaryValue
* suggest_network_prediction
=
705 GetStandardMenuItemsText();
706 suggest_network_prediction
->SetString("header",
707 l10n_util::GetStringUTF16(
708 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER
));
709 suggest_network_prediction
->SetString("body",
710 l10n_util::GetStringUTF16(
711 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY
));
712 suggest_network_prediction
->SetString(
713 "noNetworkPredictionTitle",
714 l10n_util::GetStringUTF16(
715 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION
));
716 suggestions
->Append(suggest_network_prediction
);
719 if (options
.suggestions
& SUGGEST_FIREWALL_CONFIG
) {
720 base::DictionaryValue
* suggest_firewall_config
= new base::DictionaryValue
;
721 suggest_firewall_config
->SetString("header",
722 l10n_util::GetStringUTF16(
723 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER
));
724 suggest_firewall_config
->SetString("body",
725 l10n_util::GetStringUTF16(
726 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY
));
727 suggestions
->Append(suggest_firewall_config
);
730 if (options
.suggestions
& SUGGEST_PROXY_CONFIG
) {
731 base::DictionaryValue
* suggest_proxy_config
= GetStandardMenuItemsText();
732 suggest_proxy_config
->SetString("header",
733 l10n_util::GetStringUTF16(
734 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER
));
735 suggest_proxy_config
->SetString("body",
736 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY
,
737 l10n_util::GetStringUTF16(
738 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM
)));
739 suggest_proxy_config
->SetString("proxyTitle",
740 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON
));
742 suggestions
->Append(suggest_proxy_config
);
745 if (options
.suggestions
& SUGGEST_DISABLE_EXTENSION
) {
746 base::DictionaryValue
* suggest_disable_extension
=
747 new base::DictionaryValue
;
748 // There's only a header for this suggestion.
749 suggest_disable_extension
->SetString("header",
750 l10n_util::GetStringUTF16(
751 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER
));
752 suggestions
->Append(suggest_disable_extension
);
755 if (options
.suggestions
& SUGGEST_VIEW_POLICIES
) {
756 base::DictionaryValue
* suggest_view_policies
= new base::DictionaryValue
;
757 suggest_view_policies
->SetString(
759 l10n_util::GetStringUTF16(
760 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER
));
761 suggest_view_policies
->SetString(
763 l10n_util::GetStringUTF16(
764 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY
));
765 suggestions
->Append(suggest_view_policies
);
768 if (options
.suggestions
& SUGGEST_CONTACT_ADMINISTRATOR
) {
769 base::DictionaryValue
* suggest_contant_administrator
=
770 new base::DictionaryValue
;
771 suggest_contant_administrator
->SetString(
773 l10n_util::GetStringUTF16(
774 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY
));
775 suggestions
->Append(suggest_contant_administrator
);
778 if (options
.suggestions
& SUGGEST_LEARNMORE
) {
780 switch (options
.error_code
) {
781 case net::ERR_TOO_MANY_REDIRECTS
:
782 learn_more_url
= GURL(kRedirectLoopLearnMoreUrl
);
784 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY
:
785 learn_more_url
= GURL(kWeakDHKeyLearnMoreUrl
);
791 if (learn_more_url
.is_valid()) {
792 // Add the language parameter to the URL.
793 std::string query
= learn_more_url
.query() + "&hl=" + locale
;
794 GURL::Replacements repl
;
795 repl
.SetQueryStr(query
);
796 learn_more_url
= learn_more_url
.ReplaceComponents(repl
);
798 base::DictionaryValue
* suggest_learn_more
= new base::DictionaryValue
;
799 // There's only a body for this suggestion.
800 suggest_learn_more
->SetString("body",
801 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY
));
802 suggest_learn_more
->SetString("learnMoreUrl", learn_more_url
.spec());
803 suggestions
->Append(suggest_learn_more
);
808 base::string16
LocalizedError::GetErrorDetails(const blink::WebURLError
& error
,
810 const LocalizedErrorMap
* error_map
=
811 LookupErrorMap(error
.domain
.utf8(), error
.reason
, is_post
);
813 return l10n_util::GetStringUTF16(error_map
->details_resource_id
);
815 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN
);
818 bool LocalizedError::HasStrings(const std::string
& error_domain
,
820 // Whether or not the there are strings for an error does not depend on
821 // whether or not the page was be generated by a POST, so just claim it was
823 return LookupErrorMap(error_domain
, error_code
, /*is_post=*/false) != NULL
;
826 void LocalizedError::GetAppErrorStrings(
827 const GURL
& display_url
,
828 const extensions::Extension
* app
,
829 base::DictionaryValue
* error_strings
) {
832 bool rtl
= LocaleIsRTL();
833 error_strings
->SetString("textdirection", rtl
? "rtl" : "ltr");
835 base::string16
failed_url(base::ASCIIToUTF16(display_url
.spec()));
836 // URLs are always LTR.
838 base::i18n::WrapStringWithLTRFormatting(&failed_url
);
839 error_strings
->SetString(
840 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE
,
841 failed_url
.c_str()));
843 error_strings
->SetString("title", app
->name());
844 error_strings
->SetString(
846 extensions::IconsInfo::GetIconURL(
848 extension_misc::EXTENSION_ICON_GIGANTOR
,
849 ExtensionIconSet::MATCH_SMALLER
).spec());
850 error_strings
->SetString("name", app
->name());
851 error_strings
->SetString(
853 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING
));
855 #if defined(OS_CHROMEOS)
856 GURL
learn_more_url(kAppWarningLearnMoreUrl
);
857 base::DictionaryValue
* suggest_learn_more
= new base::DictionaryValue();
858 suggest_learn_more
->SetString("msg",
859 l10n_util::GetStringUTF16(
860 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY
));
861 suggest_learn_more
->SetString("learnMoreUrl", learn_more_url
.spec());
862 error_strings
->Set("suggestionsLearnMore", suggest_learn_more
);
863 #endif // defined(OS_CHROMEOS)