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

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 21192002: Remove more methods from PluginDelegate. Some I moved the implementationto the callers. For others,… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
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/renderer/pepper/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // returned vector are only guaranteed valid so long as the vector of strings 317 // returned vector are only guaranteed valid so long as the vector of strings
318 // is not modified. 318 // is not modified.
319 scoped_ptr<const char*[]> StringVectorToArgArray( 319 scoped_ptr<const char*[]> StringVectorToArgArray(
320 const std::vector<std::string>& vector) { 320 const std::vector<std::string>& vector) {
321 scoped_ptr<const char*[]> array(new const char*[vector.size()]); 321 scoped_ptr<const char*[]> array(new const char*[vector.size()]);
322 for (size_t i = 0; i < vector.size(); ++i) 322 for (size_t i = 0; i < vector.size(); ++i)
323 array[i] = vector[i].c_str(); 323 array[i] = vector[i].c_str();
324 return array.Pass(); 324 return array.Pass();
325 } 325 }
326 326
327 class PluginInstanceLockTarget : public MouseLockDispatcher::LockTarget {
328 public:
329 PluginInstanceLockTarget(PepperPluginInstanceImpl* plugin)
330 : plugin_(plugin) {}
331
332 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
333 plugin_->OnLockMouseACK(succeeded);
334 }
335
336 virtual void OnMouseLockLost() OVERRIDE {
337 plugin_->OnMouseLockLost();
338 }
339
340 virtual bool HandleMouseLockedInputEvent(
341 const WebKit::WebMouseEvent &event) OVERRIDE {
342 plugin_->HandleMouseLockedInputEvent(event);
343 return true;
344 }
345
346 private:
347 PepperPluginInstanceImpl* plugin_;
348 };
349
350
327 } // namespace 351 } // namespace
328 352
329 // static 353 // static
330 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( 354 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create(
331 PluginDelegate* delegate, 355 PluginDelegate* delegate,
332 RenderViewImpl* render_view, 356 RenderViewImpl* render_view,
333 PluginModule* module, 357 PluginModule* module,
334 WebPluginContainer* container, 358 WebPluginContainer* container,
335 const GURL& plugin_url) { 359 const GURL& plugin_url) {
336 base::Callback<const void*(const char*)> get_plugin_interface_func = 360 base::Callback<const void*(const char*)> get_plugin_interface_func =
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 PluginObjectSet plugin_object_copy; 525 PluginObjectSet plugin_object_copy;
502 live_plugin_objects_.swap(plugin_object_copy); 526 live_plugin_objects_.swap(plugin_object_copy);
503 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 527 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
504 i != plugin_object_copy.end(); ++i) 528 i != plugin_object_copy.end(); ++i)
505 delete *i; 529 delete *i;
506 530
507 if (TrackedCallback::IsPending(lock_mouse_callback_)) 531 if (TrackedCallback::IsPending(lock_mouse_callback_))
508 lock_mouse_callback_->Abort(); 532 lock_mouse_callback_->Abort();
509 533
510 delegate_->InstanceDeleted(this); 534 delegate_->InstanceDeleted(this);
535 UnSetAndDeleteLockTargetAdapter();
511 module_->InstanceDeleted(this); 536 module_->InstanceDeleted(this);
512 // If we switched from the NaCl plugin module, notify it too. 537 // If we switched from the NaCl plugin module, notify it too.
513 if (original_module_.get()) 538 if (original_module_.get())
514 original_module_->InstanceDeleted(this); 539 original_module_->InstanceDeleted(this);
515 540
516 // This should be last since some of the above "instance deleted" calls will 541 // This should be last since some of the above "instance deleted" calls will
517 // want to look up in the global map to get info off of our object. 542 // want to look up in the global map to get info off of our object.
518 HostGlobals::Get()->InstanceDeleted(pp_instance_); 543 HostGlobals::Get()->InstanceDeleted(pp_instance_);
519 } 544 }
520 545
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // Force free all resources and vars. 637 // Force free all resources and vars.
613 HostGlobals::Get()->InstanceCrashed(pp_instance()); 638 HostGlobals::Get()->InstanceCrashed(pp_instance());
614 639
615 // Free any associated graphics. 640 // Free any associated graphics.
616 SetFullscreen(false); 641 SetFullscreen(false);
617 FlashSetFullscreen(false, false); 642 FlashSetFullscreen(false, false);
618 // Unbind current 2D or 3D graphics context. 643 // Unbind current 2D or 3D graphics context.
619 BindGraphics(pp_instance(), 0); 644 BindGraphics(pp_instance(), 0);
620 InvalidateRect(gfx::Rect()); 645 InvalidateRect(gfx::Rect());
621 646
622 delegate()->PluginCrashed(this); 647 render_view_->PluginCrashed(module_->path(), module_->GetPeerProcessId());
648 UnSetAndDeleteLockTargetAdapter();
623 } 649 }
624 650
625 static void SetGPUHistogram(const ::ppapi::Preferences& prefs, 651 static void SetGPUHistogram(const ::ppapi::Preferences& prefs,
626 const std::vector<std::string>& arg_names, 652 const std::vector<std::string>& arg_names,
627 const std::vector<std::string>& arg_values) { 653 const std::vector<std::string>& arg_values) {
628 // Calculate a histogram to let us determine how likely people are to try to 654 // Calculate a histogram to let us determine how likely people are to try to
629 // run Stage3D content on machines that have it blacklisted. 655 // run Stage3D content on machines that have it blacklisted.
630 #if defined(OS_WIN) 656 #if defined(OS_WIN)
631 bool needs_gpu = false; 657 bool needs_gpu = false;
632 bool is_xp = base::win::GetVersion() <= base::win::VERSION_XP; 658 bool is_xp = base::win::GetVersion() <= base::win::VERSION_XP;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 gfx::Rect caret(text_input_caret_); 882 gfx::Rect caret(text_input_caret_);
857 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); 883 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y);
858 return caret; 884 return caret;
859 } 885 }
860 886
861 bool PepperPluginInstanceImpl::HandleInputEvent( 887 bool PepperPluginInstanceImpl::HandleInputEvent(
862 const WebKit::WebInputEvent& event, 888 const WebKit::WebInputEvent& event,
863 WebCursorInfo* cursor_info) { 889 WebCursorInfo* cursor_info) {
864 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); 890 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent");
865 891
866 if (WebInputEvent::isMouseEventType(event.type)) 892 if (WebInputEvent::isMouseEventType(event.type)) {
867 delegate()->DidReceiveMouseEvent(this); 893 static_cast<PepperPluginDelegateImpl*>(delegate_)->DidReceiveMouseEvent(
894 this);
895 }
868 896
869 // Don't dispatch input events to crashed plugins. 897 // Don't dispatch input events to crashed plugins.
870 if (module()->is_crashed()) 898 if (module()->is_crashed())
871 return false; 899 return false;
872 900
873 // Keep a reference on the stack. See NOTE above. 901 // Keep a reference on the stack. See NOTE above.
874 scoped_refptr<PepperPluginInstanceImpl> ref(this); 902 scoped_refptr<PepperPluginInstanceImpl> ref(this);
875 903
876 bool rv = false; 904 bool rv = false;
877 if (LoadInputEventInterface()) { 905 if (LoadInputEventInterface()) {
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 lock_mouse_callback_->Run(PP_ERROR_FAILED); 1607 lock_mouse_callback_->Run(PP_ERROR_FAILED);
1580 return; 1608 return;
1581 } 1609 }
1582 1610
1583 PPB_Graphics3D_Impl* graphics_3d = bound_graphics_3d_.get(); 1611 PPB_Graphics3D_Impl* graphics_3d = bound_graphics_3d_.get();
1584 if (graphics_3d) 1612 if (graphics_3d)
1585 UpdateLayer(); 1613 UpdateLayer();
1586 1614
1587 bool old_plugin_focus = PluginHasFocus(); 1615 bool old_plugin_focus = PluginHasFocus();
1588 flash_fullscreen_ = flash_fullscreen; 1616 flash_fullscreen_ = flash_fullscreen;
1589 if (is_mouselock_pending && !delegate()->IsMouseLocked(this)) { 1617 if (is_mouselock_pending && !IsMouseLocked()) {
1590 if (!IsProcessingUserGesture() && 1618 if (!IsProcessingUserGesture() &&
1591 !module_->permissions().HasPermission( 1619 !module_->permissions().HasPermission(
1592 ::ppapi::PERMISSION_BYPASS_USER_GESTURE)) { 1620 ::ppapi::PERMISSION_BYPASS_USER_GESTURE)) {
1593 lock_mouse_callback_->Run(PP_ERROR_NO_USER_GESTURE); 1621 lock_mouse_callback_->Run(PP_ERROR_NO_USER_GESTURE);
1594 } else { 1622 } else {
1595 // Open a user gesture here so the Webkit user gesture checks will succeed 1623 // Open a user gesture here so the Webkit user gesture checks will succeed
1596 // for out-of-process plugins. 1624 // for out-of-process plugins.
1597 WebScopedUserGesture user_gesture(CurrentUserGestureToken()); 1625 WebScopedUserGesture user_gesture(CurrentUserGestureToken());
1598 if (!delegate()->LockMouse(this)) 1626 if (!LockMouse())
1599 lock_mouse_callback_->Run(PP_ERROR_FAILED); 1627 lock_mouse_callback_->Run(PP_ERROR_FAILED);
1600 } 1628 }
1601 } 1629 }
1602 1630
1603 if (PluginHasFocus() != old_plugin_focus) 1631 if (PluginHasFocus() != old_plugin_focus)
1604 SendFocusChangeNotification(); 1632 SendFocusChangeNotification();
1605 } 1633 }
1606 1634
1607 bool PepperPluginInstanceImpl::IsViewAccelerated() { 1635 bool PepperPluginInstanceImpl::IsViewAccelerated() {
1608 if (!container_) 1636 if (!container_)
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 DoSetCursor(custom_cursor.release()); 2302 DoSetCursor(custom_cursor.release());
2275 return PP_TRUE; 2303 return PP_TRUE;
2276 } 2304 }
2277 2305
2278 int32_t PepperPluginInstanceImpl::LockMouse( 2306 int32_t PepperPluginInstanceImpl::LockMouse(
2279 PP_Instance instance, 2307 PP_Instance instance,
2280 scoped_refptr<TrackedCallback> callback) { 2308 scoped_refptr<TrackedCallback> callback) {
2281 if (TrackedCallback::IsPending(lock_mouse_callback_)) 2309 if (TrackedCallback::IsPending(lock_mouse_callback_))
2282 return PP_ERROR_INPROGRESS; 2310 return PP_ERROR_INPROGRESS;
2283 2311
2284 if (delegate()->IsMouseLocked(this)) 2312 if (IsMouseLocked())
2285 return PP_OK; 2313 return PP_OK;
2286 2314
2287 if (!CanAccessMainFrame()) 2315 if (!CanAccessMainFrame())
2288 return PP_ERROR_NOACCESS; 2316 return PP_ERROR_NOACCESS;
2289 2317
2290 if (!IsProcessingUserGesture()) 2318 if (!IsProcessingUserGesture())
2291 return PP_ERROR_NO_USER_GESTURE; 2319 return PP_ERROR_NO_USER_GESTURE;
2292 2320
2293 // Attempt mouselock only if Flash isn't waiting on fullscreen, otherwise 2321 // Attempt mouselock only if Flash isn't waiting on fullscreen, otherwise
2294 // we wait and call LockMouse() in UpdateFlashFullscreenState(). 2322 // we wait and call LockMouse() in UpdateFlashFullscreenState().
2295 if (!FlashIsFullscreenOrPending() || flash_fullscreen()) { 2323 if (!FlashIsFullscreenOrPending() || flash_fullscreen_) {
2296 // Open a user gesture here so the Webkit user gesture checks will succeed 2324 // Open a user gesture here so the Webkit user gesture checks will succeed
2297 // for out-of-process plugins. 2325 // for out-of-process plugins.
2298 WebScopedUserGesture user_gesture(CurrentUserGestureToken()); 2326 WebScopedUserGesture user_gesture(CurrentUserGestureToken());
2299 if (!delegate()->LockMouse(this)) 2327 if (!LockMouse())
2300 return PP_ERROR_FAILED; 2328 return PP_ERROR_FAILED;
2301 } 2329 }
2302 2330
2303 // Either mouselock succeeded or a Flash fullscreen is pending. 2331 // Either mouselock succeeded or a Flash fullscreen is pending.
2304 lock_mouse_callback_ = callback; 2332 lock_mouse_callback_ = callback;
2305 return PP_OK_COMPLETIONPENDING; 2333 return PP_OK_COMPLETIONPENDING;
2306 } 2334 }
2307 2335
2308 void PepperPluginInstanceImpl::UnlockMouse(PP_Instance instance) { 2336 void PepperPluginInstanceImpl::UnlockMouse(PP_Instance instance) {
2309 delegate()->UnlockMouse(this); 2337 GetMouseLockDispatcher()->UnlockMouse(GetOrCreateLockTargetAdapter());
2310 } 2338 }
2311 2339
2312 void PepperPluginInstanceImpl::SetTextInputType(PP_Instance instance, 2340 void PepperPluginInstanceImpl::SetTextInputType(PP_Instance instance,
2313 PP_TextInput_Type type) { 2341 PP_TextInput_Type type) {
2314 int itype = type; 2342 int itype = type;
2315 if (itype < 0 || itype > ui::TEXT_INPUT_TYPE_URL) 2343 if (itype < 0 || itype > ui::TEXT_INPUT_TYPE_URL)
2316 itype = ui::TEXT_INPUT_TYPE_NONE; 2344 itype = ui::TEXT_INPUT_TYPE_NONE;
2317 text_input_type_ = static_cast<ui::TextInputType>(itype); 2345 text_input_type_ = static_cast<ui::TextInputType>(itype);
2318 delegate()->PluginTextInputTypeChanged(this); 2346 delegate()->PluginTextInputTypeChanged(this);
2319 } 2347 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
2599 2627
2600 void PepperPluginInstanceImpl::SetAlwaysOnTop(bool on_top) { 2628 void PepperPluginInstanceImpl::SetAlwaysOnTop(bool on_top) {
2601 always_on_top_ = on_top; 2629 always_on_top_ = on_top;
2602 } 2630 }
2603 2631
2604 void PepperPluginInstanceImpl::DoSetCursor(WebCursorInfo* cursor) { 2632 void PepperPluginInstanceImpl::DoSetCursor(WebCursorInfo* cursor) {
2605 cursor_.reset(cursor); 2633 cursor_.reset(cursor);
2606 if (fullscreen_container_) { 2634 if (fullscreen_container_) {
2607 fullscreen_container_->DidChangeCursor(*cursor); 2635 fullscreen_container_->DidChangeCursor(*cursor);
2608 } else { 2636 } else {
2609 delegate()->DidChangeCursor(this, *cursor); 2637 static_cast<PepperPluginDelegateImpl*>(delegate_)->DidChangeCursor(
2638 this, *cursor);
2610 } 2639 }
2611 } 2640 }
2612 2641
2613 bool PepperPluginInstanceImpl::IsFullPagePlugin() { 2642 bool PepperPluginInstanceImpl::IsFullPagePlugin() {
2614 WebFrame* frame = container()->element().document().frame(); 2643 WebFrame* frame = container()->element().document().frame();
2615 return frame->view()->mainFrame()->document().isPluginDocument(); 2644 return frame->view()->mainFrame()->document().isPluginDocument();
2616 } 2645 }
2617 2646
2618 void PepperPluginInstanceImpl::FlashSetFullscreen(bool fullscreen, 2647 void PepperPluginInstanceImpl::FlashSetFullscreen(bool fullscreen,
2619 bool delay_report) { 2648 bool delay_report) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 2782
2754 void PepperPluginInstanceImpl::ResetSizeAttributesAfterFullscreen() { 2783 void PepperPluginInstanceImpl::ResetSizeAttributesAfterFullscreen() {
2755 screen_size_for_fullscreen_ = gfx::Size(); 2784 screen_size_for_fullscreen_ = gfx::Size();
2756 WebElement element = container_->element(); 2785 WebElement element = container_->element();
2757 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2786 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2758 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2787 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2759 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2788 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2760 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2789 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2761 } 2790 }
2762 2791
2792 bool PepperPluginInstanceImpl::IsMouseLocked() {
2793 return GetMouseLockDispatcher()->IsMouseLockedTo(
2794 GetOrCreateLockTargetAdapter());
2795 }
2796
2797 bool PepperPluginInstanceImpl::LockMouse() {
2798 return GetMouseLockDispatcher()->LockMouse(GetOrCreateLockTargetAdapter());
2799 }
2800
2801 MouseLockDispatcher::LockTarget*
2802 PepperPluginInstanceImpl::GetOrCreateLockTargetAdapter() {
2803 if (!lock_target_.get()) {
2804 lock_target_.reset(new PluginInstanceLockTarget(this));
2805 }
2806 return lock_target_.get();
2807 }
2808
2809 MouseLockDispatcher* PepperPluginInstanceImpl::GetMouseLockDispatcher() {
2810 if (flash_fullscreen_) {
2811 RenderWidgetFullscreenPepper* container =
2812 static_cast<RenderWidgetFullscreenPepper*>(fullscreen_container_);
2813 return container->mouse_lock_dispatcher();
2814 } else {
2815 return render_view_->mouse_lock_dispatcher();
2816 }
2817 }
2818
2819 void PepperPluginInstanceImpl::UnSetAndDeleteLockTargetAdapter() {
2820 if (lock_target_.get()) {
2821 GetMouseLockDispatcher()->OnLockTargetDestroyed(lock_target_.get());
2822 lock_target_.reset();
2823 }
2824 }
2825
2763 } // namespace content 2826 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698