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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_
6 #define COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "components/plugins/renderer/plugin_placeholder.h"
10 #include "content/public/common/webplugininfo.h"
11 #include "content/public/renderer/plugin_instance_throttler.h"
14 // Placeholders can be used if a plug-in is missing or not available
15 // (blocked or disabled).
16 class LoadablePluginPlaceholder
17 : public PluginPlaceholder
,
18 public content::PluginInstanceThrottler::Observer
{
20 void set_blocked_for_background_tab(bool blocked_for_background_tab
) {
21 is_blocked_for_background_tab_
= blocked_for_background_tab
;
24 void set_blocked_for_prerendering(bool blocked_for_prerendering
) {
25 is_blocked_for_prerendering_
= blocked_for_prerendering
;
28 #if defined(ENABLE_PLUGINS)
29 void set_power_saver_enabled(bool power_saver_enabled
) {
30 power_saver_enabled_
= power_saver_enabled
;
33 // Defer loading of plug-in, and instead show the Power Saver poster image.
34 void BlockForPowerSaverPoster();
37 void set_allow_loading(bool allow_loading
) { allow_loading_
= allow_loading
; }
39 // When we load the plugin, use this already-created plugin, not a new one.
40 void SetPremadePlugin(blink::WebPlugin
* plugin
,
41 content::PluginInstanceThrottler
* throttler
);
44 LoadablePluginPlaceholder(content::RenderFrame
* render_frame
,
45 blink::WebLocalFrame
* frame
,
46 const blink::WebPluginParams
& params
,
47 const std::string
& html_data
,
48 GURL placeholderDataUrl
);
50 ~LoadablePluginPlaceholder() override
;
52 #if defined(ENABLE_PLUGINS)
53 void MarkPluginEssential(
54 content::PluginInstanceThrottler::PowerSaverUnthrottleMethod method
);
57 void OnLoadBlockedPlugins(const std::string
& identifier
);
58 void OnSetIsPrerendering(bool is_prerendering
);
60 void SetMessage(const base::string16
& message
);
61 void SetPluginInfo(const content::WebPluginInfo
& plugin_info
);
62 const content::WebPluginInfo
& GetPluginInfo() const;
63 void SetIdentifier(const std::string
& identifier
);
64 bool LoadingAllowed() const { return allow_loading_
; }
66 // Replace this placeholder with a different plugin (which could be
67 // a placeholder again).
68 void ReplacePlugin(blink::WebPlugin
* new_plugin
);
70 // Hide this placeholder.
73 // Load the blocked plugin.
76 // gin::Wrappable method:
77 gin::ObjectTemplateBuilder
GetObjectTemplateBuilder(
78 v8::Isolate
* isolate
) override
;
81 // WebViewPlugin::Delegate methods:
82 void PluginDestroyed() override
;
84 // RenderFrameObserver methods:
85 void WasShown() override
;
87 // content::PluginInstanceThrottler::Observer methods:
88 void OnThrottleStateChange() override
;
90 // Javascript callbacks:
92 // Load the blocked plugin by calling LoadPlugin().
95 // Hide the blocked plugin by calling HidePlugin().
98 void DidFinishLoadingCallback();
100 void UpdateMessage();
102 bool LoadingBlocked() const;
104 content::WebPluginInfo plugin_info_
;
106 base::string16 message_
;
108 // True if the plugin load was deferred due to page being a background tab.
109 // Plugin may be automatically loaded when the page is foregrounded.
110 bool is_blocked_for_background_tab_
;
112 // True if the plugin was blocked because the page was being prerendered.
113 // Plugin may be automatically be loaded when the page is displayed.
114 bool is_blocked_for_prerendering_
;
116 // True if the plugin load was deferred due to a Power Saver poster.
117 bool is_blocked_for_power_saver_poster_
;
119 // This is independent of deferred plugin load due to a Power Saver poster.
120 bool power_saver_enabled_
;
122 // True if the plugin has been marked essential.
123 bool plugin_marked_essential_
;
125 // When we load, uses this premade plugin instead of creating a new one.
126 blink::WebPlugin
* premade_plugin_
;
127 content::PluginInstanceThrottler
* premade_throttler_
;
131 // True if the placeholder was replaced with the real plugin.
132 bool placeholder_was_replaced_
;
135 bool finished_loading_
;
136 std::string identifier_
;
138 base::WeakPtrFactory
<LoadablePluginPlaceholder
> weak_factory_
;
140 DISALLOW_COPY_AND_ASSIGN(LoadablePluginPlaceholder
);
143 } // namespace plugins
145 #endif // COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_