diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 18:40:14 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 18:40:14 +0000 |
commit | 6ce7abc518969dfa1699a71ae87fda611012abd9 (patch) | |
tree | aa34ed9e6d1fbf23bc7868b394f7ff032116017c /chrome | |
parent | 9732c032ed9b6664149f03472475d31844a1c8ba (diff) | |
download | chromium_src-6ce7abc518969dfa1699a71ae87fda611012abd9.zip chromium_src-6ce7abc518969dfa1699a71ae87fda611012abd9.tar.gz chromium_src-6ce7abc518969dfa1699a71ae87fda611012abd9.tar.bz2 |
Hide plugins in minimized/hidden windows on the Mac
Watch for window minizing and app hiding so we know when pages aren't visible for reasons other than being in background tabs. Manually hide plugins in non-visible windows, as a temporary workaround for bug 34266.
BUG=30838
TEST=Minimize a window or hide the application while a Flash or Quicktime movie is playing; CPU usage should be the same as if it were in a background tab.
Review URL: http://codereview.chromium.org/563010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37851 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 54 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view.h | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.h | 1 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/test/test_render_view_host.h | 1 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 8 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 14 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 4 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_proxy.cc | 3 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_proxy.h | 1 |
10 files changed, 99 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 64c9f26..aeb5cb6 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -331,6 +331,18 @@ willPositionSheet:(NSWindow*)sheet // Create the bridge for the status bubble. statusBubble_ = new StatusBubbleMac([self window], self); + // Register for application hide/unhide notifications. + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(applicationDidHide:) + name:NSApplicationDidHideNotification + object:nil]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(applicationDidUnhide:) + name:NSApplicationDidUnhideNotification + object:nil]; + // We are done initializing now. initializing_ = NO; } @@ -476,6 +488,48 @@ willPositionSheet:(NSWindow*)sheet } } +// Called when we have been minimized. +- (void)windowDidMiniaturize:(NSNotification *)notification { + // Let the selected RenderWidgetHostView know, so that it can tell plugins. + if (TabContents* contents = browser_->GetSelectedTabContents()) { + if (RenderWidgetHostView* rwhv = contents->render_widget_host_view()) + rwhv->SetWindowVisibility(false); + } +} + +// Called when we have been unminimized. +- (void)windowDidDeminiaturize:(NSNotification *)notification { + // Let the selected RenderWidgetHostView know, so that it can tell plugins. + if (TabContents* contents = browser_->GetSelectedTabContents()) { + if (RenderWidgetHostView* rwhv = contents->render_widget_host_view()) + rwhv->SetWindowVisibility(true); + } +} + +// Called when the application has been hidden. +- (void)applicationDidHide:(NSNotification *)notification { + // Let the selected RenderWidgetHostView know, so that it can tell plugins + // (unless we are minimized, in which case nothing has really changed). + if (![[self window] isMiniaturized]) { + if (TabContents* contents = browser_->GetSelectedTabContents()) { + if (RenderWidgetHostView* rwhv = contents->render_widget_host_view()) + rwhv->SetWindowVisibility(false); + } + } +} + +// Called when the application has been unhidden. +- (void)applicationDidUnhide:(NSNotification *)notification { + // Let the selected RenderWidgetHostView know, so that it can tell plugins + // (unless we are minimized, in which case nothing has really changed). + if (![[self window] isMiniaturized]) { + if (TabContents* contents = browser_->GetSelectedTabContents()) { + if (RenderWidgetHostView* rwhv = contents->render_widget_host_view()) + rwhv->SetWindowVisibility(true); + } + } +} + // Called when the user clicks the zoom button (or selects it from the Window // menu) to determine the "standard size" of the window, based on the content // and other factors. If the current size/location differs nontrivally from the diff --git a/chrome/browser/renderer_host/render_widget_host_view.h b/chrome/browser/renderer_host/render_widget_host_view.h index 2a87291..0a87d3d 100644 --- a/chrome/browser/renderer_host/render_widget_host_view.h +++ b/chrome/browser/renderer_host/render_widget_host_view.h @@ -158,6 +158,14 @@ class RenderWidgetHostView { // Set the view's active state (i.e., tint state of controls). virtual void SetActive(bool active) = 0; + + // Notifies the view that its enclosing window has changed visibility + // (minimized/unminimized, app hidden/unhidden, etc). + // TODO(stuartmorgan): This is a temporary plugin-specific workaround for + // <http://crbug.com/34266>. Once that is fixed, this (and the corresponding + // message and renderer-side handling) can be removed in favor of using + // WasHidden/DidBecomeSelected. + virtual void SetWindowVisibility(bool visible) = 0; #endif #if defined(OS_LINUX) diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h index e38071b..46e9e8a 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.h +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h @@ -109,6 +109,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { virtual gfx::Rect GetWindowRect(); virtual gfx::Rect GetRootWindowRect(); virtual void SetActive(bool active); + virtual void SetWindowVisibility(bool visible); virtual void SetBackground(const SkBitmap& background); void KillSelf(); diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index fcf55eb..62eaa1e 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -491,6 +491,13 @@ void RenderWidgetHostViewMac::SetActive(bool active) { render_widget_host_->SetActive(active); } +void RenderWidgetHostViewMac::SetWindowVisibility(bool visible) { + if (render_widget_host_) { + render_widget_host_->Send(new ViewMsg_SetWindowVisibility( + render_widget_host_->routing_id(), visible)); + } +} + void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { RenderWidgetHostView::SetBackground(background); if (render_widget_host_) diff --git a/chrome/browser/renderer_host/test/test_render_view_host.h b/chrome/browser/renderer_host/test/test_render_view_host.h index ff3727e..7ec1304 100644 --- a/chrome/browser/renderer_host/test/test_render_view_host.h +++ b/chrome/browser/renderer_host/test/test_render_view_host.h @@ -77,6 +77,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostView { virtual gfx::Rect GetWindowRect(); virtual gfx::Rect GetRootWindowRect(); virtual void SetActive(bool active); + virtual void SetWindowVisibility(bool visible) {} #endif #if defined(OS_LINUX) diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 0438f15..1dcef7e 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -376,7 +376,7 @@ IPC_BEGIN_MESSAGES(View) // displaying this host can update their content settings to match. IPC_MESSAGE_CONTROL2(ViewMsg_SetContentSettingsForCurrentHost, std::string /* host */, - ContentSettings /* content_settings */) + ContentSettings /* content_settings */) // Change encoding of page in the renderer. IPC_MESSAGE_ROUTED1(ViewMsg_SetPageEncoding, @@ -753,6 +753,12 @@ IPC_BEGIN_MESSAGES(View) IPC_MESSAGE_ROUTED1(ViewMsg_SetActive, bool /* active */) +#if defined(OS_MACOSX) + // Let the RenderView know its window has changed visibility. + IPC_MESSAGE_ROUTED1(ViewMsg_SetWindowVisibility, + bool /* visibile */) +#endif + // Response message to ViewHostMsg_CreateShared/DedicatedWorker. // Sent when the worker has started. IPC_MESSAGE_ROUTED0(ViewMsg_WorkerCreated) diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index c474e72..0594162 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -574,6 +574,9 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { OnNotifyRendererViewType) IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) +#if defined(OS_MACOSX) + IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) +#endif IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, OnSetEditCommandsForNextKeyEvent) IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode, @@ -3765,6 +3768,17 @@ void RenderView::OnSetActive(bool active) { #endif } +#if defined(OS_MACOSX) +void RenderView::OnSetWindowVisibility(bool visible) { + // Inform plugins that their container has changed visibility. + std::set<WebPluginDelegateProxy*>::iterator plugin_it; + for (plugin_it = plugin_delegates_.begin(); + plugin_it != plugin_delegates_.end(); ++plugin_it) { + (*plugin_it)->SetContainerVisibility(visible); + } +} +#endif // OS_MACOSX + void RenderView::SendExtensionRequest(const std::string& name, const ListValue& args, int request_id, diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 0c5ad52..7545654 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -716,6 +716,10 @@ class RenderView : public RenderWidget, // accordingly, etc.). void OnSetActive(bool active); +#if defined(OS_MACOSX) + void OnSetWindowVisibility(bool visible); +#endif + // Execute custom context menu action. void OnCustomContextMenuAction(unsigned action); diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index da19300..b71798e 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -872,7 +872,8 @@ void WebPluginDelegateProxy::SetContainerVisibility(bool is_visible) { // TODO(stuartmorgan): Split this into two messages, and send location and // focus information with the "became visible" version since the plugins in a // hidden tab will not have been getting live updates. - IPC::Message* msg = new PluginMsg_SetWindowFocus(instance_id_, is_visible); + IPC::Message* msg = new PluginMsg_SetContainerVisibility(instance_id_, + is_visible); // Make sure visibility events are delivered in the right order relative to // sync messages they might interact with (Paint, HandleEvent, etc.). msg->set_unblock(true); diff --git a/chrome/renderer/webplugin_delegate_proxy.h b/chrome/renderer/webplugin_delegate_proxy.h index c0ce498..6a71bdb 100644 --- a/chrome/renderer/webplugin_delegate_proxy.h +++ b/chrome/renderer/webplugin_delegate_proxy.h @@ -73,6 +73,7 @@ class WebPluginDelegateProxy #if defined(OS_MACOSX) virtual void SetWindowFocus(bool window_has_focus); + // Inform the plugin that its container (window/tab) has changed visibility. virtual void SetContainerVisibility(bool is_visible); #endif |