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/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 WebURLError error; | 523 WebURLError error; |
524 error.unreachableURL = frame->document().url(); | 524 error.unreachableURL = frame->document().url(); |
525 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain); | 525 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain); |
526 error.reason = http_status_code; | 526 error.reason = http_status_code; |
527 | 527 |
528 render_view->LoadNavigationErrorPage( | 528 render_view->LoadNavigationErrorPage( |
529 frame, frame->dataSource()->request(), error, std::string(), true); | 529 frame, frame->dataSource()->request(), error, std::string(), true); |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
533 std::string ChromeContentRendererClient::GetNavigationErrorHtml( | 533 void ChromeContentRendererClient::GetNavigationErrorStrings( |
534 const WebURLRequest& failed_request, | 534 const WebKit::WebURLRequest& failed_request, |
535 const WebURLError& error) { | 535 const WebKit::WebURLError& error, |
536 GURL failed_url = error.unreachableURL; | 536 std::string* error_html, |
537 std::string html; | 537 string16* error_description) { |
538 const GURL failed_url = error.unreachableURL; | |
538 const Extension* extension = NULL; | 539 const Extension* extension = NULL; |
540 const bool is_repost = | |
541 error.reason == net::ERR_CACHE_MISS && | |
542 error.domain == WebString::fromUTF8(net::kErrorDomain) && | |
543 EqualsASCII(failed_request.httpMethod(), "POST"); | |
539 | 544 |
540 // Use a local error page. | |
541 int resource_id; | |
542 DictionaryValue error_strings; | |
543 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) | 545 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) |
544 extension = extension_dispatcher_->extensions()->GetByURL(failed_url); | 546 extension = extension_dispatcher_->extensions()->GetByURL(failed_url); |
545 if (extension) { | |
546 LocalizedError::GetAppErrorStrings(error, failed_url, extension, | |
547 &error_strings); | |
548 | 547 |
549 // TODO(erikkay): Should we use a different template for different | 548 if (error_html != NULL) { |
jam
2011/10/07 16:03:28
nit: here and below, convention is to drop the "!=
mkosiba (inactive)
2011/10/07 17:54:32
Done.
| |
550 // error messages? | 549 // Use a local error page. |
551 resource_id = IDR_ERROR_APP_HTML; | 550 int resource_id; |
552 } else { | 551 DictionaryValue error_strings; |
553 if (error.domain == WebString::fromUTF8(net::kErrorDomain) && | 552 if (extension) { |
554 error.reason == net::ERR_CACHE_MISS && | 553 LocalizedError::GetAppErrorStrings(error, failed_url, extension, |
555 EqualsASCII(failed_request.httpMethod(), "POST")) { | 554 &error_strings); |
556 LocalizedError::GetFormRepostStrings(failed_url, &error_strings); | 555 |
556 // TODO(erikkay): Should we use a different template for different | |
557 // error messages? | |
558 resource_id = IDR_ERROR_APP_HTML; | |
557 } else { | 559 } else { |
558 LocalizedError::GetStrings(error, &error_strings); | 560 if (is_repost) { |
561 LocalizedError::GetFormRepostStrings(failed_url, &error_strings); | |
562 } else { | |
563 LocalizedError::GetStrings(error, &error_strings); | |
564 } | |
565 resource_id = IDR_NET_ERROR_HTML; | |
559 } | 566 } |
560 resource_id = IDR_NET_ERROR_HTML; | 567 |
568 const base::StringPiece template_html( | |
569 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | |
570 if (template_html.empty()) { | |
571 NOTREACHED() << "unable to load template. ID: " << resource_id; | |
572 } else { | |
573 // "t" is the id of the templates root node. | |
574 *error_html = jstemplate_builder::GetTemplatesHtml( | |
575 template_html, &error_strings, "t"); | |
576 } | |
561 } | 577 } |
562 | 578 |
563 const base::StringPiece template_html( | 579 if (error_description != NULL) { |
564 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 580 if (!extension && !is_repost) |
565 if (template_html.empty()) { | 581 *error_description = LocalizedError::GetErrorDetails(error); |
566 NOTREACHED() << "unable to load template. ID: " << resource_id; | 582 else |
567 } else { | 583 *error_description = string16(); |
568 // "t" is the id of the templates root node. | |
569 html = jstemplate_builder::GetTemplatesHtml( | |
570 template_html, &error_strings, "t"); | |
571 } | 584 } |
572 | |
573 return html; | |
574 } | 585 } |
575 | 586 |
576 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() { | 587 bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() { |
577 return !extension_dispatcher_->is_extension_process(); | 588 return !extension_dispatcher_->is_extension_process(); |
578 } | 589 } |
579 | 590 |
580 bool ChromeContentRendererClient::AllowPopup(const GURL& creator) { | 591 bool ChromeContentRendererClient::AllowPopup(const GURL& creator) { |
581 // Extensions and apps always allowed to create unrequested popups. The second | 592 // Extensions and apps always allowed to create unrequested popups. The second |
582 // check is necessary to include content scripts. | 593 // check is necessary to include content scripts. |
583 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... | |
770 if (spellcheck_.get()) | 781 if (spellcheck_.get()) |
771 thread->RemoveObserver(spellcheck_.get()); | 782 thread->RemoveObserver(spellcheck_.get()); |
772 SpellCheck* new_spellcheck = new SpellCheck(); | 783 SpellCheck* new_spellcheck = new SpellCheck(); |
773 if (spellcheck_provider_) | 784 if (spellcheck_provider_) |
774 spellcheck_provider_->SetSpellCheck(new_spellcheck); | 785 spellcheck_provider_->SetSpellCheck(new_spellcheck); |
775 spellcheck_.reset(new_spellcheck); | 786 spellcheck_.reset(new_spellcheck); |
776 thread->AddObserver(new_spellcheck); | 787 thread->AddObserver(new_spellcheck); |
777 } | 788 } |
778 | 789 |
779 } // namespace chrome | 790 } // namespace chrome |
OLD | NEW |