Chromium Code Reviews| 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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 // saved pipe handle. | 656 // saved pipe handle. |
| 657 // Temporarily, just call back. | 657 // Temporarily, just call back. |
| 658 client->BrokerConnected(PlatformFileToInt(plugin_handle), result); | 658 client->BrokerConnected(PlatformFileToInt(plugin_handle), result); |
| 659 } | 659 } |
| 660 | 660 |
| 661 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) | 661 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) |
| 662 : render_view_(render_view), | 662 : render_view_(render_view), |
| 663 has_saved_context_menu_action_(false), | 663 has_saved_context_menu_action_(false), |
| 664 saved_context_menu_action_(0), | 664 saved_context_menu_action_(0), |
| 665 id_generator_(0), | 665 id_generator_(0), |
| 666 is_pepper_plugin_focused_(false) { | 666 focused_plugin_(0) { |
| 667 } | 667 } |
| 668 | 668 |
| 669 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { | 669 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { |
| 670 } | 670 } |
| 671 | 671 |
| 672 scoped_refptr<webkit::ppapi::PluginModule> | 672 scoped_refptr<webkit::ppapi::PluginModule> |
| 673 PepperPluginDelegateImpl::CreatePepperPluginModule( | 673 PepperPluginDelegateImpl::CreatePepperPluginModule( |
| 674 const webkit::WebPluginInfo& webplugin_info, | 674 const webkit::WebPluginInfo& webplugin_info, |
| 675 bool* pepper_plugin_was_registered) { | 675 bool* pepper_plugin_was_registered) { |
| 676 *pepper_plugin_was_registered = true; | 676 *pepper_plugin_was_registered = true; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 active_instances_.begin(); | 834 active_instances_.begin(); |
| 835 i != active_instances_.end(); ++i) { | 835 i != active_instances_.end(); ++i) { |
| 836 webkit::ppapi::PluginInstance* instance = *i; | 836 webkit::ppapi::PluginInstance* instance = *i; |
| 837 if (instance->GetBitmapForOptimizedPluginPaint( | 837 if (instance->GetBitmapForOptimizedPluginPaint( |
| 838 paint_bounds, dib, location, clip)) | 838 paint_bounds, dib, location, clip)) |
| 839 return *i; | 839 return *i; |
| 840 } | 840 } |
| 841 return NULL; | 841 return NULL; |
| 842 } | 842 } |
| 843 | 843 |
| 844 void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) { | 844 void PepperPluginDelegateImpl::PluginFocusChanged( |
| 845 is_pepper_plugin_focused_ = focused; | 845 webkit::ppapi::PluginInstance* instance, |
| 846 bool focused) { | |
| 847 if (focused) { | |
| 848 focused_plugin_ = instance; | |
| 849 } else if (focused_plugin_ == instance) { | |
| 850 focused_plugin_ = 0; | |
| 851 } | |
|
James Su
2011/09/23 01:46:48
nit: no { }
| |
| 846 if (render_view_) | 852 if (render_view_) |
| 847 render_view_->PpapiPluginFocusChanged(); | 853 render_view_->PpapiPluginFocusChanged(); |
| 848 } | 854 } |
| 849 | 855 |
| 856 void PepperPluginDelegateImpl::PluginTextInputTypeChanged( | |
| 857 webkit::ppapi::PluginInstance* instance) { | |
| 858 if (focused_plugin_ == instance && render_view_) | |
| 859 render_view_->PpapiPluginFocusChanged(); | |
|
James Su
2011/09/23 01:46:48
Is it correct? Shouldn't we have a specific method
| |
| 860 } | |
| 861 | |
| 862 void PepperPluginDelegateImpl::OnImeSetComposition( | |
| 863 const string16& text, | |
| 864 const std::vector<WebKit::WebCompositionUnderline>& underlines, | |
| 865 int selection_start, | |
| 866 int selection_end) { | |
| 867 if (!CanComposeInline()) { | |
| 868 composition_text_ = text; | |
| 869 } else { | |
| 870 // TODO(kinaba) currently all composition events are sent directly to | |
| 871 // plugins. Use DOM event mechanism after WebKit is made aware about | |
| 872 // plugins supporting composition. | |
| 873 | |
| 874 // Empty -> nonempty: composition started. | |
| 875 if (composition_text_.empty() && !text.empty()) | |
| 876 focused_plugin_->HandleCompositionStart(string16()); | |
| 877 // Nonempty -> empty: composition canceled. | |
| 878 if (!composition_text_.empty() && text.empty()) | |
| 879 focused_plugin_->HandleCompositionEnd(text); | |
|
James Su
2011/09/23 01:46:48
should send composition_text_ along with compositi
| |
| 880 composition_text_ = text; | |
| 881 // Nonempty: composition is ongoing. | |
| 882 if (!composition_text_.empty()) | |
| 883 focused_plugin_->HandleCompositionUpdate(text, underlines, | |
| 884 selection_start, selection_end); | |
|
James Su
2011/09/23 01:46:48
nit: use {} for multi-line if statement.
| |
| 885 } | |
| 886 } | |
| 887 | |
| 888 void PepperPluginDelegateImpl::OnImeConfirmComposition(const string16& text) { | |
| 889 if (!text.empty()) | |
| 890 composition_text_ = text; | |
| 891 if (composition_text_.empty()) | |
| 892 return; | |
| 893 | |
| 894 if (!CanComposeInline()) { | |
|
James Su
2011/09/23 01:46:48
Is it possible that a plugin cannot handle inline
| |
| 895 for (size_t i = 0; i < text.size(); ++i) { | |
| 896 WebKit::WebKeyboardEvent char_event; | |
| 897 char_event.type = WebKit::WebInputEvent::Char; | |
| 898 char_event.timeStampSeconds = base::Time::Now().ToDoubleT(); | |
| 899 char_event.modifiers = 0; | |
| 900 char_event.windowsKeyCode = composition_text_[i]; | |
| 901 char_event.nativeKeyCode = composition_text_[i]; | |
| 902 char_event.text[0] = composition_text_[i]; | |
| 903 char_event.unmodifiedText[0] = composition_text_[i]; | |
| 904 if (render_view_->webwidget()) | |
| 905 render_view_->webwidget()->handleInputEvent(char_event); | |
| 906 } | |
| 907 } | |
|
James Su
2011/09/23 01:46:48
nit: no line break.
| |
| 908 else { | |
| 909 focused_plugin_->HandleTextInput(composition_text_); | |
| 910 focused_plugin_->HandleCompositionEnd(composition_text_); | |
|
James Su
2011/09/23 01:46:48
Should we send composition end first? Like what we
| |
| 911 } | |
| 912 composition_text_.clear(); | |
| 913 } | |
| 914 | |
| 915 WebKit::WebRect PepperPluginDelegateImpl::GetCaretBounds() const { | |
| 916 if (!focused_plugin_) | |
| 917 return WebKit::WebRect(); | |
| 918 return focused_plugin_->GetCaretBounds(); | |
| 919 } | |
| 920 | |
| 921 WebKit::WebTextInputType PepperPluginDelegateImpl::GetTextInputType() const { | |
| 922 if (!focused_plugin_) | |
| 923 return WebKit::WebTextInputTypeNone; | |
| 924 return focused_plugin_->text_input_type(); | |
| 925 } | |
| 926 | |
| 927 bool PepperPluginDelegateImpl::CanComposeInline() const { | |
| 928 if (!focused_plugin_) | |
| 929 return false; | |
| 930 return focused_plugin_->CanComposeInline(); | |
| 931 } | |
| 932 | |
| 850 void PepperPluginDelegateImpl::PluginCrashed( | 933 void PepperPluginDelegateImpl::PluginCrashed( |
| 851 webkit::ppapi::PluginInstance* instance) { | 934 webkit::ppapi::PluginInstance* instance) { |
| 852 subscribed_to_policy_updates_.erase(instance); | 935 subscribed_to_policy_updates_.erase(instance); |
| 853 render_view_->PluginCrashed(instance->module()->path()); | 936 render_view_->PluginCrashed(instance->module()->path()); |
| 854 } | 937 } |
| 855 | 938 |
| 856 void PepperPluginDelegateImpl::InstanceCreated( | 939 void PepperPluginDelegateImpl::InstanceCreated( |
| 857 webkit::ppapi::PluginInstance* instance) { | 940 webkit::ppapi::PluginInstance* instance) { |
| 858 active_instances_.insert(instance); | 941 active_instances_.insert(instance); |
| 859 | 942 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1026 } | 1109 } |
| 1027 | 1110 |
| 1028 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { | 1111 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { |
| 1029 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = | 1112 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = |
| 1030 active_instances_.begin(); | 1113 active_instances_.begin(); |
| 1031 i != active_instances_.end(); ++i) | 1114 i != active_instances_.end(); ++i) |
| 1032 (*i)->SetContentAreaFocus(has_focus); | 1115 (*i)->SetContentAreaFocus(has_focus); |
| 1033 } | 1116 } |
| 1034 | 1117 |
| 1035 bool PepperPluginDelegateImpl::IsPluginFocused() const { | 1118 bool PepperPluginDelegateImpl::IsPluginFocused() const { |
| 1036 return is_pepper_plugin_focused_; | 1119 return focused_plugin_ != 0; |
|
James Su
2011/09/23 01:46:48
!= NULL?
| |
| 1037 } | 1120 } |
| 1038 | 1121 |
| 1039 bool PepperPluginDelegateImpl::OpenFileSystem( | 1122 bool PepperPluginDelegateImpl::OpenFileSystem( |
| 1040 const GURL& url, | 1123 const GURL& url, |
| 1041 fileapi::FileSystemType type, | 1124 fileapi::FileSystemType type, |
| 1042 long long size, | 1125 long long size, |
| 1043 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1126 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
| 1044 FileSystemDispatcher* file_system_dispatcher = | 1127 FileSystemDispatcher* file_system_dispatcher = |
| 1045 ChildThread::current()->file_system_dispatcher(); | 1128 ChildThread::current()->file_system_dispatcher(); |
| 1046 return file_system_dispatcher->OpenFileSystem( | 1129 return file_system_dispatcher->OpenFileSystem( |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1492 | 1575 |
| 1493 int PepperPluginDelegateImpl::GetRoutingId() const { | 1576 int PepperPluginDelegateImpl::GetRoutingId() const { |
| 1494 return render_view_->routing_id(); | 1577 return render_view_->routing_id(); |
| 1495 } | 1578 } |
| 1496 | 1579 |
| 1497 void PepperPluginDelegateImpl::PublishInitialPolicy( | 1580 void PepperPluginDelegateImpl::PublishInitialPolicy( |
| 1498 scoped_refptr<webkit::ppapi::PluginInstance> instance, | 1581 scoped_refptr<webkit::ppapi::PluginInstance> instance, |
| 1499 const std::string& policy) { | 1582 const std::string& policy) { |
| 1500 instance->HandlePolicyUpdate(policy); | 1583 instance->HandlePolicyUpdate(policy); |
| 1501 } | 1584 } |
| OLD | NEW |