| OLD | NEW |
| 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" |
| 11 #include "chrome/common/notification_service.h" | 11 #include "chrome/common/notification_service.h" |
| 12 | 12 |
| 13 // static | 13 // static |
| 14 BlockedPopupContainer* BlockedPopupContainer::Create( | 14 BlockedPopupContainer* BlockedPopupContainer::Create( |
| 15 TabContents* owner, Profile* profile) { | 15 TabContents* owner, Profile* profile) { |
| 16 BlockedPopupContainer* container = | 16 BlockedPopupContainer* container = |
| 17 new BlockedPopupContainer(owner, profile->GetPrefs()); | 17 new BlockedPopupContainer(owner, profile); |
| 18 BlockedPopupContainerView* view = | 18 BlockedPopupContainerView* view = |
| 19 BlockedPopupContainerView::Create(container); | 19 BlockedPopupContainerView::Create(container); |
| 20 container->set_view(view); | 20 container->set_view(view); |
| 21 return container; | 21 return container; |
| 22 } | 22 } |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 BlockedPopupContainer* BlockedPopupContainer::Create( | 25 BlockedPopupContainer* BlockedPopupContainer::Create( |
| 26 TabContents* owner, Profile* profile, BlockedPopupContainerView* view) { | 26 TabContents* owner, Profile* profile, BlockedPopupContainerView* view) { |
| 27 BlockedPopupContainer* container = | 27 BlockedPopupContainer* container = |
| 28 new BlockedPopupContainer(owner, profile->GetPrefs()); | 28 new BlockedPopupContainer(owner, profile); |
| 29 container->set_view(view); | 29 container->set_view(view); |
| 30 return container; | 30 return container; |
| 31 } | 31 } |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 void BlockedPopupContainer::RegisterUserPrefs(PrefService* prefs) { | 34 void BlockedPopupContainer::RegisterUserPrefs(PrefService* prefs) { |
| 35 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts); | 35 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void BlockedPopupContainer::AddTabContents(TabContents* tab_contents, | 38 void BlockedPopupContainer::AddTabContents(TabContents* tab_contents, |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 339 |
| 340 // Erase the popup and update the UI. | 340 // Erase the popup and update the UI. |
| 341 unblocked_popups_.erase(i); | 341 unblocked_popups_.erase(i); |
| 342 UpdateView(); | 342 UpdateView(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 | 345 |
| 346 // private: | 346 // private: |
| 347 | 347 |
| 348 BlockedPopupContainer::BlockedPopupContainer(TabContents* owner, | 348 BlockedPopupContainer::BlockedPopupContainer(TabContents* owner, |
| 349 PrefService* prefs) | 349 Profile* profile) |
| 350 : owner_(owner), | 350 : owner_(owner), |
| 351 prefs_(prefs), | 351 prefs_(profile->GetPrefs()), |
| 352 has_been_dismissed_(false), | 352 has_been_dismissed_(false), |
| 353 view_(NULL) { | 353 view_(NULL), |
| 354 profile_(profile) { |
| 354 // Copy whitelist pref into local member that's easier to use. | 355 // Copy whitelist pref into local member that's easier to use. |
| 355 const ListValue* whitelist_pref = | 356 const ListValue* whitelist_pref = |
| 356 prefs_->GetList(prefs::kPopupWhitelistedHosts); | 357 prefs_->GetList(prefs::kPopupWhitelistedHosts); |
| 357 // Careful: The returned value could be NULL if the pref has never been set. | 358 // Careful: The returned value could be NULL if the pref has never been set. |
| 358 if (whitelist_pref != NULL) { | 359 if (whitelist_pref != NULL) { |
| 359 for (ListValue::const_iterator i(whitelist_pref->begin()); | 360 for (ListValue::const_iterator i(whitelist_pref->begin()); |
| 360 i != whitelist_pref->end(); ++i) { | 361 i != whitelist_pref->end(); ++i) { |
| 361 std::string host; | 362 std::string host; |
| 362 (*i)->GetAsString(&host); | 363 (*i)->GetAsString(&host); |
| 363 whitelist_.insert(host); | 364 whitelist_.insert(host); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 374 | 375 |
| 375 void BlockedPopupContainer::Observe(NotificationType type, | 376 void BlockedPopupContainer::Observe(NotificationType type, |
| 376 const NotificationSource& source, | 377 const NotificationSource& source, |
| 377 const NotificationDetails& details) { | 378 const NotificationDetails& details) { |
| 378 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); | 379 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); |
| 379 TabContents* tab_contents = Source<TabContents>(source).ptr(); | 380 TabContents* tab_contents = Source<TabContents>(source).ptr(); |
| 380 UnblockedPopups::iterator i(unblocked_popups_.find(tab_contents)); | 381 UnblockedPopups::iterator i(unblocked_popups_.find(tab_contents)); |
| 381 DCHECK(i != unblocked_popups_.end()); | 382 DCHECK(i != unblocked_popups_.end()); |
| 382 EraseDataForPopupAndUpdateUI(i); | 383 EraseDataForPopupAndUpdateUI(i); |
| 383 } | 384 } |
| OLD | NEW |