| 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/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 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { | 596 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { |
| 597 if (!document_loader_) | 597 if (!document_loader_) |
| 598 document_loader_ = loader; | 598 document_loader_ = loader; |
| 599 DCHECK(loader == document_loader_.get()); | 599 DCHECK(loader == document_loader_.get()); |
| 600 | 600 |
| 601 return PP_ToBool(instance_interface_->HandleDocumentLoad( | 601 return PP_ToBool(instance_interface_->HandleDocumentLoad( |
| 602 pp_instance(), loader->pp_resource())); | 602 pp_instance(), loader->pp_resource())); |
| 603 } | 603 } |
| 604 | 604 |
| 605 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type, | 605 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type, |
| 606 const string16& text) { | 606 const base::string16& text) { |
| 607 std::vector<WebKit::WebCompositionUnderline> empty; | 607 std::vector<WebKit::WebCompositionUnderline> empty; |
| 608 return SendCompositionEventWithUnderlineInformationToPlugin( | 608 return SendCompositionEventWithUnderlineInformationToPlugin( |
| 609 type, text, empty, static_cast<int>(text.size()), | 609 type, text, empty, static_cast<int>(text.size()), |
| 610 static_cast<int>(text.size())); | 610 static_cast<int>(text.size())); |
| 611 } | 611 } |
| 612 | 612 |
| 613 bool PluginInstance::SendCompositionEventWithUnderlineInformationToPlugin( | 613 bool PluginInstance::SendCompositionEventWithUnderlineInformationToPlugin( |
| 614 PP_InputEvent_Type type, | 614 PP_InputEvent_Type type, |
| 615 const string16& text, | 615 const base::string16& text, |
| 616 const std::vector<WebKit::WebCompositionUnderline>& underlines, | 616 const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 617 int selection_start, | 617 int selection_start, |
| 618 int selection_end) { | 618 int selection_end) { |
| 619 // Keep a reference on the stack. See NOTE above. | 619 // Keep a reference on the stack. See NOTE above. |
| 620 scoped_refptr<PluginInstance> ref(this); | 620 scoped_refptr<PluginInstance> ref(this); |
| 621 | 621 |
| 622 if (!LoadInputEventInterface()) | 622 if (!LoadInputEventInterface()) |
| 623 return false; | 623 return false; |
| 624 | 624 |
| 625 PP_InputEvent_Class event_class = PP_INPUTEVENT_CLASS_IME; | 625 PP_InputEvent_Class event_class = PP_INPUTEVENT_CLASS_IME; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 return handled; | 686 return handled; |
| 687 } | 687 } |
| 688 | 688 |
| 689 void PluginInstance::RequestInputEventsHelper(uint32_t event_classes) { | 689 void PluginInstance::RequestInputEventsHelper(uint32_t event_classes) { |
| 690 if (event_classes & PP_INPUTEVENT_CLASS_TOUCH) | 690 if (event_classes & PP_INPUTEVENT_CLASS_TOUCH) |
| 691 UpdateTouchEventRequest(); | 691 UpdateTouchEventRequest(); |
| 692 if (event_classes & PP_INPUTEVENT_CLASS_WHEEL) | 692 if (event_classes & PP_INPUTEVENT_CLASS_WHEEL) |
| 693 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | 693 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); |
| 694 } | 694 } |
| 695 | 695 |
| 696 bool PluginInstance::HandleCompositionStart(const string16& text) { | 696 bool PluginInstance::HandleCompositionStart(const base::string16& text) { |
| 697 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_START, | 697 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_START, |
| 698 text); | 698 text); |
| 699 } | 699 } |
| 700 | 700 |
| 701 bool PluginInstance::HandleCompositionUpdate( | 701 bool PluginInstance::HandleCompositionUpdate( |
| 702 const string16& text, | 702 const base::string16& text, |
| 703 const std::vector<WebKit::WebCompositionUnderline>& underlines, | 703 const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 704 int selection_start, | 704 int selection_start, |
| 705 int selection_end) { | 705 int selection_end) { |
| 706 return SendCompositionEventWithUnderlineInformationToPlugin( | 706 return SendCompositionEventWithUnderlineInformationToPlugin( |
| 707 PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE, | 707 PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE, |
| 708 text, underlines, selection_start, selection_end); | 708 text, underlines, selection_start, selection_end); |
| 709 } | 709 } |
| 710 | 710 |
| 711 bool PluginInstance::HandleCompositionEnd(const string16& text) { | 711 bool PluginInstance::HandleCompositionEnd(const base::string16& text) { |
| 712 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_END, | 712 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_END, |
| 713 text); | 713 text); |
| 714 } | 714 } |
| 715 | 715 |
| 716 bool PluginInstance::HandleTextInput(const string16& text) { | 716 bool PluginInstance::HandleTextInput(const base::string16& text) { |
| 717 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_TEXT, | 717 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_TEXT, |
| 718 text); | 718 text); |
| 719 } | 719 } |
| 720 | 720 |
| 721 void PluginInstance::GetSurroundingText(string16* text, | 721 void PluginInstance::GetSurroundingText(base::string16* text, |
| 722 ui::Range* range) const { | 722 ui::Range* range) const { |
| 723 std::vector<size_t> offsets; | 723 std::vector<size_t> offsets; |
| 724 offsets.push_back(selection_anchor_); | 724 offsets.push_back(selection_anchor_); |
| 725 offsets.push_back(selection_caret_); | 725 offsets.push_back(selection_caret_); |
| 726 *text = base::UTF8ToUTF16AndAdjustOffsets(surrounding_text_, &offsets); | 726 *text = base::UTF8ToUTF16AndAdjustOffsets(surrounding_text_, &offsets); |
| 727 range->set_start(offsets[0] == string16::npos ? text->size() : offsets[0]); | 727 range->set_start(offsets[0] == base::string16::npos ? text->size() |
| 728 range->set_end(offsets[1] == string16::npos ? text->size() : offsets[1]); | 728 : offsets[0]); |
| 729 range->set_end(offsets[1] == base::string16::npos ? text->size() |
| 730 : offsets[1]); |
| 729 } | 731 } |
| 730 | 732 |
| 731 bool PluginInstance::IsPluginAcceptingCompositionEvents() const { | 733 bool PluginInstance::IsPluginAcceptingCompositionEvents() const { |
| 732 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || | 734 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || |
| 733 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); | 735 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); |
| 734 } | 736 } |
| 735 | 737 |
| 736 gfx::Rect PluginInstance::GetCaretBounds() const { | 738 gfx::Rect PluginInstance::GetCaretBounds() const { |
| 737 if (!text_input_caret_set_) { | 739 if (!text_input_caret_set_) { |
| 738 // If it is never set by the plugin, use the bottom left corner. | 740 // If it is never set by the plugin, use the bottom left corner. |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 plugin_backing_store_rect.Offset(plugin_offset); | 989 plugin_backing_store_rect.Offset(plugin_offset); |
| 988 *location = plugin_backing_store_rect; | 990 *location = plugin_backing_store_rect; |
| 989 clip_page.Offset(plugin_offset); | 991 clip_page.Offset(plugin_offset); |
| 990 *clip = clip_page; | 992 *clip = clip_page; |
| 991 // The plugin scale factor is inverted, e.g. for a device scale factor of 2x | 993 // The plugin scale factor is inverted, e.g. for a device scale factor of 2x |
| 992 // the plugin scale factor is 0.5. | 994 // the plugin scale factor is 0.5. |
| 993 *scale_factor = 1.0 / scale; | 995 *scale_factor = 1.0 / scale; |
| 994 return true; | 996 return true; |
| 995 } | 997 } |
| 996 | 998 |
| 997 string16 PluginInstance::GetSelectedText(bool html) { | 999 base::string16 PluginInstance::GetSelectedText(bool html) { |
| 998 // Keep a reference on the stack. See NOTE above. | 1000 // Keep a reference on the stack. See NOTE above. |
| 999 scoped_refptr<PluginInstance> ref(this); | 1001 scoped_refptr<PluginInstance> ref(this); |
| 1000 if (!LoadSelectionInterface()) | 1002 if (!LoadSelectionInterface()) |
| 1001 return string16(); | 1003 return base::string16(); |
| 1002 | 1004 |
| 1003 PP_Var rv = plugin_selection_interface_->GetSelectedText(pp_instance(), | 1005 PP_Var rv = plugin_selection_interface_->GetSelectedText(pp_instance(), |
| 1004 PP_FromBool(html)); | 1006 PP_FromBool(html)); |
| 1005 StringVar* string = StringVar::FromPPVar(rv); | 1007 StringVar* string = StringVar::FromPPVar(rv); |
| 1006 string16 selection; | 1008 base::string16 selection; |
| 1007 if (string) | 1009 if (string) |
| 1008 selection = UTF8ToUTF16(string->value()); | 1010 selection = UTF8ToUTF16(string->value()); |
| 1009 // Release the ref the plugin transfered to us. | 1011 // Release the ref the plugin transfered to us. |
| 1010 HostGlobals::Get()->GetVarTracker()->ReleaseVar(rv); | 1012 HostGlobals::Get()->GetVarTracker()->ReleaseVar(rv); |
| 1011 return selection; | 1013 return selection; |
| 1012 } | 1014 } |
| 1013 | 1015 |
| 1014 string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) { | 1016 base::string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) { |
| 1015 // Keep a reference on the stack. See NOTE above. | 1017 // Keep a reference on the stack. See NOTE above. |
| 1016 scoped_refptr<PluginInstance> ref(this); | 1018 scoped_refptr<PluginInstance> ref(this); |
| 1017 if (!LoadPdfInterface()) | 1019 if (!LoadPdfInterface()) |
| 1018 return string16(); | 1020 return base::string16(); |
| 1019 | 1021 |
| 1020 PP_Point p; | 1022 PP_Point p; |
| 1021 p.x = point.x(); | 1023 p.x = point.x(); |
| 1022 p.y = point.y(); | 1024 p.y = point.y(); |
| 1023 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); | 1025 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); |
| 1024 StringVar* string = StringVar::FromPPVar(rv); | 1026 StringVar* string = StringVar::FromPPVar(rv); |
| 1025 string16 link; | 1027 base::string16 link; |
| 1026 if (string) | 1028 if (string) |
| 1027 link = UTF8ToUTF16(string->value()); | 1029 link = UTF8ToUTF16(string->value()); |
| 1028 // Release the ref the plugin transfered to us. | 1030 // Release the ref the plugin transfered to us. |
| 1029 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); | 1031 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); |
| 1030 return link; | 1032 return link; |
| 1031 } | 1033 } |
| 1032 | 1034 |
| 1033 void PluginInstance::RequestSurroundingText( | 1035 void PluginInstance::RequestSurroundingText( |
| 1034 size_t desired_number_of_characters) { | 1036 size_t desired_number_of_characters) { |
| 1035 // Keep a reference on the stack. See NOTE above. | 1037 // Keep a reference on the stack. See NOTE above. |
| 1036 scoped_refptr<PluginInstance> ref(this); | 1038 scoped_refptr<PluginInstance> ref(this); |
| 1037 if (!LoadTextInputInterface()) | 1039 if (!LoadTextInputInterface()) |
| 1038 return; | 1040 return; |
| 1039 plugin_textinput_interface_->RequestSurroundingText( | 1041 plugin_textinput_interface_->RequestSurroundingText( |
| 1040 pp_instance(), desired_number_of_characters); | 1042 pp_instance(), desired_number_of_characters); |
| 1041 } | 1043 } |
| 1042 | 1044 |
| 1043 void PluginInstance::Zoom(double factor, bool text_only) { | 1045 void PluginInstance::Zoom(double factor, bool text_only) { |
| 1044 // Keep a reference on the stack. See NOTE above. | 1046 // Keep a reference on the stack. See NOTE above. |
| 1045 scoped_refptr<PluginInstance> ref(this); | 1047 scoped_refptr<PluginInstance> ref(this); |
| 1046 if (!LoadZoomInterface()) | 1048 if (!LoadZoomInterface()) |
| 1047 return; | 1049 return; |
| 1048 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); | 1050 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); |
| 1049 } | 1051 } |
| 1050 | 1052 |
| 1051 bool PluginInstance::StartFind(const string16& search_text, | 1053 bool PluginInstance::StartFind(const base::string16& search_text, |
| 1052 bool case_sensitive, | 1054 bool case_sensitive, |
| 1053 int identifier) { | 1055 int identifier) { |
| 1054 // Keep a reference on the stack. See NOTE above. | 1056 // Keep a reference on the stack. See NOTE above. |
| 1055 scoped_refptr<PluginInstance> ref(this); | 1057 scoped_refptr<PluginInstance> ref(this); |
| 1056 if (!LoadFindInterface()) | 1058 if (!LoadFindInterface()) |
| 1057 return false; | 1059 return false; |
| 1058 find_identifier_ = identifier; | 1060 find_identifier_ = identifier; |
| 1059 return PP_ToBool( | 1061 return PP_ToBool( |
| 1060 plugin_find_interface_->StartFind( | 1062 plugin_find_interface_->StartFind( |
| 1061 pp_instance(), | 1063 pp_instance(), |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 | 1831 |
| 1830 void PluginInstance::SimulateImeSetCompositionEvent( | 1832 void PluginInstance::SimulateImeSetCompositionEvent( |
| 1831 const InputEventData& input_event) { | 1833 const InputEventData& input_event) { |
| 1832 std::vector<size_t> offsets; | 1834 std::vector<size_t> offsets; |
| 1833 offsets.push_back(input_event.composition_selection_start); | 1835 offsets.push_back(input_event.composition_selection_start); |
| 1834 offsets.push_back(input_event.composition_selection_end); | 1836 offsets.push_back(input_event.composition_selection_end); |
| 1835 offsets.insert(offsets.end(), | 1837 offsets.insert(offsets.end(), |
| 1836 input_event.composition_segment_offsets.begin(), | 1838 input_event.composition_segment_offsets.begin(), |
| 1837 input_event.composition_segment_offsets.end()); | 1839 input_event.composition_segment_offsets.end()); |
| 1838 | 1840 |
| 1839 string16 utf16_text = | 1841 base::string16 utf16_text = |
| 1840 base::UTF8ToUTF16AndAdjustOffsets(input_event.character_text, &offsets); | 1842 base::UTF8ToUTF16AndAdjustOffsets(input_event.character_text, &offsets); |
| 1841 | 1843 |
| 1842 std::vector<WebKit::WebCompositionUnderline> underlines; | 1844 std::vector<WebKit::WebCompositionUnderline> underlines; |
| 1843 for (size_t i = 2; i + 1 < offsets.size(); ++i) { | 1845 for (size_t i = 2; i + 1 < offsets.size(); ++i) { |
| 1844 WebKit::WebCompositionUnderline underline; | 1846 WebKit::WebCompositionUnderline underline; |
| 1845 underline.startOffset = offsets[i]; | 1847 underline.startOffset = offsets[i]; |
| 1846 underline.endOffset = offsets[i + 1]; | 1848 underline.endOffset = offsets[i + 1]; |
| 1847 if (input_event.composition_target_segment == static_cast<int32_t>(i - 2)) | 1849 if (input_event.composition_target_segment == static_cast<int32_t>(i - 2)) |
| 1848 underline.thick = true; | 1850 underline.thick = true; |
| 1849 underlines.push_back(underline); | 1851 underlines.push_back(underline); |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2506 screen_size_for_fullscreen_ = gfx::Size(); | 2508 screen_size_for_fullscreen_ = gfx::Size(); |
| 2507 WebElement element = container_->element(); | 2509 WebElement element = container_->element(); |
| 2508 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2510 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2509 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2511 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2510 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2512 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2511 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2513 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2512 } | 2514 } |
| 2513 | 2515 |
| 2514 } // namespace ppapi | 2516 } // namespace ppapi |
| 2515 } // namespace webkit | 2517 } // namespace webkit |
| OLD | NEW |