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 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/accessibility/browser_accessibility_manager.h" | 8 #include "content/browser/accessibility/browser_accessibility_manager.h" |
9 #include "content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.
h" | 9 #include "content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.
h" |
10 #include "content/browser/renderer_host/render_process_host_impl.h" | 10 #include "content/browser/renderer_host/render_process_host_impl.h" |
11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
12 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 12 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
13 #include "content/port/browser/smooth_scroll_gesture.h" | 13 #include "content/port/browser/smooth_scroll_gesture.h" |
14 #include "third_party/WebKit/public/web/WebScreenInfo.h" | 14 #include "third_party/WebKit/public/web/WebScreenInfo.h" |
15 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
16 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
17 #include "ui/gfx/size_conversions.h" | 17 #include "ui/gfx/size_conversions.h" |
18 #include "ui/gfx/size_f.h" | 18 #include "ui/gfx/size_f.h" |
19 | 19 |
20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/win/wrapped_window_proc.h" | 23 #include "base/win/wrapped_window_proc.h" |
24 #include "content/browser/plugin_process_host.h" | 24 #include "content/browser/plugin_process_host.h" |
| 25 #include "content/common/plugin_constants_win.h" |
| 26 #include "content/common/webplugin_geometry.h" |
25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/child_process_data.h" | 28 #include "content/public/browser/child_process_data.h" |
27 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
28 #include "ui/base/win/dpi.h" | 30 #include "ui/base/win/dpi.h" |
29 #include "ui/base/win/hwnd_util.h" | 31 #include "ui/base/win/hwnd_util.h" |
30 #include "ui/gfx/gdi_util.h" | 32 #include "ui/gfx/gdi_util.h" |
31 #include "webkit/plugins/npapi/plugin_constants_win.h" | 33 #include "webkit/plugins/npapi/plugin_utils.h" |
32 #include "webkit/plugins/npapi/webplugin.h" | |
33 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" | |
34 | |
35 using webkit::npapi::WebPluginDelegateImpl; | |
36 #endif | 34 #endif |
37 | 35 |
38 #if defined(TOOLKIT_GTK) | 36 #if defined(TOOLKIT_GTK) |
39 #include <gdk/gdkx.h> | 37 #include <gdk/gdkx.h> |
40 #include <gtk/gtk.h> | 38 #include <gtk/gtk.h> |
41 | 39 |
42 #include "content/browser/renderer_host/gtk_window_utils.h" | 40 #include "content/browser/renderer_host/gtk_window_utils.h" |
43 #endif | 41 #endif |
44 | 42 |
45 namespace content { | 43 namespace content { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return 0; | 111 return 0; |
114 default: | 112 default: |
115 break; | 113 break; |
116 } | 114 } |
117 } | 115 } |
118 return ::DefWindowProc(window, message, wparam, lparam); | 116 return ::DefWindowProc(window, message, wparam, lparam); |
119 } | 117 } |
120 | 118 |
121 bool IsPluginWrapperWindow(HWND window) { | 119 bool IsPluginWrapperWindow(HWND window) { |
122 return ui::GetClassNameW(window) == | 120 return ui::GetClassNameW(window) == |
123 string16(webkit::npapi::kWrapperNativeWindowClassName); | 121 string16(kWrapperNativeWindowClassName); |
124 } | 122 } |
125 | 123 |
126 // Create an intermediate window between the given HWND and its parent. | 124 // Create an intermediate window between the given HWND and its parent. |
127 HWND ReparentWindow(HWND window, HWND parent) { | 125 HWND ReparentWindow(HWND window, HWND parent) { |
128 static ATOM atom = 0; | 126 static ATOM atom = 0; |
129 static HMODULE instance = NULL; | 127 static HMODULE instance = NULL; |
130 if (!atom) { | 128 if (!atom) { |
131 WNDCLASSEX window_class; | 129 WNDCLASSEX window_class; |
132 base::win::InitializeWindowClass( | 130 base::win::InitializeWindowClass( |
133 webkit::npapi::kWrapperNativeWindowClassName, | 131 kWrapperNativeWindowClassName, |
134 &base::win::WrappedWindowProc<PluginWrapperWindowProc>, | 132 &base::win::WrappedWindowProc<PluginWrapperWindowProc>, |
135 CS_DBLCLKS, | 133 CS_DBLCLKS, |
136 0, | 134 0, |
137 0, | 135 0, |
138 NULL, | 136 NULL, |
139 // xxx reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), | 137 // xxx reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), |
140 reinterpret_cast<HBRUSH>(COLOR_GRAYTEXT+1), | 138 reinterpret_cast<HBRUSH>(COLOR_GRAYTEXT+1), |
141 NULL, | 139 NULL, |
142 NULL, | 140 NULL, |
143 NULL, | 141 NULL, |
(...skipping 15 matching lines...) Expand all Loading... |
159 static const int kMaxTries = 5; | 157 static const int kMaxTries = 5; |
160 BrowserThread::PostTask( | 158 BrowserThread::PostTask( |
161 BrowserThread::IO, | 159 BrowserThread::IO, |
162 FROM_HERE, | 160 FROM_HERE, |
163 base::Bind(&NotifyPluginProcessHostHelper, window, new_parent, | 161 base::Bind(&NotifyPluginProcessHostHelper, window, new_parent, |
164 kMaxTries)); | 162 kMaxTries)); |
165 return new_parent; | 163 return new_parent; |
166 } | 164 } |
167 | 165 |
168 BOOL CALLBACK PaintEnumChildProc(HWND hwnd, LPARAM lparam) { | 166 BOOL CALLBACK PaintEnumChildProc(HWND hwnd, LPARAM lparam) { |
169 if (!WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) | 167 if (!webkit::npapi::IsPluginDelegateWindow(hwnd)) |
170 return TRUE; | 168 return TRUE; |
171 | 169 |
172 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); | 170 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); |
173 gfx::Rect rect_in_pixels = ui::win::DIPToScreenRect(*rect); | 171 gfx::Rect rect_in_pixels = ui::win::DIPToScreenRect(*rect); |
174 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName); | 172 static UINT msg = RegisterWindowMessage(kPaintMessageName); |
175 WPARAM wparam = rect_in_pixels.x() << 16 | rect_in_pixels.y(); | 173 WPARAM wparam = rect_in_pixels.x() << 16 | rect_in_pixels.y(); |
176 lparam = rect_in_pixels.width() << 16 | rect_in_pixels.height(); | 174 lparam = rect_in_pixels.width() << 16 | rect_in_pixels.height(); |
177 | 175 |
178 // SendMessage gets the message across much quicker than PostMessage, since it | 176 // SendMessage gets the message across much quicker than PostMessage, since it |
179 // doesn't get queued. When the plugin thread calls PeekMessage or other | 177 // doesn't get queued. When the plugin thread calls PeekMessage or other |
180 // Win32 APIs, sent messages are dispatched automatically. | 178 // Win32 APIs, sent messages are dispatched automatically. |
181 SendNotifyMessage(hwnd, msg, wparam, lparam); | 179 SendNotifyMessage(hwnd, msg, wparam, lparam); |
182 | 180 |
183 return TRUE; | 181 return TRUE; |
184 } | 182 } |
185 | 183 |
186 // Windows callback for OnDestroy to detach the plugin windows. | 184 // Windows callback for OnDestroy to detach the plugin windows. |
187 BOOL CALLBACK DetachPluginWindowsCallbackInternal(HWND window, LPARAM param) { | 185 BOOL CALLBACK DetachPluginWindowsCallbackInternal(HWND window, LPARAM param) { |
188 RenderWidgetHostViewBase::DetachPluginWindowsCallback(window); | 186 RenderWidgetHostViewBase::DetachPluginWindowsCallback(window); |
189 return TRUE; | 187 return TRUE; |
190 } | 188 } |
191 | 189 |
192 } // namespace | 190 } // namespace |
193 | 191 |
194 // static | 192 // static |
195 void RenderWidgetHostViewBase::DetachPluginWindowsCallback(HWND window) { | 193 void RenderWidgetHostViewBase::DetachPluginWindowsCallback(HWND window) { |
196 if (WebPluginDelegateImpl::IsPluginDelegateWindow(window) && | 194 if (webkit::npapi::IsPluginDelegateWindow(window) && |
197 !IsHungAppWindow(window)) { | 195 !IsHungAppWindow(window)) { |
198 ::ShowWindow(window, SW_HIDE); | 196 ::ShowWindow(window, SW_HIDE); |
199 SetParent(window, NULL); | 197 SetParent(window, NULL); |
200 } | 198 } |
201 } | 199 } |
202 | 200 |
203 // static | 201 // static |
204 void RenderWidgetHostViewBase::MovePluginWindowsHelper( | 202 void RenderWidgetHostViewBase::MovePluginWindowsHelper( |
205 HWND parent, | 203 HWND parent, |
206 const std::vector<webkit::npapi::WebPluginGeometry>& moves) { | 204 const std::vector<WebPluginGeometry>& moves) { |
207 if (moves.empty()) | 205 if (moves.empty()) |
208 return; | 206 return; |
209 | 207 |
210 bool oop_plugins = | 208 bool oop_plugins = |
211 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) && | 209 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) && |
212 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessPlugins); | 210 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessPlugins); |
213 | 211 |
214 HDWP defer_window_pos_info = | 212 HDWP defer_window_pos_info = |
215 ::BeginDeferWindowPos(static_cast<int>(moves.size())); | 213 ::BeginDeferWindowPos(static_cast<int>(moves.size())); |
216 | 214 |
217 if (!defer_window_pos_info) { | 215 if (!defer_window_pos_info) { |
218 NOTREACHED(); | 216 NOTREACHED(); |
219 return; | 217 return; |
220 } | 218 } |
221 | 219 |
222 for (size_t i = 0; i < moves.size(); ++i) { | 220 for (size_t i = 0; i < moves.size(); ++i) { |
223 unsigned long flags = 0; | 221 unsigned long flags = 0; |
224 const webkit::npapi::WebPluginGeometry& move = moves[i]; | 222 const WebPluginGeometry& move = moves[i]; |
225 HWND window = move.window; | 223 HWND window = move.window; |
226 | 224 |
227 // As the plugin parent window which lives on the browser UI thread is | 225 // As the plugin parent window which lives on the browser UI thread is |
228 // destroyed asynchronously, it is possible that we have a stale window | 226 // destroyed asynchronously, it is possible that we have a stale window |
229 // sent in by the renderer for moving around. | 227 // sent in by the renderer for moving around. |
230 // Note: get the parent before checking if the window is valid, to avoid a | 228 // Note: get the parent before checking if the window is valid, to avoid a |
231 // race condition where the window is destroyed after the check but before | 229 // race condition where the window is destroyed after the check but before |
232 // the GetParent call. | 230 // the GetParent call. |
233 HWND cur_parent = ::GetParent(window); | 231 HWND cur_parent = ::GetParent(window); |
234 if (!::IsWindow(window)) | 232 if (!::IsWindow(window)) |
235 continue; | 233 continue; |
236 | 234 |
237 if (!WebPluginDelegateImpl::IsPluginDelegateWindow(window)) { | 235 if (!webkit::npapi::IsPluginDelegateWindow(window)) { |
238 // The renderer should only be trying to move plugin windows. However, | 236 // The renderer should only be trying to move plugin windows. However, |
239 // this may happen as a result of a race condition (i.e. even after the | 237 // this may happen as a result of a race condition (i.e. even after the |
240 // check right above), so we ignore it. | 238 // check right above), so we ignore it. |
241 continue; | 239 continue; |
242 } | 240 } |
243 | 241 |
244 if (oop_plugins) { | 242 if (oop_plugins) { |
245 if (cur_parent == WebPluginDelegateImpl::GetDefaultWindowParent()) { | 243 if (cur_parent == webkit::npapi::GetDefaultWindowParent()) { |
246 // The plugin window hasn't been parented yet, add an intermediate | 244 // The plugin window hasn't been parented yet, add an intermediate |
247 // window that lives on this thread to speed up scrolling. Note this | 245 // window that lives on this thread to speed up scrolling. Note this |
248 // only works with out of process plugins since we depend on | 246 // only works with out of process plugins since we depend on |
249 // PluginProcessHost to destroy the intermediate HWNDs. | 247 // PluginProcessHost to destroy the intermediate HWNDs. |
250 cur_parent = ReparentWindow(window, parent); | 248 cur_parent = ReparentWindow(window, parent); |
251 ::ShowWindow(window, SW_SHOW); // Window was created hidden. | 249 ::ShowWindow(window, SW_SHOW); // Window was created hidden. |
252 } else if (!IsPluginWrapperWindow(cur_parent)) { | 250 } else if (!IsPluginWrapperWindow(cur_parent)) { |
253 continue; // Race if plugin process is shutting down. | 251 continue; // Race if plugin process is shutting down. |
254 } | 252 } |
255 | 253 |
256 // We move the intermediate parent window which doesn't result in cross- | 254 // We move the intermediate parent window which doesn't result in cross- |
257 // process synchronous Windows messages. | 255 // process synchronous Windows messages. |
258 window = cur_parent; | 256 window = cur_parent; |
259 } else { | 257 } else { |
260 if (cur_parent == WebPluginDelegateImpl::GetDefaultWindowParent()) | 258 if (cur_parent == webkit::npapi::GetDefaultWindowParent()) |
261 SetParent(window, parent); | 259 SetParent(window, parent); |
262 } | 260 } |
263 | 261 |
264 if (move.visible) | 262 if (move.visible) |
265 flags |= SWP_SHOWWINDOW; | 263 flags |= SWP_SHOWWINDOW; |
266 else | 264 else |
267 flags |= SWP_HIDEWINDOW; | 265 flags |= SWP_HIDEWINDOW; |
268 | 266 |
269 #if defined(USE_AURA) | 267 #if defined(USE_AURA) |
270 // Without this flag, Windows repaints the parent area uncovered by this | 268 // Without this flag, Windows repaints the parent area uncovered by this |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 if (!defer_window_pos_info) { | 305 if (!defer_window_pos_info) { |
308 DCHECK(false) << "DeferWindowPos failed, so all plugin moves ignored."; | 306 DCHECK(false) << "DeferWindowPos failed, so all plugin moves ignored."; |
309 return; | 307 return; |
310 } | 308 } |
311 } | 309 } |
312 | 310 |
313 ::EndDeferWindowPos(defer_window_pos_info); | 311 ::EndDeferWindowPos(defer_window_pos_info); |
314 | 312 |
315 #if defined(USE_AURA) | 313 #if defined(USE_AURA) |
316 for (size_t i = 0; i < moves.size(); ++i) { | 314 for (size_t i = 0; i < moves.size(); ++i) { |
317 const webkit::npapi::WebPluginGeometry& move = moves[i]; | 315 const WebPluginGeometry& move = moves[i]; |
318 RECT r; | 316 RECT r; |
319 GetWindowRect(move.window, &r); | 317 GetWindowRect(move.window, &r); |
320 gfx::Rect gr(r); | 318 gfx::Rect gr(r); |
321 PaintEnumChildProc(move.window, reinterpret_cast<LPARAM>(&gr)); | 319 PaintEnumChildProc(move.window, reinterpret_cast<LPARAM>(&gr)); |
322 } | 320 } |
323 #endif | 321 #endif |
324 } | 322 } |
325 | 323 |
326 // static | 324 // static |
327 void RenderWidgetHostViewBase::PaintPluginWindowsHelper( | 325 void RenderWidgetHostViewBase::PaintPluginWindowsHelper( |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 | 522 |
525 uint32 RenderWidgetHostViewBase::RendererFrameNumber() { | 523 uint32 RenderWidgetHostViewBase::RendererFrameNumber() { |
526 return renderer_frame_number_; | 524 return renderer_frame_number_; |
527 } | 525 } |
528 | 526 |
529 void RenderWidgetHostViewBase::DidReceiveRendererFrame() { | 527 void RenderWidgetHostViewBase::DidReceiveRendererFrame() { |
530 ++renderer_frame_number_; | 528 ++renderer_frame_number_; |
531 } | 529 } |
532 | 530 |
533 } // namespace content | 531 } // namespace content |
OLD | NEW |