| 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" |
| 11 | 11 |
| 12 namespace default_plugin { | 12 namespace default_plugin { |
| 13 | |
| 14 #if defined(OS_WIN) | |
| 15 // | 13 // |
| 16 // Forward declare the linker-provided pseudo variable for the | 14 // Forward declare the linker-provided pseudo variable for the |
| 17 // current module handle. | 15 // current module handle. |
| 18 // | 16 // |
| 19 extern "C" IMAGE_DOS_HEADER __ImageBase; | 17 extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 20 | 18 |
| 21 // get the handle to the currently executing module | 19 // get the handle to the currently executing module |
| 22 inline HMODULE GetCurrentModuleHandle() { | 20 inline HMODULE GetCurrentModuleHandle() { |
| 23 return reinterpret_cast<HINSTANCE>(&__ImageBase); | 21 return reinterpret_cast<HINSTANCE>(&__ImageBase); |
| 24 } | 22 } |
| 25 #endif | |
| 26 | 23 |
| 27 // Initialized in NP_Initialize. | 24 // Initialized in NP_Initialize. |
| 28 NPNetscapeFuncs* g_browser = NULL; | 25 NPNetscapeFuncs* g_browser = NULL; |
| 29 | 26 |
| 30 NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs) { | 27 NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs) { |
| 31 funcs->version = 11; | 28 funcs->version = 11; |
| 32 funcs->size = sizeof(*funcs); | 29 funcs->size = sizeof(*funcs); |
| 33 funcs->newp = NPP_New; | 30 funcs->newp = NPP_New; |
| 34 funcs->destroy = NPP_Destroy; | 31 funcs->destroy = NPP_Destroy; |
| 35 funcs->setwindow = NPP_SetWindow; | 32 funcs->setwindow = NPP_SetWindow; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return; | 64 return; |
| 68 } | 65 } |
| 69 | 66 |
| 70 std::string script = "javascript:onSuccess()"; | 67 std::string script = "javascript:onSuccess()"; |
| 71 NPString script_string; | 68 NPString script_string; |
| 72 script_string.UTF8Characters = script.c_str(); | 69 script_string.UTF8Characters = script.c_str(); |
| 73 script_string.UTF8Length = | 70 script_string.UTF8Length = |
| 74 static_cast<unsigned int>(script.length()); | 71 static_cast<unsigned int>(script.length()); |
| 75 | 72 |
| 76 NPVariant result_var; | 73 NPVariant result_var; |
| 77 g_browser->evaluate(instance, window_obj, | 74 NPError result = g_browser->evaluate(instance, window_obj, |
| 78 &script_string, &result_var); | 75 &script_string, &result_var); |
| 79 g_browser->releaseobject(window_obj); | 76 g_browser->releaseobject(window_obj); |
| 80 } | 77 } |
| 81 | 78 |
| 82 } // namespace CHROMIUM_DefaultPluginTest | 79 } // namespace CHROMIUM_DefaultPluginTest |
| 83 | 80 |
| 84 bool NegotiateModels(NPP instance) { | |
| 85 #if defined(OS_MACOSX) | |
| 86 NPError err; | |
| 87 // Set drawing model to core graphics | |
| 88 NPBool supportsCoreGraphics = FALSE; | |
| 89 err = g_browser->getvalue(instance, | |
| 90 NPNVsupportsCoreGraphicsBool, | |
| 91 &supportsCoreGraphics); | |
| 92 if (err != NPERR_NO_ERROR || !supportsCoreGraphics) { | |
| 93 NOTREACHED(); | |
| 94 return false; | |
| 95 } | |
| 96 err = g_browser->setvalue(instance, | |
| 97 NPPVpluginDrawingModel, | |
| 98 (void*)NPDrawingModelCoreGraphics); | |
| 99 if (err != NPERR_NO_ERROR) { | |
| 100 NOTREACHED(); | |
| 101 return false; | |
| 102 } | |
| 103 | |
| 104 // Set event model to cocoa | |
| 105 NPBool supportsCocoaEvents = FALSE; | |
| 106 err = g_browser->getvalue(instance, | |
| 107 NPNVsupportsCocoaBool, | |
| 108 &supportsCocoaEvents); | |
| 109 if (err != NPERR_NO_ERROR || !supportsCocoaEvents) { | |
| 110 NOTREACHED(); | |
| 111 return false; | |
| 112 } | |
| 113 err = g_browser->setvalue(instance, | |
| 114 NPPVpluginEventModel, | |
| 115 (void*)NPEventModelCocoa); | |
| 116 if (err != NPERR_NO_ERROR) { | |
| 117 NOTREACHED(); | |
| 118 return false; | |
| 119 } | |
| 120 #endif | |
| 121 return true; | |
| 122 } | |
| 123 | |
| 124 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, | 81 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, |
| 125 char* argn[], char* argv[], NPSavedData* saved) { | 82 char* argn[], char* argv[], NPSavedData* saved) { |
| 126 if (instance == NULL) | 83 if (instance == NULL) |
| 127 return NPERR_INVALID_INSTANCE_ERROR; | 84 return NPERR_INVALID_INSTANCE_ERROR; |
| 128 | 85 |
| 129 // We don't want the null plugin to work in the following cases:- | 86 // We don't want the null plugin to work in the following cases:- |
| 130 // 1. Test-shell | 87 // 1. Test-shell |
| 131 // 2. The plugin is running in the renderer process. | 88 // 2. The plugin is running in the renderer process. |
| 132 if (webkit_glue::IsPluginRunningInRendererProcess()) { | 89 if (webkit_glue::IsPluginRunningInRendererProcess()) { |
| 133 if (!base::strcasecmp(plugin_type, | 90 if (!base::strcasecmp(plugin_type, |
| 134 "application/chromium-test-default-plugin")) { | 91 "application/chromium-test-default-plugin")) { |
| 135 SignalTestResult(instance); | 92 SignalTestResult(instance); |
| 136 return NPERR_NO_ERROR; | 93 return NPERR_NO_ERROR; |
| 137 } | 94 } |
| 138 return NPERR_GENERIC_ERROR; | 95 return NPERR_GENERIC_ERROR; |
| 139 } | 96 } |
| 140 | 97 |
| 141 if (!NegotiateModels(instance)) | 98 |
| 142 return NPERR_INCOMPATIBLE_VERSION_ERROR; | |
| 143 | |
| 144 PluginInstallerImpl* plugin_impl = new PluginInstallerImpl(mode); | 99 PluginInstallerImpl* plugin_impl = new PluginInstallerImpl(mode); |
| 145 plugin_impl->Initialize( | 100 plugin_impl->Initialize(GetCurrentModuleHandle(), instance, plugin_type, argc, |
| 146 #if defined(OS_WIN) | |
| 147 GetCurrentModuleHandle(), | |
| 148 #else | |
| 149 NULL, | |
| 150 #endif | |
| 151 instance, plugin_type, argc, | |
| 152 argn, argv); | 101 argn, argv); |
| 153 | |
| 154 instance->pdata = reinterpret_cast<void*>(plugin_impl); | 102 instance->pdata = reinterpret_cast<void*>(plugin_impl); |
| 155 return NPERR_NO_ERROR; | 103 return NPERR_NO_ERROR; |
| 156 } | 104 } |
| 157 | 105 |
| 158 NPError NPP_Destroy(NPP instance, NPSavedData** save) { | 106 NPError NPP_Destroy(NPP instance, NPSavedData** save) { |
| 159 PluginInstallerImpl* plugin_impl = | 107 PluginInstallerImpl* plugin_impl = |
| 160 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); | 108 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); |
| 161 | 109 |
| 162 if (plugin_impl) { | 110 if (plugin_impl) { |
| 163 plugin_impl->Shutdown(); | 111 plugin_impl->Shutdown(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 184 } | 132 } |
| 185 | 133 |
| 186 PluginInstallerImpl* plugin_impl = | 134 PluginInstallerImpl* plugin_impl = |
| 187 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); | 135 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); |
| 188 | 136 |
| 189 if (plugin_impl == NULL) { | 137 if (plugin_impl == NULL) { |
| 190 NOTREACHED(); | 138 NOTREACHED(); |
| 191 return NPERR_GENERIC_ERROR; | 139 return NPERR_GENERIC_ERROR; |
| 192 } | 140 } |
| 193 | 141 |
| 194 if (!plugin_impl->NPP_SetWindow(window_info)) { | 142 HWND window_handle = reinterpret_cast<HWND>(window_info->window); |
| 143 if (!plugin_impl->SetWindow(window_handle)) { |
| 195 delete plugin_impl; | 144 delete plugin_impl; |
| 196 return NPERR_GENERIC_ERROR; | 145 return NPERR_GENERIC_ERROR; |
| 197 } | 146 } |
| 198 | 147 |
| 199 return NPERR_NO_ERROR; | 148 return NPERR_NO_ERROR; |
| 200 } | 149 } |
| 201 | 150 |
| 202 NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, | 151 NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, |
| 203 NPBool seekable, uint16* stype) { | 152 NPBool seekable, uint16* stype) { |
| 204 if (instance == NULL) | 153 if (instance == NULL) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 if (instance == NULL) | 233 if (instance == NULL) |
| 285 return 0; | 234 return 0; |
| 286 | 235 |
| 287 PluginInstallerImpl* plugin_impl = | 236 PluginInstallerImpl* plugin_impl = |
| 288 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); | 237 reinterpret_cast<PluginInstallerImpl*>(instance->pdata); |
| 289 | 238 |
| 290 return plugin_impl->NPP_HandleEvent(event); | 239 return plugin_impl->NPP_HandleEvent(event); |
| 291 } | 240 } |
| 292 | 241 |
| 293 } // default_plugin | 242 } // default_plugin |
| OLD | NEW |