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
10struct MHD_Connection;
11struct Request;
12
13class UrlHandler {
14public:
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
22class CmdHandler : public UrlHandler {
23public:
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
30class ImgHandler : public UrlHandler {
31public:
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
38class BreakHandler : public UrlHandler {
39public:
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;
44private:
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 */
52class ClipAlphaHandler : public UrlHandler {
53public:
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 */
64class EnableGPUHandler : public UrlHandler {
65public:
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
72class PostHandler : public UrlHandler {
73public:
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
80class DownloadHandler : public UrlHandler {
81public:
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
88class InfoHandler : public UrlHandler {
89public:
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
96class DataHandler : public UrlHandler {
97public:
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
104class RootHandler : public UrlHandler {
105public:
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