Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / pepper_audio_input_host.cc
index 59b4f98..0da9cd1 100644 (file)
 #include "content/renderer/pepper/pepper_platform_audio_input.h"
 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
-#include "content/renderer/render_view_impl.h"
+#include "content/renderer/render_frame_impl.h"
 #include "ipc/ipc_message.h"
 #include "ppapi/c/pp_errors.h"
 #include "ppapi/host/dispatch_host_message.h"
 #include "ppapi/host/ppapi_host.h"
 #include "ppapi/proxy/ppapi_messages.h"
 #include "ppapi/proxy/serialized_structs.h"
-#include "third_party/WebKit/public/web/WebDocument.h"
-#include "third_party/WebKit/public/web/WebElement.h"
-#include "third_party/WebKit/public/web/WebPluginContainer.h"
 
 namespace content {
 
@@ -42,23 +39,19 @@ base::PlatformFile ConvertSharedMemoryHandle(
 
 }  // namespace
 
-PepperAudioInputHost::PepperAudioInputHost(
-    RendererPpapiHostImpl* host,
-    PP_Instance instance,
-    PP_Resource resource)
+PepperAudioInputHost::PepperAudioInputHost(RendererPpapiHostImpl* host,
+                                           PP_Instance instance,
+                                           PP_Resource resource)
     : ResourceHost(host->GetPpapiHost(), instance, resource),
       renderer_ppapi_host_(host),
       audio_input_(NULL),
-      enumeration_helper_(
-          this,
-          PepperMediaDeviceManager::GetForRenderView(
-              host->GetRenderViewForInstance(pp_instance())),
-          PP_DEVICETYPE_DEV_AUDIOCAPTURE) {
-}
+      enumeration_helper_(this,
+                          PepperMediaDeviceManager::GetForRenderFrame(
+                              host->GetRenderFrameForInstance(pp_instance())),
+                          PP_DEVICETYPE_DEV_AUDIOCAPTURE,
+                          host->GetDocumentURL(instance)) {}
 
-PepperAudioInputHost::~PepperAudioInputHost() {
-  Close();
-}
+PepperAudioInputHost::~PepperAudioInputHost() { Close(); }
 
 int32_t PepperAudioInputHost::OnResourceMessageReceived(
     const IPC::Message& msg,
@@ -67,13 +60,12 @@ int32_t PepperAudioInputHost::OnResourceMessageReceived(
   if (enumeration_helper_.HandleResourceMessage(msg, context, &result))
     return result;
 
-  IPC_BEGIN_MESSAGE_MAP(PepperAudioInputHost, msg)
+  PPAPI_BEGIN_MESSAGE_MAP(PepperAudioInputHost, msg)
     PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_AudioInput_Open, OnOpen)
     PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_AudioInput_StartOrStop,
-                                      OnStartOrStop);
-    PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_AudioInput_Close,
-                                        OnClose);
-  IPC_END_MESSAGE_MAP()
+                                      OnStartOrStop)
+    PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_AudioInput_Close, OnClose)
+  PPAPI_END_MESSAGE_MAP()
   return PP_ERROR_FAILED;
 }
 
@@ -85,38 +77,37 @@ void PepperAudioInputHost::StreamCreated(
 }
 
 void PepperAudioInputHost::StreamCreationFailed() {
-  OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0,
+  OnOpenComplete(PP_ERROR_FAILED,
+                 base::SharedMemory::NULLHandle(),
+                 0,
                  base::SyncSocket::kInvalidHandle);
 }
 
-int32_t PepperAudioInputHost::OnOpen(
-    ppapi::host::HostMessageContext* context,
-    const std::string& device_id,
-    PP_AudioSampleRate sample_rate,
-    uint32_t sample_frame_count) {
-  if (open_context_)
+int32_t PepperAudioInputHost::OnOpen(ppapi::host::HostMessageContext* context,
+                                     const std::string& device_id,
+                                     PP_AudioSampleRate sample_rate,
+                                     uint32_t sample_frame_count) {
+  if (open_context_.is_valid())
     return PP_ERROR_INPROGRESS;
   if (audio_input_)
     return PP_ERROR_FAILED;
 
-  PepperPluginInstanceImpl* instance =
-      renderer_ppapi_host_->GetPluginInstanceImpl(pp_instance());
-  if (!instance)
+  GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance());
+  if (!document_url.is_valid())
     return PP_ERROR_FAILED;
 
   // When it is done, we'll get called back on StreamCreated() or
   // StreamCreationFailed().
-  RenderViewImpl* render_view = static_cast<RenderViewImpl*>(
-      renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()));
-
   audio_input_ = PepperPlatformAudioInput::Create(
-      render_view->AsWeakPtr(), device_id,
-      instance->container()->element().document().url(),
+      renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance())->
+          GetRoutingID(),
+      device_id,
+      document_url,
       static_cast<int>(sample_rate),
-      static_cast<int>(sample_frame_count), this);
+      static_cast<int>(sample_frame_count),
+      this);
   if (audio_input_) {
-    open_context_.reset(new ppapi::host::ReplyMessageContext(
-        context->MakeReplyMessageContext()));
+    open_context_ = context->MakeReplyMessageContext();
     return PP_OK_COMPLETIONPENDING;
   } else {
     return PP_ERROR_FAILED;
@@ -150,7 +141,7 @@ void PepperAudioInputHost::OnOpenComplete(
   base::SyncSocket scoped_socket(socket_handle);
   base::SharedMemory scoped_shared_memory(shared_memory_handle, false);
 
-  if (!open_context_) {
+  if (!open_context_.is_valid()) {
     NOTREACHED();
     return;
   }
@@ -176,12 +167,9 @@ void PepperAudioInputHost::OnOpenComplete(
   // inconvenient to clean up. Our IPC code will automatically handle this for
   // us, as long as the remote side always closes the handles it receives, even
   // in the failure case.
-  open_context_->params.set_result(result);
-  open_context_->params.AppendHandle(serialized_socket_handle);
-  open_context_->params.AppendHandle(serialized_shared_memory_handle);
-
-  host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply());
-  open_context_.reset();
+  open_context_.params.AppendHandle(serialized_socket_handle);
+  open_context_.params.AppendHandle(serialized_shared_memory_handle);
+  SendOpenReply(result);
 }
 
 int32_t PepperAudioInputHost::GetRemoteHandles(
@@ -209,12 +197,14 @@ void PepperAudioInputHost::Close() {
   audio_input_->ShutDown();
   audio_input_ = NULL;
 
-  if (open_context_) {
-    open_context_->params.set_result(PP_ERROR_ABORTED);
-    host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply());
-    open_context_.reset();
-  }
+  if (open_context_.is_valid())
+    SendOpenReply(PP_ERROR_ABORTED);
 }
 
-}  // namespace content
+void PepperAudioInputHost::SendOpenReply(int32_t result) {
+  open_context_.params.set_result(result);
+  host()->SendReply(open_context_, PpapiPluginMsg_AudioInput_OpenReply());
+  open_context_ = ppapi::host::ReplyMessageContext();
+}
 
+}  // namespace content