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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
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
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"
144 #include "ppapi/shared_impl/scoped_pp_var.h"
143 #include "ppapi/shared_impl/time_conversion.h" 145 #include "ppapi/shared_impl/time_conversion.h"
146 #include "ppapi/shared_impl/var.h"
144 #include "ppapi/thunk/enter.h" 147 #include "ppapi/thunk/enter.h"
145 #include "ppapi/thunk/ppb_graphics_2d_api.h" 148 #include "ppapi/thunk/ppb_graphics_2d_api.h"
146 #include "ppapi/thunk/thunk.h" 149 #include "ppapi/thunk/thunk.h"
147 150
148 #if defined(OS_CHROMEOS) 151 #if defined(OS_CHROMEOS)
149 #include "ppapi/c/private/ppb_platform_verification_private.h" 152 #include "ppapi/c/private/ppb_platform_verification_private.h"
150 #endif 153 #endif
151 154
152 using ppapi::InputEventData; 155 using ppapi::InputEventData;
153 using ppapi::PpapiGlobals; 156 using ppapi::PpapiGlobals;
(...skipping 20 matching lines...) Expand all
174 177
175 // Maintains all currently loaded plugin libs for validating PP_Module 178 // Maintains all currently loaded plugin libs for validating PP_Module
176 // identifiers. 179 // identifiers.
177 typedef std::set<PluginModule*> PluginModuleSet; 180 typedef std::set<PluginModule*> PluginModuleSet;
178 181
179 PluginModuleSet* GetLivePluginSet() { 182 PluginModuleSet* GetLivePluginSet() {
180 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ()); 183 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ());
181 return &live_plugin_libs; 184 return &live_plugin_libs;
182 } 185 }
183 186
187 class PowerSaverTestPluginDelegate : public PluginInstanceThrottler::Observer {
188 public:
189 explicit PowerSaverTestPluginDelegate(PluginInstanceThrottlerImpl* throttler)
190 : throttler_(throttler) {
191 throttler_->AddObserver(this);
192 }
193
194 virtual ~PowerSaverTestPluginDelegate() {
195 throttler_->RemoveObserver(this);
196 }
197
198 private:
199 void OnThrottleStateChange() override {
200 SendMessageToPlugin("throttleStatusChange");
201 }
202
203 void OnPeripheralStateChange() override {
204 SendMessageToPlugin("peripheralStatusChange");
205 }
206
207 void OnHiddenForPlaceholder(bool hidden) override {
208 SendMessageToPlugin("hiddenForPlaceholderStatusChange");
209 }
210
211 void OnThrottlerDestroyed() override { delete this; }
212
213 void SendMessageToPlugin(const std::string& message) {
214 if (throttler_->GetWebPlugin() && throttler_->GetWebPlugin()->instance()) {
215 throttler_->GetWebPlugin()->instance()->HandleMessage(
216 ppapi::ScopedPPVar(ppapi::ScopedPPVar::PassRef(),
217 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.
218 }
219 }
220
221 // Non-owning pointer.
222 PluginInstanceThrottlerImpl* const throttler_;
223 };
224
184 // PPB_Core -------------------------------------------------------------------- 225 // PPB_Core --------------------------------------------------------------------
185 226
186 void AddRefResource(PP_Resource resource) { 227 void AddRefResource(PP_Resource resource) {
187 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); 228 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource);
188 } 229 }
189 230
190 void ReleaseResource(PP_Resource resource) { 231 void ReleaseResource(PP_Resource resource) {
191 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); 232 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource);
192 } 233 }
193 234
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 base::MessageLoop::current()->QuitNow(); 280 base::MessageLoop::current()->QuitNow();
240 } 281 }
241 282
242 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { 283 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
243 return HostGlobals::Get()->GetResourceTracker()->GetLiveObjectsForInstance( 284 return HostGlobals::Get()->GetResourceTracker()->GetLiveObjectsForInstance(
244 instance_id); 285 instance_id);
245 } 286 }
246 287
247 PP_Bool IsOutOfProcess() { return PP_FALSE; } 288 PP_Bool IsOutOfProcess() { return PP_FALSE; }
248 289
249 PP_Bool IsPeripheral(PP_Instance instance_id) { 290 PP_Var GetPowerSaverStatus(PP_Instance instance_id) {
250 PepperPluginInstanceImpl* plugin_instance = 291 PepperPluginInstanceImpl* plugin_instance =
251 host_globals->GetInstance(instance_id); 292 host_globals->GetInstance(instance_id);
252 if (!plugin_instance || !plugin_instance->throttler()) 293 if (!plugin_instance || !plugin_instance->throttler())
253 return PP_FALSE; 294 return PP_MakeUndefined();
254 return PP_FromBool(plugin_instance->throttler()->power_saver_enabled()); 295 PluginInstanceThrottlerImpl* throttler = plugin_instance->throttler();
296
297 // Refcounted by the returned PP_Var.
298 ppapi::DictionaryVar* dictionary = new ppapi::DictionaryVar;
299 dictionary->Set(
300 ppapi::StringVar::StringToPPVar("isHiddenForPlaceholder"),
301 PP_MakeBool(PP_FromBool(throttler->IsHiddenForPlaceholder())));
302 dictionary->Set(ppapi::StringVar::StringToPPVar("isPeripheral"),
303 PP_MakeBool(PP_FromBool(throttler->power_saver_enabled())));
304 dictionary->Set(ppapi::StringVar::StringToPPVar("isThrottled"),
305 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.
306 return dictionary->GetPPVar();
307 }
308
309 void SubscribeToPowerSaverNotifications(PP_Instance instance_id) {
310 PepperPluginInstanceImpl* plugin_instance =
311 host_globals->GetInstance(instance_id);
312 if (!plugin_instance || !plugin_instance->throttler())
313 return;
314
315 // Manages its own lifetime.
316 new PowerSaverTestPluginDelegate(plugin_instance->throttler());
255 } 317 }
256 318
257 void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) { 319 void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) {
258 PepperPluginInstanceImpl* plugin_instance = 320 PepperPluginInstanceImpl* plugin_instance =
259 host_globals->GetInstance(instance); 321 host_globals->GetInstance(instance);
260 if (!plugin_instance) 322 if (!plugin_instance)
261 return; 323 return;
262 324
263 EnterResource<PPB_InputEvent_API> enter(input_event, false); 325 EnterResource<PPB_InputEvent_API> enter(input_event, false);
264 if (enter.failed()) 326 if (enter.failed())
(...skipping 30 matching lines...) Expand all
295 content::PepperPluginInstance::Get(instance)->GetIsolate()-> 357 content::PepperPluginInstance::Get(instance)->GetIsolate()->
296 RequestGarbageCollectionForTesting(v8::Isolate::kFullGarbageCollection); 358 RequestGarbageCollectionForTesting(v8::Isolate::kFullGarbageCollection);
297 } 359 }
298 360
299 const PPB_Testing_Private testing_interface = { 361 const PPB_Testing_Private testing_interface = {
300 &ReadImageData, 362 &ReadImageData,
301 &RunMessageLoop, 363 &RunMessageLoop,
302 &QuitMessageLoop, 364 &QuitMessageLoop,
303 &GetLiveObjectsForInstance, 365 &GetLiveObjectsForInstance,
304 &IsOutOfProcess, 366 &IsOutOfProcess,
305 &IsPeripheral, 367 &GetPowerSaverStatus,
368 &SubscribeToPowerSaverNotifications,
306 &SimulateInputEvent, 369 &SimulateInputEvent,
307 &GetDocumentURL, 370 &GetDocumentURL,
308 &GetLiveVars, 371 &GetLiveVars,
309 &SetMinimumArrayBufferSizeForShmem, 372 &SetMinimumArrayBufferSizeForShmem,
310 &RunV8GC}; 373 &RunV8GC};
311 374
312 // GetInterface ---------------------------------------------------------------- 375 // GetInterface ----------------------------------------------------------------
313 376
314 const void* InternalGetInterface(const char* name) { 377 const void* InternalGetInterface(const char* name) {
315 // Allow custom interface factories first stab at the GetInterface call. 378 // Allow custom interface factories first stab at the GetInterface call.
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 channel_handle, 799 channel_handle,
737 peer_pid, 800 peer_pid,
738 plugin_child_id, 801 plugin_child_id,
739 false)) // is_external = false 802 false)) // is_external = false
740 return scoped_refptr<PluginModule>(); 803 return scoped_refptr<PluginModule>();
741 804
742 return module; 805 return module;
743 } 806 }
744 807
745 } // namespace content 808 } // namespace content
OLDNEW
« 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