| 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 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 5 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/gfx/gdi_util.h" | |
| 13 #include "base/gfx/point.h" | |
| 14 #include "base/stats_counters.h" | 12 #include "base/stats_counters.h" |
| 15 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 16 #include "webkit/default_plugin/plugin_impl.h" | 14 #include "webkit/default_plugin/plugin_impl.h" |
| 17 #include "webkit/glue/glue_util.h" | 15 #include "webkit/glue/glue_util.h" |
| 18 #include "webkit/glue/webplugin.h" | 16 #include "webkit/glue/webplugin.h" |
| 19 #include "webkit/glue/plugins/plugin_instance.h" | 17 #include "webkit/glue/plugins/plugin_instance.h" |
| 20 #include "webkit/glue/plugins/plugin_lib.h" | 18 #include "webkit/glue/plugins/plugin_lib.h" |
| 21 #include "webkit/glue/plugins/plugin_list.h" | 19 #include "webkit/glue/plugins/plugin_list.h" |
| 22 #include "webkit/glue/plugins/plugin_stream_url.h" | 20 #include "webkit/glue/plugins/plugin_stream_url.h" |
| 23 #include "webkit/glue/webkit_glue.h" | 21 #include "webkit/glue/webkit_glue.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 instance_(instance), | 124 instance_(instance), |
| 127 quirks_(0), | 125 quirks_(0), |
| 128 plugin_(NULL), | 126 plugin_(NULL), |
| 129 windowless_(false), | 127 windowless_(false), |
| 130 windowed_handle_(NULL), | 128 windowed_handle_(NULL), |
| 131 windowed_did_set_window_(false), | 129 windowed_did_set_window_(false), |
| 132 windowless_needs_set_window_(true), | 130 windowless_needs_set_window_(true), |
| 133 plugin_wnd_proc_(NULL), | 131 plugin_wnd_proc_(NULL), |
| 134 last_message_(0), | 132 last_message_(0), |
| 135 is_calling_wndproc(false), | 133 is_calling_wndproc(false), |
| 136 initial_plugin_resize_done_(false), | |
| 137 dummy_window_for_activation_(NULL), | 134 dummy_window_for_activation_(NULL), |
| 138 handle_event_message_filter_hook_(NULL), | 135 handle_event_message_filter_hook_(NULL), |
| 139 handle_event_pump_messages_event_(NULL), | 136 handle_event_pump_messages_event_(NULL), |
| 140 handle_event_depth_(0), | 137 handle_event_depth_(0), |
| 141 user_gesture_message_posted_(false), | 138 user_gesture_message_posted_(false), |
| 142 #pragma warning(suppress: 4355) // can use this | 139 #pragma warning(suppress: 4355) // can use this |
| 143 user_gesture_msg_factory_(this), | 140 user_gesture_msg_factory_(this), |
| 144 plugin_module_handle_(NULL) { | 141 plugin_module_handle_(NULL) { |
| 145 memset(&window_, 0, sizeof(window_)); | 142 memset(&window_, 0, sizeof(window_)); |
| 146 | 143 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 311 } |
| 315 } | 312 } |
| 316 } | 313 } |
| 317 | 314 |
| 318 instance_ = 0; | 315 instance_ = 0; |
| 319 } | 316 } |
| 320 } | 317 } |
| 321 | 318 |
| 322 void WebPluginDelegateImpl::UpdateGeometry( | 319 void WebPluginDelegateImpl::UpdateGeometry( |
| 323 const gfx::Rect& window_rect, | 320 const gfx::Rect& window_rect, |
| 324 const gfx::Rect& clip_rect, | 321 const gfx::Rect& clip_rect) { |
| 325 const std::vector<gfx::Rect>& cutout_rects, | |
| 326 bool visible) { | |
| 327 if (windowless_) { | 322 if (windowless_) { |
| 328 WindowlessUpdateGeometry(window_rect, clip_rect); | 323 WindowlessUpdateGeometry(window_rect, clip_rect); |
| 329 } else { | 324 } else { |
| 330 WindowedUpdateGeometry(window_rect, clip_rect, cutout_rects, visible); | 325 WindowedUpdateGeometry(window_rect, clip_rect); |
| 331 } | 326 } |
| 332 } | 327 } |
| 333 | 328 |
| 334 void WebPluginDelegateImpl::Paint(HDC hdc, const gfx::Rect& rect) { | 329 void WebPluginDelegateImpl::Paint(HDC hdc, const gfx::Rect& rect) { |
| 335 if (windowless_) | 330 if (windowless_) |
| 336 WindowlessPaint(hdc, rect); | 331 WindowlessPaint(hdc, rect); |
| 337 } | 332 } |
| 338 | 333 |
| 339 void WebPluginDelegateImpl::Print(HDC hdc) { | 334 void WebPluginDelegateImpl::Print(HDC hdc) { |
| 340 // Disabling the call to NPP_Print as it causes a crash in | 335 // Disabling the call to NPP_Print as it causes a crash in |
| (...skipping 28 matching lines...) Expand all Loading... |
| 369 bool success, | 364 bool success, |
| 370 bool notify_needed, | 365 bool notify_needed, |
| 371 int notify_data) { | 366 int notify_data) { |
| 372 instance()->SendJavaScriptStream(url, result, success, notify_needed, | 367 instance()->SendJavaScriptStream(url, result, success, notify_needed, |
| 373 notify_data); | 368 notify_data); |
| 374 } | 369 } |
| 375 | 370 |
| 376 void WebPluginDelegateImpl::DidReceiveManualResponse( | 371 void WebPluginDelegateImpl::DidReceiveManualResponse( |
| 377 const std::string& url, const std::string& mime_type, | 372 const std::string& url, const std::string& mime_type, |
| 378 const std::string& headers, uint32 expected_length, uint32 last_modified) { | 373 const std::string& headers, uint32 expected_length, uint32 last_modified) { |
| 374 if (!windowless_) { |
| 375 // Calling NPP_WriteReady before NPP_SetWindow causes movies to not load in |
| 376 // Flash. See http://b/issue?id=892174. |
| 377 DCHECK(windowed_did_set_window_); |
| 378 } |
| 379 |
| 379 instance()->DidReceiveManualResponse(url, mime_type, headers, | 380 instance()->DidReceiveManualResponse(url, mime_type, headers, |
| 380 expected_length, last_modified); | 381 expected_length, last_modified); |
| 381 } | 382 } |
| 382 | 383 |
| 383 void WebPluginDelegateImpl::DidReceiveManualData(const char* buffer, | 384 void WebPluginDelegateImpl::DidReceiveManualData(const char* buffer, |
| 384 int length) { | 385 int length) { |
| 385 instance()->DidReceiveManualData(buffer, length); | 386 instance()->DidReceiveManualData(buffer, length); |
| 386 } | 387 } |
| 387 | 388 |
| 388 void WebPluginDelegateImpl::DidFinishManualLoading() { | 389 void WebPluginDelegateImpl::DidFinishManualLoading() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 400 void WebPluginDelegateImpl::InstallMissingPlugin() { | 401 void WebPluginDelegateImpl::InstallMissingPlugin() { |
| 401 NPEvent evt; | 402 NPEvent evt; |
| 402 evt.event = PluginInstallerImpl::kInstallMissingPluginMessage; | 403 evt.event = PluginInstallerImpl::kInstallMissingPluginMessage; |
| 403 evt.lParam = 0; | 404 evt.lParam = 0; |
| 404 evt.wParam = 0; | 405 evt.wParam = 0; |
| 405 instance()->NPP_HandleEvent(&evt); | 406 instance()->NPP_HandleEvent(&evt); |
| 406 } | 407 } |
| 407 | 408 |
| 408 void WebPluginDelegateImpl::WindowedUpdateGeometry( | 409 void WebPluginDelegateImpl::WindowedUpdateGeometry( |
| 409 const gfx::Rect& window_rect, | 410 const gfx::Rect& window_rect, |
| 410 const gfx::Rect& clip_rect, | 411 const gfx::Rect& clip_rect) { |
| 411 const std::vector<gfx::Rect>& cutout_rects, | 412 if (WindowedReposition(window_rect, clip_rect) || |
| 412 bool visible) { | |
| 413 if (WindowedReposition(window_rect, clip_rect, cutout_rects, visible) || | |
| 414 !windowed_did_set_window_) { | 413 !windowed_did_set_window_) { |
| 415 // Let the plugin know that it has been moved | 414 // Let the plugin know that it has been moved |
| 416 WindowedSetWindow(); | 415 WindowedSetWindow(); |
| 417 } | 416 } |
| 418 } | 417 } |
| 419 | 418 |
| 420 bool WebPluginDelegateImpl::WindowedCreatePlugin() { | 419 bool WebPluginDelegateImpl::WindowedCreatePlugin() { |
| 421 DCHECK(!windowed_handle_); | 420 DCHECK(!windowed_handle_); |
| 422 | 421 |
| 423 RegisterNativeWindowClass(); | 422 RegisterNativeWindowClass(); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 reinterpret_cast<LPARAM>( | 654 reinterpret_cast<LPARAM>( |
| 656 &WebPluginDelegateImpl::FlashWindowlessWndProc))) { | 655 &WebPluginDelegateImpl::FlashWindowlessWndProc))) { |
| 657 // Log that this happened. Flash will still work; it just means the | 656 // Log that this happened. Flash will still work; it just means the |
| 658 // throttle isn't installed (and Flash will use more CPU). | 657 // throttle isn't installed (and Flash will use more CPU). |
| 659 NOTREACHED(); | 658 NOTREACHED(); |
| 660 LOG(ERROR) << "Failed to wrap all windowless Flash windows"; | 659 LOG(ERROR) << "Failed to wrap all windowless Flash windows"; |
| 661 } | 660 } |
| 662 return true; | 661 return true; |
| 663 } | 662 } |
| 664 | 663 |
| 665 void WebPluginDelegateImpl::MoveWindow( | |
| 666 HWND window, | |
| 667 const gfx::Rect& window_rect, | |
| 668 const gfx::Rect& clip_rect, | |
| 669 const std::vector<gfx::Rect>& cutout_rects, | |
| 670 bool visible) { | |
| 671 HRGN hrgn = ::CreateRectRgn(clip_rect.x(), | |
| 672 clip_rect.y(), | |
| 673 clip_rect.right(), | |
| 674 clip_rect.bottom()); | |
| 675 gfx::SubtractRectanglesFromRegion(hrgn, cutout_rects); | |
| 676 | |
| 677 // Note: System will own the hrgn after we call SetWindowRgn, | |
| 678 // so we don't need to call DeleteObject(hrgn) | |
| 679 ::SetWindowRgn(window, hrgn, FALSE); | |
| 680 | |
| 681 unsigned long flags = 0; | |
| 682 if (visible) | |
| 683 flags |= SWP_SHOWWINDOW; | |
| 684 else | |
| 685 flags |= SWP_HIDEWINDOW; | |
| 686 | |
| 687 ::SetWindowPos(window, | |
| 688 NULL, | |
| 689 window_rect.x(), | |
| 690 window_rect.y(), | |
| 691 window_rect.width(), | |
| 692 window_rect.height(), | |
| 693 flags); | |
| 694 } | |
| 695 | |
| 696 bool WebPluginDelegateImpl::WindowedReposition( | 664 bool WebPluginDelegateImpl::WindowedReposition( |
| 697 const gfx::Rect& window_rect, | 665 const gfx::Rect& window_rect, |
| 698 const gfx::Rect& clip_rect, | 666 const gfx::Rect& clip_rect) { |
| 699 const std::vector<gfx::Rect>& cutout_rects, | |
| 700 bool visible) { | |
| 701 if (!windowed_handle_) { | 667 if (!windowed_handle_) { |
| 702 NOTREACHED(); | 668 NOTREACHED(); |
| 703 return false; | 669 return false; |
| 704 } | 670 } |
| 705 | 671 |
| 706 if (window_rect_ == window_rect && clip_rect_ == clip_rect && | 672 if (window_rect_ == window_rect && clip_rect_ == clip_rect) |
| 707 cutout_rects == cutout_rects_ && | |
| 708 initial_plugin_resize_done_) | |
| 709 return false; | 673 return false; |
| 710 | 674 |
| 675 // Clipping is handled by WebPlugin. |
| 676 if (window_rect.size() != window_rect_.size()) { |
| 677 ::SetWindowPos(windowed_handle_, |
| 678 NULL, |
| 679 0, |
| 680 0, |
| 681 window_rect.width(), |
| 682 window_rect.height(), |
| 683 SWP_SHOWWINDOW); |
| 684 } |
| 685 |
| 711 window_rect_ = window_rect; | 686 window_rect_ = window_rect; |
| 712 clip_rect_ = clip_rect; | 687 clip_rect_ = clip_rect; |
| 713 cutout_rects_ = cutout_rects; | |
| 714 | 688 |
| 715 if (!initial_plugin_resize_done_) { | 689 // Ensure that the entire window gets repainted. |
| 716 // We need to ensure that the plugin process continues to reposition | 690 ::InvalidateRect(windowed_handle_, NULL, FALSE); |
| 717 // the plugin window until we receive an indication that it is now visible. | |
| 718 // Subsequent repositions will be done by the browser. | |
| 719 if (visible) | |
| 720 initial_plugin_resize_done_ = true; | |
| 721 // We created the window with 0 width and height since we didn't know it | |
| 722 // at the time. Now that we know the geometry, we we can update its size | |
| 723 // since the browser only calls SetWindowPos when scrolling occurs. | |
| 724 MoveWindow(windowed_handle_, window_rect, clip_rect, cutout_rects, visible); | |
| 725 // Ensure that the entire window gets repainted. | |
| 726 ::InvalidateRect(windowed_handle_, NULL, FALSE); | |
| 727 } | |
| 728 | 691 |
| 729 return true; | 692 return true; |
| 730 } | 693 } |
| 731 | 694 |
| 732 void WebPluginDelegateImpl::WindowedSetWindow() { | 695 void WebPluginDelegateImpl::WindowedSetWindow() { |
| 733 if (!instance_) | 696 if (!instance_) |
| 734 return; | 697 return; |
| 735 | 698 |
| 736 if (!windowed_handle_) { | 699 if (!windowed_handle_) { |
| 737 NOTREACHED(); | 700 NOTREACHED(); |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 | 1129 |
| 1167 // It is ok to pass NULL here to GetCursor as we are not looking for cursor | 1130 // It is ok to pass NULL here to GetCursor as we are not looking for cursor |
| 1168 // types defined by Webkit. | 1131 // types defined by Webkit. |
| 1169 HCURSOR previous_cursor = | 1132 HCURSOR previous_cursor = |
| 1170 current_plugin_instance_->current_windowless_cursor_.GetCursor(NULL); | 1133 current_plugin_instance_->current_windowless_cursor_.GetCursor(NULL); |
| 1171 | 1134 |
| 1172 current_plugin_instance_->current_windowless_cursor_.InitFromExternalCursor( | 1135 current_plugin_instance_->current_windowless_cursor_.InitFromExternalCursor( |
| 1173 cursor); | 1136 cursor); |
| 1174 return previous_cursor; | 1137 return previous_cursor; |
| 1175 } | 1138 } |
| OLD | NEW |