OLD | NEW |
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/gurl.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 // See RenderFrame for documentation. |
29 void RegisterPeripheralPlugin(const GURL& content_origin, | 29 void RegisterPeripheralPlugin(const url::Origin& content_origin, |
30 const base::Closure& unthrottle_callback); | 30 const base::Closure& unthrottle_callback); |
31 | 31 |
32 // Returns true if this plugin should have power saver enabled. | 32 // Returns true if this plugin should have power saver enabled. |
33 // | 33 // |
34 // Power Saver is enabled for plugin content that are cross-origin and | 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. | 35 // heuristically determined to be not essential to the web page content. |
36 // | 36 // |
37 // Plugin content is defined to be cross-origin when the plugin source's | 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: | 38 // origin differs from the top level frame's origin. For example: |
39 // - Cross-origin: a.com -> b.com/plugin.swf | 39 // - Cross-origin: a.com -> b.com/plugin.swf |
40 // - Cross-origin: a.com -> b.com/iframe.html -> 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 | 41 // - Same-origin: a.com -> b.com/iframe-to-a.html -> a.com/plugin.swf |
42 // | 42 // |
| 43 // |main_frame_origin| is the origin of the main frame. |
| 44 // |
43 // |content_origin| is the origin of the plugin content. | 45 // |content_origin| is the origin of the plugin content. |
44 // | 46 // |
45 // |width| and |height| are zoom and device scale independent logical pixels. | 47 // |width| and |height| are zoom and device scale independent logical pixels. |
46 // | 48 // |
47 // |cross_origin_main_content| may be NULL. It is set to true if the | 49 // |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. | 50 // plugin content is cross-origin but still the "main attraction" of the page. |
49 bool ShouldThrottleContent(const GURL& content_origin, | 51 bool ShouldThrottleContent(const url::Origin& main_frame_origin, |
| 52 const url::Origin& content_origin, |
50 const std::string& plugin_module_name, | 53 const std::string& plugin_module_name, |
51 int width, | 54 int width, |
52 int height, | 55 int height, |
53 bool* cross_origin_main_content) const; | 56 bool* cross_origin_main_content) const; |
54 | 57 |
55 // Whitelists a |content_origin| so its content will never be throttled in | 58 // Whitelists a |content_origin| so its content will never be throttled in |
56 // this RenderFrame. Whitelist is cleared by top level navigation. | 59 // this RenderFrame. Whitelist is cleared by top level navigation. |
57 void WhitelistContentOrigin(const GURL& content_origin); | 60 void WhitelistContentOrigin(const url::Origin& content_origin); |
58 | 61 |
59 private: | 62 private: |
60 struct PeripheralPlugin { | 63 struct PeripheralPlugin { |
61 PeripheralPlugin(const GURL& content_origin, | 64 PeripheralPlugin(const url::Origin& content_origin, |
62 const base::Closure& unthrottle_callback); | 65 const base::Closure& unthrottle_callback); |
63 ~PeripheralPlugin(); | 66 ~PeripheralPlugin(); |
64 | 67 |
65 GURL content_origin; | 68 url::Origin content_origin; |
66 base::Closure unthrottle_callback; | 69 base::Closure unthrottle_callback; |
67 }; | 70 }; |
68 | 71 |
69 enum OverrideForTesting { | 72 enum OverrideForTesting { |
70 Normal, | 73 Normal, |
71 Never, | 74 Never, |
72 IgnoreList, | 75 IgnoreList, |
73 Always | 76 Always |
74 }; | 77 }; |
75 | 78 |
76 // RenderFrameObserver implementation. | 79 // RenderFrameObserver implementation. |
77 void DidCommitProvisionalLoad(bool is_new_navigation, | 80 void DidCommitProvisionalLoad(bool is_new_navigation, |
78 bool is_same_page_navigation) override; | 81 bool is_same_page_navigation) override; |
79 bool OnMessageReceived(const IPC::Message& message) override; | 82 bool OnMessageReceived(const IPC::Message& message) override; |
80 | 83 |
81 void OnUpdatePluginContentOriginWhitelist( | 84 void OnUpdatePluginContentOriginWhitelist( |
82 const std::set<GURL>& origin_whitelist); | 85 const std::set<url::Origin>& origin_whitelist); |
83 | 86 |
84 OverrideForTesting override_for_testing_; | 87 OverrideForTesting override_for_testing_; |
85 | 88 |
86 // Local copy of the whitelist for the entire tab. | 89 // Local copy of the whitelist for the entire tab. |
87 std::set<GURL> origin_whitelist_; | 90 std::set<url::Origin> origin_whitelist_; |
88 | 91 |
89 // Set of peripheral plugins eligible to be unthrottled ex post facto. | 92 // Set of peripheral plugins eligible to be unthrottled ex post facto. |
90 std::vector<PeripheralPlugin> peripheral_plugins_; | 93 std::vector<PeripheralPlugin> peripheral_plugins_; |
91 | 94 |
92 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper); | 95 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper); |
93 }; | 96 }; |
94 | 97 |
95 } // namespace content | 98 } // namespace content |
96 | 99 |
97 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_ | 100 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_ |
OLD | NEW |