summaryrefslogtreecommitdiffstats
path: root/chrome/plugin/plugin_main.cc
diff options
context:
space:
mode:
authoramanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-11 01:57:28 +0000
committeramanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-11 01:57:28 +0000
commit6bf1a81cdfcc48f20cf53c2601f4456f2d9d30ef (patch)
tree7bedf19228a20b83189ab96e617e72210991c7c4 /chrome/plugin/plugin_main.cc
parent7e05f6c4baad4f81e06835b83febe2784568ebe1 (diff)
downloadchromium_src-6bf1a81cdfcc48f20cf53c2601f4456f2d9d30ef.zip
chromium_src-6bf1a81cdfcc48f20cf53c2601f4456f2d9d30ef.tar.gz
chromium_src-6bf1a81cdfcc48f20cf53c2601f4456f2d9d30ef.tar.bz2
Wire up windowless plugins. Mostly Mac related, some cross
platform aspects. BUG=10809 TEST=none Review URL: http://codereview.chromium.org/113637 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20453 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/plugin/plugin_main.cc')
-rw-r--r--chrome/plugin/plugin_main.cc63
1 files changed, 60 insertions, 3 deletions
diff --git a/chrome/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc
index fb8880f..4cc7911 100644
--- a/chrome/plugin/plugin_main.cc
+++ b/chrome/plugin/plugin_main.cc
@@ -27,6 +27,47 @@
#include "base/global_descriptors_posix.h"
#endif
+#if defined(OS_MACOSX)
+
+// To support Mac NPAPI plugins that use the Carbon event model (i.e., most
+// shipping plugins for MacOS X 10.5 and earlier), we need some way for the
+// Carbon event dispatcher to run, even though the plugin host process itself
+// does not use Carbon events. Rather than give control to the standard
+// Carbon event loop, we schedule a periodic task on the main thread which
+// empties the Carbon event queue every 20ms (chosen to match how often Safari
+// does the equivalent operation). This allows plugins to receive idle events
+// and schedule Carbon timers without swamping the CPU. If, in the future,
+// we remove support for the Carbon event model and only support the Cocoa
+// event model, this can be removed. Note that this approach does not install
+// standard application event handlers for the menubar, AppleEvents, and so on.
+// This is intentional, since the plugin process is not actually an application
+// with its own UI elements--all rendering and event handling happens via IPC
+// to the renderer process which invoked it.
+
+namespace {
+
+const int kPluginUpdateIntervalMs = 20; // 20ms = 50Hz
+
+void PluginCarbonEventTask() {
+ EventRef theEvent;
+ EventTargetRef theTarget;
+
+ theTarget = GetEventDispatcherTarget();
+
+ // Dispatch any pending events. but do not block if there are no events.
+ while (ReceiveNextEvent(0, NULL, kEventDurationNoWait,
+ true, &theEvent) == noErr) {
+ SendEventToEventTarget (theEvent, theTarget);
+ ReleaseEvent(theEvent);
+ }
+
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ NewRunnableFunction(PluginCarbonEventTask), kPluginUpdateIntervalMs);
+}
+
+}
+#endif
+
// main() routine for running as the plugin process.
int PluginMain(const MainFunctionParams& parameters) {
// The main thread of the plugin services IO.
@@ -37,9 +78,9 @@ int PluginMain(const MainFunctionParams& parameters) {
// Initialize the SystemMonitor
base::SystemMonitor::Start();
-#if defined(OS_WIN)
const CommandLine& parsed_command_line = parameters.command_line_;
+#if defined(OS_WIN)
sandbox::TargetServices* target_services =
parameters.sandbox_info_.TargetServices();
@@ -59,16 +100,32 @@ int PluginMain(const MainFunctionParams& parameters) {
DCHECK(sandbox_test_module);
}
}
-
+#endif
if (parsed_command_line.HasSwitch(switches::kPluginStartupDialog)) {
+#if defined(OS_WIN)
std::wstring title = chrome::kBrowserAppName;
title += L" plugin"; // makes attaching to process easier
win_util::MessageBox(NULL, L"plugin starting...", title,
MB_OK | MB_SETFOREGROUND);
- }
+#elif defined(OS_MACOSX)
+ // TODO(playmobil): In the long term, overriding this flag doesn't seem
+ // right, either use our own flag or open a dialog we can use.
+ // This is just to ease debugging in the interim.
+ LOG(WARNING) << "Plugin ("
+ << getpid()
+ << ") paused waiting for debugger to attach @ pid";
+ pause();
#else
NOTIMPLEMENTED() << " non-windows startup, plugin startup dialog etc.";
#endif
+ }
+
+#if defined(OS_MACOSX)
+ // Spin off a consumer for the native (Carbon) event stream so
+ // that plugin timers, event handlers, etc. will work properly.
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ NewRunnableFunction(PluginCarbonEventTask), kPluginUpdateIntervalMs);
+#endif
{
ChildProcess plugin_process(new PluginThread());