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
;
27 struct PPBURLLoader_UpdateProgress_Params
;
29 class PPB_URLLoader_Proxy
: public InterfaceProxy
{
31 PPB_URLLoader_Proxy(Dispatcher
* dispatcher
);
32 virtual ~PPB_URLLoader_Proxy();
34 static const Info
* GetTrustedInfo();
36 static PP_Resource
CreateProxyResource(PP_Instance instance
);
38 // URLLoader objects are normally allocated by the Create function, but
39 // they are also provided to PPP_Instance.OnMsgHandleDocumentLoad. This
40 // function allows the proxy for DocumentLoad to create the correct plugin
41 // proxied info for the given browser-supplied URLLoader resource ID.
42 static PP_Resource
TrackPluginResource(
43 const HostResource
& url_loader_resource
);
45 // InterfaceProxy implementation.
46 virtual bool OnMessageReceived(const IPC::Message
& msg
);
48 // URLLoader objects are sent from places other than just URLLoader.Create,
49 // in particular when doing a full-frame plugin. This function does the
50 // necessary setup in the host before the resource is sent. Call this any
51 // time you're sending a new URLLoader that the plugin hasn't seen yet.
52 void PrepareURLLoaderForSendingToPlugin(PP_Resource resource
);
54 static const ApiID kApiID
= API_ID_PPB_URL_LOADER
;
57 // Plugin->renderer message handlers.
58 void OnMsgCreate(PP_Instance instance
,
59 HostResource
* result
);
60 void OnMsgOpen(const HostResource
& loader
,
61 const URLRequestInfoData
& data
);
62 void OnMsgFollowRedirect(const HostResource
& loader
);
63 void OnMsgGetResponseInfo(const HostResource
& loader
,
64 HostResource
* result
);
65 void OnMsgReadResponseBody(const HostResource
& loader
,
66 int32_t bytes_to_read
);
67 void OnMsgFinishStreamingToFile(const HostResource
& loader
);
68 void OnMsgClose(const HostResource
& loader
);
69 void OnMsgGrantUniversalAccess(const HostResource
& loader
);
71 // Renderer->plugin message handlers.
72 void OnMsgUpdateProgress(
73 const PPBURLLoader_UpdateProgress_Params
& params
);
74 void OnMsgReadResponseBodyAck(const IPC::Message
& message
);
75 void OnMsgCallbackComplete(const HostResource
& host_resource
, int32_t result
);
77 // Handles callbacks for read complete messages. Takes ownership of the
79 void OnReadCallback(int32_t result
, IPC::Message
* message
);
81 // Handles callback for everything but reads.
82 void OnCallback(int32_t result
, const HostResource
& resource
);
84 ProxyCompletionCallbackFactory
<PPB_URLLoader_Proxy
> callback_factory_
;
90 #endif // PPAPI_PPB_URL_LOADER_PROXY_H_