summaryrefslogtreecommitdiff
path: root/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2013-09-13 12:51:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 20:50:05 +0200
commitd441d6f39bb846989d95bcf5caf387b42414718d (patch)
treee367e64a75991c554930278175d403c072de6bb8 /Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp
parent0060b2994c07842f4c59de64b5e3e430525c4b90 (diff)
downloadqtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit. Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp')
-rw-r--r--Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp96
1 files changed, 76 insertions, 20 deletions
diff --git a/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp b/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp
index 18f303948..ccd93a97f 100644
--- a/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp
+++ b/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp
@@ -1,4 +1,6 @@
/*
+ * Copyright (C) 2013 University of Szeged
+ * Copyright (C) 2013 Renata Hodovan <reni@inf.u-szeged.hu>
* Copyright (C) 2010 Apple Inc. All rights reserved.
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
*
@@ -27,6 +29,7 @@
#include "config.h"
#include "WebProcess.h"
+#include "WebKit2Initialize.h"
#include <QGuiApplication>
#include <QList>
#include <QNetworkProxyFactory>
@@ -34,15 +37,7 @@
#include <QStringList>
#include <QUrl>
#include <WebCore/RunLoop.h>
-#include <runtime/InitializeThreading.h>
-#include <wtf/MainThread.h>
-
-#if USE(ACCELERATED_COMPOSITING)
-#include "CoordinatedGraphicsLayer.h"
-#endif
-#if USE(QTKIT)
-#include "WebSystemInterface.h"
-#endif
+#include <errno.h>
#ifndef NDEBUG
#if !OS(WINDOWS)
@@ -60,6 +55,11 @@
extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t);
#endif
+#if ENABLE(SUID_SANDBOX_LINUX)
+#include "SandboxEnvironmentLinux.h"
+#include <sys/wait.h>
+#endif
+
using namespace WebCore;
namespace WebKit {
@@ -142,17 +142,72 @@ static void initializeProxy()
QNetworkProxyFactory::setUseSystemConfiguration(true);
}
+#if ENABLE(SUID_SANDBOX_LINUX)
+pid_t chrootMe()
+{
+ // Get the file descriptor of the socketpair.
+ char* sandboxSocketDescriptorString = getenv(SANDBOX_DESCRIPTOR);
+ if (!sandboxSocketDescriptorString)
+ return -1;
+
+ char* firstInvalidCharacter;
+ long int sandboxSocketDescriptor = strtol(sandboxSocketDescriptorString, &firstInvalidCharacter, 10);
+ if (*firstInvalidCharacter != '\0') {
+ fprintf(stderr, "The socket descriptor of sandbox is not valid.\n");
+ return -1;
+ }
+
+ // Get the PID of the setuid helper.
+ char* sandboxHelperPIDString = getenv(SANDBOX_HELPER_PID);
+ pid_t sandboxHelperPID = -1;
+
+ // If no PID is available, the default of -1 will do.
+ if (sandboxHelperPIDString) {
+ errno = 0;
+ sandboxHelperPID = strtol(sandboxHelperPIDString, &firstInvalidCharacter, 10);
+ if (*firstInvalidCharacter != '\0') {
+ fprintf(stderr, "The PID of sandbox is not valid.\n");
+ return -1;
+ }
+ }
+
+ // Send the chrootMe message to the helper.
+ char sandboxMeMessage = MSG_CHROOTME;
+ ssize_t numberOfCharacters = write(sandboxSocketDescriptor, &sandboxMeMessage, 1);
+ if (numberOfCharacters != 1) {
+ fprintf(stderr, "ChrootMe msg failed to write: %s.\n", strerror(errno));
+ return -1;
+ }
+
+ // Read the acknowledgement message from the helper.
+ numberOfCharacters = read(sandboxSocketDescriptor, &sandboxMeMessage, 1);
+ if (numberOfCharacters != 1 || sandboxMeMessage != MSG_CHROOTED) {
+ fprintf(stderr, "Couldn't read the confirmation message: %s.\n", strerror(errno));
+ return -1;
+ }
+ close(sandboxSocketDescriptor);
+
+ // Wait for the helper process.
+ int expectedPID = waitpid(sandboxHelperPID, 0, 0);
+ if (expectedPID != -1 && (sandboxHelperPID == -1 || expectedPID == sandboxHelperPID))
+ return expectedPID;
+ fprintf(stderr, "Couldn't wait for the helper process: %s\n", strerror(errno));
+ return -1;
+}
+#endif
+
Q_DECL_EXPORT int WebProcessMainQt(QGuiApplication* app)
{
+#if ENABLE(SUID_SANDBOX_LINUX)
+ pid_t helper = chrootMe();
+ if (helper == -1) {
+ fprintf(stderr, "Asking for chroot failed.\n");
+ return -1;
+ }
+#endif
initializeProxy();
- JSC::initializeThreading();
- WTF::initializeMainThread();
- RunLoop::initializeMainRunLoop();
-
-#if USE(QTKIT)
- InitWebCoreSystemInterfaceForWK2();
-#endif
+ InitializeWebKit2();
// Create the connection.
if (app->arguments().size() <= 1) {
@@ -186,11 +241,12 @@ Q_DECL_EXPORT int WebProcessMainQt(QGuiApplication* app)
identifier = static_cast<CoreIPC::Connection::Identifier>(id);
#endif
#endif
-#if USE(ACCELERATED_COMPOSITING)
- CoordinatedGraphicsLayer::initFactory();
-#endif
- WebKit::WebProcess::shared().initialize(identifier, RunLoop::main());
+
+ WebKit::ChildProcessInitializationParameters parameters;
+ parameters.connectionIdentifier = identifier;
+
+ WebKit::WebProcess::shared().initialize(parameters);
RunLoop::run();