Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2874)

Unified Diff: chrome/renderer/net/net_error_helper.cc

Issue 137623011: Switch to using the new Link Doctor API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove bonus line from a merge conflict Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/net/net_error_helper.h ('k') | chrome/renderer/net/net_error_helper_core.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/net/net_error_helper.cc
===================================================================
--- chrome/renderer/net/net_error_helper.cc (revision 253247)
+++ chrome/renderer/net/net_error_helper.cc (working copy)
@@ -6,11 +6,11 @@
#include <string>
+#include "base/i18n/rtl.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
-#include "chrome/common/localized_error.h"
#include "chrome/common/net/net_error_info.h"
#include "chrome/common/render_messages.h"
#include "content/public/common/content_client.h"
@@ -45,9 +45,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();
@@ -62,6 +62,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)
@@ -97,7 +109,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()
@@ -112,9 +125,11 @@
core_.GetErrorHTML(GetFrameType(frame), error, is_failed_post, error_html);
}
-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;
@@ -130,7 +145,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");
}
@@ -156,6 +171,7 @@
RenderThread::Get()->GetLocale(),
render_frame()->GetRenderView()->
GetAcceptLanguages(),
+ scoped_ptr<LocalizedError::ErrorPageParams>(),
&error_strings);
std::string json;
@@ -173,27 +189,32 @@
render_frame()->GetRenderView()->EvaluateScript(frame_xpath, js16, 0, false);
}
-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::OnNetErrorInfo(int status_num) {
@@ -204,20 +225,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());
}
}
« no previous file with comments | « chrome/renderer/net/net_error_helper.h ('k') | chrome/renderer/net/net_error_helper_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698