OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/chrome_content_renderer_client.h" | 5 #include "chrome/renderer/chrome_content_renderer_client.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 // Use an internal error page, if we have one for the status code. | 525 // Use an internal error page, if we have one for the status code. |
526 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, | 526 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, |
527 http_status_code)) { | 527 http_status_code)) { |
528 return false; | 528 return false; |
529 } | 529 } |
530 | 530 |
531 *error_domain = LocalizedError::kHttpErrorDomain; | 531 *error_domain = LocalizedError::kHttpErrorDomain; |
532 return true; | 532 return true; |
533 } | 533 } |
534 | 534 |
535 std::string ChromeContentRendererClient::GetNavigationErrorHtml( | 535 void ChromeContentRendererClient::GetNavigationErrorStrings( |
536 const WebURLRequest& failed_request, | 536 const WebKit::WebURLRequest& failed_request, |
537 const WebURLError& error) { | 537 const WebKit::WebURLError& error, |
538 GURL failed_url = error.unreachableURL; | 538 std::string* error_html, |
539 std::string html; | 539 string16* error_description) { |
| 540 const GURL failed_url = error.unreachableURL; |
540 const Extension* extension = NULL; | 541 const Extension* extension = NULL; |
| 542 const bool is_repost = |
| 543 error.reason == net::ERR_CACHE_MISS && |
| 544 error.domain == WebString::fromUTF8(net::kErrorDomain) && |
| 545 EqualsASCII(failed_request.httpMethod(), "POST"); |
541 | 546 |
542 // Use a local error page. | |
543 int resource_id; | |
544 DictionaryValue error_strings; | |
545 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) | 547 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) |
546 extension = extension_dispatcher_->extensions()->GetByURL(failed_url); | 548 extension = extension_dispatcher_->extensions()->GetByURL(failed_url); |
547 if (extension) { | |
548 LocalizedError::GetAppErrorStrings(error, failed_url, extension, | |
549 &error_strings); | |
550 | 549 |
551 // TODO(erikkay): Should we use a different template for different | 550 if (error_html) { |
552 // error messages? | 551 // Use a local error page. |
553 resource_id = IDR_ERROR_APP_HTML; | 552 int resource_id; |
554 } else { | 553 DictionaryValue error_strings; |
555 if (error.domain == WebString::fromUTF8(net::kErrorDomain) && | 554 if (extension) { |
556 error.reason == net::ERR_CACHE_MISS && | 555 LocalizedError::GetAppErrorStrings(error, failed_url, extension, |
557 EqualsASCII(failed_request.httpMethod(), "POST")) { | 556 &error_strings); |
558 LocalizedError::GetFormRepostStrings(failed_url, &error_strings); | 557 |
| 558 // TODO(erikkay): Should we use a different template for different |
| 559 // error messages? |
| 560 resource_id = IDR_ERROR_APP_HTML; |
559 } else { | 561 } else { |
560 LocalizedError::GetStrings(error, &error_strings); | 562 if (is_repost) { |
| 563 LocalizedError::GetFormRepostStrings(failed_url, &error_strings); |
| 564 } else { |
| 565 LocalizedError::GetStrings(error, &error_strings); |
| 566 } |
| 567 resource_id = IDR_NET_ERROR_HTML; |
561 } | 568 } |
562 resource_id = IDR_NET_ERROR_HTML; | 569 |
| 570 const base::StringPiece template_html( |
| 571 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 572 if (template_html.empty()) { |
| 573 NOTREACHED() << "unable to load template. ID: " << resource_id; |
| 574 } else { |
| 575 // "t" is the id of the templates root node. |
| 576 *error_html = jstemplate_builder::GetTemplatesHtml( |
| 577 template_html, &error_strings, "t"); |
| 578 } |
563 } | 579 } |
564 | 580 |
565 const base::StringPiece template_html( | 581 if (error_description) { |
566 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 582 if (!extension && !is_repost) |
567 if (template_html.empty()) { | 583 *error_description = LocalizedError::GetErrorDetails(error); |
568 NOTREACHED() << "unable to load template. ID: " << resource_id; | |
569 } else { | |
570 // "t" is the id of the templates root node. | |
571 html = jstemplate_builder::GetTemplatesHtml( | |
572 template_html, &error_strings, "t"); | |
573 } | 584 } |
574 | |
575 return html; | |
576 } | 585 } |
577 | 586 |
578 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() { | 587 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() { |
579 return !extension_dispatcher_->is_extension_process(); | 588 return !extension_dispatcher_->is_extension_process(); |
580 } | 589 } |
581 | 590 |
582 bool ChromeContentRendererClient::AllowPopup(const GURL& creator) { | 591 bool ChromeContentRendererClient::AllowPopup(const GURL& creator) { |
583 // Extensions and apps always allowed to create unrequested popups. The second | 592 // Extensions and apps always allowed to create unrequested popups. The second |
584 // check is necessary to include content scripts. | 593 // check is necessary to include content scripts. |
585 return extension_dispatcher_->extensions()->GetByURL(creator) || | 594 return extension_dispatcher_->extensions()->GetByURL(creator) || |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 if (spellcheck_.get()) | 781 if (spellcheck_.get()) |
773 thread->RemoveObserver(spellcheck_.get()); | 782 thread->RemoveObserver(spellcheck_.get()); |
774 SpellCheck* new_spellcheck = new SpellCheck(); | 783 SpellCheck* new_spellcheck = new SpellCheck(); |
775 if (spellcheck_provider_) | 784 if (spellcheck_provider_) |
776 spellcheck_provider_->SetSpellCheck(new_spellcheck); | 785 spellcheck_provider_->SetSpellCheck(new_spellcheck); |
777 spellcheck_.reset(new_spellcheck); | 786 spellcheck_.reset(new_spellcheck); |
778 thread->AddObserver(new_spellcheck); | 787 thread->AddObserver(new_spellcheck); |
779 } | 788 } |
780 | 789 |
781 } // namespace chrome | 790 } // namespace chrome |
OLD | NEW |