Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrCaps.h" | 8 #include "GrCaps.h" |
| 9 #include "GrContextFactory.h" | 9 #include "GrContextFactory.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 const char* content_type, const char* transfer_en coding, | 136 const char* content_type, const char* transfer_en coding, |
| 137 const char* data, uint64_t off, size_t size) { | 137 const char* data, uint64_t off, size_t size) { |
| 138 struct UploadContext* uc = reinterpret_cast<UploadContext*>(cls); | 138 struct UploadContext* uc = reinterpret_cast<UploadContext*>(cls); |
| 139 | 139 |
| 140 if (0 != size) { | 140 if (0 != size) { |
| 141 uc->fStream.write(data, size); | 141 uc->fStream.write(data, size); |
| 142 } | 142 } |
| 143 return MHD_YES; | 143 return MHD_YES; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // SendOK just sends an empty response with a 200 OK status code. | |
| 147 static int SendOK(MHD_Connection* connection) { | |
| 148 const char * data = ""; | |
|
ethannicholas
2016/02/10 21:37:16
nit: space before '*'
jcgregorio
2016/02/10 21:42:19
Done.
| |
| 149 | |
| 150 struct MHD_Response* response = MHD_create_response_from_buffer (strlen(data ), (void*)data, MHD_RESPMEM_PERSISTENT); | |
|
ethannicholas
2016/02/10 21:37:16
nit: space before '(', needs a line break
jcgregorio
2016/02/10 21:42:19
Done.
| |
| 151 int ret = MHD_queue_response(connection, 200, response); | |
| 152 MHD_destroy_response(response); | |
| 153 return ret; | |
| 154 } | |
| 155 | |
| 146 static int SendData(MHD_Connection* connection, const SkData* data, const char* type, | 156 static int SendData(MHD_Connection* connection, const SkData* data, const char* type, |
| 147 bool setContentDisposition = false, const char* dispositionS tring = nullptr) { | 157 bool setContentDisposition = false, const char* dispositionS tring = nullptr) { |
| 148 MHD_Response* response = MHD_create_response_from_buffer(data->size(), | 158 MHD_Response* response = MHD_create_response_from_buffer(data->size(), |
| 149 const_cast<void*>(d ata->data()), | 159 const_cast<void*>(d ata->data()), |
| 150 MHD_RESPMEM_MUST_CO PY); | 160 MHD_RESPMEM_MUST_CO PY); |
| 151 MHD_add_response_header(response, "Content-Type", type); | 161 MHD_add_response_header(response, "Content-Type", type); |
| 152 | 162 |
| 153 if (setContentDisposition) { | 163 if (setContentDisposition) { |
| 154 MHD_add_response_header(response, "Content-Disposition", dispositionStri ng); | 164 MHD_add_response_header(response, "Content-Disposition", dispositionStri ng); |
| 155 } | 165 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 if (commands.count() == 1 && 0 == strcmp(method, MHD_HTTP_METHOD_GET)) { | 231 if (commands.count() == 1 && 0 == strcmp(method, MHD_HTTP_METHOD_GET)) { |
| 222 int n = request->fDebugCanvas->getSize() - 1; | 232 int n = request->fDebugCanvas->getSize() - 1; |
| 223 return SendJSON(connection, request->fDebugCanvas, n); | 233 return SendJSON(connection, request->fDebugCanvas, n); |
| 224 } | 234 } |
| 225 | 235 |
| 226 // /cmd/N, for now only delete supported | 236 // /cmd/N, for now only delete supported |
| 227 if (commands.count() == 2 && 0 == strcmp(method, MHD_HTTP_METHOD_DELETE) ) { | 237 if (commands.count() == 2 && 0 == strcmp(method, MHD_HTTP_METHOD_DELETE) ) { |
| 228 int n; | 238 int n; |
| 229 sscanf(commands[1].c_str(), "%d", &n); | 239 sscanf(commands[1].c_str(), "%d", &n); |
| 230 request->fDebugCanvas->deleteDrawCommandAt(n); | 240 request->fDebugCanvas->deleteDrawCommandAt(n); |
| 231 return MHD_YES; | 241 return SendOK(connection); |
| 232 } | 242 } |
| 233 | 243 |
| 234 // /cmd/N/[0|1] | 244 // /cmd/N/[0|1] |
| 235 if (commands.count() == 3 && 0 == strcmp(method, MHD_HTTP_METHOD_POST)) { | 245 if (commands.count() == 3 && 0 == strcmp(method, MHD_HTTP_METHOD_POST)) { |
| 236 int n, toggle; | 246 int n, toggle; |
| 237 sscanf(commands[1].c_str(), "%d", &n); | 247 sscanf(commands[1].c_str(), "%d", &n); |
| 238 sscanf(commands[2].c_str(), "%d", &toggle); | 248 sscanf(commands[2].c_str(), "%d", &toggle); |
| 239 request->fDebugCanvas->toggleCommand(n, toggle); | 249 request->fDebugCanvas->toggleCommand(n, toggle); |
| 240 return MHD_YES; | 250 return SendOK(connection); |
| 241 } | 251 } |
| 242 | 252 |
| 243 return MHD_NO; | 253 return MHD_NO; |
| 244 } | 254 } |
| 245 }; | 255 }; |
| 246 | 256 |
| 247 class ImgHandler : public UrlHandler { | 257 class ImgHandler : public UrlHandler { |
| 248 public: | 258 public: |
| 249 bool canHandle(const char* method, const char* url) override { | 259 bool canHandle(const char* method, const char* url) override { |
| 250 static const char* kBasePath = "/img"; | 260 static const char* kBasePath = "/img"; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 MHD_stop_daemon(daemon); | 556 MHD_stop_daemon(daemon); |
| 547 return 0; | 557 return 0; |
| 548 } | 558 } |
| 549 | 559 |
| 550 #if !defined SK_BUILD_FOR_IOS | 560 #if !defined SK_BUILD_FOR_IOS |
| 551 int main(int argc, char** argv) { | 561 int main(int argc, char** argv) { |
| 552 SkCommandLineFlags::Parse(argc, argv); | 562 SkCommandLineFlags::Parse(argc, argv); |
| 553 return skiaserve_main(); | 563 return skiaserve_main(); |
| 554 } | 564 } |
| 555 #endif | 565 #endif |
| OLD | NEW |