Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/search_engines/default_search_policy_handler.cc

Issue 268643002: Use the DefaultSearchManager as the exclusive authority on DSE, ignoring Web Data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/search_engines/default_search_policy_handler.h" 5 #include "chrome/browser/search_engines/default_search_policy_handler.h"
6 6
7 #include "base/prefs/pref_value_map.h" 7 #include "base/prefs/pref_value_map.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 const base::Value* url; 221 const base::Value* url;
222 std::string dummy; 222 std::string dummy;
223 if (DefaultSearchURLIsValid(policies, &url, &dummy) || 223 if (DefaultSearchURLIsValid(policies, &url, &dummy) ||
224 !AnyDefaultSearchPoliciesSpecified(policies)) 224 !AnyDefaultSearchPoliciesSpecified(policies))
225 return true; 225 return true;
226 errors->AddError(key::kDefaultSearchProviderSearchURL, url ? 226 errors->AddError(key::kDefaultSearchProviderSearchURL, url ?
227 IDS_POLICY_INVALID_SEARCH_URL_ERROR : IDS_POLICY_NOT_SPECIFIED_ERROR); 227 IDS_POLICY_INVALID_SEARCH_URL_ERROR : IDS_POLICY_NOT_SPECIFIED_ERROR);
228 return false; 228 return false;
229 } 229 }
230 230
231 void DefaultSearchPolicyHandler::HandleDictionaryPref(const PolicyMap& policies, 231 void DefaultSearchPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
232 PrefValueMap* prefs) { 232 PrefValueMap* prefs) {
233 if (DefaultSearchProviderIsDisabled(policies)) { 233 if (DefaultSearchProviderIsDisabled(policies)) {
234 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 234 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
235 dict->SetBoolean(DefaultSearchManager::kDisabledByPolicy, true); 235 dict->SetBoolean(DefaultSearchManager::kDisabledByPolicy, true);
236 DefaultSearchManager::AddPrefValueToMap(dict.release(), prefs); 236 DefaultSearchManager::AddPrefValueToMap(dict.release(), prefs);
237 return; 237 return;
238 } 238 }
239 239
240 // The search URL is required. The other entries are optional. Just make 240 // The search URL is required. The other entries are optional. Just make
241 // sure that they are all specified via policy, so that the regular prefs 241 // sure that they are all specified via policy, so that the regular prefs
242 // aren't used. 242 // aren't used.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (host.empty()) 293 if (host.empty())
294 host = "_"; 294 host = "_";
295 if (name.empty()) 295 if (name.empty())
296 dict->SetString(DefaultSearchManager::kShortName, host); 296 dict->SetString(DefaultSearchManager::kShortName, host);
297 if (keyword.empty()) 297 if (keyword.empty())
298 dict->SetString(DefaultSearchManager::kKeyword, host); 298 dict->SetString(DefaultSearchManager::kKeyword, host);
299 299
300 DefaultSearchManager::AddPrefValueToMap(dict.release(), prefs); 300 DefaultSearchManager::AddPrefValueToMap(dict.release(), prefs);
301 } 301 }
302 302
303 void DefaultSearchPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
304 PrefValueMap* prefs) {
305 HandleDictionaryPref(policies, prefs);
306
307 if (DefaultSearchProviderIsDisabled(policies)) {
308 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, false);
309
310 // If default search is disabled, the other fields are ignored.
311 prefs->SetString(prefs::kDefaultSearchProviderName, std::string());
312 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, std::string());
313 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, std::string());
314 prefs->SetString(prefs::kDefaultSearchProviderIconURL, std::string());
315 prefs->SetString(prefs::kDefaultSearchProviderEncodings, std::string());
316 prefs->SetString(prefs::kDefaultSearchProviderKeyword, std::string());
317 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, std::string());
318 prefs->SetString(prefs::kDefaultSearchProviderNewTabURL, std::string());
319 prefs->SetValue(prefs::kDefaultSearchProviderAlternateURLs,
320 new base::ListValue());
321 prefs->SetString(
322 prefs::kDefaultSearchProviderSearchTermsReplacementKey, std::string());
323 prefs->SetString(prefs::kDefaultSearchProviderImageURL, std::string());
324 prefs->SetString(
325 prefs::kDefaultSearchProviderSearchURLPostParams, std::string());
326 prefs->SetString(
327 prefs::kDefaultSearchProviderSuggestURLPostParams, std::string());
328 prefs->SetString(
329 prefs::kDefaultSearchProviderInstantURLPostParams, std::string());
330 prefs->SetString(
331 prefs::kDefaultSearchProviderImageURLPostParams, std::string());
332 } else {
333 // The search URL is required. The other entries are optional. Just make
334 // sure that they are all specified via policy, so that the regular prefs
335 // aren't used.
336 const base::Value* dummy;
337 std::string url;
338 if (DefaultSearchURLIsValid(policies, &dummy, &url)) {
339
340 for (std::vector<TypeCheckingPolicyHandler*>::const_iterator handler =
341 handlers_.begin();
342 handler != handlers_.end(); ++handler) {
343 (*handler)->ApplyPolicySettings(policies, prefs);
344 }
345
346 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderSuggestURL);
347 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderIconURL);
348 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderEncodings);
349 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderKeyword);
350 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderInstantURL);
351 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderNewTabURL);
352 EnsureListPrefExists(prefs, prefs::kDefaultSearchProviderAlternateURLs);
353 EnsureStringPrefExists(
354 prefs,
355 prefs::kDefaultSearchProviderSearchTermsReplacementKey);
356 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderImageURL);
357 EnsureStringPrefExists(
358 prefs,
359 prefs::kDefaultSearchProviderSearchURLPostParams);
360 EnsureStringPrefExists(
361 prefs,
362 prefs::kDefaultSearchProviderSuggestURLPostParams);
363 EnsureStringPrefExists(
364 prefs,
365 prefs::kDefaultSearchProviderInstantURLPostParams);
366 EnsureStringPrefExists(
367 prefs,
368 prefs::kDefaultSearchProviderImageURLPostParams);
369
370 // For the name and keyword, default to the host if not specified. If
371 // there is no host (file: URLs? Not sure), use "_" to guarantee that the
372 // keyword is non-empty.
373 std::string name, keyword;
374 std::string host(GURL(url).host());
375 if (host.empty())
376 host = "_";
377 if (!prefs->GetString(prefs::kDefaultSearchProviderName, &name) ||
378 name.empty()) {
379 prefs->SetString(prefs::kDefaultSearchProviderName, host);
380 }
381 if (!prefs->GetString(prefs::kDefaultSearchProviderKeyword, &keyword) ||
382 keyword.empty()) {
383 prefs->SetString(prefs::kDefaultSearchProviderKeyword, host);
384 }
385
386 // And clear the IDs since these are not specified via policy.
387 prefs->SetString(prefs::kDefaultSearchProviderID, std::string());
388 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID,
389 std::string());
390 }
391 }
392 content::NotificationService::current()->Notify(
393 chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED,
394 content::NotificationService::AllSources(),
395 content::NotificationService::NoDetails());
396 }
397
398 bool DefaultSearchPolicyHandler::CheckIndividualPolicies( 303 bool DefaultSearchPolicyHandler::CheckIndividualPolicies(
399 const PolicyMap& policies, 304 const PolicyMap& policies,
400 PolicyErrorMap* errors) { 305 PolicyErrorMap* errors) {
401 for (std::vector<TypeCheckingPolicyHandler*>::const_iterator handler = 306 for (std::vector<TypeCheckingPolicyHandler*>::const_iterator handler =
402 handlers_.begin(); 307 handlers_.begin();
403 handler != handlers_.end(); ++handler) { 308 handler != handlers_.end(); ++handler) {
404 if (!(*handler)->CheckPolicySettings(policies, errors)) 309 if (!(*handler)->CheckPolicySettings(policies, errors))
405 return false; 310 return false;
406 } 311 }
407 return true; 312 return true;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 void DefaultSearchPolicyHandler::EnsureListPrefExists( 364 void DefaultSearchPolicyHandler::EnsureListPrefExists(
460 PrefValueMap* prefs, 365 PrefValueMap* prefs,
461 const std::string& path) { 366 const std::string& path) {
462 base::Value* value; 367 base::Value* value;
463 base::ListValue* list_value; 368 base::ListValue* list_value;
464 if (!prefs->GetValue(path, &value) || !value->GetAsList(&list_value)) 369 if (!prefs->GetValue(path, &value) || !value->GetAsList(&list_value))
465 prefs->SetValue(path, new base::ListValue()); 370 prefs->SetValue(path, new base::ListValue());
466 } 371 }
467 372
468 } // namespace policy 373 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698