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