Port Android relocation packer to chromium build
[chromium-blink-merge.git] / chrome / common / localized_error.cc
blobcd7e5ef083a570efee1aa42baa4e1c52326de6a9
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_ADDRESS_UNREACHABLE,
141 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
142 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
143 IDS_ERRORPAGES_SUMMARY_ADDRESS_UNREACHABLE,
144 IDS_ERRORPAGES_DETAILS_ADDRESS_UNREACHABLE,
145 SUGGEST_RELOAD | SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
147 {net::ERR_NETWORK_ACCESS_DENIED,
148 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
149 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
150 IDS_ERRORPAGES_SUMMARY_NETWORK_ACCESS_DENIED,
151 IDS_ERRORPAGES_DETAILS_NETWORK_ACCESS_DENIED,
152 SUGGEST_FIREWALL_CONFIG,
154 {net::ERR_PROXY_CONNECTION_FAILED,
155 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
156 IDS_ERRORPAGES_HEADING_PROXY_CONNECTION_FAILED,
157 IDS_ERRORPAGES_SUMMARY_PROXY_CONNECTION_FAILED,
158 IDS_ERRORPAGES_DETAILS_PROXY_CONNECTION_FAILED,
159 SUGGEST_PROXY_CONFIG,
161 {net::ERR_INTERNET_DISCONNECTED,
162 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
163 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
164 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
165 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
166 SUGGEST_NONE,
168 {net::ERR_FILE_NOT_FOUND,
169 IDS_ERRORPAGES_TITLE_NOT_FOUND,
170 IDS_ERRORPAGES_HEADING_NOT_FOUND,
171 IDS_ERRORPAGES_SUMMARY_NOT_FOUND,
172 IDS_ERRORPAGES_DETAILS_FILE_NOT_FOUND,
173 SUGGEST_NONE,
175 {net::ERR_CACHE_MISS,
176 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
177 IDS_ERRORPAGES_HEADING_CACHE_MISS,
178 IDS_ERRORPAGES_SUMMARY_CACHE_MISS,
179 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
180 SUGGEST_RELOAD,
182 {net::ERR_CACHE_READ_FAILURE,
183 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
184 IDS_ERRORPAGES_HEADING_CACHE_READ_FAILURE,
185 IDS_ERRORPAGES_SUMMARY_CACHE_READ_FAILURE,
186 IDS_ERRORPAGES_DETAILS_CACHE_READ_FAILURE,
187 SUGGEST_RELOAD,
189 {net::ERR_NETWORK_IO_SUSPENDED,
190 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
191 IDS_ERRORPAGES_HEADING_NETWORK_IO_SUSPENDED,
192 IDS_ERRORPAGES_SUMMARY_NETWORK_IO_SUSPENDED,
193 IDS_ERRORPAGES_DETAILS_NETWORK_IO_SUSPENDED,
194 SUGGEST_RELOAD,
196 {net::ERR_TOO_MANY_REDIRECTS,
197 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
198 IDS_ERRORPAGES_HEADING_TOO_MANY_REDIRECTS,
199 IDS_ERRORPAGES_SUMMARY_TOO_MANY_REDIRECTS,
200 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS,
201 SUGGEST_RELOAD | SUGGEST_LEARNMORE,
203 {net::ERR_EMPTY_RESPONSE,
204 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
205 IDS_ERRORPAGES_HEADING_EMPTY_RESPONSE,
206 IDS_ERRORPAGES_SUMMARY_EMPTY_RESPONSE,
207 IDS_ERRORPAGES_DETAILS_EMPTY_RESPONSE,
208 SUGGEST_RELOAD,
210 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
211 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
212 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
213 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
214 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
215 SUGGEST_NONE,
217 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
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_DISPOSITION,
222 SUGGEST_NONE,
224 {net::ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION,
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_LOCATION,
229 SUGGEST_NONE,
231 {net::ERR_CONTENT_LENGTH_MISMATCH,
232 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
233 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
234 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
235 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
236 SUGGEST_RELOAD,
238 {net::ERR_INCOMPLETE_CHUNKED_ENCODING,
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_SSL_PROTOCOL_ERROR,
246 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
247 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
248 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
249 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
250 SUGGEST_NONE,
252 {net::ERR_SSL_UNSAFE_NEGOTIATION,
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_UNSAFE_NEGOTIATION,
257 SUGGEST_NONE,
259 {net::ERR_BAD_SSL_CLIENT_AUTH_CERT,
260 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
261 IDS_ERRORPAGES_HEADING_BAD_SSL_CLIENT_AUTH_CERT,
262 IDS_ERRORPAGES_SUMMARY_BAD_SSL_CLIENT_AUTH_CERT,
263 IDS_ERRORPAGES_DETAILS_BAD_SSL_CLIENT_AUTH_CERT,
264 SUGGEST_NONE,
266 {net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY,
267 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
268 IDS_ERRORPAGES_HEADING_WEAK_SERVER_EPHEMERAL_DH_KEY,
269 IDS_ERRORPAGES_SUMMARY_WEAK_SERVER_EPHEMERAL_DH_KEY,
270 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
271 SUGGEST_LEARNMORE,
273 {net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN,
274 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
275 IDS_ERRORPAGES_HEADING_PINNING_FAILURE,
276 IDS_ERRORPAGES_SUMMARY_PINNING_FAILURE,
277 IDS_ERRORPAGES_DETAILS_PINNING_FAILURE,
278 SUGGEST_NONE,
280 {net::ERR_TEMPORARILY_THROTTLED,
281 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
282 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
283 IDS_ERRORPAGES_SUMMARY_TEMPORARILY_THROTTLED,
284 IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED,
285 SUGGEST_NONE,
287 {net::ERR_BLOCKED_BY_CLIENT,
288 IDS_ERRORPAGES_TITLE_BLOCKED,
289 IDS_ERRORPAGES_HEADING_BLOCKED,
290 IDS_ERRORPAGES_SUMMARY_BLOCKED,
291 IDS_ERRORPAGES_DETAILS_BLOCKED,
292 SUGGEST_RELOAD | SUGGEST_DISABLE_EXTENSION,
294 {net::ERR_NETWORK_CHANGED,
295 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
296 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
297 IDS_ERRORPAGES_SUMMARY_NETWORK_CHANGED,
298 IDS_ERRORPAGES_DETAILS_NETWORK_CHANGED,
299 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION,
301 {net::ERR_BLOCKED_BY_ADMINISTRATOR,
302 IDS_ERRORPAGES_TITLE_BLOCKED,
303 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
304 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR,
305 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR,
306 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR,
308 {net::ERR_BLOCKED_ENROLLMENT_CHECK_PENDING,
309 IDS_ERRORPAGES_TITLE_BLOCKED,
310 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
311 IDS_ERRORPAGES_SUMMARY_BLOCKED_ENROLLMENT_CHECK_PENDING,
312 IDS_ERRORPAGES_DETAILS_BLOCKED_ENROLLMENT_CHECK_PENDING,
313 SUGGEST_CHECK_CONNECTION,
315 {net::ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
316 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
317 IDS_ERRORPAGES_HEADING_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
318 IDS_ERRORPAGES_SUMMARY_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
319 IDS_ERRORPAGES_DETAILS_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
320 SUGGEST_NONE,
322 {net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH,
323 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
324 IDS_ERRORPAGES_HEADING_SSL_VERSION_OR_CIPHER_MISMATCH,
325 IDS_ERRORPAGES_SUMMARY_SSL_VERSION_OR_CIPHER_MISMATCH,
326 IDS_ERRORPAGES_DETAILS_SSL_VERSION_OR_CIPHER_MISMATCH,
327 SUGGEST_NONE,
331 // Special error page to be used in the case of navigating back to a page
332 // generated by a POST. LocalizedError::HasStrings expects this net error code
333 // to also appear in the array above.
334 const LocalizedErrorMap repost_error = {
335 net::ERR_CACHE_MISS,
336 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
337 IDS_HTTP_POST_WARNING_TITLE,
338 IDS_ERRORPAGES_HTTP_POST_WARNING,
339 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
340 SUGGEST_RELOAD,
343 const LocalizedErrorMap http_error_options[] = {
344 {403,
345 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
346 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
347 IDS_ERRORPAGES_SUMMARY_FORBIDDEN,
348 IDS_ERRORPAGES_DETAILS_FORBIDDEN,
349 SUGGEST_NONE,
351 {410,
352 IDS_ERRORPAGES_TITLE_NOT_FOUND,
353 IDS_ERRORPAGES_HEADING_NOT_FOUND,
354 IDS_ERRORPAGES_SUMMARY_GONE,
355 IDS_ERRORPAGES_DETAILS_GONE,
356 SUGGEST_NONE,
359 {500,
360 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
361 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
362 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR,
363 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR,
364 SUGGEST_RELOAD,
366 {501,
367 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
368 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
369 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
370 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED,
371 SUGGEST_NONE,
373 {502,
374 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
375 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
376 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY,
377 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY,
378 SUGGEST_RELOAD,
380 {503,
381 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
382 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
383 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE,
384 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE,
385 SUGGEST_RELOAD,
387 {504,
388 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
389 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
390 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT,
391 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT,
392 SUGGEST_RELOAD,
394 {505,
395 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
396 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
397 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
398 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED,
399 SUGGEST_NONE,
403 const LocalizedErrorMap dns_probe_error_options[] = {
404 {chrome_common_net::DNS_PROBE_POSSIBLE,
405 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
406 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
407 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
408 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
409 SUGGEST_RELOAD,
412 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
413 // error, which might be one of several DNS-related errors.
415 {chrome_common_net::DNS_PROBE_STARTED,
416 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
417 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
418 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
419 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
420 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
421 SUGGEST_RELOAD,
424 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
425 // original error, which might be one of several DNS-related errors.
427 {chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
428 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
429 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
430 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
431 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
432 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG,
434 {chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG,
435 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
436 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
437 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
438 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
439 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG,
441 {chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN,
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,
450 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps,
451 size_t num_maps,
452 int error_code) {
453 for (size_t i = 0; i < num_maps; ++i) {
454 if (maps[i].error_code == error_code)
455 return &maps[i];
457 return NULL;
460 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain,
461 int error_code, bool is_post) {
462 if (error_domain == net::kErrorDomain) {
463 // Display a different page in the special case of navigating through the
464 // history to an uncached page created by a POST.
465 if (is_post && error_code == net::ERR_CACHE_MISS)
466 return &repost_error;
467 return FindErrorMapInArray(net_error_options,
468 arraysize(net_error_options),
469 error_code);
470 } else if (error_domain == LocalizedError::kHttpErrorDomain) {
471 return FindErrorMapInArray(http_error_options,
472 arraysize(http_error_options),
473 error_code);
474 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
475 const LocalizedErrorMap* map =
476 FindErrorMapInArray(dns_probe_error_options,
477 arraysize(dns_probe_error_options),
478 error_code);
479 DCHECK(map);
480 return map;
481 } else {
482 NOTREACHED();
483 return NULL;
487 // Returns a dictionary containing the strings for the settings menu under the
488 // wrench, and the advanced settings button.
489 base::DictionaryValue* GetStandardMenuItemsText() {
490 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue();
491 standard_menu_items_text->SetString("settingsTitle",
492 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
493 standard_menu_items_text->SetString("advancedTitle",
494 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS));
495 return standard_menu_items_text;
498 // Gets the icon class for a given |error_domain| and |error_code|.
499 const char* GetIconClassForError(const std::string& error_domain,
500 int error_code) {
501 if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
502 error_domain == net::kErrorDomain) ||
503 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET &&
504 error_domain == chrome_common_net::kDnsProbeErrorDomain))
505 return "icon-offline";
507 return "icon-generic";
510 } // namespace
512 const char LocalizedError::kHttpErrorDomain[] = "http";
514 void LocalizedError::GetStrings(int error_code,
515 const std::string& error_domain,
516 const GURL& failed_url,
517 bool is_post,
518 bool stale_copy_in_cache,
519 const std::string& locale,
520 const std::string& accept_languages,
521 scoped_ptr<error_page::ErrorPageParams> params,
522 base::DictionaryValue* error_strings) {
523 webui::SetLoadTimeDataDefaults(locale, error_strings);
525 // Grab the strings and settings that depend on the error type. Init
526 // options with default values.
527 LocalizedErrorMap options = {
529 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
530 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
531 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
532 kErrorPagesNoDetails,
533 SUGGEST_NONE,
536 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
537 is_post);
538 if (error_map)
539 options = *error_map;
541 // If we got "access denied" but the url was a file URL, then we say it was a
542 // file instead of just using the "not available" default message. Just adding
543 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
544 // generated by some OSs when the operation doesn't involve a file URL.
545 if (error_domain == net::kErrorDomain &&
546 error_code == net::ERR_ACCESS_DENIED &&
547 failed_url.scheme() == "file") {
548 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED;
549 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED;
550 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED;
551 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED;
552 options.suggestions = SUGGEST_NONE;
555 base::string16 failed_url_string(net::FormatUrl(
556 failed_url, accept_languages, net::kFormatUrlOmitNothing,
557 net::UnescapeRule::NORMAL, NULL, NULL, NULL));
558 // URLs are always LTR.
559 if (base::i18n::IsRTL())
560 base::i18n::WrapStringWithLTRFormatting(&failed_url_string);
561 error_strings->SetString("title",
562 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string));
563 error_strings->SetString("heading",
564 l10n_util::GetStringUTF16(options.heading_resource_id));
566 std::string icon_class = GetIconClassForError(error_domain, error_code);
567 error_strings->SetString("iconClass", icon_class);
569 base::DictionaryValue* summary = new base::DictionaryValue;
571 // For offline show a summary message underneath the heading.
572 if (error_code == net::ERR_INTERNET_DISCONNECTED ||
573 error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET) {
574 error_strings->SetString("primaryParagraph",
575 l10n_util::GetStringUTF16(options.summary_resource_id));
577 #if defined(OS_CHROMEOS)
578 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
580 // Check if easter egg should be disabled.
581 if (command_line->HasSwitch(switches::kDisableDinosaurEasterEgg)) {
582 // The prescence of this string disables the easter egg. Acts as a flag.
583 error_strings->SetString("disabledEasterEgg",
584 l10n_util::GetStringUTF16(IDS_ERRORPAGE_FUN_DISABLED));
586 #endif
588 } else {
589 // Set summary message in the details.
590 summary->SetString("msg",
591 l10n_util::GetStringUTF16(options.summary_resource_id));
593 summary->SetString("failedUrl", failed_url_string);
594 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(),
595 accept_languages));
596 summary->SetString("productName",
597 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
599 error_strings->SetString(
600 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS));
601 error_strings->SetString(
602 "hideDetails", l10n_util::GetStringUTF16(
603 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS));
604 error_strings->Set("summary", summary);
606 if (options.details_resource_id != kErrorPagesNoDetails) {
607 error_strings->SetString(
608 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id));
611 base::string16 error_string;
612 if (error_domain == net::kErrorDomain) {
613 // Non-internationalized error string, for debugging Chrome itself.
614 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
615 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
616 std::string ascii_error_string =
617 chrome_common_net::DnsProbeStatusToString(error_code);
618 error_string = base::ASCIIToUTF16(ascii_error_string);
619 } else {
620 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
621 error_string = base::IntToString16(error_code);
623 error_strings->SetString("errorCode",
624 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string));
626 // Platform specific information for diagnosing network issues on OSX and
627 // Windows.
628 #if defined(OS_MACOSX) || defined(OS_WIN)
629 if (error_domain == net::kErrorDomain &&
630 error_code == net::ERR_INTERNET_DISCONNECTED) {
631 int platform_string_id =
632 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM;
633 #if defined(OS_WIN)
634 // Different versions of Windows have different instructions.
635 base::win::Version windows_version = base::win::GetVersion();
636 if (windows_version < base::win::VERSION_VISTA) {
637 // XP, XP64, and Server 2003.
638 platform_string_id =
639 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP;
640 } else if (windows_version == base::win::VERSION_VISTA) {
641 // Vista
642 platform_string_id =
643 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA;
645 #endif // defined(OS_WIN)
646 // Platform dependent portion of the summary section.
647 summary->SetString("msg",
648 l10n_util::GetStringFUTF16(
649 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE,
650 l10n_util::GetStringUTF16(platform_string_id)));
652 #endif // defined(OS_MACOSX) || defined(OS_WIN)
654 // If no parameters were provided, use the defaults.
655 if (!params) {
656 params.reset(new error_page::ErrorPageParams());
657 params->suggest_reload = !!(options.suggestions & SUGGEST_RELOAD);
660 base::ListValue* suggestions = NULL;
661 bool use_default_suggestions = true;
662 if (!params->override_suggestions) {
663 suggestions = new base::ListValue();
664 } else {
665 suggestions = params->override_suggestions.release();
666 use_default_suggestions = false;
669 error_strings->Set("suggestions", suggestions);
671 if (params->search_url.is_valid()) {
672 error_strings->SetString("searchHeader",
673 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH));
674 error_strings->SetString("searchUrl", params->search_url.spec());
675 error_strings->SetString("searchTerms", params->search_terms);
676 error_strings->SetInteger("searchTrackingId", params->search_tracking_id);
679 // Add the reload suggestion, if needed.
680 if (params->suggest_reload) {
681 if (!is_post) {
682 base::DictionaryValue* reload_button = new base::DictionaryValue;
683 reload_button->SetString(
684 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
685 reload_button->SetString("reloadUrl", failed_url.spec());
686 error_strings->Set("reloadButton", reload_button);
687 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id);
688 } else {
689 // If the page was created by a post, it can't be reloaded in the same
690 // way, so just add a suggestion instead.
691 // TODO(mmenke): Make the reload button bring up the repost confirmation
692 // dialog for pages resulting from posts.
693 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue;
694 suggest_reload_repost->SetString("header",
695 l10n_util::GetStringUTF16(
696 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
697 suggest_reload_repost->SetString("body",
698 l10n_util::GetStringUTF16(
699 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
700 // Add at the front, so it appears before other suggestions, in the case
701 // suggestions are being overridden by |params|.
702 suggestions->Insert(0, suggest_reload_repost);
706 // If not using the default suggestions, nothing else to do.
707 if (!use_default_suggestions)
708 return;
710 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
711 const std::string& show_saved_copy_value =
712 command_line->GetSwitchValueASCII(switches::kShowSavedCopy);
713 bool show_saved_copy_primary = (show_saved_copy_value ==
714 switches::kEnableShowSavedCopyPrimary);
715 bool show_saved_copy_secondary = (show_saved_copy_value ==
716 switches::kEnableShowSavedCopySecondary);
717 bool show_saved_copy_visible =
718 (stale_copy_in_cache && !is_post &&
719 (show_saved_copy_primary || show_saved_copy_secondary));
721 if (show_saved_copy_visible) {
722 base::DictionaryValue* show_saved_copy_button = new base::DictionaryValue;
723 show_saved_copy_button->SetString(
724 "msg", l10n_util::GetStringUTF16(
725 IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY));
726 show_saved_copy_button->SetString(
727 "title",
728 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY_HELP));
729 if (show_saved_copy_primary)
730 show_saved_copy_button->SetString("primary", "true");
731 error_strings->Set("showSavedCopyButton", show_saved_copy_button);
734 #if defined(OS_CHROMEOS)
735 error_strings->SetString(
736 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE));
737 #endif // defined(OS_CHROMEOS)
739 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
740 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue;
741 suggest_check_connection->SetString("header",
742 l10n_util::GetStringUTF16(
743 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
744 suggest_check_connection->SetString("body",
745 l10n_util::GetStringUTF16(
746 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
747 suggestions->Append(suggest_check_connection);
750 if (options.suggestions & SUGGEST_DNS_CONFIG) {
751 base::DictionaryValue* suggest_dns_config = new base::DictionaryValue;
752 suggest_dns_config->SetString("header",
753 l10n_util::GetStringUTF16(
754 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER));
755 suggest_dns_config->SetString("body",
756 l10n_util::GetStringUTF16(
757 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY));
758 suggestions->Append(suggest_dns_config);
760 base::DictionaryValue* suggest_network_prediction =
761 GetStandardMenuItemsText();
762 suggest_network_prediction->SetString("header",
763 l10n_util::GetStringUTF16(
764 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER));
765 suggest_network_prediction->SetString("body",
766 l10n_util::GetStringUTF16(
767 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY));
768 suggest_network_prediction->SetString(
769 "noNetworkPredictionTitle",
770 l10n_util::GetStringUTF16(
771 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION));
772 suggestions->Append(suggest_network_prediction);
775 if (options.suggestions & SUGGEST_FIREWALL_CONFIG) {
776 base::DictionaryValue* suggest_firewall_config = new base::DictionaryValue;
777 suggest_firewall_config->SetString("header",
778 l10n_util::GetStringUTF16(
779 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER));
780 suggest_firewall_config->SetString("body",
781 l10n_util::GetStringUTF16(
782 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY));
783 suggestions->Append(suggest_firewall_config);
786 if (options.suggestions & SUGGEST_PROXY_CONFIG) {
787 base::DictionaryValue* suggest_proxy_config = GetStandardMenuItemsText();
788 suggest_proxy_config->SetString("header",
789 l10n_util::GetStringUTF16(
790 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER));
791 suggest_proxy_config->SetString("body",
792 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY,
793 l10n_util::GetStringUTF16(
794 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM)));
795 suggest_proxy_config->SetString("proxyTitle",
796 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
798 suggestions->Append(suggest_proxy_config);
801 if (options.suggestions & SUGGEST_DISABLE_EXTENSION) {
802 base::DictionaryValue* suggest_disable_extension =
803 new base::DictionaryValue;
804 // There's only a header for this suggestion.
805 suggest_disable_extension->SetString("header",
806 l10n_util::GetStringUTF16(
807 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER));
808 suggestions->Append(suggest_disable_extension);
811 if (options.suggestions & SUGGEST_VIEW_POLICIES) {
812 base::DictionaryValue* suggest_view_policies = new base::DictionaryValue;
813 suggest_view_policies->SetString(
814 "header",
815 l10n_util::GetStringUTF16(
816 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER));
817 suggest_view_policies->SetString(
818 "body",
819 l10n_util::GetStringUTF16(
820 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY));
821 suggestions->Append(suggest_view_policies);
824 if (options.suggestions & SUGGEST_CONTACT_ADMINISTRATOR) {
825 base::DictionaryValue* suggest_contant_administrator =
826 new base::DictionaryValue;
827 suggest_contant_administrator->SetString(
828 "body",
829 l10n_util::GetStringUTF16(
830 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY));
831 suggestions->Append(suggest_contant_administrator);
834 if (options.suggestions & SUGGEST_LEARNMORE) {
835 GURL learn_more_url;
836 switch (options.error_code) {
837 case net::ERR_TOO_MANY_REDIRECTS:
838 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
839 break;
840 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
841 learn_more_url = GURL(kWeakDHKeyLearnMoreUrl);
842 break;
843 default:
844 break;
847 if (learn_more_url.is_valid()) {
848 // Add the language parameter to the URL.
849 std::string query = learn_more_url.query() + "&hl=" + locale;
850 GURL::Replacements repl;
851 repl.SetQueryStr(query);
852 learn_more_url = learn_more_url.ReplaceComponents(repl);
854 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue;
855 // There's only a body for this suggestion.
856 suggest_learn_more->SetString("body",
857 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
858 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
859 suggestions->Append(suggest_learn_more);
864 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error,
865 bool is_post) {
866 const LocalizedErrorMap* error_map =
867 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
868 if (error_map)
869 return l10n_util::GetStringUTF16(error_map->details_resource_id);
870 else
871 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
874 bool LocalizedError::HasStrings(const std::string& error_domain,
875 int error_code) {
876 // Whether or not the there are strings for an error does not depend on
877 // whether or not the page was be generated by a POST, so just claim it was
878 // not.
879 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
882 #if defined(ENABLE_EXTENSIONS)
883 void LocalizedError::GetAppErrorStrings(
884 const GURL& display_url,
885 const extensions::Extension* app,
886 const std::string& locale,
887 base::DictionaryValue* error_strings) {
888 DCHECK(app);
890 webui::SetLoadTimeDataDefaults(locale, error_strings);
892 base::string16 failed_url(base::ASCIIToUTF16(display_url.spec()));
893 // URLs are always LTR.
894 if (base::i18n::IsRTL())
895 base::i18n::WrapStringWithLTRFormatting(&failed_url);
896 error_strings->SetString(
897 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
898 failed_url.c_str()));
900 error_strings->SetString("title", app->name());
901 error_strings->SetString(
902 "icon",
903 extensions::IconsInfo::GetIconURL(
904 app,
905 extension_misc::EXTENSION_ICON_GIGANTOR,
906 ExtensionIconSet::MATCH_SMALLER).spec());
907 error_strings->SetString("name", app->name());
908 error_strings->SetString(
909 "msg",
910 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING));
912 #if defined(OS_CHROMEOS)
913 GURL learn_more_url(kAppWarningLearnMoreUrl);
914 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue();
915 suggest_learn_more->SetString("msg",
916 l10n_util::GetStringUTF16(
917 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
918 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
919 error_strings->Set("suggestionsLearnMore", suggest_learn_more);
920 #endif // defined(OS_CHROMEOS)
922 #endif