Chromium Code Reviews| 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 "content/renderer/pepper_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper_plugin_delegate_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 | 152 |
| 153 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); | 153 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 | 156 |
| 157 class PlatformAudioImpl | 157 class PlatformAudioImpl |
| 158 : public webkit::ppapi::PluginDelegate::PlatformAudio, | 158 : public webkit::ppapi::PluginDelegate::PlatformAudio, |
| 159 public AudioMessageFilter::Delegate, | 159 public AudioMessageFilter::Delegate, |
| 160 public base::RefCountedThreadSafe<PlatformAudioImpl> { | 160 public base::RefCountedThreadSafe<PlatformAudioImpl> { |
| 161 public: | 161 public: |
| 162 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) | 162 explicit PlatformAudioImpl() |
| 163 : client_(NULL), filter_(filter), stream_id_(0), | 163 : client_(NULL), stream_id_(0), |
| 164 main_message_loop_(MessageLoop::current()) { | 164 main_message_loop_(MessageLoop::current()) { |
| 165 DCHECK(RenderThread::current()); | |
|
jam
2011/06/23 18:59:55
nit: we usually avoid dchecks against a pointer be
henrika_dont_use
2011/06/27 15:05:44
Done.
| |
| 166 filter_ = RenderThread::current()->audio_message_filter(); | |
| 165 DCHECK(filter_); | 167 DCHECK(filter_); |
| 166 } | 168 } |
| 167 | 169 |
| 168 virtual ~PlatformAudioImpl() { | 170 virtual ~PlatformAudioImpl() { |
| 169 // Make sure we have been shut down. Warning: this will usually happen on | 171 // Make sure we have been shut down. Warning: this will usually happen on |
| 170 // the I/O thread! | 172 // the I/O thread! |
| 171 DCHECK_EQ(0, stream_id_); | 173 DCHECK_EQ(0, stream_id_); |
| 172 DCHECK(!client_); | 174 DCHECK(!client_); |
| 173 } | 175 } |
| 174 | 176 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 void PlatformAudioImpl::ShutDown() { | 268 void PlatformAudioImpl::ShutDown() { |
| 267 // Called on the main thread to stop all audio callbacks. We must only change | 269 // Called on the main thread to stop all audio callbacks. We must only change |
| 268 // the client on the main thread, and the delegates from the I/O thread. | 270 // the client on the main thread, and the delegates from the I/O thread. |
| 269 client_ = NULL; | 271 client_ = NULL; |
| 270 filter_->message_loop()->PostTask(FROM_HERE, | 272 filter_->message_loop()->PostTask(FROM_HERE, |
| 271 NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread)); | 273 NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread)); |
| 272 } | 274 } |
| 273 | 275 |
| 274 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { | 276 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { |
| 275 stream_id_ = filter_->AddDelegate(this); | 277 stream_id_ = filter_->AddDelegate(this); |
| 276 filter_->Send(new AudioHostMsg_CreateStream(0, stream_id_, params, true)); | 278 filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params, true)); |
| 277 } | 279 } |
| 278 | 280 |
| 279 void PlatformAudioImpl::StartPlaybackOnIOThread() { | 281 void PlatformAudioImpl::StartPlaybackOnIOThread() { |
| 280 if (stream_id_) | 282 if (stream_id_) |
| 281 filter_->Send(new AudioHostMsg_PlayStream(0, stream_id_)); | 283 filter_->Send(new AudioHostMsg_PlayStream(stream_id_)); |
| 282 } | 284 } |
| 283 | 285 |
| 284 void PlatformAudioImpl::StopPlaybackOnIOThread() { | 286 void PlatformAudioImpl::StopPlaybackOnIOThread() { |
| 285 if (stream_id_) | 287 if (stream_id_) |
| 286 filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_)); | 288 filter_->Send(new AudioHostMsg_PauseStream(stream_id_)); |
| 287 } | 289 } |
| 288 | 290 |
| 289 void PlatformAudioImpl::ShutDownOnIOThread() { | 291 void PlatformAudioImpl::ShutDownOnIOThread() { |
| 290 // Make sure we don't call shutdown more than once. | 292 // Make sure we don't call shutdown more than once. |
| 291 if (!stream_id_) | 293 if (!stream_id_) |
| 292 return; | 294 return; |
| 293 | 295 |
| 294 filter_->Send(new AudioHostMsg_CloseStream(0, stream_id_)); | 296 filter_->Send(new AudioHostMsg_CloseStream(stream_id_)); |
| 295 filter_->RemoveDelegate(stream_id_); | 297 filter_->RemoveDelegate(stream_id_); |
| 296 stream_id_ = 0; | 298 stream_id_ = 0; |
| 297 | 299 |
| 298 Release(); // Release for the delegate, balances out the reference taken in | 300 Release(); // Release for the delegate, balances out the reference taken in |
| 299 // PepperPluginDelegateImpl::CreateAudio. | 301 // PepperPluginDelegateImpl::CreateAudio. |
| 300 } | 302 } |
| 301 | 303 |
| 302 void PlatformAudioImpl::OnLowLatencyCreated( | 304 void PlatformAudioImpl::OnLowLatencyCreated( |
| 303 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, | 305 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, |
| 304 uint32 length) { | 306 uint32 length) { |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, | 844 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, |
| 843 int index) { | 845 int index) { |
| 844 render_view_->reportFindInPageSelection( | 846 render_view_->reportFindInPageSelection( |
| 845 identifier, index + 1, WebKit::WebRect()); | 847 identifier, index + 1, WebKit::WebRect()); |
| 846 } | 848 } |
| 847 | 849 |
| 848 webkit::ppapi::PluginDelegate::PlatformAudio* | 850 webkit::ppapi::PluginDelegate::PlatformAudio* |
| 849 PepperPluginDelegateImpl::CreateAudio( | 851 PepperPluginDelegateImpl::CreateAudio( |
| 850 uint32_t sample_rate, uint32_t sample_count, | 852 uint32_t sample_rate, uint32_t sample_count, |
| 851 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { | 853 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { |
| 852 scoped_refptr<PlatformAudioImpl> audio( | 854 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); |
| 853 new PlatformAudioImpl(render_view_->audio_message_filter())); | |
| 854 if (audio->Initialize(sample_rate, sample_count, client)) { | 855 if (audio->Initialize(sample_rate, sample_count, client)) { |
| 855 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). | 856 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). |
| 856 return audio.release(); | 857 return audio.release(); |
| 857 } else { | 858 } else { |
| 858 return NULL; | 859 return NULL; |
| 859 } | 860 } |
| 860 } | 861 } |
| 861 | 862 |
| 862 // If a broker has not already been created for this plugin, creates one. | 863 // If a broker has not already been created for this plugin, creates one. |
| 863 webkit::ppapi::PluginDelegate::PpapiBroker* | 864 webkit::ppapi::PluginDelegate::PpapiBroker* |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 } | 983 } |
| 983 | 984 |
| 984 bool PepperPluginDelegateImpl::ReadDirectory( | 985 bool PepperPluginDelegateImpl::ReadDirectory( |
| 985 const GURL& directory_path, | 986 const GURL& directory_path, |
| 986 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 987 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
| 987 FileSystemDispatcher* file_system_dispatcher = | 988 FileSystemDispatcher* file_system_dispatcher = |
| 988 ChildThread::current()->file_system_dispatcher(); | 989 ChildThread::current()->file_system_dispatcher(); |
| 989 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); | 990 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); |
| 990 } | 991 } |
| 991 | 992 |
| 992 class AsyncOpenFileSystemURLCallbackTranslator : | 993 class AsyncOpenFileSystemURLCallbackTranslator |
| 993 public fileapi::FileSystemCallbackDispatcher { | 994 : public fileapi::FileSystemCallbackDispatcher { |
| 994 public: | 995 public: |
| 995 AsyncOpenFileSystemURLCallbackTranslator( | 996 AsyncOpenFileSystemURLCallbackTranslator( |
| 996 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback) | 997 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback) |
| 997 : callback_(callback) { | 998 : callback_(callback) { |
| 998 } | 999 } |
| 999 | 1000 |
| 1000 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} | 1001 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} |
| 1001 | 1002 |
| 1002 virtual void DidSucceed() { | 1003 virtual void DidSucceed() { |
| 1003 NOTREACHED(); | 1004 NOTREACHED(); |
| 1004 } | 1005 } |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 if (!base::SharedMemory::IsHandleValid(handle)) { | 1329 if (!base::SharedMemory::IsHandleValid(handle)) { |
| 1329 DLOG(WARNING) << "Browser failed to allocate shared memory"; | 1330 DLOG(WARNING) << "Browser failed to allocate shared memory"; |
| 1330 return NULL; | 1331 return NULL; |
| 1331 } | 1332 } |
| 1332 return new base::SharedMemory(handle, false); | 1333 return new base::SharedMemory(handle, false); |
| 1333 } | 1334 } |
| 1334 | 1335 |
| 1335 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { | 1336 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { |
| 1336 return ppapi::Preferences(render_view_->webkit_preferences()); | 1337 return ppapi::Preferences(render_view_->webkit_preferences()); |
| 1337 } | 1338 } |
| OLD | NEW |