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 #include "webkit/glue/plugins/pepper_url_loader.h" | 5 #include "webkit/glue/plugins/pepper_url_loader.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/ppapi/c/pp_completion_callback.h" | 8 #include "third_party/ppapi/c/pp_completion_callback.h" |
9 #include "third_party/ppapi/c/pp_errors.h" | 9 #include "third_party/ppapi/c/pp_errors.h" |
10 #include "third_party/ppapi/c/ppb_url_loader.h" | 10 #include "third_party/ppapi/c/ppb_url_loader.h" |
11 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 11 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
12 #include "webkit/glue/plugins/pepper_resource_tracker.h" | |
13 #include "webkit/glue/plugins/pepper_url_request_info.h" | 12 #include "webkit/glue/plugins/pepper_url_request_info.h" |
14 #include "webkit/glue/plugins/pepper_url_response_info.h" | 13 #include "webkit/glue/plugins/pepper_url_response_info.h" |
15 | 14 |
16 namespace pepper { | 15 namespace pepper { |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
20 PP_Resource Create(PP_Instance instance_id) { | 19 PP_Resource Create(PP_Instance instance_id) { |
21 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | 20 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
22 if (!instance) | 21 if (!instance) |
23 return 0; | 22 return 0; |
24 | 23 |
25 URLLoader* loader = new URLLoader(instance); | 24 URLLoader* loader = new URLLoader(instance); |
26 loader->AddRef(); // AddRef for the caller. | 25 loader->AddRef(); // AddRef for the caller. |
27 | 26 |
28 return loader->GetResource(); | 27 return loader->GetResource(); |
29 } | 28 } |
30 | 29 |
31 bool IsURLLoader(PP_Resource resource) { | 30 bool IsURLLoader(PP_Resource resource) { |
32 return !!ResourceTracker::Get()->GetAsURLLoader(resource).get(); | 31 return !!Resource::GetAs<URLLoader>(resource).get(); |
33 } | 32 } |
34 | 33 |
35 int32_t Open(PP_Resource loader_id, | 34 int32_t Open(PP_Resource loader_id, |
36 PP_Resource request_id, | 35 PP_Resource request_id, |
37 PP_CompletionCallback callback) { | 36 PP_CompletionCallback callback) { |
38 scoped_refptr<URLLoader> loader( | 37 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); |
39 ResourceTracker::Get()->GetAsURLLoader(loader_id)); | |
40 if (!loader.get()) | 38 if (!loader.get()) |
41 return PP_Error_BadResource; | 39 return PP_Error_BadResource; |
42 | 40 |
43 scoped_refptr<URLRequestInfo> request( | 41 scoped_refptr<URLRequestInfo> request( |
44 ResourceTracker::Get()->GetAsURLRequestInfo(request_id)); | 42 Resource::GetAs<URLRequestInfo>(request_id)); |
45 if (!request.get()) | 43 if (!request.get()) |
46 return PP_Error_BadResource; | 44 return PP_Error_BadResource; |
47 | 45 |
48 return loader->Open(request, callback); | 46 return loader->Open(request, callback); |
49 } | 47 } |
50 | 48 |
51 int32_t FollowRedirect(PP_Resource loader_id, | 49 int32_t FollowRedirect(PP_Resource loader_id, |
52 PP_CompletionCallback callback) { | 50 PP_CompletionCallback callback) { |
53 scoped_refptr<URLLoader> loader( | 51 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); |
54 ResourceTracker::Get()->GetAsURLLoader(loader_id)); | |
55 if (!loader.get()) | 52 if (!loader.get()) |
56 return PP_Error_BadResource; | 53 return PP_Error_BadResource; |
57 | 54 |
58 return loader->FollowRedirect(callback); | 55 return loader->FollowRedirect(callback); |
59 } | 56 } |
60 | 57 |
61 bool GetUploadProgress(PP_Resource loader_id, | 58 bool GetUploadProgress(PP_Resource loader_id, |
62 int64_t* bytes_sent, | 59 int64_t* bytes_sent, |
63 int64_t* total_bytes_to_be_sent) { | 60 int64_t* total_bytes_to_be_sent) { |
64 scoped_refptr<URLLoader> loader( | 61 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); |
65 ResourceTracker::Get()->GetAsURLLoader(loader_id)); | |
66 if (!loader.get()) | 62 if (!loader.get()) |
67 return false; | 63 return false; |
68 | 64 |
69 *bytes_sent = loader->bytes_sent(); | 65 *bytes_sent = loader->bytes_sent(); |
70 *total_bytes_to_be_sent = loader->total_bytes_to_be_sent(); | 66 *total_bytes_to_be_sent = loader->total_bytes_to_be_sent(); |
71 return true; | 67 return true; |
72 } | 68 } |
73 | 69 |
74 bool GetDownloadProgress(PP_Resource loader_id, | 70 bool GetDownloadProgress(PP_Resource loader_id, |
75 int64_t* bytes_received, | 71 int64_t* bytes_received, |
76 int64_t* total_bytes_to_be_received) { | 72 int64_t* total_bytes_to_be_received) { |
77 scoped_refptr<URLLoader> loader( | 73 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); |
78 ResourceTracker::Get()->GetAsURLLoader(loader_id)); | |
79 if (!loader.get()) | 74 if (!loader.get()) |
80 return false; | 75 return false; |
81 | 76 |
82 *bytes_received = loader->bytes_received(); | 77 *bytes_received = loader->bytes_received(); |
83 *total_bytes_to_be_received = loader->total_bytes_to_be_received(); | 78 *total_bytes_to_be_received = loader->total_bytes_to_be_received(); |
84 return true; | 79 return true; |
85 } | 80 } |
86 | 81 |
87 PP_Resource GetResponseInfo(PP_Resource loader_id) { | 82 PP_Resource GetResponseInfo(PP_Resource loader_id) { |
88 scoped_refptr<URLLoader> loader( | 83 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); |
89 ResourceTracker::Get()->GetAsURLLoader(loader_id)); | |
90 if (!loader.get()) | 84 if (!loader.get()) |
91 return 0; | 85 return 0; |
92 | 86 |
93 URLResponseInfo* response_info = loader->response_info(); | 87 URLResponseInfo* response_info = loader->response_info(); |
94 if (!response_info) | 88 if (!response_info) |
95 return 0; | 89 return 0; |
96 response_info->AddRef(); // AddRef for the caller. | 90 response_info->AddRef(); // AddRef for the caller. |
97 | 91 |
98 return response_info->GetResource(); | 92 return response_info->GetResource(); |
99 } | 93 } |
100 | 94 |
101 int32_t ReadResponseBody(PP_Resource loader_id, | 95 int32_t ReadResponseBody(PP_Resource loader_id, |
102 char* buffer, | 96 char* buffer, |
103 int32_t bytes_to_read, | 97 int32_t bytes_to_read, |
104 PP_CompletionCallback callback) { | 98 PP_CompletionCallback callback) { |
105 scoped_refptr<URLLoader> loader( | 99 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); |
106 ResourceTracker::Get()->GetAsURLLoader(loader_id)); | |
107 if (!loader.get()) | 100 if (!loader.get()) |
108 return PP_Error_BadResource; | 101 return PP_Error_BadResource; |
109 | 102 |
110 return loader->ReadResponseBody(buffer, bytes_to_read, callback); | 103 return loader->ReadResponseBody(buffer, bytes_to_read, callback); |
111 } | 104 } |
112 | 105 |
113 void Close(PP_Resource loader_id) { | 106 void Close(PP_Resource loader_id) { |
114 scoped_refptr<URLLoader> loader( | 107 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); |
115 ResourceTracker::Get()->GetAsURLLoader(loader_id)); | |
116 if (!loader.get()) | 108 if (!loader.get()) |
117 return; | 109 return; |
118 | 110 |
119 loader->Close(); | 111 loader->Close(); |
120 } | 112 } |
121 | 113 |
122 const PPB_URLLoader ppb_urlloader = { | 114 const PPB_URLLoader ppb_urlloader = { |
123 &Create, | 115 &Create, |
124 &IsURLLoader, | 116 &IsURLLoader, |
125 &Open, | 117 &Open, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 void URLLoader::Close() { | 156 void URLLoader::Close() { |
165 NOTIMPLEMENTED(); // TODO(darin): Implement me. | 157 NOTIMPLEMENTED(); // TODO(darin): Implement me. |
166 } | 158 } |
167 | 159 |
168 // static | 160 // static |
169 const PPB_URLLoader* URLLoader::GetInterface() { | 161 const PPB_URLLoader* URLLoader::GetInterface() { |
170 return &ppb_urlloader; | 162 return &ppb_urlloader; |
171 } | 163 } |
172 | 164 |
173 } // namespace pepper | 165 } // namespace pepper |
OLD | NEW |