| 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 "webkit/activex_shim/npp_impl.h" | 9 #include "webkit/activex_shim/npp_impl.h" |
| 9 #include "webkit/default_plugin/plugin_impl.h" | 10 #include "webkit/default_plugin/plugin_impl.h" |
| 10 #include "webkit/glue/webkit_glue.h" | 11 #include "webkit/glue/webkit_glue.h" |
| 11 | 12 |
| 12 namespace default_plugin { | 13 namespace default_plugin { |
| 13 // | 14 // |
| 14 // Forward declare the linker-provided pseudo variable for the | 15 // Forward declare the linker-provided pseudo variable for the |
| 15 // current module handle. | 16 // current module handle. |
| 16 // | 17 // |
| 17 extern "C" IMAGE_DOS_HEADER __ImageBase; | 18 extern "C" IMAGE_DOS_HEADER __ImageBase; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 47 g_browser = funcs; | 48 g_browser = funcs; |
| 48 activex_shim::g_browser = funcs; | 49 activex_shim::g_browser = funcs; |
| 49 return 0; | 50 return 0; |
| 50 } | 51 } |
| 51 | 52 |
| 52 NPError API_CALL NP_Shutdown(void) { | 53 NPError API_CALL NP_Shutdown(void) { |
| 53 g_browser = NULL; | 54 g_browser = NULL; |
| 54 return 0; | 55 return 0; |
| 55 } | 56 } |
| 56 | 57 |
| 58 namespace { |
| 59 // This function is only invoked when the default plugin is invoked |
| 60 // with a special mime type application/chromium-test-default-plugin |
| 61 void SignalTestResult(NPP instance) { |
| 62 NPObject *window_obj = NULL; |
| 63 g_browser->getvalue(instance, NPNVWindowNPObject, &window_obj); |
| 64 if (!window_obj) { |
| 65 NOTREACHED(); |
| 66 return; |
| 67 } |
| 68 |
| 69 std::string script = "javascript:onSuccess()"; |
| 70 NPString script_string; |
| 71 script_string.UTF8Characters = script.c_str(); |
| 72 script_string.UTF8Length = |
| 73 static_cast<unsigned int>(script.length()); |
| 74 |
| 75 NPVariant result_var; |
| 76 NPError result = g_browser->evaluate(instance, window_obj, |
| 77 &script_string, &result_var); |
| 78 g_browser->releaseobject(window_obj); |
| 79 } |
| 80 |
| 81 } // namespace CHROMIUM_DefaultPluginTest |
| 82 |
| 57 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, | 83 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, |
| 58 char* argn[], char* argv[], NPSavedData* saved) { | 84 char* argn[], char* argv[], NPSavedData* saved) { |
| 59 if (instance == NULL) | 85 if (instance == NULL) |
| 60 return NPERR_INVALID_INSTANCE_ERROR; | 86 return NPERR_INVALID_INSTANCE_ERROR; |
| 61 | 87 |
| 62 // We don't want the null plugin to work in the following cases:- | 88 // We don't want the null plugin to work in the following cases:- |
| 63 // 1. Test-shell | 89 // 1. Test-shell |
| 64 // 2. The plugin is running in the renderer process. | 90 // 2. The plugin is running in the renderer process. |
| 65 if (webkit_glue::IsPluginRunningInRendererProcess()) { | 91 if (webkit_glue::IsPluginRunningInRendererProcess()) { |
| 92 if (!base::strcasecmp(plugin_type, |
| 93 "application/chromium-test-default-plugin")) { |
| 94 SignalTestResult(instance); |
| 95 return NPERR_NO_ERROR; |
| 96 } |
| 66 return NPERR_GENERIC_ERROR; | 97 return NPERR_GENERIC_ERROR; |
| 67 } | 98 } |
| 68 | 99 |
| 100 |
| 69 PluginInstallerImpl* plugin_impl = new PluginInstallerImpl(mode); | 101 PluginInstallerImpl* plugin_impl = new PluginInstallerImpl(mode); |
| 70 plugin_impl->Initialize(GetCurrentModuleHandle(), instance, plugin_type, argc, | 102 plugin_impl->Initialize(GetCurrentModuleHandle(), instance, plugin_type, argc, |
| 71 argn, argv); | 103 argn, argv); |
| 72 instance->pdata = reinterpret_cast<void*>(plugin_impl); | 104 instance->pdata = reinterpret_cast<void*>(plugin_impl); |
| 73 return NPERR_NO_ERROR; | 105 return NPERR_NO_ERROR; |
| 74 } | 106 } |
| 75 | 107 |
| 76 NPError NPP_Destroy(NPP instance, NPSavedData** save) { | 108 NPError NPP_Destroy(NPP instance, NPSavedData** save) { |
| 77 PluginInstallerImpl* plugin_impl = | 109 PluginInstallerImpl* plugin_impl = |
| 78 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); | 110 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 if (instance == NULL) | 235 if (instance == NULL) |
| 204 return 0; | 236 return 0; |
| 205 | 237 |
| 206 PluginInstallerImpl* plugin_impl = | 238 PluginInstallerImpl* plugin_impl = |
| 207 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); | 239 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); |
| 208 | 240 |
| 209 return plugin_impl->NPP_HandleEvent(event); | 241 return plugin_impl->NPP_HandleEvent(event); |
| 210 } | 242 } |
| 211 | 243 |
| 212 } // default_plugin | 244 } // default_plugin |
| OLD | NEW |