• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkColor.h"
9 
10 struct MHD_Connection;
11 struct Request;
12 
13 class UrlHandler {
14 public:
~UrlHandler()15     virtual ~UrlHandler() {}
16     virtual bool canHandle(const char* method, const char* url) = 0;
17     virtual int handle(Request* request, MHD_Connection* connection,
18                        const char* url, const char* method,
19                        const char* upload_data, size_t* upload_data_size) = 0;
20 };
21 
22 class CmdHandler : public UrlHandler {
23 public:
24     bool canHandle(const char* method, const char* url) override;
25     int handle(Request* request, MHD_Connection* connection,
26                const char* url, const char* method,
27                const char* upload_data, size_t* upload_data_size) override;
28 };
29 
30 class ImgHandler : public UrlHandler {
31 public:
32     bool canHandle(const char* method, const char* url) override;
33     int handle(Request* request, MHD_Connection* connection,
34                const char* url, const char* method,
35                const char* upload_data, size_t* upload_data_size) override;
36 };
37 
38 class BreakHandler : public UrlHandler {
39 public:
40     bool canHandle(const char* method, const char* url) override;
41     int handle(Request* request, MHD_Connection* connection,
42                const char* url, const char* method,
43                const char* upload_data, size_t* upload_data_size) override;
44 private:
45     static SkColor GetPixel(Request* request, int x, int y);
46 };
47 
48 /**
49    Updates the clip visualization alpha. On all subsequent /img requests, the clip will be drawn in
50    black with the specified alpha. 0 = no visible clip, 255 = fully opaque clip.
51  */
52 class ClipAlphaHandler : public UrlHandler {
53 public:
54     bool canHandle(const char* method, const char* url) override;
55     int handle(Request* request, MHD_Connection* connection,
56                const char* url, const char* method,
57                const char* upload_data, size_t* upload_data_size) override;
58 };
59 
60 /**
61    Controls whether GPU rendering is enabled. Posting to /enableGPU/1 turns GPU on, /enableGPU/0
62    disables it.
63  */
64 class EnableGPUHandler : public UrlHandler {
65 public:
66     bool canHandle(const char* method, const char* url) override;
67     int handle(Request* request, MHD_Connection* connection,
68                const char* url, const char* method,
69                const char* upload_data, size_t* upload_data_size) override;
70 };
71 
72 class PostHandler : public UrlHandler {
73 public:
74     bool canHandle(const char* method, const char* url) override;
75     int handle(Request* request, MHD_Connection* connection,
76                const char* url, const char* method,
77                const char* upload_data, size_t* upload_data_size) override;
78 };
79 
80 class DownloadHandler : public UrlHandler {
81 public:
82     bool canHandle(const char* method, const char* url) override;
83     int handle(Request* request, MHD_Connection* connection,
84                const char* url, const char* method,
85                const char* upload_data, size_t* upload_data_size) override;
86 };
87 
88 class InfoHandler : public UrlHandler {
89 public:
90     bool canHandle(const char* method, const char* url) override;
91     int handle(Request* request, MHD_Connection* connection,
92                const char* url, const char* method,
93                const char* upload_data, size_t* upload_data_size) override;
94 };
95 
96 class DataHandler : public UrlHandler {
97 public:
98     bool canHandle(const char* method, const char* url) override;
99     int handle(Request* request, MHD_Connection* connection,
100                const char* url, const char* method,
101                const char* upload_data, size_t* upload_data_size) override;
102 };
103 
104 class RootHandler : public UrlHandler {
105 public:
106     bool canHandle(const char* method, const char* url) override;
107     int handle(Request* request, MHD_Connection* connection,
108                const char* url, const char* method,
109                const char* upload_data, size_t* upload_data_size) override;
110 };
111 
112