Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / components / plugins / renderer / webview_plugin.h
blob2636089ee1dbaa55e8bd05338bd864c44a051974
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.
5 #ifndef COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_
6 #define COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_
8 #include <list>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/sequenced_task_runner_helpers.h"
12 #include "content/public/renderer/render_view_observer.h"
13 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/platform/WebURLResponse.h"
16 #include "third_party/WebKit/public/web/WebFrameClient.h"
17 #include "third_party/WebKit/public/web/WebKit.h"
18 #include "third_party/WebKit/public/web/WebPlugin.h"
19 #include "third_party/WebKit/public/web/WebViewClient.h"
21 namespace blink {
22 class WebMouseEvent;
25 namespace content {
26 class RenderView;
27 struct WebPreferences;
30 namespace gfx {
31 class Size;
34 // This class implements the WebPlugin interface by forwarding drawing and
35 // handling input events to a WebView.
36 // It can be used as a placeholder for an actual plugin, using HTML for the UI.
37 // To show HTML data inside the WebViewPlugin,
38 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake
39 // chrome:// URL as origin.
41 class WebViewPlugin : public blink::WebPlugin,
42 public blink::WebViewClient,
43 public blink::WebFrameClient,
44 public content::RenderViewObserver {
45 public:
46 class Delegate {
47 public:
48 // Called to get the V8 handle used to bind the lifetime to the frame.
49 virtual v8::Local<v8::Value> GetV8Handle(v8::Isolate*) = 0;
51 // Called upon a context menu event.
52 virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0;
54 // Called when the WebViewPlugin is destroyed.
55 virtual void PluginDestroyed() = 0;
57 // Called to enable JavaScript pass-through to a throttled plugin, which is
58 // loaded but idle. Doesn't work for blocked plugins, which is not loaded.
59 virtual v8::Local<v8::Object> GetV8ScriptableObject(v8::Isolate*) const = 0;
61 // Called when the unobscured rect of the plugin is updated.
62 virtual void OnUnobscuredRectUpdate(const gfx::Rect& unobscured_rect) {}
65 // Convenience method to set up a new WebViewPlugin using |preferences|
66 // and displaying |html_data|. |url| should be a (fake) data:text/html URL;
67 // it is only used for navigation and never actually resolved.
68 static WebViewPlugin* Create(content::RenderView* render_view,
69 Delegate* delegate,
70 const content::WebPreferences& preferences,
71 const std::string& html_data,
72 const GURL& url);
74 blink::WebView* web_view() { return web_view_; }
76 // When loading a plugin document (i.e. a full page plugin not embedded in
77 // another page), we save all data that has been received, and replay it with
78 // this method on the actual plugin.
79 void ReplayReceivedData(blink::WebPlugin* plugin);
81 void RestoreTitleText();
83 // WebPlugin methods:
84 virtual blink::WebPluginContainer* container() const;
85 virtual bool initialize(blink::WebPluginContainer*);
86 virtual void destroy();
88 virtual v8::Local<v8::Object> v8ScriptableObject(v8::Isolate* isolate);
90 virtual void layoutIfNeeded() override;
91 virtual void paint(blink::WebCanvas* canvas,
92 const blink::WebRect& rect) override;
94 // Coordinates are relative to the containing window.
95 virtual void updateGeometry(
96 const blink::WebRect& window_rect,
97 const blink::WebRect& clip_rect,
98 const blink::WebRect& unobscured_rect,
99 const blink::WebVector<blink::WebRect>& cut_outs_rects,
100 bool is_visible);
102 virtual void updateFocus(bool foucsed, blink::WebFocusType focus_type);
103 virtual void updateVisibility(bool) {}
105 virtual bool acceptsInputEvents();
106 virtual bool handleInputEvent(const blink::WebInputEvent& event,
107 blink::WebCursorInfo& cursor_info);
109 virtual void didReceiveResponse(const blink::WebURLResponse& response);
110 virtual void didReceiveData(const char* data, int data_length);
111 virtual void didFinishLoading();
112 virtual void didFailLoading(const blink::WebURLError& error);
114 // Called in response to WebPluginContainer::loadFrameRequest
115 virtual void didFinishLoadingFrameRequest(const blink::WebURL& url,
116 void* notifyData) {}
117 virtual void didFailLoadingFrameRequest(const blink::WebURL& url,
118 void* notify_data,
119 const blink::WebURLError& error) {}
121 // WebViewClient methods:
122 virtual bool acceptsLoadDrops();
124 virtual void setToolTipText(const blink::WebString&,
125 blink::WebTextDirection);
127 virtual void startDragging(blink::WebLocalFrame* frame,
128 const blink::WebDragData& drag_data,
129 blink::WebDragOperationsMask mask,
130 const blink::WebImage& image,
131 const blink::WebPoint& point);
133 // TODO(ojan): Remove this override and have this class use a non-null
134 // layerTreeView.
135 virtual bool allowsBrokenNullLayerTreeView() const;
137 // WebWidgetClient methods:
138 virtual void didInvalidateRect(const blink::WebRect&);
139 virtual void didUpdateLayoutSize(const blink::WebSize&);
140 virtual void didChangeCursor(const blink::WebCursorInfo& cursor);
141 virtual void scheduleAnimation();
143 // WebFrameClient methods:
144 virtual void didClearWindowObject(blink::WebLocalFrame* frame);
146 // This method is defined in WebPlugin as well as in WebFrameClient, but with
147 // different parameters. We only care about implementing the WebPlugin
148 // version, so we implement this method and call the default in WebFrameClient
149 // (which does nothing) to correctly overload it.
150 virtual void didReceiveResponse(blink::WebLocalFrame* frame,
151 unsigned identifier,
152 const blink::WebURLResponse& response);
154 private:
155 friend class base::DeleteHelper<WebViewPlugin>;
156 WebViewPlugin(content::RenderView* render_view,
157 Delegate* delegate,
158 const content::WebPreferences& preferences);
159 virtual ~WebViewPlugin();
161 // content::RenderViewObserver methods:
162 void OnDestruct() override;
163 void OnZoomLevelChanged() override;
165 // Manages its own lifetime.
166 Delegate* delegate_;
168 blink::WebCursorInfo current_cursor_;
170 // Owns us.
171 blink::WebPluginContainer* container_;
173 // Owned by us, deleted via |close()|.
174 blink::WebView* web_view_;
176 // Owned by us, deleted via |close()|.
177 blink::WebFrame* web_frame_;
178 gfx::Rect rect_;
180 blink::WebURLResponse response_;
181 std::list<std::string> data_;
182 scoped_ptr<blink::WebURLError> error_;
183 blink::WebString old_title_;
184 bool finished_loading_;
185 bool focused_;
188 #endif // COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_