/**************************************************************************** ** ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPLv3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in ** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "renderer/content_renderer_client_qt.h" #include "base/strings/utf_string_conversions.h" #include "chrome/common/localized_error.h" #include "components/visitedlink/renderer/visitedlink_slave.h" #include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_view.h" #include "net/base/net_errors.h" #include "third_party/WebKit/public/platform/WebURLError.h" #include "third_party/WebKit/public/platform/WebURLRequest.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/webui/jstemplate_builder.h" #include "renderer/qt_render_view_observer.h" #include "grit/renderer_resources.h" static const char kHttpErrorDomain[] = "http"; ContentRendererClientQt::ContentRendererClientQt() { } ContentRendererClientQt::~ContentRendererClientQt() { } void ContentRendererClientQt::RenderThreadStarted() { m_visitedLinkSlave.reset(new visitedlink::VisitedLinkSlave); content::RenderThread::Get()->AddObserver(m_visitedLinkSlave.data()); } void ContentRendererClientQt::RenderViewCreated(content::RenderView* render_view) { // RenderViewObserver destroys itself with its RenderView. new QtRenderViewObserver(render_view); } bool ContentRendererClientQt::HasErrorPage(int httpStatusCode, std::string *errorDomain) { // Use an internal error page, if we have one for the status code. if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, httpStatusCode)) { return false; } *errorDomain = LocalizedError::kHttpErrorDomain; return true; } // To tap into the chromium localized strings. Ripped from the chrome layer (highly simplified). void ContentRendererClientQt::GetNavigationErrorStrings(content::RenderView* render_view, blink::WebFrame *frame, const blink::WebURLRequest &failed_request, const blink::WebURLError &error, std::string *error_html, base::string16 *error_description) { Q_UNUSED(frame) const bool isPost = EqualsASCII(failed_request.httpMethod(), "POST"); if (error_html) { // Use a local error page. int resource_id; base::DictionaryValue error_strings; const std::string locale = content::RenderThread::Get()->GetLocale(); // TODO(elproxy): We could potentially get better diagnostics here by first calling NetErrorHelper::GetErrorStringsForDnsProbe LocalizedError::GetStrings(error.reason, error.domain.utf8(), error.unreachableURL, isPost, error.staleCopyInCache && !isPost, locale, render_view->GetAcceptLanguages(), scoped_ptr(), &error_strings); resource_id = IDR_NET_ERROR_HTML; const base::StringPiece template_html(ui::ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); if (template_html.empty()) NOTREACHED() << "unable to load template. ID: " << resource_id; else // "t" is the id of the templates root node. *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); } if (error_description) { *error_description = LocalizedError::GetErrorDetails(error, isPost); } } unsigned long long ContentRendererClientQt::VisitedLinkHash(const char *canonicalUrl, size_t length) { return m_visitedLinkSlave->ComputeURLFingerprint(canonicalUrl, length); } bool ContentRendererClientQt::IsLinkVisited(unsigned long long linkHash) { return m_visitedLinkSlave->IsVisited(linkHash); }