OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/plugin_process_host.h" | 5 #include "content/browser/plugin_process_host.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
10 #include <utility> // for pair<> | 10 #include <utility> // for pair<> |
11 #endif | 11 #endif |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "app/app_switches.h" | 15 #include "app/app_switches.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/file_path.h" | 17 #include "base/file_path.h" |
18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/chrome_plugin_browsing_context.h" | 24 #include "chrome/browser/browser_thread.h" |
25 #include "chrome/browser/net/url_request_tracking.h" | 25 #include "chrome/browser/net/url_request_tracking.h" |
26 #include "chrome/browser/plugin_download_helper.h" | 26 #include "chrome/browser/plugin_download_helper.h" |
27 #include "chrome/browser/plugin_service.h" | 27 #include "chrome/browser/plugin_service.h" |
28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_plugin_lib.h" | |
31 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/logging_chrome.h" | 31 #include "chrome/common/logging_chrome.h" |
33 #include "chrome/common/net/url_request_context_getter.h" | 32 #include "chrome/common/net/url_request_context_getter.h" |
34 #include "chrome/common/plugin_messages.h" | 33 #include "chrome/common/plugin_messages.h" |
35 #include "chrome/common/render_messages.h" | 34 #include "chrome/common/render_messages.h" |
36 #include "chrome/common/render_messages_params.h" | 35 #include "chrome/common/render_messages_params.h" |
37 #include "content/browser/browser_thread.h" | 36 #include "content/browser/browser_thread.h" |
38 #include "content/browser/child_process_security_policy.h" | |
39 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 37 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
40 #include "content/browser/renderer_host/resource_message_filter.h" | 38 #include "content/browser/renderer_host/resource_message_filter.h" |
41 #include "ipc/ipc_switches.h" | 39 #include "ipc/ipc_switches.h" |
42 #include "net/base/cookie_store.h" | |
43 #include "net/base/io_buffer.h" | 40 #include "net/base/io_buffer.h" |
44 #include "net/url_request/url_request.h" | 41 #include "net/url_request/url_request.h" |
45 #include "net/url_request/url_request_context.h" | 42 #include "net/url_request/url_request_context.h" |
46 #include "ui/base/ui_base_switches.h" | 43 #include "ui/base/ui_base_switches.h" |
47 #include "ui/gfx/native_widget_types.h" | 44 #include "ui/gfx/native_widget_types.h" |
48 | 45 |
49 #if defined(USE_X11) | 46 #if defined(USE_X11) |
50 #include "ui/gfx/gtk_native_view_id_manager.h" | 47 #include "ui/gfx/gtk_native_view_id_manager.h" |
51 #endif | 48 #endif |
52 | 49 |
53 #if defined(OS_MACOSX) | 50 #if defined(OS_MACOSX) |
54 #include "base/mac/mac_util.h" | 51 #include "base/mac/mac_util.h" |
55 #include "chrome/common/plugin_carbon_interpose_constants_mac.h" | 52 #include "chrome/common/plugin_carbon_interpose_constants_mac.h" |
56 #include "ui/gfx/rect.h" | 53 #include "ui/gfx/rect.h" |
57 #endif | 54 #endif |
58 | 55 |
59 static const char kDefaultPluginFinderURL[] = | 56 static const char kDefaultPluginFinderURL[] = |
60 "https://dl-ssl.google.com/edgedl/chrome/plugins/plugins2.xml"; | 57 "https://dl-ssl.google.com/edgedl/chrome/plugins/plugins2.xml"; |
61 | 58 |
62 namespace { | |
63 | |
64 // Helper class that we pass to ResourceMessageFilter so that it can find the | |
65 // right net::URLRequestContext for a request. | |
66 class PluginURLRequestContextOverride | |
67 : public ResourceMessageFilter::URLRequestContextOverride { | |
68 public: | |
69 PluginURLRequestContextOverride() { | |
70 } | |
71 | |
72 virtual net::URLRequestContext* GetRequestContext( | |
73 const ViewHostMsg_Resource_Request& resource_request) { | |
jam
2011/02/25 22:19:33
one minor change that could be done now: GetReques
Aaron Boodman
2011/02/25 22:48:28
You mean "resource type"? If so, done.
| |
74 return CPBrowsingContextManager::GetInstance()->ToURLRequestContext( | |
75 resource_request.request_context); | |
76 } | |
77 | |
78 private: | |
79 virtual ~PluginURLRequestContextOverride() {} | |
80 }; | |
81 | |
82 } // namespace | |
83 | |
84 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
85 void PluginProcessHost::OnPluginWindowDestroyed(HWND window, HWND parent) { | 60 void PluginProcessHost::OnPluginWindowDestroyed(HWND window, HWND parent) { |
86 // The window is destroyed at this point, we just care about its parent, which | 61 // The window is destroyed at this point, we just care about its parent, which |
87 // is the intermediate window we created. | 62 // is the intermediate window we created. |
88 std::set<HWND>::iterator window_index = | 63 std::set<HWND>::iterator window_index = |
89 plugin_parent_windows_set_.find(parent); | 64 plugin_parent_windows_set_.find(parent); |
90 if (window_index == plugin_parent_windows_set_.end()) | 65 if (window_index == plugin_parent_windows_set_.end()) |
91 return; | 66 return; |
92 | 67 |
93 plugin_parent_windows_set_.erase(window_index); | 68 plugin_parent_windows_set_.erase(window_index); |
(...skipping 19 matching lines...) Expand all Loading... | |
113 void PluginProcessHost::OnMapNativeViewId(gfx::NativeViewId id, | 88 void PluginProcessHost::OnMapNativeViewId(gfx::NativeViewId id, |
114 gfx::PluginWindowHandle* output) { | 89 gfx::PluginWindowHandle* output) { |
115 *output = 0; | 90 *output = 0; |
116 GtkNativeViewManager::GetInstance()->GetXIDForId(output, id); | 91 GtkNativeViewManager::GetInstance()->GetXIDForId(output, id); |
117 } | 92 } |
118 #endif // defined(TOOLKIT_USES_GTK) | 93 #endif // defined(TOOLKIT_USES_GTK) |
119 | 94 |
120 PluginProcessHost::PluginProcessHost() | 95 PluginProcessHost::PluginProcessHost() |
121 : BrowserChildProcessHost( | 96 : BrowserChildProcessHost( |
122 PLUGIN_PROCESS, | 97 PLUGIN_PROCESS, |
123 PluginService::GetInstance()->resource_dispatcher_host(), | 98 PluginService::GetInstance()->resource_dispatcher_host()), |
124 new PluginURLRequestContextOverride()), | |
125 ALLOW_THIS_IN_INITIALIZER_LIST(resolve_proxy_msg_helper_(this, NULL)) | 99 ALLOW_THIS_IN_INITIALIZER_LIST(resolve_proxy_msg_helper_(this, NULL)) |
126 #if defined(OS_MACOSX) | 100 #if defined(OS_MACOSX) |
127 , plugin_cursor_visible_(true) | 101 , plugin_cursor_visible_(true) |
128 #endif | 102 #endif |
129 { | 103 { |
130 } | 104 } |
131 | 105 |
132 PluginProcessHost::~PluginProcessHost() { | 106 PluginProcessHost::~PluginProcessHost() { |
133 #if defined(OS_WIN) | 107 #if defined(OS_WIN) |
134 // We erase HWNDs from the plugin_parent_windows_set_ when we receive a | 108 // We erase HWNDs from the plugin_parent_windows_set_ when we receive a |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 // If specified, prepend a launcher program to the command line. | 209 // If specified, prepend a launcher program to the command line. |
236 if (!plugin_launcher.empty()) | 210 if (!plugin_launcher.empty()) |
237 cmd_line->PrependWrapper(plugin_launcher); | 211 cmd_line->PrependWrapper(plugin_launcher); |
238 | 212 |
239 if (!locale.empty()) { | 213 if (!locale.empty()) { |
240 // Pass on the locale so the null plugin will use the right language in the | 214 // Pass on the locale so the null plugin will use the right language in the |
241 // prompt to install the desired plugin. | 215 // prompt to install the desired plugin. |
242 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 216 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
243 } | 217 } |
244 | 218 |
245 // Gears requires the data dir to be available on startup. | |
246 FilePath data_dir = | |
247 PluginService::GetInstance()->GetChromePluginDataDir(); | |
248 DCHECK(!data_dir.empty()); | |
249 cmd_line->AppendSwitchPath(switches::kPluginDataDir, data_dir); | |
250 | |
251 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id()); | 219 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id()); |
252 | 220 |
253 SetCrashReporterCommandLine(cmd_line); | 221 SetCrashReporterCommandLine(cmd_line); |
254 | 222 |
255 #if defined(OS_POSIX) | 223 #if defined(OS_POSIX) |
256 base::environment_vector env; | 224 base::environment_vector env; |
257 #if defined(OS_MACOSX) && !defined(__LP64__) | 225 #if defined(OS_MACOSX) && !defined(__LP64__) |
258 // Add our interposing library for Carbon. This is stripped back out in | 226 // Add our interposing library for Carbon. This is stripped back out in |
259 // plugin_main.cc, so changes here should be reflected there. | 227 // plugin_main.cc, so changes here should be reflected there. |
260 std::string interpose_list(plugin_interpose_strings::kInterposeLibraryPath); | 228 std::string interpose_list(plugin_interpose_strings::kInterposeLibraryPath); |
(...skipping 20 matching lines...) Expand all Loading... | |
281 | 249 |
282 return true; | 250 return true; |
283 } | 251 } |
284 | 252 |
285 void PluginProcessHost::ForceShutdown() { | 253 void PluginProcessHost::ForceShutdown() { |
286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
287 Send(new PluginProcessMsg_NotifyRenderersOfPendingShutdown()); | 255 Send(new PluginProcessMsg_NotifyRenderersOfPendingShutdown()); |
288 BrowserChildProcessHost::ForceShutdown(); | 256 BrowserChildProcessHost::ForceShutdown(); |
289 } | 257 } |
290 | 258 |
291 void PluginProcessHost::OnProcessLaunched() { | |
292 FilePath gears_path; | |
293 if (PathService::Get(chrome::FILE_GEARS_PLUGIN, &gears_path)) { | |
294 FilePath::StringType gears_path_lc = StringToLowerASCII(gears_path.value()); | |
295 FilePath::StringType plugin_path_lc = | |
296 StringToLowerASCII(info_.path.value()); | |
297 if (plugin_path_lc == gears_path_lc) { | |
298 // Give Gears plugins "background" priority. See http://b/1280317. | |
299 SetProcessBackgrounded(); | |
300 } | |
301 } | |
302 } | |
303 | |
304 bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { | 259 bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { |
305 bool handled = true; | 260 bool handled = true; |
306 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) | 261 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) |
307 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) | 262 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) |
308 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetPluginFinderUrl, | 263 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetPluginFinderUrl, |
309 OnGetPluginFinderUrl) | 264 OnGetPluginFinderUrl) |
310 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginMessage, OnPluginMessage) | |
311 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetCookies, OnGetCookies) | |
312 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_AccessFiles, OnAccessFiles) | |
313 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy, | 265 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy, |
314 OnResolveProxy) | 266 OnResolveProxy) |
315 #if defined(OS_WIN) | 267 #if defined(OS_WIN) |
316 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, | 268 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, |
317 OnPluginWindowDestroyed) | 269 OnPluginWindowDestroyed) |
318 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DownloadUrl, OnDownloadUrl) | 270 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DownloadUrl, OnDownloadUrl) |
319 #endif | 271 #endif |
320 #if defined(TOOLKIT_USES_GTK) | 272 #if defined(TOOLKIT_USES_GTK) |
321 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, | 273 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, |
322 OnMapNativeViewId) | 274 OnMapNativeViewId) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 // this "open channel" request into a queue of requests that will | 325 // this "open channel" request into a queue of requests that will |
374 // be run once the channel is open. | 326 // be run once the channel is open. |
375 pending_requests_.push_back(client); | 327 pending_requests_.push_back(client); |
376 return; | 328 return; |
377 } | 329 } |
378 | 330 |
379 // We already have an open channel, send a request right away to plugin. | 331 // We already have an open channel, send a request right away to plugin. |
380 RequestPluginChannel(client); | 332 RequestPluginChannel(client); |
381 } | 333 } |
382 | 334 |
383 void PluginProcessHost::OnGetCookies(uint32 request_context, | |
384 const GURL& url, | |
385 std::string* cookies) { | |
386 net::URLRequestContext* context = CPBrowsingContextManager::GetInstance()-> | |
387 ToURLRequestContext(request_context); | |
388 // TODO(mpcomplete): remove fallback case when Gears support is prevalent. | |
389 if (!context) | |
390 context = Profile::GetDefaultRequestContext()->GetURLRequestContext(); | |
391 | |
392 // Note: We don't have a first_party_for_cookies check because plugins bypass | |
393 // third-party cookie blocking. | |
394 if (context && context->cookie_store()) { | |
395 *cookies = context->cookie_store()->GetCookies(url); | |
396 } else { | |
397 DLOG(ERROR) << "Could not serve plugin cookies request."; | |
398 cookies->clear(); | |
399 } | |
400 } | |
401 | |
402 void PluginProcessHost::OnAccessFiles(int renderer_id, | |
403 const std::vector<std::string>& files, | |
404 bool* allowed) { | |
405 ChildProcessSecurityPolicy* policy = | |
406 ChildProcessSecurityPolicy::GetInstance(); | |
407 | |
408 for (size_t i = 0; i < files.size(); ++i) { | |
409 const FilePath path = FilePath::FromWStringHack(UTF8ToWide(files[i])); | |
410 if (!policy->CanReadFile(renderer_id, path)) { | |
411 VLOG(1) << "Denied unauthorized request for file " << files[i]; | |
412 *allowed = false; | |
413 return; | |
414 } | |
415 } | |
416 | |
417 *allowed = true; | |
418 } | |
419 | |
420 void PluginProcessHost::OnResolveProxy(const GURL& url, | 335 void PluginProcessHost::OnResolveProxy(const GURL& url, |
421 IPC::Message* reply_msg) { | 336 IPC::Message* reply_msg) { |
422 resolve_proxy_msg_helper_.Start(url, reply_msg); | 337 resolve_proxy_msg_helper_.Start(url, reply_msg); |
423 } | 338 } |
424 | 339 |
425 void PluginProcessHost::OnResolveProxyCompleted(IPC::Message* reply_msg, | 340 void PluginProcessHost::OnResolveProxyCompleted(IPC::Message* reply_msg, |
426 int result, | 341 int result, |
427 const std::string& proxy_list) { | 342 const std::string& proxy_list) { |
428 PluginProcessHostMsg_ResolveProxy::WriteReplyParams( | 343 PluginProcessHostMsg_ResolveProxy::WriteReplyParams( |
429 reply_msg, result, proxy_list); | 344 reply_msg, result, proxy_list); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 } | 378 } |
464 | 379 |
465 if (!g_browser_process->plugin_finder_disabled()) { | 380 if (!g_browser_process->plugin_finder_disabled()) { |
466 // TODO(iyengar): Add the plumbing to retrieve the default | 381 // TODO(iyengar): Add the plumbing to retrieve the default |
467 // plugin finder URL. | 382 // plugin finder URL. |
468 *plugin_finder_url = kDefaultPluginFinderURL; | 383 *plugin_finder_url = kDefaultPluginFinderURL; |
469 } else { | 384 } else { |
470 plugin_finder_url->clear(); | 385 plugin_finder_url->clear(); |
471 } | 386 } |
472 } | 387 } |
473 | |
474 void PluginProcessHost::OnPluginMessage( | |
475 const std::vector<uint8>& data) { | |
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
477 | |
478 ChromePluginLib *chrome_plugin = ChromePluginLib::Find(info_.path); | |
479 if (chrome_plugin) { | |
480 void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); | |
481 uint32 data_len = static_cast<uint32>(data.size()); | |
482 chrome_plugin->functions().on_message(data_ptr, data_len); | |
483 } | |
484 } | |
OLD | NEW |