OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ppapi_plugin_process_host.h" | 5 #include "content/browser/ppapi_plugin_process_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "content/browser/browser_child_process_host_impl.h" | 20 #include "content/browser/browser_child_process_host_impl.h" |
21 #include "content/browser/plugin_service_impl.h" | 21 #include "content/browser/plugin_service_impl.h" |
22 #include "content/browser/renderer_host/render_message_filter.h" | 22 #include "content/browser/renderer_host/render_message_filter.h" |
23 #include "content/common/child_process_host_impl.h" | 23 #include "content/common/child_process_host_impl.h" |
24 #include "content/common/child_process_messages.h" | 24 #include "content/common/child_process_messages.h" |
25 #include "content/common/content_switches_internal.h" | 25 #include "content/common/content_switches_internal.h" |
26 #include "content/common/mojo/constants.h" | |
27 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
28 #include "content/public/common/content_constants.h" | 27 #include "content/public/common/content_constants.h" |
29 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
30 #include "content/public/common/mojo_channel_switches.h" | 29 #include "content/public/common/mojo_channel_switches.h" |
31 #include "content/public/common/pepper_plugin_info.h" | 30 #include "content/public/common/pepper_plugin_info.h" |
32 #include "content/public/common/process_type.h" | 31 #include "content/public/common/process_type.h" |
33 #include "content/public/common/sandbox_type.h" | 32 #include "content/public/common/sandbox_type.h" |
34 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 33 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
35 #include "ipc/ipc_switches.h" | 34 #include "ipc/ipc_switches.h" |
36 #include "mojo/edk/embedder/embedder.h" | 35 #include "mojo/edk/embedder/embedder.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 311 } |
313 | 312 |
314 // We already have an open channel, send a request right away to plugin. | 313 // We already have an open channel, send a request right away to plugin. |
315 RequestPluginChannel(client); | 314 RequestPluginChannel(client); |
316 } | 315 } |
317 | 316 |
318 PpapiPluginProcessHost::PpapiPluginProcessHost( | 317 PpapiPluginProcessHost::PpapiPluginProcessHost( |
319 const PepperPluginInfo& info, | 318 const PepperPluginInfo& info, |
320 const base::FilePath& profile_data_directory) | 319 const base::FilePath& profile_data_directory) |
321 : profile_data_directory_(profile_data_directory), | 320 : profile_data_directory_(profile_data_directory), |
322 is_broker_(false) { | 321 is_broker_(false), |
| 322 mojo_child_token_(mojo::edk::GenerateRandomToken()) { |
323 uint32_t base_permissions = info.permissions; | 323 uint32_t base_permissions = info.permissions; |
324 | 324 |
325 // We don't have to do any whitelisting for APIs in this process host, so | 325 // We don't have to do any whitelisting for APIs in this process host, so |
326 // don't bother passing a browser context or document url here. | 326 // don't bother passing a browser context or document url here. |
327 if (GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( | 327 if (GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( |
328 NULL, GURL())) | 328 NULL, GURL())) |
329 base_permissions |= ppapi::PERMISSION_DEV_CHANNEL; | 329 base_permissions |= ppapi::PERMISSION_DEV_CHANNEL; |
330 permissions_ = ppapi::PpapiPermissions::GetForCommandLine(base_permissions); | 330 permissions_ = ppapi::PpapiPermissions::GetForCommandLine(base_permissions); |
331 | 331 |
332 process_.reset(new BrowserChildProcessHostImpl( | 332 process_.reset(new BrowserChildProcessHostImpl( |
333 PROCESS_TYPE_PPAPI_PLUGIN, this, kPluginMojoApplicationName)); | 333 PROCESS_TYPE_PPAPI_PLUGIN, this, mojo_child_token_)); |
334 | 334 |
335 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions_, info.name, | 335 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions_, info.name, |
336 info.path, profile_data_directory, | 336 info.path, profile_data_directory, |
337 false /* in_process */, | 337 false /* in_process */, |
338 false /* external_plugin */)); | 338 false /* external_plugin */)); |
339 | 339 |
340 filter_ = new PepperMessageFilter(); | 340 filter_ = new PepperMessageFilter(); |
341 process_->AddFilter(filter_.get()); | 341 process_->AddFilter(filter_.get()); |
342 process_->GetHost()->AddFilter(host_impl_->message_filter().get()); | 342 process_->GetHost()->AddFilter(host_impl_->message_filter().get()); |
343 #if defined(OS_WIN) | 343 #if defined(OS_WIN) |
344 process_->AddFilter(new DWriteFontProxyMessageFilter()); | 344 process_->AddFilter(new DWriteFontProxyMessageFilter()); |
345 #endif | 345 #endif |
346 | 346 |
347 GetContentClient()->browser()->DidCreatePpapiPlugin(host_impl_.get()); | 347 GetContentClient()->browser()->DidCreatePpapiPlugin(host_impl_.get()); |
348 | 348 |
349 // Only request network status updates if the plugin has dev permissions. | 349 // Only request network status updates if the plugin has dev permissions. |
350 if (permissions_.HasPermission(ppapi::PERMISSION_DEV)) | 350 if (permissions_.HasPermission(ppapi::PERMISSION_DEV)) |
351 network_observer_.reset(new PluginNetworkObserver(this)); | 351 network_observer_.reset(new PluginNetworkObserver(this)); |
352 } | 352 } |
353 | 353 |
354 PpapiPluginProcessHost::PpapiPluginProcessHost() : is_broker_(true) { | 354 PpapiPluginProcessHost::PpapiPluginProcessHost() |
| 355 : is_broker_(true), |
| 356 mojo_child_token_(mojo::edk::GenerateRandomToken()) { |
355 process_.reset(new BrowserChildProcessHostImpl( | 357 process_.reset(new BrowserChildProcessHostImpl( |
356 PROCESS_TYPE_PPAPI_BROKER, this, kPluginMojoApplicationName)); | 358 PROCESS_TYPE_PPAPI_BROKER, this, mojo_child_token_)); |
357 | 359 |
358 ppapi::PpapiPermissions permissions; // No permissions. | 360 ppapi::PpapiPermissions permissions; // No permissions. |
359 // The plugin name, path and profile data directory shouldn't be needed for | 361 // The plugin name, path and profile data directory shouldn't be needed for |
360 // the broker. | 362 // the broker. |
361 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions, | 363 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions, |
362 std::string(), base::FilePath(), | 364 std::string(), base::FilePath(), |
363 base::FilePath(), | 365 base::FilePath(), |
364 false /* in_process */, | 366 false /* in_process */, |
365 false /* external_plugin */)); | 367 false /* external_plugin */)); |
366 } | 368 } |
367 | 369 |
368 bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) { | 370 bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) { |
369 plugin_path_ = info.path; | 371 plugin_path_ = info.path; |
370 if (info.name.empty()) { | 372 if (info.name.empty()) { |
371 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); | 373 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); |
372 } else { | 374 } else { |
373 process_->SetName(base::UTF8ToUTF16(info.name)); | 375 process_->SetName(base::UTF8ToUTF16(info.name)); |
374 } | 376 } |
375 | 377 |
376 process_->GetHost()->CreateChannelMojo(); | 378 std::string mojo_channel_token = |
| 379 process_->GetHost()->CreateChannelMojo(mojo_child_token_); |
| 380 if (mojo_channel_token.empty()) { |
| 381 VLOG(1) << "Could not create pepper host channel."; |
| 382 return false; |
| 383 } |
377 | 384 |
378 const base::CommandLine& browser_command_line = | 385 const base::CommandLine& browser_command_line = |
379 *base::CommandLine::ForCurrentProcess(); | 386 *base::CommandLine::ForCurrentProcess(); |
380 base::CommandLine::StringType plugin_launcher = | 387 base::CommandLine::StringType plugin_launcher = |
381 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); | 388 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); |
382 | 389 |
383 #if defined(OS_LINUX) | 390 #if defined(OS_LINUX) |
384 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : | 391 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : |
385 ChildProcessHost::CHILD_NORMAL; | 392 ChildProcessHost::CHILD_NORMAL; |
386 #else | 393 #else |
387 int flags = ChildProcessHost::CHILD_NORMAL; | 394 int flags = ChildProcessHost::CHILD_NORMAL; |
388 #endif | 395 #endif |
389 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); | 396 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); |
390 if (exe_path.empty()) { | 397 if (exe_path.empty()) { |
391 VLOG(1) << "Pepper plugin exe path is empty."; | 398 VLOG(1) << "Pepper plugin exe path is empty."; |
392 return false; | 399 return false; |
393 } | 400 } |
394 | 401 |
395 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 402 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
396 cmd_line->AppendSwitchASCII(switches::kProcessType, | 403 cmd_line->AppendSwitchASCII(switches::kProcessType, |
397 is_broker_ ? switches::kPpapiBrokerProcess | 404 is_broker_ ? switches::kPpapiBrokerProcess |
398 : switches::kPpapiPluginProcess); | 405 : switches::kPpapiPluginProcess); |
| 406 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); |
399 | 407 |
400 #if defined(OS_WIN) | 408 #if defined(OS_WIN) |
401 cmd_line->AppendArg(is_broker_ ? switches::kPrefetchArgumentPpapiBroker | 409 cmd_line->AppendArg(is_broker_ ? switches::kPrefetchArgumentPpapiBroker |
402 : switches::kPrefetchArgumentPpapi); | 410 : switches::kPrefetchArgumentPpapi); |
403 #endif // defined(OS_WIN) | 411 #endif // defined(OS_WIN) |
404 | 412 |
405 // These switches are forwarded to both plugin and broker pocesses. | 413 // These switches are forwarded to both plugin and broker pocesses. |
406 static const char* const kCommonForwardSwitches[] = { | 414 static const char* const kCommonForwardSwitches[] = { |
407 switches::kVModule | 415 switches::kVModule |
408 }; | 416 }; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 // sent_requests_ queue should be the one that the plugin just created. | 560 // sent_requests_ queue should be the one that the plugin just created. |
553 Client* client = sent_requests_.front(); | 561 Client* client = sent_requests_.front(); |
554 sent_requests_.pop(); | 562 sent_requests_.pop(); |
555 | 563 |
556 const ChildProcessData& data = process_->GetData(); | 564 const ChildProcessData& data = process_->GetData(); |
557 client->OnPpapiChannelOpened(channel_handle, base::GetProcId(data.handle), | 565 client->OnPpapiChannelOpened(channel_handle, base::GetProcId(data.handle), |
558 data.id); | 566 data.id); |
559 } | 567 } |
560 | 568 |
561 } // namespace content | 569 } // namespace content |
OLD | NEW |