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_
11 #include "base/callback.h"
12 #include "content/common/content_export.h"
13 #include "content/public/renderer/render_frame_observer.h"
17 struct WebPluginParams
;
23 class CONTENT_EXPORT PluginPowerSaverHelper
: public RenderFrameObserver
{
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
,
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
);
60 struct PeripheralPlugin
{
61 PeripheralPlugin(const GURL
& content_origin
,
62 const base::Closure
& unthrottle_callback
);
66 base::Closure unthrottle_callback
;
69 enum OverrideForTesting
{
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_