mesa gn build: suppress -Wstring-conversion warnings
[chromium-blink-merge.git] / content / renderer / pepper / pepper_url_loader_host.h
blob8a784ef09b728810666b2b052be00e2aef6f17ca
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_
8 #include <vector>
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"
19 namespace blink {
20 class WebLocalFrame;
21 class WebURLLoader;
24 namespace content {
26 class RendererPpapiHostImpl;
28 class PepperURLLoaderHost : public ppapi::host::ResourceHost,
29 public blink::WebURLLoaderClient {
30 public:
31 // If main_document_loader is true, PP_Resource must be 0 since it will be
32 // pending until the plugin resource attaches to it.
33 PepperURLLoaderHost(RendererPpapiHostImpl* host,
34 bool main_document_loader,
35 PP_Instance instance,
36 PP_Resource resource);
37 virtual ~PepperURLLoaderHost();
39 // ResourceHost implementation.
40 int32_t OnResourceMessageReceived(
41 const IPC::Message& msg,
42 ppapi::host::HostMessageContext* context) override;
44 // blink::WebURLLoaderClient implementation.
45 virtual void willSendRequest(blink::WebURLLoader* loader,
46 blink::WebURLRequest& new_request,
47 const blink::WebURLResponse& redir_response);
48 virtual void didSendData(blink::WebURLLoader* loader,
49 unsigned long long bytes_sent,
50 unsigned long long total_bytes_to_be_sent);
51 virtual void didReceiveResponse(blink::WebURLLoader* loader,
52 const blink::WebURLResponse& response);
53 virtual void didDownloadData(blink::WebURLLoader* loader,
54 int data_length,
55 int encoded_data_length);
56 virtual void didReceiveData(blink::WebURLLoader* loader,
57 const char* data,
58 int data_length,
59 int encoded_data_length);
60 virtual void didFinishLoading(blink::WebURLLoader* loader,
61 double finish_time,
62 int64_t total_encoded_data_length);
63 virtual void didFail(blink::WebURLLoader* loader,
64 const blink::WebURLError& error);
66 private:
67 // ResourceHost protected overrides.
68 void DidConnectPendingHostToResource() override;
70 // IPC messages
71 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
72 const ppapi::URLRequestInfoData& request_data);
73 int32_t InternalOnHostMsgOpen(ppapi::host::HostMessageContext* context,
74 const ppapi::URLRequestInfoData& request_data);
75 int32_t OnHostMsgSetDeferLoading(ppapi::host::HostMessageContext* context,
76 bool defers_loading);
77 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
78 int32_t OnHostMsgGrantUniversalAccess(
79 ppapi::host::HostMessageContext* context);
81 // Sends or queues an unsolicited message to the plugin resource. This
82 // handles cases where messages must be reordered for the plugin and
83 // the case where we have created a pending host resource and the
84 // plugin has not connected to us yet.
86 // Takes ownership of the given pointer.
87 void SendUpdateToPlugin(IPC::Message* msg);
89 // Sends or queues an unsolicited message to the plugin resource. This is
90 // used inside SendUpdateToPlugin for messages that are already ordered
91 // properly.
93 // Takes ownership of the given pointer.
94 void SendOrderedUpdateToPlugin(IPC::Message* msg);
96 void Close();
98 // Returns the frame for the current request.
99 blink::WebLocalFrame* GetFrame();
101 // Calls SetDefersLoading on the current load. This encapsulates the logic
102 // differences between document loads and regular ones.
103 void SetDefersLoading(bool defers_loading);
105 // Converts a WebURLResponse to a URLResponseInfo and saves it.
106 void SaveResponse(const blink::WebURLResponse& response);
107 void DidDataFromWebURLResponse(const ppapi::URLResponseInfoData& data);
109 // Sends the UpdateProgress message (if necessary) to the plugin.
110 void UpdateProgress();
112 // Non-owning pointer.
113 RendererPpapiHostImpl* renderer_ppapi_host_;
115 // If true, then the plugin instance is a full-frame plugin and we're just
116 // wrapping the main document's loader (i.e. loader_ is null).
117 bool main_document_loader_;
119 // The data that generated the request.
120 ppapi::URLRequestInfoData request_data_;
122 // Set to true when this loader can ignore same originl policy.
123 bool has_universal_access_;
125 // The loader associated with this request. MAY BE NULL.
127 // This will be NULL if the load hasn't been opened yet, or if this is a main
128 // document loader (when registered as a mime type). Therefore, you should
129 // always NULL check this value before using it. In the case of a main
130 // document load, you would call the functions on the document to cancel the
131 // load, etc. since there is no loader.
132 scoped_ptr<blink::WebURLLoader> loader_;
134 int64_t bytes_sent_;
135 int64_t total_bytes_to_be_sent_;
136 int64_t bytes_received_;
137 int64_t total_bytes_to_be_received_;
139 // Messages sent while the resource host is pending. These will be forwarded
140 // to the plugin when the plugin side connects. The pointers are owned by
141 // this object and must be deleted.
142 ScopedVector<IPC::Message> pending_replies_;
143 ScopedVector<IPC::Message> out_of_order_replies_;
145 // True when there's a pending DataFromURLResponse call which will send a
146 // PpapiPluginMsg_URLLoader_ReceivedResponse to the plugin, which introduces
147 // ordering constraints on following messages to the plugin.
148 bool pending_response_;
150 base::WeakPtrFactory<PepperURLLoaderHost> weak_factory_;
152 DISALLOW_COPY_AND_ASSIGN(PepperURLLoaderHost);
155 } // namespace content
157 #endif // CONTENT_RENDERER_PEPPER_PEPPER_URL_LOADER_HOST_H_