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 "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/gfx/gdi_util.h" |
9 #include "base/gfx/point.h" | 10 #include "base/gfx/point.h" |
10 #include "base/stats_counters.h" | 11 #include "base/stats_counters.h" |
11 #include "webkit/default_plugin/plugin_impl.h" | 12 #include "webkit/default_plugin/plugin_impl.h" |
12 #include "webkit/glue/glue_util.h" | 13 #include "webkit/glue/glue_util.h" |
13 #include "webkit/glue/webplugin.h" | 14 #include "webkit/glue/webplugin.h" |
14 #include "webkit/glue/plugins/plugin_instance.h" | 15 #include "webkit/glue/plugins/plugin_instance.h" |
15 #include "webkit/glue/plugins/plugin_lib.h" | 16 #include "webkit/glue/plugins/plugin_lib.h" |
16 #include "webkit/glue/plugins/plugin_list.h" | 17 #include "webkit/glue/plugins/plugin_list.h" |
17 #include "webkit/glue/plugins/plugin_stream_url.h" | 18 #include "webkit/glue/plugins/plugin_stream_url.h" |
18 | 19 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 244 } |
244 | 245 |
245 instance_->NPP_Destroy(); | 246 instance_->NPP_Destroy(); |
246 | 247 |
247 instance_->set_web_plugin(NULL); | 248 instance_->set_web_plugin(NULL); |
248 | 249 |
249 instance_ = 0; | 250 instance_ = 0; |
250 } | 251 } |
251 } | 252 } |
252 | 253 |
253 void WebPluginDelegateImpl::UpdateGeometry(const gfx::Rect& window_rect, | 254 void WebPluginDelegateImpl::UpdateGeometry( |
254 const gfx::Rect& clip_rect, | 255 const gfx::Rect& window_rect, |
255 bool visible) { | 256 const gfx::Rect& clip_rect, |
| 257 const std::vector<gfx::Rect>& cutout_rects, |
| 258 bool visible) { |
256 if (windowless_) { | 259 if (windowless_) { |
257 WindowlessUpdateGeometry(window_rect, clip_rect); | 260 WindowlessUpdateGeometry(window_rect, clip_rect); |
258 } else { | 261 } else { |
259 WindowedUpdateGeometry(window_rect, clip_rect, visible); | 262 WindowedUpdateGeometry(window_rect, clip_rect, cutout_rects, visible); |
260 } | 263 } |
261 | 264 |
262 // Initiate a download on the plugin url. This should be done for the | 265 // Initiate a download on the plugin url. This should be done for the |
263 // first update geometry sequence. | 266 // first update geometry sequence. |
264 if (first_geometry_update_) { | 267 if (first_geometry_update_) { |
265 first_geometry_update_ = false; | 268 first_geometry_update_ = false; |
266 // An empty url corresponds to an EMBED tag with no src attribute. | 269 // An empty url corresponds to an EMBED tag with no src attribute. |
267 if (!load_manually_ && !plugin_url_.empty()) { | 270 if (!load_manually_ && !plugin_url_.empty()) { |
268 instance_->SendStream(plugin_url_.c_str(), false, NULL); | 271 instance_->SendStream(plugin_url_.c_str(), false, NULL); |
269 } | 272 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } | 340 } |
338 | 341 |
339 void WebPluginDelegateImpl::InstallMissingPlugin() { | 342 void WebPluginDelegateImpl::InstallMissingPlugin() { |
340 NPEvent evt; | 343 NPEvent evt; |
341 evt.event = PluginInstallerImpl::kInstallMissingPluginMessage; | 344 evt.event = PluginInstallerImpl::kInstallMissingPluginMessage; |
342 evt.lParam = 0; | 345 evt.lParam = 0; |
343 evt.wParam = 0; | 346 evt.wParam = 0; |
344 instance()->NPP_HandleEvent(&evt); | 347 instance()->NPP_HandleEvent(&evt); |
345 } | 348 } |
346 | 349 |
347 void WebPluginDelegateImpl::WindowedUpdateGeometry(const gfx::Rect& window_rect, | 350 void WebPluginDelegateImpl::WindowedUpdateGeometry( |
348 const gfx::Rect& clip_rect, | 351 const gfx::Rect& window_rect, |
349 bool visible) { | 352 const gfx::Rect& clip_rect, |
350 if (WindowedReposition(window_rect, clip_rect, visible) || | 353 const std::vector<gfx::Rect>& cutout_rects, |
| 354 bool visible) { |
| 355 if (WindowedReposition(window_rect, clip_rect, cutout_rects, visible) || |
351 !windowed_did_set_window_) { | 356 !windowed_did_set_window_) { |
352 // Let the plugin know that it has been moved | 357 // Let the plugin know that it has been moved |
353 WindowedSetWindow(); | 358 WindowedSetWindow(); |
354 } | 359 } |
355 } | 360 } |
356 | 361 |
357 bool WebPluginDelegateImpl::WindowedCreatePlugin() { | 362 bool WebPluginDelegateImpl::WindowedCreatePlugin() { |
358 DCHECK(!windowed_handle_); | 363 DCHECK(!windowed_handle_); |
359 | 364 |
360 RegisterNativeWindowClass(); | 365 RegisterNativeWindowClass(); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 reinterpret_cast<LPARAM>( | 582 reinterpret_cast<LPARAM>( |
578 &WebPluginDelegateImpl::FlashWindowlessWndProc))) { | 583 &WebPluginDelegateImpl::FlashWindowlessWndProc))) { |
579 // Log that this happened. Flash will still work; it just means the | 584 // Log that this happened. Flash will still work; it just means the |
580 // throttle isn't installed (and Flash will use more CPU). | 585 // throttle isn't installed (and Flash will use more CPU). |
581 NOTREACHED(); | 586 NOTREACHED(); |
582 LOG(ERROR) << "Failed to wrap all windowless Flash windows"; | 587 LOG(ERROR) << "Failed to wrap all windowless Flash windows"; |
583 } | 588 } |
584 return true; | 589 return true; |
585 } | 590 } |
586 | 591 |
587 void WebPluginDelegateImpl::MoveWindow(HWND window, | 592 void WebPluginDelegateImpl::MoveWindow( |
588 const gfx::Rect& window_rect, | 593 HWND window, |
589 const gfx::Rect& clip_rect, | 594 const gfx::Rect& window_rect, |
590 bool visible) { | 595 const gfx::Rect& clip_rect, |
| 596 const std::vector<gfx::Rect>& cutout_rects, |
| 597 bool visible) { |
591 HRGN hrgn = ::CreateRectRgn(clip_rect.x(), | 598 HRGN hrgn = ::CreateRectRgn(clip_rect.x(), |
592 clip_rect.y(), | 599 clip_rect.y(), |
593 clip_rect.right(), | 600 clip_rect.right(), |
594 clip_rect.bottom()); | 601 clip_rect.bottom()); |
| 602 gfx::SubtractRectanglesFromRegion(hrgn, cutout_rects); |
595 | 603 |
596 // Note: System will own the hrgn after we call SetWindowRgn, | 604 // Note: System will own the hrgn after we call SetWindowRgn, |
597 // so we don't need to call DeleteObject(hrgn) | 605 // so we don't need to call DeleteObject(hrgn) |
598 ::SetWindowRgn(window, hrgn, FALSE); | 606 ::SetWindowRgn(window, hrgn, FALSE); |
599 | 607 |
600 unsigned long flags = 0; | 608 unsigned long flags = 0; |
601 if (visible) | 609 if (visible) |
602 flags |= SWP_SHOWWINDOW; | 610 flags |= SWP_SHOWWINDOW; |
603 else | 611 else |
604 flags |= SWP_HIDEWINDOW; | 612 flags |= SWP_HIDEWINDOW; |
605 | 613 |
606 ::SetWindowPos(window, | 614 ::SetWindowPos(window, |
607 NULL, | 615 NULL, |
608 window_rect.x(), | 616 window_rect.x(), |
609 window_rect.y(), | 617 window_rect.y(), |
610 window_rect.width(), | 618 window_rect.width(), |
611 window_rect.height(), | 619 window_rect.height(), |
612 flags); | 620 flags); |
613 } | 621 } |
614 | 622 |
615 bool WebPluginDelegateImpl::WindowedReposition(const gfx::Rect& window_rect, | 623 bool WebPluginDelegateImpl::WindowedReposition( |
616 const gfx::Rect& clip_rect, | 624 const gfx::Rect& window_rect, |
617 bool visible) { | 625 const gfx::Rect& clip_rect, |
| 626 const std::vector<gfx::Rect>& cutout_rects, |
| 627 bool visible) { |
618 if (!windowed_handle_) { | 628 if (!windowed_handle_) { |
619 NOTREACHED(); | 629 NOTREACHED(); |
620 return false; | 630 return false; |
621 } | 631 } |
622 | 632 |
623 if (window_rect_ == window_rect && clip_rect_ == clip_rect && | 633 if (window_rect_ == window_rect && clip_rect_ == clip_rect && |
| 634 cutout_rects == cutout_rects_ && |
624 initial_plugin_resize_done_) | 635 initial_plugin_resize_done_) |
625 return false; | 636 return false; |
626 | 637 |
627 window_rect_ = window_rect; | 638 window_rect_ = window_rect; |
628 clip_rect_ = clip_rect; | 639 clip_rect_ = clip_rect; |
| 640 cutout_rects_ = cutout_rects; |
629 | 641 |
630 if (!initial_plugin_resize_done_) { | 642 if (!initial_plugin_resize_done_) { |
631 // We need to ensure that the plugin process continues to reposition | 643 // We need to ensure that the plugin process continues to reposition |
632 // the plugin window until we receive an indication that it is now visible. | 644 // the plugin window until we receive an indication that it is now visible. |
633 // Subsequent repositions will be done by the browser. | 645 // Subsequent repositions will be done by the browser. |
634 if (visible) | 646 if (visible) |
635 initial_plugin_resize_done_ = true; | 647 initial_plugin_resize_done_ = true; |
636 // We created the window with 0 width and height since we didn't know it | 648 // We created the window with 0 width and height since we didn't know it |
637 // at the time. Now that we know the geometry, we we can update its size | 649 // at the time. Now that we know the geometry, we we can update its size |
638 // since the browser only calls SetWindowPos when scrolling occurs. | 650 // since the browser only calls SetWindowPos when scrolling occurs. |
639 MoveWindow(windowed_handle_, window_rect, clip_rect, visible); | 651 MoveWindow(windowed_handle_, window_rect, clip_rect, cutout_rects, visible); |
640 // Ensure that the entire window gets repainted. | 652 // Ensure that the entire window gets repainted. |
641 ::InvalidateRect(windowed_handle_, NULL, FALSE); | 653 ::InvalidateRect(windowed_handle_, NULL, FALSE); |
642 } | 654 } |
643 | 655 |
644 return true; | 656 return true; |
645 } | 657 } |
646 | 658 |
647 void WebPluginDelegateImpl::WindowedSetWindow() { | 659 void WebPluginDelegateImpl::WindowedSetWindow() { |
648 if (!instance_) | 660 if (!instance_) |
649 return; | 661 return; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 const gfx::Rect& clip_rect) { | 796 const gfx::Rect& clip_rect) { |
785 // Only resend to the instance if the geometry has changed. | 797 // Only resend to the instance if the geometry has changed. |
786 if (window_rect == window_rect_ && clip_rect == clip_rect_) | 798 if (window_rect == window_rect_ && clip_rect == clip_rect_) |
787 return; | 799 return; |
788 | 800 |
789 // Set this flag before entering the instance in case of side-effects. | 801 // Set this flag before entering the instance in case of side-effects. |
790 windowless_needs_set_window_ = true; | 802 windowless_needs_set_window_ = true; |
791 | 803 |
792 // We will inform the instance of this change when we call NPP_SetWindow. | 804 // We will inform the instance of this change when we call NPP_SetWindow. |
793 clip_rect_ = clip_rect; | 805 clip_rect_ = clip_rect; |
| 806 cutout_rects_.clear(); |
794 | 807 |
795 if (window_rect_ != window_rect) { | 808 if (window_rect_ != window_rect) { |
796 window_rect_ = window_rect; | 809 window_rect_ = window_rect; |
797 | 810 |
798 WindowlessSetWindow(true); | 811 WindowlessSetWindow(true); |
799 | 812 |
800 WINDOWPOS win_pos = {0}; | 813 WINDOWPOS win_pos = {0}; |
801 win_pos.x = window_rect_.x(); | 814 win_pos.x = window_rect_.x(); |
802 win_pos.y = window_rect_.y(); | 815 win_pos.y = window_rect_.y(); |
803 win_pos.cx = window_rect_.width(); | 816 win_pos.cx = window_rect_.width(); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 break; | 1068 break; |
1056 } | 1069 } |
1057 | 1070 |
1058 return false; | 1071 return false; |
1059 } | 1072 } |
1060 | 1073 |
1061 void WebPluginDelegateImpl::OnUserGestureEnd() { | 1074 void WebPluginDelegateImpl::OnUserGestureEnd() { |
1062 user_gesture_message_posted_ = false; | 1075 user_gesture_message_posted_ = false; |
1063 instance()->PopPopupsEnabledState(); | 1076 instance()->PopPopupsEnabledState(); |
1064 } | 1077 } |
OLD | NEW |