Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / common / content_switches_internal.cc
blobaa34ca1891396b26dffa3e51ee1f8253b86c3815
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/content_switches_internal.h"
7 #include <string>
9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h"
11 #include "content/public/common/content_switches.h"
13 #if defined(OS_WIN)
14 #include "base/strings/string_tokenizer.h"
15 #include "base/win/windows_version.h"
16 #include "ui/gfx/win/direct_write.h"
17 #endif
19 namespace content {
21 namespace {
23 #if defined(OS_WIN)
24 static bool g_win32k_renderer_lockdown_disabled = false;
25 #endif
27 } // namespace
29 bool IsPinchToZoomEnabled() {
30 const base::CommandLine& command_line =
31 *base::CommandLine::ForCurrentProcess();
33 // --disable-pinch should always disable pinch
34 if (command_line.HasSwitch(switches::kDisablePinch))
35 return false;
37 #if defined(OS_WIN)
38 return base::win::GetVersion() >= base::win::VERSION_WIN8;
39 #elif defined(OS_CHROMEOS)
40 return true;
41 #else
42 return command_line.HasSwitch(switches::kEnableViewport) ||
43 command_line.HasSwitch(switches::kEnablePinch);
44 #endif
47 #if defined(OS_WIN)
49 void DisableWin32kRendererLockdown() {
50 g_win32k_renderer_lockdown_disabled = true;
53 bool IsWin32kRendererLockdownEnabled() {
54 if (g_win32k_renderer_lockdown_disabled)
55 return false;
56 if (base::win::GetVersion() < base::win::VERSION_WIN8)
57 return false;
58 if (!gfx::win::ShouldUseDirectWrite())
59 return false;
60 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
61 if (cmd_line->HasSwitch(switches::kDisableWin32kRendererLockDown))
62 return false;
63 return true;
66 bool IsWin32kLockdownEnabledForMimeType(const std::string& mime_type) {
67 // Consider PPAPI lockdown a superset of renderer lockdown.
68 if (!IsWin32kRendererLockdownEnabled())
69 return false;
70 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
72 std::string mime_types =
73 cmd_line->GetSwitchValueASCII(switches::kEnableWin32kLockDownMimeTypes);
75 if (mime_types.empty()) {
76 mime_types =
77 base::FieldTrialList::FindFullName("EnableWin32kLockDownMimeTypes");
80 // Consider the value * to enable all mime types for lockdown.
81 if (mime_types == "*")
82 return true;
84 base::StringTokenizer tokenizer(mime_types, ",");
85 tokenizer.set_quote_chars("\"");
86 while (tokenizer.GetNext()) {
87 if (tokenizer.token() == mime_type)
88 return true;
91 return false;
93 #endif
95 V8CacheOptions GetV8CacheOptions() {
96 const base::CommandLine& command_line =
97 *base::CommandLine::ForCurrentProcess();
98 std::string v8_cache_options =
99 command_line.GetSwitchValueASCII(switches::kV8CacheOptions);
100 if (v8_cache_options.empty())
101 v8_cache_options = base::FieldTrialList::FindFullName("V8CacheOptions");
102 if (v8_cache_options == "none") {
103 return V8_CACHE_OPTIONS_NONE;
104 } else if (v8_cache_options == "parse") {
105 return V8_CACHE_OPTIONS_PARSE;
106 } else if (v8_cache_options == "code") {
107 return V8_CACHE_OPTIONS_CODE;
108 } else {
109 return V8_CACHE_OPTIONS_DEFAULT;
113 } // namespace content