Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Unified Diff: content/browser/renderer_host/render_widget_host.h

Issue 9473001: Extract minimal RenderViewHost interface for embedders, leaving (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ready for initial review. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host.h
diff --git a/content/browser/renderer_host/render_widget_host.h b/content/browser/renderer_host/render_widget_host.h
index 31fb45e275691a4e0bf53784bfca0008d2ff6963..f92d204cd2c8e092d47020a87684f5f02b399e6b 100644
--- a/content/browser/renderer_host/render_widget_host.h
+++ b/content/browser/renderer_host/render_widget_host.h
@@ -32,6 +32,7 @@
class BackingStore;
struct EditCommand;
class RenderViewHost;
+class RenderWidgetHostImpl;
class TransportDIB;
struct ViewHostMsg_UpdateRect_Params;
class WebCursor;
@@ -68,11 +69,99 @@ struct WebScreenInfo;
// TODO(joi): Once I finish defining this interface (once
// RenderViewHost interface is also in place), group together
// implementation functions in subclasses.
-class CONTENT_EXPORT RenderWidgetHost {
+//
+// TODO(joi): Move to file render_widget_host_impl.h
+class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Sender {
public:
- explicit RenderWidgetHost(content::RenderProcessHost* process);
virtual ~RenderWidgetHost() {}
+ // Edit operations.
+ virtual void Undo() = 0;
+ virtual void Redo() = 0;
+ virtual void Cut() = 0;
+ virtual void Copy() = 0;
+ virtual void CopyToFindPboard() = 0;
+ virtual void Paste() = 0;
+ virtual void PasteAndMatchStyle() = 0;
+ virtual void Delete() = 0;
+ virtual void SelectAll() = 0;
+
+ // Update the text direction of the focused input element and notify it to a
+ // renderer process.
+ // These functions have two usage scenarios: changing the text direction
+ // from a menu (as Safari does), and; changing the text direction when a user
+ // presses a set of keys (as IE and Firefox do).
+ // 1. Change the text direction from a menu.
+ // In this scenario, we receive a menu event only once and we should update
+ // the text direction immediately when a user chooses a menu item. So, we
+ // should call both functions at once as listed in the following snippet.
+ // void RenderViewHost::SetTextDirection(WebTextDirection direction) {
+ // UpdateTextDirection(direction);
+ // NotifyTextDirection();
+ // }
+ // 2. Change the text direction when pressing a set of keys.
+ // Because of auto-repeat, we may receive the same key-press event many
+ // times while we presses the keys and it is nonsense to send the same IPC
+ // message every time when we receive a key-press event.
+ // To suppress the number of IPC messages, we just update the text direction
+ // when receiving a key-press event and send an IPC message when we release
+ // the keys as listed in the following snippet.
+ // if (key_event.type == WebKeyboardEvent::KEY_DOWN) {
+ // if (key_event.windows_key_code == 'A' &&
+ // key_event.modifiers == WebKeyboardEvent::CTRL_KEY) {
+ // UpdateTextDirection(dir);
+ // } else {
+ // CancelUpdateTextDirection();
+ // }
+ // } else if (key_event.type == WebKeyboardEvent::KEY_UP) {
+ // NotifyTextDirection();
+ // }
+ // Once we cancel updating the text direction, we have to ignore all
+ // succeeding UpdateTextDirection() requests until calling
+ // NotifyTextDirection(). (We may receive keydown events even after we
+ // canceled updating the text direction because of auto-repeat.)
+ // Note: we cannot undo this change for compatibility with Firefox and IE.
+ virtual void UpdateTextDirection(WebKit::WebTextDirection direction) = 0;
+ virtual void NotifyTextDirection() = 0;
+
+ virtual void Blur() = 0;
+
+ // Enable renderer accessibility. This should only be called when a
+ // screenreader is detected.
+ virtual void EnableRendererAccessibility() = 0;
+
+ // Forwards the given message to the renderer. These are called by
+ // the view when it has received a message.
+ virtual void ForwardMouseEvent(
+ const WebKit::WebMouseEvent& mouse_event) = 0;
+ virtual void ForwardWheelEvent(
+ const WebKit::WebMouseWheelEvent& wheel_event) = 0;
+ virtual void ForwardKeyboardEvent(
+ const NativeWebKeyboardEvent& key_event) = 0;
+
+ // Get access to the widget's backing store. If a resize is in progress,
+ // then the current size of the backing store may be less than the size of
+ // the widget's view. If you pass |force_create| as true, then the backing
+ // store will be created if it doesn't exist. Otherwise, NULL will be returned
+ // if the backing store doesn't already exist. It will also return NULL if the
+ // backing store could not be created.
+ virtual BackingStore* GetBackingStore(bool force_create) = 0;
jam 2012/02/29 01:40:47 sorry my change conflicted with this!
Jói 2012/03/02 10:40:36 Hehe, no worries :)
+
+ virtual const gfx::Point& GetLastScrollOffset() const = 0;
+
+ virtual content::RenderProcessHost* GetProcess() const = 0;
+
+ virtual int GetRoutingID() const = 0;
+
+ // Gets the View of this RenderWidgetHost. Can be NULL, e.g. if the
+ // RenderWidget is being destroyed or the render process crashed. You should
+ // never cache this pointer since it can become NULL if the renderer crashes,
+ // instead you should always ask for it using the accessor.
+ virtual content::RenderWidgetHostView* GetView() const = 0;
+
+ // Returns true if this is a RenderViewHost, false if not.
+ virtual bool IsRenderView() const = 0;
+
// Used as the details object for a
// RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK notification.
// TODO(joi): Switch out for a std::pair.
@@ -97,49 +186,46 @@ class CONTENT_EXPORT RenderWidgetHost {
const gfx::Size& page_size,
const gfx::Size& desired_size) = 0;
- // Get access to the widget's backing store. If a resize is in progress,
- // then the current size of the backing store may be less than the size of
- // the widget's view. If you pass |force_create| as true, then the backing
- // store will be created if it doesn't exist. Otherwise, NULL will be returned
- // if the backing store doesn't already exist. It will also return NULL if the
- // backing store could not be created.
- virtual BackingStore* GetBackingStore(bool force_create) = 0;
+ // Makes an IPC call to tell webkit to replace the currently selected word
+ // or a word around the cursor.
+ virtual void Replace(const string16& word) = 0;
- // Returns true if this is a RenderViewHost, false if not.
- virtual bool IsRenderView() const = 0;
+ // Called to notify the RenderWidget that the resize rect has changed without
+ // the size of the RenderWidget itself changing.
+ virtual void ResizeRectChanged(const gfx::Rect& new_rect) = 0;
+
+ // Restart the active hang monitor timeout. Clears all existing timeouts and
+ // starts with a new one. This can be because the renderer has become
+ // active, the tab is being hidden, or the user has chosen to wait some more
+ // to give the tab a chance to become active and we don't want to display a
+ // warning too soon.
+ virtual void RestartHangMonitorTimeout() = 0;
+
+ virtual void SetIgnoreInputEvents(bool ignore_input_events) = 0;
+
+ // Stops loading the page.
+ virtual void Stop() = 0;
// Called to notify the RenderWidget that it has been resized.
virtual void WasResized() = 0;
- // TODO(joi): Get rid of these inline accessors and the associated
- // data from the interface, make them into pure virtual GetFoo
- // methods instead.
- content::RenderProcessHost* process() const { return process_; }
+ // Access to the implementation's
+ // IPC::Channel::Listener::OnMessageReceived. Intended only for
+ // test code.
+ virtual bool OnMessageReceivedForTesting(const IPC::Message& msg) = 0;
- // Gets the View of this RenderWidgetHost. Can be NULL, e.g. if the
- // RenderWidget is being destroyed or the render process crashed. You should
- // never cache this pointer since it can become NULL if the renderer crashes,
- // instead you should always ask for it using the accessor.
- content::RenderWidgetHostView* view() const;
+ // Retrieves the implementation class. Intended only for code
+ // within content/. This method is necessary because
+ // RenderWidgetHost is the root of a diamond inheritance pattern, so
+ // subclasses inherit it virtually, which removes our ability to
+ // static_cast to the subclass.
+ virtual RenderWidgetHostImpl* AsRWHImpl() = 0;
// Gets a RenderVidgetHost pointer from an IPC::Channel::Listener pointer.
static RenderWidgetHost* FromIPCChannelListener(
IPC::Channel::Listener* listener);
static const RenderWidgetHost* FromIPCChannelListener(
const IPC::Channel::Listener* listener);
-
- protected:
- // Created during construction but initialized during Init*(). Therefore, it
- // is guaranteed never to be NULL, but its channel may be NULL if the
- // renderer crashed, so you must always check that.
- content::RenderProcessHost* process_;
-
- // The View associated with the RenderViewHost. The lifetime of this object
- // is associated with the lifetime of the Render process. If the Renderer
- // crashes, its View is destroyed and this pointer becomes NULL, even though
- // render_view_host_ lives on to load another URL (creating a new View while
- // doing so).
- content::RenderWidgetHostViewPort* view_;
};
// This class manages the browser side of a browser<->renderer HWND connection.
@@ -217,9 +303,8 @@ class CONTENT_EXPORT RenderWidgetHost {
// the RenderWidgetHost's IPC message map.
//
// TODO(joi): Move to content namespace.
-class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
- public IPC::Channel::Listener,
- public IPC::Channel::Sender {
+class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
+ public IPC::Channel::Listener {
public:
// routing_id can be MSG_ROUTING_NONE, in which case the next available
// routing id is taken from the RenderProcessHost.
@@ -228,10 +313,48 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
static RenderWidgetHostImpl* FromRWHV(content::RenderWidgetHostView* rwhv);
+ // RenderWidgetHost implementation.
+ virtual void Undo() OVERRIDE;
+ virtual void Redo() OVERRIDE;
+ virtual void Cut() OVERRIDE;
+ virtual void Copy() OVERRIDE;
+ virtual void CopyToFindPboard() OVERRIDE;
+ virtual void Paste() OVERRIDE;
+ virtual void PasteAndMatchStyle() OVERRIDE;
+ virtual void Delete() OVERRIDE;
+ virtual void SelectAll() OVERRIDE;
+ virtual void UpdateTextDirection(WebKit::WebTextDirection direction) OVERRIDE;
+ virtual void NotifyTextDirection() OVERRIDE;
+ virtual void Blur() OVERRIDE;
+ virtual void EnableRendererAccessibility() OVERRIDE;
+ virtual void ForwardMouseEvent(
+ const WebKit::WebMouseEvent& mouse_event) OVERRIDE;
+ virtual void ForwardWheelEvent(
+ const WebKit::WebMouseWheelEvent& wheel_event) OVERRIDE;
+ virtual void ForwardKeyboardEvent(
+ const NativeWebKeyboardEvent& key_event) OVERRIDE;
+ virtual BackingStore* GetBackingStore(bool force_create) OVERRIDE;
+ virtual const gfx::Point& GetLastScrollOffset() const OVERRIDE;
+ virtual content::RenderProcessHost* GetProcess() const OVERRIDE;
+ virtual int GetRoutingID() const OVERRIDE;
+ virtual content::RenderWidgetHostView* GetView() const OVERRIDE;
+ virtual bool IsRenderView() const OVERRIDE;
+ virtual void PaintAtSize(TransportDIB::Handle dib_handle,
+ int tag,
+ const gfx::Size& page_size,
+ const gfx::Size& desired_size) OVERRIDE;
+ virtual void Replace(const string16& word) OVERRIDE;
+ virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE;
+ virtual void RestartHangMonitorTimeout() OVERRIDE;
+ virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+ virtual void WasResized() OVERRIDE;
+ virtual bool OnMessageReceivedForTesting(const IPC::Message& msg) OVERRIDE;
+ virtual RenderWidgetHostImpl* AsRWHImpl() OVERRIDE;
+
// Sets the View of this RenderWidgetHost.
void SetView(content::RenderWidgetHostView* view);
- int routing_id() const { return routing_id_; }
int surface_id() const { return surface_id_; }
bool renderer_accessible() { return renderer_accessible_; }
@@ -251,9 +374,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
// Tells the renderer to die and then calls Destroy().
virtual void Shutdown();
- // Manual RTTI FTW. We are not hosting a web page.
- virtual bool IsRenderView() const OVERRIDE;
-
// IPC::Channel::Listener
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
@@ -265,19 +385,12 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
void WasHidden();
void WasRestored();
- virtual void WasResized() OVERRIDE;
-
- // Called to notify the RenderWidget that the resize rect has changed without
- // the size of the RenderWidget itself changing.
- void ResizeRectChanged(const gfx::Rect& new_rect);
-
// Called to notify the RenderWidget that its associated native window got
// focused.
virtual void GotFocus();
// Tells the renderer it got/lost focus.
void Focus();
- void Blur();
virtual void LostCapture();
// Sets whether the renderer should show controls in an active state. On all
@@ -300,13 +413,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
// Indicates if the page has finished loading.
void SetIsLoading(bool is_loading);
- virtual void PaintAtSize(TransportDIB::Handle dib_handle,
- int tag,
- const gfx::Size& page_size,
- const gfx::Size& desired_size) OVERRIDE;
-
- virtual BackingStore* GetBackingStore(bool force_create) OVERRIDE;
-
// Allocate a new backing store of the given size. Returns NULL on failure
// (for example, if we don't currently have a RenderWidgetHostView.)
BackingStore* AllocBackingStore(const gfx::Size& size);
@@ -326,65 +432,19 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
// left on the existing timeouts.
void StartHangMonitorTimeout(base::TimeDelta delay);
- // Restart the active hang monitor timeout. Clears all existing timeouts and
- // starts with a new one. This can be because the renderer has become
- // active, the tab is being hidden, or the user has chosen to wait some more
- // to give the tab a chance to become active and we don't want to display a
- // warning too soon.
- void RestartHangMonitorTimeout();
-
// Stops all existing hang monitor timeouts and assumes the renderer is
// responsive.
void StopHangMonitorTimeout();
// Forwards the given message to the renderer. These are called by the view
// when it has received a message.
- virtual void ForwardMouseEvent(const WebKit::WebMouseEvent& mouse_event);
- // Called when a mouse click activates the renderer.
- virtual void OnMouseActivate();
- void ForwardWheelEvent(const WebKit::WebMouseWheelEvent& wheel_event);
void ForwardGestureEvent(const WebKit::WebGestureEvent& gesture_event);
- virtual void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event);
virtual void ForwardTouchEvent(const WebKit::WebTouchEvent& touch_event);
- // Update the text direction of the focused input element and notify it to a
- // renderer process.
- // These functions have two usage scenarios: changing the text direction
- // from a menu (as Safari does), and; changing the text direction when a user
- // presses a set of keys (as IE and Firefox do).
- // 1. Change the text direction from a menu.
- // In this scenario, we receive a menu event only once and we should update
- // the text direction immediately when a user chooses a menu item. So, we
- // should call both functions at once as listed in the following snippet.
- // void RenderViewHost::SetTextDirection(WebTextDirection direction) {
- // UpdateTextDirection(direction);
- // NotifyTextDirection();
- // }
- // 2. Change the text direction when pressing a set of keys.
- // Because of auto-repeat, we may receive the same key-press event many
- // times while we presses the keys and it is nonsense to send the same IPC
- // message every time when we receive a key-press event.
- // To suppress the number of IPC messages, we just update the text direction
- // when receiving a key-press event and send an IPC message when we release
- // the keys as listed in the following snippet.
- // if (key_event.type == WebKeyboardEvent::KEY_DOWN) {
- // if (key_event.windows_key_code == 'A' &&
- // key_event.modifiers == WebKeyboardEvent::CTRL_KEY) {
- // UpdateTextDirection(dir);
- // } else {
- // CancelUpdateTextDirection();
- // }
- // } else if (key_event.type == WebKeyboardEvent::KEY_UP) {
- // NotifyTextDirection();
- // }
- // Once we cancel updating the text direction, we have to ignore all
- // succeeding UpdateTextDirection() requests until calling
- // NotifyTextDirection(). (We may receive keydown events even after we
- // canceled updating the text direction because of auto-repeat.)
- // Note: we cannot undo this change for compatibility with Firefox and IE.
- void UpdateTextDirection(WebKit::WebTextDirection direction);
void CancelUpdateTextDirection();
- void NotifyTextDirection();
+
+ // Called when a mouse click activates the renderer.
+ virtual void OnMouseActivate();
// Notifies the renderer whether or not the input method attached to this
// process is activated.
@@ -436,17 +496,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
// And to also expose it to the RenderWidgetHostView.
virtual gfx::Rect GetRootWindowResizerRect() const;
- // Makes an IPC call to tell webkit to replace the currently selected word
- // or a word around the cursor.
- void Replace(const string16& word);
-
- // Enable renderer accessibility. This should only be called when a
- // screenreader is detected.
- void EnableRendererAccessibility();
-
- void set_ignore_input_events(bool ignore_input_events) {
- ignore_input_events_ = ignore_input_events;
- }
bool ignore_input_events() const {
return ignore_input_events_;
}
@@ -454,17 +503,12 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
// Activate deferred plugin handles.
void ActivateDeferredPluginHandles();
- const gfx::Point& last_scroll_offset() const { return last_scroll_offset_; }
-
bool has_touch_handler() const { return has_touch_handler_; }
// Notification that the user has made some kind of input that could
// perform an action. See OnUserGesture for more details.
void StartUserGesture();
- // Stops loading the page.
- void Stop();
-
// Set the RenderView background.
void SetBackground(const SkBitmap& background);
@@ -509,17 +553,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
// Requests the renderer to select the region between two points.
void SelectRange(const gfx::Point& start, const gfx::Point& end);
- // Edit operations.
- void Undo();
- void Redo();
- void Cut();
- void Copy();
- void CopyToFindPboard();
- void Paste();
- void PasteAndMatchStyle();
- void Delete();
- void SelectAll();
-
// Called when the reponse to a pending mouse lock request has arrived.
// Returns true if |allowed| is true and the mouse has been successfully
// locked.
@@ -599,6 +632,13 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
void SetShouldAutoResize(bool enable);
protected:
+ // The View associated with the RenderViewHost. The lifetime of this object
+ // is associated with the lifetime of the Render process. If the Renderer
+ // crashes, its View is destroyed and this pointer becomes NULL, even though
+ // render_view_host_ lives on to load another URL (creating a new View while
+ // doing so).
+ content::RenderWidgetHostViewPort* view_;
+
// true if a renderer has once been valid. We use this flag to display a sad
// tab only when we lose our renderer and not if a paint occurs during
// initialization.
@@ -716,6 +756,14 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
// renderer.
void ProcessTouchAck(bool processed);
+ // Created during construction but initialized during Init*(). Therefore, it
+ // is guaranteed never to be NULL, but its channel may be NULL if the
+ // renderer crashed, so you must always check that.
+ content::RenderProcessHost* process_;
+
+ // The ID of the corresponding object in the Renderer Instance.
+ int routing_id_;
+
// True if renderer accessibility is enabled. This should only be set when a
// screenreader is detected as it can potentially slow down Chrome.
bool renderer_accessible_;
@@ -723,9 +771,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost,
// Stores random bits of data for others to associate with this object.
base::PropertyBag property_bag_;
- // The ID of the corresponding object in the Renderer Instance.
- int routing_id_;
-
// The ID of the surface corresponding to this render widget.
int surface_id_;

Powered by Google App Engine
This is Rietveld 408576698