diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 23:46:22 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 23:46:22 +0000 |
commit | 2c4410df7aaa0ed2c50edb1107c085098124fc99 (patch) | |
tree | 58f235bf5a6fb9f35053f08260fc91a3ff5c00ff /chrome/browser/tab_contents/tab_contents.cc | |
parent | 21e9e6d3296ea4198352619ed7a71cb92bc845de (diff) | |
download | chromium_src-2c4410df7aaa0ed2c50edb1107c085098124fc99.zip chromium_src-2c4410df7aaa0ed2c50edb1107c085098124fc99.tar.gz chromium_src-2c4410df7aaa0ed2c50edb1107c085098124fc99.tar.bz2 |
Popup whitelisting checkpoint.
This provides some basic UI for the popup whitelist. The actual whitelist is completely unimplemented and just has TODOs at the hook points. The actual blocking behavior of the browser is unchanged.
The popup blocker bubble menu now gets an extra section below the popups with checkable "Always show popups from <host>" items (usually one, can be more on pages with popups from iframes from different hosts). Clicking one of these will whitelist a hostname and open its popups, and remove it from the menu. When navigating to a page with whitelisted popups, the popup blocker bubble is opened (showing "Blocked Popups: 0", text subject to change), and the menu contains the checked entr(y/ies) relevant to these page. Clicking one of these un-whitelists the host and removes the entry from the menu (closing the menu if that was the last such entry).
Known UI questions:
* Wording is all speculative
* Should manually closing all popups associated with a whitelisted site remove that entry/close the menu automatically? (I suspect yes)
* Should un-whitelisting a site via the menu entry close its popups, just like whitelisting it opens them? (Not sure)
* Should menu items for sites stick around after toggling their whitelisting status, thus keeping the bubble onscreen until it's manually closed, the page is navigated, etc.? (While this is slightly more consistent, I suspect the answer is no)
BUG=11440
Review URL: http://codereview.chromium.org/113058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/tab_contents.cc')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 743e1bd..14cdd22 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -791,16 +791,25 @@ void TabContents::AddNewContents(TabContents* new_contents, return; #if defined(OS_WIN) + bool constrain_popup = false; if ((disposition == NEW_POPUP) && !user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisablePopupBlocking)) { - // Unrequested popups from normal pages are constrained. - TabContents* popup_owner = this; + // Unrequested popups from normal pages are constrained unless they're in + // the whitelist. + std::string host; + if (creator_url.is_valid()) + host = creator_url.host(); + constrain_popup = true; // TODO(pkasting): Add whitelist + TabContents* our_owner = delegate_->GetConstrainingContents(this); - if (our_owner) - popup_owner = our_owner; - popup_owner->AddConstrainedPopup(new_contents, initial_pos); - } else { + TabContents* popup_owner = our_owner ? our_owner : this; + if (constrain_popup) + popup_owner->AddConstrainedPopup(new_contents, initial_pos, host); + else + popup_owner->OnPopupOpenedFromWhitelistedHost(host); + } + if (!constrain_popup) { new_contents->DisassociateFromPopupCount(); delegate_->AddNewContents(this, new_contents, disposition, initial_pos, @@ -816,28 +825,9 @@ void TabContents::AddNewContents(TabContents* new_contents, } #if defined(OS_WIN) -void TabContents::AddConstrainedPopup(TabContents* new_contents, - const gfx::Rect& initial_pos) { - if (!blocked_popups_) { - CRect client_rect; - GetClientRect(GetNativeView(), &client_rect); - gfx::Point anchor_position( - client_rect.Width() - - views::NativeScrollBar::GetVerticalScrollBarWidth(), - client_rect.Height()); - - blocked_popups_ = BlockedPopupContainer::Create( - this, profile(), anchor_position); - child_windows_.push_back(blocked_popups_); - } - - blocked_popups_->AddTabContents(new_contents, initial_pos); - PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification()); -} - void TabContents::CloseAllSuppressedPopups() { if (blocked_popups_) - blocked_popups_->CloseAllPopups(); + blocked_popups_->CloseAll(); } #endif @@ -1142,6 +1132,12 @@ bool TabContents::IsActiveEntry(int32 page_id) { active_entry->page_id() == page_id); } +#if defined(OS_WIN) +void TabContents::SetWhitelistForHost(const std::string& host, bool whitelist) { + // TODO(pkasting): Add whitelist +} +#endif + // Notifies the RenderWidgetHost instance about the fact that the page is // loading, or done loading and calls the base implementation. void TabContents::SetIsLoading(bool is_loading, @@ -1174,6 +1170,33 @@ void TabContents::SetIsLoading(bool is_loading, } #if defined(OS_WIN) +void TabContents::CreateBlockedPopupContainerIfNecessary() { + if (blocked_popups_) + return; + + CRect client_rect; + GetClientRect(GetNativeView(), &client_rect); + gfx::Point anchor_position( + client_rect.Width() - views::NativeScrollBar::GetVerticalScrollBarWidth(), + client_rect.Height()); + blocked_popups_ = BlockedPopupContainer::Create(this, profile(), + anchor_position); + child_windows_.push_back(blocked_popups_); +} + +void TabContents::AddConstrainedPopup(TabContents* new_contents, + const gfx::Rect& initial_pos, + const std::string& host) { + CreateBlockedPopupContainerIfNecessary(); + blocked_popups_->AddTabContents(new_contents, initial_pos, host); + PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification()); +} + +void TabContents::OnPopupOpenedFromWhitelistedHost(const std::string& host) { + CreateBlockedPopupContainerIfNecessary(); + blocked_popups_->OnPopupOpenedFromWhitelistedHost(host); +} + // TODO(brettw) This should be on the TabContentsView. void TabContents::RepositionSupressedPopupsToFit(const gfx::Size& new_size) { // TODO(erg): There's no way to detect whether scroll bars are @@ -1192,7 +1215,7 @@ void TabContents::RepositionSupressedPopupsToFit(const gfx::Size& new_size) { bool TabContents::ShowingBlockedPopupNotification() const { return blocked_popups_ != NULL && - blocked_popups_->GetTabContentsCount() != 0; + blocked_popups_->GetBlockedPopupCount() != 0; } #endif // defined(OS_WIN) |