Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / components / plugins / renderer / plugin_placeholder.h
blob63a1d08c8b1c47c1bca8e3fe87955a37e4bdf93c
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 COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_
6 #define COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "components/plugins/renderer/webview_plugin.h"
10 #include "content/public/renderer/render_frame_observer.h"
11 #include "gin/handle.h"
12 #include "gin/wrappable.h"
13 #include "third_party/WebKit/public/web/WebKit.h"
14 #include "third_party/WebKit/public/web/WebPluginParams.h"
16 namespace plugins {
18 // This abstract class is the base class of all plugin placeholders.
19 class PluginPlaceholderBase : public content::RenderFrameObserver,
20 public WebViewPlugin::Delegate {
21 public:
22 // |render_frame| and |frame| are weak pointers. If either one is going away,
23 // our |plugin_| will be destroyed as well and will notify us.
24 PluginPlaceholderBase(content::RenderFrame* render_frame,
25 blink::WebLocalFrame* frame,
26 const blink::WebPluginParams& params,
27 const std::string& html_data);
29 ~PluginPlaceholderBase() override;
31 WebViewPlugin* plugin() { return plugin_; }
33 protected:
34 blink::WebLocalFrame* GetFrame();
35 const blink::WebPluginParams& GetPluginParams() const;
37 // WebViewPlugin::Delegate methods:
38 void ShowContextMenu(const blink::WebMouseEvent&) override;
39 void PluginDestroyed() override;
40 v8::Local<v8::Object> GetV8ScriptableObject(
41 v8::Isolate* isolate) const override;
43 protected:
44 // Hide this placeholder.
45 void HidePlugin();
46 bool hidden() { return hidden_; }
48 // JavaScript callbacks:
49 void HideCallback();
51 private:
52 // RenderFrameObserver methods:
53 void OnDestruct() override;
55 blink::WebLocalFrame* frame_;
56 blink::WebPluginParams plugin_params_;
57 WebViewPlugin* plugin_;
59 bool hidden_;
61 DISALLOW_COPY_AND_ASSIGN(PluginPlaceholderBase);
64 // A basic placeholder that supports only hiding.
65 class PluginPlaceholder final : public PluginPlaceholderBase,
66 public gin::Wrappable<PluginPlaceholder> {
67 public:
68 static gin::WrapperInfo kWrapperInfo;
70 PluginPlaceholder(content::RenderFrame* render_frame,
71 blink::WebLocalFrame* frame,
72 const blink::WebPluginParams& params,
73 const std::string& html_data);
74 ~PluginPlaceholder() override;
76 private:
77 // WebViewPlugin::Delegate methods:
78 v8::Local<v8::Value> GetV8Handle(v8::Isolate* isolate) final;
80 // gin::Wrappable method:
81 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
82 v8::Isolate* isolate) override;
85 } // namespace plugins
87 #endif // COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_