Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Side by Side Diff: chrome/plugin/plugin_main.cc

Issue 113637: Wire up windowless plugins. Mostly Mac related, some cross (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/transport_dib_mac.cc ('k') | chrome/plugin/webplugin_delegate_stub.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include "app/win_util.h" 8 #include "app/win_util.h"
9 #endif 9 #endif
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/system_monitor.h" 13 #include "base/system_monitor.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/common/child_process.h" 15 #include "chrome/common/child_process.h"
16 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/logging_chrome.h" 18 #include "chrome/common/logging_chrome.h"
19 #include "chrome/common/main_function_params.h" 19 #include "chrome/common/main_function_params.h"
20 #include "chrome/plugin/plugin_thread.h" 20 #include "chrome/plugin/plugin_thread.h"
21 21
22 #if defined(OS_WIN) 22 #if defined(OS_WIN)
23 #include "chrome/test/injection_test_dll.h" 23 #include "chrome/test/injection_test_dll.h"
24 #include "sandbox/src/sandbox.h" 24 #include "sandbox/src/sandbox.h"
25 #elif defined(OS_LINUX) 25 #elif defined(OS_LINUX)
26 #include "chrome/common/chrome_descriptors.h" 26 #include "chrome/common/chrome_descriptors.h"
27 #include "base/global_descriptors_posix.h" 27 #include "base/global_descriptors_posix.h"
28 #endif 28 #endif
29 29
30 #if defined(OS_MACOSX)
31
32 // To support Mac NPAPI plugins that use the Carbon event model (i.e., most
33 // shipping plugins for MacOS X 10.5 and earlier), we need some way for the
34 // Carbon event dispatcher to run, even though the plugin host process itself
35 // does not use Carbon events. Rather than give control to the standard
36 // Carbon event loop, we schedule a periodic task on the main thread which
37 // empties the Carbon event queue every 20ms (chosen to match how often Safari
38 // does the equivalent operation). This allows plugins to receive idle events
39 // and schedule Carbon timers without swamping the CPU. If, in the future,
40 // we remove support for the Carbon event model and only support the Cocoa
41 // event model, this can be removed. Note that this approach does not install
42 // standard application event handlers for the menubar, AppleEvents, and so on.
43 // This is intentional, since the plugin process is not actually an application
44 // with its own UI elements--all rendering and event handling happens via IPC
45 // to the renderer process which invoked it.
46
47 namespace {
48
49 const int kPluginUpdateIntervalMs = 20; // 20ms = 50Hz
50
51 void PluginCarbonEventTask() {
52 EventRef theEvent;
53 EventTargetRef theTarget;
54
55 theTarget = GetEventDispatcherTarget();
56
57 // Dispatch any pending events. but do not block if there are no events.
58 while (ReceiveNextEvent(0, NULL, kEventDurationNoWait,
59 true, &theEvent) == noErr) {
60 SendEventToEventTarget (theEvent, theTarget);
61 ReleaseEvent(theEvent);
62 }
63
64 MessageLoop::current()->PostDelayedTask(FROM_HERE,
65 NewRunnableFunction(PluginCarbonEventTask), kPluginUpdateIntervalMs);
66 }
67
68 }
69 #endif
70
30 // main() routine for running as the plugin process. 71 // main() routine for running as the plugin process.
31 int PluginMain(const MainFunctionParams& parameters) { 72 int PluginMain(const MainFunctionParams& parameters) {
32 // The main thread of the plugin services IO. 73 // The main thread of the plugin services IO.
33 MessageLoopForIO main_message_loop; 74 MessageLoopForIO main_message_loop;
34 std::wstring app_name = chrome::kBrowserAppName; 75 std::wstring app_name = chrome::kBrowserAppName;
35 PlatformThread::SetName(WideToASCII(app_name + L"_PluginMain").c_str()); 76 PlatformThread::SetName(WideToASCII(app_name + L"_PluginMain").c_str());
36 77
37 // Initialize the SystemMonitor 78 // Initialize the SystemMonitor
38 base::SystemMonitor::Start(); 79 base::SystemMonitor::Start();
39 80
40 #if defined(OS_WIN)
41 const CommandLine& parsed_command_line = parameters.command_line_; 81 const CommandLine& parsed_command_line = parameters.command_line_;
42 82
83 #if defined(OS_WIN)
43 sandbox::TargetServices* target_services = 84 sandbox::TargetServices* target_services =
44 parameters.sandbox_info_.TargetServices(); 85 parameters.sandbox_info_.TargetServices();
45 86
46 CoInitialize(NULL); 87 CoInitialize(NULL);
47 DLOG(INFO) << "Started plugin with " << 88 DLOG(INFO) << "Started plugin with " <<
48 parsed_command_line.command_line_string(); 89 parsed_command_line.command_line_string();
49 90
50 HMODULE sandbox_test_module = NULL; 91 HMODULE sandbox_test_module = NULL;
51 bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox) || 92 bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox) ||
52 !parsed_command_line.HasSwitch(switches::kSafePlugins); 93 !parsed_command_line.HasSwitch(switches::kSafePlugins);
53 if (target_services && !no_sandbox) { 94 if (target_services && !no_sandbox) {
54 // The command line might specify a test plugin to load. 95 // The command line might specify a test plugin to load.
55 if (parsed_command_line.HasSwitch(switches::kTestSandbox)) { 96 if (parsed_command_line.HasSwitch(switches::kTestSandbox)) {
56 std::wstring test_plugin_name = 97 std::wstring test_plugin_name =
57 parsed_command_line.GetSwitchValue(switches::kTestSandbox); 98 parsed_command_line.GetSwitchValue(switches::kTestSandbox);
58 sandbox_test_module = LoadLibrary(test_plugin_name.c_str()); 99 sandbox_test_module = LoadLibrary(test_plugin_name.c_str());
59 DCHECK(sandbox_test_module); 100 DCHECK(sandbox_test_module);
60 } 101 }
61 } 102 }
62 103 #endif
63 if (parsed_command_line.HasSwitch(switches::kPluginStartupDialog)) { 104 if (parsed_command_line.HasSwitch(switches::kPluginStartupDialog)) {
105 #if defined(OS_WIN)
64 std::wstring title = chrome::kBrowserAppName; 106 std::wstring title = chrome::kBrowserAppName;
65 title += L" plugin"; // makes attaching to process easier 107 title += L" plugin"; // makes attaching to process easier
66 win_util::MessageBox(NULL, L"plugin starting...", title, 108 win_util::MessageBox(NULL, L"plugin starting...", title,
67 MB_OK | MB_SETFOREGROUND); 109 MB_OK | MB_SETFOREGROUND);
68 } 110 #elif defined(OS_MACOSX)
111 // TODO(playmobil): In the long term, overriding this flag doesn't seem
112 // right, either use our own flag or open a dialog we can use.
113 // This is just to ease debugging in the interim.
114 LOG(WARNING) << "Plugin ("
115 << getpid()
116 << ") paused waiting for debugger to attach @ pid";
117 pause();
69 #else 118 #else
70 NOTIMPLEMENTED() << " non-windows startup, plugin startup dialog etc."; 119 NOTIMPLEMENTED() << " non-windows startup, plugin startup dialog etc.";
71 #endif 120 #endif
121 }
122
123 #if defined(OS_MACOSX)
124 // Spin off a consumer for the native (Carbon) event stream so
125 // that plugin timers, event handlers, etc. will work properly.
126 MessageLoop::current()->PostDelayedTask(FROM_HERE,
127 NewRunnableFunction(PluginCarbonEventTask), kPluginUpdateIntervalMs);
128 #endif
72 129
73 { 130 {
74 ChildProcess plugin_process(new PluginThread()); 131 ChildProcess plugin_process(new PluginThread());
75 #if defined(OS_WIN) 132 #if defined(OS_WIN)
76 if (!no_sandbox && target_services) 133 if (!no_sandbox && target_services)
77 target_services->LowerToken(); 134 target_services->LowerToken();
78 135
79 if (sandbox_test_module) { 136 if (sandbox_test_module) {
80 RunRendererTests run_security_tests = 137 RunRendererTests run_security_tests =
81 reinterpret_cast<RunPluginTests>(GetProcAddress(sandbox_test_module, 138 reinterpret_cast<RunPluginTests>(GetProcAddress(sandbox_test_module,
(...skipping 13 matching lines...) Expand all
95 152
96 MessageLoop::current()->Run(); 153 MessageLoop::current()->Run();
97 } 154 }
98 155
99 #if defined(OS_WIN) 156 #if defined(OS_WIN)
100 CoUninitialize(); 157 CoUninitialize();
101 #endif 158 #endif
102 159
103 return 0; 160 return 0;
104 } 161 }
OLDNEW
« no previous file with comments | « chrome/common/transport_dib_mac.cc ('k') | chrome/plugin/webplugin_delegate_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698