OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/common/content_export.h" |
| 13 #include "ppapi/c/dev/ppb_device_ref_dev.h" |
| 14 |
| 15 namespace ppapi { |
| 16 struct DeviceRefData; |
| 17 |
| 18 namespace host { |
| 19 struct HostMessageContext; |
| 20 struct ReplyMessageContext; |
| 21 class ResourceHost; |
| 22 } |
| 23 } |
| 24 |
| 25 namespace IPC { |
| 26 class Message; |
| 27 } |
| 28 |
| 29 namespace webkit { |
| 30 namespace ppapi { |
| 31 class PluginDelegate; |
| 32 } |
| 33 } |
| 34 |
| 35 namespace content { |
| 36 |
| 37 // Resource hosts that support device enumeration can use this class to filter |
| 38 // and process PpapiHostMsg_DeviceEnumeration_* messages. |
| 39 // TODO(yzshen): Refactor ppapi::host::ResourceMessageFilter to support message |
| 40 // handling on the same thread, and then derive this class from the filter |
| 41 // class. |
| 42 class CONTENT_EXPORT PepperDeviceEnumerationHostHelper { |
| 43 public: |
| 44 class Delegate { |
| 45 public: |
| 46 virtual ~Delegate() {} |
| 47 |
| 48 // TODO(yzshen): Move the relevant functionality out of PluginDelegate and |
| 49 // get rid of this method. |
| 50 virtual webkit::ppapi::PluginDelegate* GetPluginDelegate() = 0; |
| 51 }; |
| 52 |
| 53 // |resource_host| and |delegate| must outlive this object. |
| 54 PepperDeviceEnumerationHostHelper(ppapi::host::ResourceHost* resource_host, |
| 55 Delegate* delegate, |
| 56 PP_DeviceType_Dev device_type); |
| 57 ~PepperDeviceEnumerationHostHelper(); |
| 58 |
| 59 // Returns true if the message has been handled. |
| 60 bool HandleResourceMessage(const IPC::Message& msg, |
| 61 ppapi::host::HostMessageContext* context, |
| 62 int32_t* result); |
| 63 |
| 64 private: |
| 65 class ScopedRequest; |
| 66 |
| 67 // Has a different signature than HandleResourceMessage() in order to utilize |
| 68 // message dispatching macros. |
| 69 int32_t InternalHandleResourceMessage( |
| 70 const IPC::Message& msg, |
| 71 ppapi::host::HostMessageContext* context, |
| 72 bool* handled); |
| 73 |
| 74 int32_t OnMsgEnumerateDevices(ppapi::host::HostMessageContext* context); |
| 75 int32_t OnMsgMonitorDeviceChange(ppapi::host::HostMessageContext* context, |
| 76 uint32_t callback_id); |
| 77 int32_t OnMsgStopMonitoringDeviceChange( |
| 78 ppapi::host::HostMessageContext* context); |
| 79 |
| 80 void OnEnumerateDevicesComplete( |
| 81 int request_id, |
| 82 bool succeeded, |
| 83 const std::vector<ppapi::DeviceRefData>& devices); |
| 84 void OnNotifyDeviceChange( |
| 85 uint32_t callback_id, |
| 86 int request_id, |
| 87 bool succeeded, |
| 88 const std::vector<ppapi::DeviceRefData>& devices); |
| 89 |
| 90 // Non-owning pointers. |
| 91 ppapi::host::ResourceHost* resource_host_; |
| 92 Delegate* delegate_; |
| 93 |
| 94 PP_DeviceType_Dev device_type_; |
| 95 |
| 96 scoped_ptr<ScopedRequest> enumerate_; |
| 97 scoped_ptr<ScopedRequest> monitor_; |
| 98 |
| 99 scoped_ptr<ppapi::host::ReplyMessageContext> enumerate_devices_context_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(PepperDeviceEnumerationHostHelper); |
| 102 }; |
| 103 |
| 104 } // namespace content |
| 105 |
| 106 #endif // CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ |
OLD | NEW |