OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "base/gfx/rect.h" | 5 #include "base/gfx/rect.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (!delegate_) | 243 if (!delegate_) |
244 return; | 244 return; |
245 | 245 |
246 // Note that |canvas| is only used when in windowless mode. | 246 // Note that |canvas| is only used when in windowless mode. |
247 delegate_->Paint(canvas, paint_rect); | 247 delegate_->Paint(canvas, paint_rect); |
248 } | 248 } |
249 | 249 |
250 void WebPluginImpl::updateGeometry( | 250 void WebPluginImpl::updateGeometry( |
251 const WebRect& window_rect, const WebRect& clip_rect, | 251 const WebRect& window_rect, const WebRect& clip_rect, |
252 const WebVector<WebRect>& cutout_rects, bool is_visible) { | 252 const WebVector<WebRect>& cutout_rects, bool is_visible) { |
253 if (window_ && page_delegate_) { | 253 WebPluginGeometry new_geometry; |
254 // Notify the window hosting the plugin (the WebViewDelegate) that | 254 new_geometry.window = window_; |
255 // it needs to adjust the plugin, so that all the HWNDs can be moved | 255 new_geometry.window_rect = window_rect; |
256 // at the same time. | 256 new_geometry.clip_rect = clip_rect; |
257 WebPluginGeometry move; | 257 new_geometry.visible = is_visible; |
258 move.window = window_; | 258 new_geometry.rects_valid = true; |
259 move.window_rect = window_rect; | 259 for (size_t i = 0; i < cutout_rects.size(); ++i) |
260 move.clip_rect = clip_rect; | 260 new_geometry.cutout_rects.push_back(cutout_rects[i]); |
261 for (size_t i = 0; i < cutout_rects.size(); ++i) | |
262 move.cutout_rects.push_back(cutout_rects[i]); | |
263 move.rects_valid = true; | |
264 move.visible = is_visible; | |
265 | 261 |
266 page_delegate_->DidMovePlugin(move); | 262 // Only send DidMovePlugin if the geometry changed in some way. |
| 263 if (window_ && |
| 264 page_delegate_ && |
| 265 (first_geometry_update_ || !new_geometry.Equals(geometry_))) { |
| 266 page_delegate_->DidMovePlugin(new_geometry); |
267 } | 267 } |
268 | 268 |
269 if (first_geometry_update_ || window_rect != window_rect_ || | 269 // Only UpdateGeometry if either the window or clip rects have changed. |
270 clip_rect != clip_rect_) { | 270 if (first_geometry_update_ || |
271 window_rect_ = window_rect; | 271 new_geometry.window_rect != geometry_.window_rect || |
272 clip_rect_ = clip_rect; | 272 new_geometry.clip_rect != geometry_.clip_rect) { |
273 // Notify the plugin that its parameters have changed. | 273 // Notify the plugin that its parameters have changed. |
274 delegate_->UpdateGeometry(window_rect_, clip_rect_); | 274 delegate_->UpdateGeometry(new_geometry.window_rect, new_geometry.clip_rect); |
| 275 } |
275 | 276 |
276 // Initiate a download on the plugin url. This should be done for the | 277 // Initiate a download on the plugin url. This should be done for the |
277 // first update geometry sequence. We need to ensure that the plugin | 278 // first update geometry sequence. We need to ensure that the plugin |
278 // receives the geometry update before it starts receiving data. | 279 // receives the geometry update before it starts receiving data. |
279 if (first_geometry_update_) { | 280 if (first_geometry_update_) { |
280 first_geometry_update_ = false; | 281 // An empty url corresponds to an EMBED tag with no src attribute. |
281 // An empty url corresponds to an EMBED tag with no src attribute. | 282 if (!load_manually_ && plugin_url_.is_valid()) { |
282 if (!load_manually_ && plugin_url_.is_valid()) { | 283 // The Flash plugin hangs for a while if it receives data before |
283 // The Flash plugin hangs for a while if it receives data before | 284 // receiving valid plugin geometry. By valid geometry we mean the |
284 // receiving valid plugin geometry. By valid geometry we mean the | 285 // geometry received by a call to setFrameRect in the Webkit |
285 // geometry received by a call to setFrameRect in the Webkit | 286 // layout code path. To workaround this issue we download the |
286 // layout code path. To workaround this issue we download the | 287 // plugin source url on a timer. |
287 // plugin source url on a timer. | 288 MessageLoop::current()->PostDelayedTask( |
288 MessageLoop::current()->PostDelayedTask( | 289 FROM_HERE, method_factory_.NewRunnableMethod( |
289 FROM_HERE, method_factory_.NewRunnableMethod( | 290 &WebPluginImpl::OnDownloadPluginSrcUrl), 0); |
290 &WebPluginImpl::OnDownloadPluginSrcUrl), 0); | |
291 } | |
292 } | 291 } |
293 } | 292 } |
| 293 |
| 294 first_geometry_update_ = false; |
| 295 geometry_ = new_geometry; |
294 } | 296 } |
295 | 297 |
296 void WebPluginImpl::updateFocus(bool focused) { | 298 void WebPluginImpl::updateFocus(bool focused) { |
297 if (focused && windowless_) | 299 if (focused && accepts_input_events_) |
298 delegate_->SetFocus(); | 300 delegate_->SetFocus(); |
299 } | 301 } |
300 | 302 |
301 void WebPluginImpl::updateVisibility(bool visible) { | 303 void WebPluginImpl::updateVisibility(bool visible) { |
302 if (!window_ || !page_delegate_) | 304 if (!window_ || !page_delegate_) |
303 return; | 305 return; |
304 | 306 |
305 WebPluginGeometry move; | 307 WebPluginGeometry move; |
306 move.window = window_; | 308 move.window = window_; |
307 move.window_rect = gfx::Rect(); | 309 move.window_rect = gfx::Rect(); |
308 move.clip_rect = gfx::Rect(); | 310 move.clip_rect = gfx::Rect(); |
309 move.rects_valid = false; | 311 move.rects_valid = false; |
310 move.visible = visible; | 312 move.visible = visible; |
311 | 313 |
312 page_delegate_->DidMovePlugin(move); | 314 page_delegate_->DidMovePlugin(move); |
313 } | 315 } |
314 | 316 |
315 bool WebPluginImpl::acceptsInputEvents() { | 317 bool WebPluginImpl::acceptsInputEvents() { |
316 return windowless_; | 318 return accepts_input_events_; |
317 } | 319 } |
318 | 320 |
319 bool WebPluginImpl::handleInputEvent( | 321 bool WebPluginImpl::handleInputEvent( |
320 const WebInputEvent& event, WebCursorInfo& cursor_info) { | 322 const WebInputEvent& event, WebCursorInfo& cursor_info) { |
321 return delegate_->HandleInputEvent(event, &cursor_info); | 323 return delegate_->HandleInputEvent(event, &cursor_info); |
322 } | 324 } |
323 | 325 |
324 void WebPluginImpl::didReceiveResponse(const WebURLResponse& response) { | 326 void WebPluginImpl::didReceiveResponse(const WebURLResponse& response) { |
325 ignore_response_error_ = false; | 327 ignore_response_error_ = false; |
326 | 328 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 url, reason, reinterpret_cast<intptr_t>(notify_data)); | 369 url, reason, reinterpret_cast<intptr_t>(notify_data)); |
368 } | 370 } |
369 | 371 |
370 // ----------------------------------------------------------------------------- | 372 // ----------------------------------------------------------------------------- |
371 | 373 |
372 WebPluginImpl::WebPluginImpl( | 374 WebPluginImpl::WebPluginImpl( |
373 WebFrame* webframe, const WebPluginParams& params, | 375 WebFrame* webframe, const WebPluginParams& params, |
374 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) | 376 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) |
375 : windowless_(false), | 377 : windowless_(false), |
376 window_(NULL), | 378 window_(NULL), |
| 379 accepts_input_events_(false), |
377 page_delegate_(page_delegate), | 380 page_delegate_(page_delegate), |
378 webframe_(webframe), | 381 webframe_(webframe), |
379 delegate_(NULL), | 382 delegate_(NULL), |
380 container_(NULL), | 383 container_(NULL), |
381 plugin_url_(params.url), | 384 plugin_url_(params.url), |
382 load_manually_(params.loadManually), | 385 load_manually_(params.loadManually), |
383 first_geometry_update_(true), | 386 first_geometry_update_(true), |
384 ignore_response_error_(false), | 387 ignore_response_error_(false), |
385 mime_type_(params.mimeType.utf8()), | 388 mime_type_(params.mimeType.utf8()), |
386 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 389 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
387 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); | 390 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); |
388 StringToLowerASCII(&mime_type_); | 391 StringToLowerASCII(&mime_type_); |
389 | 392 |
390 for (size_t i = 0; i < params.attributeNames.size(); ++i) { | 393 for (size_t i = 0; i < params.attributeNames.size(); ++i) { |
391 arg_names_.push_back(params.attributeNames[i].utf8()); | 394 arg_names_.push_back(params.attributeNames[i].utf8()); |
392 arg_values_.push_back(params.attributeValues[i].utf8()); | 395 arg_values_.push_back(params.attributeValues[i].utf8()); |
393 } | 396 } |
394 } | 397 } |
395 | 398 |
396 WebPluginImpl::~WebPluginImpl() { | 399 WebPluginImpl::~WebPluginImpl() { |
397 } | 400 } |
398 | 401 |
399 void WebPluginImpl::SetWindow(gfx::PluginWindowHandle window) { | 402 void WebPluginImpl::SetWindow(gfx::PluginWindowHandle window) { |
400 if (window) { | 403 if (window) { |
401 DCHECK(!windowless_); | 404 DCHECK(!windowless_); |
402 window_ = window; | 405 window_ = window; |
| 406 accepts_input_events_ = false; |
403 if (page_delegate_) { | 407 if (page_delegate_) { |
404 // Tell the view delegate that the plugin window was created, so that it | 408 // Tell the view delegate that the plugin window was created, so that it |
405 // can create necessary container widgets. | 409 // can create necessary container widgets. |
406 page_delegate_->CreatedPluginWindow(window); | 410 page_delegate_->CreatedPluginWindow(window); |
407 } | 411 } |
408 } else { | 412 } else { |
409 DCHECK(!window_); // Make sure not called twice. | 413 DCHECK(!window_); // Make sure not called twice. |
410 windowless_ = true; | 414 windowless_ = true; |
| 415 accepts_input_events_ = true; |
411 } | 416 } |
412 } | 417 } |
413 | 418 |
414 void WebPluginImpl::WillDestroyWindow(gfx::PluginWindowHandle window) { | 419 void WebPluginImpl::WillDestroyWindow(gfx::PluginWindowHandle window) { |
415 DCHECK_EQ(window, window_); | 420 DCHECK_EQ(window, window_); |
416 window_ = NULL; | 421 window_ = NULL; |
417 if (page_delegate_) | 422 if (page_delegate_) |
418 page_delegate_->WillDestroyPluginWindow(window); | 423 page_delegate_->WillDestroyPluginWindow(window); |
419 } | 424 } |
420 | 425 |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 WebDevToolsAgent* WebPluginImpl::GetDevToolsAgent() { | 1130 WebDevToolsAgent* WebPluginImpl::GetDevToolsAgent() { |
1126 if (!webframe_) | 1131 if (!webframe_) |
1127 return NULL; | 1132 return NULL; |
1128 WebView* view = webframe_->view(); | 1133 WebView* view = webframe_->view(); |
1129 if (!view) | 1134 if (!view) |
1130 return NULL; | 1135 return NULL; |
1131 return view->devToolsAgent(); | 1136 return view->devToolsAgent(); |
1132 } | 1137 } |
1133 | 1138 |
1134 } // namespace webkit_glue | 1139 } // namespace webkit_glue |
OLD | NEW |