2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #if USE(PLUGIN_HOST_PROCESS) && ENABLE(NETSCAPE_PLUGIN_API)
28 #import "NetscapePluginHostProxy.h"
31 #import <wtf/StdLibExtras.h>
33 #import "HostedNetscapePluginStream.h"
34 #import "NetscapePluginHostManager.h"
35 #import "NetscapePluginInstanceProxy.h"
36 #import "WebFrameInternal.h"
37 #import "WebHostedNetscapePluginView.h"
38 #import "WebKitSystemInterface.h"
39 #import <WebCore/Frame.h>
40 #import <WebCore/IdentifierRep.h>
41 #import <WebCore/ScriptController.h>
44 #import "WebKitPluginHost.h"
45 #import "WebKitPluginClientServer.h"
50 using namespace WebCore;
52 @interface WebPlaceholderModalWindow : NSWindow
55 @implementation WebPlaceholderModalWindow
56 // Prevent NSApp from calling requestUserAttention: when the window is shown
57 // modally, even if the app is inactive. See 6823049.
58 - (BOOL)_wantsUserAttention
66 class PluginDestroyDeferrer {
68 PluginDestroyDeferrer(NetscapePluginInstanceProxy* proxy)
71 m_proxy->willCallPluginFunction();
74 ~PluginDestroyDeferrer()
77 m_proxy->didCallPluginFunction(stopped);
81 RefPtr<NetscapePluginInstanceProxy> m_proxy;
84 typedef HashMap<mach_port_t, NetscapePluginHostProxy*> PluginProxyMap;
85 static PluginProxyMap& pluginProxyMap()
87 DEFINE_STATIC_LOCAL(PluginProxyMap, pluginProxyMap, ());
89 return pluginProxyMap;
92 unsigned NetscapePluginHostProxy::s_processingRequests;
94 NetscapePluginHostProxy::NetscapePluginHostProxy(mach_port_t clientPort, mach_port_t pluginHostPort, const ProcessSerialNumber& pluginHostPSN, bool shouldCacheMissingPropertiesAndMethods)
95 : m_clientPort(clientPort)
96 , m_portSet(MACH_PORT_NULL)
97 , m_pluginHostPort(pluginHostPort)
99 , m_menuBarIsVisible(true)
100 , m_fullscreenWindowIsShowing(false)
101 , m_pluginHostPSN(pluginHostPSN)
102 , m_shouldCacheMissingPropertiesAndMethods(shouldCacheMissingPropertiesAndMethods)
104 pluginProxyMap().add(m_clientPort, this);
106 // FIXME: We should use libdispatch for this.
107 CFMachPortContext context = { 0, this, 0, 0, 0 };
108 m_deadNameNotificationPort.adoptCF(CFMachPortCreate(0, deadNameNotificationCallback, &context, 0));
110 mach_port_t previous;
111 mach_port_request_notification(mach_task_self(), pluginHostPort, MACH_NOTIFY_DEAD_NAME, 0,
112 CFMachPortGetPort(m_deadNameNotificationPort.get()), MACH_MSG_TYPE_MAKE_SEND_ONCE, &previous);
113 ASSERT(previous == MACH_PORT_NULL);
115 RetainPtr<CFRunLoopSourceRef> deathPortSource(AdoptCF, CFMachPortCreateRunLoopSource(0, m_deadNameNotificationPort.get(), 0));
117 CFRunLoopAddSource(CFRunLoopGetCurrent(), deathPortSource.get(), kCFRunLoopDefaultMode);
119 m_clientPortSource.adoptCF(WKCreateMIGServerSource((mig_subsystem_t)&WKWebKitPluginClient_subsystem, m_clientPort));
120 CFRunLoopAddSource(CFRunLoopGetCurrent(), m_clientPortSource.get(), kCFRunLoopDefaultMode);
121 CFRunLoopAddSource(CFRunLoopGetCurrent(), m_clientPortSource.get(), (CFStringRef)NSEventTrackingRunLoopMode);
124 NetscapePluginHostProxy::~NetscapePluginHostProxy()
126 pluginProxyMap().remove(m_clientPort);
130 mach_port_extract_member(mach_task_self(), m_clientPort, m_portSet);
131 mach_port_extract_member(mach_task_self(), CFMachPortGetPort(m_deadNameNotificationPort.get()), m_portSet);
132 mach_port_destroy(mach_task_self(), m_portSet);
135 ASSERT(m_clientPortSource);
136 CFRunLoopSourceInvalidate(m_clientPortSource.get());
137 m_clientPortSource = 0;
140 void NetscapePluginHostProxy::pluginHostDied()
142 PluginInstanceMap instances;
143 m_instances.swap(instances);
145 PluginInstanceMap::const_iterator end = instances.end();
146 for (PluginInstanceMap::const_iterator it = instances.begin(); it != end; ++it)
147 it->second->pluginHostDied();
149 NetscapePluginHostManager::shared().pluginHostDied(this);
151 // The plug-in crashed while its menu bar was hidden. Make sure to show it.
152 if (!m_menuBarIsVisible)
153 setMenuBarVisible(true);
155 // The plug-in crashed while it had a modal dialog up.
162 void NetscapePluginHostProxy::addPluginInstance(NetscapePluginInstanceProxy* instance)
164 ASSERT(!m_instances.contains(instance->pluginID()));
166 m_instances.set(instance->pluginID(), instance);
169 void NetscapePluginHostProxy::removePluginInstance(NetscapePluginInstanceProxy* instance)
171 ASSERT(m_instances.get(instance->pluginID()) == instance);
173 m_instances.remove(instance->pluginID());
176 NetscapePluginInstanceProxy* NetscapePluginHostProxy::pluginInstance(uint32_t pluginID)
178 NetscapePluginInstanceProxy* result = m_instances.get(pluginID).get();
179 ASSERT(!result || result->hostProxy() == this);
183 void NetscapePluginHostProxy::deadNameNotificationCallback(CFMachPortRef port, void *msg, CFIndex size, void *info)
186 ASSERT(static_cast<mach_msg_header_t*>(msg)->msgh_id == MACH_NOTIFY_DEAD_NAME);
188 static_cast<NetscapePluginHostProxy*>(info)->pluginHostDied();
191 void NetscapePluginHostProxy::setMenuBarVisible(bool visible)
193 m_menuBarIsVisible = visible;
195 [NSMenu setMenuBarVisible:visible];
198 void NetscapePluginHostProxy::didEnterFullscreen() const
200 SetFrontProcess(&m_pluginHostPSN);
203 void NetscapePluginHostProxy::didExitFullscreen() const
205 // If the plug-in host is the current application then we should bring ourselves to the front when it exits full-screen mode.
207 ProcessSerialNumber frontProcess;
208 GetFrontProcess(&frontProcess);
209 Boolean isSameProcess = 0;
210 SameProcess(&frontProcess, &m_pluginHostPSN, &isSameProcess);
214 ProcessSerialNumber currentProcess;
215 GetCurrentProcess(¤tProcess);
216 SetFrontProcess(¤tProcess);
219 void NetscapePluginHostProxy::setFullscreenWindowIsShowing(bool isShowing)
221 if (m_fullscreenWindowIsShowing == isShowing)
224 m_fullscreenWindowIsShowing = isShowing;
225 if (m_fullscreenWindowIsShowing)
226 didEnterFullscreen();
232 void NetscapePluginHostProxy::applicationDidBecomeActive()
234 SetFrontProcess(&m_pluginHostPSN);
237 void NetscapePluginHostProxy::beginModal()
239 ASSERT(!m_placeholderWindow);
240 ASSERT(!m_activationObserver);
242 m_placeholderWindow.adoptNS([[WebPlaceholderModalWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
244 m_activationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationWillBecomeActiveNotification object:NSApp queue:nil
245 usingBlock:^(NSNotification *){ applicationDidBecomeActive(); }];
247 // We need to be able to get the setModal(false) call from the plug-in host.
248 CFRunLoopAddSource(CFRunLoopGetCurrent(), m_clientPortSource.get(), (CFStringRef)NSModalPanelRunLoopMode);
250 [NSApp runModalForWindow:m_placeholderWindow.get()];
252 [m_placeholderWindow.get() orderOut:nil];
253 m_placeholderWindow = 0;
256 void NetscapePluginHostProxy::endModal()
258 ASSERT(m_placeholderWindow);
259 ASSERT(m_activationObserver);
261 [[NSNotificationCenter defaultCenter] removeObserver:m_activationObserver.get()];
262 m_activationObserver = nil;
264 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_clientPortSource.get(), (CFStringRef)NSModalPanelRunLoopMode);
268 // Make ourselves the front process.
269 ProcessSerialNumber psn;
270 GetCurrentProcess(&psn);
271 SetFrontProcess(&psn);
275 void NetscapePluginHostProxy::setModal(bool modal)
277 if (modal == m_isModal)
288 bool NetscapePluginHostProxy::processRequests()
290 s_processingRequests++;
293 mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &m_portSet);
294 mach_port_insert_member(mach_task_self(), m_clientPort, m_portSet);
295 mach_port_insert_member(mach_task_self(), CFMachPortGetPort(m_deadNameNotificationPort.get()), m_portSet);
300 mach_msg_header_t* msg = reinterpret_cast<mach_msg_header_t*>(buffer);
302 kern_return_t kr = mach_msg(msg, MACH_RCV_MSG, 0, sizeof(buffer), m_portSet, 0, MACH_PORT_NULL);
304 if (kr != KERN_SUCCESS) {
305 LOG_ERROR("Could not receive mach message, error %x", kr);
306 s_processingRequests--;
310 if (msg->msgh_local_port == m_clientPort) {
311 __ReplyUnion__WKWebKitPluginClient_subsystem reply;
312 mach_msg_header_t* replyHeader = reinterpret_cast<mach_msg_header_t*>(&reply);
314 if (WebKitPluginClient_server(msg, replyHeader) && replyHeader->msgh_remote_port != MACH_PORT_NULL) {
315 kr = mach_msg(replyHeader, MACH_SEND_MSG, replyHeader->msgh_size, 0, MACH_PORT_NULL, 0, MACH_PORT_NULL);
317 if (kr != KERN_SUCCESS) {
318 LOG_ERROR("Could not send mach message, error %x", kr);
319 s_processingRequests--;
324 s_processingRequests--;
328 if (msg->msgh_local_port == CFMachPortGetPort(m_deadNameNotificationPort.get())) {
329 ASSERT(msg->msgh_id == MACH_NOTIFY_DEAD_NAME);
331 s_processingRequests--;
335 ASSERT_NOT_REACHED();
336 s_processingRequests--;
340 } // namespace WebKit
342 using namespace WebKit;
344 // Helper class for deallocating data
345 class DataDeallocator {
347 DataDeallocator(data_t data, mach_msg_type_number_t dataLength)
348 : m_data(reinterpret_cast<vm_address_t>(data))
349 , m_dataLength(dataLength)
358 vm_deallocate(mach_task_self(), m_data, m_dataLength);
363 vm_size_t m_dataLength;
367 kern_return_t WKPCStatusText(mach_port_t clientPort, uint32_t pluginID, data_t text, mach_msg_type_number_t textCnt)
369 DataDeallocator deallocator(text, textCnt);
371 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
375 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
379 instanceProxy->status(text);
383 kern_return_t WKPCLoadURL(mach_port_t clientPort, uint32_t pluginID, data_t url, mach_msg_type_number_t urlLength, data_t target, mach_msg_type_number_t targetLength,
384 data_t postData, mach_msg_type_number_t postDataLength, uint32_t flags,
385 uint16_t* outResult, uint32_t* outStreamID)
387 DataDeallocator urlDeallocator(url, urlLength);
388 DataDeallocator targetDeallocator(target, targetLength);
389 DataDeallocator postDataDeallocator(postData, postDataLength);
391 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
395 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
399 uint32_t streamID = 0;
400 NPError result = instanceProxy->loadURL(url, target, postData, postDataLength, static_cast<LoadURLFlags>(flags), streamID);
403 *outStreamID = streamID;
407 kern_return_t WKPCCancelLoadURL(mach_port_t clientPort, uint32_t pluginID, uint32_t streamID, int16_t reason)
409 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
413 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
417 if (!instanceProxy->cancelStreamLoad(streamID, reason))
423 kern_return_t WKPCInvalidateRect(mach_port_t clientPort, uint32_t pluginID, double x, double y, double width, double height)
425 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
429 if (!hostProxy->isProcessingRequests()) {
430 if (NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID))
431 instanceProxy->invalidateRect(x, y, width, height);
436 CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopDefaultMode, ^{
437 if (NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort)) {
438 if (NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID))
439 instanceProxy->invalidateRect(x, y, width, height);
446 kern_return_t WKPCGetScriptableNPObjectReply(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID)
448 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
452 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
456 instanceProxy->setCurrentReply(requestID, new NetscapePluginInstanceProxy::GetScriptableNPObjectReply(objectID));
460 kern_return_t WKPCBooleanReply(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, boolean_t result)
462 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
466 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
470 instanceProxy->setCurrentReply(requestID, new NetscapePluginInstanceProxy::BooleanReply(result));
474 kern_return_t WKPCBooleanAndDataReply(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, boolean_t returnValue, data_t resultData, mach_msg_type_number_t resultLength)
476 DataDeallocator deallocator(resultData, resultLength);
478 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
482 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
486 RetainPtr<CFDataRef> result(AdoptCF, CFDataCreate(0, reinterpret_cast<UInt8*>(resultData), resultLength));
487 instanceProxy->setCurrentReply(requestID, new NetscapePluginInstanceProxy::BooleanAndDataReply(returnValue, result));
492 kern_return_t WKPCInstantiatePluginReply(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, kern_return_t result, uint32_t renderContextID, uint32_t rendererType)
494 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
498 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
502 instanceProxy->setCurrentReply(requestID, new NetscapePluginInstanceProxy::InstantiatePluginReply(result, renderContextID, static_cast<RendererType>(rendererType)));
506 kern_return_t WKPCGetWindowNPObject(mach_port_t clientPort, uint32_t pluginID, uint32_t* outObjectID)
508 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
512 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
517 if (!instanceProxy->getWindowNPObject(objectID))
520 *outObjectID = objectID;
524 kern_return_t WKPCGetPluginElementNPObject(mach_port_t clientPort, uint32_t pluginID, uint32_t* outObjectID)
526 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
530 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
535 if (!instanceProxy->getPluginElementNPObject(objectID))
538 *outObjectID = objectID;
542 kern_return_t WKPCForgetBrowserObject(mach_port_t clientPort, uint32_t pluginID, uint32_t objectID)
544 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
548 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
552 return instanceProxy->forgetBrowserObjectID(objectID) ? KERN_SUCCESS : KERN_FAILURE;
555 kern_return_t WKPCEvaluate(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, data_t scriptData, mach_msg_type_number_t scriptLength, boolean_t allowPopups)
557 DataDeallocator deallocator(scriptData, scriptLength);
559 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
563 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
567 PluginDestroyDeferrer deferrer(instanceProxy);
569 String script = String::fromUTF8WithLatin1Fallback(scriptData, scriptLength);
571 data_t resultData = 0;
572 mach_msg_type_number_t resultLength = 0;
573 boolean_t returnValue = instanceProxy->evaluate(objectID, script, resultData, resultLength, allowPopups);
575 hostProxy = instanceProxy->hostProxy();
579 _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
581 mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
586 kern_return_t WKPCGetStringIdentifier(mach_port_t clientPort, data_t name, mach_msg_type_number_t nameCnt, uint64_t* identifier)
588 DataDeallocator deallocator(name, nameCnt);
590 COMPILE_ASSERT(sizeof(*identifier) == sizeof(IdentifierRep*), identifier_sizes);
592 *identifier = reinterpret_cast<uint64_t>(IdentifierRep::get(name));
596 kern_return_t WKPCGetIntIdentifier(mach_port_t clientPort, int32_t value, uint64_t* identifier)
598 COMPILE_ASSERT(sizeof(*identifier) == sizeof(NPIdentifier), identifier_sizes);
600 *identifier = reinterpret_cast<uint64_t>(IdentifierRep::get(value));
604 static Identifier identifierFromIdentifierRep(IdentifierRep* identifier)
606 ASSERT(IdentifierRep::isValid(identifier));
607 ASSERT(identifier->isString());
609 const char* str = identifier->string();
610 return Identifier(JSDOMWindow::commonJSGlobalData(), stringToUString(String::fromUTF8WithLatin1Fallback(str, strlen(str))));
613 kern_return_t WKPCInvoke(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier,
614 data_t argumentsData, mach_msg_type_number_t argumentsLength)
616 DataDeallocator deallocator(argumentsData, argumentsLength);
618 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
622 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
626 PluginDestroyDeferrer deferrer(instanceProxy);
628 IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
629 if (!IdentifierRep::isValid(identifier))
632 Identifier methodNameIdentifier = identifierFromIdentifierRep(identifier);
634 data_t resultData = 0;
635 mach_msg_type_number_t resultLength = 0;
636 boolean_t returnValue = instanceProxy->invoke(objectID, methodNameIdentifier, argumentsData, argumentsLength, resultData, resultLength);
638 hostProxy = instanceProxy->hostProxy();
642 _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
644 mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
649 kern_return_t WKPCInvokeDefault(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID,
650 data_t argumentsData, mach_msg_type_number_t argumentsLength)
652 DataDeallocator deallocator(argumentsData, argumentsLength);
654 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
658 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
662 PluginDestroyDeferrer deferrer(instanceProxy);
664 data_t resultData = 0;
665 mach_msg_type_number_t resultLength = 0;
666 boolean_t returnValue = instanceProxy->invokeDefault(objectID, argumentsData, argumentsLength, resultData, resultLength);
668 hostProxy = instanceProxy->hostProxy();
672 _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
674 mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
679 kern_return_t WKPCConstruct(mach_port_t clientPort, uint32_t pluginID, uint32_t objectID,
680 data_t argumentsData, mach_msg_type_number_t argumentsLength,
681 boolean_t* returnValue, data_t* resultData, mach_msg_type_number_t* resultLength)
683 DataDeallocator deallocator(argumentsData, argumentsLength);
685 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
689 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
693 PluginDestroyDeferrer deferrer(instanceProxy);
695 *returnValue = instanceProxy->construct(objectID, argumentsData, argumentsLength, *resultData, *resultLength);
700 kern_return_t WKPCGetProperty(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier)
702 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
706 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
710 IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
711 if (!IdentifierRep::isValid(identifier))
714 PluginDestroyDeferrer deferrer(instanceProxy);
716 data_t resultData = 0;
717 mach_msg_type_number_t resultLength = 0;
718 boolean_t returnValue;
720 if (identifier->isString()) {
721 Identifier propertyNameIdentifier = identifierFromIdentifierRep(identifier);
722 returnValue = instanceProxy->getProperty(objectID, propertyNameIdentifier, resultData, resultLength);
724 returnValue = instanceProxy->setProperty(objectID, identifier->number(), resultData, resultLength);
726 hostProxy = instanceProxy->hostProxy();
730 _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
732 mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
737 kern_return_t WKPCSetProperty(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier, data_t valueData, mach_msg_type_number_t valueLength)
739 DataDeallocator deallocator(valueData, valueLength);
741 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
745 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
749 PluginDestroyDeferrer deferrer(instanceProxy);
751 IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
752 if (!IdentifierRep::isValid(identifier))
756 if (identifier->isString()) {
757 Identifier propertyNameIdentifier = identifierFromIdentifierRep(identifier);
758 result = instanceProxy->setProperty(objectID, propertyNameIdentifier, valueData, valueLength);
760 result = instanceProxy->setProperty(objectID, identifier->number(), valueData, valueLength);
762 hostProxy = instanceProxy->hostProxy();
766 _WKPHBooleanReply(hostProxy->port(), instanceProxy->pluginID(), requestID, result);
771 kern_return_t WKPCRemoveProperty(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier)
773 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
777 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
781 PluginDestroyDeferrer deferrer(instanceProxy);
783 IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
784 if (!IdentifierRep::isValid(identifier))
788 if (identifier->isString()) {
789 Identifier propertyNameIdentifier = identifierFromIdentifierRep(identifier);
790 result = instanceProxy->removeProperty(objectID, propertyNameIdentifier);
792 result = instanceProxy->removeProperty(objectID, identifier->number());
794 hostProxy = instanceProxy->hostProxy();
798 _WKPHBooleanReply(hostProxy->port(), instanceProxy->pluginID(), requestID, result);
803 kern_return_t WKPCHasProperty(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier)
805 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
809 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
813 PluginDestroyDeferrer deferrer(instanceProxy);
815 IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
816 if (!IdentifierRep::isValid(identifier))
819 boolean_t returnValue;
820 if (identifier->isString()) {
821 Identifier propertyNameIdentifier = identifierFromIdentifierRep(identifier);
822 returnValue = instanceProxy->hasProperty(objectID, propertyNameIdentifier);
824 returnValue = instanceProxy->hasProperty(objectID, identifier->number());
826 hostProxy = instanceProxy->hostProxy();
830 _WKPHBooleanReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue);
835 kern_return_t WKPCHasMethod(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier)
837 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
841 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
845 PluginDestroyDeferrer deferrer(instanceProxy);
847 IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
848 if (!IdentifierRep::isValid(identifier))
851 Identifier methodNameIdentifier = identifierFromIdentifierRep(identifier);
852 boolean_t returnValue = instanceProxy->hasMethod(objectID, methodNameIdentifier);
854 hostProxy = instanceProxy->hostProxy();
858 _WKPHBooleanReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue);
863 kern_return_t WKPCIdentifierInfo(mach_port_t clientPort, uint64_t serverIdentifier, data_t* infoData, mach_msg_type_number_t* infoLength)
865 IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
866 if (!IdentifierRep::isValid(identifier))
870 if (identifier->isString()) {
871 const char* str = identifier->string();
872 info = [NSData dataWithBytesNoCopy:(void*)str length:strlen(str) freeWhenDone:NO];
874 info = [NSNumber numberWithInt:identifier->number()];
876 RetainPtr<NSData*> data = [NSPropertyListSerialization dataFromPropertyList:info format:NSPropertyListBinaryFormat_v1_0 errorDescription:0];
879 *infoLength = [data.get() length];
880 mig_allocate(reinterpret_cast<vm_address_t*>(infoData), *infoLength);
882 memcpy(*infoData, [data.get() bytes], *infoLength);
887 kern_return_t WKPCEnumerate(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID)
889 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
893 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
897 data_t resultData = 0;
898 mach_msg_type_number_t resultLength = 0;
899 boolean_t returnValue = instanceProxy->enumerate(objectID, resultData, resultLength);
901 hostProxy = instanceProxy->hostProxy();
905 _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
908 mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
913 kern_return_t WKPCSetMenuBarVisible(mach_port_t clientPort, boolean_t menuBarVisible)
915 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
919 hostProxy->setMenuBarVisible(menuBarVisible);
924 kern_return_t WKPCSetFullscreenWindowIsShowing(mach_port_t clientPort, boolean_t fullscreenWindowIsShowing)
926 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
930 hostProxy->setFullscreenWindowIsShowing(fullscreenWindowIsShowing);
935 kern_return_t WKPCSetModal(mach_port_t clientPort, boolean_t modal)
937 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
941 if (!hostProxy->isProcessingRequests()) {
942 hostProxy->setModal(modal);
947 CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopDefaultMode, ^{
948 if (NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort))
949 hostProxy->setModal(modal);
955 kern_return_t WKPCGetCookies(mach_port_t clientPort, uint32_t pluginID,
956 data_t urlData, mach_msg_type_number_t urlLength,
957 boolean_t* returnValue, data_t* cookiesData, mach_msg_type_number_t* cookiesLength)
962 DataDeallocator deallocator(urlData, urlLength);
964 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
968 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
972 *returnValue = instanceProxy->getCookies(urlData, urlLength, *cookiesData, *cookiesLength);
977 kern_return_t WKPCGetProxy(mach_port_t clientPort, uint32_t pluginID,
978 data_t urlData, mach_msg_type_number_t urlLength,
979 boolean_t* returnValue, data_t* proxyData, mach_msg_type_number_t* proxyLength)
984 DataDeallocator deallocator(urlData, urlLength);
986 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
990 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
994 *returnValue = instanceProxy->getProxy(urlData, urlLength, *proxyData, *proxyLength);
999 kern_return_t WKPCSetCookies(mach_port_t clientPort, uint32_t pluginID,
1000 data_t urlData, mach_msg_type_number_t urlLength,
1001 data_t cookiesData, mach_msg_type_number_t cookiesLength,
1002 boolean_t* returnValue)
1004 DataDeallocator urlDeallocator(urlData, urlLength);
1005 DataDeallocator cookiesDeallocator(cookiesData, cookiesLength);
1007 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
1009 return KERN_FAILURE;
1011 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
1013 return KERN_FAILURE;
1015 *returnValue = instanceProxy->setCookies(urlData, urlLength, cookiesData, cookiesLength);
1016 return KERN_SUCCESS;
1019 kern_return_t WKPCGetAuthenticationInfo(mach_port_t clientPort, uint32_t pluginID,
1020 data_t protocolData, mach_msg_type_number_t protocolLength,
1021 data_t hostData, mach_msg_type_number_t hostLength,
1023 data_t schemeData, mach_msg_type_number_t schemeLength,
1024 data_t realmData, mach_msg_type_number_t realmLength,
1025 boolean_t* returnValue,
1026 data_t* usernameData, mach_msg_type_number_t *usernameLength,
1027 data_t* passwordData, mach_msg_type_number_t *passwordLength)
1029 DataDeallocator protocolDeallocator(protocolData, protocolLength);
1030 DataDeallocator hostDeallocator(hostData, hostLength);
1031 DataDeallocator schemeDeallocator(schemeData, schemeLength);
1032 DataDeallocator realmDeallocator(realmData, realmLength);
1035 *usernameLength = 0;
1037 *passwordLength = 0;
1039 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
1041 return KERN_FAILURE;
1043 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
1045 return KERN_FAILURE;
1047 *returnValue = instanceProxy->getAuthenticationInfo(protocolData, hostData, port, schemeData, realmData, *usernameData, *usernameLength, *passwordData, *passwordLength);
1049 return KERN_SUCCESS;
1052 kern_return_t WKPCConvertPoint(mach_port_t clientPort, uint32_t pluginID,
1053 double sourceX, double sourceY, uint32_t sourceSpace,
1054 uint32_t destSpace, boolean_t *returnValue, double *destX, double *destY)
1056 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
1058 return KERN_FAILURE;
1060 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
1062 return KERN_FAILURE;
1064 *returnValue = instanceProxy->convertPoint(sourceX, sourceY, static_cast<NPCoordinateSpace>(sourceSpace),
1065 *destX, *destY, static_cast<NPCoordinateSpace>(destSpace));
1066 return KERN_SUCCESS;
1069 kern_return_t WKPCCheckIfAllowedToLoadURL(mach_port_t clientPort, uint32_t pluginID, data_t urlData, mach_msg_type_number_t urlLength,
1070 data_t targetData, mach_msg_type_number_t targetLength, uint32_t *checkID)
1072 DataDeallocator urlDeallocator(urlData, urlLength);
1073 DataDeallocator targetDeallocator(targetData, targetLength);
1075 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
1077 return KERN_FAILURE;
1079 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
1081 return KERN_FAILURE;
1083 *checkID = instanceProxy->checkIfAllowedToLoadURL(urlData, targetData);
1084 return KERN_SUCCESS;
1087 kern_return_t WKPCCancelCheckIfAllowedToLoadURL(mach_port_t clientPort, uint32_t pluginID, uint32_t checkID)
1089 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
1091 return KERN_FAILURE;
1093 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
1095 return KERN_FAILURE;
1097 instanceProxy->cancelCheckIfAllowedToLoadURL(checkID);
1098 return KERN_SUCCESS;
1101 kern_return_t WKPCResolveURL(mach_port_t clientPort, uint32_t pluginID, data_t urlData, mach_msg_type_number_t urlLength,
1102 data_t targetData, mach_msg_type_number_t targetLength,
1103 data_t *resolvedURLData, mach_msg_type_number_t *resolvedURLLength)
1105 DataDeallocator urlDeallocator(urlData, urlLength);
1106 DataDeallocator targetDeallocator(targetData, targetLength);
1108 *resolvedURLData = 0;
1109 *resolvedURLLength = 0;
1111 NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
1113 return KERN_FAILURE;
1115 NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
1117 return KERN_FAILURE;
1119 instanceProxy->resolveURL(urlData, targetData, *resolvedURLData, *resolvedURLLength);
1120 return KERN_SUCCESS;
1123 kern_return_t WKPCSetException(mach_port_t clientPort, data_t message, mach_msg_type_number_t messageCnt)
1125 DataDeallocator deallocator(message, messageCnt);
1127 NetscapePluginInstanceProxy::setGlobalException(String::fromUTF8WithLatin1Fallback(message, messageCnt));
1129 return KERN_SUCCESS;
1132 #endif // USE(PLUGIN_HOST_PROCESS) && ENABLE(NETSCAPE_PLUGIN_API)