WindowedPluginTest.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include "WindowedPluginTest.h"
  26. using namespace std;
  27. static const wchar_t instancePointerProperty[] = L"org.webkit.TestNetscapePlugin.WindowedPluginTest.InstancePointer";
  28. WindowedPluginTest::WindowedPluginTest(NPP npp, const string& identifier)
  29. : PluginTest(npp, identifier)
  30. , m_window(0)
  31. , m_originalWndProc(0)
  32. {
  33. }
  34. HWND WindowedPluginTest::testHarnessWindow() const
  35. {
  36. return ::GetAncestor(window(), GA_ROOT);
  37. }
  38. NPError WindowedPluginTest::NPP_SetWindow(NPP instance, NPWindow* window)
  39. {
  40. HWND newWindow = reinterpret_cast<HWND>(window->window);
  41. if (newWindow == m_window)
  42. return NPERR_NO_ERROR;
  43. if (m_window) {
  44. ::RemovePropW(m_window, instancePointerProperty);
  45. ::SetWindowLongPtr(m_window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(m_originalWndProc));
  46. m_originalWndProc = 0;
  47. }
  48. m_window = newWindow;
  49. if (!m_window)
  50. return NPERR_NO_ERROR;
  51. m_originalWndProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtrW(m_window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(staticWndProc)));
  52. ::SetPropW(m_window, instancePointerProperty, this);
  53. return NPERR_NO_ERROR;
  54. }
  55. LRESULT WindowedPluginTest::staticWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  56. {
  57. WindowedPluginTest* instance = reinterpret_cast<WindowedPluginTest*>(::GetPropW(hwnd, instancePointerProperty));
  58. bool handled = false;
  59. LRESULT result = instance->wndProc(message, wParam, lParam, handled);
  60. if (handled)
  61. return result;
  62. return ::CallWindowProcW(instance->m_originalWndProc, hwnd, message, wParam, lParam);
  63. }