Changeset 83215 in webkit


Ignore:
Timestamp:
Apr 7, 2011 3:11:08 PM (13 years ago)
Author:
Martin Robinson
Message:

2011-04-07 Amruth Raj <amruthraj@motorola.com> and Martin Robinson <mrobinson@igalia.com>

Reviewed by Kenneth Rohde Christiansen.

[GTK] Implement SharedMemory for WebKit2
https://bugs.webkit.org/show_bug.cgi?id=49791

Share the SharedMemory, Attachment and Connection implementations with the Qt port.
Both implementation are, in fact, general Unix implementations using standard Unix
domain sockets and sendmsg / recvmsg. This should reduce the amount of duplicated code
greatly and lay the groundwork for GTK+/Qt implementations for other operating systems.

  • GNUmakefile.am: Replaced GTK+ versions of files with the Unix ones.
  • Platform/CoreIPC/ArgumentDecoder.cpp: Extended Qt #ifdefs to include GTK. (CoreIPC::ArgumentDecoder::~ArgumentDecoder):
  • Platform/CoreIPC/ArgumentEncoder.cpp: Ditto. (CoreIPC::ArgumentEncoder::~ArgumentEncoder):
  • Platform/CoreIPC/Attachment.h: Ditto.
  • Platform/CoreIPC/Connection.h: Combined the GTK+ and Qt sections.
  • Platform/CoreIPC/unix/AttachmentUnix.cpp: Renamed from Source/WebKit2/Platform/CoreIPC/qt/AttachmentQt.cpp.
  • Platform/CoreIPC/unix/ConnectionUnix.cpp: Renamed from Source/WebKit2/Platform/CoreIPC/qt/ConnectionQt.cpp.
  • Platform/unix/SharedMemoryUnix.cpp: Renamed from Source/WebKit2/Platform/qt/SharedMemoryQt.cpp.
  • UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp: (WebKit::ProcessLauncher::launchProcess): Use SOCK_DGRAM instead of SOCK_STREAM to match Qt.
  • WebKit2.pro: Updated source list to reflect file renaming.
Location:
trunk/Source/WebKit2
Files:
2 added
1 deleted
9 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r83211 r83215  
     12011-04-07   Amruth Raj  <amruthraj@motorola.com> and Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [GTK] Implement SharedMemory for WebKit2
     6        https://bugs.webkit.org/show_bug.cgi?id=49791
     7
     8        Share the SharedMemory, Attachment and Connection implementations with the Qt port.
     9        Both implementation are, in fact, general Unix implementations using standard Unix
     10        domain sockets and sendmsg / recvmsg. This should reduce the amount of duplicated code
     11        greatly and lay the groundwork for GTK+/Qt implementations for other operating systems.
     12
     13        * GNUmakefile.am: Replaced GTK+ versions of files with the Unix ones.
     14        * Platform/CoreIPC/ArgumentDecoder.cpp: Extended Qt #ifdefs to include GTK.
     15        (CoreIPC::ArgumentDecoder::~ArgumentDecoder):
     16        * Platform/CoreIPC/ArgumentEncoder.cpp: Ditto.
     17        (CoreIPC::ArgumentEncoder::~ArgumentEncoder):
     18        * Platform/CoreIPC/Attachment.h: Ditto.
     19        * Platform/CoreIPC/Connection.h: Combined the GTK+ and Qt sections.
     20        * Platform/CoreIPC/unix/AttachmentUnix.cpp: Renamed from Source/WebKit2/Platform/CoreIPC/qt/AttachmentQt.cpp.
     21        * Platform/CoreIPC/unix/ConnectionUnix.cpp: Renamed from Source/WebKit2/Platform/CoreIPC/qt/ConnectionQt.cpp.
     22        * Platform/unix/SharedMemoryUnix.cpp: Renamed from Source/WebKit2/Platform/qt/SharedMemoryQt.cpp.
     23        * UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
     24        (WebKit::ProcessLauncher::launchProcess): Use SOCK_DGRAM instead of SOCK_STREAM to match Qt.
     25        * WebKit2.pro: Updated source list to reflect file renaming.
     26
    1272011-04-07  Alexey Proskuryakov  <ap@apple.com>
    228
  • trunk/Source/WebKit2/GNUmakefile.am

    r82929 r83215  
    9494        Source/WebKit2/Platform/CoreIPC/DataReference.cpp \
    9595        Source/WebKit2/Platform/CoreIPC/DataReference.h \
    96         Source/WebKit2/Platform/CoreIPC/gtk/ConnectionGtk.cpp \
    9796        Source/WebKit2/Platform/CoreIPC/HandleMessage.h \
    9897        Source/WebKit2/Platform/CoreIPC/MessageID.h \
    9998        Source/WebKit2/Platform/CoreIPC/MessageSender.h \
     99        Source/WebKit2/Platform/CoreIPC/unix/AttachmentUnix.cpp \
     100        Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp \
    100101        Source/WebKit2/Platform/gtk/ModuleGtk.cpp \
    101102        Source/WebKit2/Platform/gtk/RunLoopGtk.cpp \
    102         Source/WebKit2/Platform/gtk/SharedMemoryGtk.cpp \
    103103        Source/WebKit2/Platform/gtk/WorkQueueGtk.cpp \
    104104        Source/WebKit2/Platform/Logging.cpp \
     
    110110        Source/WebKit2/Platform/RunLoop.h \
    111111        Source/WebKit2/Platform/SharedMemory.h \
     112        Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp \
    112113        Source/WebKit2/Platform/WorkItem.h \
    113114        Source/WebKit2/Platform/WorkQueue.cpp \
  • trunk/Source/WebKit2/Platform/CoreIPC/ArgumentDecoder.cpp

    r82285 r83215  
    4848    ASSERT(m_buffer);
    4949    fastFree(m_buffer);
    50 #if !PLATFORM(QT)
     50#if !PLATFORM(QT) && !PLATFORM(GTK)
    5151    // FIXME: We need to dispose of the mach ports in cases of failure.
    5252#else
  • trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.cpp

    r82285 r83215  
    5151    if (m_buffer)
    5252        fastFree(m_buffer);
    53 #if !PLATFORM(QT)
     53#if !PLATFORM(QT) && !PLATFORM(GTK)
    5454    // FIXME: We need to dispose of the attachments in cases of failure.
    5555#else
  • trunk/Source/WebKit2/Platform/CoreIPC/Attachment.h

    r76507 r83215  
    4141        MachPortType,
    4242        MachOOLMemoryType
    43 #elif PLATFORM(QT)
     43#elif PLATFORM(QT) || PLATFORM(GTK)
    4444        MappedMemory
    4545#endif
     
    4949    Attachment(mach_port_name_t port, mach_msg_type_name_t disposition);
    5050    Attachment(void* address, mach_msg_size_t size, mach_msg_copy_options_t copyOptions, bool deallocate);
    51 #elif PLATFORM(QT)
     51#elif PLATFORM(QT) || PLATFORM(GTK)
    5252    Attachment(int fileDescriptor, size_t);
    5353#endif
     
    6767    mach_msg_copy_options_t copyOptions() const { ASSERT(m_type == MachOOLMemoryType); return m_oolMemory.copyOptions; }
    6868    bool deallocate() const { ASSERT(m_type == MachOOLMemoryType); return m_oolMemory.deallocate; }
    69 #elif PLATFORM(QT)
     69#elif PLATFORM(QT) || PLATFORM(GTK)
    7070    size_t size() const { return m_size; }
    7171
     
    9595        } m_oolMemory;
    9696    };
    97 #elif PLATFORM(QT)
     97#elif PLATFORM(QT) || PLATFORM(GTK)
    9898    int m_fileDescriptor;
    9999    size_t m_size;
  • trunk/Source/WebKit2/Platform/CoreIPC/Connection.h

    r82045 r83215  
    306306    OVERLAPPED m_writeState;
    307307    HANDLE m_connectionPipe;
    308 #elif PLATFORM(QT)
     308#elif PLATFORM(QT) || PLATFORM(GTK)
    309309    // Called on the connection queue.
    310310    void readyReadHandler();
     
    312312    Vector<uint8_t> m_readBuffer;
    313313    size_t m_currentMessageSize;
     314    int m_socketDescriptor;
     315
     316#if PLATFORM(QT)
    314317    QSocketNotifier* m_socketNotifier;
    315     int m_socketDescriptor;
    316 #elif PLATFORM(GTK)
    317     void readEventHandler();
    318     void processCompletedMessage();
    319     bool messageProcessingCompleted() { return !m_currentMessageSize; }
    320 
    321     int m_socket;
    322     Vector<uint8_t> m_readBuffer;
    323     size_t m_currentMessageSize;
    324     size_t m_pendingBytes;
     318#endif
    325319#endif
    326320};
  • trunk/Source/WebKit2/Platform/CoreIPC/unix/AttachmentUnix.cpp

    r83214 r83215  
    2828#include "Attachment.h"
    2929
    30 #if PLATFORM(QT)
    3130#include <unistd.h>
    3231#include <errno.h>
    33 #endif
    34 
    3532
    3633namespace CoreIPC {
  • trunk/Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp

    r83214 r83215  
    3333#include "SharedMemory.h"
    3434#include "WebProcessProxy.h"
    35 #include <QApplication>
    36 #include <QSocketNotifier>
    3735#include <sys/socket.h>
    3836#include <unistd.h>
     
    4139#include <wtf/Assertions.h>
    4240
     41#if PLATFORM(QT)
     42#include <QApplication>
     43#include <QSocketNotifier>
     44#elif PLATFORM(GTK)
     45#include <glib.h>
     46#endif
     47
    4348using namespace std;
    4449
     
    4954
    5055enum {
    51     MessageBodyIsOOL = 1U << 31
     56    MessageBodyIsOOL = 1 << 31
    5257};
    5358
     
    8994{
    9095    m_socketDescriptor = identifier;
    91     m_socketNotifier = 0;
    9296    m_readBuffer.resize(messageMaxSize);
    9397    m_currentMessageSize = 0;
     98
     99#if PLATFORM(QT)
     100    m_socketNotifier = 0;
     101#endif
    94102}
    95103
     
    102110        return;
    103111
     112#if PLATFORM(GTK)
     113    m_connectionQueue.unregisterEventSourceHandler(m_socketDescriptor);
     114#endif
     115
     116#if PLATFORM(QT)
    104117    delete m_socketNotifier;
    105118    m_socketNotifier = 0;
     119#endif
     120
    106121    m_socketDescriptor = -1;
    107122    m_isConnected = false;
    108123}
    109124
     125#if PLATFORM(QT)
    110126class SocketNotifierResourceGuard {
    111127public:
     
    124140    QSocketNotifier* const m_socketNotifier;
    125141};
     142#endif
    126143
    127144template<class T, class iterator>
     
    145162{
    146163    Deque<Attachment> attachments;
     164#if PLATFORM(QT)
    147165    SocketNotifierResourceGuard socketNotifierEnabler(m_socketNotifier);
     166#endif
    148167    AttachmentResourceGuard<Deque<Attachment>, Deque<Attachment>::iterator> attachementDisposer(attachments);
    149168
    150     OwnArrayPtr<char> attachmentDescriptorBuffer = adoptArrayPtr(new char[CMSG_SPACE(sizeof(int) * (attachmentMaxAmount))]);
     169    char attachmentDescriptorBuffer[CMSG_SPACE(sizeof(int) * (attachmentMaxAmount))];
    151170    struct msghdr message;
    152171    memset(&message, 0, sizeof(message));
     
    155174    memset(&iov, 0, sizeof(iov));
    156175
    157     message.msg_control = attachmentDescriptorBuffer.get();
     176    message.msg_control = attachmentDescriptorBuffer;
    158177    message.msg_controllen = CMSG_SPACE(sizeof(int) * (attachmentMaxAmount));
    159178
     
    185204    if (messageInfo.attachmentCount()) {
    186205        if (controlMessage && controlMessage->cmsg_level == SOL_SOCKET && controlMessage->cmsg_type == SCM_RIGHTS) {
    187             OwnArrayPtr<size_t> attachmentSizes = adoptArrayPtr(new size_t[messageInfo.attachmentCount()]);
    188             memcpy(attachmentSizes.get(), messageData, sizeof(size_t) * messageInfo.attachmentCount());
     206            size_t attachmentSizes[messageInfo.attachmentCount()];
     207            memcpy(attachmentSizes, messageData, sizeof(attachmentSizes));
    189208
    190209            messageData += sizeof(attachmentSizes);
    191210
    192             OwnArrayPtr<int> fileDescriptors = adoptArrayPtr(new int[messageInfo.attachmentCount()]);
    193             memcpy(fileDescriptors.get(), CMSG_DATA(controlMessage), sizeof(int) * messageInfo.attachmentCount());
     211            int fileDescriptors[messageInfo.attachmentCount()];
     212            memcpy(fileDescriptors, CMSG_DATA(controlMessage), sizeof(fileDescriptors));
    194213
    195214            int attachmentCount = messageInfo.attachmentCount();
     
    254273bool Connection::open()
    255274{
     275#if PLATFORM(QT)
    256276    ASSERT(!m_socketNotifier);
     277#endif
     278
    257279    int flags = fcntl(m_socketDescriptor, F_GETFL, 0);
    258280    while (fcntl(m_socketDescriptor, F_SETFL, flags | O_NONBLOCK) == -1) {
     
    264286
    265287    m_isConnected = true;
     288#if PLATFORM(QT)
    266289    m_socketNotifier = m_connectionQueue.registerSocketEventHandler(m_socketDescriptor, QSocketNotifier::Read, WorkItem::create(this, &Connection::readyReadHandler));
     290#elif PLATFORM(GTK)
     291    m_connectionQueue.registerEventSourceHandler(m_socketDescriptor, (G_IO_HUP | G_IO_ERR), WorkItem::create(this, &Connection::connectionDidClose));
     292    m_connectionQueue.registerEventSourceHandler(m_socketDescriptor, G_IO_IN, WorkItem::create(this, &Connection::readyReadHandler));
     293#endif
    267294
    268295    // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal
     
    275302bool Connection::platformCanSendOutgoingMessages() const
    276303{
    277     return m_socketNotifier;
     304    return m_isConnected;
    278305}
    279306
    280307bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEncoder> arguments)
    281308{
     309#if PLATFORM(QT)
    282310    ASSERT(m_socketNotifier);
     311#endif
     312
    283313    COMPILE_ASSERT(sizeof(MessageInfo) + attachmentMaxAmount * sizeof(size_t) <= messageMaxSize, AttachmentsFitToMessageInline);
    284314
     
    321351    iov[0].iov_len = sizeof(messageInfo);
    322352
    323     OwnArrayPtr<char> attachmentFDBuffer = adoptArrayPtr(new char[CMSG_SPACE(sizeof(int) * attachments.size())]);
    324     OwnArrayPtr<size_t> attachmentSizes = adoptArrayPtr(new size_t[attachments.size()]);
     353    char attachmentFDBuffer[CMSG_SPACE(sizeof(int) * (attachments.size()))];
     354    size_t attachmentSizes[attachments.size()];
    325355
    326356    if (!attachments.isEmpty()) {
    327         message.msg_control = attachmentFDBuffer.get();
    328         message.msg_controllen = sizeof(char) * CMSG_SPACE(sizeof(int) * attachments.size());
     357        message.msg_control = attachmentFDBuffer;
     358        message.msg_controllen = sizeof(attachmentFDBuffer);
    329359
    330360        struct cmsghdr* cmsg = CMSG_FIRSTHDR(&message);
     
    334364
    335365        int* fdptr = reinterpret_cast<int*>(CMSG_DATA(cmsg));
    336         for (int i = 0; i < attachments.size(); ++i) {
     366        for (size_t i = 0; i < attachments.size(); ++i) {
    337367            attachmentSizes[i] = attachments[i].size();
    338368            fdptr[i] = attachments[i].fileDescriptor();
     
    341371        message.msg_controllen = cmsg->cmsg_len;
    342372
    343         iov[iovLength].iov_base = attachmentSizes.get();
    344         iov[iovLength].iov_len = sizeof(size_t) * attachments.size();
     373        iov[iovLength].iov_base = attachmentSizes;
     374        iov[iovLength].iov_len = sizeof(attachmentSizes);
    345375        ++iovLength;
    346376    }
     
    362392}
    363393
     394#if PLATFORM(QT)
    364395void Connection::setShouldCloseConnectionOnProcessTermination(WebKit::PlatformProcessIdentifier process)
    365396{
    366397    m_connectionQueue.scheduleWorkOnTermination(process, WorkItem::create(this, &Connection::connectionDidClose));
    367398}
     399#endif
    368400
    369401} // namespace CoreIPC
  • trunk/Source/WebKit2/Platform/SharedMemory.h

    r82651 r83215  
    3131#include <wtf/RefCounted.h>
    3232
    33 #if PLATFORM(QT)
     33#if PLATFORM(QT) || PLATFORM(GTK)
    3434#include "Attachment.h"
    3535#include <wtf/text/WTFString.h>
     
    6161        static bool decode(CoreIPC::ArgumentDecoder*, Handle&);
    6262
    63 #if PLATFORM(QT)
     63#if PLATFORM(QT) || PLATFORM(GTK)
    6464        CoreIPC::Attachment releaseToAttachment() const;
    6565        void adoptFromAttachment(int fileDescriptor, size_t);
     
    7171#elif PLATFORM(WIN)
    7272        mutable HANDLE m_handle;
    73 #elif PLATFORM(QT)
     73#elif PLATFORM(QT) || PLATFORM(GTK)
    7474        mutable int m_fileDescriptor;
    7575#endif
     
    104104#elif PLATFORM(WIN)
    105105    HANDLE m_handle;
    106 #elif PLATFORM(QT)
     106#elif PLATFORM(QT) || PLATFORM(GTK)
    107107    int m_fileDescriptor;
    108108#endif
  • trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp

    r83214 r83215  
    3232#include "ArgumentEncoder.h"
    3333#include "WebCoreArgumentCoders.h"
    34 #include <QDir>
    3534#include <errno.h>
    3635#include <fcntl.h>
     
    4342#include <wtf/CurrentTime.h>
    4443
     44#if PLATFORM(QT)
     45#include <QDir>
     46#elif PLATFORM(GTK)
     47#include <wtf/gobject/GOwnPtr.h>
     48#endif
     49
    4550namespace WebKit {
    4651
     
    102107PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
    103108{
     109#if PLATFORM(QT)
    104110    QString tempName = QDir::temp().filePath(QLatin1String("qwkshm.XXXXXX"));
    105111    QByteArray tempNameCSTR = tempName.toLocal8Bit();
    106112    char* tempNameC = tempNameCSTR.data();
     113#elif PLATFORM(GTK)
     114    GOwnPtr<gchar> tempName(g_build_filename(g_get_tmp_dir(), "WK2SharedMemoryXXXXXX", NULL));
     115    gchar* tempNameC = tempName.get();
     116#endif
    107117
    108118    int fileDescriptor;
  • trunk/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp

    r76916 r83215  
    5050
    5151    int sockets[2];
    52     if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0) {
     52    if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) < 0) {
    5353        fprintf(stderr, "Creation of socket failed with errno %d.\n", errno);
    5454        ASSERT_NOT_REACHED();
  • trunk/Source/WebKit2/WebKit2.pro

    r82839 r83215  
    299299    Platform/CoreIPC/Connection.cpp \
    300300    Platform/CoreIPC/DataReference.cpp \
    301     Platform/CoreIPC/qt/AttachmentQt.cpp \
    302     Platform/CoreIPC/qt/ConnectionQt.cpp \
     301    Platform/CoreIPC/unix/AttachmentUnix.cpp \
     302    Platform/CoreIPC/unix/ConnectionUnix.cpp \
    303303    Platform/Logging.cpp \
    304304    Platform/Module.cpp \
     
    307307    Platform/qt/ModuleQt.cpp \
    308308    Platform/qt/RunLoopQt.cpp \
    309     Platform/qt/SharedMemoryQt.cpp \
    310309    Platform/qt/WorkQueueQt.cpp \
     310    Platform/unix/SharedMemoryUnix.cpp \
    311311    Shared/Plugins/Netscape/NetscapePluginModule.cpp \
    312312    Shared/Plugins/Netscape/NetscapePluginModuleNone.cpp \
Note: See TracChangeset for help on using the changeset viewer.