| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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_client.h" | |
| 6 | |
| 7 #include "base/string_util.h" | |
| 8 #include "webkit/glue/plugins/test/plugin_test.h" | |
| 9 #include "webkit/glue/plugins/test/plugin_test_factory.h" | |
| 10 | |
| 11 namespace NPAPIClient { | |
| 12 | |
| 13 NPNetscapeFuncs* PluginClient::host_functions_; | |
| 14 | |
| 15 NPError PluginClient::GetEntryPoints(NPPluginFuncs* pFuncs) { | |
| 16 if (pFuncs == NULL) | |
| 17 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 18 | |
| 19 if (pFuncs->size < sizeof(NPPluginFuncs)) | |
| 20 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 21 | |
| 22 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; | |
| 23 pFuncs->newp = NPP_New; | |
| 24 pFuncs->destroy = NPP_Destroy; | |
| 25 pFuncs->setwindow = NPP_SetWindow; | |
| 26 pFuncs->newstream = NPP_NewStream; | |
| 27 pFuncs->destroystream = NPP_DestroyStream; | |
| 28 pFuncs->asfile = NPP_StreamAsFile; | |
| 29 pFuncs->writeready = NPP_WriteReady; | |
| 30 pFuncs->write = NPP_Write; | |
| 31 pFuncs->print = NPP_Print; | |
| 32 pFuncs->event = NPP_HandleEvent; | |
| 33 pFuncs->urlnotify = NPP_URLNotify; | |
| 34 pFuncs->getvalue = NPP_GetValue; | |
| 35 pFuncs->setvalue = NPP_SetValue; | |
| 36 pFuncs->javaClass = NULL; | |
| 37 pFuncs->urlredirectnotify = NPP_URLRedirectNotify; | |
| 38 | |
| 39 return NPERR_NO_ERROR; | |
| 40 } | |
| 41 | |
| 42 NPError PluginClient::Initialize(NPNetscapeFuncs* pFuncs) { | |
| 43 if (pFuncs == NULL) { | |
| 44 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 45 } | |
| 46 | |
| 47 if (static_cast<unsigned char>((pFuncs->version >> 8) & 0xff) > | |
| 48 NP_VERSION_MAJOR) { | |
| 49 return NPERR_INCOMPATIBLE_VERSION_ERROR; | |
| 50 } | |
| 51 | |
| 52 #if defined(OS_WIN) | |
| 53 // Check if we should crash. | |
| 54 HANDLE crash_event = CreateEvent(NULL, TRUE, FALSE, L"TestPluginCrashOnInit"); | |
| 55 if (WaitForSingleObject(crash_event, 0) == WAIT_OBJECT_0) { | |
| 56 int *zero = NULL; | |
| 57 *zero = 0; | |
| 58 } | |
| 59 CloseHandle(crash_event); | |
| 60 #endif | |
| 61 | |
| 62 host_functions_ = pFuncs; | |
| 63 | |
| 64 return NPERR_NO_ERROR; | |
| 65 } | |
| 66 | |
| 67 NPError PluginClient::Shutdown() { | |
| 68 return NPERR_NO_ERROR; | |
| 69 } | |
| 70 | |
| 71 } // namespace NPAPIClient | |
| 72 | |
| 73 extern "C" { | |
| 74 NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, | |
| 75 int16 argc, char* argn[], char* argv[], NPSavedData* saved) { | |
| 76 if (instance == NULL) | |
| 77 return NPERR_INVALID_INSTANCE_ERROR; | |
| 78 | |
| 79 // We look at the test name requested via the plugin arguments. We match | |
| 80 // that against a given test and try to instantiate it. | |
| 81 | |
| 82 // lookup the name parameter | |
| 83 std::string test_name; | |
| 84 for (int name_index = 0; name_index < argc; name_index++) { | |
| 85 if (base::strcasecmp(argn[name_index], "name") == 0) { | |
| 86 test_name = argv[name_index]; | |
| 87 break; | |
| 88 } | |
| 89 } | |
| 90 if (test_name.empty()) | |
| 91 return NPERR_GENERIC_ERROR; // no name found | |
| 92 | |
| 93 NPAPIClient::PluginTest* new_test = NPAPIClient::CreatePluginTest(test_name, | |
| 94 instance, NPAPIClient::PluginClient::HostFunctions()); | |
| 95 if (new_test == NULL) { | |
| 96 // If we don't have a test case for this, create a | |
| 97 // generic one which basically never fails. | |
| 98 LOG(WARNING) << "Unknown test name '" << test_name | |
| 99 << "'; using default test."; | |
| 100 new_test = new NPAPIClient::PluginTest(instance, | |
| 101 NPAPIClient::PluginClient::HostFunctions()); | |
| 102 } | |
| 103 | |
| 104 NPError ret = new_test->New(mode, argc, (const char**)argn, | |
| 105 (const char**)argv, saved); | |
| 106 if ((ret == NPERR_NO_ERROR) && new_test->IsWindowless()) { | |
| 107 NPAPIClient::PluginClient::HostFunctions()->setvalue( | |
| 108 instance, NPPVpluginWindowBool, NULL); | |
| 109 } | |
| 110 | |
| 111 return ret; | |
| 112 } | |
| 113 | |
| 114 NPError NPP_Destroy(NPP instance, NPSavedData** save) { | |
| 115 if (instance == NULL) | |
| 116 return NPERR_INVALID_INSTANCE_ERROR; | |
| 117 | |
| 118 NPAPIClient::PluginTest* plugin = | |
| 119 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 120 | |
| 121 NPError rv = plugin->Destroy(); | |
| 122 delete plugin; | |
| 123 return rv; | |
| 124 } | |
| 125 | |
| 126 NPError NPP_SetWindow(NPP instance, NPWindow* pNPWindow) { | |
| 127 if (instance == NULL) | |
| 128 return NPERR_INVALID_INSTANCE_ERROR; | |
| 129 | |
| 130 NPAPIClient::PluginTest* plugin = | |
| 131 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 132 | |
| 133 return plugin->SetWindow(pNPWindow); | |
| 134 } | |
| 135 | |
| 136 NPError NPP_NewStream(NPP instance, NPMIMEType type, | |
| 137 NPStream* stream, NPBool seekable, uint16* stype) { | |
| 138 if (instance == NULL) | |
| 139 return NPERR_INVALID_INSTANCE_ERROR; | |
| 140 | |
| 141 NPAPIClient::PluginTest* plugin = | |
| 142 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 143 | |
| 144 return plugin->NewStream(type, stream, seekable, stype); | |
| 145 } | |
| 146 | |
| 147 int32 NPP_WriteReady(NPP instance, NPStream *stream) { | |
| 148 if (instance == NULL) | |
| 149 return NPERR_INVALID_INSTANCE_ERROR; | |
| 150 | |
| 151 NPAPIClient::PluginTest* plugin = | |
| 152 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 153 | |
| 154 return plugin->WriteReady(stream); | |
| 155 } | |
| 156 | |
| 157 int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, | |
| 158 int32 len, void *buffer) { | |
| 159 if (instance == NULL) | |
| 160 return NPERR_INVALID_INSTANCE_ERROR; | |
| 161 | |
| 162 NPAPIClient::PluginTest* plugin = | |
| 163 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 164 | |
| 165 return plugin->Write(stream, offset, len, buffer); | |
| 166 } | |
| 167 | |
| 168 NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason) { | |
| 169 if (instance == NULL) | |
| 170 return NPERR_INVALID_INSTANCE_ERROR; | |
| 171 | |
| 172 NPAPIClient::PluginTest* plugin = | |
| 173 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 174 | |
| 175 return plugin->DestroyStream(stream, reason); | |
| 176 } | |
| 177 | |
| 178 void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) { | |
| 179 if (instance == NULL) | |
| 180 return; | |
| 181 | |
| 182 NPAPIClient::PluginTest* plugin = | |
| 183 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 184 | |
| 185 return plugin->StreamAsFile(stream, fname); | |
| 186 } | |
| 187 | |
| 188 void NPP_Print(NPP instance, NPPrint* printInfo) { | |
| 189 if (instance == NULL) | |
| 190 return; | |
| 191 | |
| 192 // XXXMB - do work here. | |
| 193 } | |
| 194 | |
| 195 void NPP_URLNotify(NPP instance, const char* url, NPReason reason, | |
| 196 void* notifyData) { | |
| 197 if (instance == NULL) | |
| 198 return; | |
| 199 | |
| 200 NPAPIClient::PluginTest* plugin = | |
| 201 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 202 | |
| 203 return plugin->URLNotify(url, reason, notifyData); | |
| 204 } | |
| 205 | |
| 206 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { | |
| 207 if (instance == NULL) | |
| 208 return NPERR_INVALID_INSTANCE_ERROR; | |
| 209 | |
| 210 // XXXMB - do work here. | |
| 211 return NPERR_GENERIC_ERROR; | |
| 212 } | |
| 213 | |
| 214 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) { | |
| 215 if (instance == NULL) | |
| 216 return NPERR_INVALID_INSTANCE_ERROR; | |
| 217 | |
| 218 // XXXMB - do work here. | |
| 219 return NPERR_GENERIC_ERROR; | |
| 220 } | |
| 221 | |
| 222 int16 NPP_HandleEvent(NPP instance, void* event) { | |
| 223 if (instance == NULL) | |
| 224 return 0; | |
| 225 | |
| 226 NPAPIClient::PluginTest* plugin = | |
| 227 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 228 | |
| 229 return plugin->HandleEvent(event); | |
| 230 } | |
| 231 | |
| 232 void NPP_URLRedirectNotify(NPP instance, const char* url, int32_t status, | |
| 233 void* notify_data) { | |
| 234 if (instance) { | |
| 235 NPAPIClient::PluginTest* plugin = | |
| 236 reinterpret_cast<NPAPIClient::PluginTest*>(instance->pdata); | |
| 237 plugin->URLRedirectNotify(url, status, notify_data); | |
| 238 } | |
| 239 } | |
| 240 } // extern "C" | |
| OLD | NEW |