summaryrefslogtreecommitdiffstats
path: root/o3d/plugin/win
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-13 17:30:45 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-13 17:30:45 +0000
commit4d1218e091dae7e30ad59150bfeb4acaade10c0f (patch)
tree92c59fb76666c1491acaed5652640eeb394d8ff8 /o3d/plugin/win
parent7f1fe3fad451d8809d94b19fca516a2a2134e38c (diff)
downloadchromium_src-4d1218e091dae7e30ad59150bfeb4acaade10c0f.zip
chromium_src-4d1218e091dae7e30ad59150bfeb4acaade10c0f.tar.gz
chromium_src-4d1218e091dae7e30ad59150bfeb4acaade10c0f.tar.bz2
Fixed full screen window class issues.
Now main_win.cc unregisters the full screen window class so that if the DLL is reloaded at a different address later, the WindowProc will point at the new address. Also now using the DLL's module handle rather than the one associated with the plugin (which will likely be the browser exes handle). Review URL: http://codereview.chromium.org/149496 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20500 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/plugin/win')
-rw-r--r--o3d/plugin/win/main_win.cc38
1 files changed, 31 insertions, 7 deletions
diff --git a/o3d/plugin/win/main_win.cc b/o3d/plugin/win/main_win.cc
index 594dbff..48c1be1 100644
--- a/o3d/plugin/win/main_win.cc
+++ b/o3d/plugin/win/main_win.cc
@@ -55,14 +55,22 @@ using glue::StreamManager;
using o3d::DisplayWindowWindows;
using o3d::Event;
+namespace {
+// The instance handle of the O3D DLL.
+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;
-#if !defined(O3D_INTERNAL_PLUGIN)
extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
DWORD reason,
LPVOID reserved) {
+ g_module_instance = instance;
+
if (reason == DLL_PROCESS_DETACH) {
// Teardown V8 when the plugin dll is unloaded.
// NOTE: NP_Shutdown would have been a good place for this code but
@@ -79,6 +87,8 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
#endif // O3D_INTERNAL_PLUGIN
namespace {
+const wchar_t* const kFullScreenWindowClassName = L"O3DFullScreenWindowClass";
+
// We would normally make this a stack variable in main(), but in a
// plugin, that's not possible, so we allocate it dynamically and
// destroy it explicitly.
@@ -657,6 +667,19 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
return 0;
}
+bool RegisterFullScreenWindowClass() {
+ WNDCLASSEX window_class = { sizeof(WNDCLASSEX) };
+ window_class.hInstance = g_module_instance;
+ window_class.lpfnWndProc = WindowProc;
+ window_class.lpszClassName = kFullScreenWindowClassName;
+ window_class.style = CS_DBLCLKS;
+ return RegisterClassEx(&window_class) != 0;
+}
+
+void UnregisterFullScreenWindowClass() {
+ UnregisterClass(kFullScreenWindowClassName, g_module_instance);
+}
+
NPError InitializePlugin() {
#if !defined(O3D_INTERNAL_PLUGIN)
if (!o3d::SetupOutOfMemoryHandler())
@@ -682,6 +705,9 @@ NPError InitializePlugin() {
DLOG(INFO) << "NP_Initialize";
+ if (!RegisterFullScreenWindowClass())
+ return NPERR_MODULE_LOAD_FAILED_ERROR;
+
return NPERR_NO_ERROR;
}
@@ -716,12 +742,8 @@ HWND CreateFullscreenWindow(PluginObject *obj,
}
CHECK(mode.width() > 0 && mode.height() > 0);
- HINSTANCE instance =
- reinterpret_cast<HINSTANCE>(
- ::GetWindowLongPtr(obj->GetPluginHWnd(), GWLP_HINSTANCE));
- WNDCLASSEX *wcx = obj->GetFullscreenWindowClass(instance, WindowProc);
HWND hWnd = CreateWindowEx(NULL,
- wcx->lpszClassName,
+ kFullScreenWindowClassName,
L"O3D Test Fullscreen Window",
WS_POPUP,
0, 0,
@@ -729,7 +751,7 @@ HWND CreateFullscreenWindow(PluginObject *obj,
mode.height(),
NULL,
NULL,
- instance,
+ g_module_instance,
NULL);
ShowWindow(hWnd, SW_SHOW);
@@ -754,6 +776,8 @@ NPError OSCALL NP_Shutdown(void) {
HANDLE_CRASHES;
DLOG(INFO) << "NP_Shutdown";
+ UnregisterFullScreenWindowClass();
+
#if !defined(O3D_INTERNAL_PLUGIN)
if (g_logger) {