From ae600d6b0fdb4bf9b5589df7bac162b1b112c7dd Mon Sep 17 00:00:00 2001 From: Arvid Nilsson Date: Thu, 5 Dec 2013 16:53:34 +0100 Subject: Introduce WebEngineLibraryInfo for providing paths This allows us to customize paths on BlackBerry, where QtWebEngine is currently installed to an different location than the rest of Qt5. Change-Id: I7144c992bed9fe4d7543ce0d23ee8cd5f5669dd9 Reviewed-by: Pierre Rossi Reviewed-by: Andras Becsi --- src/core/content_main_delegate_qt.cpp | 32 +--------- src/core/core_gyp_generator.pro | 2 + src/core/resource_bundle_qt.cpp | 8 +-- src/core/web_engine_library_info.cpp | 117 ++++++++++++++++++++++++++++++++++ src/core/web_engine_library_info.h | 55 ++++++++++++++++ 5 files changed, 179 insertions(+), 35 deletions(-) create mode 100644 src/core/web_engine_library_info.cpp create mode 100644 src/core/web_engine_library_info.h diff --git a/src/core/content_main_delegate_qt.cpp b/src/core/content_main_delegate_qt.cpp index c967cfd48..c8367fe37 100644 --- a/src/core/content_main_delegate_qt.cpp +++ b/src/core/content_main_delegate_qt.cpp @@ -45,40 +45,14 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/ui_base_paths.h" #include "ui/base/resource/resource_bundle.h" -#include -#include -#include -#include -#include #include "content_client_qt.h" -#include "type_conversion.h" - -#ifndef QTWEBENGINEPROCESS_NAME -#error "No name defined for QtWebEngine's process" -#endif -static QString subProcessPath() { - static bool initialized = false; - static QString processPath (QLibraryInfo::location(QLibraryInfo::LibraryExecutablesPath) - % QDir::separator() % QStringLiteral(QTWEBENGINEPROCESS_NAME)); - if (initialized) - return processPath; - - // Allow overriding at runtime for the time being. - const QByteArray fromEnv = qgetenv("QTWEBENGINEPROCESS_PATH"); - if (!fromEnv.isEmpty()) - processPath = QString::fromLatin1(fromEnv); - if (processPath.isEmpty() || !QFileInfo(processPath).exists()) - qFatal("QtWebEngineProcess not found at location %s. Try setting the QTWEBENGINEPROCESS_PATH environment variable.", qPrintable(processPath)); - initialized = true; - return processPath; -} +#include "web_engine_library_info.h" void ContentMainDelegateQt::PreSandboxStartup() { - PathService::Override(base::FILE_EXE, base::FilePath(toFilePathString(subProcessPath()))); - const QString localesPath(QLibraryInfo::location(QLibraryInfo::TranslationsPath) % QStringLiteral("/qtwebengine_locales")); - PathService::Override(ui::DIR_LOCALES, base::FilePath(toFilePathString(localesPath))); + PathService::Override(base::FILE_EXE, WebEngineLibraryInfo::subProcessPath()); + PathService::Override(ui::DIR_LOCALES, WebEngineLibraryInfo::localesPath()); ui::ResourceBundle::InitSharedInstanceWithLocale(l10n_util::GetApplicationLocale(std::string("en-US")), 0); } diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index 01d123f38..60157377e 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -51,6 +51,7 @@ SOURCES = \ web_contents_delegate_qt.cpp \ web_contents_view_qt.cpp \ web_engine_context.cpp \ + web_engine_library_info.cpp \ web_event_factory.cpp \ yuv_video_node.cpp \ qrc_protocol_handler_qt.cpp \ @@ -78,6 +79,7 @@ HEADERS = \ web_contents_delegate_qt.h \ web_contents_view_qt.h \ web_engine_context.h \ + web_engine_library_info.h \ web_event_factory.h \ yuv_video_node.h \ qrc_protocol_handler_qt.h \ diff --git a/src/core/resource_bundle_qt.cpp b/src/core/resource_bundle_qt.cpp index ea893d330..05c168101 100644 --- a/src/core/resource_bundle_qt.cpp +++ b/src/core/resource_bundle_qt.cpp @@ -42,11 +42,7 @@ #include "base/command_line.h" #include "content/public/common/content_switches.h" #include "ui/base/resource/resource_bundle.h" -#include "type_conversion.h" - -#include -#include -#include +#include "web_engine_library_info.h" namespace ui { @@ -57,7 +53,7 @@ void ResourceBundle::LoadCommonResources() return; // We repacked the resources we need and installed them. now let chromium mmap that file. - AddDataPackFromPath(base::FilePath(toFilePathString(QLibraryInfo::location(QLibraryInfo::DataPath) % QStringLiteral("/qtwebengine_resources.pak"))) , SCALE_FACTOR_100P); + AddDataPackFromPath(WebEngineLibraryInfo::repackedResourcesPath(), SCALE_FACTOR_100P); } // As GetLocaleFilePath is excluded for Mac in resource_bundle.cc, diff --git a/src/core/web_engine_library_info.cpp b/src/core/web_engine_library_info.cpp new file mode 100644 index 000000000..b996297ff --- /dev/null +++ b/src/core/web_engine_library_info.cpp @@ -0,0 +1,117 @@ +/*************************************************************************** +** +** Copyright (C) 2013 BlackBerry Limited. All rights reserved. +** 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$ +** +****************************************************************************/ + +#include "web_engine_library_info.h" + +#include "type_conversion.h" + +#include +#include +#include +#include +#include + +#ifndef QTWEBENGINEPROCESS_NAME +#error "No name defined for QtWebEngine's process" +#endif + +static QString location(QLibraryInfo::LibraryLocation path) +{ +#if defined(Q_OS_BLACKBERRY) + // On BlackBerry, the qtwebengine may live in /usr/lib/qtwebengine. + // If so, the QTWEBENGINEPROCESS_PATH env var is set to /usr/lib/qtwebengine/bin/QTWEBENGINEPROCESS_NAME. + static QString webEnginePath; + static bool initialized = false; + if (!initialized) { + const QByteArray fromEnv = qgetenv("QTWEBENGINEPROCESS_PATH"); + if (!fromEnv.isEmpty()) { + QDir dir = QFileInfo(QString::fromLatin1(fromEnv)).dir(); + if (dir.cdUp()) + webEnginePath = dir.absolutePath(); + } + initialized = true; + } + switch (path) { + case QLibraryInfo::TranslationsPath: + if (!webEnginePath.isEmpty()) + return webEnginePath % QDir::separator() % QStringLiteral("translations"); + break; + case QLibraryInfo::DataPath: + if (!webEnginePath.isEmpty()) + return webEnginePath; + break; + default: + break; + } +#endif + + return QLibraryInfo::location(path); +} + +base::FilePath WebEngineLibraryInfo::subProcessPath() +{ + static bool initialized = false; + static QString processPath (location(QLibraryInfo::LibraryExecutablesPath) + % QDir::separator() % QStringLiteral(QTWEBENGINEPROCESS_NAME)); + if (!initialized) { + // Allow overriding at runtime for the time being. + const QByteArray fromEnv = qgetenv("QTWEBENGINEPROCESS_PATH"); + if (!fromEnv.isEmpty()) + processPath = QString::fromLatin1(fromEnv); + if (processPath.isEmpty() || !QFileInfo(processPath).exists()) + qFatal("QtWebEngineProcess not found at location %s. Try setting the QTWEBENGINEPROCESS_PATH environment variable.", qPrintable(processPath)); + initialized = true; + } + + return base::FilePath(toFilePathString(processPath)); +} + +base::FilePath WebEngineLibraryInfo::localesPath() +{ + QString path = location(QLibraryInfo::TranslationsPath) % QStringLiteral("/qtwebengine_locales"); + return base::FilePath(toFilePathString(path)); +} + +base::FilePath WebEngineLibraryInfo::repackedResourcesPath() +{ + QString path = location(QLibraryInfo::DataPath) % QStringLiteral("/qtwebengine_resources.pak"); + return base::FilePath(toFilePathString(path)); +} diff --git a/src/core/web_engine_library_info.h b/src/core/web_engine_library_info.h new file mode 100644 index 000000000..0ad88b90d --- /dev/null +++ b/src/core/web_engine_library_info.h @@ -0,0 +1,55 @@ +/*************************************************************************** +** +** Copyright (C) 2013 BlackBerry Limited. All rights reserved. +** 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 WEB_ENGINE_LIBRARY_INFO_H +#define WEB_ENGINE_LIBRARY_INFO_H + +#include "base/files/file_path.h" + +class WebEngineLibraryInfo { +public: + static base::FilePath subProcessPath(); + static base::FilePath localesPath(); + static base::FilePath repackedResourcesPath(); +}; + + +#endif // WEB_ENGINE_LIBRARY_INFO_H -- cgit v1.2.3