| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/npapi/plugin_instance.h" | 5 #include "webkit/plugins/npapi/plugin_instance.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "webkit/glue/webkit_glue.h" | 13 #include "webkit/glue/webkit_glue.h" |
| 13 #include "webkit/plugins/npapi/plugin_host.h" | 14 #include "webkit/plugins/npapi/plugin_host.h" |
| 14 #include "webkit/plugins/npapi/plugin_lib.h" | 15 #include "webkit/plugins/npapi/plugin_lib.h" |
| 15 #include "webkit/plugins/npapi/plugin_stream_url.h" | 16 #include "webkit/plugins/npapi/plugin_stream_url.h" |
| 16 #include "webkit/plugins/npapi/plugin_string_stream.h" | 17 #include "webkit/plugins/npapi/plugin_string_stream.h" |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 DCHECK(load_manually_); | 425 DCHECK(load_manually_); |
| 425 if (plugin_data_stream_.get() != NULL) { | 426 if (plugin_data_stream_.get() != NULL) { |
| 426 plugin_data_stream_->DidFail(); | 427 plugin_data_stream_->DidFail(); |
| 427 plugin_data_stream_ = NULL; | 428 plugin_data_stream_ = NULL; |
| 428 } | 429 } |
| 429 } | 430 } |
| 430 | 431 |
| 431 void PluginInstance::PluginThreadAsyncCall(void (*func)(void *), | 432 void PluginInstance::PluginThreadAsyncCall(void (*func)(void *), |
| 432 void *user_data) { | 433 void *user_data) { |
| 433 message_loop_->PostTask( | 434 message_loop_->PostTask( |
| 434 FROM_HERE, NewRunnableMethod( | 435 FROM_HERE, base::Bind(&PluginInstance::OnPluginThreadAsyncCall, this, |
| 435 this, &PluginInstance::OnPluginThreadAsyncCall, func, user_data)); | 436 func, user_data)); |
| 436 } | 437 } |
| 437 | 438 |
| 438 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void *), | 439 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void *), |
| 439 void *user_data) { | 440 void *user_data) { |
| 440 // Do not invoke the callback if NPP_Destroy has already been invoked. | 441 // Do not invoke the callback if NPP_Destroy has already been invoked. |
| 441 if (webplugin_) | 442 if (webplugin_) |
| 442 func(user_data); | 443 func(user_data); |
| 443 } | 444 } |
| 444 | 445 |
| 445 uint32 PluginInstance::ScheduleTimer(uint32 interval, | 446 uint32 PluginInstance::ScheduleTimer(uint32 interval, |
| 446 NPBool repeat, | 447 NPBool repeat, |
| 447 void (*func)(NPP id, uint32 timer_id)) { | 448 void (*func)(NPP id, uint32 timer_id)) { |
| 448 // Use next timer id. | 449 // Use next timer id. |
| 449 uint32 timer_id; | 450 uint32 timer_id; |
| 450 timer_id = next_timer_id_; | 451 timer_id = next_timer_id_; |
| 451 ++next_timer_id_; | 452 ++next_timer_id_; |
| 452 DCHECK(next_timer_id_ != 0); | 453 DCHECK(next_timer_id_ != 0); |
| 453 | 454 |
| 454 // Record timer interval and repeat. | 455 // Record timer interval and repeat. |
| 455 TimerInfo info; | 456 TimerInfo info; |
| 456 info.interval = interval; | 457 info.interval = interval; |
| 457 info.repeat = repeat ? true : false; | 458 info.repeat = repeat ? true : false; |
| 458 timers_[timer_id] = info; | 459 timers_[timer_id] = info; |
| 459 | 460 |
| 460 // Schedule the callback. | 461 // Schedule the callback. |
| 461 MessageLoop::current()->PostDelayedTask( | 462 MessageLoop::current()->PostDelayedTask( |
| 462 FROM_HERE, | 463 FROM_HERE, |
| 463 NewRunnableMethod( | 464 base::Bind(&PluginInstance::OnTimerCall, this, func, npp_, timer_id), |
| 464 this, &PluginInstance::OnTimerCall, func, npp_, timer_id), | |
| 465 interval); | 465 interval); |
| 466 return timer_id; | 466 return timer_id; |
| 467 } | 467 } |
| 468 | 468 |
| 469 void PluginInstance::UnscheduleTimer(uint32 timer_id) { | 469 void PluginInstance::UnscheduleTimer(uint32 timer_id) { |
| 470 // Remove info about the timer. | 470 // Remove info about the timer. |
| 471 TimerMap::iterator it = timers_.find(timer_id); | 471 TimerMap::iterator it = timers_.find(timer_id); |
| 472 if (it != timers_.end()) | 472 if (it != timers_.end()) |
| 473 timers_.erase(it); | 473 timers_.erase(it); |
| 474 } | 474 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 492 // callback might unschedule the timer. | 492 // callback might unschedule the timer. |
| 493 TimerInfo info = it->second; | 493 TimerInfo info = it->second; |
| 494 | 494 |
| 495 func(id, timer_id); | 495 func(id, timer_id); |
| 496 | 496 |
| 497 // If the timer was unscheduled by the callback, just free up the timer id. | 497 // If the timer was unscheduled by the callback, just free up the timer id. |
| 498 if (timers_.find(timer_id) == timers_.end()) | 498 if (timers_.find(timer_id) == timers_.end()) |
| 499 return; | 499 return; |
| 500 | 500 |
| 501 // Reschedule repeating timers after invoking the callback so callback is not | 501 // Reschedule repeating timers after invoking the callback so callback is not |
| 502 // re-entered if it pumps the messager loop. | 502 // re-entered if it pumps the message loop. |
| 503 if (info.repeat) { | 503 if (info.repeat) { |
| 504 MessageLoop::current()->PostDelayedTask( | 504 MessageLoop::current()->PostDelayedTask( |
| 505 FROM_HERE, | 505 FROM_HERE, |
| 506 NewRunnableMethod( | 506 base::Bind(&PluginInstance::OnTimerCall, this, func, npp_, timer_id), |
| 507 this, &PluginInstance::OnTimerCall, func, npp_, timer_id), | |
| 508 info.interval); | 507 info.interval); |
| 509 } else { | 508 } else { |
| 510 timers_.erase(it); | 509 timers_.erase(it); |
| 511 } | 510 } |
| 512 } | 511 } |
| 513 | 512 |
| 514 void PluginInstance::PushPopupsEnabledState(bool enabled) { | 513 void PluginInstance::PushPopupsEnabledState(bool enabled) { |
| 515 popups_enabled_stack_.push(enabled); | 514 popups_enabled_stack_.push(enabled); |
| 516 } | 515 } |
| 517 | 516 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 plugin_stream->UpdateUrl( | 677 plugin_stream->UpdateUrl( |
| 679 plugin_stream->pending_redirect_url().c_str()); | 678 plugin_stream->pending_redirect_url().c_str()); |
| 680 } | 679 } |
| 681 break; | 680 break; |
| 682 } | 681 } |
| 683 } | 682 } |
| 684 } | 683 } |
| 685 | 684 |
| 686 } // namespace npapi | 685 } // namespace npapi |
| 687 } // namespace webkit | 686 } // namespace webkit |
| OLD | NEW |