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

Side by Side Diff: chrome/browser/content_settings/content_settings_pref_provider.cc

Issue 7088017: Split incognito extension content settings in session-only and persistent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 9 years, 6 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 (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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ContentSettingsType content_type) const { 126 ContentSettingsType content_type) const {
127 base::AutoLock lock(lock_); 127 base::AutoLock lock(lock_);
128 return default_content_settings_.settings[content_type]; 128 return default_content_settings_.settings[content_type];
129 } 129 }
130 130
131 void PrefDefaultProvider::UpdateDefaultSetting( 131 void PrefDefaultProvider::UpdateDefaultSetting(
132 ContentSettingsType content_type, 132 ContentSettingsType content_type,
133 ContentSetting setting) { 133 ContentSetting setting) {
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
135 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. 135 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation.
136 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS ||
137 setting != CONTENT_SETTING_ASK ||
138 CommandLine::ForCurrentProcess()->HasSwitch(
139 switches::kEnableClickToPlay));
140 136
141 // The default settings may not be directly modified for OTR sessions. 137 // The default settings may not be directly modified for OTR sessions.
142 // Instead, they are synced to the main profile's setting. 138 // Instead, they are synced to the main profile's setting.
143 if (is_incognito_) 139 if (is_incognito_)
144 return; 140 return;
145 141
146 PrefService* prefs = profile_->GetPrefs(); 142 PrefService* prefs = profile_->GetPrefs();
147 143
148 std::string dictionary_path(kTypeNames[content_type]); 144 std::string dictionary_path(kTypeNames[content_type]);
149 updating_preferences_ = true; 145 updating_preferences_ = true;
150 { 146 {
151 base::AutoLock lock(lock_); 147 base::AutoLock lock(lock_);
152 DictionaryPrefUpdate update(prefs, prefs::kDefaultContentSettings); 148 DictionaryPrefUpdate update(prefs, prefs::kDefaultContentSettings);
153 DictionaryValue* default_settings_dictionary = update.Get(); 149 DictionaryValue* default_settings_dictionary = update.Get();
154 if ((setting == CONTENT_SETTING_DEFAULT) || 150 if ((setting == CONTENT_SETTING_DEFAULT) ||
155 (setting == kDefaultSettings[content_type])) { 151 (setting == kDefaultSettings[content_type])) {
156 default_content_settings_.settings[content_type] = 152 default_content_settings_.settings[content_type] =
157 kDefaultSettings[content_type]; 153 kDefaultSettings[content_type];
158 default_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, 154 default_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path,
159 NULL); 155 NULL);
160 } else { 156 } else {
161 default_content_settings_.settings[content_type] = setting; 157 default_content_settings_.settings[content_type] = setting;
162 default_settings_dictionary->SetWithoutPathExpansion( 158 default_settings_dictionary->SetWithoutPathExpansion(
163 dictionary_path, Value::CreateIntegerValue(setting)); 159 dictionary_path, Value::CreateIntegerValue(setting));
164 } 160 }
165 } 161 }
166 updating_preferences_ = false; 162 updating_preferences_ = false;
167 163
168 NotifyObservers( 164 ContentSettingsDetails details(
169 ContentSettingsDetails(ContentSettingsPattern(), content_type, "")); 165 ContentSettingsPattern(), content_type, std::string());
166 NotifyObservers(details);
170 } 167 }
171 168
172 bool PrefDefaultProvider::DefaultSettingIsManaged( 169 bool PrefDefaultProvider::DefaultSettingIsManaged(
173 ContentSettingsType content_type) const { 170 ContentSettingsType content_type) const {
174 return false; 171 return false;
175 } 172 }
176 173
177 void PrefDefaultProvider::ResetToDefaults() { 174 void PrefDefaultProvider::ResetToDefaults() {
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
179 base::AutoLock lock(lock_); 176 base::AutoLock lock(lock_);
(...skipping 20 matching lines...) Expand all
200 197
201 std::string* name = Details<std::string>(details).ptr(); 198 std::string* name = Details<std::string>(details).ptr();
202 if (*name == prefs::kDefaultContentSettings) { 199 if (*name == prefs::kDefaultContentSettings) {
203 ReadDefaultSettings(true); 200 ReadDefaultSettings(true);
204 } else { 201 } else {
205 NOTREACHED() << "Unexpected preference observed"; 202 NOTREACHED() << "Unexpected preference observed";
206 return; 203 return;
207 } 204 }
208 205
209 if (!is_incognito_) { 206 if (!is_incognito_) {
210 NotifyObservers(ContentSettingsDetails( 207 ContentSettingsDetails details(ContentSettingsPattern(),
211 ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); 208 CONTENT_SETTINGS_TYPE_DEFAULT,
209 std::string());
210 NotifyObservers(details);
212 } 211 }
213 } else if (type == NotificationType::PROFILE_DESTROYED) { 212 } else if (type == NotificationType::PROFILE_DESTROYED) {
214 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); 213 DCHECK_EQ(profile_, Source<Profile>(source).ptr());
215 UnregisterObservers(); 214 UnregisterObservers();
216 } else { 215 } else {
217 NOTREACHED() << "Unexpected notification"; 216 NOTREACHED() << "Unexpected notification";
218 } 217 }
219 } 218 }
220 219
221 void PrefDefaultProvider::UnregisterObservers() { 220 void PrefDefaultProvider::UnregisterObservers() {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 NULL); 489 NULL);
491 } else { 490 } else {
492 host_settings_dictionary->SetWithoutPathExpansion( 491 host_settings_dictionary->SetWithoutPathExpansion(
493 dictionary_path, Value::CreateIntegerValue(setting)); 492 dictionary_path, Value::CreateIntegerValue(setting));
494 } 493 }
495 } 494 }
496 } 495 }
497 } // End scope of update. 496 } // End scope of update.
498 updating_preferences_ = false; 497 updating_preferences_ = false;
499 498
500 NotifyObservers(ContentSettingsDetails(requesting_pattern, content_type, "")); 499 ContentSettingsDetails details(
500 requesting_pattern, content_type, std::string());
501 NotifyObservers(details);
501 } 502 }
502 503
503 void PrefProvider::ResetToDefaults() { 504 void PrefProvider::ResetToDefaults() {
504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
505 506
506 { 507 {
507 base::AutoLock auto_lock(lock()); 508 base::AutoLock auto_lock(lock());
508 host_content_settings()->clear(); 509 host_content_settings()->clear();
509 incognito_settings()->clear(); 510 incognito_settings()->clear();
510 } 511 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 ++i; 562 ++i;
562 } 563 }
563 } else { 564 } else {
564 ++i; 565 ++i;
565 } 566 }
566 } 567 }
567 } 568 }
568 } // End scope of update. 569 } // End scope of update.
569 updating_preferences_ = false; 570 updating_preferences_ = false;
570 571
571 NotifyObservers( 572 ContentSettingsDetails details(
572 ContentSettingsDetails(ContentSettingsPattern(), content_type, "")); 573 ContentSettingsPattern(), content_type, std::string());
574 NotifyObservers(details);
573 } 575 }
574 576
575 void PrefProvider::Observe( 577 void PrefProvider::Observe(
576 NotificationType type, 578 NotificationType type,
577 const NotificationSource& source, 579 const NotificationSource& source,
578 const NotificationDetails& details) { 580 const NotificationDetails& details) {
579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
580 582
581 if (type == NotificationType::PREF_CHANGED) { 583 if (type == NotificationType::PREF_CHANGED) {
582 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); 584 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr());
583 if (updating_preferences_) 585 if (updating_preferences_)
584 return; 586 return;
585 587
586 std::string* name = Details<std::string>(details).ptr(); 588 std::string* name = Details<std::string>(details).ptr();
587 if (*name == prefs::kContentSettingsPatterns) { 589 if (*name == prefs::kContentSettingsPatterns) {
588 ReadExceptions(true); 590 ReadExceptions(true);
589 } else { 591 } else {
590 NOTREACHED() << "Unexpected preference observed"; 592 NOTREACHED() << "Unexpected preference observed";
591 return; 593 return;
592 } 594 }
593 595
594 if (!is_incognito()) { 596 if (!is_incognito()) {
595 NotifyObservers(ContentSettingsDetails(ContentSettingsPattern(), 597 ContentSettingsDetails details(ContentSettingsPattern(),
596 CONTENT_SETTINGS_TYPE_DEFAULT, 598 CONTENT_SETTINGS_TYPE_DEFAULT,
597 "")); 599 std::string());
600 NotifyObservers(details);
598 } 601 }
599 } else if (type == NotificationType::PROFILE_DESTROYED) { 602 } else if (type == NotificationType::PROFILE_DESTROYED) {
600 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); 603 DCHECK_EQ(profile_, Source<Profile>(source).ptr());
601 UnregisterObservers(); 604 UnregisterObservers();
602 } else { 605 } else {
603 NOTREACHED() << "Unexpected notification"; 606 NOTREACHED() << "Unexpected notification";
604 } 607 }
605 } 608 }
606 609
607 PrefProvider::~PrefProvider() { 610 PrefProvider::~PrefProvider() {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 ContentSettingsPattern::FromString(host), 836 ContentSettingsPattern::FromString(host),
834 CONTENT_SETTINGS_TYPE_POPUPS, 837 CONTENT_SETTINGS_TYPE_POPUPS,
835 "", 838 "",
836 CONTENT_SETTING_ALLOW); 839 CONTENT_SETTING_ALLOW);
837 } 840 }
838 prefs->ClearPref(prefs::kPopupWhitelistedHosts); 841 prefs->ClearPref(prefs::kPopupWhitelistedHosts);
839 } 842 }
840 } 843 }
841 844
842 } // namespace content_settings 845 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698