1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/prefs/command_line_pref_store.h"
#include <stddef.h>
#include <string>
#include <utility>
#include <vector>
#include "ash/ash_switches.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/proxy_config/proxy_config_dictionary.h"
#include "components/proxy_config/proxy_config_pref_names.h"
#include "components/ssl_config/ssl_config_prefs.h"
#include "components/ssl_config/ssl_config_switches.h"
#include "content/public/common/content_switches.h"
#include "ui/base/ui_base_switches.h"
#if defined(OS_CHROMEOS)
#include "chromeos/chromeos_switches.h"
#endif
const CommandLinePrefStore::StringSwitchToPreferenceMapEntry
CommandLinePrefStore::string_switch_map_[] = {
{ switches::kLang, prefs::kApplicationLocale },
{ data_reduction_proxy::switches::kDataReductionProxy,
data_reduction_proxy::prefs::kDataReductionProxy },
{ switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist },
{ switches::kSSLVersionMin, ssl_config::prefs::kSSLVersionMin },
{ switches::kSSLVersionMax, ssl_config::prefs::kSSLVersionMax },
{ switches::kSSLVersionFallbackMin,
ssl_config::prefs::kSSLVersionFallbackMin },
#if defined(OS_ANDROID)
{ switches::kAuthAndroidNegotiateAccountType,
prefs::kAuthAndroidNegotiateAccountType },
#endif
};
const CommandLinePrefStore::PathSwitchToPreferenceMapEntry
CommandLinePrefStore::path_switch_map_[] = {
{ switches::kDiskCacheDir, prefs::kDiskCacheDir },
};
const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
CommandLinePrefStore::boolean_switch_map_[] = {
{ switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true },
{ switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled,
true },
{ switches::kAllowOutdatedPlugins, prefs::kPluginsAllowOutdated, true },
{ switches::kAlwaysAuthorizePlugins, prefs::kPluginsAlwaysAuthorize,
true },
{ switches::kNoPings, prefs::kEnableHyperlinkAuditing, false },
{ switches::kNoReferrers, prefs::kEnableReferrers, false },
{ switches::kAllowRunningInsecureContent,
prefs::kWebKitAllowRunningInsecureContent, true },
{ switches::kNoDisplayingInsecureContent,
prefs::kWebKitAllowDisplayingInsecureContent, false },
{ switches::kAllowCrossOriginAuthPrompt,
prefs::kAllowCrossOriginAuthPrompt, true },
{ switches::kDisablePrintPreview, prefs::kPrintPreviewDisabled, true },
#if defined(OS_CHROMEOS)
{ chromeos::switches::kEnableTouchpadThreeFingerClick,
prefs::kEnableTouchpadThreeFingerClick, true },
{ ash::switches::kAshEnableUnifiedDesktop,
prefs::kUnifiedDesktopEnabledByDefault, true },
#endif
{ switches::kDisableAsyncDns, prefs::kBuiltInDnsClientEnabled, false },
};
const CommandLinePrefStore::IntegerSwitchToPreferenceMapEntry
CommandLinePrefStore::integer_switch_map_[] = {
{ switches::kDiskCacheSize, prefs::kDiskCacheSize },
{ switches::kMediaCacheSize, prefs::kMediaCacheSize },
};
CommandLinePrefStore::CommandLinePrefStore(
const base::CommandLine* command_line)
: command_line_(command_line) {
ApplySimpleSwitches();
ApplyProxyMode();
ValidateProxySwitches();
ApplySSLSwitches();
ApplyBackgroundModeSwitches();
}
CommandLinePrefStore::~CommandLinePrefStore() {}
bool CommandLinePrefStore::ValidateProxySwitches() {
if (command_line_->HasSwitch(switches::kNoProxyServer) &&
(command_line_->HasSwitch(switches::kProxyAutoDetect) ||
command_line_->HasSwitch(switches::kProxyServer) ||
command_line_->HasSwitch(switches::kProxyPacUrl) ||
command_line_->HasSwitch(switches::kProxyBypassList))) {
LOG(WARNING) << "Additional command-line proxy switches specified when --"
<< switches::kNoProxyServer << " was also specified.";
return false;
}
return true;
}
void CommandLinePrefStore::ApplySimpleSwitches() {
// Look for each switch we know about and set its preference accordingly.
for (size_t i = 0; i < arraysize(string_switch_map_); ++i) {
if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) {
SetValue(string_switch_map_[i].preference_path,
make_scoped_ptr(
new base::StringValue(command_line_->GetSwitchValueASCII(
string_switch_map_[i].switch_name))),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
for (size_t i = 0; i < arraysize(path_switch_map_); ++i) {
if (command_line_->HasSwitch(path_switch_map_[i].switch_name)) {
SetValue(
path_switch_map_[i].preference_path,
make_scoped_ptr(new base::StringValue(
command_line_->GetSwitchValuePath(path_switch_map_[i].switch_name)
.value())),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
for (size_t i = 0; i < arraysize(integer_switch_map_); ++i) {
if (command_line_->HasSwitch(integer_switch_map_[i].switch_name)) {
std::string str_value = command_line_->GetSwitchValueASCII(
integer_switch_map_[i].switch_name);
int int_value = 0;
if (!base::StringToInt(str_value, &int_value)) {
LOG(ERROR) << "The value " << str_value << " of "
<< integer_switch_map_[i].switch_name
<< " can not be converted to integer, ignoring!";
continue;
}
SetValue(integer_switch_map_[i].preference_path,
make_scoped_ptr(new base::FundamentalValue(int_value)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) {
if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) {
SetValue(boolean_switch_map_[i].preference_path,
make_scoped_ptr(new base::FundamentalValue(
boolean_switch_map_[i].set_value)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
}
void CommandLinePrefStore::ApplyProxyMode() {
if (command_line_->HasSwitch(switches::kNoProxyServer)) {
SetValue(proxy_config::prefs::kProxy,
make_scoped_ptr(ProxyConfigDictionary::CreateDirect()),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
} else if (command_line_->HasSwitch(switches::kProxyPacUrl)) {
std::string pac_script_url =
command_line_->GetSwitchValueASCII(switches::kProxyPacUrl);
SetValue(proxy_config::prefs::kProxy,
make_scoped_ptr(
ProxyConfigDictionary::CreatePacScript(pac_script_url, false)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
} else if (command_line_->HasSwitch(switches::kProxyAutoDetect)) {
SetValue(proxy_config::prefs::kProxy,
make_scoped_ptr(ProxyConfigDictionary::CreateAutoDetect()),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
} else if (command_line_->HasSwitch(switches::kProxyServer)) {
std::string proxy_server =
command_line_->GetSwitchValueASCII(switches::kProxyServer);
std::string bypass_list =
command_line_->GetSwitchValueASCII(switches::kProxyBypassList);
SetValue(proxy_config::prefs::kProxy,
make_scoped_ptr(ProxyConfigDictionary::CreateFixedServers(
proxy_server, bypass_list)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
void CommandLinePrefStore::ApplySSLSwitches() {
if (command_line_->HasSwitch(switches::kCipherSuiteBlacklist)) {
scoped_ptr<base::ListValue> list_value(new base::ListValue());
list_value->AppendStrings(base::SplitString(
command_line_->GetSwitchValueASCII(switches::kCipherSuiteBlacklist),
",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL));
SetValue(ssl_config::prefs::kCipherSuiteBlacklist, std::move(list_value),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
void CommandLinePrefStore::ApplyBackgroundModeSwitches() {
if (command_line_->HasSwitch(switches::kDisableExtensions)) {
SetValue(prefs::kBackgroundModeEnabled,
make_scoped_ptr(new base::FundamentalValue(false)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
|