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 "base/timer/timer.h"
10 #include "components/plugins/renderer/plugin_placeholder.h"
11 #include "content/public/common/webplugininfo.h"
12 #include "content/public/renderer/plugin_instance_throttler.h"
13 #include "content/public/renderer/render_thread.h"
16 // Placeholders can be used if a plugin is missing or not available
17 // (blocked or disabled).
18 class LoadablePluginPlaceholder
: public PluginPlaceholderBase
{
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 bool power_saver_enabled() const { return power_saver_enabled_
; }
30 void set_power_saver_enabled(bool power_saver_enabled
) {
31 power_saver_enabled_
= power_saver_enabled
;
34 // Defer loading of plugin, and instead show the Power Saver poster image.
35 void BlockForPowerSaverPoster();
37 // When we load the plugin, use this already-created plugin, not a new one.
38 void SetPremadePlugin(content::PluginInstanceThrottler
* throttler
);
40 void AllowLoading() { allow_loading_
= true; }
43 LoadablePluginPlaceholder(content::RenderFrame
* render_frame
,
44 blink::WebLocalFrame
* frame
,
45 const blink::WebPluginParams
& params
,
46 const std::string
& html_data
);
48 ~LoadablePluginPlaceholder() override
;
50 void MarkPluginEssential(
51 content::PluginInstanceThrottler::PowerSaverUnthrottleMethod method
);
53 void OnLoadBlockedPlugins(const std::string
& identifier
);
54 void OnSetIsPrerendering(bool is_prerendering
);
56 void SetMessage(const base::string16
& message
);
57 void SetPluginInfo(const content::WebPluginInfo
& plugin_info
);
58 const content::WebPluginInfo
& GetPluginInfo() const;
59 void SetIdentifier(const std::string
& identifier
);
60 const std::string
& GetIdentifier() const;
61 bool LoadingAllowed() const { return allow_loading_
; }
63 const gfx::Rect
& unobscured_rect() { return unobscured_rect_
; }
65 // Replace this placeholder with a different plugin (which could be
66 // a placeholder again).
67 void ReplacePlugin(blink::WebPlugin
* new_plugin
);
69 // Load the blocked plugin.
72 // Javascript callbacks:
74 void DidFinishLoadingCallback();
77 // WebViewPlugin::Delegate methods:
78 void PluginDestroyed() override
;
79 v8::Local
<v8::Object
> GetV8ScriptableObject(
80 v8::Isolate
* isolate
) const override
;
81 void OnUnobscuredRectUpdate(const gfx::Rect
& unobscured_rect
) override
;
83 // RenderFrameObserver methods:
84 void WasShown() override
;
88 bool LoadingBlocked() const;
89 void RecheckSizeAndMaybeUnthrottle();
91 // Plugin creation is embedder-specific.
92 virtual blink::WebPlugin
* CreatePlugin() = 0;
94 content::WebPluginInfo plugin_info_
;
96 base::string16 message_
;
98 // True if the plugin load was deferred due to page being a background tab.
99 // Plugin may be automatically loaded when the page is foregrounded.
100 bool is_blocked_for_background_tab_
;
102 // True if the plugin was blocked because the page was being prerendered.
103 // Plugin may be automatically be loaded when the page is displayed.
104 bool is_blocked_for_prerendering_
;
106 // True if the plugin load was deferred due to a Power Saver poster.
107 bool is_blocked_for_power_saver_poster_
;
109 // True if power saver is enabled for this plugin and it has not been marked
110 // essential (by a click or retroactive whitelisting).
111 bool power_saver_enabled_
;
113 // When we load, uses this premade plugin instead of creating a new one.
114 content::PluginInstanceThrottler
* premade_throttler_
;
118 bool finished_loading_
;
119 std::string identifier_
;
121 // Used to prevent re-entrancy during the size recheck for throttled plugins.
122 bool in_size_recheck_
;
123 gfx::Rect unobscured_rect_
;
124 base::OneShotTimer
<LoadablePluginPlaceholder
> size_update_timer_
;
126 base::WeakPtrFactory
<LoadablePluginPlaceholder
> weak_factory_
;
128 DISALLOW_COPY_AND_ASSIGN(LoadablePluginPlaceholder
);
131 } // namespace plugins
133 #endif // COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_