summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-09 00:33:04 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-09 00:33:04 +0000
commite7f5c6f8aede399fe896e8218d89087408011d18 (patch)
tree58ed75a2b1ae424a089a9a9fd8bb5724fed35ded /chrome
parent1188a6c0b9025c6ccb9eff833599b951fc778a9a (diff)
downloadchromium_src-e7f5c6f8aede399fe896e8218d89087408011d18.zip
chromium_src-e7f5c6f8aede399fe896e8218d89087408011d18.tar.gz
chromium_src-e7f5c6f8aede399fe896e8218d89087408011d18.tar.bz2
Implement the popup blocking whitelist pref. This makes the whitelist actually function.BUG=11440
Review URL: http://codereview.chromium.org/115149 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15702 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_prefs.cc4
-rw-r--r--chrome/browser/views/blocked_popup_container.cc66
-rw-r--r--chrome/browser/views/blocked_popup_container.h17
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
5 files changed, 70 insertions, 21 deletions
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc
index fce04ae..014c7b6 100644
--- a/chrome/browser/browser_prefs.cc
+++ b/chrome/browser/browser_prefs.cc
@@ -25,6 +25,7 @@
#if defined(OS_WIN) // TODO(port): whittle this down as we port
#include "chrome/browser/task_manager.h"
+#include "chrome/browser/views/blocked_popup_container.h"
#include "chrome/browser/views/bookmark_manager_view.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/keyword_editor_view.h"
@@ -63,6 +64,9 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) {
TabContents::RegisterUserPrefs(user_prefs);
TemplateURLPrepopulateData::RegisterUserPrefs(user_prefs);
NewTabUI::RegisterUserPrefs(user_prefs);
+#if defined(OS_WIN) // TODO(port): whittle this down as we port
+ BlockedPopupContainer::RegisterUserPrefs(user_prefs);
+#endif
}
} // namespace browser
diff --git a/chrome/browser/views/blocked_popup_container.cc b/chrome/browser/views/blocked_popup_container.cc
index 5fcd792..47e5f8e 100644
--- a/chrome/browser/views/blocked_popup_container.cc
+++ b/chrome/browser/views/blocked_popup_container.cc
@@ -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 @@ bool BlockedPopupContainerView::IsItemChecked(int id) const {
}
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
@@ -233,33 +235,28 @@ void BlockedPopupContainerView::ExecuteCommand(int id) {
}
}
+BlockedPopupContainer::~BlockedPopupContainer() {
+}
+
+// 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;
}
-BlockedPopupContainer::~BlockedPopupContainer() {
-}
-
-BlockedPopupContainer::BlockedPopupContainer(TabContents* owner,
- Profile* profile)
- : Animation(kFramerate, NULL),
- owner_(owner),
- container_view_(NULL),
- has_been_dismissed_(false),
- in_show_animation_(false),
- visibility_percentage_(0) {
-}
-
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 +290,7 @@ void BlockedPopupContainer::AddTabContents(TabContents* tab_contents,
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 +361,13 @@ void BlockedPopupContainer::ToggleWhitelistingForHost(size_t index) {
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 +376,10 @@ void BlockedPopupContainer::ToggleWhitelistingForHost(size_t index) {
++j;
}
} else {
+ // Remove from whitelist.
+ whitelist_.erase(host);
+ whitelist_pref->Remove(StringValue(host));
+
for (UnblockedPopups::iterator i(unblocked_popups_.begin());
i != unblocked_popups_.end(); ) {
TabContents* tab_contents = i->first;
@@ -482,6 +487,29 @@ ExtensionFunctionDispatcher* BlockedPopupContainer::
// private:
+BlockedPopupContainer::BlockedPopupContainer(TabContents* owner,
+ 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::AnimateToState(double state) {
visibility_percentage_ = in_show_animation_ ? state : (1 - state);
SetPosition();
diff --git a/chrome/browser/views/blocked_popup_container.h b/chrome/browser/views/blocked_popup_container.h
index 894cc42..640bdd0 100644
--- a/chrome/browser/views/blocked_popup_container.h
+++ b/chrome/browser/views/blocked_popup_container.h
@@ -10,6 +10,7 @@
#ifndef CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_H_
#define CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_H_
+#include <set>
#include <utility>
#include <vector>
@@ -25,6 +26,7 @@
#include "views/widget/widget_win.h"
class BlockedPopupContainer;
+class PrefService;
class Profile;
class TabContents;
class TextButton;
@@ -93,6 +95,8 @@ class BlockedPopupContainer : public Animation,
public:
virtual ~BlockedPopupContainer();
+ static void RegisterUserPrefs(PrefService* prefs);
+
// Creates a BlockedPopupContainer, anchoring the container to the lower
// right corner.
static BlockedPopupContainer* Create(
@@ -200,7 +204,7 @@ class BlockedPopupContainer : public Animation,
virtual void UpdateTargetURL(TabContents* source, const GURL& url) { }
// Creates an ExtensionFunctionDispatcher that has no browser
- virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher(
+ virtual ExtensionFunctionDispatcher* CreateExtensionFunctionDispatcher(
RenderViewHost* render_view_host,
const std::string& extension_id);
@@ -224,8 +228,11 @@ class BlockedPopupContainer : public Animation,
// string is hostname. bool is whitelisted status.
typedef std::map<std::string, bool> PopupHosts;
+ // string is hostname.
+ typedef std::set<std::string> Whitelist;
+
// Creates a container for a certain TabContents.
- BlockedPopupContainer(TabContents* owner, Profile* profile);
+ BlockedPopupContainer(TabContents* owner, PrefService* prefs);
// Overridden from Animation:
// Changes the visibility percentage of the BlockedPopupContainer. This is
@@ -279,9 +286,15 @@ class BlockedPopupContainer : public Animation,
// The TabContents that owns and constrains this BlockedPopupContainer.
TabContents* owner_;
+ // The PrefService we can query to find out what's on the whitelist.
+ PrefService* prefs_;
+
// Registrar to handle notifications we care about.
NotificationRegistrar registrar_;
+ // The whitelisted hosts, which we allow to open popups directly.
+ Whitelist whitelist_;
+
// Information about all blocked popups.
BlockedPopups blocked_popups_;
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 7ab6f8f..266e60b 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -78,6 +78,9 @@ const wchar_t kAcceptLanguages[] = L"intl.accept_languages";
// stored in non-translatable part of the resource bundle.
const wchar_t kStaticEncodings[] = L"intl.static_encodings";
+// The list of hostnames for which we whitelist popups (rather than blocking).
+const wchar_t kPopupWhitelistedHosts[] = L"profile.popup_whitelisted_sites";
+
// WebKit preferences.
// A boolean flag to indicate whether WebKit standard font family is
// serif or sans-serif. We don't have a UI for setting standard family.
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index a0c1795..92c674d 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -24,6 +24,7 @@ extern const wchar_t kApplicationLocale[];
extern const wchar_t kDefaultCharset[];
extern const wchar_t kAcceptLanguages[];
extern const wchar_t kStaticEncodings[];
+extern const wchar_t kPopupWhitelistedHosts[];
extern const wchar_t kShowBookmarkBar[];
extern const wchar_t kWebKitStandardFontIsSerif[];
extern const wchar_t kWebKitFixedFontFamily[];