Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Unified Diff: content/renderer/pepper/plugin_module.cc

Issue 1114623002: Plugin Power Saver: Make PPS work well with prerendered pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/pepper/plugin_module.cc
diff --git a/content/renderer/pepper/plugin_module.cc b/content/renderer/pepper/plugin_module.cc
index 1cbdcaf34f616de3f66c6012ce99826e713e6aef..bb7b5e8cef9adfc37a42ea5b59b1b43d5effc2b8 100644
--- a/content/renderer/pepper/plugin_module.cc
+++ b/content/renderer/pepper/plugin_module.cc
@@ -135,6 +135,7 @@
#include "ppapi/c/trusted/ppb_file_chooser_trusted.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
#include "ppapi/shared_impl/callback_tracker.h"
+#include "ppapi/shared_impl/dictionary_var.h"
#include "ppapi/shared_impl/ppapi_preferences.h"
#include "ppapi/shared_impl/ppapi_switches.h"
#include "ppapi/shared_impl/ppb_input_event_shared.h"
@@ -181,6 +182,59 @@ PluginModuleSet* GetLivePluginSet() {
return &live_plugin_libs;
}
+class PowerSaverTestPluginDelegate : public PluginInstanceThrottler::Observer {
+ public:
+ explicit PowerSaverTestPluginDelegate(PluginInstanceThrottlerImpl* throttler)
+ : throttler_(throttler) {
+ throttler_->AddObserver(this);
+ PostPowerSaverStatusToJavaScript(throttler_, "initial");
+ }
+
+ virtual ~PowerSaverTestPluginDelegate() { throttler_->RemoveObserver(this); }
+
+ static void PostPowerSaverStatusToJavaScript(
+ PluginInstanceThrottlerImpl* throttler,
+ const std::string& source) {
+ if (!throttler->GetWebPlugin() || !throttler->GetWebPlugin()->instance())
+ return;
+
+ PepperPluginInstanceImpl* instance = throttler->GetWebPlugin()->instance();
+
+ // Refcounted by the returned PP_Var.
+ ppapi::DictionaryVar* dictionary = new ppapi::DictionaryVar;
+ dictionary->Set(ppapi::StringVar::StringToPPVar("source"),
+ ppapi::StringVar::StringToPPVar(source));
+ dictionary->Set(
+ ppapi::StringVar::StringToPPVar("isHiddenForPlaceholder"),
+ PP_MakeBool(PP_FromBool(throttler->IsHiddenForPlaceholder())));
+ dictionary->Set(ppapi::StringVar::StringToPPVar("isPeripheral"),
+ PP_MakeBool(PP_FromBool(throttler->power_saver_enabled())));
+ dictionary->Set(ppapi::StringVar::StringToPPVar("isThrottled"),
+ PP_MakeBool(PP_FromBool(throttler->IsThrottled())));
+
+ instance->PostMessageToJavaScript(dictionary->GetPPVar());
+ }
+
+ private:
+ void OnThrottleStateChange() override {
+ PostPowerSaverStatusToJavaScript(throttler_, "throttleStatusChange");
+ }
+
+ void OnPeripheralStateChange() override {
+ PostPowerSaverStatusToJavaScript(throttler_, "peripheralStatusChange");
+ }
+
+ void OnHiddenForPlaceholder(bool hidden) override {
+ PostPowerSaverStatusToJavaScript(throttler_,
+ "hiddenForPlaceholderStatusChange");
+ }
+
+ void OnThrottlerDestroyed() override { delete this; }
+
+ // Non-owning pointer.
+ PluginInstanceThrottlerImpl* const throttler_;
+};
+
// PPB_Core --------------------------------------------------------------------
void AddRefResource(PP_Resource resource) {
@@ -246,12 +300,24 @@ uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
PP_Bool IsOutOfProcess() { return PP_FALSE; }
-PP_Bool IsPeripheral(PP_Instance instance_id) {
+void PostPowerSaverStatus(PP_Instance instance_id) {
PepperPluginInstanceImpl* plugin_instance =
host_globals->GetInstance(instance_id);
if (!plugin_instance || !plugin_instance->throttler())
- return PP_FALSE;
- return PP_FromBool(plugin_instance->throttler()->power_saver_enabled());
+ return;
+
+ PowerSaverTestPluginDelegate::PostPowerSaverStatusToJavaScript(
+ plugin_instance->throttler(), "getPowerSaverStatusResponse");
+}
+
+void SubscribeToPowerSaverNotifications(PP_Instance instance_id) {
+ PepperPluginInstanceImpl* plugin_instance =
+ host_globals->GetInstance(instance_id);
+ if (!plugin_instance || !plugin_instance->throttler())
+ return;
+
+ // Manages its own lifetime.
+ new PowerSaverTestPluginDelegate(plugin_instance->throttler());
}
void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) {
@@ -302,7 +368,8 @@ const PPB_Testing_Private testing_interface = {
&QuitMessageLoop,
&GetLiveObjectsForInstance,
&IsOutOfProcess,
- &IsPeripheral,
+ &PostPowerSaverStatus,
+ &SubscribeToPowerSaverNotifications,
&SimulateInputEvent,
&GetDocumentURL,
&GetLiveVars,
« no previous file with comments | « content/renderer/pepper/plugin_instance_throttler_impl.cc ('k') | ppapi/api/private/ppb_testing_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698