summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/blocked_popup_container.cc32
-rw-r--r--chrome/browser/blocked_popup_container.h31
-rw-r--r--chrome/browser/views/blocked_popup_container_view_win.cc55
-rw-r--r--chrome/browser/views/blocked_popup_container_view_win.h3
5 files changed, 117 insertions, 10 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index eb010ea..f7b250b 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -4424,9 +4424,15 @@ each locale. -->
<message name="IDS_POPUP_TITLE_FORMAT" desc="Order of URL - Title on the popup">
<ph name="URL">$1</ph> - <ph name="WINDOW_TITLE">$2</ph>
</message>
+ <message name="IDS_NOTICE_TITLE_FORMAT" desc="Order of URL - Reason">
+ <ph name="URL">$1</ph> - <ph name="REASON">$2</ph>
+ </message>
<message name="IDS_POPUP_HOST_FORMAT" desc="Checkable menu item to always allow popups from a particular hostname">
Always show pop-ups from <ph name="URL">$1</ph>
</message>
+ <message name="IDS_BLOCKED_NOTICE_COUNT" desc="Message shown in the corner of the content window when there are blocked items.">
+ Blocked Items: <ph name="COUNT">$1<ex>2</ex></ph>
+ </message>
<!-- Multiple download warning-->
<message name="IDS_MULTI_DOWNLOAD_WARNING" desc="Warning invoked if multiple downloads are attempted without user interaction.">
diff --git a/chrome/browser/blocked_popup_container.cc b/chrome/browser/blocked_popup_container.cc
index 4df5bef..c82998b 100644
--- a/chrome/browser/blocked_popup_container.cc
+++ b/chrome/browser/blocked_popup_container.cc
@@ -107,13 +107,40 @@ void BlockedPopupContainer::LaunchPopupAtIndex(size_t index) {
void BlockedPopupContainer::AddBlockedNotice(const GURL& url,
const string16& reason) {
- // TODO(idanan): Implement this. See header for description.
+ // Nothing to show after we have been dismissed.
+ if (has_been_dismissed_)
+ return;
+
+ // Don't notify for hosts which are already shown. Too much noise otherwise.
+ // TODO(idanan): Figure out what to do for multiple reasons of blocking the
+ // same host.
+ if (notice_hosts_.find(url.host()) != notice_hosts_.end())
+ return;
+
+ notice_hosts_.insert(url.host());
+ blocked_notices_.push_back(BlockedNotice(url, reason));
+
+ UpdateView();
+ view_->ShowView();
+ owner_->PopupNotificationVisibilityChanged(true);
+}
+
+void BlockedPopupContainer::GetHostAndReasonForNotice(
+ size_t index, std::string* host, string16* reason) const {
+ DCHECK(host);
+ DCHECK(reason);
+ *host = blocked_notices_[index].url_.host();
+ *reason = blocked_notices_[index].reason_;
}
size_t BlockedPopupContainer::GetBlockedPopupCount() const {
return blocked_popups_.size();
}
+size_t BlockedPopupContainer::GetBlockedNoticeCount() const {
+ return blocked_notices_.size();
+}
+
bool BlockedPopupContainer::IsHostWhitelisted(size_t index) const {
PopupHosts::const_iterator i(ConvertHostIndexToIterator(index));
return (i == popup_hosts_.end()) ? false : i->second;
@@ -372,7 +399,8 @@ BlockedPopupContainer::BlockedPopupContainer(TabContents* owner,
}
void BlockedPopupContainer::UpdateView() {
- if (blocked_popups_.empty() && unblocked_popups_.empty())
+ if (blocked_popups_.empty() && unblocked_popups_.empty() &&
+ blocked_notices_.empty())
HideSelf();
else
view_->UpdateLabel();
diff --git a/chrome/browser/blocked_popup_container.h b/chrome/browser/blocked_popup_container.h
index d7e5d0e..155d648 100644
--- a/chrome/browser/blocked_popup_container.h
+++ b/chrome/browser/blocked_popup_container.h
@@ -106,6 +106,14 @@ class BlockedPopupContainer : public TabContentsDelegate,
// Adds a blocked notice if one is not already there for the same host.
void AddBlockedNotice(const GURL& url, const string16& reason);
+ // Returns the hostname and reason for notice |index|.
+ void GetHostAndReasonForNotice(size_t index,
+ std::string* host,
+ string16* reason) const;
+
+ // Returns the number of blocked notices, popups don't count.
+ size_t GetBlockedNoticeCount() const;
+
// Returns true if host |index| is whitelisted. Returns false if |index| is
// invalid.
bool IsHostWhitelisted(size_t index) const;
@@ -130,6 +138,11 @@ class BlockedPopupContainer : public TabContentsDelegate,
// Returns the names of hosts showing popups.
std::vector<std::string> GetHosts() const;
+ // Returns the number of popup hosts.
+ size_t GetPopupHostCount() const {
+ return popup_hosts_.size();
+ }
+
// Deletes all local state.
void ClearData();
@@ -207,6 +220,18 @@ class BlockedPopupContainer : public TabContentsDelegate,
// string is hostname. bool is whitelisted status.
typedef std::map<std::string, bool> PopupHosts;
+ struct BlockedNotice {
+ BlockedNotice(const GURL& url, const string16& reason)
+ : url_(url), reason_(reason) {}
+
+ GURL url_;
+ string16 reason_;
+ };
+ typedef std::vector<BlockedNotice> BlockedNotices;
+
+ // Hosts with notifications showing.
+ typedef std::set<std::string> NoticeHosts;
+
// Creates a BlockedPopupContainer, anchoring the container to the lower
// right corner using the given BlockedPopupContainerView. Use only for
// testing.
@@ -273,6 +298,12 @@ class BlockedPopupContainer : public TabContentsDelegate,
// Information about all popup hosts.
PopupHosts popup_hosts_;
+ // Notices for all blocked resources.
+ BlockedNotices blocked_notices_;
+
+ // Hosts which had notifications shown.
+ NoticeHosts notice_hosts_;
+
// Our platform specific view.
BlockedPopupContainerView* view_;
diff --git a/chrome/browser/views/blocked_popup_container_view_win.cc b/chrome/browser/views/blocked_popup_container_view_win.cc
index 844dc91..058e5d2 100644
--- a/chrome/browser/views/blocked_popup_container_view_win.cc
+++ b/chrome/browser/views/blocked_popup_container_view_win.cc
@@ -27,6 +27,11 @@ namespace {
// The minimal border around the edge of the notification.
const int kSmallPadding = 2;
+// The offset needed for blocked notices not to clash with anything else.
+// Basically 2 separators (one between popups and hosts, one between hosts
+// and notices).
+const int kNoticeMenuOffset = 2;
+
// The background color of the blocked popup notification.
const SkColor kBackgroundColorTop = SkColorSetRGB(255, 242, 183);
const SkColor kBackgroundColorBottom = SkColorSetRGB(250, 230, 145);
@@ -126,9 +131,10 @@ BlockedPopupContainerInternalView::BlockedPopupContainerInternalView(
l10n_util::GetStringF(IDS_POPUPS_BLOCKED_COUNT,
IntToWString(kWidestNumber)),
NULL, true);
- // Now set the text to the other possible display string so that the button
- // will update its max text width (in case this string is longer).
+ // Now set the text to the other possible display strings so that the button
+ // will update its max text width (in case one of these string is longer).
popup_count_label_->SetText(l10n_util::GetString(IDS_POPUPS_UNBLOCKED));
+ popup_count_label_->SetText(l10n_util::GetString(IDS_BLOCKED_NOTICE_COUNT));
popup_count_label_->set_alignment(views::TextButton::ALIGN_CENTER);
AddChildView(popup_count_label_);
@@ -151,11 +157,21 @@ BlockedPopupContainerInternalView::~BlockedPopupContainerInternalView() {
}
void BlockedPopupContainerInternalView::UpdateLabel() {
- size_t blocked_popups = container_->GetBlockedPopupCount();
- popup_count_label_->SetText((blocked_popups > 0) ?
- l10n_util::GetStringF(IDS_POPUPS_BLOCKED_COUNT,
- UintToWString(blocked_popups)) :
- l10n_util::GetString(IDS_POPUPS_UNBLOCKED));
+ size_t blocked_items =
+ container_->GetBlockedPopupCount() + container_->GetBlockedNoticeCount();
+
+ std::wstring label;
+ if (blocked_items == 0) {
+ label = l10n_util::GetString(IDS_POPUPS_UNBLOCKED);
+ } else if (container_->GetBlockedNoticeCount() == 0) {
+ label = l10n_util::GetStringF(IDS_POPUPS_BLOCKED_COUNT,
+ UintToWString(blocked_items));
+ } else {
+ label = l10n_util::GetStringF(IDS_BLOCKED_NOTICE_COUNT,
+ UintToWString(blocked_items));
+ }
+ popup_count_label_->SetText(label);
+
Layout();
SchedulePaint();
}
@@ -241,6 +257,22 @@ void BlockedPopupContainerInternalView::ButtonPressed(views::Button* sender) {
views::Menu::NORMAL);
}
+ size_t notice_count = container_->GetBlockedNoticeCount();
+ if (notice_count)
+ launch_menu_->AppendSeparator();
+
+ for (size_t i = 0; i < notice_count; ++i) {
+ std::string host;
+ string16 reason;
+ container_->GetModel()->GetHostAndReasonForNotice(i, &host, &reason);
+ launch_menu_->AppendMenuItem(
+ BlockedPopupContainer::kImpossibleNumberOfPopups +
+ hosts.size() + i + kNoticeMenuOffset + 1,
+ l10n_util::GetStringF(IDS_NOTICE_TITLE_FORMAT,
+ ASCIIToWide(host), reason),
+ views::Menu::NORMAL);
+ }
+
CPoint cursor_position;
::GetCursorPos(&cursor_position);
launch_menu_->RunMenuAt(cursor_position.x, cursor_position.y);
@@ -262,7 +294,10 @@ bool BlockedPopupContainerInternalView::IsItemChecked(int id) const {
void BlockedPopupContainerInternalView::ExecuteCommand(int id) {
DCHECK_GT(id, 0);
size_t id_size_t = static_cast<size_t>(id);
- if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) {
+ if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups +
+ container_->GetModel()->GetPopupHostCount() + kNoticeMenuOffset) {
+ // Nothing to do for now for notices.
+ } else if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) {
// Decrement id since all index based commands have 1 added to them. (See
// ButtonPressed() for detail).
container_->GetModel()->ToggleWhitelistingForHost(
@@ -307,6 +342,10 @@ size_t BlockedPopupContainerViewWin::GetBlockedPopupCount() const {
return container_model_->GetBlockedPopupCount();
}
+size_t BlockedPopupContainerViewWin::GetBlockedNoticeCount() const {
+ return container_model_->GetBlockedNoticeCount();
+}
+
// Overridden from AnimationDelegate:
void BlockedPopupContainerViewWin::AnimationStarted(
diff --git a/chrome/browser/views/blocked_popup_container_view_win.h b/chrome/browser/views/blocked_popup_container_view_win.h
index b1bfead..756a4de 100644
--- a/chrome/browser/views/blocked_popup_container_view_win.h
+++ b/chrome/browser/views/blocked_popup_container_view_win.h
@@ -51,6 +51,9 @@ class BlockedPopupContainerViewWin : public BlockedPopupContainerView,
// Returns the number of blocked popups from the model
size_t GetBlockedPopupCount() const;
+ // Returns the number of blocked notices from the model
+ size_t GetBlockedNoticeCount() const;
+
// Returns the model that owns us.
BlockedPopupContainer* GetModel() const { return container_model_; }