summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/chrome_dll.rc1
-rw-r--r--chrome/app/chrome_dll_resource.h9
-rw-r--r--chrome/app/generated_resources.grd30
-rw-r--r--chrome/browser/blocked_popup_container.cc407
-rw-r--r--chrome/browser/blocked_popup_container.h240
-rw-r--r--chrome/browser/blocked_popup_container_interactive_uitest.cc289
-rw-r--r--chrome/browser/blocked_popup_container_unittest.cc101
-rw-r--r--chrome/browser/browser.cc17
-rw-r--r--chrome/browser/browser.h6
-rw-r--r--chrome/browser/browser_prefs.cc2
-rw-r--r--chrome/browser/cocoa/blocked_popup_container_controller.h58
-rw-r--r--chrome/browser/cocoa/blocked_popup_container_controller.mm382
-rw-r--r--chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm105
-rw-r--r--chrome/browser/gtk/blocked_popup_container_view_gtk.cc314
-rw-r--r--chrome/browser/gtk/blocked_popup_container_view_gtk.h112
-rw-r--r--chrome/browser/host_content_settings_map.cc18
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_ui.cc63
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.cc6
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h3
-rw-r--r--chrome/browser/sync/glue/preference_model_associator.cc3
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc97
-rw-r--r--chrome/browser/tab_contents/tab_contents.h47
-rw-r--r--chrome/browser/tab_contents/tab_contents_delegate.h8
-rw-r--r--chrome/browser/tab_contents/tab_contents_view_gtk.cc45
-rw-r--r--chrome/browser/tab_contents/tab_contents_view_gtk.h15
-rw-r--r--chrome/browser/views/accelerator_table_gtk.cc3
-rw-r--r--chrome/browser/views/blocked_popup_container_view_views.cc571
-rw-r--r--chrome/browser/views/blocked_popup_container_view_views.h71
-rw-r--r--chrome/browser/views/content_blocked_bubble_contents.cc39
-rw-r--r--chrome/browser/views/content_blocked_bubble_contents.h31
-rw-r--r--chrome/browser/views/location_bar_view.cc12
-rw-r--r--chrome/browser/views/location_bar_view.h4
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_gtk.cc10
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_win.cc5
-rwxr-xr-xchrome/chrome_browser.gypi8
-rwxr-xr-xchrome/chrome_tests.gypi4
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/test/interactive_ui/interactive_ui_tests.gypi2
38 files changed, 230 insertions, 2911 deletions
diff --git a/chrome/app/chrome_dll.rc b/chrome/app/chrome_dll.rc
index 57c2f50..6320f22 100644
--- a/chrome/app/chrome_dll.rc
+++ b/chrome/app/chrome_dll.rc
@@ -39,7 +39,6 @@ BEGIN
VK_DELETE, IDC_CLEAR_BROWSING_DATA, VIRTKEY, CONTROL, SHIFT
VK_F4, IDC_CLOSE_TAB, VIRTKEY, CONTROL
"W", IDC_CLOSE_TAB, VIRTKEY, CONTROL
- "W", IDC_CLOSE_POPUPS, VIRTKEY, SHIFT, ALT
"W", IDC_CLOSE_WINDOW, VIRTKEY, CONTROL, SHIFT
"F", IDC_FIND, VIRTKEY, CONTROL
"G", IDC_FIND_NEXT, VIRTKEY, CONTROL
diff --git a/chrome/app/chrome_dll_resource.h b/chrome/app/chrome_dll_resource.h
index 5302f1f..423c053 100644
--- a/chrome/app/chrome_dll_resource.h
+++ b/chrome/app/chrome_dll_resource.h
@@ -118,11 +118,10 @@
#define IDC_BOOKMARK_PAGE 35000
#define IDC_BOOKMARK_ALL_TABS 35001
#define IDC_VIEW_SOURCE 35002
-#define IDC_CLOSE_POPUPS 35003
-#define IDC_PRINT 35004
-#define IDC_SAVE_PAGE 35005
-#define IDC_ENCODING_MENU 35006
-#define IDC_EMAIL_PAGE_LOCATION 35007
+#define IDC_PRINT 35003
+#define IDC_SAVE_PAGE 35004
+#define IDC_ENCODING_MENU 35005
+#define IDC_EMAIL_PAGE_LOCATION 35006
// When adding a new encoding to this list, be sure to append it to the
// EncodingMenuController::kValidEncodingIds array in
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 62490f5..f86d5e3 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -5983,36 +5983,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
Continue
</message>
- <!-- Constrained Window -->
- <message name="IDS_BLOCKED_POPUP" desc="Text on a blocked popup's window titlebar.">
- Blocked Pop-up
- </message>
- <message name="IDS_POPUPS_BLOCKED_COUNT" desc="Message on the blocked popup window when there are blocked popups">
- Pop-ups Blocked: <ph name="COUNT">$1<ex>2</ex></ph>
- </message>
- <message name="IDS_POPUPS_UNBLOCKED" desc="Message on the blocked popup window when there are only whitelisted popups">
- Manage pop-ups
- </message>
- <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>
- <if expr="not pp_ifdef('use_titlecase')">
- <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>
- </if>
- <if expr="pp_ifdef('use_titlecase')">
- <message name="IDS_POPUP_HOST_FORMAT" desc="In Title Case: Checkable menu item to always allow popups from a particular hostname">
- Always Show Pop-ups From <ph name="URL">$1</ph>
- </message>
- </if>
- <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.">
This site is attempting to download multiple files. Do you want to allow this?
diff --git a/chrome/browser/blocked_popup_container.cc b/chrome/browser/blocked_popup_container.cc
index cb48a98..ae52604 100644
--- a/chrome/browser/blocked_popup_container.cc
+++ b/chrome/browser/blocked_popup_container.cc
@@ -1,244 +1,73 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "chrome/browser/blocked_popup_container.h"
-#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/common/pref_service.h"
-#include "chrome/common/notification_service.h"
// static
const size_t BlockedPopupContainer::kImpossibleNumberOfPopups = 30;
-// static
-BlockedPopupContainer* BlockedPopupContainer::Create(
- TabContents* owner, Profile* profile) {
- BlockedPopupContainer* container =
- new BlockedPopupContainer(owner, profile);
- BlockedPopupContainerView* view =
- BlockedPopupContainerView::Create(container);
- container->set_view(view);
- return container;
-}
-
-// static
-BlockedPopupContainer* BlockedPopupContainer::Create(
- TabContents* owner, Profile* profile, BlockedPopupContainerView* view) {
- BlockedPopupContainer* container =
- new BlockedPopupContainer(owner, profile);
- container->set_view(view);
- return container;
-}
-
-// static
-void BlockedPopupContainer::RegisterUserPrefs(PrefService* prefs) {
- prefs->RegisterListPref(prefs::kPopupWhitelistedHosts);
+BlockedPopupContainer::BlockedPopupContainer(TabContents* owner)
+ : owner_(owner) {
}
void BlockedPopupContainer::AddTabContents(TabContents* tab_contents,
- const gfx::Rect& bounds,
- const std::string& host) {
- // Show whitelisted popups immediately.
- bool whitelisted = !!whitelist_.count(host);
- if (whitelisted)
- owner_->AddNewContents(tab_contents, NEW_POPUP, bounds, true);
-
- if (has_been_dismissed_) {
- // Don't want to show any other UI.
- if (!whitelisted)
- delete tab_contents; // Discard blocked popups entirely.
+ const gfx::Rect& bounds) {
+ if (blocked_popups_.size() == (kImpossibleNumberOfPopups - 1)) {
+ delete tab_contents;
+ LOG(INFO) << "Warning: Renderer is sending more popups to us than should "
+ "be possible. Renderer compromised?";
return;
}
- if (whitelisted) {
- // Listen for this popup's destruction, so if the user closes it manually,
- // we'll know to stop caring about it.
- registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(tab_contents));
-
- unblocked_popups_[tab_contents] = host;
- } else {
- if (blocked_popups_.size() == (kImpossibleNumberOfPopups - 1)) {
- delete tab_contents;
- LOG(INFO) << "Warning: Renderer is sending more popups to us than should "
- "be possible. Renderer compromised?";
- return;
- }
- blocked_popups_.push_back(BlockedPopup(tab_contents, bounds, host));
-
- tab_contents->set_delegate(this);
- }
-
- PopupHosts::const_iterator i(popup_hosts_.find(host));
- if (i == popup_hosts_.end())
- popup_hosts_[host] = whitelisted;
- else
- DCHECK_EQ(whitelisted, i->second);
-
- UpdateView();
- view_->ShowView();
- owner_->PopupNotificationVisibilityChanged(true);
+ blocked_popups_.push_back(BlockedPopup(tab_contents, bounds));
+ tab_contents->set_delegate(this);
+ if (blocked_popups_.size() == 1)
+ owner_->PopupNotificationVisibilityChanged(true);
}
-void BlockedPopupContainer::LaunchPopupAtIndex(size_t index) {
- if (index >= blocked_popups_.size())
- return;
-
+void BlockedPopupContainer::LaunchPopupForContents(TabContents* tab_contents) {
// Open the popup.
- BlockedPopups::iterator i(blocked_popups_.begin() + index);
- TabContents* tab_contents = i->tab_contents;
- tab_contents->set_delegate(NULL);
- owner_->AddNewContents(tab_contents, NEW_POPUP, i->bounds, true);
-
- const std::string& host = i->host;
- if (!host.empty()) {
- // Listen for this popup's destruction, so if the user closes it manually,
- // we'll know to stop caring about it.
- registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(tab_contents));
-
- // Add the popup to the unblocked list. (Do this before the below call!)
- unblocked_popups_[tab_contents] = i->host;
+ for (BlockedPopups::iterator i(blocked_popups_.begin());
+ i != blocked_popups_.end(); ++i) {
+ if (i->tab_contents == tab_contents) {
+ tab_contents->set_delegate(NULL);
+ owner_->AddNewContents(tab_contents, NEW_POPUP, i->bounds, true);
+ blocked_popups_.erase(i);
+ break;
+ }
}
- // Remove the popup from the blocked list.
- EraseDataForPopupAndUpdateUI(i);
-}
-
-void BlockedPopupContainer::AddBlockedNotice(const GURL& url,
- const string16& reason) {
- // 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_;
+ if (blocked_popups_.empty())
+ Destroy();
}
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 {
- return ConvertHostIndexToIterator(index)->second;
-}
-
-void BlockedPopupContainer::ToggleWhitelistingForHost(size_t index) {
- PopupHosts::const_iterator i(ConvertHostIndexToIterator(index));
- const std::string& host = i->first;
- bool should_whitelist = !i->second;
- popup_hosts_[host] = should_whitelist;
-
- if (should_whitelist) {
- whitelist_.insert(host);
-
- // Open the popups in order.
- for (size_t j = 0; j < blocked_popups_.size();) {
- if (blocked_popups_[j].host == host)
- LaunchPopupAtIndex(j); // This shifts the rest of the entries down.
- else
- ++j;
- }
- } else {
- // Remove from whitelist.
- whitelist_.erase(host);
-
- for (UnblockedPopups::iterator i(unblocked_popups_.begin());
- i != unblocked_popups_.end(); ) {
- TabContents* tab_contents = i->first;
- TabContentsDelegate* delegate = tab_contents->delegate();
- if ((i->second == host) && delegate->IsPopup(tab_contents)) {
- // Convert the popup back into a blocked popup.
- delegate->DetachContents(tab_contents);
- tab_contents->set_delegate(this);
-
- // Add the popup to the blocked list. (Do this before the below call!)
- gfx::Rect bounds;
- tab_contents->GetContainerBounds(&bounds);
- blocked_popups_.push_back(BlockedPopup(tab_contents, bounds, host));
-
- // Remove the popup from the unblocked list.
- UnblockedPopups::iterator to_erase = i;
- ++i;
- EraseDataForPopupAndUpdateUI(to_erase);
- } else {
- ++i;
- }
- }
- }
-
- // Persist whitelisting state if we're not off the record.
- if (prefs_) {
- ListValue* whitelist_pref =
- prefs_->GetMutableList(prefs::kPopupWhitelistedHosts);
- if (should_whitelist) {
- whitelist_pref->Append(new StringValue(host));
- } else {
- // Stupidly, gcc complains that you're accessing the (private) StringValue
- // copy constructor if you inline the temp creation into the Remove()
- // call.
- StringValue host_value(host);
- whitelist_pref->Remove(host_value);
- }
- }
-}
-
-void BlockedPopupContainer::CloseAll() {
- ClearData();
- HideSelf();
+void BlockedPopupContainer::GetBlockedContents(
+ BlockedContents* blocked_contents) const {
+ DCHECK(blocked_contents);
+ for (BlockedPopups::const_iterator i(blocked_popups_.begin());
+ i != blocked_popups_.end(); ++i)
+ blocked_contents->push_back(i->tab_contents);
}
void BlockedPopupContainer::Destroy() {
- view_->Destroy();
-
- ClearData();
- GetConstrainingContents(NULL)->WillCloseBlockedPopupContainer(this);
-
+ for (BlockedPopups::iterator i(blocked_popups_.begin());
+ i != blocked_popups_.end(); ++i) {
+ TabContents* tab_contents = i->tab_contents;
+ tab_contents->set_delegate(NULL);
+ delete tab_contents;
+ }
+ blocked_popups_.clear();
+ owner_->WillCloseBlockedPopupContainer(this);
delete this;
}
-void BlockedPopupContainer::RepositionBlockedPopupContainer() {
- view_->SetPosition();
-}
-
-TabContents* BlockedPopupContainer::GetTabContentsAt(size_t index) const {
- return blocked_popups_[index].tab_contents;
-}
-
-std::vector<std::string> BlockedPopupContainer::GetHosts() const {
- std::vector<std::string> hosts;
- for (PopupHosts::const_iterator i(popup_hosts_.begin());
- i != popup_hosts_.end(); ++i)
- hosts.push_back(i->first);
- return hosts;
-}
-
// Overridden from TabContentsDelegate:
void BlockedPopupContainer::OpenURLFromTab(TabContents* source,
const GURL& url,
@@ -258,12 +87,12 @@ void BlockedPopupContainer::AddNewContents(TabContents* source,
}
void BlockedPopupContainer::CloseContents(TabContents* source) {
- for (BlockedPopups::iterator it = blocked_popups_.begin();
- it != blocked_popups_.end(); ++it) {
- TabContents* tab_contents = it->tab_contents;
+ for (BlockedPopups::iterator i(blocked_popups_.begin());
+ i != blocked_popups_.end(); ++i) {
+ TabContents* tab_contents = i->tab_contents;
if (tab_contents == source) {
tab_contents->set_delegate(NULL);
- EraseDataForPopupAndUpdateUI(it);
+ blocked_popups_.erase(i);
delete tab_contents;
break;
}
@@ -272,10 +101,10 @@ void BlockedPopupContainer::CloseContents(TabContents* source) {
void BlockedPopupContainer::MoveContents(TabContents* source,
const gfx::Rect& new_bounds) {
- for (BlockedPopups::iterator it = blocked_popups_.begin();
- it != blocked_popups_.end(); ++it) {
- if (it->tab_contents == source) {
- it->bounds = new_bounds;
+ for (BlockedPopups::iterator i(blocked_popups_.begin());
+ i != blocked_popups_.end(); ++i) {
+ if (i->tab_contents == source) {
+ i->bounds = new_bounds;
break;
}
}
@@ -289,145 +118,3 @@ TabContents* BlockedPopupContainer::GetConstrainingContents(
TabContents* source) {
return owner_;
}
-
-void BlockedPopupContainer::HideSelf() {
- view_->HideView();
- owner_->PopupNotificationVisibilityChanged(false);
-}
-
-void BlockedPopupContainer::ClearData() {
- for (BlockedPopups::iterator i(blocked_popups_.begin());
- i != blocked_popups_.end(); ++i) {
- TabContents* tab_contents = i->tab_contents;
- tab_contents->set_delegate(NULL);
- delete tab_contents;
- }
- blocked_popups_.clear();
-
- registrar_.RemoveAll();
- unblocked_popups_.clear();
-
- popup_hosts_.clear();
-}
-
-BlockedPopupContainer::PopupHosts::const_iterator
- BlockedPopupContainer::ConvertHostIndexToIterator(size_t index) const {
- if (index >= popup_hosts_.size())
- return popup_hosts_.end();
- // If only there was a std::map::const_iterator::operator +=() ...
- PopupHosts::const_iterator i(popup_hosts_.begin());
- for (size_t j = 0; j < index; ++j)
- ++i;
- return i;
-}
-
-void BlockedPopupContainer::EraseDataForPopupAndUpdateUI(
- BlockedPopups::iterator i) {
- // Erase the host if this is the last popup for that host.
- const std::string& host = i->host;
- if (!host.empty()) {
- bool should_erase_host = true;
- for (BlockedPopups::const_iterator j(blocked_popups_.begin());
- j != blocked_popups_.end(); ++j) {
- if ((j != i) && (j->host == host)) {
- should_erase_host = false;
- break;
- }
- }
- if (should_erase_host) {
- for (UnblockedPopups::const_iterator j(unblocked_popups_.begin());
- j != unblocked_popups_.end(); ++j) {
- if (j->second == host) {
- should_erase_host = false;
- break;
- }
- }
- if (should_erase_host)
- popup_hosts_.erase(host);
- }
- }
-
- // Erase the popup and update the UI.
- blocked_popups_.erase(i);
- UpdateView();
-}
-
-void BlockedPopupContainer::EraseDataForPopupAndUpdateUI(
- UnblockedPopups::iterator i) {
- // Stop listening for this popup's destruction.
- registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(i->first));
-
- // Erase the host if this is the last popup for that host.
- const std::string& host = i->second;
- if (!host.empty()) {
- bool should_erase_host = true;
- for (UnblockedPopups::const_iterator j(unblocked_popups_.begin());
- j != unblocked_popups_.end(); ++j) {
- if ((j != i) && (j->second == host)) {
- should_erase_host = false;
- break;
- }
- }
- if (should_erase_host) {
- for (BlockedPopups::const_iterator j(blocked_popups_.begin());
- j != blocked_popups_.end(); ++j) {
- if (j->host == host) {
- should_erase_host = false;
- break;
- }
- }
- if (should_erase_host)
- popup_hosts_.erase(host);
- }
- }
-
- // Erase the popup and update the UI.
- unblocked_popups_.erase(i);
- UpdateView();
-}
-
-
-// private:
-
-BlockedPopupContainer::BlockedPopupContainer(TabContents* owner,
- Profile* profile)
- : owner_(owner),
- prefs_(profile->GetPrefs()),
- has_been_dismissed_(false),
- view_(NULL),
- profile_(profile) {
- // 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);
- }
- }
-
- if (profile->IsOffTheRecord())
- prefs_ = NULL; // Don't persist whitelist changes.
-}
-
-void BlockedPopupContainer::UpdateView() {
- if (blocked_popups_.empty() && unblocked_popups_.empty() &&
- blocked_notices_.empty())
- HideSelf();
- else
- view_->UpdateLabel();
-}
-
-void BlockedPopupContainer::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
- TabContents* tab_contents = Source<TabContents>(source).ptr();
- UnblockedPopups::iterator i(unblocked_popups_.find(tab_contents));
- DCHECK(i != unblocked_popups_.end());
- EraseDataForPopupAndUpdateUI(i);
-}
diff --git a/chrome/browser/blocked_popup_container.h b/chrome/browser/blocked_popup_container.h
index c3c5682..1cbc0f2 100644
--- a/chrome/browser/blocked_popup_container.h
+++ b/chrome/browser/blocked_popup_container.h
@@ -1,157 +1,43 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
// Defines the public interface for the blocked popup notifications. This
// interface should only be used by TabContents. Users and subclasses of
// TabContents should use the appropriate methods on TabContents to access
// information about blocked popups.
-// TODO(idanan): Rename class to BlockedContentContainer.
-
#ifndef CHROME_BROWSER_BLOCKED_POPUP_CONTAINER_H_
#define CHROME_BROWSER_BLOCKED_POPUP_CONTAINER_H_
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-#include "app/gfx/native_widget_types.h"
-#include "base/gfx/rect.h"
-#include "base/string16.h"
-#include "chrome/browser/tab_contents/constrained_window.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
-#include "chrome/common/notification_registrar.h"
-
-class BlockedPopupContainer;
-class PrefService;
-class Profile;
-class TabContents;
-
-// Interface that the BlockedPopupContainer model/controller uses to
-// communicate with its platform specific view.
-class BlockedPopupContainerView {
- public:
- // Platform specific constructor used by BlockedPopupContainer to create a
- // view that is displayed to the user.
- static BlockedPopupContainerView* Create(BlockedPopupContainer* container);
-
- // Notification that the view should properly position itself in |view|.
- virtual void SetPosition() = 0;
-
- // Shows the blocked popup view / Animates the blocked popup view in.
- virtual void ShowView() = 0;
- // Sets the text in the blocked popup label.
- virtual void UpdateLabel() = 0;
-
- // Hides the blocked popup view / Animates the blocked popup view out.
- virtual void HideView() = 0;
-
- // Called by the BlockedPopupContainer that owns us. Destroys the view or
- // starts a delayed Task to destroy the View at some later time.
- virtual void Destroy() = 0;
-
- virtual ~BlockedPopupContainerView() {}
-};
-
-// Takes ownership of TabContents that are unrequested popup windows and
-// presents an interface to the user for launching them. (Or never showing them
-// again). This class contains all the cross-platform bits that can be used in
-// all ports.
-//
-// +- BlockedPopupContainer ---+ +- BlockedPopupContainerView -----+
-// | All model logic | +--->| Abstract cross platform |
-// | | | | interface |
-// | | | | |
-// | Owns a platform view_ +----+ | |
-// +---------------------------+ +---------------------------------+
-// ^
-// |
-// +-------------------------------+-----------+
-// | |
-// +- BPCViewGtk -----------+ +- BPCViewWin ----------------------+
-// | Gtk UI | | Views UI |
-// | | | |
-// +------------------------+ +-----------------------------------+
-//
-// Getting here will take multiple patches.
-class BlockedPopupContainer : public TabContentsDelegate,
- public NotificationObserver {
+// Takes ownership of TabContents that are unrequested popup windows.
+class BlockedPopupContainer : public TabContentsDelegate {
public:
- // Creates a BlockedPopupContainer, anchoring the container to the lower
- // right corner.
- static BlockedPopupContainer* Create(TabContents* owner, Profile* profile);
-
- static void RegisterUserPrefs(PrefService* prefs);
-
- // Returns the profile associated with the Browser this container exists in.
- Profile* profile() const { return profile_; }
+ typedef std::vector<TabContents*> BlockedContents;
- // Sets this BlockedPopupContainer's view. BlockedPopupContainer now owns
- // |view| and is responsible for calling Destroy() on it.
- void set_view(BlockedPopupContainerView* view) { view_ = view; }
+ // Creates a container for a certain TabContents:
+ explicit BlockedPopupContainer(TabContents* owner);
// Adds a popup to this container. |bounds| are the window bounds requested by
// the popup window.
void AddTabContents(TabContents* tab_contents,
- const gfx::Rect& bounds,
- const std::string& host);
+ const gfx::Rect& bounds);
- // Shows the blocked popup at index |index|.
- void LaunchPopupAtIndex(size_t index);
+ // Shows the blocked popup with TabContents |tab_contents|.
+ void LaunchPopupForContents(TabContents* tab_contents);
- // Returns the number of blocked popups
+ // Returns the number of blocked popups.
size_t GetBlockedPopupCount() const;
- // 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.
- // NOTE: Does not sanity-check; do not pass an invalid index!
- bool IsHostWhitelisted(size_t index) const;
-
- // If host |index| is currently whitelisted, un-whitelists it. Otherwise,
- // whitelists it and opens all blocked popups from it.
- // NOTE: Does not sanity-check; do not pass an invalid index!
- void ToggleWhitelistingForHost(size_t index);
-
- // Deletes all popups and hides the interface parts.
- void CloseAll();
+ // Returns the contained TabContents pointers. |blocked_contents| must be
+ // non-NULL.
+ void GetBlockedContents(BlockedContents* blocked_contents) const;
// Sets this object up to delete itself.
void Destroy();
- // Message called when a BlockedPopupContainer should move itself to the
- // bottom right corner of our parent view.
- void RepositionBlockedPopupContainer();
-
- // Returns the TabContents for the blocked popup |index|.
- TabContents* GetTabContentsAt(size_t index) const;
-
- // 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();
-
- // Called to force this container to never show itself again.
- void set_dismissed() { has_been_dismissed_ = true; }
-
// Overridden from TabContentsDelegate:
// Forwards OpenURLFromTab to our |owner_|.
@@ -206,114 +92,22 @@ class BlockedPopupContainer : public TabContentsDelegate,
protected:
struct BlockedPopup {
BlockedPopup(TabContents* tab_contents,
- const gfx::Rect& bounds,
- const std::string& host)
- : tab_contents(tab_contents), bounds(bounds), host(host) {
+ const gfx::Rect& bounds)
+ : tab_contents(tab_contents), bounds(bounds) {
}
TabContents* tab_contents;
gfx::Rect bounds;
- std::string host;
};
typedef std::vector<BlockedPopup> BlockedPopups;
- // TabContents is the popup contents. string is opener hostname.
- typedef std::map<TabContents*, std::string> UnblockedPopups;
-
- // 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.
- static BlockedPopupContainer* Create(TabContents* owner, Profile* profile,
- BlockedPopupContainerView* view);
-
- // Hides the UI portion of the container.
- void HideSelf();
-
- // 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(size_t index) const;
-
- // Removes the popup at |i| from the blocked popup list. If this popup's host
- // is not otherwised referenced on either popup list, removes the host from
- // the host list. Updates the view's label to match the new state.
- void EraseDataForPopupAndUpdateUI(BlockedPopups::iterator i);
-
- // Same as above, but works on the unblocked popup list.
- void EraseDataForPopupAndUpdateUI(UnblockedPopups::iterator i);
-
private:
- friend class BlockedPopupContainerImpl;
- friend class BlockedPopupContainerTest;
- friend class BlockedPopupContainerControllerTest;
-
- // string is hostname.
- typedef std::set<std::string> Whitelist;
-
- // Creates a container for a certain TabContents:
- BlockedPopupContainer(TabContents* owner, Profile* profile);
-
- // Either hides the view if there are no popups, or updates the label if
- // there are.
- void UpdateView();
-
- // Overridden from notificationObserver:
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
// The TabContents that owns and constrains this BlockedPopupContainer.
TabContents* owner_;
- // The PrefService we can query to find out what's on the whitelist. If the
- // profile is off the record, this will be NULL.
- PrefService* prefs_;
-
- // Once the container is hidden, this is set to prevent it from reappearing.
- bool has_been_dismissed_;
-
- // 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_;
- // Information about all unblocked popups.
- UnblockedPopups unblocked_popups_;
-
- // 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_;
-
- // The profile for the browser associated with the container.
- Profile* profile_;
-
DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedPopupContainer);
};
diff --git a/chrome/browser/blocked_popup_container_interactive_uitest.cc b/chrome/browser/blocked_popup_container_interactive_uitest.cc
deleted file mode 100644
index e69a934..0000000
--- a/chrome/browser/blocked_popup_container_interactive_uitest.cc
+++ /dev/null
@@ -1,289 +0,0 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <string>
-
-#include "app/l10n_util.h"
-#include "base/file_path.h"
-#include "base/gfx/rect.h"
-#include "base/keyboard_codes.h"
-#include "chrome/browser/view_ids.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/test/automation/automation_constants.h"
-#include "chrome/test/automation/browser_proxy.h"
-#include "chrome/test/automation/tab_proxy.h"
-#include "chrome/test/automation/window_proxy.h"
-#include "chrome/test/ui/ui_test.h"
-#include "grit/generated_resources.h"
-#include "net/base/net_util.h"
-#include "views/event.h"
-
-class BlockedPopupContainerInteractiveTest : public UITest {
- protected:
- BlockedPopupContainerInteractiveTest() {
- show_window_ = true;
- }
-
- virtual void SetUp() {
- UITest::SetUp();
-
- browser_ = automation()->GetBrowserWindow(0);
- ASSERT_TRUE(browser_.get());
-
- window_ = browser_->GetWindow();
- ASSERT_TRUE(window_.get());
-
- tab_ = browser_->GetTab(0);
- ASSERT_TRUE(tab_.get());
- }
-
- void NavigateMainTabTo(const std::string& file_name) {
- FilePath filename(test_data_directory_);
- filename = filename.AppendASCII("constrained_files");
- filename = filename.AppendASCII(file_name);
- ASSERT_TRUE(tab_->NavigateToURL(net::FilePathToFileURL(filename)));
- }
-
- void SimulateClickInCenterOf(const scoped_refptr<WindowProxy>& window) {
- gfx::Rect tab_view_bounds;
- ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER,
- &tab_view_bounds, true));
-
- // Simulate a click of the actual link to force user_gesture to be
- // true; if we don't, the resulting popup will be constrained, which
- // isn't what we want to test.
- ASSERT_TRUE(window->SimulateOSClick(tab_view_bounds.CenterPoint(),
- views::Event::EF_LEFT_BUTTON_DOWN));
- }
-
- scoped_refptr<BrowserProxy> browser_;
- scoped_refptr<WindowProxy> window_;
- scoped_refptr<TabProxy> tab_;
-};
-
-TEST_F(BlockedPopupContainerInteractiveTest, TestOpenAndResizeTo) {
- NavigateMainTabTo("constrained_window_onload_resizeto.html");
- SimulateClickInCenterOf(window_);
-
- ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000));
-
- scoped_refptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1));
- ASSERT_TRUE(popup_browser != NULL);
- scoped_refptr<WindowProxy> popup_window(popup_browser->GetWindow());
- ASSERT_TRUE(popup_window != NULL);
-
- // Make sure we were created with the correct width and height.
- gfx::Rect rect;
- bool is_timeout = false;
- ASSERT_TRUE(popup_window->GetViewBoundsWithTimeout(
- VIEW_ID_TAB_CONTAINER, &rect, false, 1000, &is_timeout));
- ASSERT_FALSE(is_timeout);
- EXPECT_EQ(300, rect.width());
- EXPECT_EQ(320, rect.height());
-
-#if defined(OS_LINUX)
- // It seems we have to wait a little bit for the widgets to spin up before
- // we can start clicking on them.
- PlatformThread::Sleep(500);
-#endif
-
- SimulateClickInCenterOf(popup_window);
-
- // No idea how to wait here other then sleeping. This timeout used to be
- // lower, then we started hitting it before it was done. :(
- PlatformThread::Sleep(5000);
-
- // The actual content will be LESS than (200, 200) because resizeTo
- // deals with a window's outer{Width,Height} instead of its
- // inner{Width,Height}.
- is_timeout = false;
- ASSERT_TRUE(popup_window->GetViewBoundsWithTimeout(
- VIEW_ID_TAB_CONTAINER, &rect, false, 1000, &is_timeout));
- ASSERT_FALSE(is_timeout);
- EXPECT_LT(rect.height(), 200);
-#if defined(OS_LINUX)
- // On Linux we may run in an environment where there is no window frame. In
- // this case our width might be exactly 200. The height will still be less
- // because we have to show the location bar.
- EXPECT_LE(rect.width(), 200);
-#else
- EXPECT_LT(rect.width(), 200);
-#endif
-}
-
-// Helper function used to get the number of blocked popups out of the window
-// title.
-bool ParseCountOutOfTitle(const std::wstring& title, int* output) {
- // Since we will be reading the number of popup windows open by grabbing the
- // number out of the window title, and that format string is localized, we
- // need to find out the offset into that string.
- const wchar_t* placeholder = L"XXXX";
- size_t offset =
- l10n_util::GetStringF(IDS_POPUPS_BLOCKED_COUNT, placeholder).
- find(placeholder);
-
- std::wstring number;
- while (offset < title.size() && iswdigit(title[offset])) {
- number += title[offset];
- offset++;
- }
-
- return StringToInt(WideToUTF16(number), output);
-}
-
-// Tests that in the window.open() equivalent of a fork bomb, we stop building
-// windows.
-// Flaky, http://crbug.com/26692.
-TEST_F(BlockedPopupContainerInteractiveTest, FLAKY_DontSpawnEndlessPopups) {
- NavigateMainTabTo("infinite_popups.html");
- SimulateClickInCenterOf(window_);
-
- ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000));
-
- scoped_refptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1));
- ASSERT_TRUE(popup_browser.get());
- scoped_refptr<TabProxy> popup_tab(popup_browser->GetTab(0));
- ASSERT_TRUE(popup_tab.get());
-
- // And now we spin, waiting to make sure that we don't spawn popup
- // windows endlessly. The current limit is 25, so allowing for possible race
- // conditions and one off errors, don't break out until we go over 30 popup
- // windows (in which case we are bork bork bork).
- const int kMaxPopupWindows = 30;
-
- int popup_window_count = 0;
- int new_popup_window_count = 0;
- int times_slept = 0;
- bool continuing = true;
- while (continuing && popup_window_count < kMaxPopupWindows) {
- ASSERT_TRUE(popup_tab->GetBlockedPopupCount(&new_popup_window_count));
- if (new_popup_window_count == popup_window_count) {
- if (times_slept == 10) {
- continuing = false;
- } else {
- // Nothing intereseting is going on wait it out.
- PlatformThread::Sleep(automation::kSleepTime);
- times_slept++;
- }
- } else {
- times_slept = 0;
- }
-
- EXPECT_GE(new_popup_window_count, popup_window_count);
- EXPECT_LE(new_popup_window_count, kMaxPopupWindows);
- popup_window_count = new_popup_window_count;
- }
-}
-
-// Make sure that we refuse to close windows when a constrained popup is
-// displayed.
-TEST_F(BlockedPopupContainerInteractiveTest, FLAKY_WindowOpenWindowClosePopup) {
- NavigateMainTabTo("openclose_main.html");
- SimulateClickInCenterOf(window_);
-
- ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000));
-
- // Make sure we have a blocked popup notification
- scoped_refptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1));
- ASSERT_TRUE(popup_browser.get());
- scoped_refptr<WindowProxy> popup_window(popup_browser->GetWindow());
- ASSERT_TRUE(popup_window.get());
- scoped_refptr<TabProxy> popup_tab(popup_browser->GetTab(0));
- ASSERT_TRUE(popup_tab.get());
- ASSERT_TRUE(popup_tab->WaitForBlockedPopupCountToChangeTo(1, 1000));
-
- // Ensure we didn't close the first popup window.
- ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 3000));
-}
-
-TEST_F(BlockedPopupContainerInteractiveTest, BlockAlertFromBlockedPopup) {
- NavigateMainTabTo("block_alert.html");
-
- // Wait for there to be an app modal dialog (and fail if it's shown).
- ASSERT_FALSE(automation()->WaitForAppModalDialog(4000));
-
- // Ensure one browser window.
- int browser_window_count;
- ASSERT_TRUE(automation()->GetBrowserWindowCount(&browser_window_count));
- ASSERT_EQ(1, browser_window_count);
-
- // Ensure one blocked popup window: the popup didn't escape.
- int popup_count = 0;
- ASSERT_TRUE(tab_->GetBlockedPopupCount(&popup_count));
- ASSERT_EQ(1, popup_count);
-}
-
-TEST_F(BlockedPopupContainerInteractiveTest, ShowAlertFromNormalPopup) {
- NavigateMainTabTo("show_alert.html");
- SimulateClickInCenterOf(window_);
-
- ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000));
-
- scoped_refptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1));
- ASSERT_TRUE(popup_browser.get());
- scoped_refptr<WindowProxy> popup_window(popup_browser->GetWindow());
- ASSERT_TRUE(popup_window.get());
- scoped_refptr<TabProxy> popup_tab(popup_browser->GetTab(0));
- ASSERT_TRUE(popup_tab.get());
-
-#if defined(OS_LINUX)
- // It seems we have to wait a little bit for the widgets to spin up before
- // we can start clicking on them.
- PlatformThread::Sleep(500);
-#endif
-
- SimulateClickInCenterOf(popup_window);
-
- // Wait for there to be an app modal dialog.
- ASSERT_TRUE(automation()->WaitForAppModalDialog(5000));
-}
-
-// Make sure that window focus works while creating a popup window so that we
-// don't
-TEST_F(BlockedPopupContainerInteractiveTest, DontBreakOnBlur) {
- NavigateMainTabTo("window_blur_test.html");
- SimulateClickInCenterOf(window_);
-
- // Wait for the popup window to open.
- ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000));
-
- // We popup shouldn't be closed by the onblur handler.
- ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 1500));
-}
-
-// Tests that tab related keyboard accelerators are reserved by the app.
-
-class BrowserInteractiveTest : public UITest {
-};
-
-TEST_F(BrowserInteractiveTest, ReserveKeyboardAccelerators) {
- const std::string kBadPage =
- "<html><script>"
- "document.onkeydown = function() {"
- " event.preventDefault();"
- " return false;"
- "}"
- "</script></html>";
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- browser->AppendTab(GURL("data:text/html," + kBadPage));
- int tab_count = 0;
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- ASSERT_EQ(tab_count, 2);
-
- int active_tab = 0;
- ASSERT_TRUE(browser->GetActiveTabIndex(&active_tab));
- ASSERT_EQ(active_tab, 1);
-
- scoped_refptr<WindowProxy> window(browser->GetWindow());
- ASSERT_TRUE(window->SimulateOSKeyPress(
- base::VKEY_TAB, views::Event::EF_CONTROL_DOWN));
- ASSERT_TRUE(browser->WaitForTabToBecomeActive(0, action_max_timeout_ms()));
-
-#if !defined(OS_MACOSX) // see BrowserWindowCocoa::GetCommandId
- ASSERT_TRUE(browser->ActivateTab(1));
- ASSERT_TRUE(window->SimulateOSKeyPress(
- base::VKEY_F4, views::Event::EF_CONTROL_DOWN));
- ASSERT_TRUE(browser->WaitForTabCountToBecome(1, action_max_timeout_ms()));
-#endif
-}
diff --git a/chrome/browser/blocked_popup_container_unittest.cc b/chrome/browser/blocked_popup_container_unittest.cc
deleted file mode 100644
index e57fec4..0000000
--- a/chrome/browser/blocked_popup_container_unittest.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Tests the cross platform BlockedPopupContainer model/controller object.
-//
-// TODO(erg): The unit tests on BlockedPopupContainer need to be greatly
-// expanded.
-
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-#include "app/app_paths.h"
-#include "base/path_service.h"
-#include "chrome/browser/blocked_popup_container.h"
-#include "chrome/browser/tab_contents/test_tab_contents.h"
-#include "chrome/browser/renderer_host/test/test_render_view_host.h"
-#include "chrome/test/testing_profile.h"
-#include "net/base/net_util.h"
-
-namespace {
-const std::string host1 = "host1";
-} // namespace
-
-// Mock for our view.
-class MockBlockedPopupContainerView : public BlockedPopupContainerView {
- public:
- MOCK_METHOD0(SetPosition, void());
- MOCK_METHOD0(ShowView, void());
- MOCK_METHOD0(UpdateLabel, void());
- MOCK_METHOD0(HideView, void());
- MOCK_METHOD0(Destroy, void());
-};
-
-class BlockedPopupContainerTest : public RenderViewHostTestHarness {
- public:
- TabContents* BuildTabContents() {
- // This will be deleted when the TabContents goes away.
- SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get());
-
- // Set up and use TestTabContents here.
- return new TestTabContents(profile_.get(), instance);
- }
-
- GURL GetTestCase(const std::string& file) {
- FilePath filename;
- PathService::Get(app::DIR_TEST_DATA, &filename);
- filename = filename.AppendASCII("constrained_files");
- filename = filename.AppendASCII(file);
- return net::FilePathToFileURL(filename);
- }
-
- protected:
- virtual void SetUp() {
- RenderViewHostTestHarness::SetUp();
- container_ = new BlockedPopupContainer(contents(), profile());
- container_->set_view(&mock);
-
- contents_->set_blocked_popup_container(container_);
- }
-
- // Our blocked popup container that we are testing. WARNING: If you are
- // trying to test destruction issues, make sure to remove |container_| from
- // |contents_|.
- BlockedPopupContainer* container_;
-
- // The mock that we're using.
- MockBlockedPopupContainerView mock;
-};
-
-// Destroying the container should tell the View to destroy itself.
-TEST_F(BlockedPopupContainerTest, TestDestroy) {
- EXPECT_CALL(mock, Destroy()).Times(1);
-}
-
-// Make sure TabContents::RepositionSupressedPopupsToFit() filters to the view.
-TEST_F(BlockedPopupContainerTest, TestReposition) {
- EXPECT_CALL(mock, SetPosition()).Times(1);
- // Always need this to shut gmock up. :-/
- EXPECT_CALL(mock, Destroy()).Times(1);
-
- contents_->RepositionSupressedPopupsToFit();
-}
-
-// Test the basic blocked popup case.
-TEST_F(BlockedPopupContainerTest, BasicCase) {
- EXPECT_CALL(mock, UpdateLabel()).Times(1);
- EXPECT_CALL(mock, ShowView()).Times(1);
- EXPECT_CALL(mock, Destroy()).Times(1);
-
- // Create another TabContents representing the blocked popup case.
- TabContents* popup = BuildTabContents();
- popup->controller().LoadURL(GetTestCase("error"), GURL(),
- PageTransition::LINK);
- container_->AddTabContents(popup, gfx::Rect(), host1);
-
- EXPECT_EQ(container_->GetBlockedPopupCount(), static_cast<size_t>(1));
- EXPECT_EQ(container_->GetTabContentsAt(0), popup);
- ASSERT_THAT(container_->GetHosts(), testing::Contains(host1));
- EXPECT_FALSE(container_->IsHostWhitelisted(0));
-}
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 2728c27..bc7b764 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1075,13 +1075,6 @@ bool Browser::SupportsWindowFeature(WindowFeature feature) const {
return !!(features & feature);
}
-#if defined(OS_WIN)
-void Browser::ClosePopups() {
- UserMetrics::RecordAction("CloseAllSuppressedPopups", profile_);
- GetSelectedTabContents()->CloseAllSuppressedPopups();
-}
-#endif
-
void Browser::EmailPageLocation() {
UserMetrics::RecordAction("EmailPageLocation", profile_);
GetSelectedTabContents()->EmailPageLocation();
@@ -1506,9 +1499,6 @@ void Browser::ExecuteCommandWithDisposition(
case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break;
case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break;
case IDC_VIEW_SOURCE: ViewSource(); break;
-#if defined(OS_WIN)
- case IDC_CLOSE_POPUPS: ClosePopups(); break;
-#endif
case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break;
case IDC_PRINT: Print(); break;
case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break;
@@ -1610,7 +1600,6 @@ void Browser::ExecuteCommandWithDisposition(
bool Browser::IsReservedCommand(int command_id) {
return command_id == IDC_CLOSE_TAB ||
- command_id == IDC_CLOSE_POPUPS ||
command_id == IDC_CLOSE_WINDOW ||
command_id == IDC_NEW_INCOGNITO_WINDOW ||
command_id == IDC_NEW_TAB ||
@@ -2154,6 +2143,11 @@ void Browser::ContentsZoomChange(bool zoom_in) {
ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS);
}
+void Browser::OnBlockedContentChange(TabContents* source) {
+ if (source == GetSelectedTabContents())
+ window_->GetLocationBar()->UpdateContentBlockedIcons();
+}
+
void Browser::SetTabContentBlocked(TabContents* contents, bool blocked) {
int index = tabstrip_model()->GetIndexOfTabContents(contents);
if (index == TabStripModel::kNoTab) {
@@ -2510,7 +2504,6 @@ void Browser::InitCommandState() {
#endif
// Page-related commands
- command_updater_.UpdateCommandEnabled(IDC_CLOSE_POPUPS, true);
command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
command_updater_.UpdateCommandEnabled(IDC_PRINT, true);
command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true);
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 4058632..4b35a1b 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -373,10 +373,7 @@ class Browser : public TabStripModelDelegate,
virtual bool SupportsWindowFeature(WindowFeature feature) const;
// TODO(port): port these, and re-merge the two function declaration lists.
-#if defined(OS_WIN)
// Page-related commands.
- void ClosePopups();
-#endif
void Print();
void EmailPageLocation();
void ToggleEncodingAutoDetect();
@@ -590,6 +587,7 @@ class Browser : public TabStripModelDelegate,
virtual void ContentsMouseEvent(
TabContents* source, const gfx::Point& location, bool motion);
virtual void ContentsZoomChange(bool zoom_in);
+ virtual void OnBlockedContentChange(TabContents* source);
virtual void SetTabContentBlocked(TabContents* contents, bool blocked);
virtual void TabContentsFocused(TabContents* tab_content);
virtual bool TakeFocus(bool reverse);
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc
index 85f35a0..5d918c8 100644
--- a/chrome/browser/browser_prefs.cc
+++ b/chrome/browser/browser_prefs.cc
@@ -6,7 +6,6 @@
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
-#include "chrome/browser/blocked_popup_container.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/debugger/devtools_manager.h"
@@ -93,7 +92,6 @@ void RegisterUserPrefs(PrefService* user_prefs) {
ExtensionDOMUI::RegisterUserPrefs(user_prefs);
ExtensionsUI::RegisterUserPrefs(user_prefs);
NewTabUI::RegisterUserPrefs(user_prefs);
- BlockedPopupContainer::RegisterUserPrefs(user_prefs);
HostContentSettingsMap::RegisterUserPrefs(user_prefs);
HostZoomMap::RegisterUserPrefs(user_prefs);
DevToolsManager::RegisterUserPrefs(user_prefs);
diff --git a/chrome/browser/cocoa/blocked_popup_container_controller.h b/chrome/browser/cocoa/blocked_popup_container_controller.h
deleted file mode 100644
index df3eb64..0000000
--- a/chrome/browser/cocoa/blocked_popup_container_controller.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_CONTROLLER_H_
-#define CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_CONTROLLER_H_
-
-#import <Cocoa/Cocoa.h>
-
-#include "base/scoped_nsobject.h"
-#include "base/scoped_ptr.h"
-#include "chrome/browser/blocked_popup_container.h"
-#include "chrome/browser/cocoa/hover_close_button.h"
-
-@class BubbleView;
-
-// Controller for the blocked popup view. Communicates with the cross-platform
-// code via a C++ bridge class, below. The BlockedPopupContainer class doesn't
-// really "own" the bridge, it just keeps a pointer to it and calls Destroy() on
-// it when it's supposed to go away. As a result, this class needs to own itself
-// (always keep an extra retain), and will autorelease itself (and the bridge
-// which it owns) when the bridge gets a Destroy() message.
-// TODO(pinkerton): Reverse the ownership if it makes more sense. I'm leaving
-// it this way because I assume we eventually want this to be a
-// NSViewController, and we usually have the Obj-C controller owning the
-// bridge (rather than the other way around).
-@interface BlockedPopupContainerController : NSObject {
- @private
- scoped_ptr<BlockedPopupContainerView> bridge_;
- BlockedPopupContainer* container_; // Weak. "owns" me.
- scoped_nsobject<BubbleView> view_;
- scoped_nsobject<HoverCloseButton> closeButton_;
-
- IBOutlet NSPopUpButton* popupButton_;
-}
-
-// Initialize with the given popup container. Creates the C++ bridge object
-// used to represet the "view".
-- (id)initWithContainer:(BlockedPopupContainer*)container;
-
-// Returns the C++ brige object.
-- (BlockedPopupContainerView*)bridge;
-
-// Called by the bridge to perform certain actions from the back-end code.
-- (void)show;
-- (void)hide;
-- (void)update;
-
-@end
-
-@interface BlockedPopupContainerController(ForTesting)
-- (BubbleView*)view;
-- (IBAction)closePopup:(id)sender;
-- (NSMenu*)buildMenu;
-- (void)setContainer:(BlockedPopupContainer*)container;
-@end
-
-#endif // CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/blocked_popup_container_controller.mm b/chrome/browser/cocoa/blocked_popup_container_controller.mm
deleted file mode 100644
index 5dc761d..0000000
--- a/chrome/browser/cocoa/blocked_popup_container_controller.mm
+++ /dev/null
@@ -1,382 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
-
-#import "chrome/browser/cocoa/blocked_popup_container_controller.h"
-
-#include "app/l10n_util_mac.h"
-#include "base/nsimage_cache_mac.h"
-#include "base/sys_string_conversions.h"
-#import "chrome/browser/cocoa/bubble_view.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents/tab_contents_view.h"
-#include "grit/generated_resources.h"
-
-// A C++ bridge class that manages the interaction between the C++ interface
-// and the Objective-C view controller that implements the popup blocker.
-class BlockedPopupContainerViewBridge : public BlockedPopupContainerView {
- public:
- BlockedPopupContainerViewBridge(BlockedPopupContainerController* controller);
- virtual ~BlockedPopupContainerViewBridge();
-
- // Overrides from BlockedPopupContainerView
- virtual void SetPosition();
- virtual void ShowView();
- virtual void UpdateLabel();
- virtual void HideView();
- virtual void Destroy();
-
- private:
- BlockedPopupContainerController* controller_; // Weak, owns us.
-};
-
-@interface BlockedPopupContainerController(Private)
-- (void)initPopupView;
-- (NSView*)containingView;
-@end
-
-@implementation BlockedPopupContainerController
-
-// Initialize with the given popup container. Creates the C++ bridge object
-// used to represent the "view".
-- (id)initWithContainer:(BlockedPopupContainer*)container {
- if ((self = [super init])) {
- container_ = container;
- bridge_.reset(new BlockedPopupContainerViewBridge(self));
- [self initPopupView];
- }
- return self;
-}
-
-- (void)dealloc {
- [view_ removeFromSuperview];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [super dealloc];
-}
-
-- (IBAction)closePopup:(id)sender {
- container_->set_dismissed();
- container_->CloseAll();
-}
-
-// Create and initialize the popup view and its label, close box, etc.
-- (void)initPopupView {
- static const float kWidth = 200.0;
- static const float kHeight = 20.0;
- static const float kCloseBoxSize = 16.0;
- static const float kCloseBoxPaddingY = 2.0;
- static const float kLabelPaddingX = 5.0;
-
- NSWindow* window = [[self containingView] window];
-
- // Create it below the parent's bottom edge so we can animate it into place.
- NSRect startFrame = NSMakeRect(0.0, -kHeight, kWidth, kHeight);
- view_.reset([[BubbleView alloc] initWithFrame:startFrame
- themeProvider:window]);
- [view_ setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
- [view_ setCornerFlags:kRoundedTopLeftCorner | kRoundedTopRightCorner];
-
- // Create the text label and position it. We'll resize it later when the
- // label gets updated. The view owns the label, we only hold a weak reference.
- NSRect labelFrame = NSMakeRect(kLabelPaddingX,
- 0,
- startFrame.size.width - kCloseBoxSize,
- startFrame.size.height);
- popupButton_ = [[[NSPopUpButton alloc] initWithFrame:labelFrame] autorelease];
- [popupButton_ setAutoresizingMask:NSViewWidthSizable];
- [popupButton_ setBordered:NO];
- [popupButton_ setBezelStyle:NSTexturedRoundedBezelStyle];
- [popupButton_ setPullsDown:YES];
- // TODO(pinkerton): this doesn't work, not sure why.
- [popupButton_ setPreferredEdge:NSMaxYEdge];
- // TODO(pinkerton): no matter what, the arrows always draw in the middle
- // of the button. We can turn off the arrows entirely, but then will the
- // user ever know to click it?
- [[popupButton_ cell] setArrowPosition:NSPopUpNoArrow];
- [[popupButton_ cell] setAltersStateOfSelectedItem:NO];
- // If we don't add this, no title will ever display.
- [popupButton_ addItemWithTitle:@""];
- [view_ addSubview:popupButton_];
-
- // Register for notifications that the menu is about to display so we can
- // fill it in lazily
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(showMenu:)
- name:NSPopUpButtonCellWillPopUpNotification
- object:[popupButton_ cell]];
-
- // Create the close box and position at the left of the view.
- NSRect closeFrame = NSMakeRect(startFrame.size.width - kCloseBoxSize,
- kCloseBoxPaddingY,
- kCloseBoxSize,
- kCloseBoxSize);
- closeButton_.reset([[HoverCloseButton alloc] initWithFrame:closeFrame]);
- [closeButton_ setAutoresizingMask:NSViewMinXMargin];
- [closeButton_ setButtonType:NSMomentaryChangeButton];
- [closeButton_ setBordered:NO];
- [closeButton_ setTarget:self];
- [closeButton_ setAction:@selector(closePopup:)];
- [view_ addSubview:closeButton_];
-}
-
-// Returns the C++ brige object.
-- (BlockedPopupContainerView*)bridge {
- return bridge_.get();
-}
-
-// Returns the parent of the RWHVMac. We insert our popup blocker as a sibling
-// so that it stays around as the RWHVMac is created/destroyed during
-// navigation.
-- (NSView*)containingView {
- NSView* view = nil;
- if (container_)
- view = container_->GetConstrainingContents(NULL)->view()->GetNativeView();
- return view;
-}
-
-- (void)show {
- const float kLeftPadding = 20; // Leave room for the scrollbar.
-
- // No need to do anything if it's already on screen.
- if ([view_ superview]) return;
-
- // Position the view at the bottom right corner, always leaving room for the
- // scrollbar. This is what window does. It also doesn't care about covering
- // up the horizontal scrollbar.
- NSView* parent = [self containingView];
- NSRect frame = [view_ frame];
- frame.origin.x = [parent frame].size.width - frame.size.width - kLeftPadding;
- [view_ setFrame:frame];
-
- // Add the view and animate it sliding up into view.
- [parent addSubview:view_.get()];
- frame.origin.y = 0;
- [[view_ animator] setFrame:frame];
-}
-
-- (void)hide {
- [view_ removeFromSuperview];
-}
-
-// Resize the view based on the new label contents. The autoresize mask will
-// take care of resizing everything else.
-- (void)resizeWithLabel:(NSString*)label {
- // It would be nice to teach BubbleView to honor -sizeToFit, but it can't
- // really handle the subviews that get added. So just measure the string
- // and pad for the views.
- NSDictionary* attributes =
- [NSDictionary dictionaryWithObjectsAndKeys:
- NSFontAttributeName, [view_ font],
- nil];
- NSSize stringSize = [label sizeWithAttributes:attributes];
- // Keep the right edge in the same place.
- NSRect frame = [view_ frame];
- CGFloat originalWidth = frame.size.width;
- frame.size.width =
- stringSize.width + [closeButton_ frame].size.width +
- [popupButton_ frame].origin.x + kBubbleViewTextPositionX;
- frame.origin.x -= frame.size.width - originalWidth;
- [view_ setFrame:frame];
-}
-
-- (void)update {
- size_t blockedNotices = container_->GetBlockedNoticeCount();
- size_t blockedItems = container_->GetBlockedPopupCount() + blockedNotices;
- NSString* label = nil;
- if (!blockedItems) {
- label = l10n_util::GetNSString(IDS_POPUPS_UNBLOCKED);
- } else if (!blockedNotices) {
- label = l10n_util::GetNSStringF(IDS_POPUPS_BLOCKED_COUNT,
- UintToString16(blockedItems));
- } else {
- label = l10n_util::GetNSStringF(IDS_BLOCKED_NOTICE_COUNT,
- UintToString16(blockedItems));
- }
- [self resizeWithLabel:label];
- [view_ setContent:label];
-}
-
-// Called when the user selects an item from the popup menu. The tag, if below
-// |kImpossibleNumberOfPopups| will be the index into the container's popup
-// array. In that case, we should display the popup. Otherwise, the tag is
-// either a host we should toggle whitelisting on or a notice (for which we do
-// nothing as yet).
-// |sender| is the NSMenuItem that was chosen.
-- (void)menuAction:(id)sender {
- size_t tag = static_cast<size_t>([sender tag]);
-
- // Is this a click on a popup?
- if (tag < BlockedPopupContainer::kImpossibleNumberOfPopups) {
- container_->LaunchPopupAtIndex(tag);
- return;
- }
-
- tag -= BlockedPopupContainer::kImpossibleNumberOfPopups;
-
- // Is this a click on a host?
- size_t hostCount = container_->GetPopupHostCount();
- if (tag < hostCount) {
- container_->ToggleWhitelistingForHost(tag);
- return;
- }
-
- tag -= hostCount;
-
- // Nothing to do for now for notices.
-}
-
-namespace {
-void GetURLAndTitleForPopup(
- const BlockedPopupContainer* container,
- size_t index,
- string16* url,
- string16* title) {
- DCHECK(url);
- DCHECK(title);
- TabContents* tab_contents = container->GetTabContentsAt(index);
- const GURL& tab_contents_url = tab_contents->GetURL().GetOrigin();
- *url = UTF8ToUTF16(tab_contents_url.possibly_invalid_spec());
- *title = tab_contents->GetTitle();
-}
-} // namespace
-
-// Build a new popup menu from scratch. The menu contains the blocked popups
-// (tags being the popup's index), followed by the list of hosts from which
-// the popups were blocked (tags being |kImpossibleNumberOfPopups| + host
-// index). The hosts are used to toggle whitelisting for a site.
-- (NSMenu*)buildMenu {
- NSMenu* menu = [[[NSMenu alloc] init] autorelease];
-
- // For pop-down menus, the first item is what is displayed while tracking the
- // menu and it remains there if nothing is selected. Set it to the
- // current title.
- NSString* currentTitle = [popupButton_ title];
- scoped_nsobject<NSMenuItem> dummy(
- [[NSMenuItem alloc] initWithTitle:currentTitle
- action:nil
- keyEquivalent:@""]);
- [menu addItem:dummy.get()];
-
- // Add the list of blocked popups titles to the menu. We set the array index
- // as the tag for use in the menu action rather than relying on the menu item
- // index.
- const size_t count = container_->GetBlockedPopupCount();
- for (size_t i = 0; i < count; ++i) {
- string16 url, title;
- GetURLAndTitleForPopup(container_, i, &url, &title);
- NSString* titleStr =
- l10n_util::GetNSStringF(IDS_POPUP_TITLE_FORMAT, url, title);
- scoped_nsobject<NSMenuItem> item(
- [[NSMenuItem alloc] initWithTitle:titleStr
- action:@selector(menuAction:)
- keyEquivalent:@""]);
- [item setTag:i];
- [item setTarget:self];
- [menu addItem:item.get()];
- }
-
- // Add the list of hosts. We begin tagging these at
- // |kImpossibleNumberOfPopups|. If whitelisting has already been enabled
- // for a site, mark it with a checkmark.
- std::vector<std::string> hosts(container_->GetHosts());
- if (!hosts.empty() && count)
- [menu addItem:[NSMenuItem separatorItem]];
- size_t first_host = BlockedPopupContainer::kImpossibleNumberOfPopups;
- for (size_t i = 0; i < hosts.size(); ++i) {
- NSString* titleStr =
- l10n_util::GetNSStringF(IDS_POPUP_HOST_FORMAT, UTF8ToUTF16(hosts[i]));
- scoped_nsobject<NSMenuItem> item(
- [[NSMenuItem alloc] initWithTitle:titleStr
- action:@selector(menuAction:)
- keyEquivalent:@""]);
- if (container_->IsHostWhitelisted(i))
- [item setState:NSOnState];
- [item setTag:first_host + i];
- [item setTarget:self];
- [menu addItem:item.get()];
- }
-
- // Add the list of notices. We begin tagging these at
- // |kImpossibleNumberOfPopups + hosts.size()|.
- size_t notice_count = container_->GetBlockedNoticeCount();
- if (notice_count && (!hosts.empty() || count))
- [menu addItem:[NSMenuItem separatorItem]];
- size_t first_notice = first_host + hosts.size();
- for (size_t i = 0; i < notice_count; ++i) {
- std::string host;
- string16 reason;
- container_->GetHostAndReasonForNotice(i, &host, &reason);
- NSString* titleStr =
- l10n_util::GetNSStringF(IDS_NOTICE_TITLE_FORMAT, UTF8ToUTF16(host),
- reason);
- scoped_nsobject<NSMenuItem> item(
- [[NSMenuItem alloc] initWithTitle:titleStr
- action:@selector(menuAction:)
- keyEquivalent:@""]);
- [item setTag:first_notice + i];
- [item setTarget:self];
- [menu addItem:item.get()];
- }
-
- return menu;
-}
-
-// Called when the popup button is about to display the menu, giving us a
-// chance to fill in the contents.
-- (void)showMenu:(NSNotification*)notify {
- NSMenu* menu = [self buildMenu];
- [[notify object] setMenu:menu];
-}
-
-// Only used for testing.
-- (BubbleView*)view {
- return view_.get();
-}
-
-// Only used for testing.
-- (void)setContainer:(BlockedPopupContainer*)container {
- container_ = container;
-}
-
-@end
-
-//---------------------------------------------------------------------------
-
-BlockedPopupContainerView* BlockedPopupContainerView::Create(
- BlockedPopupContainer* container) {
- // We "leak" |blocker| for now, we'll release it when the bridge class
- // gets a Destroy() message.
- BlockedPopupContainerController* blocker =
- [[BlockedPopupContainerController alloc] initWithContainer:container];
- return [blocker bridge];
-}
-
-BlockedPopupContainerViewBridge::BlockedPopupContainerViewBridge(
- BlockedPopupContainerController* controller) {
- controller_ = controller;
-}
-
-BlockedPopupContainerViewBridge::~BlockedPopupContainerViewBridge() {
-}
-
-void BlockedPopupContainerViewBridge::SetPosition() {
- // Doesn't ever get called, also a no-op on GTK.
- NOTIMPLEMENTED();
-}
-
-void BlockedPopupContainerViewBridge::ShowView() {
- [controller_ show];
-}
-
-void BlockedPopupContainerViewBridge::UpdateLabel() {
- [controller_ update];
-}
-
-void BlockedPopupContainerViewBridge::HideView() {
- [controller_ hide];
-}
-
-void BlockedPopupContainerViewBridge::Destroy() {
- [controller_ autorelease];
-}
diff --git a/chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm b/chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm
deleted file mode 100644
index 7cb8615..0000000
--- a/chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import <Cocoa/Cocoa.h>
-
-#include "app/app_paths.h"
-#include "base/path_service.h"
-#include "base/scoped_nsautorelease_pool.h"
-#import "chrome/browser/cocoa/blocked_popup_container_controller.h"
-#include "chrome/browser/cocoa/browser_test_helper.h"
-#include "chrome/browser/cocoa/cocoa_test_helper.h"
-#include "chrome/browser/renderer_host/test/test_render_view_host.h"
-#include "net/base/net_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-
-namespace {
-const std::string host1 = "host1";
-} // namespace
-
-class BlockedPopupContainerControllerTest : public RenderViewHostTestHarness {
- public:
- virtual void SetUp() {
- // This is all a bit convoluted because the standard factory Create() call
- // doesn't give us access to the cocoa controller for testing (since it's
- // an internal implementation detail). As a result, we need to create one
- // separately and inject the bridge with a test-only Create() call.
- // Unfortunate, but no way around it.
- RenderViewHostTestHarness::SetUp();
- CocoaTest::BootstrapCocoa();
- cocoa_controller_ = [[BlockedPopupContainerController alloc]
- initWithContainer:nil];
- EXPECT_TRUE([cocoa_controller_ bridge]);
- container_ = BlockedPopupContainer::Create(contents(), profile(),
- [cocoa_controller_ bridge]);
- [cocoa_controller_ setContainer:container_];
- contents_->set_blocked_popup_container(container_);
- }
-
- virtual void TearDown() {
- // This will also signal the Cocoa controller to delete itself with a
- // Destroy() mesage to the bridge. It also clears out the association with
- // |contents_|.
- container_->Destroy();
- RenderViewHostTestHarness::TearDown();
- }
-
- TabContents* BuildTabContents() {
- // This will be deleted when the TabContents goes away.
- SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get());
-
- // Set up and use TestTabContents here.
- return new TestTabContents(profile_.get(), instance);
- }
-
- GURL GetTestCase(const std::string& file) {
- FilePath filename;
- PathService::Get(app::DIR_TEST_DATA, &filename);
- filename = filename.AppendASCII("constrained_files");
- filename = filename.AppendASCII(file);
- return net::FilePathToFileURL(filename);
- }
-
- base::ScopedNSAutoreleasePool pool;
- BlockedPopupContainer* container_;
- BlockedPopupContainerController* cocoa_controller_;
-};
-
-TEST_F(BlockedPopupContainerControllerTest, BasicPopupBlock) {
- // This is taken from the popup blocker unit test.
- TabContents* popup = BuildTabContents();
- popup->controller().LoadURL(GetTestCase("error"), GURL(),
- PageTransition::LINK);
- container_->AddTabContents(popup, gfx::Rect(), host1);
- EXPECT_EQ(1U, container_->GetBlockedPopupCount());
- EXPECT_EQ(popup, container_->GetTabContentsAt(0));
- ASSERT_EQ(1U, container_->GetPopupHostCount());
- EXPECT_FALSE(container_->IsHostWhitelisted(0));
-
- // Ensure the view has been displayed. If it has a superview, then ShowView()
- // has been called on the bridge. If the bubble has a string, then
- // UpdateLabel() has been called.
- EXPECT_TRUE([cocoa_controller_ view]);
- EXPECT_TRUE([[cocoa_controller_ view] superview]);
- EXPECT_GT([[[cocoa_controller_ view] content] length], 0U);
-
- // Validate the menu. It should have 4 items (the dummy title item, 1 poupup,
- // a separator, 1 host).
- NSMenu* menu = [cocoa_controller_ buildMenu];
- EXPECT_TRUE(menu);
- EXPECT_EQ(4, [menu numberOfItems]);
-
- // Change the whitelisting and make sure the host is checked.
- container_->ToggleWhitelistingForHost(0);
- menu = [cocoa_controller_ buildMenu];
- EXPECT_TRUE(menu);
- EXPECT_EQ(2, [menu numberOfItems]);
- EXPECT_EQ(NSOnState, [[menu itemAtIndex:1] state]);
-
- // Close the popup and verify it's no longer in the view hierarchy. This
- // means HideView() has been called.
- [cocoa_controller_ closePopup:nil];
- EXPECT_FALSE([[cocoa_controller_ view] superview]);
-}
diff --git a/chrome/browser/gtk/blocked_popup_container_view_gtk.cc b/chrome/browser/gtk/blocked_popup_container_view_gtk.cc
deleted file mode 100644
index ae522da..0000000
--- a/chrome/browser/gtk/blocked_popup_container_view_gtk.cc
+++ /dev/null
@@ -1,314 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
-
-#include "chrome/browser/gtk/blocked_popup_container_view_gtk.h"
-
-#include "app/gfx/gtk_util.h"
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "base/string_util.h"
-#include "chrome/browser/gtk/custom_button.h"
-#include "chrome/browser/gtk/gtk_chrome_button.h"
-#include "chrome/browser/gtk/gtk_theme_provider.h"
-#include "chrome/browser/gtk/rounded_window.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
-#include "chrome/common/gtk_util.h"
-#include "chrome/common/notification_service.h"
-#include "grit/generated_resources.h"
-#include "grit/theme_resources.h"
-
-namespace {
-
-// The minimal border around the edge of the notification.
-const int kSmallPadding = 2;
-
-// Color of the gradient in the background.
-const double kBackgroundColorTop[] = { 246.0 / 255, 250.0 / 255, 1.0 };
-const double kBackgroundColorBottom[] = { 219.0 / 255, 235.0 / 255, 1.0 };
-
-// Rounded corner radius (in pixels).
-const int kCornerSize = 4;
-
-} // namespace
-
-// static
-BlockedPopupContainerView* BlockedPopupContainerView::Create(
- BlockedPopupContainer* container) {
- return new BlockedPopupContainerViewGtk(container);
-}
-
-BlockedPopupContainerViewGtk::~BlockedPopupContainerViewGtk() {
- container_.Destroy();
-}
-
-TabContentsViewGtk* BlockedPopupContainerViewGtk::ContainingView() {
- return static_cast<TabContentsViewGtk*>(
- model_->GetConstrainingContents(NULL)->view());
-}
-
-void BlockedPopupContainerViewGtk::GetURLAndTitleForPopup(
- size_t index, string16* url, string16* title) const {
- DCHECK(url);
- DCHECK(title);
- TabContents* tab_contents = model_->GetTabContentsAt(index);
- const GURL& tab_contents_url = tab_contents->GetURL().GetOrigin();
- *url = UTF8ToUTF16(tab_contents_url.possibly_invalid_spec());
- *title = tab_contents->GetTitle();
-}
-
-// Overridden from BlockedPopupContainerView:
-void BlockedPopupContainerViewGtk::SetPosition() {
- // No-op. Not required with the GTK version.
-}
-
-void BlockedPopupContainerViewGtk::ShowView() {
- // TODO(erg): Animate in.
- gtk_widget_show_all(container_.get());
-}
-
-void BlockedPopupContainerViewGtk::UpdateLabel() {
- size_t blocked_notices = model_->GetBlockedNoticeCount();
- size_t blocked_items = model_->GetBlockedPopupCount() + blocked_notices;
-
- GtkWidget* label = gtk_bin_get_child(GTK_BIN(menu_button_));
- if (!label) {
- label = gtk_label_new("");
- gtk_container_add(GTK_CONTAINER(menu_button_), label);
- }
-
- std::string label_text;
- if (blocked_items == 0) {
- label_text = l10n_util::GetStringUTF8(IDS_POPUPS_UNBLOCKED);
- } else if (blocked_notices == 0) {
- label_text = l10n_util::GetStringFUTF8(IDS_POPUPS_BLOCKED_COUNT,
- UintToString16(blocked_items));
- } else {
- label_text = l10n_util::GetStringFUTF8(IDS_BLOCKED_NOTICE_COUNT,
- UintToString16(blocked_items));
- }
- gtk_label_set_text(GTK_LABEL(label), label_text.c_str());
-}
-
-void BlockedPopupContainerViewGtk::HideView() {
- // TODO(erg): Animate out.
- gtk_widget_hide(container_.get());
-}
-
-void BlockedPopupContainerViewGtk::Destroy() {
- ContainingView()->RemoveBlockedPopupView(this);
- delete this;
-}
-
-void BlockedPopupContainerViewGtk::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK(type == NotificationType::BROWSER_THEME_CHANGED);
-
- // Make sure the label exists (so we can change its colors).
- UpdateLabel();
-
- // Update the label's colors.
- GtkWidget* label = gtk_bin_get_child(GTK_BIN(menu_button_));
- if (theme_provider_->UseGtkTheme()) {
- gtk_util::SetLabelColor(label, NULL);
- } else {
- GdkColor color = theme_provider_->GetGdkColor(
- BrowserThemeProvider::COLOR_BOOKMARK_TEXT);
- gtk_util::SetLabelColor(label, &color);
-
-
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- close_button_->SetBackground(
- theme_provider_->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT),
- rb.GetBitmapNamed(IDR_CLOSE_BAR),
- rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK));
- }
-
- GdkColor color = theme_provider_->GetBorderColor();
- gtk_util::SetRoundedWindowBorderColor(container_.get(), color);
-}
-
-bool BlockedPopupContainerViewGtk::IsCommandEnabled(int command_id) const {
- return true;
-}
-
-bool BlockedPopupContainerViewGtk::IsItemChecked(int id) const {
- // |id| should be > 0 since all index based commands have 1 added to them.
- DCHECK_GT(id, 0);
- size_t id_size_t = static_cast<size_t>(id);
-
- if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) {
- id_size_t -= BlockedPopupContainer::kImpossibleNumberOfPopups + 1;
- if (id_size_t < model_->GetPopupHostCount())
- return model_->IsHostWhitelisted(id_size_t);
- }
-
- return false;
-}
-
-void BlockedPopupContainerViewGtk::ExecuteCommandById(int id) {
- DCHECK_GT(id, 0);
- size_t id_size_t = static_cast<size_t>(id);
-
- // Is this a click on a popup?
- if (id_size_t < BlockedPopupContainer::kImpossibleNumberOfPopups) {
- model_->LaunchPopupAtIndex(id_size_t - 1);
- return;
- }
-
- // |id| shouldn't be == kImpossibleNumberOfPopups since the popups end before
- // this and the hosts start after it. (If it is used, it is as a separator.)
- DCHECK_NE(id_size_t, BlockedPopupContainer::kImpossibleNumberOfPopups);
- id_size_t -= BlockedPopupContainer::kImpossibleNumberOfPopups + 1;
-
- // Is this a click on a host?
- size_t host_count = model_->GetPopupHostCount();
- if (id_size_t < host_count) {
- model_->ToggleWhitelistingForHost(id_size_t);
- return;
- }
-
- // |id shouldn't be == host_count since this is the separator between hosts
- // and notices.
- DCHECK_NE(id_size_t, host_count);
- id_size_t -= host_count + 1;
-
- // Nothing to do for now for notices.
-}
-
-BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk(
- BlockedPopupContainer* container)
- : model_(container),
- theme_provider_(GtkThemeProvider::GetFrom(container->profile())),
- close_button_(CustomDrawButton::CloseButton(theme_provider_)) {
- Init();
-
- registrar_.Add(this,
- NotificationType::BROWSER_THEME_CHANGED,
- NotificationService::AllSources());
- theme_provider_->InitThemesFor(this);
-}
-
-void BlockedPopupContainerViewGtk::Init() {
- menu_button_ = theme_provider_->BuildChromeButton();
- UpdateLabel();
- g_signal_connect(menu_button_, "clicked",
- G_CALLBACK(OnMenuButtonClicked), this);
-
- GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), menu_button_, FALSE, FALSE, kSmallPadding);
- gtk_util::CenterWidgetInHBox(hbox, close_button_->widget(), true, 0);
- g_signal_connect(close_button_->widget(), "clicked",
- G_CALLBACK(OnCloseButtonClicked), this);
-
- container_.Own(gtk_util::CreateGtkBorderBin(hbox, NULL,
- kSmallPadding, kSmallPadding, kSmallPadding, kSmallPadding));
- // Connect an expose signal that draws the background. Most connect before
- // the ActAsRoundedWindow one.
- g_signal_connect(container_.get(), "expose-event",
- G_CALLBACK(OnRoundedExposeCallback), this);
- gtk_util::ActAsRoundedWindow(
- container_.get(), gfx::kGdkBlack, kCornerSize,
- gtk_util::ROUNDED_TOP_LEFT | gtk_util::ROUNDED_TOP_RIGHT,
- gtk_util::BORDER_LEFT | gtk_util::BORDER_TOP | gtk_util::BORDER_RIGHT);
-
- ContainingView()->AttachBlockedPopupView(this);
-}
-
-void BlockedPopupContainerViewGtk::OnMenuButtonClicked(
- GtkButton *button, BlockedPopupContainerViewGtk* container) {
- container->launch_menu_.reset(new MenuGtk(container));
-
- // Set items 1 .. popup_count as individual popups.
- size_t popup_count = container->model_->GetBlockedPopupCount();
- for (size_t i = 0; i < popup_count; ++i) {
- string16 url, title;
- container->GetURLAndTitleForPopup(i, &url, &title);
- // We can't just use the index into container_ here because Menu reserves
- // the value 0 as the nop command.
- container->launch_menu_->AppendMenuItemWithLabel(i + 1,
- l10n_util::GetStringFUTF8(IDS_POPUP_TITLE_FORMAT, url, title));
- }
-
- // Set items (kImpossibleNumberOfPopups + 1) ..
- // (kImpossibleNumberOfPopups + hosts.size()) as hosts.
- std::vector<std::string> hosts(container->model_->GetHosts());
- if (!hosts.empty() && (popup_count > 0))
- container->launch_menu_->AppendSeparator();
- size_t first_host = BlockedPopupContainer::kImpossibleNumberOfPopups + 1;
- for (size_t i = 0; i < hosts.size(); ++i) {
- container->launch_menu_->AppendCheckMenuItemWithLabel(first_host + i,
- l10n_util::GetStringFUTF8(IDS_POPUP_HOST_FORMAT,
- UTF8ToUTF16(hosts[i])));
- }
-
- // Set items (kImpossibleNumberOfPopups + hosts.size() + 2) ..
- // (kImpossibleNumberOfPopups + hosts.size() + 1 + notice_count) as notices.
- size_t notice_count = container->model_->GetBlockedNoticeCount();
- if (notice_count && (!hosts.empty() || (popup_count > 0)))
- container->launch_menu_->AppendSeparator();
- size_t first_notice = first_host + hosts.size() + 1;
- for (size_t i = 0; i < notice_count; ++i) {
- std::string host;
- string16 reason;
- container->model_->GetHostAndReasonForNotice(i, &host, &reason);
- container->launch_menu_->AppendMenuItemWithLabel(first_notice + i,
- l10n_util::GetStringFUTF8(IDS_NOTICE_TITLE_FORMAT, UTF8ToUTF16(host),
- reason));
- }
-
- container->launch_menu_->PopupAsContext(gtk_get_current_event_time());
-}
-
-void BlockedPopupContainerViewGtk::OnCloseButtonClicked(
- GtkButton *button, BlockedPopupContainerViewGtk* container) {
- container->model_->set_dismissed();
- container->model_->CloseAll();
-}
-
-gboolean BlockedPopupContainerViewGtk::OnRoundedExposeCallback(
- GtkWidget* widget, GdkEventExpose* event,
- BlockedPopupContainerViewGtk* container) {
- if (!container->theme_provider_->UseGtkTheme()) {
- int width = widget->allocation.width;
- int height = widget->allocation.height;
-
- // Clip to our damage rect.
- cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(event->window));
- gdk_cairo_rectangle(cr, &event->area);
- cairo_clip(cr);
-
- if (container->theme_provider_->GetThemeID() ==
- BrowserThemeProvider::kDefaultThemeID) {
- // We are using the default theme. Use a fairly soft gradient for the
- // background of the blocked popup notification.
- int half_width = width / 2;
- cairo_pattern_t* pattern = cairo_pattern_create_linear(
- half_width, 0, half_width, height);
- cairo_pattern_add_color_stop_rgb(
- pattern, 0.0, kBackgroundColorTop[0], kBackgroundColorTop[1],
- kBackgroundColorTop[2]);
- cairo_pattern_add_color_stop_rgb(
- pattern, 1.0,
- kBackgroundColorBottom[0], kBackgroundColorBottom[1],
- kBackgroundColorBottom[2]);
- cairo_set_source(cr, pattern);
- cairo_paint(cr);
- cairo_pattern_destroy(pattern);
- } else {
- // Use the toolbar color the theme specifies instead. It would be nice to
- // have a gradient here, but there isn't a second color to use...
- GdkColor color = container->theme_provider_->GetGdkColor(
- BrowserThemeProvider::COLOR_TOOLBAR);
- gdk_cairo_set_source_color(cr, &color);
- cairo_paint(cr);
- }
-
- cairo_destroy(cr);
- }
-
- return FALSE;
-}
diff --git a/chrome/browser/gtk/blocked_popup_container_view_gtk.h b/chrome/browser/gtk/blocked_popup_container_view_gtk.h
deleted file mode 100644
index a0bfa6c..0000000
--- a/chrome/browser/gtk/blocked_popup_container_view_gtk.h
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
-
-#ifndef CHROME_BROWSER_GTK_BLOCKED_POPUP_CONTAINER_VIEW_GTK_H_
-#define CHROME_BROWSER_GTK_BLOCKED_POPUP_CONTAINER_VIEW_GTK_H_
-
-#include <gtk/gtk.h>
-
-#include "base/basictypes.h"
-#include "base/scoped_ptr.h"
-#include "chrome/browser/blocked_popup_container.h"
-#include "chrome/browser/gtk/menu_gtk.h"
-#include "chrome/common/notification_observer.h"
-#include "chrome/common/notification_registrar.h"
-#include "chrome/common/owned_widget_gtk.h"
-
-class BlockedPopupContainerInternalView;
-class CustomDrawButton;
-class GtkThemeProvider;
-class MenuGtk;
-class NotificationObserver;
-class PrefService;
-class Profile;
-class TabContents;
-class TabContentsViewGtk;
-class TextButton;
-
-namespace views {
-class ImageButton;
-}
-
-// The GTK blocked popup container notification.
-class BlockedPopupContainerViewGtk : public BlockedPopupContainerView,
- public NotificationObserver,
- public MenuGtk::Delegate {
- public:
- virtual ~BlockedPopupContainerViewGtk();
-
- // Returns the Gtk view that currently owns us.
- TabContentsViewGtk* ContainingView();
-
- // Returns the URL and title for popup |index|, used to construct a string for
- // display.
- void GetURLAndTitleForPopup(size_t index,
- string16* url,
- string16* title) const;
-
- GtkWidget* widget() { return container_.get(); }
-
- // Overridden from BlockedPopupContainerView:
- virtual void SetPosition();
- virtual void ShowView();
- virtual void UpdateLabel();
- virtual void HideView();
- virtual void Destroy();
-
- // Overridden from NotificationObserver:
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- // Overridden from MenuGtk::Delegate:
- virtual bool IsCommandEnabled(int command_id) const;
- virtual bool IsItemChecked(int command_id) const;
- virtual void ExecuteCommandById(int command_id);
-
- private:
- // For the static constructor BlockedPopupContainerView::Create().
- friend class BlockedPopupContainerView;
-
- // Creates a container for a certain TabContents.
- explicit BlockedPopupContainerViewGtk(BlockedPopupContainer* container);
-
- // Builds all the messy GTK stuff.
- void Init();
-
- // Callbacks for the two buttons in the notification
- static void OnMenuButtonClicked(GtkButton *button,
- BlockedPopupContainerViewGtk* container);
- static void OnCloseButtonClicked(GtkButton *button,
- BlockedPopupContainerViewGtk* container);
-
- // Draw the custom background to our rounded widget.
- static gboolean OnRoundedExposeCallback(
- GtkWidget* widget, GdkEventExpose* event,
- BlockedPopupContainerViewGtk* container);
-
- NotificationRegistrar registrar_;
-
- // Our model; calling the shots.
- BlockedPopupContainer* model_;
-
- // The top level of our local GTK hierarchy.
- OwnedWidgetGtk container_;
-
- // The "Blocked Popups: XXX" button.
- GtkWidget* menu_button_;
-
- // Our theme provider.
- GtkThemeProvider* theme_provider_;
-
- // Closes the container.
- scoped_ptr<CustomDrawButton> close_button_;
-
- // The popup menu with options to launch blocked popups.
- scoped_ptr<MenuGtk> launch_menu_;
-
- DISALLOW_COPY_AND_ASSIGN(BlockedPopupContainerViewGtk);
-};
-
-#endif // CHROME_BROWSER_GTK_BLOCKED_POPUP_CONTAINER_VIEW_GTK_H_
diff --git a/chrome/browser/host_content_settings_map.cc b/chrome/browser/host_content_settings_map.cc
index eb35f5c..0546ece 100644
--- a/chrome/browser/host_content_settings_map.cc
+++ b/chrome/browser/host_content_settings_map.cc
@@ -53,6 +53,21 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile)
}
}
+ // Migrate obsolete popups pref.
+ if (prefs->HasPrefPath(prefs::kPopupWhitelistedHosts)) {
+ const ListValue* whitelist_pref =
+ prefs->GetList(prefs::kPopupWhitelistedHosts);
+ for (ListValue::const_iterator i(whitelist_pref->begin());
+ i != whitelist_pref->end(); ++i) {
+ std::string host;
+ (*i)->GetAsString(&host);
+ SetContentSetting(host, CONTENT_SETTINGS_TYPE_POPUPS,
+ CONTENT_SETTING_ALLOW);
+ }
+ prefs->ClearPref(prefs::kPopupWhitelistedHosts);
+ }
+
+ // Read global defaults.
DCHECK_EQ(arraysize(kTypeNames),
static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES));
const DictionaryValue* default_settings_dictionary =
@@ -64,6 +79,7 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile)
}
ForceDefaultsToBeExplicit();
+ // Read host-specific exceptions.
const DictionaryValue* all_settings_dictionary =
prefs->GetDictionary(prefs::kPerHostContentSettings);
// Careful: The returned value could be NULL if the pref has never been set.
@@ -81,6 +97,7 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile)
}
}
+ // Read misc. global settings.
block_third_party_cookies_ =
prefs->GetBoolean(prefs::kBlockThirdPartyCookies);
}
@@ -94,6 +111,7 @@ void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
// Obsolete prefs, for migration:
prefs->RegisterIntegerPref(prefs::kCookieBehavior,
net::StaticCookiePolicy::ALLOW_ALL_COOKIES);
+ prefs->RegisterListPref(prefs::kPopupWhitelistedHosts);
}
ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
diff --git a/chrome/browser/privacy_blacklist/blacklist_ui.cc b/chrome/browser/privacy_blacklist/blacklist_ui.cc
index 704d17c..0c5537f 100644
--- a/chrome/browser/privacy_blacklist/blacklist_ui.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_ui.cc
@@ -1,77 +1,26 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/privacy_blacklist/blacklist_ui.h"
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "base/string16.h"
-#include "chrome/browser/blocked_popup_container.h"
#include "chrome/browser/chrome_thread.h"
-#include "chrome/browser/privacy_blacklist/blacklist.h"
#include "chrome/browser/privacy_blacklist/blacklist_request_info.h"
-#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "grit/generated_resources.h"
-
-// Displays more info why some content has been blocked.
-class DisplayBlockedContentNoticeTask : public Task {
- public:
- DisplayBlockedContentNoticeTask(const GURL& url,
- const Blacklist::Match* match,
- const ResourceDispatcherHostRequestInfo* info)
- : url_(url),
- child_id_(info->child_id()),
- route_id_(info->route_id()) {
- if (match->attributes() & Blacklist::kBlockCookies) {
- // No cookies sent or stored.
- details_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
- } else if (match->attributes() & Blacklist::kDontSendReferrer) {
- // No referrer sent.
- details_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER);
- } else {
- NOTREACHED();
- }
- }
-
- virtual void Run() {
- RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_);
- if (!view)
- return; // The view may be gone by the time we get here.
-
- view->delegate()->AddBlockedNotice(url_, details_);
- }
-
- private:
- // URL for which we blocked content.
- const GURL url_;
-
- // More detailed info what has been blocked.
- string16 details_;
-
- // Information that allows us to identify the right tab to display the notice.
- const int child_id_;
- const int route_id_;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayBlockedContentNoticeTask);
-};
// static
-void BlacklistUI::OnNonvisualContentBlocked(const URLRequest* request) {
+void BlacklistUI::OnNonvisualContentBlocked(const URLRequest* /*request*/) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ // TODO
+
+ /* This code will probably be useful when this function is implemented.
BlacklistRequestInfo* request_info =
BlacklistRequestInfo::FromURLRequest(request);
const Blacklist* blacklist = request_info->GetBlacklist();
scoped_ptr<Blacklist::Match> match(blacklist->FindMatch(request->url()));
const ResourceDispatcherHostRequestInfo* info =
ResourceDispatcherHost::InfoForRequest(request);
-
- // Notify the UI that something non-visual has been blocked.
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- new DisplayBlockedContentNoticeTask(request->url(), match.get(), info));
+ */
}
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.cc b/chrome/browser/renderer_host/render_view_host_delegate.cc
index 8f424db..ac54b26 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.cc
+++ b/chrome/browser/renderer_host/render_view_host_delegate.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -65,10 +65,6 @@ TabContents* RenderViewHostDelegate::GetAsTabContents() {
return NULL;
}
-void RenderViewHostDelegate::AddBlockedNotice(const GURL& url,
- const string16& reason) {
-}
-
GURL RenderViewHostDelegate::GetAlternateErrorPageURL() const {
return GURL();
}
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index 892aa86..6ac79f7 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -410,9 +410,6 @@ class RenderViewHostDelegate {
// not a TabContents, returns NULL.
virtual TabContents* GetAsTabContents();
- // Adds a notice that something was blocked.
- virtual void AddBlockedNotice(const GURL& url, const string16& reason);
-
// Return id number of browser window which this object is attached to. If no
// browser window is attached to, just return -1.
virtual int GetBrowserWindowID() const = 0;
diff --git a/chrome/browser/sync/glue/preference_model_associator.cc b/chrome/browser/sync/glue/preference_model_associator.cc
index 924fcf0..996e802 100644
--- a/chrome/browser/sync/glue/preference_model_associator.cc
+++ b/chrome/browser/sync/glue/preference_model_associator.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -27,7 +27,6 @@ PreferenceModelAssociator::PreferenceModelAssociator(
synced_preferences_.insert(prefs::kHomePage);
synced_preferences_.insert(prefs::kRestoreOnStartup);
synced_preferences_.insert(prefs::kURLsToRestoreOnStartup);
- synced_preferences_.insert(prefs::kPopupWhitelistedHosts);
synced_preferences_.insert(prefs::kShowBookmarkBar);
}
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index d8cc146..81215e9 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -7,6 +7,7 @@
#include "app/gfx/text_elider.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "base/auto_reset.h"
#include "base/file_version_info.h"
#include "base/process_util.h"
#include "base/string16.h"
@@ -246,6 +247,7 @@ TabContents::TabContents(Profile* profile,
contents_mime_type_(),
encoding_(),
blocked_popups_(NULL),
+ dont_notify_render_view_(false),
infobar_delegates_(),
find_ui_active_(false),
find_op_aborted_(false),
@@ -336,15 +338,9 @@ TabContents::~TabContents() {
// TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
// some of these to close. CloseWindows is async, so it might get called
// twice before it runs.
- int size = static_cast<int>(child_windows_.size());
- for (int i = size - 1; i >= 0; --i) {
- ConstrainedWindow* window = child_windows_[i];
- if (window) {
- window->CloseConstrainedWindow();
- BlockTabContent(false);
- }
- }
+ CloseConstrainedWindows();
+ // Close all blocked popups.
if (blocked_popups_)
blocked_popups_->Destroy();
@@ -566,6 +562,9 @@ bool TabContents::ShouldDisplayFavIcon() {
}
bool TabContents::IsContentBlocked(ContentSettingsType content_type) const {
+ if (content_type == CONTENT_SETTINGS_TYPE_POPUPS)
+ return blocked_popups_ != NULL;
+
// TODO(pkasting): Return meaningful values here.
return false;
}
@@ -844,12 +843,9 @@ void TabContents::AddNewContents(TabContents* new_contents,
Source<TabContentsDelegate>(delegate_),
Details<TabContents>(this));
}
- PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
-}
-void TabContents::CloseAllSuppressedPopups() {
- if (blocked_popups_)
- blocked_popups_->CloseAll();
+ // TODO(pkasting): Why is this necessary?
+ PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
}
bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
@@ -863,7 +859,11 @@ bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
}
void TabContents::PopupNotificationVisibilityChanged(bool visible) {
- render_view_host()->PopupNotificationVisibilityChanged(visible);
+ if (is_being_destroyed_)
+ return;
+ if (!dont_notify_render_view_)
+ render_view_host()->PopupNotificationVisibilityChanged(visible);
+ delegate_->OnBlockedContentChange(this);
}
gfx::NativeView TabContents::GetContentNativeView() const {
@@ -1053,6 +1053,7 @@ void TabContents::WillCloseBlockedPopupContainer(
BlockedPopupContainer* container) {
DCHECK(blocked_popups_ == container);
blocked_popups_ = NULL;
+ PopupNotificationVisibilityChanged(false);
}
void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
@@ -1268,33 +1269,18 @@ void TabContents::SetIsLoading(bool is_loading,
det);
}
-void TabContents::CreateBlockedPopupContainerIfNecessary() {
- if (blocked_popups_)
- return;
-
- blocked_popups_ = BlockedPopupContainer::Create(this, profile());
-}
-
void TabContents::AddPopup(TabContents* new_contents,
const gfx::Rect& initial_pos) {
- CreateBlockedPopupContainerIfNecessary();
- // A popup is associated with the toplevel site instead of a potential frame
- // that spawns it.
- const GURL& url = GetURL();
- blocked_popups_->AddTabContents(
- new_contents, initial_pos,
- url.is_valid() ? url.host() : std::string());
-}
-
-// TODO(brettw) This should be on the TabContentsView.
-void TabContents::RepositionSupressedPopupsToFit() {
- if (blocked_popups_)
- blocked_popups_->RepositionBlockedPopupContainer();
-}
-
-bool TabContents::ShowingBlockedPopupNotification() const {
- return blocked_popups_ != NULL &&
- blocked_popups_->GetBlockedPopupCount() != 0;
+ GURL url(GetURL());
+ if (url.is_valid() &&
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ url.host(), CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
+ AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
+ } else {
+ if (!blocked_popups_)
+ blocked_popups_ = new BlockedPopupContainer(this);
+ blocked_popups_->AddTabContents(new_contents, initial_pos);
+ }
}
namespace {
@@ -1432,8 +1418,16 @@ void TabContents::DidNavigateMainFramePostCommit(
}
}
- // Close constrained popups if necessary.
- MaybeCloseChildWindows(details.previous_url, details.entry->url());
+ // Close constrained windows if necessary.
+ if (!net::RegistryControlledDomainService::SameDomainOrHost(
+ details.previous_url, details.entry->url()))
+ CloseConstrainedWindows();
+
+ // Close blocked popups.
+ if (blocked_popups_) {
+ AutoReset auto_reset(&dont_notify_render_view_, true);
+ blocked_popups_->Destroy();
+ }
// Update the starred state.
UpdateStarredStateForCurrentURL();
@@ -1455,30 +1449,18 @@ void TabContents::DidNavigateAnyFramePostCommit(
GetPasswordManager()->ProvisionallySavePassword(params.password_form);
}
-void TabContents::MaybeCloseChildWindows(const GURL& previous_url,
- const GURL& current_url) {
- if (net::RegistryControlledDomainService::SameDomainOrHost(
- previous_url, current_url))
- return;
-
- // Clear out any child windows since we are leaving this page entirely.
+void TabContents::CloseConstrainedWindows() {
+ // Clear out any constrained windows since we are leaving this page entirely.
// We use indices instead of iterators in case CloseWindow does something
// that may invalidate an iterator.
int size = static_cast<int>(child_windows_.size());
for (int i = size - 1; i >= 0; --i) {
ConstrainedWindow* window = child_windows_[i];
if (window) {
- DCHECK(delegate_);
window->CloseConstrainedWindow();
BlockTabContent(false);
}
}
-
- // Close the popup container.
- if (blocked_popups_) {
- blocked_popups_->Destroy();
- blocked_popups_ = NULL;
- }
}
void TabContents::UpdateStarredStateForCurrentURL() {
@@ -2012,11 +1994,6 @@ TabContents* TabContents::GetAsTabContents() {
return this;
}
-void TabContents::AddBlockedNotice(const GURL& url, const string16& reason) {
- CreateBlockedPopupContainerIfNecessary();
- blocked_popups_->AddBlockedNotice(url, reason);
-}
-
ViewType::Type TabContents::GetRenderViewType() const {
return ViewType::TAB_CONTENTS;
}
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index e42c1fb..4222e77 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -369,12 +369,6 @@ class TabContents : public PageNavigator,
const gfx::Rect& initial_pos,
bool user_gesture);
- // Closes all constrained windows that represent web popups that have not yet
- // been activated by the user and are as such auto-positioned in the bottom
- // right of the screen. This is a quick way for users to "clean up" a flurry
- // of unwanted popups.
- void CloseAllSuppressedPopups();
-
// Execute code in this tab. Returns true if the message was successfully
// sent.
bool ExecuteCode(int request_id, const std::string& extension_id,
@@ -671,10 +665,7 @@ class TabContents : public PageNavigator,
// Used to access the child_windows_ (ConstrainedWindowList) for testing
// automation purposes.
friend class AutomationProvider;
- friend class BlockedPopupContainerTest;
- friend class BlockedPopupContainerControllerTest;
- FRIEND_TEST(BlockedPopupContainerTest, TestReposition);
FRIEND_TEST(TabContentsTest, NoJSMessageOnInterstitials);
FRIEND_TEST(TabContentsTest, UpdateTitle);
FRIEND_TEST(TabContentsTest, CrossSiteCantPreemptAfterUnload);
@@ -701,30 +692,10 @@ class TabContents : public PageNavigator,
void SetIsLoading(bool is_loading,
LoadNotificationDetails* details);
- // Constructs |blocked_popups_| if need be.
- void CreateBlockedPopupContainerIfNecessary();
-
// Adds the incoming |new_contents| to the |blocked_popups_| container.
void AddPopup(TabContents* new_contents,
const gfx::Rect& initial_pos);
- // Called by a derived class when the TabContents is resized, causing
- // suppressed constrained web popups to be repositioned to the new bounds
- // if necessary.
- void RepositionSupressedPopupsToFit();
-
- // Whether we have a notification AND the notification owns popups windows.
- // (We keep the notification object around even when it's not shown since it
- // determines whether to show itself).
- bool ShowingBlockedPopupNotification() const;
-
- // Only used during unit testing; otherwise |blocked_popups_| will be created
- // on demand.
- void set_blocked_popup_container(BlockedPopupContainer* container) {
- DCHECK(blocked_popups_ == NULL);
- blocked_popups_ = container;
- }
-
// Called by derived classes to indicate that we're no longer waiting for a
// response. This won't actually update the throbber, but it will get picked
// up at the next animation step if the throbber is going.
@@ -758,11 +729,8 @@ class TabContents : public PageNavigator,
const NavigationController::LoadCommittedDetails& details,
const ViewHostMsg_FrameNavigate_Params& params);
- // Closes all child windows (constrained popups) when the domain changes.
- // Supply the new and old URLs, and this function will figure out when the
- // domain changing conditions are met.
- void MaybeCloseChildWindows(const GURL& previous_url,
- const GURL& current_url);
+ // Closes all constrained windows.
+ void CloseConstrainedWindows();
// Updates the starred state from the bookmark bar model. If the state has
// changed, the delegate is notified.
@@ -874,7 +842,6 @@ class TabContents : public PageNavigator,
GetFormFieldHistoryDelegate();
virtual RenderViewHostDelegate::AutoFill* GetAutoFillDelegate();
virtual TabContents* GetAsTabContents();
- virtual void AddBlockedNotice(const GURL& url, const string16& reason);
virtual ViewType::Type GetRenderViewType() const;
virtual int GetBrowserWindowID() const;
virtual void RenderViewCreated(RenderViewHost* render_view_host);
@@ -1092,12 +1059,14 @@ class TabContents : public PageNavigator,
// Character encoding. TODO(jungshik) : convert to std::string
std::string encoding_;
- // Data for shelves and stuff ------------------------------------------------
-
- // ConstrainedWindow with additional methods for managing blocked
- // popups.
+ // Object that holds any blocked popups frmo the current page.
BlockedPopupContainer* blocked_popups_;
+ // TODO(pkasting): Hack to try and fix Linux browser tests.
+ bool dont_notify_render_view_;
+
+ // Data for shelves and stuff ------------------------------------------------
+
// Delegates for InfoBars associated with this TabContents.
std::vector<InfoBarDelegate*> infobar_delegates_;
diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h
index 9cdd2cc..a193b2e 100644
--- a/chrome/browser/tab_contents/tab_contents_delegate.h
+++ b/chrome/browser/tab_contents/tab_contents_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -111,6 +111,12 @@ class TabContentsDelegate {
// Request the delegate to change the zoom level of the current tab.
virtual void ContentsZoomChange(bool zoom_in) { }
+ // Notifies the delegate that something has changed about what content the
+ // TabContents is blocking. Interested parties should call
+ // TabContents::IsContentBlocked() to see if something they care about has
+ // changed.
+ virtual void OnBlockedContentChange(TabContents* source) { }
+
// Check whether this contents is inside a window dedicated to running a web
// application.
virtual bool IsApplication() const { return false; }
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
index a085ced..6957566 100644
--- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc
+++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,7 +16,6 @@
#include "base/string_util.h"
#include "build/build_config.h"
#include "chrome/browser/download/download_shelf.h"
-#include "chrome/browser/gtk/blocked_popup_container_view_gtk.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/gtk/constrained_window_gtk.h"
#include "chrome/browser/gtk/gtk_expanded_container.h"
@@ -112,7 +111,6 @@ TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
: TabContentsView(tab_contents),
floating_(gtk_floating_container_new()),
expanded_(gtk_expanded_container_new()),
- popup_view_(NULL),
constrained_window_(NULL) {
gtk_widget_set_name(expanded_, "chrome-tab-contents-view");
g_signal_connect(expanded_, "size-allocate",
@@ -134,21 +132,6 @@ TabContentsViewGtk::~TabContentsViewGtk() {
floating_.Destroy();
}
-void TabContentsViewGtk::AttachBlockedPopupView(
- BlockedPopupContainerViewGtk* popup_view) {
- DCHECK(popup_view_ == NULL);
- popup_view_ = popup_view;
- gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()),
- popup_view->widget());
-}
-
-void TabContentsViewGtk::RemoveBlockedPopupView(
- BlockedPopupContainerViewGtk* popup_view) {
- DCHECK(popup_view_ == popup_view);
- gtk_container_remove(GTK_CONTAINER(floating_.get()), popup_view->widget());
- popup_view_ = NULL;
-}
-
void TabContentsViewGtk::AttachConstrainedWindow(
ConstrainedWindowGtk* constrained_window) {
DCHECK(constrained_window_ == NULL);
@@ -390,32 +373,6 @@ void TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget,
void TabContentsViewGtk::OnSetFloatingPosition(
GtkFloatingContainer* floating_container, GtkAllocation* allocation,
TabContentsViewGtk* tab_contents_view) {
- if (tab_contents_view->popup_view_) {
- GtkWidget* widget = tab_contents_view->popup_view_->widget();
-
- // Look at the size request of the status bubble and tell the
- // GtkFloatingContainer where we want it positioned.
- GtkRequisition requisition;
- gtk_widget_size_request(widget, &requisition);
-
- GValue value = { 0, };
- g_value_init(&value, G_TYPE_INT);
-
- int child_x = std::max(
- allocation->x + allocation->width - requisition.width -
- kScrollbarWidthHack, 0);
- g_value_set_int(&value, child_x);
- gtk_container_child_set_property(GTK_CONTAINER(floating_container),
- widget, "x", &value);
-
- int child_y = std::max(
- allocation->y + allocation->height - requisition.height, 0);
- g_value_set_int(&value, child_y);
- gtk_container_child_set_property(GTK_CONTAINER(floating_container),
- widget, "y", &value);
- g_value_unset(&value);
- }
-
// Place each ConstrainedWindow in the center of the view.
int half_view_width = std::max((allocation->x + allocation->width) / 2, 0);
int half_view_height = std::max((allocation->y + allocation->height) / 2, 0);
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h
index 0c84e1e..954e560 100644
--- a/chrome/browser/tab_contents/tab_contents_view_gtk.h
+++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,7 +14,6 @@
#include "chrome/common/notification_registrar.h"
#include "chrome/common/owned_widget_gtk.h"
-class BlockedPopupContainerViewGtk;
class ConstrainedWindowGtk;
class GtkThemeProperties;
class RenderViewContextMenuGtk;
@@ -32,11 +31,6 @@ class TabContentsViewGtk : public TabContentsView,
explicit TabContentsViewGtk(TabContents* tab_contents);
virtual ~TabContentsViewGtk();
- // Unlike Windows, the BlockedPopupContainerView needs to collaborate with
- // the TabContentsViewGtk to position the notification.
- void AttachBlockedPopupView(BlockedPopupContainerViewGtk* popup_view);
- void RemoveBlockedPopupView(BlockedPopupContainerViewGtk* popup_view);
-
// Unlike Windows, ConstrainedWindows need to collaborate with the
// TabContentsViewGtk to position the dialogs.
void AttachConstrainedWindow(ConstrainedWindowGtk* constrained_window);
@@ -104,8 +98,7 @@ class TabContentsViewGtk : public TabContentsView,
GtkFloatingContainer* floating_container, GtkAllocation* allocation,
TabContentsViewGtk* tab_contents_view);
- // Contains |expanded_| as its GtkBin member and a possible floating widget
- // from |popup_view_|.
+ // Contains |expanded_| as its GtkBin member.
OwnedWidgetGtk floating_;
// This container holds the tab's web page views. It is a GtkExpandedContainer
@@ -127,10 +120,6 @@ class TabContentsViewGtk : public TabContentsView,
FocusStoreGtk focus_store_;
- // Our UI for controlling popups (or NULL if no popup windows have been
- // opened). |popup_view_| is owned by the TabContents, not the view.
- BlockedPopupContainerViewGtk* popup_view_;
-
// The UI for the constrained dialog currently displayed. This is owned by
// TabContents, not the view.
ConstrainedWindowGtk* constrained_window_;
diff --git a/chrome/browser/views/accelerator_table_gtk.cc b/chrome/browser/views/accelerator_table_gtk.cc
index 6f6e8c9..28a630b 100644
--- a/chrome/browser/views/accelerator_table_gtk.cc
+++ b/chrome/browser/views/accelerator_table_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -30,7 +30,6 @@ const AcceleratorMapping kAcceleratorMap[] = {
{ base::VKEY_W, false, true, false, IDC_CLOSE_TAB },
{ base::VKEY_T, true, true, false, IDC_RESTORE_TAB },
{ base::VKEY_W, true, true, false, IDC_CLOSE_WINDOW },
- { base::VKEY_W, true, false, true, IDC_CLOSE_POPUPS },
{ base::VKEY_TAB, false, true, false, IDC_SELECT_NEXT_TAB },
{ base::VKEY_TAB, true, true, false, IDC_SELECT_PREVIOUS_TAB },
diff --git a/chrome/browser/views/blocked_popup_container_view_views.cc b/chrome/browser/views/blocked_popup_container_view_views.cc
deleted file mode 100644
index 4feedba..0000000
--- a/chrome/browser/views/blocked_popup_container_view_views.cc
+++ /dev/null
@@ -1,571 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
-
-#include "chrome/browser/views/blocked_popup_container_view_views.h"
-
-#include <math.h>
-#if defined(OS_WIN)
-#include <windows.h>
-#endif
-
-#include "app/gfx/canvas.h"
-#include "app/gfx/path.h"
-#include "app/gfx/scrollbar_size.h"
-#include "app/l10n_util.h"
-#include "app/menus/simple_menu_model.h"
-#include "app/resource_bundle.h"
-#include "app/slide_animation.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "grit/generated_resources.h"
-#include "grit/theme_resources.h"
-#include "views/background.h"
-#include "views/controls/button/image_button.h"
-#include "views/controls/button/menu_button.h"
-#include "views/controls/menu/menu_2.h"
-#include "views/screen.h"
-
-#if defined(OS_WIN)
-#include "views/widget/widget_win.h"
-#elif defined(OS_LINUX)
-#include "views/widget/widget_gtk.h"
-#endif
-
-namespace {
-// The minimal border around the edge of the notification.
-const int kSmallPadding = 2;
-
-// The background color of the blocked popup notification.
-const SkColor kBackgroundColorTop = SkColorSetRGB(255, 242, 183);
-const SkColor kBackgroundColorBottom = SkColorSetRGB(250, 230, 145);
-
-// The border color of the blocked popup notification. This is the same as the
-// border around the inside of the tab contents.
-const SkColor kBorderColor = SkColorSetRGB(190, 205, 223);
-
-// So that the MenuButton doesn't change its size as its text changes, during
-// construction we feed it the strings it will be displaying, so it can set the
-// max text width to the right value. "99" should preallocate enough space for
-// all numbers we'd show.
-const int kWidestNumber = 99;
-
-// Rounded corner radius (in pixels).
-const int kBackgroundCornerRadius = 4;
-
-// Rounded corner definition so the top corners are rounded, and the bottom are
-// normal 90 degree angles.
-const SkScalar kRoundedCornerRad[8] = {
- // Top left corner
- SkIntToScalar(kBackgroundCornerRadius),
- SkIntToScalar(kBackgroundCornerRadius),
- // Top right corner
- SkIntToScalar(kBackgroundCornerRadius),
- SkIntToScalar(kBackgroundCornerRadius),
- // Bottom right corner
- 0,
- 0,
- // Bottom left corner
- 0,
- 0
-};
-
-} // namespace
-
-#if defined(OS_WIN)
-
-// BlockedPopupContainerViewWidget Win ----------------------------------------
-
-class BlockedPopupContainerViewWidget : public views::WidgetWin {
- public:
- BlockedPopupContainerViewWidget(BlockedPopupContainerViewViews* container,
- gfx::NativeView parent);
-
- void SetBoundsAndShow(const gfx::Rect& bounds);
- void Show();
- void Hide();
-
- // Returns the size of our parent.
- gfx::Size GetParentSize();
-
- private:
- virtual void OnSize(UINT param, const CSize& size);
-
- BlockedPopupContainerViewViews* container_;
-
- DISALLOW_COPY_AND_ASSIGN(BlockedPopupContainerViewWidget);
-};
-
-BlockedPopupContainerViewWidget::BlockedPopupContainerViewWidget(
- BlockedPopupContainerViewViews* container, gfx::NativeView parent)
- : container_(container) {
- set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
- WidgetWin::Init(parent, gfx::Rect());
-}
-
-void BlockedPopupContainerViewWidget::SetBoundsAndShow(
- const gfx::Rect& bounds) {
- SetWindowPos(HWND_TOP, bounds.x(), bounds.y(), bounds.width(),
- bounds.height(), SWP_SHOWWINDOW);
-}
-
-void BlockedPopupContainerViewWidget::Show() {
- SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
-}
-
-void BlockedPopupContainerViewWidget::Hide() {
- SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
-}
-
-gfx::Size BlockedPopupContainerViewWidget::GetParentSize() {
- HWND parent = GetParent();
- RECT client_rect;
- ::GetClientRect(parent, &client_rect);
- return gfx::Size(client_rect.right - client_rect.left,
- client_rect.bottom - client_rect.top);
-}
-
-void BlockedPopupContainerViewWidget::OnSize(UINT param, const CSize& size) {
- container_->UpdateWidgetShape(this, gfx::Size(size.cx, size.cy));
-
- LayoutRootView();
-}
-
-#elif defined(OS_LINUX)
-
-// BlockedPopupContainerViewWidget GTK ----------------------------------------
-class BlockedPopupContainerViewWidget : public views::WidgetGtk {
- public:
- BlockedPopupContainerViewWidget(BlockedPopupContainerViewViews* container,
- gfx::NativeView parent);
-
- void SetBoundsAndShow(const gfx::Rect& bounds);
-
- // Returns the size of our parent.
- gfx::Size GetParentSize();
-
- private:
- virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation);
-
- BlockedPopupContainerViewViews* container_;
-
- DISALLOW_COPY_AND_ASSIGN(BlockedPopupContainerViewWidget);
-};
-
-BlockedPopupContainerViewWidget::BlockedPopupContainerViewWidget(
- BlockedPopupContainerViewViews* container,
- gfx::NativeView parent)
- : views::WidgetGtk(views::WidgetGtk::TYPE_CHILD),
- container_(container) {
- WidgetGtk::Init(parent, gfx::Rect());
-}
-
-void BlockedPopupContainerViewWidget::SetBoundsAndShow(
- const gfx::Rect& bounds) {
- SetBounds(bounds);
- Show();
-}
-
-gfx::Size BlockedPopupContainerViewWidget::GetParentSize() {
- GtkWidget* parent = gtk_widget_get_parent(GetNativeView());
- return gfx::Size(parent->allocation.width, parent->allocation.height);
-}
-
-void BlockedPopupContainerViewWidget::OnSizeAllocate(
- GtkWidget* widget, GtkAllocation* allocation) {
- WidgetGtk::OnSizeAllocate(widget, allocation);
- container_->UpdateWidgetShape(
- this, gfx::Size(allocation->width, allocation->height));
-}
-
-#endif
-
-// BlockedPopupContainerInternalView ------------------------------------------
-
-// The view presented to the user notifying them of the number of popups
-// blocked. This view should only be used inside of BlockedPopupContainer.
-class BlockedPopupContainerInternalView : public views::View,
- public views::ButtonListener,
- public menus::SimpleMenuModel::Delegate {
- public:
- explicit BlockedPopupContainerInternalView(
- BlockedPopupContainerViewViews* container);
- ~BlockedPopupContainerInternalView();
-
- // Sets the label on the menu button.
- void UpdateLabel();
-
- std::wstring label() const { return popup_count_label_->text(); }
-
- // Overridden from views::View:
-
- // Paints our border and background. (Does not paint children.)
- virtual void Paint(gfx::Canvas* canvas);
- // Sets positions of all child views.
- virtual void Layout();
- // Gets the desired size of the popup notification.
- virtual gfx::Size GetPreferredSize();
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- // Overridden from SimpleMenuModel::Delegate:
-
- // Displays the status of the "Show Blocked Popup Notification" item.
- virtual bool IsCommandIdChecked(int id) const;
- virtual bool IsCommandIdEnabled(int id) const { return true; }
- virtual bool GetAcceleratorForCommandId(int command_id,
- menus::Accelerator* accelerator) {
- return false;
- }
- // Called after user clicks a menu item.
- virtual void ExecuteCommand(int id);
-
- private:
- // Our owner and HWND parent.
- BlockedPopupContainerViewViews* container_;
-
- // The button which brings up the popup menu.
- views::MenuButton* popup_count_label_;
-
- // Our "X" button.
- views::ImageButton* close_button_;
-
- // Model for the menu.
- scoped_ptr<menus::SimpleMenuModel> launch_menu_model_;
-
- // Popup menu shown to user.
- scoped_ptr<views::Menu2> launch_menu_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedPopupContainerInternalView);
-};
-
-
-BlockedPopupContainerInternalView::BlockedPopupContainerInternalView(
- BlockedPopupContainerViewViews* container)
- : container_(container) {
- ResourceBundle &resource_bundle = ResourceBundle::GetSharedInstance();
-
- // Create a button with a multidigit number to reserve space.
- popup_count_label_ = new views::MenuButton(
- this,
- l10n_util::GetStringF(IDS_POPUPS_BLOCKED_COUNT,
- IntToWString(kWidestNumber)),
- NULL, true);
- // 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_);
-
- // For now, we steal the Find close button, since it looks OK.
- close_button_ = new views::ImageButton(this);
- close_button_->SetFocusable(true);
- close_button_->SetImage(views::CustomButton::BS_NORMAL,
- resource_bundle.GetBitmapNamed(IDR_CLOSE_BAR));
- close_button_->SetImage(views::CustomButton::BS_HOT,
- resource_bundle.GetBitmapNamed(IDR_CLOSE_BAR_H));
- close_button_->SetImage(views::CustomButton::BS_PUSHED,
- resource_bundle.GetBitmapNamed(IDR_CLOSE_BAR_P));
- AddChildView(close_button_);
-
- set_background(views::Background::CreateStandardPanelBackground());
- UpdateLabel();
-}
-
-BlockedPopupContainerInternalView::~BlockedPopupContainerInternalView() {
-}
-
-void BlockedPopupContainerInternalView::UpdateLabel() {
- size_t blocked_notices = container_->model()->GetBlockedNoticeCount();
- size_t blocked_items = container_->model()->GetBlockedPopupCount() +
- blocked_notices;
-
- std::wstring label;
- if (blocked_items == 0) {
- label = l10n_util::GetString(IDS_POPUPS_UNBLOCKED);
- } else if (blocked_notices == 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();
-}
-
-void BlockedPopupContainerInternalView::Paint(gfx::Canvas* canvas) {
- // Draw the standard background.
- View::Paint(canvas);
-
- SkRect rect;
- rect.set(0, 0, SkIntToScalar(width()), SkIntToScalar(height()));
-
- // Draw the border
- SkPaint border_paint;
- border_paint.setFlags(SkPaint::kAntiAlias_Flag);
- border_paint.setStyle(SkPaint::kStroke_Style);
- border_paint.setColor(kBorderColor);
- SkPath border_path;
- border_path.addRoundRect(rect, kRoundedCornerRad, SkPath::kCW_Direction);
- canvas->drawPath(border_path, border_paint);
-}
-
-void BlockedPopupContainerInternalView::Layout() {
- gfx::Size panel_size = GetPreferredSize();
- gfx::Size button_size = close_button_->GetPreferredSize();
- gfx::Size size = popup_count_label_->GetPreferredSize();
-
- popup_count_label_->SetBounds(kSmallPadding, kSmallPadding,
- size.width(),
- size.height());
-
- int close_button_padding =
- static_cast<int>(ceil(panel_size.height() / 2.0) -
- ceil(button_size.height() / 2.0));
- close_button_->SetBounds(width() - button_size.width() - close_button_padding,
- close_button_padding,
- button_size.width(),
- button_size.height());
-}
-
-gfx::Size BlockedPopupContainerInternalView::GetPreferredSize() {
- gfx::Size preferred_size = popup_count_label_->GetPreferredSize();
- preferred_size.Enlarge(close_button_->GetPreferredSize().width(), 0);
- // Add padding to all sides of the |popup_count_label_| except the right.
- preferred_size.Enlarge(kSmallPadding, 2 * kSmallPadding);
-
- // Add padding to the left and right side of |close_button_| equal to its
- // horizontal/vertical spacing.
- gfx::Size button_size = close_button_->GetPreferredSize();
- int close_button_padding =
- static_cast<int>(ceil(preferred_size.height() / 2.0) -
- ceil(button_size.height() / 2.0));
- preferred_size.Enlarge(2 * close_button_padding, 0);
-
- return preferred_size;
-}
-
-void BlockedPopupContainerInternalView::ButtonPressed(
- views::Button* sender, const views::Event& event) {
- if (sender == close_button_) {
- container_->model()->set_dismissed();
- container_->model()->CloseAll();
- }
-
- if (sender != popup_count_label_)
- return;
-
- launch_menu_model_.reset(new menus::SimpleMenuModel(this));
-
- // Set items 1 .. popup_count as individual popups.
- size_t popup_count = container_->model()->GetBlockedPopupCount();
- for (size_t i = 0; i < popup_count; ++i) {
- std::wstring url, title;
- container_->GetURLAndTitleForPopup(i, &url, &title);
- // We can't just use the index into container_ here because Menu reserves
- // the value 0 as the nop command.
- launch_menu_model_->AddItem(i + 1,
- l10n_util::GetStringFUTF16(IDS_POPUP_TITLE_FORMAT, WideToUTF16(url),
- WideToUTF16(title)));
- }
-
- // Set items (kImpossibleNumberOfPopups + 1) ..
- // (kImpossibleNumberOfPopups + hosts.size()) as hosts.
- std::vector<std::string> hosts(container_->model()->GetHosts());
- if (!hosts.empty() && (popup_count > 0))
- launch_menu_model_->AddSeparator();
- size_t first_host = BlockedPopupContainer::kImpossibleNumberOfPopups + 1;
- for (size_t i = 0; i < hosts.size(); ++i) {
- launch_menu_model_->AddCheckItem(first_host + i,
- l10n_util::GetStringFUTF16(IDS_POPUP_HOST_FORMAT,
- UTF8ToUTF16(hosts[i])));
- }
-
- // Set items (kImpossibleNumberOfPopups + hosts.size() + 2) ..
- // (kImpossibleNumberOfPopups + hosts.size() + 1 + notice_count) as notices.
- size_t notice_count = container_->model()->GetBlockedNoticeCount();
- if (notice_count && (!hosts.empty() || (popup_count > 0)))
- launch_menu_model_->AddSeparator();
- size_t first_notice = first_host + hosts.size() + 1;
- for (size_t i = 0; i < notice_count; ++i) {
- std::string host;
- string16 reason;
- container_->model()->GetHostAndReasonForNotice(i, &host, &reason);
- launch_menu_model_->AddItem(first_notice + i,
- l10n_util::GetStringFUTF16(IDS_NOTICE_TITLE_FORMAT, ASCIIToUTF16(host),
- reason));
- }
-
- launch_menu_.reset(new views::Menu2(launch_menu_model_.get()));
- launch_menu_->RunContextMenuAt(views::Screen::GetCursorScreenPoint());
-}
-
-bool BlockedPopupContainerInternalView::IsCommandIdChecked(int id) const {
- // |id| should be > 0 since all index based commands have 1 added to them.
- DCHECK_GT(id, 0);
- size_t id_size_t = static_cast<size_t>(id);
-
- if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) {
- id_size_t -= BlockedPopupContainer::kImpossibleNumberOfPopups + 1;
- if (id_size_t < container_->model()->GetPopupHostCount())
- return container_->model()->IsHostWhitelisted(id_size_t);
- }
-
- return false;
-}
-
-void BlockedPopupContainerInternalView::ExecuteCommand(int id) {
- // |id| should be > 0 since all index based commands have 1 added to them.
- DCHECK_GT(id, 0);
- size_t id_size_t = static_cast<size_t>(id);
-
- // Is this a click on a popup?
- if (id_size_t < BlockedPopupContainer::kImpossibleNumberOfPopups) {
- container_->model()->LaunchPopupAtIndex(id_size_t - 1);
- return;
- }
-
- // |id| shouldn't be == kImpossibleNumberOfPopups since the popups end before
- // this and the hosts start after it. (If it is used, it is as a separator.)
- DCHECK_NE(id_size_t, BlockedPopupContainer::kImpossibleNumberOfPopups);
- id_size_t -= BlockedPopupContainer::kImpossibleNumberOfPopups + 1;
-
- // Is this a click on a host?
- size_t host_count = container_->model()->GetPopupHostCount();
- if (id_size_t < host_count) {
- container_->model()->ToggleWhitelistingForHost(id_size_t);
- return;
- }
-
- // |id shouldn't be == host_count since this is the separator between hosts
- // and notices.
- DCHECK_NE(id_size_t, host_count);
- id_size_t -= host_count + 1;
-
- // Nothing to do for now for notices.
-}
-
-// BlockedPopupContainerViewViews ---------------------------------------------
-
-// static
-BlockedPopupContainerView* BlockedPopupContainerView::Create(
- BlockedPopupContainer* container) {
- return new BlockedPopupContainerViewViews(container);
-}
-
-BlockedPopupContainerViewViews::~BlockedPopupContainerViewViews() {
-}
-
-void BlockedPopupContainerViewViews::GetURLAndTitleForPopup(
- size_t index, std::wstring* url, std::wstring* title) const {
- DCHECK(url);
- DCHECK(title);
- TabContents* tab_contents = model()->GetTabContentsAt(index);
- const GURL& tab_contents_url = tab_contents->GetURL().GetOrigin();
- *url = UTF8ToWide(tab_contents_url.possibly_invalid_spec());
- *title = UTF16ToWideHack(tab_contents->GetTitle());
-}
-
-// Overridden from AnimationDelegate:
-
-void BlockedPopupContainerViewViews::AnimationStarted(
- const Animation* animation) {
- SetPosition();
-}
-
-void BlockedPopupContainerViewViews::AnimationEnded(const Animation* animation) {
- SetPosition();
-}
-
-void BlockedPopupContainerViewViews::AnimationProgressed(
- const Animation* animation) {
- SetPosition();
-}
-
-// Overridden from BlockedPopupContainerView:
-
-void BlockedPopupContainerViewViews::SetPosition() {
- gfx::Size parent_size = widget_->GetParentSize();
-
- // TODO(erg): There's no way to detect whether scroll bars are
- // visible, so for beta, we're just going to assume that the
- // vertical scroll bar is visible, and not care about covering up
- // the horizontal scroll bar. Fixing this is half of
- // http://b/1118139.
- gfx::Point anchor_point(parent_size.width() - gfx::scrollbar_size(),
- parent_size.height());
-
- gfx::Size size = container_view_->GetPreferredSize();
- int base_x = anchor_point.x() - size.width();
-
- int real_height =
- static_cast<int>(size.height() * slide_animation_->GetCurrentValue());
- int real_y = anchor_point.y() - real_height;
-
- if (real_height > 0) {
- int x;
- if (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) {
- // Size this window using the anchor point as top-right corner.
- x = base_x;
- } else {
- // Size this window to the bottom left corner of top client window. In
- // Chrome, scrollbars always appear on the right, even for a RTL page or
- // when the UI is RTL (see http://crbug.com/6113 for more detail). Thus 0
- // is always a safe value for x-axis.
- x = 0;
- }
- widget_->SetBoundsAndShow(gfx::Rect(x, real_y, size.width(), real_height));
- container_view_->SchedulePaint();
- } else {
- widget_->Hide();
- }
-}
-
-void BlockedPopupContainerViewViews::ShowView() {
- widget_->Show();
- slide_animation_->Show();
-}
-
-void BlockedPopupContainerViewViews::UpdateLabel() {
- container_view_->UpdateLabel();
-}
-
-void BlockedPopupContainerViewViews::HideView() {
- slide_animation_->Hide();
-}
-
-void BlockedPopupContainerViewViews::Destroy() {
- widget_->CloseNow();
- delete this;
-}
-
-// private:
-
-BlockedPopupContainerViewViews::BlockedPopupContainerViewViews(
- BlockedPopupContainer* container)
- : widget_(NULL),
- model_(container),
- container_view_(NULL),
- slide_animation_(new SlideAnimation(this)) {
- widget_ = new BlockedPopupContainerViewWidget(this,
- model_->GetConstrainingContents(NULL)->GetNativeView());
- container_view_ = new BlockedPopupContainerInternalView(this);
- widget_->SetContentsView(container_view_);
- SetPosition();
-}
-
-void BlockedPopupContainerViewViews::UpdateWidgetShape(
- BlockedPopupContainerViewWidget* widget, const gfx::Size& size) {
- // Set the shape so we have rounded corners on the top.
- SkRect rect;
- rect.set(0, 0, SkIntToScalar(size.width()), SkIntToScalar(size.height()));
- gfx::Path path;
- path.addRoundRect(rect, kRoundedCornerRad, SkPath::kCW_Direction);
- widget->SetShape(path.CreateNativeRegion());
-}
diff --git a/chrome/browser/views/blocked_popup_container_view_views.h b/chrome/browser/views/blocked_popup_container_view_views.h
deleted file mode 100644
index 2553021..0000000
--- a/chrome/browser/views/blocked_popup_container_view_views.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_VIEW_VIEWS_H_
-#define CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_VIEW_VIEWS_H_
-
-#include "app/animation.h"
-#include "chrome/browser/blocked_popup_container.h"
-
-class BlockedPopupContainerViewWidget;
-class BlockedPopupContainerInternalView;
-class SlideAnimation;
-
-// Takes ownership of TabContents that are unrequested popup windows and
-// presents an interface to the user for launching them. (Or never showing them
-// again).
-class BlockedPopupContainerViewViews : public BlockedPopupContainerView,
- public AnimationDelegate {
- public:
- virtual ~BlockedPopupContainerViewViews();
-
- // Returns the URL and title for popup |index|, used to construct a string for
- // display.
- void GetURLAndTitleForPopup(size_t index,
- std::wstring* url,
- std::wstring* title) const;
-
- // Returns the model that owns us.
- BlockedPopupContainer* model() const { return model_; }
-
- // Overridden from AnimationDelegate:
- virtual void AnimationStarted(const Animation* animation);
- virtual void AnimationEnded(const Animation* animation);
- virtual void AnimationProgressed(const Animation* animation);
-
- // Overridden from BlockedPopupContainerView:
- virtual void SetPosition();
- virtual void ShowView();
- virtual void UpdateLabel();
- virtual void HideView();
- virtual void Destroy();
-
- private:
- // For the static constructor BlockedPopupContainerView::Create().
- friend class BlockedPopupContainerView;
- friend class BlockedPopupContainerViewWidget;
-
- // Creates a container for a certain TabContents.
- explicit BlockedPopupContainerViewViews(BlockedPopupContainer* container);
-
- // Updates the shape of the widget.
- void UpdateWidgetShape(BlockedPopupContainerViewWidget* widget,
- const gfx::Size& size);
-
- // Widget hosting container_view_.
- BlockedPopupContainerViewWidget* widget_;
-
- // Our model; calling the shots.
- BlockedPopupContainer* model_;
-
- // Our associated view object.
- BlockedPopupContainerInternalView* container_view_;
-
- // The animation that slides us up and down.
- scoped_ptr<SlideAnimation> slide_animation_;
-
- DISALLOW_COPY_AND_ASSIGN(BlockedPopupContainerViewViews);
-};
-
-#endif // CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_VIEW_VIEWS_H_
diff --git a/chrome/browser/views/content_blocked_bubble_contents.cc b/chrome/browser/views/content_blocked_bubble_contents.cc
index 82c9eca..35eb5b4 100644
--- a/chrome/browser/views/content_blocked_bubble_contents.cc
+++ b/chrome/browser/views/content_blocked_bubble_contents.cc
@@ -5,9 +5,13 @@
#include "chrome/browser/views/content_blocked_bubble_contents.h"
#include "app/l10n_util.h"
+#include "chrome/browser/blocked_popup_container.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/info_bubble.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/notification_type.h"
#include "grit/generated_resources.h"
#include "views/controls/button/native_button.h"
#include "views/controls/button/radio_button.h"
@@ -24,16 +28,20 @@ ContentBlockedBubbleContents::ContentBlockedBubbleContents(
ContentSettingsType content_type,
const std::string& host,
const std::wstring& display_host,
- Profile* profile)
+ Profile* profile,
+ TabContents* tab_contents)
: content_type_(content_type),
host_(host),
display_host_(display_host),
profile_(profile),
+ tab_contents_(tab_contents),
info_bubble_(NULL),
allow_radio_(NULL),
block_radio_(NULL),
close_button_(NULL),
manage_link_(NULL) {
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
+ Source<TabContents>(tab_contents));
}
ContentBlockedBubbleContents::~ContentBlockedBubbleContents() {
@@ -71,7 +79,18 @@ void ContentBlockedBubbleContents::LinkActivated(views::Link* source,
#endif
}
- // TODO(pkasting): A popup link was clicked, show the corresponding popup.
+ PopupLinks::const_iterator i(popup_links_.find(source));
+ DCHECK(i != popup_links_.end());
+ if (tab_contents_ && tab_contents_->blocked_popup_container())
+ tab_contents_->blocked_popup_container()->LaunchPopupForContents(i->second);
+}
+
+void ContentBlockedBubbleContents::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
+ DCHECK(source == Source<TabContents>(tab_contents_));
+ tab_contents_ = NULL;
}
void ContentBlockedBubbleContents::InitControlLayout() {
@@ -102,15 +121,21 @@ void ContentBlockedBubbleContents::InitControlLayout() {
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
if (content_type_ == CONTENT_SETTINGS_TYPE_POPUPS) {
- /* TODO(pkasting): Show list of blocked popups as clickable links.
- for (size_t i = 0; i < num_popups; ++i) {
- if (i != 0)
+ BlockedPopupContainer::BlockedContents blocked_contents;
+ DCHECK(tab_contents_->blocked_popup_container());
+ tab_contents_->blocked_popup_container()->GetBlockedContents(
+ &blocked_contents);
+ for (BlockedPopupContainer::BlockedContents::const_iterator
+ i(blocked_contents.begin()); i != blocked_contents.end(); ++i) {
+ views::Link* link = new views::Link(UTF16ToWideHack((*i)->GetTitle()));
+ link->SetController(this);
+ popup_links_[link] = *i;
+ if (i != blocked_contents.begin())
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, single_column_set_id);
- layout->AddView(popup_link);
+ layout->AddView(link);
}
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
- */
views::Separator* separator = new views::Separator;
layout->StartRow(0, single_column_set_id);
diff --git a/chrome/browser/views/content_blocked_bubble_contents.h b/chrome/browser/views/content_blocked_bubble_contents.h
index 7b7c434..f7ffe1b 100644
--- a/chrome/browser/views/content_blocked_bubble_contents.h
+++ b/chrome/browser/views/content_blocked_bubble_contents.h
@@ -5,9 +5,11 @@
#ifndef CHROME_BROWSER_VIEWS_CONTENT_BLOCKED_BUBBLE_CONTENTS_H_
#define CHROME_BROWSER_VIEWS_CONTENT_BLOCKED_BUBBLE_CONTENTS_H_
+#include <map>
#include <string>
#include "chrome/common/content_settings_types.h"
+#include "chrome/common/notification_registrar.h"
#include "views/controls/button/button.h"
#include "views/controls/link.h"
@@ -23,6 +25,7 @@
class InfoBubble;
class Profile;
+class TabContents;
namespace views {
class NativeButton;
@@ -31,14 +34,23 @@ class RadioButton;
class ContentBlockedBubbleContents : public views::View,
public views::ButtonListener,
- public views::LinkController {
+ public views::LinkController,
+ public NotificationObserver {
public:
ContentBlockedBubbleContents(ContentSettingsType content_type,
const std::string& host,
const std::wstring& display_host,
- Profile* profile);
+ Profile* profile,
+ TabContents* tab_contents);
virtual ~ContentBlockedBubbleContents();
+ // Sets |info_bubble_|, so we can close the bubble if needed. The caller owns
+ // the bubble and must keep it alive.
+ void set_info_bubble(InfoBubble* info_bubble) { info_bubble_ = info_bubble; }
+
+ private:
+ typedef std::map<views::Link*, TabContents*> PopupLinks;
+
// Overridden from views::View:
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
@@ -48,11 +60,11 @@ class ContentBlockedBubbleContents : public views::View,
// views::LinkController:
virtual void LinkActivated(views::Link* source, int event_flags);
- // Sets |info_bubble_|, so we can close the bubble if needed. The caller owns
- // the bubble and must keep it alive.
- void set_info_bubble(InfoBubble* info_bubble) { info_bubble_ = info_bubble; }
+ // NotificationObserver:
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
- private:
// Creates the child views.
void InitControlLayout();
@@ -66,11 +78,18 @@ class ContentBlockedBubbleContents : public views::View,
// The active profile.
Profile* profile_;
+ // The active tab contents.
+ TabContents* tab_contents_;
+
+ // A registrar for listening for TAB_CONTENTS_DESTROYED notifications.
+ NotificationRegistrar registrar_;
+
// The InfoBubble holding us.
InfoBubble* info_bubble_;
// Some of our controls, so we can tell what's been clicked when we get a
// message.
+ PopupLinks popup_links_;
views::RadioButton* allow_radio_;
views::RadioButton* block_radio_;
views::NativeButton* close_button_;
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 39773b7..5a29b59 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -346,9 +346,8 @@ void LocationBarView::SetProfile(Profile* profile) {
}
}
-GURL LocationBarView::GetURL() const {
- const TabContents* tab_contents = delegate_->GetTabContents();
- return tab_contents ? tab_contents->GetURL() : GURL();
+TabContents* LocationBarView::GetTabContents() const {
+ return delegate_->GetTabContents();
}
void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction *page_action,
@@ -1373,14 +1372,17 @@ bool LocationBarView::ContentBlockedImageView::OnMousePressed(
bounds.set_x(location.x());
bounds.set_width(width());
- GURL url = parent_->GetURL();
+ TabContents* tab_contents = parent_->GetTabContents();
+ if (!tab_contents)
+ return true;
+ GURL url = tab_contents->GetURL();
std::wstring display_host;
net::AppendFormattedHost(url,
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), &display_host,
NULL, NULL);
ContentBlockedBubbleContents* bubble_contents =
new ContentBlockedBubbleContents(content_type_, url.host(), display_host,
- profile_);
+ profile_, tab_contents);
DCHECK(!info_bubble_);
info_bubble_ = InfoBubble::Show(GetWindow(), bounds, bubble_contents, this);
bubble_contents->set_info_bubble(info_bubble_);
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index 4b405c3..4554efb 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -102,9 +102,9 @@ class LocationBarView : public LocationBar,
void SetProfile(Profile* profile);
Profile* profile() { return profile_; }
- // Returns the URL for the current page. This should only be used by the
+ // Returns the current TabContents. This should only be used by the
// ContentBlockedImageView.
- GURL GetURL() const;
+ TabContents* GetTabContents() const;
// Sets |preview_enabled| for the PageAction View associated with this
// |page_action|. If |preview_enabled| is true, the view will display the
diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
index 79f246b..51f7057 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
@@ -1,6 +1,6 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "chrome/browser/views/tab_contents/tab_contents_view_gtk.h"
@@ -23,7 +23,6 @@
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/browser/tab_contents/web_drag_dest_gtk.h"
-#include "chrome/browser/views/blocked_popup_container_view_views.h"
#include "chrome/browser/views/sad_tab_view.h"
#include "chrome/browser/views/tab_contents/render_view_context_menu_win.h"
#include "views/controls/native/native_view_host.h"
@@ -393,9 +392,6 @@ void TabContentsViewGtk::WasSized(const gfx::Size& size) {
if (tab_contents()->render_widget_host_view())
tab_contents()->render_widget_host_view()->SetSize(size);
- // TODO(brettw) this function can probably be moved to this class.
- tab_contents()->RepositionSupressedPopupsToFit();
-
SetFloatingPosition(size);
}
diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
index f6bb820..05dfc32 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -507,9 +507,6 @@ void TabContentsViewWin::WasSized(const gfx::Size& size) {
tab_contents()->interstitial_page()->SetSize(size);
if (tab_contents()->render_widget_host_view())
tab_contents()->render_widget_host_view()->SetSize(size);
-
- // TODO(brettw) this function can probably be moved to this class.
- tab_contents()->RepositionSupressedPopupsToFit();
}
bool TabContentsViewWin::ScrollZoom(int scroll_type) {
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index f5a04cc..15b097cf 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -359,8 +359,6 @@
'browser/cocoa/base_view.h',
'browser/cocoa/base_view.mm',
'browser/cocoa/browser_window_factory.mm',
- 'browser/cocoa/blocked_popup_container_controller.h',
- 'browser/cocoa/blocked_popup_container_controller.mm',
'browser/cocoa/bookmark_all_tabs_controller.h',
'browser/cocoa/bookmark_all_tabs_controller.mm',
'browser/cocoa/bookmark_bar_bridge.h',
@@ -885,8 +883,6 @@
'browser/gtk/accessible_widget_helper_gtk.h',
'browser/gtk/back_forward_button_gtk.cc',
'browser/gtk/back_forward_button_gtk.h',
- 'browser/gtk/blocked_popup_container_view_gtk.cc',
- 'browser/gtk/blocked_popup_container_view_gtk.h',
'browser/gtk/bookmark_bar_gtk.cc',
'browser/gtk/bookmark_bar_gtk.h',
'browser/gtk/bookmark_bar_instructions_gtk.cc',
@@ -1707,8 +1703,6 @@
'browser/views/autocomplete/autocomplete_popup_gtk.h',
'browser/views/autofill_profiles_view_win.cc',
'browser/views/autofill_profiles_view_win.h',
- 'browser/views/blocked_popup_container_view_views.cc',
- 'browser/views/blocked_popup_container_view_views.h',
'browser/views/bookmark_bar_instructions_view.cc',
'browser/views/bookmark_bar_instructions_view.h',
'browser/views/bookmark_bar_view.cc',
@@ -2306,8 +2300,6 @@
['include', '^browser/views/autocomplete/autocomplete_popup_contents_view.h'],
['include', '^browser/views/autocomplete/autocomplete_popup_gtk.cc'],
['include', '^browser/views/autocomplete/autocomplete_popup_gtk.h'],
- ['include', '^browser/views/blocked_popup_container_view_views.cc'],
- ['include', '^browser/views/blocked_popup_container_view_views.h'],
['include', '^browser/views/bookmark_bar_instructions_view.cc'],
['include', '^browser/views/bookmark_bar_instructions_view.h'],
['include', '^browser/views/bookmark_bar_view.cc'],
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 5738f3e..939ffa4 100755
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1,4 +1,4 @@
-# Copyright (c) 2009 The Chromium Authors. All rights reserved.
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -528,7 +528,6 @@
'browser/autofill/personal_data_manager_unittest.cc',
'browser/automation/automation_provider_unittest.cc',
'browser/back_forward_menu_model_unittest.cc',
- 'browser/blocked_popup_container_unittest.cc',
'browser/bookmarks/bookmark_codec_unittest.cc',
'browser/bookmarks/bookmark_drag_data_unittest.cc',
'browser/bookmarks/bookmark_folder_tree_model_unittest.cc',
@@ -568,7 +567,6 @@
'browser/cocoa/base_view_unittest.mm',
'browser/cocoa/background_gradient_view_unittest.mm',
'browser/cocoa/background_tile_view_unittest.mm',
- 'browser/cocoa/blocked_popup_container_controller_unittest.mm',
'browser/cocoa/bookmark_all_tabs_controller_unittest.mm',
'browser/cocoa/bookmark_bar_bridge_unittest.mm',
'browser/cocoa/bookmark_bar_controller_unittest.mm',
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 9254f73..39fdb86 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -50,7 +50,8 @@ 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).
+// OBSOLETE. The list of hostnames for which we whitelist popups (rather than
+// blocking).
const wchar_t kPopupWhitelistedHosts[] = L"profile.popup_whitelisted_sites";
// WebKit preferences.
diff --git a/chrome/test/interactive_ui/interactive_ui_tests.gypi b/chrome/test/interactive_ui/interactive_ui_tests.gypi
index 260035f..d05f7fc 100644
--- a/chrome/test/interactive_ui/interactive_ui_tests.gypi
+++ b/chrome/test/interactive_ui/interactive_ui_tests.gypi
@@ -32,7 +32,6 @@
'<(DEPTH)/chrome/browser/browser_keyevents_browsertest.cc',
'<(DEPTH)/chrome/browser/debugger/devtools_sanity_unittest.cc',
'<(DEPTH)/chrome/browser/views/bookmark_bar_view_test.cc',
- '<(DEPTH)/chrome/browser/blocked_popup_container_interactive_uitest.cc',
'<(DEPTH)/chrome/browser/views/find_bar_host_interactive_uitest.cc',
'<(DEPTH)/chrome/browser/views/tabs/tab_dragging_test.cc',
'<(DEPTH)/chrome/test/in_process_browser_test.cc',
@@ -82,7 +81,6 @@
'<(DEPTH)/chrome/browser/browser_keyevents_browsertest.cc',
'<(DEPTH)/chrome/browser/debugger/devtools_sanity_unittest.cc',
'<(DEPTH)/chrome/browser/views/bookmark_bar_view_test.cc',
- '<(DEPTH)/chrome/browser/blocked_popup_container_interactive_uitest.cc',
'<(DEPTH)/chrome/browser/views/find_bar_host_interactive_uitest.cc',
'<(DEPTH)/chrome/browser/views/tabs/tab_dragging_test.cc',
'<(DEPTH)/chrome/test/interactive_ui/npapi_interactive_test.cc',