Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/plugin_module.h" | 5 #include "content/renderer/pepper/plugin_module.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 PluginModuleSet* GetLivePluginSet() { | 180 PluginModuleSet* GetLivePluginSet() { |
| 181 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ()); | 181 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ()); |
| 182 return &live_plugin_libs; | 182 return &live_plugin_libs; |
| 183 } | 183 } |
| 184 | 184 |
| 185 class PowerSaverTestPluginDelegate : public PluginInstanceThrottler::Observer { | 185 class PowerSaverTestPluginDelegate : public PluginInstanceThrottler::Observer { |
| 186 public: | 186 public: |
| 187 explicit PowerSaverTestPluginDelegate(PluginInstanceThrottlerImpl* throttler) | 187 explicit PowerSaverTestPluginDelegate(PluginInstanceThrottlerImpl* throttler) |
| 188 : throttler_(throttler) { | 188 : throttler_(throttler) { |
| 189 throttler_->AddObserver(this); | 189 throttler_->AddObserver(this); |
| 190 PostPowerSaverStatusToJavaScript(throttler_, "initial"); | 190 PostPowerSaverStatusToJavaScript("initial"); |
| 191 } | 191 } |
| 192 | 192 |
| 193 virtual ~PowerSaverTestPluginDelegate() { throttler_->RemoveObserver(this); } | 193 virtual ~PowerSaverTestPluginDelegate() { throttler_->RemoveObserver(this); } |
| 194 | 194 |
| 195 static void PostPowerSaverStatusToJavaScript( | 195 static void PostPowerSaverStatusToJavaScript( |
|
tommycli
2015/05/08 19:26:58
The changes in this file are necessary because pre
| |
| 196 PluginInstanceThrottlerImpl* throttler, | 196 PepperPluginInstanceImpl* instance, |
| 197 const std::string& source) { | 197 const std::string& source) { |
| 198 if (!throttler->GetWebPlugin() || !throttler->GetWebPlugin()->instance()) | 198 DCHECK(instance); |
| 199 return; | |
| 200 | 199 |
| 201 PepperPluginInstanceImpl* instance = throttler->GetWebPlugin()->instance(); | 200 bool is_hidden_for_placeholder = false; |
| 201 bool is_peripheral = false; | |
| 202 bool is_throttled = false; | |
| 203 | |
| 204 if (instance->throttler()) { | |
| 205 PluginInstanceThrottlerImpl* throttler = instance->throttler(); | |
| 206 is_hidden_for_placeholder = throttler->IsHiddenForPlaceholder(); | |
| 207 is_peripheral = throttler->power_saver_enabled(); | |
| 208 is_throttled = throttler->IsThrottled(); | |
| 209 } | |
| 202 | 210 |
| 203 // Refcounted by the returned PP_Var. | 211 // Refcounted by the returned PP_Var. |
| 204 ppapi::DictionaryVar* dictionary = new ppapi::DictionaryVar; | 212 ppapi::DictionaryVar* dictionary = new ppapi::DictionaryVar; |
| 205 dictionary->Set(ppapi::StringVar::StringToPPVar("source"), | 213 dictionary->Set(ppapi::StringVar::StringToPPVar("source"), |
| 206 ppapi::StringVar::StringToPPVar(source)); | 214 ppapi::StringVar::StringToPPVar(source)); |
| 207 dictionary->Set( | 215 dictionary->Set(ppapi::StringVar::StringToPPVar("isHiddenForPlaceholder"), |
| 208 ppapi::StringVar::StringToPPVar("isHiddenForPlaceholder"), | 216 PP_MakeBool(PP_FromBool(is_hidden_for_placeholder))); |
| 209 PP_MakeBool(PP_FromBool(throttler->IsHiddenForPlaceholder()))); | |
| 210 dictionary->Set(ppapi::StringVar::StringToPPVar("isPeripheral"), | 217 dictionary->Set(ppapi::StringVar::StringToPPVar("isPeripheral"), |
| 211 PP_MakeBool(PP_FromBool(throttler->power_saver_enabled()))); | 218 PP_MakeBool(PP_FromBool(is_peripheral))); |
| 212 dictionary->Set(ppapi::StringVar::StringToPPVar("isThrottled"), | 219 dictionary->Set(ppapi::StringVar::StringToPPVar("isThrottled"), |
| 213 PP_MakeBool(PP_FromBool(throttler->IsThrottled()))); | 220 PP_MakeBool(PP_FromBool(is_throttled))); |
| 214 | 221 |
| 215 instance->PostMessageToJavaScript(dictionary->GetPPVar()); | 222 instance->PostMessageToJavaScript(dictionary->GetPPVar()); |
| 216 } | 223 } |
| 217 | 224 |
| 218 private: | 225 private: |
| 219 void OnThrottleStateChange() override { | 226 void OnThrottleStateChange() override { |
| 220 PostPowerSaverStatusToJavaScript(throttler_, "throttleStatusChange"); | 227 PostPowerSaverStatusToJavaScript("throttleStatusChange"); |
| 221 } | 228 } |
| 222 | 229 |
| 223 void OnPeripheralStateChange() override { | 230 void OnPeripheralStateChange() override { |
| 224 PostPowerSaverStatusToJavaScript(throttler_, "peripheralStatusChange"); | 231 PostPowerSaverStatusToJavaScript("peripheralStatusChange"); |
| 225 } | 232 } |
| 226 | 233 |
| 227 void OnHiddenForPlaceholder(bool hidden) override { | 234 void OnHiddenForPlaceholder(bool hidden) override { |
| 228 PostPowerSaverStatusToJavaScript(throttler_, | 235 PostPowerSaverStatusToJavaScript("hiddenForPlaceholderStatusChange"); |
| 229 "hiddenForPlaceholderStatusChange"); | |
| 230 } | 236 } |
| 231 | 237 |
| 232 void OnThrottlerDestroyed() override { delete this; } | 238 void OnThrottlerDestroyed() override { delete this; } |
| 233 | 239 |
| 240 void PostPowerSaverStatusToJavaScript(const std::string& source) { | |
| 241 if (!throttler_->GetWebPlugin() || !throttler_->GetWebPlugin()->instance()) | |
| 242 return; | |
| 243 PostPowerSaverStatusToJavaScript(throttler_->GetWebPlugin()->instance(), | |
| 244 source); | |
| 245 } | |
| 246 | |
| 234 // Non-owning pointer. | 247 // Non-owning pointer. |
| 235 PluginInstanceThrottlerImpl* const throttler_; | 248 PluginInstanceThrottlerImpl* const throttler_; |
| 236 }; | 249 }; |
| 237 | 250 |
| 238 // PPB_Core -------------------------------------------------------------------- | 251 // PPB_Core -------------------------------------------------------------------- |
| 239 | 252 |
| 240 void AddRefResource(PP_Resource resource) { | 253 void AddRefResource(PP_Resource resource) { |
| 241 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); | 254 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); |
| 242 } | 255 } |
| 243 | 256 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { | 309 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { |
| 297 return HostGlobals::Get()->GetResourceTracker()->GetLiveObjectsForInstance( | 310 return HostGlobals::Get()->GetResourceTracker()->GetLiveObjectsForInstance( |
| 298 instance_id); | 311 instance_id); |
| 299 } | 312 } |
| 300 | 313 |
| 301 PP_Bool IsOutOfProcess() { return PP_FALSE; } | 314 PP_Bool IsOutOfProcess() { return PP_FALSE; } |
| 302 | 315 |
| 303 void PostPowerSaverStatus(PP_Instance instance_id) { | 316 void PostPowerSaverStatus(PP_Instance instance_id) { |
| 304 PepperPluginInstanceImpl* plugin_instance = | 317 PepperPluginInstanceImpl* plugin_instance = |
| 305 host_globals->GetInstance(instance_id); | 318 host_globals->GetInstance(instance_id); |
| 306 if (!plugin_instance || !plugin_instance->throttler()) | 319 if (!plugin_instance) |
| 307 return; | 320 return; |
| 308 | 321 |
| 309 PowerSaverTestPluginDelegate::PostPowerSaverStatusToJavaScript( | 322 PowerSaverTestPluginDelegate::PostPowerSaverStatusToJavaScript( |
| 310 plugin_instance->throttler(), "getPowerSaverStatusResponse"); | 323 plugin_instance, "getPowerSaverStatusResponse"); |
| 311 } | 324 } |
| 312 | 325 |
| 313 void SubscribeToPowerSaverNotifications(PP_Instance instance_id) { | 326 void SubscribeToPowerSaverNotifications(PP_Instance instance_id) { |
| 314 PepperPluginInstanceImpl* plugin_instance = | 327 PepperPluginInstanceImpl* plugin_instance = |
| 315 host_globals->GetInstance(instance_id); | 328 host_globals->GetInstance(instance_id); |
| 316 if (!plugin_instance || !plugin_instance->throttler()) | 329 if (!plugin_instance) |
| 317 return; | 330 return; |
| 318 | 331 |
| 319 // Manages its own lifetime. | 332 if (plugin_instance->throttler()) { |
| 320 new PowerSaverTestPluginDelegate(plugin_instance->throttler()); | 333 // Manages its own lifetime. |
| 334 new PowerSaverTestPluginDelegate(plugin_instance->throttler()); | |
| 335 } else { | |
| 336 // Just send an initial status. This status will never be updated. | |
| 337 PowerSaverTestPluginDelegate::PostPowerSaverStatusToJavaScript( | |
| 338 plugin_instance, "initial"); | |
| 339 } | |
| 321 } | 340 } |
| 322 | 341 |
| 323 void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) { | 342 void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) { |
| 324 PepperPluginInstanceImpl* plugin_instance = | 343 PepperPluginInstanceImpl* plugin_instance = |
| 325 host_globals->GetInstance(instance); | 344 host_globals->GetInstance(instance); |
| 326 if (!plugin_instance) | 345 if (!plugin_instance) |
| 327 return; | 346 return; |
| 328 | 347 |
| 329 EnterResource<PPB_InputEvent_API> enter(input_event, false); | 348 EnterResource<PPB_InputEvent_API> enter(input_event, false); |
| 330 if (enter.failed()) | 349 if (enter.failed()) |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 channel_handle, | 822 channel_handle, |
| 804 peer_pid, | 823 peer_pid, |
| 805 plugin_child_id, | 824 plugin_child_id, |
| 806 false)) // is_external = false | 825 false)) // is_external = false |
| 807 return scoped_refptr<PluginModule>(); | 826 return scoped_refptr<PluginModule>(); |
| 808 | 827 |
| 809 return module; | 828 return module; |
| 810 } | 829 } |
| 811 | 830 |
| 812 } // namespace content | 831 } // namespace content |
| OLD | NEW |