Home | History | Annotate | Download | only in Hosted
      1 /*
      2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      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.
     12  *
     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.
     24  */
     25 
     26 #if USE(PLUGIN_HOST_PROCESS)
     27 
     28 #import "NetscapePluginHostProxy.h"
     29 
     30 #import <mach/mach.h>
     31 #import <wtf/StdLibExtras.h>
     32 
     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>
     42 #import <string>
     43 
     44 extern "C" {
     45 #import "WebKitPluginHost.h"
     46 #import "WebKitPluginClientServer.h"
     47 }
     48 
     49 using namespace std;
     50 using namespace JSC;
     51 using namespace WebCore;
     52 
     53 @interface WebPlaceholderModalWindow : NSWindow
     54 @end
     55 
     56 @implementation WebPlaceholderModalWindow
     57 // Prevent NSApp from calling requestUserAttention: when the window is shown
     58 // modally, even if the app is inactive. See 6823049.
     59 - (BOOL)_wantsUserAttention
     60 {
     61     return NO;
     62 }
     63 @end
     64 
     65 namespace WebKit {
     66 
     67 class PluginDestroyDeferrer {
     68 public:
     69     PluginDestroyDeferrer(NetscapePluginInstanceProxy* proxy)
     70         : m_proxy(proxy)
     71     {
     72         m_proxy->willCallPluginFunction();
     73     }
     74 
     75     ~PluginDestroyDeferrer()
     76     {
     77         m_proxy->didCallPluginFunction();
     78     }
     79 
     80 private:
     81     RefPtr<NetscapePluginInstanceProxy> m_proxy;
     82 };
     83 
     84 typedef HashMap<mach_port_t, NetscapePluginHostProxy*> PluginProxyMap;
     85 static PluginProxyMap& pluginProxyMap()
     86 {
     87     DEFINE_STATIC_LOCAL(PluginProxyMap, pluginProxyMap, ());
     88 
     89     return pluginProxyMap;
     90 }
     91 
     92 NetscapePluginHostProxy::NetscapePluginHostProxy(mach_port_t clientPort, mach_port_t pluginHostPort, const ProcessSerialNumber& pluginHostPSN, bool shouldCacheMissingPropertiesAndMethods)
     93     : m_clientPort(clientPort)
     94     , m_portSet(MACH_PORT_NULL)
     95     , m_pluginHostPort(pluginHostPort)
     96     , m_isModal(false)
     97     , m_menuBarIsVisible(true)
     98     , m_fullScreenWindowIsShowing(false)
     99     , m_pluginHostPSN(pluginHostPSN)
    100     , m_processingRequests(0)
    101     , m_shouldCacheMissingPropertiesAndMethods(shouldCacheMissingPropertiesAndMethods)
    102 {
    103     pluginProxyMap().add(m_clientPort, this);
    104 
    105     // FIXME: We should use libdispatch for this.
    106     CFMachPortContext context = { 0, this, 0, 0, 0 };
    107     m_deadNameNotificationPort.adoptCF(CFMachPortCreate(0, deadNameNotificationCallback, &context, 0));
    108 
    109     mach_port_t previous;
    110     mach_port_request_notification(mach_task_self(), pluginHostPort, MACH_NOTIFY_DEAD_NAME, 0,
    111                                    CFMachPortGetPort(m_deadNameNotificationPort.get()), MACH_MSG_TYPE_MAKE_SEND_ONCE, &previous);
    112     ASSERT(previous == MACH_PORT_NULL);
    113 
    114     RetainPtr<CFRunLoopSourceRef> deathPortSource(AdoptCF, CFMachPortCreateRunLoopSource(0, m_deadNameNotificationPort.get(), 0));
    115 
    116     CFRunLoopAddSource(CFRunLoopGetCurrent(), deathPortSource.get(), kCFRunLoopDefaultMode);
    117 
    118 #ifdef USE_LIBDISPATCH
    119     // FIXME: Unfortunately we can't use a dispatch source here until <rdar://problem/6393180> has been resolved.
    120     m_clientPortSource = dispatch_source_mig_create(m_clientPort, WKWebKitPluginClient_subsystem.maxsize, 0,
    121                                                     dispatch_get_main_queue(), WebKitPluginClient_server);
    122 #else
    123     m_clientPortSource.adoptCF(WKCreateMIGServerSource((mig_subsystem_t)&WKWebKitPluginClient_subsystem, m_clientPort));
    124     CFRunLoopAddSource(CFRunLoopGetCurrent(), m_clientPortSource.get(), kCFRunLoopDefaultMode);
    125     CFRunLoopAddSource(CFRunLoopGetCurrent(), m_clientPortSource.get(), (CFStringRef)NSEventTrackingRunLoopMode);
    126 #endif
    127 }
    128 
    129 NetscapePluginHostProxy::~NetscapePluginHostProxy()
    130 {
    131     pluginProxyMap().remove(m_clientPort);
    132 
    133     // Free the port set
    134     if (m_portSet) {
    135         mach_port_extract_member(mach_task_self(), m_clientPort, m_portSet);
    136         mach_port_extract_member(mach_task_self(), CFMachPortGetPort(m_deadNameNotificationPort.get()), m_portSet);
    137         mach_port_destroy(mach_task_self(), m_portSet);
    138     }
    139 
    140     ASSERT(m_clientPortSource);
    141 #ifdef USE_LIBDISPATCH
    142     dispatch_release(m_clientPortSource);
    143 #else
    144     CFRunLoopSourceInvalidate(m_clientPortSource.get());
    145     m_clientPortSource = 0;
    146 #endif
    147 }
    148 
    149 void NetscapePluginHostProxy::pluginHostDied()
    150 {
    151     PluginInstanceMap instances;
    152     m_instances.swap(instances);
    153 
    154     PluginInstanceMap::const_iterator end = instances.end();
    155     for (PluginInstanceMap::const_iterator it = instances.begin(); it != end; ++it)
    156         it->second->pluginHostDied();
    157 
    158     NetscapePluginHostManager::shared().pluginHostDied(this);
    159 
    160     // The plug-in crashed while its menu bar was hidden. Make sure to show it.
    161     if (!m_menuBarIsVisible)
    162         setMenuBarVisible(true);
    163 
    164     // The plug-in crashed while it had a modal dialog up.
    165     if (m_isModal)
    166         endModal();
    167 
    168     delete this;
    169 }
    170 
    171 void NetscapePluginHostProxy::addPluginInstance(NetscapePluginInstanceProxy* instance)
    172 {
    173     ASSERT(!m_instances.contains(instance->pluginID()));
    174 
    175     m_instances.set(instance->pluginID(), instance);
    176 }
    177 
    178 void NetscapePluginHostProxy::removePluginInstance(NetscapePluginInstanceProxy* instance)
    179 {
    180     ASSERT(m_instances.get(instance->pluginID()) == instance);
    181 
    182     m_instances.remove(instance->pluginID());
    183 }
    184 
    185 NetscapePluginInstanceProxy* NetscapePluginHostProxy::pluginInstance(uint32_t pluginID)
    186 {
    187     return m_instances.get(pluginID).get();
    188 }
    189 
    190 void NetscapePluginHostProxy::deadNameNotificationCallback(CFMachPortRef port, void *msg, CFIndex size, void *info)
    191 {
    192     ASSERT(msg);
    193     ASSERT(static_cast<mach_msg_header_t*>(msg)->msgh_id == MACH_NOTIFY_DEAD_NAME);
    194 
    195     static_cast<NetscapePluginHostProxy*>(info)->pluginHostDied();
    196 }
    197 
    198 void NetscapePluginHostProxy::setMenuBarVisible(bool visible)
    199 {
    200     m_menuBarIsVisible = visible;
    201 
    202     [NSMenu setMenuBarVisible:visible];
    203 }
    204 
    205 void NetscapePluginHostProxy::didEnterFullScreen() const
    206 {
    207     SetFrontProcess(&m_pluginHostPSN);
    208 }
    209 
    210 void NetscapePluginHostProxy::didExitFullScreen() const
    211 {
    212     // If the plug-in host is the current application then we should bring ourselves to the front when it exits full-screen mode.
    213 
    214     ProcessSerialNumber frontProcess;
    215     GetFrontProcess(&frontProcess);
    216     Boolean isSameProcess = 0;
    217     SameProcess(&frontProcess, &m_pluginHostPSN, &isSameProcess);
    218     if (!isSameProcess)
    219         return;
    220 
    221     ProcessSerialNumber currentProcess;
    222     GetCurrentProcess(&currentProcess);
    223     SetFrontProcess(&currentProcess);
    224 }
    225 
    226 void NetscapePluginHostProxy::setFullScreenWindowIsShowing(bool isShowing)
    227 {
    228     if (m_fullScreenWindowIsShowing == isShowing)
    229         return;
    230 
    231     m_fullScreenWindowIsShowing = isShowing;
    232     if (m_fullScreenWindowIsShowing)
    233         didEnterFullScreen();
    234     else
    235         didExitFullScreen();
    236 
    237 }
    238 
    239 void NetscapePluginHostProxy::applicationDidBecomeActive()
    240 {
    241     SetFrontProcess(&m_pluginHostPSN);
    242 }
    243 
    244 void NetscapePluginHostProxy::beginModal()
    245 {
    246     ASSERT(!m_placeholderWindow);
    247     ASSERT(!m_activationObserver);
    248 
    249     m_placeholderWindow.adoptNS([[WebPlaceholderModalWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
    250 
    251     m_activationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationWillBecomeActiveNotification object:NSApp queue:nil
    252                                                                          usingBlock:^(NSNotification *){ applicationDidBecomeActive(); }];
    253 
    254     // We need to be able to get the setModal(false) call from the plug-in host.
    255     CFRunLoopAddSource(CFRunLoopGetCurrent(), m_clientPortSource.get(), (CFStringRef)NSModalPanelRunLoopMode);
    256 
    257     [NSApp runModalForWindow:m_placeholderWindow.get()];
    258 
    259     [m_placeholderWindow.get() orderOut:nil];
    260     m_placeholderWindow = 0;
    261 }
    262 
    263 void NetscapePluginHostProxy::endModal()
    264 {
    265     ASSERT(m_placeholderWindow);
    266     ASSERT(m_activationObserver);
    267 
    268     [[NSNotificationCenter defaultCenter] removeObserver:m_activationObserver.get()];
    269     m_activationObserver = nil;
    270 
    271     CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_clientPortSource.get(), (CFStringRef)NSModalPanelRunLoopMode);
    272 
    273     [NSApp stopModal];
    274 
    275     // Make ourselves the front process.
    276     ProcessSerialNumber psn;
    277     GetCurrentProcess(&psn);
    278     SetFrontProcess(&psn);
    279 }
    280 
    281 
    282 void NetscapePluginHostProxy::setModal(bool modal)
    283 {
    284     if (modal == m_isModal)
    285         return;
    286 
    287     m_isModal = modal;
    288 
    289     if (m_isModal)
    290         beginModal();
    291     else
    292         endModal();
    293 }
    294 
    295 bool NetscapePluginHostProxy::processRequests()
    296 {
    297     m_processingRequests++;
    298 
    299    if (!m_portSet) {
    300         mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &m_portSet);
    301         mach_port_insert_member(mach_task_self(), m_clientPort, m_portSet);
    302         mach_port_insert_member(mach_task_self(), CFMachPortGetPort(m_deadNameNotificationPort.get()), m_portSet);
    303     }
    304 
    305     char buffer[4096];
    306 
    307     mach_msg_header_t* msg = reinterpret_cast<mach_msg_header_t*>(buffer);
    308 
    309     kern_return_t kr = mach_msg(msg, MACH_RCV_MSG, 0, sizeof(buffer), m_portSet, 0, MACH_PORT_NULL);
    310 
    311     if (kr != KERN_SUCCESS) {
    312         LOG_ERROR("Could not receive mach message, error %x", kr);
    313         m_processingRequests--;
    314         return false;
    315     }
    316 
    317     if (msg->msgh_local_port == m_clientPort) {
    318         __ReplyUnion__WKWebKitPluginClient_subsystem reply;
    319         mach_msg_header_t* replyHeader = reinterpret_cast<mach_msg_header_t*>(&reply);
    320 
    321         if (WebKitPluginClient_server(msg, replyHeader) && replyHeader->msgh_remote_port != MACH_PORT_NULL) {
    322             kr = mach_msg(replyHeader, MACH_SEND_MSG, replyHeader->msgh_size, 0, MACH_PORT_NULL, 0, MACH_PORT_NULL);
    323 
    324             if (kr != KERN_SUCCESS) {
    325                 LOG_ERROR("Could not send mach message, error %x", kr);
    326                 m_processingRequests--;
    327                 return false;
    328             }
    329         }
    330 
    331         m_processingRequests--;
    332         return true;
    333     }
    334 
    335     if (msg->msgh_local_port == CFMachPortGetPort(m_deadNameNotificationPort.get())) {
    336         ASSERT(msg->msgh_id == MACH_NOTIFY_DEAD_NAME);
    337         pluginHostDied();
    338         m_processingRequests--;
    339         return false;
    340     }
    341 
    342     ASSERT_NOT_REACHED();
    343     m_processingRequests--;
    344     return false;
    345 }
    346 
    347 } // namespace WebKit
    348 
    349 using namespace WebKit;
    350 
    351 // Helper class for deallocating data
    352 class DataDeallocator {
    353 public:
    354     DataDeallocator(data_t data, mach_msg_type_number_t dataLength)
    355         : m_data(reinterpret_cast<vm_address_t>(data))
    356         , m_dataLength(dataLength)
    357     {
    358     }
    359 
    360     ~DataDeallocator()
    361     {
    362         if (!m_data)
    363             return;
    364 
    365         vm_deallocate(mach_task_self(), m_data, m_dataLength);
    366     }
    367 
    368 private:
    369     vm_address_t m_data;
    370     vm_size_t m_dataLength;
    371 };
    372 
    373 // MiG callbacks
    374 kern_return_t WKPCStatusText(mach_port_t clientPort, uint32_t pluginID, data_t text, mach_msg_type_number_t textCnt)
    375 {
    376     DataDeallocator deallocator(text, textCnt);
    377 
    378     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    379     if (!hostProxy)
    380         return KERN_FAILURE;
    381 
    382     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    383     if (!instanceProxy)
    384         return KERN_FAILURE;
    385 
    386     instanceProxy->status(text);
    387     return KERN_SUCCESS;
    388 }
    389 
    390 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,
    391                           data_t postData, mach_msg_type_number_t postDataLength, uint32_t flags,
    392                           uint16_t* outResult, uint32_t* outStreamID)
    393 {
    394     DataDeallocator urlDeallocator(url, urlLength);
    395     DataDeallocator targetDeallocator(target, targetLength);
    396     DataDeallocator postDataDeallocator(postData, postDataLength);
    397 
    398     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    399     if (!hostProxy)
    400         return KERN_FAILURE;
    401 
    402     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    403     if (!instanceProxy)
    404         return KERN_FAILURE;
    405 
    406     uint32_t streamID = 0;
    407     NPError result = instanceProxy->loadURL(url, target, postData, postDataLength, static_cast<LoadURLFlags>(flags), streamID);
    408 
    409     *outResult = result;
    410     *outStreamID = streamID;
    411     return KERN_SUCCESS;
    412 }
    413 
    414 kern_return_t WKPCCancelLoadURL(mach_port_t clientPort, uint32_t pluginID, uint32_t streamID, int16_t reason)
    415 {
    416     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    417     if (!hostProxy)
    418         return KERN_FAILURE;
    419 
    420     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    421     if (!instanceProxy)
    422         return KERN_FAILURE;
    423 
    424     if (!instanceProxy->cancelStreamLoad(streamID, reason))
    425         return KERN_FAILURE;
    426 
    427     return KERN_SUCCESS;
    428 }
    429 
    430 kern_return_t WKPCInvalidateRect(mach_port_t clientPort, uint32_t pluginID, double x, double y, double width, double height)
    431 {
    432     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    433     if (!hostProxy)
    434         return KERN_SUCCESS;
    435 
    436     if (!hostProxy->isProcessingRequests()) {
    437         if (NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID))
    438             instanceProxy->invalidateRect(x, y, width, height);
    439         return KERN_SUCCESS;
    440     }
    441 
    442     // Defer the work
    443     CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopDefaultMode, ^{
    444         if (NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort)) {
    445             if (NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID))
    446                 instanceProxy->invalidateRect(x, y, width, height);
    447         }
    448     });
    449 
    450     return KERN_SUCCESS;
    451 }
    452 
    453 kern_return_t WKPCGetScriptableNPObjectReply(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID)
    454 {
    455     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    456     if (!hostProxy)
    457         return KERN_FAILURE;
    458 
    459     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    460     if (!instanceProxy)
    461         return KERN_FAILURE;
    462 
    463     instanceProxy->setCurrentReply(requestID, new NetscapePluginInstanceProxy::GetScriptableNPObjectReply(objectID));
    464     return KERN_SUCCESS;
    465 }
    466 
    467 kern_return_t WKPCBooleanReply(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, boolean_t result)
    468 {
    469     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    470     if (!hostProxy)
    471         return KERN_FAILURE;
    472 
    473     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    474     if (!instanceProxy)
    475         return KERN_FAILURE;
    476 
    477     instanceProxy->setCurrentReply(requestID, new NetscapePluginInstanceProxy::BooleanReply(result));
    478     return KERN_SUCCESS;
    479 }
    480 
    481 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)
    482 {
    483     DataDeallocator deallocator(resultData, resultLength);
    484 
    485     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    486     if (!hostProxy)
    487         return KERN_FAILURE;
    488 
    489     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    490     if (!instanceProxy)
    491         return KERN_FAILURE;
    492 
    493     RetainPtr<CFDataRef> result(AdoptCF, CFDataCreate(0, reinterpret_cast<UInt8*>(resultData), resultLength));
    494     instanceProxy->setCurrentReply(requestID, new NetscapePluginInstanceProxy::BooleanAndDataReply(returnValue, result));
    495 
    496     return KERN_SUCCESS;
    497 }
    498 
    499 kern_return_t WKPCInstantiatePluginReply(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, kern_return_t result, uint32_t renderContextID, boolean_t useSoftwareRenderer)
    500 {
    501     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    502     if (!hostProxy)
    503         return KERN_FAILURE;
    504 
    505     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    506     if (!instanceProxy)
    507         return KERN_FAILURE;
    508 
    509     instanceProxy->setCurrentReply(requestID, new NetscapePluginInstanceProxy::InstantiatePluginReply(result, renderContextID, useSoftwareRenderer));
    510     return KERN_SUCCESS;
    511 }
    512 
    513 kern_return_t WKPCGetWindowNPObject(mach_port_t clientPort, uint32_t pluginID, uint32_t* outObjectID)
    514 {
    515     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    516     if (!hostProxy)
    517         return KERN_FAILURE;
    518 
    519     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    520     if (!instanceProxy)
    521         return KERN_FAILURE;
    522 
    523     uint32_t objectID;
    524     if (!instanceProxy->getWindowNPObject(objectID))
    525         return KERN_FAILURE;
    526 
    527     *outObjectID = objectID;
    528     return KERN_SUCCESS;
    529 }
    530 
    531 kern_return_t WKPCGetPluginElementNPObject(mach_port_t clientPort, uint32_t pluginID, uint32_t* outObjectID)
    532 {
    533     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    534     if (!hostProxy)
    535         return KERN_FAILURE;
    536 
    537     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    538     if (!instanceProxy)
    539         return KERN_FAILURE;
    540 
    541     uint32_t objectID;
    542     if (!instanceProxy->getPluginElementNPObject(objectID))
    543         return KERN_FAILURE;
    544 
    545     *outObjectID = objectID;
    546     return KERN_SUCCESS;
    547 }
    548 
    549 kern_return_t WKPCReleaseObject(mach_port_t clientPort, uint32_t pluginID, uint32_t objectID)
    550 {
    551     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    552     if (!hostProxy)
    553         return KERN_FAILURE;
    554 
    555     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    556     if (!instanceProxy)
    557         return KERN_FAILURE;
    558 
    559     instanceProxy->releaseObject(objectID);
    560     return KERN_SUCCESS;
    561 }
    562 
    563 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)
    564 {
    565     DataDeallocator deallocator(scriptData, scriptLength);
    566 
    567     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    568     if (!hostProxy)
    569         return KERN_FAILURE;
    570 
    571     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    572     if (!instanceProxy)
    573         return KERN_FAILURE;
    574 
    575     PluginDestroyDeferrer deferrer(instanceProxy);
    576 
    577     String script = String::fromUTF8WithLatin1Fallback(scriptData, scriptLength);
    578 
    579     data_t resultData = 0;
    580     mach_msg_type_number_t resultLength = 0;
    581     boolean_t returnValue = instanceProxy->evaluate(objectID, script, resultData, resultLength, allowPopups);
    582 
    583     _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
    584     if (resultData)
    585         mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
    586 
    587     return KERN_SUCCESS;
    588 }
    589 
    590 kern_return_t WKPCGetStringIdentifier(mach_port_t clientPort, data_t name, mach_msg_type_number_t nameCnt, uint64_t* identifier)
    591 {
    592     DataDeallocator deallocator(name, nameCnt);
    593 
    594     COMPILE_ASSERT(sizeof(*identifier) == sizeof(IdentifierRep*), identifier_sizes);
    595 
    596     *identifier = reinterpret_cast<uint64_t>(IdentifierRep::get(name));
    597     return KERN_SUCCESS;
    598 }
    599 
    600 kern_return_t WKPCGetIntIdentifier(mach_port_t clientPort, int32_t value, uint64_t* identifier)
    601 {
    602     COMPILE_ASSERT(sizeof(*identifier) == sizeof(NPIdentifier), identifier_sizes);
    603 
    604     *identifier = reinterpret_cast<uint64_t>(IdentifierRep::get(value));
    605     return KERN_SUCCESS;
    606 }
    607 
    608 static Identifier identifierFromIdentifierRep(IdentifierRep* identifier)
    609 {
    610     ASSERT(IdentifierRep::isValid(identifier));
    611     ASSERT(identifier->isString());
    612 
    613     const char* str = identifier->string();
    614     return Identifier(JSDOMWindow::commonJSGlobalData(), String::fromUTF8WithLatin1Fallback(str, strlen(str)));
    615 }
    616 
    617 kern_return_t WKPCInvoke(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier,
    618                          data_t argumentsData, mach_msg_type_number_t argumentsLength)
    619 {
    620     DataDeallocator deallocator(argumentsData, argumentsLength);
    621 
    622     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    623     if (!hostProxy)
    624         return KERN_FAILURE;
    625 
    626     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    627     if (!instanceProxy)
    628         return KERN_FAILURE;
    629 
    630     PluginDestroyDeferrer deferrer(instanceProxy);
    631 
    632     IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
    633     if (!IdentifierRep::isValid(identifier))
    634         return KERN_FAILURE;
    635 
    636     Identifier methodNameIdentifier = identifierFromIdentifierRep(identifier);
    637 
    638     data_t resultData = 0;
    639     mach_msg_type_number_t resultLength = 0;
    640     boolean_t returnValue = instanceProxy->invoke(objectID, methodNameIdentifier, argumentsData, argumentsLength, resultData, resultLength);
    641 
    642     _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
    643     if (resultData)
    644         mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
    645 
    646     return KERN_SUCCESS;
    647 }
    648 
    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)
    651 {
    652     DataDeallocator deallocator(argumentsData, argumentsLength);
    653 
    654     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    655     if (!hostProxy)
    656         return KERN_FAILURE;
    657 
    658     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    659     if (!instanceProxy)
    660         return KERN_FAILURE;
    661 
    662     PluginDestroyDeferrer deferrer(instanceProxy);
    663 
    664     data_t resultData = 0;
    665     mach_msg_type_number_t resultLength = 0;
    666     boolean_t returnValue = instanceProxy->invokeDefault(objectID, argumentsData, argumentsLength, resultData, resultLength);
    667 
    668     _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
    669     if (resultData)
    670         mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
    671 
    672     return KERN_SUCCESS;
    673 }
    674 
    675 kern_return_t WKPCConstruct(mach_port_t clientPort, uint32_t pluginID, uint32_t objectID,
    676                             data_t argumentsData, mach_msg_type_number_t argumentsLength,
    677                             boolean_t* returnValue, data_t* resultData, mach_msg_type_number_t* resultLength)
    678 {
    679     DataDeallocator deallocator(argumentsData, argumentsLength);
    680 
    681     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    682     if (!hostProxy)
    683         return KERN_FAILURE;
    684 
    685     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    686     if (!instanceProxy)
    687         return KERN_FAILURE;
    688 
    689     PluginDestroyDeferrer deferrer(instanceProxy);
    690 
    691     *returnValue = instanceProxy->construct(objectID, argumentsData, argumentsLength, *resultData, *resultLength);
    692 
    693     return KERN_SUCCESS;
    694 }
    695 
    696 kern_return_t WKPCGetProperty(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier)
    697 {
    698     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    699     if (!hostProxy)
    700         return KERN_FAILURE;
    701 
    702     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    703     if (!instanceProxy)
    704         return KERN_FAILURE;
    705 
    706     IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
    707     if (!IdentifierRep::isValid(identifier))
    708         return KERN_FAILURE;
    709 
    710     PluginDestroyDeferrer deferrer(instanceProxy);
    711 
    712     data_t resultData = 0;
    713     mach_msg_type_number_t resultLength = 0;
    714     boolean_t returnValue;
    715 
    716     if (identifier->isString()) {
    717         Identifier propertyNameIdentifier = identifierFromIdentifierRep(identifier);
    718         returnValue = instanceProxy->getProperty(objectID, propertyNameIdentifier, resultData, resultLength);
    719     } else
    720         returnValue = instanceProxy->setProperty(objectID, identifier->number(), resultData, resultLength);
    721 
    722     _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
    723     if (resultData)
    724         mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
    725 
    726     return KERN_SUCCESS;
    727 }
    728 
    729 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)
    730 {
    731     DataDeallocator deallocator(valueData, valueLength);
    732 
    733     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    734     if (!hostProxy)
    735         return KERN_FAILURE;
    736 
    737     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    738     if (!instanceProxy)
    739         return KERN_FAILURE;
    740 
    741     PluginDestroyDeferrer deferrer(instanceProxy);
    742 
    743     IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
    744     if (!IdentifierRep::isValid(identifier))
    745         return KERN_FAILURE;
    746 
    747     bool result;
    748     if (identifier->isString()) {
    749         Identifier propertyNameIdentifier = identifierFromIdentifierRep(identifier);
    750         result = instanceProxy->setProperty(objectID, propertyNameIdentifier, valueData, valueLength);
    751     } else
    752         result = instanceProxy->setProperty(objectID, identifier->number(), valueData, valueLength);
    753 
    754     _WKPHBooleanReply(hostProxy->port(), instanceProxy->pluginID(), requestID, result);
    755 
    756     return KERN_SUCCESS;
    757 }
    758 
    759 kern_return_t WKPCRemoveProperty(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier)
    760 {
    761     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    762     if (!hostProxy)
    763         return KERN_FAILURE;
    764 
    765     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    766     if (!instanceProxy)
    767         return KERN_FAILURE;
    768 
    769     PluginDestroyDeferrer deferrer(instanceProxy);
    770 
    771     IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
    772     if (!IdentifierRep::isValid(identifier))
    773         return KERN_FAILURE;
    774 
    775     bool result;
    776     if (identifier->isString()) {
    777         Identifier propertyNameIdentifier = identifierFromIdentifierRep(identifier);
    778         result = instanceProxy->removeProperty(objectID, propertyNameIdentifier);
    779     } else
    780         result = instanceProxy->removeProperty(objectID, identifier->number());
    781 
    782     _WKPHBooleanReply(hostProxy->port(), instanceProxy->pluginID(), requestID, result);
    783 
    784     return KERN_SUCCESS;
    785 }
    786 
    787 kern_return_t WKPCHasProperty(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier)
    788 {
    789     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    790     if (!hostProxy)
    791         return KERN_FAILURE;
    792 
    793     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    794     if (!instanceProxy)
    795         return KERN_FAILURE;
    796 
    797     PluginDestroyDeferrer deferrer(instanceProxy);
    798 
    799     IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
    800     if (!IdentifierRep::isValid(identifier))
    801         return KERN_FAILURE;
    802 
    803     boolean_t returnValue;
    804     if (identifier->isString()) {
    805         Identifier propertyNameIdentifier = identifierFromIdentifierRep(identifier);
    806         returnValue = instanceProxy->hasProperty(objectID, propertyNameIdentifier);
    807     } else
    808         returnValue = instanceProxy->hasProperty(objectID, identifier->number());
    809 
    810     _WKPHBooleanReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue);
    811 
    812     return KERN_SUCCESS;
    813 }
    814 
    815 kern_return_t WKPCHasMethod(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID, uint64_t serverIdentifier)
    816 {
    817     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    818     if (!hostProxy)
    819         return KERN_FAILURE;
    820 
    821     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    822     if (!instanceProxy)
    823         return KERN_FAILURE;
    824 
    825     PluginDestroyDeferrer deferrer(instanceProxy);
    826 
    827     IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
    828     if (!IdentifierRep::isValid(identifier))
    829         return KERN_FAILURE;
    830 
    831     Identifier methodNameIdentifier = identifierFromIdentifierRep(identifier);
    832     boolean_t returnValue = instanceProxy->hasMethod(objectID, methodNameIdentifier);
    833 
    834     _WKPHBooleanReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue);
    835 
    836     return KERN_SUCCESS;
    837 }
    838 
    839 kern_return_t WKPCIdentifierInfo(mach_port_t clientPort, uint64_t serverIdentifier, data_t* infoData, mach_msg_type_number_t* infoLength)
    840 {
    841     IdentifierRep* identifier = reinterpret_cast<IdentifierRep*>(serverIdentifier);
    842     if (!IdentifierRep::isValid(identifier))
    843         return KERN_FAILURE;
    844 
    845     id info;
    846     if (identifier->isString()) {
    847         const char* str = identifier->string();
    848         info = [NSData dataWithBytesNoCopy:(void*)str length:strlen(str) freeWhenDone:NO];
    849     } else
    850         info = [NSNumber numberWithInt:identifier->number()];
    851 
    852     RetainPtr<NSData*> data = [NSPropertyListSerialization dataFromPropertyList:info format:NSPropertyListBinaryFormat_v1_0 errorDescription:0];
    853     ASSERT(data);
    854 
    855     *infoLength = [data.get() length];
    856     mig_allocate(reinterpret_cast<vm_address_t*>(infoData), *infoLength);
    857 
    858     memcpy(*infoData, [data.get() bytes], *infoLength);
    859 
    860     return KERN_SUCCESS;
    861 }
    862 
    863 kern_return_t WKPCEnumerate(mach_port_t clientPort, uint32_t pluginID, uint32_t requestID, uint32_t objectID)
    864 {
    865     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    866     if (!hostProxy)
    867         return KERN_FAILURE;
    868 
    869     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    870     if (!instanceProxy)
    871         return KERN_FAILURE;
    872 
    873     data_t resultData = 0;
    874     mach_msg_type_number_t resultLength = 0;
    875     boolean_t returnValue = instanceProxy->enumerate(objectID, resultData, resultLength);
    876 
    877     _WKPHBooleanAndDataReply(hostProxy->port(), instanceProxy->pluginID(), requestID, returnValue, resultData, resultLength);
    878 
    879     if (resultData)
    880         mig_deallocate(reinterpret_cast<vm_address_t>(resultData), resultLength);
    881 
    882     return KERN_SUCCESS;
    883 }
    884 
    885 kern_return_t WKPCSetMenuBarVisible(mach_port_t clientPort, boolean_t menuBarVisible)
    886 {
    887     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    888     if (!hostProxy)
    889         return KERN_FAILURE;
    890 
    891     hostProxy->setMenuBarVisible(menuBarVisible);
    892 
    893     return KERN_SUCCESS;
    894 }
    895 
    896 kern_return_t WKPCSetFullScreenWindowIsShowing(mach_port_t clientPort, boolean_t fullScreenWindowIsShowing)
    897 {
    898     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    899     if (!hostProxy)
    900         return KERN_FAILURE;
    901 
    902     hostProxy->setFullScreenWindowIsShowing(fullScreenWindowIsShowing);
    903 
    904     return KERN_SUCCESS;
    905 }
    906 
    907 kern_return_t WKPCSetModal(mach_port_t clientPort, boolean_t modal)
    908 {
    909     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    910     if (!hostProxy)
    911         return KERN_FAILURE;
    912 
    913     hostProxy->setModal(modal);
    914 
    915     return KERN_SUCCESS;
    916 }
    917 
    918 kern_return_t WKPCGetCookies(mach_port_t clientPort, uint32_t pluginID,
    919                              data_t urlData, mach_msg_type_number_t urlLength,
    920                              boolean_t* returnValue, data_t* cookiesData, mach_msg_type_number_t* cookiesLength)
    921 {
    922     *cookiesData = 0;
    923     *cookiesLength = 0;
    924 
    925     DataDeallocator deallocator(urlData, urlLength);
    926 
    927     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    928     if (!hostProxy)
    929         return KERN_FAILURE;
    930 
    931     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    932     if (!instanceProxy)
    933         return KERN_FAILURE;
    934 
    935     *returnValue = instanceProxy->getCookies(urlData, urlLength, *cookiesData, *cookiesLength);
    936 
    937     return KERN_SUCCESS;
    938 }
    939 
    940 kern_return_t WKPCGetProxy(mach_port_t clientPort, uint32_t pluginID,
    941                            data_t urlData, mach_msg_type_number_t urlLength,
    942                            boolean_t* returnValue, data_t* proxyData, mach_msg_type_number_t* proxyLength)
    943 {
    944     *proxyData = 0;
    945     *proxyLength = 0;
    946 
    947     DataDeallocator deallocator(urlData, urlLength);
    948 
    949     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    950     if (!hostProxy)
    951         return KERN_FAILURE;
    952 
    953     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    954     if (!instanceProxy)
    955         return KERN_FAILURE;
    956 
    957     *returnValue = instanceProxy->getProxy(urlData, urlLength, *proxyData, *proxyLength);
    958 
    959     return KERN_SUCCESS;
    960 }
    961 
    962 kern_return_t WKPCSetCookies(mach_port_t clientPort, uint32_t pluginID,
    963                              data_t urlData, mach_msg_type_number_t urlLength,
    964                              data_t cookiesData, mach_msg_type_number_t cookiesLength,
    965                              boolean_t* returnValue)
    966 {
    967     DataDeallocator urlDeallocator(urlData, urlLength);
    968     DataDeallocator cookiesDeallocator(cookiesData, cookiesLength);
    969 
    970     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
    971     if (!hostProxy)
    972         return KERN_FAILURE;
    973 
    974     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
    975     if (!instanceProxy)
    976         return KERN_FAILURE;
    977 
    978     *returnValue = instanceProxy->setCookies(urlData, urlLength, cookiesData, cookiesLength);
    979     return KERN_SUCCESS;
    980 }
    981 
    982 kern_return_t WKPCGetAuthenticationInfo(mach_port_t clientPort, uint32_t pluginID,
    983                                         data_t protocolData, mach_msg_type_number_t protocolLength,
    984                                         data_t hostData, mach_msg_type_number_t hostLength,
    985                                         uint32_t port,
    986                                         data_t schemeData, mach_msg_type_number_t schemeLength,
    987                                         data_t realmData, mach_msg_type_number_t realmLength,
    988                                         boolean_t* returnValue,
    989                                         data_t* usernameData, mach_msg_type_number_t *usernameLength,
    990                                         data_t* passwordData, mach_msg_type_number_t *passwordLength)
    991 {
    992     DataDeallocator protocolDeallocator(protocolData, protocolLength);
    993     DataDeallocator hostDeallocator(hostData, hostLength);
    994     DataDeallocator schemeDeallocator(schemeData, schemeLength);
    995     DataDeallocator realmDeallocator(realmData, realmLength);
    996 
    997     *usernameData = 0;
    998     *usernameLength = 0;
    999     *passwordData = 0;
   1000     *passwordLength = 0;
   1001 
   1002     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
   1003     if (!hostProxy)
   1004         return KERN_FAILURE;
   1005 
   1006     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
   1007     if (!instanceProxy)
   1008         return KERN_FAILURE;
   1009 
   1010     *returnValue = instanceProxy->getAuthenticationInfo(protocolData, hostData, port, schemeData, realmData, *usernameData, *usernameLength, *passwordData, *passwordLength);
   1011 
   1012     return KERN_SUCCESS;
   1013 }
   1014 
   1015 kern_return_t WKPCConvertPoint(mach_port_t clientPort, uint32_t pluginID,
   1016                                double sourceX, double sourceY, uint32_t sourceSpace,
   1017                                uint32_t destSpace, boolean_t *returnValue, double *destX, double *destY)
   1018 {
   1019     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
   1020     if (!hostProxy)
   1021         return KERN_FAILURE;
   1022 
   1023     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
   1024     if (!instanceProxy)
   1025         return KERN_FAILURE;
   1026 
   1027     *returnValue = instanceProxy->convertPoint(sourceX, sourceY, static_cast<NPCoordinateSpace>(sourceSpace),
   1028                                                *destX, *destY, static_cast<NPCoordinateSpace>(destSpace));
   1029     return KERN_SUCCESS;
   1030 }
   1031 
   1032 kern_return_t WKPCCheckIfAllowedToLoadURL(mach_port_t clientPort, uint32_t pluginID, data_t urlData, mach_msg_type_number_t urlLength,
   1033                                           data_t targetData, mach_msg_type_number_t targetLength, uint32_t *checkID)
   1034 {
   1035     DataDeallocator urlDeallocator(urlData, urlLength);
   1036     DataDeallocator targetDeallocator(targetData, targetLength);
   1037 
   1038     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
   1039     if (!hostProxy)
   1040         return KERN_FAILURE;
   1041 
   1042     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
   1043     if (!instanceProxy)
   1044         return KERN_FAILURE;
   1045 
   1046     *checkID = instanceProxy->checkIfAllowedToLoadURL(urlData, targetData);
   1047     return KERN_SUCCESS;
   1048 }
   1049 
   1050 kern_return_t WKPCCancelCheckIfAllowedToLoadURL(mach_port_t clientPort, uint32_t pluginID, uint32_t checkID)
   1051 {
   1052     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
   1053     if (!hostProxy)
   1054         return KERN_FAILURE;
   1055 
   1056     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
   1057     if (!instanceProxy)
   1058         return KERN_FAILURE;
   1059 
   1060     instanceProxy->cancelCheckIfAllowedToLoadURL(checkID);
   1061     return KERN_SUCCESS;
   1062 }
   1063 
   1064 kern_return_t WKPCResolveURL(mach_port_t clientPort, uint32_t pluginID, data_t urlData, mach_msg_type_number_t urlLength,
   1065                              data_t targetData, mach_msg_type_number_t targetLength,
   1066                              data_t *resolvedURLData, mach_msg_type_number_t *resolvedURLLength)
   1067 {
   1068     DataDeallocator urlDeallocator(urlData, urlLength);
   1069     DataDeallocator targetDeallocator(targetData, targetLength);
   1070 
   1071     *resolvedURLData = 0;
   1072     *resolvedURLLength = 0;
   1073 
   1074     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
   1075     if (!hostProxy)
   1076         return KERN_FAILURE;
   1077 
   1078     NetscapePluginInstanceProxy* instanceProxy = hostProxy->pluginInstance(pluginID);
   1079     if (!instanceProxy)
   1080         return KERN_FAILURE;
   1081 
   1082     instanceProxy->resolveURL(urlData, targetData, *resolvedURLData, *resolvedURLLength);
   1083     return KERN_SUCCESS;
   1084 }
   1085 
   1086 #if !defined(BUILDING_ON_SNOW_LEOPARD)
   1087 kern_return_t WKPCRunSyncOpenPanel(mach_port_t clientPort, data_t panelData, mach_msg_type_number_t panelDataLength)
   1088 {
   1089     DataDeallocator panelDataDeallocator(panelData, panelDataLength);
   1090 
   1091     NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
   1092     if (!hostProxy)
   1093         return KERN_FAILURE;
   1094 
   1095     NSOpenPanel *sheet = [NSOpenPanel openPanel];
   1096     NSDictionary *panelState = [NSPropertyListSerialization propertyListFromData:[NSData dataWithBytes:panelData length:panelDataLength]
   1097                                                                 mutabilityOption:NSPropertyListImmutable
   1098                                                                           format:NULL
   1099                                                                 errorDescription:nil];
   1100 
   1101     [sheet setCanChooseFiles:[[panelState objectForKey:@"canChooseFiles"] boolValue]];
   1102     [sheet setCanChooseDirectories:[[panelState objectForKey:@"canChooseDirectories"] boolValue]];
   1103     [sheet setResolvesAliases:[[panelState objectForKey:@"resolvesAliases"] boolValue]];
   1104     [sheet setAllowsMultipleSelection:[[panelState objectForKey:@"allowsMultipleSelection"] boolValue]];
   1105     [sheet setCanCreateDirectories:[[panelState objectForKey:@"canCreateDirectories"] boolValue]];
   1106     [sheet setShowsHiddenFiles:[[panelState objectForKey:@"showsHiddenFiles"] boolValue]];
   1107     [sheet setExtensionHidden:[[panelState objectForKey:@"isExtensionHidden"] boolValue]];
   1108     [sheet setCanSelectHiddenExtension:[[panelState objectForKey:@"canSelectHiddenExtension"] boolValue]];
   1109     [sheet setAllowsOtherFileTypes:[[panelState objectForKey:@"allowsOtherFileTypes"] boolValue]];
   1110     [sheet setTreatsFilePackagesAsDirectories:[[panelState objectForKey:@"treatsFilePackagesAsDirectories"] boolValue]];
   1111     [sheet setPrompt:[panelState objectForKey:@"prompt"]];
   1112     [sheet setNameFieldLabel:[panelState objectForKey:@"nameFieldLabel"]];
   1113     [sheet setMessage:[panelState objectForKey:@"message"]];
   1114     [sheet setAllowedFileTypes:[panelState objectForKey:@"allowedFileTypes"]];
   1115     [sheet setRequiredFileType:[panelState objectForKey:@"requiredFileType"]];
   1116     [sheet setTitle:[panelState objectForKey:@"title"]];
   1117     [sheet runModal];
   1118 
   1119     NSDictionary *ret = [NSDictionary dictionaryWithObjectsAndKeys:
   1120                          [sheet filenames], @"filenames",
   1121                          WKNoteOpenPanelFiles([sheet filenames]), @"extensions",
   1122                          nil];
   1123 
   1124     RetainPtr<NSData*> data = [NSPropertyListSerialization dataFromPropertyList:ret format:NSPropertyListBinaryFormat_v1_0 errorDescription:0];
   1125     ASSERT(data);
   1126 
   1127     _WKPHSyncOpenPanelReply(hostProxy->port(), const_cast<char *>(static_cast<const char*>([data.get() bytes])), [data.get() length]);
   1128     return KERN_SUCCESS;
   1129 }
   1130 #else
   1131 kern_return_t WKPCRunSyncOpenPanel(mach_port_t clientPort, data_t panelData, mach_msg_type_number_t panelDataLength)
   1132 {
   1133     return KERN_FAILURE;
   1134 }
   1135 #endif // !defined(BUILDING_ON_SNOW_LEOPARD)
   1136 
   1137 kern_return_t WKPCSetException(mach_port_t clientPort, data_t message, mach_msg_type_number_t messageCnt)
   1138 {
   1139     DataDeallocator deallocator(message, messageCnt);
   1140 
   1141     string str(message, messageCnt);
   1142     NetscapePluginInstanceProxy::setGlobalException(str.c_str());
   1143 
   1144     return KERN_SUCCESS;
   1145 }
   1146 
   1147 #endif // USE(PLUGIN_HOST_PROCESS)
   1148