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

Side by Side Diff: content/common/sandbox_win.cc

Issue 231763003: Support sideloaded fonts via command line option for blink layout_tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 8 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
OLDNEW
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/common/sandbox_win.h" 5 #include "content/common/sandbox_win.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/debugger.h" 11 #include "base/debug/debugger.h"
12 #include "base/debug/profiler.h" 12 #include "base/debug/profiler.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/hash.h" 15 #include "base/hash.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/process/launch.h" 17 #include "base/process/launch.h"
18 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h"
20 #include "base/win/iat_patch_function.h" 22 #include "base/win/iat_patch_function.h"
21 #include "base/win/scoped_handle.h" 23 #include "base/win/scoped_handle.h"
22 #include "base/win/scoped_process_information.h" 24 #include "base/win/scoped_process_information.h"
23 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
24 #include "content/public/common/content_client.h" 26 #include "content/public/common/content_client.h"
25 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
26 #include "content/public/common/sandbox_init.h" 28 #include "content/public/common/sandbox_init.h"
27 #include "content/public/common/sandboxed_process_launcher_delegate.h" 29 #include "content/public/common/sandboxed_process_launcher_delegate.h"
28 #include "ipc/ipc_switches.h" 30 #include "ipc/ipc_switches.h"
29 #include "sandbox/win/src/process_mitigations.h" 31 #include "sandbox/win/src/process_mitigations.h"
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 bool ShouldUseDirectWrite() { 576 bool ShouldUseDirectWrite() {
575 // If the flag is currently on, and we're on Win7 or above, we enable 577 // If the flag is currently on, and we're on Win7 or above, we enable
576 // DirectWrite. Skia does not require the additions to DirectWrite in QFE 578 // DirectWrite. Skia does not require the additions to DirectWrite in QFE
577 // 2670838, so a Win7 check is sufficient. We do not currently attempt to 579 // 2670838, so a Win7 check is sufficient. We do not currently attempt to
578 // support Vista, where SP2 and the Platform Update are required. 580 // support Vista, where SP2 and the Platform Update are required.
579 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 581 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
580 return command_line.HasSwitch(switches::kEnableDirectWrite) && 582 return command_line.HasSwitch(switches::kEnableDirectWrite) &&
581 base::win::GetVersion() >= base::win::VERSION_WIN7; 583 base::win::GetVersion() >= base::win::VERSION_WIN7;
582 } 584 }
583 585
586 bool GetSideloadFontFiles(std::vector<std::string>* files) {
587 files->clear();
jam 2014/04/14 05:40:02 nit: no need for return value and out parameter, j
scottmg 2014/04/14 15:48:58 Done.
588 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
589 if (command_line.HasSwitch(switches::kRegisterFontFiles)) {
590 std::vector<std::string> font_files;
591 base::SplitString(
592 command_line.GetSwitchValueASCII(switches::kRegisterFontFiles),
593 ';',
594 files);
595 }
596 return !files->empty();
597 }
598
584 base::ProcessHandle StartSandboxedProcess( 599 base::ProcessHandle StartSandboxedProcess(
585 SandboxedProcessLauncherDelegate* delegate, 600 SandboxedProcessLauncherDelegate* delegate,
586 CommandLine* cmd_line) { 601 CommandLine* cmd_line) {
587 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 602 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
588 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType); 603 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType);
589 604
590 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess", 0, type_str); 605 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess", 0, type_str);
591 606
592 bool in_sandbox = true; 607 bool in_sandbox = true;
593 if (delegate) 608 if (delegate)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 if (!disable_default_policy && !AddPolicyForSandboxedProcess(policy)) 662 if (!disable_default_policy && !AddPolicyForSandboxedProcess(policy))
648 return 0; 663 return 0;
649 664
650 if (type_str == switches::kRendererProcess) { 665 if (type_str == switches::kRendererProcess) {
651 if (ShouldUseDirectWrite()) { 666 if (ShouldUseDirectWrite()) {
652 AddDirectory(base::DIR_WINDOWS_FONTS, 667 AddDirectory(base::DIR_WINDOWS_FONTS,
653 NULL, 668 NULL,
654 true, 669 true,
655 sandbox::TargetPolicy::FILES_ALLOW_READONLY, 670 sandbox::TargetPolicy::FILES_ALLOW_READONLY,
656 policy); 671 policy);
672 std::vector<std::string> font_files;
673 if (GetSideloadFontFiles(&font_files)) {
674 for (std::vector<std::string>::const_iterator i(font_files.begin());
675 i != font_files.end();
676 ++i) {
677 policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
678 sandbox::TargetPolicy::FILES_ALLOW_READONLY,
679 base::UTF8ToWide(i->c_str()).c_str());
jam 2014/04/14 05:40:02 nit: the first c_str() isn't needed
scottmg 2014/04/14 15:48:58 Done.
680 }
681 }
657 } 682 }
658 } else { 683 } else {
659 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into 684 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into
660 // this subprocess. See 685 // this subprocess. See
661 // http://code.google.com/p/chromium/issues/detail?id=25580 686 // http://code.google.com/p/chromium/issues/detail?id=25580
662 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); 687 cmd_line->AppendSwitchASCII("ignored", " --type=renderer ");
663 } 688 }
664 689
665 sandbox::ResultCode result; 690 sandbox::ResultCode result;
666 if (!exposed_dir.empty()) { 691 if (!exposed_dir.empty()) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 } 787 }
763 788
764 return false; 789 return false;
765 } 790 }
766 791
767 bool BrokerAddTargetPeer(HANDLE peer_process) { 792 bool BrokerAddTargetPeer(HANDLE peer_process) {
768 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; 793 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK;
769 } 794 }
770 795
771 } // namespace content 796 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698