summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2014-02-05 16:11:56 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-06 15:18:57 +0100
commit22d4f9340ca37d28d7ed463a3a5dc00a5182b311 (patch)
treeeaf2bcb0fe61366467ec683d9effbd2669761d5d /src
parent2f2735388fc48afa5bca0246efb8f50ae1fc4bd9 (diff)
Register a path provider for Qt instead of using PathService::Override
Change-Id: I465a5465ec4189b077a8c1cbab7485c628eca899 Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/content_main_delegate_qt.cpp5
-rw-r--r--src/core/type_conversion.h5
-rw-r--r--src/core/web_engine_context.cpp12
-rw-r--r--src/core/web_engine_library_info.cpp96
-rw-r--r--src/core/web_engine_library_info.h4
5 files changed, 96 insertions, 26 deletions
diff --git a/src/core/content_main_delegate_qt.cpp b/src/core/content_main_delegate_qt.cpp
index 20bedc039..43cca7ef9 100644
--- a/src/core/content_main_delegate_qt.cpp
+++ b/src/core/content_main_delegate_qt.cpp
@@ -63,9 +63,8 @@ static base::StringPiece PlatformResourceProvider(int key) {
void ContentMainDelegateQt::PreSandboxStartup()
{
- PathService::Override(base::FILE_EXE, WebEngineLibraryInfo::subProcessPath());
- PathService::Override(content::DIR_MEDIA_LIBS, WebEngineLibraryInfo::pluginsPath());
- PathService::Override(ui::DIR_LOCALES, WebEngineLibraryInfo::localesPath());
+ // Register the Qt path provider which handles necessary paths for base, ui and content.
+ PathService::RegisterProvider(WebEngineLibraryInfo::pathProviderQt, base::PATH_START, content::PATH_END);
net::NetModule::SetResourceProvider(PlatformResourceProvider);
ui::ResourceBundle::InitSharedInstanceWithLocale(l10n_util::GetApplicationLocale(std::string("en-US")), 0);
diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h
index a1c39581f..5e489353c 100644
--- a/src/core/type_conversion.h
+++ b/src/core/type_conversion.h
@@ -135,6 +135,11 @@ inline base::FilePath::StringType toFilePathString(const QString &str)
#endif
}
+inline base::FilePath toFilePath(const QString &str)
+{
+ return base::FilePath(toFilePathString(str));
+}
+
template <typename T>
inline T fileListingHelper(const QString &) {qFatal("Specialization missing for %s.", Q_FUNC_INFO);}
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index 28d336e9d..1e28c4ab8 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -45,6 +45,7 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
+#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/app/content_main_runner.h"
@@ -52,7 +53,6 @@
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
-
#include "content/public/browser/utility_process_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/browser/gpu/gpu_process_host.h"
@@ -131,11 +131,11 @@ WebEngineContext::WebEngineContext(WebContentsAdapterClient::RenderingMode rende
CommandLine* parsedCommandLine = CommandLine::ForCurrentProcess();
parsedCommandLine->AppendSwitchASCII(switches::kUserAgent, webkit_glue::BuildUserAgentFromProduct("QtWebEngine/0.1"));
-#if defined(OS_WIN)
- parsedCommandLine->AppendSwitchNative(switches::kBrowserSubprocessPath,WebEngineLibraryInfo::subProcessPath().value().c_str());
-#else
- parsedCommandLine->AppendSwitchASCII(switches::kBrowserSubprocessPath, WebEngineLibraryInfo::subProcessPath().value().c_str());
-#endif
+
+ base::FilePath subprocessPath;
+ PathService::Get(content::CHILD_PROCESS_EXE, &subprocessPath);
+ parsedCommandLine->AppendSwitchPath(switches::kBrowserSubprocessPath, subprocessPath);
+
parsedCommandLine->AppendSwitch(switches::kNoSandbox);
parsedCommandLine->AppendSwitch(switches::kDisablePlugins);
diff --git a/src/core/web_engine_library_info.cpp b/src/core/web_engine_library_info.cpp
index a6b7c5d8d..40cd7a1b7 100644
--- a/src/core/web_engine_library_info.cpp
+++ b/src/core/web_engine_library_info.cpp
@@ -41,19 +41,29 @@
#include "web_engine_library_info.h"
+#include "base/base_paths.h"
+#include "base/file_util.h"
+#include "content/public/common/content_paths.h"
+#include "ui/base/ui_base_paths.h"
#include "type_conversion.h"
#include <QByteArray>
+#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QLibraryInfo>
+#include <QStandardPaths>
+#include <QString>
#include <QStringBuilder>
#ifndef QTWEBENGINEPROCESS_NAME
#error "No name defined for QtWebEngine's process"
#endif
-static QString location(QLibraryInfo::LibraryLocation path)
+
+namespace {
+
+QString location(QLibraryInfo::LibraryLocation path)
{
#if defined(Q_OS_BLACKBERRY)
// On BlackBerry, the qtwebengine may live in /usr/lib/qtwebengine.
@@ -86,13 +96,7 @@ static QString location(QLibraryInfo::LibraryLocation path)
return QLibraryInfo::location(path);
}
-base::FilePath WebEngineLibraryInfo::pluginsPath()
-{
- QString path = location(QLibraryInfo::PluginsPath) % QDir::separator() % QStringLiteral("qtwebengine");
- return base::FilePath(toFilePathString(path));
-}
-
-base::FilePath WebEngineLibraryInfo::subProcessPath()
+QString subProcessPath()
{
static bool initialized = false;
static QString processPath (location(QLibraryInfo::LibraryExecutablesPath)
@@ -107,17 +111,81 @@ base::FilePath WebEngineLibraryInfo::subProcessPath()
initialized = true;
}
- return base::FilePath(toFilePathString(processPath));
+ return processPath;
+}
+
+QString pluginsPath()
+{
+ return location(QLibraryInfo::PluginsPath) % QDir::separator() % QStringLiteral("qtwebengine");
+}
+
+QString localesPath()
+{
+ return location(QLibraryInfo::TranslationsPath) % QStringLiteral("/qtwebengine_locales");
}
-base::FilePath WebEngineLibraryInfo::localesPath()
+QString fallbackDir() {
+ static QString directory = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName();
+ return directory;
+}
+
+} // namespace
+
+#if defined(OS_ANDROID)
+namespace base {
+// Replace the Android base path provider that depends on jni.
+// With this we avoid patching chromium which we would need since
+// PathService registers PathProviderAndroid by default on Android.
+bool PathProviderAndroid(int key, FilePath* result)
{
- QString path = location(QLibraryInfo::TranslationsPath) % QStringLiteral("/qtwebengine_locales");
- return base::FilePath(toFilePathString(path));
+ return WebEngineLibraryInfo::pathProviderQt(key, result);
}
+}
+#endif // defined(OS_ANDROID)
+
base::FilePath WebEngineLibraryInfo::repackedResourcesPath()
{
- QString path = location(QLibraryInfo::DataPath) % QStringLiteral("/qtwebengine_resources.pak");
- return base::FilePath(toFilePathString(path));
+ return toFilePath(location(QLibraryInfo::DataPath) % QStringLiteral("/qtwebengine_resources.pak"));
+}
+
+bool WebEngineLibraryInfo::pathProviderQt(int key, base::FilePath* result)
+{
+ QString directory;
+ switch (key) {
+ case base::FILE_EXE:
+ case content::CHILD_PROCESS_EXE:
+ *result = toFilePath(subProcessPath());
+ return true;
+ case base::DIR_CACHE:
+ directory = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
+ break;
+ case base::DIR_HOME:
+ directory = QDir::homePath();
+ break;
+ case base::DIR_USER_DESKTOP:
+ directory = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
+ break;
+#if defined(OS_ANDROID)
+ case base::DIR_SOURCE_ROOT:
+ case base::DIR_ANDROID_EXTERNAL_STORAGE:
+ case base::DIR_ANDROID_APP_DATA:
+ directory = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+ break;
+#endif
+ case content::DIR_MEDIA_LIBS:
+ *result = toFilePath(pluginsPath());
+ return true;
+ case ui::DIR_LOCALES:
+ *result = toFilePath(localesPath());
+ return true;
+ default:
+ // Note: the path system expects this function to override the default
+ // behavior. So no need to log an error if we don't support a given
+ // path. The system will just use the default.
+ return false;
+ }
+
+ *result = toFilePath(directory.isEmpty() ? fallbackDir() : directory);
+ return true;
}
diff --git a/src/core/web_engine_library_info.h b/src/core/web_engine_library_info.h
index a2b3fab31..644f85003 100644
--- a/src/core/web_engine_library_info.h
+++ b/src/core/web_engine_library_info.h
@@ -46,10 +46,8 @@
class WebEngineLibraryInfo {
public:
- static base::FilePath subProcessPath();
- static base::FilePath pluginsPath();
- static base::FilePath localesPath();
static base::FilePath repackedResourcesPath();
+ static bool pathProviderQt(int key, base::FilePath* result);
};