OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_ | 5 #ifndef COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_ |
6 #define COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_ | 6 #define COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "components/plugins/renderer/plugin_placeholder.h" | 9 #include "components/plugins/renderer/plugin_placeholder.h" |
10 #include "content/public/common/webplugininfo.h" | 10 #include "content/public/common/webplugininfo.h" |
11 #include "content/public/renderer/plugin_instance_throttler.h" | 11 #include "content/public/renderer/plugin_instance_throttler.h" |
| 12 #include "content/public/renderer/render_thread.h" |
12 | 13 |
13 namespace plugins { | 14 namespace plugins { |
14 // Placeholders can be used if a plugin is missing or not available | 15 // Placeholders can be used if a plugin is missing or not available |
15 // (blocked or disabled). | 16 // (blocked or disabled). |
16 class LoadablePluginPlaceholder : public PluginPlaceholder { | 17 class LoadablePluginPlaceholder : public PluginPlaceholderBase { |
17 public: | 18 public: |
18 void set_blocked_for_background_tab(bool blocked_for_background_tab) { | 19 void set_blocked_for_background_tab(bool blocked_for_background_tab) { |
19 is_blocked_for_background_tab_ = blocked_for_background_tab; | 20 is_blocked_for_background_tab_ = blocked_for_background_tab; |
20 } | 21 } |
21 | 22 |
22 void set_blocked_for_prerendering(bool blocked_for_prerendering) { | 23 void set_blocked_for_prerendering(bool blocked_for_prerendering) { |
23 is_blocked_for_prerendering_ = blocked_for_prerendering; | 24 is_blocked_for_prerendering_ = blocked_for_prerendering; |
24 } | 25 } |
25 | 26 |
26 #if defined(ENABLE_PLUGINS) | |
27 bool power_saver_enabled() const { return power_saver_enabled_; } | 27 bool power_saver_enabled() const { return power_saver_enabled_; } |
28 | 28 |
29 void set_power_saver_enabled(bool power_saver_enabled) { | 29 void set_power_saver_enabled(bool power_saver_enabled) { |
30 power_saver_enabled_ = power_saver_enabled; | 30 power_saver_enabled_ = power_saver_enabled; |
31 } | 31 } |
32 | 32 |
33 // Defer loading of plugin, and instead show the Power Saver poster image. | 33 // Defer loading of plugin, and instead show the Power Saver poster image. |
34 void BlockForPowerSaverPoster(); | 34 void BlockForPowerSaverPoster(); |
35 | 35 |
36 // When we load the plugin, use this already-created plugin, not a new one. | 36 // When we load the plugin, use this already-created plugin, not a new one. |
37 void SetPremadePlugin(content::PluginInstanceThrottler* throttler); | 37 void SetPremadePlugin(content::PluginInstanceThrottler* throttler); |
38 #endif | |
39 | 38 |
40 void set_allow_loading(bool allow_loading) { allow_loading_ = allow_loading; } | 39 void DisallowLoading() { allow_loading_ = false; } |
41 | 40 |
42 protected: | 41 protected: |
43 LoadablePluginPlaceholder(content::RenderFrame* render_frame, | 42 LoadablePluginPlaceholder(content::RenderFrame* render_frame, |
44 blink::WebLocalFrame* frame, | 43 blink::WebLocalFrame* frame, |
45 const blink::WebPluginParams& params, | 44 const blink::WebPluginParams& params, |
46 const std::string& html_data, | 45 const std::string& html_data); |
47 GURL placeholderDataUrl); | |
48 | 46 |
49 ~LoadablePluginPlaceholder() override; | 47 ~LoadablePluginPlaceholder() override; |
50 | 48 |
51 #if defined(ENABLE_PLUGINS) | |
52 void MarkPluginEssential( | 49 void MarkPluginEssential( |
53 content::PluginInstanceThrottler::PowerSaverUnthrottleMethod method); | 50 content::PluginInstanceThrottler::PowerSaverUnthrottleMethod method); |
54 #endif | |
55 | 51 |
56 void OnLoadBlockedPlugins(const std::string& identifier); | 52 void OnLoadBlockedPlugins(const std::string& identifier); |
57 void OnSetIsPrerendering(bool is_prerendering); | 53 void OnSetIsPrerendering(bool is_prerendering); |
58 | 54 |
59 void SetMessage(const base::string16& message); | 55 void SetMessage(const base::string16& message); |
60 void SetPluginInfo(const content::WebPluginInfo& plugin_info); | 56 void SetPluginInfo(const content::WebPluginInfo& plugin_info); |
61 const content::WebPluginInfo& GetPluginInfo() const; | 57 const content::WebPluginInfo& GetPluginInfo() const; |
62 void SetIdentifier(const std::string& identifier); | 58 void SetIdentifier(const std::string& identifier); |
63 const std::string& GetIdentifier() const; | 59 const std::string& GetIdentifier() const; |
64 bool LoadingAllowed() const { return allow_loading_; } | 60 bool LoadingAllowed() const { return allow_loading_; } |
65 | 61 |
66 // Replace this placeholder with a different plugin (which could be | 62 // Replace this placeholder with a different plugin (which could be |
67 // a placeholder again). | 63 // a placeholder again). |
68 void ReplacePlugin(blink::WebPlugin* new_plugin); | 64 void ReplacePlugin(blink::WebPlugin* new_plugin); |
69 | 65 |
70 // Hide this placeholder. | |
71 void HidePlugin(); | |
72 | |
73 // Load the blocked plugin. | 66 // Load the blocked plugin. |
74 void LoadPlugin(); | 67 void LoadPlugin(); |
75 | 68 |
76 // WebViewPlugin::Delegate (via PluginPlaceholder) method | 69 // Javascript callbacks: |
77 void BindWebFrame(blink::WebFrame* frame) override; | 70 void LoadCallback(); |
78 | 71 void DidFinishLoadingCallback(); |
79 // gin::Wrappable method: | |
80 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | |
81 v8::Isolate* isolate) override; | |
82 | 72 |
83 private: | 73 private: |
84 // WebViewPlugin::Delegate methods: | 74 // WebViewPlugin::Delegate methods: |
85 void PluginDestroyed() override; | 75 void PluginDestroyed() override; |
86 v8::Local<v8::Object> GetV8ScriptableObject( | 76 v8::Local<v8::Object> GetV8ScriptableObject( |
87 v8::Isolate* isolate) const override; | 77 v8::Isolate* isolate) const override; |
88 | 78 |
89 // RenderFrameObserver methods: | 79 // RenderFrameObserver methods: |
90 void WasShown() override; | 80 void WasShown() override; |
91 | 81 |
92 // Javascript callbacks: | |
93 void LoadCallback(); | |
94 void HideCallback(); | |
95 void DidFinishLoadingCallback(); | |
96 | |
97 void UpdateMessage(); | 82 void UpdateMessage(); |
98 | 83 |
99 bool LoadingBlocked() const; | 84 bool LoadingBlocked() const; |
100 | 85 |
101 // Plugin creation is embedder-specific. | 86 // Plugin creation is embedder-specific. |
102 virtual blink::WebPlugin* CreatePlugin() = 0; | 87 virtual blink::WebPlugin* CreatePlugin() = 0; |
103 | 88 |
104 content::WebPluginInfo plugin_info_; | 89 content::WebPluginInfo plugin_info_; |
105 | 90 |
106 base::string16 message_; | 91 base::string16 message_; |
(...skipping 11 matching lines...) Expand all Loading... |
118 | 103 |
119 // True if power saver is enabled for this plugin and it has not been marked | 104 // True if power saver is enabled for this plugin and it has not been marked |
120 // essential (by a click or retroactive whitelisting). | 105 // essential (by a click or retroactive whitelisting). |
121 bool power_saver_enabled_; | 106 bool power_saver_enabled_; |
122 | 107 |
123 // When we load, uses this premade plugin instead of creating a new one. | 108 // When we load, uses this premade plugin instead of creating a new one. |
124 content::PluginInstanceThrottler* premade_throttler_; | 109 content::PluginInstanceThrottler* premade_throttler_; |
125 | 110 |
126 bool allow_loading_; | 111 bool allow_loading_; |
127 | 112 |
128 bool hidden_; | |
129 bool finished_loading_; | 113 bool finished_loading_; |
130 std::string identifier_; | 114 std::string identifier_; |
131 | 115 |
132 base::WeakPtrFactory<LoadablePluginPlaceholder> weak_factory_; | 116 base::WeakPtrFactory<LoadablePluginPlaceholder> weak_factory_; |
133 | 117 |
134 DISALLOW_COPY_AND_ASSIGN(LoadablePluginPlaceholder); | 118 DISALLOW_COPY_AND_ASSIGN(LoadablePluginPlaceholder); |
135 }; | 119 }; |
136 | 120 |
137 } // namespace plugins | 121 } // namespace plugins |
138 | 122 |
139 #endif // COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_ | 123 #endif // COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_ |
OLD | NEW |