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

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: update comments 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..e37735c8911752fe2d6b6ca8dedd5654c27a73ab 100644
--- a/content/renderer/pepper/plugin_module.cc
+++ b/content/renderer/pepper/plugin_module.cc
@@ -135,12 +135,15 @@
#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"
#include "ppapi/shared_impl/ppb_opengles2_shared.h"
#include "ppapi/shared_impl/ppb_var_shared.h"
+#include "ppapi/shared_impl/scoped_pp_var.h"
#include "ppapi/shared_impl/time_conversion.h"
+#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_graphics_2d_api.h"
#include "ppapi/thunk/thunk.h"
@@ -181,6 +184,44 @@ PluginModuleSet* GetLivePluginSet() {
return &live_plugin_libs;
}
+class PowerSaverTestPluginDelegate : public PluginInstanceThrottler::Observer {
+ public:
+ explicit PowerSaverTestPluginDelegate(PluginInstanceThrottlerImpl* throttler)
+ : throttler_(throttler) {
+ throttler_->AddObserver(this);
+ }
+
+ virtual ~PowerSaverTestPluginDelegate() {
+ throttler_->RemoveObserver(this);
+ }
+
+ private:
+ void OnThrottleStateChange() override {
+ SendMessageToPlugin("throttleStatusChange");
+ }
+
+ void OnPeripheralStateChange() override {
+ SendMessageToPlugin("peripheralStatusChange");
+ }
+
+ void OnHiddenForPlaceholder(bool hidden) override {
+ SendMessageToPlugin("hiddenForPlaceholderStatusChange");
+ }
+
+ void OnThrottlerDestroyed() override { delete this; }
+
+ void SendMessageToPlugin(const std::string& message) {
+ if (throttler_->GetWebPlugin() && throttler_->GetWebPlugin()->instance()) {
+ throttler_->GetWebPlugin()->instance()->HandleMessage(
+ ppapi::ScopedPPVar(ppapi::ScopedPPVar::PassRef(),
+ ppapi::StringVar::StringToPPVar(message)));
raymes 2015/05/01 01:02:05 This is still a bit un-idiomatic from a pepper per
tommycli 2015/05/01 23:12:43 Done.
+ }
+ }
+
+ // Non-owning pointer.
+ PluginInstanceThrottlerImpl* const throttler_;
+};
+
// PPB_Core --------------------------------------------------------------------
void AddRefResource(PP_Resource resource) {
@@ -246,12 +287,33 @@ uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
PP_Bool IsOutOfProcess() { return PP_FALSE; }
-PP_Bool IsPeripheral(PP_Instance instance_id) {
+PP_Var GetPowerSaverStatus(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 PP_MakeUndefined();
+ PluginInstanceThrottlerImpl* throttler = plugin_instance->throttler();
+
+ // Refcounted by the returned PP_Var.
+ ppapi::DictionaryVar* dictionary = new ppapi::DictionaryVar;
+ 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())));
raymes 2015/05/01 01:02:05 Also, if we're going to postMessage the data, why
tommycli 2015/05/01 23:12:43 Done.
+ return dictionary->GetPPVar();
+}
+
+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 +364,8 @@ const PPB_Testing_Private testing_interface = {
&QuitMessageLoop,
&GetLiveObjectsForInstance,
&IsOutOfProcess,
- &IsPeripheral,
+ &GetPowerSaverStatus,
+ &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