diff options
author | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-07 23:44:00 +0000 |
---|---|---|
committer | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-07 23:44:00 +0000 |
commit | eda238a1f264b36245da55d7f64ae55ebec7666a (patch) | |
tree | de71d2791e9f61cce288f66ff68a821a97475729 | |
parent | 1a39d73e551b07893d3b7cecb3ef3ac4871d105b (diff) | |
download | chromium_src-eda238a1f264b36245da55d7f64ae55ebec7666a.zip chromium_src-eda238a1f264b36245da55d7f64ae55ebec7666a.tar.gz chromium_src-eda238a1f264b36245da55d7f64ae55ebec7666a.tar.bz2 |
Pass result of blockage across content API when new tab blocked. This change allows the proper blockage of foreground tabs created without user-gestures for rel=noreferrer links.
BUG=118317
Review URL: https://chromiumcodereview.appspot.com/10868116
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155535 0039d316-1c4b-4281-b951-d872f2087c98
45 files changed, 174 insertions, 117 deletions
diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc index 5bf226e..6accc45 100644 --- a/chrome/browser/background/background_contents_service.cc +++ b/chrome/browser/background/background_contents_service.cc @@ -612,11 +612,12 @@ void BackgroundContentsService::AddWebContents( WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { Browser* browser = browser::FindLastActiveWithProfile( Profile::FromBrowserContext(new_contents->GetBrowserContext())); if (browser) { chrome::AddWebContents(browser, NULL, new_contents, disposition, - initial_pos, user_gesture); + initial_pos, user_gesture, was_blocked); } } diff --git a/chrome/browser/background/background_contents_service.h b/chrome/browser/background/background_contents_service.h index 8bca22b..e8d462e 100644 --- a/chrome/browser/background/background_contents_service.h +++ b/chrome/browser/background/background_contents_service.h @@ -65,7 +65,8 @@ class BackgroundContentsService : private content::NotificationObserver, virtual void AddWebContents(content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; // Gets the parent application id for the passed BackgroundContents. Returns // an empty string if no parent application found (e.g. passed diff --git a/chrome/browser/component/web_contents_delegate_android/web_contents_delegate_android.cc b/chrome/browser/component/web_contents_delegate_android/web_contents_delegate_android.cc index 6659e2b..a7e44f25 100644 --- a/chrome/browser/component/web_contents_delegate_android/web_contents_delegate_android.cc +++ b/chrome/browser/component/web_contents_delegate_android/web_contents_delegate_android.cc @@ -138,7 +138,8 @@ void WebContentsDelegateAndroid::AddNewContents( WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); bool handled = false; diff --git a/chrome/browser/component/web_contents_delegate_android/web_contents_delegate_android.h b/chrome/browser/component/web_contents_delegate_android/web_contents_delegate_android.h index a542707..06bcc5b 100644 --- a/chrome/browser/component/web_contents_delegate_android/web_contents_delegate_android.h +++ b/chrome/browser/component/web_contents_delegate_android/web_contents_delegate_android.h @@ -70,7 +70,8 @@ class WebContentsDelegateAndroid : public content::WebContentsDelegate { content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void ActivateContents(content::WebContents* contents) OVERRIDE; virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc index acd0e0d..711a48e 100644 --- a/chrome/browser/debugger/devtools_window.cc +++ b/chrome/browser/debugger/devtools_window.cc @@ -581,10 +581,12 @@ void DevToolsWindow::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { if (inspected_tab_) { inspected_tab_->web_contents()->GetDelegate()->AddNewContents( - source, new_contents, disposition, initial_pos, user_gesture); + source, new_contents, disposition, initial_pos, user_gesture, + was_blocked); } } diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h index ef5cc38..2f7bddc 100644 --- a/chrome/browser/debugger/devtools_window.h +++ b/chrome/browser/debugger/devtools_window.h @@ -118,7 +118,8 @@ class DevToolsWindow : private content::NotificationObserver, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void CloseContents(content::WebContents* source) OVERRIDE {} virtual bool PreHandleKeyboardEvent( content::WebContents* source, diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 7e35321..af8c3d2 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -595,7 +595,8 @@ void ExtensionHost::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { // First, if the creating extension view was associated with a tab contents, // use that tab content's delegate. We must be careful here that the // associated tab contents has the same profile as the new tab contents. In @@ -609,9 +610,12 @@ void ExtensionHost::AddNewContents(WebContents* source, if (associated_contents && associated_contents->GetBrowserContext() == new_contents->GetBrowserContext()) { - associated_contents->AddNewContents( - new_contents, disposition, initial_pos, user_gesture); - return; + WebContentsDelegate* delegate = associated_contents->GetDelegate(); + if (delegate) { + delegate->AddNewContents( + associated_contents, new_contents, disposition, initial_pos, + user_gesture, was_blocked); + } } } diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index b2c2430..e93c52bb 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -163,7 +163,8 @@ class ExtensionHost : public content::WebContentsDelegate, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void CloseContents(content::WebContents* contents) OVERRIDE; virtual void OnStartDownload(content::WebContents* source, content::DownloadItem* download) OVERRIDE; diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc index 2edacf3..1ae8bf9 100644 --- a/chrome/browser/notifications/balloon_host.cc +++ b/chrome/browser/notifications/balloon_host.cc @@ -81,12 +81,13 @@ void BalloonHost::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { Browser* browser = browser::FindLastActiveWithProfile( Profile::FromBrowserContext(new_contents->GetBrowserContext())); if (browser) { chrome::AddWebContents(browser, NULL, new_contents, disposition, - initial_pos, user_gesture); + initial_pos, user_gesture, was_blocked); } } diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h index 070c3ac..83dc9cc 100644 --- a/chrome/browser/notifications/balloon_host.h +++ b/chrome/browser/notifications/balloon_host.h @@ -67,7 +67,8 @@ class BalloonHost : public content::WebContentsDelegate, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; // content::WebContentsObserver implementation: virtual void RenderViewCreated( diff --git a/chrome/browser/tab_contents/background_contents.cc b/chrome/browser/tab_contents/background_contents.cc index efa0804..b8aad65 100644 --- a/chrome/browser/tab_contents/background_contents.cc +++ b/chrome/browser/tab_contents/background_contents.cc @@ -98,9 +98,10 @@ void BackgroundContents::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { delegate_->AddWebContents( - new_contents, disposition, initial_pos, user_gesture); + new_contents, disposition, initial_pos, user_gesture, was_blocked); } void BackgroundContents::RenderViewGone(base::TerminationStatus status) { diff --git a/chrome/browser/tab_contents/background_contents.h b/chrome/browser/tab_contents/background_contents.h index 1233f586f..73c7006 100644 --- a/chrome/browser/tab_contents/background_contents.h +++ b/chrome/browser/tab_contents/background_contents.h @@ -30,11 +30,13 @@ class BackgroundContents : public content::WebContentsDelegate, public: // Called by AddNewContents(). Asks the delegate to attach the opened // WebContents to a suitable container (e.g. browser) or to show it if it's - // a popup window. + // a popup window. If |was_blocked| is non-NULL, then |*was_blocked| will be + // set to true if the popup gets blocked, and left unchanged otherwise. virtual void AddWebContents(content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) = 0; + bool user_gesture, + bool* was_blocked) = 0; protected: virtual ~Delegate() {} @@ -57,7 +59,8 @@ class BackgroundContents : public content::WebContentsDelegate, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; // content::WebContentsObserver implementation: virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; diff --git a/chrome/browser/ui/blocked_content/blocked_content_container.cc b/chrome/browser/ui/blocked_content/blocked_content_container.cc index 585a11f4..d17db9e 100644 --- a/chrome/browser/ui/blocked_content/blocked_content_container.cc +++ b/chrome/browser/ui/blocked_content/blocked_content_container.cc @@ -75,11 +75,15 @@ void BlockedContentContainer::LaunchForContents(TabContents* tab_contents) { tab_contents->blocked_content_tab_helper()->set_delegate(NULL); // We needn't call WasShown to change its status because the // WebContents::AddNewContents will do it. - owner_->web_contents()->AddNewContents( - tab_contents->web_contents(), - content.disposition, - content.bounds, - content.user_gesture); + WebContentsDelegate* delegate = owner_->web_contents()->GetDelegate(); + if (delegate) { + delegate->AddNewContents(owner_->web_contents(), + tab_contents->web_contents(), + content.disposition, + content.bounds, + content.user_gesture, + NULL); + } break; } } @@ -120,9 +124,13 @@ void BlockedContentContainer::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_position, - bool user_gesture) { - owner_->web_contents()->AddNewContents( - new_contents, disposition, initial_position, user_gesture); + bool user_gesture, + bool* was_blocked) { + WebContentsDelegate* delegate = owner_->web_contents()->GetDelegate(); + if (delegate) { + delegate->AddNewContents(owner_->web_contents(), new_contents, disposition, + initial_position, user_gesture, was_blocked); + } } void BlockedContentContainer::CloseContents(WebContents* source) { diff --git a/chrome/browser/ui/blocked_content/blocked_content_container.h b/chrome/browser/ui/blocked_content/blocked_content_container.h index f6eb7d8..7b82ab8 100644 --- a/chrome/browser/ui/blocked_content/blocked_content_container.h +++ b/chrome/browser/ui/blocked_content/blocked_content_container.h @@ -62,7 +62,8 @@ class BlockedContentContainer : public BlockedContentTabHelperDelegate, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_position, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; // Removes |source| from our internal list of blocked contents. virtual void CloseContents(content::WebContents* source) OVERRIDE; diff --git a/chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc b/chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc index a92bba0..8d834ed 100644 --- a/chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc +++ b/chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc @@ -19,6 +19,7 @@ #include "content/public/browser/notification_source.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_delegate.h" using content::NavigationEntry; @@ -88,6 +89,7 @@ void BlockedContentTabHelper::AddTabContents(TabContents* new_contents, } void BlockedContentTabHelper::AddPopup(TabContents* new_contents, + WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) { // A page can't spawn popups (or do anything else, either) until its load @@ -109,16 +111,21 @@ void BlockedContentTabHelper::AddPopup(TabContents* new_contents, creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) { - web_contents()->AddNewContents(new_contents->web_contents(), - NEW_POPUP, - initial_pos, - true); // user_gesture + content::WebContentsDelegate* delegate = web_contents()->GetDelegate(); + if (delegate) { + delegate->AddNewContents(web_contents(), + new_contents->web_contents(), + disposition, + initial_pos, + true, // user_gesture + NULL); + } } else { // Call blocked_contents_->AddTabContents with user_gesture == true // so that the contents will not get blocked again. SendNotification(new_contents, true); blocked_contents_->AddTabContents(new_contents, - NEW_POPUP, + disposition, initial_pos, true); // user_gesture tab_contents_->content_settings()->OnContentBlocked( diff --git a/chrome/browser/ui/blocked_content/blocked_content_tab_helper.h b/chrome/browser/ui/blocked_content/blocked_content_tab_helper.h index e317443..9a22669 100644 --- a/chrome/browser/ui/blocked_content/blocked_content_tab_helper.h +++ b/chrome/browser/ui/blocked_content/blocked_content_tab_helper.h @@ -40,6 +40,7 @@ class BlockedContentTabHelper : public content::WebContentsObserver { // Adds the incoming |new_contents| to the |blocked_contents_| container. void AddPopup(TabContents* new_contents, + WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture); diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index ead0d36..dadf61f 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1306,9 +1306,10 @@ void Browser::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { chrome::AddWebContents(this, source, new_contents, disposition, initial_pos, - user_gesture); + user_gesture, was_blocked); } void Browser::ActivateContents(WebContents* contents) { diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index c19365b..b610b6b 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -540,7 +540,8 @@ class Browser : public TabStripModelObserver, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void ActivateContents(content::WebContents* contents) OVERRIDE; virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; diff --git a/chrome/browser/ui/browser_tabstrip.cc b/chrome/browser/ui/browser_tabstrip.cc index a68688d..e6168de 100644 --- a/chrome/browser/ui/browser_tabstrip.cc +++ b/chrome/browser/ui/browser_tabstrip.cc @@ -99,7 +99,8 @@ void AddWebContents(Browser* browser, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { // No code for this yet. DCHECK(disposition != SAVE_TO_DISK); // Can't create a new contents for the current tab - invalid case. @@ -118,23 +119,26 @@ void AddWebContents(Browser* browser, } if (source_tab_contents) { - // Handle blocking of all contents. + // Handle blocking of tabs. if (source_blocked_content->all_contents_blocked()) { - source_blocked_content->AddTabContents(new_tab_contents, - disposition, - initial_pos, - user_gesture); + source_blocked_content->AddTabContents( + new_tab_contents, disposition, initial_pos, user_gesture); + if (was_blocked) + *was_blocked = true; return; } // Handle blocking of popups. - if ((disposition == NEW_POPUP) && !user_gesture && + if ((disposition == NEW_POPUP || disposition == NEW_FOREGROUND_TAB) && + !user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisablePopupBlocking)) { // Unrequested popups from normal pages are constrained unless they're in // the white list. The popup owner will handle checking this. - source_tab_contents->blocked_content_tab_helper()-> - AddPopup(new_tab_contents, initial_pos, user_gesture); + source_blocked_content->AddPopup( + new_tab_contents, disposition, initial_pos, user_gesture); + if (was_blocked) + *was_blocked = true; return; } diff --git a/chrome/browser/ui/browser_tabstrip.h b/chrome/browser/ui/browser_tabstrip.h index ba9906a..f4c6177 100644 --- a/chrome/browser/ui/browser_tabstrip.h +++ b/chrome/browser/ui/browser_tabstrip.h @@ -55,13 +55,15 @@ void AddTab(Browser* browser, // Creates a new tab with the already-created WebContents 'new_contents'. // The window for the added contents will be reparented correctly when this // method returns. If |disposition| is NEW_POPUP, |pos| should hold the -// initial position. +// initial position. If |was_blocked| is non-NULL, then |*was_blocked| will be +// set to true if the popup gets blocked, and left unchanged otherwise. void AddWebContents(Browser* browser, content::WebContents* source_contents, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture); + bool user_gesture, + bool* was__blocked); void CloseWebContents(Browser* browser, content::WebContents* contents); void CloseAllTabs(Browser* browser); diff --git a/chrome/browser/ui/cocoa/web_dialog_window_controller.mm b/chrome/browser/ui/cocoa/web_dialog_window_controller.mm index 2885d19..d24ff34 100644 --- a/chrome/browser/ui/cocoa/web_dialog_window_controller.mm +++ b/chrome/browser/ui/cocoa/web_dialog_window_controller.mm @@ -78,7 +78,8 @@ public: content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; private: @@ -234,13 +235,15 @@ void WebDialogWindowDelegateBridge::AddNewContents( content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { if (delegate_ && delegate_->HandleAddNewContents( source, new_contents, disposition, initial_pos, user_gesture)) { return; } WebDialogWebContentsDelegate::AddNewContents( - source, new_contents, disposition, initial_pos, user_gesture); + source, new_contents, disposition, initial_pos, user_gesture, + was_blocked); } void WebDialogWindowDelegateBridge::LoadingStateChanged( diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc index 89374b5..8ca5ce0 100644 --- a/chrome/browser/ui/extensions/shell_window.cc +++ b/chrome/browser/ui/extensions/shell_window.cc @@ -255,7 +255,8 @@ void ShellWindow::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { DCHECK(source == web_contents_); DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == profile_); @@ -265,7 +266,7 @@ void ShellWindow::AddNewContents(WebContents* source, disposition = disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, - user_gesture); + user_gesture, was_blocked); } void ShellWindow::HandleKeyboardEvent( diff --git a/chrome/browser/ui/extensions/shell_window.h b/chrome/browser/ui/extensions/shell_window.h index b0e592b..235fc5e 100644 --- a/chrome/browser/ui/extensions/shell_window.h +++ b/chrome/browser/ui/extensions/shell_window.h @@ -136,7 +136,8 @@ class ShellWindow : public content::NotificationObserver, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) OVERRIDE; diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc index de2ae3c..88bc22fb 100644 --- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc @@ -196,14 +196,16 @@ void DraggedTabControllerGtk::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { DCHECK(disposition != CURRENT_TAB); // Theoretically could be called while dragging if the page tries to // spawn a window. Route this message back to the browser in most cases. if (drag_data_->GetSourceTabData()->original_delegate_) { drag_data_->GetSourceTabData()->original_delegate_->AddNewContents( - source, new_contents, disposition, initial_pos, user_gesture); + source, new_contents, disposition, initial_pos, user_gesture, + was_blocked); } } diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h index 643cc98c..f7134a1 100644 --- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h +++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h @@ -93,7 +93,8 @@ class DraggedTabControllerGtk : public content::NotificationObserver, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator() OVERRIDE; diff --git a/chrome/browser/ui/gtk/web_dialog_gtk.cc b/chrome/browser/ui/gtk/web_dialog_gtk.cc index 6452c62..330efbf 100644 --- a/chrome/browser/ui/gtk/web_dialog_gtk.cc +++ b/chrome/browser/ui/gtk/web_dialog_gtk.cc @@ -165,13 +165,15 @@ void WebDialogGtk::AddNewContents(content::WebContents* source, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { if (delegate_ && delegate_->HandleAddNewContents( source, new_contents, disposition, initial_pos, user_gesture)) { return; } WebDialogWebContentsDelegate::AddNewContents( - source, new_contents, disposition, initial_pos, user_gesture); + source, new_contents, disposition, initial_pos, user_gesture, + was_blocked); } void WebDialogGtk::LoadingStateChanged(content::WebContents* source) { diff --git a/chrome/browser/ui/gtk/web_dialog_gtk.h b/chrome/browser/ui/gtk/web_dialog_gtk.h index 463cde3..a7de5de 100644 --- a/chrome/browser/ui/gtk/web_dialog_gtk.h +++ b/chrome/browser/ui/gtk/web_dialog_gtk.h @@ -62,7 +62,8 @@ class WebDialogGtk : public ui::WebDialogWebContentsDelegate, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; private: diff --git a/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.cc b/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.cc index 1b26737..771c171 100644 --- a/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.cc +++ b/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.cc @@ -67,7 +67,8 @@ void WebIntentInlineDispositionDelegate::AddNewContents( content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { DCHECK_EQ(source, web_contents_); DCHECK_EQ(Profile::FromBrowserContext(new_contents->GetBrowserContext()), browser_->profile()); @@ -76,7 +77,7 @@ void WebIntentInlineDispositionDelegate::AddNewContents( disposition = disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; chrome::AddWebContents(browser_, NULL, new_contents, disposition, initial_pos, - user_gesture); + user_gesture, was_blocked); } void WebIntentInlineDispositionDelegate::LoadingStateChanged( diff --git a/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h b/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h index 3688ba9..cf91e9d 100644 --- a/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h +++ b/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h @@ -43,7 +43,8 @@ class WebIntentInlineDispositionDelegate content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; virtual void ResizeDueToAutoResize(content::WebContents* source, const gfx::Size& pref_size) OVERRIDE; diff --git a/chrome/browser/ui/panels/panel_host.cc b/chrome/browser/ui/panels/panel_host.cc index 1e3e5c8..3421f64 100644 --- a/chrome/browser/ui/panels/panel_host.cc +++ b/chrome/browser/ui/panels/panel_host.cc @@ -113,7 +113,8 @@ void PanelHost::AddNewContents(content::WebContents* source, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { chrome::NavigateParams navigate_params(profile_, new_contents->GetURL(), content::PAGE_TRANSITION_LINK); // Create a TabContents because the NavigateParams takes a TabContents, diff --git a/chrome/browser/ui/panels/panel_host.h b/chrome/browser/ui/panels/panel_host.h index d153b18..5451ce1 100644 --- a/chrome/browser/ui/panels/panel_host.h +++ b/chrome/browser/ui/panels/panel_host.h @@ -57,7 +57,8 @@ class PanelHost : public content::WebContentsDelegate, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void ActivateContents(content::WebContents* contents) OVERRIDE; virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; diff --git a/chrome/browser/ui/views/external_tab_container_win.cc b/chrome/browser/ui/views/external_tab_container_win.cc index a2b47a7..4753593 100644 --- a/chrome/browser/ui/views/external_tab_container_win.cc +++ b/chrome/browser/ui/views/external_tab_container_win.cc @@ -465,7 +465,8 @@ void ExternalTabContainerWin::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { if (!automation_) { DCHECK(pending_); LOG(ERROR) << "Invalid automation provider. Dropping new contents notify"; diff --git a/chrome/browser/ui/views/external_tab_container_win.h b/chrome/browser/ui/views/external_tab_container_win.h index 74c5b58..66aeb1a 100644 --- a/chrome/browser/ui/views/external_tab_container_win.h +++ b/chrome/browser/ui/views/external_tab_container_win.h @@ -115,7 +115,8 @@ class ExternalTabContainerWin : public ExternalTabContainer, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void CloseContents(content::WebContents* source) OVERRIDE; virtual void MoveContents(content::WebContents* source, const gfx::Rect& pos) OVERRIDE; diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller.cc b/chrome/browser/ui/views/tabs/tab_drag_controller.cc index 2fcdb38..081c414 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller.cc +++ b/chrome/browser/ui/views/tabs/tab_drag_controller.cc @@ -561,14 +561,16 @@ void TabDragController::AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { DCHECK_NE(CURRENT_TAB, disposition); // Theoretically could be called while dragging if the page tries to // spawn a window. Route this message back to the browser in most cases. if (source_tab_drag_data()->original_delegate) { source_tab_drag_data()->original_delegate->AddNewContents( - source, new_contents, disposition, initial_pos, user_gesture); + source, new_contents, disposition, initial_pos, user_gesture, + was_blocked); } } diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller.h b/chrome/browser/ui/views/tabs/tab_drag_controller.h index 9c31a5a..f021a2d 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller.h +++ b/chrome/browser/ui/views/tabs/tab_drag_controller.h @@ -214,7 +214,8 @@ class TabDragController : public content::WebContentsDelegate, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; virtual bool ShouldSuppressDialogs() OVERRIDE; virtual content::JavaScriptDialogCreator* diff --git a/chrome/browser/ui/webui/print_preview/print_preview_ui_unittest.cc b/chrome/browser/ui/webui/print_preview/print_preview_ui_unittest.cc index 0ff0896a..7d65c1a 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_ui_unittest.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_ui_unittest.cc @@ -225,7 +225,7 @@ TEST_F(PrintPreviewUIUnitTest, InitiatorTabGetsFocusOnPrintPreviewTabClose) { WebContentsTester* initiator_tester = WebContentsTester::For(initiator_contents); chrome::AddWebContents(browser(), NULL, initiator_contents, - NEW_FOREGROUND_TAB, gfx::Rect(), false); + NEW_FOREGROUND_TAB, gfx::Rect(), false, NULL); TabContents* initiator_tab = TabContents::FromWebContents(initiator_contents); ASSERT_TRUE(initiator_tab); EXPECT_EQ(2, browser()->tab_count()); diff --git a/chrome/browser/ui/webui/web_dialog_web_contents_delegate_unittest.cc b/chrome/browser/ui/webui/web_dialog_web_contents_delegate_unittest.cc index d331bed..db3e0c8 100644 --- a/chrome/browser/ui/webui/web_dialog_web_contents_delegate_unittest.cc +++ b/chrome/browser/ui/webui/web_dialog_web_contents_delegate_unittest.cc @@ -92,7 +92,7 @@ TEST_F(WebDialogWebContentsDelegateTest, AddNewContentsForegroundTabTest) { WebContents* contents = WebContentsTester::CreateTestWebContents(profile(), NULL); test_web_contents_delegate_->AddNewContents( - NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), false); + NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), false, NULL); // This should create a new foreground tab in the existing browser. EXPECT_EQ(1, browser()->tab_count()); EXPECT_EQ(1U, BrowserList::size()); @@ -107,7 +107,7 @@ TEST_F(WebDialogWebContentsDelegateTest, DetachTest) { NULL, OpenURLParams(GURL(chrome::kAboutBlankURL), Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); test_web_contents_delegate_->AddNewContents(NULL, NULL, NEW_FOREGROUND_TAB, - gfx::Rect(), false); + gfx::Rect(), false, NULL); EXPECT_EQ(0, browser()->tab_count()); EXPECT_EQ(1U, BrowserList::size()); } diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 9f0fe26..c8f3746 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -160,6 +160,7 @@ using content::SessionStorageNamespace; using content::SiteInstance; using content::UserMetricsAction; using content::WebContents; +using content::WebContentsDelegate; using content::WebContentsObserver; using content::WebUI; using content::WebUIController; @@ -1036,17 +1037,6 @@ WebContents* WebContentsImpl::Clone() { return tc; } -void WebContentsImpl::AddNewContents(WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) { - if (!delegate_) - return; - - delegate_->AddNewContents(this, new_contents, disposition, initial_pos, - user_gesture); -} - gfx::NativeView WebContentsImpl::GetContentNativeView() const { return view_->GetContentNativeView(); } @@ -1290,17 +1280,21 @@ void WebContentsImpl::CreateNewWindow( if (params.opener_suppressed) { // When the opener is suppressed, the original renderer cannot access the // new window. As a result, we need to show and navigate the window here. - gfx::Rect initial_pos; - // TODO(cdn) Fix popup white-listing for links that open in a new process. - AddNewContents( - new_contents, params.user_gesture ? params.disposition : NEW_POPUP, - initial_pos, params.user_gesture); - - content::OpenURLParams open_params(params.target_url, content::Referrer(), - CURRENT_TAB, - content::PAGE_TRANSITION_LINK, - true /* is_renderer_initiated */); - new_contents->OpenURL(open_params); + bool was_blocked = false; + if (delegate_) { + gfx::Rect initial_pos; + delegate_->AddNewContents( + this, new_contents, params.disposition, initial_pos, + params.user_gesture, &was_blocked); + } + if (!was_blocked) { + content::OpenURLParams open_params(params.target_url, + content::Referrer(), + CURRENT_TAB, + content::PAGE_TRANSITION_LINK, + true /* is_renderer_initiated */); + new_contents->OpenURL(open_params); + } } } @@ -1340,8 +1334,13 @@ void WebContentsImpl::ShowCreatedWindow(int route_id, const gfx::Rect& initial_pos, bool user_gesture) { WebContentsImpl* contents = GetCreatedWindow(route_id); - if (contents) - AddNewContents(contents, disposition, initial_pos, user_gesture); + if (contents) { + WebContentsDelegate* delegate = GetDelegate(); + if (delegate) { + delegate->AddNewContents( + this, contents, disposition, initial_pos, user_gesture, NULL); + } + } } void WebContentsImpl::ShowCreatedWidget(int route_id, diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index d0d5100..18645b5 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -206,10 +206,6 @@ class CONTENT_EXPORT WebContentsImpl virtual bool NeedToFireBeforeUnload() OVERRIDE; virtual void Stop() OVERRIDE; virtual content::WebContents* Clone() OVERRIDE; - virtual void AddNewContents(content::WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; virtual gfx::NativeView GetContentNativeView() const OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE; diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 2509c4f5..8a443fa 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -221,14 +221,6 @@ class WebContents : public PageNavigator, // heap-allocated pointer is owned by the caller. virtual WebContents* Clone() = 0; - // Window management --------------------------------------------------------- - - // Adds a new tab or window with the given already-created contents. - virtual void AddNewContents(WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) = 0; - // Views and focus ----------------------------------------------------------- // TODO(brettw): Most of these should be removed and the caller should call // the view directly. diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h index b02a1ec..48d90ac 100644 --- a/content/public/browser/web_contents_delegate.h +++ b/content/public/browser/web_contents_delegate.h @@ -100,12 +100,14 @@ class CONTENT_EXPORT WebContentsDelegate { // Creates a new tab with the already-created WebContents 'new_contents'. // The window for the added contents should be reparented correctly when this // method returns. If |disposition| is NEW_POPUP, |pos| should hold the - // initial position. + // initial position. If |was_blocked| is non-NULL, then |*was_blocked| will + // be set to true if the popup gets blocked, and left unchanged otherwise. virtual void AddNewContents(WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) {} + bool user_gesture, + bool* was_blocked) {} // Selects the specified contents, bringing its container to the front. virtual void ActivateContents(WebContents* contents) {} diff --git a/ui/views/controls/webview/web_dialog_view.cc b/ui/views/controls/webview/web_dialog_view.cc index 917eeb4..d4981a9 100644 --- a/ui/views/controls/webview/web_dialog_view.cc +++ b/ui/views/controls/webview/web_dialog_view.cc @@ -281,13 +281,15 @@ void WebDialogView::AddNewContents(content::WebContents* source, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { if (delegate_ && delegate_->HandleAddNewContents( source, new_contents, disposition, initial_pos, user_gesture)) { return; } WebDialogWebContentsDelegate::AddNewContents( - source, new_contents, disposition, initial_pos, user_gesture); + source, new_contents, disposition, initial_pos, user_gesture, + was_blocked); } void WebDialogView::LoadingStateChanged(content::WebContents* source) { diff --git a/ui/views/controls/webview/web_dialog_view.h b/ui/views/controls/webview/web_dialog_view.h index 428dd60..0f7792f 100644 --- a/ui/views/controls/webview/web_dialog_view.h +++ b/ui/views/controls/webview/web_dialog_view.h @@ -106,7 +106,8 @@ class WEBVIEW_EXPORT WebDialogView : public views::ClientView, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; private: diff --git a/ui/web_dialogs/web_dialog_web_contents_delegate.cc b/ui/web_dialogs/web_dialog_web_contents_delegate.cc index 19d97a5..fbed22b 100644 --- a/ui/web_dialogs/web_dialog_web_contents_delegate.cc +++ b/ui/web_dialogs/web_dialog_web_contents_delegate.cc @@ -42,7 +42,8 @@ WebContents* WebDialogWebContentsDelegate::OpenURLFromTab( void WebDialogWebContentsDelegate::AddNewContents( WebContents* source, WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) { + bool user_gesture, + bool* was_blocked) { handler_->AddNewContents(browser_context_, source, new_contents, disposition, initial_pos, user_gesture); } diff --git a/ui/web_dialogs/web_dialog_web_contents_delegate.h b/ui/web_dialogs/web_dialog_web_contents_delegate.h index e7965c9..bbe3ba8 100644 --- a/ui/web_dialogs/web_dialog_web_contents_delegate.h +++ b/ui/web_dialogs/web_dialog_web_contents_delegate.h @@ -61,7 +61,8 @@ class WEB_DIALOGS_EXPORT WebDialogWebContentsDelegate content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) OVERRIDE; + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual bool IsPopupOrPanel( const content::WebContents* source) const OVERRIDE; virtual bool ShouldAddNavigationToHistory( |