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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/location.h" |
| 11 #include "base/single_thread_task_runner.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/thread_task_runner_handle.h" |
13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
14 #include "content/child/npapi/plugin_host.h" | 16 #include "content/child/npapi/plugin_host.h" |
15 #include "content/child/npapi/plugin_lib.h" | 17 #include "content/child/npapi/plugin_lib.h" |
16 #include "content/child/npapi/plugin_stream_url.h" | 18 #include "content/child/npapi/plugin_stream_url.h" |
17 #include "content/child/npapi/plugin_string_stream.h" | 19 #include "content/child/npapi/plugin_string_stream.h" |
18 #include "content/child/npapi/webplugin.h" | 20 #include "content/child/npapi/webplugin.h" |
19 #include "content/child/npapi/webplugin_delegate.h" | 21 #include "content/child/npapi/webplugin_delegate.h" |
20 #include "content/child/npapi/webplugin_resource_client.h" | 22 #include "content/child/npapi/webplugin_resource_client.h" |
21 #include "content/public/common/content_constants.h" | 23 #include "content/public/common/content_constants.h" |
22 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
(...skipping 23 matching lines...) Expand all Loading... |
46 #else | 48 #else |
47 drawing_model_(NPDrawingModelQuickDraw), | 49 drawing_model_(NPDrawingModelQuickDraw), |
48 #endif | 50 #endif |
49 #ifdef NP_NO_CARBON | 51 #ifdef NP_NO_CARBON |
50 event_model_(NPEventModelCocoa), | 52 event_model_(NPEventModelCocoa), |
51 #else | 53 #else |
52 event_model_(NPEventModelCarbon), | 54 event_model_(NPEventModelCarbon), |
53 #endif | 55 #endif |
54 currently_handled_event_(NULL), | 56 currently_handled_event_(NULL), |
55 #endif | 57 #endif |
56 message_loop_(base::MessageLoop::current()), | 58 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
57 load_manually_(false), | 59 load_manually_(false), |
58 in_close_streams_(false), | 60 in_close_streams_(false), |
59 next_timer_id_(1), | 61 next_timer_id_(1), |
60 next_notify_id_(0), | 62 next_notify_id_(0), |
61 next_range_request_id_(0), | 63 next_range_request_id_(0), |
62 handles_url_redirects_(false) { | 64 handles_url_redirects_(false) { |
63 npp_ = new NPP_t(); | 65 npp_ = new NPP_t(); |
64 npp_->ndata = 0; | 66 npp_->ndata = 0; |
65 npp_->pdata = 0; | 67 npp_->pdata = 0; |
66 | 68 |
67 if (mime_type_ == kFlashPluginSwfMimeType) | 69 if (mime_type_ == kFlashPluginSwfMimeType) |
68 transparent_ = false; | 70 transparent_ = false; |
69 | 71 |
70 memset(&zero_padding_, 0, sizeof(zero_padding_)); | 72 memset(&zero_padding_, 0, sizeof(zero_padding_)); |
71 DCHECK(message_loop_); | |
72 } | 73 } |
73 | 74 |
74 PluginInstance::~PluginInstance() { | 75 PluginInstance::~PluginInstance() { |
75 CloseStreams(); | 76 CloseStreams(); |
76 | 77 |
77 if (npp_ != 0) { | 78 if (npp_ != 0) { |
78 delete npp_; | 79 delete npp_; |
79 npp_ = 0; | 80 npp_ = 0; |
80 } | 81 } |
81 | 82 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 void PluginInstance::DidManualLoadFail() { | 432 void PluginInstance::DidManualLoadFail() { |
432 DCHECK(load_manually_); | 433 DCHECK(load_manually_); |
433 if (plugin_data_stream_.get() != NULL) { | 434 if (plugin_data_stream_.get() != NULL) { |
434 plugin_data_stream_->DidFail(plugin_data_stream_->ResourceId()); | 435 plugin_data_stream_->DidFail(plugin_data_stream_->ResourceId()); |
435 plugin_data_stream_ = NULL; | 436 plugin_data_stream_ = NULL; |
436 } | 437 } |
437 } | 438 } |
438 | 439 |
439 void PluginInstance::PluginThreadAsyncCall(void (*func)(void*), | 440 void PluginInstance::PluginThreadAsyncCall(void (*func)(void*), |
440 void* user_data) { | 441 void* user_data) { |
441 message_loop_->PostTask( | 442 task_runner_->PostTask( |
442 FROM_HERE, base::Bind(&PluginInstance::OnPluginThreadAsyncCall, this, | 443 FROM_HERE, base::Bind(&PluginInstance::OnPluginThreadAsyncCall, this, |
443 func, user_data)); | 444 func, user_data)); |
444 } | 445 } |
445 | 446 |
446 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void*), | 447 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void*), |
447 void* user_data) { | 448 void* user_data) { |
448 // Do not invoke the callback if NPP_Destroy has already been invoked. | 449 // Do not invoke the callback if NPP_Destroy has already been invoked. |
449 if (webplugin_) | 450 if (webplugin_) |
450 func(user_data); | 451 func(user_data); |
451 } | 452 } |
452 | 453 |
453 uint32 PluginInstance::ScheduleTimer(uint32 interval, | 454 uint32 PluginInstance::ScheduleTimer(uint32 interval, |
454 NPBool repeat, | 455 NPBool repeat, |
455 void (*func)(NPP id, uint32 timer_id)) { | 456 void (*func)(NPP id, uint32 timer_id)) { |
456 // Use next timer id. | 457 // Use next timer id. |
457 uint32 timer_id; | 458 uint32 timer_id; |
458 timer_id = next_timer_id_; | 459 timer_id = next_timer_id_; |
459 ++next_timer_id_; | 460 ++next_timer_id_; |
460 DCHECK(next_timer_id_ != 0); | 461 DCHECK(next_timer_id_ != 0); |
461 | 462 |
462 // Record timer interval and repeat. | 463 // Record timer interval and repeat. |
463 TimerInfo info; | 464 TimerInfo info; |
464 info.interval = interval; | 465 info.interval = interval; |
465 info.repeat = repeat ? true : false; | 466 info.repeat = repeat ? true : false; |
466 timers_[timer_id] = info; | 467 timers_[timer_id] = info; |
467 | 468 |
468 // Schedule the callback. | 469 // Schedule the callback. |
469 base::MessageLoop::current()->PostDelayedTask( | 470 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
470 FROM_HERE, | 471 FROM_HERE, |
471 base::Bind(&PluginInstance::OnTimerCall, this, func, npp_, timer_id), | 472 base::Bind(&PluginInstance::OnTimerCall, this, func, npp_, timer_id), |
472 base::TimeDelta::FromMilliseconds(interval)); | 473 base::TimeDelta::FromMilliseconds(interval)); |
473 return timer_id; | 474 return timer_id; |
474 } | 475 } |
475 | 476 |
476 void PluginInstance::UnscheduleTimer(uint32 timer_id) { | 477 void PluginInstance::UnscheduleTimer(uint32 timer_id) { |
477 // Remove info about the timer. | 478 // Remove info about the timer. |
478 TimerMap::iterator it = timers_.find(timer_id); | 479 TimerMap::iterator it = timers_.find(timer_id); |
479 if (it != timers_.end()) | 480 if (it != timers_.end()) |
(...skipping 21 matching lines...) Expand all Loading... |
501 | 502 |
502 func(id, timer_id); | 503 func(id, timer_id); |
503 | 504 |
504 // If the timer was unscheduled by the callback, just free up the timer id. | 505 // If the timer was unscheduled by the callback, just free up the timer id. |
505 if (timers_.find(timer_id) == timers_.end()) | 506 if (timers_.find(timer_id) == timers_.end()) |
506 return; | 507 return; |
507 | 508 |
508 // Reschedule repeating timers after invoking the callback so callback is not | 509 // Reschedule repeating timers after invoking the callback so callback is not |
509 // re-entered if it pumps the message loop. | 510 // re-entered if it pumps the message loop. |
510 if (info.repeat) { | 511 if (info.repeat) { |
511 base::MessageLoop::current()->PostDelayedTask( | 512 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
512 FROM_HERE, | 513 FROM_HERE, |
513 base::Bind(&PluginInstance::OnTimerCall, this, func, npp_, timer_id), | 514 base::Bind(&PluginInstance::OnTimerCall, this, func, npp_, timer_id), |
514 base::TimeDelta::FromMilliseconds(info.interval)); | 515 base::TimeDelta::FromMilliseconds(info.interval)); |
515 } else { | 516 } else { |
516 timers_.erase(it); | 517 timers_.erase(it); |
517 } | 518 } |
518 } | 519 } |
519 | 520 |
520 void PluginInstance::PushPopupsEnabledState(bool enabled) { | 521 void PluginInstance::PushPopupsEnabledState(bool enabled) { |
521 popups_enabled_stack_.push(enabled); | 522 popups_enabled_stack_.push(enabled); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 if (plugin_stream->notify_data() == notify_data) { | 689 if (plugin_stream->notify_data() == notify_data) { |
689 PluginStreamUrl* plugin_stream_url = | 690 PluginStreamUrl* plugin_stream_url = |
690 static_cast<PluginStreamUrl*>(plugin_stream); | 691 static_cast<PluginStreamUrl*>(plugin_stream); |
691 plugin_stream_url->URLRedirectResponse(allow); | 692 plugin_stream_url->URLRedirectResponse(allow); |
692 break; | 693 break; |
693 } | 694 } |
694 } | 695 } |
695 } | 696 } |
696 | 697 |
697 } // namespace content | 698 } // namespace content |
OLD | NEW |