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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 #include "ppapi/c/private/ppb_uma_private.h" | 128 #include "ppapi/c/private/ppb_uma_private.h" |
129 #include "ppapi/c/private/ppb_video_destination_private.h" | 129 #include "ppapi/c/private/ppb_video_destination_private.h" |
130 #include "ppapi/c/private/ppb_video_source_private.h" | 130 #include "ppapi/c/private/ppb_video_source_private.h" |
131 #include "ppapi/c/private/ppb_x509_certificate_private.h" | 131 #include "ppapi/c/private/ppb_x509_certificate_private.h" |
132 #include "ppapi/c/trusted/ppb_broker_trusted.h" | 132 #include "ppapi/c/trusted/ppb_broker_trusted.h" |
133 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" | 133 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" |
134 #include "ppapi/c/trusted/ppb_char_set_trusted.h" | 134 #include "ppapi/c/trusted/ppb_char_set_trusted.h" |
135 #include "ppapi/c/trusted/ppb_file_chooser_trusted.h" | 135 #include "ppapi/c/trusted/ppb_file_chooser_trusted.h" |
136 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | 136 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" |
137 #include "ppapi/shared_impl/callback_tracker.h" | 137 #include "ppapi/shared_impl/callback_tracker.h" |
| 138 #include "ppapi/shared_impl/dictionary_var.h" |
138 #include "ppapi/shared_impl/ppapi_preferences.h" | 139 #include "ppapi/shared_impl/ppapi_preferences.h" |
139 #include "ppapi/shared_impl/ppapi_switches.h" | 140 #include "ppapi/shared_impl/ppapi_switches.h" |
140 #include "ppapi/shared_impl/ppb_input_event_shared.h" | 141 #include "ppapi/shared_impl/ppb_input_event_shared.h" |
141 #include "ppapi/shared_impl/ppb_opengles2_shared.h" | 142 #include "ppapi/shared_impl/ppb_opengles2_shared.h" |
142 #include "ppapi/shared_impl/ppb_var_shared.h" | 143 #include "ppapi/shared_impl/ppb_var_shared.h" |
143 #include "ppapi/shared_impl/time_conversion.h" | 144 #include "ppapi/shared_impl/time_conversion.h" |
144 #include "ppapi/thunk/enter.h" | 145 #include "ppapi/thunk/enter.h" |
145 #include "ppapi/thunk/ppb_graphics_2d_api.h" | 146 #include "ppapi/thunk/ppb_graphics_2d_api.h" |
146 #include "ppapi/thunk/thunk.h" | 147 #include "ppapi/thunk/thunk.h" |
147 | 148 |
(...skipping 26 matching lines...) Expand all Loading... |
174 | 175 |
175 // Maintains all currently loaded plugin libs for validating PP_Module | 176 // Maintains all currently loaded plugin libs for validating PP_Module |
176 // identifiers. | 177 // identifiers. |
177 typedef std::set<PluginModule*> PluginModuleSet; | 178 typedef std::set<PluginModule*> PluginModuleSet; |
178 | 179 |
179 PluginModuleSet* GetLivePluginSet() { | 180 PluginModuleSet* GetLivePluginSet() { |
180 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ()); | 181 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ()); |
181 return &live_plugin_libs; | 182 return &live_plugin_libs; |
182 } | 183 } |
183 | 184 |
| 185 class PowerSaverTestPluginDelegate : public PluginInstanceThrottler::Observer { |
| 186 public: |
| 187 explicit PowerSaverTestPluginDelegate(PluginInstanceThrottlerImpl* throttler) |
| 188 : throttler_(throttler) { |
| 189 throttler_->AddObserver(this); |
| 190 PostPowerSaverStatusToJavaScript(throttler_, "initial"); |
| 191 } |
| 192 |
| 193 virtual ~PowerSaverTestPluginDelegate() { throttler_->RemoveObserver(this); } |
| 194 |
| 195 static void PostPowerSaverStatusToJavaScript( |
| 196 PluginInstanceThrottlerImpl* throttler, |
| 197 const std::string& source) { |
| 198 if (!throttler->GetWebPlugin() || !throttler->GetWebPlugin()->instance()) |
| 199 return; |
| 200 |
| 201 PepperPluginInstanceImpl* instance = throttler->GetWebPlugin()->instance(); |
| 202 |
| 203 // Refcounted by the returned PP_Var. |
| 204 ppapi::DictionaryVar* dictionary = new ppapi::DictionaryVar; |
| 205 dictionary->Set(ppapi::StringVar::StringToPPVar("source"), |
| 206 ppapi::StringVar::StringToPPVar(source)); |
| 207 dictionary->Set( |
| 208 ppapi::StringVar::StringToPPVar("isHiddenForPlaceholder"), |
| 209 PP_MakeBool(PP_FromBool(throttler->IsHiddenForPlaceholder()))); |
| 210 dictionary->Set(ppapi::StringVar::StringToPPVar("isPeripheral"), |
| 211 PP_MakeBool(PP_FromBool(throttler->power_saver_enabled()))); |
| 212 dictionary->Set(ppapi::StringVar::StringToPPVar("isThrottled"), |
| 213 PP_MakeBool(PP_FromBool(throttler->IsThrottled()))); |
| 214 |
| 215 instance->PostMessageToJavaScript(dictionary->GetPPVar()); |
| 216 } |
| 217 |
| 218 private: |
| 219 void OnThrottleStateChange() override { |
| 220 PostPowerSaverStatusToJavaScript(throttler_, "throttleStatusChange"); |
| 221 } |
| 222 |
| 223 void OnPeripheralStateChange() override { |
| 224 PostPowerSaverStatusToJavaScript(throttler_, "peripheralStatusChange"); |
| 225 } |
| 226 |
| 227 void OnHiddenForPlaceholder(bool hidden) override { |
| 228 PostPowerSaverStatusToJavaScript(throttler_, |
| 229 "hiddenForPlaceholderStatusChange"); |
| 230 } |
| 231 |
| 232 void OnThrottlerDestroyed() override { delete this; } |
| 233 |
| 234 // Non-owning pointer. |
| 235 PluginInstanceThrottlerImpl* const throttler_; |
| 236 }; |
| 237 |
184 // PPB_Core -------------------------------------------------------------------- | 238 // PPB_Core -------------------------------------------------------------------- |
185 | 239 |
186 void AddRefResource(PP_Resource resource) { | 240 void AddRefResource(PP_Resource resource) { |
187 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); | 241 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); |
188 } | 242 } |
189 | 243 |
190 void ReleaseResource(PP_Resource resource) { | 244 void ReleaseResource(PP_Resource resource) { |
191 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); | 245 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); |
192 } | 246 } |
193 | 247 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 base::MessageLoop::current()->QuitNow(); | 293 base::MessageLoop::current()->QuitNow(); |
240 } | 294 } |
241 | 295 |
242 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { | 296 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { |
243 return HostGlobals::Get()->GetResourceTracker()->GetLiveObjectsForInstance( | 297 return HostGlobals::Get()->GetResourceTracker()->GetLiveObjectsForInstance( |
244 instance_id); | 298 instance_id); |
245 } | 299 } |
246 | 300 |
247 PP_Bool IsOutOfProcess() { return PP_FALSE; } | 301 PP_Bool IsOutOfProcess() { return PP_FALSE; } |
248 | 302 |
249 PP_Bool IsPeripheral(PP_Instance instance_id) { | 303 void PostPowerSaverStatus(PP_Instance instance_id) { |
250 PepperPluginInstanceImpl* plugin_instance = | 304 PepperPluginInstanceImpl* plugin_instance = |
251 host_globals->GetInstance(instance_id); | 305 host_globals->GetInstance(instance_id); |
252 if (!plugin_instance || !plugin_instance->throttler()) | 306 if (!plugin_instance || !plugin_instance->throttler()) |
253 return PP_FALSE; | 307 return; |
254 return PP_FromBool(plugin_instance->throttler()->power_saver_enabled()); | 308 |
| 309 PowerSaverTestPluginDelegate::PostPowerSaverStatusToJavaScript( |
| 310 plugin_instance->throttler(), "getPowerSaverStatusResponse"); |
| 311 } |
| 312 |
| 313 void SubscribeToPowerSaverNotifications(PP_Instance instance_id) { |
| 314 PepperPluginInstanceImpl* plugin_instance = |
| 315 host_globals->GetInstance(instance_id); |
| 316 if (!plugin_instance || !plugin_instance->throttler()) |
| 317 return; |
| 318 |
| 319 // Manages its own lifetime. |
| 320 new PowerSaverTestPluginDelegate(plugin_instance->throttler()); |
255 } | 321 } |
256 | 322 |
257 void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) { | 323 void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) { |
258 PepperPluginInstanceImpl* plugin_instance = | 324 PepperPluginInstanceImpl* plugin_instance = |
259 host_globals->GetInstance(instance); | 325 host_globals->GetInstance(instance); |
260 if (!plugin_instance) | 326 if (!plugin_instance) |
261 return; | 327 return; |
262 | 328 |
263 EnterResource<PPB_InputEvent_API> enter(input_event, false); | 329 EnterResource<PPB_InputEvent_API> enter(input_event, false); |
264 if (enter.failed()) | 330 if (enter.failed()) |
(...skipping 30 matching lines...) Expand all Loading... |
295 content::PepperPluginInstance::Get(instance)->GetIsolate()-> | 361 content::PepperPluginInstance::Get(instance)->GetIsolate()-> |
296 RequestGarbageCollectionForTesting(v8::Isolate::kFullGarbageCollection); | 362 RequestGarbageCollectionForTesting(v8::Isolate::kFullGarbageCollection); |
297 } | 363 } |
298 | 364 |
299 const PPB_Testing_Private testing_interface = { | 365 const PPB_Testing_Private testing_interface = { |
300 &ReadImageData, | 366 &ReadImageData, |
301 &RunMessageLoop, | 367 &RunMessageLoop, |
302 &QuitMessageLoop, | 368 &QuitMessageLoop, |
303 &GetLiveObjectsForInstance, | 369 &GetLiveObjectsForInstance, |
304 &IsOutOfProcess, | 370 &IsOutOfProcess, |
305 &IsPeripheral, | 371 &PostPowerSaverStatus, |
| 372 &SubscribeToPowerSaverNotifications, |
306 &SimulateInputEvent, | 373 &SimulateInputEvent, |
307 &GetDocumentURL, | 374 &GetDocumentURL, |
308 &GetLiveVars, | 375 &GetLiveVars, |
309 &SetMinimumArrayBufferSizeForShmem, | 376 &SetMinimumArrayBufferSizeForShmem, |
310 &RunV8GC}; | 377 &RunV8GC}; |
311 | 378 |
312 // GetInterface ---------------------------------------------------------------- | 379 // GetInterface ---------------------------------------------------------------- |
313 | 380 |
314 const void* InternalGetInterface(const char* name) { | 381 const void* InternalGetInterface(const char* name) { |
315 // Allow custom interface factories first stab at the GetInterface call. | 382 // Allow custom interface factories first stab at the GetInterface call. |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 channel_handle, | 803 channel_handle, |
737 peer_pid, | 804 peer_pid, |
738 plugin_child_id, | 805 plugin_child_id, |
739 false)) // is_external = false | 806 false)) // is_external = false |
740 return scoped_refptr<PluginModule>(); | 807 return scoped_refptr<PluginModule>(); |
741 | 808 |
742 return module; | 809 return module; |
743 } | 810 } |
744 | 811 |
745 } // namespace content | 812 } // namespace content |
OLD | NEW |