| Index: trunk/src/chrome/renderer/net/net_error_helper.cc
|
| ===================================================================
|
| --- trunk/src/chrome/renderer/net/net_error_helper.cc (revision 263955)
|
| +++ trunk/src/chrome/renderer/net/net_error_helper.cc (working copy)
|
| @@ -7,6 +7,7 @@
|
| #include <string>
|
|
|
| #include "base/command_line.h"
|
| +#include "base/i18n/rtl.h"
|
| #include "base/json/json_writer.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| @@ -48,9 +49,9 @@
|
|
|
| namespace {
|
|
|
| -// Number of seconds to wait for the alternate error page server. If it takes
|
| -// too long, just use the local error page.
|
| -static const int kAlterErrorPageFetchTimeoutSec = 3000;
|
| +// Number of seconds to wait for the navigation correction service to return
|
| +// suggestions. If it takes too long, just use the local error page.
|
| +static const int kNavigationCorrectionFetchTimeoutSec = 3;
|
|
|
| NetErrorHelperCore::PageType GetLoadingPageType(const blink::WebFrame* frame) {
|
| GURL url = frame->provisionalDataSource()->request().url();
|
| @@ -65,6 +66,18 @@
|
| return NetErrorHelperCore::SUB_FRAME;
|
| }
|
|
|
| +// Copied from localized_error.cc.
|
| +// TODO(mmenke): Share code?
|
| +bool LocaleIsRTL() {
|
| +#if defined(TOOLKIT_GTK)
|
| + // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within
|
| + // the renderer sandbox.
|
| + return base::i18n::ICUIsRTL();
|
| +#else
|
| + return base::i18n::IsRTL();
|
| +#endif
|
| +}
|
| +
|
| } // namespace
|
|
|
| NetErrorHelper::NetErrorHelper(RenderFrame* render_view)
|
| @@ -106,7 +119,8 @@
|
|
|
| IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message)
|
| IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo)
|
| - IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL);
|
| + IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo,
|
| + OnSetNavigationCorrectionInfo);
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP()
|
|
|
| @@ -130,9 +144,11 @@
|
| return core_.ShouldSuppressErrorPage(GetFrameType(frame), url);
|
| }
|
|
|
| -void NetErrorHelper::GenerateLocalizedErrorPage(const blink::WebURLError& error,
|
| - bool is_failed_post,
|
| - std::string* error_html) const {
|
| +void NetErrorHelper::GenerateLocalizedErrorPage(
|
| + const blink::WebURLError& error,
|
| + bool is_failed_post,
|
| + scoped_ptr<LocalizedError::ErrorPageParams> params,
|
| + std::string* error_html) const {
|
| error_html->clear();
|
|
|
| int resource_id = IDR_NET_ERROR_HTML;
|
| @@ -148,7 +164,7 @@
|
| RenderThread::Get()->GetLocale(),
|
| render_frame()->GetRenderView()->
|
| GetAcceptLanguages(),
|
| - &error_strings);
|
| + params.Pass(), &error_strings);
|
| // "t" is the id of the template's root node.
|
| *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t");
|
| }
|
| @@ -178,6 +194,7 @@
|
| RenderThread::Get()->GetLocale(),
|
| render_frame()->GetRenderView()->
|
| GetAcceptLanguages(),
|
| + scoped_ptr<LocalizedError::ErrorPageParams>(),
|
| &error_strings);
|
|
|
| std::string json;
|
| @@ -194,27 +211,32 @@
|
| render_frame()->ExecuteJavaScript(js16);
|
| }
|
|
|
| -void NetErrorHelper::FetchErrorPage(const GURL& url) {
|
| - DCHECK(!alt_error_page_fetcher_.get());
|
| +void NetErrorHelper::FetchNavigationCorrections(
|
| + const GURL& navigation_correction_url,
|
| + const std::string& navigation_correction_request_body) {
|
| + DCHECK(!correction_fetcher_.get());
|
|
|
| blink::WebView* web_view = render_frame()->GetRenderView()->GetWebView();
|
| if (!web_view)
|
| return;
|
| blink::WebFrame* frame = web_view->mainFrame();
|
|
|
| - alt_error_page_fetcher_.reset(content::ResourceFetcher::Create(url));
|
| -
|
| - alt_error_page_fetcher_->Start(
|
| + correction_fetcher_.reset(
|
| + content::ResourceFetcher::Create(navigation_correction_url));
|
| + correction_fetcher_->SetMethod("POST");
|
| + correction_fetcher_->SetBody(navigation_correction_request_body);
|
| + correction_fetcher_->SetHeader("Content-Type", "application/json");
|
| + correction_fetcher_->Start(
|
| frame, blink::WebURLRequest::TargetIsMainFrame,
|
| - base::Bind(&NetErrorHelper::OnAlternateErrorPageRetrieved,
|
| + base::Bind(&NetErrorHelper::OnNavigationCorrectionsFetched,
|
| base::Unretained(this)));
|
|
|
| - alt_error_page_fetcher_->SetTimeout(
|
| - base::TimeDelta::FromSeconds(kAlterErrorPageFetchTimeoutSec));
|
| + correction_fetcher_->SetTimeout(
|
| + base::TimeDelta::FromSeconds(kNavigationCorrectionFetchTimeoutSec));
|
| }
|
|
|
| -void NetErrorHelper::CancelFetchErrorPage() {
|
| - alt_error_page_fetcher_.reset();
|
| +void NetErrorHelper::CancelFetchNavigationCorrections() {
|
| + correction_fetcher_.reset();
|
| }
|
|
|
| void NetErrorHelper::ReloadPage() {
|
| @@ -229,20 +251,30 @@
|
| core_.OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num));
|
| }
|
|
|
| -void NetErrorHelper::OnSetAltErrorPageURL(const GURL& alt_error_page_url) {
|
| - core_.set_alt_error_page_url(alt_error_page_url);
|
| +void NetErrorHelper::OnSetNavigationCorrectionInfo(
|
| + const GURL& navigation_correction_url,
|
| + const std::string& language,
|
| + const std::string& country_code,
|
| + const std::string& api_key,
|
| + const GURL& search_url) {
|
| + core_.OnSetNavigationCorrectionInfo(navigation_correction_url, language,
|
| + country_code, api_key, search_url);
|
| }
|
|
|
| -void NetErrorHelper::OnAlternateErrorPageRetrieved(
|
| +void NetErrorHelper::OnNavigationCorrectionsFetched(
|
| const blink::WebURLResponse& response,
|
| const std::string& data) {
|
| // The fetcher may only be deleted after |data| is passed to |core_|. Move
|
| // it to a temporary to prevent any potential re-entrancy issues.
|
| scoped_ptr<content::ResourceFetcher> fetcher(
|
| - alt_error_page_fetcher_.release());
|
| + correction_fetcher_.release());
|
| if (!response.isNull() && response.httpStatusCode() == 200) {
|
| - core_.OnAlternateErrorPageFetched(data);
|
| + core_.OnNavigationCorrectionsFetched(
|
| + data, render_frame()->GetRenderView()->GetAcceptLanguages(),
|
| + LocaleIsRTL());
|
| } else {
|
| - core_.OnAlternateErrorPageFetched("");
|
| + core_.OnNavigationCorrectionsFetched(
|
| + "", render_frame()->GetRenderView()->GetAcceptLanguages(),
|
| + LocaleIsRTL());
|
| }
|
| }
|
|
|