summaryrefslogtreecommitdiffstats
path: root/chrome/browser/blocked_content_container.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 15:30:40 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 15:30:40 +0000
commitc65e2f15891448a06a89c7a2e0e9aa74d1a44c67 (patch)
tree0a8f6b8d60b332a9d4c60f85046f8a3f7ba3e96d /chrome/browser/blocked_content_container.cc
parent87996f6636dd308b649e38e7b83df05045e62b81 (diff)
downloadchromium_src-c65e2f15891448a06a89c7a2e0e9aa74d1a44c67.zip
chromium_src-c65e2f15891448a06a89c7a2e0e9aa74d1a44c67.tar.gz
chromium_src-c65e2f15891448a06a89c7a2e0e9aa74d1a44c67.tar.bz2
Fixes instant so that it correctly deals with child contents. I've
changed around BlockedPopupContainer so that it can handle any types and made TabContents offer a mode to block all child content. BUG=58927 TEST=enable instant, go to a site that would normally show a popup on entering (or explicitly enable all popups). While typing in the omnibox the popup shouldn't appear, but as soon as you commit the instant result it should appear. Review URL: http://codereview.chromium.org/3694005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/blocked_content_container.cc')
-rw-r--r--chrome/browser/blocked_content_container.cc149
1 files changed, 149 insertions, 0 deletions
diff --git a/chrome/browser/blocked_content_container.cc b/chrome/browser/blocked_content_container.cc
new file mode 100644
index 0000000..58897c4
--- /dev/null
+++ b/chrome/browser/blocked_content_container.cc
@@ -0,0 +1,149 @@
+// 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_content_container.h"
+
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "gfx/rect.h"
+
+// static
+const size_t BlockedContentContainer::kImpossibleNumberOfPopups = 30;
+
+struct BlockedContentContainer::BlockedContent {
+ BlockedContent(TabContents* tab_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& bounds,
+ bool user_gesture)
+ : tab_contents(tab_contents),
+ disposition(disposition),
+ bounds(bounds),
+ user_gesture(user_gesture) {
+ }
+
+ TabContents* tab_contents;
+ WindowOpenDisposition disposition;
+ gfx::Rect bounds;
+ bool user_gesture;
+};
+
+BlockedContentContainer::BlockedContentContainer(TabContents* owner)
+ : owner_(owner) {
+}
+
+void BlockedContentContainer::AddTabContents(TabContents* tab_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& bounds,
+ bool user_gesture) {
+ if (blocked_contents_.size() == (kImpossibleNumberOfPopups - 1)) {
+ delete tab_contents;
+ LOG(INFO) << "Warning: Renderer is sending more popups to us than should "
+ "be possible. Renderer compromised?";
+ return;
+ }
+
+ blocked_contents_.push_back(
+ BlockedContent(tab_contents, disposition, bounds, user_gesture));
+ tab_contents->set_delegate(this);
+ if (blocked_contents_.size() == 1)
+ owner_->PopupNotificationVisibilityChanged(true);
+}
+
+void BlockedContentContainer::LaunchForContents(TabContents* tab_contents) {
+ // Open the popup.
+ for (BlockedContents::iterator i(blocked_contents_.begin());
+ i != blocked_contents_.end(); ++i) {
+ if (i->tab_contents == tab_contents) {
+ // To support the owner blocking the content again we copy and erase
+ // before attempting to add.
+ BlockedContent content(*i);
+ blocked_contents_.erase(i);
+ i = blocked_contents_.end();
+ tab_contents->set_delegate(NULL);
+ owner_->AddNewContents(tab_contents, content.disposition, content.bounds,
+ content.user_gesture);
+ break;
+ }
+ }
+
+ if (blocked_contents_.empty())
+ Destroy();
+}
+
+size_t BlockedContentContainer::GetBlockedContentsCount() const {
+ return blocked_contents_.size();
+}
+
+void BlockedContentContainer::GetBlockedContents(
+ std::vector<TabContents*>* blocked_contents) const {
+ DCHECK(blocked_contents);
+ for (BlockedContents::const_iterator i(blocked_contents_.begin());
+ i != blocked_contents_.end(); ++i)
+ blocked_contents->push_back(i->tab_contents);
+}
+
+void BlockedContentContainer::Destroy() {
+ for (BlockedContents::iterator i(blocked_contents_.begin());
+ i != blocked_contents_.end(); ++i) {
+ TabContents* tab_contents = i->tab_contents;
+ tab_contents->set_delegate(NULL);
+ delete tab_contents;
+ }
+ blocked_contents_.clear();
+ owner_->WillCloseBlockedContentContainer(this);
+ delete this;
+}
+
+// Overridden from TabContentsDelegate:
+void BlockedContentContainer::OpenURLFromTab(TabContents* source,
+ const GURL& url,
+ const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition) {
+ owner_->OpenURL(url, referrer, disposition, transition);
+}
+
+void BlockedContentContainer::AddNewContents(TabContents* source,
+ TabContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_position,
+ bool user_gesture) {
+ owner_->AddNewContents(new_contents, disposition, initial_position,
+ user_gesture);
+}
+
+void BlockedContentContainer::CloseContents(TabContents* source) {
+ for (BlockedContents::iterator i(blocked_contents_.begin());
+ i != blocked_contents_.end(); ++i) {
+ TabContents* tab_contents = i->tab_contents;
+ if (tab_contents == source) {
+ tab_contents->set_delegate(NULL);
+ blocked_contents_.erase(i);
+ delete tab_contents;
+ break;
+ }
+ }
+}
+
+void BlockedContentContainer::MoveContents(TabContents* source,
+ const gfx::Rect& new_bounds) {
+ for (BlockedContents::iterator i(blocked_contents_.begin());
+ i != blocked_contents_.end(); ++i) {
+ if (i->tab_contents == source) {
+ i->bounds = new_bounds;
+ break;
+ }
+ }
+}
+
+bool BlockedContentContainer::IsPopup(const TabContents* source) const {
+ // Assume everything added is a popup. This may turn out to be wrong, but
+ // callers don't cache this information so it should be fine if the value ends
+ // up changing.
+ return true;
+}
+
+TabContents* BlockedContentContainer::GetConstrainingContents(
+ TabContents* source) {
+ return owner_;
+}