OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" | 7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/surface/transport_dib.h" | 10 #include "app/surface/transport_dib.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 private: | 117 private: |
118 WebKit::WebView* web_view_; | 118 WebKit::WebView* web_view_; |
119 ggl::Context* context_; | 119 ggl::Context* context_; |
120 }; | 120 }; |
121 | 121 |
122 #endif // ENABLE_GPU | 122 #endif // ENABLE_GPU |
123 | 123 |
124 class PlatformAudioImpl | 124 class PlatformAudioImpl |
125 : public pepper::PluginDelegate::PlatformAudio, | 125 : public pepper::PluginDelegate::PlatformAudio, |
126 public AudioMessageFilter::Delegate { | 126 public AudioMessageFilter::Delegate, |
| 127 public base::RefCountedThreadSafe<PlatformAudioImpl> { |
127 public: | 128 public: |
128 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) | 129 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) |
129 : client_(NULL), filter_(filter), stream_id_(0) { | 130 : client_(NULL), filter_(filter), stream_id_(0), |
| 131 main_message_loop_(MessageLoop::current()) { |
130 DCHECK(filter_); | 132 DCHECK(filter_); |
131 } | 133 } |
132 | 134 |
133 virtual ~PlatformAudioImpl() { | 135 virtual ~PlatformAudioImpl() { |
134 // Make sure we have been shut down. | 136 // Make sure we have been shut down. |
135 DCHECK_EQ(0, stream_id_); | 137 DCHECK_EQ(0, stream_id_); |
136 DCHECK(!client_); | 138 DCHECK(!client_); |
137 } | 139 } |
138 | 140 |
139 // Initialize this audio context. StreamCreated() will be called when the | 141 // Initialize this audio context. StreamCreated() will be called when the |
(...skipping 30 matching lines...) Expand all Loading... |
170 | 172 |
171 virtual void OnVolume(double volume) { } | 173 virtual void OnVolume(double volume) { } |
172 | 174 |
173 // The client to notify when the stream is created. | 175 // The client to notify when the stream is created. |
174 pepper::PluginDelegate::PlatformAudio::Client* client_; | 176 pepper::PluginDelegate::PlatformAudio::Client* client_; |
175 // MessageFilter used to send/receive IPC. | 177 // MessageFilter used to send/receive IPC. |
176 scoped_refptr<AudioMessageFilter> filter_; | 178 scoped_refptr<AudioMessageFilter> filter_; |
177 // Our ID on the MessageFilter. | 179 // Our ID on the MessageFilter. |
178 int32 stream_id_; | 180 int32 stream_id_; |
179 | 181 |
| 182 MessageLoop* main_message_loop_; |
| 183 |
180 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); | 184 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); |
181 }; | 185 }; |
182 | 186 |
183 #ifdef ENABLE_GPU | 187 #ifdef ENABLE_GPU |
184 | 188 |
185 bool PlatformContext3DImpl::Init() { | 189 bool PlatformContext3DImpl::Init() { |
186 // Ignore initializing more than once. | 190 // Ignore initializing more than once. |
187 if (context_) | 191 if (context_) |
188 return true; | 192 return true; |
189 | 193 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 uint32 length) { | 294 uint32 length) { |
291 #if defined(OS_WIN) | 295 #if defined(OS_WIN) |
292 DCHECK(handle); | 296 DCHECK(handle); |
293 DCHECK(socket_handle); | 297 DCHECK(socket_handle); |
294 #else | 298 #else |
295 DCHECK_NE(-1, handle.fd); | 299 DCHECK_NE(-1, handle.fd); |
296 DCHECK_NE(-1, socket_handle); | 300 DCHECK_NE(-1, socket_handle); |
297 #endif | 301 #endif |
298 DCHECK(length); | 302 DCHECK(length); |
299 | 303 |
300 client_->StreamCreated(handle, length, socket_handle); | 304 if (MessageLoop::current() == main_message_loop_) { |
| 305 if (client_) { |
| 306 client_->StreamCreated(handle, length, socket_handle); |
| 307 } |
| 308 } else { |
| 309 main_message_loop_->PostTask(FROM_HERE, |
| 310 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, |
| 311 handle, socket_handle, length)); |
| 312 } |
301 } | 313 } |
302 | 314 |
303 void PlatformAudioImpl::ShutDown() { | 315 void PlatformAudioImpl::ShutDown() { |
304 // Make sure we don't call shutdown more than once. | 316 // Make sure we don't call shutdown more than once. |
305 if (!stream_id_) { | 317 if (!stream_id_) { |
306 return; | 318 return; |
307 } | 319 } |
308 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); | 320 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); |
309 filter_->RemoveDelegate(stream_id_); | 321 filter_->RemoveDelegate(stream_id_); |
310 stream_id_ = 0; | 322 stream_id_ = 0; |
311 client_ = NULL; | 323 client_ = NULL; |
| 324 |
| 325 // Release on the IO thread so that we avoid race problems with |
| 326 // OnLowLatencyCreated. |
| 327 filter_->message_loop()->ReleaseSoon(FROM_HERE, this); |
312 } | 328 } |
313 | 329 |
314 // Implements the VideoDecoder. | 330 // Implements the VideoDecoder. |
315 class PlatformVideoDecoderImpl | 331 class PlatformVideoDecoderImpl |
316 : public pepper::PluginDelegate::PlatformVideoDecoder { | 332 : public pepper::PluginDelegate::PlatformVideoDecoder { |
317 public: | 333 public: |
318 PlatformVideoDecoderImpl() | 334 PlatformVideoDecoderImpl() |
319 : input_buffer_size_(0), | 335 : input_buffer_size_(0), |
320 next_dib_id_(0), | 336 next_dib_id_(0), |
321 dib_(NULL) { | 337 dib_(NULL) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 | 569 |
554 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, | 570 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, |
555 int index) { | 571 int index) { |
556 render_view_->reportFindInPageSelection( | 572 render_view_->reportFindInPageSelection( |
557 identifier, index + 1, WebKit::WebRect()); | 573 identifier, index + 1, WebKit::WebRect()); |
558 } | 574 } |
559 | 575 |
560 pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( | 576 pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( |
561 uint32_t sample_rate, uint32_t sample_count, | 577 uint32_t sample_rate, uint32_t sample_count, |
562 pepper::PluginDelegate::PlatformAudio::Client* client) { | 578 pepper::PluginDelegate::PlatformAudio::Client* client) { |
563 scoped_ptr<PlatformAudioImpl> audio( | 579 scoped_refptr<PlatformAudioImpl> audio( |
564 new PlatformAudioImpl(render_view_->audio_message_filter())); | 580 new PlatformAudioImpl(render_view_->audio_message_filter())); |
565 if (audio->Initialize(sample_rate, sample_count, client)) { | 581 if (audio->Initialize(sample_rate, sample_count, client)) { |
| 582 |
| 583 // Also note ReleaseSoon invoked in PlatformAudioImpl::ShutDown(). |
566 return audio.release(); | 584 return audio.release(); |
567 } else { | 585 } else { |
568 return NULL; | 586 return NULL; |
569 } | 587 } |
570 } | 588 } |
571 | 589 |
572 bool PepperPluginDelegateImpl::RunFileChooser( | 590 bool PepperPluginDelegateImpl::RunFileChooser( |
573 const WebKit::WebFileChooserParams& params, | 591 const WebKit::WebFileChooserParams& params, |
574 WebKit::WebFileChooserCompletion* chooser_completion) { | 592 WebKit::WebFileChooserCompletion* chooser_completion) { |
575 return render_view_->runFileChooser(params, chooser_completion); | 593 return render_view_->runFileChooser(params, chooser_completion); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 } | 842 } |
825 | 843 |
826 void PepperPluginDelegateImpl::DidStopLoading() { | 844 void PepperPluginDelegateImpl::DidStopLoading() { |
827 render_view_->DidStopLoadingForPlugin(); | 845 render_view_->DidStopLoadingForPlugin(); |
828 } | 846 } |
829 | 847 |
830 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { | 848 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { |
831 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( | 849 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( |
832 render_view_->routing_id(), restrictions)); | 850 render_view_->routing_id(), restrictions)); |
833 } | 851 } |
OLD | NEW |