Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_url_loader_host.h
blobe515174eb40395018e3a6db13835c77ea7c42df0
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 WebKit {
20 class WebFrame;
21 class WebURLLoader;
24 namespace content {
26 class RendererPpapiHostImpl;
28 class PepperURLLoaderHost
29 : public ppapi::host::ResourceHost,
30 public WebKit::WebURLLoaderClient {
31 public:
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,
36 PP_Instance instance,
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 // WebKit::WebURLLoaderClient implementation.
46 virtual void willSendRequest(WebKit::WebURLLoader* loader,
47 WebKit::WebURLRequest& new_request,
48 const WebKit::WebURLResponse& redir_response);
49 virtual void didSendData(WebKit::WebURLLoader* loader,
50 unsigned long long bytes_sent,
51 unsigned long long total_bytes_to_be_sent);
52 virtual void didReceiveResponse(WebKit::WebURLLoader* loader,
53 const WebKit::WebURLResponse& response);
54 virtual void didDownloadData(WebKit::WebURLLoader* loader,
55 int data_length,
56 int encoded_data_length);
57 virtual void didReceiveData(WebKit::WebURLLoader* loader,
58 const char* data,
59 int data_length,
60 int encoded_data_length);
61 virtual void didFinishLoading(WebKit::WebURLLoader* loader,
62 double finish_time);
63 virtual void didFail(WebKit::WebURLLoader* loader,
64 const WebKit::WebURLError& error);
66 private:
67 // ResourceHost protected overrides.
68 virtual 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 WebKit::WebFrame* 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 WebKit::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<WebKit::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_