summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-04 20:21:13 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-04 20:21:13 +0000
commit204f1df524af03fa30c20b9d57c4c89ce0162b42 (patch)
treef0831574bacacd626ea124ec01cd2cd0e922a4e1
parent8f104af0562fd65b427ebbb08cd98ad0caa14f5c (diff)
downloadchromium_src-204f1df524af03fa30c20b9d57c4c89ce0162b42.zip
chromium_src-204f1df524af03fa30c20b9d57c4c89ce0162b42.tar.gz
chromium_src-204f1df524af03fa30c20b9d57c4c89ce0162b42.tar.bz2
Hook up page visibility to the View info for a plugin.
TEST=manual (run audio example and switch tab visibility) BUG= Review URL: http://codereview.chromium.org/9022016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116370 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.cc11
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.h4
-rw-r--r--content/renderer/render_view_impl.cc10
-rw-r--r--content/renderer/render_widget.h3
-rw-r--r--ppapi/examples/audio/audio.cc16
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/upcall.h88
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc4
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h1
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h3
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc10
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h3
11 files changed, 103 insertions, 50 deletions
diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc
index 0a15278..f69efe4 100644
--- a/content/renderer/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper_plugin_delegate_impl.cc
@@ -1349,6 +1349,13 @@ void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) {
(*i)->SetContentAreaFocus(has_focus);
}
+void PepperPluginDelegateImpl::PageVisibilityChanged(bool is_visible) {
+ for (std::set<webkit::ppapi::PluginInstance*>::iterator i =
+ active_instances_.begin();
+ i != active_instances_.end(); ++i)
+ (*i)->PageVisibilityChanged(is_visible);
+}
+
bool PepperPluginDelegateImpl::IsPluginFocused() const {
return focused_plugin_ != NULL;
}
@@ -2028,6 +2035,10 @@ bool PepperPluginDelegateImpl::IsInFullscreenMode() {
return render_view_->is_fullscreen();
}
+bool PepperPluginDelegateImpl::IsPageVisible() const {
+ return !render_view_->is_hidden();
+}
+
bool PepperPluginDelegateImpl::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PepperPluginDelegateImpl, message)
diff --git a/content/renderer/pepper_plugin_delegate_impl.h b/content/renderer/pepper_plugin_delegate_impl.h
index fc2e357..2ef8fb7 100644
--- a/content/renderer/pepper_plugin_delegate_impl.h
+++ b/content/renderer/pepper_plugin_delegate_impl.h
@@ -174,6 +174,9 @@ class PepperPluginDelegateImpl
// notifies all of the plugins.
void OnSetFocus(bool has_focus);
+ // Notification that the page visibility has changed. The default is visible.
+ void PageVisibilityChanged(bool is_visible);
+
// IME status.
bool IsPluginFocused() const;
gfx::Rect GetCaretBounds() const;
@@ -382,6 +385,7 @@ class PepperPluginDelegateImpl
virtual void DidReceiveMouseEvent(
webkit::ppapi::PluginInstance* instance) OVERRIDE;
virtual bool IsInFullscreenMode() OVERRIDE;
+ virtual bool IsPageVisible() const OVERRIDE;
// RenderViewObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 80f0852..515ef64 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -4309,8 +4309,11 @@ void RenderViewImpl::OnWasHidden() {
webview()->setVisibilityState(visibilityState(), false);
}
+ // Inform PPAPI plugins that their page is no longer visible.
+ pepper_delegate_.PageVisibilityChanged(false);
+
#if defined(OS_MACOSX)
- // Inform plugins that their container is no longer visible.
+ // Inform NPAPI 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) {
@@ -4328,8 +4331,11 @@ void RenderViewImpl::OnWasRestored(bool needs_repainting) {
webview()->setVisibilityState(visibilityState(), false);
}
+ // Inform PPAPI plugins that their page is visible.
+ pepper_delegate_.PageVisibilityChanged(true);
+
#if defined(OS_MACOSX)
- // Inform plugins that their container is now visible.
+ // Inform NPAPI 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) {
diff --git a/content/renderer/render_widget.h b/content/renderer/render_widget.h
index 5dc7962..d9c9535 100644
--- a/content/renderer/render_widget.h
+++ b/content/renderer/render_widget.h
@@ -98,6 +98,7 @@ class CONTENT_EXPORT RenderWidget
gfx::Size size() const { return size_; }
bool has_focus() const { return has_focus_; }
bool is_fullscreen() const { return is_fullscreen_; }
+ bool is_hidden() const { return is_hidden_; }
// IPC::Channel::Listener
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
@@ -273,8 +274,6 @@ class CONTENT_EXPORT RenderWidget
// state.
void SetHidden(bool hidden);
- bool is_hidden() const { return is_hidden_; }
-
void WillToggleFullscreen();
void DidToggleFullscreen();
diff --git a/ppapi/examples/audio/audio.cc b/ppapi/examples/audio/audio.cc
index ca7ff88..2c01faf 100644
--- a/ppapi/examples/audio/audio.cc
+++ b/ppapi/examples/audio/audio.cc
@@ -19,6 +19,7 @@
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/view.h"
// Separate left and right frequency to make sure we didn't swap L & R.
// Sounds pretty horrible, though...
@@ -35,6 +36,7 @@ class MyInstance : public pp::Instance {
public:
explicit MyInstance(PP_Instance instance)
: pp::Instance(instance),
+ visible_(false),
sample_rate_(kDefaultSampleRate),
sample_count_(0),
audio_wave_l_(0.0),
@@ -60,6 +62,12 @@ class MyInstance : public pp::Instance {
return audio_.StartPlayback();
}
+ virtual void DidChangeView(const pp::View& view) {
+ // The frequency will change depending on whether the page is in the
+ // foreground or background.
+ visible_ = view.IsPageVisible();
+ }
+
private:
static void SineWaveCallbackTrampoline(void* samples,
uint32_t num_bytes,
@@ -68,8 +76,10 @@ class MyInstance : public pp::Instance {
}
void SineWaveCallback(void* samples, uint32_t num_bytes) {
- double delta_l = 2.0 * M_PI * kLeftFrequency / sample_rate_;
- double delta_r = 2.0 * M_PI * kRightFrequency / sample_rate_;
+ double delta_l = 2.0 * M_PI * kLeftFrequency / sample_rate_ /
+ (visible_ ? 1 : 2);
+ double delta_r = 2.0 * M_PI * kRightFrequency / sample_rate_ /
+ (visible_ ? 1 : 2);
// Use per channel audio wave value to avoid clicks on buffer boundries.
double wave_l = audio_wave_l_;
@@ -92,6 +102,8 @@ class MyInstance : public pp::Instance {
audio_wave_r_ = wave_r;
}
+ bool visible_;
+
PP_AudioSampleRate sample_rate_;
uint32_t sample_count_;
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/upcall.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/upcall.h
index 175aead..27acffd 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/upcall.h
+++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/upcall.h
@@ -1,44 +1,44 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
-//
-// Automatically generated code. See srpcgen.py
-//
-// NaCl Simple Remote Procedure Call interface abstractions.
-
-#ifndef GEN_PPAPI_PROXY_UPCALL_H_
-#define GEN_PPAPI_PROXY_UPCALL_H_
-
-#ifndef __native_client__
-#include "native_client/src/include/portability.h"
-#endif // __native_client__
-#include "native_client/src/shared/srpc/nacl_srpc.h"
-#include "ppapi/c/pp_instance.h"
-#include "ppapi/c/pp_module.h"
-#include "ppapi/c/pp_resource.h"
-
-class PppUpcallRpcServer {
- public:
- static void PPB_Core_CallOnMainThread(
- NaClSrpcRpc* rpc,
- NaClSrpcClosure* done,
- int32_t delay_in_milliseconds,
- int32_t callback_id,
- int32_t result);
-
- private:
- PppUpcallRpcServer();
- PppUpcallRpcServer(const PppUpcallRpcServer&);
- void operator=(const PppUpcallRpcServer);
-}; // class PppUpcallRpcServer
-
-class PpbUpcalls {
- public:
- static NaClSrpcHandlerDesc srpc_methods[];
-}; // class PpbUpcalls
-
-
-#endif // GEN_PPAPI_PROXY_UPCALL_H_
-
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
+//
+// Automatically generated code. See srpcgen.py
+//
+// NaCl Simple Remote Procedure Call interface abstractions.
+
+#ifndef GEN_PPAPI_PROXY_UPCALL_H_
+#define GEN_PPAPI_PROXY_UPCALL_H_
+
+#ifndef __native_client__
+#include "native_client/src/include/portability.h"
+#endif // __native_client__
+#include "native_client/src/shared/srpc/nacl_srpc.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_resource.h"
+
+class PppUpcallRpcServer {
+ public:
+ static void PPB_Core_CallOnMainThread(
+ NaClSrpcRpc* rpc,
+ NaClSrpcClosure* done,
+ int32_t delay_in_milliseconds,
+ int32_t callback_id,
+ int32_t result);
+
+ private:
+ PppUpcallRpcServer();
+ PppUpcallRpcServer(const PppUpcallRpcServer&);
+ void operator=(const PppUpcallRpcServer);
+}; // class PppUpcallRpcServer
+
+class PpbUpcalls {
+ public:
+ static NaClSrpcHandlerDesc srpc_methods[];
+}; // class PpbUpcalls
+
+
+#endif // GEN_PPAPI_PROXY_UPCALL_H_
+
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index 92093a0..52d59bc 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -364,5 +364,9 @@ bool MockPluginDelegate::IsInFullscreenMode() {
return false;
}
+bool MockPluginDelegate::IsPageVisible() const {
+ return true;
+}
+
} // namespace ppapi
} // namespace webkit
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index b1d3158..7fe0155 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -154,6 +154,7 @@ class MockPluginDelegate : public PluginDelegate {
const WebKit::WebCursorInfo& cursor);
virtual void DidReceiveMouseEvent(PluginInstance* instance);
virtual bool IsInFullscreenMode();
+ virtual bool IsPageVisible() const;
};
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index c45704e..af93ec8 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -514,6 +514,9 @@ class PluginDelegate {
// Determines if the browser entered fullscreen mode.
virtual bool IsInFullscreenMode() = 0;
+
+ // Returns true if the containing page is visible.
+ virtual bool IsPageVisible() const = 0;
};
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index c5c52ce..8f1ff5d 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -314,6 +314,8 @@ PluginInstance::PluginInstance(
module_->InstanceCreated(this);
delegate_->InstanceCreated(this);
message_channel_.reset(new MessageChannel(this));
+
+ view_data_.is_page_visible = delegate->IsPageVisible();
}
PluginInstance::~PluginInstance() {
@@ -799,6 +801,14 @@ void PluginInstance::SetContentAreaFocus(bool has_focus) {
}
}
+void PluginInstance::PageVisibilityChanged(bool is_visible) {
+ if (is_visible == view_data_.is_page_visible)
+ return; // Nothing to do.
+ ViewData old_data = view_data_;
+ view_data_.is_page_visible = is_visible;
+ SendDidChangeView(old_data);
+}
+
void PluginInstance::ViewInitiatedPaint() {
if (GetBoundGraphics2D())
GetBoundGraphics2D()->ViewInitiatedPaint();
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index bb43a9d..3e7f179 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -188,6 +188,9 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
void SetWebKitFocus(bool has_focus);
void SetContentAreaFocus(bool has_focus);
+ // Notification about page visibility. The default is "visible".
+ void PageVisibilityChanged(bool is_visible);
+
// Notifications that the view has rendered the page and that it has been
// flushed to the screen. These messages are used to send Flush callbacks to
// the plugin for DeviceContext2D.