summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authortschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-17 00:24:05 +0000
committertschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-17 00:24:05 +0000
commit3c3bb496c0271b02a370f4a2d3eef038ca3b9c55 (patch)
tree8389bce96981431b23339d23c881a4087eb3de35 /o3d
parent00ce5197adb6ce412b047fa2317363fcc37e6390 (diff)
downloadchromium_src-3c3bb496c0271b02a370f4a2d3eef038ca3b9c55.zip
chromium_src-3c3bb496c0271b02a370f4a2d3eef038ca3b9c55.tar.gz
chromium_src-3c3bb496c0271b02a370f4a2d3eef038ca3b9c55.tar.bz2
- Check for a NULL PluginObject at all NPAPI entry points. This fixes a crash in Chrome where the browser foolishly calls NPP_SetWindow with instance->pdata == NULL.
- Factor out obscene amounts of redundancy from main_<platform>.(cc|mm) into main.cc. This makes no change to the functionality, except that NP_Initialize on Linux now has HANDLE_CRASHES whereas before it did not. TEST=built on Linux, Mac, and Windows; installed and loaded O3D on each platform and made sure it worked; repeatedly loaded on Mac & Win in Chrome 8.0.552.200 and verified no crashes; inspected "svn diff" output manually and verified that the code and order of execution of that code is unchanded for each platform BUG=none Review URL: http://codereview.chromium.org/4957002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/plugin/cross/main.cc262
-rw-r--r--o3d/plugin/cross/main.h61
-rw-r--r--o3d/plugin/cross/plugin_logging.h1
-rw-r--r--o3d/plugin/linux/main_linux.cc198
-rw-r--r--o3d/plugin/mac/main_mac.mm195
-rw-r--r--o3d/plugin/win/main_win.cc198
6 files changed, 453 insertions, 462 deletions
diff --git a/o3d/plugin/cross/main.cc b/o3d/plugin/cross/main.cc
index e552bce..575d524 100644
--- a/o3d/plugin/cross/main.cc
+++ b/o3d/plugin/cross/main.cc
@@ -32,21 +32,50 @@
#include "plugin/cross/main.h"
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "plugin/cross/config.h"
+#include "plugin/cross/out_of_memory.h"
+#include "plugin/cross/whitelist.h"
+#ifdef OS_WIN
+#include "breakpad/win/bluescreen_detector.h"
+#endif
+
using glue::_o3d::PluginObject;
using glue::StreamManager;
#if !defined(O3D_INTERNAL_PLUGIN)
-int BreakpadEnabler::scope_count_ = 0;
+#ifdef OS_WIN
+#define O3D_DEBUG_LOG_FILENAME L"debug.log"
+#else
+#define O3D_DEBUG_LOG_FILENAME "debug.log"
+#endif
+
+#if defined(OS_WIN) || defined(OS_MACOSX)
+o3d::PluginLogging *g_logger = NULL;
+static bool g_logging_initialized = false;
+#ifdef OS_WIN
+static o3d::BluescreenDetector *g_bluescreen_detector = NULL;
+#endif // OS_WIN
+#endif // OS_WIN || OS_MACOSX
-// Used for breakpad crash handling
-ExceptionManager *g_exception_manager = NULL;
+// We would normally make this a stack variable in main(), but in a
+// plugin, that's not possible, so we make it a global. When the DLL is loaded
+// this it gets constructed and when it is unlooaded it is destructed. Note
+// that this cannot be done in NP_Initialize and NP_Shutdown because those
+// calls do not necessarily signify the DLL being loaded and unloaded. If the
+// DLL is not unloaded then the values of global variables are preserved.
+static base::AtExitManager g_at_exit_manager;
+
+int BreakpadEnabler::scope_count_ = 0;
#endif // O3D_INTERNAL_PLUGIN
namespace o3d {
-NPError NP_GetValue(void *instance, NPPVariable variable, void *value) {
+NPError NP_GetValue(NPPVariable variable, void *value) {
switch (variable) {
case NPPVpluginNameString:
*static_cast<char **>(value) = const_cast<char*>(O3D_PLUGIN_NAME);
@@ -61,10 +90,27 @@ NPError NP_GetValue(void *instance, NPPVariable variable, void *value) {
return NPERR_NO_ERROR;
}
-NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream,
- NPBool seekable, uint16 *stype) {
+int16 NPP_HandleEvent(NPP instance, void *event) {
HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return 0;
+ }
+
+ return PlatformNPPHandleEvent(instance, obj, event);
+}
+
+NPError NPP_NewStream(NPP instance,
+ NPMIMEType type,
+ NPStream *stream,
+ NPBool seekable,
+ uint16 *stype) {
+ HANDLE_CRASHES;
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return NPERR_INVALID_PARAM;
+ }
+
StreamManager *stream_manager = obj->stream_manager();
if (stream_manager->NewStream(stream, stype)) {
return NPERR_NO_ERROR;
@@ -76,7 +122,11 @@ NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream,
NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) {
HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return NPERR_NO_ERROR;
+ }
+
StreamManager *stream_manager = obj->stream_manager();
if (stream_manager->DestroyStream(stream, reason)) {
return NPERR_NO_ERROR;
@@ -88,7 +138,11 @@ NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) {
int32 NPP_WriteReady(NPP instance, NPStream *stream) {
HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return 0;
+ }
+
StreamManager *stream_manager = obj->stream_manager();
return stream_manager->WriteReady(stream);
}
@@ -96,7 +150,11 @@ int32 NPP_WriteReady(NPP instance, NPStream *stream) {
int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len,
void *buffer) {
HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return 0;
+ }
+
StreamManager *stream_manager = obj->stream_manager();
return stream_manager->Write(stream, offset, len, buffer);
}
@@ -108,20 +166,25 @@ void NPP_Print(NPP instance, NPPrint *platformPrint) {
void NPP_URLNotify(NPP instance, const char *url, NPReason reason,
void *notifyData) {
HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
- // Make sure the plugin hasn't been destroyed already.
- if (obj) {
- StreamManager *stream_manager = obj->stream_manager();
- stream_manager->URLNotify(url, reason, notifyData);
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return;
}
+
+ StreamManager *stream_manager = obj->stream_manager();
+ stream_manager->URLNotify(url, reason, notifyData);
}
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
HANDLE_CRASHES;
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return NPERR_INVALID_PARAM;
+ }
+
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);
@@ -130,19 +193,98 @@ NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
break;
}
default: {
- NPError ret = PlatformNPPGetValue(instance, variable, value);
+ NPError ret = PlatformNPPGetValue(obj, variable, value);
if (ret == NPERR_INVALID_PARAM)
- ret = o3d::NP_GetValue(instance, variable, value);
+ ret = o3d::NP_GetValue(variable, value);
return ret;
}
}
return NPERR_NO_ERROR;
}
+NPError NPP_New(NPMIMEType pluginType,
+ NPP instance,
+ uint16 mode,
+ int16 argc,
+ char *argn[],
+ char *argv[],
+ NPSavedData *saved) {
+ HANDLE_CRASHES;
+
+#if !defined(O3D_INTERNAL_PLUGIN) && (defined(OS_WIN) || defined(OS_MACOSX))
+ // TODO(tschmelcher): Support this on Linux?
+ if (!g_logging_initialized) {
+ // Get user config metrics. These won't be stored though unless the user
+ // opts-in for usagestats logging
+ GetUserAgentMetrics(instance);
+ GetUserConfigMetrics();
+ // Create usage stats logs object
+ g_logger = o3d::PluginLogging::InitializeUsageStatsLogging();
+#ifdef OS_WIN
+ if (g_logger) {
+ // Setup blue-screen detection
+ g_bluescreen_detector = new o3d::BluescreenDetector();
+ g_bluescreen_detector->Start();
+ }
+#endif
+ g_logging_initialized = true;
+ }
+#endif
+
+ if (!IsDomainAuthorized(instance)) {
+ return NPERR_INVALID_URL;
+ }
+
+ PluginObject *obj = glue::_o3d::PluginObject::Create(instance);
+ instance->pdata = obj;
+ glue::_o3d::InitializeGlue(instance);
+ obj->Init(argc, argn, argv);
+ return PlatformNPPNew(instance, obj);
+}
+
+NPError NPP_Destroy(NPP instance, NPSavedData **save) {
+ HANDLE_CRASHES;
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return NPERR_NO_ERROR;
+ }
+
+ NPError err = PlatformNPPDestroy(instance, obj);
+
+ NPN_ReleaseObject(obj);
+ instance->pdata = NULL;
+
+ return err;
+}
+
NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
HANDLE_CRASHES;
return NPERR_GENERIC_ERROR;
}
+
+NPError NPP_SetWindow(NPP instance, NPWindow* window) {
+ HANDLE_CRASHES;
+ PluginObject *obj = static_cast<PluginObject *>(instance->pdata);
+ if (!obj) {
+ return NPERR_NO_ERROR;
+ }
+
+ return PlatformNPPSetWindow(instance, obj, window);
+}
+
+// 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);
+ if (!obj) {
+ return;
+ }
+
+ StreamManager *stream_manager = obj->stream_manager();
+ PlatformNPPStreamAsFile(stream_manager, stream, fname);
+}
+
} // namespace o3d
#if defined(O3D_INTERNAL_PLUGIN)
@@ -151,6 +293,88 @@ namespace o3d {
extern "C" {
#endif
+NPError EXPORT_SYMBOL OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs
+#ifdef OS_LINUX
+ ,
+ NPPluginFuncs *pluginFuncs
+#endif
+ ) {
+ HANDLE_CRASHES;
+ NPError err = InitializeNPNApi(browserFuncs);
+ if (err != NPERR_NO_ERROR) {
+ return err;
+ }
+
+#ifdef OS_LINUX
+ NP_GetEntryPoints(pluginFuncs);
+#endif // OS_LINUX
+
+#if !defined(O3D_INTERNAL_PLUGIN)
+ if (!o3d::SetupOutOfMemoryHandler())
+ return NPERR_MODULE_LOAD_FAILED_ERROR;
+#endif // O3D_INTERNAL_PLUGIN
+
+ err = o3d::PlatformPreNPInitialize();
+ if (err != NPERR_NO_ERROR) {
+ return err;
+ }
+
+#if !defined(O3D_INTERNAL_PLUGIN)
+ // Turn on the logging.
+ CommandLine::Init(0, NULL);
+
+ FilePath log;
+ file_util::GetTempDir(&log);
+ log.Append(O3D_DEBUG_LOG_FILENAME);
+
+ InitLogging(log.value().c_str(),
+ logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
+ logging::DONT_LOCK_LOG_FILE,
+ logging::APPEND_TO_OLD_LOG_FILE);
+#endif // O3D_INTERNAL_PLUGIN
+
+ DLOG(INFO) << "NP_Initialize";
+
+ return o3d::PlatformPostNPInitialize();
+}
+
+NPError EXPORT_SYMBOL OSCALL NP_Shutdown(void) {
+ HANDLE_CRASHES;
+ DLOG(INFO) << "NP_Shutdown";
+
+ NPError err = o3d::PlatformPreNPShutdown();
+ if (err != NPERR_NO_ERROR) {
+ return err;
+ }
+
+#if !defined(O3D_INTERNAL_PLUGIN)
+#if defined(OS_WIN) || defined(OS_MACOSX)
+ if (g_logger) {
+ // Do a last sweep to aggregate metrics before we shut down
+ g_logger->ProcessMetrics(true, false, false);
+ delete g_logger;
+ g_logger = NULL;
+ g_logging_initialized = false;
+ stats_report::g_global_metrics.Uninitialize();
+ }
+#endif // OS_WIN || OS_MACOSX
+
+ CommandLine::Reset();
+
+#ifdef OS_WIN
+ // Strictly speaking, on windows, it's not really necessary to call
+ // Stop(), but we do so for completeness
+ if (g_bluescreen_detector) {
+ g_bluescreen_detector->Stop();
+ delete g_bluescreen_detector;
+ g_bluescreen_detector = NULL;
+ }
+#endif // OS_WIN
+#endif // O3D_INTERNAL_PLUGIN
+
+ return o3d::PlatformPostNPShutdown();
+}
+
NPError EXPORT_SYMBOL OSCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) {
HANDLE_CRASHES;
pluginFuncs->version = 11;
@@ -182,7 +406,7 @@ char* NP_GetMIMEDescription(void) {
extern "C" {
NPError EXPORT_SYMBOL NP_GetValue(void *instance, NPPVariable variable,
void *value) {
- return o3d::NP_GetValue(instance, variable, value);
+ return o3d::NP_GetValue(variable, value);
}
}
#endif
diff --git a/o3d/plugin/cross/main.h b/o3d/plugin/cross/main.h
index f8c8512..d54fed2 100644
--- a/o3d/plugin/cross/main.h
+++ b/o3d/plugin/cross/main.h
@@ -37,26 +37,15 @@
#ifndef O3D_PLUGIN_CROSS_MAIN_H_
#define O3D_PLUGIN_CROSS_MAIN_H_
-#include "core/cross/renderer_platform.h"
-
#include <npfunctions.h>
-#include <stdio.h>
-
-#include <fstream>
-#include <iostream>
-#include "core/cross/renderer.h"
#include "plugin/cross/o3d_glue.h"
-#include "plugin/cross/config.h"
+#include "plugin/cross/plugin_logging.h"
#include "plugin/cross/stream_manager.h"
#include "third_party/nixysa/static_glue/npapi/common.h"
#include "third_party/nixysa/static_glue/npapi/npn_api.h"
-#if !defined(O3D_INTERNAL_PLUGIN)
-#include "breakpad/win/exception_handler_win32.h"
-#endif // O3D_INTERNAL_PLUGIN
-
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) && !defined(O3D_INTERNAL_PLUGIN)
#define EXPORT_SYMBOL __attribute__((visibility ("default")))
#else
#define EXPORT_SYMBOL
@@ -66,7 +55,9 @@
#define HANDLE_CRASHES void(0)
#else // O3D_INTERNAL_PLUGIN
-extern ExceptionManager *g_exception_manager;
+#if defined(OS_WIN) || defined(OS_MACOSX)
+extern o3d::PluginLogging *g_logger;
+#endif
// BreakpadEnabler is a simple class to keep track of whether or not
// we're executing code that we want to handle crashes for
@@ -75,7 +66,7 @@ extern ExceptionManager *g_exception_manager;
// Create a stack-based instance at the start of each function
// where crash handling is desired.
-#define HANDLE_CRASHES BreakpadEnabler enabler
+#define HANDLE_CRASHES BreakpadEnabler enabler
class BreakpadEnabler {
public:
@@ -90,7 +81,7 @@ class BreakpadEnabler {
static bool IsEnabled() { return scope_count_ > 0; }
private:
- static int scope_count_;
+ static int scope_count_;
};
#endif // O3D_INTERNAL_PLUGIN
@@ -100,13 +91,21 @@ namespace o3d {
#else
extern "C" {
#endif
- NPError OSCALL NP_Shutdown(void);
- NPError OSCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs);
+ NPError EXPORT_SYMBOL OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs
+#ifdef OS_LINUX
+ ,
+ NPPluginFuncs *pluginFuncs
+#endif
+ );
+
+ NPError EXPORT_SYMBOL OSCALL NP_Shutdown(void);
+ NPError EXPORT_SYMBOL OSCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs);
}
namespace o3d {
-void WriteLogString(const char* text, int length);
+// Plugin entry points, implemented in main.cc.
+
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);
@@ -125,7 +124,6 @@ NPError NPP_NewStream(NPP instance,
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);
@@ -145,6 +143,29 @@ void NPP_URLNotify(NPP instance,
const char *url,
NPReason reason,
void *notifyData);
+
+// Platform-specific helpers, implemented in main_<platform>.(cc|mm)
+
+NPError PlatformPreNPInitialize();
+NPError PlatformPostNPInitialize();
+NPError PlatformPreNPShutdown();
+NPError PlatformPostNPShutdown();
+
+NPError PlatformNPPDestroy(NPP instance, glue::_o3d::PluginObject *obj);
+NPError PlatformNPPGetValue(glue::_o3d::PluginObject *obj,
+ NPPVariable variable,
+ void *value);
+int16 PlatformNPPHandleEvent(NPP instance,
+ glue::_o3d::PluginObject *obj,
+ void *event);
+NPError PlatformNPPNew(NPP instance, glue::_o3d::PluginObject *obj);
+NPError PlatformNPPSetWindow(NPP instance,
+ glue::_o3d::PluginObject *obj,
+ NPWindow *window);
+void PlatformNPPStreamAsFile(glue::StreamManager *stream_manager,
+ NPStream *stream,
+ const char *fname);
+
}; // namespace o3d
#endif // O3D_PLUGIN_CROSS_MAIN_H_
diff --git a/o3d/plugin/cross/plugin_logging.h b/o3d/plugin/cross/plugin_logging.h
index dcdff44..7997cb4 100644
--- a/o3d/plugin/cross/plugin_logging.h
+++ b/o3d/plugin/cross/plugin_logging.h
@@ -38,6 +38,7 @@
#ifndef O3D_PLUGIN_CROSS_PLUGIN_LOGGING_H_
#define O3D_PLUGIN_CROSS_PLUGIN_LOGGING_H_
+#include "statsreport/metrics.h"
#include "statsreport/common/highres_timer.h"
#include "base/scoped_ptr.h"
#include "base/basictypes.h"
diff --git a/o3d/plugin/linux/main_linux.cc b/o3d/plugin/linux/main_linux.cc
index 6714074..846acc6 100644
--- a/o3d/plugin/linux/main_linux.cc
+++ b/o3d/plugin/linux/main_linux.cc
@@ -33,20 +33,20 @@
// This file implements the platform specific parts of the plugin for
// the Linux platform.
+#include "plugin/cross/main.h"
+
#include <X11/keysym.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
-#include "base/at_exit.h"
-#include "base/command_line.h"
-#include "base/file_util.h"
+
#include "base/logging.h"
-#include "base/scoped_ptr.h"
#include "base/third_party/nspr/prtypes.h"
-#include "o3d/breakpad/linux/breakpad.h"
-#include "plugin/cross/main.h"
-#include "plugin/cross/out_of_memory.h"
-#include "plugin/cross/whitelist.h"
+#include "core/cross/event.h"
+#include "core/linux/display_window_linux.h"
#include "plugin/linux/envvars.h"
+#if !defined(O3D_INTERNAL_PLUGIN)
+#include "breakpad/linux/breakpad.h"
+#endif
using glue::_o3d::PluginObject;
using glue::StreamManager;
@@ -54,20 +54,15 @@ using o3d::DisplayWindowLinux;
using o3d::Event;
namespace {
-// We would normally make this a stack variable in main(), but in a
-// plugin, that's not possible, so we make it a global. When the DLL is loaded
-// this it gets constructed and when it is unlooaded it is destructed. Note
-// that this cannot be done in NP_Initialize and NP_Shutdown because those
-// calls do not necessarily signify the DLL being loaded and unloaded. If the
-// DLL is not unloaded then the values of global variables are preserved.
-base::AtExitManager g_at_exit_manager;
bool g_xembed_support = false;
+#if !defined(O3D_INTERNAL_PLUGIN)
o3d::Breakpad g_breakpad;
+#endif
#ifdef O3D_PLUGIN_ENV_VARS_FILE
-static const char *kEnvVarsFilePath = O3D_PLUGIN_ENV_VARS_FILE;
+static const char kEnvVarsFilePath[] = O3D_PLUGIN_ENV_VARS_FILE;
#endif
static void DrawPlugin(PluginObject *obj) {
@@ -625,27 +620,20 @@ static gboolean GtkTimeoutCallback(gpointer user_data) {
return TRUE;
}
-NPError InitializePlugin() {
- if (!o3d::SetupOutOfMemoryHandler())
- return NPERR_MODULE_LOAD_FAILED_ERROR;
+} // end anonymous namespace
+
+namespace o3d {
+NPError PlatformPreNPInitialize() {
+#if !defined(O3D_INTERNAL_PLUGIN)
// Setup breakpad
g_breakpad.Initialize();
g_breakpad.set_version(O3D_PLUGIN_VERSION);
+#endif
+ return NPERR_NO_ERROR;
+}
- CommandLine::Init(0, NULL);
-
- FilePath log;
- file_util::GetTempDir(&log);
- log = log.Append("debug.log");
-
- InitLogging(log.value().c_str(),
- logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
- logging::DONT_LOCK_LOG_FILE,
- logging::APPEND_TO_OLD_LOG_FILE);
-
- DLOG(INFO) << "NP_Initialize";
-
+NPError PlatformPostNPInitialize() {
#ifdef O3D_PLUGIN_ENV_VARS_FILE
// Before doing anything more, we first load our environment variables file.
// This file is a newline-delimited list of any system-specific environment
@@ -680,38 +668,21 @@ NPError InitializePlugin() {
return NPERR_NO_ERROR;
}
-} // end anonymous namespace
-
-#if defined(O3D_INTERNAL_PLUGIN)
-namespace o3d {
-#else
-extern "C" {
-#endif
-
-NPError EXPORT_SYMBOL OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs,
- NPPluginFuncs *pluginFuncs) {
- NPError retval = InitializeNPNApi(browserFuncs);
- if (retval != NPERR_NO_ERROR) return retval;
- NP_GetEntryPoints(pluginFuncs);
- return InitializePlugin();
+NPError PlatformPreNPShutdown() {
+ return NPERR_NO_ERROR;
}
-NPError EXPORT_SYMBOL OSCALL NP_Shutdown(void) {
- HANDLE_CRASHES;
- DLOG(INFO) << "NP_Shutdown";
-
- CommandLine::Reset();
-
+NPError PlatformPostNPShutdown() {
+#if !defined(O3D_INTERNAL_PLUGIN)
g_breakpad.Shutdown();
+#endif
return NPERR_NO_ERROR;
}
-} // namespace o3d / extern "C"
-
-namespace o3d {
-
-NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) {
+NPError PlatformNPPGetValue(PluginObject *obj,
+ NPPVariable variable,
+ void *value) {
switch (variable) {
case NPPVpluginNeedsXEmbed:
*static_cast<NPBool *>(value) = g_xembed_support;
@@ -722,73 +693,53 @@ NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) {
return NPERR_NO_ERROR;
}
-NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
- char *argn[], char *argv[], NPSavedData *saved) {
- HANDLE_CRASHES;
-
- if (!IsDomainAuthorized(instance)) {
- return NPERR_INVALID_URL;
- }
-
- PluginObject* pluginObject = glue::_o3d::PluginObject::Create(
- instance);
- instance->pdata = pluginObject;
- glue::_o3d::InitializeGlue(instance);
- pluginObject->Init(argc, argn, argv);
-
- // Get the metrics for the system setup
- GetUserConfigMetrics();
+NPError PlatformNPPNew(NPP instance, PluginObject *obj) {
return NPERR_NO_ERROR;
}
-NPError NPP_Destroy(NPP instance, NPSavedData **save) {
- HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
- if (obj) {
- obj->TearDown();
+NPError PlatformNPPDestroy(NPP instance, PluginObject *obj) {
+ // TODO(tschmelcher): Do we really have to do this before the other teardown
+ // below? If not then we can factor out the platform-specific TearDown()
+ // calls into NPP_Destroy() in main.cc.
+ obj->TearDown();
- 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_);
- obj->gtk_container_ = NULL;
- }
- if (obj->gtk_fullscreen_container_) {
- gtk_widget_destroy(obj->gtk_fullscreen_container_);
- obj->gtk_fullscreen_container_ = NULL;
- }
- if (obj->gdk_display_) {
- gdk_display_close(obj->gdk_display_);
- obj->gdk_display_ = NULL;
- }
- obj->gtk_event_source_ = NULL;
- obj->event_handler_id_ = 0;
- obj->window_ = 0;
- obj->drawable_ = 0;
-
- NPN_ReleaseObject(obj);
- instance->pdata = NULL;
+ 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_);
+ obj->gtk_container_ = NULL;
}
+ if (obj->gtk_fullscreen_container_) {
+ gtk_widget_destroy(obj->gtk_fullscreen_container_);
+ obj->gtk_fullscreen_container_ = NULL;
+ }
+ if (obj->gdk_display_) {
+ gdk_display_close(obj->gdk_display_);
+ obj->gdk_display_ = NULL;
+ }
+ obj->gtk_event_source_ = NULL;
+ obj->event_handler_id_ = 0;
+ obj->window_ = 0;
+ obj->drawable_ = 0;
return NPERR_NO_ERROR;
}
-NPError NPP_SetWindow(NPP instance, NPWindow *window) {
- HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
-
+NPError PlatformNPPSetWindow(NPP instance,
+ PluginObject *obj,
+ NPWindow *window) {
NPSetWindowCallbackStruct *cb_struct =
static_cast<NPSetWindowCallbackStruct *>(window->ws_info);
Window xwindow = reinterpret_cast<Window>(window->window);
@@ -854,22 +805,19 @@ NPError NPP_SetWindow(NPP instance, NPWindow *window) {
return NPERR_NO_ERROR;
}
-// 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();
-
+void PlatformNPPStreamAsFile(StreamManager *stream_manager,
+ NPStream *stream,
+ const char *fname) {
stream_manager->SetStreamFile(stream, fname);
}
-int16 NPP_HandleEvent(NPP instance, void *event) {
- HANDLE_CRASHES;
+int16 PlatformNPPHandleEvent(NPP instance, PluginObject *obj, void *event) {
return 0;
}
+
} // namespace o3d
+// TODO(tschmelcher): This stuff does not belong in this file.
namespace glue {
namespace _o3d {
diff --git a/o3d/plugin/mac/main_mac.mm b/o3d/plugin/mac/main_mac.mm
index 5d28f236..e3daf86 100644
--- a/o3d/plugin/mac/main_mac.mm
+++ b/o3d/plugin/mac/main_mac.mm
@@ -35,37 +35,22 @@
#include "plugin/cross/main.h"
-#include "base/at_exit.h"
-#include "base/command_line.h"
-#include "base/file_util.h"
-#include "base/logging.h"
-#include "base/scoped_ptr.h"
-
#import <Cocoa/Cocoa.h>
#include <Carbon/Carbon.h>
#include <OpenGL/OpenGL.h>
#include <AGL/agl.h>
#include <AGL/aglRenderers.h>
+#include "base/logging.h"
#include "core/cross/event.h"
-#include "statsreport/metrics.h"
+#include "core/mac/display_window_mac.h"
#include "plugin/cross/config.h"
-#include "plugin/cross/plugin_logging.h"
#include "plugin/cross/plugin_metrics.h"
-#include "plugin/cross/o3d_glue.h"
-#include "plugin/cross/out_of_memory.h"
-#include "plugin/cross/whitelist.h"
#include "plugin/mac/plugin_mac.h"
#include "plugin/mac/graphics_utils_mac.h"
#include "plugin/mac/fullscreen_window_mac.h"
#import "plugin/mac/o3d_layer.h"
-
-#if !defined(O3D_INTERNAL_PLUGIN)
-o3d::PluginLogging* g_logger = NULL;
-bool g_logging_initialized = false;
-#endif
-
using glue::_o3d::PluginObject;
using glue::StreamManager;
using o3d::Bitmap;
@@ -75,18 +60,11 @@ using o3d::FullscreenWindowMac;
using o3d::Renderer;
namespace {
-// We would normally make this a stack variable in main(), but in a
-// plugin, that's not possible, so we make it a global. When the DLL is loaded
-// this it gets constructed and when it is unlooaded it is destructed. Note
-// that this cannot be done in NP_Initialize and NP_Shutdown because those
-// calls do not necessarily signify the DLL being loaded and unloaded. If the
-// DLL is not unloaded then the values of global variables are preserved.
-base::AtExitManager g_at_exit_manager;
#define CFTIMER
// #define DEFERRED_DRAW_ON_NULLEVENTS
-
+
// Helper that extracts the O3DLayer obj c object from the PluginObject
// and coerces it to the right type. The code can't live in the PluginObject
// since it's c++ code and doesn't know about objective c types, and it saves
@@ -477,37 +455,6 @@ enum nsPluginEventType {
nsPluginEventType_Idle = 0
};
-NPError InitializePlugin() {
-#if !defined(O3D_INTERNAL_PLUGIN)
- if (!o3d::SetupOutOfMemoryHandler())
- return NPERR_MODULE_LOAD_FAILED_ERROR;
-
- o3d::InitializeBreakpad();
-
-#ifdef CFTIMER
- o3d::gRenderTimer.Start();
-#endif // CFTIMER
-
- // Turn on the logging.
- CommandLine::Init(0, NULL);
-
- FilePath log;
- file_util::GetTempDir(&log);
- log = log.Append("debug.log");
-
- InitLogging(log.value().c_str(),
- logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
- logging::DONT_LOCK_LOG_FILE,
- logging::APPEND_TO_OLD_LOG_FILE);
-
- DLOG(INFO) << "NP_Initialize";
-
- o3d::SetupOutOfMemoryHandler();
-#endif // O3D_INTERNAL_PLUGIN
-
- return NPERR_NO_ERROR;
-}
-
// When to prefer Core Animation. Safari's support in 10.5 was too
// buggy to attempt to use.
static bool PreferCoreAnimation() {
@@ -637,18 +584,11 @@ namespace o3d {
extern "C" {
#endif
-NPError OSCALL NP_Initialize(NPNetscapeFuncs* browserFuncs) {
- HANDLE_CRASHES;
- NPError retval = InitializeNPNApi(browserFuncs);
- if (retval != NPERR_NO_ERROR) return retval;
- return InitializePlugin();
-}
-
#if !defined(O3D_INTERNAL_PLUGIN)
// Wrapper that discards the return value to match the expected type of
// NPP_ShutdownProcPtr.
-void NPP_ShutdownWrapper() {
+static void NPP_ShutdownWrapper() {
NP_Shutdown();
}
@@ -669,41 +609,45 @@ int main(NPNetscapeFuncs* browserFuncs,
#endif // O3D_INTERNAL_PLUGIN
-NPError OSCALL NP_Shutdown(void) {
-#if !defined(O3D_INTERNAL_PLUGIN)
- HANDLE_CRASHES;
- DLOG(INFO) << "NP_Shutdown";
-
- if (g_logger) {
- // Do a last sweep to aggregate metrics before we shut down
- g_logger->ProcessMetrics(true, false, false);
- delete g_logger;
- g_logger = NULL;
- g_logging_initialized = false;
- stats_report::g_global_metrics.Uninitialize();
- }
+} // namespace o3d / extern "C"
- CommandLine::Reset();
+namespace o3d {
-#ifdef CFTIMER
- o3d::gRenderTimer.Stop();
-#endif
+NPError PlatformPreNPInitialize() {
+#if !defined(O3D_INTERNAL_PLUGIN)
+ o3d::InitializeBreakpad();
- o3d::ShutdownBreakpad();
+#ifdef CFTIMER
+ o3d::gRenderTimer.Start();
+#endif // CFTIMER
#endif // O3D_INTERNAL_PLUGIN
return NPERR_NO_ERROR;
}
-} // namespace o3d / extern "C"
+NPError PlatformPostNPInitialize() {
+ return NPERR_NO_ERROR;
+}
+NPError PlatformPreNPShutdown() {
+ return NPERR_NO_ERROR;
+}
+NPError PlatformPostNPShutdown() {
+#if !defined(O3D_INTERNAL_PLUGIN)
+#ifdef CFTIMER
+ o3d::gRenderTimer.Stop();
+#endif
-namespace o3d {
+ o3d::ShutdownBreakpad();
+#endif // O3D_INTERNAL_PLUGIN
-NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) {
- PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
+ return NPERR_NO_ERROR;
+}
+NPError PlatformNPPGetValue(PluginObject *obj,
+ NPPVariable variable,
+ void *value) {
switch (variable) {
case NPPVpluginCoreAnimationLayer:
if (!ObjO3DLayer(obj)) {
@@ -942,68 +886,35 @@ bool HandleCocoaEvent(NPP instance, NPCocoaEvent* the_event,
return handled;
}
-NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
- char* argn[], char* argv[], NPSavedData* saved) {
- HANDLE_CRASHES;
-
- NPError err = NPERR_NO_ERROR;
-
-#if !defined(O3D_INTERNAL_PLUGIN)
- if (!g_logging_initialized) {
- o3d::GetUserAgentMetrics(instance);
- GetUserConfigMetrics();
- // Create usage stats logs object
- g_logger = o3d::PluginLogging::InitializeUsageStatsLogging();
- g_logging_initialized = true;
- }
-#endif // O3D_INTERNAL_PLUGIN
-
- if (!IsDomainAuthorized(instance)) {
- return NPERR_INVALID_URL;
- }
-
- PluginObject* pluginObject = glue::_o3d::PluginObject::Create(
- instance);
- instance->pdata = pluginObject;
- glue::_o3d::InitializeGlue(instance);
- pluginObject->Init(argc, argn, argv);
-
- err = Mac_SetBestEventAndDrawingModel(instance,
- static_cast<PluginObject*>(
- instance->pdata));
+NPError PlatformNPPNew(NPP instance, PluginObject *obj) {
+ NPError err = Mac_SetBestEventAndDrawingModel(instance, obj);
if (err != NPERR_NO_ERROR)
return err;
#ifdef CFTIMER
- if (pluginObject->drawing_model_ == NPDrawingModelCoreAnimation) {
+ if (obj->drawing_model_ == NPDrawingModelCoreAnimation) {
o3d::gRenderTimer.AddInstance(instance);
}
#endif
return NPERR_NO_ERROR;
}
-NPError NPP_Destroy(NPP instance, NPSavedData** save) {
- HANDLE_CRASHES;
- PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
- if (obj) {
+NPError PlatformNPPDestroy(NPP instance, PluginObject *obj) {
#if defined(CFTIMER)
- o3d::gRenderTimer.RemoveInstance(instance);
+ o3d::gRenderTimer.RemoveInstance(instance);
#endif
- // TODO(maf) / TODO(kbr): are we leaking AGL / CGL contexts?
+ // TODO(maf) / TODO(kbr): are we leaking AGL / CGL contexts?
- if (obj->drawing_model_ == NPDrawingModelCoreAnimation) {
- O3DLayer* layer = ObjO3DLayer(obj);
- if (layer) {
- // Prevent the layer from rendering any more.
- [layer setPluginObject:NULL];
- }
+ if (obj->drawing_model_ == NPDrawingModelCoreAnimation) {
+ O3DLayer* layer = ObjO3DLayer(obj);
+ if (layer) {
+ // Prevent the layer from rendering any more.
+ [layer setPluginObject:NULL];
}
-
- obj->TearDown();
- NPN_ReleaseObject(obj);
- instance->pdata = NULL;
}
+ obj->TearDown();
+
return NPERR_NO_ERROR;
}
@@ -1011,9 +922,9 @@ bool CheckForAGLError() {
return aglGetError() != AGL_NO_ERROR;
}
-NPError NPP_SetWindow(NPP instance, NPWindow* window) {
- HANDLE_CRASHES;
- PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
+NPError PlatformNPPSetWindow(NPP instance,
+ PluginObject *obj,
+ NPWindow* window) {
WindowRef new_window = NULL;
assert(window != NULL);
@@ -1341,13 +1252,9 @@ NPError NPP_SetWindow(NPP instance, NPWindow* window) {
return NPERR_NO_ERROR;
}
-// 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();
-
+void PlatformNPPStreamAsFile(StreamManager *stream_manager,
+ NPStream *stream,
+ const char *fname) {
// Some browsers give us an absolute HFS path in fname, some give us an
// absolute Posix path, so convert to Posix if needed.
if ((!fname) || (fname[0] == '/') || !fname[0]) {
@@ -1361,9 +1268,7 @@ void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) {
}
}
-int16 NPP_HandleEvent(NPP instance, void* event) {
- HANDLE_CRASHES;
- PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
+int16 PlatformNPPHandleEvent(NPP instance, PluginObject *obj, void *event) {
if (obj->event_model_ == NPEventModelCarbon) {
EventRecord* theEvent = static_cast<EventRecord*>(event);
return HandleMacEvent(theEvent, instance) ? 1 : 0;
diff --git a/o3d/plugin/win/main_win.cc b/o3d/plugin/win/main_win.cc
index 1cbceb8..8f93439 100644
--- a/o3d/plugin/win/main_win.cc
+++ b/o3d/plugin/win/main_win.cc
@@ -39,19 +39,14 @@
#include <windowsx.h>
#include <shellapi.h>
-#include "base/at_exit.h"
-#include "base/command_line.h"
-#include "base/file_util.h"
#include "base/logging.h"
-#include "base/ref_counted.h"
#include "core/cross/display_mode.h"
#include "core/cross/event.h"
-#include "plugin/cross/plugin_logging.h"
-#include "plugin/cross/out_of_memory.h"
-#include "plugin/cross/whitelist.h"
-#include "statsreport/metrics.h"
+#include "core/win/display_window_win.h"
#include "v8/include/v8.h"
-#include "breakpad/win/bluescreen_detector.h"
+#if !defined(O3D_INTERNAL_PLUGIN)
+#include "breakpad/win/exception_handler_win32.h"
+#endif
using glue::_o3d::PluginObject;
using glue::StreamManager;
@@ -64,10 +59,8 @@ HINSTANCE g_module_instance;
} // namespace anonymous
#if !defined(O3D_INTERNAL_PLUGIN)
-
-o3d::PluginLogging* g_logger = NULL;
-bool g_logging_initialized = false;
-o3d::BluescreenDetector *g_bluescreen_detector = NULL;
+// Used for breakpad crash handling
+static ExceptionManager *g_exception_manager = NULL;
extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
DWORD reason,
@@ -94,14 +87,6 @@ const wchar_t* const kO3DWindowClassName = L"O3DWindowClass";
void CleanupAllWindows(PluginObject *obj);
-// We would normally make this a stack variable in main(), but in a
-// plugin, that's not possible, so we make it a global. When the DLL is loaded
-// this it gets constructed and when it is unlooaded it is destructed. Note
-// that this cannot be done in NP_Initialize and NP_Shutdown because those
-// calls do not necessarily signify the DLL being loaded and unloaded. If the
-// DLL is not unloaded then the values of global variables are preserved.
-base::AtExitManager g_at_exit_manager;
-
static int HandleKeyboardEvent(PluginObject *obj,
HWND hWnd,
UINT Msg,
@@ -481,8 +466,6 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
}
#if !defined(O3D_INTERNAL_PLUGIN)
- // TODO: Only logging for windows until we figure out the proper
- // mac way
if (g_logger) g_logger->UpdateLogging();
#endif
@@ -653,38 +636,6 @@ void UnregisterO3DWindowClass() {
UnregisterClass(kO3DWindowClassName, g_module_instance);
}
-NPError InitializePlugin() {
-#if !defined(O3D_INTERNAL_PLUGIN)
- if (!o3d::SetupOutOfMemoryHandler())
- return NPERR_MODULE_LOAD_FAILED_ERROR;
-
- // Setup crash handler
- if (!g_exception_manager) {
- g_exception_manager = new ExceptionManager(false);
- g_exception_manager->StartMonitoring();
- }
-
- // Turn on the logging.
- CommandLine::Init(0, NULL);
-
- FilePath log;
- file_util::GetTempDir(&log);
- log.Append(L"debug.log");
-
- InitLogging(log.value().c_str(),
- logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
- logging::DONT_LOCK_LOG_FILE,
- logging::APPEND_TO_OLD_LOG_FILE);
-#endif // O3D_INTERNAL_PLUGIN
-
- DLOG(INFO) << "NP_Initialize";
-
- if (!RegisterO3DWindowClass())
- return NPERR_MODULE_LOAD_FAILED_ERROR;
-
- return NPERR_NO_ERROR;
-}
-
void CleanupAllWindows(PluginObject *obj) {
if (obj->GetContentHWnd()) {
::KillTimer(obj->GetContentHWnd(), 0);
@@ -752,123 +703,67 @@ bool GetScreenRect(HWND hwnd,
} // namespace anonymous
-#if defined(O3D_INTERNAL_PLUGIN)
namespace o3d {
-#else
-extern "C" {
-#endif
-NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs) {
- HANDLE_CRASHES;
-
- NPError retval = InitializeNPNApi(browserFuncs);
- if (retval != NPERR_NO_ERROR) return retval;
- return InitializePlugin();
+NPError PlatformPreNPInitialize() {
+#if !defined(O3D_INTERNAL_PLUGIN)
+ // Setup crash handler
+ if (!g_exception_manager) {
+ g_exception_manager = new ExceptionManager(false);
+ g_exception_manager->StartMonitoring();
+ }
+#endif // O3D_INTERNAL_PLUGIN
+ return NPERR_NO_ERROR;
}
-NPError OSCALL NP_Shutdown(void) {
- HANDLE_CRASHES;
- DLOG(INFO) << "NP_Shutdown";
+NPError PlatformPostNPInitialize() {
+ if (!RegisterO3DWindowClass())
+ return NPERR_MODULE_LOAD_FAILED_ERROR;
+ return NPERR_NO_ERROR;
+}
+
+NPError PlatformPreNPShutdown() {
+ // TODO(tschmelcher): Is there a reason we need to do this before the main
+ // shutdown tasks? If not, we can axe the PlatformPreNPShutdown() function.
UnregisterO3DWindowClass();
+ return NPERR_NO_ERROR;
+}
+NPError PlatformPostNPShutdown() {
#if !defined(O3D_INTERNAL_PLUGIN)
-
- if (g_logger) {
- // Do a last sweep to aggregate metrics before we shut down
- g_logger->ProcessMetrics(true, false, false);
- delete g_logger;
- g_logger = NULL;
- g_logging_initialized = false;
- stats_report::g_global_metrics.Uninitialize();
- }
-
- CommandLine::Reset();
-
// TODO : This is commented out until we can determine if
// it's safe to shutdown breakpad at this stage (Gears, for
// example, never deletes...)
// Shutdown breakpad
// delete g_exception_manager;
-
- // Strictly speaking, on windows, it's not really necessary to call
- // Stop(), but we do so for completeness
- if (g_bluescreen_detector) {
- g_bluescreen_detector->Stop();
- delete g_bluescreen_detector;
- g_bluescreen_detector = NULL;
- }
-
-#endif // O3D_INTERNAL_PLUGIN
+#endif
return NPERR_NO_ERROR;
}
-} // extern "C" / namespace o3d
-namespace o3d {
-
-NPError NPP_New(NPMIMEType pluginType,
- NPP instance,
- uint16 mode,
- int16 argc,
- char *argn[],
- char *argv[],
- NPSavedData *saved) {
- HANDLE_CRASHES;
-
-#if !defined(O3D_INTERNAL_PLUGIN)
- if (!g_logging_initialized) {
- // Get user config metrics. These won't be stored though unless the user
- // opts-in for usagestats logging
- GetUserAgentMetrics(instance);
- GetUserConfigMetrics();
- // Create usage stats logs object
- g_logger = o3d::PluginLogging::InitializeUsageStatsLogging();
- if (g_logger) {
- // Setup blue-screen detection
- g_bluescreen_detector = new o3d::BluescreenDetector();
- g_bluescreen_detector->Start();
- }
- g_logging_initialized = true;
- }
-#endif
-
- if (!IsDomainAuthorized(instance)) {
- return NPERR_INVALID_URL;
- }
-
- PluginObject* pluginObject = glue::_o3d::PluginObject::Create(
- instance);
- instance->pdata = pluginObject;
- glue::_o3d::InitializeGlue(instance);
- pluginObject->Init(argc, argn, argv);
+NPError PlatformNPPNew(NPP instance, PluginObject *obj) {
return NPERR_NO_ERROR;
}
-NPError NPP_Destroy(NPP instance, NPSavedData **save) {
- HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
- if (obj) {
- if (obj->GetHWnd()) {
- CleanupAllWindows(obj);
- }
-
- obj->TearDown();
- NPN_ReleaseObject(obj);
- instance->pdata = NULL;
+NPError PlatformNPPDestroy(NPP instance, PluginObject *obj) {
+ if (obj->GetHWnd()) {
+ CleanupAllWindows(obj);
}
+ obj->TearDown();
return NPERR_NO_ERROR;
}
-NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) {
+NPError PlatformNPPGetValue(PluginObject *obj,
+ NPPVariable variable,
+ void *value) {
return NPERR_INVALID_PARAM;
}
-NPError NPP_SetWindow(NPP instance, NPWindow *window) {
- HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
-
+NPError PlatformNPPSetWindow(NPP instance,
+ PluginObject *obj,
+ NPWindow *window) {
HWND hWnd = static_cast<HWND>(window->window);
if (!hWnd) {
// Chrome calls us this way before NPP_Destroy.
@@ -948,22 +843,19 @@ NPError NPP_SetWindow(NPP instance, NPWindow *window) {
return NPERR_NO_ERROR;
}
-// 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();
-
+void PlatformNPPStreamAsFile(StreamManager *stream_manager,
+ NPStream *stream,
+ const char *fname) {
stream_manager->SetStreamFile(stream, fname);
}
-int16 NPP_HandleEvent(NPP instance, void *event) {
- HANDLE_CRASHES;
+int16 PlatformNPPHandleEvent(NPP instance, PluginObject *obj, void *event) {
return 0;
}
+
} // namespace o3d
+// TODO(tschmelcher): This stuff does not belong in this file.
namespace glue {
namespace _o3d {
bool PluginObject::GetDisplayMode(int mode_id, o3d::DisplayMode *mode) {