OLD | NEW |
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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "base/utf_offset_string_conversions.h" | 14 #include "base/utf_offset_string_conversions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "ppapi/c/dev/ppb_find_dev.h" | 16 #include "ppapi/c/dev/ppb_find_dev.h" |
17 #include "ppapi/c/dev/ppb_zoom_dev.h" | 17 #include "ppapi/c/dev/ppb_zoom_dev.h" |
18 #include "ppapi/c/dev/ppp_find_dev.h" | 18 #include "ppapi/c/dev/ppp_find_dev.h" |
19 #include "ppapi/c/dev/ppp_selection_dev.h" | 19 #include "ppapi/c/dev/ppp_selection_dev.h" |
| 20 #include "ppapi/c/dev/ppp_text_input_dev.h" |
20 #include "ppapi/c/dev/ppp_zoom_dev.h" | 21 #include "ppapi/c/dev/ppp_zoom_dev.h" |
21 #include "ppapi/c/pp_rect.h" | 22 #include "ppapi/c/pp_rect.h" |
22 #include "ppapi/c/ppb_audio_config.h" | 23 #include "ppapi/c/ppb_audio_config.h" |
23 #include "ppapi/c/ppb_core.h" | 24 #include "ppapi/c/ppb_core.h" |
24 #include "ppapi/c/ppb_gamepad.h" | 25 #include "ppapi/c/ppb_gamepad.h" |
25 #include "ppapi/c/ppp_input_event.h" | 26 #include "ppapi/c/ppp_input_event.h" |
26 #include "ppapi/c/ppp_instance.h" | 27 #include "ppapi/c/ppp_instance.h" |
27 #include "ppapi/c/ppp_messaging.h" | 28 #include "ppapi/c/ppp_messaging.h" |
28 #include "ppapi/c/ppp_mouse_lock.h" | 29 #include "ppapi/c/ppp_mouse_lock.h" |
29 #include "ppapi/c/private/ppp_instance_private.h" | 30 #include "ppapi/c/private/ppp_instance_private.h" |
(...skipping 18 matching lines...) Expand all Loading... |
48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
49 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" | 50 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" |
50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" | 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" |
53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
54 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 55 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
55 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 56 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
56 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 57 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 59 #include "ui/base/range/range.h" |
58 #include "webkit/plugins/ppapi/common.h" | 60 #include "webkit/plugins/ppapi/common.h" |
59 #include "webkit/plugins/ppapi/event_conversion.h" | 61 #include "webkit/plugins/ppapi/event_conversion.h" |
60 #include "webkit/plugins/ppapi/fullscreen_container.h" | 62 #include "webkit/plugins/ppapi/fullscreen_container.h" |
61 #include "webkit/plugins/ppapi/gfx_conversion.h" | 63 #include "webkit/plugins/ppapi/gfx_conversion.h" |
62 #include "webkit/plugins/ppapi/host_globals.h" | 64 #include "webkit/plugins/ppapi/host_globals.h" |
63 #include "webkit/plugins/ppapi/message_channel.h" | 65 #include "webkit/plugins/ppapi/message_channel.h" |
64 #include "webkit/plugins/ppapi/npapi_glue.h" | 66 #include "webkit/plugins/ppapi/npapi_glue.h" |
65 #include "webkit/plugins/ppapi/plugin_module.h" | 67 #include "webkit/plugins/ppapi/plugin_module.h" |
66 #include "webkit/plugins/ppapi/plugin_object.h" | 68 #include "webkit/plugins/ppapi/plugin_object.h" |
67 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 69 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 150 |
149 namespace { | 151 namespace { |
150 | 152 |
151 // The default text input type is to regard the plugin always accept text input. | 153 // The default text input type is to regard the plugin always accept text input. |
152 // This is for allowing users to use input methods even on completely-IME- | 154 // This is for allowing users to use input methods even on completely-IME- |
153 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16). | 155 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16). |
154 // Plugins need to explicitly opt out the text input mode if they know | 156 // Plugins need to explicitly opt out the text input mode if they know |
155 // that they don't accept texts. | 157 // that they don't accept texts. |
156 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT; | 158 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT; |
157 | 159 |
| 160 // The length of text to request as a surrounding context of selection. |
| 161 // For now, the value is copied from the one with render_view_impl.cc. |
| 162 // TODO(kinaba) implement a way to dynamically sync the requirement. |
| 163 static const size_t kExtraCharsBeforeAndAfterSelection = 100; |
| 164 |
158 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ | 165 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ |
159 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ | 166 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ |
160 == static_cast<int>(np_name), \ | 167 == static_cast<int>(np_name), \ |
161 mismatching_enums) | 168 mismatching_enums) |
162 | 169 |
163 // <embed>/<object> attributes. | 170 // <embed>/<object> attributes. |
164 const char kWidth[] = "width"; | 171 const char kWidth[] = "width"; |
165 const char kHeight[] = "height"; | 172 const char kHeight[] = "height"; |
166 const char kBorder[] = "border"; // According to w3c, deprecated. | 173 const char kBorder[] = "border"; // According to w3c, deprecated. |
167 const char kStyle[] = "style"; | 174 const char kStyle[] = "style"; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 has_webkit_focus_(false), | 286 has_webkit_focus_(false), |
280 has_content_area_focus_(false), | 287 has_content_area_focus_(false), |
281 find_identifier_(-1), | 288 find_identifier_(-1), |
282 plugin_find_interface_(NULL), | 289 plugin_find_interface_(NULL), |
283 plugin_messaging_interface_(NULL), | 290 plugin_messaging_interface_(NULL), |
284 plugin_mouse_lock_interface_(NULL), | 291 plugin_mouse_lock_interface_(NULL), |
285 plugin_input_event_interface_(NULL), | 292 plugin_input_event_interface_(NULL), |
286 plugin_private_interface_(NULL), | 293 plugin_private_interface_(NULL), |
287 plugin_pdf_interface_(NULL), | 294 plugin_pdf_interface_(NULL), |
288 plugin_selection_interface_(NULL), | 295 plugin_selection_interface_(NULL), |
| 296 plugin_textinput_interface_(NULL), |
289 plugin_zoom_interface_(NULL), | 297 plugin_zoom_interface_(NULL), |
290 checked_for_plugin_input_event_interface_(false), | 298 checked_for_plugin_input_event_interface_(false), |
291 checked_for_plugin_messaging_interface_(false), | 299 checked_for_plugin_messaging_interface_(false), |
292 plugin_print_interface_(NULL), | 300 plugin_print_interface_(NULL), |
293 plugin_graphics_3d_interface_(NULL), | 301 plugin_graphics_3d_interface_(NULL), |
294 always_on_top_(false), | 302 always_on_top_(false), |
295 fullscreen_container_(NULL), | 303 fullscreen_container_(NULL), |
296 flash_fullscreen_(false), | 304 flash_fullscreen_(false), |
297 desired_fullscreen_state_(false), | 305 desired_fullscreen_state_(false), |
298 message_channel_(NULL), | 306 message_channel_(NULL), |
299 sad_plugin_(NULL), | 307 sad_plugin_(NULL), |
300 input_event_mask_(0), | 308 input_event_mask_(0), |
301 filtered_input_event_mask_(0), | 309 filtered_input_event_mask_(0), |
302 text_input_type_(kPluginDefaultTextInputType), | 310 text_input_type_(kPluginDefaultTextInputType), |
303 text_input_caret_(0, 0, 0, 0), | 311 text_input_caret_(0, 0, 0, 0), |
304 text_input_caret_bounds_(0, 0, 0, 0), | 312 text_input_caret_bounds_(0, 0, 0, 0), |
305 text_input_caret_set_(false), | 313 text_input_caret_set_(false), |
| 314 selection_caret_(0), |
| 315 selection_anchor_(0), |
306 lock_mouse_callback_(PP_BlockUntilComplete()), | 316 lock_mouse_callback_(PP_BlockUntilComplete()), |
307 pending_user_gesture_(0.0) { | 317 pending_user_gesture_(0.0) { |
308 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 318 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
309 | 319 |
310 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 320 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
311 DCHECK(delegate); | 321 DCHECK(delegate); |
312 module_->InstanceCreated(this); | 322 module_->InstanceCreated(this); |
313 delegate_->InstanceCreated(this); | 323 delegate_->InstanceCreated(this); |
314 message_channel_.reset(new MessageChannel(this)); | 324 message_channel_.reset(new MessageChannel(this)); |
315 | 325 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 text_input_caret_bounds_ = bounding_box; | 639 text_input_caret_bounds_ = bounding_box; |
630 text_input_caret_set_ = true; | 640 text_input_caret_set_ = true; |
631 delegate()->PluginCaretPositionChanged(this); | 641 delegate()->PluginCaretPositionChanged(this); |
632 } | 642 } |
633 | 643 |
634 void PluginInstance::SetTextInputType(ui::TextInputType type) { | 644 void PluginInstance::SetTextInputType(ui::TextInputType type) { |
635 text_input_type_ = type; | 645 text_input_type_ = type; |
636 delegate()->PluginTextInputTypeChanged(this); | 646 delegate()->PluginTextInputTypeChanged(this); |
637 } | 647 } |
638 | 648 |
| 649 void PluginInstance::SelectionChanged() { |
| 650 // TODO(kinaba): currently the browser always calls RequestSurroundingText. |
| 651 // It can be optimized so that it won't call it back until the information |
| 652 // is really needed. |
| 653 RequestSurroundingText(kExtraCharsBeforeAndAfterSelection); |
| 654 } |
| 655 |
| 656 void PluginInstance::UpdateSurroundingText(const std::string& text, |
| 657 size_t caret, size_t anchor) { |
| 658 surrounding_text_ = text; |
| 659 selection_caret_ = caret; |
| 660 selection_anchor_ = anchor; |
| 661 delegate()->PluginSelectionChanged(this); |
| 662 } |
| 663 |
| 664 void PluginInstance::GetSurroundingText(string16* text, |
| 665 ui::Range* range) const { |
| 666 std::vector<size_t> offsets; |
| 667 offsets.push_back(selection_anchor_); |
| 668 offsets.push_back(selection_caret_); |
| 669 *text = UTF8ToUTF16AndAdjustOffsets(surrounding_text_, &offsets); |
| 670 range->set_start(offsets[0] == string16::npos ? text->size() : offsets[0]); |
| 671 range->set_end(offsets[1] == string16::npos ? text->size() : offsets[1]); |
| 672 } |
| 673 |
639 bool PluginInstance::IsPluginAcceptingCompositionEvents() const { | 674 bool PluginInstance::IsPluginAcceptingCompositionEvents() const { |
640 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || | 675 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || |
641 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); | 676 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); |
642 } | 677 } |
643 | 678 |
644 gfx::Rect PluginInstance::GetCaretBounds() const { | 679 gfx::Rect PluginInstance::GetCaretBounds() const { |
645 if (!text_input_caret_set_) { | 680 if (!text_input_caret_set_) { |
646 // If it is never set by the plugin, use the bottom left corner. | 681 // If it is never set by the plugin, use the bottom left corner. |
647 return gfx::Rect(view_data_.rect.point.x, | 682 return gfx::Rect(view_data_.rect.point.x, |
648 view_data_.rect.point.y + view_data_.rect.size.height, | 683 view_data_.rect.point.y + view_data_.rect.size.height, |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); | 932 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); |
898 StringVar* string = StringVar::FromPPVar(rv); | 933 StringVar* string = StringVar::FromPPVar(rv); |
899 string16 link; | 934 string16 link; |
900 if (string) | 935 if (string) |
901 link = UTF8ToUTF16(string->value()); | 936 link = UTF8ToUTF16(string->value()); |
902 // Release the ref the plugin transfered to us. | 937 // Release the ref the plugin transfered to us. |
903 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); | 938 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); |
904 return link; | 939 return link; |
905 } | 940 } |
906 | 941 |
| 942 bool PluginInstance::RequestSurroundingText( |
| 943 size_t desired_number_of_characters) { |
| 944 // Keep a reference on the stack. See NOTE above. |
| 945 scoped_refptr<PluginInstance> ref(this); |
| 946 if (!LoadTextInputInterface()) |
| 947 return false; |
| 948 plugin_textinput_interface_->RequestSurroundingText( |
| 949 pp_instance(), desired_number_of_characters); |
| 950 return true; |
| 951 } |
| 952 |
907 void PluginInstance::Zoom(double factor, bool text_only) { | 953 void PluginInstance::Zoom(double factor, bool text_only) { |
908 // Keep a reference on the stack. See NOTE above. | 954 // Keep a reference on the stack. See NOTE above. |
909 scoped_refptr<PluginInstance> ref(this); | 955 scoped_refptr<PluginInstance> ref(this); |
910 if (!LoadZoomInterface()) | 956 if (!LoadZoomInterface()) |
911 return; | 957 return; |
912 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); | 958 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); |
913 } | 959 } |
914 | 960 |
915 bool PluginInstance::StartFind(const string16& search_text, | 961 bool PluginInstance::StartFind(const string16& search_text, |
916 bool case_sensitive, | 962 bool case_sensitive, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 | 1059 |
1014 bool PluginInstance::LoadSelectionInterface() { | 1060 bool PluginInstance::LoadSelectionInterface() { |
1015 if (!plugin_selection_interface_) { | 1061 if (!plugin_selection_interface_) { |
1016 plugin_selection_interface_ = | 1062 plugin_selection_interface_ = |
1017 static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( | 1063 static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( |
1018 PPP_SELECTION_DEV_INTERFACE)); | 1064 PPP_SELECTION_DEV_INTERFACE)); |
1019 } | 1065 } |
1020 return !!plugin_selection_interface_; | 1066 return !!plugin_selection_interface_; |
1021 } | 1067 } |
1022 | 1068 |
| 1069 bool PluginInstance::LoadTextInputInterface() { |
| 1070 if (!plugin_textinput_interface_) { |
| 1071 plugin_textinput_interface_ = |
| 1072 static_cast<const PPP_TextInput_Dev*>(module_->GetPluginInterface( |
| 1073 PPP_TEXTINPUT_DEV_INTERFACE)); |
| 1074 } |
| 1075 |
| 1076 return !!plugin_textinput_interface_; |
| 1077 } |
| 1078 |
1023 bool PluginInstance::LoadZoomInterface() { | 1079 bool PluginInstance::LoadZoomInterface() { |
1024 if (!plugin_zoom_interface_) { | 1080 if (!plugin_zoom_interface_) { |
1025 plugin_zoom_interface_ = | 1081 plugin_zoom_interface_ = |
1026 static_cast<const PPP_Zoom_Dev*>(module_->GetPluginInterface( | 1082 static_cast<const PPP_Zoom_Dev*>(module_->GetPluginInterface( |
1027 PPP_ZOOM_DEV_INTERFACE)); | 1083 PPP_ZOOM_DEV_INTERFACE)); |
1028 } | 1084 } |
1029 | 1085 |
1030 return !!plugin_zoom_interface_; | 1086 return !!plugin_zoom_interface_; |
1031 } | 1087 } |
1032 | 1088 |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2107 screen_size_for_fullscreen_ = gfx::Size(); | 2163 screen_size_for_fullscreen_ = gfx::Size(); |
2108 WebElement element = container_->element(); | 2164 WebElement element = container_->element(); |
2109 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2165 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2110 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2166 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2111 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2167 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2112 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2168 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2113 } | 2169 } |
2114 | 2170 |
2115 } // namespace ppapi | 2171 } // namespace ppapi |
2116 } // namespace webkit | 2172 } // namespace webkit |
OLD | NEW |