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 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 // This class implements the WebPlugin interface by forwarding drawing and | 36 // This class implements the WebPlugin interface by forwarding drawing and |
37 // handling input events to a WebView. | 37 // handling input events to a WebView. |
38 // It can be used as a placeholder for an actual plugin, using HTML for the UI. | 38 // It can be used as a placeholder for an actual plugin, using HTML for the UI. |
39 // To show HTML data inside the WebViewPlugin, | 39 // To show HTML data inside the WebViewPlugin, |
40 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake | 40 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake |
41 // chrome:// URL as origin. | 41 // chrome:// URL as origin. |
42 | 42 |
43 class WebViewPlugin : public blink::WebPlugin, | 43 class WebViewPlugin : public blink::WebPlugin, |
44 public blink::WebViewClient, | 44 public blink::WebViewClient, |
45 public blink::WebFrameClient, | |
46 public content::RenderViewObserver { | 45 public content::RenderViewObserver { |
47 public: | 46 public: |
48 class Delegate { | 47 class Delegate { |
49 public: | 48 public: |
50 // Called to get the V8 handle used to bind the lifetime to the frame. | 49 // Called to get the V8 handle used to bind the lifetime to the frame. |
51 virtual v8::Local<v8::Value> GetV8Handle(v8::Isolate*) = 0; | 50 virtual v8::Local<v8::Value> GetV8Handle(v8::Isolate*) = 0; |
52 | 51 |
53 // Called upon a context menu event. | 52 // Called upon a context menu event. |
54 virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0; | 53 virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0; |
55 | 54 |
(...skipping 12 matching lines...) Expand all Loading... |
68 // and displaying |html_data|. |url| should be a (fake) data:text/html URL; | 67 // and displaying |html_data|. |url| should be a (fake) data:text/html URL; |
69 // it is only used for navigation and never actually resolved. | 68 // it is only used for navigation and never actually resolved. |
70 static WebViewPlugin* Create(content::RenderView* render_view, | 69 static WebViewPlugin* Create(content::RenderView* render_view, |
71 Delegate* delegate, | 70 Delegate* delegate, |
72 const content::WebPreferences& preferences, | 71 const content::WebPreferences& preferences, |
73 const std::string& html_data, | 72 const std::string& html_data, |
74 const GURL& url); | 73 const GURL& url); |
75 | 74 |
76 blink::WebView* web_view() { return web_view_; } | 75 blink::WebView* web_view() { return web_view_; } |
77 | 76 |
78 // When loading a plugin document (i.e. a full page plugin not embedded in | 77 bool focused() const { return focused_; } |
79 // another page), we save all data that has been received, and replay it with | 78 const blink::WebString& old_title() const { return old_title_; } |
80 // this method on the actual plugin. | |
81 void ReplayReceivedData(blink::WebPlugin* plugin); | |
82 | |
83 void RestoreTitleText(); | |
84 | 79 |
85 // WebPlugin methods: | 80 // WebPlugin methods: |
86 blink::WebPluginContainer* container() const override; | 81 blink::WebPluginContainer* container() const override; |
87 // The WebViewPlugin, by design, never fails to initialize. It's used to | 82 // The WebViewPlugin, by design, never fails to initialize. It's used to |
88 // display placeholders and error messages, so it must never fail. | 83 // display placeholders and error messages, so it must never fail. |
89 bool initialize(blink::WebPluginContainer*) override; | 84 bool initialize(blink::WebPluginContainer*) override; |
90 void destroy() override; | 85 void destroy() override; |
91 | 86 |
92 v8::Local<v8::Object> v8ScriptableObject(v8::Isolate* isolate) override; | 87 v8::Local<v8::Object> v8ScriptableObject(v8::Isolate* isolate) override; |
93 | 88 |
94 void updateAllLifecyclePhases() override; | 89 void updateAllLifecyclePhases() override; |
95 void paint(blink::WebCanvas* canvas, const blink::WebRect& rect) override; | 90 void paint(blink::WebCanvas* canvas, const blink::WebRect& rect) override; |
96 | 91 |
97 // Coordinates are relative to the containing window. | 92 // Coordinates are relative to the containing window. |
98 void updateGeometry(const blink::WebRect& window_rect, | 93 void updateGeometry(const blink::WebRect& window_rect, |
99 const blink::WebRect& clip_rect, | 94 const blink::WebRect& clip_rect, |
100 const blink::WebRect& unobscured_rect, | 95 const blink::WebRect& unobscured_rect, |
101 const blink::WebVector<blink::WebRect>& cut_outs_rects, | 96 const blink::WebVector<blink::WebRect>& cut_outs_rects, |
102 bool is_visible) override; | 97 bool is_visible) override; |
103 | 98 |
104 void updateFocus(bool foucsed, blink::WebFocusType focus_type) override; | 99 void updateFocus(bool foucsed, blink::WebFocusType focus_type) override; |
105 void updateVisibility(bool) override {} | 100 void updateVisibility(bool) override {} |
106 | 101 |
107 blink::WebInputEventResult handleInputEvent( | 102 blink::WebInputEventResult handleInputEvent( |
108 const blink::WebInputEvent& event, | 103 const blink::WebInputEvent& event, |
109 blink::WebCursorInfo& cursor_info) override; | 104 blink::WebCursorInfo& cursor_info) override; |
110 | 105 |
111 // didReceiveResponse() overrides both WebPlugin and WebFrameClient. | 106 void didReceiveResponse(const blink::WebURLResponse& response) override; |
112 // The WebFrameClient variant receives callbacks, but the WebPlugin variant | |
113 // shouldn't. | |
114 // TODO(japhet): WebViewPlugin shouldn't be a WebFrameClient, after which | |
115 // didReceiveResponse() should have a NOTREACHED(). | |
116 void didReceiveResponse(const blink::WebURLResponse& response) override {} | |
117 void didReceiveData(const char* data, int data_length) override; | 107 void didReceiveData(const char* data, int data_length) override; |
118 void didFinishLoading() override; | 108 void didFinishLoading() override; |
119 void didFailLoading(const blink::WebURLError& error) override; | 109 void didFailLoading(const blink::WebURLError& error) override; |
120 | 110 |
121 // WebViewClient methods: | 111 // WebViewClient methods: |
122 bool acceptsLoadDrops() override; | 112 bool acceptsLoadDrops() override; |
123 | 113 |
124 void setToolTipText(const blink::WebString&, | 114 void setToolTipText(const blink::WebString&, |
125 blink::WebTextDirection) override; | 115 blink::WebTextDirection) override; |
126 | 116 |
127 void startDragging(blink::WebLocalFrame* frame, | 117 void startDragging(blink::WebLocalFrame* frame, |
128 const blink::WebDragData& drag_data, | 118 const blink::WebDragData& drag_data, |
129 blink::WebDragOperationsMask mask, | 119 blink::WebDragOperationsMask mask, |
130 const blink::WebImage& image, | 120 const blink::WebImage& image, |
131 const blink::WebPoint& point) override; | 121 const blink::WebPoint& point) override; |
132 | 122 |
133 // TODO(ojan): Remove this override and have this class use a non-null | 123 // TODO(ojan): Remove this override and have this class use a non-null |
134 // layerTreeView. | 124 // layerTreeView. |
135 bool allowsBrokenNullLayerTreeView() const override; | 125 bool allowsBrokenNullLayerTreeView() const override; |
136 | 126 |
137 // WebWidgetClient methods: | 127 // WebWidgetClient methods: |
138 void didInvalidateRect(const blink::WebRect&) override; | 128 void didInvalidateRect(const blink::WebRect&) override; |
139 void didChangeCursor(const blink::WebCursorInfo& cursor) override; | 129 void didChangeCursor(const blink::WebCursorInfo& cursor) override; |
140 void scheduleAnimation() override; | 130 void scheduleAnimation() override; |
141 | 131 |
142 // WebFrameClient methods: | |
143 void didClearWindowObject(blink::WebLocalFrame* frame) override; | |
144 | |
145 private: | 132 private: |
146 friend class base::DeleteHelper<WebViewPlugin>; | 133 friend class base::DeleteHelper<WebViewPlugin>; |
147 WebViewPlugin(content::RenderView* render_view, | 134 WebViewPlugin(content::RenderView* render_view, |
148 Delegate* delegate, | 135 Delegate* delegate, |
149 const content::WebPreferences& preferences); | 136 const content::WebPreferences& preferences); |
150 ~WebViewPlugin() override; | 137 ~WebViewPlugin() override; |
151 | 138 |
152 // content::RenderViewObserver methods: | 139 // content::RenderViewObserver methods: |
153 void OnDestruct() override; | 140 void OnDestruct() override; |
154 void OnZoomLevelChanged() override; | 141 void OnZoomLevelChanged() override; |
(...skipping 12 matching lines...) Expand all Loading... |
167 // Owned by us, deleted via |close()|. | 154 // Owned by us, deleted via |close()|. |
168 blink::WebView* web_view_; | 155 blink::WebView* web_view_; |
169 | 156 |
170 // Owned by us, deleted via |close()|. | 157 // Owned by us, deleted via |close()|. |
171 blink::WebFrameWidget* web_frame_widget_; | 158 blink::WebFrameWidget* web_frame_widget_; |
172 | 159 |
173 // Owned by us, deleted via |close()|. | 160 // Owned by us, deleted via |close()|. |
174 blink::WebFrame* web_frame_; | 161 blink::WebFrame* web_frame_; |
175 gfx::Rect rect_; | 162 gfx::Rect rect_; |
176 | 163 |
177 std::list<std::string> data_; | |
178 std::unique_ptr<blink::WebURLError> error_; | |
179 blink::WebString old_title_; | 164 blink::WebString old_title_; |
180 bool finished_loading_; | |
181 bool focused_; | 165 bool focused_; |
182 bool is_painting_; | 166 bool is_painting_; |
183 bool is_resizing_; | 167 bool is_resizing_; |
184 | 168 |
| 169 // A helper needed to create a WebLocalFrame. |
| 170 class PluginWebFrameClient : public blink::WebFrameClient { |
| 171 public: |
| 172 PluginWebFrameClient(WebViewPlugin* plugin) : plugin_(plugin) {} |
| 173 ~PluginWebFrameClient() override {} |
| 174 void didClearWindowObject(blink::WebLocalFrame* frame) override; |
| 175 |
| 176 private: |
| 177 WebViewPlugin* plugin_; |
| 178 }; |
| 179 PluginWebFrameClient web_frame_client_; |
| 180 |
185 // Should be invalidated when destroy() is called. | 181 // Should be invalidated when destroy() is called. |
186 base::WeakPtrFactory<WebViewPlugin> weak_factory_; | 182 base::WeakPtrFactory<WebViewPlugin> weak_factory_; |
187 }; | 183 }; |
188 | 184 |
189 #endif // COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ | 185 #endif // COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ |
OLD | NEW |