diff options
author | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 18:35:53 +0000 |
---|---|---|
committer | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 18:35:53 +0000 |
commit | 9bcc6daa3287203a358e782d2e63f53ac18102e1 (patch) | |
tree | b9fcca846890a50e387175def5c979dcc4c4bb4f /o3d/plugin/linux | |
parent | 1279ace64f4bdd009ec06528cf6c94e11b48bf69 (diff) | |
download | chromium_src-9bcc6daa3287203a358e782d2e63f53ac18102e1.zip chromium_src-9bcc6daa3287203a358e782d2e63f53ac18102e1.tar.gz chromium_src-9bcc6daa3287203a358e782d2e63f53ac18102e1.tar.bz2 |
In preparation for becoming an internal plugin in chrome I did these things:
- Move declarations in the global namespace into the o3d namespace to avoid conflicts with Chrome.
- Ifdef out code that we do not want to run as an internal plugin (like breakpad, DllMain, etc)
- Prevent NP_Initialize, etc from being exported as an internal plugin.
Unfortunately I had to move functions around to group them by namespace so the diffs look like there is more change than there actually is.
Review URL: http://codereview.chromium.org/149130
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20285 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/plugin/linux')
-rw-r--r-- | o3d/plugin/linux/main_linux.cc | 386 |
1 files changed, 200 insertions, 186 deletions
diff --git a/o3d/plugin/linux/main_linux.cc b/o3d/plugin/linux/main_linux.cc index d381ae0..a0f1095 100644 --- a/o3d/plugin/linux/main_linux.cc +++ b/o3d/plugin/linux/main_linux.cc @@ -56,8 +56,6 @@ scoped_ptr<base::AtExitManager> g_at_exit_manager; bool g_xembed_support = false; -} // end anonymous namespace - static void DrawPlugin(PluginObject *obj) { // Limit drawing to no more than once every timer tick. if (!obj->draw_) return; @@ -65,10 +63,6 @@ static void DrawPlugin(PluginObject *obj) { obj->draw_ = false; } -void RenderOnDemandCallbackHandler::Run() { - DrawPlugin(obj_); -} - // Xt support functions void LinuxTimer(XtPointer data, XtIntervalId* id) { @@ -576,21 +570,6 @@ static gboolean GtkTimeoutCallback(gpointer user_data) { return TRUE; } -bool PluginObject::GetDisplayMode(int id, o3d::DisplayMode *mode) { - return false; -} - -// TODO: Where should this really live? It's platform-specific, but in -// PluginObject, which mainly lives in cross/o3d_glue.h+cc. -bool PluginObject::RequestFullscreenDisplay() { - // TODO: Unimplemented. - return false; -} - -void PluginObject::CancelFullscreenDisplay() { - // TODO: Unimplemented. -} - NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) { switch (variable) { case NPPVpluginNeedsXEmbed: @@ -602,193 +581,228 @@ NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) { return NPERR_NO_ERROR; } -extern "C" { - NPError InitializePlugin() { - if (!o3d::SetupOutOfMemoryHandler()) - return NPERR_MODULE_LOAD_FAILED_ERROR; - - // Initialize the AtExitManager so that base singletons can be - // destroyed properly. - g_at_exit_manager.reset(new base::AtExitManager()); - - CommandLine::Init(0, NULL); - InitLogging("debug.log", - logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, - logging::DONT_LOCK_LOG_FILE, - logging::APPEND_TO_OLD_LOG_FILE); - - DLOG(INFO) << "NP_Initialize"; - - // Check for XEmbed support in the browser. - NPBool xembed_support = 0; - NPError err = NPN_GetValue(NULL, NPNVSupportsXEmbedBool, &xembed_support); - if (err != NPERR_NO_ERROR) +NPError InitializePlugin() { + if (!o3d::SetupOutOfMemoryHandler()) + return NPERR_MODULE_LOAD_FAILED_ERROR; + + // Initialize the AtExitManager so that base singletons can be + // destroyed properly. + g_at_exit_manager.reset(new base::AtExitManager()); + + CommandLine::Init(0, NULL); + InitLogging("debug.log", + logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, + logging::DONT_LOCK_LOG_FILE, + logging::APPEND_TO_OLD_LOG_FILE); + + DLOG(INFO) << "NP_Initialize"; + + // Check for XEmbed support in the browser. + NPBool xembed_support = 0; + NPError err = NPN_GetValue(NULL, NPNVSupportsXEmbedBool, &xembed_support); + if (err != NPERR_NO_ERROR) + xembed_support = 0; + + if (xembed_support) { + // Check for Gtk2 toolkit support in the browser. + NPNToolkitType toolkit = static_cast<NPNToolkitType>(0); + err = NPN_GetValue(NULL, NPNVToolkit, &toolkit); + if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2) xembed_support = 0; + } + g_xembed_support = xembed_support != 0; - if (xembed_support) { - // Check for Gtk2 toolkit support in the browser. - NPNToolkitType toolkit = static_cast<NPNToolkitType>(0); - err = NPN_GetValue(NULL, NPNVToolkit, &toolkit); - if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2) - xembed_support = 0; - } - g_xembed_support = xembed_support != 0; + return NPERR_NO_ERROR; +} - return NPERR_NO_ERROR; - } +} // end anonymous namespace - NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs, - NPPluginFuncs *pluginFuncs) { - NPError retval = InitializeNPNApi(browserFuncs); - if (retval != NPERR_NO_ERROR) return retval; - NP_GetEntryPoints(pluginFuncs); - return InitializePlugin(); - } +#if defined(O3D_INTERNAL_PLUGIN) +namespace o3d { +#else +extern "C" { +#endif - NPError OSCALL NP_Shutdown(void) { - HANDLE_CRASHES; - DLOG(INFO) << "NP_Shutdown"; +NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs, + NPPluginFuncs *pluginFuncs) { + NPError retval = InitializeNPNApi(browserFuncs); + if (retval != NPERR_NO_ERROR) return retval; + NP_GetEntryPoints(pluginFuncs); + return InitializePlugin(); +} - CommandLine::Terminate(); +NPError OSCALL NP_Shutdown(void) { + HANDLE_CRASHES; + DLOG(INFO) << "NP_Shutdown"; - // Force all base singletons to be destroyed. - g_at_exit_manager.reset(NULL); + CommandLine::Terminate(); - return NPERR_NO_ERROR; - } + // Force all base singletons to be destroyed. + g_at_exit_manager.reset(NULL); - NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, - char *argn[], char *argv[], NPSavedData *saved) { - HANDLE_CRASHES; + return NPERR_NO_ERROR; +} - PluginObject* pluginObject = glue::_o3d::PluginObject::Create( - instance); - instance->pdata = pluginObject; - glue::_o3d::InitializeGlue(instance); - pluginObject->Init(argc, argn, argv); +} // namespace o3d / extern "C" - // Get the metrics for the system setup - GetUserConfigMetrics(); - return NPERR_NO_ERROR; - } +namespace o3d { - NPError NPP_Destroy(NPP instance, NPSavedData **save) { - HANDLE_CRASHES; - PluginObject *obj = static_cast<PluginObject*>(instance->pdata); - if (obj) { - if (obj->xt_widget_) { - // NOTE: This crashes. Not sure why, possibly the widget has - // already been destroyed, but we haven't received a SetWindow(NULL). - // XtRemoveEventHandler(obj->xt_widget_, ExposureMask, False, - // LinuxExposeHandler, obj); - obj->xt_widget_ = NULL; - } - if (obj->xt_interval_) { - XtRemoveTimeOut(obj->xt_interval_); - obj->xt_interval_ = 0; - } - if (obj->timeout_id_) { - g_source_remove(obj->timeout_id_); - obj->timeout_id_ = 0; - } - if (obj->gtk_container_) { - gtk_widget_destroy(obj->gtk_container_); - gtk_widget_unref(obj->gtk_container_); - obj->gtk_container_ = NULL; - } - obj->window_ = 0; - obj->display_ = NULL; +void RenderOnDemandCallbackHandler::Run() { + DrawPlugin(obj_); +} + +NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, + char *argn[], char *argv[], NPSavedData *saved) { + HANDLE_CRASHES; + + PluginObject* pluginObject = glue::_o3d::PluginObject::Create( + instance); + instance->pdata = pluginObject; + glue::_o3d::InitializeGlue(instance); + pluginObject->Init(argc, argn, argv); - obj->TearDown(); - NPN_ReleaseObject(obj); - instance->pdata = NULL; + // Get the metrics for the system setup + GetUserConfigMetrics(); + return NPERR_NO_ERROR; +} + +NPError NPP_Destroy(NPP instance, NPSavedData **save) { + HANDLE_CRASHES; + PluginObject *obj = static_cast<PluginObject*>(instance->pdata); + if (obj) { + if (obj->xt_widget_) { + // NOTE: This crashes. Not sure why, possibly the widget has + // already been destroyed, but we haven't received a SetWindow(NULL). + // XtRemoveEventHandler(obj->xt_widget_, ExposureMask, False, + // LinuxExposeHandler, obj); + obj->xt_widget_ = NULL; + } + if (obj->xt_interval_) { + XtRemoveTimeOut(obj->xt_interval_); + obj->xt_interval_ = 0; + } + if (obj->timeout_id_) { + g_source_remove(obj->timeout_id_); + obj->timeout_id_ = 0; } + if (obj->gtk_container_) { + gtk_widget_destroy(obj->gtk_container_); + gtk_widget_unref(obj->gtk_container_); + obj->gtk_container_ = NULL; + } + obj->window_ = 0; + obj->display_ = NULL; - return NPERR_NO_ERROR; + obj->TearDown(); + NPN_ReleaseObject(obj); + instance->pdata = NULL; } + return NPERR_NO_ERROR; +} - NPError NPP_SetWindow(NPP instance, NPWindow *window) { - HANDLE_CRASHES; - PluginObject *obj = static_cast<PluginObject*>(instance->pdata); - - NPSetWindowCallbackStruct *cb_struct = - static_cast<NPSetWindowCallbackStruct *>(window->ws_info); - Window xwindow = reinterpret_cast<Window>(window->window); - if (xwindow != obj->window_) { - Display *display = cb_struct->display; - Window drawable = xwindow; - if (g_xembed_support) { - // We asked for a XEmbed plugin, the xwindow is a GtkSocket, we create - // a GtkPlug to go into it. - obj->gtk_container_ = gtk_plug_new(xwindow); - gtk_widget_set_double_buffered(obj->gtk_container_, FALSE); - gtk_widget_add_events(obj->gtk_container_, - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_SCROLL_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_POINTER_MOTION_MASK | - GDK_EXPOSURE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); - g_signal_connect(G_OBJECT(obj->gtk_container_), "event", - G_CALLBACK(GtkEventCallback), obj); - gtk_widget_show(obj->gtk_container_); - drawable = GDK_WINDOW_XID(obj->gtk_container_->window); - obj->timeout_id_ = g_timeout_add(10, GtkTimeoutCallback, obj); - } else { - // No XEmbed support, the xwindow is a Xt Widget. - Widget widget = XtWindowToWidget(display, xwindow); - if (!widget) { - DLOG(ERROR) << "window is not a Widget"; - return NPERR_MODULE_LOAD_FAILED_ERROR; - } - obj->xt_widget_ = widget; - XtAddEventHandler(widget, ExposureMask, 0, LinuxExposeHandler, obj); - XtAddEventHandler(widget, KeyPressMask|KeyReleaseMask, 0, - LinuxKeyHandler, obj); - XtAddEventHandler(widget, ButtonPressMask|ButtonReleaseMask, 0, - LinuxMouseButtonHandler, obj); - XtAddEventHandler(widget, PointerMotionMask, 0, - LinuxMouseMoveHandler, obj); - XtAddEventHandler(widget, EnterWindowMask|LeaveWindowMask, 0, - LinuxEnterLeaveHandler, obj); - obj->xt_app_context_ = XtWidgetToApplicationContext(widget); - obj->xt_interval_ = - XtAppAddTimeOut(obj->xt_app_context_, 10, LinuxTimer, obj); - } - // Create and assign the graphics context. - o3d::DisplayWindowLinux default_display; - default_display.set_display(display); - default_display.set_window(drawable); - - obj->CreateRenderer(default_display); - obj->client()->Init(); - obj->client()->SetRenderOnDemandCallback( - new RenderOnDemandCallbackHandler(obj)); - obj->display_ = display; - obj->window_ = xwindow; +NPError NPP_SetWindow(NPP instance, NPWindow *window) { + HANDLE_CRASHES; + PluginObject *obj = static_cast<PluginObject*>(instance->pdata); + + NPSetWindowCallbackStruct *cb_struct = + static_cast<NPSetWindowCallbackStruct *>(window->ws_info); + Window xwindow = reinterpret_cast<Window>(window->window); + if (xwindow != obj->window_) { + Display *display = cb_struct->display; + Window drawable = xwindow; + if (g_xembed_support) { + // We asked for a XEmbed plugin, the xwindow is a GtkSocket, we create + // a GtkPlug to go into it. + obj->gtk_container_ = gtk_plug_new(xwindow); + gtk_widget_set_double_buffered(obj->gtk_container_, FALSE); + gtk_widget_add_events(obj->gtk_container_, + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_SCROLL_MASK | + GDK_KEY_PRESS_MASK | + GDK_KEY_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | + GDK_EXPOSURE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); + g_signal_connect(G_OBJECT(obj->gtk_container_), "event", + G_CALLBACK(GtkEventCallback), obj); + gtk_widget_show(obj->gtk_container_); + drawable = GDK_WINDOW_XID(obj->gtk_container_->window); + obj->timeout_id_ = g_timeout_add(10, GtkTimeoutCallback, obj); + } else { + // No XEmbed support, the xwindow is a Xt Widget. + Widget widget = XtWindowToWidget(display, xwindow); + if (!widget) { + DLOG(ERROR) << "window is not a Widget"; + return NPERR_MODULE_LOAD_FAILED_ERROR; + } + obj->xt_widget_ = widget; + XtAddEventHandler(widget, ExposureMask, 0, LinuxExposeHandler, obj); + XtAddEventHandler(widget, KeyPressMask|KeyReleaseMask, 0, + LinuxKeyHandler, obj); + XtAddEventHandler(widget, ButtonPressMask|ButtonReleaseMask, 0, + LinuxMouseButtonHandler, obj); + XtAddEventHandler(widget, PointerMotionMask, 0, + LinuxMouseMoveHandler, obj); + XtAddEventHandler(widget, EnterWindowMask|LeaveWindowMask, 0, + LinuxEnterLeaveHandler, obj); + obj->xt_app_context_ = XtWidgetToApplicationContext(widget); + obj->xt_interval_ = + XtAppAddTimeOut(obj->xt_app_context_, 10, LinuxTimer, obj); } - obj->Resize(window->width, window->height); - return NPERR_NO_ERROR; + // Create and assign the graphics context. + o3d::DisplayWindowLinux default_display; + default_display.set_display(display); + default_display.set_window(drawable); + + obj->CreateRenderer(default_display); + obj->client()->Init(); + obj->client()->SetRenderOnDemandCallback( + new RenderOnDemandCallbackHandler(obj)); + obj->display_ = display; + obj->window_ = xwindow; } + obj->Resize(window->width, window->height); - // Called when the browser has finished attempting to stream data to - // a file as requested. If fname == NULL the attempt was not successful. - void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) { - HANDLE_CRASHES; - PluginObject *obj = static_cast<PluginObject*>(instance->pdata); - StreamManager *stream_manager = obj->stream_manager(); + return NPERR_NO_ERROR; +} - stream_manager->SetStreamFile(stream, fname); - } +// Called when the browser has finished attempting to stream data to +// a file as requested. If fname == NULL the attempt was not successful. +void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) { + HANDLE_CRASHES; + PluginObject *obj = static_cast<PluginObject*>(instance->pdata); + StreamManager *stream_manager = obj->stream_manager(); - int16 NPP_HandleEvent(NPP instance, void *event) { - HANDLE_CRASHES; - return 0; - } -}; // end extern "C" + stream_manager->SetStreamFile(stream, fname); +} + +int16 NPP_HandleEvent(NPP instance, void *event) { + HANDLE_CRASHES; + return 0; +} +} // namespace o3d + +namespace glue { +namespace _o3d { + +bool PluginObject::GetDisplayMode(int id, o3d::DisplayMode *mode) { + return false; +} + +// TODO: Where should this really live? It's platform-specific, but in +// PluginObject, which mainly lives in cross/o3d_glue.h+cc. +bool PluginObject::RequestFullscreenDisplay() { + // TODO: Unimplemented. + return false; +} + +void PluginObject::CancelFullscreenDisplay() { + // TODO: Unimplemented. +} +} // namespace _o3d +} // namespace glue |