Update comments of TabObserver#onLoadStarted and rename onContentChanged
[chromium-blink-merge.git] / components / plugins / renderer / loadable_plugin_placeholder.h
blob5ebb98f14ec13ac414c6eb77172571e4ac3e1ece
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"
12 #include "content/public/renderer/render_thread.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 bool power_saver_enabled() const { return power_saver_enabled_; }
29 void set_power_saver_enabled(bool power_saver_enabled) {
30 power_saver_enabled_ = power_saver_enabled;
33 // Defer loading of plugin, and instead show the Power Saver poster image.
34 void BlockForPowerSaverPoster();
36 // When we load the plugin, use this already-created plugin, not a new one.
37 void SetPremadePlugin(content::PluginInstanceThrottler* throttler);
39 void DisallowLoading() { allow_loading_ = false; }
41 protected:
42 LoadablePluginPlaceholder(content::RenderFrame* render_frame,
43 blink::WebLocalFrame* frame,
44 const blink::WebPluginParams& params,
45 const std::string& html_data);
47 ~LoadablePluginPlaceholder() override;
49 void MarkPluginEssential(
50 content::PluginInstanceThrottler::PowerSaverUnthrottleMethod method);
52 void OnLoadBlockedPlugins(const std::string& identifier);
53 void OnSetIsPrerendering(bool is_prerendering);
55 void SetMessage(const base::string16& message);
56 void SetPluginInfo(const content::WebPluginInfo& plugin_info);
57 const content::WebPluginInfo& GetPluginInfo() const;
58 void SetIdentifier(const std::string& identifier);
59 const std::string& GetIdentifier() const;
60 bool LoadingAllowed() const { return allow_loading_; }
62 // Replace this placeholder with a different plugin (which could be
63 // a placeholder again).
64 void ReplacePlugin(blink::WebPlugin* new_plugin);
66 // Load the blocked plugin.
67 void LoadPlugin();
69 // gin::Wrappable method:
70 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
71 v8::Isolate* isolate) override;
73 private:
74 // WebViewPlugin::Delegate methods:
75 void PluginDestroyed() override;
76 v8::Local<v8::Object> GetV8ScriptableObject(
77 v8::Isolate* isolate) const override;
79 // RenderFrameObserver methods:
80 void WasShown() override;
82 // Javascript callbacks:
83 void LoadCallback();
84 void HideCallback();
85 void DidFinishLoadingCallback();
87 void UpdateMessage();
89 bool LoadingBlocked() const;
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_;
116 bool allow_loading_;
118 bool finished_loading_;
119 std::string identifier_;
121 base::WeakPtrFactory<LoadablePluginPlaceholder> weak_factory_;
123 DISALLOW_COPY_AND_ASSIGN(LoadablePluginPlaceholder);
126 } // namespace plugins
128 #endif // COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_