| 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 18 matching lines...) Expand all Loading... |
| 29 } | 29 } |
| 30 | 30 |
| 31 // This class implements the WebPlugin interface by forwarding drawing and | 31 // This class implements the WebPlugin interface by forwarding drawing and |
| 32 // handling input events to a WebView. | 32 // handling input events to a WebView. |
| 33 // It can be used as a placeholder for an actual plugin, using HTML for the UI. | 33 // It can be used as a placeholder for an actual plugin, using HTML for the UI. |
| 34 // To show HTML data inside the WebViewPlugin, | 34 // To show HTML data inside the WebViewPlugin, |
| 35 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake | 35 // call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake |
| 36 // chrome:// URL as origin. | 36 // chrome:// URL as origin. |
| 37 | 37 |
| 38 class WebViewPlugin : public blink::WebPlugin, | 38 class WebViewPlugin : public blink::WebPlugin, |
| 39 public blink::WebViewClient, | |
| 40 public content::RenderViewObserver { | 39 public content::RenderViewObserver { |
| 41 public: | 40 public: |
| 42 class Delegate { | 41 class Delegate { |
| 43 public: | 42 public: |
| 44 // Called to get the V8 handle used to bind the lifetime to the frame. | 43 // Called to get the V8 handle used to bind the lifetime to the frame. |
| 45 virtual v8::Local<v8::Value> GetV8Handle(v8::Isolate*) = 0; | 44 virtual v8::Local<v8::Value> GetV8Handle(v8::Isolate*) = 0; |
| 46 | 45 |
| 47 // Called upon a context menu event. | 46 // Called upon a context menu event. |
| 48 virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0; | 47 virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0; |
| 49 | 48 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 60 | 59 |
| 61 // Convenience method to set up a new WebViewPlugin using |preferences| | 60 // Convenience method to set up a new WebViewPlugin using |preferences| |
| 62 // and displaying |html_data|. |url| should be a (fake) data:text/html URL; | 61 // and displaying |html_data|. |url| should be a (fake) data:text/html URL; |
| 63 // it is only used for navigation and never actually resolved. | 62 // it is only used for navigation and never actually resolved. |
| 64 static WebViewPlugin* Create(content::RenderView* render_view, | 63 static WebViewPlugin* Create(content::RenderView* render_view, |
| 65 Delegate* delegate, | 64 Delegate* delegate, |
| 66 const content::WebPreferences& preferences, | 65 const content::WebPreferences& preferences, |
| 67 const std::string& html_data, | 66 const std::string& html_data, |
| 68 const GURL& url); | 67 const GURL& url); |
| 69 | 68 |
| 70 blink::WebView* web_view() { return web_view_; } | 69 blink::WebView* web_view() { return web_view_helper_.web_view(); } |
| 71 | 70 |
| 72 bool focused() const { return focused_; } | |
| 73 const blink::WebString& old_title() const { return old_title_; } | 71 const blink::WebString& old_title() const { return old_title_; } |
| 74 | 72 |
| 73 // When loading a plugin document (i.e. a full page plugin not embedded in |
| 74 // another page), we save all data that has been received, and replay it with |
| 75 // this method on the actual plugin. |
| 76 void ReplayReceivedData(blink::WebPlugin* plugin); |
| 77 |
| 75 // WebPlugin methods: | 78 // WebPlugin methods: |
| 76 blink::WebPluginContainer* container() const override; | 79 blink::WebPluginContainer* container() const override; |
| 77 // The WebViewPlugin, by design, never fails to initialize. It's used to | 80 // The WebViewPlugin, by design, never fails to initialize. It's used to |
| 78 // display placeholders and error messages, so it must never fail. | 81 // display placeholders and error messages, so it must never fail. |
| 79 bool initialize(blink::WebPluginContainer*) override; | 82 bool initialize(blink::WebPluginContainer*) override; |
| 80 void destroy() override; | 83 void destroy() override; |
| 81 | 84 |
| 82 v8::Local<v8::Object> v8ScriptableObject(v8::Isolate* isolate) override; | 85 v8::Local<v8::Object> v8ScriptableObject(v8::Isolate* isolate) override; |
| 83 | 86 |
| 84 void updateAllLifecyclePhases() override; | 87 void updateAllLifecyclePhases() override; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 96 | 99 |
| 97 blink::WebInputEventResult handleInputEvent( | 100 blink::WebInputEventResult handleInputEvent( |
| 98 const blink::WebInputEvent& event, | 101 const blink::WebInputEvent& event, |
| 99 blink::WebCursorInfo& cursor_info) override; | 102 blink::WebCursorInfo& cursor_info) override; |
| 100 | 103 |
| 101 void didReceiveResponse(const blink::WebURLResponse& response) override; | 104 void didReceiveResponse(const blink::WebURLResponse& response) override; |
| 102 void didReceiveData(const char* data, int data_length) override; | 105 void didReceiveData(const char* data, int data_length) override; |
| 103 void didFinishLoading() override; | 106 void didFinishLoading() override; |
| 104 void didFailLoading(const blink::WebURLError& error) override; | 107 void didFailLoading(const blink::WebURLError& error) override; |
| 105 | 108 |
| 106 // WebViewClient methods: | |
| 107 bool acceptsLoadDrops() override; | |
| 108 | |
| 109 void setToolTipText(const blink::WebString&, | |
| 110 blink::WebTextDirection) override; | |
| 111 | |
| 112 void startDragging(blink::WebReferrerPolicy, | |
| 113 const blink::WebDragData&, | |
| 114 blink::WebDragOperationsMask, | |
| 115 const blink::WebImage&, | |
| 116 const blink::WebPoint&) override; | |
| 117 | |
| 118 // TODO(ojan): Remove this override and have this class use a non-null | |
| 119 // layerTreeView. | |
| 120 bool allowsBrokenNullLayerTreeView() const override; | |
| 121 | |
| 122 // WebWidgetClient methods: | |
| 123 void didInvalidateRect(const blink::WebRect&) override; | |
| 124 void didChangeCursor(const blink::WebCursorInfo& cursor) override; | |
| 125 void scheduleAnimation() override; | |
| 126 | |
| 127 private: | 109 private: |
| 128 friend class base::DeleteHelper<WebViewPlugin>; | 110 friend class base::DeleteHelper<WebViewPlugin>; |
| 129 WebViewPlugin(content::RenderView* render_view, | 111 WebViewPlugin(content::RenderView* render_view, |
| 130 Delegate* delegate, | 112 Delegate* delegate, |
| 131 const content::WebPreferences& preferences); | 113 const content::WebPreferences& preferences); |
| 132 ~WebViewPlugin() override; | 114 ~WebViewPlugin() override; |
| 133 | 115 |
| 134 // content::RenderViewObserver methods: | 116 // content::RenderViewObserver methods: |
| 135 void OnDestruct() override; | 117 void OnDestruct() override {} |
| 136 void OnZoomLevelChanged() override; | 118 void OnZoomLevelChanged() override; |
| 137 | 119 |
| 138 void UpdatePluginForNewGeometry(const blink::WebRect& window_rect, | 120 void UpdatePluginForNewGeometry(const blink::WebRect& window_rect, |
| 139 const blink::WebRect& unobscured_rect); | 121 const blink::WebRect& unobscured_rect); |
| 140 | 122 |
| 141 // Manages its own lifetime. | 123 // Manages its own lifetime. |
| 142 Delegate* delegate_; | 124 Delegate* delegate_; |
| 143 | 125 |
| 144 blink::WebCursorInfo current_cursor_; | 126 blink::WebCursorInfo current_cursor_; |
| 145 | 127 |
| 146 // Owns us. | 128 // Owns us. |
| 147 blink::WebPluginContainer* container_; | 129 blink::WebPluginContainer* container_; |
| 148 | 130 |
| 149 // Owned by us, deleted via |close()|. | |
| 150 blink::WebView* web_view_; | |
| 151 | |
| 152 gfx::Rect rect_; | 131 gfx::Rect rect_; |
| 153 | 132 |
| 133 blink::WebURLResponse response_; |
| 134 std::list<std::string> data_; |
| 135 std::unique_ptr<blink::WebURLError> error_; |
| 154 blink::WebString old_title_; | 136 blink::WebString old_title_; |
| 137 bool finished_loading_; |
| 155 bool focused_; | 138 bool focused_; |
| 156 bool is_painting_; | 139 bool is_painting_; |
| 157 bool is_resizing_; | 140 bool is_resizing_; |
| 158 | 141 |
| 159 // A helper needed to create a WebLocalFrame. | 142 // A helper that handles interaction from WebViewPlugin's internal WebView. |
| 160 class PluginWebFrameClient : public blink::WebFrameClient { | 143 class WebViewHelper : public blink::WebViewClient, |
| 144 public blink::WebFrameClient { |
| 161 public: | 145 public: |
| 162 PluginWebFrameClient(WebViewPlugin* plugin) : plugin_(plugin) {} | 146 WebViewHelper(WebViewPlugin* plugin, |
| 163 ~PluginWebFrameClient() override {} | 147 const content::WebPreferences& preferences); |
| 148 ~WebViewHelper() override; |
| 149 |
| 150 blink::WebView* web_view() { return web_view_; } |
| 151 |
| 152 // WebViewClient methods: |
| 153 bool acceptsLoadDrops() override; |
| 154 |
| 155 // WebWidgetClient methods: |
| 156 void setToolTipText(const blink::WebString&, |
| 157 blink::WebTextDirection) override; |
| 158 void startDragging(blink::WebReferrerPolicy, |
| 159 const blink::WebDragData&, |
| 160 blink::WebDragOperationsMask, |
| 161 const blink::WebImage&, |
| 162 const blink::WebPoint&) override; |
| 163 // TODO(ojan): Remove this override and have this class use a non-null |
| 164 // layerTreeView. |
| 165 bool allowsBrokenNullLayerTreeView() const override; |
| 166 void didInvalidateRect(const blink::WebRect&) override; |
| 167 void didChangeCursor(const blink::WebCursorInfo& cursor) override; |
| 168 void scheduleAnimation() override; |
| 169 |
| 170 // WebFrameClient methods: |
| 164 void didClearWindowObject(blink::WebLocalFrame* frame) override; | 171 void didClearWindowObject(blink::WebLocalFrame* frame) override; |
| 165 | 172 |
| 166 private: | 173 private: |
| 167 WebViewPlugin* plugin_; | 174 WebViewPlugin* plugin_; |
| 175 |
| 176 // Owned by us, deleted via |close()|. |
| 177 blink::WebView* web_view_; |
| 168 }; | 178 }; |
| 169 PluginWebFrameClient web_frame_client_; | 179 WebViewHelper web_view_helper_; |
| 170 | 180 |
| 171 // Should be invalidated when destroy() is called. | 181 // Should be invalidated when destroy() is called. |
| 172 base::WeakPtrFactory<WebViewPlugin> weak_factory_; | 182 base::WeakPtrFactory<WebViewPlugin> weak_factory_; |
| 173 }; | 183 }; |
| 174 | 184 |
| 175 #endif // COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ | 185 #endif // COMPONENTS_PLUGINS_RENDERER_WEBVIEW_PLUGIN_H_ |
| OLD | NEW |