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