OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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. | |
4 | |
5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ | |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ | |
7 | |
8 #include <deque> | |
9 | |
10 #include "base/scoped_ptr.h" | |
11 #include "ppapi/c/pp_completion_callback.h" | |
12 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | |
13 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" | |
14 #include "webkit/glue/plugins/pepper_plugin_instance.h" | |
15 #include "webkit/glue/plugins/pepper_resource.h" | |
16 | |
17 struct PPB_URLLoader; | |
18 struct PPB_URLLoaderTrusted; | |
19 | |
20 namespace WebKit { | |
21 class WebFrame; | |
22 class WebURL; | |
23 } | |
24 | |
25 namespace pepper { | |
26 | |
27 class PluginInstance; | |
28 class URLRequestInfo; | |
29 class URLResponseInfo; | |
30 | |
31 class URLLoader : public Resource, | |
32 public WebKit::WebURLLoaderClient, | |
33 public PluginInstance::Observer { | |
34 public: | |
35 URLLoader(PluginInstance* instance, bool main_document_loader); | |
36 virtual ~URLLoader(); | |
37 | |
38 // Returns a pointer to the interface implementing PPB_URLLoader that is | |
39 // exposed to the plugin. | |
40 static const PPB_URLLoader* GetInterface(); | |
41 | |
42 // Returns a pointer to the interface implementing PPB_URLLoaderTrusted that | |
43 // is exposed to the plugin. | |
44 static const PPB_URLLoaderTrusted* GetTrustedInterface(); | |
45 | |
46 // Resource overrides. | |
47 virtual URLLoader* AsURLLoader(); | |
48 | |
49 // PPB_URLLoader implementation. | |
50 int32_t Open(URLRequestInfo* request, PP_CompletionCallback callback); | |
51 int32_t FollowRedirect(PP_CompletionCallback callback); | |
52 bool GetUploadProgress(int64_t* bytes_sent, | |
53 int64_t* total_bytes_to_be_sent); | |
54 bool GetDownloadProgress(int64_t* bytes_received, | |
55 int64_t* total_bytes_to_be_received); | |
56 int32_t ReadResponseBody(char* buffer, int32_t bytes_to_read, | |
57 PP_CompletionCallback callback); | |
58 int32_t FinishStreamingToFile(PP_CompletionCallback callback); | |
59 void Close(); | |
60 | |
61 // PPB_URLLoaderTrusted implementation. | |
62 void GrantUniversalAccess(); | |
63 void SetStatusCallback(PP_URLLoaderTrusted_StatusCallback cb); | |
64 | |
65 // WebKit::WebURLLoaderClient implementation. | |
66 virtual void willSendRequest(WebKit::WebURLLoader* loader, | |
67 WebKit::WebURLRequest& new_request, | |
68 const WebKit::WebURLResponse& redir_response); | |
69 virtual void didSendData(WebKit::WebURLLoader* loader, | |
70 unsigned long long bytes_sent, | |
71 unsigned long long total_bytes_to_be_sent); | |
72 virtual void didReceiveResponse(WebKit::WebURLLoader* loader, | |
73 const WebKit::WebURLResponse& response); | |
74 virtual void didDownloadData(WebKit::WebURLLoader* loader, | |
75 int data_length); | |
76 virtual void didReceiveData(WebKit::WebURLLoader* loader, | |
77 const char* data, | |
78 int data_length); | |
79 virtual void didFinishLoading(WebKit::WebURLLoader* loader, | |
80 double finish_time); | |
81 virtual void didFail(WebKit::WebURLLoader* loader, | |
82 const WebKit::WebURLError& error); | |
83 | |
84 // PluginInstance::Observer implementation. | |
85 virtual void InstanceDestroyed(PluginInstance* instance); | |
86 | |
87 URLResponseInfo* response_info() const { return response_info_; } | |
88 | |
89 private: | |
90 void RunCallback(int32_t result); | |
91 size_t FillUserBuffer(); | |
92 | |
93 // Converts a WebURLResponse to a URLResponseInfo and saves it. | |
94 void SaveResponse(const WebKit::WebURLResponse& response); | |
95 | |
96 int32_t CanRequest(const WebKit::WebFrame* frame, const WebKit::WebURL& url); | |
97 | |
98 // Calls the status_callback_ (if any) with the current upload and download | |
99 // progress. Call this function if you update any of these values to | |
100 // synchronize an out-of-process plugin's state. | |
101 void UpdateStatus(); | |
102 | |
103 // Returns true if the plugin has requested we record download or upload | |
104 // progress. When false, we don't need to update the counters. We go out of | |
105 // our way not to allow access to this information unless it's requested, | |
106 // even when it would be easier just to return it and not check, so that | |
107 // plugins don't depend on access without setting the flag. | |
108 bool RecordDownloadProgress() const; | |
109 bool RecordUploadProgress() const; | |
110 | |
111 // This will be NULL if the instance has been deleted but this URLLoader was | |
112 // somehow leaked. In general, you should not need to check this for NULL. | |
113 // However, if you see a NULL pointer crash, that means somebody is holding | |
114 // a reference to this object longer than the PluginInstance's lifetime. | |
115 PluginInstance* instance_; | |
116 | |
117 // If true, then the plugin instance is a full-frame plugin and we're just | |
118 // wrapping the main document's loader (i.e. loader_ is null). | |
119 bool main_document_loader_; | |
120 scoped_ptr<WebKit::WebURLLoader> loader_; | |
121 scoped_refptr<URLRequestInfo> request_info_; | |
122 scoped_refptr<URLResponseInfo> response_info_; | |
123 PP_CompletionCallback pending_callback_; | |
124 std::deque<char> buffer_; | |
125 int64_t bytes_sent_; | |
126 int64_t total_bytes_to_be_sent_; | |
127 int64_t bytes_received_; | |
128 int64_t total_bytes_to_be_received_; | |
129 char* user_buffer_; | |
130 size_t user_buffer_size_; | |
131 int32_t done_status_; | |
132 | |
133 bool has_universal_access_; | |
134 | |
135 PP_URLLoaderTrusted_StatusCallback status_callback_; | |
136 }; | |
137 | |
138 } // namespace pepper | |
139 | |
140 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ | |
OLD | NEW |