| Index: include/AdblockPlus/IWebRequest.h |
| diff --git a/include/AdblockPlus/WebRequest.h b/include/AdblockPlus/IWebRequest.h |
| similarity index 75% |
| copy from include/AdblockPlus/WebRequest.h |
| copy to include/AdblockPlus/IWebRequest.h |
| index 9eae7e4e7d36f6ea96559fac9315acaee5a5ffc9..110d25fdebdbdf2530f568ef547a25595da0c5ac 100644 |
| --- a/include/AdblockPlus/WebRequest.h |
| +++ b/include/AdblockPlus/IWebRequest.h |
| @@ -15,20 +15,21 @@ |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| -#ifndef ADBLOCK_PLUS_WEB_REQUEST_H |
| -#define ADBLOCK_PLUS_WEB_REQUEST_H |
| +#ifndef ADBLOCK_PLUS_IWEB_REQUEST_H |
| +#define ADBLOCK_PLUS_IWEB_REQUEST_H |
| +#include <cstdint> |
| +#include <functional> |
| #include <memory> |
| -#include <stdint.h> |
| -#include <string> |
| #include <vector> |
| +#include <string> |
| namespace AdblockPlus |
| { |
| /** |
| * List of HTTP headers. |
| */ |
| - typedef std::vector<std::pair<std::string, std::string> > HeaderList; |
| + typedef std::vector<std::pair<std::string, std::string>> HeaderList; |
| /** |
| * HTTP response. |
| @@ -66,15 +67,14 @@ namespace AdblockPlus |
| }; |
| /** |
| - * Web request interface. |
| + * Web request interface used to implement XMLHttpRequest. |
| */ |
| - class WebRequest |
| + struct IWebRequest |
| { |
| - public: |
| /** |
| * Possible [Mozilla status codes](https://developer.mozilla.org/en/docs/Table_Of_Errors#Network_Errors). |
| */ |
| - enum |
| + enum MozillaStatusCode |
| { |
| NS_OK = 0, |
| NS_ERROR_FAILURE = 0x80004005, |
| @@ -94,21 +94,26 @@ namespace AdblockPlus |
| NS_ERROR_NOT_INITIALIZED = 0xc1f30001 |
| }; |
| - virtual inline ~WebRequest() {}; |
| + /** |
| + * Callback type invoked when the server response is ready. |
| + * The parameter is the server response. |
| + */ |
| + typedef std::function<void(const ServerResponse&)> GetCallback; |
| + virtual ~IWebRequest() {}; |
| /** |
| * Performs a GET request. |
| * @param url Request URL. |
| * @param requestHeaders Request headers. |
| - * @return HTTP response. |
| + * @param getCallback to invoke when the server response is ready. |
| */ |
| - virtual ServerResponse GET(const std::string& url, const HeaderList& requestHeaders) const = 0; |
| + virtual void GET(const std::string& url, const HeaderList& requestHeaders, const GetCallback& getCallback) = 0; |
| }; |
| /** |
| - * Shared smart pointer to a `WebRequest` instance. |
| + * Unique smart pointer to an instance of `IWebRequest` implementation. |
| */ |
| - typedef std::shared_ptr<WebRequest> WebRequestSharedPtr; |
| + typedef std::unique_ptr<IWebRequest> WebRequestPtr; |
| } |
| #endif |