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 <string> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/weak_ptr.h" | |
8 #include "components/plugins/renderer/webview_plugin.h" | 12 #include "components/plugins/renderer/webview_plugin.h" |
9 #include "content/public/common/webplugininfo.h" | 13 #include "content/public/common/webplugininfo.h" |
10 #include "content/public/renderer/context_menu_client.h" | 14 #include "content/public/renderer/context_menu_client.h" |
11 #include "content/public/renderer/render_process_observer.h" | 15 #include "content/public/renderer/render_process_observer.h" |
12 #include "content/public/renderer/render_view_observer.h" | 16 #include "content/public/renderer/render_view_observer.h" |
13 #include "third_party/WebKit/public/web/WebPluginParams.h" | 17 #include "third_party/WebKit/public/web/WebPluginParams.h" |
14 #include "webkit/renderer/cpp_bound_class.h" | 18 #include "v8/include/v8.h" |
15 | 19 |
16 namespace content { | 20 namespace content { |
17 struct WebPluginInfo; | 21 struct WebPluginInfo; |
18 } | 22 } |
19 | 23 |
20 namespace plugins { | 24 namespace plugins { |
21 // Placeholders can be used if a plug-in is missing or not available | 25 // Placeholders can be used if a plug-in is missing or not available |
22 // (blocked or disabled). | 26 // (blocked or disabled). |
23 class PluginPlaceholder : public content::RenderViewObserver, | 27 class PluginPlaceholder : public content::RenderViewObserver, |
24 public webkit_glue::CppBoundClass, | |
25 public WebViewPlugin::Delegate { | 28 public WebViewPlugin::Delegate { |
26 public: | 29 public: |
27 | 30 |
28 WebViewPlugin* plugin() { return plugin_; } | 31 WebViewPlugin* plugin() { return plugin_; } |
29 | 32 |
30 void set_blocked_for_prerendering(bool blocked_for_prerendering) { | 33 void set_blocked_for_prerendering(bool blocked_for_prerendering) { |
31 is_blocked_for_prerendering_ = blocked_for_prerendering; | 34 is_blocked_for_prerendering_ = blocked_for_prerendering; |
32 } | 35 } |
33 | 36 |
34 void set_allow_loading(bool allow_loading) { allow_loading_ = allow_loading; } | 37 void set_allow_loading(bool allow_loading) { allow_loading_ = allow_loading; } |
35 | 38 |
36 protected: | 39 protected: |
37 // |render_view| and |frame| are weak pointers. If either one is going away, | 40 // |render_view| and |frame| are weak pointers. If either one is going away, |
38 // our |plugin_| will be destroyed as well and will notify us. | 41 // our |plugin_| will be destroyed as well and will notify us. |
39 PluginPlaceholder(content::RenderView* render_view, | 42 PluginPlaceholder(content::RenderView* render_view, |
40 blink::WebFrame* frame, | 43 blink::WebFrame* frame, |
41 const blink::WebPluginParams& params, | 44 const blink::WebPluginParams& params, |
42 const std::string& html_data, | 45 const std::string& html_data, |
43 GURL placeholderDataUrl); | 46 GURL placeholderDataUrl); |
44 | 47 |
45 virtual ~PluginPlaceholder(); | 48 virtual ~PluginPlaceholder(); |
46 | 49 |
50 // Derived classes should invoke this method to install additional callbacks | |
51 // on the window.plugin object. When the callbacks are invoked, the Observe() | |
Bernhard Bauer
2013/11/14 16:25:43
Nit: This sentence reads a bit weird. How about, "
jochen (gone - plz use gerrit)
2013/11/15 10:09:39
Done.
| |
52 // method will be invoked. | |
53 void RegisterCallback(const std::string& callback); | |
54 | |
55 virtual void Observe(const std::string& callback); | |
Bernhard Bauer
2013/11/14 16:25:43
Nit: add a comment
jochen (gone - plz use gerrit)
2013/11/15 10:09:39
Done.
| |
56 | |
47 void OnLoadBlockedPlugins(const std::string& identifier); | 57 void OnLoadBlockedPlugins(const std::string& identifier); |
48 void OnSetIsPrerendering(bool is_prerendering); | 58 void OnSetIsPrerendering(bool is_prerendering); |
49 | 59 |
50 void SetMessage(const string16& message); | 60 void SetMessage(const string16& message); |
51 void SetPluginInfo(const content::WebPluginInfo& plugin_info); | 61 void SetPluginInfo(const content::WebPluginInfo& plugin_info); |
52 const content::WebPluginInfo& GetPluginInfo() const; | 62 const content::WebPluginInfo& GetPluginInfo() const; |
53 void SetIdentifier(const std::string& identifier); | 63 void SetIdentifier(const std::string& identifier); |
54 blink::WebFrame* GetFrame(); | 64 blink::WebFrame* GetFrame(); |
55 const blink::WebPluginParams& GetPluginParams() const; | 65 const blink::WebPluginParams& GetPluginParams() const; |
56 bool LoadingAllowed() const { return allow_loading_; } | 66 bool LoadingAllowed() const { return allow_loading_; } |
57 | 67 |
58 // Replace this placeholder with a different plugin (which could be | 68 // Replace this placeholder with a different plugin (which could be |
59 // a placeholder again). | 69 // a placeholder again). |
60 void ReplacePlugin(blink::WebPlugin* new_plugin); | 70 void ReplacePlugin(blink::WebPlugin* new_plugin); |
61 | 71 |
62 // Hide this placeholder. | 72 // Hide this placeholder. |
63 void HidePlugin(); | 73 void HidePlugin(); |
64 | 74 |
65 // Load the blocked plugin. | 75 // Load the blocked plugin. |
66 void LoadPlugin(); | 76 void LoadPlugin(); |
67 | 77 |
68 // WebViewPlugin::Delegate method: | 78 // WebViewPlugin::Delegate method: |
69 virtual void BindWebFrame(blink::WebFrame* frame) OVERRIDE; | 79 virtual void BindWebFrame(blink::WebFrame* frame) OVERRIDE; |
70 | 80 |
71 private: | 81 private: |
72 // WebViewPlugin::Delegate methods: | 82 // WebViewPlugin::Delegate methods: |
73 virtual void WillDestroyPlugin() OVERRIDE; | 83 virtual void WillDestroyPlugin() OVERRIDE; |
74 virtual void ShowContextMenu(const blink::WebMouseEvent&) OVERRIDE; | 84 virtual void ShowContextMenu(const blink::WebMouseEvent&) OVERRIDE; |
75 | 85 |
76 // Javascript callbacks: | 86 void InternalObserve(const std::string& callback); |
77 // All ignore arguments (which are, however, required by caller) and return | |
78 // nothing. | |
79 | |
80 // Load the blocked plugin by calling LoadPlugin(). | |
81 void LoadCallback(const webkit_glue::CppArgumentList& args, | |
82 webkit_glue::CppVariant* result); | |
83 | |
84 // Hide the blocked plugin by calling HidePlugin(). | |
85 void HideCallback(const webkit_glue::CppArgumentList& args, | |
86 webkit_glue::CppVariant* result); | |
87 | |
88 void DidFinishLoadingCallback(const webkit_glue::CppArgumentList& args, | |
89 webkit_glue::CppVariant* result); | |
90 | 87 |
91 void UpdateMessage(); | 88 void UpdateMessage(); |
92 | 89 |
93 blink::WebFrame* frame_; | 90 blink::WebFrame* frame_; |
94 blink::WebPluginParams plugin_params_; | 91 blink::WebPluginParams plugin_params_; |
95 WebViewPlugin* plugin_; | 92 WebViewPlugin* plugin_; |
96 | 93 |
97 content::WebPluginInfo plugin_info_; | 94 content::WebPluginInfo plugin_info_; |
98 | 95 |
99 string16 message_; | 96 string16 message_; |
100 | 97 |
101 // True iff the plugin was blocked because the page was being prerendered. | 98 // True iff the plugin was blocked because the page was being prerendered. |
102 // Plugin will automatically be loaded when the page is displayed. | 99 // Plugin will automatically be loaded when the page is displayed. |
103 bool is_blocked_for_prerendering_; | 100 bool is_blocked_for_prerendering_; |
104 bool allow_loading_; | 101 bool allow_loading_; |
105 | 102 |
106 bool hidden_; | 103 bool hidden_; |
107 bool finished_loading_; | 104 bool finished_loading_; |
108 std::string identifier_; | 105 std::string identifier_; |
109 | 106 |
107 std::vector<std::string> callbacks_; | |
108 | |
109 base::WeakPtrFactory<PluginPlaceholder> weak_factory_; | |
110 | |
110 DISALLOW_COPY_AND_ASSIGN(PluginPlaceholder); | 111 DISALLOW_COPY_AND_ASSIGN(PluginPlaceholder); |
111 }; | 112 }; |
112 | 113 |
113 } // namespace plugins | 114 } // namespace plugins |
114 | 115 |
115 #endif // COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ | 116 #endif // COMPONENTS_PLUGINS_RENDERER_PLUGIN_PLACEHOLDER_H_ |
OLD | NEW |