| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 7 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "base/stats_counters.h" | 16 #include "base/stats_counters.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "webkit/api/public/WebInputEvent.h" | 18 #include "webkit/api/public/WebInputEvent.h" |
| 19 #include "webkit/default_plugin/plugin_impl.h" | 19 #include "webkit/default_plugin/plugin_impl.h" |
| 20 #include "webkit/glue/glue_util.h" | 20 #include "webkit/glue/glue_util.h" |
| 21 #include "webkit/glue/webplugin.h" | 21 #include "webkit/glue/webplugin.h" |
| 22 #include "webkit/glue/plugins/fake_plugin_window_tracker_mac.h" | 22 #include "webkit/glue/plugins/fake_plugin_window_tracker_mac.h" |
| 23 #include "webkit/glue/plugins/plugin_constants_win.h" | 23 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 24 #include "webkit/glue/plugins/plugin_instance.h" | 24 #include "webkit/glue/plugins/plugin_instance.h" |
| 25 #include "webkit/glue/plugins/plugin_lib.h" | 25 #include "webkit/glue/plugins/plugin_lib.h" |
| 26 #include "webkit/glue/plugins/plugin_list.h" | 26 #include "webkit/glue/plugins/plugin_list.h" |
| 27 #include "webkit/glue/plugins/plugin_stream_url.h" | 27 #include "webkit/glue/plugins/plugin_stream_url.h" |
| 28 #include "webkit/glue/webkit_glue.h" | 28 #include "webkit/glue/webkit_glue.h" |
| 29 | 29 |
| 30 // If we're compiling support for the QuickDraw drawing model, turn off GCC |
| 31 // warnings about deprecated functions (since QuickDraw is a deprecated API). |
| 32 // According to the GCC documentation, this can only be done per file, not |
| 33 // pushed and popped like some options can be. |
| 34 #ifndef NP_NO_QUICKDRAW |
| 35 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 36 #endif |
| 37 |
| 30 using webkit_glue::WebPlugin; | 38 using webkit_glue::WebPlugin; |
| 31 using webkit_glue::WebPluginDelegate; | 39 using webkit_glue::WebPluginDelegate; |
| 32 using webkit_glue::WebPluginResourceClient; | 40 using webkit_glue::WebPluginResourceClient; |
| 33 using WebKit::WebCursorInfo; | 41 using WebKit::WebCursorInfo; |
| 34 using WebKit::WebKeyboardEvent; | 42 using WebKit::WebKeyboardEvent; |
| 35 using WebKit::WebInputEvent; | 43 using WebKit::WebInputEvent; |
| 36 using WebKit::WebMouseEvent; | 44 using WebKit::WebMouseEvent; |
| 37 | 45 |
| 38 // Important implementation notes: The Mac definition of NPAPI, particularly | 46 // Important implementation notes: The Mac definition of NPAPI, particularly |
| 39 // the distinction between windowed and windowless modes, differs from the | 47 // the distinction between windowed and windowless modes, differs from the |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 93 |
| 86 WebPluginDelegateImpl::WebPluginDelegateImpl( | 94 WebPluginDelegateImpl::WebPluginDelegateImpl( |
| 87 gfx::PluginWindowHandle containing_view, | 95 gfx::PluginWindowHandle containing_view, |
| 88 NPAPI::PluginInstance *instance) | 96 NPAPI::PluginInstance *instance) |
| 89 : windowless_needs_set_window_(true), | 97 : windowless_needs_set_window_(true), |
| 90 // all Mac plugins are "windowless" in the Windows/X11 sense | 98 // all Mac plugins are "windowless" in the Windows/X11 sense |
| 91 windowless_(true), | 99 windowless_(true), |
| 92 plugin_(NULL), | 100 plugin_(NULL), |
| 93 instance_(instance), | 101 instance_(instance), |
| 94 parent_(containing_view), | 102 parent_(containing_view), |
| 103 qd_world_(0), |
| 95 quirks_(0), | 104 quirks_(0), |
| 96 handle_event_depth_(0), | 105 handle_event_depth_(0), |
| 97 user_gesture_message_posted_(this), | 106 user_gesture_message_posted_(this), |
| 98 user_gesture_msg_factory_(this), | 107 user_gesture_msg_factory_(this), |
| 99 null_event_factory_(this), | 108 null_event_factory_(this), |
| 100 last_mouse_x_(0), | 109 last_mouse_x_(0), |
| 101 last_mouse_y_(0) { | 110 last_mouse_y_(0) { |
| 102 memset(&window_, 0, sizeof(window_)); | 111 memset(&window_, 0, sizeof(window_)); |
| 112 #ifndef NP_NO_QUICKDRAW |
| 113 memset(&qd_port_, 0, sizeof(qd_port_)); |
| 114 #endif |
| 103 } | 115 } |
| 104 | 116 |
| 105 WebPluginDelegateImpl::~WebPluginDelegateImpl() { | 117 WebPluginDelegateImpl::~WebPluginDelegateImpl() { |
| 118 #ifndef NP_NO_QUICKDRAW |
| 119 if (qd_port_.port) { |
| 120 DisposeGWorld(qd_port_.port); |
| 121 DisposeGWorld(qd_world_); |
| 122 } |
| 123 #endif |
| 106 FakePluginWindowTracker::SharedInstance()->RemoveFakeWindowForDelegate( | 124 FakePluginWindowTracker::SharedInstance()->RemoveFakeWindowForDelegate( |
| 107 this, reinterpret_cast<WindowRef>(cg_context_.window)); | 125 this, reinterpret_cast<WindowRef>(cg_context_.window)); |
| 108 DestroyInstance(); | 126 DestroyInstance(); |
| 109 } | 127 } |
| 110 | 128 |
| 111 void WebPluginDelegateImpl::PluginDestroyed() { | 129 void WebPluginDelegateImpl::PluginDestroyed() { |
| 112 delete this; | 130 delete this; |
| 113 } | 131 } |
| 114 | 132 |
| 115 bool WebPluginDelegateImpl::Initialize(const GURL& url, | 133 bool WebPluginDelegateImpl::Initialize(const GURL& url, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 139 if (!start_result) | 157 if (!start_result) |
| 140 return false; | 158 return false; |
| 141 | 159 |
| 142 FakePluginWindowTracker* window_tracker = | 160 FakePluginWindowTracker* window_tracker = |
| 143 FakePluginWindowTracker::SharedInstance(); | 161 FakePluginWindowTracker::SharedInstance(); |
| 144 cg_context_.window = window_tracker->GenerateFakeWindowForDelegate(this); | 162 cg_context_.window = window_tracker->GenerateFakeWindowForDelegate(this); |
| 145 cg_context_.context = NULL; | 163 cg_context_.context = NULL; |
| 146 Rect window_bounds = { 0, 0, window_rect_.height(), window_rect_.width() }; | 164 Rect window_bounds = { 0, 0, window_rect_.height(), window_rect_.width() }; |
| 147 SetWindowBounds(reinterpret_cast<WindowRef>(cg_context_.window), | 165 SetWindowBounds(reinterpret_cast<WindowRef>(cg_context_.window), |
| 148 kWindowContentRgn, &window_bounds); | 166 kWindowContentRgn, &window_bounds); |
| 149 window_.window = &cg_context_; | 167 |
| 150 window_.type = NPWindowTypeWindow; | 168 switch (instance_->drawing_model()) { |
| 169 #ifndef NP_NO_QUICKDRAW |
| 170 case NPDrawingModelQuickDraw: |
| 171 window_.window = &qd_port_; |
| 172 window_.type = NPWindowTypeDrawable; |
| 173 break; |
| 174 #endif |
| 175 case NPDrawingModelCoreGraphics: |
| 176 window_.window = &cg_context_; |
| 177 window_.type = NPWindowTypeDrawable; |
| 178 break; |
| 179 default: |
| 180 NOTREACHED(); |
| 181 break; |
| 182 } |
| 151 | 183 |
| 152 plugin->SetWindow(NULL); | 184 plugin->SetWindow(NULL); |
| 153 plugin_url_ = url.spec(); | 185 plugin_url_ = url.spec(); |
| 154 | 186 |
| 155 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 187 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 156 null_event_factory_.NewRunnableMethod( | 188 null_event_factory_.NewRunnableMethod( |
| 157 &WebPluginDelegateImpl::OnNullEvent), | 189 &WebPluginDelegateImpl::OnNullEvent), |
| 158 kPluginIdleThrottleDelayMs); | 190 kPluginIdleThrottleDelayMs); |
| 159 return true; | 191 return true; |
| 160 } | 192 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 187 WindowlessUpdateGeometry(window_rect, clip_rect); | 219 WindowlessUpdateGeometry(window_rect, clip_rect); |
| 188 } | 220 } |
| 189 | 221 |
| 190 void WebPluginDelegateImpl::UpdateContext(CGContextRef context) { | 222 void WebPluginDelegateImpl::UpdateContext(CGContextRef context) { |
| 191 // Flash on the Mac apparently caches the context from the struct it recieves | 223 // Flash on the Mac apparently caches the context from the struct it recieves |
| 192 // in NPP_SetWindow, and continue to use it even when the contents of the | 224 // in NPP_SetWindow, and continue to use it even when the contents of the |
| 193 // struct have changed, so we need to call NPP_SetWindow again if the context | 225 // struct have changed, so we need to call NPP_SetWindow again if the context |
| 194 // changes. | 226 // changes. |
| 195 if (context != cg_context_.context) { | 227 if (context != cg_context_.context) { |
| 196 cg_context_.context = context; | 228 cg_context_.context = context; |
| 229 #ifndef NP_NO_QUICKDRAW |
| 230 if (instance()->drawing_model() == NPDrawingModelQuickDraw) { |
| 231 if (qd_port_.port) { |
| 232 DisposeGWorld(qd_port_.port); |
| 233 DisposeGWorld(qd_world_); |
| 234 qd_port_.port = NULL; |
| 235 qd_world_ = NULL; |
| 236 } |
| 237 Rect window_bounds = { |
| 238 0, 0, window_rect_.height(), window_rect_.width() |
| 239 }; |
| 240 // Create a GWorld pointing at the same bits as our CGContextRef |
| 241 NewGWorldFromPtr(&qd_world_, k32BGRAPixelFormat, &window_bounds, |
| 242 NULL, NULL, 0, |
| 243 static_cast<Ptr>(CGBitmapContextGetData(context)), |
| 244 static_cast<SInt32>(CGBitmapContextGetBytesPerRow(context))); |
| 245 // Create a GWorld for the plugin to paint into whenever it wants |
| 246 NewGWorld(&qd_port_.port, k32ARGBPixelFormat, &window_bounds, |
| 247 NULL, NULL, kNativeEndianPixMap); |
| 248 SetGWorld(qd_port_.port, NULL); |
| 249 // Fill with black |
| 250 ForeColor(blackColor); |
| 251 BackColor(whiteColor); |
| 252 PaintRect(&window_bounds); |
| 253 } |
| 254 #endif |
| 197 WindowlessSetWindow(true); | 255 WindowlessSetWindow(true); |
| 198 } | 256 } |
| 199 } | 257 } |
| 200 | 258 |
| 201 void WebPluginDelegateImpl::Paint(CGContextRef context, const gfx::Rect& rect) { | 259 void WebPluginDelegateImpl::Paint(CGContextRef context, const gfx::Rect& rect) { |
| 202 DCHECK(windowless_); | 260 DCHECK(windowless_); |
| 203 WindowlessPaint(context, rect); | 261 WindowlessPaint(context, rect); |
| 204 } | 262 } |
| 205 | 263 |
| 206 void WebPluginDelegateImpl::Print(CGContextRef context) { | 264 void WebPluginDelegateImpl::Print(CGContextRef context) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 void WebPluginDelegateImpl::WindowlessPaint(gfx::NativeDrawingContext context, | 338 void WebPluginDelegateImpl::WindowlessPaint(gfx::NativeDrawingContext context, |
| 281 const gfx::Rect& damage_rect) { | 339 const gfx::Rect& damage_rect) { |
| 282 // If we somehow get a paint before we've set up the plugin window, bail. | 340 // If we somehow get a paint before we've set up the plugin window, bail. |
| 283 if (!cg_context_.context) | 341 if (!cg_context_.context) |
| 284 return; | 342 return; |
| 285 DCHECK(cg_context_.context == context); | 343 DCHECK(cg_context_.context == context); |
| 286 | 344 |
| 287 static StatsRate plugin_paint("Plugin.Paint"); | 345 static StatsRate plugin_paint("Plugin.Paint"); |
| 288 StatsScope<StatsRate> scope(plugin_paint); | 346 StatsScope<StatsRate> scope(plugin_paint); |
| 289 | 347 |
| 290 // We save and restore the NSGraphicsContext state in case the plugin uses | 348 switch (instance()->drawing_model()) { |
| 291 // Cocoa drawing. | 349 #ifndef NP_NO_QUICKDRAW |
| 292 [NSGraphicsContext saveGraphicsState]; | 350 case NPDrawingModelQuickDraw: |
| 293 [NSGraphicsContext setCurrentContext:[NSGraphicsContext | 351 { |
| 294 graphicsContextWithGraphicsPort:context | 352 // Plugins using the QuickDraw drawing model do not restrict their |
| 295 flipped:YES]]; | 353 // drawing to update events the way that CoreGraphics-based plugins |
| 296 CGContextSaveGState(context); | 354 // do. When we are asked to paint, we therefore just copy from the |
| 355 // plugin's persistent offscreen GWorld into our shared memory bitmap |
| 356 // context. |
| 357 Rect window_bounds = { |
| 358 0, 0, window_rect_.height(), window_rect_.width() |
| 359 }; |
| 360 PixMapHandle plugin_pixmap = GetGWorldPixMap(qd_port_.port); |
| 361 if (LockPixels(plugin_pixmap)) { |
| 362 PixMapHandle shared_pixmap = GetGWorldPixMap(qd_world_); |
| 363 if (LockPixels(shared_pixmap)) { |
| 364 SetGWorld(qd_world_, NULL); |
| 365 // Set foreground and background colors to avoid "colorizing" the |
| 366 // image. |
| 367 ForeColor(blackColor); |
| 368 BackColor(whiteColor); |
| 369 CopyBits(reinterpret_cast<BitMap*>(*plugin_pixmap), |
| 370 reinterpret_cast<BitMap*>(*shared_pixmap), |
| 371 &window_bounds, &window_bounds, srcCopy, NULL); |
| 372 UnlockPixels(shared_pixmap); |
| 373 } |
| 374 UnlockPixels(plugin_pixmap); |
| 375 } |
| 376 break; |
| 377 } |
| 378 #endif |
| 379 case NPDrawingModelCoreGraphics: |
| 380 { |
| 381 NPEvent paint_event; |
| 297 | 382 |
| 298 NPEvent paint_event; | 383 // Save and restore the NSGraphicsContext state in case the plugin uses |
| 299 paint_event.what = updateEvt; | 384 // Cocoa drawing. |
| 300 paint_event.message = reinterpret_cast<uint32>(cg_context_.window); | 385 [NSGraphicsContext saveGraphicsState]; |
| 301 paint_event.when = TickCount(); | 386 [NSGraphicsContext setCurrentContext: |
| 302 paint_event.where.h = 0; | 387 [NSGraphicsContext graphicsContextWithGraphicsPort:context |
| 303 paint_event.where.v = 0; | 388 flipped:YES]]; |
| 304 paint_event.modifiers = 0; | 389 CGContextSaveGState(context); |
| 305 instance()->NPP_HandleEvent(&paint_event); | |
| 306 | 390 |
| 307 CGContextRestoreGState(context); | 391 paint_event.what = updateEvt; |
| 308 [NSGraphicsContext restoreGraphicsState]; | 392 paint_event.message = reinterpret_cast<uint32>(cg_context_.window); |
| 393 paint_event.when = TickCount(); |
| 394 paint_event.where.h = 0; |
| 395 paint_event.where.v = 0; |
| 396 paint_event.modifiers = 0; |
| 397 instance()->NPP_HandleEvent(&paint_event); |
| 398 |
| 399 CGContextRestoreGState(context); |
| 400 [NSGraphicsContext restoreGraphicsState]; |
| 401 break; |
| 402 } |
| 403 } |
| 309 } | 404 } |
| 310 | 405 |
| 311 // Moves our dummy window to the given offset relative to the last known | 406 // Moves our dummy window to the given offset relative to the last known |
| 312 // location of the real renderer window's content view. | 407 // location of the real renderer window's content view. |
| 313 // If new_width or new_height is non-zero, the window size (content region) | 408 // If new_width or new_height is non-zero, the window size (content region) |
| 314 // will be updated accordingly; if they are zero, the existing size will be | 409 // will be updated accordingly; if they are zero, the existing size will be |
| 315 // preserved. | 410 // preserved. |
| 316 static void UpdateDummyWindowBoundsWithOffset(WindowRef window, | 411 static void UpdateDummyWindowBoundsWithOffset(WindowRef window, |
| 317 int x_offset, int y_offset, | 412 int x_offset, int y_offset, |
| 318 int new_width, int new_height) { | 413 int new_width, int new_height) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 348 window_.height = window_rect_.height(); | 443 window_.height = window_rect_.height(); |
| 349 window_.width = window_rect_.width(); | 444 window_.width = window_rect_.width(); |
| 350 window_.x = 0; | 445 window_.x = 0; |
| 351 window_.y = 0; | 446 window_.y = 0; |
| 352 | 447 |
| 353 UpdateDummyWindowBoundsWithOffset( | 448 UpdateDummyWindowBoundsWithOffset( |
| 354 reinterpret_cast<WindowRef>(cg_context_.window), window_rect_.x(), | 449 reinterpret_cast<WindowRef>(cg_context_.window), window_rect_.x(), |
| 355 window_rect_.y(), window_rect_.width(), window_rect_.height()); | 450 window_rect_.y(), window_rect_.width(), window_rect_.height()); |
| 356 | 451 |
| 357 NPError err = instance()->NPP_SetWindow(&window_); | 452 NPError err = instance()->NPP_SetWindow(&window_); |
| 453 |
| 358 DCHECK(err == NPERR_NO_ERROR); | 454 DCHECK(err == NPERR_NO_ERROR); |
| 359 } | 455 } |
| 360 | 456 |
| 361 void WebPluginDelegateImpl::SetFocus() { | 457 void WebPluginDelegateImpl::SetFocus() { |
| 362 NPEvent focus_event = { 0 }; | 458 NPEvent focus_event = { 0 }; |
| 363 focus_event.what = NPEventType_GetFocusEvent; | 459 focus_event.what = NPEventType_GetFocusEvent; |
| 364 focus_event.when = TickCount(); | 460 focus_event.when = TickCount(); |
| 365 instance()->NPP_HandleEvent(&focus_event); | 461 instance()->NPP_HandleEvent(&focus_event); |
| 366 } | 462 } |
| 367 | 463 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, | 597 bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, |
| 502 WebCursorInfo* cursor) { | 598 WebCursorInfo* cursor) { |
| 503 // If we somehow get an event before we've set up the plugin window, bail. | 599 // If we somehow get an event before we've set up the plugin window, bail. |
| 504 if (!cg_context_.context) | 600 if (!cg_context_.context) |
| 505 return false; | 601 return false; |
| 506 DCHECK(windowless_) << "events should only be received in windowless mode"; | 602 DCHECK(windowless_) << "events should only be received in windowless mode"; |
| 507 DCHECK(cursor != NULL); | 603 DCHECK(cursor != NULL); |
| 508 | 604 |
| 509 NPEvent np_event = {0}; | 605 NPEvent np_event = {0}; |
| 510 if (!NPEventFromWebInputEvent(event, &np_event)) { | 606 if (!NPEventFromWebInputEvent(event, &np_event)) { |
| 607 LOG(WARNING) << "NPEventFromWebInputEvent failed"; |
| 511 return false; | 608 return false; |
| 512 } | 609 } |
| 513 np_event.when = TickCount(); | 610 np_event.when = TickCount(); |
| 514 if (np_event.what == nullEvent) { | 611 if (np_event.what == nullEvent) { |
| 515 last_mouse_x_ = np_event.where.h; | 612 last_mouse_x_ = np_event.where.h; |
| 516 last_mouse_y_ = np_event.where.v; | 613 last_mouse_y_ = np_event.where.v; |
| 517 return true; // Let the recurring task actually send the event. | 614 return true; // Let the recurring task actually send the event. |
| 518 } | 615 } |
| 519 | 616 |
| 520 // If this is a mouse event, we need to make sure our dummy window has the | 617 // If this is a mouse event, we need to make sure our dummy window has the |
| 521 // correct location before we send the event to the plugin, so that any | 618 // correct location before we send the event to the plugin, so that any |
| 522 // coordinate conversion the plugin does will work out. | 619 // coordinate conversion the plugin does will work out. |
| 523 if (WebInputEventIsWebMouseEvent(event)) { | 620 if (WebInputEventIsWebMouseEvent(event)) { |
| 524 const WebMouseEvent* mouse_event = | 621 const WebMouseEvent* mouse_event = |
| 525 static_cast<const WebMouseEvent*>(&event); | 622 static_cast<const WebMouseEvent*>(&event); |
| 526 UpdateWindowLocation(reinterpret_cast<WindowRef>(cg_context_.window), | 623 UpdateWindowLocation(reinterpret_cast<WindowRef>(cg_context_.window), |
| 527 *mouse_event); | 624 *mouse_event); |
| 528 } | 625 } |
| 529 CGContextSaveGState(cg_context_.context); | 626 bool ret = false; |
| 530 bool ret = instance()->NPP_HandleEvent(&np_event) != 0; | 627 switch (instance()->drawing_model()) { |
| 531 CGContextRestoreGState(cg_context_.context); | 628 #ifndef NP_NO_QUICKDRAW |
| 629 case NPDrawingModelQuickDraw: |
| 630 SetGWorld(qd_port_.port, NULL); |
| 631 ret = instance()->NPP_HandleEvent(&np_event) != 0; |
| 632 break; |
| 633 #endif |
| 634 case NPDrawingModelCoreGraphics: |
| 635 CGContextSaveGState(cg_context_.context); |
| 636 ret = instance()->NPP_HandleEvent(&np_event) != 0; |
| 637 CGContextRestoreGState(cg_context_.context); |
| 638 break; |
| 639 } |
| 532 return ret; | 640 return ret; |
| 533 } | 641 } |
| 534 | 642 |
| 535 WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( | 643 WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( |
| 536 int resource_id, const GURL& url, bool notify_needed, | 644 int resource_id, const GURL& url, bool notify_needed, |
| 537 intptr_t notify_data, intptr_t existing_stream) { | 645 intptr_t notify_data, intptr_t existing_stream) { |
| 538 // Stream already exists. This typically happens for range requests | 646 // Stream already exists. This typically happens for range requests |
| 539 // initiated via NPN_RequestRead. | 647 // initiated via NPN_RequestRead. |
| 540 if (existing_stream) { | 648 if (existing_stream) { |
| 541 NPAPI::PluginStream* plugin_stream = | 649 NPAPI::PluginStream* plugin_stream = |
| 542 reinterpret_cast<NPAPI::PluginStream*>(existing_stream); | 650 reinterpret_cast<NPAPI::PluginStream*>(existing_stream); |
| 543 | 651 |
| 544 plugin_stream->CancelRequest(); | 652 plugin_stream->CancelRequest(); |
| 545 | 653 |
| 546 return plugin_stream->AsResourceClient(); | 654 return plugin_stream->AsResourceClient(); |
| 547 } | 655 } |
| 548 | 656 |
| 549 std::string mime_type; | 657 std::string mime_type; |
| 550 NPAPI::PluginStreamUrl *stream = instance()->CreateStream( | 658 NPAPI::PluginStreamUrl *stream = instance()->CreateStream( |
| 551 resource_id, url, mime_type, notify_needed, | 659 resource_id, url, mime_type, notify_needed, |
| 552 reinterpret_cast<void*>(notify_data)); | 660 reinterpret_cast<void*>(notify_data)); |
| 553 return stream; | 661 return stream; |
| 554 } | 662 } |
| 555 | 663 |
| 556 void WebPluginDelegateImpl::OnNullEvent() { | 664 void WebPluginDelegateImpl::OnNullEvent() { |
| 557 if (!webkit_glue::IsPluginRunningInRendererProcess()) { | 665 if (!webkit_glue::IsPluginRunningInRendererProcess()) { |
| 558 // If the plugin is running in a subprocess, drain any pending system | 666 switch (instance_->event_model()) { |
| 559 // events so that the plugin's event handlers will get called on any | 667 case NPEventModelCarbon: |
| 560 // windows it has created. Filter out activate/deactivate events on | 668 // If the plugin is running in a subprocess, drain any pending system |
| 561 // the fake browser window, but pass everything else through. | 669 // events so that the plugin's event handlers will get called on any |
| 562 EventRecord event; | 670 // windows it has created. Filter out activate/deactivate events on |
| 563 while (GetNextEvent(everyEvent, &event)) { | 671 // the fake browser window, but pass everything else through. |
| 564 if (event.what == activateEvt && cg_context_.window && | 672 EventRecord event; |
| 565 reinterpret_cast<void *>(event.message) != cg_context_.window) | 673 while (GetNextEvent(everyEvent, &event)) { |
| 566 continue; | 674 if (event.what == activateEvt && cg_context_.window && |
| 567 instance()->NPP_HandleEvent(&event); | 675 reinterpret_cast<void *>(event.message) != cg_context_.window) |
| 676 continue; |
| 677 instance()->NPP_HandleEvent(&event); |
| 678 } |
| 679 break; |
| 568 } | 680 } |
| 569 } | 681 } |
| 570 | 682 |
| 571 // Send an idle event so that the plugin can do background work | 683 // Send an idle event so that the plugin can do background work |
| 572 NPEvent np_event = {0}; | 684 NPEvent np_event = {0}; |
| 573 np_event.what = nullEvent; | 685 np_event.what = nullEvent; |
| 574 np_event.when = TickCount(); | 686 np_event.when = TickCount(); |
| 575 np_event.modifiers = GetCurrentKeyModifiers(); | 687 np_event.modifiers = GetCurrentKeyModifiers(); |
| 576 if (!Button()) | 688 if (!Button()) |
| 577 np_event.modifiers |= btnState; | 689 np_event.modifiers |= btnState; |
| 578 np_event.where.h = last_mouse_x_; | 690 np_event.where.h = last_mouse_x_; |
| 579 np_event.where.v = last_mouse_y_; | 691 np_event.where.v = last_mouse_y_; |
| 580 instance()->NPP_HandleEvent(&np_event); | 692 instance()->NPP_HandleEvent(&np_event); |
| 581 | 693 |
| 694 #ifndef NP_NO_QUICKDRAW |
| 695 // Quickdraw-based plugins can draw at any time, so tell the renderer to |
| 696 // repaint. |
| 697 // TODO: only do this if the contents of the offscreen GWorld has changed, |
| 698 // so as not to spam the renderer with an unchanging image. |
| 699 if (instance_->drawing_model() == NPDrawingModelQuickDraw) |
| 700 instance()->webplugin()->Invalidate(); |
| 701 #endif |
| 702 |
| 582 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 703 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 583 null_event_factory_.NewRunnableMethod( | 704 null_event_factory_.NewRunnableMethod( |
| 584 &WebPluginDelegateImpl::OnNullEvent), | 705 &WebPluginDelegateImpl::OnNullEvent), |
| 585 kPluginIdleThrottleDelayMs); | 706 kPluginIdleThrottleDelayMs); |
| 586 } | 707 } |
| OLD | NEW |