OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "webkit/plugins/npapi/test/plugin_javascript_open_popup.h" | |
6 | |
7 #include "build/build_config.h" | |
8 #include "base/logging.h" | |
9 | |
10 #if defined(USE_X11) | |
11 #include "third_party/npapi/bindings/npapi_x11.h" | |
12 #endif | |
13 #include "webkit/plugins/npapi/test/plugin_client.h" | |
14 | |
15 namespace NPAPIClient { | |
16 | |
17 ExecuteJavascriptOpenPopupWithPluginTest:: | |
18 ExecuteJavascriptOpenPopupWithPluginTest(NPP id, | |
19 NPNetscapeFuncs *host_functions) | |
20 : PluginTest(id, host_functions), | |
21 popup_window_test_started_(false) { | |
22 } | |
23 | |
24 int16 ExecuteJavascriptOpenPopupWithPluginTest::SetWindow( | |
25 NPWindow* window) { | |
26 #if !defined(OS_MACOSX) | |
27 if (window->window == NULL) | |
28 return NPERR_NO_ERROR; | |
29 #endif | |
30 | |
31 if (!popup_window_test_started_) { | |
32 popup_window_test_started_ = true; | |
33 HostFunctions()->geturl( | |
34 id(), "popup_window_with_target_plugin.html", "_blank"); | |
35 } | |
36 return NPERR_NO_ERROR; | |
37 } | |
38 | |
39 // ExecuteJavascriptPopupWindowTargetPluginTest member defines. | |
40 ExecuteJavascriptPopupWindowTargetPluginTest:: | |
41 ExecuteJavascriptPopupWindowTargetPluginTest( | |
42 NPP id, NPNetscapeFuncs* host_functions) | |
43 : PluginTest(id, host_functions), | |
44 test_completed_(false) { | |
45 } | |
46 | |
47 int16 ExecuteJavascriptPopupWindowTargetPluginTest::SetWindow( | |
48 NPWindow* window) { | |
49 #if !defined(OS_MACOSX) | |
50 if (window->window == NULL) | |
51 return NPERR_NO_ERROR; | |
52 #endif | |
53 | |
54 if (!test_completed_) { | |
55 if (CheckWindow(window)) { | |
56 SignalTestCompleted(); | |
57 test_completed_ = true; | |
58 } | |
59 } | |
60 return PluginTest::SetWindow(window); | |
61 } | |
62 | |
63 #if defined(OS_WIN) | |
64 bool ExecuteJavascriptPopupWindowTargetPluginTest::CheckWindow( | |
65 NPWindow* window) { | |
66 HWND window_handle = reinterpret_cast<HWND>(window->window); | |
67 | |
68 if (IsWindow(window_handle)) { | |
69 HWND parent_window = GetParent(window_handle); | |
70 if (!IsWindow(parent_window)) | |
71 SetError("Windowed plugin instantiated with NULL parent"); | |
72 return true; | |
73 } | |
74 | |
75 return false; | |
76 } | |
77 | |
78 #elif defined(USE_X11) | |
79 // This code blindly follows the same sorts of verifications done on | |
80 // the Windows side. Does it make sense on X? Maybe not really, but | |
81 // it can't hurt to do extra validations. | |
82 bool ExecuteJavascriptPopupWindowTargetPluginTest::CheckWindow( | |
83 NPWindow* window) { | |
84 Window xwindow = reinterpret_cast<Window>(window->window); | |
85 // Grab a pointer to the extra SetWindow data so we can grab the display out. | |
86 NPSetWindowCallbackStruct* extra = | |
87 static_cast<NPSetWindowCallbackStruct*>(window->ws_info); | |
88 | |
89 if (xwindow) { | |
90 Window root, parent; | |
91 Window* wins = NULL; | |
92 unsigned int num_child; | |
93 Status status = XQueryTree(extra->display, xwindow, &root, &parent, | |
94 &wins, &num_child); | |
95 if (wins) | |
96 XFree(wins); | |
97 DCHECK(status != 0); | |
98 if (!parent || parent == root) | |
99 SetError("Windowed plugin instantiated with NULL parent"); | |
100 return true; | |
101 } | |
102 | |
103 return false; | |
104 } | |
105 #elif defined(OS_MACOSX) | |
106 bool ExecuteJavascriptPopupWindowTargetPluginTest::CheckWindow( | |
107 NPWindow* window) { | |
108 // TODO(port) scaffolding--replace with a real test once NPWindow is done. | |
109 return false; | |
110 } | |
111 #endif | |
112 | |
113 } // namespace NPAPIClient | |
OLD | NEW |