| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
| 16 #include "base/sync_socket.h" | 16 #include "base/sync_socket.h" |
| 17 #include "base/task.h" | 17 #include "base/task.h" |
| 18 #include "base/time.h" | 18 #include "base/time.h" |
| 19 #include "content/common/child_process_messages.h" | 19 #include "content/common/child_process_messages.h" |
| 20 #include "content/common/child_process.h" |
| 20 #include "content/common/child_thread.h" | 21 #include "content/common/child_thread.h" |
| 21 #include "content/common/content_switches.h" | 22 #include "content/common/content_switches.h" |
| 22 #include "content/common/file_system/file_system_dispatcher.h" | 23 #include "content/common/file_system/file_system_dispatcher.h" |
| 23 #include "content/common/media/audio_messages.h" | 24 #include "content/common/media/audio_messages.h" |
| 24 #include "content/common/pepper_file_messages.h" | 25 #include "content/common/pepper_file_messages.h" |
| 25 #include "content/common/pepper_plugin_registry.h" | 26 #include "content/common/pepper_plugin_registry.h" |
| 26 #include "content/common/pepper_messages.h" | 27 #include "content/common/pepper_messages.h" |
| 27 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
| 28 #include "content/renderer/content_renderer_client.h" | 29 #include "content/renderer/content_renderer_client.h" |
| 29 #include "content/renderer/gpu/command_buffer_proxy.h" | 30 #include "content/renderer/gpu/command_buffer_proxy.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 153 |
| 153 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); | 154 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 | 157 |
| 157 class PlatformAudioImpl | 158 class PlatformAudioImpl |
| 158 : public webkit::ppapi::PluginDelegate::PlatformAudio, | 159 : public webkit::ppapi::PluginDelegate::PlatformAudio, |
| 159 public AudioMessageFilter::Delegate, | 160 public AudioMessageFilter::Delegate, |
| 160 public base::RefCountedThreadSafe<PlatformAudioImpl> { | 161 public base::RefCountedThreadSafe<PlatformAudioImpl> { |
| 161 public: | 162 public: |
| 162 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) | 163 explicit PlatformAudioImpl() |
| 163 : client_(NULL), filter_(filter), stream_id_(0), | 164 : client_(NULL), stream_id_(0), |
| 164 main_message_loop_(MessageLoop::current()) { | 165 main_message_loop_(MessageLoop::current()) { |
| 165 DCHECK(filter_); | 166 filter_ = RenderThread::current()->audio_message_filter(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 virtual ~PlatformAudioImpl() { | 169 virtual ~PlatformAudioImpl() { |
| 169 // Make sure we have been shut down. Warning: this will usually happen on | 170 // Make sure we have been shut down. Warning: this will usually happen on |
| 170 // the I/O thread! | 171 // the I/O thread! |
| 171 DCHECK_EQ(0, stream_id_); | 172 DCHECK_EQ(0, stream_id_); |
| 172 DCHECK(!client_); | 173 DCHECK(!client_); |
| 173 } | 174 } |
| 174 | 175 |
| 175 // Initialize this audio context. StreamCreated() will be called when the | 176 // Initialize this audio context. StreamCreated() will be called when the |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 233 |
| 233 client_ = client; | 234 client_ = client; |
| 234 | 235 |
| 235 AudioParameters params; | 236 AudioParameters params; |
| 236 params.format = AudioParameters::AUDIO_PCM_LINEAR; | 237 params.format = AudioParameters::AUDIO_PCM_LINEAR; |
| 237 params.channels = 2; | 238 params.channels = 2; |
| 238 params.sample_rate = sample_rate; | 239 params.sample_rate = sample_rate; |
| 239 params.bits_per_sample = 16; | 240 params.bits_per_sample = 16; |
| 240 params.samples_per_packet = sample_count; | 241 params.samples_per_packet = sample_count; |
| 241 | 242 |
| 242 filter_->message_loop()->PostTask(FROM_HERE, | 243 ChildProcess::current()->io_message_loop()->PostTask( |
| 244 FROM_HERE, |
| 243 NewRunnableMethod(this, &PlatformAudioImpl::InitializeOnIOThread, | 245 NewRunnableMethod(this, &PlatformAudioImpl::InitializeOnIOThread, |
| 244 params)); | 246 params)); |
| 245 return true; | 247 return true; |
| 246 } | 248 } |
| 247 | 249 |
| 248 bool PlatformAudioImpl::StartPlayback() { | 250 bool PlatformAudioImpl::StartPlayback() { |
| 249 if (filter_) { | 251 if (filter_) { |
| 250 filter_->message_loop()->PostTask(FROM_HERE, | 252 ChildProcess::current()->io_message_loop()->PostTask( |
| 253 FROM_HERE, |
| 251 NewRunnableMethod(this, &PlatformAudioImpl::StartPlaybackOnIOThread)); | 254 NewRunnableMethod(this, &PlatformAudioImpl::StartPlaybackOnIOThread)); |
| 252 return true; | 255 return true; |
| 253 } | 256 } |
| 254 return false; | 257 return false; |
| 255 } | 258 } |
| 256 | 259 |
| 257 bool PlatformAudioImpl::StopPlayback() { | 260 bool PlatformAudioImpl::StopPlayback() { |
| 258 if (filter_) { | 261 if (filter_) { |
| 259 filter_->message_loop()->PostTask(FROM_HERE, | 262 ChildProcess::current()->io_message_loop()->PostTask( |
| 263 FROM_HERE, |
| 260 NewRunnableMethod(this, &PlatformAudioImpl::StopPlaybackOnIOThread)); | 264 NewRunnableMethod(this, &PlatformAudioImpl::StopPlaybackOnIOThread)); |
| 261 return true; | 265 return true; |
| 262 } | 266 } |
| 263 return false; | 267 return false; |
| 264 } | 268 } |
| 265 | 269 |
| 266 void PlatformAudioImpl::ShutDown() { | 270 void PlatformAudioImpl::ShutDown() { |
| 267 // Called on the main thread to stop all audio callbacks. We must only change | 271 // 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. | 272 // the client on the main thread, and the delegates from the I/O thread. |
| 269 client_ = NULL; | 273 client_ = NULL; |
| 270 filter_->message_loop()->PostTask(FROM_HERE, | 274 ChildProcess::current()->io_message_loop()->PostTask( |
| 275 FROM_HERE, |
| 271 NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread)); | 276 NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread)); |
| 272 } | 277 } |
| 273 | 278 |
| 274 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { | 279 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { |
| 275 stream_id_ = filter_->AddDelegate(this); | 280 stream_id_ = filter_->AddDelegate(this); |
| 276 filter_->Send(new AudioHostMsg_CreateStream(0, stream_id_, params, true)); | 281 filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params, true)); |
| 277 } | 282 } |
| 278 | 283 |
| 279 void PlatformAudioImpl::StartPlaybackOnIOThread() { | 284 void PlatformAudioImpl::StartPlaybackOnIOThread() { |
| 280 if (stream_id_) | 285 if (stream_id_) |
| 281 filter_->Send(new AudioHostMsg_PlayStream(0, stream_id_)); | 286 filter_->Send(new AudioHostMsg_PlayStream(stream_id_)); |
| 282 } | 287 } |
| 283 | 288 |
| 284 void PlatformAudioImpl::StopPlaybackOnIOThread() { | 289 void PlatformAudioImpl::StopPlaybackOnIOThread() { |
| 285 if (stream_id_) | 290 if (stream_id_) |
| 286 filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_)); | 291 filter_->Send(new AudioHostMsg_PauseStream(stream_id_)); |
| 287 } | 292 } |
| 288 | 293 |
| 289 void PlatformAudioImpl::ShutDownOnIOThread() { | 294 void PlatformAudioImpl::ShutDownOnIOThread() { |
| 290 // Make sure we don't call shutdown more than once. | 295 // Make sure we don't call shutdown more than once. |
| 291 if (!stream_id_) | 296 if (!stream_id_) |
| 292 return; | 297 return; |
| 293 | 298 |
| 294 filter_->Send(new AudioHostMsg_CloseStream(0, stream_id_)); | 299 filter_->Send(new AudioHostMsg_CloseStream(stream_id_)); |
| 295 filter_->RemoveDelegate(stream_id_); | 300 filter_->RemoveDelegate(stream_id_); |
| 296 stream_id_ = 0; | 301 stream_id_ = 0; |
| 297 | 302 |
| 298 Release(); // Release for the delegate, balances out the reference taken in | 303 Release(); // Release for the delegate, balances out the reference taken in |
| 299 // PepperPluginDelegateImpl::CreateAudio. | 304 // PepperPluginDelegateImpl::CreateAudio. |
| 300 } | 305 } |
| 301 | 306 |
| 302 void PlatformAudioImpl::OnLowLatencyCreated( | 307 void PlatformAudioImpl::OnLowLatencyCreated( |
| 303 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, | 308 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, |
| 304 uint32 length) { | 309 uint32 length) { |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, | 847 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, |
| 843 int index) { | 848 int index) { |
| 844 render_view_->reportFindInPageSelection( | 849 render_view_->reportFindInPageSelection( |
| 845 identifier, index + 1, WebKit::WebRect()); | 850 identifier, index + 1, WebKit::WebRect()); |
| 846 } | 851 } |
| 847 | 852 |
| 848 webkit::ppapi::PluginDelegate::PlatformAudio* | 853 webkit::ppapi::PluginDelegate::PlatformAudio* |
| 849 PepperPluginDelegateImpl::CreateAudio( | 854 PepperPluginDelegateImpl::CreateAudio( |
| 850 uint32_t sample_rate, uint32_t sample_count, | 855 uint32_t sample_rate, uint32_t sample_count, |
| 851 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { | 856 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { |
| 852 scoped_refptr<PlatformAudioImpl> audio( | 857 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); |
| 853 new PlatformAudioImpl(render_view_->audio_message_filter())); | |
| 854 if (audio->Initialize(sample_rate, sample_count, client)) { | 858 if (audio->Initialize(sample_rate, sample_count, client)) { |
| 855 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). | 859 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). |
| 856 return audio.release(); | 860 return audio.release(); |
| 857 } else { | 861 } else { |
| 858 return NULL; | 862 return NULL; |
| 859 } | 863 } |
| 860 } | 864 } |
| 861 | 865 |
| 862 // If a broker has not already been created for this plugin, creates one. | 866 // If a broker has not already been created for this plugin, creates one. |
| 863 webkit::ppapi::PluginDelegate::PpapiBroker* | 867 webkit::ppapi::PluginDelegate::PpapiBroker* |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 } | 986 } |
| 983 | 987 |
| 984 bool PepperPluginDelegateImpl::ReadDirectory( | 988 bool PepperPluginDelegateImpl::ReadDirectory( |
| 985 const GURL& directory_path, | 989 const GURL& directory_path, |
| 986 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 990 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
| 987 FileSystemDispatcher* file_system_dispatcher = | 991 FileSystemDispatcher* file_system_dispatcher = |
| 988 ChildThread::current()->file_system_dispatcher(); | 992 ChildThread::current()->file_system_dispatcher(); |
| 989 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); | 993 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); |
| 990 } | 994 } |
| 991 | 995 |
| 992 class AsyncOpenFileSystemURLCallbackTranslator : | 996 class AsyncOpenFileSystemURLCallbackTranslator |
| 993 public fileapi::FileSystemCallbackDispatcher { | 997 : public fileapi::FileSystemCallbackDispatcher { |
| 994 public: | 998 public: |
| 995 AsyncOpenFileSystemURLCallbackTranslator( | 999 AsyncOpenFileSystemURLCallbackTranslator( |
| 996 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback) | 1000 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback) |
| 997 : callback_(callback) { | 1001 : callback_(callback) { |
| 998 } | 1002 } |
| 999 | 1003 |
| 1000 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} | 1004 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} |
| 1001 | 1005 |
| 1002 virtual void DidSucceed() { | 1006 virtual void DidSucceed() { |
| 1003 NOTREACHED(); | 1007 NOTREACHED(); |
| 1004 } | 1008 } |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 if (!base::SharedMemory::IsHandleValid(handle)) { | 1332 if (!base::SharedMemory::IsHandleValid(handle)) { |
| 1329 DLOG(WARNING) << "Browser failed to allocate shared memory"; | 1333 DLOG(WARNING) << "Browser failed to allocate shared memory"; |
| 1330 return NULL; | 1334 return NULL; |
| 1331 } | 1335 } |
| 1332 return new base::SharedMemory(handle, false); | 1336 return new base::SharedMemory(handle, false); |
| 1333 } | 1337 } |
| 1334 | 1338 |
| 1335 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { | 1339 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { |
| 1336 return ppapi::Preferences(render_view_->webkit_preferences()); | 1340 return ppapi::Preferences(render_view_->webkit_preferences()); |
| 1337 } | 1341 } |
| OLD | NEW |