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 "content/renderer/pepper/pepper_plugin_instance_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bit_cast.h" | 10 #include "base/bit_cast.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 #include "third_party/WebKit/public/web/WebPluginScriptForbiddenScope.h" | 113 #include "third_party/WebKit/public/web/WebPluginScriptForbiddenScope.h" |
114 #include "third_party/WebKit/public/web/WebPrintParams.h" | 114 #include "third_party/WebKit/public/web/WebPrintParams.h" |
115 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h" | 115 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h" |
116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" | 116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" |
117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
118 #include "third_party/WebKit/public/web/WebScriptSource.h" | 118 #include "third_party/WebKit/public/web/WebScriptSource.h" |
119 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 119 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
120 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 120 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
121 #include "third_party/WebKit/public/web/WebView.h" | 121 #include "third_party/WebKit/public/web/WebView.h" |
122 #include "third_party/khronos/GLES2/gl2.h" | 122 #include "third_party/khronos/GLES2/gl2.h" |
123 #include "ui/events/blink/blink_event_util.h" | |
123 #include "ui/gfx/image/image_skia.h" | 124 #include "ui/gfx/image/image_skia.h" |
124 #include "ui/gfx/image/image_skia_rep.h" | 125 #include "ui/gfx/image/image_skia_rep.h" |
125 #include "ui/gfx/range/range.h" | 126 #include "ui/gfx/range/range.h" |
126 #include "url/origin.h" | 127 #include "url/origin.h" |
127 #include "v8/include/v8.h" | 128 #include "v8/include/v8.h" |
128 | 129 |
129 #if defined(OS_CHROMEOS) | 130 #if defined(OS_CHROMEOS) |
130 #include "ui/events/keycodes/keyboard_codes_posix.h" | 131 #include "ui/events/keycodes/keyboard_codes_posix.h" |
131 #endif | 132 #endif |
132 | 133 |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 text_input_caret_bounds_(0, 0, 0, 0), | 526 text_input_caret_bounds_(0, 0, 0, 0), |
526 text_input_caret_set_(false), | 527 text_input_caret_set_(false), |
527 selection_caret_(0), | 528 selection_caret_(0), |
528 selection_anchor_(0), | 529 selection_anchor_(0), |
529 pending_user_gesture_(0.0), | 530 pending_user_gesture_(0.0), |
530 document_loader_(NULL), | 531 document_loader_(NULL), |
531 external_document_load_(false), | 532 external_document_load_(false), |
532 isolate_(v8::Isolate::GetCurrent()), | 533 isolate_(v8::Isolate::GetCurrent()), |
533 is_deleted_(false), | 534 is_deleted_(false), |
534 initialized_(false), | 535 initialized_(false), |
536 viewport_to_dip_scale_(1.f), | |
535 view_change_weak_ptr_factory_(this), | 537 view_change_weak_ptr_factory_(this), |
536 weak_factory_(this) { | 538 weak_factory_(this) { |
537 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 539 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
538 | 540 |
539 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 541 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
540 module_->InstanceCreated(this); | 542 module_->InstanceCreated(this); |
541 | 543 |
542 if (render_frame) { // NULL in tests | 544 if (render_frame) { // NULL in tests |
543 render_frame->render_view()->PepperInstanceCreated(this); | 545 render_frame->render_view()->PepperInstanceCreated(this); |
544 // Bind a callback now so that we can inform the RenderViewImpl when we are | 546 // Bind a callback now so that we can inform the RenderViewImpl when we are |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 : offsets[1]); | 1073 : offsets[1]); |
1072 } | 1074 } |
1073 | 1075 |
1074 bool PepperPluginInstanceImpl::IsPluginAcceptingCompositionEvents() const { | 1076 bool PepperPluginInstanceImpl::IsPluginAcceptingCompositionEvents() const { |
1075 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || | 1077 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || |
1076 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); | 1078 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); |
1077 } | 1079 } |
1078 | 1080 |
1079 gfx::Rect PepperPluginInstanceImpl::GetCaretBounds() const { | 1081 gfx::Rect PepperPluginInstanceImpl::GetCaretBounds() const { |
1080 if (!text_input_caret_set_) { | 1082 if (!text_input_caret_set_) { |
1083 gfx::Rect rect(view_data_.rect.point.x, | |
1084 view_data_.rect.point.y + view_data_.rect.size.height, | |
1085 0, 0); | |
1081 // If it is never set by the plugin, use the bottom left corner. | 1086 // If it is never set by the plugin, use the bottom left corner. |
bbudge
2016/01/21 00:34:51
Comment seems misplaced. Should it be before setti
oshima
2016/01/21 01:12:07
Done. I also removed else (I was going to fix it b
| |
1082 return gfx::Rect(view_data_.rect.point.x, | 1087 ConvertDIPToViewport(&rect); |
1083 view_data_.rect.point.y + view_data_.rect.size.height, | 1088 return rect; |
1084 0, | 1089 } else { |
1085 0); | 1090 // TODO(kinaba) Take CSS transformation into accont. |
bbudge
2016/01/21 00:34:51
sp. account
oshima
2016/01/21 01:12:07
Done.
| |
1091 // TODO(kinaba) Take bounding_box into account. On some platforms, an | |
bbudge
2016/01/21 00:34:51
It's not clear to me what 'bounding_box' is referr
oshima
2016/01/21 01:12:07
I believe kinaba@ meant |text_input_caret_bounds_|
| |
1092 // "exclude rectangle" where candidate window must avoid the region can be | |
1093 // passed to IME. Currently, we pass only the caret rectangle because | |
1094 // it is the only information supported uniformly in Chromium. | |
1095 gfx::Rect caret(text_input_caret_); | |
1096 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | |
1097 ConvertDIPToViewport(&caret); | |
1098 return caret; | |
1086 } | 1099 } |
1087 | |
1088 // TODO(kinaba) Take CSS transformation into accont. | |
1089 // TODO(kinaba) Take bounding_box into account. On some platforms, an | |
1090 // "exclude rectangle" where candidate window must avoid the region can be | |
1091 // passed to IME. Currently, we pass only the caret rectangle because | |
1092 // it is the only information supported uniformly in Chromium. | |
1093 gfx::Rect caret(text_input_caret_); | |
1094 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | |
1095 return caret; | |
1096 } | 1100 } |
1097 | 1101 |
1098 bool PepperPluginInstanceImpl::HandleInputEvent( | 1102 bool PepperPluginInstanceImpl::HandleInputEvent( |
1099 const blink::WebInputEvent& event, | 1103 const blink::WebInputEvent& event, |
1100 WebCursorInfo* cursor_info) { | 1104 WebCursorInfo* cursor_info) { |
1101 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1105 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
1102 | 1106 |
1103 if (!has_been_clicked_ && is_flash_plugin_ && | 1107 if (!has_been_clicked_ && is_flash_plugin_ && |
1104 event.type == blink::WebInputEvent::MouseDown && | 1108 event.type == blink::WebInputEvent::MouseDown && |
1105 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) { | 1109 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) { |
1106 has_been_clicked_ = true; | 1110 has_been_clicked_ = true; |
1107 blink::WebRect bounds = container()->element().boundsInViewport(); | 1111 blink::WebRect bounds = container()->element().boundsInViewport(); |
1112 render_frame()->GetRenderWidget()->convertViewportToWindow(&bounds); | |
1108 RecordFlashClickSizeMetric(bounds.width, bounds.height); | 1113 RecordFlashClickSizeMetric(bounds.width, bounds.height); |
1109 } | 1114 } |
1110 | 1115 |
1111 if (throttler_ && throttler_->ConsumeInputEvent(event)) | 1116 if (throttler_ && throttler_->ConsumeInputEvent(event)) |
1112 return true; | 1117 return true; |
1113 | 1118 |
1114 if (!render_frame_) | 1119 if (!render_frame_) |
1115 return false; | 1120 return false; |
1116 if (WebInputEvent::isMouseEventType(event.type)) { | 1121 if (WebInputEvent::isMouseEventType(event.type)) { |
1117 render_frame_->PepperDidReceiveMouseEvent(this); | 1122 render_frame_->PepperDidReceiveMouseEvent(this); |
(...skipping 13 matching lines...) Expand all Loading... | |
1131 bool rv = false; | 1136 bool rv = false; |
1132 if (LoadInputEventInterface()) { | 1137 if (LoadInputEventInterface()) { |
1133 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); | 1138 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); |
1134 if (!event_class) | 1139 if (!event_class) |
1135 return false; | 1140 return false; |
1136 | 1141 |
1137 if ((filtered_input_event_mask_ & event_class) || | 1142 if ((filtered_input_event_mask_ & event_class) || |
1138 (input_event_mask_ & event_class)) { | 1143 (input_event_mask_ & event_class)) { |
1139 // Actually send the event. | 1144 // Actually send the event. |
1140 std::vector<ppapi::InputEventData> events; | 1145 std::vector<ppapi::InputEventData> events; |
1141 CreateInputEventData(event, &events); | 1146 scoped_ptr<const WebInputEvent> event_in_dip( |
1147 ui::ScaleWebInputEvent(event, viewport_to_dip_scale_)); | |
1148 if (event_in_dip) | |
1149 CreateInputEventData(*event_in_dip.get(), &events); | |
1150 else | |
1151 CreateInputEventData(event, &events); | |
1142 | 1152 |
1143 // Allow the user gesture to be pending after the plugin handles the | 1153 // Allow the user gesture to be pending after the plugin handles the |
1144 // event. This allows out-of-process plugins to respond to the user | 1154 // event. This allows out-of-process plugins to respond to the user |
1145 // gesture after processing has finished here. | 1155 // gesture after processing has finished here. |
1146 if (WebUserGestureIndicator::isProcessingUserGesture()) { | 1156 if (WebUserGestureIndicator::isProcessingUserGesture()) { |
1147 pending_user_gesture_ = | 1157 pending_user_gesture_ = |
1148 ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); | 1158 ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); |
1149 pending_user_gesture_token_ = | 1159 pending_user_gesture_token_ = |
1150 WebUserGestureIndicator::currentUserGestureToken(); | 1160 WebUserGestureIndicator::currentUserGestureToken(); |
1151 pending_user_gesture_token_.setOutOfProcess(); | 1161 pending_user_gesture_token_.setOutOfProcess(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1249 unobscured_rect_ = unobscured; | 1259 unobscured_rect_ = unobscured; |
1250 | 1260 |
1251 cut_outs_rects_ = cut_outs_rects; | 1261 cut_outs_rects_ = cut_outs_rects; |
1252 | 1262 |
1253 view_data_.rect = PP_FromGfxRect(window); | 1263 view_data_.rect = PP_FromGfxRect(window); |
1254 view_data_.clip_rect = PP_FromGfxRect(clip); | 1264 view_data_.clip_rect = PP_FromGfxRect(clip); |
1255 view_data_.device_scale = container_->deviceScaleFactor(); | 1265 view_data_.device_scale = container_->deviceScaleFactor(); |
1256 view_data_.css_scale = | 1266 view_data_.css_scale = |
1257 container_->pageZoomFactor() * container_->pageScaleFactor(); | 1267 container_->pageZoomFactor() * container_->pageScaleFactor(); |
1258 | 1268 |
1269 float windowToViewportScale = | |
1270 render_frame()->GetRenderWidget()->convertWindowToViewport(1.0f); | |
bbudge
2016/01/21 00:34:51
nit: Mixing 1.0f and 1.f.
1.0f seems more consist
oshima
2016/01/21 01:12:07
Done
| |
1271 viewport_to_dip_scale_ = 1.f / windowToViewportScale; | |
1272 ConvertRectToDIP(&view_data_.rect); | |
1273 ConvertRectToDIP(&view_data_.clip_rect); | |
1274 view_data_.css_scale *= viewport_to_dip_scale_; | |
1275 view_data_.device_scale /= viewport_to_dip_scale_; | |
1276 | |
1259 gfx::Size scroll_offset = | 1277 gfx::Size scroll_offset = |
1260 container_->element().document().frame()->scrollOffset(); | 1278 container_->element().document().frame()->scrollOffset(); |
1261 view_data_.scroll_offset = PP_MakePoint(scroll_offset.width(), | 1279 view_data_.scroll_offset = PP_MakePoint(scroll_offset.width(), |
1262 scroll_offset.height()); | 1280 scroll_offset.height()); |
1263 | 1281 |
1264 if (desired_fullscreen_state_ || view_data_.is_fullscreen) { | 1282 if (desired_fullscreen_state_ || view_data_.is_fullscreen) { |
1265 WebElement element = container_->element(); | 1283 WebElement element = container_->element(); |
1266 WebDocument document = element.document(); | 1284 WebDocument document = element.document(); |
1267 bool is_fullscreen_element = (element == document.fullScreenElement()); | 1285 bool is_fullscreen_element = (element == document.fullScreenElement()); |
1268 if (!view_data_.is_fullscreen && desired_fullscreen_state_ && | 1286 if (!view_data_.is_fullscreen && desired_fullscreen_state_ && |
(...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3292 } | 3310 } |
3293 | 3311 |
3294 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { | 3312 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { |
3295 if (initialized_ && !javascript_used_ && is_flash_plugin_) { | 3313 if (initialized_ && !javascript_used_ && is_flash_plugin_) { |
3296 javascript_used_ = true; | 3314 javascript_used_ = true; |
3297 RenderThread::Get()->RecordAction( | 3315 RenderThread::Get()->RecordAction( |
3298 base::UserMetricsAction("Flash.JavaScriptUsed")); | 3316 base::UserMetricsAction("Flash.JavaScriptUsed")); |
3299 } | 3317 } |
3300 } | 3318 } |
3301 | 3319 |
3320 void PepperPluginInstanceImpl::ConvertRectToDIP(PP_Rect* rect) const { | |
3321 rect->point.x *= viewport_to_dip_scale_; | |
3322 rect->point.y *= viewport_to_dip_scale_; | |
3323 rect->size.width *= viewport_to_dip_scale_; | |
3324 rect->size.height *= viewport_to_dip_scale_; | |
3325 } | |
3326 | |
3327 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { | |
3328 rect->set_x(rect->x() / viewport_to_dip_scale_); | |
3329 rect->set_y(rect->y() / viewport_to_dip_scale_); | |
3330 rect->set_width(rect->width() / viewport_to_dip_scale_); | |
3331 rect->set_height(rect->height() / viewport_to_dip_scale_); | |
3332 } | |
3333 | |
3302 } // namespace content | 3334 } // namespace content |
OLD | NEW |