| Index: chrome/browser/views/blocked_popup_container.cc
|
| ===================================================================
|
| --- chrome/browser/views/blocked_popup_container.cc (revision 15670)
|
| +++ chrome/browser/views/blocked_popup_container.cc (working copy)
|
| @@ -21,6 +21,8 @@
|
| #include "chrome/browser/profile.h"
|
| #include "chrome/browser/tab_contents/tab_contents.h"
|
| #include "chrome/common/notification_service.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "chrome/common/pref_service.h"
|
| #include "grit/generated_resources.h"
|
| #include "grit/theme_resources.h"
|
| #include "views/background.h"
|
| @@ -221,7 +223,7 @@
|
| }
|
|
|
| void BlockedPopupContainerView::ExecuteCommand(int id) {
|
| - DCHECK(id > 0);
|
| + DCHECK_GT(id, 0);
|
| size_t id_size_t = static_cast<size_t>(id);
|
| if (id_size_t > kImpossibleNumberOfPopups) {
|
| // Decrement id since all index based commands have 1 added to them. (See
|
| @@ -234,9 +236,15 @@
|
| }
|
|
|
| // static
|
| +void BlockedPopupContainer::RegisterUserPrefs(PrefService* prefs) {
|
| + prefs->RegisterListPref(prefs::kPopupWhitelistedHosts);
|
| +}
|
| +
|
| +// static
|
| BlockedPopupContainer* BlockedPopupContainer::Create(
|
| TabContents* owner, Profile* profile, const gfx::Point& initial_anchor) {
|
| - BlockedPopupContainer* container = new BlockedPopupContainer(owner, profile);
|
| + BlockedPopupContainer* container =
|
| + new BlockedPopupContainer(owner, profile->GetPrefs());
|
| container->Init(initial_anchor);
|
| return container;
|
| }
|
| @@ -245,21 +253,33 @@
|
| }
|
|
|
| BlockedPopupContainer::BlockedPopupContainer(TabContents* owner,
|
| - Profile* profile)
|
| + PrefService* prefs)
|
| : Animation(kFramerate, NULL),
|
| owner_(owner),
|
| + prefs_(prefs),
|
| container_view_(NULL),
|
| has_been_dismissed_(false),
|
| in_show_animation_(false),
|
| visibility_percentage_(0) {
|
| + // Copy whitelist pref into local member that's easier to use.
|
| + const ListValue* whitelist_pref =
|
| + prefs_->GetList(prefs::kPopupWhitelistedHosts);
|
| + // Careful: The returned value could be NULL if the pref has never been set.
|
| + if (whitelist_pref != NULL) {
|
| + for (ListValue::const_iterator i(whitelist_pref->begin());
|
| + i != whitelist_pref->end(); ++i) {
|
| + std::string host;
|
| + (*i)->GetAsString(&host);
|
| + whitelist_.insert(host);
|
| + }
|
| + }
|
| }
|
|
|
| void BlockedPopupContainer::AddTabContents(TabContents* tab_contents,
|
| const gfx::Rect& bounds,
|
| const std::string& host) {
|
| - bool whitelisted = false; // TODO: Check if host is on whitelist.
|
| -
|
| // Show whitelisted popups immediately.
|
| + bool whitelisted = !!whitelist_.count(host);
|
| if (whitelisted)
|
| owner_->AddNewContents(tab_contents, NEW_POPUP, bounds, true, GURL());
|
|
|
| @@ -293,7 +313,7 @@
|
| if (i == popup_hosts_.end())
|
| popup_hosts_[host] = whitelisted;
|
| else
|
| - DCHECK(!i->second); // This host was already reported as whitelisted!
|
| + DCHECK_EQ(whitelisted, i->second);
|
|
|
| // Update UI.
|
| container_view_->UpdateLabel();
|
| @@ -364,9 +384,13 @@
|
| const std::string& host = i->first;
|
| bool should_whitelist = !i->second;
|
| popup_hosts_[host] = should_whitelist;
|
| - // TODO: Update whitelist pref.
|
|
|
| + ListValue* whitelist_pref =
|
| + prefs_->GetMutableList(prefs::kPopupWhitelistedHosts);
|
| if (should_whitelist) {
|
| + whitelist_.insert(host);
|
| + whitelist_pref->Append(new StringValue(host));
|
| +
|
| // Open the popups in order.
|
| for (size_t j = 0; j < blocked_popups_.size(); ) {
|
| if (blocked_popups_[j].host == host)
|
| @@ -375,6 +399,11 @@
|
| ++j;
|
| }
|
| } else {
|
| + // Remove from whitelist.
|
| + whitelist_.erase(host);
|
| + StringValue host_value(host);
|
| + whitelist_pref->Remove(&host_value);
|
| +
|
| for (UnblockedPopups::iterator i(unblocked_popups_.begin());
|
| i != unblocked_popups_.end(); ) {
|
| TabContents* tab_contents = i->first;
|
|
|