Roll src/third_party/WebKit 9d2dfea:3aea697 (svn 201972:201973)
[chromium-blink-merge.git] / content / renderer / pepper / plugin_power_saver_helper.h
blob70a435a2d175f739db1e3abf00af61d07cc1793f
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.h"
12 #include "content/common/content_export.h"
13 #include "content/public/renderer/render_frame_observer.h"
14 #include "url/gurl.h"
16 namespace blink {
17 struct WebPluginParams;
18 struct WebRect;
21 namespace content {
23 class CONTENT_EXPORT PluginPowerSaverHelper : public RenderFrameObserver {
24 public:
25 explicit PluginPowerSaverHelper(RenderFrame* render_frame);
26 ~PluginPowerSaverHelper() override;
28 // See RenderFrame for documentation.
29 void RegisterPeripheralPlugin(const GURL& content_origin,
30 const base::Closure& unthrottle_callback);
32 // Returns true if this plugin should have power saver enabled.
34 // Power Saver is enabled for plugin content that are cross-origin and
35 // heuristically determined to be not essential to the web page content.
37 // Plugin content is defined to be cross-origin when the plugin source's
38 // origin differs from the top level frame's origin. For example:
39 // - Cross-origin: a.com -> b.com/plugin.swf
40 // - Cross-origin: a.com -> b.com/iframe.html -> b.com/plugin.swf
41 // - Same-origin: a.com -> b.com/iframe-to-a.html -> a.com/plugin.swf
43 // |content_origin| is the origin of the plugin content.
45 // |width| and |height| are zoom and device scale independent logical pixels.
47 // |cross_origin_main_content| may be NULL. It is set to true if the
48 // plugin content is cross-origin but still the "main attraction" of the page.
49 bool ShouldThrottleContent(const GURL& content_origin,
50 const std::string& plugin_module_name,
51 int width,
52 int height,
53 bool* cross_origin_main_content) const;
55 // Whitelists a |content_origin| so its content will never be throttled in
56 // this RenderFrame. Whitelist is cleared by top level navigation.
57 void WhitelistContentOrigin(const GURL& content_origin);
59 private:
60 struct PeripheralPlugin {
61 PeripheralPlugin(const GURL& content_origin,
62 const base::Closure& unthrottle_callback);
63 ~PeripheralPlugin();
65 GURL content_origin;
66 base::Closure unthrottle_callback;
69 enum OverrideForTesting {
70 Normal,
71 Never,
72 IgnoreList,
73 Always
76 // RenderFrameObserver implementation.
77 void DidCommitProvisionalLoad(bool is_new_navigation,
78 bool is_same_page_navigation) override;
79 bool OnMessageReceived(const IPC::Message& message) override;
81 void OnUpdatePluginContentOriginWhitelist(
82 const std::set<GURL>& origin_whitelist);
84 OverrideForTesting override_for_testing_;
86 // Local copy of the whitelist for the entire tab.
87 std::set<GURL> origin_whitelist_;
89 // Set of peripheral plugins eligible to be unthrottled ex post facto.
90 std::vector<PeripheralPlugin> peripheral_plugins_;
92 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper);
95 } // namespace content
97 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_