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. 4 5 #ifndef COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ 6 #define COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ 7 8 #include "components/plugins/renderer/webview_plugin.h" 9 #include "content/public/common/webplugininfo.h" 10 #include "content/public/renderer/context_menu_client.h" 11 #include "content/public/renderer/render_frame_observer.h" 12 #include "content/public/renderer/render_process_observer.h" 13 #include "gin/wrappable.h" 14 #include "third_party/WebKit/public/web/WebPluginParams.h" 15 16 namespace content { 17 struct WebPluginInfo; 18 } 19 20 namespace plugins { 21 // Placeholders can be used if a plug-in is missing or not available 22 // (blocked or disabled). 23 class PluginPlaceholder : public content::RenderFrameObserver, 24 public WebViewPlugin::Delegate, 25 public gin::Wrappable<PluginPlaceholder> { 26 public: 27 static gin::WrapperInfo kWrapperInfo; 28 plugin()29 WebViewPlugin* plugin() { return plugin_; } 30 set_blocked_for_prerendering(bool blocked_for_prerendering)31 void set_blocked_for_prerendering(bool blocked_for_prerendering) { 32 is_blocked_for_prerendering_ = blocked_for_prerendering; 33 } 34 set_allow_loading(bool allow_loading)35 void set_allow_loading(bool allow_loading) { allow_loading_ = allow_loading; } 36 37 protected: 38 // |render_frame| and |frame| are weak pointers. If either one is going away, 39 // our |plugin_| will be destroyed as well and will notify us. 40 PluginPlaceholder(content::RenderFrame* render_frame, 41 blink::WebLocalFrame* frame, 42 const blink::WebPluginParams& params, 43 const std::string& html_data, 44 GURL placeholderDataUrl); 45 46 virtual ~PluginPlaceholder(); 47 48 void OnLoadBlockedPlugins(const std::string& identifier); 49 void OnSetIsPrerendering(bool is_prerendering); 50 51 void SetMessage(const base::string16& message); 52 void SetPluginInfo(const content::WebPluginInfo& plugin_info); 53 const content::WebPluginInfo& GetPluginInfo() const; 54 void SetIdentifier(const std::string& identifier); 55 blink::WebLocalFrame* GetFrame(); 56 const blink::WebPluginParams& GetPluginParams() const; LoadingAllowed()57 bool LoadingAllowed() const { return allow_loading_; } 58 59 // Replace this placeholder with a different plugin (which could be 60 // a placeholder again). 61 void ReplacePlugin(blink::WebPlugin* new_plugin); 62 63 // Hide this placeholder. 64 void HidePlugin(); 65 66 // Load the blocked plugin. 67 void LoadPlugin(); 68 69 // gin::Wrappable method: 70 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( 71 v8::Isolate* isolate) OVERRIDE; 72 73 private: 74 // WebViewPlugin::Delegate methods: 75 virtual void ShowContextMenu(const blink::WebMouseEvent&) OVERRIDE; 76 virtual void PluginDestroyed() OVERRIDE; 77 78 // RenderFrameObserver methods: 79 virtual void OnDestruct() OVERRIDE; 80 81 // Javascript callbacks: 82 83 // Load the blocked plugin by calling LoadPlugin(). 84 void LoadCallback(); 85 86 // Hide the blocked plugin by calling HidePlugin(). 87 void HideCallback(); 88 89 void DidFinishLoadingCallback(); 90 91 void UpdateMessage(); 92 93 blink::WebLocalFrame* frame_; 94 blink::WebPluginParams plugin_params_; 95 WebViewPlugin* plugin_; 96 97 content::WebPluginInfo plugin_info_; 98 99 base::string16 message_; 100 101 // True iff the plugin was blocked because the page was being prerendered. 102 // Plugin will automatically be loaded when the page is displayed. 103 bool is_blocked_for_prerendering_; 104 bool allow_loading_; 105 106 bool hidden_; 107 bool finished_loading_; 108 std::string identifier_; 109 110 DISALLOW_COPY_AND_ASSIGN(PluginPlaceholder); 111 }; 112 113 } // namespace plugins 114 115 #endif // COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ 116