Android Chromoting: Remove exit-fullscreen button.
[chromium-blink-merge.git] / components / plugins / renderer / webview_plugin.h
blobb65e204d212459952a83162849e86e553f952d04
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 "third_party/WebKit/public/platform/WebCursorInfo.h"
13 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/WebKit/public/platform/WebURLResponse.h"
15 #include "third_party/WebKit/public/web/WebFrameClient.h"
16 #include "third_party/WebKit/public/web/WebPlugin.h"
17 #include "third_party/WebKit/public/web/WebViewClient.h"
19 namespace blink {
20 class WebMouseEvent;
23 namespace content {
24 class RenderView;
25 struct WebPreferences;
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.
35 class WebViewPlugin : public blink::WebPlugin,
36 public blink::WebViewClient,
37 public blink::WebFrameClient {
38 public:
39 class Delegate {
40 public:
41 // Bind |frame| to a Javascript object, enabling the delegate to receive
42 // callback methods from Javascript inside the WebFrame.
43 // This method is called from WebFrameClient::didClearWindowObject.
44 virtual void BindWebFrame(blink::WebFrame* frame) = 0;
46 // Called upon a context menu event.
47 virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0;
49 // Called when the WebViewPlugin is destroyed.
50 virtual void PluginDestroyed() = 0;
53 // Convenience method to set up a new WebViewPlugin using |preferences|
54 // and displaying |html_data|. |url| should be a (fake) data:text/html URL;
55 // it is only used for navigation and never actually resolved.
56 static WebViewPlugin* Create(Delegate* delegate,
57 const content::WebPreferences& preferences,
58 const std::string& html_data,
59 const GURL& url);
61 blink::WebView* web_view() { return web_view_; }
63 // When loading a plugin document (i.e. a full page plugin not embedded in
64 // another page), we save all data that has been received, and replay it with
65 // this method on the actual plugin.
66 void ReplayReceivedData(blink::WebPlugin* plugin);
68 void RestoreTitleText();
70 // WebPlugin methods:
71 virtual blink::WebPluginContainer* container() const;
72 virtual bool initialize(blink::WebPluginContainer*);
73 virtual void destroy();
75 virtual NPObject* scriptableObject();
76 virtual struct _NPP* pluginNPP();
78 virtual bool getFormValue(blink::WebString& value);
80 virtual void paint(blink::WebCanvas* canvas, const blink::WebRect& rect);
82 // Coordinates are relative to the containing window.
83 virtual void updateGeometry(
84 const blink::WebRect& window_rect,
85 const blink::WebRect& clip_rect,
86 const blink::WebRect& unobscured_rect,
87 const blink::WebVector<blink::WebRect>& cut_outs_rects,
88 bool is_visible);
90 virtual void updateFocus(bool foucsed, blink::WebFocusType focus_type);
91 virtual void updateVisibility(bool) {}
93 virtual bool acceptsInputEvents();
94 virtual bool handleInputEvent(const blink::WebInputEvent& event,
95 blink::WebCursorInfo& cursor_info);
97 virtual void didReceiveResponse(const blink::WebURLResponse& response);
98 virtual void didReceiveData(const char* data, int data_length);
99 virtual void didFinishLoading();
100 virtual void didFailLoading(const blink::WebURLError& error);
102 // Called in response to WebPluginContainer::loadFrameRequest
103 virtual void didFinishLoadingFrameRequest(const blink::WebURL& url,
104 void* notifyData) {}
105 virtual void didFailLoadingFrameRequest(const blink::WebURL& url,
106 void* notify_data,
107 const blink::WebURLError& error) {}
109 // WebViewClient methods:
110 virtual bool acceptsLoadDrops();
112 virtual void setToolTipText(const blink::WebString&,
113 blink::WebTextDirection);
115 virtual void startDragging(blink::WebLocalFrame* frame,
116 const blink::WebDragData& drag_data,
117 blink::WebDragOperationsMask mask,
118 const blink::WebImage& image,
119 const blink::WebPoint& point);
121 // TODO(ojan): Remove this override and have this class use a non-null
122 // layerTreeView.
123 virtual bool allowsBrokenNullLayerTreeView() const;
125 // WebWidgetClient methods:
126 virtual void didInvalidateRect(const blink::WebRect&);
127 virtual void didChangeCursor(const blink::WebCursorInfo& cursor);
128 virtual void scheduleAnimation();
130 // WebFrameClient methods:
131 virtual void didClearWindowObject(blink::WebLocalFrame* frame);
133 // This method is defined in WebPlugin as well as in WebFrameClient, but with
134 // different parameters. We only care about implementing the WebPlugin
135 // version, so we implement this method and call the default in WebFrameClient
136 // (which does nothing) to correctly overload it.
137 virtual void didReceiveResponse(blink::WebLocalFrame* frame,
138 unsigned identifier,
139 const blink::WebURLResponse& response);
141 private:
142 friend class base::DeleteHelper<WebViewPlugin>;
143 WebViewPlugin(Delegate* delegate, const content::WebPreferences& preferences);
144 virtual ~WebViewPlugin();
146 // Manages its own lifetime.
147 Delegate* delegate_;
149 blink::WebCursorInfo current_cursor_;
151 // Owns us.
152 blink::WebPluginContainer* container_;
154 // Owned by us, deleted via |close()|.
155 blink::WebView* web_view_;
157 // Owned by us, deleted via |close()|.
158 blink::WebFrame* web_frame_;
159 gfx::Rect rect_;
161 blink::WebURLResponse response_;
162 std::list<std::string> data_;
163 bool finished_loading_;
164 scoped_ptr<blink::WebURLError> error_;
165 blink::WebString old_title_;
166 bool focused_;
169 #endif // COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_