2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Collabora Ltd. All rights reserved.
4 * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "PluginView.h"
33 #include "DocumentLoader.h"
35 #include "FloatPoint.h"
36 #include "FocusController.h"
38 #include "FrameLoadRequest.h"
39 #include "FrameLoader.h"
40 #include "FrameTree.h"
41 #include "FrameView.h"
42 #include "GraphicsContext.h"
43 #include "HTMLNames.h"
44 #include "HTMLPlugInElement.h"
45 #include "HostWindow.h"
47 #include "JSDOMBinding.h"
48 #include "KeyboardEvent.h"
49 #include "MouseEvent.h"
50 #include "NotImplemented.h"
52 #include "PlatformMouseEvent.h"
53 #include "PlatformKeyboardEvent.h"
54 #include "PluginContainerQt.h"
55 #include "PluginDebug.h"
56 #include "PluginPackage.h"
57 #include "PluginMainThreadScheduler.h"
58 #include "QWebPageClient.h"
59 #include "RenderLayer.h"
60 #include "ScriptController.h"
62 #include "npruntime_impl.h"
63 #include "qwebpage_p.h"
64 #include "runtime_root.h"
66 #include <QApplication>
67 #include <QDesktopWidget>
76 #include <X11/extensions/Xrender.h>
78 #include <runtime/JSLock.h>
79 #include <runtime/JSValue.h>
82 using JSC::Interpreter;
93 using namespace HTMLNames;
95 void PluginView::updatePluginWidget()
100 ASSERT(parent()->isFrameView());
101 FrameView* frameView = static_cast<FrameView*>(parent());
103 IntRect oldWindowRect = m_windowRect;
104 IntRect oldClipRect = m_clipRect;
106 m_windowRect = IntRect(frameView->contentsToWindow(frameRect().location()), frameRect().size());
107 m_clipRect = windowClipRect();
108 m_clipRect.move(-m_windowRect.x(), -m_windowRect.y());
110 if (m_windowRect == oldWindowRect && m_clipRect == oldClipRect)
113 if (!m_isWindowed && m_windowRect.size() != oldWindowRect.size()) {
114 #if defined(MOZ_PLATFORM_MAEMO) && (MOZ_PLATFORM_MAEMO == 5)
115 // On Maemo5, Flash always renders to 16-bit buffer
117 m_image = QImage(m_windowRect.width(), m_windowRect.height(), QImage::Format_RGB16);
122 XFreePixmap(QX11Info::display(), m_drawable);
124 m_drawable = XCreatePixmap(QX11Info::display(), QX11Info::appRootWindow(), m_windowRect.width(), m_windowRect.height(),
125 ((NPSetWindowCallbackStruct*)m_npWindow.ws_info)->depth);
126 QApplication::syncX(); // make sure that the server knows about the Drawable
130 // do not call setNPWindowIfNeeded immediately, will be called on paint()
131 m_hasPendingGeometryChange = true;
133 // (i) in order to move/resize the plugin window at the same time as the
134 // rest of frame during e.g. scrolling, we set the window geometry
135 // in the paint() function, but as paint() isn't called when the
136 // plugin window is outside the frame which can be caused by a
137 // scroll, we need to move/resize immediately.
138 // (ii) if we are running layout tests from DRT, paint() won't ever get called
139 // so we need to call setNPWindowIfNeeded() if window geometry has changed
140 if (!m_windowRect.intersects(frameView->frameRect())
141 || (QWebPagePrivate::drtRun && platformPluginWidget() && (m_windowRect != oldWindowRect || m_clipRect != oldClipRect)))
142 setNPWindowIfNeeded();
144 // Make sure we get repainted afterwards. This is necessary for downward
145 // scrolling to move the plugin widget properly.
149 void PluginView::setFocus(bool focused)
151 if (platformPluginWidget()) {
153 platformPluginWidget()->setFocus(Qt::OtherFocusReason);
155 Widget::setFocus(focused);
159 void PluginView::show()
161 Q_ASSERT(platformPluginWidget() == platformWidget());
165 void PluginView::hide()
167 Q_ASSERT(platformPluginWidget() == platformWidget());
171 #if defined(MOZ_PLATFORM_MAEMO) && (MOZ_PLATFORM_MAEMO == 5)
172 void PluginView::paintUsingImageSurfaceExtension(QPainter* painter, const IntRect& exposedRect)
174 NPImageExpose imageExpose;
176 QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient();
177 const bool surfaceHasUntransformedContents = client && qobject_cast<QWidget*>(client->pluginParent());
179 QPaintDevice* surface = QPainter::redirected(painter->device(), &offset);
181 // If the surface is a QImage, we can render directly into it
182 if (surfaceHasUntransformedContents && surface && surface->devType() == QInternal::Image) {
183 QImage* image = static_cast<QImage*>(surface);
184 offset = -offset; // negating the offset gives us the offset of the view within the surface
185 imageExpose.data = reinterpret_cast<char*>(image->bits());
186 imageExpose.dataSize.width = image->width();
187 imageExpose.dataSize.height = image->height();
188 imageExpose.stride = image->bytesPerLine();
189 imageExpose.depth = image->depth(); // this is guaranteed to be 16 on Maemo5
190 imageExpose.translateX = offset.x() + m_windowRect.x();
191 imageExpose.translateY = offset.y() + m_windowRect.y();
192 imageExpose.scaleX = 1;
193 imageExpose.scaleY = 1;
195 if (m_isTransparent) {
196 // On Maemo5, Flash expects the buffer to contain the contents that are below it.
197 // We don't support transparency for non-raster graphicssystem, so clean the image
198 // before giving to Flash.
199 QPainter imagePainter(&m_image);
200 imagePainter.fillRect(exposedRect, Qt::white);
203 imageExpose.data = reinterpret_cast<char*>(m_image.bits());
204 imageExpose.dataSize.width = m_image.width();
205 imageExpose.dataSize.height = m_image.height();
206 imageExpose.stride = m_image.bytesPerLine();
207 imageExpose.depth = m_image.depth();
208 imageExpose.translateX = 0;
209 imageExpose.translateY = 0;
210 imageExpose.scaleX = 1;
211 imageExpose.scaleY = 1;
213 imageExpose.x = exposedRect.x();
214 imageExpose.y = exposedRect.y();
215 imageExpose.width = exposedRect.width();
216 imageExpose.height = exposedRect.height();
219 memset(&xevent, 0, sizeof(XEvent));
220 XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose;
221 exposeEvent.type = GraphicsExpose;
222 exposeEvent.display = 0;
223 exposeEvent.drawable = reinterpret_cast<XID>(&imageExpose);
224 exposeEvent.x = exposedRect.x();
225 exposeEvent.y = exposedRect.y();
226 exposeEvent.width = exposedRect.width();
227 exposeEvent.height = exposedRect.height();
229 dispatchNPEvent(xevent);
231 if (!surfaceHasUntransformedContents || !surface || surface->devType() != QInternal::Image)
232 painter->drawImage(QPoint(frameRect().x() + exposedRect.x(), frameRect().y() + exposedRect.y()), m_image, exposedRect);
236 void PluginView::paint(GraphicsContext* context, const IntRect& rect)
239 paintMissingPluginIcon(context, rect);
243 if (context->paintingDisabled())
246 setNPWindowIfNeeded();
252 #if defined(MOZ_PLATFORM_MAEMO) && (MOZ_PLATFORM_MAEMO == 5)
258 QPainter* painter = context->platformContext();
259 IntRect exposedRect(rect);
260 exposedRect.intersect(frameRect());
261 exposedRect.move(-frameRect().x(), -frameRect().y());
263 #if defined(MOZ_PLATFORM_MAEMO) && (MOZ_PLATFORM_MAEMO == 5)
264 if (!m_image.isNull()) {
265 paintUsingImageSurfaceExtension(painter, exposedRect);
270 QPixmap qtDrawable = QPixmap::fromX11Pixmap(m_drawable, QPixmap::ExplicitlyShared);
271 const int drawableDepth = ((NPSetWindowCallbackStruct*)m_npWindow.ws_info)->depth;
272 ASSERT(drawableDepth == qtDrawable.depth());
273 const bool syncX = m_pluginDisplay && m_pluginDisplay != QX11Info::display();
275 // When printing, Qt uses a QPicture to capture the output in preview mode. The
276 // QPicture holds a reference to the X Pixmap. As a result, the print preview would
277 // update itself when the X Pixmap changes. To prevent this, we create a copy.
278 if (m_element->document()->printing())
279 qtDrawable = qtDrawable.copy();
281 if (m_isTransparent && drawableDepth != 32) {
282 // Attempt content propagation for drawable with no alpha by copying over from the backing store
284 QPaintDevice* backingStoreDevice = QPainter::redirected(painter->device(), &offset);
285 offset = -offset; // negating the offset gives us the offset of the view within the backing store pixmap
287 const bool hasValidBackingStore = backingStoreDevice && backingStoreDevice->devType() == QInternal::Pixmap;
288 QPixmap* backingStorePixmap = static_cast<QPixmap*>(backingStoreDevice);
290 // We cannot grab contents from the backing store when painting on QGraphicsView items
291 // (because backing store contents are already transformed). What we really mean to do
292 // here is to check if we are painting on QWebView, but let's be a little permissive :)
293 QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient();
294 const bool backingStoreHasUntransformedContents = client && qobject_cast<QWidget*>(client->pluginParent());
296 if (hasValidBackingStore && backingStorePixmap->depth() == drawableDepth
297 && backingStoreHasUntransformedContents) {
298 GC gc = XDefaultGC(QX11Info::display(), QX11Info::appScreen());
299 XCopyArea(QX11Info::display(), backingStorePixmap->handle(), m_drawable, gc,
300 offset.x() + m_windowRect.x() + exposedRect.x(), offset.y() + m_windowRect.y() + exposedRect.y(),
301 exposedRect.width(), exposedRect.height(), exposedRect.x(), exposedRect.y());
302 } else { // no backing store, clean the pixmap because the plugin thinks its transparent
303 QPainter painter(&qtDrawable);
304 painter.fillRect(exposedRect, Qt::white);
308 QApplication::syncX();
312 memset(&xevent, 0, sizeof(XEvent));
313 XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose;
314 exposeEvent.type = GraphicsExpose;
315 exposeEvent.display = QX11Info::display();
316 exposeEvent.drawable = qtDrawable.handle();
317 exposeEvent.x = exposedRect.x();
318 exposeEvent.y = exposedRect.y();
319 exposeEvent.width = exposedRect.x() + exposedRect.width(); // flash bug? it thinks width is the right in transparent mode
320 exposeEvent.height = exposedRect.y() + exposedRect.height(); // flash bug? it thinks height is the bottom in transparent mode
322 dispatchNPEvent(xevent);
325 XSync(m_pluginDisplay, False); // sync changes by plugin
327 painter->drawPixmap(QPoint(frameRect().x() + exposedRect.x(), frameRect().y() + exposedRect.y()), qtDrawable,
331 // TODO: Unify across ports.
332 bool PluginView::dispatchNPEvent(NPEvent& event)
334 if (!m_plugin->pluginFuncs()->event)
337 PluginView::setCurrentPluginView(this);
338 JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
339 setCallingPlugin(true);
340 bool accepted = m_plugin->pluginFuncs()->event(m_instance, &event);
341 setCallingPlugin(false);
342 PluginView::setCurrentPluginView(0);
347 void setSharedXEventFields(XEvent* xEvent, QWidget* ownerWidget)
349 xEvent->xany.serial = 0; // we are unaware of the last request processed by X Server
350 xEvent->xany.send_event = false;
351 xEvent->xany.display = QX11Info::display();
352 // NOTE: event->xany.window doesn't always respond to the .window property of other XEvent's
353 // but does in the case of KeyPress, KeyRelease, ButtonPress, ButtonRelease, and MotionNotify
354 // events; thus, this is right:
355 xEvent->xany.window = ownerWidget ? ownerWidget->window()->handle() : 0;
358 void PluginView::initXEvent(XEvent* xEvent)
360 memset(xEvent, 0, sizeof(XEvent));
362 QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient();
363 QWidget* ownerWidget = client ? client->ownerWidget() : 0;
364 setSharedXEventFields(xEvent, ownerWidget);
367 void setXKeyEventSpecificFields(XEvent* xEvent, KeyboardEvent* event)
369 QKeyEvent* qKeyEvent = event->keyEvent()->qtEvent();
371 xEvent->type = (event->type() == eventNames().keydownEvent) ? 2 : 3; // ints as Qt unsets KeyPress and KeyRelease
372 xEvent->xkey.root = QX11Info::appRootWindow();
373 xEvent->xkey.subwindow = 0; // we have no child window
374 xEvent->xkey.time = event->timeStamp();
375 xEvent->xkey.state = qKeyEvent->nativeModifiers();
376 xEvent->xkey.keycode = qKeyEvent->nativeScanCode();
377 xEvent->xkey.same_screen = true;
379 // NOTE: As the XEvents sent to the plug-in are synthesized and there is not a native window
380 // corresponding to the plug-in rectangle, some of the members of the XEvent structures are not
381 // set to their normal Xserver values. e.g. Key events don't have a position.
382 // source: https://developer.mozilla.org/en/NPEvent
385 xEvent->xkey.x_root = 0;
386 xEvent->xkey.y_root = 0;
389 void PluginView::handleKeyboardEvent(KeyboardEvent* event)
394 if (event->type() != eventNames().keydownEvent && event->type() != eventNames().keyupEvent)
398 initXEvent(&npEvent);
399 setXKeyEventSpecificFields(&npEvent, event);
401 if (!dispatchNPEvent(npEvent))
402 event->setDefaultHandled();
405 static unsigned int inputEventState(MouseEvent* event)
407 unsigned int state = 0;
408 if (event->ctrlKey())
409 state |= ControlMask;
410 if (event->shiftKey())
414 if (event->metaKey())
419 static void setXButtonEventSpecificFields(XEvent* xEvent, MouseEvent* event, const IntPoint& postZoomPos)
421 XButtonEvent& xbutton = xEvent->xbutton;
422 xbutton.type = event->type() == eventNames().mousedownEvent ? ButtonPress : ButtonRelease;
423 xbutton.root = QX11Info::appRootWindow();
424 xbutton.subwindow = 0;
425 xbutton.time = event->timeStamp();
426 xbutton.x = postZoomPos.x();
427 xbutton.y = postZoomPos.y();
428 xbutton.x_root = event->screenX();
429 xbutton.y_root = event->screenY();
430 xbutton.state = inputEventState(event);
431 switch (event->button()) {
433 xbutton.button = Button2;
436 xbutton.button = Button3;
440 xbutton.button = Button1;
443 xbutton.same_screen = true;
446 static void setXMotionEventSpecificFields(XEvent* xEvent, MouseEvent* event, const IntPoint& postZoomPos)
448 XMotionEvent& xmotion = xEvent->xmotion;
449 xmotion.type = MotionNotify;
450 xmotion.root = QX11Info::appRootWindow();
451 xmotion.subwindow = 0;
452 xmotion.time = event->timeStamp();
453 xmotion.x = postZoomPos.x();
454 xmotion.y = postZoomPos.y();
455 xmotion.x_root = event->screenX();
456 xmotion.y_root = event->screenY();
457 xmotion.state = inputEventState(event);
458 xmotion.is_hint = NotifyNormal;
459 xmotion.same_screen = true;
462 static void setXCrossingEventSpecificFields(XEvent* xEvent, MouseEvent* event, const IntPoint& postZoomPos)
464 XCrossingEvent& xcrossing = xEvent->xcrossing;
465 xcrossing.type = event->type() == eventNames().mouseoverEvent ? EnterNotify : LeaveNotify;
466 xcrossing.root = QX11Info::appRootWindow();
467 xcrossing.subwindow = 0;
468 xcrossing.time = event->timeStamp();
469 xcrossing.x = postZoomPos.y();
470 xcrossing.y = postZoomPos.x();
471 xcrossing.x_root = event->screenX();
472 xcrossing.y_root = event->screenY();
473 xcrossing.state = inputEventState(event);
474 xcrossing.mode = NotifyNormal;
475 xcrossing.detail = NotifyDetailNone;
476 xcrossing.same_screen = true;
477 xcrossing.focus = false;
480 void PluginView::handleMouseEvent(MouseEvent* event)
485 if (event->type() == eventNames().mousedownEvent) {
486 // Give focus to the plugin on click
487 if (Page* page = m_parentFrame->page())
488 page->focusController()->setActive(true);
490 focusPluginElement();
494 initXEvent(&npEvent);
496 IntPoint postZoomPos = roundedIntPoint(m_element->renderer()->absoluteToLocal(event->absoluteLocation()));
498 if (event->type() == eventNames().mousedownEvent || event->type() == eventNames().mouseupEvent)
499 setXButtonEventSpecificFields(&npEvent, event, postZoomPos);
500 else if (event->type() == eventNames().mousemoveEvent)
501 setXMotionEventSpecificFields(&npEvent, event, postZoomPos);
502 else if (event->type() == eventNames().mouseoutEvent || event->type() == eventNames().mouseoverEvent)
503 setXCrossingEventSpecificFields(&npEvent, event, postZoomPos);
507 if (!dispatchNPEvent(npEvent))
508 event->setDefaultHandled();
511 void PluginView::handleFocusInEvent()
514 initXEvent(&npEvent);
516 XFocusChangeEvent& event = npEvent.xfocus;
517 event.type = 9; /* int as Qt unsets FocusIn */
518 event.mode = NotifyNormal;
519 event.detail = NotifyDetailNone;
521 dispatchNPEvent(npEvent);
524 void PluginView::handleFocusOutEvent()
527 initXEvent(&npEvent);
529 XFocusChangeEvent& event = npEvent.xfocus;
530 event.type = 10; /* int as Qt unsets FocusOut */
531 event.mode = NotifyNormal;
532 event.detail = NotifyDetailNone;
534 dispatchNPEvent(npEvent);
537 void PluginView::setParent(ScrollView* parent)
539 Widget::setParent(parent);
545 void PluginView::setNPWindowRect(const IntRect&)
548 setNPWindowIfNeeded();
551 void PluginView::setNPWindowIfNeeded()
553 if (!m_isStarted || !parent() || !m_plugin->pluginFuncs()->setwindow)
556 // If the plugin didn't load sucessfully, no point in calling setwindow
557 if (m_status != PluginStatusLoadedSuccessfully)
560 // On Unix, only call plugin if it's full-page or windowed
561 if (m_mode != NP_FULL && m_mode != NP_EMBED)
564 // Check if the platformPluginWidget still exists
565 if (m_isWindowed && !platformPluginWidget())
568 if (!m_hasPendingGeometryChange)
570 m_hasPendingGeometryChange = false;
573 platformPluginWidget()->setGeometry(m_windowRect);
574 // if setMask is set with an empty QRegion, no clipping will
575 // be performed, so in that case we hide the plugin view
576 platformPluginWidget()->setVisible(!m_clipRect.isEmpty());
577 platformPluginWidget()->setMask(QRegion(m_clipRect));
579 m_npWindow.x = m_windowRect.x();
580 m_npWindow.y = m_windowRect.y();
582 m_npWindow.clipRect.left = max(0, m_clipRect.x());
583 m_npWindow.clipRect.top = max(0, m_clipRect.y());
584 m_npWindow.clipRect.right = m_clipRect.x() + m_clipRect.width();
585 m_npWindow.clipRect.bottom = m_clipRect.y() + m_clipRect.height();
590 m_npWindow.clipRect.left = 0;
591 m_npWindow.clipRect.top = 0;
592 m_npWindow.clipRect.right = 0;
593 m_npWindow.clipRect.bottom = 0;
596 if (m_plugin->quirks().contains(PluginQuirkDontCallSetWindowMoreThanOnce)) {
597 // FLASH WORKAROUND: Only set initially. Multiple calls to
598 // setNPWindow() cause the plugin to crash in windowed mode.
599 if (!m_isWindowed || m_npWindow.width == -1 || m_npWindow.height == -1) {
600 m_npWindow.width = m_windowRect.width();
601 m_npWindow.height = m_windowRect.height();
604 m_npWindow.width = m_windowRect.width();
605 m_npWindow.height = m_windowRect.height();
608 PluginView::setCurrentPluginView(this);
609 JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
610 setCallingPlugin(true);
611 m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow);
612 setCallingPlugin(false);
613 PluginView::setCurrentPluginView(0);
616 void PluginView::setParentVisible(bool visible)
618 if (isParentVisible() == visible)
621 Widget::setParentVisible(visible);
623 if (isSelfVisible() && platformPluginWidget())
624 platformPluginWidget()->setVisible(visible);
627 NPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32_t len, const char* buf)
629 String filename(buf, len);
631 if (filename.startsWith("file:///"))
632 filename = filename.substring(8);
635 if (!getFileSize(filename, size))
636 return NPERR_FILE_NOT_FOUND;
638 FILE* fileHandle = fopen((filename.utf8()).data(), "r");
640 return NPERR_FILE_NOT_FOUND;
643 int bytesRead = fread(buffer.data(), 1, size, fileHandle);
648 return NPERR_FILE_NOT_FOUND;
650 return NPERR_NO_ERROR;
653 bool PluginView::platformGetValueStatic(NPNVariable variable, void* value, NPError* result)
657 *static_cast<uint32_t*>(value) = 0;
658 *result = NPERR_NO_ERROR;
661 case NPNVSupportsXEmbedBool:
662 *static_cast<NPBool*>(value) = true;
663 *result = NPERR_NO_ERROR;
666 case NPNVjavascriptEnabledBool:
667 *static_cast<NPBool*>(value) = true;
668 *result = NPERR_NO_ERROR;
671 case NPNVSupportsWindowless:
672 *static_cast<NPBool*>(value) = true;
673 *result = NPERR_NO_ERROR;
676 #if defined(MOZ_PLATFORM_MAEMO) && (MOZ_PLATFORM_MAEMO == 5)
677 case NPNVSupportsWindowlessLocal:
678 *static_cast<NPBool*>(value) = true;
679 *result = NPERR_NO_ERROR;
688 bool PluginView::platformGetValue(NPNVariable variable, void* value, NPError* result)
692 *(void **)value = QX11Info::display();
693 *result = NPERR_NO_ERROR;
696 case NPNVxtAppContext:
697 *result = NPERR_GENERIC_ERROR;
700 case NPNVnetscapeWindow: {
701 void* w = reinterpret_cast<void*>(value);
702 QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient();
703 *((XID *)w) = client ? client->ownerWidget()->window()->winId() : 0;
704 *result = NPERR_NO_ERROR;
709 if (m_plugin->quirks().contains(PluginQuirkRequiresGtkToolKit)) {
710 *((uint32_t *)value) = 2;
711 *result = NPERR_NO_ERROR;
721 void PluginView::invalidateRect(const IntRect& rect)
724 if (platformWidget())
725 platformWidget()->update(rect);
729 invalidateWindowlessPluginRect(rect);
732 void PluginView::invalidateRect(NPRect* rect)
738 IntRect r(rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top);
739 invalidateWindowlessPluginRect(r);
742 void PluginView::invalidateRegion(NPRegion region)
747 void PluginView::forceRedraw()
752 static Display *getPluginDisplay()
754 // The plugin toolkit might run using a different X connection. At the moment, we only
755 // support gdk based plugins (like flash) that use a different X connection.
756 // The code below has the same effect as this one:
757 // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default());
758 QLibrary library("libgdk-x11-2.0.so.0");
762 typedef void *(*gdk_display_get_default_ptr)();
763 gdk_display_get_default_ptr gdk_display_get_default = (gdk_display_get_default_ptr)library.resolve("gdk_display_get_default");
764 if (!gdk_display_get_default)
767 typedef void *(*gdk_x11_display_get_xdisplay_ptr)(void *);
768 gdk_x11_display_get_xdisplay_ptr gdk_x11_display_get_xdisplay = (gdk_x11_display_get_xdisplay_ptr)library.resolve("gdk_x11_display_get_xdisplay");
769 if (!gdk_x11_display_get_xdisplay)
772 return (Display*)gdk_x11_display_get_xdisplay(gdk_display_get_default());
775 static void getVisualAndColormap(int depth, Visual **visual, Colormap *colormap)
780 #ifndef QT_NO_XRENDER
781 static const bool useXRender = qgetenv("QT_X11_NO_XRENDER").isNull(); // Should also check for XRender >= 0.5
783 static const bool useXRender = false;
786 if (!useXRender && depth == 32)
791 templ.screen = QX11Info::appScreen();
793 templ.c_class = TrueColor;
794 XVisualInfo* xvi = XGetVisualInfo(QX11Info::display(), VisualScreenMask | VisualDepthMask | VisualClassMask, &templ, &nvi);
799 #ifndef QT_NO_XRENDER
801 for (int idx = 0; idx < nvi; ++idx) {
802 XRenderPictFormat* format = XRenderFindVisualFormat(QX11Info::display(), xvi[idx].visual);
803 if (format->type == PictTypeDirect && format->direct.alphaMask) {
804 *visual = xvi[idx].visual;
809 #endif // QT_NO_XRENDER
810 *visual = xvi[0].visual;
815 *colormap = XCreateColormap(QX11Info::display(), QX11Info::appRootWindow(), *visual, AllocNone);
818 bool PluginView::platformStart()
821 ASSERT(m_status == PluginStatusLoadedSuccessfully);
823 if (m_plugin->pluginFuncs()->getvalue) {
824 PluginView::setCurrentPluginView(this);
825 JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
826 setCallingPlugin(true);
827 m_plugin->pluginFuncs()->getvalue(m_instance, NPPVpluginNeedsXEmbed, &m_needsXEmbed);
828 setCallingPlugin(false);
829 PluginView::setCurrentPluginView(0);
833 QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient();
834 if (m_needsXEmbed && client) {
835 setPlatformWidget(new PluginContainerQt(this, client->ownerWidget()));
836 // sync our XEmbed container window creation before sending the xid to plugins.
837 QApplication::syncX();
840 m_status = PluginStatusCanNotLoadPlugin;
844 setPlatformWidget(0);
845 m_pluginDisplay = getPluginDisplay();
850 NPSetWindowCallbackStruct* wsi = new NPSetWindowCallbackStruct();
854 const QX11Info* x11Info = &platformPluginWidget()->x11Info();
856 wsi->display = x11Info->display();
857 wsi->visual = (Visual*)x11Info->visual();
858 wsi->depth = x11Info->depth();
859 wsi->colormap = x11Info->colormap();
861 m_npWindow.type = NPWindowTypeWindow;
862 m_npWindow.window = (void*)platformPluginWidget()->winId();
863 m_npWindow.width = -1;
864 m_npWindow.height = -1;
866 const QX11Info* x11Info = &QApplication::desktop()->x11Info();
868 if (x11Info->depth() == 32 || !m_plugin->quirks().contains(PluginQuirkRequiresDefaultScreenDepth)) {
869 getVisualAndColormap(32, &m_visual, &m_colormap);
874 getVisualAndColormap(x11Info->depth(), &m_visual, &m_colormap);
875 wsi->depth = x11Info->depth();
878 wsi->display = x11Info->display();
879 wsi->visual = m_visual;
880 wsi->colormap = m_colormap;
882 m_npWindow.type = NPWindowTypeDrawable;
883 m_npWindow.window = 0; // Not used?
886 m_npWindow.width = -1;
887 m_npWindow.height = -1;
890 m_npWindow.ws_info = wsi;
892 if (!(m_plugin->quirks().contains(PluginQuirkDeferFirstSetWindowCall))) {
893 updatePluginWidget();
894 setNPWindowIfNeeded();
900 void PluginView::platformDestroy()
902 if (platformPluginWidget())
903 delete platformPluginWidget();
906 XFreePixmap(QX11Info::display(), m_drawable);
909 XFreeColormap(QX11Info::display(), m_colormap);
912 void PluginView::halt()
916 void PluginView::restart()
920 } // namespace WebCore