| 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_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
| 18 #include "base/property_bag.h" | 18 #include "base/property_bag.h" |
| 19 #include "base/string16.h" | 19 #include "base/string16.h" |
| 20 #include "base/timer.h" | 20 #include "base/timer.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "content/public/browser/render_widget_host.h" | 22 #include "content/public/browser/render_widget_host.h" |
| 23 #include "content/public/common/page_zoom.h" | 23 #include "content/public/common/page_zoom.h" |
| 24 #include "ui/base/ime/text_input_type.h" | 24 #include "ui/base/ime/text_input_type.h" |
| 25 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
| 26 | 26 |
| 27 class BackingStore; | 27 class BackingStore; |
| 28 class MockRenderWidgetHost; |
| 29 class WebCursor; |
| 28 struct EditCommand; | 30 struct EditCommand; |
| 29 struct ViewHostMsg_UpdateRect_Params; | 31 struct ViewHostMsg_UpdateRect_Params; |
| 30 class WebCursor; | |
| 31 | 32 |
| 32 namespace base { | 33 namespace base { |
| 33 class TimeTicks; | 34 class TimeTicks; |
| 34 } | 35 } |
| 35 | 36 |
| 36 namespace content { | |
| 37 class RenderWidgetHostViewPort; | |
| 38 } | |
| 39 | |
| 40 namespace ui { | 37 namespace ui { |
| 41 class Range; | 38 class Range; |
| 42 } | 39 } |
| 43 | 40 |
| 44 namespace WebKit { | 41 namespace WebKit { |
| 45 class WebInputEvent; | 42 class WebInputEvent; |
| 46 class WebMouseEvent; | 43 class WebMouseEvent; |
| 47 struct WebCompositionUnderline; | 44 struct WebCompositionUnderline; |
| 48 struct WebScreenInfo; | 45 struct WebScreenInfo; |
| 49 } | 46 } |
| 50 | 47 |
| 48 namespace content { |
| 49 |
| 50 class RenderWidgetHostViewPort; |
| 51 |
| 51 // This implements the RenderWidgetHost interface that is exposed to | 52 // This implements the RenderWidgetHost interface that is exposed to |
| 52 // embedders of content, and adds things only visible to content. | 53 // embedders of content, and adds things only visible to content. |
| 53 // | |
| 54 // TODO(joi): Move to content namespace. | |
| 55 class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, | 54 class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, |
| 56 public IPC::Channel::Listener { | 55 public IPC::Channel::Listener { |
| 57 public: | 56 public: |
| 58 // routing_id can be MSG_ROUTING_NONE, in which case the next available | 57 // routing_id can be MSG_ROUTING_NONE, in which case the next available |
| 59 // routing id is taken from the RenderProcessHost. | 58 // routing id is taken from the RenderProcessHost. |
| 60 RenderWidgetHostImpl(content::RenderProcessHost* process, int routing_id); | 59 RenderWidgetHostImpl(RenderProcessHost* process, int routing_id); |
| 61 virtual ~RenderWidgetHostImpl(); | 60 virtual ~RenderWidgetHostImpl(); |
| 62 | 61 |
| 63 // Use RenderWidgetHostImpl::From(rwh) to downcast a | 62 // Use RenderWidgetHostImpl::From(rwh) to downcast a |
| 64 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this | 63 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this |
| 65 // uses RenderWidgetHost::AsRenderWidgetHostImpl(). | 64 // uses RenderWidgetHost::AsRenderWidgetHostImpl(). |
| 66 static RenderWidgetHostImpl* From(RenderWidgetHost* rwh); | 65 static RenderWidgetHostImpl* From(RenderWidgetHost* rwh); |
| 67 | 66 |
| 68 // RenderWidgetHost implementation. | 67 // RenderWidgetHost implementation. |
| 69 virtual void Undo() OVERRIDE; | 68 virtual void Undo() OVERRIDE; |
| 70 virtual void Redo() OVERRIDE; | 69 virtual void Redo() OVERRIDE; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 88 CGContextRef target) OVERRIDE; | 87 CGContextRef target) OVERRIDE; |
| 89 #endif | 88 #endif |
| 90 virtual void EnableRendererAccessibility() OVERRIDE; | 89 virtual void EnableRendererAccessibility() OVERRIDE; |
| 91 virtual void ForwardMouseEvent( | 90 virtual void ForwardMouseEvent( |
| 92 const WebKit::WebMouseEvent& mouse_event) OVERRIDE; | 91 const WebKit::WebMouseEvent& mouse_event) OVERRIDE; |
| 93 virtual void ForwardWheelEvent( | 92 virtual void ForwardWheelEvent( |
| 94 const WebKit::WebMouseWheelEvent& wheel_event) OVERRIDE; | 93 const WebKit::WebMouseWheelEvent& wheel_event) OVERRIDE; |
| 95 virtual void ForwardKeyboardEvent( | 94 virtual void ForwardKeyboardEvent( |
| 96 const NativeWebKeyboardEvent& key_event) OVERRIDE; | 95 const NativeWebKeyboardEvent& key_event) OVERRIDE; |
| 97 virtual const gfx::Point& GetLastScrollOffset() const OVERRIDE; | 96 virtual const gfx::Point& GetLastScrollOffset() const OVERRIDE; |
| 98 virtual content::RenderProcessHost* GetProcess() const OVERRIDE; | 97 virtual RenderProcessHost* GetProcess() const OVERRIDE; |
| 99 virtual int GetRoutingID() const OVERRIDE; | 98 virtual int GetRoutingID() const OVERRIDE; |
| 100 virtual content::RenderWidgetHostView* GetView() const OVERRIDE; | 99 virtual RenderWidgetHostView* GetView() const OVERRIDE; |
| 101 virtual bool IsRenderView() const OVERRIDE; | 100 virtual bool IsRenderView() const OVERRIDE; |
| 102 virtual void PaintAtSize(TransportDIB::Handle dib_handle, | 101 virtual void PaintAtSize(TransportDIB::Handle dib_handle, |
| 103 int tag, | 102 int tag, |
| 104 const gfx::Size& page_size, | 103 const gfx::Size& page_size, |
| 105 const gfx::Size& desired_size) OVERRIDE; | 104 const gfx::Size& desired_size) OVERRIDE; |
| 106 virtual void Replace(const string16& word) OVERRIDE; | 105 virtual void Replace(const string16& word) OVERRIDE; |
| 107 virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE; | 106 virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE; |
| 108 virtual void RestartHangMonitorTimeout() OVERRIDE; | 107 virtual void RestartHangMonitorTimeout() OVERRIDE; |
| 109 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; | 108 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; |
| 110 virtual void Stop() OVERRIDE; | 109 virtual void Stop() OVERRIDE; |
| 111 virtual void WasResized() OVERRIDE; | 110 virtual void WasResized() OVERRIDE; |
| 112 virtual bool OnMessageReceivedForTesting(const IPC::Message& msg) OVERRIDE; | 111 virtual bool OnMessageReceivedForTesting(const IPC::Message& msg) OVERRIDE; |
| 113 | 112 |
| 114 // Sets the View of this RenderWidgetHost. | 113 // Sets the View of this RenderWidgetHost. |
| 115 void SetView(content::RenderWidgetHostView* view); | 114 void SetView(RenderWidgetHostView* view); |
| 116 | 115 |
| 117 int surface_id() const { return surface_id_; } | 116 int surface_id() const { return surface_id_; } |
| 118 bool renderer_accessible() { return renderer_accessible_; } | 117 bool renderer_accessible() { return renderer_accessible_; } |
| 119 | 118 |
| 120 bool empty() const { return current_size_.IsEmpty(); } | 119 bool empty() const { return current_size_.IsEmpty(); } |
| 121 | 120 |
| 122 // Returns the property bag for this widget, where callers can add extra data | 121 // Returns the property bag for this widget, where callers can add extra data |
| 123 // they may wish to associate with it. Returns a pointer rather than a | 122 // they may wish to associate with it. Returns a pointer rather than a |
| 124 // reference since the PropertyAccessors expect this. | 123 // reference since the PropertyAccessors expect this. |
| 125 const base::PropertyBag* property_bag() const { return &property_bag_; } | 124 const base::PropertyBag* property_bag() const { return &property_bag_; } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 // Indicates if the render widget host should track the render widget's size | 398 // Indicates if the render widget host should track the render widget's size |
| 400 // as opposed to visa versa. | 399 // as opposed to visa versa. |
| 401 void SetShouldAutoResize(bool enable); | 400 void SetShouldAutoResize(bool enable); |
| 402 | 401 |
| 403 protected: | 402 protected: |
| 404 // The View associated with the RenderViewHost. The lifetime of this object | 403 // The View associated with the RenderViewHost. The lifetime of this object |
| 405 // is associated with the lifetime of the Render process. If the Renderer | 404 // is associated with the lifetime of the Render process. If the Renderer |
| 406 // crashes, its View is destroyed and this pointer becomes NULL, even though | 405 // crashes, its View is destroyed and this pointer becomes NULL, even though |
| 407 // render_view_host_ lives on to load another URL (creating a new View while | 406 // render_view_host_ lives on to load another URL (creating a new View while |
| 408 // doing so). | 407 // doing so). |
| 409 content::RenderWidgetHostViewPort* view_; | 408 RenderWidgetHostViewPort* view_; |
| 410 | 409 |
| 411 // true if a renderer has once been valid. We use this flag to display a sad | 410 // true if a renderer has once been valid. We use this flag to display a sad |
| 412 // tab only when we lose our renderer and not if a paint occurs during | 411 // tab only when we lose our renderer and not if a paint occurs during |
| 413 // initialization. | 412 // initialization. |
| 414 bool renderer_initialized_; | 413 bool renderer_initialized_; |
| 415 | 414 |
| 416 // This value indicates how long to wait before we consider a renderer hung. | 415 // This value indicates how long to wait before we consider a renderer hung. |
| 417 int hung_renderer_delay_ms_; | 416 int hung_renderer_delay_ms_; |
| 418 | 417 |
| 419 private: | 418 private: |
| 420 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostTest, Resize); | 419 friend class ::MockRenderWidgetHost; |
| 421 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostTest, ResizeThenCrash); | |
| 422 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostTest, HiddenPaint); | |
| 423 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostTest, PaintAtSize); | |
| 424 | 420 |
| 425 // Tell this object to destroy itself. | 421 // Tell this object to destroy itself. |
| 426 void Destroy(); | 422 void Destroy(); |
| 427 | 423 |
| 428 // Checks whether the renderer is hung and calls NotifyRendererUnresponsive | 424 // Checks whether the renderer is hung and calls NotifyRendererUnresponsive |
| 429 // if it is. | 425 // if it is. |
| 430 void CheckRendererIsUnresponsive(); | 426 void CheckRendererIsUnresponsive(); |
| 431 | 427 |
| 432 // Called if we know the renderer is responsive. When we currently think the | 428 // Called if we know the renderer is responsive. When we currently think the |
| 433 // renderer is unresponsive, this will clear that state and call | 429 // renderer is unresponsive, this will clear that state and call |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 void ProcessWheelAck(bool processed); | 515 void ProcessWheelAck(bool processed); |
| 520 | 516 |
| 521 // Called on OnMsgInputEventAck() to process a touch event ack message. | 517 // Called on OnMsgInputEventAck() to process a touch event ack message. |
| 522 // This can result in a gesture event being generated and sent back to the | 518 // This can result in a gesture event being generated and sent back to the |
| 523 // renderer. | 519 // renderer. |
| 524 void ProcessTouchAck(WebKit::WebInputEvent::Type type, bool processed); | 520 void ProcessTouchAck(WebKit::WebInputEvent::Type type, bool processed); |
| 525 | 521 |
| 526 // Created during construction but initialized during Init*(). Therefore, it | 522 // Created during construction but initialized during Init*(). Therefore, it |
| 527 // is guaranteed never to be NULL, but its channel may be NULL if the | 523 // is guaranteed never to be NULL, but its channel may be NULL if the |
| 528 // renderer crashed, so you must always check that. | 524 // renderer crashed, so you must always check that. |
| 529 content::RenderProcessHost* process_; | 525 RenderProcessHost* process_; |
| 530 | 526 |
| 531 // The ID of the corresponding object in the Renderer Instance. | 527 // The ID of the corresponding object in the Renderer Instance. |
| 532 int routing_id_; | 528 int routing_id_; |
| 533 | 529 |
| 534 // True if renderer accessibility is enabled. This should only be set when a | 530 // True if renderer accessibility is enabled. This should only be set when a |
| 535 // screenreader is detected as it can potentially slow down Chrome. | 531 // screenreader is detected as it can potentially slow down Chrome. |
| 536 bool renderer_accessible_; | 532 bool renderer_accessible_; |
| 537 | 533 |
| 538 // Stores random bits of data for others to associate with this object. | 534 // Stores random bits of data for others to associate with this object. |
| 539 base::PropertyBag property_bag_; | 535 base::PropertyBag property_bag_; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 // Keeps track of whether the webpage has any touch event handler. If it does, | 668 // Keeps track of whether the webpage has any touch event handler. If it does, |
| 673 // then touch events are sent to the renderer. Otherwise, the touch events are | 669 // then touch events are sent to the renderer. Otherwise, the touch events are |
| 674 // not sent to the renderer. | 670 // not sent to the renderer. |
| 675 bool has_touch_handler_; | 671 bool has_touch_handler_; |
| 676 | 672 |
| 677 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_; | 673 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_; |
| 678 | 674 |
| 679 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl); | 675 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl); |
| 680 }; | 676 }; |
| 681 | 677 |
| 678 } // namespace content |
| 679 |
| 682 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ | 680 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ |
| OLD | NEW |