| 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/utf_offset_string_conversions.h" | 13 #include "base/utf_offset_string_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "ppapi/c/dev/ppb_find_dev.h" | 15 #include "ppapi/c/dev/ppb_find_dev.h" |
| 16 #include "ppapi/c/dev/ppb_gamepad_dev.h" | 16 #include "ppapi/c/dev/ppb_gamepad_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/ppp_input_event.h" | 25 #include "ppapi/c/ppp_input_event.h" |
| 25 #include "ppapi/c/ppp_instance.h" | 26 #include "ppapi/c/ppp_instance.h" |
| 26 #include "ppapi/c/ppp_messaging.h" | 27 #include "ppapi/c/ppp_messaging.h" |
| 27 #include "ppapi/c/ppp_mouse_lock.h" | 28 #include "ppapi/c/ppp_mouse_lock.h" |
| 28 #include "ppapi/c/private/ppp_instance_private.h" | 29 #include "ppapi/c/private/ppp_instance_private.h" |
| 29 #include "ppapi/shared_impl/ppb_input_event_shared.h" | 30 #include "ppapi/shared_impl/ppb_input_event_shared.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 48 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" | 49 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" |
| 49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 52 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 53 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 53 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 54 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 54 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 55 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
| 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 57 #include "ui/base/range/range.h" |
| 56 #include "webkit/plugins/ppapi/common.h" | 58 #include "webkit/plugins/ppapi/common.h" |
| 57 #include "webkit/plugins/ppapi/event_conversion.h" | 59 #include "webkit/plugins/ppapi/event_conversion.h" |
| 58 #include "webkit/plugins/ppapi/fullscreen_container.h" | 60 #include "webkit/plugins/ppapi/fullscreen_container.h" |
| 59 #include "webkit/plugins/ppapi/gfx_conversion.h" | 61 #include "webkit/plugins/ppapi/gfx_conversion.h" |
| 60 #include "webkit/plugins/ppapi/host_globals.h" | 62 #include "webkit/plugins/ppapi/host_globals.h" |
| 61 #include "webkit/plugins/ppapi/message_channel.h" | 63 #include "webkit/plugins/ppapi/message_channel.h" |
| 62 #include "webkit/plugins/ppapi/npapi_glue.h" | 64 #include "webkit/plugins/ppapi/npapi_glue.h" |
| 63 #include "webkit/plugins/ppapi/plugin_module.h" | 65 #include "webkit/plugins/ppapi/plugin_module.h" |
| 64 #include "webkit/plugins/ppapi/plugin_object.h" | 66 #include "webkit/plugins/ppapi/plugin_object.h" |
| 65 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 67 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 147 |
| 146 namespace { | 148 namespace { |
| 147 | 149 |
| 148 // The default text input type is to regard the plugin always accept text input. | 150 // The default text input type is to regard the plugin always accept text input. |
| 149 // This is for allowing users to use input methods even on completely-IME- | 151 // This is for allowing users to use input methods even on completely-IME- |
| 150 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16). | 152 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16). |
| 151 // Plugins need to explicitly opt out the text input mode if they know | 153 // Plugins need to explicitly opt out the text input mode if they know |
| 152 // that they don't accept texts. | 154 // that they don't accept texts. |
| 153 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT; | 155 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT; |
| 154 | 156 |
| 157 // The length of text to request as a surrounding context of selection. |
| 158 // For now, the value is copied from the one with render_view_impl.cc. |
| 159 // TODO(kinaba) implement a way to dynamically sync the requirement. |
| 160 static const size_t kExtraCharsBeforeAndAfterSelection = 100; |
| 161 |
| 155 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ | 162 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ |
| 156 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ | 163 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ |
| 157 == static_cast<int>(np_name), \ | 164 == static_cast<int>(np_name), \ |
| 158 mismatching_enums) | 165 mismatching_enums) |
| 159 | 166 |
| 160 // <embed>/<object> attributes. | 167 // <embed>/<object> attributes. |
| 161 const char kWidth[] = "width"; | 168 const char kWidth[] = "width"; |
| 162 const char kHeight[] = "height"; | 169 const char kHeight[] = "height"; |
| 163 const char kBorder[] = "border"; // According to w3c, deprecated. | 170 const char kBorder[] = "border"; // According to w3c, deprecated. |
| 164 const char kStyle[] = "style"; | 171 const char kStyle[] = "style"; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 has_webkit_focus_(false), | 283 has_webkit_focus_(false), |
| 277 has_content_area_focus_(false), | 284 has_content_area_focus_(false), |
| 278 find_identifier_(-1), | 285 find_identifier_(-1), |
| 279 plugin_find_interface_(NULL), | 286 plugin_find_interface_(NULL), |
| 280 plugin_messaging_interface_(NULL), | 287 plugin_messaging_interface_(NULL), |
| 281 plugin_mouse_lock_interface_(NULL), | 288 plugin_mouse_lock_interface_(NULL), |
| 282 plugin_input_event_interface_(NULL), | 289 plugin_input_event_interface_(NULL), |
| 283 plugin_private_interface_(NULL), | 290 plugin_private_interface_(NULL), |
| 284 plugin_pdf_interface_(NULL), | 291 plugin_pdf_interface_(NULL), |
| 285 plugin_selection_interface_(NULL), | 292 plugin_selection_interface_(NULL), |
| 293 plugin_textinput_interface_(NULL), |
| 286 plugin_zoom_interface_(NULL), | 294 plugin_zoom_interface_(NULL), |
| 287 checked_for_plugin_input_event_interface_(false), | 295 checked_for_plugin_input_event_interface_(false), |
| 288 checked_for_plugin_messaging_interface_(false), | 296 checked_for_plugin_messaging_interface_(false), |
| 289 plugin_print_interface_(NULL), | 297 plugin_print_interface_(NULL), |
| 290 plugin_graphics_3d_interface_(NULL), | 298 plugin_graphics_3d_interface_(NULL), |
| 291 always_on_top_(false), | 299 always_on_top_(false), |
| 292 fullscreen_container_(NULL), | 300 fullscreen_container_(NULL), |
| 293 flash_fullscreen_(false), | 301 flash_fullscreen_(false), |
| 294 desired_fullscreen_state_(false), | 302 desired_fullscreen_state_(false), |
| 295 message_channel_(NULL), | 303 message_channel_(NULL), |
| 296 sad_plugin_(NULL), | 304 sad_plugin_(NULL), |
| 297 input_event_mask_(0), | 305 input_event_mask_(0), |
| 298 filtered_input_event_mask_(0), | 306 filtered_input_event_mask_(0), |
| 299 text_input_type_(kPluginDefaultTextInputType), | 307 text_input_type_(kPluginDefaultTextInputType), |
| 300 text_input_caret_(0, 0, 0, 0), | 308 text_input_caret_(0, 0, 0, 0), |
| 301 text_input_caret_bounds_(0, 0, 0, 0), | 309 text_input_caret_bounds_(0, 0, 0, 0), |
| 302 text_input_caret_set_(false), | 310 text_input_caret_set_(false), |
| 311 selection_caret_(0), |
| 312 selection_anchor_(0), |
| 303 lock_mouse_callback_(PP_BlockUntilComplete()) { | 313 lock_mouse_callback_(PP_BlockUntilComplete()) { |
| 304 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 314 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
| 305 | 315 |
| 306 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 316 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 307 DCHECK(delegate); | 317 DCHECK(delegate); |
| 308 module_->InstanceCreated(this); | 318 module_->InstanceCreated(this); |
| 309 delegate_->InstanceCreated(this); | 319 delegate_->InstanceCreated(this); |
| 310 message_channel_.reset(new MessageChannel(this)); | 320 message_channel_.reset(new MessageChannel(this)); |
| 311 | 321 |
| 312 view_data_.is_page_visible = delegate->IsPageVisible(); | 322 view_data_.is_page_visible = delegate->IsPageVisible(); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 text_input_caret_bounds_ = bounding_box; | 635 text_input_caret_bounds_ = bounding_box; |
| 626 text_input_caret_set_ = true; | 636 text_input_caret_set_ = true; |
| 627 delegate()->PluginCaretPositionChanged(this); | 637 delegate()->PluginCaretPositionChanged(this); |
| 628 } | 638 } |
| 629 | 639 |
| 630 void PluginInstance::SetTextInputType(ui::TextInputType type) { | 640 void PluginInstance::SetTextInputType(ui::TextInputType type) { |
| 631 text_input_type_ = type; | 641 text_input_type_ = type; |
| 632 delegate()->PluginTextInputTypeChanged(this); | 642 delegate()->PluginTextInputTypeChanged(this); |
| 633 } | 643 } |
| 634 | 644 |
| 645 void PluginInstance::SelectionChanged() { |
| 646 // TODO(kinaba): currently the browser always calls RequestSurroundingText. |
| 647 // It can be optimized so that it won't call it back until the information |
| 648 // is really needed. |
| 649 RequestSurroundingText(kExtraCharsBeforeAndAfterSelection); |
| 650 } |
| 651 |
| 652 void PluginInstance::UpdateSurroundingText(const std::string& text, |
| 653 size_t caret, size_t anchor) { |
| 654 surrounding_text_ = text; |
| 655 selection_caret_ = caret; |
| 656 selection_anchor_ = anchor; |
| 657 delegate()->PluginSelectionChanged(this); |
| 658 } |
| 659 |
| 660 void PluginInstance::GetSurroundingText(string16* text, |
| 661 ui::Range* range) const { |
| 662 std::vector<size_t> offsets; |
| 663 offsets.push_back(selection_anchor_); |
| 664 offsets.push_back(selection_caret_); |
| 665 *text = UTF8ToUTF16AndAdjustOffsets(surrounding_text_, &offsets); |
| 666 range->set_start(offsets[0] == string16::npos ? text->size() : offsets[0]); |
| 667 range->set_end(offsets[1] == string16::npos ? text->size() : offsets[1]); |
| 668 } |
| 669 |
| 635 bool PluginInstance::IsPluginAcceptingCompositionEvents() const { | 670 bool PluginInstance::IsPluginAcceptingCompositionEvents() const { |
| 636 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || | 671 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || |
| 637 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); | 672 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); |
| 638 } | 673 } |
| 639 | 674 |
| 640 gfx::Rect PluginInstance::GetCaretBounds() const { | 675 gfx::Rect PluginInstance::GetCaretBounds() const { |
| 641 if (!text_input_caret_set_) { | 676 if (!text_input_caret_set_) { |
| 642 // If it is never set by the plugin, use the bottom left corner. | 677 // If it is never set by the plugin, use the bottom left corner. |
| 643 return gfx::Rect(view_data_.rect.point.x, | 678 return gfx::Rect(view_data_.rect.point.x, |
| 644 view_data_.rect.point.y + view_data_.rect.size.height, | 679 view_data_.rect.point.y + view_data_.rect.size.height, |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); | 919 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); |
| 885 StringVar* string = StringVar::FromPPVar(rv); | 920 StringVar* string = StringVar::FromPPVar(rv); |
| 886 string16 link; | 921 string16 link; |
| 887 if (string) | 922 if (string) |
| 888 link = UTF8ToUTF16(string->value()); | 923 link = UTF8ToUTF16(string->value()); |
| 889 // Release the ref the plugin transfered to us. | 924 // Release the ref the plugin transfered to us. |
| 890 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); | 925 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); |
| 891 return link; | 926 return link; |
| 892 } | 927 } |
| 893 | 928 |
| 929 bool PluginInstance::RequestSurroundingText( |
| 930 size_t desired_number_of_characters) { |
| 931 // Keep a reference on the stack. See NOTE above. |
| 932 scoped_refptr<PluginInstance> ref(this); |
| 933 if (!LoadTextInputInterface()) |
| 934 return false; |
| 935 plugin_textinput_interface_->RequestSurroundingText( |
| 936 pp_instance(), desired_number_of_characters); |
| 937 return true; |
| 938 } |
| 939 |
| 894 void PluginInstance::Zoom(double factor, bool text_only) { | 940 void PluginInstance::Zoom(double factor, bool text_only) { |
| 895 // Keep a reference on the stack. See NOTE above. | 941 // Keep a reference on the stack. See NOTE above. |
| 896 scoped_refptr<PluginInstance> ref(this); | 942 scoped_refptr<PluginInstance> ref(this); |
| 897 if (!LoadZoomInterface()) | 943 if (!LoadZoomInterface()) |
| 898 return; | 944 return; |
| 899 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); | 945 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); |
| 900 } | 946 } |
| 901 | 947 |
| 902 bool PluginInstance::StartFind(const string16& search_text, | 948 bool PluginInstance::StartFind(const string16& search_text, |
| 903 bool case_sensitive, | 949 bool case_sensitive, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 | 1046 |
| 1001 bool PluginInstance::LoadSelectionInterface() { | 1047 bool PluginInstance::LoadSelectionInterface() { |
| 1002 if (!plugin_selection_interface_) { | 1048 if (!plugin_selection_interface_) { |
| 1003 plugin_selection_interface_ = | 1049 plugin_selection_interface_ = |
| 1004 static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( | 1050 static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( |
| 1005 PPP_SELECTION_DEV_INTERFACE)); | 1051 PPP_SELECTION_DEV_INTERFACE)); |
| 1006 } | 1052 } |
| 1007 return !!plugin_selection_interface_; | 1053 return !!plugin_selection_interface_; |
| 1008 } | 1054 } |
| 1009 | 1055 |
| 1056 bool PluginInstance::LoadTextInputInterface() { |
| 1057 if (!plugin_textinput_interface_) { |
| 1058 plugin_textinput_interface_ = |
| 1059 static_cast<const PPP_TextInput_Dev*>(module_->GetPluginInterface( |
| 1060 PPP_TEXTINPUT_DEV_INTERFACE)); |
| 1061 } |
| 1062 |
| 1063 return !!plugin_textinput_interface_; |
| 1064 } |
| 1065 |
| 1010 bool PluginInstance::LoadZoomInterface() { | 1066 bool PluginInstance::LoadZoomInterface() { |
| 1011 if (!plugin_zoom_interface_) { | 1067 if (!plugin_zoom_interface_) { |
| 1012 plugin_zoom_interface_ = | 1068 plugin_zoom_interface_ = |
| 1013 static_cast<const PPP_Zoom_Dev*>(module_->GetPluginInterface( | 1069 static_cast<const PPP_Zoom_Dev*>(module_->GetPluginInterface( |
| 1014 PPP_ZOOM_DEV_INTERFACE)); | 1070 PPP_ZOOM_DEV_INTERFACE)); |
| 1015 } | 1071 } |
| 1016 | 1072 |
| 1017 return !!plugin_zoom_interface_; | 1073 return !!plugin_zoom_interface_; |
| 1018 } | 1074 } |
| 1019 | 1075 |
| (...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 screen_size_for_fullscreen_ = gfx::Size(); | 2136 screen_size_for_fullscreen_ = gfx::Size(); |
| 2081 WebElement element = container_->element(); | 2137 WebElement element = container_->element(); |
| 2082 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2138 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2083 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2139 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2084 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2140 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2085 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2141 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2086 } | 2142 } |
| 2087 | 2143 |
| 2088 } // namespace ppapi | 2144 } // namespace ppapi |
| 2089 } // namespace webkit | 2145 } // namespace webkit |
| OLD | NEW |