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/policy/configuration_policy_handler.h" | 5 #include "chrome/browser/policy/configuration_policy_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 Value::TYPE_STRING }, | 85 Value::TYPE_STRING }, |
86 { key::kDefaultSearchProviderIconURL, | 86 { key::kDefaultSearchProviderIconURL, |
87 prefs::kDefaultSearchProviderIconURL, | 87 prefs::kDefaultSearchProviderIconURL, |
88 Value::TYPE_STRING }, | 88 Value::TYPE_STRING }, |
89 { key::kDefaultSearchProviderEncodings, | 89 { key::kDefaultSearchProviderEncodings, |
90 prefs::kDefaultSearchProviderEncodings, | 90 prefs::kDefaultSearchProviderEncodings, |
91 Value::TYPE_LIST }, | 91 Value::TYPE_LIST }, |
92 { key::kDefaultSearchProviderAlternateURLs, | 92 { key::kDefaultSearchProviderAlternateURLs, |
93 prefs::kDefaultSearchProviderAlternateURLs, | 93 prefs::kDefaultSearchProviderAlternateURLs, |
94 Value::TYPE_LIST }, | 94 Value::TYPE_LIST }, |
| 95 { key::kDefaultSearchProviderSearchTermsReplacementKey, |
| 96 prefs::kDefaultSearchProviderSearchTermsReplacementKey, |
| 97 Value::TYPE_STRING }, |
95 }; | 98 }; |
96 | 99 |
97 // List of entries determining which proxy policies can be specified, depending | 100 // List of entries determining which proxy policies can be specified, depending |
98 // on the ProxyMode. | 101 // on the ProxyMode. |
99 const ProxyModeValidationEntry kProxyModeValidationMap[] = { | 102 const ProxyModeValidationEntry kProxyModeValidationMap[] = { |
100 { ProxyPrefs::kDirectProxyModeName, | 103 { ProxyPrefs::kDirectProxyModeName, |
101 false, false, false, IDS_POLICY_PROXY_MODE_DISABLED_ERROR }, | 104 false, false, false, IDS_POLICY_PROXY_MODE_DISABLED_ERROR }, |
102 { ProxyPrefs::kAutoDetectProxyModeName, | 105 { ProxyPrefs::kAutoDetectProxyModeName, |
103 false, false, false, IDS_POLICY_PROXY_MODE_AUTO_DETECT_ERROR }, | 106 false, false, false, IDS_POLICY_PROXY_MODE_AUTO_DETECT_ERROR }, |
104 { ProxyPrefs::kPacScriptProxyModeName, | 107 { ProxyPrefs::kPacScriptProxyModeName, |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 // If default search is disabled, the other fields are ignored. | 821 // If default search is disabled, the other fields are ignored. |
819 prefs->SetString(prefs::kDefaultSearchProviderName, std::string()); | 822 prefs->SetString(prefs::kDefaultSearchProviderName, std::string()); |
820 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); | 823 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); |
821 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); | 824 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); |
822 prefs->SetString(prefs::kDefaultSearchProviderIconURL, std::string()); | 825 prefs->SetString(prefs::kDefaultSearchProviderIconURL, std::string()); |
823 prefs->SetString(prefs::kDefaultSearchProviderEncodings, std::string()); | 826 prefs->SetString(prefs::kDefaultSearchProviderEncodings, std::string()); |
824 prefs->SetString(prefs::kDefaultSearchProviderKeyword, std::string()); | 827 prefs->SetString(prefs::kDefaultSearchProviderKeyword, std::string()); |
825 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, std::string()); | 828 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, std::string()); |
826 prefs->SetValue(prefs::kDefaultSearchProviderAlternateURLs, | 829 prefs->SetValue(prefs::kDefaultSearchProviderAlternateURLs, |
827 new ListValue()); | 830 new ListValue()); |
| 831 prefs->SetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey, |
| 832 std::string()); |
828 } else { | 833 } else { |
829 // The search URL is required. The other entries are optional. Just make | 834 // The search URL is required. The other entries are optional. Just make |
830 // sure that they are all specified via policy, so that the regular prefs | 835 // sure that they are all specified via policy, so that the regular prefs |
831 // aren't used. | 836 // aren't used. |
832 const Value* dummy; | 837 const Value* dummy; |
833 std::string url; | 838 std::string url; |
834 if (DefaultSearchURLIsValid(policies, &dummy, &url)) { | 839 if (DefaultSearchURLIsValid(policies, &dummy, &url)) { |
835 for (std::vector<ConfigurationPolicyHandler*>::const_iterator handler = | 840 for (std::vector<ConfigurationPolicyHandler*>::const_iterator handler = |
836 handlers_.begin(); handler != handlers_.end(); ++handler) | 841 handlers_.begin(); handler != handlers_.end(); ++handler) |
837 (*handler)->ApplyPolicySettings(policies, prefs); | 842 (*handler)->ApplyPolicySettings(policies, prefs); |
838 | 843 |
839 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderSuggestURL); | 844 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderSuggestURL); |
840 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderIconURL); | 845 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderIconURL); |
841 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderEncodings); | 846 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderEncodings); |
842 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderKeyword); | 847 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderKeyword); |
843 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderInstantURL); | 848 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderInstantURL); |
844 EnsureListPrefExists(prefs, prefs::kDefaultSearchProviderAlternateURLs); | 849 EnsureListPrefExists(prefs, prefs::kDefaultSearchProviderAlternateURLs); |
| 850 EnsureStringPrefExists(prefs, |
| 851 prefs::kDefaultSearchProviderSearchTermsReplacementKey); |
845 | 852 |
846 // For the name and keyword, default to the host if not specified. If | 853 // For the name and keyword, default to the host if not specified. If |
847 // there is no host (file: URLs? Not sure), use "_" to guarantee that the | 854 // there is no host (file: URLs? Not sure), use "_" to guarantee that the |
848 // keyword is non-empty. | 855 // keyword is non-empty. |
849 std::string name, keyword; | 856 std::string name, keyword; |
850 std::string host(GURL(url).host()); | 857 std::string host(GURL(url).host()); |
851 if (host.empty()) | 858 if (host.empty()) |
852 host = "_"; | 859 host = "_"; |
853 if (!prefs->GetString(prefs::kDefaultSearchProviderName, &name) || | 860 if (!prefs->GetString(prefs::kDefaultSearchProviderName, &name) || |
854 name.empty()) | 861 name.empty()) |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 errors->AddError(policy_name(), | 1461 errors->AddError(policy_name(), |
1455 IDS_POLICY_OUT_OF_RANGE_ERROR, | 1462 IDS_POLICY_OUT_OF_RANGE_ERROR, |
1456 base::IntToString(restore_value)); | 1463 base::IntToString(restore_value)); |
1457 } | 1464 } |
1458 } | 1465 } |
1459 } | 1466 } |
1460 return true; | 1467 return true; |
1461 } | 1468 } |
1462 | 1469 |
1463 } // namespace policy | 1470 } // namespace policy |
OLD | NEW |