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 // |page_frame_url| is the URL of the frame containing the plugin, which may
44 // be different from the URL of the top level document.
46 // |poster_image| may be NULL. It is set to the absolute URL of the poster
47 // image if it exists and this method returns true. Otherwise, an empty GURL.
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 GURL
& content_origin
,
52 const std::string
& plugin_module_name
,
55 bool* cross_origin_main_content
) const;
57 // Whitelists a |content_origin| so its content will never be throttled in
58 // this RenderFrame. Whitelist is cleared by top level navigation.
59 void WhitelistContentOrigin(const GURL
& content_origin
);
62 struct PeripheralPlugin
{
63 PeripheralPlugin(const GURL
& content_origin
,
64 const base::Closure
& unthrottle_callback
);
68 base::Closure unthrottle_callback
;
71 // RenderFrameObserver implementation.
72 void DidCommitProvisionalLoad(bool is_new_navigation
,
73 bool is_same_page_navigation
) override
;
74 bool OnMessageReceived(const IPC::Message
& message
) override
;
76 void OnUpdatePluginContentOriginWhitelist(
77 const std::set
<GURL
>& origin_whitelist
);
79 // Local copy of the whitelist for the entire tab.
80 std::set
<GURL
> origin_whitelist_
;
82 // Set of peripheral plugins eligible to be unthrottled ex post facto.
83 std::vector
<PeripheralPlugin
> peripheral_plugins_
;
85 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper
);
88 } // namespace content
90 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_