diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-08-19 15:17:56 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-08-20 18:15:57 +0200 |
commit | c1c7c3cfa9d8c3e6f05095d0880a84a13a0d9e01 (patch) | |
tree | 1a77807a994125236fc6631e84cdad83d9e3897e | |
parent | abd17e1583e8e13b1a46d599fb695c1189550226 (diff) | |
download | qtwebengine-c1c7c3cfa9d8c3e6f05095d0880a84a13a0d9e01.tar.gz |
Centralize type conversion functions.
This adds the common GURL->QUrl and string16->QString conversions
into a common header and use those functions throughout the code.
Move the qStringToStringType into the same header and rename it
to a name consistent with the others.
This also cleans up shared_globals.h by moving content:: forward
declarations in the cpp, where they are used.
Change-Id: I19527ea7de1f6047aae8b44c97eb4d7c3e5a0e54
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
-rw-r--r-- | lib/browser_context_qt.h | 3 | ||||
-rw-r--r-- | lib/type_conversion.h | 74 | ||||
-rw-r--r-- | lib/web_contents_adapter.cpp | 12 | ||||
-rw-r--r-- | lib/web_contents_delegate_qt.cpp | 5 | ||||
-rw-r--r-- | lib/web_contents_delegate_qt.h | 3 | ||||
-rw-r--r-- | lib/web_contents_view_qt.cpp | 3 | ||||
-rw-r--r-- | lib/web_engine_context.cpp | 3 | ||||
-rw-r--r-- | shared/shared_globals.cpp | 5 | ||||
-rw-r--r-- | shared/shared_globals.h | 20 |
9 files changed, 89 insertions, 39 deletions
diff --git a/lib/browser_context_qt.h b/lib/browser_context_qt.h index 8ba01779a..88bba1e9e 100644 --- a/lib/browser_context_qt.h +++ b/lib/browser_context_qt.h @@ -66,6 +66,7 @@ #include "download_manager_delegate_qt.h" #include "resource_context_qt.h" +#include "type_conversion.h" #include "url_request_context_getter_qt.h" class BrowserContextQt : public content::BrowserContext @@ -90,7 +91,7 @@ public: dataLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName(); dataLocation.append(QDir::separator() % QStringLiteral("QtWebEngine")); - return base::FilePath(qStringToStringType(dataLocation)); + return base::FilePath(toFilePathString(dataLocation)); } virtual bool IsOffTheRecord() const Q_DECL_OVERRIDE diff --git a/lib/type_conversion.h b/lib/type_conversion.h new file mode 100644 index 000000000..51a543f73 --- /dev/null +++ b/lib/type_conversion.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TYPE_CONVERSION_H +#define TYPE_CONVERSION_H + +#include <QString> +#include <QUrl> +#include "base/files/file_path.h" +#include "url/gurl.h" + +inline QString toQt(const string16 &string) +{ + return QString::fromUtf16(string.data()); +} + +inline QUrl toQt(const GURL &url) +{ + return QUrl(QString::fromStdString(url.spec())); +} + +inline GURL toGurl(const QUrl& url) +{ + return GURL(url.toString().toStdString()); +} + +inline base::FilePath::StringType toFilePathString(const QString &str) +{ +#if defined(OS_POSIX) + return str.toStdString(); +#elif defined(OS_WIN) + return str.toStdWString(); +#endif +} + +#endif // TYPE_CONVERSION_H diff --git a/lib/web_contents_adapter.cpp b/lib/web_contents_adapter.cpp index 8302c9199..73970094e 100644 --- a/lib/web_contents_adapter.cpp +++ b/lib/web_contents_adapter.cpp @@ -118,10 +118,7 @@ void WebContentsAdapter::reload() void WebContentsAdapter::load(const QUrl &url) { - QString urlString = url.toString(); - GURL gurl(urlString.toStdString()); - - content::NavigationController::LoadURLParams params(gurl); + content::NavigationController::LoadURLParams params(toGurl(url)); params.transition_type = content::PageTransitionFromInt(content::PAGE_TRANSITION_TYPED | content::PAGE_TRANSITION_FROM_ADDRESS_BAR); webContents()->GetController().LoadURLWithParams(params); webContents()->GetView()->Focus(); @@ -129,16 +126,13 @@ void WebContentsAdapter::load(const QUrl &url) QUrl WebContentsAdapter::activeUrl() const { - GURL gurl = webContents()->GetVisibleURL(); - return QUrl(QString::fromStdString(gurl.spec())); + return toQt(webContents()->GetVisibleURL()); } QString WebContentsAdapter::pageTitle() const { content::NavigationEntry* entry = webContents()->GetController().GetVisibleEntry(); - if (!entry) - return QString(); - return QString::fromUtf16(entry->GetTitle().data()); + return entry ? toQt(entry->GetTitle()) : QString(); } content::WebContents *WebContentsAdapter::webContents() const diff --git a/lib/web_contents_delegate_qt.cpp b/lib/web_contents_delegate_qt.cpp index 9cadf4b60..738ebd0fc 100644 --- a/lib/web_contents_delegate_qt.cpp +++ b/lib/web_contents_delegate_qt.cpp @@ -41,6 +41,7 @@ #include "web_contents_delegate_qt.h" +#include "type_conversion.h" #include "web_contents_adapter_client.h" #include "content/public/browser/navigation_controller.h" @@ -87,9 +88,7 @@ void WebContentsDelegateQt::NavigationStateChanged(const content::WebContents* s { if (changed_flags & content::INVALIDATE_TYPE_URL) { Q_ASSERT(m_viewClient); - GURL gurl = web_contents()->GetVisibleURL(); - QUrl url(QString::fromStdString(gurl.spec())); - m_viewClient->urlChanged(url); + m_viewClient->urlChanged(toQt(web_contents()->GetVisibleURL())); } } diff --git a/lib/web_contents_delegate_qt.h b/lib/web_contents_delegate_qt.h index e5ff9173d..a3a46caa6 100644 --- a/lib/web_contents_delegate_qt.h +++ b/lib/web_contents_delegate_qt.h @@ -46,9 +46,6 @@ #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents.h" -#include <QObject> -#include <QUrl> - namespace content { class BrowserContext; class SiteInstance; diff --git a/lib/web_contents_view_qt.cpp b/lib/web_contents_view_qt.cpp index 09863ca9e..db991d84b 100644 --- a/lib/web_contents_view_qt.cpp +++ b/lib/web_contents_view_qt.cpp @@ -62,8 +62,7 @@ content::RenderWidgetHostView* WebContentsViewQt::CreateViewForWidget(content::R void WebContentsViewQt::SetPageTitle(const string16& title) { - QString string = QString::fromUtf16(title.data()); - m_client->titleChanged(string); + m_client->titleChanged(toQt(title)); } void WebContentsViewQt::GetContainerBounds(gfx::Rect* out) const diff --git a/lib/web_engine_context.cpp b/lib/web_engine_context.cpp index 49f38c682..95a3f93ec 100644 --- a/lib/web_engine_context.cpp +++ b/lib/web_engine_context.cpp @@ -58,6 +58,7 @@ #include "webkit/common/user_agent/user_agent_util.h" #include "content_browser_client_qt.h" +#include "type_conversion.h" #include <QCoreApplication> #include <QStringList> @@ -94,7 +95,7 @@ public: // before the sandbox is engaged. void PreSandboxStartup() Q_DECL_OVERRIDE { - PathService::Override(base::FILE_EXE, base::FilePath(qStringToStringType(subProcessPath()))); + PathService::Override(base::FILE_EXE, base::FilePath(toFilePathString(subProcessPath()))); } content::ContentBrowserClient* CreateContentBrowserClient() Q_DECL_OVERRIDE diff --git a/shared/shared_globals.cpp b/shared/shared_globals.cpp index bb2fcfb39..08d2368db 100644 --- a/shared/shared_globals.cpp +++ b/shared/shared_globals.cpp @@ -64,6 +64,11 @@ void GetScreenInfoFromNativeWindow(QWindow* window, WebKit::WebScreenInfo* resul } namespace content { +class WebContentsImpl; +class WebContentsViewPort; +class WebContentsViewDelegate; +class RenderViewHostDelegateView; + WebContentsViewPort* CreateWebContentsView(WebContentsImpl*, WebContentsViewDelegate*, RenderViewHostDelegateView**) diff --git a/shared/shared_globals.h b/shared/shared_globals.h index c0b167269..314c7fbf1 100644 --- a/shared/shared_globals.h +++ b/shared/shared_globals.h @@ -42,11 +42,8 @@ #ifndef SHARED_GLOBALS_H #define SHARED_GLOBALS_H -#include "base/files/file_path.h" #include "third_party/WebKit/public/platform/WebScreenInfo.h" -#include <QString> - #ifdef QT_WEBENGINE_LOGGING #define QT_NOT_YET_IMPLEMENTED fprintf(stderr, "function %s not implemented! - %s:%d\n", __func__, __FILE__, __LINE__); #define QT_NOT_USED fprintf(stderr, "# function %s should not be used! - %s:%d\n", __func__, __FILE__, __LINE__); Q_UNREACHABLE(); @@ -55,25 +52,8 @@ #define QT_NOT_USED Q_UNREACHABLE(); // This will assert in debug. #endif -namespace content { -class WebContentsImpl; -class WebContentsViewPort; -class WebContentsViewDelegate; -class RenderViewHostDelegateView; -} // namespace content - class QWindow; void GetScreenInfoFromNativeWindow(QWindow* window, WebKit::WebScreenInfo* results); - -inline base::FilePath::StringType qStringToStringType(const QString &str) -{ -#if defined(OS_POSIX) - return str.toStdString(); -#elif defined(OS_WIN) - return str.toStdWString(); -#endif -} - #endif |