Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: content/renderer/pepper/plugin_power_saver_helper.h

Issue 1421693002: Plugin Power Saver: Do not always throttle plugins with posters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0025-pps-poster-pixel-tests
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_ 5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_
6 #define CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_ 6 #define CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 #include "content/public/renderer/render_frame_observer.h" 13 #include "content/public/renderer/render_frame_observer.h"
14 #include "url/origin.h" 14 #include "url/origin.h"
15 15
16 namespace blink { 16 namespace blink {
17 struct WebPluginParams; 17 struct WebPluginParams;
18 struct WebRect; 18 struct WebRect;
19 } 19 }
20 20
21 namespace content { 21 namespace content {
22 22
23 class CONTENT_EXPORT PluginPowerSaverHelper : public RenderFrameObserver { 23 class CONTENT_EXPORT PluginPowerSaverHelper : public RenderFrameObserver {
24 public: 24 public:
25 explicit PluginPowerSaverHelper(RenderFrame* render_frame); 25 explicit PluginPowerSaverHelper(RenderFrame* render_frame);
26 ~PluginPowerSaverHelper() override; 26 ~PluginPowerSaverHelper() override;
27 27
28 // See RenderFrame for documentation. 28 private:
29 void RegisterPeripheralPlugin(const url::Origin& content_origin, 29 friend class RenderFrameImpl;
30 const base::Closure& unthrottle_callback);
31 30
32 // Returns true if this plugin should have power saver enabled.
33 //
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.
36 //
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
42 //
43 // |main_frame_origin| is the origin of the main frame.
44 //
45 // |content_origin| is the origin of the plugin content.
46 //
47 // |width| and |height| are zoom and device scale independent logical pixels.
48 //
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,
54 int width,
55 int height,
56 bool* cross_origin_main_content) const;
57
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);
61
62 private:
63 struct PeripheralPlugin { 31 struct PeripheralPlugin {
64 PeripheralPlugin(const url::Origin& content_origin, 32 PeripheralPlugin(const url::Origin& content_origin,
65 const base::Closure& unthrottle_callback); 33 const base::Closure& unthrottle_callback);
66 ~PeripheralPlugin(); 34 ~PeripheralPlugin();
67 35
68 url::Origin content_origin; 36 url::Origin content_origin;
69 base::Closure unthrottle_callback; 37 base::Closure unthrottle_callback;
70 }; 38 };
71 39
72 enum OverrideForTesting { 40 enum OverrideForTesting {
73 Normal, 41 Normal,
74 Never, 42 Never,
75 IgnoreList, 43 IgnoreList,
76 Always 44 Always
77 }; 45 };
78 46
47 // See RenderFrame for documentation.
48 void RegisterPeripheralPlugin(const url::Origin& content_origin,
49 const base::Closure& unthrottle_callback);
50 bool ShouldThrottleContent(const url::Origin& main_frame_origin,
51 const url::Origin& content_origin,
52 const std::string& plugin_module_name,
53 int width,
54 int height,
55 bool* cross_origin_main_content) const;
56 void WhitelistContentOrigin(const url::Origin& content_origin);
57
79 // RenderFrameObserver implementation. 58 // RenderFrameObserver implementation.
80 void DidCommitProvisionalLoad(bool is_new_navigation, 59 void DidCommitProvisionalLoad(bool is_new_navigation,
81 bool is_same_page_navigation) override; 60 bool is_same_page_navigation) override;
82 bool OnMessageReceived(const IPC::Message& message) override; 61 bool OnMessageReceived(const IPC::Message& message) override;
83 62
84 void OnUpdatePluginContentOriginWhitelist( 63 void OnUpdatePluginContentOriginWhitelist(
85 const std::set<url::Origin>& origin_whitelist); 64 const std::set<url::Origin>& origin_whitelist);
86 65
87 OverrideForTesting override_for_testing_; 66 OverrideForTesting override_for_testing_;
88 67
89 // Local copy of the whitelist for the entire tab. 68 // Local copy of the whitelist for the entire tab.
90 std::set<url::Origin> origin_whitelist_; 69 std::set<url::Origin> origin_whitelist_;
91 70
92 // Set of peripheral plugins eligible to be unthrottled ex post facto. 71 // Set of peripheral plugins eligible to be unthrottled ex post facto.
93 std::vector<PeripheralPlugin> peripheral_plugins_; 72 std::vector<PeripheralPlugin> peripheral_plugins_;
94 73
95 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper); 74 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper);
96 }; 75 };
97 76
98 } // namespace content 77 } // namespace content
99 78
100 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_ 79 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698