| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 "chrome_frame/chrome_frame_npapi_entrypoints.h" | |
| 6 #include "chrome_frame/chrome_frame_npapi.h" | |
| 7 | |
| 8 #define NPAPI WINAPI | |
| 9 | |
| 10 // Plugin entry points. | |
| 11 extern "C" { | |
| 12 NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs); | |
| 13 NPError NPAPI NP_GetEntryPoints(NPPluginFuncs* plugin_funcs); | |
| 14 void NPAPI NP_Shutdown(); | |
| 15 } | |
| 16 | |
| 17 NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs) { | |
| 18 DVLOG(1) << __FUNCTION__; | |
| 19 _pAtlModule->Lock(); | |
| 20 npapi::InitializeBrowserFunctions(browser_funcs); | |
| 21 return NPERR_NO_ERROR; | |
| 22 } | |
| 23 | |
| 24 NPError NPAPI NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) { | |
| 25 plugin_funcs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; | |
| 26 plugin_funcs->size = sizeof(plugin_funcs); | |
| 27 plugin_funcs->newp = chrome_frame::NPP_New; | |
| 28 plugin_funcs->destroy = chrome_frame::NPP_Destroy; | |
| 29 plugin_funcs->setwindow = chrome_frame::NPP_SetWindow; | |
| 30 plugin_funcs->newstream = chrome_frame::NPP_NewStream; | |
| 31 plugin_funcs->destroystream = chrome_frame::NPP_DestroyStream; | |
| 32 plugin_funcs->asfile = NULL; | |
| 33 plugin_funcs->writeready = chrome_frame::NPP_WriteReady; | |
| 34 plugin_funcs->write = chrome_frame::NPP_Write; | |
| 35 plugin_funcs->print = chrome_frame::NPP_Print; | |
| 36 plugin_funcs->event = NULL; | |
| 37 plugin_funcs->urlnotify = chrome_frame::NPP_URLNotify; | |
| 38 plugin_funcs->getvalue = chrome_frame::NPP_GetValue; | |
| 39 plugin_funcs->setvalue = chrome_frame::NPP_SetValue; | |
| 40 plugin_funcs->urlredirectnotify = chrome_frame::NPP_URLRedirectNotify; | |
| 41 return NPERR_NO_ERROR; | |
| 42 } | |
| 43 | |
| 44 void NPAPI NP_Shutdown() { | |
| 45 DVLOG(1) << __FUNCTION__; | |
| 46 | |
| 47 npapi::UninitializeBrowserFunctions(); | |
| 48 | |
| 49 _pAtlModule->Unlock(); // matches Lock() inside NP_Initialize | |
| 50 | |
| 51 DLOG_IF(ERROR, _pAtlModule->GetLockCount() != 0) | |
| 52 << "Being shut down but still have " << _pAtlModule->GetLockCount() | |
| 53 << " living objects"; | |
| 54 } | |
| 55 | |
| 56 | |
| 57 namespace chrome_frame { | |
| 58 | |
| 59 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, | |
| 60 char* argn[], char* argv[], NPSavedData* saved) { | |
| 61 if (instance == NULL) | |
| 62 return NPERR_INVALID_INSTANCE_ERROR; | |
| 63 | |
| 64 ChromeFrameNPAPI::ChromeFrameNPObject* chrome_frame_npapi_obj = | |
| 65 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>( | |
| 66 npapi::CreateObject(instance, ChromeFrameNPAPI::PluginClass())); | |
| 67 DCHECK(chrome_frame_npapi_obj != NULL); | |
| 68 | |
| 69 ChromeFrameNPAPI* plugin_instance = | |
| 70 chrome_frame_npapi_obj->chrome_frame_plugin_instance; | |
| 71 DCHECK(plugin_instance != NULL); | |
| 72 | |
| 73 // Note that we MUST set instance->pdata BEFORE calling Initialize. This is | |
| 74 // because Initialize can call back into the NPAPI host which will need the | |
| 75 // pdata field to be set. | |
| 76 chrome_frame_npapi_obj->chrome_frame_plugin_instance = | |
| 77 plugin_instance; | |
| 78 instance->pdata = chrome_frame_npapi_obj; | |
| 79 | |
| 80 bool init = plugin_instance->Initialize(plugin_type, instance, | |
| 81 mode, argc, argn, argv); | |
| 82 DCHECK(init); | |
| 83 | |
| 84 return NPERR_NO_ERROR; | |
| 85 } | |
| 86 | |
| 87 NPError NPP_Destroy(NPP instance, NPSavedData** save) { | |
| 88 // Takes ownership and releases the object at the end of scope. | |
| 89 ScopedNpObject<ChromeFrameNPAPI::ChromeFrameNPObject> chrome_frame_npapi_obj( | |
| 90 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>( | |
| 91 instance->pdata)); | |
| 92 | |
| 93 if (chrome_frame_npapi_obj.get()) { | |
| 94 ChromeFrameNPAPI* plugin_instance = | |
| 95 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 96 | |
| 97 plugin_instance->Uninitialize(); | |
| 98 instance->pdata = NULL; | |
| 99 } | |
| 100 | |
| 101 return NPERR_NO_ERROR; | |
| 102 } | |
| 103 | |
| 104 NPError NPP_SetWindow(NPP instance, NPWindow* window_info) { | |
| 105 if (window_info == NULL) { | |
| 106 NOTREACHED(); | |
| 107 return NPERR_GENERIC_ERROR; | |
| 108 } | |
| 109 | |
| 110 ChromeFrameNPAPI* plugin_instance = | |
| 111 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 112 | |
| 113 if (plugin_instance == NULL) { | |
| 114 return NPERR_INVALID_INSTANCE_ERROR; | |
| 115 } | |
| 116 | |
| 117 plugin_instance->SetWindow(window_info); | |
| 118 return NPERR_NO_ERROR; | |
| 119 } | |
| 120 | |
| 121 NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, | |
| 122 NPBool seekable, uint16* stream_type) { | |
| 123 ChromeFrameNPAPI* plugin_instance = | |
| 124 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 125 if (plugin_instance == NULL) { | |
| 126 return NPERR_INVALID_INSTANCE_ERROR; | |
| 127 } | |
| 128 | |
| 129 return plugin_instance->NewStream(type, stream, seekable, stream_type); | |
| 130 } | |
| 131 | |
| 132 NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) { | |
| 133 ChromeFrameNPAPI* plugin_instance = | |
| 134 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 135 if (plugin_instance == NULL) { | |
| 136 return NPERR_INVALID_INSTANCE_ERROR; | |
| 137 } | |
| 138 | |
| 139 return plugin_instance->DestroyStream(stream, reason); | |
| 140 } | |
| 141 | |
| 142 NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) { | |
| 143 if (variable == NPPVpluginScriptableNPObject) { | |
| 144 void** plugin = reinterpret_cast<void**>(value); | |
| 145 ChromeFrameNPAPI::ChromeFrameNPObject* chrome_frame_npapi_obj = | |
| 146 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>( | |
| 147 instance->pdata); | |
| 148 // Return value is expected to be retained | |
| 149 npapi::RetainObject(reinterpret_cast<NPObject*>(chrome_frame_npapi_obj)); | |
| 150 *plugin = chrome_frame_npapi_obj; | |
| 151 return NPERR_NO_ERROR; | |
| 152 } | |
| 153 return NPERR_GENERIC_ERROR; | |
| 154 } | |
| 155 | |
| 156 NPError NPP_SetValue(NPP instance, NPNVariable variable, void* value) { | |
| 157 return NPERR_GENERIC_ERROR; | |
| 158 } | |
| 159 | |
| 160 int32 NPP_WriteReady(NPP instance, NPStream* stream) { | |
| 161 static const int kMaxBytesForPluginConsumption = 0x7FFFFFFF; | |
| 162 | |
| 163 ChromeFrameNPAPI* plugin_instance = | |
| 164 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 165 | |
| 166 if (plugin_instance == NULL) { | |
| 167 return kMaxBytesForPluginConsumption; | |
| 168 } | |
| 169 | |
| 170 return plugin_instance->WriteReady(stream); | |
| 171 } | |
| 172 | |
| 173 int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, | |
| 174 void* buffer) { | |
| 175 ChromeFrameNPAPI* plugin_instance = | |
| 176 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 177 | |
| 178 if (plugin_instance == NULL) | |
| 179 return len; | |
| 180 | |
| 181 return plugin_instance->Write(stream, offset, len, buffer); | |
| 182 } | |
| 183 | |
| 184 void NPP_URLNotify(NPP instance, const char* url, NPReason reason, | |
| 185 void* notifyData) { | |
| 186 ChromeFrameNPAPI* plugin_instance = | |
| 187 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 188 if (plugin_instance) { | |
| 189 plugin_instance->UrlNotify(url, reason, notifyData); | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 void NPP_Print(NPP instance, NPPrint* print_info) { | |
| 194 ChromeFrameNPAPI* plugin_instance = | |
| 195 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 196 | |
| 197 if (plugin_instance == NULL) { | |
| 198 NOTREACHED() << "Failed to find plugin instance"; | |
| 199 return; | |
| 200 } | |
| 201 | |
| 202 plugin_instance->Print(print_info); | |
| 203 } | |
| 204 | |
| 205 void NPP_URLRedirectNotify(NPP instance, const char* url, int status, | |
| 206 void* notify_data) { | |
| 207 ChromeFrameNPAPI* plugin_instance = | |
| 208 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
| 209 | |
| 210 if (plugin_instance == NULL) { | |
| 211 NOTREACHED() << "Failed to find plugin instance"; | |
| 212 npapi::URLRedirectResponse(instance, notify_data, false); | |
| 213 return; | |
| 214 } | |
| 215 plugin_instance->URLRedirectNotify(url, status, notify_data); | |
| 216 } | |
| 217 | |
| 218 } // namespace chrome_frame | |
| OLD | NEW |