| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // behalf of a RenderWidgetHost. This class bridges between the IO thread | 30 // behalf of a RenderWidgetHost. This class bridges between the IO thread |
| 31 // where the RenderProcessHost's MessageFilter lives and the UI thread where | 31 // where the RenderProcessHost's MessageFilter lives and the UI thread where |
| 32 // the RenderWidgetHost lives. | 32 // the RenderWidgetHost lives. |
| 33 // | 33 // |
| 34 // | 34 // |
| 35 // OPTIMIZED RESIZE | 35 // OPTIMIZED RESIZE |
| 36 // | 36 // |
| 37 // RenderWidgetHelper is used to implement optimized resize. When the | 37 // RenderWidgetHelper is used to implement optimized resize. When the |
| 38 // RenderWidgetHost is resized, it sends a Resize message to its RenderWidget | 38 // RenderWidgetHost is resized, it sends a Resize message to its RenderWidget |
| 39 // counterpart in the renderer process. The RenderWidget generates a | 39 // counterpart in the renderer process. The RenderWidget generates a |
| 40 // PaintRect message in response to the Resize message, and it sets the | 40 // UpdateRect message in response to the Resize message, and it sets the |
| 41 // IS_RESIZE_ACK flag in the PaintRect message to true. | 41 // IS_RESIZE_ACK flag in the UpdateRect message to true. |
| 42 // | 42 // |
| 43 // Back in the browser process, when the RenderProcessHost's MessageFilter | 43 // Back in the browser process, when the RenderProcessHost's MessageFilter |
| 44 // sees a PaintRect message, it directs it to the RenderWidgetHelper by | 44 // sees a UpdateRect message, it directs it to the RenderWidgetHelper by |
| 45 // calling the DidReceivePaintMsg method. That method stores the data for | 45 // calling the DidReceiveUpdateMsg method. That method stores the data for |
| 46 // the PaintRect message in a map, where it can be directly accessed by the | 46 // the UpdateRect message in a map, where it can be directly accessed by the |
| 47 // RenderWidgetHost on the UI thread during a call to RenderWidgetHost's | 47 // RenderWidgetHost on the UI thread during a call to RenderWidgetHost's |
| 48 // GetBackingStore method. | 48 // GetBackingStore method. |
| 49 // | 49 // |
| 50 // When the RenderWidgetHost's GetBackingStore method is called, it first | 50 // When the RenderWidgetHost's GetBackingStore method is called, it first |
| 51 // checks to see if it is waiting for a resize ack. If it is, then it calls | 51 // checks to see if it is waiting for a resize ack. If it is, then it calls |
| 52 // the RenderWidgetHelper's WaitForPaintMsg to check if there is already a | 52 // the RenderWidgetHelper's WaitForUpdateMsg to check if there is already a |
| 53 // resulting PaintRect message (or to wait a short amount of time for one to | 53 // resulting UpdateRect message (or to wait a short amount of time for one to |
| 54 // arrive). The main goal of this mechanism is to short-cut the usual way in | 54 // arrive). The main goal of this mechanism is to short-cut the usual way in |
| 55 // which IPC messages are proxied over to the UI thread via InvokeLater. | 55 // which IPC messages are proxied over to the UI thread via InvokeLater. |
| 56 // This approach is necessary since window resize is followed up immediately | 56 // This approach is necessary since window resize is followed up immediately |
| 57 // by a request to repaint the window. | 57 // by a request to repaint the window. |
| 58 // | 58 // |
| 59 // | 59 // |
| 60 // OPTIMIZED TAB SWITCHING | 60 // OPTIMIZED TAB SWITCHING |
| 61 // | 61 // |
| 62 // When a RenderWidgetHost is in a background tab, it is flagged as hidden. | 62 // When a RenderWidgetHost is in a background tab, it is flagged as hidden. |
| 63 // This causes the corresponding RenderWidget to stop sending PaintRect | 63 // This causes the corresponding RenderWidget to stop sending UpdateRect |
| 64 // messages. The RenderWidgetHost also discards its backingstore when it is | 64 // messages. The RenderWidgetHost also discards its backingstore when it is |
| 65 // hidden, which helps free up memory. As a result, when a RenderWidgetHost | 65 // hidden, which helps free up memory. As a result, when a RenderWidgetHost |
| 66 // is restored, it can be momentarily without a backingstore. (Restoring a | 66 // is restored, it can be momentarily without a backingstore. (Restoring a |
| 67 // RenderWidgetHost results in a WasRestored message being sent to the | 67 // RenderWidgetHost results in a WasRestored message being sent to the |
| 68 // RenderWidget, which triggers a full PaintRect message.) This can lead to | 68 // RenderWidget, which triggers a full UpdateRect message.) This can lead to |
| 69 // an observed rendering glitch as the TabContents will just have to fill | 69 // an observed rendering glitch as the TabContents will just have to fill |
| 70 // white overtop the RenderWidgetHost until the RenderWidgetHost receives a | 70 // white overtop the RenderWidgetHost until the RenderWidgetHost receives a |
| 71 // PaintRect message to refresh its backingstore. | 71 // UpdateRect message to refresh its backingstore. |
| 72 // | 72 // |
| 73 // To avoid this 'white flash', the RenderWidgetHost again makes use of the | 73 // To avoid this 'white flash', the RenderWidgetHost again makes use of the |
| 74 // RenderWidgetHelper's WaitForPaintMsg method. When the RenderWidgetHost's | 74 // RenderWidgetHelper's WaitForUpdateMsg method. When the RenderWidgetHost's |
| 75 // GetBackingStore method is called, it will call WaitForPaintMsg if it has | 75 // GetBackingStore method is called, it will call WaitForUpdateMsg if it has |
| 76 // no backingstore. | 76 // no backingstore. |
| 77 // | 77 // |
| 78 // TRANSPORT DIB CREATION | 78 // TRANSPORT DIB CREATION |
| 79 // | 79 // |
| 80 // On some platforms (currently the Mac) the renderer cannot create transport | 80 // On some platforms (currently the Mac) the renderer cannot create transport |
| 81 // DIBs because of sandbox limitations. Thus, it has to make synchronous IPCs | 81 // DIBs because of sandbox limitations. Thus, it has to make synchronous IPCs |
| 82 // to the browser for them. Since these requests are synchronous, they cannot | 82 // to the browser for them. Since these requests are synchronous, they cannot |
| 83 // terminate on the UI thread. Thus, in this case, this object performs the | 83 // terminate on the UI thread. Thus, in this case, this object performs the |
| 84 // allocation and maintains the set of allocated transport DIBs which the | 84 // allocation and maintains the set of allocated transport DIBs which the |
| 85 // renderers can refer to. | 85 // renderers can refer to. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 96 int GetNextRoutingID(); | 96 int GetNextRoutingID(); |
| 97 | 97 |
| 98 | 98 |
| 99 // UI THREAD ONLY ----------------------------------------------------------- | 99 // UI THREAD ONLY ----------------------------------------------------------- |
| 100 | 100 |
| 101 // These three functions provide the backend implementation of the | 101 // These three functions provide the backend implementation of the |
| 102 // corresponding functions in RenderProcessHost. See those declarations | 102 // corresponding functions in RenderProcessHost. See those declarations |
| 103 // for documentation. | 103 // for documentation. |
| 104 void CancelResourceRequests(int render_widget_id); | 104 void CancelResourceRequests(int render_widget_id); |
| 105 void CrossSiteClosePageACK(const ViewMsg_ClosePage_Params& params); | 105 void CrossSiteClosePageACK(const ViewMsg_ClosePage_Params& params); |
| 106 bool WaitForPaintMsg(int render_widget_id, | 106 bool WaitForUpdateMsg(int render_widget_id, |
| 107 const base::TimeDelta& max_delay, | 107 const base::TimeDelta& max_delay, |
| 108 IPC::Message* msg); | 108 IPC::Message* msg); |
| 109 | 109 |
| 110 #if defined(OS_MACOSX) | 110 #if defined(OS_MACOSX) |
| 111 // Given the id of a transport DIB, return a mapping to it or NULL on error. | 111 // Given the id of a transport DIB, return a mapping to it or NULL on error. |
| 112 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id); | 112 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id); |
| 113 #endif | 113 #endif |
| 114 | 114 |
| 115 | 115 |
| 116 // IO THREAD ONLY ----------------------------------------------------------- | 116 // IO THREAD ONLY ----------------------------------------------------------- |
| 117 | 117 |
| 118 // Called on the IO thread when a PaintRect message is received. | 118 // Called on the IO thread when a UpdateRect message is received. |
| 119 void DidReceivePaintMsg(const IPC::Message& msg); | 119 void DidReceiveUpdateMsg(const IPC::Message& msg); |
| 120 | 120 |
| 121 void CreateNewWindow(int opener_id, | 121 void CreateNewWindow(int opener_id, |
| 122 bool user_gesture, | 122 bool user_gesture, |
| 123 base::ProcessHandle render_process, | 123 base::ProcessHandle render_process, |
| 124 int* route_id); | 124 int* route_id); |
| 125 void CreateNewWidget(int opener_id, bool activatable, int* route_id); | 125 void CreateNewWidget(int opener_id, bool activatable, int* route_id); |
| 126 | 126 |
| 127 #if defined(OS_MACOSX) | 127 #if defined(OS_MACOSX) |
| 128 // Called on the IO thread to handle the allocation of a transport DIB | 128 // Called on the IO thread to handle the allocation of a transport DIB |
| 129 void AllocTransportDIB(size_t size, TransportDIB::Handle* result); | 129 void AllocTransportDIB(size_t size, TransportDIB::Handle* result); |
| 130 | 130 |
| 131 // Called on the IO thread to handle the freeing of a transport DIB | 131 // Called on the IO thread to handle the freeing of a transport DIB |
| 132 void FreeTransportDIB(TransportDIB::Id dib_id); | 132 void FreeTransportDIB(TransportDIB::Id dib_id); |
| 133 #endif | 133 #endif |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 // A class used to proxy a paint message. PaintMsgProxy objects are created | 136 // A class used to proxy a paint message. PaintMsgProxy objects are created |
| 137 // on the IO thread and destroyed on the UI thread. | 137 // on the IO thread and destroyed on the UI thread. |
| 138 class PaintMsgProxy; | 138 class UpdateMsgProxy; |
| 139 friend class PaintMsgProxy; | 139 friend class UpdateMsgProxy; |
| 140 friend class base::RefCountedThreadSafe<RenderWidgetHelper>; | 140 friend class base::RefCountedThreadSafe<RenderWidgetHelper>; |
| 141 | 141 |
| 142 // Map from render_widget_id to live PaintMsgProxy instance. | 142 // Map from render_widget_id to live PaintMsgProxy instance. |
| 143 typedef base::hash_map<int, PaintMsgProxy*> PaintMsgProxyMap; | 143 typedef base::hash_map<int, UpdateMsgProxy*> UpdateMsgProxyMap; |
| 144 | 144 |
| 145 ~RenderWidgetHelper(); | 145 ~RenderWidgetHelper(); |
| 146 | 146 |
| 147 // Called on the UI thread to discard a paint message. | 147 // Called on the UI thread to discard a paint message. |
| 148 void OnDiscardPaintMsg(PaintMsgProxy* proxy); | 148 void OnDiscardUpdateMsg(UpdateMsgProxy* proxy); |
| 149 | 149 |
| 150 // Called on the UI thread to dispatch a paint message if necessary. | 150 // Called on the UI thread to dispatch a paint message if necessary. |
| 151 void OnDispatchPaintMsg(PaintMsgProxy* proxy); | 151 void OnDispatchUpdateMsg(UpdateMsgProxy* proxy); |
| 152 | 152 |
| 153 // Called on the UI thread to finish creating a window. | 153 // Called on the UI thread to finish creating a window. |
| 154 void OnCreateWindowOnUI(int opener_id, | 154 void OnCreateWindowOnUI(int opener_id, |
| 155 int route_id); | 155 int route_id); |
| 156 | 156 |
| 157 // Called on the IO thread after a window was created on the UI thread. | 157 // Called on the IO thread after a window was created on the UI thread. |
| 158 void OnCreateWindowOnIO(int route_id); | 158 void OnCreateWindowOnIO(int route_id); |
| 159 | 159 |
| 160 // Called on the UI thread to finish creating a widget. | 160 // Called on the UI thread to finish creating a widget. |
| 161 void OnCreateWidgetOnUI(int opener_id, int route_id, bool activatable); | 161 void OnCreateWidgetOnUI(int opener_id, int route_id, bool activatable); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 | 172 |
| 173 // On OSX we keep file descriptors to all the allocated DIBs around until | 173 // On OSX we keep file descriptors to all the allocated DIBs around until |
| 174 // the renderer frees them. | 174 // the renderer frees them. |
| 175 Lock allocated_dibs_lock_; | 175 Lock allocated_dibs_lock_; |
| 176 std::map<TransportDIB::Id, int> allocated_dibs_; | 176 std::map<TransportDIB::Id, int> allocated_dibs_; |
| 177 #endif | 177 #endif |
| 178 | 178 |
| 179 // A map of live paint messages. Must hold pending_paints_lock_ to access. | 179 // A map of live paint messages. Must hold pending_paints_lock_ to access. |
| 180 // The PaintMsgProxy objects are not owned by this map. (See PaintMsgProxy | 180 // The PaintMsgProxy objects are not owned by this map. (See PaintMsgProxy |
| 181 // for details about how the lifetime of instances are managed.) | 181 // for details about how the lifetime of instances are managed.) |
| 182 PaintMsgProxyMap pending_paints_; | 182 UpdateMsgProxyMap pending_paints_; |
| 183 Lock pending_paints_lock_; | 183 Lock pending_paints_lock_; |
| 184 | 184 |
| 185 int render_process_id_; | 185 int render_process_id_; |
| 186 | 186 |
| 187 // Event used to implement WaitForPaintMsg. | 187 // Event used to implement WaitForUpdateMsg. |
| 188 base::WaitableEvent event_; | 188 base::WaitableEvent event_; |
| 189 | 189 |
| 190 // The next routing id to use. | 190 // The next routing id to use. |
| 191 base::AtomicSequenceNumber next_routing_id_; | 191 base::AtomicSequenceNumber next_routing_id_; |
| 192 | 192 |
| 193 ResourceDispatcherHost* resource_dispatcher_host_; | 193 ResourceDispatcherHost* resource_dispatcher_host_; |
| 194 | 194 |
| 195 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHelper); | 195 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHelper); |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ | 198 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ |
| OLD | NEW |