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 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 #include <queue> | 11 #include <queue> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
21 #include "base/process/kill.h" | 21 #include "base/process/kill.h" |
22 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
24 #include "base/timer/timer.h" | 24 #include "base/timer/timer.h" |
25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
26 #include "cc/resources/shared_bitmap.h" | 26 #include "cc/resources/shared_bitmap.h" |
27 #include "content/browser/accessibility/browser_accessibility_manager.h" | |
28 #include "content/browser/renderer_host/event_with_latency_info.h" | 27 #include "content/browser/renderer_host/event_with_latency_info.h" |
29 #include "content/browser/renderer_host/input/input_ack_handler.h" | 28 #include "content/browser/renderer_host/input/input_ack_handler.h" |
30 #include "content/browser/renderer_host/input/input_router_client.h" | 29 #include "content/browser/renderer_host/input/input_router_client.h" |
31 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 30 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
32 #include "content/browser/renderer_host/input/touch_emulator_client.h" | 31 #include "content/browser/renderer_host/input/touch_emulator_client.h" |
33 #include "content/common/input/input_event_ack_state.h" | 32 #include "content/common/input/input_event_ack_state.h" |
34 #include "content/common/input/synthetic_gesture_packet.h" | 33 #include "content/common/input/synthetic_gesture_packet.h" |
35 #include "content/common/view_message_enums.h" | 34 #include "content/common/view_message_enums.h" |
36 #include "content/public/browser/render_widget_host.h" | 35 #include "content/public/browser/render_widget_host.h" |
37 #include "content/public/common/page_zoom.h" | 36 #include "content/public/common/page_zoom.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 struct WebScreenInfo; | 70 struct WebScreenInfo; |
72 } | 71 } |
73 | 72 |
74 #if defined(OS_ANDROID) | 73 #if defined(OS_ANDROID) |
75 namespace blink { | 74 namespace blink { |
76 class WebLayer; | 75 class WebLayer; |
77 } | 76 } |
78 #endif | 77 #endif |
79 | 78 |
80 namespace content { | 79 namespace content { |
| 80 class BrowserAccessibilityManager; |
81 class InputRouter; | 81 class InputRouter; |
82 class MockRenderWidgetHost; | 82 class MockRenderWidgetHost; |
83 class RenderWidgetHostDelegate; | 83 class RenderWidgetHostDelegate; |
84 class RenderWidgetHostViewBase; | 84 class RenderWidgetHostViewBase; |
85 class SyntheticGestureController; | 85 class SyntheticGestureController; |
86 class TimeoutMonitor; | 86 class TimeoutMonitor; |
87 class TouchEmulator; | 87 class TouchEmulator; |
88 class WebCursor; | 88 class WebCursor; |
89 struct EditCommand; | 89 struct EditCommand; |
90 | 90 |
91 // This implements the RenderWidgetHost interface that is exposed to | 91 // This implements the RenderWidgetHost interface that is exposed to |
92 // embedders of content, and adds things only visible to content. | 92 // embedders of content, and adds things only visible to content. |
93 class CONTENT_EXPORT RenderWidgetHostImpl | 93 class CONTENT_EXPORT RenderWidgetHostImpl |
94 : virtual public RenderWidgetHost, | 94 : virtual public RenderWidgetHost, |
95 public InputRouterClient, | 95 public InputRouterClient, |
96 public InputAckHandler, | 96 public InputAckHandler, |
97 public TouchEmulatorClient, | 97 public TouchEmulatorClient, |
98 public IPC::Listener, | 98 public IPC::Listener { |
99 public BrowserAccessibilityDelegate { | |
100 public: | 99 public: |
101 // routing_id can be MSG_ROUTING_NONE, in which case the next available | 100 // routing_id can be MSG_ROUTING_NONE, in which case the next available |
102 // routing id is taken from the RenderProcessHost. | 101 // routing id is taken from the RenderProcessHost. |
103 // If this object outlives |delegate|, DetachDelegate() must be called when | 102 // If this object outlives |delegate|, DetachDelegate() must be called when |
104 // |delegate| goes away. | 103 // |delegate| goes away. |
105 RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, | 104 RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, |
106 RenderProcessHost* process, | 105 RenderProcessHost* process, |
107 int routing_id, | 106 int routing_id, |
108 bool hidden); | 107 bool hidden); |
109 virtual ~RenderWidgetHostImpl(); | 108 virtual ~RenderWidgetHostImpl(); |
(...skipping 24 matching lines...) Expand all Loading... |
134 virtual void CopyFromBackingStore( | 133 virtual void CopyFromBackingStore( |
135 const gfx::Rect& src_rect, | 134 const gfx::Rect& src_rect, |
136 const gfx::Size& accelerated_dst_size, | 135 const gfx::Size& accelerated_dst_size, |
137 const base::Callback<void(bool, const SkBitmap&)>& callback, | 136 const base::Callback<void(bool, const SkBitmap&)>& callback, |
138 const SkColorType color_type) OVERRIDE; | 137 const SkColorType color_type) OVERRIDE; |
139 virtual bool CanCopyFromBackingStore() OVERRIDE; | 138 virtual bool CanCopyFromBackingStore() OVERRIDE; |
140 #if defined(OS_ANDROID) | 139 #if defined(OS_ANDROID) |
141 virtual void LockBackingStore() OVERRIDE; | 140 virtual void LockBackingStore() OVERRIDE; |
142 virtual void UnlockBackingStore() OVERRIDE; | 141 virtual void UnlockBackingStore() OVERRIDE; |
143 #endif | 142 #endif |
144 virtual void EnableFullAccessibilityMode() OVERRIDE; | |
145 virtual bool IsFullAccessibilityModeForTesting() OVERRIDE; | |
146 virtual void EnableTreeOnlyAccessibilityMode() OVERRIDE; | |
147 virtual bool IsTreeOnlyAccessibilityModeForTesting() OVERRIDE; | |
148 virtual void ForwardMouseEvent( | 143 virtual void ForwardMouseEvent( |
149 const blink::WebMouseEvent& mouse_event) OVERRIDE; | 144 const blink::WebMouseEvent& mouse_event) OVERRIDE; |
150 virtual void ForwardWheelEvent( | 145 virtual void ForwardWheelEvent( |
151 const blink::WebMouseWheelEvent& wheel_event) OVERRIDE; | 146 const blink::WebMouseWheelEvent& wheel_event) OVERRIDE; |
152 virtual void ForwardKeyboardEvent( | 147 virtual void ForwardKeyboardEvent( |
153 const NativeWebKeyboardEvent& key_event) OVERRIDE; | 148 const NativeWebKeyboardEvent& key_event) OVERRIDE; |
154 virtual const gfx::Vector2d& GetLastScrollOffset() const OVERRIDE; | 149 virtual const gfx::Vector2d& GetLastScrollOffset() const OVERRIDE; |
155 virtual RenderProcessHost* GetProcess() const OVERRIDE; | 150 virtual RenderProcessHost* GetProcess() const OVERRIDE; |
156 virtual int GetRoutingID() const OVERRIDE; | 151 virtual int GetRoutingID() const OVERRIDE; |
157 virtual RenderWidgetHostView* GetView() const OVERRIDE; | 152 virtual RenderWidgetHostView* GetView() const OVERRIDE; |
158 virtual bool IsLoading() const OVERRIDE; | 153 virtual bool IsLoading() const OVERRIDE; |
159 virtual bool IsRenderView() const OVERRIDE; | 154 virtual bool IsRenderView() const OVERRIDE; |
160 virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE; | 155 virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE; |
161 virtual void RestartHangMonitorTimeout() OVERRIDE; | 156 virtual void RestartHangMonitorTimeout() OVERRIDE; |
162 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; | 157 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; |
163 virtual void Stop() OVERRIDE; | 158 virtual void Stop() OVERRIDE; |
164 virtual void WasResized() OVERRIDE; | 159 virtual void WasResized() OVERRIDE; |
165 virtual void AddKeyPressEventCallback( | 160 virtual void AddKeyPressEventCallback( |
166 const KeyPressEventCallback& callback) OVERRIDE; | 161 const KeyPressEventCallback& callback) OVERRIDE; |
167 virtual void RemoveKeyPressEventCallback( | 162 virtual void RemoveKeyPressEventCallback( |
168 const KeyPressEventCallback& callback) OVERRIDE; | 163 const KeyPressEventCallback& callback) OVERRIDE; |
169 virtual void AddMouseEventCallback( | 164 virtual void AddMouseEventCallback( |
170 const MouseEventCallback& callback) OVERRIDE; | 165 const MouseEventCallback& callback) OVERRIDE; |
171 virtual void RemoveMouseEventCallback( | 166 virtual void RemoveMouseEventCallback( |
172 const MouseEventCallback& callback) OVERRIDE; | 167 const MouseEventCallback& callback) OVERRIDE; |
173 virtual void GetWebScreenInfo(blink::WebScreenInfo* result) OVERRIDE; | 168 virtual void GetWebScreenInfo(blink::WebScreenInfo* result) OVERRIDE; |
174 | 169 |
175 virtual SkColorType PreferredReadbackFormat() OVERRIDE; | 170 virtual SkColorType PreferredReadbackFormat() OVERRIDE; |
176 | 171 |
177 // BrowserAccessibilityDelegate | |
178 virtual void AccessibilitySetFocus(int acc_obj_id) OVERRIDE; | |
179 virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE; | |
180 virtual void AccessibilityShowMenu(int acc_obj_id) OVERRIDE; | |
181 virtual void AccessibilityScrollToMakeVisible( | |
182 int acc_obj_id, gfx::Rect subfocus) OVERRIDE; | |
183 virtual void AccessibilityScrollToPoint( | |
184 int acc_obj_id, gfx::Point point) OVERRIDE; | |
185 virtual void AccessibilitySetTextSelection( | |
186 int acc_obj_id, int start_offset, int end_offset) OVERRIDE; | |
187 virtual bool AccessibilityViewHasFocus() const OVERRIDE; | |
188 virtual gfx::Rect AccessibilityGetViewBounds() const OVERRIDE; | |
189 virtual gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds) | |
190 const OVERRIDE; | |
191 virtual void AccessibilityHitTest(const gfx::Point& point) OVERRIDE; | |
192 virtual void AccessibilityFatalError() OVERRIDE; | |
193 | |
194 // Forces redraw in the renderer and when the update reaches the browser | 172 // Forces redraw in the renderer and when the update reaches the browser |
195 // grabs snapshot from the compositor. Returns PNG-encoded snapshot. | 173 // grabs snapshot from the compositor. Returns PNG-encoded snapshot. |
196 void GetSnapshotFromBrowser( | 174 void GetSnapshotFromBrowser( |
197 const base::Callback<void(const unsigned char*,size_t)> callback); | 175 const base::Callback<void(const unsigned char*,size_t)> callback); |
198 | 176 |
199 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const; | 177 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const; |
200 | 178 |
201 // Notification that the screen info has changed. | 179 // Notification that the screen info has changed. |
202 void NotifyScreenInfoChanged(); | 180 void NotifyScreenInfoChanged(); |
203 | 181 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 void StartUserGesture(); | 366 void StartUserGesture(); |
389 | 367 |
390 // Set the RenderView background transparency. | 368 // Set the RenderView background transparency. |
391 void SetBackgroundOpaque(bool opaque); | 369 void SetBackgroundOpaque(bool opaque); |
392 | 370 |
393 // Notifies the renderer that the next key event is bound to one or more | 371 // Notifies the renderer that the next key event is bound to one or more |
394 // pre-defined edit commands | 372 // pre-defined edit commands |
395 void SetEditCommandsForNextKeyEvent( | 373 void SetEditCommandsForNextKeyEvent( |
396 const std::vector<EditCommand>& commands); | 374 const std::vector<EditCommand>& commands); |
397 | 375 |
398 // Gets the accessibility mode. | |
399 AccessibilityMode accessibility_mode() const { | |
400 return accessibility_mode_; | |
401 } | |
402 | |
403 // Adds the given accessibility mode to the current accessibility mode bitmap. | |
404 void AddAccessibilityMode(AccessibilityMode mode); | |
405 | |
406 // Removes the given accessibility mode from the current accessibility mode | |
407 // bitmap, managing the bits that are shared with other modes such that a | |
408 // bit will only be turned off when all modes that depend on it have been | |
409 // removed. | |
410 void RemoveAccessibilityMode(AccessibilityMode mode); | |
411 | |
412 // Resets the accessibility mode to the default setting in | |
413 // BrowserStateAccessibilityImpl. | |
414 void ResetAccessibilityMode(); | |
415 | |
416 #if defined(OS_WIN) | |
417 void SetParentNativeViewAccessible( | |
418 gfx::NativeViewAccessible accessible_parent); | |
419 gfx::NativeViewAccessible GetParentNativeViewAccessible() const; | |
420 #endif | |
421 | |
422 // Executes the edit command on the RenderView. | 376 // Executes the edit command on the RenderView. |
423 void ExecuteEditCommand(const std::string& command, | 377 void ExecuteEditCommand(const std::string& command, |
424 const std::string& value); | 378 const std::string& value); |
425 | 379 |
426 // Tells the renderer to scroll the currently focused node into rect only if | 380 // Tells the renderer to scroll the currently focused node into rect only if |
427 // the currently focused node is a Text node (textfield, text area or content | 381 // the currently focused node is a Text node (textfield, text area or content |
428 // editable divs). | 382 // editable divs). |
429 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect); | 383 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect); |
430 | 384 |
431 // Requests the renderer to move the caret selection towards the point. | 385 // Requests the renderer to move the caret selection towards the point. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 gfx::Size snapshot_size, | 467 gfx::Size snapshot_size, |
514 scoped_refptr<base::RefCountedBytes> png_data); | 468 scoped_refptr<base::RefCountedBytes> png_data); |
515 | 469 |
516 // LatencyComponents generated in the renderer must have component IDs | 470 // LatencyComponents generated in the renderer must have component IDs |
517 // provided to them by the browser process. This function adds the correct | 471 // provided to them by the browser process. This function adds the correct |
518 // component ID where necessary. | 472 // component ID where necessary. |
519 void AddLatencyInfoComponentIds(ui::LatencyInfo* latency_info); | 473 void AddLatencyInfoComponentIds(ui::LatencyInfo* latency_info); |
520 | 474 |
521 InputRouter* input_router() { return input_router_.get(); } | 475 InputRouter* input_router() { return input_router_.get(); } |
522 | 476 |
| 477 // Get the BrowserAccessibilityManager for the root of the frame tree, |
| 478 BrowserAccessibilityManager* GetRootBrowserAccessibilityManager(); |
| 479 |
| 480 // Get the BrowserAccessibilityManager for the root of the frame tree, |
| 481 // or create it if it doesn't already exist. |
| 482 BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager(); |
| 483 |
| 484 #if defined(OS_WIN) |
| 485 gfx::NativeViewAccessible GetParentNativeViewAccessible(); |
| 486 #endif |
| 487 |
523 protected: | 488 protected: |
524 virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE; | 489 virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE; |
525 | 490 |
526 // Create a LatencyInfo struct with INPUT_EVENT_LATENCY_RWH_COMPONENT | 491 // Create a LatencyInfo struct with INPUT_EVENT_LATENCY_RWH_COMPONENT |
527 // component if it is not already in |original|. And if |original| is | 492 // component if it is not already in |original|. And if |original| is |
528 // not NULL, it is also merged into the resulting LatencyInfo. | 493 // not NULL, it is also merged into the resulting LatencyInfo. |
529 ui::LatencyInfo CreateRWHLatencyInfoIfNotExist( | 494 ui::LatencyInfo CreateRWHLatencyInfoIfNotExist( |
530 const ui::LatencyInfo* original, blink::WebInputEvent::Type type); | 495 const ui::LatencyInfo* original, blink::WebInputEvent::Type type); |
531 | 496 |
532 // Called when we receive a notification indicating that the renderer | 497 // Called when we receive a notification indicating that the renderer |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 void WindowSnapshotReachedScreen(int snapshot_id); | 667 void WindowSnapshotReachedScreen(int snapshot_id); |
703 | 668 |
704 void OnSnapshotDataReceived(int snapshot_id, | 669 void OnSnapshotDataReceived(int snapshot_id, |
705 const unsigned char* png, | 670 const unsigned char* png, |
706 size_t size); | 671 size_t size); |
707 | 672 |
708 void OnSnapshotDataReceivedAsync( | 673 void OnSnapshotDataReceivedAsync( |
709 int snapshot_id, | 674 int snapshot_id, |
710 scoped_refptr<base::RefCountedBytes> png_data); | 675 scoped_refptr<base::RefCountedBytes> png_data); |
711 | 676 |
712 // Send a message to the renderer process to change the accessibility mode. | |
713 void SetAccessibilityMode(AccessibilityMode AccessibilityMode); | |
714 | |
715 // Our delegate, which wants to know mainly about keyboard events. | 677 // Our delegate, which wants to know mainly about keyboard events. |
716 // It will remain non-NULL until DetachDelegate() is called. | 678 // It will remain non-NULL until DetachDelegate() is called. |
717 RenderWidgetHostDelegate* delegate_; | 679 RenderWidgetHostDelegate* delegate_; |
718 | 680 |
719 // Created during construction but initialized during Init*(). Therefore, it | 681 // Created during construction but initialized during Init*(). Therefore, it |
720 // is guaranteed never to be NULL, but its channel may be NULL if the | 682 // is guaranteed never to be NULL, but its channel may be NULL if the |
721 // renderer crashed, so you must always check that. | 683 // renderer crashed, so you must always check that. |
722 RenderProcessHost* process_; | 684 RenderProcessHost* process_; |
723 | 685 |
724 // The ID of the corresponding object in the Renderer Instance. | 686 // The ID of the corresponding object in the Renderer Instance. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 gfx::Size new_auto_size_; | 738 gfx::Size new_auto_size_; |
777 | 739 |
778 // True if the render widget host should track the render widget's size as | 740 // True if the render widget host should track the render widget's size as |
779 // opposed to visa versa. | 741 // opposed to visa versa. |
780 bool should_auto_resize_; | 742 bool should_auto_resize_; |
781 | 743 |
782 bool waiting_for_screen_rects_ack_; | 744 bool waiting_for_screen_rects_ack_; |
783 gfx::Rect last_view_screen_rect_; | 745 gfx::Rect last_view_screen_rect_; |
784 gfx::Rect last_window_screen_rect_; | 746 gfx::Rect last_window_screen_rect_; |
785 | 747 |
786 AccessibilityMode accessibility_mode_; | |
787 | |
788 // Keyboard event listeners. | 748 // Keyboard event listeners. |
789 std::vector<KeyPressEventCallback> key_press_event_callbacks_; | 749 std::vector<KeyPressEventCallback> key_press_event_callbacks_; |
790 | 750 |
791 // Mouse event callbacks. | 751 // Mouse event callbacks. |
792 std::vector<MouseEventCallback> mouse_event_callbacks_; | 752 std::vector<MouseEventCallback> mouse_event_callbacks_; |
793 | 753 |
794 // If true, then we should repaint when restoring even if we have a | 754 // If true, then we should repaint when restoring even if we have a |
795 // backingstore. This flag is set to true if we receive a paint message | 755 // backingstore. This flag is set to true if we receive a paint message |
796 // while is_hidden_ to true. Even though we tell the render widget to hide | 756 // while is_hidden_ to true. Even though we tell the render widget to hide |
797 // itself, a paint message could already be in flight at that point. | 757 // itself, a paint message could already be in flight at that point. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 typedef std::map<int, | 840 typedef std::map<int, |
881 base::Callback<void(const unsigned char*, size_t)> > PendingSnapshotMap; | 841 base::Callback<void(const unsigned char*, size_t)> > PendingSnapshotMap; |
882 PendingSnapshotMap pending_browser_snapshots_; | 842 PendingSnapshotMap pending_browser_snapshots_; |
883 | 843 |
884 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl); | 844 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl); |
885 }; | 845 }; |
886 | 846 |
887 } // namespace content | 847 } // namespace content |
888 | 848 |
889 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ | 849 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ |
OLD | NEW |