- add sources.
[platform/framework/web/crosswalk.git] / src / content / test / plugin / plugin_create_instance_in_paint.cc
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.
4
5 #include "content/test/plugin/plugin_create_instance_in_paint.h"
6
7 #include "base/logging.h"
8 #include "content/test/plugin/plugin_client.h"
9
10 namespace NPAPIClient {
11
12 CreateInstanceInPaintTest::CreateInstanceInPaintTest(
13     NPP id, NPNetscapeFuncs *host_functions)
14     : PluginTest(id, host_functions),
15       window_(NULL), created_(false) {
16 }
17
18 NPError CreateInstanceInPaintTest::SetWindow(NPWindow* pNPWindow) {
19   if (pNPWindow->window == NULL)
20     return NPERR_NO_ERROR;
21
22   if (test_id() == "1") {
23     if (!window_) {
24       static ATOM window_class = 0;
25       if (!window_class) {
26         WNDCLASSEX wcex;
27         wcex.cbSize         = sizeof(WNDCLASSEX);
28         wcex.style          = CS_DBLCLKS;
29         wcex.lpfnWndProc    =
30             &NPAPIClient::CreateInstanceInPaintTest::WindowProc;
31         wcex.cbClsExtra     = 0;
32         wcex.cbWndExtra     = 0;
33         wcex.hInstance      = GetModuleHandle(NULL);
34         wcex.hIcon          = 0;
35         wcex.hCursor        = 0;
36         wcex.hbrBackground  = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);
37         wcex.lpszMenuName   = 0;
38         wcex.lpszClassName  = L"CreateInstanceInPaintTestWindowClass";
39         wcex.hIconSm        = 0;
40         window_class = RegisterClassEx(&wcex);
41       }
42
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);
49       DCHECK(window_);
50       // TODO: this property leaks.
51       ::SetProp(window_, L"Plugin_Instance", this);
52     }
53   } else if (test_id() == "2") {
54     SignalTestCompleted();
55   } else {
56     NOTREACHED();
57   }
58   return NPERR_NO_ERROR;
59 }
60
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));
73     }
74   }
75
76   return DefWindowProc(window, message, wparam, lparam);
77 }
78
79 } // namespace NPAPIClient