OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // HACK: we need this #define in place before npapi.h is included for | 5 // HACK: we need this #define in place before npapi.h is included for |
6 // plugins to work. However, all sorts of headers include npapi.h, so | 6 // plugins to work. However, all sorts of headers include npapi.h, so |
7 // the only way to be certain the define is in place is to put it | 7 // the only way to be certain the define is in place is to put it |
8 // here. You might ask, "Why not set it in npapi.h directly, or in | 8 // here. You might ask, "Why not set it in npapi.h directly, or in |
9 // this directory's SConscript, then?" but it turns out this define | 9 // this directory's SConscript, then?" but it turns out this define |
10 // makes npapi.h include Xlib.h, which in turn defines a ton of symbols | 10 // makes npapi.h include Xlib.h, which in turn defines a ton of symbols |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (!start_result) | 101 if (!start_result) |
102 return false; | 102 return false; |
103 | 103 |
104 windowless_ = instance_->windowless(); | 104 windowless_ = instance_->windowless(); |
105 if (windowless_) { | 105 if (windowless_) { |
106 // For windowless plugins we should set the containing window handle | 106 // For windowless plugins we should set the containing window handle |
107 // as the instance window handle. This is what Safari does. Not having | 107 // as the instance window handle. This is what Safari does. Not having |
108 // a valid window handle causes subtle bugs with plugins which retreive | 108 // a valid window handle causes subtle bugs with plugins which retreive |
109 // the window handle and validate the same. The window handle can be | 109 // the window handle and validate the same. The window handle can be |
110 // retreived via NPN_GetValue of NPNVnetscapeWindow. | 110 // retreived via NPN_GetValue of NPNVnetscapeWindow. |
111 NOTIMPLEMENTED() << "windowless not implemented"; | |
112 return false; | |
113 // instance_->set_window_handle(parent_); | 111 // instance_->set_window_handle(parent_); |
114 // CreateDummyWindowForActivation(); | 112 // CreateDummyWindowForActivation(); |
115 // handle_event_pump_messages_event_ = CreateEvent(NULL, TRUE, FALSE, NULL); | 113 // handle_event_pump_messages_event_ = CreateEvent(NULL, TRUE, FALSE, NULL); |
116 } else { | 114 } else { |
117 if (!WindowedCreatePlugin()) | 115 if (!WindowedCreatePlugin()) |
118 return false; | 116 return false; |
119 } | 117 } |
120 | 118 |
121 plugin->SetWindow(windowed_handle_, /* unused event param */ NULL); | 119 plugin->SetWindow(windowed_handle_, /* unused event param */ NULL); |
122 plugin_url_ = url.spec(); | 120 plugin_url_ = url.spec(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 const gfx::Rect& clip_rect) { | 152 const gfx::Rect& clip_rect) { |
155 if (windowless_) { | 153 if (windowless_) { |
156 WindowlessUpdateGeometry(window_rect, clip_rect); | 154 WindowlessUpdateGeometry(window_rect, clip_rect); |
157 } else { | 155 } else { |
158 WindowedUpdateGeometry(window_rect, clip_rect); | 156 WindowedUpdateGeometry(window_rect, clip_rect); |
159 } | 157 } |
160 } | 158 } |
161 | 159 |
162 void WebPluginDelegateImpl::Paint(void* dc, const gfx::Rect& rect) { | 160 void WebPluginDelegateImpl::Paint(void* dc, const gfx::Rect& rect) { |
163 if (windowless_) { | 161 if (windowless_) { |
164 // TODO(port): windowless painting. | 162 WindowlessPaint(dc, rect); |
165 // WindowlessPaint(dc, rect); | |
166 } | 163 } |
167 } | 164 } |
168 | 165 |
169 void WebPluginDelegateImpl::Print(void* dc) { | 166 void WebPluginDelegateImpl::Print(void* dc) { |
170 NOTIMPLEMENTED(); | 167 NOTIMPLEMENTED(); |
171 } | 168 } |
172 | 169 |
173 NPObject* WebPluginDelegateImpl::GetPluginScriptableObject() { | 170 NPObject* WebPluginDelegateImpl::GetPluginScriptableObject() { |
174 return instance_->GetPluginScriptableObject(); | 171 return instance_->GetPluginScriptableObject(); |
175 } | 172 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 NPError err = instance()->NPP_SetWindow(&window_); | 401 NPError err = instance()->NPP_SetWindow(&window_); |
405 DCHECK(err == NPERR_NO_ERROR); | 402 DCHECK(err == NPERR_NO_ERROR); |
406 } | 403 } |
407 | 404 |
408 void WebPluginDelegateImpl::WindowlessUpdateGeometry( | 405 void WebPluginDelegateImpl::WindowlessUpdateGeometry( |
409 const gfx::Rect& window_rect, | 406 const gfx::Rect& window_rect, |
410 const gfx::Rect& clip_rect) { | 407 const gfx::Rect& clip_rect) { |
411 // Only resend to the instance if the geometry has changed. | 408 // Only resend to the instance if the geometry has changed. |
412 if (window_rect == window_rect_ && clip_rect == clip_rect_) | 409 if (window_rect == window_rect_ && clip_rect == clip_rect_) |
413 return; | 410 return; |
414 /* | 411 |
415 // Set this flag before entering the instance in case of side-effects. | 412 // Set this flag before entering the instance in case of side-effects. |
416 windowless_needs_set_window_ = true; | 413 windowless_needs_set_window_ = true; |
417 | 414 |
418 // We will inform the instance of this change when we call NPP_SetWindow. | 415 // We will inform the instance of this change when we call NPP_SetWindow. |
419 clip_rect_ = clip_rect; | 416 clip_rect_ = clip_rect; |
420 cutout_rects_.clear(); | 417 cutout_rects_.clear(); |
421 | 418 |
422 if (window_rect_ != window_rect) { | 419 if (window_rect_ != window_rect) { |
423 window_rect_ = window_rect; | 420 window_rect_ = window_rect; |
424 | 421 |
425 WindowlessSetWindow(true); | 422 WindowlessSetWindow(true); |
426 | |
427 WINDOWPOS win_pos = {0}; | |
428 win_pos.x = window_rect_.x(); | |
429 win_pos.y = window_rect_.y(); | |
430 win_pos.cx = window_rect_.width(); | |
431 win_pos.cy = window_rect_.height(); | |
432 | |
433 NPEvent pos_changed_event; | |
434 pos_changed_event.event = WM_WINDOWPOSCHANGED; | |
435 pos_changed_event.wParam = 0; | |
436 pos_changed_event.lParam = PtrToUlong(&win_pos); | |
437 | |
438 instance()->NPP_HandleEvent(&pos_changed_event); | |
439 } | 423 } |
440 */ | |
441 } | 424 } |
442 | 425 |
443 #if 0 | 426 void WebPluginDelegateImpl::WindowlessPaint(void* context, |
444 void WebPluginDelegateImpl::WindowlessPaint(HDC hdc, | |
445 const gfx::Rect& damage_rect) { | 427 const gfx::Rect& damage_rect) { |
446 DCHECK(hdc); | 428 // Compare to: |
| 429 // http://mxr.mozilla.org/firefox/source/layout/generic/nsObjectFrame.cpp#4222 |
447 | 430 |
448 RECT damage_rect_win; | 431 DCHECK(context); |
449 damage_rect_win.left = damage_rect.x(); // + window_rect_.x(); | |
450 damage_rect_win.top = damage_rect.y(); // + window_rect_.y(); | |
451 damage_rect_win.right = damage_rect_win.left + damage_rect.width(); | |
452 damage_rect_win.bottom = damage_rect_win.top + damage_rect.height(); | |
453 | 432 |
454 // We need to pass the HDC to the plugin via NPP_SetWindow in the | 433 // We need to pass the DC to the plugin via NPP_SetWindow in the |
455 // first paint to ensure that it initiates rect invalidations. | 434 // first paint to ensure that it initiates rect invalidations. |
456 if (window_.window == NULL) | 435 // TODO(evanm): for now, it appears we always need to do this. |
| 436 if (true) |
457 windowless_needs_set_window_ = true; | 437 windowless_needs_set_window_ = true; |
458 | 438 |
459 window_.window = hdc; | |
460 // TODO(darin): we should avoid calling NPP_SetWindow here since it may | 439 // TODO(darin): we should avoid calling NPP_SetWindow here since it may |
461 // cause page layout to be invalidated. | 440 // cause page layout to be invalidated. |
462 | 441 |
463 // We really don't need to continually call SetWindow. | 442 // We really don't need to continually call SetWindow. |
464 // m_needsSetWindow flags when the geometry has changed. | 443 // m_needsSetWindow flags when the geometry has changed. |
465 if (windowless_needs_set_window_) | 444 if (windowless_needs_set_window_) |
466 WindowlessSetWindow(false); | 445 WindowlessSetWindow(false); |
467 | 446 |
468 NPEvent paint_event; | 447 XGraphicsExposeEvent event = {0}; |
469 paint_event.event = WM_PAINT; | 448 event.type = GraphicsExpose; |
470 // NOTE: NPAPI is not 64bit safe. It puts pointers into 32bit values. | 449 event.display = GDK_DISPLAY(); |
471 paint_event.wParam = PtrToUlong(hdc); | 450 event.drawable = (Drawable)context; |
472 paint_event.lParam = PtrToUlong(&damage_rect_win); | 451 event.x = damage_rect.x(); |
| 452 event.y = damage_rect.y(); |
| 453 event.width = damage_rect.width(); |
| 454 event.height = damage_rect.height(); |
| 455 |
473 static StatsRate plugin_paint("Plugin.Paint"); | 456 static StatsRate plugin_paint("Plugin.Paint"); |
474 StatsScope<StatsRate> scope(plugin_paint); | 457 StatsScope<StatsRate> scope(plugin_paint); |
475 instance()->NPP_HandleEvent(&paint_event); | 458 NPError err = instance()->NPP_HandleEvent(reinterpret_cast<XEvent*>(&event)); |
| 459 DCHECK(err == NPERR_NO_ERROR); |
476 } | 460 } |
477 #endif | |
478 | 461 |
479 void WebPluginDelegateImpl::WindowlessSetWindow(bool force_set_window) { | 462 void WebPluginDelegateImpl::WindowlessSetWindow(bool force_set_window) { |
480 if (!instance()) | 463 if (!instance()) |
481 return; | 464 return; |
482 | 465 |
483 if (window_rect_.IsEmpty()) // wait for geometry to be set. | 466 if (window_rect_.IsEmpty()) // wait for geometry to be set. |
484 return; | 467 return; |
485 | 468 |
486 DCHECK(instance()->windowless()); | 469 DCHECK(instance()->windowless()); |
| 470 // Mozilla docs say that this window param is not used for windowless |
| 471 // plugins; rather, the window is passed during the GraphicsExpose event. |
| 472 DCHECK(window_.window == 0); |
487 | 473 |
488 window_.clipRect.top = clip_rect_.y(); | 474 window_.clipRect.top = clip_rect_.y(); |
489 window_.clipRect.left = clip_rect_.x(); | 475 window_.clipRect.left = clip_rect_.x(); |
490 window_.clipRect.bottom = clip_rect_.y() + clip_rect_.height(); | 476 window_.clipRect.bottom = clip_rect_.y() + clip_rect_.height(); |
491 window_.clipRect.right = clip_rect_.x() + clip_rect_.width(); | 477 window_.clipRect.right = clip_rect_.x() + clip_rect_.width(); |
492 window_.height = window_rect_.height(); | 478 window_.height = window_rect_.height(); |
493 window_.width = window_rect_.width(); | 479 window_.width = window_rect_.width(); |
494 window_.x = window_rect_.x(); | 480 window_.x = window_rect_.x(); |
495 window_.y = window_rect_.y(); | 481 window_.y = window_rect_.y(); |
496 window_.type = NPWindowTypeDrawable; | 482 window_.type = NPWindowTypeDrawable; |
497 | 483 |
| 484 NPSetWindowCallbackStruct* extra = new NPSetWindowCallbackStruct; |
| 485 extra->display = GDK_DISPLAY(); |
| 486 GdkVisual* visual = gdk_visual_get_system(); |
| 487 extra->visual = GDK_VISUAL_XVISUAL(visual); |
| 488 extra->depth = visual->depth; |
| 489 // XXX we leak the colormap. |
| 490 GdkColormap* colormap = gdk_colormap_new(gdk_visual_get_system(), FALSE); |
| 491 extra->colormap = GDK_COLORMAP_XCOLORMAP(colormap); |
| 492 window_.ws_info = extra; |
| 493 |
| 494 if (!force_set_window) |
| 495 windowless_needs_set_window_ = false; |
| 496 |
498 NPError err = instance()->NPP_SetWindow(&window_); | 497 NPError err = instance()->NPP_SetWindow(&window_); |
499 DCHECK(err == NPERR_NO_ERROR); | 498 DCHECK(err == NPERR_NO_ERROR); |
500 } | 499 } |
501 | 500 |
502 void WebPluginDelegateImpl::SetFocus() { | 501 void WebPluginDelegateImpl::SetFocus() { |
503 DCHECK(instance()->windowless()); | 502 DCHECK(instance()->windowless()); |
504 | 503 |
505 NOTIMPLEMENTED(); | 504 NOTIMPLEMENTED(); |
506 /* NPEvent focus_event; | 505 /* NPEvent focus_event; |
507 focus_event.event = WM_SETFOCUS; | 506 focus_event.event = WM_SETFOCUS; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 | 623 |
625 void WebPluginDelegateImpl::URLRequestRouted(const std::string&url, | 624 void WebPluginDelegateImpl::URLRequestRouted(const std::string&url, |
626 bool notify_needed, | 625 bool notify_needed, |
627 void* notify_data) { | 626 void* notify_data) { |
628 if (notify_needed) { | 627 if (notify_needed) { |
629 instance()->SetURLLoadData(GURL(url.c_str()), notify_data); | 628 instance()->SetURLLoadData(GURL(url.c_str()), notify_data); |
630 } | 629 } |
631 } | 630 } |
632 | 631 |
633 | 632 |
OLD | NEW |