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

Side by Side Diff: chrome/browser/renderer_host/render_widget_helper.h

Issue 21485: Bitmap transport (Closed)
Patch Set: Fix some mac crashes Created 11 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 unified diff | Download patch
OLDNEW
1
2 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
3 // 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
4 // found in the LICENSE file. 3 // found in the LICENSE file.
5 4
6 #ifndef CHROME_BROWSER_RENDEDER_HOST_RENDER_WIDGET_HELPER_H_ 5 #ifndef CHROME_BROWSER_RENDEDER_HOST_RENDER_WIDGET_HELPER_H_
7 #define CHROME_BROWSER_RENDEDER_HOST_RENDER_WIDGET_HELPER_H_ 6 #define CHROME_BROWSER_RENDEDER_HOST_RENDER_WIDGET_HELPER_H_
8 7
9 #include "base/atomic_sequence_num.h" 8 #include "base/atomic_sequence_num.h"
10 #include "base/hash_tables.h" 9 #include "base/hash_tables.h"
11 #include "base/process.h" 10 #include "base/process.h"
12 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
13 #include "base/lock.h" 12 #include "base/lock.h"
14 #include "base/waitable_event.h" 13 #include "base/waitable_event.h"
14 #include "chrome/common/ipc_maybe.h"
15 #include "chrome/common/modal_dialog_event.h" 15 #include "chrome/common/modal_dialog_event.h"
16 #include "chrome/common/transport_dib.h"
16 17
17 namespace IPC { 18 namespace IPC {
18 class Message; 19 class Message;
19 } 20 }
20 21
21 namespace base { 22 namespace base {
22 class TimeDelta; 23 class TimeDelta;
23 } 24 }
24 25
25 class MessageLoop; 26 class MessageLoop;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // RenderWidget, which triggers a full PaintRect message.) This can lead to 68 // RenderWidget, which triggers a full PaintRect message.) This can lead to
68 // an observed rendering glitch as the WebContents will just have to fill 69 // an observed rendering glitch as the WebContents will just have to fill
69 // white overtop the RenderWidgetHost until the RenderWidgetHost receives a 70 // white overtop the RenderWidgetHost until the RenderWidgetHost receives a
70 // PaintRect message to refresh its backingstore. 71 // PaintRect message to refresh its backingstore.
71 // 72 //
72 // 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
73 // RenderWidgetHelper's WaitForPaintMsg method. When the RenderWidgetHost's 74 // RenderWidgetHelper's WaitForPaintMsg method. When the RenderWidgetHost's
74 // GetBackingStore method is called, it will call WaitForPaintMsg if it has 75 // GetBackingStore method is called, it will call WaitForPaintMsg if it has
75 // no backingstore. 76 // no backingstore.
76 // 77 //
78 // TRANSPORT DIB CREATION
79 //
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
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
84 // allocation and maintains the set of allocated transport DIBs which the
85 // renderers can refer to.
86 //
77 class RenderWidgetHelper : 87 class RenderWidgetHelper :
78 public base::RefCountedThreadSafe<RenderWidgetHelper> { 88 public base::RefCountedThreadSafe<RenderWidgetHelper> {
79 public: 89 public:
80 RenderWidgetHelper(int render_process_id); 90 RenderWidgetHelper(int render_process_id);
81 ~RenderWidgetHelper(); 91 ~RenderWidgetHelper();
82 92
83 // Gets the next available routing id. This is thread safe. 93 // Gets the next available routing id. This is thread safe.
84 int GetNextRoutingID(); 94 int GetNextRoutingID();
85 95
86 // Sets whether popup blocking is enabled or not. 96 // Sets whether popup blocking is enabled or not.
87 void set_block_popups(bool block) { block_popups_ = block; } 97 void set_block_popups(bool block) { block_popups_ = block; }
88 98
89 99
90 // UI THREAD ONLY ----------------------------------------------------------- 100 // UI THREAD ONLY -----------------------------------------------------------
91 101
92 // These three functions provide the backend implementation of the 102 // These three functions provide the backend implementation of the
93 // corresponding functions in RenderProcessHost. See those declarations 103 // corresponding functions in RenderProcessHost. See those declarations
94 // for documentation. 104 // for documentation.
95 void CancelResourceRequests(int render_widget_id); 105 void CancelResourceRequests(int render_widget_id);
96 void CrossSiteClosePageACK(int new_render_process_host_id, 106 void CrossSiteClosePageACK(int new_render_process_host_id,
97 int new_request_id); 107 int new_request_id);
98 bool WaitForPaintMsg(int render_widget_id, 108 bool WaitForPaintMsg(int render_widget_id,
99 const base::TimeDelta& max_delay, 109 const base::TimeDelta& max_delay,
100 IPC::Message* msg); 110 IPC::Message* msg);
101 111
112 #if defined(OS_MACOSX)
113 // Given the id of a transport DIB, return a mapping to it or NULL on error.
114 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id);
115 #endif
116
102 117
103 // IO THREAD ONLY ----------------------------------------------------------- 118 // IO THREAD ONLY -----------------------------------------------------------
104 119
105 // Called on the IO thread when a PaintRect message is received. 120 // Called on the IO thread when a PaintRect message is received.
106 void DidReceivePaintMsg(const IPC::Message& msg); 121 void DidReceivePaintMsg(const IPC::Message& msg);
107 122
108 MessageLoop* ui_loop() { return ui_loop_; } 123 MessageLoop* ui_loop() { return ui_loop_; }
109 124
110 void CreateNewWindow(int opener_id, 125 void CreateNewWindow(int opener_id,
111 bool user_gesture, 126 bool user_gesture,
112 base::ProcessHandle render_process, 127 base::ProcessHandle render_process,
113 int* route_id, 128 int* route_id,
114 ModalDialogEvent* modal_dialog_event); 129 ModalDialogEvent* modal_dialog_event);
115 void CreateNewWidget(int opener_id, bool activatable, int* route_id); 130 void CreateNewWidget(int opener_id, bool activatable, int* route_id);
116 131
132 #if defined(OS_MACOSX)
133 // Called on the IO thread to handle the allocation of a transport DIB
134 void AllocTransportDIB(size_t size, IPC::Maybe<TransportDIB::Handle>* result);
135
136 // Called on the IO thread to handle the freeing of a transport DIB
137 void FreeTransportDIB(TransportDIB::Id dib_id);
138 #endif
139
117 private: 140 private:
118 // A class used to proxy a paint message. PaintMsgProxy objects are created 141 // A class used to proxy a paint message. PaintMsgProxy objects are created
119 // on the IO thread and destroyed on the UI thread. 142 // on the IO thread and destroyed on the UI thread.
120 class PaintMsgProxy; 143 class PaintMsgProxy;
121 friend class PaintMsgProxy; 144 friend class PaintMsgProxy;
122 145
123 // Map from render_widget_id to live PaintMsgProxy instance. 146 // Map from render_widget_id to live PaintMsgProxy instance.
124 typedef base::hash_map<int, PaintMsgProxy*> PaintMsgProxyMap; 147 typedef base::hash_map<int, PaintMsgProxy*> PaintMsgProxyMap;
125 148
126 // Called on the UI thread to discard a paint message. 149 // Called on the UI thread to discard a paint message.
127 void OnDiscardPaintMsg(PaintMsgProxy* proxy); 150 void OnDiscardPaintMsg(PaintMsgProxy* proxy);
128 151
129 // Called on the UI thread to dispatch a paint message if necessary. 152 // Called on the UI thread to dispatch a paint message if necessary.
130 void OnDispatchPaintMsg(PaintMsgProxy* proxy); 153 void OnDispatchPaintMsg(PaintMsgProxy* proxy);
131 154
132 // Called on the UI thread to send a message to the RenderProcessHost. 155 // Called on the UI thread to send a message to the RenderProcessHost.
133 void OnSimulateReceivedMessage(const IPC::Message& message); 156 void OnSimulateReceivedMessage(const IPC::Message& message);
134 157
135 // Called on the IO thread to cancel resource requests for the render widget. 158 // Called on the IO thread to cancel resource requests for the render widget.
136 void OnCancelResourceRequests(ResourceDispatcherHost* dispatcher, 159 void OnCancelResourceRequests(ResourceDispatcherHost* dispatcher,
137 int render_widget_id); 160 int render_widget_id);
138 161
139 // Called on the IO thread to resume a cross-site response. 162 // Called on the IO thread to resume a cross-site response.
140 void OnCrossSiteClosePageACK(ResourceDispatcherHost* dispatcher, 163 void OnCrossSiteClosePageACK(ResourceDispatcherHost* dispatcher,
141 int new_render_process_host_id, 164 int new_render_process_host_id,
142 int new_request_id); 165 int new_request_id);
143 166
167 #if defined(OS_MACOSX)
168 // Called on destruction to release all allocated transport DIBs
169 void ClearAllocatedDIBs();
170
171 // On OSX we keep file descriptors to all the allocated DIBs around until
172 // the renderer frees them.
173 Lock allocated_dibs_lock_;
174 std::map<TransportDIB::Id, int> allocated_dibs_;
175 #endif
176
144 // A map of live paint messages. Must hold pending_paints_lock_ to access. 177 // A map of live paint messages. Must hold pending_paints_lock_ to access.
145 // The PaintMsgProxy objects are not owned by this map. (See PaintMsgProxy 178 // The PaintMsgProxy objects are not owned by this map. (See PaintMsgProxy
146 // for details about how the lifetime of instances are managed.) 179 // for details about how the lifetime of instances are managed.)
147 PaintMsgProxyMap pending_paints_; 180 PaintMsgProxyMap pending_paints_;
148 Lock pending_paints_lock_; 181 Lock pending_paints_lock_;
149 182
150 int render_process_id_; 183 int render_process_id_;
151 MessageLoop* ui_loop_; 184 MessageLoop* ui_loop_;
152 185
153 // Event used to implement WaitForPaintMsg. 186 // Event used to implement WaitForPaintMsg.
154 base::WaitableEvent event_; 187 base::WaitableEvent event_;
155 188
156 // The next routing id to use. 189 // The next routing id to use.
157 base::AtomicSequenceNumber next_routing_id_; 190 base::AtomicSequenceNumber next_routing_id_;
158 191
159 // Whether popup blocking is enabled or not. 192 // Whether popup blocking is enabled or not.
160 bool block_popups_; 193 bool block_popups_;
161 194
162 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHelper); 195 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHelper);
163 }; 196 };
164 197
165 #endif // CHROME_BROWSER_RENDEDER_HOST_RENDER_WIDGET_HELPER_H_ 198 #endif // CHROME_BROWSER_RENDEDER_HOST_RENDER_WIDGET_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698