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 PPAPI_PROXY_PPB_INSTANCE_PROXY_H_ 6 #define PPAPI_PROXY_PPB_INSTANCE_PROXY_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "ppapi/c/pp_instance.h" 12 #include "ppapi/c/pp_resource.h" 13 #include "ppapi/c/pp_var.h" 14 #include "ppapi/proxy/interface_proxy.h" 15 #include "ppapi/proxy/proxy_completion_callback_factory.h" 16 #include "ppapi/shared_impl/host_resource.h" 17 #include "ppapi/shared_impl/ppb_instance_shared.h" 18 #include "ppapi/shared_impl/singleton_resource_id.h" 19 #include "ppapi/thunk/ppb_instance_api.h" 20 #include "ppapi/utility/completion_callback_factory.h" 21 22 // Windows headers interfere with this file. 23 #ifdef PostMessage 24 #undef PostMessage 25 #endif 26 27 struct PP_DecryptedBlockInfo; 28 struct PP_DecryptedFrameInfo; 29 30 namespace ppapi { 31 namespace proxy { 32 33 class SerializedVarReceiveInput; 34 class SerializedVarOutParam; 35 class SerializedVarReturnValue; 36 37 class PPB_Instance_Proxy : public InterfaceProxy, 38 public PPB_Instance_Shared { 39 public: 40 PPB_Instance_Proxy(Dispatcher* dispatcher); 41 virtual ~PPB_Instance_Proxy(); 42 43 // InterfaceProxy implementation. 44 virtual bool OnMessageReceived(const IPC::Message& msg); 45 46 // PPB_Instance_API implementation. 47 virtual PP_Bool BindGraphics(PP_Instance instance, 48 PP_Resource device) OVERRIDE; 49 virtual PP_Bool IsFullFrame(PP_Instance instance) OVERRIDE; 50 virtual const ViewData* GetViewData(PP_Instance instance) OVERRIDE; 51 virtual PP_Bool FlashIsFullscreen(PP_Instance instance) OVERRIDE; 52 virtual PP_Var GetWindowObject(PP_Instance instance) OVERRIDE; 53 virtual PP_Var GetOwnerElementObject(PP_Instance instance) OVERRIDE; 54 virtual PP_Var ExecuteScript(PP_Instance instance, 55 PP_Var script, 56 PP_Var* exception) OVERRIDE; 57 virtual uint32_t GetAudioHardwareOutputSampleRate(PP_Instance instance) 58 OVERRIDE; 59 virtual uint32_t GetAudioHardwareOutputBufferSize(PP_Instance instance) 60 OVERRIDE; 61 virtual PP_Var GetDefaultCharSet(PP_Instance instance) OVERRIDE; 62 virtual void SetPluginToHandleFindRequests(PP_Instance instance) OVERRIDE; 63 virtual void NumberOfFindResultsChanged(PP_Instance instance, 64 int32_t total, 65 PP_Bool final_result) OVERRIDE; 66 virtual void SelectedFindResultChanged(PP_Instance instance, 67 int32_t index) OVERRIDE; 68 virtual void SetTickmarks(PP_Instance instance, 69 const PP_Rect* tickmarks, 70 uint32_t count) OVERRIDE; 71 virtual PP_Bool IsFullscreen(PP_Instance instance) OVERRIDE; 72 virtual PP_Bool SetFullscreen(PP_Instance instance, 73 PP_Bool fullscreen) OVERRIDE; 74 virtual PP_Bool GetScreenSize(PP_Instance instance, 75 PP_Size* size) OVERRIDE; 76 virtual Resource* GetSingletonResource(PP_Instance instance, 77 SingletonResourceID id) OVERRIDE; 78 virtual int32_t RequestInputEvents(PP_Instance instance, 79 uint32_t event_classes) OVERRIDE; 80 virtual int32_t RequestFilteringInputEvents(PP_Instance instance, 81 uint32_t event_classes) OVERRIDE; 82 virtual void StartTrackingLatency(PP_Instance instance) OVERRIDE; 83 virtual void ClearInputEventRequest(PP_Instance instance, 84 uint32_t event_classes) OVERRIDE; 85 virtual void ZoomChanged(PP_Instance instance, double factor) OVERRIDE; 86 virtual void ZoomLimitsChanged(PP_Instance instance, 87 double minimum_factor, 88 double maximium_factor) OVERRIDE; 89 virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE; 90 virtual int32_t RegisterMessageHandler(PP_Instance instance, 91 void* user_data, 92 const PPP_MessageHandler_0_2* handler, 93 PP_Resource message_loop) OVERRIDE; 94 virtual int32_t RegisterMessageHandler_1_1_Deprecated( 95 PP_Instance instance, 96 void* user_data, 97 const PPP_MessageHandler_0_1_Deprecated* handler, 98 PP_Resource message_loop) OVERRIDE; 99 virtual void UnregisterMessageHandler(PP_Instance instance) OVERRIDE; 100 virtual PP_Bool SetCursor(PP_Instance instance, 101 PP_MouseCursor_Type type, 102 PP_Resource image, 103 const PP_Point* hot_spot) OVERRIDE; 104 virtual int32_t LockMouse(PP_Instance instance, 105 scoped_refptr<TrackedCallback> callback) OVERRIDE; 106 virtual void UnlockMouse(PP_Instance instance) OVERRIDE; 107 virtual void SetTextInputType(PP_Instance instance, 108 PP_TextInput_Type type) OVERRIDE; 109 virtual void UpdateCaretPosition(PP_Instance instance, 110 const PP_Rect& caret, 111 const PP_Rect& bounding_box) OVERRIDE; 112 virtual void CancelCompositionText(PP_Instance instance) OVERRIDE; 113 virtual void SelectionChanged(PP_Instance instance) OVERRIDE; 114 virtual void UpdateSurroundingText(PP_Instance instance, 115 const char* text, 116 uint32_t caret, 117 uint32_t anchor) OVERRIDE; 118 virtual PP_Var GetDocumentURL(PP_Instance instance, 119 PP_URLComponents_Dev* components) OVERRIDE; 120 #if !defined(OS_NACL) 121 virtual PP_Var ResolveRelativeToDocument( 122 PP_Instance instance, 123 PP_Var relative, 124 PP_URLComponents_Dev* components) OVERRIDE; 125 virtual PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) OVERRIDE; 126 virtual PP_Bool DocumentCanAccessDocument(PP_Instance instance, 127 PP_Instance target) OVERRIDE; 128 virtual PP_Var GetPluginInstanceURL( 129 PP_Instance instance, 130 PP_URLComponents_Dev* components) OVERRIDE; 131 virtual PP_Var GetPluginReferrerURL( 132 PP_Instance instance, 133 PP_URLComponents_Dev* components) OVERRIDE; 134 virtual void PromiseResolved(PP_Instance instance, 135 uint32 promise_id) OVERRIDE; 136 virtual void PromiseResolvedWithSession(PP_Instance instance, 137 uint32 promise_id, 138 PP_Var web_session_id_var) OVERRIDE; 139 virtual void PromiseResolvedWithKeyIds(PP_Instance instance, 140 uint32 promise_id, 141 PP_Var key_ids_var) OVERRIDE; 142 virtual void PromiseRejected(PP_Instance instance, 143 uint32 promise_id, 144 PP_CdmExceptionCode exception_code, 145 uint32 system_code, 146 PP_Var error_description_var) OVERRIDE; 147 virtual void SessionMessage(PP_Instance instance, 148 PP_Var web_session_id_var, 149 PP_Var message_var, 150 PP_Var destination_url_var) OVERRIDE; 151 virtual void SessionKeysChange(PP_Instance instance, 152 PP_Var web_session_id_var, 153 PP_Bool has_additional_usable_key) OVERRIDE; 154 virtual void SessionExpirationChange(PP_Instance instance, 155 PP_Var web_session_id_var, 156 PP_Time new_expiry_time) OVERRIDE; 157 virtual void SessionReady(PP_Instance instance, 158 PP_Var web_session_id_var) OVERRIDE; 159 virtual void SessionClosed(PP_Instance instance, 160 PP_Var web_session_id_var) OVERRIDE; 161 virtual void SessionError(PP_Instance instance, 162 PP_Var web_session_id_var, 163 PP_CdmExceptionCode exception_code, 164 uint32 system_code, 165 PP_Var error_description_var) OVERRIDE; 166 virtual void DeliverBlock(PP_Instance instance, 167 PP_Resource decrypted_block, 168 const PP_DecryptedBlockInfo* block_info) OVERRIDE; 169 virtual void DecoderInitializeDone(PP_Instance instance, 170 PP_DecryptorStreamType decoder_type, 171 uint32_t request_id, 172 PP_Bool success) OVERRIDE; 173 virtual void DecoderDeinitializeDone(PP_Instance instance, 174 PP_DecryptorStreamType decoder_type, 175 uint32_t request_id) OVERRIDE; 176 virtual void DecoderResetDone(PP_Instance instance, 177 PP_DecryptorStreamType decoder_type, 178 uint32_t request_id) OVERRIDE; 179 virtual void DeliverFrame(PP_Instance instance, 180 PP_Resource decrypted_frame, 181 const PP_DecryptedFrameInfo* frame_info) OVERRIDE; 182 virtual void DeliverSamples( 183 PP_Instance instance, 184 PP_Resource audio_frames, 185 const PP_DecryptedSampleInfo* sample_info) OVERRIDE; 186 #endif // !defined(OS_NACL) 187 188 static const ApiID kApiID = API_ID_PPB_INSTANCE; 189 190 private: 191 // Plugin -> Host message handlers. 192 void OnHostMsgGetWindowObject(PP_Instance instance, 193 SerializedVarReturnValue result); 194 void OnHostMsgGetOwnerElementObject(PP_Instance instance, 195 SerializedVarReturnValue result); 196 void OnHostMsgBindGraphics(PP_Instance instance, 197 PP_Resource device); 198 void OnHostMsgIsFullFrame(PP_Instance instance, PP_Bool* result); 199 void OnHostMsgExecuteScript(PP_Instance instance, 200 SerializedVarReceiveInput script, 201 SerializedVarOutParam out_exception, 202 SerializedVarReturnValue result); 203 void OnHostMsgGetAudioHardwareOutputSampleRate(PP_Instance instance, 204 uint32_t *result); 205 void OnHostMsgGetAudioHardwareOutputBufferSize(PP_Instance instance, 206 uint32_t *result); 207 void OnHostMsgGetDefaultCharSet(PP_Instance instance, 208 SerializedVarReturnValue result); 209 void OnHostMsgSetPluginToHandleFindRequests(PP_Instance instance); 210 void OnHostMsgNumberOfFindResultsChanged(PP_Instance instance, 211 int32_t total, 212 PP_Bool final_result); 213 void OnHostMsgSelectFindResultChanged(PP_Instance instance, 214 int32_t index); 215 void OnHostMsgSetTickmarks(PP_Instance instance, 216 const std::vector<PP_Rect>& tickmarks); 217 void OnHostMsgSetFullscreen(PP_Instance instance, 218 PP_Bool fullscreen, 219 PP_Bool* result); 220 void OnHostMsgGetScreenSize(PP_Instance instance, 221 PP_Bool* result, 222 PP_Size* size); 223 void OnHostMsgRequestInputEvents(PP_Instance instance, 224 bool is_filtering, 225 uint32_t event_classes); 226 void OnHostMsgStartTrackingLatency(PP_Instance instance); 227 void OnHostMsgClearInputEvents(PP_Instance instance, 228 uint32_t event_classes); 229 void OnHostMsgPostMessage(PP_Instance instance, 230 SerializedVarReceiveInput message); 231 void OnHostMsgLockMouse(PP_Instance instance); 232 void OnHostMsgUnlockMouse(PP_Instance instance); 233 void OnHostMsgSetCursor(PP_Instance instance, 234 int32_t type, 235 const ppapi::HostResource& custom_image, 236 const PP_Point& hot_spot); 237 void OnHostMsgSetTextInputType(PP_Instance instance, PP_TextInput_Type type); 238 void OnHostMsgUpdateCaretPosition(PP_Instance instance, 239 const PP_Rect& caret, 240 const PP_Rect& bounding_box); 241 void OnHostMsgCancelCompositionText(PP_Instance instance); 242 void OnHostMsgUpdateSurroundingText( 243 PP_Instance instance, 244 const std::string& text, 245 uint32_t caret, 246 uint32_t anchor); 247 void OnHostMsgGetDocumentURL(PP_Instance instance, 248 PP_URLComponents_Dev* components, 249 SerializedVarReturnValue result); 250 251 #if !defined(OS_NACL) 252 void OnHostMsgResolveRelativeToDocument(PP_Instance instance, 253 SerializedVarReceiveInput relative, 254 SerializedVarReturnValue result); 255 void OnHostMsgDocumentCanRequest(PP_Instance instance, 256 SerializedVarReceiveInput url, 257 PP_Bool* result); 258 void OnHostMsgDocumentCanAccessDocument(PP_Instance active, 259 PP_Instance target, 260 PP_Bool* result); 261 void OnHostMsgGetPluginInstanceURL(PP_Instance instance, 262 SerializedVarReturnValue result); 263 void OnHostMsgGetPluginReferrerURL(PP_Instance instance, 264 SerializedVarReturnValue result); 265 266 virtual void OnHostMsgPromiseResolved(PP_Instance instance, 267 uint32_t promise_id); 268 virtual void OnHostMsgPromiseResolvedWithSession( 269 PP_Instance instance, 270 uint32_t promise_id, 271 SerializedVarReceiveInput web_session_id); 272 virtual void OnHostMsgPromiseResolvedWithKeyIds( 273 PP_Instance instance, 274 uint32 promise_id, 275 const std::vector<std::vector<uint8_t> >& key_ids); 276 virtual void OnHostMsgPromiseRejected( 277 PP_Instance instance, 278 uint32_t promise_id, 279 PP_CdmExceptionCode exception_code, 280 uint32_t system_code, 281 SerializedVarReceiveInput error_description); 282 virtual void OnHostMsgSessionMessage( 283 PP_Instance instance, 284 SerializedVarReceiveInput web_session_id, 285 SerializedVarReceiveInput message, 286 SerializedVarReceiveInput destination_url); 287 virtual void OnHostMsgSessionKeysChange(PP_Instance instance, 288 const std::string& web_session_id, 289 PP_Bool has_additional_usable_key); 290 virtual void OnHostMsgSessionExpirationChange( 291 PP_Instance instance, 292 const std::string& web_session_id, 293 PP_Time new_expiry_time); 294 virtual void OnHostMsgSessionReady(PP_Instance instance, 295 SerializedVarReceiveInput web_session_id); 296 virtual void OnHostMsgSessionClosed(PP_Instance instance, 297 SerializedVarReceiveInput web_session_id); 298 virtual void OnHostMsgSessionError( 299 PP_Instance instance, 300 SerializedVarReceiveInput web_session_id, 301 PP_CdmExceptionCode exception_code, 302 uint32_t system_code, 303 SerializedVarReceiveInput error_description); 304 virtual void OnHostMsgDecoderInitializeDone( 305 PP_Instance instance, 306 PP_DecryptorStreamType decoder_type, 307 uint32_t request_id, 308 PP_Bool success); 309 virtual void OnHostMsgDecoderDeinitializeDone( 310 PP_Instance instance, 311 PP_DecryptorStreamType decoder_type, 312 uint32_t request_id); 313 virtual void OnHostMsgDecoderResetDone(PP_Instance instance, 314 PP_DecryptorStreamType decoder_type, 315 uint32_t request_id); 316 virtual void OnHostMsgDeliverBlock(PP_Instance instance, 317 PP_Resource decrypted_block, 318 const std::string& serialized_block_info); 319 virtual void OnHostMsgDeliverFrame(PP_Instance instance, 320 PP_Resource decrypted_frame, 321 const std::string& serialized_block_info); 322 virtual void OnHostMsgDeliverSamples( 323 PP_Instance instance, 324 PP_Resource audio_frames, 325 const std::string& serialized_sample_info); 326 #endif // !defined(OS_NACL) 327 328 // Host -> Plugin message handlers. 329 void OnPluginMsgMouseLockComplete(PP_Instance instance, int32_t result); 330 331 void MouseLockCompleteInHost(int32_t result, PP_Instance instance); 332 333 // Other helpers. 334 void CancelAnyPendingRequestSurroundingText(PP_Instance instance); 335 336 ProxyCompletionCallbackFactory<PPB_Instance_Proxy> callback_factory_; 337 }; 338 339 } // namespace proxy 340 } // namespace ppapi 341 342 #endif // PPAPI_PROXY_PPB_INSTANCE_PROXY_H_ 343