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