OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings/content_settings_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 }; | 70 }; |
71 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, | 71 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, |
72 type_names_incorrect_size); | 72 type_names_incorrect_size); |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 namespace content_settings { | 76 namespace content_settings { |
77 | 77 |
78 PrefDefaultProvider::PrefDefaultProvider(Profile* profile) | 78 PrefDefaultProvider::PrefDefaultProvider(Profile* profile) |
79 : profile_(profile), | 79 : profile_(profile), |
80 is_off_the_record_(profile_->IsOffTheRecord()), | 80 is_incognito_(profile_->IsOffTheRecord()), |
81 updating_preferences_(false) { | 81 updating_preferences_(false) { |
82 initializing_ = true; | 82 initializing_ = true; |
83 PrefService* prefs = profile->GetPrefs(); | 83 PrefService* prefs = profile->GetPrefs(); |
84 | 84 |
85 MigrateObsoleteNotificationPref(prefs); | 85 MigrateObsoleteNotificationPref(prefs); |
86 | 86 |
87 // Read global defaults. | 87 // Read global defaults. |
88 DCHECK_EQ(arraysize(kTypeNames), | 88 DCHECK_EQ(arraysize(kTypeNames), |
89 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); | 89 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); |
90 ReadDefaultSettings(true); | 90 ReadDefaultSettings(true); |
(...skipping 20 matching lines...) Expand all Loading... |
111 ContentSetting setting) { | 111 ContentSetting setting) { |
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
113 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 113 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
114 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || | 114 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || |
115 setting != CONTENT_SETTING_ASK || | 115 setting != CONTENT_SETTING_ASK || |
116 CommandLine::ForCurrentProcess()->HasSwitch( | 116 CommandLine::ForCurrentProcess()->HasSwitch( |
117 switches::kEnableClickToPlay)); | 117 switches::kEnableClickToPlay)); |
118 | 118 |
119 // The default settings may not be directly modified for OTR sessions. | 119 // The default settings may not be directly modified for OTR sessions. |
120 // Instead, they are synced to the main profile's setting. | 120 // Instead, they are synced to the main profile's setting. |
121 if (is_off_the_record_) | 121 if (is_incognito_) |
122 return; | 122 return; |
123 | 123 |
124 PrefService* prefs = profile_->GetPrefs(); | 124 PrefService* prefs = profile_->GetPrefs(); |
125 | 125 |
126 DictionaryValue* default_settings_dictionary = | 126 DictionaryValue* default_settings_dictionary = |
127 prefs->GetMutableDictionary(prefs::kDefaultContentSettings); | 127 prefs->GetMutableDictionary(prefs::kDefaultContentSettings); |
128 std::string dictionary_path(kTypeNames[content_type]); | 128 std::string dictionary_path(kTypeNames[content_type]); |
129 updating_preferences_ = true; | 129 updating_preferences_ = true; |
130 { | 130 { |
131 base::AutoLock lock(lock_); | 131 base::AutoLock lock(lock_); |
(...skipping 20 matching lines...) Expand all Loading... |
152 ContentSettingsType content_type) const { | 152 ContentSettingsType content_type) const { |
153 return false; | 153 return false; |
154 } | 154 } |
155 | 155 |
156 void PrefDefaultProvider::ResetToDefaults() { | 156 void PrefDefaultProvider::ResetToDefaults() { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
158 base::AutoLock lock(lock_); | 158 base::AutoLock lock(lock_); |
159 default_content_settings_ = ContentSettings(); | 159 default_content_settings_ = ContentSettings(); |
160 ForceDefaultsToBeExplicit(); | 160 ForceDefaultsToBeExplicit(); |
161 | 161 |
162 if (!is_off_the_record_) { | 162 if (!is_incognito_) { |
163 PrefService* prefs = profile_->GetPrefs(); | 163 PrefService* prefs = profile_->GetPrefs(); |
164 updating_preferences_ = true; | 164 updating_preferences_ = true; |
165 prefs->ClearPref(prefs::kDefaultContentSettings); | 165 prefs->ClearPref(prefs::kDefaultContentSettings); |
166 updating_preferences_ = false; | 166 updating_preferences_ = false; |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 void PrefDefaultProvider::Observe(NotificationType type, | 170 void PrefDefaultProvider::Observe(NotificationType type, |
171 const NotificationSource& source, | 171 const NotificationSource& source, |
172 const NotificationDetails& details) { | 172 const NotificationDetails& details) { |
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
174 | 174 |
175 if (type == NotificationType::PREF_CHANGED) { | 175 if (type == NotificationType::PREF_CHANGED) { |
176 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 176 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); |
177 if (updating_preferences_) | 177 if (updating_preferences_) |
178 return; | 178 return; |
179 | 179 |
180 std::string* name = Details<std::string>(details).ptr(); | 180 std::string* name = Details<std::string>(details).ptr(); |
181 if (*name == prefs::kDefaultContentSettings) { | 181 if (*name == prefs::kDefaultContentSettings) { |
182 ReadDefaultSettings(true); | 182 ReadDefaultSettings(true); |
183 } else { | 183 } else { |
184 NOTREACHED() << "Unexpected preference observed"; | 184 NOTREACHED() << "Unexpected preference observed"; |
185 return; | 185 return; |
186 } | 186 } |
187 | 187 |
188 if (!is_off_the_record_) { | 188 if (!is_incognito_) { |
189 NotifyObservers(ContentSettingsDetails( | 189 NotifyObservers(ContentSettingsDetails( |
190 ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); | 190 ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); |
191 } | 191 } |
192 } else if (type == NotificationType::PROFILE_DESTROYED) { | 192 } else if (type == NotificationType::PROFILE_DESTROYED) { |
193 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | 193 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
194 UnregisterObservers(); | 194 UnregisterObservers(); |
195 } else { | 195 } else { |
196 NOTREACHED() << "Unexpected notification"; | 196 NOTREACHED() << "Unexpected notification"; |
197 } | 197 } |
198 } | 198 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 370 |
371 const ContentSettingsPattern pattern( | 371 const ContentSettingsPattern pattern( |
372 requesting_pattern.CanonicalizePattern()); | 372 requesting_pattern.CanonicalizePattern()); |
373 | 373 |
374 bool early_exit = false; | 374 bool early_exit = false; |
375 std::string pattern_str(pattern.AsString()); | 375 std::string pattern_str(pattern.AsString()); |
376 PrefService* prefs = NULL; | 376 PrefService* prefs = NULL; |
377 DictionaryValue* all_settings_dictionary = NULL; | 377 DictionaryValue* all_settings_dictionary = NULL; |
378 | 378 |
379 // Select content-settings-map to write to. | 379 // Select content-settings-map to write to. |
380 HostContentSettings* map_to_modify = off_the_record_settings(); | 380 HostContentSettings* map_to_modify = incognito_settings(); |
381 if (!is_off_the_record()) { | 381 if (!is_incognito()) { |
382 prefs = profile_->GetPrefs(); | 382 prefs = profile_->GetPrefs(); |
383 all_settings_dictionary = | 383 all_settings_dictionary = |
384 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); | 384 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); |
385 | 385 |
386 map_to_modify = host_content_settings(); | 386 map_to_modify = host_content_settings(); |
387 } | 387 } |
388 | 388 |
389 // Update content-settings-map. | 389 // Update content-settings-map. |
390 { | 390 { |
391 base::AutoLock auto_lock(lock()); | 391 base::AutoLock auto_lock(lock()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 host_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, | 452 host_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, |
453 NULL); | 453 NULL); |
454 } else { | 454 } else { |
455 host_settings_dictionary->SetWithoutPathExpansion( | 455 host_settings_dictionary->SetWithoutPathExpansion( |
456 dictionary_path, Value::CreateIntegerValue(setting)); | 456 dictionary_path, Value::CreateIntegerValue(setting)); |
457 } | 457 } |
458 } | 458 } |
459 } | 459 } |
460 | 460 |
461 updating_preferences_ = true; | 461 updating_preferences_ = true; |
462 if (!is_off_the_record()) | 462 if (!is_incognito()) |
463 ScopedUserPrefUpdate update(prefs, prefs::kContentSettingsPatterns); | 463 ScopedUserPrefUpdate update(prefs, prefs::kContentSettingsPatterns); |
464 updating_preferences_ = false; | 464 updating_preferences_ = false; |
465 | 465 |
466 NotifyObservers(ContentSettingsDetails(pattern, content_type, "")); | 466 NotifyObservers(ContentSettingsDetails(pattern, content_type, "")); |
467 } | 467 } |
468 | 468 |
469 void PrefProvider::ResetToDefaults() { | 469 void PrefProvider::ResetToDefaults() { |
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
471 | 471 |
472 { | 472 { |
473 base::AutoLock auto_lock(lock()); | 473 base::AutoLock auto_lock(lock()); |
474 host_content_settings()->clear(); | 474 host_content_settings()->clear(); |
475 off_the_record_settings()->clear(); | 475 incognito_settings()->clear(); |
476 } | 476 } |
477 | 477 |
478 if (!is_off_the_record()) { | 478 if (!is_incognito()) { |
479 PrefService* prefs = profile_->GetPrefs(); | 479 PrefService* prefs = profile_->GetPrefs(); |
480 updating_preferences_ = true; | 480 updating_preferences_ = true; |
481 prefs->ClearPref(prefs::kContentSettingsPatterns); | 481 prefs->ClearPref(prefs::kContentSettingsPatterns); |
482 updating_preferences_ = false; | 482 updating_preferences_ = false; |
483 } | 483 } |
484 } | 484 } |
485 | 485 |
486 void PrefProvider::ClearAllContentSettingsRules( | 486 void PrefProvider::ClearAllContentSettingsRules( |
487 ContentSettingsType content_type) { | 487 ContentSettingsType content_type) { |
488 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 488 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
489 | 489 |
490 PrefService* prefs = NULL; | 490 PrefService* prefs = NULL; |
491 DictionaryValue* all_settings_dictionary = NULL; | 491 DictionaryValue* all_settings_dictionary = NULL; |
492 HostContentSettings* map_to_modify = off_the_record_settings(); | 492 HostContentSettings* map_to_modify = incognito_settings(); |
493 | 493 |
494 if (!is_off_the_record()) { | 494 if (!is_incognito()) { |
495 prefs = profile_->GetPrefs(); | 495 prefs = profile_->GetPrefs(); |
496 all_settings_dictionary = | 496 all_settings_dictionary = |
497 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); | 497 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); |
498 map_to_modify = host_content_settings(); | 498 map_to_modify = host_content_settings(); |
499 } | 499 } |
500 | 500 |
501 { | 501 { |
502 base::AutoLock auto_lock(lock()); | 502 base::AutoLock auto_lock(lock()); |
503 for (HostContentSettings::iterator i(map_to_modify->begin()); | 503 for (HostContentSettings::iterator i(map_to_modify->begin()); |
504 i != map_to_modify->end(); ) { | 504 i != map_to_modify->end(); ) { |
(...skipping 19 matching lines...) Expand all Loading... |
524 kTypeNames[content_type], NULL); | 524 kTypeNames[content_type], NULL); |
525 ++i; | 525 ++i; |
526 } | 526 } |
527 } else { | 527 } else { |
528 ++i; | 528 ++i; |
529 } | 529 } |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
533 updating_preferences_ = true; | 533 updating_preferences_ = true; |
534 if (!is_off_the_record()) | 534 if (!is_incognito()) |
535 ScopedUserPrefUpdate update(prefs, prefs::kContentSettingsPatterns); | 535 ScopedUserPrefUpdate update(prefs, prefs::kContentSettingsPatterns); |
536 updating_preferences_ = false; | 536 updating_preferences_ = false; |
537 | 537 |
538 NotifyObservers( | 538 NotifyObservers( |
539 ContentSettingsDetails(ContentSettingsPattern(), content_type, "")); | 539 ContentSettingsDetails(ContentSettingsPattern(), content_type, "")); |
540 } | 540 } |
541 | 541 |
542 void PrefProvider::Observe( | 542 void PrefProvider::Observe( |
543 NotificationType type, | 543 NotificationType type, |
544 const NotificationSource& source, | 544 const NotificationSource& source, |
545 const NotificationDetails& details) { | 545 const NotificationDetails& details) { |
546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
547 | 547 |
548 if (type == NotificationType::PREF_CHANGED) { | 548 if (type == NotificationType::PREF_CHANGED) { |
549 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 549 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); |
550 if (updating_preferences_) | 550 if (updating_preferences_) |
551 return; | 551 return; |
552 | 552 |
553 std::string* name = Details<std::string>(details).ptr(); | 553 std::string* name = Details<std::string>(details).ptr(); |
554 if (*name == prefs::kContentSettingsPatterns) { | 554 if (*name == prefs::kContentSettingsPatterns) { |
555 ReadExceptions(true); | 555 ReadExceptions(true); |
556 } else { | 556 } else { |
557 NOTREACHED() << "Unexpected preference observed"; | 557 NOTREACHED() << "Unexpected preference observed"; |
558 return; | 558 return; |
559 } | 559 } |
560 | 560 |
561 if (!is_off_the_record()) { | 561 if (!is_incognito()) { |
562 NotifyObservers(ContentSettingsDetails(ContentSettingsPattern(), | 562 NotifyObservers(ContentSettingsDetails(ContentSettingsPattern(), |
563 CONTENT_SETTINGS_TYPE_DEFAULT, | 563 CONTENT_SETTINGS_TYPE_DEFAULT, |
564 "")); | 564 "")); |
565 } | 565 } |
566 } else if (type == NotificationType::PROFILE_DESTROYED) { | 566 } else if (type == NotificationType::PROFILE_DESTROYED) { |
567 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | 567 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
568 UnregisterObservers(); | 568 UnregisterObservers(); |
569 } else { | 569 } else { |
570 NOTREACHED() << "Unexpected notification"; | 570 NOTREACHED() << "Unexpected notification"; |
571 } | 571 } |
(...skipping 14 matching lines...) Expand all Loading... |
586 prefs->GetDictionary(prefs::kContentSettingsPatterns); | 586 prefs->GetDictionary(prefs::kContentSettingsPatterns); |
587 | 587 |
588 if (overwrite) | 588 if (overwrite) |
589 host_content_settings()->clear(); | 589 host_content_settings()->clear(); |
590 | 590 |
591 // Careful: The returned value could be NULL if the pref has never been set. | 591 // Careful: The returned value could be NULL if the pref has never been set. |
592 if (all_settings_dictionary != NULL) { | 592 if (all_settings_dictionary != NULL) { |
593 DictionaryValue* mutable_settings; | 593 DictionaryValue* mutable_settings; |
594 scoped_ptr<DictionaryValue> mutable_settings_scope; | 594 scoped_ptr<DictionaryValue> mutable_settings_scope; |
595 | 595 |
596 if (!is_off_the_record()) { | 596 if (!is_incognito()) { |
597 mutable_settings = | 597 mutable_settings = |
598 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); | 598 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); |
599 } else { | 599 } else { |
600 // Create copy as we do not want to persist anything in OTR prefs. | 600 // Create copy as we do not want to persist anything in OTR prefs. |
601 mutable_settings = all_settings_dictionary->DeepCopy(); | 601 mutable_settings = all_settings_dictionary->DeepCopy(); |
602 mutable_settings_scope.reset(mutable_settings); | 602 mutable_settings_scope.reset(mutable_settings); |
603 } | 603 } |
604 | 604 |
605 // Convert all Unicode patterns into punycode form, then read. | 605 // Convert all Unicode patterns into punycode form, then read. |
606 CanonicalizeContentSettingsExceptions(mutable_settings); | 606 CanonicalizeContentSettingsExceptions(mutable_settings); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 ContentSettingsPattern(host), | 797 ContentSettingsPattern(host), |
798 CONTENT_SETTINGS_TYPE_POPUPS, | 798 CONTENT_SETTINGS_TYPE_POPUPS, |
799 "", | 799 "", |
800 CONTENT_SETTING_ALLOW); | 800 CONTENT_SETTING_ALLOW); |
801 } | 801 } |
802 prefs->ClearPref(prefs::kPopupWhitelistedHosts); | 802 prefs->ClearPref(prefs::kPopupWhitelistedHosts); |
803 } | 803 } |
804 } | 804 } |
805 | 805 |
806 } // namespace content_settings | 806 } // namespace content_settings |
OLD | NEW |