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/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/common/content_constants.h" | 27 #include "content/public/common/content_constants.h" |
28 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
| 29 #include "content/public/common/mojo_channel_switches.h" |
29 #include "content/public/common/pepper_plugin_info.h" | 30 #include "content/public/common/pepper_plugin_info.h" |
30 #include "content/public/common/process_type.h" | 31 #include "content/public/common/process_type.h" |
31 #include "content/public/common/sandbox_type.h" | 32 #include "content/public/common/sandbox_type.h" |
32 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 33 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
33 #include "ipc/ipc_switches.h" | 34 #include "ipc/ipc_switches.h" |
34 #include "mojo/edk/embedder/embedder.h" | 35 #include "mojo/edk/embedder/embedder.h" |
35 #include "net/base/network_change_notifier.h" | 36 #include "net/base/network_change_notifier.h" |
36 #include "ppapi/proxy/ppapi_messages.h" | 37 #include "ppapi/proxy/ppapi_messages.h" |
37 #include "ui/base/ui_base_switches.h" | 38 #include "ui/base/ui_base_switches.h" |
38 | 39 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 311 } |
311 | 312 |
312 // 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. |
313 RequestPluginChannel(client); | 314 RequestPluginChannel(client); |
314 } | 315 } |
315 | 316 |
316 PpapiPluginProcessHost::PpapiPluginProcessHost( | 317 PpapiPluginProcessHost::PpapiPluginProcessHost( |
317 const PepperPluginInfo& info, | 318 const PepperPluginInfo& info, |
318 const base::FilePath& profile_data_directory) | 319 const base::FilePath& profile_data_directory) |
319 : profile_data_directory_(profile_data_directory), | 320 : profile_data_directory_(profile_data_directory), |
320 is_broker_(false) { | 321 is_broker_(false), |
| 322 mojo_child_token_(mojo::edk::GenerateRandomToken()) { |
321 uint32_t base_permissions = info.permissions; | 323 uint32_t base_permissions = info.permissions; |
322 | 324 |
323 // 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 |
324 // don't bother passing a browser context or document url here. | 326 // don't bother passing a browser context or document url here. |
325 if (GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( | 327 if (GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( |
326 NULL, GURL())) | 328 NULL, GURL())) |
327 base_permissions |= ppapi::PERMISSION_DEV_CHANNEL; | 329 base_permissions |= ppapi::PERMISSION_DEV_CHANNEL; |
328 permissions_ = ppapi::PpapiPermissions::GetForCommandLine(base_permissions); | 330 permissions_ = ppapi::PpapiPermissions::GetForCommandLine(base_permissions); |
329 | 331 |
330 process_.reset(new BrowserChildProcessHostImpl( | 332 process_.reset(new BrowserChildProcessHostImpl( |
331 PROCESS_TYPE_PPAPI_PLUGIN, this, mojo::edk::GenerateRandomToken())); | 333 PROCESS_TYPE_PPAPI_PLUGIN, this, mojo_child_token_)); |
332 | 334 |
333 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions_, info.name, | 335 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions_, info.name, |
334 info.path, profile_data_directory, | 336 info.path, profile_data_directory, |
335 false /* in_process */, | 337 false /* in_process */, |
336 false /* external_plugin */)); | 338 false /* external_plugin */)); |
337 | 339 |
338 filter_ = new PepperMessageFilter(); | 340 filter_ = new PepperMessageFilter(); |
339 process_->AddFilter(filter_.get()); | 341 process_->AddFilter(filter_.get()); |
340 process_->GetHost()->AddFilter(host_impl_->message_filter().get()); | 342 process_->GetHost()->AddFilter(host_impl_->message_filter().get()); |
341 #if defined(OS_WIN) | 343 #if defined(OS_WIN) |
342 process_->AddFilter(new DWriteFontProxyMessageFilter()); | 344 process_->AddFilter(new DWriteFontProxyMessageFilter()); |
343 #endif | 345 #endif |
344 | 346 |
345 GetContentClient()->browser()->DidCreatePpapiPlugin(host_impl_.get()); | 347 GetContentClient()->browser()->DidCreatePpapiPlugin(host_impl_.get()); |
346 | 348 |
347 // Only request network status updates if the plugin has dev permissions. | 349 // Only request network status updates if the plugin has dev permissions. |
348 if (permissions_.HasPermission(ppapi::PERMISSION_DEV)) | 350 if (permissions_.HasPermission(ppapi::PERMISSION_DEV)) |
349 network_observer_.reset(new PluginNetworkObserver(this)); | 351 network_observer_.reset(new PluginNetworkObserver(this)); |
350 } | 352 } |
351 | 353 |
352 PpapiPluginProcessHost::PpapiPluginProcessHost() | 354 PpapiPluginProcessHost::PpapiPluginProcessHost() |
353 : is_broker_(true) { | 355 : is_broker_(true), |
| 356 mojo_child_token_(mojo::edk::GenerateRandomToken()) { |
354 process_.reset(new BrowserChildProcessHostImpl( | 357 process_.reset(new BrowserChildProcessHostImpl( |
355 PROCESS_TYPE_PPAPI_BROKER, this, mojo::edk::GenerateRandomToken())); | 358 PROCESS_TYPE_PPAPI_BROKER, this, mojo_child_token_)); |
356 | 359 |
357 ppapi::PpapiPermissions permissions; // No permissions. | 360 ppapi::PpapiPermissions permissions; // No permissions. |
358 // 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 |
359 // the broker. | 362 // the broker. |
360 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions, | 363 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions, |
361 std::string(), base::FilePath(), | 364 std::string(), base::FilePath(), |
362 base::FilePath(), | 365 base::FilePath(), |
363 false /* in_process */, | 366 false /* in_process */, |
364 false /* external_plugin */)); | 367 false /* external_plugin */)); |
365 } | 368 } |
366 | 369 |
367 bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) { | 370 bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) { |
368 plugin_path_ = info.path; | 371 plugin_path_ = info.path; |
369 if (info.name.empty()) { | 372 if (info.name.empty()) { |
370 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); | 373 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); |
371 } else { | 374 } else { |
372 process_->SetName(base::UTF8ToUTF16(info.name)); | 375 process_->SetName(base::UTF8ToUTF16(info.name)); |
373 } | 376 } |
374 | 377 |
375 std::string channel_id = process_->GetHost()->CreateChannel(); | 378 std::string mojo_channel_token = |
376 if (channel_id.empty()) { | 379 process_->GetHost()->CreateChannelMojo(mojo_child_token_); |
| 380 if (mojo_channel_token.empty()) { |
377 VLOG(1) << "Could not create pepper host channel."; | 381 VLOG(1) << "Could not create pepper host channel."; |
378 return false; | 382 return false; |
379 } | 383 } |
380 | 384 |
381 const base::CommandLine& browser_command_line = | 385 const base::CommandLine& browser_command_line = |
382 *base::CommandLine::ForCurrentProcess(); | 386 *base::CommandLine::ForCurrentProcess(); |
383 base::CommandLine::StringType plugin_launcher = | 387 base::CommandLine::StringType plugin_launcher = |
384 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); | 388 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); |
385 | 389 |
386 #if defined(OS_LINUX) | 390 #if defined(OS_LINUX) |
387 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : | 391 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : |
388 ChildProcessHost::CHILD_NORMAL; | 392 ChildProcessHost::CHILD_NORMAL; |
389 #else | 393 #else |
390 int flags = ChildProcessHost::CHILD_NORMAL; | 394 int flags = ChildProcessHost::CHILD_NORMAL; |
391 #endif | 395 #endif |
392 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); | 396 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); |
393 if (exe_path.empty()) { | 397 if (exe_path.empty()) { |
394 VLOG(1) << "Pepper plugin exe path is empty."; | 398 VLOG(1) << "Pepper plugin exe path is empty."; |
395 return false; | 399 return false; |
396 } | 400 } |
397 | 401 |
398 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 402 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
399 cmd_line->AppendSwitchASCII(switches::kProcessType, | 403 cmd_line->AppendSwitchASCII(switches::kProcessType, |
400 is_broker_ ? switches::kPpapiBrokerProcess | 404 is_broker_ ? switches::kPpapiBrokerProcess |
401 : switches::kPpapiPluginProcess); | 405 : switches::kPpapiPluginProcess); |
402 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 406 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); |
403 | 407 |
404 #if defined(OS_WIN) | 408 #if defined(OS_WIN) |
405 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) { | 409 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) { |
406 cmd_line->AppendArg(is_broker_ ? switches::kPrefetchArgumentPpapiBroker | 410 cmd_line->AppendArg(is_broker_ ? switches::kPrefetchArgumentPpapiBroker |
407 : switches::kPrefetchArgumentPpapi); | 411 : switches::kPrefetchArgumentPpapi); |
408 } | 412 } |
409 #endif // defined(OS_WIN) | 413 #endif // defined(OS_WIN) |
410 | 414 |
411 // These switches are forwarded to both plugin and broker pocesses. | 415 // These switches are forwarded to both plugin and broker pocesses. |
412 static const char* const kCommonForwardSwitches[] = { | 416 static const char* const kCommonForwardSwitches[] = { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 // sent_requests_ queue should be the one that the plugin just created. | 558 // sent_requests_ queue should be the one that the plugin just created. |
555 Client* client = sent_requests_.front(); | 559 Client* client = sent_requests_.front(); |
556 sent_requests_.pop(); | 560 sent_requests_.pop(); |
557 | 561 |
558 const ChildProcessData& data = process_->GetData(); | 562 const ChildProcessData& data = process_->GetData(); |
559 client->OnPpapiChannelOpened(channel_handle, base::GetProcId(data.handle), | 563 client->OnPpapiChannelOpened(channel_handle, base::GetProcId(data.handle), |
560 data.id); | 564 data.id); |
561 } | 565 } |
562 | 566 |
563 } // namespace content | 567 } // namespace content |
OLD | NEW |