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/views/blocked_popup_container.h | |
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/views/blocked_popup_container.h')
-rw-r--r-- | chrome/browser/views/blocked_popup_container.h | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/chrome/browser/views/blocked_popup_container.h b/chrome/browser/views/blocked_popup_container.h index 214b8f8..80112e5 100644 --- a/chrome/browser/views/blocked_popup_container.h +++ b/chrome/browser/views/blocked_popup_container.h @@ -104,19 +104,39 @@ class BlockedPopupContainer : public ConstrainedWindow, // Adds a Tabbed contents to this container. |bounds| are the window bounds // requested by the popup window. - void AddTabContents(TabContents* blocked_contents, const gfx::Rect& bounds); + void AddTabContents(TabContents* blocked_contents, + const gfx::Rect& bounds, + const std::string& host); + + // Called when a popup from whitelisted host |host| is opened, so we can show + // the "stop whitelisting" UI. + void OnPopupOpenedFromWhitelistedHost(const std::string& host); // Creates a window from blocked popup |index|. void LaunchPopupIndex(int index); // Returns the number of blocked popups - int GetTabContentsCount() const; + int GetBlockedPopupCount() const; + + // Returns the URL and title for popup |index|, used to construct a string for + // display. + void GetURLAndTitleForPopup(int index, + std::wstring* url, + std::wstring* title) const; + + // Returns the names of hosts showing popups. + std::vector<std::wstring> GetHosts() const; + + // Returns true if host |index| is whitelisted. Returns false if |index| is + // invalid. + bool IsHostWhitelisted(int index) const; - // Returns the string to display to the user in the menu for item |index|. - std::wstring GetDisplayStringForItem(int index); + // If host |index| is currently whitelisted, un-whitelists it. Otherwise, + // whitelists it and opens all blocked popups from it. + void ToggleWhitelistingForHost(int index); // Deletes all popups and hides the interface parts. - void CloseAllPopups(); + void CloseAll(); // Called to force this container to never show itself again. void set_dismissed() { has_been_dismissed_ = true; } @@ -168,7 +188,7 @@ class BlockedPopupContainer : public ConstrainedWindow, virtual void CloseContents(TabContents* source); // Changes the opening rectangle associated with |source|. - virtual void MoveContents(TabContents* source, const gfx::Rect& pos); + virtual void MoveContents(TabContents* source, const gfx::Rect& new_bounds); // Always returns true. virtual bool IsPopup(TabContents* source); @@ -207,6 +227,22 @@ class BlockedPopupContainer : public ConstrainedWindow, virtual void OnSize(UINT param, const CSize& size); private: + struct BlockedPopup { + BlockedPopup(TabContents* tab_contents, + const gfx::Rect& bounds, + const std::string& host) + : tab_contents(tab_contents), bounds(bounds), host(host) { + } + + TabContents* tab_contents; + gfx::Rect bounds; + std::string host; + }; + typedef std::vector<BlockedPopup> BlockedPopups; + + // string is hostname. bool is whitelisted status. + typedef std::map<std::string, bool> PopupHosts; + // Creates a container for a certain TabContents. BlockedPopupContainer(TabContents* owner, Profile* profile); @@ -225,14 +261,26 @@ class BlockedPopupContainer : public ConstrainedWindow, // change. void SetPosition(); - // Deletes each contents in |blocked_popups_|. - void CloseEachTabContents(); + // Deletes all local state. + void ClearData(); + + // Helper function to convert a host index (which the view uses) into an + // iterator into |popup_hosts_|. Returns popup_hosts_.end() if |index| is + // invalid. + PopupHosts::const_iterator ConvertHostIndexToIterator(int index) const; + + // If the popup at |i| is the last one associated with its host, removes the + // host from the host list. + void EraseHostIfNeeded(BlockedPopups::iterator i); // The TabContents that owns and constrains this BlockedPopupContainer. TabContents* owner_; - // The TabContents and initial positions of all blocked popups. - std::vector<std::pair<TabContents*, gfx::Rect> > blocked_popups_; + // Information about all blocked popups. + BlockedPopups blocked_popups_; + + // Information about all popup hosts. + PopupHosts popup_hosts_; // Our associated view object. BlockedPopupContainerView* container_view_; |