summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-02 10:40:49 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-02 10:40:49 +0000
commit8cc8d4914c363a3308fdbae1415e2a3fbbce8e9e (patch)
treef2b38543aa09fd9945341376bfca465b7efbbf92 /chrome/browser/tab_contents
parent458788376076d57d182ca22060b335d2e5f2e18f (diff)
downloadchromium_src-8cc8d4914c363a3308fdbae1415e2a3fbbce8e9e.zip
chromium_src-8cc8d4914c363a3308fdbae1415e2a3fbbce8e9e.tar.gz
chromium_src-8cc8d4914c363a3308fdbae1415e2a3fbbce8e9e.tar.bz2
Wire popup blocking UI to the new machinery and port over the user's old whitelist.
Notably, this removes the UI entirely for Mac and Linux. We need to rebuild it. This also guts the old system's testing, since most of it disappeared or changed radically. We should test the new stuff. I will file a followup bug for that. There are various tiny edge cases, like if you click the address bar icon really quickly, sometimes you'll get popups without any title yet, which makes them leave gaps in the bubble that appears. We can fix that sort of thing. The critical bit I tried to ensure was that we never try to open a dead popup or use a dead TabContents, no matter what. BUG=33314 TEST=Go visit some sites with popups and play with things Review URL: http://codereview.chromium.org/562013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37819 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-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
5 files changed, 55 insertions, 157 deletions
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_;