diff options
author | Steve Block <steveblock@google.com> | 2011-05-25 19:08:45 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-08 13:51:31 +0100 |
commit | 2bde8e466a4451c7319e3a072d118917957d6554 (patch) | |
tree | 28f4a1b869a513e565c7760d0e6a06e7cf1fe95a /Source/WebKit2/PluginProcess | |
parent | 6939c99b71d9372d14a0c74a772108052e8c48c8 (diff) | |
download | external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.zip external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.gz external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.bz2 |
Merge WebKit at r82507: Initial merge by git
Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e
Diffstat (limited to 'Source/WebKit2/PluginProcess')
12 files changed, 419 insertions, 107 deletions
diff --git a/Source/WebKit2/PluginProcess/Info.plist b/Source/WebKit2/PluginProcess/Info.plist new file mode 100644 index 0000000..cbf2492 --- /dev/null +++ b/Source/WebKit2/PluginProcess/Info.plist @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleExecutable</key> + <string>${PRODUCT_NAME}</string> + <key>CFBundleGetInfoString</key> + <string>${BUNDLE_VERSION}, Copyright 2003-2011 Apple Inc.</string> + <key>CFBundleIdentifier</key> + <string>com.apple.WebKit.${PRODUCT_NAME}</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>${PRODUCT_NAME}</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>${SHORT_VERSION_STRING}</string> + <key>CFBundleVersion</key> + <string>${BUNDLE_VERSION}</string> + <key>LSFileQuarantineEnabled</key> + <true/> + <key>LSMinimumSystemVersion</key> + <string>${MACOSX_DEPLOYMENT_TARGET}</string> + <key>LSUIElement</key> + <true/> + <key>NSPrincipalClass</key> + <string>NSApplication</string> +</dict> +</plist> diff --git a/Source/WebKit2/PluginProcess/PluginControllerProxy.cpp b/Source/WebKit2/PluginProcess/PluginControllerProxy.cpp index b140f78..03a8aec 100644 --- a/Source/WebKit2/PluginProcess/PluginControllerProxy.cpp +++ b/Source/WebKit2/PluginProcess/PluginControllerProxy.cpp @@ -78,11 +78,21 @@ bool PluginControllerProxy::initialize(const Plugin::Parameters& parameters) ASSERT(!m_plugin); m_plugin = NetscapePlugin::create(PluginProcess::shared().netscapePluginModule()); - if (!m_plugin) + if (!m_plugin) { + // This will delete the plug-in controller proxy object. + m_connection->removePluginControllerProxy(this, 0); return false; + } if (!m_plugin->initialize(this, parameters)) { + // Get the plug-in so we can pass it to removePluginControllerProxy. The pointer is only + // used as an identifier so it's OK to just get a weak reference. + Plugin* plugin = m_plugin.get(); + m_plugin = 0; + + // This will delete the plug-in controller proxy object. + m_connection->removePluginControllerProxy(this, plugin); return false; } @@ -102,13 +112,17 @@ void PluginControllerProxy::destroy() return; } + // Get the plug-in so we can pass it to removePluginControllerProxy. The pointer is only + // used as an identifier so it's OK to just get a weak reference. + Plugin* plugin = m_plugin.get(); + m_plugin->destroy(); m_plugin = 0; platformDestroy(); // This will delete the plug-in controller proxy object. - m_connection->removePluginControllerProxy(this); + m_connection->removePluginControllerProxy(this, plugin); } void PluginControllerProxy::paint() @@ -122,11 +136,16 @@ void PluginControllerProxy::paint() IntRect dirtyRect = m_dirtyRect; m_dirtyRect = IntRect(); + ASSERT(m_plugin); + // Create a graphics context. OwnPtr<GraphicsContext> graphicsContext = m_backingStore->createGraphicsContext(); + graphicsContext->translate(-m_frameRect.x(), -m_frameRect.y()); - ASSERT(m_plugin); + if (m_plugin->isTransparent()) + graphicsContext->clearRect(dirtyRect); + m_plugin->paint(graphicsContext.get(), dirtyRect); m_connection->connection()->send(Messages::PluginProxy::Update(dirtyRect), m_pluginInstanceID); @@ -199,7 +218,7 @@ NPObject* PluginControllerProxy::windowScriptNPObject() if (!windowScriptNPObjectID) return 0; - return m_connection->npRemoteObjectMap()->createNPObjectProxy(windowScriptNPObjectID); + return m_connection->npRemoteObjectMap()->createNPObjectProxy(windowScriptNPObjectID, m_plugin.get()); } NPObject* PluginControllerProxy::pluginElementNPObject() @@ -212,7 +231,7 @@ NPObject* PluginControllerProxy::pluginElementNPObject() if (!pluginElementNPObjectID) return 0; - return m_connection->npRemoteObjectMap()->createNPObjectProxy(pluginElementNPObjectID); + return m_connection->npRemoteObjectMap()->createNPObjectProxy(pluginElementNPObjectID, m_plugin.get()); } bool PluginControllerProxy::evaluate(NPObject* npObject, const String& scriptString, NPVariant* result, bool allowPopups) @@ -223,7 +242,7 @@ bool PluginControllerProxy::evaluate(NPObject* npObject, const String& scriptStr OBJECT_TO_NPVARIANT(npObject, npObjectAsNPVariant); // Send the NPObject over as an NPVariantData. - NPVariantData npObjectAsNPVariantData = m_connection->npRemoteObjectMap()->npVariantToNPVariantData(npObjectAsNPVariant); + NPVariantData npObjectAsNPVariantData = m_connection->npRemoteObjectMap()->npVariantToNPVariantData(npObjectAsNPVariant, m_plugin.get()); bool returnValue = false; NPVariantData resultData; @@ -234,7 +253,7 @@ bool PluginControllerProxy::evaluate(NPObject* npObject, const String& scriptStr if (!returnValue) return false; - *result = m_connection->npRemoteObjectMap()->npVariantDataToNPVariant(resultData); + *result = m_connection->npRemoteObjectMap()->npVariantDataToNPVariant(resultData, m_plugin.get()); return true; } @@ -321,7 +340,7 @@ 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) +void PluginControllerProxy::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect, const ShareableBitmap::Handle& backingStoreHandle) { m_frameRect = frameRect; m_clipRect = clipRect; @@ -330,7 +349,7 @@ void PluginControllerProxy::geometryDidChange(const IntRect& frameRect, const In if (!backingStoreHandle.isNull()) { // Create a new backing store. - m_backingStore = ShareableBitmap::create(frameRect.size(), backingStoreHandle); + m_backingStore = ShareableBitmap::create(backingStoreHandle); } m_plugin->geometryDidChange(frameRect, clipRect); @@ -429,7 +448,7 @@ void PluginControllerProxy::paintEntirePlugin() paint(); } -void PluginControllerProxy::snapshot(WebCore::IntSize& bufferSize, SharedMemory::Handle& backingStoreHandle) +void PluginControllerProxy::snapshot(ShareableBitmap::Handle& backingStoreHandle) { ASSERT(m_plugin); RefPtr<ShareableBitmap> bitmap = m_plugin->snapshot(); @@ -437,7 +456,6 @@ void PluginControllerProxy::snapshot(WebCore::IntSize& bufferSize, SharedMemory: return; bitmap->createHandle(backingStoreHandle); - bufferSize = bitmap->size(); } void PluginControllerProxy::setFocus(bool hasFocus) @@ -459,7 +477,7 @@ void PluginControllerProxy::getPluginScriptableNPObject(uint64_t& pluginScriptab return; } - pluginScriptableNPObjectID = m_connection->npRemoteObjectMap()->registerNPObject(pluginScriptableNPObject); + pluginScriptableNPObjectID = m_connection->npRemoteObjectMap()->registerNPObject(pluginScriptableNPObject, m_plugin.get()); releaseNPObject(pluginScriptableNPObject); } diff --git a/Source/WebKit2/PluginProcess/PluginControllerProxy.h b/Source/WebKit2/PluginProcess/PluginControllerProxy.h index e470f85..65be39e 100644 --- a/Source/WebKit2/PluginProcess/PluginControllerProxy.h +++ b/Source/WebKit2/PluginProcess/PluginControllerProxy.h @@ -32,7 +32,7 @@ #include "Plugin.h" #include "PluginController.h" #include "RunLoop.h" -#include "SharedMemory.h" +#include "ShareableBitmap.h" #include <wtf/Noncopyable.h> #if PLATFORM(MAC) @@ -105,7 +105,7 @@ private: // 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 geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, const ShareableBitmap::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); @@ -121,7 +121,7 @@ private: void handleMouseLeaveEvent(const WebMouseEvent&, bool& handled); void handleKeyboardEvent(const WebKeyboardEvent&, bool& handled); void paintEntirePlugin(); - void snapshot(WebCore::IntSize& bufferSize, SharedMemory::Handle& backingStoreHandle); + void snapshot(ShareableBitmap::Handle& backingStoreHandle); void setFocus(bool); void didUpdate(); void getPluginScriptableNPObject(uint64_t& pluginScriptableNPObjectID); diff --git a/Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in b/Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in index 91cc57f..6e27b36 100644 --- a/Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in +++ b/Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in @@ -24,7 +24,7 @@ messages -> PluginControllerProxy { # Sent when the plug-in geometry changes. - GeometryDidChange(WebCore::IntRect frameRect, WebCore::IntRect clipRect, WebKit::SharedMemory::Handle backingStoreHandle) + GeometryDidChange(WebCore::IntRect frameRect, WebCore::IntRect clipRect, WebKit::ShareableBitmap::Handle backingStoreHandle) # Sent when a frame has finished loading. FrameDidFinishLoading(uint64_t requestID) @@ -101,7 +101,7 @@ messages -> PluginControllerProxy { #endif # Return a snapshot of the plugin - Snapshot() -> (WebCore::IntSize size, WebKit::SharedMemory::Handle backingStoreHandle) + Snapshot() -> (WebKit::ShareableBitmap::Handle backingStoreHandle) # Sent when private browsing is enabled or disabled PrivateBrowsingStateChanged(bool isPrivateBrowsingEnabled) diff --git a/Source/WebKit2/PluginProcess/PluginProcess.cpp b/Source/WebKit2/PluginProcess/PluginProcess.cpp index 9a9f3bc..e35de9d 100644 --- a/Source/WebKit2/PluginProcess/PluginProcess.cpp +++ b/Source/WebKit2/PluginProcess/PluginProcess.cpp @@ -72,6 +72,11 @@ void PluginProcess::removeWebProcessConnection(WebProcessConnection* webProcessC ASSERT(vectorIndex != notFound); m_webProcessConnections.remove(vectorIndex); + + if (m_webProcessConnections.isEmpty() && m_pluginModule) { + // Decrement the load count. This is balanced by a call to incrementLoadCount in createWebProcessConnection. + m_pluginModule->decrementLoadCount(); + } startShutdownTimerIfNecessary(); } @@ -133,6 +138,8 @@ void PluginProcess::createWebProcessConnection() mach_port_t listeningPort; mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort); + bool didHaveAnyWebProcessConnections = !m_webProcessConnections.isEmpty(); + // Create a listening connection. RefPtr<WebProcessConnection> connection = WebProcessConnection::create(listeningPort); m_webProcessConnections.append(connection.release()); @@ -140,6 +147,14 @@ void PluginProcess::createWebProcessConnection() CoreIPC::MachPort clientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND); m_connection->send(Messages::PluginProcessProxy::DidCreateWebProcessConnection(clientPort), 0); + if (NetscapePluginModule* module = netscapePluginModule()) { + if (!didHaveAnyWebProcessConnections) { + // Increment the load count. This is matched by a call to decrementLoadCount in removeWebProcessConnection. + // We do this so that the plug-in module's NP_Shutdown won't be called until right before exiting. + module->incrementLoadCount(); + } + } + // Stop the shutdown timer. m_shutdownTimer.stop(); } diff --git a/Source/WebKit2/PluginProcess/PluginProcess.h b/Source/WebKit2/PluginProcess/PluginProcess.h index 3e14e5e..83c3b30 100644 --- a/Source/WebKit2/PluginProcess/PluginProcess.h +++ b/Source/WebKit2/PluginProcess/PluginProcess.h @@ -52,6 +52,9 @@ public: #if PLATFORM(MAC) void initializeShim(); + void setModalWindowIsShowing(bool); + void setFullscreenWindowIsShowing(bool); + #if USE(ACCELERATED_COMPOSITING) mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; } #endif diff --git a/Source/WebKit2/PluginProcess/WebProcessConnection.cpp b/Source/WebKit2/PluginProcess/WebProcessConnection.cpp index 07c9309..56ffbb9 100644 --- a/Source/WebKit2/PluginProcess/WebProcessConnection.cpp +++ b/Source/WebKit2/PluginProcess/WebProcessConnection.cpp @@ -52,6 +52,7 @@ WebProcessConnection::WebProcessConnection(CoreIPC::Connection::Identifier conne m_connection = CoreIPC::Connection::createServerConnection(connectionIdentifier, this, RunLoop::main()); m_npRemoteObjectMap = NPRemoteObjectMap::create(m_connection.get()); + m_connection->setOnlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(true); m_connection->open(); } @@ -70,7 +71,7 @@ void WebProcessConnection::destroyPluginControllerProxy(PluginControllerProxy* p pluginController->destroy(); } -void WebProcessConnection::removePluginControllerProxy(PluginControllerProxy* pluginController) +void WebProcessConnection::removePluginControllerProxy(PluginControllerProxy* pluginController, Plugin* plugin) { { ASSERT(m_pluginControllers.contains(pluginController->pluginInstanceID())); @@ -78,12 +79,14 @@ void WebProcessConnection::removePluginControllerProxy(PluginControllerProxy* pl OwnPtr<PluginControllerProxy> pluginControllerOwnPtr = adoptPtr(m_pluginControllers.take(pluginController->pluginInstanceID())); ASSERT(pluginControllerOwnPtr == pluginController); } - + + // Invalidate all objects related to this plug-in. + if (plugin) + m_npRemoteObjectMap->pluginDestroyed(plugin); + 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. @@ -167,13 +170,10 @@ void WebProcessConnection::createPlugin(uint64_t pluginInstanceID, const Plugin: // Now try to initialize the plug-in. result = pluginControllerProxyPtr->initialize(parameters); - if (result) { - remoteLayerClientID = pluginControllerProxyPtr->remoteLayerClientID(); + if (!result) return; - } - // We failed to initialize, remove the plug-in controller. This could cause us to be deleted. - removePluginControllerProxy(pluginControllerProxyPtr); + remoteLayerClientID = pluginControllerProxyPtr->remoteLayerClientID(); } } // namespace WebKit diff --git a/Source/WebKit2/PluginProcess/WebProcessConnection.h b/Source/WebKit2/PluginProcess/WebProcessConnection.h index 4953e61..83fe0fe 100644 --- a/Source/WebKit2/PluginProcess/WebProcessConnection.h +++ b/Source/WebKit2/PluginProcess/WebProcessConnection.h @@ -47,7 +47,7 @@ public: CoreIPC::Connection* connection() const { return m_connection.get(); } NPRemoteObjectMap* npRemoteObjectMap() const { return m_npRemoteObjectMap.get(); } - void removePluginControllerProxy(PluginControllerProxy*); + void removePluginControllerProxy(PluginControllerProxy*, Plugin*); private: WebProcessConnection(CoreIPC::Connection::Identifier); diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm b/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm index 5a54719..3a3586a 100644 --- a/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm +++ b/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm @@ -28,17 +28,98 @@ #if ENABLE(PLUGIN_PROCESS) -// FIXME (WebKit2) <rdar://problem/8728860> WebKit2 needs to be localized -#define UI_STRING(__str, __desc) [NSString stringWithUTF8String:__str] - #import "NetscapePlugin.h" #import "PluginProcessShim.h" +#import "PluginProcessProxyMessages.h" #import "PluginProcessCreationParameters.h" +#import <WebCore/LocalizedStrings.h> #import <WebKitSystemInterface.h> #import <dlfcn.h> +#import <wtf/HashSet.h> namespace WebKit { +class FullscreenWindowTracker { + WTF_MAKE_NONCOPYABLE(FullscreenWindowTracker); + +public: + FullscreenWindowTracker() { } + + template<typename T> void windowShown(T window); + template<typename T> void windowHidden(T window); + +private: + typedef HashSet<void*> WindowSet; + WindowSet m_windows; +}; + +static bool rectCoversAnyScreen(NSRect rect) +{ + for (NSScreen *screen in [NSScreen screens]) { + if (NSContainsRect(rect, [screen frame])) + return YES; + } + return NO; +} + +#ifndef NP_NO_CARBON +static bool windowCoversAnyScreen(WindowRef window) +{ + HIRect bounds; + HIWindowGetBounds(window, kWindowStructureRgn, kHICoordSpaceScreenPixel, &bounds); + + // Convert to Cocoa-style screen coordinates that use a Y offset relative to the zeroth screen's origin. + bounds.origin.y = NSHeight([[[NSScreen screens] objectAtIndex:0] frame]) - CGRectGetMaxY(bounds); + + return rectCoversAnyScreen(NSRectFromCGRect(bounds)); +} +#endif + +static bool windowCoversAnyScreen(NSWindow* window) +{ + return rectCoversAnyScreen([window frame]); +} + +template<typename T> void FullscreenWindowTracker::windowShown(T window) +{ + // If this window is already visible then there is nothing to do. + WindowSet::iterator it = m_windows.find(window); + if (it != m_windows.end()) + return; + + // If the window is not full-screen then we're not interested in it. + if (!windowCoversAnyScreen(window)) + return; + + bool windowSetWasEmpty = m_windows.isEmpty(); + + m_windows.add(window); + + // If this is the first full screen window to be shown, notify the UI process. + if (windowSetWasEmpty) + PluginProcess::shared().setFullscreenWindowIsShowing(true); +} + +template<typename T> void FullscreenWindowTracker::windowHidden(T window) +{ + // If this is not a window that we're tracking then there is nothing to do. + WindowSet::iterator it = m_windows.find(window); + if (it == m_windows.end()) + return; + + m_windows.remove(it); + + // If this was the last full screen window that was visible, notify the UI process. + if (m_windows.isEmpty()) + PluginProcess::shared().setFullscreenWindowIsShowing(false); +} + +static FullscreenWindowTracker& fullscreenWindowTracker() +{ + DEFINE_STATIC_LOCAL(FullscreenWindowTracker, fullscreenWindowTracker, ()); + return fullscreenWindowTracker; +} + static bool isUserbreakSet = false; static void initShouldCallRealDebugger() @@ -78,18 +159,62 @@ static UInt32 getCurrentEventButtonState() #endif } +static void cocoaWindowShown(NSWindow *window) +{ + fullscreenWindowTracker().windowShown(window); +} + +static void cocoaWindowHidden(NSWindow *window) +{ + fullscreenWindowTracker().windowHidden(window); +} + +static void carbonWindowShown(WindowRef window) +{ +#ifndef NP_NO_CARBON + fullscreenWindowTracker().windowShown(window); +#endif +} + +static void carbonWindowHidden(WindowRef window) +{ +#ifndef NP_NO_CARBON + fullscreenWindowTracker().windowHidden(window); +#endif +} + +static void setModal(bool modalWindowIsShowing) +{ + PluginProcess::shared().setModalWindowIsShowing(modalWindowIsShowing); +} + void PluginProcess::initializeShim() { const PluginProcessShimCallbacks callbacks = { shouldCallRealDebugger, isWindowActive, - getCurrentEventButtonState + getCurrentEventButtonState, + cocoaWindowShown, + cocoaWindowHidden, + carbonWindowShown, + carbonWindowHidden, + setModal, }; PluginProcessShimInitializeFunc initFunc = reinterpret_cast<PluginProcessShimInitializeFunc>(dlsym(RTLD_DEFAULT, "WebKitPluginProcessShimInitialize")); initFunc(callbacks); } +void PluginProcess::setModalWindowIsShowing(bool modalWindowIsShowing) +{ + m_connection->send(Messages::PluginProcessProxy::SetModalWindowIsShowing(modalWindowIsShowing), 0); +} + +void PluginProcess::setFullscreenWindowIsShowing(bool fullscreenWindowIsShowing) +{ + m_connection->send(Messages::PluginProcessProxy::SetFullscreenWindowIsShowing(fullscreenWindowIsShowing), 0); +} + void PluginProcess::platformInitialize(const PluginProcessCreationParameters& parameters) { m_compositingRenderServerPort = parameters.acceleratedCompositingPort.port(); diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.cpp b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.cpp deleted file mode 100644 index 346ead9..0000000 --- a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 index 0fbee23..b021a3a 100644 --- a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h +++ b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h @@ -26,6 +26,8 @@ #ifndef PluginProcessShim_h #define PluginProcessShim_h +@class NSWindow; + #include <Carbon/Carbon.h> namespace WebKit { @@ -34,6 +36,11 @@ struct PluginProcessShimCallbacks { bool (*shouldCallRealDebugger)(); bool (*isWindowActive)(WindowRef, bool& result); UInt32 (*getCurrentEventButtonState)(); + void (*cocoaWindowShown)(NSWindow *); + void (*cocoaWindowHidden)(NSWindow *); + void (*carbonWindowShown)(WindowRef); + void (*carbonWindowHidden)(WindowRef); + void (*setModal)(bool); }; typedef void (*PluginProcessShimInitializeFunc)(const PluginProcessShimCallbacks&); diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm new file mode 100644 index 0000000..6a32727 --- /dev/null +++ b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm @@ -0,0 +1,190 @@ +/* + * 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. + */ + +#import "PluginProcessShim.h" + +#import <AppKit/AppKit.h> +#import <Carbon/Carbon.h> +#import <WebKitSystemInterface.h> +#import <stdio.h> +#import <objc/objc-runtime.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); + +static PluginProcessShimCallbacks pluginProcessShimCallbacks; + +static IMP NSApplication_RunModalForWindow; +static unsigned modalCount = 0; + +static void beginModal() +{ + // Make sure to make ourselves the front process + ProcessSerialNumber psn; + GetCurrentProcess(&psn); + SetFrontProcess(&psn); + + if (!modalCount++) + pluginProcessShimCallbacks.setModal(true); +} + +static void endModal() +{ + if (!--modalCount) + pluginProcessShimCallbacks.setModal(false); +} + +static NSInteger shim_NSApplication_RunModalForWindow(id self, SEL _cmd, NSWindow* window) +{ + beginModal(); + NSInteger result = ((NSInteger (*)(id, SEL, NSWindow *))NSApplication_RunModalForWindow)(self, _cmd, window); + endModal(); + + return result; +} + +#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); +} + +static void shimModalDialog(ModalFilterUPP modalFilter, DialogItemIndex *itemHit) +{ + beginModal(); + ModalDialog(modalFilter, itemHit); + endModal(); +} + +static DialogItemIndex shimAlert(SInt16 alertID, ModalFilterUPP modalFilter) +{ + beginModal(); + DialogItemIndex index = Alert(alertID, modalFilter); + endModal(); + + return index; +} + +static void shimShowWindow(WindowRef window) +{ + pluginProcessShimCallbacks.carbonWindowShown(window); + ShowWindow(window); +} + +static void shimHideWindow(WindowRef window) +{ + pluginProcessShimCallbacks.carbonWindowHidden(window); + HideWindow(window); +} + +static bool isMenuBarVisible = true; + +static void shimShowMenuBar(void) +{ + isMenuBarVisible = true; + + ShowMenuBar(); +} + +static void shimHideMenuBar(void) +{ + isMenuBarVisible = false; + + // Make sure to make ourselves the front process + ProcessSerialNumber psn; + GetCurrentProcess(&psn); + SetFrontProcess(&psn); + + HideMenuBar(); +} + +static Boolean shimIsMenuBarVisible(void) +{ + return isMenuBarVisible; +} + +DYLD_INTERPOSE(shimDebugger, Debugger); +DYLD_INTERPOSE(shimGetCurrentEventButtonState, GetCurrentEventButtonState); +DYLD_INTERPOSE(shimIsWindowActive, IsWindowActive); +DYLD_INTERPOSE(shimModalDialog, ModalDialog); +DYLD_INTERPOSE(shimAlert, Alert); +DYLD_INTERPOSE(shimShowWindow, ShowWindow); +DYLD_INTERPOSE(shimHideWindow, HideWindow); +DYLD_INTERPOSE(shimShowMenuBar, ShowMenuBar) +DYLD_INTERPOSE(shimHideMenuBar, HideMenuBar) +DYLD_INTERPOSE(shimIsMenuBarVisible, IsMenuBarVisible); + +#endif + +__attribute__((visibility("default"))) +void WebKitPluginProcessShimInitialize(const PluginProcessShimCallbacks& callbacks) +{ + pluginProcessShimCallbacks = callbacks; + + // Override -[NSApplication runModalForWindow:] + Method runModalForWindowMethod = class_getInstanceMethod(objc_getClass("NSApplication"), @selector(runModalForWindow:)); + NSApplication_RunModalForWindow = method_setImplementation(runModalForWindowMethod, reinterpret_cast<IMP>(shim_NSApplication_RunModalForWindow)); + + NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; + + // Track when any Cocoa window is about to be be shown. + id orderOnScreenObserver = [defaultCenter addObserverForName:WKWindowWillOrderOnScreenNotification() + object:nil + queue:nil + usingBlock:^(NSNotification *notification) { pluginProcessShimCallbacks.cocoaWindowShown([notification object]); }]; + // Track when any cocoa window is about to be hidden. + id orderOffScreenObserver = [defaultCenter addObserverForName:WKWindowWillOrderOffScreenNotification() + object:nil + queue:nil + usingBlock:^(NSNotification *notification) { pluginProcessShimCallbacks.cocoaWindowHidden([notification object]); }]; + + // Leak the two observers so that they observe notifications for the lifetime of the process. + CFRetain(orderOnScreenObserver); + CFRetain(orderOffScreenObserver); +} + +} // namespace WebKit |