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"
14 #include "url/origin.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 url::Origin
& 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 // |main_frame_origin| is the origin of the main frame.
45 // |content_origin| is the origin of the plugin content.
47 // |width| and |height| are zoom and device scale independent logical pixels.
49 // |cross_origin_main_content| may be NULL. It is set to true if the
50 // plugin content is cross-origin but still the "main attraction" of the page.
51 bool ShouldThrottleContent(const url::Origin
& main_frame_origin
,
52 const url::Origin
& content_origin
,
53 const std::string
& plugin_module_name
,
56 bool* cross_origin_main_content
) const;
58 // Whitelists a |content_origin| so its content will never be throttled in
59 // this RenderFrame. Whitelist is cleared by top level navigation.
60 void WhitelistContentOrigin(const url::Origin
& content_origin
);
63 struct PeripheralPlugin
{
64 PeripheralPlugin(const url::Origin
& content_origin
,
65 const base::Closure
& unthrottle_callback
);
68 url::Origin content_origin
;
69 base::Closure unthrottle_callback
;
72 enum OverrideForTesting
{
79 // RenderFrameObserver implementation.
80 void DidCommitProvisionalLoad(bool is_new_navigation
,
81 bool is_same_page_navigation
) override
;
82 bool OnMessageReceived(const IPC::Message
& message
) override
;
84 void OnUpdatePluginContentOriginWhitelist(
85 const std::set
<url::Origin
>& origin_whitelist
);
87 OverrideForTesting override_for_testing_
;
89 // Local copy of the whitelist for the entire tab.
90 std::set
<url::Origin
> origin_whitelist_
;
92 // Set of peripheral plugins eligible to be unthrottled ex post facto.
93 std::vector
<PeripheralPlugin
> peripheral_plugins_
;
95 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper
);
98 } // namespace content
100 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_