OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ |
7 | 7 |
| 8 #include <deque> |
| 9 |
| 10 #include "base/scoped_ptr.h" |
| 11 #include "third_party/ppapi/c/pp_completion_callback.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoader.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" |
8 #include "webkit/glue/plugins/pepper_resource.h" | 14 #include "webkit/glue/plugins/pepper_resource.h" |
9 | 15 |
10 typedef struct _pp_CompletionCallback PP_CompletionCallback; | |
11 typedef struct _ppb_URLLoader PPB_URLLoader; | 16 typedef struct _ppb_URLLoader PPB_URLLoader; |
12 | 17 |
13 namespace pepper { | 18 namespace pepper { |
14 | 19 |
15 class PluginInstance; | 20 class PluginInstance; |
16 class URLRequestInfo; | 21 class URLRequestInfo; |
17 class URLResponseInfo; | 22 class URLResponseInfo; |
18 | 23 |
19 class URLLoader : public Resource { | 24 class URLLoader : public Resource, public WebKit::WebURLLoaderClient { |
20 public: | 25 public: |
21 explicit URLLoader(PluginInstance* instance); | 26 explicit URLLoader(PluginInstance* instance); |
22 virtual ~URLLoader(); | 27 virtual ~URLLoader(); |
23 | 28 |
24 // Returns a pointer to the interface implementing PPB_URLLoader that is | 29 // Returns a pointer to the interface implementing PPB_URLLoader that is |
25 // exposed to the plugin. | 30 // exposed to the plugin. |
26 static const PPB_URLLoader* GetInterface(); | 31 static const PPB_URLLoader* GetInterface(); |
27 | 32 |
28 // Resource overrides. | 33 // Resource overrides. |
29 URLLoader* AsURLLoader() { return this; } | 34 URLLoader* AsURLLoader() { return this; } |
30 | 35 |
31 // PPB_URLLoader implementation. | 36 // PPB_URLLoader implementation. |
32 int32_t Open(URLRequestInfo* request, PP_CompletionCallback callback); | 37 int32_t Open(URLRequestInfo* request, PP_CompletionCallback callback); |
33 int32_t FollowRedirect(PP_CompletionCallback callback); | 38 int32_t FollowRedirect(PP_CompletionCallback callback); |
34 int32_t ReadResponseBody(char* buffer, int32_t bytes_to_read, | 39 int32_t ReadResponseBody(char* buffer, int32_t bytes_to_read, |
35 PP_CompletionCallback callback); | 40 PP_CompletionCallback callback); |
36 void Close(); | 41 void Close(); |
37 | 42 |
38 URLResponseInfo* response_info() const { return response_info_; } | 43 URLResponseInfo* response_info() const { return response_info_; } |
39 | 44 |
40 // Progress counters: | 45 // Progress counters. |
41 int64_t bytes_sent() const { return bytes_sent_; } | 46 int64_t bytes_sent() const { return bytes_sent_; } |
42 int64_t total_bytes_to_be_sent() const { return total_bytes_to_be_sent_; } | 47 int64_t total_bytes_to_be_sent() const { return total_bytes_to_be_sent_; } |
43 int64_t bytes_received() const { return bytes_received_; } | 48 int64_t bytes_received() const { return bytes_received_; } |
44 int64_t total_bytes_to_be_received() const { | 49 int64_t total_bytes_to_be_received() const { |
45 return total_bytes_to_be_received_; | 50 return total_bytes_to_be_received_; |
46 } | 51 } |
47 | 52 |
48 private: | 53 private: |
| 54 void RunCallback(int32_t result); |
| 55 size_t FillUserBuffer(); |
| 56 |
| 57 // WebKit::WebURLLoaderClient implementation. |
| 58 virtual void willSendRequest(WebKit::WebURLLoader* loader, |
| 59 WebKit::WebURLRequest& new_request, |
| 60 const WebKit::WebURLResponse& redir_response); |
| 61 virtual void didSendData(WebKit::WebURLLoader* loader, |
| 62 unsigned long long bytes_sent, |
| 63 unsigned long long total_bytes_to_be_sent); |
| 64 virtual void didReceiveResponse(WebKit::WebURLLoader* loader, |
| 65 const WebKit::WebURLResponse& response); |
| 66 virtual void didReceiveData(WebKit::WebURLLoader* loader, |
| 67 const char* data, |
| 68 int data_length); |
| 69 virtual void didFinishLoading(WebKit::WebURLLoader* loader); |
| 70 virtual void didFail(WebKit::WebURLLoader* loader, |
| 71 const WebKit::WebURLError& error); |
| 72 |
| 73 scoped_refptr<PluginInstance> instance_; |
| 74 scoped_ptr<WebKit::WebURLLoader> loader_; |
49 scoped_refptr<URLResponseInfo> response_info_; | 75 scoped_refptr<URLResponseInfo> response_info_; |
| 76 PP_CompletionCallback pending_callback_; |
| 77 std::deque<char> buffer_; |
50 int64_t bytes_sent_; | 78 int64_t bytes_sent_; |
51 int64_t total_bytes_to_be_sent_; | 79 int64_t total_bytes_to_be_sent_; |
52 int64_t bytes_received_; | 80 int64_t bytes_received_; |
53 int64_t total_bytes_to_be_received_; | 81 int64_t total_bytes_to_be_received_; |
| 82 char* user_buffer_; |
| 83 size_t user_buffer_size_; |
54 }; | 84 }; |
55 | 85 |
56 } // namespace pepper | 86 } // namespace pepper |
57 | 87 |
58 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ | 88 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_URL_LOADER_H_ |
OLD | NEW |