Plugin Power Saver: Implement 'poster' functionality.
[chromium-blink-merge.git] / chrome / renderer / plugins / chrome_plugin_placeholder.h
blob617a83e3e3948915a2a41376e05647a15d7d6b52
1 // Copyright 2013 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 CHROME_RENDERER_PLUGINS_CHROME_PLUGIN_PLACEHOLDER_H_
6 #define CHROME_RENDERER_PLUGINS_CHROME_PLUGIN_PLACEHOLDER_H_
8 #include "components/plugins/renderer/plugin_placeholder.h"
10 struct ChromeViewHostMsg_GetPluginInfo_Status;
12 class ChromePluginPlaceholder : public plugins::PluginPlaceholder,
13 public content::RenderProcessObserver,
14 public content::ContextMenuClient {
15 public:
16 static const char kPluginPlaceholderDataURL[];
18 // Returns the absolute (resolved) URL of the poster image.
19 // Returns an empty GURL if there is no poster image parameter.
20 static GURL GetPluginInstancePosterImage(const blink::WebPluginParams& params,
21 const GURL& base_url);
23 static ChromePluginPlaceholder* CreateBlockedPlugin(
24 content::RenderFrame* render_frame,
25 blink::WebLocalFrame* frame,
26 const blink::WebPluginParams& params,
27 const content::WebPluginInfo& info,
28 const std::string& identifier,
29 const base::string16& name,
30 int resource_id,
31 const base::string16& message);
33 // Creates a new WebViewPlugin with a MissingPlugin as a delegate.
34 static ChromePluginPlaceholder* CreateMissingPlugin(
35 content::RenderFrame* render_frame,
36 blink::WebLocalFrame* frame,
37 const blink::WebPluginParams& params);
39 static ChromePluginPlaceholder* CreateErrorPlugin(
40 content::RenderFrame* render_frame,
41 const base::FilePath& plugin_path);
43 void SetStatus(const ChromeViewHostMsg_GetPluginInfo_Status& status);
45 #if defined(ENABLE_PLUGIN_INSTALLATION)
46 int32 CreateRoutingId();
47 #endif
49 private:
50 ChromePluginPlaceholder(content::RenderFrame* render_frame,
51 blink::WebLocalFrame* frame,
52 const blink::WebPluginParams& params,
53 const std::string& html_data,
54 const base::string16& title);
55 ~ChromePluginPlaceholder() override;
57 // WebViewPlugin::Delegate (via PluginPlaceholder) method
58 void BindWebFrame(blink::WebFrame* frame) override;
60 // gin::Wrappable (via PluginPlaceholder) method
61 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
62 v8::Isolate* isolate) override;
64 // content::RenderViewObserver (via PluginPlaceholder) override:
65 bool OnMessageReceived(const IPC::Message& message) override;
67 // WebViewPlugin::Delegate (via PluginPlaceholder) methods:
68 void ShowContextMenu(const blink::WebMouseEvent&) override;
70 // content::RenderProcessObserver methods:
71 void PluginListChanged() override;
73 // content::ContextMenuClient methods:
74 void OnMenuAction(int request_id, unsigned action) override;
75 void OnMenuClosed(int request_id) override;
77 // Javascript callback opens chrome://plugins in a new tab.
78 void OpenAboutPluginsCallback();
80 void OnLoadBlockedPlugins(const std::string& identifier);
81 void OnSetIsPrerendering(bool is_prerendering);
82 #if defined(ENABLE_PLUGIN_INSTALLATION)
83 void OnDidNotFindMissingPlugin();
84 void OnFoundMissingPlugin(const base::string16& plugin_name);
85 void OnStartedDownloadingPlugin();
86 void OnFinishedDownloadingPlugin();
87 void OnErrorDownloadingPlugin(const std::string& error);
88 void OnCancelledDownloadingPlugin();
89 #endif
91 // We use a scoped_ptr so we can forward-declare the struct; it's defined in
92 // an IPC message file which can't be easily included in other header files.
93 scoped_ptr<ChromeViewHostMsg_GetPluginInfo_Status> status_;
95 base::string16 title_;
97 #if defined(ENABLE_PLUGIN_INSTALLATION)
98 // |routing_id()| is the routing ID of our associated RenderView, but we have
99 // a separate routing ID for messages specific to this placeholder.
100 int32 placeholder_routing_id_;
101 #endif
103 bool has_host_;
104 int context_menu_request_id_; // Nonzero when request pending.
105 base::string16 plugin_name_;
107 DISALLOW_COPY_AND_ASSIGN(ChromePluginPlaceholder);
110 #endif // CHROME_RENDERER_PLUGINS_CHROME_PLUGIN_PLACEHOLDER_H_