summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordominich@chromium.org <dominich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-13 20:05:14 +0000
committerdominich@chromium.org <dominich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-13 20:05:14 +0000
commitbbbe5d7dd70dabe0d728e789326879e02f63d040 (patch)
treebd7fe778d2b05c603544c0681a1e5db71a08a62d
parent6f6a5c5fcf68ff9715593153762f0f59a0c9ea14 (diff)
downloadchromium_src-bbbe5d7dd70dabe0d728e789326879e02f63d040.zip
chromium_src-bbbe5d7dd70dabe0d728e789326879e02f63d040.tar.gz
chromium_src-bbbe5d7dd70dabe0d728e789326879e02f63d040.tar.bz2
Block the creation of a new window when prerendering.
BUG=none TEST=PrerenderBrowserTest.PrerenderPopup Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=84922 Review URL: http://codereview.chromium.org/6955003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85308 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/prerender/prerender_contents.cc5
-rw-r--r--chrome/browser/prerender/prerender_manager.cc2
-rw-r--r--chrome/browser/tab_contents/render_view_host_delegate_helper.cc17
-rw-r--r--content/browser/tab_contents/tab_contents_view.cc5
-rw-r--r--content/common/notification_type.h6
5 files changed, 30 insertions, 5 deletions
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc
index 2f2ebd0..bdbd6b9 100644
--- a/chrome/browser/prerender/prerender_contents.cc
+++ b/chrome/browser/prerender/prerender_contents.cc
@@ -287,7 +287,8 @@ void PrerenderContents::StartPrerendering(
Source<RenderViewHostDelegate>(GetRenderViewHostDelegate()));
// Register for new windows from any source.
- notification_registrar_.Add(this, NotificationType::CREATING_NEW_WINDOW,
+ notification_registrar_.Add(this,
+ NotificationType::CREATING_NEW_WINDOW_CANCELLED,
Source<TabContents>(new_contents));
DCHECK(load_start_time_.is_null());
@@ -502,7 +503,7 @@ void PrerenderContents::Observe(NotificationType type,
break;
}
- case NotificationType::CREATING_NEW_WINDOW: {
+ case NotificationType::CREATING_NEW_WINDOW_CANCELLED: {
if (prerender_contents_.get()) {
CHECK(Source<TabContents>(source).ptr() ==
prerender_contents_->tab_contents());
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index a929b7b..8c0d2d0 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -550,7 +550,6 @@ bool PrerenderManager::MaybeUsePreloadedPage(TabContents* tab_contents,
new_tab_contents->controller().CopyStateFromAndPrune(
&old_tab_contents->controller(),
false);
-
old_tab_contents->delegate()->SwapTabContents(old_tab_contents,
new_tab_contents);
@@ -821,6 +820,7 @@ void PrerenderManager::DeleteOldTabContents() {
while (!old_tab_contents_list_.empty()) {
TabContentsWrapper* tab_contents = old_tab_contents_list_.front();
old_tab_contents_list_.pop_front();
+ // TODO(dominich): should we use Instant Unload Handler here?
delete tab_contents;
}
MaybeStopSchedulingPeriodicCleanups();
diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
index 57c3ed8..dfe0de1 100644
--- a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
+++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/browser/user_style_sheet_watcher.h"
@@ -104,13 +105,23 @@ TabContents* RenderViewHostDelegateViewHelper::CreateNewWindow(
}
}
+ TabContents* base_tab_contents = opener->GetAsTabContents();
+
+ // Do not create the new TabContents if the opener is a prerender TabContents.
+ prerender::PrerenderManager* prerender_manager =
+ profile->GetPrerenderManager();
+ if (prerender_manager &&
+ prerender_manager->IsTabContentsPrerendering(base_tab_contents)) {
+ return NULL;
+ }
+
// Create the new web contents. This will automatically create the new
// TabContentsView. In the future, we may want to create the view separately.
TabContents* new_contents =
new TabContents(profile,
site,
route_id,
- opener->GetAsTabContents(),
+ base_tab_contents,
NULL);
new_contents->set_opener_web_ui_type(webui_type);
TabContentsView* new_view = new_contents->view();
@@ -150,8 +161,10 @@ RenderViewHostDelegateViewHelper::CreateNewFullscreenWidget(
TabContents* RenderViewHostDelegateViewHelper::GetCreatedWindow(int route_id) {
PendingContents::iterator iter = pending_contents_.find(route_id);
+
+ // Certain systems can block the creation of new windows. If we didn't succeed
+ // in creating one, just return NULL.
if (iter == pending_contents_.end()) {
- DCHECK(false);
return NULL;
}
diff --git a/content/browser/tab_contents/tab_contents_view.cc b/content/browser/tab_contents/tab_contents_view.cc
index 79ee406..4ea5d9b 100644
--- a/content/browser/tab_contents/tab_contents_view.cc
+++ b/content/browser/tab_contents/tab_contents_view.cc
@@ -50,6 +50,11 @@ void TabContentsView::CreateNewWindow(
if (tab_contents_->delegate())
tab_contents_->delegate()->TabContentsCreated(new_contents);
+ } else {
+ NotificationService::current()->Notify(
+ NotificationType::CREATING_NEW_WINDOW_CANCELLED,
+ Source<TabContents>(tab_contents_),
+ Details<const ViewHostMsg_CreateWindow_Params>(&params));
}
}
diff --git a/content/common/notification_type.h b/content/common/notification_type.h
index c7e4d6a..7f57c50 100644
--- a/content/common/notification_type.h
+++ b/content/common/notification_type.h
@@ -131,6 +131,12 @@ class NotificationType {
// ViewHostMsg_CreateWindow_Params object are provided.
CREATING_NEW_WINDOW,
+ // A new window was requested but was not created. The source will be a
+ // Source<TabContents> corresponding to the tab the request originated from.
+ // Details are the ViewHostMsg_CreateWindow_Params object that were used in
+ // the request.
+ CREATING_NEW_WINDOW_CANCELLED,
+
// SSL ---------------------------------------------------------------------
// Updating the SSL security indicators (the lock icon and such) proceeds