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.
5 #ifndef PPAPI_PPB_URL_LOADER_PROXY_H_
6 #define PPAPI_PPB_URL_LOADER_PROXY_H_
8 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_module.h"
11 #include "ppapi/c/pp_resource.h"
12 #include "ppapi/c/pp_size.h"
13 #include "ppapi/c/pp_var.h"
14 #include "ppapi/c/ppb_url_loader.h"
15 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
16 #include "ppapi/proxy/interface_proxy.h"
17 #include "ppapi/proxy/proxy_completion_callback_factory.h"
18 #include "ppapi/shared_impl/host_resource.h"
19 #include "ppapi/utility/completion_callback_factory.h"
23 struct URLRequestInfoData
;
24 struct URLResponseInfoData
;
28 struct PPBURLLoader_UpdateProgress_Params
;
30 class PPB_URLLoader_Proxy
: public InterfaceProxy
{
32 PPB_URLLoader_Proxy(Dispatcher
* dispatcher
);
33 virtual ~PPB_URLLoader_Proxy();
35 static const Info
* GetTrustedInfo();
37 static PP_Resource
CreateProxyResource(PP_Instance instance
);
39 // URLLoader objects are normally allocated by the Create function, but
40 // they are also provided to PPP_Instance.OnMsgHandleDocumentLoad. This
41 // function allows the proxy for DocumentLoad to create the correct plugin
42 // proxied info for the given browser-supplied URLLoader resource ID.
43 static PP_Resource
TrackPluginResource(
44 const HostResource
& url_loader_resource
);
46 // InterfaceProxy implementation.
47 virtual bool OnMessageReceived(const IPC::Message
& msg
);
49 // URLLoader objects are sent from places other than just URLLoader.Create,
50 // in particular when doing a full-frame plugin. This function does the
51 // necessary setup in the host before the resource is sent. Call this any
52 // time you're sending a new URLLoader that the plugin hasn't seen yet.
53 void PrepareURLLoaderForSendingToPlugin(PP_Resource resource
);
55 static const ApiID kApiID
= API_ID_PPB_URL_LOADER
;
58 // Plugin->renderer message handlers.
59 void OnMsgCreate(PP_Instance instance
,
60 HostResource
* result
);
61 void OnMsgOpen(const HostResource
& loader
,
62 const URLRequestInfoData
& data
);
63 void OnMsgFollowRedirect(const HostResource
& loader
);
64 void OnMsgGetResponseInfo(const HostResource
& loader
,
66 URLResponseInfoData
* result
);
67 void OnMsgReadResponseBody(const HostResource
& loader
,
68 int32_t bytes_to_read
);
69 void OnMsgFinishStreamingToFile(const HostResource
& loader
);
70 void OnMsgClose(const HostResource
& loader
);
71 void OnMsgGrantUniversalAccess(const HostResource
& loader
);
73 // Renderer->plugin message handlers.
74 void OnMsgUpdateProgress(
75 const PPBURLLoader_UpdateProgress_Params
& params
);
76 void OnMsgReadResponseBodyAck(const IPC::Message
& message
);
77 void OnMsgCallbackComplete(const HostResource
& host_resource
, int32_t result
);
79 // Handles callbacks for read complete messages. Takes ownership of the
81 void OnReadCallback(int32_t result
, IPC::Message
* message
);
83 // Handles callback for everything but reads.
84 void OnCallback(int32_t result
, const HostResource
& resource
);
86 ProxyCompletionCallbackFactory
<PPB_URLLoader_Proxy
> callback_factory_
;
92 #endif // PPAPI_PPB_URL_LOADER_PROXY_H_