diff options
author | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-23 19:38:21 +0000 |
---|---|---|
committer | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-23 19:38:21 +0000 |
commit | 29df0bbe6c78373c3d8c1949ab0e900eee99f727 (patch) | |
tree | 8ad53f3e52ab322346dd15a6550c5acfc9e49e85 | |
parent | 0f3db35be89698ea3f6affd469ec372dbf1fe23b (diff) | |
download | chromium_src-29df0bbe6c78373c3d8c1949ab0e900eee99f727.zip chromium_src-29df0bbe6c78373c3d8c1949ab0e900eee99f727.tar.gz chromium_src-29df0bbe6c78373c3d8c1949ab0e900eee99f727.tar.bz2 |
Making window.focus()/blur() work only when there is a user gesture.
Also making window.focus() select tab if it is not visible.
The RenderViewHost now calls ActivateContent and the new DeactivateContent (instead of using the recently added TabContentsDelegate::Activate/Deactivate methods which have been removed).
BUG=29643,52346
TEST=Create a page with buttons that call window.focus()/blur() directly and with a timeout. When called directly, the calls should succeed (the browser should be activated/deactivated). When called with a timeout, nothing should happen. Also test that a popup calling window.opener.focus() cause the opening tab to become selected when it is not the current tab.
Review URL: http://codereview.chromium.org/3156016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57094 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 66 insertions, 26 deletions
diff --git a/chrome/browser/blocked_popup_container.h b/chrome/browser/blocked_popup_container.h index 04565de..8fbd31a 100644 --- a/chrome/browser/blocked_popup_container.h +++ b/chrome/browser/blocked_popup_container.h @@ -60,8 +60,10 @@ class BlockedPopupContainer : public TabContentsDelegate { const gfx::Rect& initial_position, bool user_gesture); - // Ignore activation requests from the TabContents we're blocking. + // Ignore activation/deactivation requests from the TabContents we're + // blocking. virtual void ActivateContents(TabContents* contents) {} + virtual void DeactivateContents(TabContents* contents) {} // Ignored; BlockedPopupContainer doesn't display a throbber. virtual void LoadingStateChanged(TabContents* source) {} diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index f8c91744..e4a5f8c 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2659,6 +2659,10 @@ void Browser::ActivateContents(TabContents* contents) { window_->Activate(); } +void Browser::DeactivateContents(TabContents* contents) { + window_->Deactivate(); +} + void Browser::LoadingStateChanged(TabContents* source) { window_->UpdateLoadingAnimations(tabstrip_model_.TabsAreLoading()); window_->UpdateTitleBar(); @@ -2802,14 +2806,6 @@ bool Browser::TakeFocus(bool reverse) { return false; } -void Browser::Activate() { - window_->Activate(); -} - -void Browser::Deactivate() { - window_->Deactivate(); -} - bool Browser::IsApplication() const { return (type_ & TYPE_APP) != 0; } diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 5f9a23c..3213795 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -703,6 +703,7 @@ class Browser : public TabStripModelDelegate, const gfx::Rect& initial_pos, bool user_gesture); virtual void ActivateContents(TabContents* contents); + virtual void DeactivateContents(TabContents* contents); virtual void LoadingStateChanged(TabContents* source); virtual void CloseContents(TabContents* source); virtual void MoveContents(TabContents* source, const gfx::Rect& pos); @@ -719,8 +720,6 @@ class Browser : public TabStripModelDelegate, virtual void SetTabContentBlocked(TabContents* contents, bool blocked); virtual void TabContentsFocused(TabContents* tab_content); virtual bool TakeFocus(bool reverse); - virtual void Activate(); - virtual void Deactivate(); virtual bool IsApplication() const; virtual void ConvertContentsToApplication(TabContents* source); virtual bool ShouldDisplayURLField(); diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h index 9c19982..89914a6 100644 --- a/chrome/browser/debugger/devtools_window.h +++ b/chrome/browser/debugger/devtools_window.h @@ -83,6 +83,7 @@ class DevToolsWindow const gfx::Rect& initial_pos, bool user_gesture) {} virtual void ActivateContents(TabContents* contents) {} + virtual void DeactivateContents(TabContents* contents) {} virtual void LoadingStateChanged(TabContents* source) {} virtual void CloseContents(TabContents* source) {} virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} diff --git a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc index 8bec35f..be32f7f 100644 --- a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc +++ b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc @@ -76,6 +76,11 @@ void HtmlDialogTabContentsDelegate::ActivateContents(TabContents* contents) { // this frame and we don't have a TabStripModel. } +void HtmlDialogTabContentsDelegate::DeactivateContents(TabContents* contents) { + // We don't care about this notification (called when a user gesture triggers + // a call to window.blur()). +} + void HtmlDialogTabContentsDelegate::LoadingStateChanged(TabContents* source) { // We don't care about this notification. } diff --git a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h index 1c5cca0..4b68a9f 100644 --- a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h +++ b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h @@ -48,6 +48,7 @@ class HtmlDialogTabContentsDelegate : public TabContentsDelegate { const gfx::Rect& initial_pos, bool user_gesture); virtual void ActivateContents(TabContents* contents); + virtual void DeactivateContents(TabContents* contents); virtual void LoadingStateChanged(TabContents* source); virtual void CloseContents(TabContents* source); virtual bool IsPopup(const TabContents* source) const; diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index 59da688..8e374c8 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -403,6 +403,9 @@ bool ExternalTabContainer::infobars_enabled() { void ExternalTabContainer::ActivateContents(TabContents* contents) { } +void ExternalTabContainer::DeactivateContents(TabContents* contents) { +} + void ExternalTabContainer::LoadingStateChanged(TabContents* source) { } diff --git a/chrome/browser/external_tab_container_win.h b/chrome/browser/external_tab_container_win.h index 443b3e8..591a1ff 100644 --- a/chrome/browser/external_tab_container_win.h +++ b/chrome/browser/external_tab_container_win.h @@ -117,6 +117,7 @@ class ExternalTabContainer : public TabContentsDelegate, const gfx::Rect& initial_pos, bool user_gesture); virtual void ActivateContents(TabContents* contents); + virtual void DeactivateContents(TabContents* contents); virtual void LoadingStateChanged(TabContents* source); virtual void CloseContents(TabContents* source); virtual void MoveContents(TabContents* source, const gfx::Rect& pos); diff --git a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc index 64c314d..551aeb8 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc @@ -146,6 +146,10 @@ void DraggedTabControllerGtk::ActivateContents(TabContents* contents) { // Ignored. } +void DraggedTabControllerGtk::DeactivateContents(TabContents* contents) { + // Ignored. +} + void DraggedTabControllerGtk::LoadingStateChanged(TabContents* source) { // TODO(jhawkins): It would be nice to respond to this message by changing the // screen shot in the dragged tab. diff --git a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h index a9fba9d..b8b8eb3 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h +++ b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h @@ -82,6 +82,7 @@ class DraggedTabControllerGtk : public NotificationObserver, const gfx::Rect& initial_pos, bool user_gesture); virtual void ActivateContents(TabContents* contents); + virtual void DeactivateContents(TabContents* contents); virtual void LoadingStateChanged(TabContents* source); virtual void CloseContents(TabContents* source); virtual void MoveContents(TabContents* source, const gfx::Rect& pos); diff --git a/chrome/browser/sidebar/sidebar_container.h b/chrome/browser/sidebar/sidebar_container.h index 152331d..9d9eb82 100644 --- a/chrome/browser/sidebar/sidebar_container.h +++ b/chrome/browser/sidebar/sidebar_container.h @@ -104,6 +104,7 @@ class SidebarContainer const gfx::Rect& initial_pos, bool user_gesture) {} virtual void ActivateContents(TabContents* contents) {} + virtual void DeactivateContents(TabContents* contents) {} virtual void LoadingStateChanged(TabContents* source) {} virtual void CloseContents(TabContents* source) {} virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} diff --git a/chrome/browser/tab_contents/match_preview.cc b/chrome/browser/tab_contents/match_preview.cc index c8a8c21..4a05856 100644 --- a/chrome/browser/tab_contents/match_preview.cc +++ b/chrome/browser/tab_contents/match_preview.cc @@ -37,6 +37,7 @@ class MatchPreview::TabContentsDelegateImpl : public TabContentsDelegate { virtual void ActivateContents(TabContents* contents) { match_preview_->CommitCurrentPreview(); } + virtual void DeactivateContents(TabContents* contents) {} virtual void LoadingStateChanged(TabContents* source) {} virtual void CloseContents(TabContents* source) {} virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index d12434c..a9e5524 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -815,6 +815,11 @@ void TabContents::Activate() { delegate_->ActivateContents(this); } +void TabContents::Deactivate() { + if (delegate_) + delegate_->DeactivateContents(this); +} + void TabContents::ShowContents() { RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); if (rwhv) diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 4fafde2..c852a14 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -325,6 +325,9 @@ class TabContents : public PageNavigator, // to the foreground if necessary. void Activate(); + // Deactivates this contents by deactivating its containing window. + void Deactivate(); + // TODO(brettw) document these. virtual void ShowContents(); virtual void HideContents(); diff --git a/chrome/browser/tab_contents/tab_contents_delegate.cc b/chrome/browser/tab_contents/tab_contents_delegate.cc index f19422b..aca5fc6 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.cc +++ b/chrome/browser/tab_contents/tab_contents_delegate.cc @@ -70,12 +70,6 @@ bool TabContentsDelegate::TakeFocus(bool reverse) { return false; } -void TabContentsDelegate::Activate() { -} - -void TabContentsDelegate::Deactivate(){ -} - void TabContentsDelegate::SetTabContentBlocked( TabContents* contents, bool blocked) { } diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index 2a31508..921c9a7 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -68,6 +68,10 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { // Selects the specified contents, bringing its container to the front. virtual void ActivateContents(TabContents* contents) = 0; + // Deactivates the specified contents by deactivating its container and + // potentialy moving it to the back of the Z order. + virtual void DeactivateContents(TabContents* contents) = 0; + // Notifies the delegate that this contents is starting or is done loading // some resource. The delegate should use this notification to represent // loading feedback. See TabContents::is_loading() @@ -179,11 +183,6 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { // this. Returns true if the delegate successfully handled it. virtual bool TakeFocus(bool reverse); - // Called by WebKit to notify that the page requested the tab hosting window - // to be activated/deactivated (by calling window.focus()/blur()). - virtual void Activate(); - virtual void Deactivate(); - // Changes the blocked state of the tab at |index|. TabContents are // considered blocked while displaying a tab modal dialog. During that time // renderer host will ignore any UI interaction within TabContent outside of diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/chrome/browser/tab_contents/tab_contents_view.cc index c08d1b7..9c369d0 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/chrome/browser/tab_contents/tab_contents_view.cc @@ -72,11 +72,11 @@ void TabContentsView::ShowCreatedWidget(int route_id, } void TabContentsView::Activate() { - tab_contents_->delegate()->Activate(); + tab_contents_->Activate(); } void TabContentsView::Deactivate() { - tab_contents_->delegate()->Deactivate(); + tab_contents_->Deactivate(); } void TabContentsView::ShowCreatedFullscreenWidget(int route_id) { diff --git a/chrome/browser/views/app_launcher.h b/chrome/browser/views/app_launcher.h index 71038e3..2f99ec8 100644 --- a/chrome/browser/views/app_launcher.h +++ b/chrome/browser/views/app_launcher.h @@ -86,6 +86,7 @@ class AppLauncher : public AnimationDelegate, const gfx::Rect& initial_pos, bool user_gesture); virtual void ActivateContents(TabContents* contents) {} + virtual void DeactivateContents(TabContents* contents) {} virtual void LoadingStateChanged(TabContents* source) {} virtual void CloseContents(TabContents* source) {} virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc index 8ee4259..b0dc9e3 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/views/tabs/dragged_tab_controller.cc @@ -429,6 +429,10 @@ void DraggedTabController::ActivateContents(TabContents* contents) { // Ignored. } +void DraggedTabController::DeactivateContents(TabContents* contents) { + // Ignored. +} + void DraggedTabController::LoadingStateChanged(TabContents* source) { // It would be nice to respond to this message by changing the // screen shot in the dragged tab. diff --git a/chrome/browser/views/tabs/dragged_tab_controller.h b/chrome/browser/views/tabs/dragged_tab_controller.h index 4c2c66d..5c9c619 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.h +++ b/chrome/browser/views/tabs/dragged_tab_controller.h @@ -104,6 +104,7 @@ class DraggedTabController : public TabContentsDelegate, const gfx::Rect& initial_pos, bool user_gesture); virtual void ActivateContents(TabContents* contents); + virtual void DeactivateContents(TabContents* contents); virtual void LoadingStateChanged(TabContents* source); virtual void CloseContents(TabContents* source); virtual void MoveContents(TabContents* source, const gfx::Rect& pos); diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 2e66fc7..6feb581 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -2222,6 +2222,24 @@ void RenderView::didAcceptAutocompleteSuggestion( // WebKit::WebWidgetClient ---------------------------------------------------- +void RenderView::didFocus() { + // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed + // we won't have to test for user gesture anymore and we can + // move that code back to render_widget.cc + if (webview() && webview()->mainFrame() && + webview()->mainFrame()->isProcessingUserGesture()) { + Send(new ViewHostMsg_Focus(routing_id_)); + } +} + +void RenderView::didBlur() { + // TODO(jcivelli): see TODO above in didFocus(). + if (webview() && webview()->mainFrame() && + webview()->mainFrame()->isProcessingUserGesture()) { + Send(new ViewHostMsg_Blur(routing_id_)); + } +} + // We are supposed to get a single call to Show for a newly created RenderView // that was created via RenderView::CreateWebView. So, we wait until this // point to dispatch the ShowView message. diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 7000d2a..29a5430 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -310,6 +310,8 @@ class RenderView : public RenderWidget, // WebKit::WebWidgetClient implementation ------------------------------------ // Most methods are handled by RenderWidget. + virtual void didFocus(); + virtual void didBlur(); virtual void show(WebKit::WebNavigationPolicy policy); virtual void closeWidgetSoon(); virtual void runModal(); diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc index 7b14ccd..9111391 100644 --- a/chrome/renderer/render_widget.cc +++ b/chrome/renderer/render_widget.cc @@ -655,11 +655,9 @@ void RenderWidget::show(WebNavigationPolicy) { } void RenderWidget::didFocus() { - Send(new ViewHostMsg_Focus(routing_id_)); } void RenderWidget::didBlur() { - Send(new ViewHostMsg_Blur(routing_id_)); } void RenderWidget::DoDeferredClose() { |