1 // Copyright (c) 2013 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 CONTENT_RENDERER_PEPPER_PEPPER_URL_LOADER_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_URL_LOADER_HOST_H_
10 #include "base/memory/scoped_vector.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/common/content_export.h"
13 #include "ppapi/host/resource_host.h"
14 #include "ppapi/proxy/resource_message_params.h"
15 #include "ppapi/shared_impl/url_request_info_data.h"
16 #include "ppapi/shared_impl/url_response_info_data.h"
17 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
26 class RendererPpapiHostImpl;
28 class PepperURLLoaderHost
29 : public ppapi::host::ResourceHost,
30 public blink::WebURLLoaderClient {
32 // If main_document_loader is true, PP_Resource must be 0 since it will be
33 // pending until the plugin resource attaches to it.
34 PepperURLLoaderHost(RendererPpapiHostImpl* host,
35 bool main_document_loader,
37 PP_Resource resource);
38 virtual ~PepperURLLoaderHost();
40 // ResourceHost implementation.
41 virtual int32_t OnResourceMessageReceived(
42 const IPC::Message& msg,
43 ppapi::host::HostMessageContext* context) OVERRIDE;
45 // blink::WebURLLoaderClient implementation.
46 virtual void willSendRequest(blink::WebURLLoader* loader,
47 blink::WebURLRequest& new_request,
48 const blink::WebURLResponse& redir_response);
49 virtual void didSendData(blink::WebURLLoader* loader,
50 unsigned long long bytes_sent,
51 unsigned long long total_bytes_to_be_sent);
52 virtual void didReceiveResponse(blink::WebURLLoader* loader,
53 const blink::WebURLResponse& response);
54 virtual void didDownloadData(blink::WebURLLoader* loader,
56 int encoded_data_length);
57 virtual void didReceiveData(blink::WebURLLoader* loader,
60 int encoded_data_length);
61 virtual void didFinishLoading(blink::WebURLLoader* loader,
63 int64_t total_encoded_data_length);
64 virtual void didFail(blink::WebURLLoader* loader,
65 const blink::WebURLError& error);
68 // ResourceHost protected overrides.
69 virtual void DidConnectPendingHostToResource() OVERRIDE;
72 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
73 const ppapi::URLRequestInfoData& request_data);
74 int32_t InternalOnHostMsgOpen(ppapi::host::HostMessageContext* context,
75 const ppapi::URLRequestInfoData& request_data);
76 int32_t OnHostMsgSetDeferLoading(ppapi::host::HostMessageContext* context,
78 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
79 int32_t OnHostMsgGrantUniversalAccess(
80 ppapi::host::HostMessageContext* context);
82 // Sends or queues an unsolicited message to the plugin resource. This
83 // handles cases where messages must be reordered for the plugin and
84 // the case where we have created a pending host resource and the
85 // plugin has not connected to us yet.
87 // Takes ownership of the given pointer.
88 void SendUpdateToPlugin(IPC::Message* msg);
90 // Sends or queues an unsolicited message to the plugin resource. This is
91 // used inside SendUpdateToPlugin for messages that are already ordered
94 // Takes ownership of the given pointer.
95 void SendOrderedUpdateToPlugin(IPC::Message* msg);
99 // Returns the frame for the current request.
100 blink::WebFrame* GetFrame();
102 // Calls SetDefersLoading on the current load. This encapsulates the logic
103 // differences between document loads and regular ones.
104 void SetDefersLoading(bool defers_loading);
106 // Converts a WebURLResponse to a URLResponseInfo and saves it.
107 void SaveResponse(const blink::WebURLResponse& response);
108 void DidDataFromWebURLResponse(const ppapi::URLResponseInfoData& data);
110 // Sends the UpdateProgress message (if necessary) to the plugin.
111 void UpdateProgress();
113 // Non-owning pointer.
114 RendererPpapiHostImpl* renderer_ppapi_host_;
116 // If true, then the plugin instance is a full-frame plugin and we're just
117 // wrapping the main document's loader (i.e. loader_ is null).
118 bool main_document_loader_;
120 // The data that generated the request.
121 ppapi::URLRequestInfoData request_data_;
123 // Set to true when this loader can ignore same originl policy.
124 bool has_universal_access_;
126 // The loader associated with this request. MAY BE NULL.
128 // This will be NULL if the load hasn't been opened yet, or if this is a main
129 // document loader (when registered as a mime type). Therefore, you should
130 // always NULL check this value before using it. In the case of a main
131 // document load, you would call the functions on the document to cancel the
132 // load, etc. since there is no loader.
133 scoped_ptr<blink::WebURLLoader> loader_;
136 int64_t total_bytes_to_be_sent_;
137 int64_t bytes_received_;
138 int64_t total_bytes_to_be_received_;
140 // Messages sent while the resource host is pending. These will be forwarded
141 // to the plugin when the plugin side connects. The pointers are owned by
142 // this object and must be deleted.
143 ScopedVector<IPC::Message> pending_replies_;
144 ScopedVector<IPC::Message> out_of_order_replies_;
146 // True when there's a pending DataFromURLResponse call which will send a
147 // PpapiPluginMsg_URLLoader_ReceivedResponse to the plugin, which introduces
148 // ordering constraints on following messages to the plugin.
149 bool pending_response_;
151 base::WeakPtrFactory<PepperURLLoaderHost> weak_factory_;
153 DISALLOW_COPY_AND_ASSIGN(PepperURLLoaderHost);
156 } // namespace content
158 #endif // CONTENT_RENDERER_PEPPER_PEPPER_URL_LOADER_HOST_H_