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

Side by Side Diff: chrome/browser/blocked_popup_container.cc

Issue 434109: Don't save popup blocker whitelist modifications performed while off the reco... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
« no previous file with comments | « chrome/browser/blocked_popup_container.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "chrome/browser/blocked_popup_container.h" 5 #include "chrome/browser/blocked_popup_container.h"
6 6
7 #include "chrome/browser/profile.h" 7 #include "chrome/browser/profile.h"
8 #include "chrome/browser/tab_contents/tab_contents.h" 8 #include "chrome/browser/tab_contents/tab_contents.h"
9 #include "chrome/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "chrome/common/pref_service.h" 10 #include "chrome/common/pref_service.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 bool BlockedPopupContainer::IsHostWhitelisted(size_t index) const { 148 bool BlockedPopupContainer::IsHostWhitelisted(size_t index) const {
149 return ConvertHostIndexToIterator(index)->second; 149 return ConvertHostIndexToIterator(index)->second;
150 } 150 }
151 151
152 void BlockedPopupContainer::ToggleWhitelistingForHost(size_t index) { 152 void BlockedPopupContainer::ToggleWhitelistingForHost(size_t index) {
153 PopupHosts::const_iterator i(ConvertHostIndexToIterator(index)); 153 PopupHosts::const_iterator i(ConvertHostIndexToIterator(index));
154 const std::string& host = i->first; 154 const std::string& host = i->first;
155 bool should_whitelist = !i->second; 155 bool should_whitelist = !i->second;
156 popup_hosts_[host] = should_whitelist; 156 popup_hosts_[host] = should_whitelist;
157 157
158 ListValue* whitelist_pref =
159 prefs_->GetMutableList(prefs::kPopupWhitelistedHosts);
160 if (should_whitelist) { 158 if (should_whitelist) {
161 whitelist_.insert(host); 159 whitelist_.insert(host);
162 whitelist_pref->Append(new StringValue(host));
163 160
164 // Open the popups in order. 161 // Open the popups in order.
165 for (size_t j = 0; j < blocked_popups_.size();) { 162 for (size_t j = 0; j < blocked_popups_.size();) {
166 if (blocked_popups_[j].host == host) 163 if (blocked_popups_[j].host == host)
167 LaunchPopupAtIndex(j); // This shifts the rest of the entries down. 164 LaunchPopupAtIndex(j); // This shifts the rest of the entries down.
168 else 165 else
169 ++j; 166 ++j;
170 } 167 }
171 } else { 168 } else {
172 // Remove from whitelist. 169 // Remove from whitelist.
173 whitelist_.erase(host); 170 whitelist_.erase(host);
174 StringValue host_as_string(host);
175 whitelist_pref->Remove(host_as_string);
176 171
177 for (UnblockedPopups::iterator i(unblocked_popups_.begin()); 172 for (UnblockedPopups::iterator i(unblocked_popups_.begin());
178 i != unblocked_popups_.end(); ) { 173 i != unblocked_popups_.end(); ) {
179 TabContents* tab_contents = i->first; 174 TabContents* tab_contents = i->first;
180 TabContentsDelegate* delegate = tab_contents->delegate(); 175 TabContentsDelegate* delegate = tab_contents->delegate();
181 if ((i->second == host) && delegate->IsPopup(tab_contents)) { 176 if ((i->second == host) && delegate->IsPopup(tab_contents)) {
182 // Convert the popup back into a blocked popup. 177 // Convert the popup back into a blocked popup.
183 delegate->DetachContents(tab_contents); 178 delegate->DetachContents(tab_contents);
184 tab_contents->set_delegate(this); 179 tab_contents->set_delegate(this);
185 180
186 // Add the popup to the blocked list. (Do this before the below call!) 181 // Add the popup to the blocked list. (Do this before the below call!)
187 gfx::Rect bounds; 182 gfx::Rect bounds;
188 tab_contents->GetContainerBounds(&bounds); 183 tab_contents->GetContainerBounds(&bounds);
189 blocked_popups_.push_back(BlockedPopup(tab_contents, bounds, host)); 184 blocked_popups_.push_back(BlockedPopup(tab_contents, bounds, host));
190 185
191 // Remove the popup from the unblocked list. 186 // Remove the popup from the unblocked list.
192 UnblockedPopups::iterator to_erase = i; 187 UnblockedPopups::iterator to_erase = i;
193 ++i; 188 ++i;
194 EraseDataForPopupAndUpdateUI(to_erase); 189 EraseDataForPopupAndUpdateUI(to_erase);
195 } else { 190 } else {
196 ++i; 191 ++i;
197 } 192 }
198 } 193 }
199 } 194 }
195
196 // Persist whitelisting state if we're not off the record.
197 if (prefs_) {
198 ListValue* whitelist_pref =
199 prefs_->GetMutableList(prefs::kPopupWhitelistedHosts);
200 if (should_whitelist) {
201 whitelist_pref->Append(new StringValue(host));
202 } else {
203 // Stupidly, gcc complains that you're accessing the (private) StringValue
204 // copy constructor if you inline the temp creation into the Remove()
205 // call.
206 StringValue host_value(host);
207 whitelist_pref->Remove(host_value);
208 }
209 }
200 } 210 }
201 211
202 void BlockedPopupContainer::CloseAll() { 212 void BlockedPopupContainer::CloseAll() {
203 ClearData(); 213 ClearData();
204 HideSelf(); 214 HideSelf();
205 } 215 }
206 216
207 void BlockedPopupContainer::Destroy() { 217 void BlockedPopupContainer::Destroy() {
208 view_->Destroy(); 218 view_->Destroy();
209 219
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 Profile* profile) 394 Profile* profile)
385 : owner_(owner), 395 : owner_(owner),
386 prefs_(profile->GetPrefs()), 396 prefs_(profile->GetPrefs()),
387 has_been_dismissed_(false), 397 has_been_dismissed_(false),
388 view_(NULL), 398 view_(NULL),
389 profile_(profile) { 399 profile_(profile) {
390 // Copy whitelist pref into local member that's easier to use. 400 // Copy whitelist pref into local member that's easier to use.
391 const ListValue* whitelist_pref = 401 const ListValue* whitelist_pref =
392 prefs_->GetList(prefs::kPopupWhitelistedHosts); 402 prefs_->GetList(prefs::kPopupWhitelistedHosts);
393 // Careful: The returned value could be NULL if the pref has never been set. 403 // Careful: The returned value could be NULL if the pref has never been set.
394 if (whitelist_pref == NULL) 404 if (whitelist_pref != NULL) {
395 return; 405 for (ListValue::const_iterator i(whitelist_pref->begin());
396 for (ListValue::const_iterator i(whitelist_pref->begin()); 406 i != whitelist_pref->end(); ++i) {
397 i != whitelist_pref->end(); ++i) { 407 std::string host;
398 std::string host; 408 (*i)->GetAsString(&host);
399 (*i)->GetAsString(&host); 409 whitelist_.insert(host);
400 whitelist_.insert(host); 410 }
401 } 411 }
412
413 if (profile->IsOffTheRecord())
414 prefs_ = NULL; // Don't persist any zoom levels.
Elliot Glaysher 2009/11/30 17:39:13 I assume this comment was copy/pasted?
402 } 415 }
403 416
404 void BlockedPopupContainer::UpdateView() { 417 void BlockedPopupContainer::UpdateView() {
405 if (blocked_popups_.empty() && unblocked_popups_.empty() && 418 if (blocked_popups_.empty() && unblocked_popups_.empty() &&
406 blocked_notices_.empty()) 419 blocked_notices_.empty())
407 HideSelf(); 420 HideSelf();
408 else 421 else
409 view_->UpdateLabel(); 422 view_->UpdateLabel();
410 } 423 }
411 424
412 void BlockedPopupContainer::Observe(NotificationType type, 425 void BlockedPopupContainer::Observe(NotificationType type,
413 const NotificationSource& source, 426 const NotificationSource& source,
414 const NotificationDetails& details) { 427 const NotificationDetails& details) {
415 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); 428 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
416 TabContents* tab_contents = Source<TabContents>(source).ptr(); 429 TabContents* tab_contents = Source<TabContents>(source).ptr();
417 UnblockedPopups::iterator i(unblocked_popups_.find(tab_contents)); 430 UnblockedPopups::iterator i(unblocked_popups_.find(tab_contents));
418 DCHECK(i != unblocked_popups_.end()); 431 DCHECK(i != unblocked_popups_.end());
419 EraseDataForPopupAndUpdateUI(i); 432 EraseDataForPopupAndUpdateUI(i);
420 } 433 }
OLDNEW
« no previous file with comments | « chrome/browser/blocked_popup_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698