Chromium Code Reviews| 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, |