Process Alt-Svc headers.
[chromium-blink-merge.git] / content / renderer / pepper / plugin_power_saver_helper.h
blob3e88b10ac056fad99e15cc42e9b63856ff10efb5
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 // |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,
53 int width,
54 int height,
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);
61 private:
62 struct PeripheralPlugin {
63 PeripheralPlugin(const GURL& content_origin,
64 const base::Closure& unthrottle_callback);
65 ~PeripheralPlugin();
67 GURL content_origin;
68 base::Closure unthrottle_callback;
71 enum OverrideForTesting {
72 Normal,
73 Never,
74 IgnoreList,
75 Always
78 // RenderFrameObserver implementation.
79 void DidCommitProvisionalLoad(bool is_new_navigation,
80 bool is_same_page_navigation) override;
81 bool OnMessageReceived(const IPC::Message& message) override;
83 void OnUpdatePluginContentOriginWhitelist(
84 const std::set<GURL>& origin_whitelist);
86 OverrideForTesting override_for_testing_;
88 // Local copy of the whitelist for the entire tab.
89 std::set<GURL> origin_whitelist_;
91 // Set of peripheral plugins eligible to be unthrottled ex post facto.
92 std::vector<PeripheralPlugin> peripheral_plugins_;
94 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper);
97 } // namespace content
99 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_