Home | History | Annotate | Download | only in Netscape
      1 /*
      2  * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "NetscapePlugin.h"
     28 
     29 #include "NPRuntimeObjectMap.h"
     30 #include "NetscapePluginStream.h"
     31 #include "PluginController.h"
     32 #include "ShareableBitmap.h"
     33 #include <WebCore/GraphicsContext.h>
     34 #include <WebCore/HTTPHeaderMap.h>
     35 #include <WebCore/IntRect.h>
     36 #include <WebCore/KURL.h>
     37 #include <utility>
     38 #include <wtf/text/CString.h>
     39 
     40 using namespace WebCore;
     41 using namespace std;
     42 
     43 namespace WebKit {
     44 
     45 // The plug-in that we're currently calling NPP_New for.
     46 static NetscapePlugin* currentNPPNewPlugin;
     47 
     48 PassRefPtr<NetscapePlugin> NetscapePlugin::create(PassRefPtr<NetscapePluginModule> pluginModule)
     49 {
     50     if (!pluginModule)
     51         return 0;
     52 
     53     return adoptRef(new NetscapePlugin(pluginModule));
     54 }
     55 
     56 NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
     57     : m_pluginController(0)
     58     , m_nextRequestID(0)
     59     , m_pluginModule(pluginModule)
     60     , m_npWindow()
     61     , m_isStarted(false)
     62 #if PLATFORM(MAC)
     63     , m_isWindowed(false)
     64 #else
     65     , m_isWindowed(true)
     66 #endif
     67     , m_isTransparent(false)
     68     , m_inNPPNew(false)
     69     , m_loadManually(false)
     70 #if PLATFORM(MAC)
     71     , m_drawingModel(static_cast<NPDrawingModel>(-1))
     72     , m_eventModel(static_cast<NPEventModel>(-1))
     73     , m_currentMouseEvent(0)
     74     , m_pluginHasFocus(false)
     75     , m_windowHasFocus(false)
     76 #ifndef NP_NO_CARBON
     77     , m_nullEventTimer(RunLoop::main(), this, &NetscapePlugin::nullEventTimerFired)
     78     , m_npCGContext()
     79 #endif
     80 #elif PLUGIN_ARCHITECTURE(X11)
     81     , m_drawable(0)
     82     , m_pluginDisplay(0)
     83 #endif
     84 {
     85     m_npp.ndata = this;
     86     m_npp.pdata = 0;
     87 
     88     m_pluginModule->incrementLoadCount();
     89 }
     90 
     91 NetscapePlugin::~NetscapePlugin()
     92 {
     93     ASSERT(!m_isStarted);
     94 
     95     m_pluginModule->decrementLoadCount();
     96 }
     97 
     98 PassRefPtr<NetscapePlugin> NetscapePlugin::fromNPP(NPP npp)
     99 {
    100     if (npp)
    101         return static_cast<NetscapePlugin*>(npp->ndata);
    102 
    103     // FIXME: Return the current NetscapePlugin here.
    104     ASSERT_NOT_REACHED();
    105     return 0;
    106 }
    107 
    108 void NetscapePlugin::invalidate(const NPRect* invalidRect)
    109 {
    110     IntRect rect;
    111 
    112     if (!invalidRect)
    113         rect = IntRect(0, 0, m_frameRect.width(), m_frameRect.height());
    114     else
    115         rect = IntRect(invalidRect->left, invalidRect->top,
    116                        invalidRect->right - invalidRect->left, invalidRect->bottom - invalidRect->top);
    117 
    118     if (platformInvalidate(rect))
    119         return;
    120 
    121     m_pluginController->invalidate(rect);
    122 }
    123 
    124 const char* NetscapePlugin::userAgent(NPP npp)
    125 {
    126     if (npp)
    127         return fromNPP(npp)->userAgent();
    128 
    129     if (currentNPPNewPlugin)
    130         return currentNPPNewPlugin->userAgent();
    131 
    132     return 0;
    133 }
    134 
    135 const char* NetscapePlugin::userAgent()
    136 {
    137     if (m_userAgent.isNull()) {
    138         m_userAgent = m_pluginController->userAgent().utf8();
    139         ASSERT(!m_userAgent.isNull());
    140     }
    141     return m_userAgent.data();
    142 }
    143 
    144 void NetscapePlugin::loadURL(const String& method, const String& urlString, const String& target, const HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody,
    145                              bool sendNotification, void* notificationData)
    146 {
    147     uint64_t requestID = ++m_nextRequestID;
    148 
    149     m_pluginController->loadURL(requestID, method, urlString, target, headerFields, httpBody, allowPopups());
    150 
    151     if (target.isNull()) {
    152         // The browser is going to send the data in a stream, create a plug-in stream.
    153         RefPtr<NetscapePluginStream> pluginStream = NetscapePluginStream::create(this, requestID, sendNotification, notificationData);
    154         ASSERT(!m_streams.contains(requestID));
    155 
    156         m_streams.set(requestID, pluginStream.release());
    157         return;
    158     }
    159 
    160     if (sendNotification) {
    161         // Eventually we are going to get a frameDidFinishLoading or frameDidFail call for this request.
    162         // Keep track of the notification data so we can call NPP_URLNotify.
    163         ASSERT(!m_pendingURLNotifications.contains(requestID));
    164         m_pendingURLNotifications.set(requestID, make_pair(urlString, notificationData));
    165     }
    166 }
    167 
    168 NPError NetscapePlugin::destroyStream(NPStream* stream, NPReason reason)
    169 {
    170     NetscapePluginStream* pluginStream = 0;
    171 
    172     for (StreamsMap::const_iterator it = m_streams.begin(), end = m_streams.end(); it != end; ++it) {
    173         if (it->second->npStream() == stream) {
    174             pluginStream = it->second.get();
    175             break;
    176         }
    177     }
    178 
    179     if (!pluginStream)
    180         return NPERR_INVALID_INSTANCE_ERROR;
    181 
    182     return pluginStream->destroy(reason);
    183 }
    184 
    185 void NetscapePlugin::setIsWindowed(bool isWindowed)
    186 {
    187     // Once the plugin has started, it's too late to change whether the plugin is windowed or not.
    188     // (This is true in Firefox and Chrome, too.) Disallow setting m_isWindowed in that case to
    189     // keep our internal state consistent.
    190     if (m_isStarted)
    191         return;
    192 
    193     m_isWindowed = isWindowed;
    194 }
    195 
    196 void NetscapePlugin::setIsTransparent(bool isTransparent)
    197 {
    198     m_isTransparent = isTransparent;
    199 }
    200 
    201 void NetscapePlugin::setStatusbarText(const String& statusbarText)
    202 {
    203     m_pluginController->setStatusbarText(statusbarText);
    204 }
    205 
    206 void NetscapePlugin::setException(const String& exceptionString)
    207 {
    208     // FIXME: If the plug-in is running in its own process, this needs to send a CoreIPC message instead of
    209     // calling the runtime object map directly.
    210     NPRuntimeObjectMap::setGlobalException(exceptionString);
    211 }
    212 
    213 bool NetscapePlugin::evaluate(NPObject* npObject, const String& scriptString, NPVariant* result)
    214 {
    215     return m_pluginController->evaluate(npObject, scriptString, result, allowPopups());
    216 }
    217 
    218 bool NetscapePlugin::isPrivateBrowsingEnabled()
    219 {
    220     return m_pluginController->isPrivateBrowsingEnabled();
    221 }
    222 
    223 NPObject* NetscapePlugin::windowScriptNPObject()
    224 {
    225     return m_pluginController->windowScriptNPObject();
    226 }
    227 
    228 NPObject* NetscapePlugin::pluginElementNPObject()
    229 {
    230     return m_pluginController->pluginElementNPObject();
    231 }
    232 
    233 void NetscapePlugin::cancelStreamLoad(NetscapePluginStream* pluginStream)
    234 {
    235     if (pluginStream == m_manualStream) {
    236         m_pluginController->cancelManualStreamLoad();
    237         return;
    238     }
    239 
    240     // Ask the plug-in controller to cancel this stream load.
    241     m_pluginController->cancelStreamLoad(pluginStream->streamID());
    242 }
    243 
    244 void NetscapePlugin::removePluginStream(NetscapePluginStream* pluginStream)
    245 {
    246     if (pluginStream == m_manualStream) {
    247         m_manualStream = 0;
    248         return;
    249     }
    250 
    251     ASSERT(m_streams.get(pluginStream->streamID()) == pluginStream);
    252     m_streams.remove(pluginStream->streamID());
    253 }
    254 
    255 bool NetscapePlugin::isAcceleratedCompositingEnabled()
    256 {
    257 #if USE(ACCELERATED_COMPOSITING)
    258     return m_pluginController->isAcceleratedCompositingEnabled();
    259 #else
    260     return false;
    261 #endif
    262 }
    263 
    264 void NetscapePlugin::pushPopupsEnabledState(bool state)
    265 {
    266     m_popupEnabledStates.append(state);
    267 }
    268 
    269 void NetscapePlugin::popPopupsEnabledState()
    270 {
    271     ASSERT(!m_popupEnabledStates.isEmpty());
    272 
    273     m_popupEnabledStates.removeLast();
    274 }
    275 
    276 String NetscapePlugin::proxiesForURL(const String& urlString)
    277 {
    278     return m_pluginController->proxiesForURL(urlString);
    279 }
    280 
    281 String NetscapePlugin::cookiesForURL(const String& urlString)
    282 {
    283     return m_pluginController->cookiesForURL(urlString);
    284 }
    285 
    286 void NetscapePlugin::setCookiesForURL(const String& urlString, const String& cookieString)
    287 {
    288     m_pluginController->setCookiesForURL(urlString, cookieString);
    289 }
    290 
    291 NPError NetscapePlugin::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* savedData)
    292 {
    293     return m_pluginModule->pluginFuncs().newp(pluginType, &m_npp, mode, argc, argn, argv, savedData);
    294 }
    295 
    296 NPError NetscapePlugin::NPP_Destroy(NPSavedData** savedData)
    297 {
    298     return m_pluginModule->pluginFuncs().destroy(&m_npp, savedData);
    299 }
    300 
    301 NPError NetscapePlugin::NPP_SetWindow(NPWindow* npWindow)
    302 {
    303     return m_pluginModule->pluginFuncs().setwindow(&m_npp, npWindow);
    304 }
    305 
    306 NPError NetscapePlugin::NPP_NewStream(NPMIMEType mimeType, NPStream* stream, NPBool seekable, uint16_t* streamType)
    307 {
    308     return m_pluginModule->pluginFuncs().newstream(&m_npp, mimeType, stream, seekable, streamType);
    309 }
    310 
    311 NPError NetscapePlugin::NPP_DestroyStream(NPStream* stream, NPReason reason)
    312 {
    313     return m_pluginModule->pluginFuncs().destroystream(&m_npp, stream, reason);
    314 }
    315 
    316 void NetscapePlugin::NPP_StreamAsFile(NPStream* stream, const char* filename)
    317 {
    318     return m_pluginModule->pluginFuncs().asfile(&m_npp, stream, filename);
    319 }
    320 
    321 int32_t NetscapePlugin::NPP_WriteReady(NPStream* stream)
    322 {
    323     return m_pluginModule->pluginFuncs().writeready(&m_npp, stream);
    324 }
    325 
    326 int32_t NetscapePlugin::NPP_Write(NPStream* stream, int32_t offset, int32_t len, void* buffer)
    327 {
    328     return m_pluginModule->pluginFuncs().write(&m_npp, stream, offset, len, buffer);
    329 }
    330 
    331 int16_t NetscapePlugin::NPP_HandleEvent(void* event)
    332 {
    333     return m_pluginModule->pluginFuncs().event(&m_npp, event);
    334 }
    335 
    336 void NetscapePlugin::NPP_URLNotify(const char* url, NPReason reason, void* notifyData)
    337 {
    338     m_pluginModule->pluginFuncs().urlnotify(&m_npp, url, reason, notifyData);
    339 }
    340 
    341 NPError NetscapePlugin::NPP_GetValue(NPPVariable variable, void *value)
    342 {
    343     if (!m_pluginModule->pluginFuncs().getvalue)
    344         return NPERR_GENERIC_ERROR;
    345 
    346     return m_pluginModule->pluginFuncs().getvalue(&m_npp, variable, value);
    347 }
    348 
    349 NPError NetscapePlugin::NPP_SetValue(NPNVariable variable, void *value)
    350 {
    351     if (!m_pluginModule->pluginFuncs().setvalue)
    352         return NPERR_GENERIC_ERROR;
    353 
    354     return m_pluginModule->pluginFuncs().setvalue(&m_npp, variable, value);
    355 }
    356 
    357 void NetscapePlugin::callSetWindow()
    358 {
    359 #if PLUGIN_ARCHITECTURE(X11)
    360     // We use a backing store as the painting area for the plugin.
    361     m_npWindow.x = 0;
    362     m_npWindow.y = 0;
    363 #else
    364     m_npWindow.x = m_frameRect.x();
    365     m_npWindow.y = m_frameRect.y();
    366 #endif
    367     m_npWindow.width = m_frameRect.width();
    368     m_npWindow.height = m_frameRect.height();
    369     m_npWindow.clipRect.top = m_clipRect.y();
    370     m_npWindow.clipRect.left = m_clipRect.x();
    371     m_npWindow.clipRect.bottom = m_clipRect.maxY();
    372     m_npWindow.clipRect.right = m_clipRect.maxX();
    373 
    374     NPP_SetWindow(&m_npWindow);
    375 }
    376 
    377 bool NetscapePlugin::shouldLoadSrcURL()
    378 {
    379     // Check if we should cancel the load
    380     NPBool cancelSrcStream = false;
    381 
    382     if (NPP_GetValue(NPPVpluginCancelSrcStream, &cancelSrcStream) != NPERR_NO_ERROR)
    383         return true;
    384 
    385     return !cancelSrcStream;
    386 }
    387 
    388 NetscapePluginStream* NetscapePlugin::streamFromID(uint64_t streamID)
    389 {
    390     return m_streams.get(streamID).get();
    391 }
    392 
    393 void NetscapePlugin::stopAllStreams()
    394 {
    395     Vector<RefPtr<NetscapePluginStream> > streams;
    396     copyValuesToVector(m_streams, streams);
    397 
    398     for (size_t i = 0; i < streams.size(); ++i)
    399         streams[i]->stop(NPRES_USER_BREAK);
    400 }
    401 
    402 bool NetscapePlugin::allowPopups() const
    403 {
    404     if (m_pluginModule->pluginFuncs().version >= NPVERS_HAS_POPUPS_ENABLED_STATE) {
    405         if (!m_popupEnabledStates.isEmpty())
    406             return m_popupEnabledStates.last();
    407     }
    408 
    409     // FIXME: Check if the current event is a user gesture.
    410     // Really old versions of Flash required this for popups to work, but all newer versions
    411     // support NPN_PushPopupEnabledState/NPN_PopPopupEnabledState.
    412     return false;
    413 }
    414 
    415 bool NetscapePlugin::initialize(PluginController* pluginController, const Parameters& parameters)
    416 {
    417     ASSERT(!m_pluginController);
    418     ASSERT(pluginController);
    419 
    420     m_pluginController = pluginController;
    421 
    422     uint16_t mode = parameters.loadManually ? NP_FULL : NP_EMBED;
    423 
    424     m_loadManually = parameters.loadManually;
    425 
    426     CString mimeTypeCString = parameters.mimeType.utf8();
    427 
    428     ASSERT(parameters.names.size() == parameters.values.size());
    429 
    430     Vector<CString> paramNames;
    431     Vector<CString> paramValues;
    432     for (size_t i = 0; i < parameters.names.size(); ++i) {
    433         paramNames.append(parameters.names[i].utf8());
    434         paramValues.append(parameters.values[i].utf8());
    435     }
    436 
    437     // The strings that these pointers point to are kept alive by paramNames and paramValues.
    438     Vector<const char*> names;
    439     Vector<const char*> values;
    440     for (size_t i = 0; i < paramNames.size(); ++i) {
    441         names.append(paramNames[i].data());
    442         values.append(paramValues[i].data());
    443     }
    444 
    445 #if PLATFORM(MAC)
    446     if (m_pluginModule->pluginQuirks().contains(PluginQuirks::MakeTransparentIfBackgroundAttributeExists)) {
    447         for (size_t i = 0; i < parameters.names.size(); ++i) {
    448             if (equalIgnoringCase(parameters.names[i], "background")) {
    449                 setIsTransparent(true);
    450                 break;
    451             }
    452         }
    453     }
    454 #endif
    455 
    456     NetscapePlugin* previousNPPNewPlugin = currentNPPNewPlugin;
    457 
    458     m_inNPPNew = true;
    459     currentNPPNewPlugin = this;
    460 
    461     NPError error = NPP_New(const_cast<char*>(mimeTypeCString.data()), mode, names.size(),
    462                             const_cast<char**>(names.data()), const_cast<char**>(values.data()), 0);
    463 
    464     m_inNPPNew = false;
    465     currentNPPNewPlugin = previousNPPNewPlugin;
    466 
    467     if (error != NPERR_NO_ERROR)
    468         return false;
    469 
    470     m_isStarted = true;
    471 
    472     // FIXME: This is not correct in all cases.
    473     m_npWindow.type = NPWindowTypeDrawable;
    474 
    475     if (!platformPostInitialize()) {
    476         destroy();
    477         return false;
    478     }
    479 
    480     // Load the src URL if needed.
    481     if (!parameters.loadManually && !parameters.url.isEmpty() && shouldLoadSrcURL())
    482         loadURL("GET", parameters.url.string(), String(), HTTPHeaderMap(), Vector<uint8_t>(), false, 0);
    483 
    484     return true;
    485 }
    486 
    487 void NetscapePlugin::destroy()
    488 {
    489     ASSERT(m_isStarted);
    490 
    491     // Stop all streams.
    492     stopAllStreams();
    493 
    494 #if !PLUGIN_ARCHITECTURE(MAC)
    495     m_npWindow.window = 0;
    496     callSetWindow();
    497 #endif
    498 
    499     NPP_Destroy(0);
    500 
    501     m_isStarted = false;
    502     m_pluginController = 0;
    503 
    504     platformDestroy();
    505 }
    506 
    507 void NetscapePlugin::paint(GraphicsContext* context, const IntRect& dirtyRect)
    508 {
    509     ASSERT(m_isStarted);
    510 
    511     platformPaint(context, dirtyRect);
    512 }
    513 
    514 PassRefPtr<ShareableBitmap> NetscapePlugin::snapshot()
    515 {
    516     if (!supportsSnapshotting() || m_frameRect.isEmpty())
    517         return 0;
    518 
    519     ASSERT(m_isStarted);
    520 
    521     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(m_frameRect.size(), ShareableBitmap::SupportsAlpha);
    522     OwnPtr<GraphicsContext> context = bitmap->createGraphicsContext();
    523 
    524     context->translate(-m_frameRect.x(), -m_frameRect.y());
    525 
    526     platformPaint(context.get(), m_frameRect, true);
    527 
    528     return bitmap.release();
    529 }
    530 
    531 bool NetscapePlugin::isTransparent()
    532 {
    533     return m_isTransparent;
    534 }
    535 
    536 void NetscapePlugin::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect)
    537 {
    538     ASSERT(m_isStarted);
    539 
    540     if (m_frameRect == frameRect && m_clipRect == clipRect) {
    541         // Nothing to do.
    542         return;
    543     }
    544 
    545     m_frameRect = frameRect;
    546     m_clipRect = clipRect;
    547 
    548     platformGeometryDidChange();
    549     callSetWindow();
    550 }
    551 
    552 void NetscapePlugin::frameDidFinishLoading(uint64_t requestID)
    553 {
    554     ASSERT(m_isStarted);
    555 
    556     PendingURLNotifyMap::iterator it = m_pendingURLNotifications.find(requestID);
    557     if (it == m_pendingURLNotifications.end())
    558         return;
    559 
    560     String url = it->second.first;
    561     void* notificationData = it->second.second;
    562 
    563     m_pendingURLNotifications.remove(it);
    564 
    565     NPP_URLNotify(url.utf8().data(), NPRES_DONE, notificationData);
    566 }
    567 
    568 void NetscapePlugin::frameDidFail(uint64_t requestID, bool wasCancelled)
    569 {
    570     ASSERT(m_isStarted);
    571 
    572     PendingURLNotifyMap::iterator it = m_pendingURLNotifications.find(requestID);
    573     if (it == m_pendingURLNotifications.end())
    574         return;
    575 
    576     String url = it->second.first;
    577     void* notificationData = it->second.second;
    578 
    579     m_pendingURLNotifications.remove(it);
    580 
    581     NPP_URLNotify(url.utf8().data(), wasCancelled ? NPRES_USER_BREAK : NPRES_NETWORK_ERR, notificationData);
    582 }
    583 
    584 void NetscapePlugin::didEvaluateJavaScript(uint64_t requestID, const String& requestURLString, const String& result)
    585 {
    586     ASSERT(m_isStarted);
    587 
    588     if (NetscapePluginStream* pluginStream = streamFromID(requestID))
    589         pluginStream->sendJavaScriptStream(requestURLString, result);
    590 }
    591 
    592 void NetscapePlugin::streamDidReceiveResponse(uint64_t streamID, const KURL& responseURL, uint32_t streamLength,
    593                                               uint32_t lastModifiedTime, const String& mimeType, const String& headers)
    594 {
    595     ASSERT(m_isStarted);
    596 
    597     if (NetscapePluginStream* pluginStream = streamFromID(streamID))
    598         pluginStream->didReceiveResponse(responseURL, streamLength, lastModifiedTime, mimeType, headers);
    599 }
    600 
    601 void NetscapePlugin::streamDidReceiveData(uint64_t streamID, const char* bytes, int length)
    602 {
    603     ASSERT(m_isStarted);
    604 
    605     if (NetscapePluginStream* pluginStream = streamFromID(streamID))
    606         pluginStream->didReceiveData(bytes, length);
    607 }
    608 
    609 void NetscapePlugin::streamDidFinishLoading(uint64_t streamID)
    610 {
    611     ASSERT(m_isStarted);
    612 
    613     if (NetscapePluginStream* pluginStream = streamFromID(streamID))
    614         pluginStream->didFinishLoading();
    615 }
    616 
    617 void NetscapePlugin::streamDidFail(uint64_t streamID, bool wasCancelled)
    618 {
    619     ASSERT(m_isStarted);
    620 
    621     if (NetscapePluginStream* pluginStream = streamFromID(streamID))
    622         pluginStream->didFail(wasCancelled);
    623 }
    624 
    625 void NetscapePlugin::manualStreamDidReceiveResponse(const KURL& responseURL, uint32_t streamLength, uint32_t lastModifiedTime,
    626                                                     const String& mimeType, const String& headers)
    627 {
    628     ASSERT(m_isStarted);
    629     ASSERT(m_loadManually);
    630     ASSERT(!m_manualStream);
    631 
    632     m_manualStream = NetscapePluginStream::create(this, 0, false, 0);
    633     m_manualStream->didReceiveResponse(responseURL, streamLength, lastModifiedTime, mimeType, headers);
    634 }
    635 
    636 void NetscapePlugin::manualStreamDidReceiveData(const char* bytes, int length)
    637 {
    638     ASSERT(m_isStarted);
    639     ASSERT(m_loadManually);
    640     ASSERT(m_manualStream);
    641 
    642     m_manualStream->didReceiveData(bytes, length);
    643 }
    644 
    645 void NetscapePlugin::manualStreamDidFinishLoading()
    646 {
    647     ASSERT(m_isStarted);
    648     ASSERT(m_loadManually);
    649     ASSERT(m_manualStream);
    650 
    651     m_manualStream->didFinishLoading();
    652 }
    653 
    654 void NetscapePlugin::manualStreamDidFail(bool wasCancelled)
    655 {
    656     ASSERT(m_isStarted);
    657     ASSERT(m_loadManually);
    658     ASSERT(m_manualStream);
    659 
    660     m_manualStream->didFail(wasCancelled);
    661 }
    662 
    663 bool NetscapePlugin::handleMouseEvent(const WebMouseEvent& mouseEvent)
    664 {
    665     ASSERT(m_isStarted);
    666 
    667     return platformHandleMouseEvent(mouseEvent);
    668 }
    669 
    670 bool NetscapePlugin::handleWheelEvent(const WebWheelEvent& wheelEvent)
    671 {
    672     ASSERT(m_isStarted);
    673 
    674     return platformHandleWheelEvent(wheelEvent);
    675 }
    676 
    677 bool NetscapePlugin::handleMouseEnterEvent(const WebMouseEvent& mouseEvent)
    678 {
    679     ASSERT(m_isStarted);
    680 
    681     return platformHandleMouseEnterEvent(mouseEvent);
    682 }
    683 
    684 bool NetscapePlugin::handleMouseLeaveEvent(const WebMouseEvent& mouseEvent)
    685 {
    686     ASSERT(m_isStarted);
    687 
    688     return platformHandleMouseLeaveEvent(mouseEvent);
    689 }
    690 
    691 bool NetscapePlugin::handleKeyboardEvent(const WebKeyboardEvent& keyboardEvent)
    692 {
    693     ASSERT(m_isStarted);
    694 
    695     return platformHandleKeyboardEvent(keyboardEvent);
    696 }
    697 
    698 void NetscapePlugin::setFocus(bool hasFocus)
    699 {
    700     ASSERT(m_isStarted);
    701 
    702     platformSetFocus(hasFocus);
    703 }
    704 
    705 NPObject* NetscapePlugin::pluginScriptableNPObject()
    706 {
    707     ASSERT(m_isStarted);
    708     NPObject* scriptableNPObject = 0;
    709 
    710     if (NPP_GetValue(NPPVpluginScriptableNPObject, &scriptableNPObject) != NPERR_NO_ERROR)
    711         return 0;
    712 
    713     return scriptableNPObject;
    714 }
    715 
    716 void NetscapePlugin::privateBrowsingStateChanged(bool privateBrowsingEnabled)
    717 {
    718     ASSERT(m_isStarted);
    719 
    720     // From https://wiki.mozilla.org/Plugins:PrivateMode
    721     //   When the browser turns private mode on or off it will call NPP_SetValue for "NPNVprivateModeBool"
    722     //   (assigned enum value 18) with a pointer to an NPBool value on all applicable instances.
    723     //   Plugins should check the boolean value pointed to, not the pointer itself.
    724     //   The value will be true when private mode is on.
    725     NPBool value = privateBrowsingEnabled;
    726     NPP_SetValue(NPNVprivateModeBool, &value);
    727 }
    728 
    729 bool NetscapePlugin::supportsSnapshotting() const
    730 {
    731 #if PLATFORM(MAC)
    732     return m_pluginModule && m_pluginModule->pluginQuirks().contains(PluginQuirks::SupportsSnapshotting);
    733 #endif
    734     return false;
    735 }
    736 
    737 PluginController* NetscapePlugin::controller()
    738 {
    739     return m_pluginController;
    740 }
    741 
    742 } // namespace WebKit
    743