OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/plugins/test/plugin_npobject_lifetime_test.h" | 5 #include "webkit/glue/plugins/test/plugin_npobject_lifetime_test.h" |
6 | 6 |
7 namespace NPAPIClient { | 7 namespace NPAPIClient { |
8 | 8 |
9 const int kNPObjectLifetimeTimer = 100; | 9 const int kNPObjectLifetimeTimer = 100; |
10 const int kNPObjectLifetimeTimerElapse = 2000; | 10 const int kNPObjectLifetimeTimerElapse = 2000; |
11 | 11 |
12 NPObject* NPObjectLifetimeTestInstance2::plugin_instance_object_ = NULL; | 12 NPObject* NPObjectLifetimeTestInstance2::plugin_instance_object_ = NULL; |
13 | 13 |
14 NPObjectDeletePluginInNPN_Evaluate* | 14 NPObjectDeletePluginInNPN_Evaluate* |
15 NPObjectDeletePluginInNPN_Evaluate::g_npn_evaluate_test_instance_ = NULL; | 15 NPObjectDeletePluginInNPN_Evaluate::g_npn_evaluate_test_instance_ = NULL; |
16 | 16 |
17 NPObjectLifetimeTest::NPObjectLifetimeTest(NPP id, | 17 NPObjectLifetimeTest::NPObjectLifetimeTest(NPP id, |
18 NPNetscapeFuncs *host_functions) | 18 NPNetscapeFuncs *host_functions) |
19 : PluginTest(id, host_functions), | 19 : PluginTest(id, host_functions), |
20 other_plugin_instance_object_(NULL) { | 20 other_plugin_instance_object_(NULL) { |
21 } | 21 } |
22 | 22 |
23 NPError NPObjectLifetimeTest::SetWindow(NPWindow* pNPWindow) { | 23 NPError NPObjectLifetimeTest::SetWindow(NPWindow* pNPWindow) { |
| 24 if (pNPWindow->window == NULL) |
| 25 return NPERR_NO_ERROR; |
| 26 |
24 HWND window_handle = reinterpret_cast<HWND>(pNPWindow->window); | 27 HWND window_handle = reinterpret_cast<HWND>(pNPWindow->window); |
25 if (!::GetProp(window_handle, L"Plugin_Instance")) { | 28 if (!::GetProp(window_handle, L"Plugin_Instance")) { |
26 ::SetProp(window_handle, L"Plugin_Instance", this); | 29 ::SetProp(window_handle, L"Plugin_Instance", this); |
27 // We attempt to retreive the NPObject for the plugin instance identified | 30 // We attempt to retreive the NPObject for the plugin instance identified |
28 // by the NPObjectLifetimeTestInstance2 class as it may not have been | 31 // by the NPObjectLifetimeTestInstance2 class as it may not have been |
29 // instantiated yet. | 32 // instantiated yet. |
30 SetTimer(window_handle, kNPObjectLifetimeTimer, kNPObjectLifetimeTimerElapse
, | 33 SetTimer(window_handle, kNPObjectLifetimeTimer, kNPObjectLifetimeTimerElapse
, |
31 TimerProc); | 34 TimerProc); |
32 } | 35 } |
33 return NPERR_NO_ERROR; | 36 return NPERR_NO_ERROR; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 80 } |
78 | 81 |
79 NPObjectLifetimeTestInstance2::~NPObjectLifetimeTestInstance2() { | 82 NPObjectLifetimeTestInstance2::~NPObjectLifetimeTestInstance2() { |
80 if (plugin_instance_object_) { | 83 if (plugin_instance_object_) { |
81 HostFunctions()->releaseobject(plugin_instance_object_); | 84 HostFunctions()->releaseobject(plugin_instance_object_); |
82 plugin_instance_object_ = NULL; | 85 plugin_instance_object_ = NULL; |
83 } | 86 } |
84 } | 87 } |
85 | 88 |
86 NPError NPObjectLifetimeTestInstance2::SetWindow(NPWindow* pNPWindow) { | 89 NPError NPObjectLifetimeTestInstance2::SetWindow(NPWindow* pNPWindow) { |
| 90 if (pNPWindow->window == NULL) |
| 91 return NPERR_NO_ERROR; |
| 92 |
87 if (!plugin_instance_object_) { | 93 if (!plugin_instance_object_) { |
88 if (!HostFunctions()->getvalue(id(), NPNVWindowNPObject, | 94 if (!HostFunctions()->getvalue(id(), NPNVWindowNPObject, |
89 &plugin_instance_object_)) { | 95 &plugin_instance_object_)) { |
90 SetError("Failed to get NPObject for plugin instance2"); | 96 SetError("Failed to get NPObject for plugin instance2"); |
91 SignalTestCompleted(); | 97 SignalTestCompleted(); |
92 return NPERR_GENERIC_ERROR; | 98 return NPERR_GENERIC_ERROR; |
93 } | 99 } |
94 } | 100 } |
95 | 101 |
96 return NPERR_NO_ERROR; | 102 return NPERR_NO_ERROR; |
97 } | 103 } |
98 | 104 |
99 | 105 |
100 NPObjectDeletePluginInNPN_Evaluate::NPObjectDeletePluginInNPN_Evaluate( | 106 NPObjectDeletePluginInNPN_Evaluate::NPObjectDeletePluginInNPN_Evaluate( |
101 NPP id, NPNetscapeFuncs *host_functions) | 107 NPP id, NPNetscapeFuncs *host_functions) |
102 : PluginTest(id, host_functions), | 108 : PluginTest(id, host_functions), |
103 plugin_instance_object_(NULL), | 109 plugin_instance_object_(NULL), |
104 npn_evaluate_timer_proc_set_(false) { | 110 npn_evaluate_timer_proc_set_(false) { |
105 g_npn_evaluate_test_instance_ = this; | 111 g_npn_evaluate_test_instance_ = this; |
106 } | 112 } |
107 | 113 |
108 NPObjectDeletePluginInNPN_Evaluate::~NPObjectDeletePluginInNPN_Evaluate() { | 114 NPObjectDeletePluginInNPN_Evaluate::~NPObjectDeletePluginInNPN_Evaluate() { |
109 if (plugin_instance_object_) { | 115 if (plugin_instance_object_) { |
110 HostFunctions()->releaseobject(plugin_instance_object_); | 116 HostFunctions()->releaseobject(plugin_instance_object_); |
111 plugin_instance_object_ = NULL; | 117 plugin_instance_object_ = NULL; |
112 } | 118 } |
113 } | 119 } |
114 | 120 |
115 NPError NPObjectDeletePluginInNPN_Evaluate::SetWindow(NPWindow* np_window) { | 121 NPError NPObjectDeletePluginInNPN_Evaluate::SetWindow(NPWindow* np_window) { |
| 122 if (np_window->window == NULL) |
| 123 return NPERR_NO_ERROR; |
| 124 |
116 HWND window_handle = reinterpret_cast<HWND>(np_window->window); | 125 HWND window_handle = reinterpret_cast<HWND>(np_window->window); |
117 // We setup a timerproc to invoke NPN_Evaluate to destroy this plugin | 126 // We setup a timerproc to invoke NPN_Evaluate to destroy this plugin |
118 // instance. This is to ensure that we don't destroy the plugin instance | 127 // instance. This is to ensure that we don't destroy the plugin instance |
119 // while it is being used in webkit as this leads to crashes and is a | 128 // while it is being used in webkit as this leads to crashes and is a |
120 // more accurate representation of the renderer crash as described in | 129 // more accurate representation of the renderer crash as described in |
121 // http://b/issue?id=1134683. | 130 // http://b/issue?id=1134683. |
122 if (!npn_evaluate_timer_proc_set_) { | 131 if (!npn_evaluate_timer_proc_set_) { |
123 npn_evaluate_timer_proc_set_ = true; | 132 npn_evaluate_timer_proc_set_ = true; |
124 SetTimer(window_handle, kNPObjectLifetimeTimer, kNPObjectLifetimeTimerElapse
, | 133 SetTimer(window_handle, kNPObjectLifetimeTimer, kNPObjectLifetimeTimerElapse
, |
125 TimerProc); | 134 TimerProc); |
(...skipping 26 matching lines...) Expand all Loading... |
152 static_cast<unsigned int>(script.length()); | 161 static_cast<unsigned int>(script.length()); |
153 | 162 |
154 NPVariant result_var; | 163 NPVariant result_var; |
155 bool result = g_npn_evaluate_test_instance_->HostFunctions()->evaluate( | 164 bool result = g_npn_evaluate_test_instance_->HostFunctions()->evaluate( |
156 g_npn_evaluate_test_instance_->id(), window_obj, | 165 g_npn_evaluate_test_instance_->id(), window_obj, |
157 &script_string, &result_var); | 166 &script_string, &result_var); |
158 // If this test failed we would have crashed by now. | 167 // If this test failed we would have crashed by now. |
159 } | 168 } |
160 | 169 |
161 } // namespace NPAPIClient | 170 } // namespace NPAPIClient |
OLD | NEW |