diff options
Diffstat (limited to 'o3d/plugin/cross')
-rw-r--r-- | o3d/plugin/cross/blacklist.cc | 3 | ||||
-rw-r--r-- | o3d/plugin/cross/config.h | 4 | ||||
-rw-r--r-- | o3d/plugin/cross/config_common.cc | 3 | ||||
-rw-r--r-- | o3d/plugin/cross/main.cc | 234 | ||||
-rw-r--r-- | o3d/plugin/cross/main.h | 125 | ||||
-rw-r--r-- | o3d/plugin/cross/o3d_glue.cc | 18 |
6 files changed, 210 insertions, 177 deletions
diff --git a/o3d/plugin/cross/blacklist.cc b/o3d/plugin/cross/blacklist.cc index 270c4df..9a0b33f 100644 --- a/o3d/plugin/cross/blacklist.cc +++ b/o3d/plugin/cross/blacklist.cc @@ -35,6 +35,8 @@ #include "plugin/cross/config.h" #include "base/logging.h" +namespace o3d { + // Checks the driver GUID against the blacklist file. Returns true if there's a // match [this driver is blacklisted] or if an IO error occurred. Check the // state of input_file to determine which it was. @@ -68,3 +70,4 @@ bool IsDriverBlacklisted(std::ifstream *input_file, unsigned int guid) { CHECK(input_file->eof()); return false; } +} // namespace o3d diff --git a/o3d/plugin/cross/config.h b/o3d/plugin/cross/config.h index 58ecc00..45fbaf5 100644 --- a/o3d/plugin/cross/config.h +++ b/o3d/plugin/cross/config.h @@ -40,6 +40,8 @@ #include <string> #include "plugin/cross/o3d_glue.h" +namespace o3d { + // Returns the user agent string. // Arguments: // npp: plugin instance. @@ -112,4 +114,6 @@ bool GetUserAgentMetrics(NPP npp); bool GetOpenGLMetrics(); +} // namespace o3d + #endif // O3D_PLUGIN_CROSS_CONFIG_H_ diff --git a/o3d/plugin/cross/config_common.cc b/o3d/plugin/cross/config_common.cc index 35d02f7..180443c 100644 --- a/o3d/plugin/cross/config_common.cc +++ b/o3d/plugin/cross/config_common.cc @@ -52,6 +52,8 @@ using glue::_o3d::GetServiceLocator; +namespace o3d { + // Gets the value of "navigator.userAgent" in the JavaScript context, which // contains the user agent string. std::string GetUserAgent(NPP npp) { @@ -213,3 +215,4 @@ bool CheckConfig(NPP npp) { if (!CheckUserAgent(npp, user_agent)) return false; return true; } +} // namespace o3d diff --git a/o3d/plugin/cross/main.cc b/o3d/plugin/cross/main.cc index 5f08407..23265e6 100644 --- a/o3d/plugin/cross/main.cc +++ b/o3d/plugin/cross/main.cc @@ -35,129 +35,141 @@ using glue::_o3d::PluginObject; using glue::StreamManager; +#if !defined(O3D_INTERNAL_PLUGIN) + int BreakpadEnabler::scope_count_ = 0; // Used for breakpad crash handling ExceptionManager *g_exception_manager = NULL; -extern "C" { - char *NP_GetMIMEDescription(void) { - return O3D_PLUGIN_MIME_TYPE "::O3D MIME"; - } - - NPError NP_GetValue(void *instance, NPPVariable variable, void *value) { - switch (variable) { - case NPPVpluginNameString: - *static_cast<char **>(value) = O3D_PLUGIN_NAME; - break; - case NPPVpluginDescriptionString: - *static_cast<char **>(value) = O3D_PLUGIN_DESCRIPTION; - break; - default: - return NPERR_INVALID_PARAM; - break; - } - return NPERR_NO_ERROR; - } - - NPError OSCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) { - HANDLE_CRASHES; - pluginFuncs->version = 11; - pluginFuncs->size = sizeof(*pluginFuncs); - pluginFuncs->newp = NPP_New; - pluginFuncs->destroy = NPP_Destroy; - pluginFuncs->setwindow = NPP_SetWindow; - pluginFuncs->newstream = NPP_NewStream; - pluginFuncs->destroystream = NPP_DestroyStream; - pluginFuncs->asfile = NPP_StreamAsFile; - pluginFuncs->writeready = NPP_WriteReady; - pluginFuncs->write = NPP_Write; - pluginFuncs->print = NPP_Print; - pluginFuncs->event = NPP_HandleEvent; - pluginFuncs->urlnotify = NPP_URLNotify; - pluginFuncs->getvalue = NPP_GetValue; - pluginFuncs->setvalue = NPP_SetValue; +#endif // O3D_INTERNAL_PLUGIN - return NPERR_NO_ERROR; - } +namespace o3d { - NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, - NPBool seekable, uint16 *stype) { - HANDLE_CRASHES; - PluginObject *obj = static_cast<PluginObject*>(instance->pdata); - StreamManager *stream_manager = obj->stream_manager(); - if (stream_manager->NewStream(stream, stype)) { - return NPERR_NO_ERROR; - } else { - // TODO: find out which error we should return - return NPERR_INVALID_PARAM; - } - } +char *NP_GetMIMEDescription(void) { + return O3D_PLUGIN_MIME_TYPE "::O3D MIME"; +} - NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) { - HANDLE_CRASHES; - PluginObject *obj = static_cast<PluginObject*>(instance->pdata); - StreamManager *stream_manager = obj->stream_manager(); - if (stream_manager->DestroyStream(stream, reason)) { - return NPERR_NO_ERROR; - } else { - // TODO: find out which error we should return +NPError NP_GetValue(void *instance, NPPVariable variable, void *value) { + switch (variable) { + case NPPVpluginNameString: + *static_cast<char **>(value) = O3D_PLUGIN_NAME; + break; + case NPPVpluginDescriptionString: + *static_cast<char **>(value) = O3D_PLUGIN_DESCRIPTION; + break; + default: return NPERR_INVALID_PARAM; - } + break; } - - int32 NPP_WriteReady(NPP instance, NPStream *stream) { - HANDLE_CRASHES; - PluginObject *obj = static_cast<PluginObject*>(instance->pdata); - StreamManager *stream_manager = obj->stream_manager(); - return stream_manager->WriteReady(stream); - } - - int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, - void *buffer) { - HANDLE_CRASHES; - PluginObject *obj = static_cast<PluginObject*>(instance->pdata); - StreamManager *stream_manager = obj->stream_manager(); - return stream_manager->Write(stream, offset, len, buffer); - } - - void NPP_Print(NPP instance, NPPrint *platformPrint) { - HANDLE_CRASHES; - } - - void NPP_URLNotify(NPP instance, const char *url, NPReason reason, - void *notifyData) { - HANDLE_CRASHES; - PluginObject *obj = static_cast<PluginObject*>(instance->pdata); - StreamManager *stream_manager = obj->stream_manager(); - stream_manager->URLNotify(url, reason, notifyData); + return NPERR_NO_ERROR; +} + +NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, + NPBool seekable, uint16 *stype) { + HANDLE_CRASHES; + PluginObject *obj = static_cast<PluginObject*>(instance->pdata); + StreamManager *stream_manager = obj->stream_manager(); + if (stream_manager->NewStream(stream, stype)) { + return NPERR_NO_ERROR; + } else { + // TODO: find out which error we should return + return NPERR_INVALID_PARAM; } +} - NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { - HANDLE_CRASHES; - switch (variable) { - case NPPVpluginScriptableNPObject: { - void **v = static_cast<void **>(value); - PluginObject *obj = static_cast<PluginObject *>(instance->pdata); - // Return value is expected to be retained - GLUE_PROFILE_START(instance, "retainobject"); - NPN_RetainObject(obj); - GLUE_PROFILE_STOP(instance, "retainobject"); - *v = obj; - break; - } - default: { - NPError ret = PlatformNPPGetValue(instance, variable, value); - if (ret == NPERR_INVALID_PARAM) - ret = NP_GetValue(instance, variable, value); - return ret; - } - } +NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) { + HANDLE_CRASHES; + PluginObject *obj = static_cast<PluginObject*>(instance->pdata); + StreamManager *stream_manager = obj->stream_manager(); + if (stream_manager->DestroyStream(stream, reason)) { return NPERR_NO_ERROR; + } else { + // TODO: find out which error we should return + return NPERR_INVALID_PARAM; } - - NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) { - HANDLE_CRASHES; - return NPERR_GENERIC_ERROR; +} + +int32 NPP_WriteReady(NPP instance, NPStream *stream) { + HANDLE_CRASHES; + PluginObject *obj = static_cast<PluginObject*>(instance->pdata); + StreamManager *stream_manager = obj->stream_manager(); + return stream_manager->WriteReady(stream); +} + +int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, + void *buffer) { + HANDLE_CRASHES; + PluginObject *obj = static_cast<PluginObject*>(instance->pdata); + StreamManager *stream_manager = obj->stream_manager(); + return stream_manager->Write(stream, offset, len, buffer); +} + +void NPP_Print(NPP instance, NPPrint *platformPrint) { + HANDLE_CRASHES; +} + +void NPP_URLNotify(NPP instance, const char *url, NPReason reason, + void *notifyData) { + HANDLE_CRASHES; + PluginObject *obj = static_cast<PluginObject*>(instance->pdata); + StreamManager *stream_manager = obj->stream_manager(); + stream_manager->URLNotify(url, reason, notifyData); +} + +NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { + HANDLE_CRASHES; + switch (variable) { + case NPPVpluginScriptableNPObject: { + void **v = static_cast<void **>(value); + PluginObject *obj = static_cast<PluginObject *>(instance->pdata); + // Return value is expected to be retained + GLUE_PROFILE_START(instance, "retainobject"); + NPN_RetainObject(obj); + GLUE_PROFILE_STOP(instance, "retainobject"); + *v = obj; + break; + } + default: { + NPError ret = PlatformNPPGetValue(instance, variable, value); + if (ret == NPERR_INVALID_PARAM) + ret = o3d::NP_GetValue(instance, variable, value); + return ret; + } } -} // extern "C" + return NPERR_NO_ERROR; +} + +NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) { + HANDLE_CRASHES; + return NPERR_GENERIC_ERROR; +} +} // namespace o3d + +#if defined(O3D_INTERNAL_PLUGIN) +namespace o3d { +#else +extern "C" { +#endif + +NPError OSCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) { + HANDLE_CRASHES; + pluginFuncs->version = 11; + pluginFuncs->size = sizeof(*pluginFuncs); + pluginFuncs->newp = o3d::NPP_New; + pluginFuncs->destroy = o3d::NPP_Destroy; + pluginFuncs->setwindow = o3d::NPP_SetWindow; + pluginFuncs->newstream = o3d::NPP_NewStream; + pluginFuncs->destroystream = o3d::NPP_DestroyStream; + pluginFuncs->asfile = o3d::NPP_StreamAsFile; + pluginFuncs->writeready = o3d::NPP_WriteReady; + pluginFuncs->write = o3d::NPP_Write; + pluginFuncs->print = o3d::NPP_Print; + pluginFuncs->event = o3d::NPP_HandleEvent; + pluginFuncs->urlnotify = o3d::NPP_URLNotify; + pluginFuncs->getvalue = o3d::NPP_GetValue; + pluginFuncs->setvalue = o3d::NPP_SetValue; + + return NPERR_NO_ERROR; +} +} // namespace o3d / extern "C" diff --git a/o3d/plugin/cross/main.h b/o3d/plugin/cross/main.h index e72f458..003a63a 100644 --- a/o3d/plugin/cross/main.h +++ b/o3d/plugin/cross/main.h @@ -43,7 +43,10 @@ #include <fstream> #include <iostream> +#if !defined(O3D_INTERNAL_PLUGIN) #include "breakpad/win/exception_handler_win32.h" +#endif // O3D_INTERNAL_PLUGIN + #include "core/cross/renderer.h" #include "core/cross/renderer_platform.h" #include "plugin/cross/o3d_glue.h" @@ -52,20 +55,11 @@ #include "third_party/nixysa/files/static_glue/npapi/common.h" #include "third_party/nixysa/files/static_glue/npapi/npn_api.h" -extern ExceptionManager *g_exception_manager; - -class RenderOnDemandCallbackHandler - : public o3d::Client::RenderOnDemandCallback { - public: - explicit RenderOnDemandCallbackHandler(glue::_o3d::PluginObject* obj) - : obj_(obj) { - } +#if defined(O3D_INTERNAL_PLUGIN) +#define HANDLE_CRASHES void(0) +#else // O3D_INTERNAL_PLUGIN - // This function is implemented for each platform. - virtual void Run(); - private: - glue::_o3d::PluginObject* obj_; -}; +extern ExceptionManager *g_exception_manager; // BreakpadEnabler is a simple class to keep track of whether or not // we're executing code that we want to handle crashes for @@ -92,54 +86,71 @@ class BreakpadEnabler { static int scope_count_; }; +#endif // O3D_INTERNAL_PLUGIN +#if defined(O3D_INTERNAL_PLUGIN) namespace o3d { -void WriteLogString(const char* text, int length); -} // end namespace o3d - -NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value); - -// NPAPI declarations. Some of these are only implemented in the -// platform-specific versions of "main.cc". - +#else extern "C" { +#endif NPError OSCALL NP_Shutdown(void); NPError OSCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs); - NPError NPP_Destroy(NPP instance, NPSavedData **save); - NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason); - NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value); - - NPError NPP_New(NPMIMEType pluginType, - NPP instance, - uint16 mode, - int16 argc, - char *argn[], - char *argv[], - NPSavedData *saved); - - NPError NPP_NewStream(NPP instance, - NPMIMEType type, - NPStream *stream, - NPBool seekable, - uint16 *stype); - - NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value); - NPError NPP_SetWindow(NPP instance, NPWindow *window); - - int32 NPP_Write(NPP instance, - NPStream *stream, - int32 offset, - int32 len, - void *buffer); - - int32 NPP_WriteReady(NPP instance, NPStream *stream); - void NPP_Print(NPP instance, NPPrint *platformPrint); - void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname); - - void NPP_URLNotify(NPP instance, - const char *url, - NPReason reason, - void *notifyData); -}; // end extern "C" +} + +namespace o3d { + +class RenderOnDemandCallbackHandler + : public o3d::Client::RenderOnDemandCallback { + public: + explicit RenderOnDemandCallbackHandler(glue::_o3d::PluginObject* obj) + : obj_(obj) { + } + + // This function is implemented for each platform. + virtual void Run(); + private: + glue::_o3d::PluginObject* obj_; +}; + +void WriteLogString(const char* text, int length); +NPError NPP_Destroy(NPP instance, NPSavedData **save); +NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason); +NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value); + +NPError NPP_New(NPMIMEType pluginType, + NPP instance, + uint16 mode, + int16 argc, + char *argn[], + char *argv[], + NPSavedData *saved); + +NPError NPP_NewStream(NPP instance, + NPMIMEType type, + NPStream *stream, + NPBool seekable, + uint16 *stype); + +NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value); +NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value); +NPError NPP_SetWindow(NPP instance, NPWindow *window); + +int32 NPP_Write(NPP instance, + NPStream *stream, + int32 offset, + int32 len, + void *buffer); + +int32 NPP_WriteReady(NPP instance, NPStream *stream); +void NPP_Print(NPP instance, NPPrint *platformPrint); +int16 NPP_HandleEvent(NPP instance, void *event); + +void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname); + +void NPP_URLNotify(NPP instance, + const char *url, + NPReason reason, + void *notifyData); +}; // namespace o3d #endif // O3D_PLUGIN_CROSS_MAIN_H_ diff --git a/o3d/plugin/cross/o3d_glue.cc b/o3d/plugin/cross/o3d_glue.cc index 63c8a60..9eecd0d 100644 --- a/o3d/plugin/cross/o3d_glue.cc +++ b/o3d/plugin/cross/o3d_glue.cc @@ -167,7 +167,7 @@ PluginObject::PluginObject(NPP npp) globals_npobject_ = glue::CreateStaticNPObject(npp); client_npobject_ = glue::namespace_o3d::class_Client::GetNPObject(npp, client_); - user_agent_ = GetUserAgent(npp); + user_agent_ = o3d::GetUserAgent(npp); } PluginObject::~PluginObject() { @@ -205,7 +205,7 @@ void PluginObject::TearDown() { ClearPluginProperty(hWnd_); #endif // OS_WIN #ifdef OS_MACOSX - ReleaseSafariBrowserWindow(mac_cocoa_window_); + o3d::ReleaseSafariBrowserWindow(mac_cocoa_window_); #endif UnmapAll(); @@ -231,7 +231,7 @@ void PluginObject::TearDown() { } void PluginObject::CreateRenderer(const o3d::DisplayWindow& display_window) { - if (!CheckConfig(npp_)) { + if (!o3d::CheckConfig(npp_)) { renderer_init_status_ = o3d::Renderer::GPU_NOT_UP_TO_SPEC; } else { renderer_ = o3d::Renderer::CreateDefaultRenderer(&service_locator_); @@ -279,10 +279,10 @@ void PluginObject::MacEventReceived() { CFRelease(previousTime); } if (!mac_cocoa_window_) { - mac_cocoa_window_ = SafariBrowserWindowForWindowRef(mac_window_); + mac_cocoa_window_ = o3d::SafariBrowserWindowForWindowRef(mac_window_); } mac_window_selected_tab_ = - SelectedTabForSafariBrowserWindow(mac_cocoa_window_); + o3d::SelectedTabForSafariBrowserWindow(mac_cocoa_window_); } // Returns the time elapsed since the MacEventReceived function was last called. @@ -306,10 +306,10 @@ bool PluginObject::DetectTabHiding() { return false; if (!mac_cocoa_window_) { - mac_cocoa_window_ = SafariBrowserWindowForWindowRef(mac_window_); + mac_cocoa_window_ = o3d::SafariBrowserWindowForWindowRef(mac_window_); } - return SelectedTabForSafariBrowserWindow(mac_cocoa_window_) != + return o3d::SelectedTabForSafariBrowserWindow(mac_cocoa_window_) != mac_window_selected_tab_; } @@ -550,8 +550,8 @@ static bool PluginGetProperty(NPObject *header, NPIdentifier name, if (name == property_ids[PROP_GPU_CONFIG]) { // Gets the GPU config (VendorID, DeviceID, name) as a string. // NOTE: this should probably be removed before we ship. - GPUDevice device; - bool result = GetGPUDevice(npp, &device); + o3d::GPUDevice device; + bool result = o3d::GetGPUDevice(npp, &device); if (!result) return false; std::string return_value = std::string("VendorID = 0x"); char id_text[9]; |