| 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_WEBVIEW_PLUGIN_H_ | 5 #ifndef COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ |
| 6 #define COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ | 6 #define COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/sequenced_task_runner_helpers.h" | 11 #include "base/sequenced_task_runner_helpers.h" |
| 12 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 12 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| 13 #include "third_party/WebKit/public/platform/WebString.h" | 13 #include "third_party/WebKit/public/platform/WebString.h" |
| 14 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 14 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 15 #include "third_party/WebKit/public/web/WebFrameClient.h" | 15 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 16 #include "third_party/WebKit/public/web/WebPlugin.h" | 16 #include "third_party/WebKit/public/web/WebPlugin.h" |
| 17 #include "third_party/WebKit/public/web/WebViewClient.h" | 17 #include "third_party/WebKit/public/web/WebViewClient.h" |
| 18 | 18 |
| 19 struct WebPreferences; | |
| 20 | |
| 21 namespace blink { | 19 namespace blink { |
| 22 class WebMouseEvent; | 20 class WebMouseEvent; |
| 23 } | 21 } |
| 24 | 22 |
| 23 namespace content { |
| 24 class RenderView; |
| 25 struct WebPreferences; |
| 26 } |
| 27 |
| 25 // This class implements the WebPlugin interface by forwarding drawing and | 28 // This class implements the WebPlugin interface by forwarding drawing and |
| 26 // handling input events to a WebView. | 29 // handling input events to a WebView. |
| 27 // It can be used as a placeholder for an actual plugin, using HTML for the UI. | 30 // It can be used as a placeholder for an actual plugin, using HTML for the UI. |
| 28 // To show HTML data inside the WebViewPlugin, | 31 // To show HTML data inside the WebViewPlugin, |
| 29 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake | 32 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake |
| 30 // chrome:// URL as origin. | 33 // chrome:// URL as origin. |
| 31 | 34 |
| 32 class WebViewPlugin : public blink::WebPlugin, | 35 class WebViewPlugin : public blink::WebPlugin, |
| 33 public blink::WebViewClient, | 36 public blink::WebViewClient, |
| 34 public blink::WebFrameClient { | 37 public blink::WebFrameClient { |
| 35 public: | 38 public: |
| 36 class Delegate { | 39 class Delegate { |
| 37 public: | 40 public: |
| 38 // Bind |frame| to a Javascript object, enabling the delegate to receive | 41 // Bind |frame| to a Javascript object, enabling the delegate to receive |
| 39 // callback methods from Javascript inside the WebFrame. | 42 // callback methods from Javascript inside the WebFrame. |
| 40 // This method is called from WebFrameClient::didClearWindowObject. | 43 // This method is called from WebFrameClient::didClearWindowObject. |
| 41 virtual void BindWebFrame(blink::WebFrame* frame) = 0; | 44 virtual void BindWebFrame(blink::WebFrame* frame) = 0; |
| 42 | 45 |
| 43 // Called upon a context menu event. | 46 // Called upon a context menu event. |
| 44 virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0; | 47 virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0; |
| 45 | 48 |
| 46 // Called when the WebViewPlugin is destroyed. | 49 // Called when the WebViewPlugin is destroyed. |
| 47 virtual void PluginDestroyed() = 0; | 50 virtual void PluginDestroyed() = 0; |
| 48 }; | 51 }; |
| 49 | 52 |
| 50 // Convenience method to set up a new WebViewPlugin using |preferences| | 53 // Convenience method to set up a new WebViewPlugin using |preferences| |
| 51 // and displaying |html_data|. |url| should be a (fake) chrome:// URL; it is | 54 // and displaying |html_data|. |url| should be a (fake) chrome:// URL; it is |
| 52 // only used for navigation and never actually resolved. | 55 // only used for navigation and never actually resolved. |
| 53 static WebViewPlugin* Create(Delegate* delegate, | 56 static WebViewPlugin* Create(Delegate* delegate, |
| 54 const WebPreferences& preferences, | 57 const content::WebPreferences& preferences, |
| 55 const std::string& html_data, | 58 const std::string& html_data, |
| 56 const GURL& url); | 59 const GURL& url); |
| 57 | 60 |
| 58 blink::WebView* web_view() { return web_view_; } | 61 blink::WebView* web_view() { return web_view_; } |
| 59 | 62 |
| 60 // When loading a plug-in document (i.e. a full page plug-in not embedded in | 63 // When loading a plug-in document (i.e. a full page plug-in not embedded in |
| 61 // another page), we save all data that has been received, and replay it with | 64 // another page), we save all data that has been received, and replay it with |
| 62 // this method on the actual plug-in. | 65 // this method on the actual plug-in. |
| 63 void ReplayReceivedData(blink::WebPlugin* plugin); | 66 void ReplayReceivedData(blink::WebPlugin* plugin); |
| 64 | 67 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // This method is defined in WebPlugin as well as in WebFrameClient, but with | 131 // This method is defined in WebPlugin as well as in WebFrameClient, but with |
| 129 // different parameters. We only care about implementing the WebPlugin | 132 // different parameters. We only care about implementing the WebPlugin |
| 130 // version, so we implement this method and call the default in WebFrameClient | 133 // version, so we implement this method and call the default in WebFrameClient |
| 131 // (which does nothing) to correctly overload it. | 134 // (which does nothing) to correctly overload it. |
| 132 virtual void didReceiveResponse(blink::WebLocalFrame* frame, | 135 virtual void didReceiveResponse(blink::WebLocalFrame* frame, |
| 133 unsigned identifier, | 136 unsigned identifier, |
| 134 const blink::WebURLResponse& response); | 137 const blink::WebURLResponse& response); |
| 135 | 138 |
| 136 private: | 139 private: |
| 137 friend class base::DeleteHelper<WebViewPlugin>; | 140 friend class base::DeleteHelper<WebViewPlugin>; |
| 138 WebViewPlugin(Delegate* delegate, const WebPreferences& preferences); | 141 WebViewPlugin(Delegate* delegate, const content::WebPreferences& preferences); |
| 139 virtual ~WebViewPlugin(); | 142 virtual ~WebViewPlugin(); |
| 140 | 143 |
| 141 // Manages its own lifetime. | 144 // Manages its own lifetime. |
| 142 Delegate* delegate_; | 145 Delegate* delegate_; |
| 143 | 146 |
| 144 blink::WebCursorInfo current_cursor_; | 147 blink::WebCursorInfo current_cursor_; |
| 145 | 148 |
| 146 // Owns us. | 149 // Owns us. |
| 147 blink::WebPluginContainer* container_; | 150 blink::WebPluginContainer* container_; |
| 148 | 151 |
| 149 // Owned by us, deleted via |close()|. | 152 // Owned by us, deleted via |close()|. |
| 150 blink::WebView* web_view_; | 153 blink::WebView* web_view_; |
| 151 | 154 |
| 152 // Owned by us, deleted via |close()|. | 155 // Owned by us, deleted via |close()|. |
| 153 blink::WebFrame* web_frame_; | 156 blink::WebFrame* web_frame_; |
| 154 gfx::Rect rect_; | 157 gfx::Rect rect_; |
| 155 | 158 |
| 156 blink::WebURLResponse response_; | 159 blink::WebURLResponse response_; |
| 157 std::list<std::string> data_; | 160 std::list<std::string> data_; |
| 158 bool finished_loading_; | 161 bool finished_loading_; |
| 159 scoped_ptr<blink::WebURLError> error_; | 162 scoped_ptr<blink::WebURLError> error_; |
| 160 blink::WebString old_title_; | 163 blink::WebString old_title_; |
| 161 bool focused_; | 164 bool focused_; |
| 162 }; | 165 }; |
| 163 | 166 |
| 164 #endif // COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ | 167 #endif // COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ |
| OLD | NEW |