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