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
|
// 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 <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/values.h"
#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.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 },
{ switches::kGSSAPILibraryName, prefs::kGSSAPILibraryName },
{ data_reduction_proxy::switches::kDataReductionProxy,
data_reduction_proxy::prefs::kDataReductionProxy },
{ switches::kSSLVersionMin, prefs::kSSLVersionMin },
{ switches::kSSLVersionMax, prefs::kSSLVersionMax },
{ switches::kSSLVersionFallbackMin, prefs::kSSLVersionFallbackMin },
};
const CommandLinePrefStore::PathSwitchToPreferenceMapEntry
CommandLinePrefStore::path_switch_map_[] = {
{ switches::kDiskCacheDir, prefs::kDiskCacheDir },
};
const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
CommandLinePrefStore::boolean_switch_map_[] = {
{ switches::kDisableAuthNegotiateCnameLookup,
prefs::kDisableAuthNegotiateCnameLookup, true },
{ switches::kEnableAuthNegotiatePort, prefs::kEnableAuthNegotiatePort,
true },
{ 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 },
#endif
{ switches::kDisableAsyncDns, prefs::kBuiltInDnsClientEnabled, false },
{ switches::kEnableAsyncDns, prefs::kBuiltInDnsClientEnabled, true },
};
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,
new base::StringValue(command_line_->GetSwitchValueASCII(
string_switch_map_[i].switch_name)));
}
}
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,
new base::StringValue(command_line_->GetSwitchValuePath(
path_switch_map_[i].switch_name).value()));
}
}
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,
new base::FundamentalValue(int_value));
}
}
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,
new base::FundamentalValue(boolean_switch_map_[i].set_value));
}
}
}
void CommandLinePrefStore::ApplyProxyMode() {
if (command_line_->HasSwitch(switches::kNoProxyServer)) {
SetValue(prefs::kProxy,
ProxyConfigDictionary::CreateDirect());
} else if (command_line_->HasSwitch(switches::kProxyPacUrl)) {
std::string pac_script_url =
command_line_->GetSwitchValueASCII(switches::kProxyPacUrl);
SetValue(prefs::kProxy,
ProxyConfigDictionary::CreatePacScript(pac_script_url, false));
} else if (command_line_->HasSwitch(switches::kProxyAutoDetect)) {
SetValue(prefs::kProxy,
ProxyConfigDictionary::CreateAutoDetect());
} 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(prefs::kProxy,
ProxyConfigDictionary::CreateFixedServers(proxy_server,
bypass_list));
}
}
void CommandLinePrefStore::ApplySSLSwitches() {
if (command_line_->HasSwitch(switches::kCipherSuiteBlacklist)) {
std::string cipher_suites =
command_line_->GetSwitchValueASCII(switches::kCipherSuiteBlacklist);
std::vector<std::string> cipher_strings;
base::SplitString(cipher_suites, ',', &cipher_strings);
base::ListValue* list_value = new base::ListValue();
for (std::vector<std::string>::const_iterator it = cipher_strings.begin();
it != cipher_strings.end(); ++it) {
list_value->Append(new base::StringValue(*it));
}
SetValue(prefs::kCipherSuiteBlacklist, list_value);
}
}
void CommandLinePrefStore::ApplyBackgroundModeSwitches() {
if (command_line_->HasSwitch(switches::kDisableExtensions))
SetValue(prefs::kBackgroundModeEnabled, new base::FundamentalValue(false));
}
|