[Android] Add tests for toolbar of Chrome Custom Tabs
[chromium-blink-merge.git] / components / plugins / renderer / loadable_plugin_placeholder.h
blob0111dffc9540064f2ec29cd2089cc9911dc095e1
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"
14 namespace plugins {
15 // Placeholders can be used if a plugin is missing or not available
16 // (blocked or disabled).
17 class LoadablePluginPlaceholder : public PluginPlaceholder {
18 public:
19 void set_blocked_for_background_tab(bool blocked_for_background_tab) {
20 is_blocked_for_background_tab_ = blocked_for_background_tab;
23 void set_blocked_for_prerendering(bool blocked_for_prerendering) {
24 is_blocked_for_prerendering_ = blocked_for_prerendering;
27 #if defined(ENABLE_PLUGINS)
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);
39 #endif
41 void set_allow_loading(bool allow_loading) { allow_loading_ = allow_loading; }
43 protected:
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);
55 #endif
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 const std::string& GetIdentifier() const;
65 bool LoadingAllowed() const { return allow_loading_; }
67 // Replace this placeholder with a different plugin (which could be
68 // a placeholder again).
69 void ReplacePlugin(blink::WebPlugin* new_plugin);
71 // Hide this placeholder.
72 void HidePlugin();
74 // Load the blocked plugin.
75 void LoadPlugin();
77 // WebViewPlugin::Delegate (via PluginPlaceholder) method
78 void BindWebFrame(blink::WebFrame* frame) override;
80 // gin::Wrappable method:
81 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
82 v8::Isolate* isolate) override;
84 private:
85 // WebViewPlugin::Delegate methods:
86 void PluginDestroyed() override;
87 v8::Local<v8::Object> GetV8ScriptableObject(
88 v8::Isolate* isolate) const override;
89 #if defined(ENABLE_PLUGINS)
90 void OnUnobscuredSizeUpdate(const gfx::Size& unobscured_size) override;
91 #endif
93 // RenderFrameObserver methods:
94 void WasShown() override;
96 // Javascript callbacks:
97 void LoadCallback();
98 void HideCallback();
99 void DidFinishLoadingCallback();
101 void UpdateMessage();
103 bool LoadingBlocked() const;
104 #if defined(ENABLE_PLUGINS)
105 void RecheckSizeAndMaybeUnthrottle();
106 #endif
108 // Plugin creation is embedder-specific.
109 virtual blink::WebPlugin* CreatePlugin() = 0;
111 content::WebPluginInfo plugin_info_;
113 base::string16 message_;
115 // 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.
117 bool is_blocked_for_background_tab_;
119 // True if the plugin was blocked because the page was being prerendered.
120 // Plugin may be automatically be loaded when the page is displayed.
121 bool is_blocked_for_prerendering_;
123 // True if the plugin load was deferred due to a Power Saver poster.
124 bool is_blocked_for_power_saver_poster_;
126 // True if power saver is enabled for this plugin and it has not been marked
127 // essential (by a click or retroactive whitelisting).
128 bool power_saver_enabled_;
130 // When we load, uses this premade plugin instead of creating a new one.
131 content::PluginInstanceThrottler* premade_throttler_;
133 bool allow_loading_;
135 bool hidden_;
136 bool finished_loading_;
137 std::string identifier_;
139 // Used to prevent re-entrancy during the size recheck for throttled plugins.
140 bool in_size_recheck_;
141 gfx::Size unobscured_size_;
142 base::OneShotTimer<LoadablePluginPlaceholder> size_update_timer_;
144 base::WeakPtrFactory<LoadablePluginPlaceholder> weak_factory_;
146 DISALLOW_COPY_AND_ASSIGN(LoadablePluginPlaceholder);
149 } // namespace plugins
151 #endif // COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_