| 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/child/npapi/plugin_instance.h" | 5 #include "content/child/npapi/plugin_instance.h" |
| 6 | 6 |
| 7 #include <string.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 12 #include "base/location.h" |
| 11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 15 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 16 #include "content/child/npapi/plugin_host.h" | 18 #include "content/child/npapi/plugin_host.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 func, user_data)); | 274 func, user_data)); |
| 273 } | 275 } |
| 274 | 276 |
| 275 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void*), | 277 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void*), |
| 276 void* user_data) { | 278 void* user_data) { |
| 277 // Do not invoke the callback if NPP_Destroy has already been invoked. | 279 // Do not invoke the callback if NPP_Destroy has already been invoked. |
| 278 if (webplugin_) | 280 if (webplugin_) |
| 279 func(user_data); | 281 func(user_data); |
| 280 } | 282 } |
| 281 | 283 |
| 282 uint32 PluginInstance::ScheduleTimer(uint32 interval, | 284 uint32_t PluginInstance::ScheduleTimer(uint32_t interval, |
| 283 NPBool repeat, | 285 NPBool repeat, |
| 284 void (*func)(NPP id, uint32 timer_id)) { | 286 void (*func)(NPP id, |
| 287 uint32_t timer_id)) { |
| 285 // Use next timer id. | 288 // Use next timer id. |
| 286 uint32 timer_id; | 289 uint32_t timer_id; |
| 287 timer_id = next_timer_id_; | 290 timer_id = next_timer_id_; |
| 288 ++next_timer_id_; | 291 ++next_timer_id_; |
| 289 DCHECK(next_timer_id_ != 0); | 292 DCHECK(next_timer_id_ != 0); |
| 290 | 293 |
| 291 // Record timer interval and repeat. | 294 // Record timer interval and repeat. |
| 292 TimerInfo info; | 295 TimerInfo info; |
| 293 info.interval = interval; | 296 info.interval = interval; |
| 294 info.repeat = repeat ? true : false; | 297 info.repeat = repeat ? true : false; |
| 295 timers_[timer_id] = info; | 298 timers_[timer_id] = info; |
| 296 | 299 |
| 297 // Schedule the callback. | 300 // Schedule the callback. |
| 298 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 301 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 299 FROM_HERE, | 302 FROM_HERE, |
| 300 base::Bind(&PluginInstance::OnTimerCall, this, func, npp_, timer_id), | 303 base::Bind(&PluginInstance::OnTimerCall, this, func, npp_, timer_id), |
| 301 base::TimeDelta::FromMilliseconds(interval)); | 304 base::TimeDelta::FromMilliseconds(interval)); |
| 302 return timer_id; | 305 return timer_id; |
| 303 } | 306 } |
| 304 | 307 |
| 305 void PluginInstance::UnscheduleTimer(uint32 timer_id) { | 308 void PluginInstance::UnscheduleTimer(uint32_t timer_id) { |
| 306 // Remove info about the timer. | 309 // Remove info about the timer. |
| 307 TimerMap::iterator it = timers_.find(timer_id); | 310 TimerMap::iterator it = timers_.find(timer_id); |
| 308 if (it != timers_.end()) | 311 if (it != timers_.end()) |
| 309 timers_.erase(it); | 312 timers_.erase(it); |
| 310 } | 313 } |
| 311 | 314 |
| 312 #if !defined(OS_MACOSX) | 315 #if !defined(OS_MACOSX) |
| 313 NPError PluginInstance::PopUpContextMenu(NPMenu* menu) { | 316 NPError PluginInstance::PopUpContextMenu(NPMenu* menu) { |
| 314 NOTIMPLEMENTED(); | 317 NOTIMPLEMENTED(); |
| 315 return NPERR_GENERIC_ERROR; | 318 return NPERR_GENERIC_ERROR; |
| 316 } | 319 } |
| 317 #endif | 320 #endif |
| 318 | 321 |
| 319 void PluginInstance::OnTimerCall(void (*func)(NPP id, uint32 timer_id), | 322 void PluginInstance::OnTimerCall(void (*func)(NPP id, uint32_t timer_id), |
| 320 NPP id, | 323 NPP id, |
| 321 uint32 timer_id) { | 324 uint32_t timer_id) { |
| 322 // Do not invoke callback if the timer has been unscheduled. | 325 // Do not invoke callback if the timer has been unscheduled. |
| 323 TimerMap::iterator it = timers_.find(timer_id); | 326 TimerMap::iterator it = timers_.find(timer_id); |
| 324 if (it == timers_.end()) | 327 if (it == timers_.end()) |
| 325 return; | 328 return; |
| 326 | 329 |
| 327 // Get all information about the timer before invoking the callback. The | 330 // Get all information about the timer before invoking the callback. The |
| 328 // callback might unschedule the timer. | 331 // callback might unschedule the timer. |
| 329 TimerInfo info = it->second; | 332 TimerInfo info = it->second; |
| 330 | 333 |
| 331 func(id, timer_id); | 334 func(id, timer_id); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 if (dest_y) | 421 if (dest_y) |
| 419 *dest_y = target_y; | 422 *dest_y = target_y; |
| 420 return true; | 423 return true; |
| 421 #else | 424 #else |
| 422 NOTIMPLEMENTED(); | 425 NOTIMPLEMENTED(); |
| 423 return false; | 426 return false; |
| 424 #endif | 427 #endif |
| 425 } | 428 } |
| 426 | 429 |
| 427 } // namespace content | 430 } // namespace content |
| OLD | NEW |