1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/test/plugin/plugin_create_instance_in_paint.h"
7 #include "base/logging.h"
8 #include "content/test/plugin/plugin_client.h"
10 namespace NPAPIClient
{
12 CreateInstanceInPaintTest::CreateInstanceInPaintTest(
13 NPP id
, NPNetscapeFuncs
*host_functions
)
14 : PluginTest(id
, host_functions
),
15 window_(NULL
), created_(false) {
18 NPError
CreateInstanceInPaintTest::SetWindow(NPWindow
* pNPWindow
) {
19 if (pNPWindow
->window
== NULL
)
20 return NPERR_NO_ERROR
;
22 if (test_id() == "1") {
24 static ATOM window_class
= 0;
27 wcex
.cbSize
= sizeof(WNDCLASSEX
);
28 wcex
.style
= CS_DBLCLKS
;
30 &NPAPIClient::CreateInstanceInPaintTest::WindowProc
;
33 wcex
.hInstance
= GetModuleHandle(NULL
);
36 wcex
.hbrBackground
= reinterpret_cast<HBRUSH
>(COLOR_WINDOW
+1);
37 wcex
.lpszMenuName
= 0;
38 wcex
.lpszClassName
= L
"CreateInstanceInPaintTestWindowClass";
40 window_class
= RegisterClassEx(&wcex
);
43 HWND parent
= reinterpret_cast<HWND
>(pNPWindow
->window
);
44 window_
= CreateWindowEx(
45 WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
,
46 MAKEINTATOM(window_class
), 0,
47 WS_CHILD
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
| WS_VISIBLE
,
48 0, 0, 100, 100, parent
, 0, GetModuleHandle(NULL
), 0);
50 // TODO: this property leaks.
51 ::SetProp(window_
, L
"Plugin_Instance", this);
53 } else if (test_id() == "2") {
54 SignalTestCompleted();
58 return NPERR_NO_ERROR
;
61 LRESULT CALLBACK
CreateInstanceInPaintTest::WindowProc(
62 HWND window
, UINT message
, WPARAM wparam
, LPARAM lparam
) {
63 if (message
== WM_PAINT
) {
64 CreateInstanceInPaintTest
* this_instance
=
65 reinterpret_cast<CreateInstanceInPaintTest
*>
66 (::GetProp(window
, L
"Plugin_Instance"));
67 if (this_instance
->test_id() == "1" && !this_instance
->created_
) {
68 ::RemoveProp(window
, L
"Plugin_Instance");
69 this_instance
->created_
= true;
70 this_instance
->HostFunctions()->geturlnotify(
71 this_instance
->id(), "javascript:CreateNewInstance()", NULL
,
72 reinterpret_cast<void*>(1));
76 return DefWindowProc(window
, message
, wparam
, lparam
);
79 } // namespace NPAPIClient