2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
28 #import "PluginProcess.h"
30 #if ENABLE(PLUGIN_PROCESS)
32 #import "NetscapePlugin.h"
33 #import "PluginProcessShim.h"
34 #import "PluginProcessProxyMessages.h"
35 #import "PluginProcessCreationParameters.h"
36 #import <WebCore/LocalizedStrings.h>
37 #import <WebKitSystemInterface.h>
39 #import <wtf/HashSet.h>
43 static pthread_once_t shouldCallRealDebuggerOnce = PTHREAD_ONCE_INIT;
45 class FullscreenWindowTracker {
46 WTF_MAKE_NONCOPYABLE(FullscreenWindowTracker);
49 FullscreenWindowTracker() { }
51 template<typename T> void windowShown(T window);
52 template<typename T> void windowHidden(T window);
55 typedef HashSet<void*> WindowSet;
59 static bool rectCoversAnyScreen(NSRect rect)
61 for (NSScreen *screen in [NSScreen screens]) {
62 if (NSContainsRect(rect, [screen frame]))
69 static bool windowCoversAnyScreen(WindowRef window)
72 HIWindowGetBounds(window, kWindowStructureRgn, kHICoordSpaceScreenPixel, &bounds);
74 // Convert to Cocoa-style screen coordinates that use a Y offset relative to the zeroth screen's origin.
75 bounds.origin.y = NSHeight([(NSScreen *)[[NSScreen screens] objectAtIndex:0] frame]) - CGRectGetMaxY(bounds);
77 return rectCoversAnyScreen(NSRectFromCGRect(bounds));
81 static bool windowCoversAnyScreen(NSWindow* window)
83 return rectCoversAnyScreen([window frame]);
86 template<typename T> void FullscreenWindowTracker::windowShown(T window)
88 // If this window is already visible then there is nothing to do.
89 WindowSet::iterator it = m_windows.find(window);
90 if (it != m_windows.end())
93 // If the window is not full-screen then we're not interested in it.
94 if (!windowCoversAnyScreen(window))
97 bool windowSetWasEmpty = m_windows.isEmpty();
99 m_windows.add(window);
101 // If this is the first full screen window to be shown, notify the UI process.
102 if (windowSetWasEmpty)
103 PluginProcess::shared().setFullscreenWindowIsShowing(true);
106 template<typename T> void FullscreenWindowTracker::windowHidden(T window)
108 // If this is not a window that we're tracking then there is nothing to do.
109 WindowSet::iterator it = m_windows.find(window);
110 if (it == m_windows.end())
113 m_windows.remove(it);
115 // If this was the last full screen window that was visible, notify the UI process.
116 if (m_windows.isEmpty())
117 PluginProcess::shared().setFullscreenWindowIsShowing(false);
120 static FullscreenWindowTracker& fullscreenWindowTracker()
122 DEFINE_STATIC_LOCAL(FullscreenWindowTracker, fullscreenWindowTracker, ());
123 return fullscreenWindowTracker;
126 static bool isUserbreakSet = false;
128 static void initShouldCallRealDebugger()
130 char* var = getenv("USERBREAK");
133 isUserbreakSet = atoi(var);
136 static bool shouldCallRealDebugger()
138 pthread_once(&shouldCallRealDebuggerOnce, initShouldCallRealDebugger);
140 return isUserbreakSet;
143 static bool isWindowActive(WindowRef windowRef, bool& result)
146 if (NetscapePlugin* plugin = NetscapePlugin::netscapePluginFromWindow(windowRef)) {
147 result = plugin->isWindowActive();
154 static UInt32 getCurrentEventButtonState()
157 return NetscapePlugin::buttonState();
159 ASSERT_NOT_REACHED();
164 static void cocoaWindowShown(NSWindow *window)
166 fullscreenWindowTracker().windowShown(window);
169 static void cocoaWindowHidden(NSWindow *window)
171 fullscreenWindowTracker().windowHidden(window);
174 static void carbonWindowShown(WindowRef window)
177 fullscreenWindowTracker().windowShown(window);
181 static void carbonWindowHidden(WindowRef window)
184 fullscreenWindowTracker().windowHidden(window);
188 static void setModal(bool modalWindowIsShowing)
190 PluginProcess::shared().setModalWindowIsShowing(modalWindowIsShowing);
193 void PluginProcess::initializeShim()
195 const PluginProcessShimCallbacks callbacks = {
196 shouldCallRealDebugger,
198 getCurrentEventButtonState,
206 PluginProcessShimInitializeFunc initFunc = reinterpret_cast<PluginProcessShimInitializeFunc>(dlsym(RTLD_DEFAULT, "WebKitPluginProcessShimInitialize"));
210 void PluginProcess::setModalWindowIsShowing(bool modalWindowIsShowing)
212 m_connection->send(Messages::PluginProcessProxy::SetModalWindowIsShowing(modalWindowIsShowing), 0);
215 void PluginProcess::setFullscreenWindowIsShowing(bool fullscreenWindowIsShowing)
217 m_connection->send(Messages::PluginProcessProxy::SetFullscreenWindowIsShowing(fullscreenWindowIsShowing), 0);
220 void PluginProcess::platformInitialize(const PluginProcessCreationParameters& parameters)
222 m_compositingRenderServerPort = parameters.acceleratedCompositingPort.port();
224 NSString *applicationName = [NSString stringWithFormat:WEB_UI_STRING("%@ (%@ Internet plug-in)",
225 "visible name of the plug-in host process. The first argument is the plug-in name "
226 "and the second argument is the application name."),
227 [[(NSString *)parameters.pluginPath lastPathComponent] stringByDeletingPathExtension],
228 (NSString *)parameters.parentProcessName];
230 WKSetVisibleApplicationName((CFStringRef)applicationName);
233 } // namespace WebKit
235 #endif // ENABLE(PLUGIN_PROCESS)