| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ | 5 #ifndef COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ |
| 6 #define COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ | 6 #define COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "components/plugins/renderer/webview_plugin.h" | 9 #include "components/plugins/renderer/webview_plugin.h" |
| 10 #include "content/public/renderer/render_frame_observer.h" | 10 #include "content/public/renderer/render_frame_observer.h" |
| 11 #include "gin/handle.h" |
| 11 #include "gin/wrappable.h" | 12 #include "gin/wrappable.h" |
| 13 #include "third_party/WebKit/public/web/WebKit.h" |
| 12 #include "third_party/WebKit/public/web/WebPluginParams.h" | 14 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 13 | 15 |
| 14 namespace plugins { | 16 namespace plugins { |
| 15 | 17 |
| 16 class PluginPlaceholder : public content::RenderFrameObserver, | 18 // This abstract class is the base class of all plugin placeholders. |
| 17 public WebViewPlugin::Delegate, | 19 class PluginPlaceholderBase : public content::RenderFrameObserver, |
| 18 public gin::Wrappable<PluginPlaceholder> { | 20 public WebViewPlugin::Delegate { |
| 19 public: | 21 public: |
| 20 static gin::WrapperInfo kWrapperInfo; | 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); |
| 28 |
| 29 ~PluginPlaceholderBase() override; |
| 21 | 30 |
| 22 WebViewPlugin* plugin() { return plugin_; } | 31 WebViewPlugin* plugin() { return plugin_; } |
| 23 | 32 |
| 24 protected: | 33 protected: |
| 25 // |render_frame| and |frame| are weak pointers. If either one is going away, | |
| 26 // our |plugin_| will be destroyed as well and will notify us. | |
| 27 PluginPlaceholder(content::RenderFrame* render_frame, | |
| 28 blink::WebLocalFrame* frame, | |
| 29 const blink::WebPluginParams& params, | |
| 30 const std::string& html_data, | |
| 31 GURL placeholderDataUrl); | |
| 32 | |
| 33 ~PluginPlaceholder() override; | |
| 34 | |
| 35 blink::WebLocalFrame* GetFrame(); | 34 blink::WebLocalFrame* GetFrame(); |
| 36 const blink::WebPluginParams& GetPluginParams() const; | 35 const blink::WebPluginParams& GetPluginParams() const; |
| 37 | 36 |
| 38 // WebViewPlugin::Delegate methods: | 37 // WebViewPlugin::Delegate methods: |
| 39 void ShowContextMenu(const blink::WebMouseEvent&) override; | 38 void ShowContextMenu(const blink::WebMouseEvent&) override; |
| 40 void PluginDestroyed() override; | 39 void PluginDestroyed() override; |
| 41 v8::Local<v8::Object> GetV8ScriptableObject( | 40 v8::Local<v8::Object> GetV8ScriptableObject( |
| 42 v8::Isolate* isolate) const override; | 41 v8::Isolate* isolate) const override; |
| 43 | 42 |
| 43 protected: |
| 44 // Hide this placeholder. |
| 45 void HidePlugin(); |
| 46 bool hidden() { return hidden_; } |
| 47 |
| 48 // JavaScript callbacks: |
| 49 void HideCallback(); |
| 50 |
| 44 private: | 51 private: |
| 45 // RenderFrameObserver methods: | 52 // RenderFrameObserver methods: |
| 46 void OnDestruct() override; | 53 void OnDestruct() override; |
| 47 | 54 |
| 48 blink::WebLocalFrame* frame_; | 55 blink::WebLocalFrame* frame_; |
| 49 blink::WebPluginParams plugin_params_; | 56 blink::WebPluginParams plugin_params_; |
| 50 WebViewPlugin* plugin_; | 57 WebViewPlugin* plugin_; |
| 51 | 58 |
| 52 DISALLOW_COPY_AND_ASSIGN(PluginPlaceholder); | 59 bool hidden_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(PluginPlaceholderBase); |
| 62 }; |
| 63 |
| 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; |
| 69 |
| 70 PluginPlaceholder(content::RenderFrame* render_frame, |
| 71 blink::WebLocalFrame* frame, |
| 72 const blink::WebPluginParams& params, |
| 73 const std::string& html_data); |
| 74 ~PluginPlaceholder() override; |
| 75 |
| 76 private: |
| 77 // WebViewPlugin::Delegate methods: |
| 78 v8::Local<v8::Value> GetV8Handle(v8::Isolate* isolate) final; |
| 79 |
| 80 // gin::Wrappable method: |
| 81 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 82 v8::Isolate* isolate) override; |
| 53 }; | 83 }; |
| 54 | 84 |
| 55 } // namespace plugins | 85 } // namespace plugins |
| 56 | 86 |
| 57 #endif // COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ | 87 #endif // COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ |
| OLD | NEW |