| 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 "chrome/common/chrome_content_client.h" | 5 #include "chrome/common/chrome_content_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/cpu.h" | 8 #include "base/cpu.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 switches::kEnableBundledPpapiFlash); | 297 switches::kEnableBundledPpapiFlash); |
| 298 | 298 |
| 299 *plugin = CreatePepperFlashInfo(flash_path, FLAPPER_VERSION_STRING); | 299 *plugin = CreatePepperFlashInfo(flash_path, FLAPPER_VERSION_STRING); |
| 300 *override_npapi_flash = force_enable || IsPepperFlashEnabledByDefault(); | 300 *override_npapi_flash = force_enable || IsPepperFlashEnabledByDefault(); |
| 301 return true; | 301 return true; |
| 302 #else | 302 #else |
| 303 return false; | 303 return false; |
| 304 #endif // FLAPPER_AVAILABLE | 304 #endif // FLAPPER_AVAILABLE |
| 305 } | 305 } |
| 306 | 306 |
| 307 #if defined(OS_WIN) | |
| 308 // Launches the privileged flash broker, used when flash is sandboxed. | |
| 309 // The broker is the same flash dll, except that it uses a different | |
| 310 // entrypoint (BrokerMain) and it is hosted in windows' generic surrogate | |
| 311 // process rundll32. After launching the broker we need to pass to | |
| 312 // the flash plugin the process id of the broker via the command line | |
| 313 // using --flash-broker=pid. | |
| 314 // More info about rundll32 at http://support.microsoft.com/kb/164787. | |
| 315 bool LoadFlashBroker(const FilePath& plugin_path, CommandLine* cmd_line) { | |
| 316 FilePath rundll; | |
| 317 if (!PathService::Get(base::DIR_SYSTEM, &rundll)) | |
| 318 return false; | |
| 319 rundll = rundll.AppendASCII("rundll32.exe"); | |
| 320 // Rundll32 cannot handle paths with spaces, so we use the short path. | |
| 321 wchar_t short_path[MAX_PATH]; | |
| 322 if (0 == ::GetShortPathNameW(plugin_path.value().c_str(), | |
| 323 short_path, arraysize(short_path))) | |
| 324 return false; | |
| 325 // Here is the kicker, if the user has disabled 8.3 (short path) support | |
| 326 // on the volume GetShortPathNameW does not fail but simply returns the | |
| 327 // input path. In this case if the path had any spaces then rundll32 will | |
| 328 // incorrectly interpret its parameters. So we quote the path, even though | |
| 329 // the kb/164787 says you should not. | |
| 330 std::wstring cmd_final = | |
| 331 base::StringPrintf(L"%ls \"%ls\",BrokerMain browser=chrome", | |
| 332 rundll.value().c_str(), | |
| 333 short_path); | |
| 334 base::ProcessHandle process; | |
| 335 base::LaunchOptions options; | |
| 336 options.start_hidden = true; | |
| 337 if (!base::LaunchProcess(cmd_final, options, &process)) | |
| 338 return false; | |
| 339 | |
| 340 cmd_line->AppendSwitchASCII("flash-broker", | |
| 341 base::Int64ToString(::GetProcessId(process))); | |
| 342 | |
| 343 // The flash broker, unders some circumstances can linger beyond the lifetime | |
| 344 // of the flash player, so we put it in a job object, when the browser | |
| 345 // terminates the job object is destroyed (by the OS) and the flash broker | |
| 346 // is terminated. | |
| 347 HANDLE job = ::CreateJobObjectW(NULL, NULL); | |
| 348 if (base::SetJobObjectAsKillOnJobClose(job)) { | |
| 349 ::AssignProcessToJobObject(job, process); | |
| 350 // Yes, we are leaking the object here. Read comment above. | |
| 351 } else { | |
| 352 ::CloseHandle(job); | |
| 353 return false; | |
| 354 } | |
| 355 | |
| 356 ::CloseHandle(process); | |
| 357 return true; | |
| 358 } | |
| 359 #endif // OS_WIN | |
| 360 | |
| 361 } // namespace | 307 } // namespace |
| 362 | 308 |
| 363 namespace chrome { | 309 namespace chrome { |
| 364 | 310 |
| 365 const char* const ChromeContentClient::kPDFPluginName = ::kPDFPluginName; | 311 const char* const ChromeContentClient::kPDFPluginName = ::kPDFPluginName; |
| 366 const char* const ChromeContentClient::kNaClPluginName = ::kNaClPluginName; | 312 const char* const ChromeContentClient::kNaClPluginName = ::kNaClPluginName; |
| 367 const char* const ChromeContentClient::kNaClOldPluginName = | 313 const char* const ChromeContentClient::kNaClOldPluginName = |
| 368 ::kNaClOldPluginName; | 314 ::kNaClOldPluginName; |
| 369 | 315 |
| 370 void ChromeContentClient::SetActiveURL(const GURL& url) { | 316 void ChromeContentClient::SetActiveURL(const GURL& url) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 int resource_id, | 397 int resource_id, |
| 452 ui::ScaleFactor scale_factor) const { | 398 ui::ScaleFactor scale_factor) const { |
| 453 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 399 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 454 resource_id, scale_factor); | 400 resource_id, scale_factor); |
| 455 } | 401 } |
| 456 | 402 |
| 457 gfx::Image& ChromeContentClient::GetNativeImageNamed(int resource_id) const { | 403 gfx::Image& ChromeContentClient::GetNativeImageNamed(int resource_id) const { |
| 458 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); | 404 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); |
| 459 } | 405 } |
| 460 | 406 |
| 461 #if defined(OS_WIN) | |
| 462 bool ChromeContentClient::SandboxPlugin(CommandLine* command_line, | |
| 463 sandbox::TargetPolicy* policy) { | |
| 464 std::wstring plugin_dll = command_line-> | |
| 465 GetSwitchValueNative(switches::kPluginPath); | |
| 466 | |
| 467 FilePath builtin_flash; | |
| 468 if (!PathService::Get(chrome::FILE_FLASH_PLUGIN_EXISTING, &builtin_flash)) | |
| 469 return false; | |
| 470 | |
| 471 FilePath plugin_path(plugin_dll); | |
| 472 if (plugin_path.BaseName() != builtin_flash.BaseName()) | |
| 473 return false; | |
| 474 | |
| 475 if (base::win::GetVersion() <= base::win::VERSION_XP || | |
| 476 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 477 switches::kDisableFlashSandbox)) { | |
| 478 return false; | |
| 479 } | |
| 480 | |
| 481 // Add policy for the plugin proxy window pump event | |
| 482 // used by WebPluginDelegateProxy::HandleInputEvent(). | |
| 483 if (policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES, | |
| 484 sandbox::TargetPolicy::HANDLES_DUP_ANY, | |
| 485 L"Event") != sandbox::SBOX_ALL_OK) { | |
| 486 NOTREACHED(); | |
| 487 return false; | |
| 488 } | |
| 489 | |
| 490 // Add the policy for the pipes. | |
| 491 if (policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, | |
| 492 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, | |
| 493 L"\\\\.\\pipe\\chrome.*") != sandbox::SBOX_ALL_OK) { | |
| 494 NOTREACHED(); | |
| 495 return false; | |
| 496 } | |
| 497 | |
| 498 // Spawn the flash broker and apply sandbox policy. | |
| 499 if (LoadFlashBroker(plugin_path, command_line)) { | |
| 500 // UI job restrictions break windowless Flash, so just pick up single | |
| 501 // process limit for now. | |
| 502 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); | |
| 503 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS, | |
| 504 sandbox::USER_INTERACTIVE); | |
| 505 // Allow the Flash plugin to forward some messages back to Chrome. | |
| 506 if (base::win::GetVersion() == base::win::VERSION_VISTA) { | |
| 507 // Per-window message filters required on Win7 or later must be added to: | |
| 508 // render_widget_host_view_win.cc RenderWidgetHostViewWin::ReparentWindow | |
| 509 ::ChangeWindowMessageFilter(WM_MOUSEWHEEL, MSGFLT_ADD); | |
| 510 ::ChangeWindowMessageFilter(WM_APPCOMMAND, MSGFLT_ADD); | |
| 511 } | |
| 512 policy->SetIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); | |
| 513 } else { | |
| 514 // Could not start the broker, use a very weak policy instead. | |
| 515 DLOG(WARNING) << "Failed to start flash broker"; | |
| 516 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); | |
| 517 policy->SetTokenLevel( | |
| 518 sandbox::USER_UNPROTECTED, sandbox::USER_UNPROTECTED); | |
| 519 } | |
| 520 | |
| 521 return true; | |
| 522 } | |
| 523 #endif | |
| 524 | |
| 525 #if defined(OS_MACOSX) && !defined(OS_IOS) | 407 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 526 bool ChromeContentClient::GetSandboxProfileForSandboxType( | 408 bool ChromeContentClient::GetSandboxProfileForSandboxType( |
| 527 int sandbox_type, | 409 int sandbox_type, |
| 528 int* sandbox_profile_resource_id) const { | 410 int* sandbox_profile_resource_id) const { |
| 529 DCHECK(sandbox_profile_resource_id); | 411 DCHECK(sandbox_profile_resource_id); |
| 530 if (sandbox_type == CHROME_SANDBOX_TYPE_NACL_LOADER) { | 412 if (sandbox_type == CHROME_SANDBOX_TYPE_NACL_LOADER) { |
| 531 *sandbox_profile_resource_id = IDR_NACL_SANDBOX_PROFILE; | 413 *sandbox_profile_resource_id = IDR_NACL_SANDBOX_PROFILE; |
| 532 return true; | 414 return true; |
| 533 } | 415 } |
| 534 return false; | 416 return false; |
| 535 } | 417 } |
| 536 | 418 |
| 537 std::string ChromeContentClient::GetCarbonInterposePath() const { | 419 std::string ChromeContentClient::GetCarbonInterposePath() const { |
| 538 return std::string(kInterposeLibraryPath); | 420 return std::string(kInterposeLibraryPath); |
| 539 } | 421 } |
| 540 #endif | 422 #endif |
| 541 | 423 |
| 542 bool ChromeContentClient::GetBundledFieldTrialPepperFlash( | 424 bool ChromeContentClient::GetBundledFieldTrialPepperFlash( |
| 543 content::PepperPluginInfo* plugin, | 425 content::PepperPluginInfo* plugin, |
| 544 bool* override_npapi_flash) { | 426 bool* override_npapi_flash) { |
| 545 if (!ConductingPepperFlashFieldTrial()) | 427 if (!ConductingPepperFlashFieldTrial()) |
| 546 return false; | 428 return false; |
| 547 return GetBundledPepperFlash(plugin, override_npapi_flash); | 429 return GetBundledPepperFlash(plugin, override_npapi_flash); |
| 548 } | 430 } |
| 549 | 431 |
| 550 } // namespace chrome | 432 } // namespace chrome |
| OLD | NEW |