2019-07-17 18:55:56 +00:00
|
|
|
// Copyright (c) 2019 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_NS_H_
|
|
|
|
#define SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_NS_H_
|
|
|
|
|
2019-08-11 04:24:51 +00:00
|
|
|
#include "base/values.h"
|
|
|
|
#include "gin/arguments.h"
|
|
|
|
#include "gin/handle.h"
|
|
|
|
#include "gin/wrappable.h"
|
2019-07-17 18:55:56 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
#include "native_mate/handle.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class AtomBrowserContext;
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2019-08-11 04:24:51 +00:00
|
|
|
class WebRequestNS : public gin::Wrappable<WebRequestNS> {
|
2019-07-17 18:55:56 +00:00
|
|
|
public:
|
2019-08-11 04:24:51 +00:00
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
2019-07-17 18:55:56 +00:00
|
|
|
|
2019-08-11 04:24:51 +00:00
|
|
|
static gin::Handle<WebRequestNS> Create(v8::Isolate* isolate,
|
|
|
|
AtomBrowserContext* browser_context);
|
|
|
|
|
|
|
|
// gin::Wrappable:
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
2019-07-17 18:55:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
WebRequestNS(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
|
|
|
~WebRequestNS() override;
|
2019-08-11 04:24:51 +00:00
|
|
|
|
|
|
|
enum SimpleEvent {
|
|
|
|
kOnSendHeaders,
|
|
|
|
kOnBeforeRedirect,
|
|
|
|
kOnResponseStarted,
|
|
|
|
kOnCompleted,
|
|
|
|
kOnErrorOccurred,
|
|
|
|
};
|
|
|
|
enum ResponseEvent {
|
|
|
|
kOnBeforeRequest,
|
|
|
|
kOnBeforeSendHeaders,
|
|
|
|
kOnHeadersReceived,
|
|
|
|
};
|
|
|
|
|
|
|
|
using SimpleListener = base::RepeatingCallback<void(const base::Value&)>;
|
|
|
|
using ResponseCallback = base::OnceCallback<void(const base::Value&)>;
|
|
|
|
using ResponseListener =
|
|
|
|
base::RepeatingCallback<void(const base::Value&, ResponseCallback)>;
|
|
|
|
|
|
|
|
template <SimpleEvent event>
|
|
|
|
void SetSimpleListener(gin::Arguments* args);
|
|
|
|
template <ResponseEvent event>
|
|
|
|
void SetResponseListener(gin::Arguments* args);
|
|
|
|
template <typename Listener, typename Event>
|
|
|
|
void SetListener(Event event, gin::Arguments* args);
|
2019-07-17 18:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
|
|
|
#endif // SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_NS_H_
|