OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/glue/plugins/test/plugin_thread_async_call_test.h" |
| 6 #include "webkit/glue/plugins/test/plugin_client.h" |
| 7 |
| 8 namespace NPAPIClient { |
| 9 |
| 10 namespace { |
| 11 |
| 12 // There are two plugin instances in this test. The long lived instance is used |
| 13 // for reporting errors and signalling test completion. The short lived one is |
| 14 // used to verify that async callbacks are not invoked after NPP_Destroy. |
| 15 PluginThreadAsyncCallTest* g_short_lived_instance; |
| 16 PluginThreadAsyncCallTest* g_long_lived_instance; |
| 17 |
| 18 void OnCallSucceededHelper(void* data) { |
| 19 static_cast<PluginThreadAsyncCallTest*>(data)->OnCallSucceeded(); |
| 20 } |
| 21 |
| 22 void OnCallFailed(void* data) { |
| 23 g_long_lived_instance->SetError("Async callback invoked after NPP_Destroy"); |
| 24 } |
| 25 |
| 26 void OnCallCompletedHelper(void* data) { |
| 27 static_cast<PluginThreadAsyncCallTest*>(data)->OnCallCompleted(); |
| 28 } |
| 29 } |
| 30 |
| 31 PluginThreadAsyncCallTest::PluginThreadAsyncCallTest( |
| 32 NPP id, NPNetscapeFuncs *host_functions) |
| 33 : PluginTest(id, host_functions) { |
| 34 } |
| 35 |
| 36 NPError PluginThreadAsyncCallTest::New( |
| 37 uint16 mode, int16 argc, const char* argn[], const char* argv[], |
| 38 NPSavedData* saved) { |
| 39 NPError error = PluginTest::New(mode, argc, argn, argv, saved); |
| 40 if (error != NPERR_NO_ERROR) |
| 41 return error; |
| 42 |
| 43 // Determine whether this is the short lived instance. |
| 44 for (int i = 0; i < argc; ++i) { |
| 45 if (base::strcasecmp(argn[i], "short_lived") == 0) { |
| 46 if (base::strcasecmp(argv[i], "true") == 0) { |
| 47 g_short_lived_instance = this; |
| 48 } else { |
| 49 g_long_lived_instance = this; |
| 50 } |
| 51 } |
| 52 } |
| 53 |
| 54 // Schedule an async call that will succeed. |
| 55 if (this == g_short_lived_instance) { |
| 56 HostFunctions()->pluginthreadasynccall(id(), OnCallSucceededHelper, this); |
| 57 } |
| 58 |
| 59 return NPERR_NO_ERROR; |
| 60 } |
| 61 |
| 62 void PluginThreadAsyncCallTest::OnCallSucceeded() { |
| 63 // Delete the short lived instance. |
| 64 NPIdentifier delete_id = HostFunctions()->getstringidentifier( |
| 65 "deleteShortLivedInstance"); |
| 66 |
| 67 NPObject *window_obj = NULL; |
| 68 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj); |
| 69 |
| 70 NPVariant result; |
| 71 HostFunctions()->invoke(id(), window_obj, delete_id, NULL, 0, &result); |
| 72 } |
| 73 |
| 74 NPError PluginThreadAsyncCallTest::Destroy() { |
| 75 if (this == g_short_lived_instance) { |
| 76 // Schedule an async call that should not be called. |
| 77 HostFunctions()->pluginthreadasynccall(id(), OnCallFailed, NULL); |
| 78 |
| 79 // Schedule an async call to end the test using the long lived instance. |
| 80 HostFunctions()->pluginthreadasynccall(g_long_lived_instance->id(), |
| 81 OnCallCompletedHelper, |
| 82 g_long_lived_instance); |
| 83 } |
| 84 |
| 85 return NPERR_NO_ERROR; |
| 86 } |
| 87 |
| 88 void PluginThreadAsyncCallTest::OnCallCompleted() { |
| 89 SignalTestCompleted(); |
| 90 } |
| 91 |
| 92 } // namespace NPAPIClient |
OLD | NEW |