2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "ProcessLauncher.h"
29 #include "Connection.h"
31 #include "WebProcess.h"
32 #include <WebCore/PlatformString.h>
33 #include <runtime/InitializeThreading.h>
35 #include <wtf/PassRefPtr.h>
36 #include <wtf/Threading.h>
39 #include <meegotouch/MComponentData>
46 #include <QApplication>
50 #include <QtCore/qglobal.h>
52 #include <sys/resource.h>
55 #if !defined(QWEBKIT_EXPORT)
56 # if defined(QT_SHARED)
57 # define QWEBKIT_EXPORT Q_DECL_EXPORT
59 # define QWEBKIT_EXPORT
63 using namespace WebCore;
67 void ProcessLauncher::launchProcess()
70 QString connectionIdentifier = QString::number(random());
72 QString program("QtWebProcess " + connectionIdentifier);
74 QProcess* webProcess = new QProcess;
75 webProcess->start(program);
77 if (!webProcess->waitForStarted()) {
78 qDebug() << "Failed to start" << program;
82 PlatformProcessIdentifier processIdentifier = webProcess->pid();
83 setpriority(PRIO_PROCESS, processIdentifier, 10);
85 qDebug() << program << "nice" << getpriority(PRIO_PROCESS, processIdentifier);
87 // We've finished launching the process, message back to the run loop.
88 RunLoop::main()->scheduleWork(WorkItem::create(this, &ProcessLauncher::didFinishLaunchingProcess, processIdentifier, connectionIdentifier));
91 void ProcessLauncher::terminateProcess()
93 if (!m_processIdentifier)
97 kill(m_processIdentifier, SIGKILL);
101 static void* webThreadBody(void* /* context */)
104 JSC::initializeThreading();
105 WTF::initializeMainThread();
107 // FIXME: We do not support threaded mode for now.
109 WebProcess::shared().initialize("foo", RunLoop::current());
115 CoreIPC::Connection::Identifier ProcessLauncher::createWebThread()
118 int connectionIdentifier = random();
120 if (!createThread(webThreadBody, reinterpret_cast<void*>(connectionIdentifier), "WebKit2: WebThread")) {
121 qWarning() << "failed starting thread";
125 QString serverIdentifier = QString::number(connectionIdentifier);
126 return serverIdentifier;
129 } // namespace WebKit
131 QWEBKIT_EXPORT int webProcessMain(int argc, char** argv)
133 QApplication* app = new QApplication(argc, argv);
136 new MComponentData(argc, argv);
141 JSC::initializeThreading();
142 WTF::initializeMainThread();
143 RunLoop::initializeMainRunLoop();
145 // Create the connection.
146 QString identifier(app->arguments().size() > 1 ? app->arguments().at(1) : "");
147 WebKit::WebProcess::shared().initialize(identifier, RunLoop::main());
151 // FIXME: Do more cleanup here.