diff options
Diffstat (limited to 'src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp')
-rw-r--r-- | src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp | 316 |
1 files changed, 146 insertions, 170 deletions
diff --git a/src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp b/src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp index 268718643..b313afbc0 100644 --- a/src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp +++ b/src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp @@ -29,6 +29,8 @@ #include "PluginView.h" +#include "BitmapImage.h" +#include "BitmapInfo.h" #include "Document.h" #include "DocumentLoader.h" #include "Element.h" @@ -52,6 +54,7 @@ #include "PluginMessageThrottlerWin.h" #include "PluginPackage.h" #include "PluginMainThreadScheduler.h" +#include "RenderWidget.h" #include "JSDOMBinding.h" #include "ScriptController.h" #include "PluginDatabase.h" @@ -74,17 +77,18 @@ #endif #if PLATFORM(QT) -#include <QWidget.h> +#include "QWebPageClient.h" +#include <QWidget> #endif -static inline HWND windowHandleForPlatformWidget(PlatformWidget widget) +static inline HWND windowHandleForPageClient(PlatformPageClient client) { #if PLATFORM(QT) - if (!widget) + if (!client) return 0; - return widget->winId(); + return client->ownerWidget()->winId(); #else - return widget; + return client; #endif } @@ -104,8 +108,6 @@ using namespace HTMLNames; const LPCWSTR kWebPluginViewdowClassName = L"WebPluginView"; const LPCWSTR kWebPluginViewProperty = L"WebPluginViewProperty"; -static const char* MozillaUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"; - #if !PLATFORM(WINCE) // The code used to hook BeginPaint/EndPaint originally came from // <http://www.fengyuan.com/article/wmprint.html>. @@ -143,7 +145,7 @@ HDC WINAPI PluginView::hookedBeginPaint(HWND hWnd, PAINTSTRUCT* lpPaint) "push %3\n" "call *%4\n" : "=a" (result) - : "a" (beginPaintSysCall), "g" (lpPaint), "g" (hWnd), "m" (*beginPaint) + : "a" (beginPaintSysCall), "g" (lpPaint), "g" (hWnd), "m" (beginPaint) : "memory" ); return result; @@ -173,7 +175,7 @@ BOOL WINAPI PluginView::hookedEndPaint(HWND hWnd, const PAINTSTRUCT* lpPaint) "push %3\n" "call *%4\n" : "=a" (result) - : "a" (endPaintSysCall), "g" (lpPaint), "g" (hWnd), "m" (*endPaint) + : "a" (endPaintSysCall), "g" (lpPaint), "g" (hWnd), "m" (endPaint) ); return result; #elif defined (_M_IX86) @@ -411,7 +413,7 @@ void PluginView::updatePluginWidget() m_clipRect = windowClipRect(); m_clipRect.move(-m_windowRect.x(), -m_windowRect.y()); - if (platformPluginWidget() && (m_windowRect != oldWindowRect || m_clipRect != oldClipRect)) { + if (platformPluginWidget() && (!m_haveUpdatedPluginWidget || m_windowRect != oldWindowRect || m_clipRect != oldClipRect)) { HRGN rgn; setCallingPlugin(true); @@ -429,7 +431,7 @@ void PluginView::updatePluginWidget() ::SetWindowRgn(platformPluginWidget(), rgn, TRUE); } - if (m_windowRect != oldWindowRect) + if (!m_haveUpdatedPluginWidget || m_windowRect != oldWindowRect) ::MoveWindow(platformPluginWidget(), m_windowRect.x(), m_windowRect.y(), m_windowRect.width(), m_windowRect.height(), TRUE); if (clipToZeroRect) { @@ -438,6 +440,8 @@ void PluginView::updatePluginWidget() } setCallingPlugin(false); + + m_haveUpdatedPluginWidget = true; } } @@ -492,7 +496,54 @@ bool PluginView::dispatchNPEvent(NPEvent& npEvent) return result; } -void PluginView::paintWindowedPluginIntoContext(GraphicsContext* context, const IntRect& rect) const +void PluginView::paintIntoTransformedContext(HDC hdc) +{ + if (m_isWindowed) { + SendMessage(platformPluginWidget(), WM_PRINTCLIENT, reinterpret_cast<WPARAM>(hdc), PRF_CLIENT | PRF_CHILDREN | PRF_OWNED); + return; + } + + m_npWindow.type = NPWindowTypeDrawable; + m_npWindow.window = hdc; + + WINDOWPOS windowpos = { 0 }; + +#if PLATFORM(WINCE) + IntRect r = static_cast<FrameView*>(parent())->contentsToWindow(frameRect()); + + windowpos.x = r.x(); + windowpos.y = r.y(); + windowpos.cx = r.width(); + windowpos.cy = r.height(); +#else + IntPoint p = static_cast<FrameView*>(parent())->contentsToWindow(frameRect().location()); + + windowpos.x = p.x(); + windowpos.y = p.y(); + windowpos.cx = frameRect().width(); + windowpos.cy = frameRect().height(); +#endif + + NPEvent npEvent; + npEvent.event = WM_WINDOWPOSCHANGED; + npEvent.lParam = reinterpret_cast<uint32>(&windowpos); + npEvent.wParam = 0; + + dispatchNPEvent(npEvent); + + setNPWindowRect(frameRect()); + + npEvent.event = WM_PAINT; + npEvent.wParam = reinterpret_cast<uint32>(hdc); + + // This is supposed to be a pointer to the dirty rect, but it seems that the Flash plugin + // ignores it so we just pass null. + npEvent.lParam = 0; + + dispatchNPEvent(npEvent); +} + +void PluginView::paintWindowedPluginIntoContext(GraphicsContext* context, const IntRect& rect) { #if !PLATFORM(WINCE) ASSERT(m_isWindowed); @@ -514,7 +565,7 @@ void PluginView::paintWindowedPluginIntoContext(GraphicsContext* context, const SetWorldTransform(hdc, &transform); - SendMessage(platformPluginWidget(), WM_PRINTCLIENT, reinterpret_cast<WPARAM>(hdc), PRF_CLIENT | PRF_CHILDREN | PRF_OWNED); + paintIntoTransformedContext(hdc); SetWorldTransform(hdc, &originalTransform); @@ -544,7 +595,6 @@ void PluginView::paint(GraphicsContext* context, const IntRect& rect) ASSERT(parent()->isFrameView()); IntRect rectInWindow = static_cast<FrameView*>(parent())->contentsToWindow(frameRect()); HDC hdc = context->getWindowsContext(rectInWindow, m_isTransparent); - NPEvent npEvent; // On Safari/Windows without transparency layers the GraphicsContext returns the HDC // of the window and the plugin expects that the passed in DC has window coordinates. @@ -560,44 +610,7 @@ void PluginView::paint(GraphicsContext* context, const IntRect& rect) } #endif - m_npWindow.type = NPWindowTypeDrawable; - m_npWindow.window = hdc; - - WINDOWPOS windowpos; - memset(&windowpos, 0, sizeof(windowpos)); - -#if PLATFORM(WINCE) - IntRect r = static_cast<FrameView*>(parent())->contentsToWindow(frameRect()); - - windowpos.x = r.x(); - windowpos.y = r.y(); - windowpos.cx = r.width(); - windowpos.cy = r.height(); -#else - IntPoint p = static_cast<FrameView*>(parent())->contentsToWindow(frameRect().location()); - - windowpos.x = p.x(); - windowpos.y = p.y(); - windowpos.cx = frameRect().width(); - windowpos.cy = frameRect().height(); -#endif - - npEvent.event = WM_WINDOWPOSCHANGED; - npEvent.lParam = reinterpret_cast<uint32>(&windowpos); - npEvent.wParam = 0; - - dispatchNPEvent(npEvent); - - setNPWindowRect(frameRect()); - - npEvent.event = WM_PAINT; - npEvent.wParam = reinterpret_cast<uint32>(hdc); - - // This is supposed to be a pointer to the dirty rect, but it seems that the Flash plugin - // ignores it so we just pass null. - npEvent.lParam = 0; - - dispatchNPEvent(npEvent); + paintIntoTransformedContext(hdc); context->releaseWindowsContext(hdc, frameRect(), m_isTransparent); } @@ -795,80 +808,6 @@ void PluginView::setNPWindowRect(const IntRect& rect) } } -void PluginView::stop() -{ - if (!m_isStarted) - return; - - HashSet<RefPtr<PluginStream> > streams = m_streams; - HashSet<RefPtr<PluginStream> >::iterator end = streams.end(); - for (HashSet<RefPtr<PluginStream> >::iterator it = streams.begin(); it != end; ++it) { - (*it)->stop(); - disconnectStream((*it).get()); - } - - ASSERT(m_streams.isEmpty()); - - m_isStarted = false; - - // Unsubclass the window - if (m_isWindowed) { -#if PLATFORM(WINCE) - WNDPROC currentWndProc = (WNDPROC)GetWindowLong(platformPluginWidget(), GWL_WNDPROC); - - if (currentWndProc == PluginViewWndProc) - SetWindowLong(platformPluginWidget(), GWL_WNDPROC, (LONG)m_pluginWndProc); -#else - WNDPROC currentWndProc = (WNDPROC)GetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC); - - if (currentWndProc == PluginViewWndProc) - SetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC, (LONG)m_pluginWndProc); -#endif - } - - JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); - - // Clear the window - m_npWindow.window = 0; - if (m_plugin->pluginFuncs()->setwindow && !m_plugin->quirks().contains(PluginQuirkDontSetNullWindowHandleOnDestroy)) { - setCallingPlugin(true); - m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow); - setCallingPlugin(false); - } - - PluginMainThreadScheduler::scheduler().unregisterPlugin(m_instance); - - // Destroy the plugin - NPSavedData* savedData = 0; - setCallingPlugin(true); - NPError npErr = m_plugin->pluginFuncs()->destroy(m_instance, &savedData); - setCallingPlugin(false); - LOG_NPERROR(npErr); - - if (savedData) { - if (savedData->buf) - NPN_MemFree(savedData->buf); - NPN_MemFree(savedData); - } - - m_instance->pdata = 0; -} - -const char* PluginView::userAgentStatic() -{ - return 0; -} - -const char* PluginView::userAgent() -{ - if (m_plugin->quirks().contains(PluginQuirkWantsMozillaUserAgent)) - return MozillaUserAgent; - - if (m_userAgent.isNull()) - m_userAgent = m_parentFrame->loader()->userAgent(m_url).utf8(); - return m_userAgent.data(); -} - NPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32 len, const char* buf) { String filename(buf, len); @@ -954,7 +893,7 @@ NPError PluginView::getValue(NPNVariable variable, void* value) case NPNVnetscapeWindow: { HWND* w = reinterpret_cast<HWND*>(value); - *w = windowHandleForPlatformWidget(parent() ? parent()->hostWindow()->platformWindow() : 0); + *w = windowHandleForPageClient(parent() ? parent()->hostWindow()->platformPageClient() : 0); return NPERR_NO_ERROR; } @@ -1026,50 +965,13 @@ void PluginView::forceRedraw() if (m_isWindowed) ::UpdateWindow(platformPluginWidget()); else - ::UpdateWindow(windowHandleForPlatformWidget(parent() ? parent()->hostWindow()->platformWindow() : 0)); -} - -PluginView::~PluginView() -{ - if (m_instance) - m_instance->ndata = 0; - stop(); - - deleteAllValues(m_requests); - - freeStringArray(m_paramNames, m_paramCount); - freeStringArray(m_paramValues, m_paramCount); - - if (platformPluginWidget()) - DestroyWindow(platformPluginWidget()); - - m_parentFrame->script()->cleanupScriptObjectsForPlugin(this); - - if (m_plugin && !m_plugin->quirks().contains(PluginQuirkDontUnloadPlugin)) - m_plugin->unload(); + ::UpdateWindow(windowHandleForPageClient(parent() ? parent()->hostWindow()->platformPageClient() : 0)); } -void PluginView::init() +bool PluginView::platformStart() { - if (m_haveInitialized) - return; - m_haveInitialized = true; - - if (!m_plugin) { - ASSERT(m_status == PluginStatusCanNotFindPlugin); - return; - } - - if (!m_plugin->load()) { - m_plugin = 0; - m_status = PluginStatusCanNotLoadPlugin; - return; - } - - if (!start()) { - m_status = PluginStatusCanNotLoadPlugin; - return; - } + ASSERT(m_isStarted); + ASSERT(m_status == PluginStatusLoadedSuccessfully); if (m_isWindowed) { registerPluginView(); @@ -1081,7 +983,7 @@ void PluginView::init() if (isSelfVisible()) flags |= WS_VISIBLE; - HWND parentWindowHandle = windowHandleForPlatformWidget(m_parentFrame->view()->hostWindow()->platformWindow()); + HWND parentWindowHandle = windowHandleForPageClient(m_parentFrame->view()->hostWindow()->platformPageClient()); HWND window = ::CreateWindowEx(0, kWebPluginViewdowClassName, 0, flags, 0, 0, 0, 0, parentWindowHandle, 0, Page::instanceHandle(), 0); @@ -1109,10 +1011,84 @@ void PluginView::init() m_npWindow.window = 0; } + updatePluginWidget(); + if (!m_plugin->quirks().contains(PluginQuirkDeferFirstSetWindowCall)) setNPWindowRect(frameRect()); - m_status = PluginStatusLoadedSuccessfully; + return true; +} + +void PluginView::platformDestroy() +{ + if (!platformPluginWidget()) + return; + + DestroyWindow(platformPluginWidget()); + setPlatformPluginWidget(0); +} + +PassRefPtr<Image> PluginView::snapshot() +{ + OwnPtr<HDC> hdc(CreateCompatibleDC(0)); + + if (!m_isWindowed) { + // Enable world transforms. + SetGraphicsMode(hdc.get(), GM_ADVANCED); + + XFORM transform; + GetWorldTransform(hdc.get(), &transform); + + // Windowless plug-ins assume that they're drawing onto the view's DC. + // Translate the context so that the plug-in draws at (0, 0). + ASSERT(parent()->isFrameView()); + IntPoint position = static_cast<FrameView*>(parent())->contentsToWindow(frameRect()).location(); + transform.eDx = -position.x(); + transform.eDy = -position.y(); + SetWorldTransform(hdc.get(), &transform); + } + + void* bits; + BitmapInfo bmp = BitmapInfo::createBottomUp(frameRect().size()); + OwnPtr<HBITMAP> hbmp(CreateDIBSection(0, &bmp, DIB_RGB_COLORS, &bits, 0, 0)); + + HBITMAP hbmpOld = static_cast<HBITMAP>(SelectObject(hdc.get(), hbmp.get())); + + paintIntoTransformedContext(hdc.get()); + + SelectObject(hdc.get(), hbmpOld); + + return BitmapImage::create(hbmp.get()); +} + +void PluginView::halt() +{ + ASSERT(!m_isHalted); + ASSERT(m_isStarted); + +#if !PLATFORM(QT) + // Show a screenshot of the plug-in. + toRenderWidget(m_element->renderer())->showSubstituteImage(snapshot()); +#endif + + m_isHalted = true; + m_hasBeenHalted = true; + + stop(); + platformDestroy(); +} + +void PluginView::restart() +{ + ASSERT(!m_isStarted); + ASSERT(m_isHalted); + + // Clear any substitute image. + toRenderWidget(m_element->renderer())->showSubstituteImage(0); + + m_isHalted = false; + m_haveUpdatedPluginWidget = false; + start(); } } // namespace WebCore |