Changeset 83215 in webkit
- Timestamp:
- Apr 7, 2011 3:11:08 PM (13 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 2 added
- 1 deleted
- 9 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r83211 r83215 1 2011-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 1 27 2011-04-07 Alexey Proskuryakov <ap@apple.com> 2 28 -
trunk/Source/WebKit2/GNUmakefile.am
r82929 r83215 94 94 Source/WebKit2/Platform/CoreIPC/DataReference.cpp \ 95 95 Source/WebKit2/Platform/CoreIPC/DataReference.h \ 96 Source/WebKit2/Platform/CoreIPC/gtk/ConnectionGtk.cpp \97 96 Source/WebKit2/Platform/CoreIPC/HandleMessage.h \ 98 97 Source/WebKit2/Platform/CoreIPC/MessageID.h \ 99 98 Source/WebKit2/Platform/CoreIPC/MessageSender.h \ 99 Source/WebKit2/Platform/CoreIPC/unix/AttachmentUnix.cpp \ 100 Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp \ 100 101 Source/WebKit2/Platform/gtk/ModuleGtk.cpp \ 101 102 Source/WebKit2/Platform/gtk/RunLoopGtk.cpp \ 102 Source/WebKit2/Platform/gtk/SharedMemoryGtk.cpp \103 103 Source/WebKit2/Platform/gtk/WorkQueueGtk.cpp \ 104 104 Source/WebKit2/Platform/Logging.cpp \ … … 110 110 Source/WebKit2/Platform/RunLoop.h \ 111 111 Source/WebKit2/Platform/SharedMemory.h \ 112 Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp \ 112 113 Source/WebKit2/Platform/WorkItem.h \ 113 114 Source/WebKit2/Platform/WorkQueue.cpp \ -
trunk/Source/WebKit2/Platform/CoreIPC/ArgumentDecoder.cpp
r82285 r83215 48 48 ASSERT(m_buffer); 49 49 fastFree(m_buffer); 50 #if !PLATFORM(QT) 50 #if !PLATFORM(QT) && !PLATFORM(GTK) 51 51 // FIXME: We need to dispose of the mach ports in cases of failure. 52 52 #else -
trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.cpp
r82285 r83215 51 51 if (m_buffer) 52 52 fastFree(m_buffer); 53 #if !PLATFORM(QT) 53 #if !PLATFORM(QT) && !PLATFORM(GTK) 54 54 // FIXME: We need to dispose of the attachments in cases of failure. 55 55 #else -
trunk/Source/WebKit2/Platform/CoreIPC/Attachment.h
r76507 r83215 41 41 MachPortType, 42 42 MachOOLMemoryType 43 #elif PLATFORM(QT) 43 #elif PLATFORM(QT) || PLATFORM(GTK) 44 44 MappedMemory 45 45 #endif … … 49 49 Attachment(mach_port_name_t port, mach_msg_type_name_t disposition); 50 50 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) 52 52 Attachment(int fileDescriptor, size_t); 53 53 #endif … … 67 67 mach_msg_copy_options_t copyOptions() const { ASSERT(m_type == MachOOLMemoryType); return m_oolMemory.copyOptions; } 68 68 bool deallocate() const { ASSERT(m_type == MachOOLMemoryType); return m_oolMemory.deallocate; } 69 #elif PLATFORM(QT) 69 #elif PLATFORM(QT) || PLATFORM(GTK) 70 70 size_t size() const { return m_size; } 71 71 … … 95 95 } m_oolMemory; 96 96 }; 97 #elif PLATFORM(QT) 97 #elif PLATFORM(QT) || PLATFORM(GTK) 98 98 int m_fileDescriptor; 99 99 size_t m_size; -
trunk/Source/WebKit2/Platform/CoreIPC/Connection.h
r82045 r83215 306 306 OVERLAPPED m_writeState; 307 307 HANDLE m_connectionPipe; 308 #elif PLATFORM(QT) 308 #elif PLATFORM(QT) || PLATFORM(GTK) 309 309 // Called on the connection queue. 310 310 void readyReadHandler(); … … 312 312 Vector<uint8_t> m_readBuffer; 313 313 size_t m_currentMessageSize; 314 int m_socketDescriptor; 315 316 #if PLATFORM(QT) 314 317 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 325 319 #endif 326 320 }; -
trunk/Source/WebKit2/Platform/CoreIPC/unix/AttachmentUnix.cpp
r83214 r83215 28 28 #include "Attachment.h" 29 29 30 #if PLATFORM(QT)31 30 #include <unistd.h> 32 31 #include <errno.h> 33 #endif34 35 32 36 33 namespace CoreIPC { -
trunk/Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp
r83214 r83215 33 33 #include "SharedMemory.h" 34 34 #include "WebProcessProxy.h" 35 #include <QApplication>36 #include <QSocketNotifier>37 35 #include <sys/socket.h> 38 36 #include <unistd.h> … … 41 39 #include <wtf/Assertions.h> 42 40 41 #if PLATFORM(QT) 42 #include <QApplication> 43 #include <QSocketNotifier> 44 #elif PLATFORM(GTK) 45 #include <glib.h> 46 #endif 47 43 48 using namespace std; 44 49 … … 49 54 50 55 enum { 51 MessageBodyIsOOL = 1 U<< 3156 MessageBodyIsOOL = 1 << 31 52 57 }; 53 58 … … 89 94 { 90 95 m_socketDescriptor = identifier; 91 m_socketNotifier = 0;92 96 m_readBuffer.resize(messageMaxSize); 93 97 m_currentMessageSize = 0; 98 99 #if PLATFORM(QT) 100 m_socketNotifier = 0; 101 #endif 94 102 } 95 103 … … 102 110 return; 103 111 112 #if PLATFORM(GTK) 113 m_connectionQueue.unregisterEventSourceHandler(m_socketDescriptor); 114 #endif 115 116 #if PLATFORM(QT) 104 117 delete m_socketNotifier; 105 118 m_socketNotifier = 0; 119 #endif 120 106 121 m_socketDescriptor = -1; 107 122 m_isConnected = false; 108 123 } 109 124 125 #if PLATFORM(QT) 110 126 class SocketNotifierResourceGuard { 111 127 public: … … 124 140 QSocketNotifier* const m_socketNotifier; 125 141 }; 142 #endif 126 143 127 144 template<class T, class iterator> … … 145 162 { 146 163 Deque<Attachment> attachments; 164 #if PLATFORM(QT) 147 165 SocketNotifierResourceGuard socketNotifierEnabler(m_socketNotifier); 166 #endif 148 167 AttachmentResourceGuard<Deque<Attachment>, Deque<Attachment>::iterator> attachementDisposer(attachments); 149 168 150 OwnArrayPtr<char> attachmentDescriptorBuffer = adoptArrayPtr(new char[CMSG_SPACE(sizeof(int) * (attachmentMaxAmount))]);169 char attachmentDescriptorBuffer[CMSG_SPACE(sizeof(int) * (attachmentMaxAmount))]; 151 170 struct msghdr message; 152 171 memset(&message, 0, sizeof(message)); … … 155 174 memset(&iov, 0, sizeof(iov)); 156 175 157 message.msg_control = attachmentDescriptorBuffer .get();176 message.msg_control = attachmentDescriptorBuffer; 158 177 message.msg_controllen = CMSG_SPACE(sizeof(int) * (attachmentMaxAmount)); 159 178 … … 185 204 if (messageInfo.attachmentCount()) { 186 205 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)); 189 208 190 209 messageData += sizeof(attachmentSizes); 191 210 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)); 194 213 195 214 int attachmentCount = messageInfo.attachmentCount(); … … 254 273 bool Connection::open() 255 274 { 275 #if PLATFORM(QT) 256 276 ASSERT(!m_socketNotifier); 277 #endif 278 257 279 int flags = fcntl(m_socketDescriptor, F_GETFL, 0); 258 280 while (fcntl(m_socketDescriptor, F_SETFL, flags | O_NONBLOCK) == -1) { … … 264 286 265 287 m_isConnected = true; 288 #if PLATFORM(QT) 266 289 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 267 294 268 295 // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal … … 275 302 bool Connection::platformCanSendOutgoingMessages() const 276 303 { 277 return m_ socketNotifier;304 return m_isConnected; 278 305 } 279 306 280 307 bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEncoder> arguments) 281 308 { 309 #if PLATFORM(QT) 282 310 ASSERT(m_socketNotifier); 311 #endif 312 283 313 COMPILE_ASSERT(sizeof(MessageInfo) + attachmentMaxAmount * sizeof(size_t) <= messageMaxSize, AttachmentsFitToMessageInline); 284 314 … … 321 351 iov[0].iov_len = sizeof(messageInfo); 322 352 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()]; 325 355 326 356 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); 329 359 330 360 struct cmsghdr* cmsg = CMSG_FIRSTHDR(&message); … … 334 364 335 365 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) { 337 367 attachmentSizes[i] = attachments[i].size(); 338 368 fdptr[i] = attachments[i].fileDescriptor(); … … 341 371 message.msg_controllen = cmsg->cmsg_len; 342 372 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); 345 375 ++iovLength; 346 376 } … … 362 392 } 363 393 394 #if PLATFORM(QT) 364 395 void Connection::setShouldCloseConnectionOnProcessTermination(WebKit::PlatformProcessIdentifier process) 365 396 { 366 397 m_connectionQueue.scheduleWorkOnTermination(process, WorkItem::create(this, &Connection::connectionDidClose)); 367 398 } 399 #endif 368 400 369 401 } // namespace CoreIPC -
trunk/Source/WebKit2/Platform/SharedMemory.h
r82651 r83215 31 31 #include <wtf/RefCounted.h> 32 32 33 #if PLATFORM(QT) 33 #if PLATFORM(QT) || PLATFORM(GTK) 34 34 #include "Attachment.h" 35 35 #include <wtf/text/WTFString.h> … … 61 61 static bool decode(CoreIPC::ArgumentDecoder*, Handle&); 62 62 63 #if PLATFORM(QT) 63 #if PLATFORM(QT) || PLATFORM(GTK) 64 64 CoreIPC::Attachment releaseToAttachment() const; 65 65 void adoptFromAttachment(int fileDescriptor, size_t); … … 71 71 #elif PLATFORM(WIN) 72 72 mutable HANDLE m_handle; 73 #elif PLATFORM(QT) 73 #elif PLATFORM(QT) || PLATFORM(GTK) 74 74 mutable int m_fileDescriptor; 75 75 #endif … … 104 104 #elif PLATFORM(WIN) 105 105 HANDLE m_handle; 106 #elif PLATFORM(QT) 106 #elif PLATFORM(QT) || PLATFORM(GTK) 107 107 int m_fileDescriptor; 108 108 #endif -
trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp
r83214 r83215 32 32 #include "ArgumentEncoder.h" 33 33 #include "WebCoreArgumentCoders.h" 34 #include <QDir>35 34 #include <errno.h> 36 35 #include <fcntl.h> … … 43 42 #include <wtf/CurrentTime.h> 44 43 44 #if PLATFORM(QT) 45 #include <QDir> 46 #elif PLATFORM(GTK) 47 #include <wtf/gobject/GOwnPtr.h> 48 #endif 49 45 50 namespace WebKit { 46 51 … … 102 107 PassRefPtr<SharedMemory> SharedMemory::create(size_t size) 103 108 { 109 #if PLATFORM(QT) 104 110 QString tempName = QDir::temp().filePath(QLatin1String("qwkshm.XXXXXX")); 105 111 QByteArray tempNameCSTR = tempName.toLocal8Bit(); 106 112 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 107 117 108 118 int fileDescriptor; -
trunk/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp
r76916 r83215 50 50 51 51 int sockets[2]; 52 if (socketpair(AF_UNIX, SOCK_ STREAM, 0, sockets) < 0) {52 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) < 0) { 53 53 fprintf(stderr, "Creation of socket failed with errno %d.\n", errno); 54 54 ASSERT_NOT_REACHED(); -
trunk/Source/WebKit2/WebKit2.pro
r82839 r83215 299 299 Platform/CoreIPC/Connection.cpp \ 300 300 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 \ 303 303 Platform/Logging.cpp \ 304 304 Platform/Module.cpp \ … … 307 307 Platform/qt/ModuleQt.cpp \ 308 308 Platform/qt/RunLoopQt.cpp \ 309 Platform/qt/SharedMemoryQt.cpp \310 309 Platform/qt/WorkQueueQt.cpp \ 310 Platform/unix/SharedMemoryUnix.cpp \ 311 311 Shared/Plugins/Netscape/NetscapePluginModule.cpp \ 312 312 Shared/Plugins/Netscape/NetscapePluginModuleNone.cpp \
Note: See TracChangeset
for help on using the changeset viewer.