OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #if defined(TOOLKIT_GTK) | 33 #if defined(TOOLKIT_GTK) |
34 #include "ui/base/x/x11_util.h" | 34 #include "ui/base/x/x11_util.h" |
35 #elif defined(OS_MACOSX) | 35 #elif defined(OS_MACOSX) |
36 #include "skia/ext/platform_device.h" | 36 #include "skia/ext/platform_device.h" |
37 #endif | 37 #endif |
38 | 38 |
39 class BackingStore; | 39 class BackingStore; |
40 struct EditCommand; | 40 struct EditCommand; |
41 class RenderViewHost; | 41 class RenderViewHost; |
| 42 class RenderWidgetHostImpl; |
42 class TransportDIB; | 43 class TransportDIB; |
43 struct ViewHostMsg_UpdateRect_Params; | 44 struct ViewHostMsg_UpdateRect_Params; |
44 class WebCursor; | 45 class WebCursor; |
45 | 46 |
46 namespace base { | 47 namespace base { |
47 class TimeTicks; | 48 class TimeTicks; |
48 } | 49 } |
49 | 50 |
50 namespace content { | 51 namespace content { |
51 class RenderProcessHost; | 52 class RenderProcessHost; |
(...skipping 20 matching lines...) Expand all Loading... |
72 struct WebScreenInfo; | 73 struct WebScreenInfo; |
73 } | 74 } |
74 | 75 |
75 // TODO(joi): Extract relevant bit of class documentation from | 76 // TODO(joi): Extract relevant bit of class documentation from |
76 // RenderWidgetHostImpl documentation. TODO(joi): Move to | 77 // RenderWidgetHostImpl documentation. TODO(joi): Move to |
77 // content/public/browser/render_widget_host.h | 78 // content/public/browser/render_widget_host.h |
78 // | 79 // |
79 // TODO(joi): Once I finish defining this interface (once | 80 // TODO(joi): Once I finish defining this interface (once |
80 // RenderViewHost interface is also in place), group together | 81 // RenderViewHost interface is also in place), group together |
81 // implementation functions in subclasses. | 82 // implementation functions in subclasses. |
82 class CONTENT_EXPORT RenderWidgetHost { | 83 // |
| 84 // TODO(joi): Move to file render_widget_host_impl.h |
| 85 class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Sender { |
83 public: | 86 public: |
84 explicit RenderWidgetHost(content::RenderProcessHost* process); | |
85 virtual ~RenderWidgetHost() {} | 87 virtual ~RenderWidgetHost() {} |
86 | 88 |
| 89 // Edit operations. |
| 90 virtual void Undo() = 0; |
| 91 virtual void Redo() = 0; |
| 92 virtual void Cut() = 0; |
| 93 virtual void Copy() = 0; |
| 94 virtual void CopyToFindPboard() = 0; |
| 95 virtual void Paste() = 0; |
| 96 virtual void PasteAndMatchStyle() = 0; |
| 97 virtual void Delete() = 0; |
| 98 virtual void SelectAll() = 0; |
| 99 |
| 100 // Update the text direction of the focused input element and notify it to a |
| 101 // renderer process. |
| 102 // These functions have two usage scenarios: changing the text direction |
| 103 // from a menu (as Safari does), and; changing the text direction when a user |
| 104 // presses a set of keys (as IE and Firefox do). |
| 105 // 1. Change the text direction from a menu. |
| 106 // In this scenario, we receive a menu event only once and we should update |
| 107 // the text direction immediately when a user chooses a menu item. So, we |
| 108 // should call both functions at once as listed in the following snippet. |
| 109 // void RenderViewHost::SetTextDirection(WebTextDirection direction) { |
| 110 // UpdateTextDirection(direction); |
| 111 // NotifyTextDirection(); |
| 112 // } |
| 113 // 2. Change the text direction when pressing a set of keys. |
| 114 // Because of auto-repeat, we may receive the same key-press event many |
| 115 // times while we presses the keys and it is nonsense to send the same IPC |
| 116 // message every time when we receive a key-press event. |
| 117 // To suppress the number of IPC messages, we just update the text direction |
| 118 // when receiving a key-press event and send an IPC message when we release |
| 119 // the keys as listed in the following snippet. |
| 120 // if (key_event.type == WebKeyboardEvent::KEY_DOWN) { |
| 121 // if (key_event.windows_key_code == 'A' && |
| 122 // key_event.modifiers == WebKeyboardEvent::CTRL_KEY) { |
| 123 // UpdateTextDirection(dir); |
| 124 // } else { |
| 125 // CancelUpdateTextDirection(); |
| 126 // } |
| 127 // } else if (key_event.type == WebKeyboardEvent::KEY_UP) { |
| 128 // NotifyTextDirection(); |
| 129 // } |
| 130 // Once we cancel updating the text direction, we have to ignore all |
| 131 // succeeding UpdateTextDirection() requests until calling |
| 132 // NotifyTextDirection(). (We may receive keydown events even after we |
| 133 // canceled updating the text direction because of auto-repeat.) |
| 134 // Note: we cannot undo this change for compatibility with Firefox and IE. |
| 135 virtual void UpdateTextDirection(WebKit::WebTextDirection direction) = 0; |
| 136 virtual void NotifyTextDirection() = 0; |
| 137 |
| 138 virtual void Blur() = 0; |
| 139 |
| 140 // Copies the contents of the backing store into the given (uninitialized) |
| 141 // PlatformCanvas. Returns true on success, false otherwise. |
| 142 virtual bool CopyFromBackingStore(skia::PlatformCanvas* output) = 0; |
| 143 |
| 144 #if defined(TOOLKIT_GTK) |
| 145 // Paint the backing store into the target's |dest_rect|. |
| 146 virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect& dest_rect, |
| 147 GdkWindow* target) = 0; |
| 148 #elif defined(OS_MACOSX) |
| 149 virtual gfx::Size GetBackingStoreSize() = 0; |
| 150 virtual bool CopyFromBackingStoreToCGContext(const CGRect& dest_rect, |
| 151 CGContextRef target) = 0; |
| 152 #endif |
| 153 |
| 154 // Enable renderer accessibility. This should only be called when a |
| 155 // screenreader is detected. |
| 156 virtual void EnableRendererAccessibility() = 0; |
| 157 |
| 158 // Forwards the given message to the renderer. These are called by |
| 159 // the view when it has received a message. |
| 160 virtual void ForwardMouseEvent( |
| 161 const WebKit::WebMouseEvent& mouse_event) = 0; |
| 162 virtual void ForwardWheelEvent( |
| 163 const WebKit::WebMouseWheelEvent& wheel_event) = 0; |
| 164 virtual void ForwardKeyboardEvent( |
| 165 const NativeWebKeyboardEvent& key_event) = 0; |
| 166 |
| 167 virtual const gfx::Point& GetLastScrollOffset() const = 0; |
| 168 |
| 169 virtual content::RenderProcessHost* GetProcess() const = 0; |
| 170 |
| 171 virtual int GetRoutingID() const = 0; |
| 172 |
| 173 // Gets the View of this RenderWidgetHost. Can be NULL, e.g. if the |
| 174 // RenderWidget is being destroyed or the render process crashed. You should |
| 175 // never cache this pointer since it can become NULL if the renderer crashes, |
| 176 // instead you should always ask for it using the accessor. |
| 177 virtual content::RenderWidgetHostView* GetView() const = 0; |
| 178 |
| 179 // Returns true if this is a RenderViewHost, false if not. |
| 180 virtual bool IsRenderView() const = 0; |
| 181 |
87 // Used as the details object for a | 182 // Used as the details object for a |
88 // RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK notification. | 183 // RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK notification. |
89 // TODO(joi): Switch out for a std::pair. | 184 // TODO(joi): Switch out for a std::pair. |
90 struct PaintAtSizeAckDetails { | 185 struct PaintAtSizeAckDetails { |
91 // The tag that was passed to the PaintAtSize() call that triggered this | 186 // The tag that was passed to the PaintAtSize() call that triggered this |
92 // ack. | 187 // ack. |
93 int tag; | 188 int tag; |
94 gfx::Size size; | 189 gfx::Size size; |
95 }; | 190 }; |
96 | 191 |
97 // This tells the renderer to paint into a bitmap and return it, | 192 // This tells the renderer to paint into a bitmap and return it, |
98 // regardless of whether the tab is hidden or not. It resizes the | 193 // regardless of whether the tab is hidden or not. It resizes the |
99 // web widget to match the |page_size| and then returns the bitmap | 194 // web widget to match the |page_size| and then returns the bitmap |
100 // scaled so it matches the |desired_size|, so that the scaling | 195 // scaled so it matches the |desired_size|, so that the scaling |
101 // happens on the rendering thread. When the bitmap is ready, the | 196 // happens on the rendering thread. When the bitmap is ready, the |
102 // renderer sends a PaintAtSizeACK to this host, and a | 197 // renderer sends a PaintAtSizeACK to this host, and a |
103 // RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK notification is issued. | 198 // RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK notification is issued. |
104 // Note that this bypasses most of the update logic that is normally invoked, | 199 // Note that this bypasses most of the update logic that is normally invoked, |
105 // and doesn't put the results into the backing store. | 200 // and doesn't put the results into the backing store. |
106 virtual void PaintAtSize(TransportDIB::Handle dib_handle, | 201 virtual void PaintAtSize(TransportDIB::Handle dib_handle, |
107 int tag, | 202 int tag, |
108 const gfx::Size& page_size, | 203 const gfx::Size& page_size, |
109 const gfx::Size& desired_size) = 0; | 204 const gfx::Size& desired_size) = 0; |
110 | 205 |
111 // Copies the contents of the backing store into the given (uninitialized) | 206 // Makes an IPC call to tell webkit to replace the currently selected word |
112 // PlatformCanvas. Returns true on success, false otherwise. | 207 // or a word around the cursor. |
113 virtual bool CopyFromBackingStore(skia::PlatformCanvas* output) = 0; | 208 virtual void Replace(const string16& word) = 0; |
114 | 209 |
115 #if defined(TOOLKIT_GTK) | 210 // Called to notify the RenderWidget that the resize rect has changed without |
116 // Paint the backing store into the target's |dest_rect|. | 211 // the size of the RenderWidget itself changing. |
117 virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect& dest_rect, | 212 virtual void ResizeRectChanged(const gfx::Rect& new_rect) = 0; |
118 GdkWindow* target) = 0; | |
119 #elif defined(OS_MACOSX) | |
120 virtual gfx::Size GetBackingStoreSize() = 0; | |
121 virtual bool CopyFromBackingStoreToCGContext(const CGRect& dest_rect, | |
122 CGContextRef target) = 0; | |
123 #endif | |
124 | 213 |
125 // Returns true if this is a RenderViewHost, false if not. | 214 // Restart the active hang monitor timeout. Clears all existing timeouts and |
126 virtual bool IsRenderView() const = 0; | 215 // starts with a new one. This can be because the renderer has become |
| 216 // active, the tab is being hidden, or the user has chosen to wait some more |
| 217 // to give the tab a chance to become active and we don't want to display a |
| 218 // warning too soon. |
| 219 virtual void RestartHangMonitorTimeout() = 0; |
| 220 |
| 221 virtual void SetIgnoreInputEvents(bool ignore_input_events) = 0; |
| 222 |
| 223 // Stops loading the page. |
| 224 virtual void Stop() = 0; |
127 | 225 |
128 // Called to notify the RenderWidget that it has been resized. | 226 // Called to notify the RenderWidget that it has been resized. |
129 virtual void WasResized() = 0; | 227 virtual void WasResized() = 0; |
130 | 228 |
131 // TODO(joi): Get rid of these inline accessors and the associated | 229 // Access to the implementation's |
132 // data from the interface, make them into pure virtual GetFoo | 230 // IPC::Channel::Listener::OnMessageReceived. Intended only for |
133 // methods instead. | 231 // test code. |
134 content::RenderProcessHost* process() const { return process_; } | |
135 | 232 |
136 // Gets the View of this RenderWidgetHost. Can be NULL, e.g. if the | 233 // TODO(joi): Remove this and convert the single test using it to |
137 // RenderWidget is being destroyed or the render process crashed. You should | 234 // get the TabContentsWrapper from |
138 // never cache this pointer since it can become NULL if the renderer crashes, | 235 // browser()->GetSelectedWebContents() and then call its |
139 // instead you should always ask for it using the accessor. | 236 // translate_tab_helper() to get at the object that dispatches its |
140 content::RenderWidgetHostView* view() const; | 237 // method. |
| 238 virtual bool OnMessageReceivedForTesting(const IPC::Message& msg) = 0; |
141 | 239 |
142 // Gets a RenderVidgetHost pointer from an IPC::Channel::Listener pointer. | 240 // Gets a RenderVidgetHost pointer from an IPC::Channel::Listener pointer. |
143 static RenderWidgetHost* FromIPCChannelListener( | 241 static RenderWidgetHost* FromIPCChannelListener( |
144 IPC::Channel::Listener* listener); | 242 IPC::Channel::Listener* listener); |
145 static const RenderWidgetHost* FromIPCChannelListener( | 243 static const RenderWidgetHost* FromIPCChannelListener( |
146 const IPC::Channel::Listener* listener); | 244 const IPC::Channel::Listener* listener); |
147 | 245 |
148 // Free all backing stores used for rendering to drop memory usage. | 246 // Free all backing stores used for rendering to drop memory usage. |
149 static void RemoveAllBackingStores(); | 247 static void RemoveAllBackingStores(); |
150 | 248 |
151 // Returns the size of all the backing stores used for rendering | 249 // Returns the size of all the backing stores used for rendering |
152 static size_t BackingStoreMemorySize(); | 250 static size_t BackingStoreMemorySize(); |
153 | 251 |
154 protected: | 252 protected: |
155 // Created during construction but initialized during Init*(). Therefore, it | 253 friend class RenderWidgetHostImpl; |
156 // is guaranteed never to be NULL, but its channel may be NULL if the | |
157 // renderer crashed, so you must always check that. | |
158 content::RenderProcessHost* process_; | |
159 | 254 |
160 // The View associated with the RenderViewHost. The lifetime of this object | 255 // Retrieves the implementation class. Intended only for code |
161 // is associated with the lifetime of the Render process. If the Renderer | 256 // within content/. This method is necessary because |
162 // crashes, its View is destroyed and this pointer becomes NULL, even though | 257 // RenderWidgetHost is the root of a diamond inheritance pattern, so |
163 // render_view_host_ lives on to load another URL (creating a new View while | 258 // subclasses inherit it virtually, which removes our ability to |
164 // doing so). | 259 // static_cast to the subclass. |
165 content::RenderWidgetHostViewPort* view_; | 260 virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() = 0; |
166 }; | 261 }; |
167 | 262 |
168 // This class manages the browser side of a browser<->renderer HWND connection. | 263 // This class manages the browser side of a browser<->renderer HWND connection. |
169 // The HWND lives in the browser process, and windows events are sent over | 264 // The HWND lives in the browser process, and windows events are sent over |
170 // IPC to the corresponding object in the renderer. The renderer paints into | 265 // IPC to the corresponding object in the renderer. The renderer paints into |
171 // shared memory, which we transfer to a backing store and blit to the screen | 266 // shared memory, which we transfer to a backing store and blit to the screen |
172 // when Windows sends us a WM_PAINT message. | 267 // when Windows sends us a WM_PAINT message. |
173 // | 268 // |
174 // How Shutdown Works | 269 // How Shutdown Works |
175 // | 270 // |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // | 328 // |
234 // It should be noted that the RenderViewHost, not the RenderWidgetHost, | 329 // It should be noted that the RenderViewHost, not the RenderWidgetHost, |
235 // handles IPC messages relating to the render process going away, since the | 330 // handles IPC messages relating to the render process going away, since the |
236 // way a RenderViewHost (TabContents) handles the process dying is different to | 331 // way a RenderViewHost (TabContents) handles the process dying is different to |
237 // the way a select popup does. As such the RenderWidgetHostView handles these | 332 // the way a select popup does. As such the RenderWidgetHostView handles these |
238 // messages for select popups. This placement is more out of convenience than | 333 // messages for select popups. This placement is more out of convenience than |
239 // anything else. When the view is live, these messages are forwarded to it by | 334 // anything else. When the view is live, these messages are forwarded to it by |
240 // the RenderWidgetHost's IPC message map. | 335 // the RenderWidgetHost's IPC message map. |
241 // | 336 // |
242 // TODO(joi): Move to content namespace. | 337 // TODO(joi): Move to content namespace. |
243 class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost, | 338 class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, |
244 public IPC::Channel::Listener, | 339 public IPC::Channel::Listener { |
245 public IPC::Channel::Sender { | |
246 public: | 340 public: |
247 // routing_id can be MSG_ROUTING_NONE, in which case the next available | 341 // routing_id can be MSG_ROUTING_NONE, in which case the next available |
248 // routing id is taken from the RenderProcessHost. | 342 // routing id is taken from the RenderProcessHost. |
249 RenderWidgetHostImpl(content::RenderProcessHost* process, int routing_id); | 343 RenderWidgetHostImpl(content::RenderProcessHost* process, int routing_id); |
250 virtual ~RenderWidgetHostImpl(); | 344 virtual ~RenderWidgetHostImpl(); |
251 | 345 |
252 static RenderWidgetHostImpl* FromRWHV(content::RenderWidgetHostView* rwhv); | 346 // Use RenderWidgetHostImpl::From(rwh) to downcast a |
| 347 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this |
| 348 // uses RenderWidgetHost::AsRenderWidgetHostImpl(). |
| 349 static RenderWidgetHostImpl* From(RenderWidgetHost* rwh); |
| 350 |
| 351 // RenderWidgetHost implementation. |
| 352 virtual void Undo() OVERRIDE; |
| 353 virtual void Redo() OVERRIDE; |
| 354 virtual void Cut() OVERRIDE; |
| 355 virtual void Copy() OVERRIDE; |
| 356 virtual void CopyToFindPboard() OVERRIDE; |
| 357 virtual void Paste() OVERRIDE; |
| 358 virtual void PasteAndMatchStyle() OVERRIDE; |
| 359 virtual void Delete() OVERRIDE; |
| 360 virtual void SelectAll() OVERRIDE; |
| 361 virtual void UpdateTextDirection(WebKit::WebTextDirection direction) OVERRIDE; |
| 362 virtual void NotifyTextDirection() OVERRIDE; |
| 363 virtual void Blur() OVERRIDE; |
| 364 virtual bool CopyFromBackingStore(skia::PlatformCanvas* output) OVERRIDE; |
| 365 #if defined(TOOLKIT_GTK) |
| 366 virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect& dest_rect, |
| 367 GdkWindow* target) OVERRIDE; |
| 368 #elif defined(OS_MACOSX) |
| 369 virtual gfx::Size GetBackingStoreSize() OVERRIDE; |
| 370 virtual bool CopyFromBackingStoreToCGContext(const CGRect& dest_rect, |
| 371 CGContextRef target) OVERRIDE; |
| 372 #endif |
| 373 virtual void EnableRendererAccessibility() OVERRIDE; |
| 374 virtual void ForwardMouseEvent( |
| 375 const WebKit::WebMouseEvent& mouse_event) OVERRIDE; |
| 376 virtual void ForwardWheelEvent( |
| 377 const WebKit::WebMouseWheelEvent& wheel_event) OVERRIDE; |
| 378 virtual void ForwardKeyboardEvent( |
| 379 const NativeWebKeyboardEvent& key_event) OVERRIDE; |
| 380 virtual const gfx::Point& GetLastScrollOffset() const OVERRIDE; |
| 381 virtual content::RenderProcessHost* GetProcess() const OVERRIDE; |
| 382 virtual int GetRoutingID() const OVERRIDE; |
| 383 virtual content::RenderWidgetHostView* GetView() const OVERRIDE; |
| 384 virtual bool IsRenderView() const OVERRIDE; |
| 385 virtual void PaintAtSize(TransportDIB::Handle dib_handle, |
| 386 int tag, |
| 387 const gfx::Size& page_size, |
| 388 const gfx::Size& desired_size) OVERRIDE; |
| 389 virtual void Replace(const string16& word) OVERRIDE; |
| 390 virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE; |
| 391 virtual void RestartHangMonitorTimeout() OVERRIDE; |
| 392 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; |
| 393 virtual void Stop() OVERRIDE; |
| 394 virtual void WasResized() OVERRIDE; |
| 395 virtual bool OnMessageReceivedForTesting(const IPC::Message& msg) OVERRIDE; |
253 | 396 |
254 // Sets the View of this RenderWidgetHost. | 397 // Sets the View of this RenderWidgetHost. |
255 void SetView(content::RenderWidgetHostView* view); | 398 void SetView(content::RenderWidgetHostView* view); |
256 | 399 |
257 int routing_id() const { return routing_id_; } | |
258 int surface_id() const { return surface_id_; } | 400 int surface_id() const { return surface_id_; } |
259 bool renderer_accessible() { return renderer_accessible_; } | 401 bool renderer_accessible() { return renderer_accessible_; } |
260 | 402 |
261 bool empty() const { return current_size_.IsEmpty(); } | 403 bool empty() const { return current_size_.IsEmpty(); } |
262 | 404 |
263 // Returns the property bag for this widget, where callers can add extra data | 405 // Returns the property bag for this widget, where callers can add extra data |
264 // they may wish to associate with it. Returns a pointer rather than a | 406 // they may wish to associate with it. Returns a pointer rather than a |
265 // reference since the PropertyAccessors expect this. | 407 // reference since the PropertyAccessors expect this. |
266 const base::PropertyBag* property_bag() const { return &property_bag_; } | 408 const base::PropertyBag* property_bag() const { return &property_bag_; } |
267 base::PropertyBag* property_bag() { return &property_bag_; } | 409 base::PropertyBag* property_bag() { return &property_bag_; } |
268 | 410 |
269 // Called when a renderer object already been created for this host, and we | 411 // Called when a renderer object already been created for this host, and we |
270 // just need to be attached to it. Used for window.open, <select> dropdown | 412 // just need to be attached to it. Used for window.open, <select> dropdown |
271 // menus, and other times when the renderer initiates creating an object. | 413 // menus, and other times when the renderer initiates creating an object. |
272 void Init(); | 414 void Init(); |
273 | 415 |
274 // Tells the renderer to die and then calls Destroy(). | 416 // Tells the renderer to die and then calls Destroy(). |
275 virtual void Shutdown(); | 417 virtual void Shutdown(); |
276 | 418 |
277 // Manual RTTI FTW. We are not hosting a web page. | |
278 virtual bool IsRenderView() const OVERRIDE; | |
279 | |
280 // IPC::Channel::Listener | 419 // IPC::Channel::Listener |
281 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 420 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
282 | 421 |
283 // Sends a message to the corresponding object in the renderer. | 422 // Sends a message to the corresponding object in the renderer. |
284 virtual bool Send(IPC::Message* msg) OVERRIDE; | 423 virtual bool Send(IPC::Message* msg) OVERRIDE; |
285 | 424 |
286 // Called to notify the RenderWidget that it has been hidden or restored from | 425 // Called to notify the RenderWidget that it has been hidden or restored from |
287 // having been hidden. | 426 // having been hidden. |
288 void WasHidden(); | 427 void WasHidden(); |
289 void WasRestored(); | 428 void WasRestored(); |
290 | 429 |
291 virtual void WasResized() OVERRIDE; | |
292 | |
293 // Called to notify the RenderWidget that the resize rect has changed without | |
294 // the size of the RenderWidget itself changing. | |
295 void ResizeRectChanged(const gfx::Rect& new_rect); | |
296 | |
297 // Called to notify the RenderWidget that its associated native window got | 430 // Called to notify the RenderWidget that its associated native window got |
298 // focused. | 431 // focused. |
299 virtual void GotFocus(); | 432 virtual void GotFocus(); |
300 | 433 |
301 // Tells the renderer it got/lost focus. | 434 // Tells the renderer it got/lost focus. |
302 void Focus(); | 435 void Focus(); |
303 void Blur(); | |
304 virtual void LostCapture(); | 436 virtual void LostCapture(); |
305 | 437 |
306 // Sets whether the renderer should show controls in an active state. On all | 438 // Sets whether the renderer should show controls in an active state. On all |
307 // platforms except mac, that's the same as focused. On mac, the frontmost | 439 // platforms except mac, that's the same as focused. On mac, the frontmost |
308 // window will show active controls even if the focus is not in the web | 440 // window will show active controls even if the focus is not in the web |
309 // contents, but e.g. in the omnibox. | 441 // contents, but e.g. in the omnibox. |
310 void SetActive(bool active); | 442 void SetActive(bool active); |
311 | 443 |
312 // Called to notify the RenderWidget that it has lost the mouse lock. | 444 // Called to notify the RenderWidget that it has lost the mouse lock. |
313 virtual void LostMouseLock(); | 445 virtual void LostMouseLock(); |
314 | 446 |
315 // Tells us whether the page is rendered directly via the GPU process. | 447 // Tells us whether the page is rendered directly via the GPU process. |
316 bool is_accelerated_compositing_active() { | 448 bool is_accelerated_compositing_active() { |
317 return is_accelerated_compositing_active_; | 449 return is_accelerated_compositing_active_; |
318 } | 450 } |
319 | 451 |
320 // Notifies the RenderWidgetHost that the View was destroyed. | 452 // Notifies the RenderWidgetHost that the View was destroyed. |
321 void ViewDestroyed(); | 453 void ViewDestroyed(); |
322 | 454 |
323 // Indicates if the page has finished loading. | 455 // Indicates if the page has finished loading. |
324 void SetIsLoading(bool is_loading); | 456 void SetIsLoading(bool is_loading); |
325 | 457 |
326 virtual bool CopyFromBackingStore(skia::PlatformCanvas* output) OVERRIDE; | |
327 #if defined(TOOLKIT_GTK) | |
328 virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect& dest_rect, | |
329 GdkWindow* target) OVERRIDE; | |
330 #elif defined(OS_MACOSX) | |
331 virtual gfx::Size GetBackingStoreSize() OVERRIDE; | |
332 virtual bool CopyFromBackingStoreToCGContext(const CGRect& dest_rect, | |
333 CGContextRef target) OVERRIDE; | |
334 #endif | |
335 virtual void PaintAtSize(TransportDIB::Handle dib_handle, | |
336 int tag, | |
337 const gfx::Size& page_size, | |
338 const gfx::Size& desired_size) OVERRIDE; | |
339 | |
340 // Get access to the widget's backing store. If a resize is in progress, | 458 // Get access to the widget's backing store. If a resize is in progress, |
341 // then the current size of the backing store may be less than the size of | 459 // then the current size of the backing store may be less than the size of |
342 // the widget's view. If you pass |force_create| as true, then the backing | 460 // the widget's view. If you pass |force_create| as true, then the backing |
343 // store will be created if it doesn't exist. Otherwise, NULL will be returned | 461 // store will be created if it doesn't exist. Otherwise, NULL will be returned |
344 // if the backing store doesn't already exist. It will also return NULL if the | 462 // if the backing store doesn't already exist. It will also return NULL if the |
345 // backing store could not be created. | 463 // backing store could not be created. |
346 BackingStore* GetBackingStore(bool force_create); | 464 BackingStore* GetBackingStore(bool force_create); |
347 | 465 |
348 // Allocate a new backing store of the given size. Returns NULL on failure | 466 // Allocate a new backing store of the given size. Returns NULL on failure |
349 // (for example, if we don't currently have a RenderWidgetHostView.) | 467 // (for example, if we don't currently have a RenderWidgetHostView.) |
350 BackingStore* AllocBackingStore(const gfx::Size& size); | 468 BackingStore* AllocBackingStore(const gfx::Size& size); |
351 | 469 |
352 // When a backing store does asynchronous painting, it will call this function | 470 // When a backing store does asynchronous painting, it will call this function |
353 // when it is done with the DIB. We will then forward a message to the | 471 // when it is done with the DIB. We will then forward a message to the |
354 // renderer to send another paint. | 472 // renderer to send another paint. |
355 void DonePaintingToBackingStore(); | 473 void DonePaintingToBackingStore(); |
356 | 474 |
357 // GPU accelerated version of GetBackingStore function. This will | 475 // GPU accelerated version of GetBackingStore function. This will |
358 // trigger a re-composite to the view. If a resize is pending, it will | 476 // trigger a re-composite to the view. If a resize is pending, it will |
359 // block briefly waiting for an ack from the renderer. | 477 // block briefly waiting for an ack from the renderer. |
360 void ScheduleComposite(); | 478 void ScheduleComposite(); |
361 | 479 |
362 // Starts a hang monitor timeout. If there's already a hang monitor timeout | 480 // Starts a hang monitor timeout. If there's already a hang monitor timeout |
363 // the new one will only fire if it has a shorter delay than the time | 481 // the new one will only fire if it has a shorter delay than the time |
364 // left on the existing timeouts. | 482 // left on the existing timeouts. |
365 void StartHangMonitorTimeout(base::TimeDelta delay); | 483 void StartHangMonitorTimeout(base::TimeDelta delay); |
366 | 484 |
367 // Restart the active hang monitor timeout. Clears all existing timeouts and | |
368 // starts with a new one. This can be because the renderer has become | |
369 // active, the tab is being hidden, or the user has chosen to wait some more | |
370 // to give the tab a chance to become active and we don't want to display a | |
371 // warning too soon. | |
372 void RestartHangMonitorTimeout(); | |
373 | |
374 // Stops all existing hang monitor timeouts and assumes the renderer is | 485 // Stops all existing hang monitor timeouts and assumes the renderer is |
375 // responsive. | 486 // responsive. |
376 void StopHangMonitorTimeout(); | 487 void StopHangMonitorTimeout(); |
377 | 488 |
378 // Forwards the given message to the renderer. These are called by the view | 489 // Forwards the given message to the renderer. These are called by the view |
379 // when it has received a message. | 490 // when it has received a message. |
380 virtual void ForwardMouseEvent(const WebKit::WebMouseEvent& mouse_event); | 491 void ForwardGestureEvent(const WebKit::WebGestureEvent& gesture_event); |
| 492 virtual void ForwardTouchEvent(const WebKit::WebTouchEvent& touch_event); |
| 493 |
| 494 void CancelUpdateTextDirection(); |
| 495 |
381 // Called when a mouse click activates the renderer. | 496 // Called when a mouse click activates the renderer. |
382 virtual void OnMouseActivate(); | 497 virtual void OnMouseActivate(); |
383 void ForwardWheelEvent(const WebKit::WebMouseWheelEvent& wheel_event); | |
384 void ForwardGestureEvent(const WebKit::WebGestureEvent& gesture_event); | |
385 virtual void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event); | |
386 virtual void ForwardTouchEvent(const WebKit::WebTouchEvent& touch_event); | |
387 | |
388 // Update the text direction of the focused input element and notify it to a | |
389 // renderer process. | |
390 // These functions have two usage scenarios: changing the text direction | |
391 // from a menu (as Safari does), and; changing the text direction when a user | |
392 // presses a set of keys (as IE and Firefox do). | |
393 // 1. Change the text direction from a menu. | |
394 // In this scenario, we receive a menu event only once and we should update | |
395 // the text direction immediately when a user chooses a menu item. So, we | |
396 // should call both functions at once as listed in the following snippet. | |
397 // void RenderViewHost::SetTextDirection(WebTextDirection direction) { | |
398 // UpdateTextDirection(direction); | |
399 // NotifyTextDirection(); | |
400 // } | |
401 // 2. Change the text direction when pressing a set of keys. | |
402 // Because of auto-repeat, we may receive the same key-press event many | |
403 // times while we presses the keys and it is nonsense to send the same IPC | |
404 // message every time when we receive a key-press event. | |
405 // To suppress the number of IPC messages, we just update the text direction | |
406 // when receiving a key-press event and send an IPC message when we release | |
407 // the keys as listed in the following snippet. | |
408 // if (key_event.type == WebKeyboardEvent::KEY_DOWN) { | |
409 // if (key_event.windows_key_code == 'A' && | |
410 // key_event.modifiers == WebKeyboardEvent::CTRL_KEY) { | |
411 // UpdateTextDirection(dir); | |
412 // } else { | |
413 // CancelUpdateTextDirection(); | |
414 // } | |
415 // } else if (key_event.type == WebKeyboardEvent::KEY_UP) { | |
416 // NotifyTextDirection(); | |
417 // } | |
418 // Once we cancel updating the text direction, we have to ignore all | |
419 // succeeding UpdateTextDirection() requests until calling | |
420 // NotifyTextDirection(). (We may receive keydown events even after we | |
421 // canceled updating the text direction because of auto-repeat.) | |
422 // Note: we cannot undo this change for compatibility with Firefox and IE. | |
423 void UpdateTextDirection(WebKit::WebTextDirection direction); | |
424 void CancelUpdateTextDirection(); | |
425 void NotifyTextDirection(); | |
426 | 498 |
427 // Notifies the renderer whether or not the input method attached to this | 499 // Notifies the renderer whether or not the input method attached to this |
428 // process is activated. | 500 // process is activated. |
429 // When the input method is activated, a renderer process sends IPC messages | 501 // When the input method is activated, a renderer process sends IPC messages |
430 // to notify the status of its composition node. (This message is mainly used | 502 // to notify the status of its composition node. (This message is mainly used |
431 // for notifying the position of the input cursor so that the browser can | 503 // for notifying the position of the input cursor so that the browser can |
432 // display input method windows under the cursor.) | 504 // display input method windows under the cursor.) |
433 void SetInputMethodActive(bool activate); | 505 void SetInputMethodActive(bool activate); |
434 | 506 |
435 // Update the composition node of the renderer (or WebKit). | 507 // Update the composition node of the renderer (or WebKit). |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 // SetComposition() call. | 539 // SetComposition() call. |
468 void ImeConfirmComposition(); | 540 void ImeConfirmComposition(); |
469 | 541 |
470 // Cancels an ongoing composition. | 542 // Cancels an ongoing composition. |
471 void ImeCancelComposition(); | 543 void ImeCancelComposition(); |
472 | 544 |
473 // This is for derived classes to give us access to the resizer rect. | 545 // This is for derived classes to give us access to the resizer rect. |
474 // And to also expose it to the RenderWidgetHostView. | 546 // And to also expose it to the RenderWidgetHostView. |
475 virtual gfx::Rect GetRootWindowResizerRect() const; | 547 virtual gfx::Rect GetRootWindowResizerRect() const; |
476 | 548 |
477 // Makes an IPC call to tell webkit to replace the currently selected word | |
478 // or a word around the cursor. | |
479 void Replace(const string16& word); | |
480 | |
481 // Enable renderer accessibility. This should only be called when a | |
482 // screenreader is detected. | |
483 void EnableRendererAccessibility(); | |
484 | |
485 void set_ignore_input_events(bool ignore_input_events) { | |
486 ignore_input_events_ = ignore_input_events; | |
487 } | |
488 bool ignore_input_events() const { | 549 bool ignore_input_events() const { |
489 return ignore_input_events_; | 550 return ignore_input_events_; |
490 } | 551 } |
491 | 552 |
492 // Activate deferred plugin handles. | 553 // Activate deferred plugin handles. |
493 void ActivateDeferredPluginHandles(); | 554 void ActivateDeferredPluginHandles(); |
494 | 555 |
495 const gfx::Point& last_scroll_offset() const { return last_scroll_offset_; } | |
496 | |
497 bool has_touch_handler() const { return has_touch_handler_; } | 556 bool has_touch_handler() const { return has_touch_handler_; } |
498 | 557 |
499 // Notification that the user has made some kind of input that could | 558 // Notification that the user has made some kind of input that could |
500 // perform an action. See OnUserGesture for more details. | 559 // perform an action. See OnUserGesture for more details. |
501 void StartUserGesture(); | 560 void StartUserGesture(); |
502 | 561 |
503 // Stops loading the page. | |
504 void Stop(); | |
505 | |
506 // Set the RenderView background. | 562 // Set the RenderView background. |
507 void SetBackground(const SkBitmap& background); | 563 void SetBackground(const SkBitmap& background); |
508 | 564 |
509 // Notifies the renderer that the next key event is bound to one or more | 565 // Notifies the renderer that the next key event is bound to one or more |
510 // pre-defined edit commands | 566 // pre-defined edit commands |
511 void SetEditCommandsForNextKeyEvent( | 567 void SetEditCommandsForNextKeyEvent( |
512 const std::vector<EditCommand>& commands); | 568 const std::vector<EditCommand>& commands); |
513 | 569 |
514 // Relay a request from assistive technology to perform the default action | 570 // Relay a request from assistive technology to perform the default action |
515 // on a given node. | 571 // on a given node. |
(...skipping 24 matching lines...) Expand all Loading... |
540 const std::string& value); | 596 const std::string& value); |
541 | 597 |
542 // Tells the renderer to scroll the currently focused node into rect only if | 598 // Tells the renderer to scroll the currently focused node into rect only if |
543 // the currently focused node is a Text node (textfield, text area or content | 599 // the currently focused node is a Text node (textfield, text area or content |
544 // editable divs). | 600 // editable divs). |
545 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect); | 601 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect); |
546 | 602 |
547 // Requests the renderer to select the region between two points. | 603 // Requests the renderer to select the region between two points. |
548 void SelectRange(const gfx::Point& start, const gfx::Point& end); | 604 void SelectRange(const gfx::Point& start, const gfx::Point& end); |
549 | 605 |
550 // Edit operations. | |
551 void Undo(); | |
552 void Redo(); | |
553 void Cut(); | |
554 void Copy(); | |
555 void CopyToFindPboard(); | |
556 void Paste(); | |
557 void PasteAndMatchStyle(); | |
558 void Delete(); | |
559 void SelectAll(); | |
560 | |
561 // Called when the reponse to a pending mouse lock request has arrived. | 606 // Called when the reponse to a pending mouse lock request has arrived. |
562 // Returns true if |allowed| is true and the mouse has been successfully | 607 // Returns true if |allowed| is true and the mouse has been successfully |
563 // locked. | 608 // locked. |
564 bool GotResponseToLockMouseRequest(bool allowed); | 609 bool GotResponseToLockMouseRequest(bool allowed); |
565 | 610 |
566 // Called by the view in response to AcceleratedSurfaceBuffersSwapped. | 611 // Called by the view in response to AcceleratedSurfaceBuffersSwapped. |
567 static void AcknowledgeSwapBuffers(int32 route_id, int gpu_host_id); | 612 static void AcknowledgeSwapBuffers(int32 route_id, int gpu_host_id); |
568 static void AcknowledgePostSubBuffer(int32 route_id, int gpu_host_id); | 613 static void AcknowledgePostSubBuffer(int32 route_id, int gpu_host_id); |
569 | 614 |
570 protected: | 615 protected: |
| 616 virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE; |
| 617 |
571 // Internal implementation of the public Forward*Event() methods. | 618 // Internal implementation of the public Forward*Event() methods. |
572 void ForwardInputEvent(const WebKit::WebInputEvent& input_event, | 619 void ForwardInputEvent(const WebKit::WebInputEvent& input_event, |
573 int event_size, bool is_keyboard_shortcut); | 620 int event_size, bool is_keyboard_shortcut); |
574 | 621 |
575 // Called when we receive a notification indicating that the renderer | 622 // Called when we receive a notification indicating that the renderer |
576 // process has gone. This will reset our state so that our state will be | 623 // process has gone. This will reset our state so that our state will be |
577 // consistent if a new renderer is created. | 624 // consistent if a new renderer is created. |
578 void RendererExited(base::TerminationStatus status, int exit_code); | 625 void RendererExited(base::TerminationStatus status, int exit_code); |
579 | 626 |
580 // Retrieves an id the renderer can use to refer to its view. | 627 // Retrieves an id the renderer can use to refer to its view. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 bool IsMouseLocked() const; | 677 bool IsMouseLocked() const; |
631 | 678 |
632 // RenderViewHost overrides this method to report when in fullscreen mode. | 679 // RenderViewHost overrides this method to report when in fullscreen mode. |
633 virtual bool IsFullscreen() const; | 680 virtual bool IsFullscreen() const; |
634 | 681 |
635 // Indicates if the render widget host should track the render widget's size | 682 // Indicates if the render widget host should track the render widget's size |
636 // as opposed to visa versa. | 683 // as opposed to visa versa. |
637 void SetShouldAutoResize(bool enable); | 684 void SetShouldAutoResize(bool enable); |
638 | 685 |
639 protected: | 686 protected: |
| 687 // The View associated with the RenderViewHost. The lifetime of this object |
| 688 // is associated with the lifetime of the Render process. If the Renderer |
| 689 // crashes, its View is destroyed and this pointer becomes NULL, even though |
| 690 // render_view_host_ lives on to load another URL (creating a new View while |
| 691 // doing so). |
| 692 content::RenderWidgetHostViewPort* view_; |
| 693 |
640 // true if a renderer has once been valid. We use this flag to display a sad | 694 // true if a renderer has once been valid. We use this flag to display a sad |
641 // tab only when we lose our renderer and not if a paint occurs during | 695 // tab only when we lose our renderer and not if a paint occurs during |
642 // initialization. | 696 // initialization. |
643 bool renderer_initialized_; | 697 bool renderer_initialized_; |
644 | 698 |
645 // This value indicates how long to wait before we consider a renderer hung. | 699 // This value indicates how long to wait before we consider a renderer hung. |
646 int hung_renderer_delay_ms_; | 700 int hung_renderer_delay_ms_; |
647 | 701 |
648 private: | 702 private: |
649 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostTest, Resize); | 703 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostTest, Resize); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 // Called by OnMsgInputEventAck() to process a wheel event ack message. | 799 // Called by OnMsgInputEventAck() to process a wheel event ack message. |
746 // This could result in a task being posted to allow additional wheel | 800 // This could result in a task being posted to allow additional wheel |
747 // input messages to be coalesced. | 801 // input messages to be coalesced. |
748 void ProcessWheelAck(bool processed); | 802 void ProcessWheelAck(bool processed); |
749 | 803 |
750 // Called on OnMsgInputEventAck() to process a touch event ack message. | 804 // Called on OnMsgInputEventAck() to process a touch event ack message. |
751 // This can result in a gesture event being generated and sent back to the | 805 // This can result in a gesture event being generated and sent back to the |
752 // renderer. | 806 // renderer. |
753 void ProcessTouchAck(WebKit::WebInputEvent::Type type, bool processed); | 807 void ProcessTouchAck(WebKit::WebInputEvent::Type type, bool processed); |
754 | 808 |
| 809 // Created during construction but initialized during Init*(). Therefore, it |
| 810 // is guaranteed never to be NULL, but its channel may be NULL if the |
| 811 // renderer crashed, so you must always check that. |
| 812 content::RenderProcessHost* process_; |
| 813 |
| 814 // The ID of the corresponding object in the Renderer Instance. |
| 815 int routing_id_; |
| 816 |
755 // True if renderer accessibility is enabled. This should only be set when a | 817 // True if renderer accessibility is enabled. This should only be set when a |
756 // screenreader is detected as it can potentially slow down Chrome. | 818 // screenreader is detected as it can potentially slow down Chrome. |
757 bool renderer_accessible_; | 819 bool renderer_accessible_; |
758 | 820 |
759 // Stores random bits of data for others to associate with this object. | 821 // Stores random bits of data for others to associate with this object. |
760 base::PropertyBag property_bag_; | 822 base::PropertyBag property_bag_; |
761 | 823 |
762 // The ID of the corresponding object in the Renderer Instance. | |
763 int routing_id_; | |
764 | |
765 // The ID of the surface corresponding to this render widget. | 824 // The ID of the surface corresponding to this render widget. |
766 int surface_id_; | 825 int surface_id_; |
767 | 826 |
768 // Indicates whether a page is loading or not. | 827 // Indicates whether a page is loading or not. |
769 bool is_loading_; | 828 bool is_loading_; |
770 | 829 |
771 // Indicates whether a page is hidden or not. | 830 // Indicates whether a page is hidden or not. |
772 bool is_hidden_; | 831 bool is_hidden_; |
773 | 832 |
774 // True when a page is rendered directly via the GPU process. | 833 // True when a page is rendered directly via the GPU process. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 // then touch events are sent to the renderer. Otherwise, the touch events are | 956 // then touch events are sent to the renderer. Otherwise, the touch events are |
898 // not sent to the renderer. | 957 // not sent to the renderer. |
899 bool has_touch_handler_; | 958 bool has_touch_handler_; |
900 | 959 |
901 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_; | 960 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_; |
902 | 961 |
903 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl); | 962 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl); |
904 }; | 963 }; |
905 | 964 |
906 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_H_ | 965 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_H_ |
OLD | NEW |