Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: webkit/glue/plugins/pepper_url_loader.cc

Issue 2859023: Boilerplate implementation of the Pepper URL Loader API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/plugins/pepper_url_loader.h ('k') | webkit/glue/plugins/pepper_url_request_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 #include "webkit/glue/plugins/pepper_url_loader.h"
6
7 #include "base/logging.h"
8 #include "third_party/ppapi/c/pp_completion_callback.h"
9 #include "third_party/ppapi/c/pp_errors.h"
10 #include "third_party/ppapi/c/ppb_url_loader.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"
14 #include "webkit/glue/plugins/pepper_url_response_info.h"
15
16 namespace pepper {
17
18 namespace {
19
20 PP_Resource Create(PP_Instance instance_id) {
21 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
22 if (!instance)
23 return 0;
24
25 URLLoader* loader = new URLLoader(instance);
26 loader->AddRef(); // AddRef for the caller.
27
28 return loader->GetResource();
29 }
30
31 bool IsURLLoader(PP_Resource resource) {
32 return !!ResourceTracker::Get()->GetAsURLLoader(resource).get();
33 }
34
35 int32_t Open(PP_Resource loader_id,
36 PP_Resource request_id,
37 PP_CompletionCallback callback) {
38 scoped_refptr<URLLoader> loader(
39 ResourceTracker::Get()->GetAsURLLoader(loader_id));
40 if (!loader.get())
41 return PP_Error_BadResource;
42
43 scoped_refptr<URLRequestInfo> request(
44 ResourceTracker::Get()->GetAsURLRequestInfo(request_id));
45 if (!request.get())
46 return PP_Error_BadResource;
47
48 return loader->Open(request, callback);
49 }
50
51 int32_t FollowRedirect(PP_Resource loader_id,
52 PP_CompletionCallback callback) {
53 scoped_refptr<URLLoader> loader(
54 ResourceTracker::Get()->GetAsURLLoader(loader_id));
55 if (!loader.get())
56 return PP_Error_BadResource;
57
58 return loader->FollowRedirect(callback);
59 }
60
61 bool GetUploadProgress(PP_Resource loader_id,
62 int64_t* bytes_sent,
63 int64_t* total_bytes_to_be_sent) {
64 scoped_refptr<URLLoader> loader(
65 ResourceTracker::Get()->GetAsURLLoader(loader_id));
66 if (!loader.get())
67 return false;
68
69 *bytes_sent = loader->bytes_sent();
70 *total_bytes_to_be_sent = loader->total_bytes_to_be_sent();
71 return true;
72 }
73
74 bool GetDownloadProgress(PP_Resource loader_id,
75 int64_t* bytes_received,
76 int64_t* total_bytes_to_be_received) {
77 scoped_refptr<URLLoader> loader(
78 ResourceTracker::Get()->GetAsURLLoader(loader_id));
79 if (!loader.get())
80 return false;
81
82 *bytes_received = loader->bytes_received();
83 *total_bytes_to_be_received = loader->total_bytes_to_be_received();
84 return true;
85 }
86
87 PP_Resource GetResponseInfo(PP_Resource loader_id) {
88 scoped_refptr<URLLoader> loader(
89 ResourceTracker::Get()->GetAsURLLoader(loader_id));
90 if (!loader.get())
91 return 0;
92
93 URLResponseInfo* response_info = loader->response_info();
94 if (!response_info)
95 return 0;
96 response_info->AddRef(); // AddRef for the caller.
97
98 return response_info->GetResource();
99 }
100
101 int32_t ReadResponseBody(PP_Resource loader_id,
102 char* buffer,
103 int32_t bytes_to_read,
104 PP_CompletionCallback callback) {
105 scoped_refptr<URLLoader> loader(
106 ResourceTracker::Get()->GetAsURLLoader(loader_id));
107 if (!loader.get())
108 return PP_Error_BadResource;
109
110 return loader->ReadResponseBody(buffer, bytes_to_read, callback);
111 }
112
113 void Close(PP_Resource loader_id) {
114 scoped_refptr<URLLoader> loader(
115 ResourceTracker::Get()->GetAsURLLoader(loader_id));
116 if (!loader.get())
117 return;
118
119 loader->Close();
120 }
121
122 const PPB_URLLoader ppb_urlloader = {
123 &Create,
124 &IsURLLoader,
125 &Open,
126 &FollowRedirect,
127 &GetUploadProgress,
128 &GetDownloadProgress,
129 &GetResponseInfo,
130 &ReadResponseBody,
131 &Close
132 };
133
134 } // namespace
135
136 URLLoader::URLLoader(PluginInstance* instance)
137 : Resource(instance->module()),
138 bytes_sent_(0),
139 total_bytes_to_be_sent_(0),
140 bytes_received_(0),
141 total_bytes_to_be_received_(0) {
142 }
143
144 URLLoader::~URLLoader() {
145 }
146
147 int32_t URLLoader::Open(URLRequestInfo* request,
148 PP_CompletionCallback callback) {
149 NOTIMPLEMENTED(); // TODO(darin): Implement me.
150 return PP_Error_Failed;
151 }
152
153 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) {
154 NOTIMPLEMENTED(); // TODO(darin): Implement me.
155 return PP_Error_Failed;
156 }
157
158 int32_t URLLoader::ReadResponseBody(char* buffer, int32_t bytes_to_read,
159 PP_CompletionCallback callback) {
160 NOTIMPLEMENTED(); // TODO(darin): Implement me.
161 return PP_Error_Failed;
162 }
163
164 void URLLoader::Close() {
165 NOTIMPLEMENTED(); // TODO(darin): Implement me.
166 }
167
168 // static
169 const PPB_URLLoader* URLLoader::GetInterface() {
170 return &ppb_urlloader;
171 }
172
173 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_url_loader.h ('k') | webkit/glue/plugins/pepper_url_request_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698