| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #define PEPPER_APIS_ENABLED 1 | 5 #define PEPPER_APIS_ENABLED 1 |
| 6 | 6 |
| 7 #include "chrome/renderer/webplugin_delegate_pepper.h" | 7 #include "chrome/renderer/webplugin_delegate_pepper.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "app/gfx/blit.h" | 12 #include "app/gfx/blit.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
| 17 #include "base/stats_counters.h" | 17 #include "base/stats_counters.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "webkit/api/public/WebInputEvent.h" | 19 #include "webkit/api/public/WebInputEvent.h" |
| 20 #include "webkit/glue/glue_util.h" | 20 #include "webkit/glue/glue_util.h" |
| 21 #include "webkit/glue/pepper/pepper.h" |
| 21 #include "webkit/glue/plugins/plugin_constants_win.h" | 22 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 22 #include "webkit/glue/plugins/plugin_instance.h" | 23 #include "webkit/glue/plugins/plugin_instance.h" |
| 23 #include "webkit/glue/plugins/plugin_lib.h" | 24 #include "webkit/glue/plugins/plugin_lib.h" |
| 24 #include "webkit/glue/plugins/plugin_list.h" | 25 #include "webkit/glue/plugins/plugin_list.h" |
| 25 #include "webkit/glue/plugins/plugin_stream_url.h" | 26 #include "webkit/glue/plugins/plugin_stream_url.h" |
| 26 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
| 27 | 28 |
| 28 using webkit_glue::WebPlugin; | 29 using webkit_glue::WebPlugin; |
| 29 using webkit_glue::WebPluginDelegate; | 30 using webkit_glue::WebPluginDelegate; |
| 30 using webkit_glue::WebPluginResourceClient; | 31 using webkit_glue::WebPluginResourceClient; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 274 |
| 274 void WebPluginDelegatePepper::Print(gfx::NativeDrawingContext context) { | 275 void WebPluginDelegatePepper::Print(gfx::NativeDrawingContext context) { |
| 275 NOTIMPLEMENTED(); | 276 NOTIMPLEMENTED(); |
| 276 } | 277 } |
| 277 | 278 |
| 278 void WebPluginDelegatePepper::InstallMissingPlugin() { | 279 void WebPluginDelegatePepper::InstallMissingPlugin() { |
| 279 NOTIMPLEMENTED(); | 280 NOTIMPLEMENTED(); |
| 280 } | 281 } |
| 281 | 282 |
| 282 void WebPluginDelegatePepper::SetFocus() { | 283 void WebPluginDelegatePepper::SetFocus() { |
| 283 NPEvent npevent; | 284 NPPepperEvent npevent; |
| 284 | 285 |
| 285 npevent.type = NPEventType_Focus; | 286 npevent.type = NPEventType_Focus; |
| 286 npevent.size = sizeof(NPEvent); | 287 npevent.size = sizeof(npevent); |
| 287 // TODO(sehr): what timestamp should this have? | 288 // TODO(sehr): what timestamp should this have? |
| 288 npevent.timeStampSeconds = 0.0; | 289 npevent.timeStampSeconds = 0.0; |
| 289 // Currently this API only supports gaining focus. | 290 // Currently this API only supports gaining focus. |
| 290 npevent.u.focus.value = 1; | 291 npevent.u.focus.value = 1; |
| 291 instance()->NPP_HandleEvent(&npevent); | 292 instance()->NPP_HandleEvent(&npevent); |
| 292 } | 293 } |
| 293 | 294 |
| 294 // Anonymous namespace for functions converting WebInputEvents to NPAPI types. | 295 // Anonymous namespace for functions converting WebInputEvents to NPAPI types. |
| 295 namespace { | 296 namespace { |
| 296 NPEventTypes ConvertEventTypes(WebInputEvent::Type wetype) { | 297 NPEventTypes ConvertEventTypes(WebInputEvent::Type wetype) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 314 case WebInputEvent::KeyUp: | 315 case WebInputEvent::KeyUp: |
| 315 return NPEventType_KeyUp; | 316 return NPEventType_KeyUp; |
| 316 case WebInputEvent::Char: | 317 case WebInputEvent::Char: |
| 317 return NPEventType_Char; | 318 return NPEventType_Char; |
| 318 case WebInputEvent::Undefined: | 319 case WebInputEvent::Undefined: |
| 319 default: | 320 default: |
| 320 return NPEventType_Undefined; | 321 return NPEventType_Undefined; |
| 321 } | 322 } |
| 322 } | 323 } |
| 323 | 324 |
| 324 void BuildKeyEvent(const WebInputEvent* event, NPEvent* npevent) { | 325 void BuildKeyEvent(const WebInputEvent* event, NPPepperEvent* npevent) { |
| 325 const WebKeyboardEvent* key_event = | 326 const WebKeyboardEvent* key_event = |
| 326 reinterpret_cast<const WebKeyboardEvent*>(event); | 327 reinterpret_cast<const WebKeyboardEvent*>(event); |
| 327 npevent->u.key.modifier = key_event->modifiers; | 328 npevent->u.key.modifier = key_event->modifiers; |
| 328 npevent->u.key.normalizedKeyCode = key_event->windowsKeyCode; | 329 npevent->u.key.normalizedKeyCode = key_event->windowsKeyCode; |
| 329 } | 330 } |
| 330 | 331 |
| 331 void BuildCharEvent(const WebInputEvent* event, NPEvent* npevent) { | 332 void BuildCharEvent(const WebInputEvent* event, NPPepperEvent* npevent) { |
| 332 const WebKeyboardEvent* key_event = | 333 const WebKeyboardEvent* key_event = |
| 333 reinterpret_cast<const WebKeyboardEvent*>(event); | 334 reinterpret_cast<const WebKeyboardEvent*>(event); |
| 334 npevent->u.character.modifier = key_event->modifiers; | 335 npevent->u.character.modifier = key_event->modifiers; |
| 335 // For consistency, check that the sizes of the texts agree. | 336 // For consistency, check that the sizes of the texts agree. |
| 336 DCHECK(sizeof(npevent->u.character.text) == sizeof(key_event->text)); | 337 DCHECK(sizeof(npevent->u.character.text) == sizeof(key_event->text)); |
| 337 DCHECK(sizeof(npevent->u.character.unmodifiedText) == | 338 DCHECK(sizeof(npevent->u.character.unmodifiedText) == |
| 338 sizeof(key_event->unmodifiedText)); | 339 sizeof(key_event->unmodifiedText)); |
| 339 for (size_t i = 0; i < WebKeyboardEvent::textLengthCap; ++i) { | 340 for (size_t i = 0; i < WebKeyboardEvent::textLengthCap; ++i) { |
| 340 npevent->u.character.text[i] = key_event->text[i]; | 341 npevent->u.character.text[i] = key_event->text[i]; |
| 341 npevent->u.character.unmodifiedText[i] = key_event->unmodifiedText[i]; | 342 npevent->u.character.unmodifiedText[i] = key_event->unmodifiedText[i]; |
| 342 } | 343 } |
| 343 } | 344 } |
| 344 | 345 |
| 345 void BuildMouseEvent(const WebInputEvent* event, NPEvent* npevent) { | 346 void BuildMouseEvent(const WebInputEvent* event, NPPepperEvent* npevent) { |
| 346 const WebMouseEvent* mouse_event = | 347 const WebMouseEvent* mouse_event = |
| 347 reinterpret_cast<const WebMouseEvent*>(event); | 348 reinterpret_cast<const WebMouseEvent*>(event); |
| 348 npevent->u.mouse.modifier = mouse_event->modifiers; | 349 npevent->u.mouse.modifier = mouse_event->modifiers; |
| 349 npevent->u.mouse.button = mouse_event->button; | 350 npevent->u.mouse.button = mouse_event->button; |
| 350 npevent->u.mouse.x = mouse_event->x; | 351 npevent->u.mouse.x = mouse_event->x; |
| 351 npevent->u.mouse.y = mouse_event->y; | 352 npevent->u.mouse.y = mouse_event->y; |
| 352 npevent->u.mouse.clickCount = mouse_event->clickCount; | 353 npevent->u.mouse.clickCount = mouse_event->clickCount; |
| 353 } | 354 } |
| 354 | 355 |
| 355 void BuildMouseWheelEvent(const WebInputEvent* event, NPEvent* npevent) { | 356 void BuildMouseWheelEvent(const WebInputEvent* event, NPPepperEvent* npevent) { |
| 356 const WebMouseWheelEvent* mouse_wheel_event = | 357 const WebMouseWheelEvent* mouse_wheel_event = |
| 357 reinterpret_cast<const WebMouseWheelEvent*>(event); | 358 reinterpret_cast<const WebMouseWheelEvent*>(event); |
| 358 npevent->u.wheel.modifier = mouse_wheel_event->modifiers; | 359 npevent->u.wheel.modifier = mouse_wheel_event->modifiers; |
| 359 npevent->u.wheel.deltaX = mouse_wheel_event->deltaX; | 360 npevent->u.wheel.deltaX = mouse_wheel_event->deltaX; |
| 360 npevent->u.wheel.deltaY = mouse_wheel_event->deltaY; | 361 npevent->u.wheel.deltaY = mouse_wheel_event->deltaY; |
| 361 npevent->u.wheel.wheelTicksX = mouse_wheel_event->wheelTicksX; | 362 npevent->u.wheel.wheelTicksX = mouse_wheel_event->wheelTicksX; |
| 362 npevent->u.wheel.wheelTicksY = mouse_wheel_event->wheelTicksY; | 363 npevent->u.wheel.wheelTicksY = mouse_wheel_event->wheelTicksY; |
| 363 npevent->u.wheel.scrollByPage = mouse_wheel_event->scrollByPage; | 364 npevent->u.wheel.scrollByPage = mouse_wheel_event->scrollByPage; |
| 364 } | 365 } |
| 365 } // namespace | 366 } // namespace |
| 366 | 367 |
| 367 bool WebPluginDelegatePepper::HandleInputEvent(const WebInputEvent& event, | 368 bool WebPluginDelegatePepper::HandleInputEvent(const WebInputEvent& event, |
| 368 WebCursorInfo* cursor_info) { | 369 WebCursorInfo* cursor_info) { |
| 369 NPEvent npevent; | 370 NPPepperEvent npevent; |
| 370 | 371 |
| 371 npevent.type = ConvertEventTypes(event.type); | 372 npevent.type = ConvertEventTypes(event.type); |
| 372 npevent.size = sizeof(NPEvent); | 373 npevent.size = sizeof(npevent); |
| 373 npevent.timeStampSeconds = event.timeStampSeconds; | 374 npevent.timeStampSeconds = event.timeStampSeconds; |
| 374 switch (npevent.type) { | 375 switch (npevent.type) { |
| 375 case NPEventType_Undefined: | 376 case NPEventType_Undefined: |
| 376 return false; | 377 return false; |
| 377 case NPEventType_MouseDown: | 378 case NPEventType_MouseDown: |
| 378 case NPEventType_MouseUp: | 379 case NPEventType_MouseUp: |
| 379 case NPEventType_MouseMove: | 380 case NPEventType_MouseMove: |
| 380 case NPEventType_MouseEnter: | 381 case NPEventType_MouseEnter: |
| 381 case NPEventType_MouseLeave: | 382 case NPEventType_MouseLeave: |
| 382 BuildMouseEvent(&event, &npevent); | 383 BuildMouseEvent(&event, &npevent); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 NPError WebPluginDelegatePepper::FlushRenderContext(NPRenderContext* context) { | 437 NPError WebPluginDelegatePepper::FlushRenderContext(NPRenderContext* context) { |
| 437 // TODO(brettw): we should have some kind of swapping of the canvases so we | 438 // TODO(brettw): we should have some kind of swapping of the canvases so we |
| 438 // can double buffer while avoiding this deep copy. | 439 // can double buffer while avoiding this deep copy. |
| 439 if (!plugin_canvas_->getTopPlatformDevice().accessBitmap(false).copyTo( | 440 if (!plugin_canvas_->getTopPlatformDevice().accessBitmap(false).copyTo( |
| 440 &committed_bitmap_, SkBitmap::kARGB_8888_Config)) | 441 &committed_bitmap_, SkBitmap::kARGB_8888_Config)) |
| 441 return NPERR_OUT_OF_MEMORY_ERROR; | 442 return NPERR_OUT_OF_MEMORY_ERROR; |
| 442 | 443 |
| 443 committed_bitmap_.setIsOpaque(false); | 444 committed_bitmap_.setIsOpaque(false); |
| 444 return NPERR_NO_ERROR; | 445 return NPERR_NO_ERROR; |
| 445 } | 446 } |
| OLD | NEW |