diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-01 21:23:43 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-01 21:23:43 +0000 |
commit | 941e455373dbbe837fe2e82d139af4dec1d35ddb (patch) | |
tree | 07cfc55341b2e0a62d38f821e0ca423db7f146ce /chrome | |
parent | b51cda7cb0bddadb1f4cca4c18eb27313300aa21 (diff) | |
download | chromium_src-941e455373dbbe837fe2e82d139af4dec1d35ddb.zip chromium_src-941e455373dbbe837fe2e82d139af4dec1d35ddb.tar.gz chromium_src-941e455373dbbe837fe2e82d139af4dec1d35ddb.tar.bz2 |
Add tab switch notification to the Mac plugin plumbing.
Using the new notification:
- Update plugin clip rect when it's not in a visible tab.
- Update plugin idle event rate when it's not in a visible tab.
- Switch the unfocus-on-tab-switch event to be based on the this new notification, instead of a browser-level broadcast.
Related changes:
- Stop sending redundant focus events to plugins.
- Send window activation to Carbon event plugins too, not just Cocoa.
- Now that plugins are getting window and tab de-focus events directly, remove the older hack to force all plugins to lose focus any window or tab loses focus.
BUG=29371, 32229, 30838
TEST=Flash should still only register keystrokes when it is in the active window+tab. Plugins in background tabs should use less CPU.
Review URL: http://codereview.chromium.org/548224
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 28 | ||||
-rw-r--r-- | chrome/common/plugin_messages_internal.h | 12 | ||||
-rw-r--r-- | chrome/plugin/plugin_thread.cc | 5 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.cc | 8 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.h | 1 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 24 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 4 | ||||
-rw-r--r-- | chrome/renderer/render_widget.h | 4 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_proxy.cc | 18 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_proxy.h | 1 |
10 files changed, 66 insertions, 39 deletions
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 382fafb..fcf55eb 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -51,26 +51,6 @@ namespace { // Maximum number of characters we allow in a tooltip. const size_t kMaxTooltipLength = 1024; -class NotifyPluginProcessHostTask : public Task { - public: - NotifyPluginProcessHostTask(uint32 process_id, uint32 instance_id) - : process_id_(process_id), instance_id_(instance_id) { } - - private: - void Run() { - for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); - !iter.Done(); ++iter) { - PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); - uint32 plugin_pid = plugin->handle(); - uint32 instance = (plugin_pid == process_id_) ? instance_id_ : 0; - plugin->Send(new PluginProcessMsg_PluginFocusNotify(instance)); - } - } - - uint32 process_id_; - uint32 instance_id_; -}; - } // RenderWidgetHostView -------------------------------------------------------- @@ -157,10 +137,6 @@ void RenderWidgetHostViewMac::WasHidden() { // everything again when we become selected again. is_hidden_ = true; - // tell any plugins that thought they had the focus that they do not now. - ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, - new NotifyPluginProcessHostTask(0, 0)); - // If we have a renderer, then inform it that we are being hidden so it can // reduce its resource utilization. render_widget_host_->WasHidden(); @@ -513,10 +489,6 @@ gfx::Rect RenderWidgetHostViewMac::GetRootWindowRect() { void RenderWidgetHostViewMac::SetActive(bool active) { if (render_widget_host_) render_widget_host_->SetActive(active); - if (!active) - // tell any plugins that thought they had the focus that they do not now. - ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, - new NotifyPluginProcessHostTask(0, 0)); } void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { diff --git a/chrome/common/plugin_messages_internal.h b/chrome/common/plugin_messages_internal.h index 7c10168..b1af5b0 100644 --- a/chrome/common/plugin_messages_internal.h +++ b/chrome/common/plugin_messages_internal.h @@ -49,9 +49,8 @@ IPC_BEGIN_MESSAGES(PluginProcess) #if defined(OS_MACOSX) // Notifies a plugin process that keyboard focus has changed. If another - // plugin instance has received focus, the process and instance IDs are - // passed as parameters; if focus has been taken away from a plugin, 0 is - // passed for both parameters. + // plugin instance has received focus, the instance IDs is passed as a + // parameter; if focus has been taken away from a plugin, 0 is passed. IPC_MESSAGE_CONTROL1(PluginProcessMsg_PluginFocusNotify, uint32 /* instance ID */) #endif @@ -226,8 +225,11 @@ IPC_BEGIN_MESSAGES(Plugin) WebCursor /* cursor type*/) #if defined(OS_MACOSX) - IPC_SYNC_MESSAGE_ROUTED1_0(PluginMsg_SetWindowFocus, - bool /* has_focus */) + IPC_MESSAGE_ROUTED1(PluginMsg_SetWindowFocus, + bool /* has_focus */) + + IPC_MESSAGE_ROUTED1(PluginMsg_SetContainerVisibility, + bool /* is_visible */) #endif IPC_SYNC_MESSAGE_ROUTED2_0(PluginMsg_WillSendRequest, diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc index fb02ac5..0a9ef12 100644 --- a/chrome/plugin/plugin_thread.cc +++ b/chrome/plugin/plugin_thread.cc @@ -149,14 +149,15 @@ void PluginThread::OnPluginMessage(const std::vector<unsigned char> &data) { #if defined(OS_MACOSX) void PluginThread::OnPluginFocusNotify(uint32 instance_id) { - WebPluginDelegateImpl* instance = + WebPluginDelegateImpl* focused_instance = reinterpret_cast<WebPluginDelegateImpl*>(instance_id); std::set<WebPluginDelegateImpl*> active_delegates = WebPluginDelegateImpl::GetActiveDelegates(); for (std::set<WebPluginDelegateImpl*>::iterator iter = active_delegates.begin(); iter != active_delegates.end(); iter++) { - (*iter)->FocusNotify(instance); + WebPluginDelegateImpl* instance = *iter; + instance->FocusChanged(instance == focused_instance); } } #endif diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index 253d7cf..cf6e842 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -123,6 +123,8 @@ void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { OnSendJavaScriptStream) #if defined(OS_MACOSX) IPC_MESSAGE_HANDLER(PluginMsg_SetWindowFocus, OnSetWindowFocus) + IPC_MESSAGE_HANDLER(PluginMsg_SetContainerVisibility, + OnSetContainerVisibility) #endif IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveManualResponse, OnDidReceiveManualResponse) @@ -338,7 +340,11 @@ void WebPluginDelegateStub::OnSendJavaScriptStream(const GURL& url, void WebPluginDelegateStub::OnSetWindowFocus(bool has_focus) { delegate_->SetWindowHasFocus(has_focus); } -#endif + +void WebPluginDelegateStub::OnSetContainerVisibility(bool is_visible) { + delegate_->SetContainerVisibility(is_visible); +} +#endif // OS_MACOSX void WebPluginDelegateStub::OnDidReceiveManualResponse( const GURL& url, diff --git a/chrome/plugin/webplugin_delegate_stub.h b/chrome/plugin/webplugin_delegate_stub.h index 5728fdd..b783832 100644 --- a/chrome/plugin/webplugin_delegate_stub.h +++ b/chrome/plugin/webplugin_delegate_stub.h @@ -80,6 +80,7 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, #if defined(OS_MACOSX) void OnSetWindowFocus(bool has_focus); + void OnSetContainerVisibility(bool is_visible); #endif void OnDidReceiveManualResponse( diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 388d934..e959f14 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -4179,6 +4179,30 @@ void RenderView::DidHandleKeyEvent() { edit_commands_.clear(); } +#if defined(OS_MACOSX) +void RenderView::OnWasHidden() { + RenderWidget::OnWasHidden(); + + // Inform plugins that their container is no longer visible. + std::set<WebPluginDelegateProxy*>::iterator plugin_it; + for (plugin_it = plugin_delegates_.begin(); + plugin_it != plugin_delegates_.end(); ++plugin_it) { + (*plugin_it)->SetContainerVisibility(false); + } +} + +void RenderView::OnWasRestored(bool needs_repainting) { + RenderWidget::OnWasRestored(needs_repainting); + + // Inform plugins that their container is now visible. + std::set<WebPluginDelegateProxy*>::iterator plugin_it; + for (plugin_it = plugin_delegates_.begin(); + plugin_it != plugin_delegates_.end(); ++plugin_it) { + (*plugin_it)->SetContainerVisibility(true); + } +} +#endif // OS_MACOSX + void RenderView::EnsureDocumentTag() { // TODO(darin): There's actually no reason for this to be here. We should // have the browser side manage the document tag. diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 25d598f..dbf4440 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -476,6 +476,10 @@ class RenderView : public RenderWidget, const gfx::Rect& resizer_rect); virtual void DidPaint(); virtual void DidHandleKeyEvent(); +#if OS_MACOSX + virtual void OnWasHidden(); + virtual void OnWasRestored(bool needs_repainting); +#endif private: // For unit tests. diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h index 4cf033e..86f2a17 100644 --- a/chrome/renderer/render_widget.h +++ b/chrome/renderer/render_widget.h @@ -140,8 +140,8 @@ class RenderWidget : public IPC::Channel::Listener, void OnCreatingNewAck(gfx::NativeViewId parent); virtual void OnResize(const gfx::Size& new_size, const gfx::Rect& resizer_rect); - void OnWasHidden(); - void OnWasRestored(bool needs_repainting); + virtual void OnWasHidden(); + virtual void OnWasRestored(bool needs_repainting); void OnUpdateRectAck(); void OnRequestMoveAck(); void OnHandleInputEvent(const IPC::Message& message); diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index 94ddc2a..da19300 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -860,7 +860,23 @@ int WebPluginDelegateProxy::GetProcessId() { #if defined(OS_MACOSX) void WebPluginDelegateProxy::SetWindowFocus(bool window_has_focus) { - Send(new PluginMsg_SetWindowFocus(instance_id_, window_has_focus)); + IPC::Message* msg = new PluginMsg_SetWindowFocus(instance_id_, + window_has_focus); + // 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); + Send(msg); +} + +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); + // 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); + Send(msg); } #endif // OS_MACOSX diff --git a/chrome/renderer/webplugin_delegate_proxy.h b/chrome/renderer/webplugin_delegate_proxy.h index 7df5838..c0ce498 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); + virtual void SetContainerVisibility(bool is_visible); #endif // IPC::Channel::Listener implementation: |