summaryrefslogtreecommitdiffstats
path: root/o3d/plugin/win
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 18:35:53 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 18:35:53 +0000
commit9bcc6daa3287203a358e782d2e63f53ac18102e1 (patch)
treeb9fcca846890a50e387175def5c979dcc4c4bb4f /o3d/plugin/win
parent1279ace64f4bdd009ec06528cf6c94e11b48bf69 (diff)
downloadchromium_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/win')
-rw-r--r--o3d/plugin/win/config.cc3
-rw-r--r--o3d/plugin/win/main_win.cc634
-rw-r--r--o3d/plugin/win/update_lock.cc4
-rw-r--r--o3d/plugin/win/update_lock.h4
4 files changed, 324 insertions, 321 deletions
diff --git a/o3d/plugin/win/config.cc b/o3d/plugin/win/config.cc
index dd08101..e47147a 100644
--- a/o3d/plugin/win/config.cc
+++ b/o3d/plugin/win/config.cc
@@ -57,6 +57,8 @@
#include "core/cross/install_check.h"
#include "third_party/nixysa/files/static_glue/npapi/common.h"
+namespace o3d {
+
// Check Windows version.
bool CheckOSVersion(NPP npp) {
OSVERSIONINFOEX version = {sizeof(OSVERSIONINFOEX)}; // NOLINT
@@ -232,3 +234,4 @@ bool GetUserAgentMetrics(NPP npp) {
}
return true;
}
+} // namespace o3d
diff --git a/o3d/plugin/win/main_win.cc b/o3d/plugin/win/main_win.cc
index 57623d2..594dbff 100644
--- a/o3d/plugin/win/main_win.cc
+++ b/o3d/plugin/win/main_win.cc
@@ -59,16 +59,30 @@ 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) {
+ 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
+ // unfortunately it looks like it gets called even when the dll
+ // isn't really unloaded. This is a problem since after calling
+ // V8::Dispose(), V8 cannot be initialized again.
+ bool v8_disposed = v8::V8::Dispose();
+ if (!v8_disposed)
+ DLOG(ERROR) << "Failed to release V8 resources.";
+ return true;
+ }
+ return true;
+}
+#endif // O3D_INTERNAL_PLUGIN
+
namespace {
// 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.
scoped_ptr<base::AtExitManager> g_at_exit_manager;
-} // end anonymous namespace
-
-void RenderOnDemandCallbackHandler::Run() {
- ::InvalidateRect(obj_->GetHWnd(), NULL, TRUE);
-}
static int HandleKeyboardEvent(PluginObject *obj,
HWND hWnd,
@@ -148,11 +162,11 @@ static int HandleKeyboardEvent(PluginObject *obj,
return 0;
}
-static void HandleMouseEvent(PluginObject *obj,
- HWND hWnd,
- UINT Msg,
- WPARAM wParam,
- LPARAM lParam) {
+void HandleMouseEvent(PluginObject *obj,
+ HWND hWnd,
+ UINT Msg,
+ WPARAM wParam,
+ LPARAM lParam) {
DCHECK(obj);
DCHECK(obj->client());
bool fake_dblclick = false;
@@ -326,12 +340,12 @@ static void HandleMouseEvent(PluginObject *obj,
}
// This returns 0 on success, 1 on failure, to match WindowProc.
-static LRESULT ForwardEvent(PluginObject *obj,
- HWND hWnd,
- UINT Msg,
- WPARAM wParam,
- LPARAM lParam,
- bool translateCoords) {
+LRESULT ForwardEvent(PluginObject *obj,
+ HWND hWnd,
+ UINT Msg,
+ WPARAM wParam,
+ LPARAM lParam,
+ bool translateCoords) {
DCHECK(obj);
DCHECK(obj->GetPluginHWnd());
HWND dest_hwnd = obj->GetParentHWnd();
@@ -398,7 +412,7 @@ static LRESULT ForwardEvent(PluginObject *obj,
return !::PostMessage(dest_hwnd, Msg, wParam, lParam);
}
-static LRESULT HandleDragAndDrop(PluginObject *obj, WPARAM wParam) {
+LRESULT HandleDragAndDrop(PluginObject *obj, WPARAM wParam) {
HDROP hDrop = reinterpret_cast<HDROP>(wParam);
UINT num_files = ::DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
if (!num_files) {
@@ -457,8 +471,7 @@ static LRESULT HandleDragAndDrop(PluginObject *obj, WPARAM wParam) {
return 1;
}
-static LRESULT CALLBACK
-WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
+LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
PluginObject *obj = PluginObject::GetPluginProperty(hWnd);
if (obj == NULL) { // It's not my window
return 1; // 0 often means we handled it.
@@ -644,345 +657,324 @@ WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
return 0;
}
-NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) {
- return NPERR_INVALID_PARAM;
+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();
+ }
+
+ // Initialize the AtExitManager so that base singletons can be
+ // destroyed properly.
+ g_at_exit_manager.reset(new base::AtExitManager());
+
+ // Turn on the logging.
+ CommandLine::Init(0, NULL);
+ InitLogging(L"debug.log",
+ 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 NPERR_NO_ERROR;
+}
+
+void CleanupFullscreenWindow(PluginObject *obj) {
+ DCHECK(obj->GetFullscreenHWnd());
+ obj->StorePluginProperty(obj->GetPluginHWnd(), obj);
+ ::DestroyWindow(obj->GetFullscreenHWnd());
+ obj->SetFullscreenHWnd(NULL);
+}
+
+void CleanupAllWindows(PluginObject *obj) {
+ DCHECK(obj->GetHWnd());
+ DCHECK(obj->GetPluginHWnd());
+ ::KillTimer(obj->GetHWnd(), 0);
+ if (obj->GetFullscreenHWnd()) {
+ CleanupFullscreenWindow(obj);
+ }
+ PluginObject::ClearPluginProperty(obj->GetHWnd());
+ ::SetWindowLongPtr(obj->GetPluginHWnd(),
+ GWL_WNDPROC,
+ reinterpret_cast<LONG_PTR>(
+ obj->GetDefaultPluginWindowProc()));
+ obj->SetPluginHWnd(NULL);
+ obj->SetHWnd(NULL);
}
+HWND CreateFullscreenWindow(PluginObject *obj,
+ int mode_id) {
+ o3d::DisplayMode mode;
+ if (!obj->renderer()->GetDisplayMode(mode_id, &mode)) {
+ return NULL;
+ }
+ 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,
+ L"O3D Test Fullscreen Window",
+ WS_POPUP,
+ 0, 0,
+ mode.width(),
+ mode.height(),
+ NULL,
+ NULL,
+ instance,
+ NULL);
+
+ ShowWindow(hWnd, SW_SHOW);
+ return hWnd;
+}
+} // namespace anonymous
+
+#if defined(O3D_INTERNAL_PLUGIN)
+namespace o3d {
+#else
extern "C" {
- BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) {
- 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
- // unfortunately it looks like it gets called even when the dll
- // isn't really unloaded. This is a problem since after calling
- // V8::Dispose(), V8 cannot be initialized again.
- bool v8_disposed = v8::V8::Dispose();
- if (!v8_disposed)
- DLOG(ERROR) << "Failed to release V8 resources.";
- return true;
- }
- return true;
- }
-
- NPError InitializePlugin() {
- if (!o3d::SetupOutOfMemoryHandler())
- return NPERR_MODULE_LOAD_FAILED_ERROR;
+#endif
- // Setup crash handler
- if (!g_exception_manager) {
- g_exception_manager = new ExceptionManager(false);
- g_exception_manager->StartMonitoring();
- }
+NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs) {
+ HANDLE_CRASHES;
+ NPError retval = InitializeNPNApi(browserFuncs);
+ if (retval != NPERR_NO_ERROR) return retval;
+ return InitializePlugin();
+}
- // Initialize the AtExitManager so that base singletons can be
- // destroyed properly.
- g_at_exit_manager.reset(new base::AtExitManager());
-
- // Turn on the logging.
- CommandLine::Init(0, NULL);
- InitLogging(L"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";
-
- // Limit the current thread to one processor (the current one). This ensures
- // that timing code runs on only one processor, and will not suffer any ill
- // effects from power management. See "Game Timing and Multicore Processors"
- // in the DirectX docs for more details
- {
- HANDLE current_process_handle = GetCurrentProcess();
-
- // Get the processor affinity mask for this process
- DWORD_PTR process_affinity_mask = 0;
- DWORD_PTR system_affinity_mask = 0;
-
- if (GetProcessAffinityMask(current_process_handle,
- &process_affinity_mask,
- &system_affinity_mask) != 0 &&
- process_affinity_mask) {
- // Find the lowest processor that our process is allows to run against
- DWORD_PTR affinity_mask = (process_affinity_mask &
- ((~process_affinity_mask) + 1));
-
- // Set this as the processor that our thread must always run against
- // This must be a subset of the process affinity mask
- HANDLE hCurrentThread = GetCurrentThread();
- if (INVALID_HANDLE_VALUE != hCurrentThread) {
- SetThreadAffinityMask(hCurrentThread, affinity_mask);
- CloseHandle(hCurrentThread);
- }
- }
+NPError OSCALL NP_Shutdown(void) {
+ HANDLE_CRASHES;
+ DLOG(INFO) << "NP_Shutdown";
- CloseHandle(current_process_handle);
- }
+#if !defined(O3D_INTERNAL_PLUGIN)
- return NPERR_NO_ERROR;
+ if (g_logger) {
+ // Do a last sweep to aggregate metrics before we shut down
+ g_logger->ProcessMetrics(true, false);
+ delete g_logger;
+ g_logger = NULL;
+ g_logging_initialized = false;
+ stats_report::g_global_metrics.Uninitialize();
}
- NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs) {
- HANDLE_CRASHES;
- NPError retval = InitializeNPNApi(browserFuncs);
- if (retval != NPERR_NO_ERROR) return retval;
- return InitializePlugin();
+ CommandLine::Terminate();
+
+ // Force all base singletons to be destroyed.
+ g_at_exit_manager.reset(NULL);
+
+ // 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;
}
- NPError OSCALL NP_Shutdown(void) {
- 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);
- delete g_logger;
- g_logger = NULL;
- g_logging_initialized = false;
- stats_report::g_global_metrics.Uninitialize();
- }
+#endif // O3D_INTERNAL_PLUGIN
+
+ return NPERR_NO_ERROR;
+}
+} // extern "C" / namespace o3d
- CommandLine::Terminate();
+namespace o3d {
+void RenderOnDemandCallbackHandler::Run() {
+ ::InvalidateRect(obj_->GetHWnd(), NULL, TRUE);
+}
- // 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;
+
+#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
- // 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;
+ PluginObject* pluginObject = glue::_o3d::PluginObject::Create(
+ instance);
+ instance->pdata = pluginObject;
+ glue::_o3d::InitializeGlue(instance);
+ pluginObject->Init(argc, argn, argv);
+ return NPERR_NO_ERROR;
+}
- // 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;
+NPError NPP_Destroy(NPP instance, NPSavedData **save) {
+ HANDLE_CRASHES;
+ PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
+ if (obj) {
+ if (obj->GetHWnd()) {
+ CleanupAllWindows(obj);
}
- return NPERR_NO_ERROR;
+ obj->TearDown();
+ NPN_ReleaseObject(obj);
+ instance->pdata = NULL;
}
- NPError NPP_New(NPMIMEType pluginType,
- NPP instance,
- uint16 mode,
- int16 argc,
- char *argn[],
- char *argv[],
- NPSavedData *saved) {
- HANDLE_CRASHES;
-
- 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;
+ return NPERR_NO_ERROR;
+}
+
+NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) {
+ return NPERR_INVALID_PARAM;
+}
+
+NPError NPP_SetWindow(NPP instance, NPWindow *window) {
+ HANDLE_CRASHES;
+ PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
+
+ HWND hWnd = static_cast<HWND>(window->window);
+ if (!hWnd) {
+ // Chrome calls us this way before NPP_Destroy.
+ if (obj->GetHWnd()) {
+ CleanupAllWindows(obj);
}
- PluginObject* pluginObject = glue::_o3d::PluginObject::Create(
- instance);
- instance->pdata = pluginObject;
- glue::_o3d::InitializeGlue(instance);
- pluginObject->Init(argc, argn, argv);
return NPERR_NO_ERROR;
}
-
- void CleanupFullscreenWindow(PluginObject *obj) {
- DCHECK(obj->GetFullscreenHWnd());
- obj->StorePluginProperty(obj->GetPluginHWnd(), obj);
- ::DestroyWindow(obj->GetFullscreenHWnd());
- obj->SetFullscreenHWnd(NULL);
+ if (obj->GetHWnd() == hWnd) {
+ return NPERR_NO_ERROR;
}
-
- void CleanupAllWindows(PluginObject *obj) {
- DCHECK(obj->GetHWnd());
+ if (obj->fullscreen()) {
+ // We can get here if the user alt+tabs away from the fullscreen plugin
+ // window or JavaScript resizes the plugin window.
DCHECK(obj->GetPluginHWnd());
- ::KillTimer(obj->GetHWnd(), 0);
- if (obj->GetFullscreenHWnd()) {
- CleanupFullscreenWindow(obj);
- }
- PluginObject::ClearPluginProperty(obj->GetHWnd());
- ::SetWindowLongPtr(obj->GetPluginHWnd(),
- GWL_WNDPROC,
- reinterpret_cast<LONG_PTR>(
- obj->GetDefaultPluginWindowProc()));
- obj->SetPluginHWnd(NULL);
- obj->SetHWnd(NULL);
- }
-
- 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;
- }
-
+ DCHECK(obj->GetFullscreenHWnd());
+ DCHECK(obj->GetPluginHWnd() == hWnd);
return NPERR_NO_ERROR;
}
+ DCHECK(!obj->GetPluginHWnd());
+ obj->SetPluginHWnd(hWnd);
+ obj->SetParentHWnd(::GetParent(hWnd));
+ PluginObject::StorePluginProperty(hWnd, obj);
+ obj->SetDefaultPluginWindowProc(
+ reinterpret_cast<WNDPROC>(
+ ::SetWindowLongPtr(hWnd,
+ GWL_WNDPROC,
+ reinterpret_cast<LONG_PTR>(WindowProc))));
+
+ // create and assign the graphics context
+ DisplayWindowWindows default_display;
+ default_display.set_hwnd(obj->GetHWnd());
+
+ obj->CreateRenderer(default_display);
+ obj->client()->Init();
+ obj->client()->SetRenderOnDemandCallback(
+ new RenderOnDemandCallbackHandler(obj));
+
+ // we set the timer to 10ms or 100fps. At the time of this comment
+ // the renderer does a vsync the max fps it will run will be the refresh
+ // rate of the monitor or 100fps, which ever is lower.
+ ::SetTimer(obj->GetHWnd(), 0, 10, NULL);
+
+ return NPERR_NO_ERROR;
+}
- bool PluginObject::GetDisplayMode(int mode_id, o3d::DisplayMode *mode) {
- return renderer()->GetDisplayMode(mode_id, mode);
- }
+// 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();
+ stream_manager->SetStreamFile(stream, fname);
+}
- HWND CreateFullscreenWindow(PluginObject *obj,
- int mode_id) {
- o3d::DisplayMode mode;
- if (!obj->renderer()->GetDisplayMode(mode_id, &mode)) {
- return NULL;
- }
- 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,
- L"O3D Test Fullscreen Window",
- WS_POPUP,
- 0, 0,
- mode.width(),
- mode.height(),
- NULL,
- NULL,
- instance,
- NULL);
-
- ShowWindow(hWnd, SW_SHOW);
- return hWnd;
- }
-
- // 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() {
- bool success = false;
- DCHECK(GetPluginHWnd());
- if (!fullscreen_ && renderer_ && fullscreen_region_valid_) {
- DCHECK(renderer_->fullscreen() == fullscreen_);
- DCHECK(!GetFullscreenHWnd());
- HWND drawing_hwnd =
- CreateFullscreenWindow(this, fullscreen_region_mode_id_);
- if (drawing_hwnd) {
- ::KillTimer(GetHWnd(), 0);
- SetFullscreenHWnd(drawing_hwnd);
- StorePluginPropertyUnsafe(drawing_hwnd, this);
-
- DisplayWindowWindows display;
- display.set_hwnd(GetHWnd());
- if (renderer_->SetFullscreen(true, display,
- fullscreen_region_mode_id_)) {
- fullscreen_ = true;
- client()->SendResizeEvent(renderer_->width(), renderer_->height(),
- true);
- success = true;
- } else {
- CleanupFullscreenWindow(this);
- }
- prev_width_ = renderer_->width();
- prev_height_ = renderer_->height();
- ::SetTimer(GetHWnd(), 0, 10, NULL);
- } else {
- LOG(ERROR) << "Failed to create fullscreen window.";
- }
- }
- return success;
- }
+int16 NPP_HandleEvent(NPP instance, void *event) {
+ HANDLE_CRASHES;
+ return 0;
+}
+} // namespace o3d
+
+namespace glue {
+namespace _o3d {
+bool PluginObject::GetDisplayMode(int mode_id, o3d::DisplayMode *mode) {
+ return renderer()->GetDisplayMode(mode_id, mode);
+}
- void PluginObject::CancelFullscreenDisplay() {
- DCHECK(GetPluginHWnd());
- if (fullscreen_) {
- DCHECK(renderer());
- DCHECK(renderer()->fullscreen());
+// 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() {
+ bool success = false;
+ DCHECK(GetPluginHWnd());
+ if (!fullscreen_ && renderer_ && fullscreen_region_valid_) {
+ DCHECK(renderer_->fullscreen() == fullscreen_);
+ DCHECK(!GetFullscreenHWnd());
+ HWND drawing_hwnd =
+ CreateFullscreenWindow(this, fullscreen_region_mode_id_);
+ if (drawing_hwnd) {
::KillTimer(GetHWnd(), 0);
+ SetFullscreenHWnd(drawing_hwnd);
+ StorePluginPropertyUnsafe(drawing_hwnd, this);
+
DisplayWindowWindows display;
- display.set_hwnd(GetPluginHWnd());
- if (!renderer_->SetFullscreen(false, display, 0)) {
- LOG(FATAL) << "Failed to get the renderer out of fullscreen mode!";
+ display.set_hwnd(GetHWnd());
+ if (renderer_->SetFullscreen(true, display,
+ fullscreen_region_mode_id_)) {
+ fullscreen_ = true;
+ client()->SendResizeEvent(renderer_->width(), renderer_->height(),
+ true);
+ success = true;
+ } else {
+ CleanupFullscreenWindow(this);
}
- CleanupFullscreenWindow(this);
prev_width_ = renderer_->width();
prev_height_ = renderer_->height();
- client()->SendResizeEvent(prev_width_, prev_height_, false);
::SetTimer(GetHWnd(), 0, 10, NULL);
- fullscreen_ = false;
- }
- }
-
- NPError NPP_SetWindow(NPP instance, NPWindow *window) {
- HANDLE_CRASHES;
- PluginObject *obj = static_cast<PluginObject*>(instance->pdata);
-
- HWND hWnd = static_cast<HWND>(window->window);
- if (!hWnd) {
- // Chrome calls us this way before NPP_Destroy.
- if (obj->GetHWnd()) {
- CleanupAllWindows(obj);
- }
- return NPERR_NO_ERROR;
- }
- if (obj->GetHWnd() == hWnd) {
- return NPERR_NO_ERROR;
- }
- if (obj->fullscreen()) {
- // We can get here if the user alt+tabs away from the fullscreen plugin
- // window or JavaScript resizes the plugin window.
- DCHECK(obj->GetPluginHWnd());
- DCHECK(obj->GetFullscreenHWnd());
- DCHECK(obj->GetPluginHWnd() == hWnd);
- return NPERR_NO_ERROR;
+ } else {
+ LOG(ERROR) << "Failed to create fullscreen window.";
}
- DCHECK(!obj->GetPluginHWnd());
- obj->SetPluginHWnd(hWnd);
- obj->SetParentHWnd(::GetParent(hWnd));
- PluginObject::StorePluginProperty(hWnd, obj);
- obj->SetDefaultPluginWindowProc(
- reinterpret_cast<WNDPROC>(
- ::SetWindowLongPtr(hWnd,
- GWL_WNDPROC,
- reinterpret_cast<LONG_PTR>(WindowProc))));
-
- // create and assign the graphics context
- DisplayWindowWindows default_display;
- default_display.set_hwnd(obj->GetHWnd());
-
- obj->CreateRenderer(default_display);
- obj->client()->Init();
- obj->client()->SetRenderOnDemandCallback(
- new RenderOnDemandCallbackHandler(obj));
-
- // we set the timer to 10ms or 100fps. At the time of this comment
- // the renderer does a vsync the max fps it will run will be the refresh
- // rate of the monitor or 100fps, which ever is lower.
- ::SetTimer(obj->GetHWnd(), 0, 10, NULL);
-
- 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();
-
- stream_manager->SetStreamFile(stream, fname);
}
+ return success;
+}
- int16 NPP_HandleEvent(NPP instance, void *event) {
- HANDLE_CRASHES;
- return 0;
+void PluginObject::CancelFullscreenDisplay() {
+ DCHECK(GetPluginHWnd());
+ if (fullscreen_) {
+ DCHECK(renderer());
+ DCHECK(renderer()->fullscreen());
+ ::KillTimer(GetHWnd(), 0);
+ DisplayWindowWindows display;
+ display.set_hwnd(GetPluginHWnd());
+ if (!renderer_->SetFullscreen(false, display, 0)) {
+ LOG(FATAL) << "Failed to get the renderer out of fullscreen mode!";
+ }
+ CleanupFullscreenWindow(this);
+ prev_width_ = renderer_->width();
+ prev_height_ = renderer_->height();
+ client()->SendResizeEvent(prev_width_, prev_height_, false);
+ ::SetTimer(GetHWnd(), 0, 10, NULL);
+ fullscreen_ = false;
}
-} // end extern "C"
+}
+} // namespace _o3d
+} // namespace glue
diff --git a/o3d/plugin/win/update_lock.cc b/o3d/plugin/win/update_lock.cc
index 3900365..257aeb2 100644
--- a/o3d/plugin/win/update_lock.cc
+++ b/o3d/plugin/win/update_lock.cc
@@ -32,8 +32,12 @@
#include "update_lock.h"
+#if !defined(O3D_INTERNAL_PLUGIN)
+
namespace {
// Instantiate a global object to indicate that the application is running.
update_lock::HandleWrapper g_update_lock(update_lock::LockFromUpdates());
} // anonymous namespace
+
+#endif // O3D_INTERNAL_PLUGIN
diff --git a/o3d/plugin/win/update_lock.h b/o3d/plugin/win/update_lock.h
index dcf78ad..8e7b419 100644
--- a/o3d/plugin/win/update_lock.h
+++ b/o3d/plugin/win/update_lock.h
@@ -33,6 +33,8 @@
#ifndef O3D_PLUGIN_WIN_UPDATE_LOCK_H_
#define O3D_PLUGIN_WIN_UPDATE_LOCK_H_
+#if !defined(O3D_INTERNAL_PLUGIN)
+
#include <windows.h>
#include "base/basictypes.h"
@@ -96,5 +98,7 @@ HANDLE LockFromUpdates() {
}
} // namespace update_lock
+#endif // O3D_INTERNAL_PLUGIN
+
#endif // O3D_PLUGIN_WIN_UPDATE_LOCK_H_