summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/PluginProcess
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/PluginProcess')
-rw-r--r--Source/WebKit2/PluginProcess/PluginControllerProxy.cpp450
-rw-r--r--Source/WebKit2/PluginProcess/PluginControllerProxy.h178
-rw-r--r--Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in107
-rw-r--r--Source/WebKit2/PluginProcess/PluginProcess.cpp150
-rw-r--r--Source/WebKit2/PluginProcess/PluginProcess.h101
-rw-r--r--Source/WebKit2/PluginProcess/PluginProcess.messages.in35
-rw-r--r--Source/WebKit2/PluginProcess/PluginProcessMain.h41
-rw-r--r--Source/WebKit2/PluginProcess/WebProcessConnection.cpp172
-rw-r--r--Source/WebKit2/PluginProcess/WebProcessConnection.h81
-rw-r--r--Source/WebKit2/PluginProcess/WebProcessConnection.messages.in33
-rw-r--r--Source/WebKit2/PluginProcess/mac/PluginControllerProxyMac.mm82
-rw-r--r--Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm89
-rw-r--r--Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm98
-rw-r--r--Source/WebKit2/PluginProcess/mac/PluginProcessShim.cpp76
-rw-r--r--Source/WebKit2/PluginProcess/mac/PluginProcessShim.h43
15 files changed, 1736 insertions, 0 deletions
diff --git a/Source/WebKit2/PluginProcess/PluginControllerProxy.cpp b/Source/WebKit2/PluginProcess/PluginControllerProxy.cpp
new file mode 100644
index 0000000..5eb8dd4
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/PluginControllerProxy.cpp
@@ -0,0 +1,450 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "PluginControllerProxy.h"
+
+#include "DataReference.h"
+#include "NPObjectProxy.h"
+#include "NPRemoteObjectMap.h"
+#include "NPRuntimeUtilities.h"
+#include "NPVariantData.h"
+#include "NetscapePlugin.h"
+#include "PluginProcess.h"
+#include "PluginProxyMessages.h"
+#include "ShareableBitmap.h"
+#include "WebCoreArgumentCoders.h"
+#include "WebProcessConnection.h"
+#include <WebCore/GraphicsContext.h>
+#include <wtf/text/WTFString.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+PassOwnPtr<PluginControllerProxy> PluginControllerProxy::create(WebProcessConnection* connection, uint64_t pluginInstanceID, const String& userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled)
+{
+ return adoptPtr(new PluginControllerProxy(connection, pluginInstanceID, userAgent, isPrivateBrowsingEnabled, isAcceleratedCompositingEnabled));
+}
+
+PluginControllerProxy::PluginControllerProxy(WebProcessConnection* connection, uint64_t pluginInstanceID, const String& userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled)
+ : m_connection(connection)
+ , m_pluginInstanceID(pluginInstanceID)
+ , m_userAgent(userAgent)
+ , m_isPrivateBrowsingEnabled(isPrivateBrowsingEnabled)
+ , m_isAcceleratedCompositingEnabled(isAcceleratedCompositingEnabled)
+ , m_paintTimer(RunLoop::main(), this, &PluginControllerProxy::paint)
+ , m_waitingForDidUpdate(false)
+ , m_pluginCanceledManualStreamLoad(false)
+#if PLATFORM(MAC)
+ , m_isComplexTextInputEnabled(false)
+#endif
+{
+}
+
+PluginControllerProxy::~PluginControllerProxy()
+{
+ ASSERT(!m_plugin);
+}
+
+bool PluginControllerProxy::initialize(const Plugin::Parameters& parameters)
+{
+ ASSERT(!m_plugin);
+
+ m_plugin = NetscapePlugin::create(PluginProcess::shared().netscapePluginModule());
+ if (!m_plugin)
+ return false;
+
+ if (!m_plugin->initialize(this, parameters)) {
+ m_plugin = 0;
+ return false;
+ }
+
+ platformInitialize();
+
+ return true;
+}
+
+void PluginControllerProxy::destroy()
+{
+ ASSERT(m_plugin);
+
+ m_plugin->destroy();
+ m_plugin = 0;
+
+ platformDestroy();
+}
+
+void PluginControllerProxy::paint()
+{
+ ASSERT(!m_dirtyRect.isEmpty());
+ m_paintTimer.stop();
+
+ if (!m_backingStore)
+ return;
+
+ IntRect dirtyRect = m_dirtyRect;
+ m_dirtyRect = IntRect();
+
+ // Create a graphics context.
+ OwnPtr<GraphicsContext> graphicsContext = m_backingStore->createGraphicsContext();
+ graphicsContext->translate(-m_frameRect.x(), -m_frameRect.y());
+
+ ASSERT(m_plugin);
+ m_plugin->paint(graphicsContext.get(), dirtyRect);
+
+ m_connection->connection()->send(Messages::PluginProxy::Update(dirtyRect), m_pluginInstanceID);
+}
+
+void PluginControllerProxy::startPaintTimer()
+{
+ // Check if we should start the timer.
+
+ if (m_dirtyRect.isEmpty())
+ return;
+
+ // FIXME: Check clip rect.
+
+ if (m_paintTimer.isActive())
+ return;
+
+ if (m_waitingForDidUpdate)
+ return;
+
+ // Start the timer.
+ m_paintTimer.startOneShot(0);
+
+ m_waitingForDidUpdate = true;
+}
+
+void PluginControllerProxy::invalidate(const IntRect& rect)
+{
+ // Convert the dirty rect to window coordinates.
+ IntRect dirtyRect = rect;
+ dirtyRect.move(m_frameRect.x(), m_frameRect.y());
+
+ // Make sure that the dirty rect is not greater than the plug-in itself.
+ dirtyRect.intersect(m_frameRect);
+
+ m_dirtyRect.unite(dirtyRect);
+
+ startPaintTimer();
+}
+
+String PluginControllerProxy::userAgent()
+{
+ return m_userAgent;
+}
+
+void PluginControllerProxy::loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target, const HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups)
+{
+ m_connection->connection()->send(Messages::PluginProxy::LoadURL(requestID, method, urlString, target, headerFields, httpBody, allowPopups), m_pluginInstanceID);
+}
+
+void PluginControllerProxy::cancelStreamLoad(uint64_t streamID)
+{
+ m_connection->connection()->send(Messages::PluginProxy::CancelStreamLoad(streamID), m_pluginInstanceID);
+}
+
+void PluginControllerProxy::cancelManualStreamLoad()
+{
+ m_pluginCanceledManualStreamLoad = true;
+
+ m_connection->connection()->send(Messages::PluginProxy::CancelManualStreamLoad(), m_pluginInstanceID);
+}
+
+NPObject* PluginControllerProxy::windowScriptNPObject()
+{
+ uint64_t windowScriptNPObjectID = 0;
+
+ if (!m_connection->connection()->sendSync(Messages::PluginProxy::GetWindowScriptNPObject(), Messages::PluginProxy::GetWindowScriptNPObject::Reply(windowScriptNPObjectID), m_pluginInstanceID))
+ return 0;
+
+ if (!windowScriptNPObjectID)
+ return 0;
+
+ return m_connection->npRemoteObjectMap()->createNPObjectProxy(windowScriptNPObjectID);
+}
+
+NPObject* PluginControllerProxy::pluginElementNPObject()
+{
+ uint64_t pluginElementNPObjectID = 0;
+
+ if (!m_connection->connection()->sendSync(Messages::PluginProxy::GetPluginElementNPObject(), Messages::PluginProxy::GetPluginElementNPObject::Reply(pluginElementNPObjectID), m_pluginInstanceID))
+ return 0;
+
+ if (!pluginElementNPObjectID)
+ return 0;
+
+ return m_connection->npRemoteObjectMap()->createNPObjectProxy(pluginElementNPObjectID);
+}
+
+bool PluginControllerProxy::evaluate(NPObject* npObject, const String& scriptString, NPVariant* result, bool allowPopups)
+{
+ NPVariant npObjectAsNPVariant;
+ OBJECT_TO_NPVARIANT(npObject, npObjectAsNPVariant);
+
+ // Send the NPObject over as an NPVariantData.
+ NPVariantData npObjectAsNPVariantData = m_connection->npRemoteObjectMap()->npVariantToNPVariantData(npObjectAsNPVariant);
+
+ bool returnValue = false;
+ NPVariantData resultData;
+
+ if (!m_connection->connection()->sendSync(Messages::PluginProxy::Evaluate(npObjectAsNPVariantData, scriptString, allowPopups), Messages::PluginProxy::Evaluate::Reply(returnValue, resultData), m_pluginInstanceID))
+ return false;
+
+ if (!returnValue)
+ return false;
+
+ *result = m_connection->npRemoteObjectMap()->npVariantDataToNPVariant(resultData);
+ return true;
+}
+
+void PluginControllerProxy::setStatusbarText(const String& statusbarText)
+{
+ m_connection->connection()->send(Messages::PluginProxy::SetStatusbarText(statusbarText), m_pluginInstanceID);
+}
+
+bool PluginControllerProxy::isAcceleratedCompositingEnabled()
+{
+ return m_isAcceleratedCompositingEnabled;
+}
+
+void PluginControllerProxy::pluginProcessCrashed()
+{
+ // This should never be called from here.
+ ASSERT_NOT_REACHED();
+}
+
+void PluginControllerProxy::setComplexTextInputEnabled(bool complexTextInputEnabled)
+{
+ if (m_isComplexTextInputEnabled == complexTextInputEnabled)
+ return;
+
+ m_isComplexTextInputEnabled = complexTextInputEnabled;
+
+ m_connection->connection()->send(Messages::PluginProxy::SetComplexTextInputEnabled(complexTextInputEnabled), m_pluginInstanceID);
+}
+
+String PluginControllerProxy::proxiesForURL(const String& urlString)
+{
+ String proxyString;
+
+ if (!m_connection->connection()->sendSync(Messages::PluginProxy::CookiesForURL(urlString), Messages::PluginProxy::CookiesForURL::Reply(proxyString), m_pluginInstanceID))
+ return String();
+
+ return proxyString;
+}
+
+String PluginControllerProxy::cookiesForURL(const String& urlString)
+{
+ String cookieString;
+
+ if (!m_connection->connection()->sendSync(Messages::PluginProxy::CookiesForURL(urlString), Messages::PluginProxy::CookiesForURL::Reply(cookieString), m_pluginInstanceID))
+ return String();
+
+ return cookieString;
+}
+
+void PluginControllerProxy::setCookiesForURL(const String& urlString, const String& cookieString)
+{
+ m_connection->connection()->send(Messages::PluginProxy::SetCookiesForURL(urlString, cookieString), m_pluginInstanceID);
+}
+
+bool PluginControllerProxy::isPrivateBrowsingEnabled()
+{
+ return m_isPrivateBrowsingEnabled;
+}
+
+void PluginControllerProxy::frameDidFinishLoading(uint64_t requestID)
+{
+ m_plugin->frameDidFinishLoading(requestID);
+}
+
+void PluginControllerProxy::frameDidFail(uint64_t requestID, bool wasCancelled)
+{
+ m_plugin->frameDidFail(requestID, wasCancelled);
+}
+
+void PluginControllerProxy::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect, const SharedMemory::Handle& backingStoreHandle)
+{
+ m_frameRect = frameRect;
+ m_clipRect = clipRect;
+
+ ASSERT(m_plugin);
+
+ if (!backingStoreHandle.isNull()) {
+ // Create a new backing store.
+ m_backingStore = ShareableBitmap::create(frameRect.size(), backingStoreHandle);
+ }
+
+ m_plugin->geometryDidChange(frameRect, clipRect);
+
+ platformGeometryDidChange(frameRect, clipRect);
+}
+
+void PluginControllerProxy::didEvaluateJavaScript(uint64_t requestID, const String& requestURLString, const String& result)
+{
+ m_plugin->didEvaluateJavaScript(requestID, requestURLString, result);
+}
+
+void PluginControllerProxy::streamDidReceiveResponse(uint64_t streamID, const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers)
+{
+ m_plugin->streamDidReceiveResponse(streamID, KURL(ParsedURLString, responseURLString), streamLength, lastModifiedTime, mimeType, headers);
+}
+
+void PluginControllerProxy::streamDidReceiveData(uint64_t streamID, const CoreIPC::DataReference& data)
+{
+ m_plugin->streamDidReceiveData(streamID, reinterpret_cast<const char*>(data.data()), data.size());
+}
+
+void PluginControllerProxy::streamDidFinishLoading(uint64_t streamID)
+{
+ m_plugin->streamDidFinishLoading(streamID);
+}
+
+void PluginControllerProxy::streamDidFail(uint64_t streamID, bool wasCancelled)
+{
+ m_plugin->streamDidFail(streamID, wasCancelled);
+}
+
+void PluginControllerProxy::manualStreamDidReceiveResponse(const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers)
+{
+ if (m_pluginCanceledManualStreamLoad)
+ return;
+
+ m_plugin->manualStreamDidReceiveResponse(KURL(ParsedURLString, responseURLString), streamLength, lastModifiedTime, mimeType, headers);
+}
+
+void PluginControllerProxy::manualStreamDidReceiveData(const CoreIPC::DataReference& data)
+{
+ if (m_pluginCanceledManualStreamLoad)
+ return;
+
+ m_plugin->manualStreamDidReceiveData(reinterpret_cast<const char*>(data.data()), data.size());
+}
+
+void PluginControllerProxy::manualStreamDidFinishLoading()
+{
+ if (m_pluginCanceledManualStreamLoad)
+ return;
+
+ m_plugin->manualStreamDidFinishLoading();
+}
+
+void PluginControllerProxy::manualStreamDidFail(bool wasCancelled)
+{
+ if (m_pluginCanceledManualStreamLoad)
+ return;
+
+ m_plugin->manualStreamDidFail(wasCancelled);
+}
+
+void PluginControllerProxy::handleMouseEvent(const WebMouseEvent& mouseEvent, bool& handled)
+{
+ handled = m_plugin->handleMouseEvent(mouseEvent);
+}
+
+void PluginControllerProxy::handleWheelEvent(const WebWheelEvent& wheelEvent, bool& handled)
+{
+ handled = m_plugin->handleWheelEvent(wheelEvent);
+}
+
+void PluginControllerProxy::handleMouseEnterEvent(const WebMouseEvent& mouseEnterEvent, bool& handled)
+{
+ handled = m_plugin->handleMouseEnterEvent(mouseEnterEvent);
+}
+
+void PluginControllerProxy::handleMouseLeaveEvent(const WebMouseEvent& mouseLeaveEvent, bool& handled)
+{
+ handled = m_plugin->handleMouseLeaveEvent(mouseLeaveEvent);
+}
+
+void PluginControllerProxy::handleKeyboardEvent(const WebKeyboardEvent& keyboardEvent, bool& handled)
+{
+ handled = m_plugin->handleKeyboardEvent(keyboardEvent);
+}
+
+void PluginControllerProxy::paintEntirePlugin()
+{
+ m_dirtyRect = m_frameRect;
+ paint();
+}
+
+void PluginControllerProxy::setFocus(bool hasFocus)
+{
+ m_plugin->setFocus(hasFocus);
+}
+
+void PluginControllerProxy::didUpdate()
+{
+ m_waitingForDidUpdate = false;
+ startPaintTimer();
+}
+
+void PluginControllerProxy::getPluginScriptableNPObject(uint64_t& pluginScriptableNPObjectID)
+{
+ NPObject* pluginScriptableNPObject = m_plugin->pluginScriptableNPObject();
+ if (!pluginScriptableNPObject) {
+ pluginScriptableNPObjectID = 0;
+ return;
+ }
+
+ pluginScriptableNPObjectID = m_connection->npRemoteObjectMap()->registerNPObject(pluginScriptableNPObject);
+ releaseNPObject(pluginScriptableNPObject);
+}
+
+#if PLATFORM(MAC)
+void PluginControllerProxy::windowFocusChanged(bool hasFocus)
+{
+ m_plugin->windowFocusChanged(hasFocus);
+}
+
+void PluginControllerProxy::windowAndViewFramesChanged(const IntRect& windowFrameInScreenCoordinates, const IntRect& viewFrameInWindowCoordinates)
+{
+ m_plugin->windowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates);
+}
+
+void PluginControllerProxy::windowVisibilityChanged(bool isVisible)
+{
+ m_plugin->windowVisibilityChanged(isVisible);
+}
+
+void PluginControllerProxy::sendComplexTextInput(const String& textInput)
+{
+ m_plugin->sendComplexTextInput(textInput);
+}
+
+#endif
+
+void PluginControllerProxy::privateBrowsingStateChanged(bool isPrivateBrowsingEnabled)
+{
+ m_plugin->privateBrowsingStateChanged(isPrivateBrowsingEnabled);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
diff --git a/Source/WebKit2/PluginProcess/PluginControllerProxy.h b/Source/WebKit2/PluginProcess/PluginControllerProxy.h
new file mode 100644
index 0000000..339c151
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/PluginControllerProxy.h
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PluginControllerProxy_h
+#define PluginControllerProxy_h
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "Connection.h"
+#include "Plugin.h"
+#include "PluginController.h"
+#include "RunLoop.h"
+#include "SharedMemory.h"
+#include <wtf/Noncopyable.h>
+
+#if PLATFORM(MAC)
+#include <wtf/RetainPtr.h>
+
+typedef struct __WKCARemoteLayerClientRef *WKCARemoteLayerClientRef;
+#endif
+
+namespace CoreIPC {
+ class DataReference;
+}
+
+namespace WebKit {
+
+class ShareableBitmap;
+class WebProcessConnection;
+
+class PluginControllerProxy : PluginController {
+ WTF_MAKE_NONCOPYABLE(PluginControllerProxy);
+
+public:
+ static PassOwnPtr<PluginControllerProxy> create(WebProcessConnection* connection, uint64_t pluginInstanceID, const String& userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled);
+ ~PluginControllerProxy();
+
+ uint64_t pluginInstanceID() const { return m_pluginInstanceID; }
+
+ bool initialize(const Plugin::Parameters&);
+ void destroy();
+
+ void didReceivePluginControllerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
+ CoreIPC::SyncReplyMode didReceiveSyncPluginControllerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
+
+#if PLATFORM(MAC)
+ uint32_t remoteLayerClientID() const;
+#endif
+
+private:
+ PluginControllerProxy(WebProcessConnection* connection, uint64_t pluginInstanceID, const String& userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled);
+
+ void startPaintTimer();
+ void paint();
+
+ // PluginController
+ virtual void invalidate(const WebCore::IntRect&);
+ virtual String userAgent();
+ virtual void loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target, const WebCore::HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups);
+ virtual void cancelStreamLoad(uint64_t streamID);
+ virtual void cancelManualStreamLoad();
+ virtual NPObject* windowScriptNPObject();
+ virtual NPObject* pluginElementNPObject();
+ virtual bool evaluate(NPObject*, const String& scriptString, NPVariant* result, bool allowPopups);
+ virtual void setStatusbarText(const String&);
+ virtual bool isAcceleratedCompositingEnabled();
+ virtual void pluginProcessCrashed();
+
+#if PLATFORM(MAC)
+ virtual void setComplexTextInputEnabled(bool);
+#endif
+
+ virtual String proxiesForURL(const String&);
+ virtual String cookiesForURL(const String&);
+ virtual void setCookiesForURL(const String& urlString, const String& cookieString);
+ virtual bool isPrivateBrowsingEnabled();
+
+ // Message handlers.
+ void frameDidFinishLoading(uint64_t requestID);
+ void frameDidFail(uint64_t requestID, bool wasCancelled);
+ void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, const SharedMemory::Handle& backingStoreHandle);
+ void didEvaluateJavaScript(uint64_t requestID, const String& requestURLString, const String& result);
+ void streamDidReceiveResponse(uint64_t streamID, const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers);
+ void streamDidReceiveData(uint64_t streamID, const CoreIPC::DataReference& data);
+ void streamDidFinishLoading(uint64_t streamID);
+ void streamDidFail(uint64_t streamID, bool wasCancelled);
+ void manualStreamDidReceiveResponse(const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers);
+ void manualStreamDidReceiveData(const CoreIPC::DataReference& data);
+ void manualStreamDidFinishLoading();
+ void manualStreamDidFail(bool wasCancelled);
+ void handleMouseEvent(const WebMouseEvent&, bool& handled);
+ void handleWheelEvent(const WebWheelEvent&, bool& handled);
+ void handleMouseEnterEvent(const WebMouseEvent&, bool& handled);
+ void handleMouseLeaveEvent(const WebMouseEvent&, bool& handled);
+ void handleKeyboardEvent(const WebKeyboardEvent&, bool& handled);
+ void paintEntirePlugin();
+ void setFocus(bool);
+ void didUpdate();
+ void getPluginScriptableNPObject(uint64_t& pluginScriptableNPObjectID);
+
+#if PLATFORM(MAC)
+ void windowFocusChanged(bool);
+ void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
+ void windowVisibilityChanged(bool);
+ void sendComplexTextInput(const String& textInput);
+#endif
+
+ void privateBrowsingStateChanged(bool);
+
+ void platformInitialize();
+ void platformDestroy();
+ void platformGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect);
+
+ WebProcessConnection* m_connection;
+ uint64_t m_pluginInstanceID;
+
+ String m_userAgent;
+ bool m_isPrivateBrowsingEnabled;
+ bool m_isAcceleratedCompositingEnabled;
+
+ RefPtr<Plugin> m_plugin;
+
+ // The plug-in rect and clip rect in window coordinates.
+ WebCore::IntRect m_frameRect;
+ WebCore::IntRect m_clipRect;
+
+ // The dirty rect in plug-in coordinates.
+ WebCore::IntRect m_dirtyRect;
+
+ // The paint timer, used for coalescing painting.
+ RunLoop::Timer<PluginControllerProxy> m_paintTimer;
+
+ // Whether we're waiting for the plug-in proxy in the web process to draw the contents of its
+ // backing store into the web process backing store.
+ bool m_waitingForDidUpdate;
+
+ // Whether the plug-in has canceled the manual stream load.
+ bool m_pluginCanceledManualStreamLoad;
+
+#if PLATFORM(MAC)
+ // Whether complex text input is enabled for this plug-in.
+ bool m_isComplexTextInputEnabled;
+
+ // For CA plug-ins, this holds the information needed to export the layer hierarchy to the UI process.
+ RetainPtr<WKCARemoteLayerClientRef> m_remoteLayerClient;
+#endif
+
+ // The backing store that this plug-in draws into.
+ RefPtr<ShareableBitmap> m_backingStore;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
+
+#endif // PluginControllerProxy_h
diff --git a/Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in b/Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in
new file mode 100644
index 0000000..60fd3df
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in
@@ -0,0 +1,107 @@
+# Copyright (C) 2010 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#if ENABLE(PLUGIN_PROCESS)
+
+messages -> PluginControllerProxy {
+ # Sent when the plug-in geometry changes.
+ GeometryDidChange(WebCore::IntRect frameRect, WebCore::IntRect clipRect, WebKit::SharedMemory::Handle backingStoreHandle)
+
+ # Sent when a frame has finished loading.
+ FrameDidFinishLoading(uint64_t requestID)
+
+ # Sent when a frame dfailed to load.
+ FrameDidFail(uint64_t requestID, bool wasCancelled)
+
+ # Sent when JavaScript that the plug-in asked to be evaluated has been evaluated.
+ DidEvaluateJavaScript(uint64_t requestID, WTF::String requestURLString, WTF::String result)
+
+ # Sent when the plug-in receives a response for a stream.
+ StreamDidReceiveResponse(uint64_t streamID, WTF::String responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, WTF::String mimeType, WTF::String headers)
+
+ # Sent when the plug-in receives data for a stream.
+ StreamDidReceiveData(uint64_t streamID, CoreIPC::DataReference data)
+
+ # Sent when a plug-in stream has finishes loading.
+ StreamDidFinishLoading(uint64_t streamID)
+
+ # Sent when a plug-in stream has failed to load.
+ StreamDidFail(uint64_t streamID, bool wasCancelled)
+
+ # Sent when the plug-in receives a response for the manual stream.
+ ManualStreamDidReceiveResponse(WTF::String responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, WTF::String mimeType, WTF::String headers)
+
+ # Sent when the plug-in receives data for the manual stream.
+ ManualStreamDidReceiveData(CoreIPC::DataReference data)
+
+ # Sent when the plug-in manual stream has finishes loading.
+ ManualStreamDidFinishLoading()
+
+ # Sent when the plug-in manual stream has failed to load.
+ ManualStreamDidFail(bool wasCancelled)
+
+ # Sent when a mouse event (that isn't a mouse enter/leave event or a wheel event) should be processed.
+ HandleMouseEvent(WebKit::WebMouseEvent mouseEvent) -> (bool handled)
+
+ # Sent when a mouse wheel event should be processed.
+ HandleWheelEvent(WebKit::WebWheelEvent wheelEvent) -> (bool handled)
+
+ # Sent when a mouse enter event should be processed.
+ HandleMouseEnterEvent(WebKit::WebMouseEvent mouseEvent) -> (bool handled)
+
+ # Sent when a mouse leave event should be processed.
+ HandleMouseLeaveEvent(WebKit::WebMouseEvent mouseEvent) -> (bool handled)
+
+ # Sent when a keyboard should be processed.
+ HandleKeyboardEvent(WebKit::WebKeyboardEvent keyboardEvent) -> (bool handled)
+
+ # Sent when the plug-in focus changes.
+ SetFocus(bool isFocused)
+
+ # Sent when the update requested by Update has been painted.
+ DidUpdate()
+
+ # Paint the entire plug-in.
+ PaintEntirePlugin() -> ()
+
+ # Get a reference to the plug-in's scriptable NPObject.
+ GetPluginScriptableNPObject() -> (uint64_t pluginScriptableNPObjectID)
+
+ # Send the complex text input to the plug-in.
+ SendComplexTextInput(WTF::String textInput)
+
+#if PLATFORM(MAC)
+ # Sent when the containing NSWindow's focus changes
+ WindowFocusChanged(bool hasFocus)
+
+ # Sent when the containing NSWindow or NSView frame changes
+ WindowAndViewFramesChanged(WebCore::IntRect windowFrameInScreenCoordinates, WebCore::IntRect viewFrameInWindowCoordinates)
+
+ # Sent when the containing NSWindow's visibility changes
+ WindowVisibilityChanged(bool isVisible)
+#endif
+
+ # Set when private browsing is enabled or disabled
+ PrivateBrowsingStateChanged(bool isPrivateBrowsingEnabled)
+}
+
+#endif
diff --git a/Source/WebKit2/PluginProcess/PluginProcess.cpp b/Source/WebKit2/PluginProcess/PluginProcess.cpp
new file mode 100644
index 0000000..6c19c21
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/PluginProcess.cpp
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "PluginProcess.h"
+
+#include "MachPort.h"
+#include "NetscapePluginModule.h"
+#include "PluginProcessProxyMessages.h"
+#include "PluginProcessCreationParameters.h"
+#include "WebProcessConnection.h"
+
+namespace WebKit {
+
+static const double shutdownTimeout = 15.0;
+
+PluginProcess& PluginProcess::shared()
+{
+ DEFINE_STATIC_LOCAL(PluginProcess, pluginProcess, ());
+ return pluginProcess;
+}
+
+PluginProcess::PluginProcess()
+ : m_shutdownTimer(RunLoop::main(), this, &PluginProcess::shutdownTimerFired)
+#if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
+ , m_compositingRenderServerPort(MACH_PORT_NULL)
+#endif
+{
+}
+
+PluginProcess::~PluginProcess()
+{
+}
+
+void PluginProcess::initializeConnection(CoreIPC::Connection::Identifier serverIdentifier)
+{
+ ASSERT(!m_connection);
+
+ m_connection = CoreIPC::Connection::createClientConnection(serverIdentifier, this, RunLoop::main());
+ m_connection->open();
+}
+
+void PluginProcess::removeWebProcessConnection(WebProcessConnection* webProcessConnection)
+{
+ size_t vectorIndex = m_webProcessConnections.find(webProcessConnection);
+ ASSERT(vectorIndex != notFound);
+
+ m_webProcessConnections.remove(vectorIndex);
+
+ if (m_webProcessConnections.isEmpty()) {
+ // Start the shutdown timer.
+ m_shutdownTimer.startOneShot(shutdownTimeout);
+ }
+}
+
+NetscapePluginModule* PluginProcess::netscapePluginModule()
+{
+ if (!m_pluginModule) {
+ ASSERT(!m_pluginPath.isNull());
+ m_pluginModule = NetscapePluginModule::getOrCreate(m_pluginPath);
+
+#if PLATFORM(MAC)
+ if (m_pluginModule) {
+ if (m_pluginModule->pluginQuirks().contains(PluginQuirks::PrognameShouldBeWebKitPluginHost))
+ setprogname("WebKitPluginHost");
+ }
+#endif
+ }
+
+ return m_pluginModule.get();
+}
+
+void PluginProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
+{
+ didReceivePluginProcessMessage(connection, messageID, arguments);
+}
+
+void PluginProcess::didClose(CoreIPC::Connection*)
+{
+ // The UI process has crashed, just go ahead and quit.
+ // FIXME: If the plug-in is spinning in the main loop, we'll never get this message.
+ RunLoop::current()->stop();
+}
+
+void PluginProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID)
+{
+}
+
+void PluginProcess::initialize(const PluginProcessCreationParameters& parameters)
+{
+ ASSERT(!m_pluginModule);
+
+ m_pluginPath = parameters.pluginPath;
+
+#if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
+ m_compositingRenderServerPort = parameters.acceleratedCompositingPort.port();
+#endif
+}
+
+void PluginProcess::createWebProcessConnection()
+{
+ // FIXME: This is platform specific!
+
+ // Create the listening port.
+ mach_port_t listeningPort;
+ mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
+
+ // Create a listening connection.
+ RefPtr<WebProcessConnection> connection = WebProcessConnection::create(listeningPort);
+ m_webProcessConnections.append(connection.release());
+
+ CoreIPC::MachPort clientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND);
+ m_connection->send(Messages::PluginProcessProxy::DidCreateWebProcessConnection(clientPort), 0);
+
+ // Stop the shutdown timer.
+ m_shutdownTimer.stop();
+}
+
+void PluginProcess::shutdownTimerFired()
+{
+ RunLoop::current()->stop();
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
+
diff --git a/Source/WebKit2/PluginProcess/PluginProcess.h b/Source/WebKit2/PluginProcess/PluginProcess.h
new file mode 100644
index 0000000..e60d52d
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/PluginProcess.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PluginProcess_h
+#define PluginProcess_h
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "ChildProcess.h"
+#include "RunLoop.h"
+#include <wtf/Forward.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+class NetscapePluginModule;
+class WebProcessConnection;
+struct PluginProcessCreationParameters;
+
+class PluginProcess : ChildProcess {
+public:
+ static PluginProcess& shared();
+
+ void initializeConnection(CoreIPC::Connection::Identifier);
+ void removeWebProcessConnection(WebProcessConnection* webProcessConnection);
+
+ NetscapePluginModule* netscapePluginModule();
+
+#if PLATFORM(MAC)
+ void initializeShim();
+
+#if USE(ACCELERATED_COMPOSITING)
+ mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }
+#endif
+#endif
+
+private:
+ PluginProcess();
+ ~PluginProcess();
+
+ // CoreIPC::Connection::Client
+ virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
+ virtual void didClose(CoreIPC::Connection*);
+ virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
+
+ // Message handlers.
+ void didReceivePluginProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
+ void initialize(const PluginProcessCreationParameters&);
+ void createWebProcessConnection();
+
+ void shutdownTimerFired();
+
+ // The connection to the UI process.
+ RefPtr<CoreIPC::Connection> m_connection;
+
+ // Our web process connections.
+ Vector<RefPtr<WebProcessConnection> > m_webProcessConnections;
+
+ // The plug-in path.
+ String m_pluginPath;
+
+ // The plug-in module.
+ RefPtr<NetscapePluginModule> m_pluginModule;
+
+ // A timer used for the shutdown timeout.
+ RunLoop::Timer<PluginProcess> m_shutdownTimer;
+
+#if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
+ // The Mach port used for accelerated compositing.
+ mach_port_t m_compositingRenderServerPort;
+#endif
+
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
+
+#endif // PluginProcess_h
diff --git a/Source/WebKit2/PluginProcess/PluginProcess.messages.in b/Source/WebKit2/PluginProcess/PluginProcess.messages.in
new file mode 100644
index 0000000..e9b0fd3
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/PluginProcess.messages.in
@@ -0,0 +1,35 @@
+# Copyright (C) 2010 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#if ENABLE(PLUGIN_PROCESS)
+
+messages -> PluginProcess {
+ # Initializes the plug-in.
+ Initialize(WebKit::PluginProcessCreationParameters processCreationParameters)
+
+ # Creates a web process connection. When the connection has been created,
+ # The plug-in process sends back a DidCreateWebProcessConnection message with
+ # a connection identifier.
+ CreateWebProcessConnection()
+}
+
+#endif
diff --git a/Source/WebKit2/PluginProcess/PluginProcessMain.h b/Source/WebKit2/PluginProcess/PluginProcessMain.h
new file mode 100644
index 0000000..3b3f38c
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/PluginProcessMain.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PluginProcessMain_h
+#define PluginProcessMain_h
+
+#if ENABLE(PLUGIN_PROCESS)
+
+namespace WebKit {
+
+class CommandLine;
+
+int PluginProcessMain(const CommandLine&);
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
+
+#endif // PluginProcessMain_h
diff --git a/Source/WebKit2/PluginProcess/WebProcessConnection.cpp b/Source/WebKit2/PluginProcess/WebProcessConnection.cpp
new file mode 100644
index 0000000..ae5d7ca
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/WebProcessConnection.cpp
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "WebProcessConnection.h"
+
+#include "NPRemoteObjectMap.h"
+#include "PluginControllerProxy.h"
+#include "PluginProcess.h"
+#include "RunLoop.h"
+
+namespace WebKit {
+
+PassRefPtr<WebProcessConnection> WebProcessConnection::create(CoreIPC::Connection::Identifier connectionIdentifier)
+{
+ return adoptRef(new WebProcessConnection(connectionIdentifier));
+}
+
+WebProcessConnection::~WebProcessConnection()
+{
+ ASSERT(m_pluginControllers.isEmpty());
+ ASSERT(!m_npRemoteObjectMap);
+ ASSERT(!m_connection);
+}
+
+WebProcessConnection::WebProcessConnection(CoreIPC::Connection::Identifier connectionIdentifier)
+{
+ m_connection = CoreIPC::Connection::createServerConnection(connectionIdentifier, this, RunLoop::main());
+ m_npRemoteObjectMap = NPRemoteObjectMap::create(m_connection.get());
+
+ m_connection->open();
+}
+
+void WebProcessConnection::addPluginControllerProxy(PassOwnPtr<PluginControllerProxy> pluginController)
+{
+ uint64_t pluginInstanceID = pluginController->pluginInstanceID();
+
+ ASSERT(!m_pluginControllers.contains(pluginInstanceID));
+ m_pluginControllers.set(pluginInstanceID, pluginController.leakPtr());
+}
+
+void WebProcessConnection::destroyPluginControllerProxy(PluginControllerProxy* pluginController)
+{
+ pluginController->destroy();
+
+ // This will delete the plug-in controller proxy object.
+ removePluginControllerProxy(pluginController);
+}
+
+void WebProcessConnection::removePluginControllerProxy(PluginControllerProxy* pluginController)
+{
+ {
+ ASSERT(m_pluginControllers.contains(pluginController->pluginInstanceID()));
+
+ OwnPtr<PluginControllerProxy> pluginControllerOwnPtr = adoptPtr(m_pluginControllers.take(pluginController->pluginInstanceID()));
+ ASSERT(pluginControllerOwnPtr == pluginController);
+ }
+
+ if (!m_pluginControllers.isEmpty())
+ return;
+
+ // Invalidate our remote object map.
+ m_npRemoteObjectMap->invalidate();
+ m_npRemoteObjectMap = nullptr;
+
+ // The last plug-in went away, close this connection.
+ m_connection->invalidate();
+ m_connection = nullptr;
+
+ // This will cause us to be deleted.
+ PluginProcess::shared().removeWebProcessConnection(this);
+}
+
+void WebProcessConnection::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
+{
+ if (!arguments->destinationID()) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ if (PluginControllerProxy* pluginControllerProxy = m_pluginControllers.get(arguments->destinationID()))
+ pluginControllerProxy->didReceivePluginControllerProxyMessage(connection, messageID, arguments);
+}
+
+CoreIPC::SyncReplyMode WebProcessConnection::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
+{
+ uint64_t destinationID = arguments->destinationID();
+
+ if (!destinationID)
+ return didReceiveSyncWebProcessConnectionMessage(connection, messageID, arguments, reply);
+
+ if (messageID.is<CoreIPC::MessageClassNPObjectMessageReceiver>())
+ return m_npRemoteObjectMap->didReceiveSyncMessage(connection, messageID, arguments, reply);
+
+ if (PluginControllerProxy* pluginControllerProxy = m_pluginControllers.get(destinationID))
+ return pluginControllerProxy->didReceiveSyncPluginControllerProxyMessage(connection, messageID, arguments, reply);
+
+ return CoreIPC::AutomaticReply;
+}
+
+void WebProcessConnection::didClose(CoreIPC::Connection*)
+{
+ // The web process crashed. Destroy all the plug-in controllers. Destroying the last plug-in controller
+ // will cause the web process connection itself to be destroyed.
+ Vector<PluginControllerProxy*> pluginControllers;
+ copyValuesToVector(m_pluginControllers, pluginControllers);
+
+ for (size_t i = 0; i < pluginControllers.size(); ++i)
+ destroyPluginControllerProxy(pluginControllers[i]);
+}
+
+void WebProcessConnection::destroyPlugin(uint64_t pluginInstanceID)
+{
+ PluginControllerProxy* pluginControllerProxy = m_pluginControllers.get(pluginInstanceID);
+ ASSERT(pluginControllerProxy);
+
+ destroyPluginControllerProxy(pluginControllerProxy);
+}
+
+void WebProcessConnection::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID)
+{
+ // FIXME: Implement.
+}
+
+void WebProcessConnection::createPlugin(uint64_t pluginInstanceID, const Plugin::Parameters& parameters, const String& userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled, bool& result, uint32_t& remoteLayerClientID)
+{
+ OwnPtr<PluginControllerProxy> pluginControllerProxy = PluginControllerProxy::create(this, pluginInstanceID, userAgent, isPrivateBrowsingEnabled, isAcceleratedCompositingEnabled);
+
+ PluginControllerProxy* pluginControllerProxyPtr = pluginControllerProxy.get();
+
+ // Make sure to add the proxy to the map before initializing it, since the plug-in might call out to the web process from
+ // its NPP_New function. This will hand over ownership of the proxy to the web process connection.
+ addPluginControllerProxy(pluginControllerProxy.release());
+
+ // Now try to initialize the plug-in.
+ result = pluginControllerProxyPtr->initialize(parameters);
+
+ if (result) {
+ remoteLayerClientID = pluginControllerProxyPtr->remoteLayerClientID();
+ return;
+ }
+
+ // We failed to initialize, remove the plug-in controller. This could cause us to be deleted.
+ removePluginControllerProxy(pluginControllerProxyPtr);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
diff --git a/Source/WebKit2/PluginProcess/WebProcessConnection.h b/Source/WebKit2/PluginProcess/WebProcessConnection.h
new file mode 100644
index 0000000..d965e49
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/WebProcessConnection.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebProcessConnection_h
+#define WebProcessConnection_h
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "Connection.h"
+#include "Plugin.h"
+#include <wtf/RefCounted.h>
+
+namespace WebKit {
+
+class NPRemoteObjectMap;
+class PluginControllerProxy;
+
+// A connection from a plug-in process to a web process.
+
+class WebProcessConnection : public RefCounted<WebProcessConnection>, CoreIPC::Connection::Client {
+public:
+ static PassRefPtr<WebProcessConnection> create(CoreIPC::Connection::Identifier);
+ virtual ~WebProcessConnection();
+
+ CoreIPC::Connection* connection() const { return m_connection.get(); }
+
+ NPRemoteObjectMap* npRemoteObjectMap() const { return m_npRemoteObjectMap.get(); }
+
+private:
+ WebProcessConnection(CoreIPC::Connection::Identifier);
+
+ void addPluginControllerProxy(PassOwnPtr<PluginControllerProxy>);
+ void removePluginControllerProxy(PluginControllerProxy*);
+
+ void destroyPluginControllerProxy(PluginControllerProxy*);
+
+ // CoreIPC::Connection::Client
+ virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
+ virtual CoreIPC::SyncReplyMode didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
+ virtual void didClose(CoreIPC::Connection*);
+ virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
+
+ // Message handlers.
+ CoreIPC::SyncReplyMode didReceiveSyncWebProcessConnectionMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
+ void createPlugin(uint64_t pluginInstanceID, const Plugin::Parameters&, const String& userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled, bool& result, uint32_t& remoteLayerClientID);
+ void destroyPlugin(uint64_t pluginInstanceID);
+
+ RefPtr<CoreIPC::Connection> m_connection;
+
+ HashMap<uint64_t, PluginControllerProxy*> m_pluginControllers;
+ RefPtr<NPRemoteObjectMap> m_npRemoteObjectMap;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
+
+
+#endif // WebProcessConnection_h
diff --git a/Source/WebKit2/PluginProcess/WebProcessConnection.messages.in b/Source/WebKit2/PluginProcess/WebProcessConnection.messages.in
new file mode 100644
index 0000000..1240074
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/WebProcessConnection.messages.in
@@ -0,0 +1,33 @@
+# Copyright (C) 2010 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#if ENABLE(PLUGIN_PROCESS)
+
+messages -> WebProcessConnection {
+ # Creates a plug-in instance with the given instance ID.
+ CreatePlugin(uint64_t pluginInstanceID, WebKit::Plugin::Parameters parameters, WTF::String userAgent, bool isPrivateBrowsingEnabled, bool isAcceleratedCompositingEnabled) -> (bool result, uint32_t remoteLayerClientID)
+
+ # Destroys the plug-in instance with the given instance ID.
+ DestroyPlugin(uint64_t pluginInstanceID) -> ()
+}
+
+#endif
diff --git a/Source/WebKit2/PluginProcess/mac/PluginControllerProxyMac.mm b/Source/WebKit2/PluginProcess/mac/PluginControllerProxyMac.mm
new file mode 100644
index 0000000..40d4f6d
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/mac/PluginControllerProxyMac.mm
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "PluginControllerProxy.h"
+
+#include <QuartzCore/QuartzCore.h>
+#include "PluginProcess.h"
+#include "WebKitSystemInterface.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void PluginControllerProxy::platformInitialize()
+{
+ CALayer * platformLayer = m_plugin->pluginLayer();
+ if (!platformLayer)
+ return;
+
+ ASSERT(!m_remoteLayerClient);
+
+ m_remoteLayerClient = WKCARemoteLayerClientMakeWithServerPort(PluginProcess::shared().compositingRenderServerPort());
+ ASSERT(m_remoteLayerClient);
+
+ WKCARemoteLayerClientSetLayer(m_remoteLayerClient.get(), platformLayer);
+}
+
+void PluginControllerProxy::platformDestroy()
+{
+ if (!m_remoteLayerClient)
+ return;
+
+ WKCARemoteLayerClientInvalidate(m_remoteLayerClient.get());
+ m_remoteLayerClient = nullptr;
+}
+
+uint32_t PluginControllerProxy::remoteLayerClientID() const
+{
+ if (!m_remoteLayerClient)
+ return 0;
+
+ return WKCARemoteLayerClientGetClientId(m_remoteLayerClient.get());
+}
+
+void PluginControllerProxy::platformGeometryDidChange(const IntRect& frameRect, const IntRect&)
+{
+ CALayer * pluginLayer = m_plugin->pluginLayer();
+
+ // We don't want to animate to the new size so we disable actions for this transaction.
+ [CATransaction begin];
+ [CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
+ [pluginLayer setFrame:CGRectMake(0, 0, frameRect.width(), frameRect.height())];
+ [CATransaction commit];
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm b/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm
new file mode 100644
index 0000000..ccf444c
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "PluginProcess.h"
+
+#include "NetscapePlugin.h"
+#include "PluginProcessShim.h"
+#include <dlfcn.h>
+
+namespace WebKit {
+
+static bool isUserbreakSet = false;
+
+static void initShouldCallRealDebugger()
+{
+ char* var = getenv("USERBREAK");
+
+ if (var)
+ isUserbreakSet = atoi(var);
+}
+
+static bool shouldCallRealDebugger()
+{
+ static pthread_once_t shouldCallRealDebuggerOnce = PTHREAD_ONCE_INIT;
+ pthread_once(&shouldCallRealDebuggerOnce, initShouldCallRealDebugger);
+
+ return isUserbreakSet;
+}
+
+static bool isWindowActive(WindowRef windowRef, bool& result)
+{
+#ifndef NP_NO_CARBON
+ if (NetscapePlugin* plugin = NetscapePlugin::netscapePluginFromWindow(windowRef)) {
+ result = plugin->isWindowActive();
+ return true;
+ }
+#endif
+ return false;
+}
+
+static UInt32 getCurrentEventButtonState()
+{
+#ifndef NP_NO_CARBON
+ return NetscapePlugin::buttonState();
+#else
+ ASSERT_NOT_REACHED();
+ return 0;
+#endif
+}
+
+void PluginProcess::initializeShim()
+{
+ const PluginProcessShimCallbacks callbacks = {
+ shouldCallRealDebugger,
+ isWindowActive,
+ getCurrentEventButtonState
+ };
+
+ PluginProcessShimInitializeFunc initFunc = reinterpret_cast<PluginProcessShimInitializeFunc>(dlsym(RTLD_DEFAULT, "WebKitPluginProcessShimInitialize"));
+ initFunc(callbacks);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(PLUGIN_PROCESS)
diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm b/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm
new file mode 100644
index 0000000..36cc2a1
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(PLUGIN_PROCESS)
+
+#include "PluginProcessMain.h"
+
+#include "CommandLine.h"
+#include "PluginProcess.h"
+#include "RunLoop.h"
+#include <runtime/InitializeThreading.h>
+#include <servers/bootstrap.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+#include <WebKitSystemInterface.h>
+
+// FIXME: We should be doing this another way.
+extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t);
+
+#define SHOW_CRASH_REPORTER 1
+
+namespace WebKit {
+
+// FIXME: There is much code here that is duplicated in WebProcessMainMac.mm, we should add a shared base class where
+// we can put everything.
+
+int PluginProcessMain(const CommandLine& commandLine)
+{
+ // Unset DYLD_INSERT_LIBRARIES. We don't want our plug-in process shim to be loaded
+ // by any child processes that the plug-in may launch.
+ unsetenv("DYLD_INSERT_LIBRARIES");
+
+ String serviceName = commandLine["servicename"];
+ if (serviceName.isEmpty())
+ return EXIT_FAILURE;
+
+ // Get the server port.
+ mach_port_t serverPort;
+ kern_return_t kr = bootstrap_look_up2(bootstrap_port, serviceName.utf8().data(), &serverPort, 0, 0);
+ if (kr) {
+ printf("bootstrap_look_up2 result: %x", kr);
+ return EXIT_FAILURE;
+ }
+
+#if !SHOW_CRASH_REPORTER
+ // Installs signal handlers that exit on a crash so that CrashReporter does not show up.
+ signal(SIGILL, _exit);
+ signal(SIGFPE, _exit);
+ signal(SIGBUS, _exit);
+ signal(SIGSEGV, _exit);
+#endif
+
+ // FIXME: It would be better to proxy set cursor calls over to the UI process instead of
+ // allowing plug-ins to change the mouse cursor at any time.
+ WKEnableSettingCursorWhenInBackground();
+
+ JSC::initializeThreading();
+ WTF::initializeMainThread();
+ RunLoop::initializeMainRunLoop();
+
+ // Initialize the shim.
+ PluginProcess::shared().initializeShim();
+
+ // Initialize the plug-in process connection.
+ PluginProcess::shared().initializeConnection(serverPort);
+
+ [NSApplication sharedApplication];
+
+ RunLoop::run();
+
+ return 0;
+}
+
+}
+
+#endif // ENABLE(PLUGIN_PROCESS)
diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.cpp b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.cpp
new file mode 100644
index 0000000..346ead9
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "PluginProcessShim.h"
+
+#include <Carbon/Carbon.h>
+#include <stdio.h>
+
+#define DYLD_INTERPOSE(_replacement,_replacee) \
+ __attribute__((used)) static struct{ const void* replacement; const void* replacee; } _interpose_##_replacee \
+ __attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacement, (const void*)(unsigned long)&_replacee };
+
+namespace WebKit {
+
+extern "C" void WebKitPluginProcessShimInitialize(const PluginProcessShimCallbacks& callbacks);
+
+PluginProcessShimCallbacks pluginProcessShimCallbacks;
+
+__attribute__((visibility("default")))
+void WebKitPluginProcessShimInitialize(const PluginProcessShimCallbacks& callbacks)
+{
+ pluginProcessShimCallbacks = callbacks;
+}
+
+#ifndef __LP64__
+static void shimDebugger(void)
+{
+ if (!pluginProcessShimCallbacks.shouldCallRealDebugger())
+ return;
+
+ Debugger();
+}
+
+static UInt32 shimGetCurrentEventButtonState()
+{
+ return pluginProcessShimCallbacks.getCurrentEventButtonState();
+}
+
+static Boolean shimIsWindowActive(WindowRef window)
+{
+ bool result;
+ if (pluginProcessShimCallbacks.isWindowActive(window, result))
+ return result;
+
+ return IsWindowActive(window);
+}
+
+DYLD_INTERPOSE(shimDebugger, Debugger);
+DYLD_INTERPOSE(shimGetCurrentEventButtonState, GetCurrentEventButtonState);
+DYLD_INTERPOSE(shimIsWindowActive, IsWindowActive);
+
+#endif
+
+} // namespace WebKit
diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h
new file mode 100644
index 0000000..0fbee23
--- /dev/null
+++ b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PluginProcessShim_h
+#define PluginProcessShim_h
+
+#include <Carbon/Carbon.h>
+
+namespace WebKit {
+
+struct PluginProcessShimCallbacks {
+ bool (*shouldCallRealDebugger)();
+ bool (*isWindowActive)(WindowRef, bool& result);
+ UInt32 (*getCurrentEventButtonState)();
+};
+
+typedef void (*PluginProcessShimInitializeFunc)(const PluginProcessShimCallbacks&);
+
+}
+
+#endif // PluginProcessShim_h