src/3rdparty/webkit/WebCore/plugins/PluginView.cpp
changeset 30 5dc02b23752f
parent 3 41300fa6a67c
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
     1 /*
     1 /*
     2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
     2  * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
     3  * Copyright (C) 2008 Collabora Ltd. All rights reserved.
     3  * Copyright (C) 2008 Collabora Ltd. All rights reserved.
     4  *
     4  *
     5  * Redistribution and use in source and binary forms, with or without
     5  * Redistribution and use in source and binary forms, with or without
     6  * modification, are permitted provided that the following conditions
     6  * modification, are permitted provided that the following conditions
     7  * are met:
     7  * are met:
    25  */
    25  */
    26 
    26 
    27 #include "config.h"
    27 #include "config.h"
    28 #include "PluginView.h"
    28 #include "PluginView.h"
    29 
    29 
       
    30 #include "Bridge.h"
       
    31 #include "Chrome.h"
    30 #include "Document.h"
    32 #include "Document.h"
    31 #include "DocumentLoader.h"
    33 #include "DocumentLoader.h"
    32 #include "Element.h"
    34 #include "Element.h"
       
    35 #include "FocusController.h"
       
    36 #include "Frame.h"
    33 #include "FrameLoader.h"
    37 #include "FrameLoader.h"
       
    38 #include "FrameLoaderClient.h"
    34 #include "FrameTree.h"
    39 #include "FrameTree.h"
    35 #include "Frame.h"
       
    36 #include "FrameView.h"
    40 #include "FrameView.h"
    37 #include "GraphicsContext.h"
    41 #include "GraphicsContext.h"
    38 #include "Image.h"
       
    39 #include "HTMLNames.h"
    42 #include "HTMLNames.h"
    40 #include "HTMLPlugInElement.h"
    43 #include "HTMLPlugInElement.h"
       
    44 #include "Image.h"
       
    45 #include "JSDOMBinding.h"
    41 #include "JSDOMWindow.h"
    46 #include "JSDOMWindow.h"
    42 #include "KeyboardEvent.h"
    47 #include "KeyboardEvent.h"
    43 #include "MIMETypeRegistry.h"
    48 #include "MIMETypeRegistry.h"
    44 #include "MouseEvent.h"
    49 #include "MouseEvent.h"
    45 #include "NotImplemented.h"
    50 #include "NotImplemented.h"
    46 #include "Page.h"
    51 #include "Page.h"
    47 #include "FocusController.h"
       
    48 #include "PlatformMouseEvent.h"
    52 #include "PlatformMouseEvent.h"
    49 #if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
       
    50 #include "PluginMessageThrottlerWin.h"
       
    51 #endif
       
    52 #include "PluginPackage.h"
       
    53 #include "JSDOMBinding.h"
       
    54 #include "ScriptController.h"
       
    55 #include "ScriptValue.h"
       
    56 #include "SecurityOrigin.h"
       
    57 #include "PluginDatabase.h"
    53 #include "PluginDatabase.h"
    58 #include "PluginDebug.h"
    54 #include "PluginDebug.h"
    59 #include "PluginMainThreadScheduler.h"
    55 #include "PluginMainThreadScheduler.h"
    60 #include "PluginPackage.h"
    56 #include "PluginPackage.h"
    61 #include "RenderBox.h"
    57 #include "RenderBox.h"
    62 #include "RenderObject.h"
    58 #include "RenderObject.h"
       
    59 #include "ScriptController.h"
       
    60 #include "ScriptValue.h"
       
    61 #include "SecurityOrigin.h"
       
    62 #include "Settings.h"
    63 #include "c_instance.h"
    63 #include "c_instance.h"
    64 #include "npruntime_impl.h"
    64 #include "npruntime_impl.h"
    65 #include "runtime_root.h"
    65 #include "runtime_root.h"
    66 #include "Settings.h"
       
    67 #include "runtime.h"
       
    68 #include <runtime/JSLock.h>
    66 #include <runtime/JSLock.h>
    69 #include <runtime/JSValue.h>
    67 #include <runtime/JSValue.h>
    70 #include <wtf/ASCIICType.h>
    68 #include <wtf/ASCIICType.h>
       
    69 
       
    70 #if OS(WINDOWS) && ENABLE(NETSCAPE_PLUGIN_API)
       
    71 #include "PluginMessageThrottlerWin.h"
       
    72 #endif
    71 
    73 
    72 using JSC::ExecState;
    74 using JSC::ExecState;
    73 using JSC::JSLock;
    75 using JSC::JSLock;
    74 using JSC::JSObject;
    76 using JSC::JSObject;
    75 using JSC::JSValue;
    77 using JSC::JSValue;
    82 namespace WebCore {
    84 namespace WebCore {
    83 
    85 
    84 using namespace HTMLNames;
    86 using namespace HTMLNames;
    85 
    87 
    86 static int s_callingPlugin;
    88 static int s_callingPlugin;
       
    89 
       
    90 typedef HashMap<NPP, PluginView*> InstanceMap;
       
    91 
       
    92 static InstanceMap& instanceMap()
       
    93 {
       
    94     static InstanceMap& map = *new InstanceMap;
       
    95     return map;
       
    96 }
    87 
    97 
    88 static String scriptStringIfJavaScriptURL(const KURL& url)
    98 static String scriptStringIfJavaScriptURL(const KURL& url)
    89 {
    99 {
    90     if (!protocolIsJavaScript(url))
   100     if (!protocolIsJavaScript(url))
    91         return String();
   101         return String();
   122     if (rect != frameRect())
   132     if (rect != frameRect())
   123         Widget::setFrameRect(rect);
   133         Widget::setFrameRect(rect);
   124 
   134 
   125     updatePluginWidget();
   135     updatePluginWidget();
   126 
   136 
   127 #if PLATFORM(WIN_OS) || PLATFORM(SYMBIAN)
   137 #if OS(WINDOWS) || OS(SYMBIAN)
   128     // On Windows and Symbian, always call plugin to change geometry.
   138     // On Windows and Symbian, always call plugin to change geometry.
   129     setNPWindowRect(rect);
   139     setNPWindowRect(rect);
   130 #elif XP_UNIX
   140 #elif defined(XP_UNIX)
   131     // On Unix, multiple calls to setNPWindow() in windowed mode causes Flash to crash
   141     // On Unix, multiple calls to setNPWindow() in windowed mode causes Flash to crash
   132     if (m_mode == NP_FULL || !m_isWindowed)
   142     if (m_mode == NP_FULL || !m_isWindowed)
   133         setNPWindowRect(rect);
   143         setNPWindowRect(rect);
   134 #endif
   144 #endif
   135 }
   145 }
   141 
   151 
   142 void PluginView::handleEvent(Event* event)
   152 void PluginView::handleEvent(Event* event)
   143 {
   153 {
   144     if (!m_plugin || m_isWindowed)
   154     if (!m_plugin || m_isWindowed)
   145         return;
   155         return;
       
   156 
       
   157     // Protect the plug-in from deletion while dispatching the event.
       
   158     RefPtr<PluginView> protect(this);
   146 
   159 
   147     if (event->isMouseEvent())
   160     if (event->isMouseEvent())
   148         handleMouseEvent(static_cast<MouseEvent*>(event));
   161         handleMouseEvent(static_cast<MouseEvent*>(event));
   149     else if (event->isKeyboardEvent())
   162     else if (event->isKeyboardEvent())
   150         handleKeyboardEvent(static_cast<KeyboardEvent*>(event));
   163         handleKeyboardEvent(static_cast<KeyboardEvent*>(event));
   151 #if defined(Q_WS_X11) && ENABLE(NETSCAPE_PLUGIN_API)
   164 #if defined(XP_UNIX) && ENABLE(NETSCAPE_PLUGIN_API)
   152     else if (event->type() == eventNames().DOMFocusOutEvent)
   165     else if (event->type() == eventNames().DOMFocusOutEvent)
   153         handleFocusOutEvent();
   166         handleFocusOutEvent();
   154     else if (event->type() == eventNames().DOMFocusInEvent)
   167     else if (event->type() == eventNames().DOMFocusInEvent)
   155         handleFocusInEvent();
   168         handleFocusInEvent();
   156 #endif
   169 #endif
   187 bool PluginView::startOrAddToUnstartedList()
   200 bool PluginView::startOrAddToUnstartedList()
   188 {
   201 {
   189     if (!m_parentFrame->page())
   202     if (!m_parentFrame->page())
   190         return false;
   203         return false;
   191 
   204 
   192     if (!m_parentFrame->page()->canStartPlugins()) {
   205     // We only delay starting the plug-in if we're going to kick off the load
   193         m_parentFrame->page()->addUnstartedPlugin(this);
   206     // ourselves. Otherwise, the loader will try to deliver data before we've
       
   207     // started the plug-in.
       
   208     if (!m_loadManually && !m_parentFrame->page()->canStartMedia()) {
       
   209         m_parentFrame->page()->addMediaCanStartListener(this);
   194         m_isWaitingToStart = true;
   210         m_isWaitingToStart = true;
   195         return true;
   211         return true;
   196     }
   212     }
   197 
   213 
   198     return start();
   214     return start();
   248         parentFrame()->page()->didStartPlugin(this);
   264         parentFrame()->page()->didStartPlugin(this);
   249 
   265 
   250     return true;
   266     return true;
   251 }
   267 }
   252 
   268 
       
   269 void PluginView::mediaCanStart()
       
   270 {
       
   271     ASSERT(!m_isStarted);
       
   272     if (!start())
       
   273         parentFrame()->loader()->client()->dispatchDidFailToStartPlugin(this);
       
   274 }
       
   275 
   253 PluginView::~PluginView()
   276 PluginView::~PluginView()
   254 {
   277 {
   255     LOG(Plugins, "PluginView::~PluginView()");
   278     LOG(Plugins, "PluginView::~PluginView()");
       
   279 
       
   280     ASSERT(!m_lifeSupportTimer.isActive());
       
   281 
       
   282     instanceMap().remove(m_instance);
   256 
   283 
   257     removeFromUnstartedListIfNecessary();
   284     removeFromUnstartedListIfNecessary();
   258 
   285 
   259     stop();
   286     stop();
   260 
   287 
   277         return;
   304         return;
   278 
   305 
   279     if (!m_parentFrame->page())
   306     if (!m_parentFrame->page())
   280         return;
   307         return;
   281 
   308 
   282     m_parentFrame->page()->removeUnstartedPlugin(this);
   309     m_parentFrame->page()->removeMediaCanStartListener(this);
   283 }
   310 }
   284 
   311 
   285 void PluginView::stop()
   312 void PluginView::stop()
   286 {
   313 {
   287     if (!m_isStarted)
   314     if (!m_isStarted)
   304     m_isStarted = false;
   331     m_isStarted = false;
   305 
   332 
   306     JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
   333     JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
   307 
   334 
   308 #if ENABLE(NETSCAPE_PLUGIN_API)
   335 #if ENABLE(NETSCAPE_PLUGIN_API)
   309 #if !PLATFORM(WX) // FIXME: Revisit this when implementing plugins for wx
       
   310 #ifdef XP_WIN
   336 #ifdef XP_WIN
   311     // Unsubclass the window
   337     // Unsubclass the window
   312     if (m_isWindowed) {
   338     if (m_isWindowed) {
   313 #if PLATFORM(WINCE)
   339 #if OS(WINCE)
   314         WNDPROC currentWndProc = (WNDPROC)GetWindowLong(platformPluginWidget(), GWL_WNDPROC);
   340         WNDPROC currentWndProc = (WNDPROC)GetWindowLong(platformPluginWidget(), GWL_WNDPROC);
   315 
   341 
   316         if (currentWndProc == PluginViewWndProc)
   342         if (currentWndProc == PluginViewWndProc)
   317             SetWindowLong(platformPluginWidget(), GWL_WNDPROC, (LONG)m_pluginWndProc);
   343             SetWindowLong(platformPluginWidget(), GWL_WNDPROC, (LONG)m_pluginWndProc);
   318 #else
   344 #else
   319         WNDPROC currentWndProc = (WNDPROC)GetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC);
   345         WNDPROC currentWndProc = (WNDPROC)GetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC);
   320 
   346 
   321         if (currentWndProc == PluginViewWndProc)
   347         if (currentWndProc == PluginViewWndProc)
   322             SetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC, (LONG)m_pluginWndProc);
   348             SetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC, (LONG_PTR)m_pluginWndProc);
   323 #endif
   349 #endif
   324     }
   350     }
   325 #endif // XP_WIN
   351 #endif // XP_WIN
   326 #endif // !PLATFORM(WX)
       
   327 #endif // ENABLE(NETSCAPE_PLUGIN_API)
   352 #endif // ENABLE(NETSCAPE_PLUGIN_API)
   328 
   353 
   329 #if !defined(XP_MACOSX)
   354 #if !defined(XP_MACOSX)
   330     // Clear the window
   355     // Clear the window
   331     m_npWindow.window = 0;
   356     m_npWindow.window = 0;
   419 
   444 
   420     if (jsString.isNull()) {
   445     if (jsString.isNull()) {
   421         // if this is not a targeted request, create a stream for it. otherwise,
   446         // if this is not a targeted request, create a stream for it. otherwise,
   422         // just pass it off to the loader
   447         // just pass it off to the loader
   423         if (targetFrameName.isEmpty()) {
   448         if (targetFrameName.isEmpty()) {
   424             RefPtr<PluginStream> stream = PluginStream::create(this, m_parentFrame, request->frameLoadRequest().resourceRequest(), request->sendNotification(), request->notifyData(), plugin()->pluginFuncs(), instance(), m_plugin->quirks());
   449             RefPtr<PluginStream> stream = PluginStream::create(this, m_parentFrame.get(), request->frameLoadRequest().resourceRequest(), request->sendNotification(), request->notifyData(), plugin()->pluginFuncs(), instance(), m_plugin->quirks());
   425             m_streams.add(stream);
   450             m_streams.add(stream);
   426             stream->start();
   451             stream->start();
   427         } else {
   452         } else {
   428             // If the target frame is our frame, we could destroy the
   453             // If the target frame is our frame, we could destroy the
   429             // PluginView, so we protect it. <rdar://problem/6991251>
   454             // PluginView, so we protect it. <rdar://problem/6991251>
   457 
   482 
   458         CString cstr;
   483         CString cstr;
   459         if (getString(parentFrame->script(), result, resultString))
   484         if (getString(parentFrame->script(), result, resultString))
   460             cstr = resultString.utf8();
   485             cstr = resultString.utf8();
   461 
   486 
   462         RefPtr<PluginStream> stream = PluginStream::create(this, m_parentFrame, request->frameLoadRequest().resourceRequest(), request->sendNotification(), request->notifyData(), plugin()->pluginFuncs(), instance(), m_plugin->quirks());
   487         RefPtr<PluginStream> stream = PluginStream::create(this, m_parentFrame.get(), request->frameLoadRequest().resourceRequest(), request->sendNotification(), request->notifyData(), plugin()->pluginFuncs(), instance(), m_plugin->quirks());
   463         m_streams.add(stream);
   488         m_streams.add(stream);
   464         stream->sendJavaScriptStream(requestURL, cstr);
   489         stream->sendJavaScriptStream(requestURL, cstr);
   465     }
   490     }
   466 }
   491 }
   467 
   492 
   506 
   531 
   507     const String& targetFrameName = frameLoadRequest.frameName();
   532     const String& targetFrameName = frameLoadRequest.frameName();
   508     String jsString = scriptStringIfJavaScriptURL(url);
   533     String jsString = scriptStringIfJavaScriptURL(url);
   509 
   534 
   510     if (!jsString.isNull()) {
   535     if (!jsString.isNull()) {
   511         Settings* settings = m_parentFrame->settings();
       
   512 
       
   513         // Return NPERR_GENERIC_ERROR if JS is disabled. This is what Mozilla does.
   536         // Return NPERR_GENERIC_ERROR if JS is disabled. This is what Mozilla does.
   514         if (!settings || !settings->isJavaScriptEnabled())
   537         if (!m_parentFrame->script()->canExecuteScripts(NotAboutToExecuteScript))
   515             return NPERR_GENERIC_ERROR;
   538             return NPERR_GENERIC_ERROR;
   516         
   539 
   517         // For security reasons, only allow JS requests to be made on the frame that contains the plug-in.
   540         // For security reasons, only allow JS requests to be made on the frame that contains the plug-in.
   518         if (!targetFrameName.isNull() && m_parentFrame->tree()->find(targetFrameName) != m_parentFrame)
   541         if (!targetFrameName.isNull() && m_parentFrame->tree()->find(targetFrameName) != m_parentFrame)
   519             return NPERR_INVALID_PARAM;
   542             return NPERR_INVALID_PARAM;
   520     } else if (!SecurityOrigin::canLoad(url, String(), m_parentFrame->document()))
   543     } else if (!SecurityOrigin::canLoad(url, String(), m_parentFrame->document()))
   521             return NPERR_GENERIC_ERROR;
   544             return NPERR_GENERIC_ERROR;
   596 }
   619 }
   597 
   620 
   598 void PluginView::status(const char* message)
   621 void PluginView::status(const char* message)
   599 {
   622 {
   600     if (Page* page = m_parentFrame->page())
   623     if (Page* page = m_parentFrame->page())
   601         page->chrome()->setStatusbarText(m_parentFrame, String(message));
   624         page->chrome()->setStatusbarText(m_parentFrame.get(), String(message));
   602 }
   625 }
   603 
   626 
   604 NPError PluginView::setValue(NPPVariable variable, void* value)
   627 NPError PluginView::setValue(NPPVariable variable, void* value)
   605 {
   628 {
   606     LOG(Plugins, "PluginView::setValue(%s): ", prettyNameForNPPVariable(variable, value).data());
   629     LOG(Plugins, "PluginView::setValue(%s): ", prettyNameForNPPVariable(variable, value).data());
   788     , m_baseURL(m_parentFrame->loader()->completeURL(m_parentFrame->document()->baseURL().string()))
   811     , m_baseURL(m_parentFrame->loader()->completeURL(m_parentFrame->document()->baseURL().string()))
   789     , m_status(PluginStatusLoadedSuccessfully)
   812     , m_status(PluginStatusLoadedSuccessfully)
   790     , m_requestTimer(this, &PluginView::requestTimerFired)
   813     , m_requestTimer(this, &PluginView::requestTimerFired)
   791     , m_invalidateTimer(this, &PluginView::invalidateTimerFired)
   814     , m_invalidateTimer(this, &PluginView::invalidateTimerFired)
   792     , m_popPopupsStateTimer(this, &PluginView::popPopupsStateTimerFired)
   815     , m_popPopupsStateTimer(this, &PluginView::popPopupsStateTimerFired)
       
   816     , m_lifeSupportTimer(this, &PluginView::lifeSupportTimerFired)
       
   817     , m_mode(loadManually ? NP_FULL : NP_EMBED)
   793     , m_paramNames(0)
   818     , m_paramNames(0)
   794     , m_paramValues(0)
   819     , m_paramValues(0)
   795     , m_mimeType(mimeType)
   820     , m_mimeType(mimeType)
   796 #if defined(XP_MACOSX)
   821 #if defined(XP_MACOSX)
   797     , m_isWindowed(false)
   822     , m_isWindowed(false)
   799     , m_isWindowed(true)
   824     , m_isWindowed(true)
   800 #endif
   825 #endif
   801     , m_isTransparent(false)
   826     , m_isTransparent(false)
   802     , m_haveInitialized(false)
   827     , m_haveInitialized(false)
   803     , m_isWaitingToStart(false)
   828     , m_isWaitingToStart(false)
   804 #if defined(XP_UNIX) || defined(Q_WS_X11)
   829 #if defined(XP_UNIX)
   805     , m_needsXEmbed(false)
   830     , m_needsXEmbed(false)
   806 #endif
   831 #endif
   807 #if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
   832 #if OS(WINDOWS) && ENABLE(NETSCAPE_PLUGIN_API)
   808     , m_pluginWndProc(0)
   833     , m_pluginWndProc(0)
   809     , m_lastMessage(0)
   834     , m_lastMessage(0)
   810     , m_isCallingPluginWndProc(false)
   835     , m_isCallingPluginWndProc(false)
   811     , m_wmPrintHDC(0)
   836     , m_wmPrintHDC(0)
   812     , m_haveUpdatedPluginWidget(false)
   837     , m_haveUpdatedPluginWidget(false)
   813 #endif
   838 #endif
   814 #if (PLATFORM(QT) && PLATFORM(WIN_OS)) || defined(XP_MACOSX)
   839 #if (PLATFORM(QT) && OS(WINDOWS)) || defined(XP_MACOSX)
   815     , m_window(0)
   840     , m_window(0)
   816 #endif
   841 #endif
   817 #if defined(XP_MACOSX)
   842 #if defined(XP_MACOSX)
   818     , m_drawingModel(NPDrawingModel(-1))
   843     , m_drawingModel(NPDrawingModel(-1))
   819     , m_eventModel(NPEventModel(-1))
   844     , m_eventModel(NPEventModel(-1))
   820 #endif
   845     , m_contextRef(0)
   821 #if defined(Q_WS_X11) && ENABLE(NETSCAPE_PLUGIN_API)
   846     , m_fakeWindow(0)
   822     , m_hasPendingGeometryChange(false)
   847 #endif
       
   848 #if defined(XP_UNIX) && ENABLE(NETSCAPE_PLUGIN_API)
       
   849     , m_hasPendingGeometryChange(true)
   823     , m_drawable(0)
   850     , m_drawable(0)
   824     , m_visual(0)
   851     , m_visual(0)
   825     , m_colormap(0)
   852     , m_colormap(0)
   826     , m_pluginDisplay(0)
   853     , m_pluginDisplay(0)
   827 #endif
   854 #endif
   838 
   865 
   839     m_instance = &m_instanceStruct;
   866     m_instance = &m_instanceStruct;
   840     m_instance->ndata = this;
   867     m_instance->ndata = this;
   841     m_instance->pdata = 0;
   868     m_instance->pdata = 0;
   842 
   869 
       
   870     instanceMap().add(m_instance, this);
       
   871 
   843     setParameters(paramNames, paramValues);
   872     setParameters(paramNames, paramValues);
   844 
   873 
   845     memset(&m_npWindow, 0, sizeof(m_npWindow));
   874     memset(&m_npWindow, 0, sizeof(m_npWindow));
   846 #if defined(XP_MACOSX)
   875 #if defined(XP_MACOSX)
   847     memset(&m_npCgContext, 0, sizeof(m_npCgContext));
   876     memset(&m_npCgContext, 0, sizeof(m_npCgContext));
   848 #endif
   877 #endif
   849 
       
   850     m_mode = m_loadManually ? NP_FULL : NP_EMBED;
       
   851 
   878 
   852     resize(size);
   879     resize(size);
   853 }
   880 }
   854 
   881 
   855 void PluginView::focusPluginElement()
   882 void PluginView::focusPluginElement()
   866         return;
   893         return;
   867 
   894 
   868     ASSERT(m_loadManually);
   895     ASSERT(m_loadManually);
   869     ASSERT(!m_manualStream);
   896     ASSERT(!m_manualStream);
   870 
   897 
   871     m_manualStream = PluginStream::create(this, m_parentFrame, m_parentFrame->loader()->activeDocumentLoader()->request(), false, 0, plugin()->pluginFuncs(), instance(), m_plugin->quirks());
   898     m_manualStream = PluginStream::create(this, m_parentFrame.get(), m_parentFrame->loader()->activeDocumentLoader()->request(), false, 0, plugin()->pluginFuncs(), instance(), m_plugin->quirks());
   872     m_manualStream->setLoadManually(true);
   899     m_manualStream->setLoadManually(true);
   873 
   900 
   874     m_manualStream->didReceiveResponse(0, response);
   901     m_manualStream->didReceiveResponse(0, response);
   875 }
   902 }
   876 
   903 
  1196     if (!rect.intersects(imageRect))
  1223     if (!rect.intersects(imageRect))
  1197         return;
  1224         return;
  1198 
  1225 
  1199     context->save();
  1226     context->save();
  1200     context->clip(windowClipRect());
  1227     context->clip(windowClipRect());
  1201     context->drawImage(nullPluginImage.get(), imageRect.location());
  1228     context->drawImage(nullPluginImage.get(), DeviceColorSpace, imageRect.location());
  1202     context->restore();
  1229     context->restore();
  1203 }
  1230 }
  1204 
  1231 
  1205 static const char* MozillaUserAgent = "Mozilla/5.0 ("
  1232 static const char* MozillaUserAgent = "Mozilla/5.0 ("
  1206 #if defined(XP_MACOSX)
  1233 #if defined(XP_MACOSX)
  1207         "Macintosh; U; Intel Mac OS X;"
  1234         "Macintosh; U; Intel Mac OS X;"
  1208 #elif defined(XP_WIN)
  1235 #elif defined(XP_WIN)
  1209         "Windows; U; Windows NT 5.1;"
  1236         "Windows; U; Windows NT 5.1;"
  1210 #elif defined(XP_UNIX)
  1237 #elif defined(XP_UNIX)
  1211 // The Gtk port uses X11 plugins in Mac.
  1238 // The Gtk port uses X11 plugins in Mac.
  1212 #if PLATFORM(DARWIN) && PLATFORM(GTK)
  1239 #if OS(DARWIN) && PLATFORM(GTK)
  1213     "X11; U; Intel Mac OS X;"
  1240     "X11; U; Intel Mac OS X;"
  1214 #else
  1241 #else
  1215     "X11; U; Linux i686;"
  1242     "X11; U; Linux i686;"
  1216 #endif
  1243 #endif
  1217 #endif
  1244 #endif
  1239 Node* PluginView::node() const
  1266 Node* PluginView::node() const
  1240 {
  1267 {
  1241     return m_element;
  1268     return m_element;
  1242 }
  1269 }
  1243 
  1270 
       
  1271 String PluginView::pluginName() const
       
  1272 {
       
  1273     return m_plugin->name();
       
  1274 }
       
  1275 
       
  1276 void PluginView::lifeSupportTimerFired(Timer<PluginView>*)
       
  1277 {
       
  1278     deref();
       
  1279 }
       
  1280 
       
  1281 void PluginView::keepAlive()
       
  1282 {
       
  1283     if (m_lifeSupportTimer.isActive())
       
  1284         return;
       
  1285 
       
  1286     ref();
       
  1287     m_lifeSupportTimer.startOneShot(0);
       
  1288 }
       
  1289 
       
  1290 #if ENABLE(NETSCAPE_PLUGIN_API)
       
  1291 void PluginView::keepAlive(NPP instance)
       
  1292 {
       
  1293     PluginView* view = instanceMap().get(instance);
       
  1294     if (!view)
       
  1295         return;
       
  1296 
       
  1297     view->keepAlive();
       
  1298 }
       
  1299 
       
  1300 NPError PluginView::getValueStatic(NPNVariable variable, void* value)
       
  1301 {
       
  1302     LOG(Plugins, "PluginView::getValueStatic(%s)", prettyNameForNPNVariable(variable).data());
       
  1303 
       
  1304     NPError result;
       
  1305     if (platformGetValueStatic(variable, value, &result))
       
  1306         return result;
       
  1307 
       
  1308     return NPERR_GENERIC_ERROR;
       
  1309 }
       
  1310 
       
  1311 NPError PluginView::getValue(NPNVariable variable, void* value)
       
  1312 {
       
  1313     LOG(Plugins, "PluginView::getValue(%s)", prettyNameForNPNVariable(variable).data());
       
  1314 
       
  1315     NPError result;
       
  1316     if (platformGetValue(variable, value, &result))
       
  1317         return result;
       
  1318 
       
  1319     if (platformGetValueStatic(variable, value, &result))
       
  1320         return result;
       
  1321 
       
  1322     switch (variable) {
       
  1323     case NPNVWindowNPObject: {
       
  1324         if (m_isJavaScriptPaused)
       
  1325             return NPERR_GENERIC_ERROR;
       
  1326 
       
  1327         NPObject* windowScriptObject = m_parentFrame->script()->windowScriptNPObject();
       
  1328 
       
  1329         // Return value is expected to be retained, as described here: <http://www.mozilla.org/projects/plugin/npruntime.html>
       
  1330         if (windowScriptObject)
       
  1331             _NPN_RetainObject(windowScriptObject);
       
  1332 
       
  1333         void** v = (void**)value;
       
  1334         *v = windowScriptObject;
       
  1335 
       
  1336         return NPERR_NO_ERROR;
       
  1337     }
       
  1338 
       
  1339     case NPNVPluginElementNPObject: {
       
  1340         if (m_isJavaScriptPaused)
       
  1341             return NPERR_GENERIC_ERROR;
       
  1342 
       
  1343         NPObject* pluginScriptObject = 0;
       
  1344 
       
  1345         if (m_element->hasTagName(appletTag) || m_element->hasTagName(embedTag) || m_element->hasTagName(objectTag))
       
  1346             pluginScriptObject = static_cast<HTMLPlugInElement*>(m_element)->getNPObject();
       
  1347 
       
  1348         // Return value is expected to be retained, as described here: <http://www.mozilla.org/projects/plugin/npruntime.html>
       
  1349         if (pluginScriptObject)
       
  1350             _NPN_RetainObject(pluginScriptObject);
       
  1351 
       
  1352         void** v = (void**)value;
       
  1353         *v = pluginScriptObject;
       
  1354 
       
  1355         return NPERR_NO_ERROR;
       
  1356     }
       
  1357 
       
  1358     case NPNVprivateModeBool: {
       
  1359         Page* page = m_parentFrame->page();
       
  1360         if (!page)
       
  1361             return NPERR_GENERIC_ERROR;
       
  1362         *((NPBool*)value) = !page->settings() || page->settings()->privateBrowsingEnabled();
       
  1363         return NPERR_NO_ERROR;
       
  1364     }
       
  1365 
       
  1366     default:
       
  1367         return NPERR_GENERIC_ERROR;
       
  1368     }
       
  1369 }
       
  1370 #endif
       
  1371 
       
  1372 void PluginView::privateBrowsingStateChanged(bool privateBrowsingEnabled)
       
  1373 {
       
  1374     NPP_SetValueProcPtr setValue = m_plugin->pluginFuncs()->setvalue;
       
  1375     if (!setValue)
       
  1376         return;
       
  1377 
       
  1378     PluginView::setCurrentPluginView(this);
       
  1379     JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
       
  1380     setCallingPlugin(true);
       
  1381     NPBool value = privateBrowsingEnabled;
       
  1382     setValue(m_instance, NPNVprivateModeBool, &value);
       
  1383     setCallingPlugin(false);
       
  1384     PluginView::setCurrentPluginView(0);
       
  1385 }
       
  1386 
  1244 } // namespace WebCore
  1387 } // namespace WebCore