OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/callback_forward.h" |
| 12 #include "content/public/renderer/render_frame_observer.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // PluginPowerSaverWhitelist manages the plugin content origin whitelist for |
| 18 // a single render frame. |
| 19 class CONTENT_EXPORT PluginPowerSaverHelper : public RenderFrameObserver { |
| 20 public: |
| 21 explicit PluginPowerSaverHelper(RenderFrame* render_frame); |
| 22 virtual ~PluginPowerSaverHelper(); |
| 23 |
| 24 // Returns true if this plugin should have power saver enabled. |
| 25 // |
| 26 // Power Saver is enabled for plugin content that are cross-origin and |
| 27 // heuristically determined to be not the "main attraction" of the webpage. |
| 28 // |
| 29 // Plugin content is defined to be cross-origin when the plugin source's |
| 30 // origin differs from the top level frame's origin. For example: |
| 31 // - Cross-origin: a.com -> b.com/plugin.swf |
| 32 // - Cross-origin: a.com -> b.com/iframe.html -> b.com/plugin.swf |
| 33 // - Same-origin: a.com -> b.com/iframe-to-a.html -> a.com/plugin.swf |
| 34 // |
| 35 // |cross_origin| may not be NULL. |
| 36 bool ShouldThrottleContent(const GURL& content_origin, |
| 37 int width, |
| 38 int height, |
| 39 bool* cross_origin) const; |
| 40 |
| 41 // Registers a plugin that has been marked peripheral. If the origin |
| 42 // whitelist is later updated and includes |content_origin|, then |
| 43 // |unthrottle_callback| will be called. |
| 44 void RegisterPeripheralPlugin(const GURL& content_origin, |
| 45 const base::Closure& unthrottle_callback); |
| 46 |
| 47 void WhitelistContentOrigin(const GURL& content_origin); |
| 48 |
| 49 private: |
| 50 struct PeripheralPlugin { |
| 51 PeripheralPlugin(const GURL& content_origin, |
| 52 const base::Closure& unthrottle_callback); |
| 53 ~PeripheralPlugin(); |
| 54 |
| 55 GURL content_origin; |
| 56 base::Closure unthrottle_callback; |
| 57 }; |
| 58 |
| 59 // RenderFrameObserver implementation. |
| 60 void DidCommitProvisionalLoad(bool is_new_navigation) override; |
| 61 bool OnMessageReceived(const IPC::Message& message) override; |
| 62 |
| 63 void OnUpdatePluginContentOriginWhitelist( |
| 64 const std::set<GURL>& origin_whitelist); |
| 65 |
| 66 // Local copy of the whitelist for the entire tab. |
| 67 std::set<GURL> origin_whitelist_; |
| 68 |
| 69 // Set of peripheral plugins eligible to be unthrottled ex post facto. |
| 70 std::vector<PeripheralPlugin> peripheral_plugins_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper); |
| 73 }; |
| 74 |
| 75 } // namespace content |
| 76 |
| 77 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_ |
OLD | NEW |