Mac: Fix performance issues with remote CoreAnimation
[chromium-blink-merge.git] / content / renderer / pepper / plugin_power_saver_helper.h
blob5cca041fdfc9ee1774cabfade3e7c2a3d48d583b
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.
5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_
6 #define CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_
8 #include <set>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "content/public/renderer/render_frame_observer.h"
13 #include "url/gurl.h"
15 namespace content {
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();
24 // Returns true if this plugin should have power saver enabled.
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.
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
35 // |cross_origin| may not be NULL.
36 virtual bool ShouldThrottleContent(const GURL& content_origin,
37 int width,
38 int height,
39 bool* cross_origin) const;
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 virtual void RegisterPeripheralPlugin(
45 const GURL& content_origin,
46 const base::Closure& unthrottle_callback);
48 virtual void WhitelistContentOrigin(const GURL& content_origin);
50 private:
51 struct PeripheralPlugin {
52 PeripheralPlugin(const GURL& content_origin,
53 const base::Closure& unthrottle_callback);
54 ~PeripheralPlugin();
56 GURL content_origin;
57 base::Closure unthrottle_callback;
60 // RenderFrameObserver implementation.
61 void DidCommitProvisionalLoad(bool is_new_navigation) override;
62 bool OnMessageReceived(const IPC::Message& message) override;
64 void OnUpdatePluginContentOriginWhitelist(
65 const std::set<GURL>& origin_whitelist);
67 // Local copy of the whitelist for the entire tab.
68 std::set<GURL> origin_whitelist_;
70 // Set of peripheral plugins eligible to be unthrottled ex post facto.
71 std::vector<PeripheralPlugin> peripheral_plugins_;
73 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper);
76 } // namespace content
78 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_