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