diff options
Diffstat (limited to 'Source/WebKit2/PluginProcess')
5 files changed, 70 insertions, 69 deletions
diff --git a/Source/WebKit2/PluginProcess/PluginProcess.h b/Source/WebKit2/PluginProcess/PluginProcess.h index 5ae4d359e..be34e9fce 100644 --- a/Source/WebKit2/PluginProcess/PluginProcess.h +++ b/Source/WebKit2/PluginProcess/PluginProcess.h @@ -56,6 +56,7 @@ public: #if PLATFORM(MAC) void initializeShim(); + void initializeCocoaOverrides(); void setModalWindowIsShowing(bool); void setFullscreenWindowIsShowing(bool); diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm b/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm index fab921e75..f4e834c57 100644 --- a/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm +++ b/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm @@ -36,6 +36,7 @@ #import <WebCore/LocalizedStrings.h> #import <WebKitSystemInterface.h> #import <dlfcn.h> +#import <objc/runtime.h> #import <wtf/HashSet.h> namespace WebKit { @@ -160,16 +161,6 @@ static UInt32 getCurrentEventButtonState() return 0; #endif } - -static void cocoaWindowShown(NSWindow *window) -{ - fullscreenWindowTracker().windowShown(window); -} - -static void cocoaWindowHidden(NSWindow *window) -{ - fullscreenWindowTracker().windowHidden(window); -} static void carbonWindowShown(WindowRef window) { @@ -190,14 +181,44 @@ static void setModal(bool modalWindowIsShowing) PluginProcess::shared().setModalWindowIsShowing(modalWindowIsShowing); } +static unsigned modalCount = 0; + +static void beginModal() +{ + // Make sure to make ourselves the front process + ProcessSerialNumber psn; + GetCurrentProcess(&psn); + SetFrontProcess(&psn); + + if (!modalCount++) + setModal(true); +} + +static void endModal() +{ + if (!--modalCount) + setModal(false); +} + +static IMP NSApplication_RunModalForWindow; + +static NSInteger replacedRunModalForWindow(id self, SEL _cmd, NSWindow* window) +{ + beginModal(); + NSInteger result = ((NSInteger (*)(id, SEL, NSWindow *))NSApplication_RunModalForWindow)(self, _cmd, window); + endModal(); + + return result; +} + void PluginProcess::initializeShim() { const PluginProcessShimCallbacks callbacks = { shouldCallRealDebugger, isWindowActive, getCurrentEventButtonState, - cocoaWindowShown, - cocoaWindowHidden, + beginModal, + endModal, carbonWindowShown, carbonWindowHidden, setModal, @@ -207,6 +228,30 @@ void PluginProcess::initializeShim() initFunc(callbacks); } +void PluginProcess::initializeCocoaOverrides() +{ + // Override -[NSApplication runModalForWindow:] + Method runModalForWindowMethod = class_getInstanceMethod(objc_getClass("NSApplication"), @selector(runModalForWindow:)); + NSApplication_RunModalForWindow = method_setImplementation(runModalForWindowMethod, reinterpret_cast<IMP>(replacedRunModalForWindow)); + + 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) { fullscreenWindowTracker().windowShown([notification object]); }]; + // Track when any Cocoa window is about to be hidden. + id orderOffScreenObserver = [defaultCenter addObserverForName:WKWindowWillOrderOffScreenNotification() + object:nil + queue:nil + usingBlock:^(NSNotification *notification) { fullscreenWindowTracker().windowHidden([notification object]); }]; + + // Leak the two observers so that they observe notifications for the lifetime of the process. + CFRetain(orderOnScreenObserver); + CFRetain(orderOffScreenObserver); +} + void PluginProcess::setModalWindowIsShowing(bool modalWindowIsShowing) { m_connection->send(Messages::PluginProcessProxy::SetModalWindowIsShowing(modalWindowIsShowing), 0); diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm b/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm index 732cff83a..45b56b925 100644 --- a/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm +++ b/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm @@ -116,8 +116,13 @@ int PluginProcessMain(const CommandLine& commandLine) WTF::initializeMainThread(); RunLoop::initializeMainRunLoop(); - // Initialize the shim. +#if defined(__i386__) + // Initialize the shim for 32-bit only. PluginProcess::shared().initializeShim(); +#endif + + // Initialize Cocoa overrides. + PluginProcess::shared().initializeCocoaOverrides(); // Initialize the plug-in process connection. PluginProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort), RunLoop::main()); diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h index b021a3af2..b5b597a34 100644 --- a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h +++ b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h @@ -36,8 +36,8 @@ struct PluginProcessShimCallbacks { bool (*shouldCallRealDebugger)(); bool (*isWindowActive)(WindowRef, bool& result); UInt32 (*getCurrentEventButtonState)(); - void (*cocoaWindowShown)(NSWindow *); - void (*cocoaWindowHidden)(NSWindow *); + void (*beginModal)(); + void (*endModal)(); void (*carbonWindowShown)(WindowRef); void (*carbonWindowHidden)(WindowRef); void (*setModal)(bool); diff --git a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm index fceb99b37..98476535a 100644 --- a/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm +++ b/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm @@ -42,35 +42,6 @@ extern "C" void WebKitPluginProcessShimInitialize(const PluginProcessShimCallbac 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__ #if COMPILER(CLANG) @@ -102,16 +73,16 @@ static Boolean shimIsWindowActive(WindowRef window) static void shimModalDialog(ModalFilterUPP modalFilter, DialogItemIndex *itemHit) { - beginModal(); + pluginProcessShimCallbacks.beginModal(); ModalDialog(modalFilter, itemHit); - endModal(); + pluginProcessShimCallbacks.endModal(); } static DialogItemIndex shimAlert(SInt16 alertID, ModalFilterUPP modalFilter) { - beginModal(); + pluginProcessShimCallbacks.beginModal(); DialogItemIndex index = Alert(alertID, modalFilter); - endModal(); + pluginProcessShimCallbacks.endModal(); return index; } @@ -146,27 +117,6 @@ __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 |