OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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_PLUGINS_NPAPI_WEBVIEW_PLUGIN_H_ | |
6 #define WEBKIT_PLUGINS_NPAPI_WEBVIEW_PLUGIN_H_ | |
7 | |
8 #include <list> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/task.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" | |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | |
19 | |
20 namespace WebKit { | |
21 class WebMouseEvent; | |
22 } | |
23 struct WebPreferences; | |
24 | |
25 namespace webkit { | |
26 namespace npapi { | |
27 | |
28 // This class implements the WebPlugin interface by forwarding drawing and | |
29 // handling input events to a WebView. | |
30 // It can be used as a placeholder for an actual plugin, using HTML for the UI. | |
31 // To show HTML data inside the WebViewPlugin, | |
32 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake | |
33 // chrome:// URL as origin. | |
34 | |
35 class WebViewPlugin: public WebKit::WebPlugin, public WebKit::WebViewClient, | |
36 public WebKit::WebFrameClient { | |
37 public: | |
38 class Delegate { | |
39 public: | |
40 // Bind |frame| to a Javascript object, enabling the delegate to receive | |
41 // callback methods from Javascript inside the WebFrame. | |
42 // This method is called from WebFrameClient::didClearWindowObject. | |
43 virtual void BindWebFrame(WebKit::WebFrame* frame) = 0; | |
44 | |
45 // Called before the WebViewPlugin is destroyed. The delegate should delete | |
46 // itself here. | |
47 virtual void WillDestroyPlugin() = 0; | |
48 | |
49 // Called upon a context menu event. | |
50 virtual void ShowContextMenu(const WebKit::WebMouseEvent&) = 0; | |
51 }; | |
52 | |
53 explicit WebViewPlugin(Delegate* delegate); | |
54 | |
55 // Convenience method to set up a new WebViewPlugin using |preferences| | |
56 // and displaying |html_data|. |url| should be a (fake) chrome:// URL; it is | |
57 // only used for navigation and never actually resolved. | |
58 static WebViewPlugin* Create(Delegate* delegate, | |
59 const WebPreferences& preferences, | |
60 const std::string& html_data, | |
61 const GURL& url); | |
62 | |
63 WebKit::WebView* web_view() { return web_view_; } | |
64 | |
65 WebKit::WebPluginContainer* container() { return container_; } | |
66 | |
67 // When loading a plug-in document (i.e. a full page plug-in not embedded in | |
68 // another page), we save all data that has been received, and replay it with | |
69 // this method on the actual plug-in. | |
70 void ReplayReceivedData(WebKit::WebPlugin* plugin); | |
71 | |
72 void RestoreTitleText(); | |
73 | |
74 // WebPlugin methods: | |
75 virtual bool initialize(WebKit::WebPluginContainer*); | |
76 virtual void destroy(); | |
77 | |
78 virtual NPObject* scriptableObject(); | |
79 virtual bool getFormValue(WebKit::WebString* value); | |
80 | |
81 virtual void paint(WebKit::WebCanvas* canvas, const WebKit::WebRect& rect); | |
82 | |
83 // Coordinates are relative to the containing window. | |
84 virtual void updateGeometry( | |
85 const WebKit::WebRect& frame_rect, const WebKit::WebRect& clip_rect, | |
86 const WebKit::WebVector<WebKit::WebRect>& cut_out_rects, bool is_visible); | |
87 | |
88 virtual void updateFocus(bool) {} | |
89 virtual void updateVisibility(bool) {} | |
90 | |
91 virtual bool acceptsInputEvents(); | |
92 virtual bool handleInputEvent(const WebKit::WebInputEvent& event, | |
93 WebKit::WebCursorInfo& cursor_info); | |
94 | |
95 virtual void didReceiveResponse(const WebKit::WebURLResponse& response); | |
96 virtual void didReceiveData(const char* data, int data_length); | |
97 virtual void didFinishLoading(); | |
98 virtual void didFailLoading(const WebKit::WebURLError& error); | |
99 | |
100 // Called in response to WebPluginContainer::loadFrameRequest | |
101 virtual void didFinishLoadingFrameRequest( | |
102 const WebKit::WebURL& url, void* notifyData) {} | |
103 virtual void didFailLoadingFrameRequest(const WebKit::WebURL& url, | |
104 void* notify_data, | |
105 const WebKit::WebURLError& error) {} | |
106 | |
107 // WebViewClient methods: | |
108 virtual bool acceptsLoadDrops(); | |
109 | |
110 virtual void setToolTipText(const WebKit::WebString&, | |
111 WebKit::WebTextDirection); | |
112 | |
113 virtual void startDragging(const WebKit::WebDragData& drag_data, | |
114 WebKit::WebDragOperationsMask mask, | |
115 const WebKit::WebImage& image, | |
116 const WebKit::WebPoint& point); | |
117 | |
118 // WebWidgetClient methods: | |
119 virtual void didInvalidateRect(const WebKit::WebRect&); | |
120 virtual void didChangeCursor(const WebKit::WebCursorInfo& cursor); | |
121 | |
122 // WebFrameClient methods: | |
123 virtual void didClearWindowObject(WebKit::WebFrame* frame); | |
124 | |
125 virtual bool canHandleRequest(WebKit::WebFrame* frame, | |
126 const WebKit::WebURLRequest& request); | |
127 | |
128 virtual WebKit::WebURLError cancelledError( | |
129 WebKit::WebFrame* frame, const WebKit::WebURLRequest& request); | |
130 | |
131 // This method is defined in WebPlugin as well as in WebFrameClient, but with | |
132 // different parameters. We only care about implementing the WebPlugin | |
133 // version, so we implement this method and call the default in WebFrameClient | |
134 // (which does nothing) to correctly overload it. | |
135 virtual void didReceiveResponse(WebKit::WebFrame* frame, | |
136 unsigned identifier, | |
137 const WebKit::WebURLResponse& response); | |
138 | |
139 private: | |
140 friend class DeleteTask<WebViewPlugin>; | |
141 virtual ~WebViewPlugin(); | |
142 | |
143 Delegate* delegate_; | |
144 WebKit::WebCursorInfo current_cursor_; | |
145 WebKit::WebPluginContainer* container_; | |
146 WebKit::WebView* web_view_; | |
147 gfx::Rect rect_; | |
148 | |
149 WebKit::WebURLResponse response_; | |
150 std::list<std::string> data_; | |
151 bool finished_loading_; | |
152 scoped_ptr<WebKit::WebURLError> error_; | |
153 WebKit::WebString old_title_; | |
154 }; | |
155 | |
156 } // namespace npapi | |
157 } // namespace webkit | |
158 | |
159 #endif // WEBKIT_PLUGINS_NPAPI_WEBVIEW_PLUGIN_H_ | |
OLD | NEW |