OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper_plugin_delegate_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // That message handler will then call client->BrokerConnected() with the | 658 // That message handler will then call client->BrokerConnected() with the |
659 // saved pipe handle. | 659 // saved pipe handle. |
660 // Temporarily, just call back. | 660 // Temporarily, just call back. |
661 client->BrokerConnected(PlatformFileToInt(plugin_handle), result); | 661 client->BrokerConnected(PlatformFileToInt(plugin_handle), result); |
662 } | 662 } |
663 | 663 |
664 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) | 664 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) |
665 : render_view_(render_view), | 665 : render_view_(render_view), |
666 has_saved_context_menu_action_(false), | 666 has_saved_context_menu_action_(false), |
667 saved_context_menu_action_(0), | 667 saved_context_menu_action_(0), |
668 is_pepper_plugin_focused_(false), | 668 focused_plugin_(NULL), |
669 mouse_lock_owner_(NULL), | 669 mouse_lock_owner_(NULL), |
670 mouse_locked_(false), | 670 mouse_locked_(false), |
671 pending_lock_request_(false), | 671 pending_lock_request_(false), |
672 pending_unlock_request_(false), | 672 pending_unlock_request_(false), |
673 last_mouse_event_target_(NULL) { | 673 last_mouse_event_target_(NULL) { |
674 } | 674 } |
675 | 675 |
676 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { | 676 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { |
677 DCHECK(!mouse_lock_owner_); | 677 DCHECK(!mouse_lock_owner_); |
678 } | 678 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 active_instances_.begin(); | 842 active_instances_.begin(); |
843 i != active_instances_.end(); ++i) { | 843 i != active_instances_.end(); ++i) { |
844 webkit::ppapi::PluginInstance* instance = *i; | 844 webkit::ppapi::PluginInstance* instance = *i; |
845 if (instance->GetBitmapForOptimizedPluginPaint( | 845 if (instance->GetBitmapForOptimizedPluginPaint( |
846 paint_bounds, dib, location, clip)) | 846 paint_bounds, dib, location, clip)) |
847 return *i; | 847 return *i; |
848 } | 848 } |
849 return NULL; | 849 return NULL; |
850 } | 850 } |
851 | 851 |
852 void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) { | 852 void PepperPluginDelegateImpl::PluginFocusChanged( |
853 is_pepper_plugin_focused_ = focused; | 853 webkit::ppapi::PluginInstance* instance, |
| 854 bool focused) { |
| 855 if (focused) |
| 856 focused_plugin_ = instance; |
| 857 else if (focused_plugin_ == instance) |
| 858 focused_plugin_ = NULL; |
854 if (render_view_) | 859 if (render_view_) |
855 render_view_->PpapiPluginFocusChanged(); | 860 render_view_->PpapiPluginFocusChanged(); |
856 } | 861 } |
857 | 862 |
| 863 void PepperPluginDelegateImpl::PluginTextInputTypeChanged( |
| 864 webkit::ppapi::PluginInstance* instance) { |
| 865 if (focused_plugin_ == instance && render_view_) |
| 866 render_view_->PpapiPluginTextInputTypeChanged(); |
| 867 } |
| 868 |
| 869 void PepperPluginDelegateImpl::PluginRequestedCancelComposition( |
| 870 webkit::ppapi::PluginInstance* instance) { |
| 871 if (focused_plugin_ == instance && render_view_) |
| 872 render_view_->PpapiPluginCancelComposition(); |
| 873 } |
| 874 |
| 875 void PepperPluginDelegateImpl::OnImeSetComposition( |
| 876 const string16& text, |
| 877 const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 878 int selection_start, |
| 879 int selection_end) { |
| 880 if (!IsPluginAcceptingCompositionEvents()) { |
| 881 composition_text_ = text; |
| 882 } else { |
| 883 // TODO(kinaba) currently all composition events are sent directly to |
| 884 // plugins. Use DOM event mechanism after WebKit is made aware about |
| 885 // plugins that support composition. |
| 886 // The code below mimics the behavior of WebCore::Editor::setComposition. |
| 887 |
| 888 // Empty -> nonempty: composition started. |
| 889 if (composition_text_.empty() && !text.empty()) |
| 890 focused_plugin_->HandleCompositionStart(string16()); |
| 891 // Nonempty -> empty: composition canceled. |
| 892 if (!composition_text_.empty() && text.empty()) |
| 893 focused_plugin_->HandleCompositionEnd(string16()); |
| 894 composition_text_ = text; |
| 895 // Nonempty: composition is ongoing. |
| 896 if (!composition_text_.empty()) { |
| 897 focused_plugin_->HandleCompositionUpdate(composition_text_, underlines, |
| 898 selection_start, selection_end); |
| 899 } |
| 900 } |
| 901 } |
| 902 |
| 903 void PepperPluginDelegateImpl::OnImeConfirmComposition(const string16& text) { |
| 904 // Here, text.empty() has a special meaning. It means to commit the last |
| 905 // update of composition text (see RenderWidgetHost::ImeConfirmComposition()). |
| 906 const string16& last_text = text.empty() ? composition_text_ : text; |
| 907 |
| 908 // last_text is empty only when both text and composition_text_ is. Ignore it. |
| 909 if (last_text.empty()) |
| 910 return; |
| 911 |
| 912 if (!IsPluginAcceptingCompositionEvents()) { |
| 913 for (size_t i = 0; i < text.size(); ++i) { |
| 914 WebKit::WebKeyboardEvent char_event; |
| 915 char_event.type = WebKit::WebInputEvent::Char; |
| 916 char_event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
| 917 char_event.modifiers = 0; |
| 918 char_event.windowsKeyCode = last_text[i]; |
| 919 char_event.nativeKeyCode = last_text[i]; |
| 920 char_event.text[0] = last_text[i]; |
| 921 char_event.unmodifiedText[0] = last_text[i]; |
| 922 if (render_view_->webwidget()) |
| 923 render_view_->webwidget()->handleInputEvent(char_event); |
| 924 } |
| 925 } else { |
| 926 // Mimics the order of events sent by WebKit. |
| 927 // See WebCore::Editor::setComposition() for the corresponding code. |
| 928 focused_plugin_->HandleCompositionEnd(last_text); |
| 929 focused_plugin_->HandleTextInput(last_text); |
| 930 } |
| 931 composition_text_.clear(); |
| 932 } |
| 933 |
| 934 gfx::Rect PepperPluginDelegateImpl::GetCaretBounds() const { |
| 935 if (!focused_plugin_) |
| 936 return gfx::Rect(0, 0, 0, 0); |
| 937 return focused_plugin_->GetCaretBounds(); |
| 938 } |
| 939 |
| 940 ui::TextInputType PepperPluginDelegateImpl::GetTextInputType() const { |
| 941 if (!focused_plugin_) |
| 942 return ui::TEXT_INPUT_TYPE_NONE; |
| 943 return focused_plugin_->text_input_type(); |
| 944 } |
| 945 |
| 946 bool PepperPluginDelegateImpl::IsPluginAcceptingCompositionEvents() const { |
| 947 if (!focused_plugin_) |
| 948 return false; |
| 949 return focused_plugin_->IsPluginAcceptingCompositionEvents(); |
| 950 } |
| 951 |
| 952 bool PepperPluginDelegateImpl::CanComposeInline() const { |
| 953 return IsPluginAcceptingCompositionEvents(); |
| 954 } |
| 955 |
858 void PepperPluginDelegateImpl::PluginCrashed( | 956 void PepperPluginDelegateImpl::PluginCrashed( |
859 webkit::ppapi::PluginInstance* instance) { | 957 webkit::ppapi::PluginInstance* instance) { |
860 subscribed_to_policy_updates_.erase(instance); | 958 subscribed_to_policy_updates_.erase(instance); |
861 render_view_->PluginCrashed(instance->module()->path()); | 959 render_view_->PluginCrashed(instance->module()->path()); |
862 | 960 |
863 UnlockMouse(instance); | 961 UnlockMouse(instance); |
864 } | 962 } |
865 | 963 |
866 void PepperPluginDelegateImpl::InstanceCreated( | 964 void PepperPluginDelegateImpl::InstanceCreated( |
867 webkit::ppapi::PluginInstance* instance) { | 965 webkit::ppapi::PluginInstance* instance) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 } | 1144 } |
1047 | 1145 |
1048 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { | 1146 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { |
1049 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = | 1147 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = |
1050 active_instances_.begin(); | 1148 active_instances_.begin(); |
1051 i != active_instances_.end(); ++i) | 1149 i != active_instances_.end(); ++i) |
1052 (*i)->SetContentAreaFocus(has_focus); | 1150 (*i)->SetContentAreaFocus(has_focus); |
1053 } | 1151 } |
1054 | 1152 |
1055 bool PepperPluginDelegateImpl::IsPluginFocused() const { | 1153 bool PepperPluginDelegateImpl::IsPluginFocused() const { |
1056 return is_pepper_plugin_focused_; | 1154 return focused_plugin_ != NULL; |
1057 } | 1155 } |
1058 | 1156 |
1059 void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) { | 1157 void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) { |
1060 DCHECK(!mouse_locked_ && pending_lock_request_); | 1158 DCHECK(!mouse_locked_ && pending_lock_request_); |
1061 | 1159 |
1062 mouse_locked_ = succeeded; | 1160 mouse_locked_ = succeeded; |
1063 pending_lock_request_ = false; | 1161 pending_lock_request_ = false; |
1064 if (pending_unlock_request_ && !succeeded) { | 1162 if (pending_unlock_request_ && !succeeded) { |
1065 // We have sent an unlock request after the lock request. However, since | 1163 // We have sent an unlock request after the lock request. However, since |
1066 // the lock request has failed, the unlock request will be ignored by the | 1164 // the lock request has failed, the unlock request will be ignored by the |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 | 1742 |
1645 int PepperPluginDelegateImpl::GetRoutingId() const { | 1743 int PepperPluginDelegateImpl::GetRoutingId() const { |
1646 return render_view_->routing_id(); | 1744 return render_view_->routing_id(); |
1647 } | 1745 } |
1648 | 1746 |
1649 void PepperPluginDelegateImpl::PublishInitialPolicy( | 1747 void PepperPluginDelegateImpl::PublishInitialPolicy( |
1650 scoped_refptr<webkit::ppapi::PluginInstance> instance, | 1748 scoped_refptr<webkit::ppapi::PluginInstance> instance, |
1651 const std::string& policy) { | 1749 const std::string& policy) { |
1652 instance->HandlePolicyUpdate(policy); | 1750 instance->HandlePolicyUpdate(policy); |
1653 } | 1751 } |
OLD | NEW |