| 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/default_plugin/plugin_main.h" | 5 #include "webkit/default_plugin/plugin_main.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "webkit/default_plugin/plugin_impl.h" | 9 #include "webkit/default_plugin/plugin_impl.h" |
| 10 #include "webkit/glue/webkit_glue.h" | 10 #include "webkit/glue/webkit_glue.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // get the handle to the currently executing module | 21 // get the handle to the currently executing module |
| 22 inline HMODULE GetCurrentModuleHandle() { | 22 inline HMODULE GetCurrentModuleHandle() { |
| 23 return reinterpret_cast<HINSTANCE>(&__ImageBase); | 23 return reinterpret_cast<HINSTANCE>(&__ImageBase); |
| 24 } | 24 } |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 // Initialized in NP_Initialize. | 27 // Initialized in NP_Initialize. |
| 28 NPNetscapeFuncs* g_browser = NULL; | 28 NPNetscapeFuncs* g_browser = NULL; |
| 29 | 29 |
| 30 NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs) { | 30 NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs) { |
| 31 // Be explicit about the namespace, because all internal plugins have |
| 32 // functions with these names and some might accidentally put them into the |
| 33 // global namespace. In that case, the linker might prefer the global one. |
| 31 funcs->version = 11; | 34 funcs->version = 11; |
| 32 funcs->size = sizeof(*funcs); | 35 funcs->size = sizeof(*funcs); |
| 33 funcs->newp = NPP_New; | 36 funcs->newp = default_plugin::NPP_New; |
| 34 funcs->destroy = NPP_Destroy; | 37 funcs->destroy = default_plugin::NPP_Destroy; |
| 35 funcs->setwindow = NPP_SetWindow; | 38 funcs->setwindow = default_plugin::NPP_SetWindow; |
| 36 funcs->newstream = NPP_NewStream; | 39 funcs->newstream = default_plugin::NPP_NewStream; |
| 37 funcs->destroystream = NPP_DestroyStream; | 40 funcs->destroystream = default_plugin::NPP_DestroyStream; |
| 38 funcs->writeready = NPP_WriteReady; | 41 funcs->writeready = default_plugin::NPP_WriteReady; |
| 39 funcs->write = NPP_Write; | 42 funcs->write = default_plugin::NPP_Write; |
| 40 funcs->asfile = NULL; | 43 funcs->asfile = NULL; |
| 41 funcs->print = NULL; | 44 funcs->print = NULL; |
| 42 funcs->event = NPP_HandleEvent; | 45 funcs->event = default_plugin::NPP_HandleEvent; |
| 43 funcs->urlnotify = NPP_URLNotify; | 46 funcs->urlnotify = default_plugin::NPP_URLNotify; |
| 47 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 48 funcs->getvalue = default_plugin::NPP_GetValue; |
| 49 #else |
| 44 funcs->getvalue = NULL; | 50 funcs->getvalue = NULL; |
| 51 #endif |
| 45 funcs->setvalue = NULL; | 52 funcs->setvalue = NULL; |
| 46 return NPERR_NO_ERROR; | 53 return NPERR_NO_ERROR; |
| 47 } | 54 } |
| 48 | 55 |
| 49 NPError API_CALL NP_Initialize(NPNetscapeFuncs* funcs) { | 56 NPError API_CALL NP_Initialize(NPNetscapeFuncs* funcs) { |
| 50 g_browser = funcs; | 57 g_browser = funcs; |
| 51 return 0; | 58 return 0; |
| 52 } | 59 } |
| 53 | 60 |
| 61 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 62 NPError API_CALL NP_Initialize(NPNetscapeFuncs* funcs, NPPluginFuncs* p_funcs) { |
| 63 NPError err = NP_Initialize(funcs); |
| 64 if (err != NPERR_NO_ERROR) |
| 65 return err; |
| 66 return NP_GetEntryPoints(p_funcs); |
| 67 } |
| 68 #endif |
| 69 |
| 54 NPError API_CALL NP_Shutdown(void) { | 70 NPError API_CALL NP_Shutdown(void) { |
| 55 g_browser = NULL; | 71 g_browser = NULL; |
| 56 return 0; | 72 return NPERR_NO_ERROR; |
| 57 } | 73 } |
| 58 | 74 |
| 59 namespace { | 75 namespace { |
| 60 // This function is only invoked when the default plugin is invoked | 76 // This function is only invoked when the default plugin is invoked |
| 61 // with a special mime type application/chromium-test-default-plugin | 77 // with a special mime type application/chromium-test-default-plugin |
| 62 void SignalTestResult(NPP instance) { | 78 void SignalTestResult(NPP instance) { |
| 63 NPObject *window_obj = NULL; | 79 NPObject *window_obj = NULL; |
| 64 g_browser->getvalue(instance, NPNVWindowNPObject, &window_obj); | 80 g_browser->getvalue(instance, NPNVWindowNPObject, &window_obj); |
| 65 if (!window_obj) { | 81 if (!window_obj) { |
| 66 NOTREACHED(); | 82 NOTREACHED(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 NOTREACHED(); | 126 NOTREACHED(); |
| 111 return false; | 127 return false; |
| 112 } | 128 } |
| 113 err = g_browser->setvalue(instance, | 129 err = g_browser->setvalue(instance, |
| 114 NPPVpluginEventModel, | 130 NPPVpluginEventModel, |
| 115 (void*)NPEventModelCocoa); | 131 (void*)NPEventModelCocoa); |
| 116 if (err != NPERR_NO_ERROR) { | 132 if (err != NPERR_NO_ERROR) { |
| 117 NOTREACHED(); | 133 NOTREACHED(); |
| 118 return false; | 134 return false; |
| 119 } | 135 } |
| 136 #elif defined(OS_POSIX) |
| 137 NPError err; |
| 138 // Check that chrome still supports xembed. |
| 139 NPBool supportsXEmbed = FALSE; |
| 140 err = g_browser->getvalue(instance, |
| 141 NPNVSupportsXEmbedBool, |
| 142 &supportsXEmbed); |
| 143 if (err != NPERR_NO_ERROR || !supportsXEmbed) { |
| 144 NOTREACHED(); |
| 145 return false; |
| 146 } |
| 147 |
| 148 // Check that the toolkit is still gtk2. |
| 149 NPNToolkitType toolkit; |
| 150 err = g_browser->getvalue(instance, |
| 151 NPNVToolkit, |
| 152 &toolkit); |
| 153 if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2) { |
| 154 NOTREACHED(); |
| 155 return false; |
| 156 } |
| 120 #endif | 157 #endif |
| 121 return true; | 158 return true; |
| 122 } | 159 } |
| 123 | 160 |
| 124 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, | 161 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, |
| 125 char* argn[], char* argv[], NPSavedData* saved) { | 162 char* argn[], char* argv[], NPSavedData* saved) { |
| 126 if (instance == NULL) | 163 if (instance == NULL) |
| 127 return NPERR_INVALID_INSTANCE_ERROR; | 164 return NPERR_INVALID_INSTANCE_ERROR; |
| 128 | 165 |
| 129 // We don't want the null plugin to work in the following cases:- | 166 // We don't want the null plugin to work in the following cases:- |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 310 |
| 274 if (!plugin_impl) { | 311 if (!plugin_impl) { |
| 275 NOTREACHED(); | 312 NOTREACHED(); |
| 276 return; | 313 return; |
| 277 } | 314 } |
| 278 | 315 |
| 279 plugin_impl->URLNotify(url, reason); | 316 plugin_impl->URLNotify(url, reason); |
| 280 } | 317 } |
| 281 } | 318 } |
| 282 | 319 |
| 320 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 321 NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) { |
| 322 switch (variable) { |
| 323 case NPPVpluginNeedsXEmbed: |
| 324 *static_cast<NPBool*>(value) = TRUE; |
| 325 return NPERR_NO_ERROR; |
| 326 default: |
| 327 return NPERR_INVALID_PARAM; |
| 328 } |
| 329 } |
| 330 #endif |
| 331 |
| 283 int16 NPP_HandleEvent(NPP instance, void* event) { | 332 int16 NPP_HandleEvent(NPP instance, void* event) { |
| 284 if (instance == NULL) | 333 if (instance == NULL) |
| 285 return 0; | 334 return 0; |
| 286 | 335 |
| 287 PluginInstallerImpl* plugin_impl = | 336 PluginInstallerImpl* plugin_impl = |
| 288 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); | 337 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); |
| 289 | 338 |
| 290 return plugin_impl->NPP_HandleEvent(event); | 339 return plugin_impl->NPP_HandleEvent(event); |
| 291 } | 340 } |
| 292 | 341 |
| 293 } // default_plugin | 342 } // default_plugin |
| OLD | NEW |