Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / common / localized_error.cc
blob0c4ad4361e590adf71d4784a78846863e490b287
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/strings/string16.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/grit/chromium_strings.h"
17 #include "chrome/grit/generated_resources.h"
18 #include "components/error_page/common/error_page_params.h"
19 #include "components/error_page/common/net_error_info.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"
27 #if defined(OS_WIN)
28 #include "base/win/windows_version.h"
29 #endif
31 #if defined(OS_CHROMEOS)
32 #include "base/command_line.h"
33 #include "chrome/common/chrome_switches.h"
34 #endif
36 #if defined(ENABLE_EXTENSIONS)
37 #include "extensions/common/constants.h"
38 #include "extensions/common/extension_icon_set.h"
39 #include "extensions/common/manifest_handlers/icons_handler.h"
40 #endif
42 using blink::WebURLError;
44 // Some error pages have no details.
45 const unsigned int kErrorPagesNoDetails = 0;
47 namespace {
49 static const char kRedirectLoopLearnMoreUrl[] =
50 "https://www.google.com/support/chrome/bin/answer.py?answer=95626";
51 static const char kWeakDHKeyLearnMoreUrl[] =
52 "http://sites.google.com/a/chromium.org/dev/"
53 "err_ssl_weak_server_ephemeral_dh_key";
54 #if defined(OS_CHROMEOS)
55 static const char kAppWarningLearnMoreUrl[] =
56 "chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"
57 "?answer=1721911";
58 #endif // defined(OS_CHROMEOS)
60 enum NAV_SUGGESTIONS {
61 SUGGEST_NONE = 0,
62 SUGGEST_RELOAD = 1 << 0,
63 SUGGEST_CHECK_CONNECTION = 1 << 1,
64 SUGGEST_DNS_CONFIG = 1 << 2,
65 SUGGEST_FIREWALL_CONFIG = 1 << 3,
66 SUGGEST_PROXY_CONFIG = 1 << 4,
67 SUGGEST_DISABLE_EXTENSION = 1 << 5,
68 SUGGEST_LEARNMORE = 1 << 6,
69 SUGGEST_VIEW_POLICIES = 1 << 7,
70 SUGGEST_CONTACT_ADMINISTRATOR = 1 << 8,
73 struct LocalizedErrorMap {
74 int error_code;
75 unsigned int title_resource_id;
76 unsigned int heading_resource_id;
77 // Detailed summary used when the error is in the main frame.
78 unsigned int summary_resource_id;
79 // Short one sentence description shown on mouse over when the error is in
80 // a frame.
81 unsigned int details_resource_id;
82 int suggestions; // Bitmap of SUGGEST_* values.
85 const LocalizedErrorMap net_error_options[] = {
86 {net::ERR_TIMED_OUT,
87 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
88 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
89 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
90 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
91 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
92 SUGGEST_PROXY_CONFIG,
94 {net::ERR_CONNECTION_TIMED_OUT,
95 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
96 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
97 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
98 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
99 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
100 SUGGEST_PROXY_CONFIG,
102 {net::ERR_CONNECTION_CLOSED,
103 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
104 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
105 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
106 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
107 SUGGEST_RELOAD,
109 {net::ERR_CONNECTION_RESET,
110 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
111 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
112 IDS_ERRORPAGES_SUMMARY_CONNECTION_RESET,
113 IDS_ERRORPAGES_DETAILS_CONNECTION_RESET,
114 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
115 SUGGEST_PROXY_CONFIG,
117 {net::ERR_CONNECTION_REFUSED,
118 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
119 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
120 IDS_ERRORPAGES_SUMMARY_CONNECTION_REFUSED,
121 IDS_ERRORPAGES_DETAILS_CONNECTION_REFUSED,
122 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
123 SUGGEST_PROXY_CONFIG,
125 {net::ERR_CONNECTION_FAILED,
126 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
127 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
128 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
129 IDS_ERRORPAGES_DETAILS_CONNECTION_FAILED,
130 SUGGEST_RELOAD,
132 {net::ERR_NAME_NOT_RESOLVED,
133 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
134 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
135 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
136 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
137 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_DNS_CONFIG |
138 SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
140 {net::ERR_ICANN_NAME_COLLISION,
141 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
142 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
143 IDS_ERRORPAGES_SUMMARY_ICANN_NAME_COLLISION,
144 IDS_ERRORPAGES_DETAILS_ICANN_NAME_COLLISION,
145 SUGGEST_NONE,
147 {net::ERR_ADDRESS_UNREACHABLE,
148 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
149 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
150 IDS_ERRORPAGES_SUMMARY_ADDRESS_UNREACHABLE,
151 IDS_ERRORPAGES_DETAILS_ADDRESS_UNREACHABLE,
152 SUGGEST_RELOAD | SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
154 {net::ERR_NETWORK_ACCESS_DENIED,
155 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
156 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
157 IDS_ERRORPAGES_SUMMARY_NETWORK_ACCESS_DENIED,
158 IDS_ERRORPAGES_DETAILS_NETWORK_ACCESS_DENIED,
159 SUGGEST_FIREWALL_CONFIG,
161 {net::ERR_PROXY_CONNECTION_FAILED,
162 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
163 IDS_ERRORPAGES_HEADING_PROXY_CONNECTION_FAILED,
164 IDS_ERRORPAGES_SUMMARY_PROXY_CONNECTION_FAILED,
165 IDS_ERRORPAGES_DETAILS_PROXY_CONNECTION_FAILED,
166 SUGGEST_PROXY_CONFIG,
168 {net::ERR_INTERNET_DISCONNECTED,
169 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
170 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
171 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
172 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
173 SUGGEST_NONE,
175 {net::ERR_FILE_NOT_FOUND,
176 IDS_ERRORPAGES_TITLE_NOT_FOUND,
177 IDS_ERRORPAGES_HEADING_NOT_FOUND,
178 IDS_ERRORPAGES_SUMMARY_NOT_FOUND,
179 IDS_ERRORPAGES_DETAILS_FILE_NOT_FOUND,
180 SUGGEST_NONE,
182 {net::ERR_CACHE_MISS,
183 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
184 IDS_ERRORPAGES_HEADING_CACHE_MISS,
185 IDS_ERRORPAGES_SUMMARY_CACHE_MISS,
186 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
187 SUGGEST_RELOAD,
189 {net::ERR_CACHE_READ_FAILURE,
190 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
191 IDS_ERRORPAGES_HEADING_CACHE_READ_FAILURE,
192 IDS_ERRORPAGES_SUMMARY_CACHE_READ_FAILURE,
193 IDS_ERRORPAGES_DETAILS_CACHE_READ_FAILURE,
194 SUGGEST_RELOAD,
196 {net::ERR_NETWORK_IO_SUSPENDED,
197 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
198 IDS_ERRORPAGES_HEADING_NETWORK_IO_SUSPENDED,
199 IDS_ERRORPAGES_SUMMARY_NETWORK_IO_SUSPENDED,
200 IDS_ERRORPAGES_DETAILS_NETWORK_IO_SUSPENDED,
201 SUGGEST_RELOAD,
203 {net::ERR_TOO_MANY_REDIRECTS,
204 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
205 IDS_ERRORPAGES_HEADING_TOO_MANY_REDIRECTS,
206 IDS_ERRORPAGES_SUMMARY_TOO_MANY_REDIRECTS,
207 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS,
208 SUGGEST_RELOAD | SUGGEST_LEARNMORE,
210 {net::ERR_EMPTY_RESPONSE,
211 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
212 IDS_ERRORPAGES_HEADING_EMPTY_RESPONSE,
213 IDS_ERRORPAGES_SUMMARY_EMPTY_RESPONSE,
214 IDS_ERRORPAGES_DETAILS_EMPTY_RESPONSE,
215 SUGGEST_RELOAD,
217 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
218 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
219 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
220 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
221 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
222 SUGGEST_NONE,
224 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
225 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
226 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
227 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
228 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
229 SUGGEST_NONE,
231 {net::ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION,
232 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
233 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
234 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
235 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_LOCATION,
236 SUGGEST_NONE,
238 {net::ERR_CONTENT_LENGTH_MISMATCH,
239 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
240 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
241 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
242 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
243 SUGGEST_RELOAD,
245 {net::ERR_INCOMPLETE_CHUNKED_ENCODING,
246 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
247 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
248 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
249 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
250 SUGGEST_RELOAD,
252 {net::ERR_SSL_PROTOCOL_ERROR,
253 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
254 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
255 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
256 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
257 SUGGEST_NONE,
259 {net::ERR_SSL_UNSAFE_NEGOTIATION,
260 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
261 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
262 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
263 IDS_ERRORPAGES_DETAILS_SSL_UNSAFE_NEGOTIATION,
264 SUGGEST_NONE,
266 {net::ERR_BAD_SSL_CLIENT_AUTH_CERT,
267 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
268 IDS_ERRORPAGES_HEADING_BAD_SSL_CLIENT_AUTH_CERT,
269 IDS_ERRORPAGES_SUMMARY_BAD_SSL_CLIENT_AUTH_CERT,
270 IDS_ERRORPAGES_DETAILS_BAD_SSL_CLIENT_AUTH_CERT,
271 SUGGEST_NONE,
273 {net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY,
274 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
275 IDS_ERRORPAGES_HEADING_WEAK_SERVER_EPHEMERAL_DH_KEY,
276 IDS_ERRORPAGES_SUMMARY_WEAK_SERVER_EPHEMERAL_DH_KEY,
277 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
278 SUGGEST_LEARNMORE,
280 {net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN,
281 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
282 IDS_ERRORPAGES_HEADING_PINNING_FAILURE,
283 IDS_ERRORPAGES_SUMMARY_PINNING_FAILURE,
284 IDS_ERRORPAGES_DETAILS_PINNING_FAILURE,
285 SUGGEST_NONE,
287 {net::ERR_TEMPORARILY_THROTTLED,
288 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
289 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
290 IDS_ERRORPAGES_SUMMARY_TEMPORARILY_THROTTLED,
291 IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED,
292 SUGGEST_NONE,
294 {net::ERR_BLOCKED_BY_CLIENT,
295 IDS_ERRORPAGES_TITLE_BLOCKED,
296 IDS_ERRORPAGES_HEADING_BLOCKED,
297 IDS_ERRORPAGES_SUMMARY_BLOCKED,
298 IDS_ERRORPAGES_DETAILS_BLOCKED,
299 SUGGEST_RELOAD | SUGGEST_DISABLE_EXTENSION,
301 {net::ERR_NETWORK_CHANGED,
302 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
303 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
304 IDS_ERRORPAGES_SUMMARY_NETWORK_CHANGED,
305 IDS_ERRORPAGES_DETAILS_NETWORK_CHANGED,
306 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION,
308 {net::ERR_BLOCKED_BY_ADMINISTRATOR,
309 IDS_ERRORPAGES_TITLE_BLOCKED,
310 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
311 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR,
312 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR,
313 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR,
315 {net::ERR_BLOCKED_ENROLLMENT_CHECK_PENDING,
316 IDS_ERRORPAGES_TITLE_BLOCKED,
317 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
318 IDS_ERRORPAGES_SUMMARY_BLOCKED_ENROLLMENT_CHECK_PENDING,
319 IDS_ERRORPAGES_DETAILS_BLOCKED_ENROLLMENT_CHECK_PENDING,
320 SUGGEST_CHECK_CONNECTION,
322 {net::ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
323 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
324 IDS_ERRORPAGES_HEADING_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
325 IDS_ERRORPAGES_SUMMARY_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
326 IDS_ERRORPAGES_DETAILS_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
327 SUGGEST_NONE,
329 {net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH,
330 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
331 IDS_ERRORPAGES_HEADING_SSL_VERSION_OR_CIPHER_MISMATCH,
332 IDS_ERRORPAGES_SUMMARY_SSL_VERSION_OR_CIPHER_MISMATCH,
333 IDS_ERRORPAGES_DETAILS_SSL_VERSION_OR_CIPHER_MISMATCH,
334 SUGGEST_NONE,
338 // Special error page to be used in the case of navigating back to a page
339 // generated by a POST. LocalizedError::HasStrings expects this net error code
340 // to also appear in the array above.
341 const LocalizedErrorMap repost_error = {
342 net::ERR_CACHE_MISS,
343 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
344 IDS_HTTP_POST_WARNING_TITLE,
345 IDS_ERRORPAGES_HTTP_POST_WARNING,
346 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
347 SUGGEST_RELOAD,
350 const LocalizedErrorMap http_error_options[] = {
351 {403,
352 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
353 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
354 IDS_ERRORPAGES_SUMMARY_FORBIDDEN,
355 IDS_ERRORPAGES_DETAILS_FORBIDDEN,
356 SUGGEST_NONE,
358 {410,
359 IDS_ERRORPAGES_TITLE_NOT_FOUND,
360 IDS_ERRORPAGES_HEADING_NOT_FOUND,
361 IDS_ERRORPAGES_SUMMARY_GONE,
362 IDS_ERRORPAGES_DETAILS_GONE,
363 SUGGEST_NONE,
366 {500,
367 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
368 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
369 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR,
370 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR,
371 SUGGEST_RELOAD,
373 {501,
374 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
375 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
376 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
377 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED,
378 SUGGEST_NONE,
380 {502,
381 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
382 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
383 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY,
384 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY,
385 SUGGEST_RELOAD,
387 {503,
388 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
389 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
390 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE,
391 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE,
392 SUGGEST_RELOAD,
394 {504,
395 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
396 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
397 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT,
398 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT,
399 SUGGEST_RELOAD,
401 {505,
402 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
403 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
404 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
405 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED,
406 SUGGEST_NONE,
410 const LocalizedErrorMap dns_probe_error_options[] = {
411 {chrome_common_net::DNS_PROBE_POSSIBLE,
412 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
413 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
414 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
415 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
416 SUGGEST_RELOAD,
419 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
420 // error, which might be one of several DNS-related errors.
422 {chrome_common_net::DNS_PROBE_STARTED,
423 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
424 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
425 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
426 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
427 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
428 SUGGEST_RELOAD,
431 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
432 // original error, which might be one of several DNS-related errors.
434 {chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
435 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
436 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
437 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
438 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
439 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG,
441 {chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG,
442 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
443 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
444 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
445 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
446 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG,
448 {chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN,
449 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
450 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
451 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
452 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
453 SUGGEST_RELOAD,
457 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps,
458 size_t num_maps,
459 int error_code) {
460 for (size_t i = 0; i < num_maps; ++i) {
461 if (maps[i].error_code == error_code)
462 return &maps[i];
464 return NULL;
467 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain,
468 int error_code, bool is_post) {
469 if (error_domain == net::kErrorDomain) {
470 // Display a different page in the special case of navigating through the
471 // history to an uncached page created by a POST.
472 if (is_post && error_code == net::ERR_CACHE_MISS)
473 return &repost_error;
474 return FindErrorMapInArray(net_error_options,
475 arraysize(net_error_options),
476 error_code);
477 } else if (error_domain == LocalizedError::kHttpErrorDomain) {
478 return FindErrorMapInArray(http_error_options,
479 arraysize(http_error_options),
480 error_code);
481 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
482 const LocalizedErrorMap* map =
483 FindErrorMapInArray(dns_probe_error_options,
484 arraysize(dns_probe_error_options),
485 error_code);
486 DCHECK(map);
487 return map;
488 } else {
489 NOTREACHED();
490 return NULL;
494 // Returns a dictionary containing the strings for the settings menu under the
495 // wrench, and the advanced settings button.
496 base::DictionaryValue* GetStandardMenuItemsText() {
497 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue();
498 standard_menu_items_text->SetString("settingsTitle",
499 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
500 standard_menu_items_text->SetString("advancedTitle",
501 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS));
502 return standard_menu_items_text;
505 // Gets the icon class for a given |error_domain| and |error_code|.
506 const char* GetIconClassForError(const std::string& error_domain,
507 int error_code) {
508 if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
509 error_domain == net::kErrorDomain) ||
510 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET &&
511 error_domain == chrome_common_net::kDnsProbeErrorDomain))
512 return "icon-offline";
514 return "icon-generic";
517 } // namespace
519 const char LocalizedError::kHttpErrorDomain[] = "http";
521 void LocalizedError::GetStrings(int error_code,
522 const std::string& error_domain,
523 const GURL& failed_url,
524 bool is_post,
525 bool stale_copy_in_cache,
526 const std::string& locale,
527 const std::string& accept_languages,
528 scoped_ptr<error_page::ErrorPageParams> params,
529 base::DictionaryValue* error_strings) {
530 webui::SetLoadTimeDataDefaults(locale, error_strings);
532 // Grab the strings and settings that depend on the error type. Init
533 // options with default values.
534 LocalizedErrorMap options = {
536 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
537 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
538 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
539 kErrorPagesNoDetails,
540 SUGGEST_NONE,
543 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
544 is_post);
545 if (error_map)
546 options = *error_map;
548 // If we got "access denied" but the url was a file URL, then we say it was a
549 // file instead of just using the "not available" default message. Just adding
550 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
551 // generated by some OSs when the operation doesn't involve a file URL.
552 if (error_domain == net::kErrorDomain &&
553 error_code == net::ERR_ACCESS_DENIED &&
554 failed_url.scheme() == "file") {
555 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED;
556 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED;
557 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED;
558 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED;
559 options.suggestions = SUGGEST_NONE;
562 base::string16 failed_url_string(net::FormatUrl(
563 failed_url, accept_languages, net::kFormatUrlOmitNothing,
564 net::UnescapeRule::NORMAL, NULL, NULL, NULL));
565 // URLs are always LTR.
566 if (base::i18n::IsRTL())
567 base::i18n::WrapStringWithLTRFormatting(&failed_url_string);
568 error_strings->SetString("title",
569 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string));
570 error_strings->SetString("heading",
571 l10n_util::GetStringUTF16(options.heading_resource_id));
573 std::string icon_class = GetIconClassForError(error_domain, error_code);
574 error_strings->SetString("iconClass", icon_class);
576 base::DictionaryValue* summary = new base::DictionaryValue;
578 // For offline show a summary message underneath the heading.
579 if (error_code == net::ERR_INTERNET_DISCONNECTED ||
580 error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET) {
581 error_strings->SetString("primaryParagraph",
582 l10n_util::GetStringUTF16(options.summary_resource_id));
584 #if defined(OS_CHROMEOS)
585 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
587 // Check if easter egg should be disabled.
588 if (command_line->HasSwitch(switches::kDisableDinosaurEasterEgg)) {
589 // The prescence of this string disables the easter egg. Acts as a flag.
590 error_strings->SetString("disabledEasterEgg",
591 l10n_util::GetStringUTF16(IDS_ERRORPAGE_FUN_DISABLED));
593 #endif
595 } else {
596 // Set summary message in the details.
597 summary->SetString("msg",
598 l10n_util::GetStringUTF16(options.summary_resource_id));
600 summary->SetString("failedUrl", failed_url_string);
601 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(),
602 accept_languages));
603 summary->SetString("productName",
604 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
606 error_strings->SetString(
607 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS));
608 error_strings->SetString(
609 "hideDetails", l10n_util::GetStringUTF16(
610 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS));
611 error_strings->Set("summary", summary);
613 if (options.details_resource_id != kErrorPagesNoDetails) {
614 error_strings->SetString(
615 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id));
618 base::string16 error_string;
619 if (error_domain == net::kErrorDomain) {
620 // Non-internationalized error string, for debugging Chrome itself.
621 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
622 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
623 std::string ascii_error_string =
624 chrome_common_net::DnsProbeStatusToString(error_code);
625 error_string = base::ASCIIToUTF16(ascii_error_string);
626 } else {
627 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
628 error_string = base::IntToString16(error_code);
630 error_strings->SetString("errorCode",
631 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string));
633 // Platform specific information for diagnosing network issues on OSX and
634 // Windows.
635 #if defined(OS_MACOSX) || defined(OS_WIN)
636 if (error_domain == net::kErrorDomain &&
637 error_code == net::ERR_INTERNET_DISCONNECTED) {
638 int platform_string_id =
639 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM;
640 #if defined(OS_WIN)
641 // Different versions of Windows have different instructions.
642 base::win::Version windows_version = base::win::GetVersion();
643 if (windows_version < base::win::VERSION_VISTA) {
644 // XP, XP64, and Server 2003.
645 platform_string_id =
646 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP;
647 } else if (windows_version == base::win::VERSION_VISTA) {
648 // Vista
649 platform_string_id =
650 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA;
652 #endif // defined(OS_WIN)
653 // Platform dependent portion of the summary section.
654 summary->SetString("msg",
655 l10n_util::GetStringFUTF16(
656 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE,
657 l10n_util::GetStringUTF16(platform_string_id)));
659 #endif // defined(OS_MACOSX) || defined(OS_WIN)
661 // If no parameters were provided, use the defaults.
662 if (!params) {
663 params.reset(new error_page::ErrorPageParams());
664 params->suggest_reload = !!(options.suggestions & SUGGEST_RELOAD);
667 base::ListValue* suggestions = NULL;
668 bool use_default_suggestions = true;
669 if (!params->override_suggestions) {
670 suggestions = new base::ListValue();
671 } else {
672 suggestions = params->override_suggestions.release();
673 use_default_suggestions = false;
676 error_strings->Set("suggestions", suggestions);
678 if (params->search_url.is_valid()) {
679 error_strings->SetString("searchHeader",
680 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH));
681 error_strings->SetString("searchUrl", params->search_url.spec());
682 error_strings->SetString("searchTerms", params->search_terms);
683 error_strings->SetInteger("searchTrackingId", params->search_tracking_id);
686 // Add the reload suggestion, if needed.
687 if (params->suggest_reload) {
688 if (!is_post) {
689 base::DictionaryValue* reload_button = new base::DictionaryValue;
690 reload_button->SetString(
691 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
692 reload_button->SetString("reloadUrl", failed_url.spec());
693 error_strings->Set("reloadButton", reload_button);
694 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id);
695 } else {
696 // If the page was created by a post, it can't be reloaded in the same
697 // way, so just add a suggestion instead.
698 // TODO(mmenke): Make the reload button bring up the repost confirmation
699 // dialog for pages resulting from posts.
700 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue;
701 suggest_reload_repost->SetString("header",
702 l10n_util::GetStringUTF16(
703 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
704 suggest_reload_repost->SetString("body",
705 l10n_util::GetStringUTF16(
706 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
707 // Add at the front, so it appears before other suggestions, in the case
708 // suggestions are being overridden by |params|.
709 suggestions->Insert(0, suggest_reload_repost);
713 // If not using the default suggestions, nothing else to do.
714 if (!use_default_suggestions)
715 return;
717 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
718 const std::string& show_saved_copy_value =
719 command_line->GetSwitchValueASCII(switches::kShowSavedCopy);
720 bool show_saved_copy_primary = (show_saved_copy_value ==
721 switches::kEnableShowSavedCopyPrimary);
722 bool show_saved_copy_secondary = (show_saved_copy_value ==
723 switches::kEnableShowSavedCopySecondary);
724 bool show_saved_copy_visible =
725 (stale_copy_in_cache && !is_post &&
726 (show_saved_copy_primary || show_saved_copy_secondary));
728 if (show_saved_copy_visible) {
729 base::DictionaryValue* show_saved_copy_button = new base::DictionaryValue;
730 show_saved_copy_button->SetString(
731 "msg", l10n_util::GetStringUTF16(
732 IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY));
733 show_saved_copy_button->SetString(
734 "title",
735 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY_HELP));
736 if (show_saved_copy_primary)
737 show_saved_copy_button->SetString("primary", "true");
738 error_strings->Set("showSavedCopyButton", show_saved_copy_button);
741 #if defined(OS_CHROMEOS)
742 error_strings->SetString(
743 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE));
744 #endif // defined(OS_CHROMEOS)
746 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
747 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue;
748 suggest_check_connection->SetString("header",
749 l10n_util::GetStringUTF16(
750 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
751 suggest_check_connection->SetString("body",
752 l10n_util::GetStringUTF16(
753 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
754 suggestions->Append(suggest_check_connection);
757 if (options.suggestions & SUGGEST_DNS_CONFIG) {
758 base::DictionaryValue* suggest_dns_config = new base::DictionaryValue;
759 suggest_dns_config->SetString("header",
760 l10n_util::GetStringUTF16(
761 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER));
762 suggest_dns_config->SetString("body",
763 l10n_util::GetStringUTF16(
764 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY));
765 suggestions->Append(suggest_dns_config);
767 base::DictionaryValue* suggest_network_prediction =
768 GetStandardMenuItemsText();
769 suggest_network_prediction->SetString("header",
770 l10n_util::GetStringUTF16(
771 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER));
772 suggest_network_prediction->SetString("body",
773 l10n_util::GetStringUTF16(
774 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY));
775 suggest_network_prediction->SetString(
776 "noNetworkPredictionTitle",
777 l10n_util::GetStringUTF16(
778 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION));
779 suggestions->Append(suggest_network_prediction);
782 if (options.suggestions & SUGGEST_FIREWALL_CONFIG) {
783 base::DictionaryValue* suggest_firewall_config = new base::DictionaryValue;
784 suggest_firewall_config->SetString("header",
785 l10n_util::GetStringUTF16(
786 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER));
787 suggest_firewall_config->SetString("body",
788 l10n_util::GetStringUTF16(
789 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY));
790 suggestions->Append(suggest_firewall_config);
793 if (options.suggestions & SUGGEST_PROXY_CONFIG) {
794 base::DictionaryValue* suggest_proxy_config = GetStandardMenuItemsText();
795 suggest_proxy_config->SetString("header",
796 l10n_util::GetStringUTF16(
797 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER));
798 suggest_proxy_config->SetString("body",
799 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY,
800 l10n_util::GetStringUTF16(
801 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM)));
802 suggest_proxy_config->SetString("proxyTitle",
803 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
805 suggestions->Append(suggest_proxy_config);
808 if (options.suggestions & SUGGEST_DISABLE_EXTENSION) {
809 base::DictionaryValue* suggest_disable_extension =
810 new base::DictionaryValue;
811 // There's only a header for this suggestion.
812 suggest_disable_extension->SetString("header",
813 l10n_util::GetStringUTF16(
814 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER));
815 suggestions->Append(suggest_disable_extension);
818 if (options.suggestions & SUGGEST_VIEW_POLICIES) {
819 base::DictionaryValue* suggest_view_policies = new base::DictionaryValue;
820 suggest_view_policies->SetString(
821 "header",
822 l10n_util::GetStringUTF16(
823 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER));
824 suggest_view_policies->SetString(
825 "body",
826 l10n_util::GetStringUTF16(
827 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY));
828 suggestions->Append(suggest_view_policies);
831 if (options.suggestions & SUGGEST_CONTACT_ADMINISTRATOR) {
832 base::DictionaryValue* suggest_contant_administrator =
833 new base::DictionaryValue;
834 suggest_contant_administrator->SetString(
835 "body",
836 l10n_util::GetStringUTF16(
837 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY));
838 suggestions->Append(suggest_contant_administrator);
841 if (options.suggestions & SUGGEST_LEARNMORE) {
842 GURL learn_more_url;
843 switch (options.error_code) {
844 case net::ERR_TOO_MANY_REDIRECTS:
845 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
846 break;
847 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
848 learn_more_url = GURL(kWeakDHKeyLearnMoreUrl);
849 break;
850 default:
851 break;
854 if (learn_more_url.is_valid()) {
855 // Add the language parameter to the URL.
856 std::string query = learn_more_url.query() + "&hl=" + locale;
857 GURL::Replacements repl;
858 repl.SetQueryStr(query);
859 learn_more_url = learn_more_url.ReplaceComponents(repl);
861 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue;
862 // There's only a body for this suggestion.
863 suggest_learn_more->SetString("body",
864 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
865 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
866 suggestions->Append(suggest_learn_more);
871 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error,
872 bool is_post) {
873 const LocalizedErrorMap* error_map =
874 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
875 if (error_map)
876 return l10n_util::GetStringUTF16(error_map->details_resource_id);
877 else
878 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
881 bool LocalizedError::HasStrings(const std::string& error_domain,
882 int error_code) {
883 // Whether or not the there are strings for an error does not depend on
884 // whether or not the page was be generated by a POST, so just claim it was
885 // not.
886 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
889 #if defined(ENABLE_EXTENSIONS)
890 void LocalizedError::GetAppErrorStrings(
891 const GURL& display_url,
892 const extensions::Extension* app,
893 const std::string& locale,
894 base::DictionaryValue* error_strings) {
895 DCHECK(app);
897 webui::SetLoadTimeDataDefaults(locale, error_strings);
899 base::string16 failed_url(base::ASCIIToUTF16(display_url.spec()));
900 // URLs are always LTR.
901 if (base::i18n::IsRTL())
902 base::i18n::WrapStringWithLTRFormatting(&failed_url);
903 error_strings->SetString(
904 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
905 failed_url.c_str()));
907 error_strings->SetString("title", app->name());
908 error_strings->SetString(
909 "icon",
910 extensions::IconsInfo::GetIconURL(
911 app,
912 extension_misc::EXTENSION_ICON_GIGANTOR,
913 ExtensionIconSet::MATCH_SMALLER).spec());
914 error_strings->SetString("name", app->name());
915 error_strings->SetString(
916 "msg",
917 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING));
919 #if defined(OS_CHROMEOS)
920 GURL learn_more_url(kAppWarningLearnMoreUrl);
921 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue();
922 suggest_learn_more->SetString("msg",
923 l10n_util::GetStringUTF16(
924 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
925 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
926 error_strings->Set("suggestionsLearnMore", suggest_learn_more);
927 #endif // defined(OS_CHROMEOS)
929 #endif