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