| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 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 WEBKIT_GLUE_PLUGINS_WEBVIEW_PLUGIN_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_WEBVIEW_PLUGIN_H_ |
| 7 |
| 8 #include "base/scoped_ptr.h" |
| 9 #include "base/task.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebFrameClient.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebViewClient.h" |
| 14 |
| 15 // This class implements the WebPlugin interface by forwarding drawing and |
| 16 // handling input events to a WebView. |
| 17 // It can be used as a placeholder for an actual plugin, using HTML for the UI. |
| 18 // To show HTML data inside the WebViewPlugin, |
| 19 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake |
| 20 // chrome:// URL as origin. |
| 21 |
| 22 class WebViewPlugin: public WebKit::WebPlugin, public WebKit::WebViewClient, |
| 23 public WebKit::WebFrameClient { |
| 24 public: |
| 25 class Delegate { |
| 26 public: |
| 27 // Bind |frame| to a Javascript object, enabling the delegate to receive |
| 28 // callback methods from Javascript inside the WebFrame. |
| 29 // This method is called from WebFrameClient::didClearWindowObject. |
| 30 virtual void BindWebFrame(WebKit::WebFrame* frame) = 0; |
| 31 |
| 32 // Called before the WebViewPlugin is destroyed. The delegate should delete |
| 33 // itself here. |
| 34 virtual void WillDestroyPlugin() = 0; |
| 35 }; |
| 36 |
| 37 explicit WebViewPlugin(Delegate* delegate); |
| 38 |
| 39 virtual WebKit::WebView* web_view() { return web_view_; } |
| 40 |
| 41 virtual WebKit::WebPluginContainer* container() { return container_; } |
| 42 |
| 43 // WebPlugin methods: |
| 44 virtual bool initialize(WebKit::WebPluginContainer*); |
| 45 virtual void destroy(); |
| 46 |
| 47 virtual NPObject* scriptableObject() { return NULL; } |
| 48 |
| 49 virtual void paint(WebKit::WebCanvas* canvas, const WebKit::WebRect& rect); |
| 50 |
| 51 // Coordinates are relative to the containing window. |
| 52 virtual void updateGeometry( |
| 53 const WebKit::WebRect& frame_rect, const WebKit::WebRect& clip_rect, |
| 54 const WebKit::WebVector<WebKit::WebRect>& cut_out_rects, bool is_visible); |
| 55 |
| 56 virtual void updateFocus(bool) { } |
| 57 virtual void updateVisibility(bool) { } |
| 58 |
| 59 virtual bool acceptsInputEvents() { return true; } |
| 60 virtual bool handleInputEvent(const WebKit::WebInputEvent& event, |
| 61 WebKit::WebCursorInfo& cursor_info); |
| 62 |
| 63 virtual void didReceiveResponse(const WebKit::WebURLResponse& response) { } |
| 64 virtual void didReceiveData(const char* data, int data_length) { } |
| 65 virtual void didFinishLoading() { } |
| 66 virtual void didFailLoading(const WebKit::WebURLError& error) { } |
| 67 |
| 68 // Called in response to WebPluginContainer::loadFrameRequest |
| 69 virtual void didFinishLoadingFrameRequest( |
| 70 const WebKit::WebURL& url, void* notifyData) { } |
| 71 virtual void didFailLoadingFrameRequest(const WebKit::WebURL& url, |
| 72 void* notify_data, |
| 73 const WebKit::WebURLError& error) { } |
| 74 |
| 75 // WebViewClient methods: |
| 76 virtual bool acceptsLoadDrops() { return false; } |
| 77 |
| 78 virtual void startDragging(const WebKit::WebDragData& drag_data, |
| 79 WebKit::WebDragOperationsMask mask, |
| 80 const WebKit::WebImage& image, |
| 81 const WebKit::WebPoint& point); |
| 82 |
| 83 // WebWidgetClient methods: |
| 84 virtual void didInvalidateRect(const WebKit::WebRect&); |
| 85 virtual void didChangeCursor(const WebKit::WebCursorInfo& cursor); |
| 86 |
| 87 // WebFrameClient methods: |
| 88 virtual void didClearWindowObject(WebKit::WebFrame* frame); |
| 89 |
| 90 virtual bool canHandleRequest(WebKit::WebFrame* frame, |
| 91 const WebKit::WebURLRequest& request); |
| 92 |
| 93 virtual WebKit::WebURLError cancelledError( |
| 94 WebKit::WebFrame* frame, const WebKit::WebURLRequest& request); |
| 95 |
| 96 private: |
| 97 friend class DeleteTask<WebViewPlugin>; |
| 98 virtual ~WebViewPlugin(); |
| 99 |
| 100 Delegate* delegate_; |
| 101 WebKit::WebCursorInfo current_cursor_; |
| 102 WebKit::WebPluginContainer* container_; |
| 103 WebKit::WebView* web_view_; |
| 104 gfx::Rect rect_; |
| 105 }; |
| 106 |
| 107 #endif // WEBKIT_GLUE_PLUGINS_WEBVIEW_PLUGIN_H_ |
| OLD | NEW |