2015-08-12 05:30:19 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_NET_JS_ASKER_H_
|
|
|
|
#define SHELL_BROWSER_NET_JS_ASKER_H_
|
2015-08-12 05:30:19 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2015-08-12 05:30:19 +00:00
|
|
|
#include "base/callback.h"
|
|
|
|
#include "base/values.h"
|
2018-10-05 20:29:57 +00:00
|
|
|
#include "native_mate/arguments.h"
|
2015-08-12 14:57:25 +00:00
|
|
|
#include "net/url_request/url_request_context_getter.h"
|
2015-08-12 05:30:19 +00:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
using JavaScriptHandler =
|
2016-06-08 13:52:21 +00:00
|
|
|
base::Callback<void(const base::DictionaryValue&, v8::Local<v8::Value>)>;
|
2019-05-03 19:08:41 +00:00
|
|
|
using BeforeStartCallback = base::OnceCallback<void(mate::Arguments* args)>;
|
2015-08-12 05:30:19 +00:00
|
|
|
|
2018-10-05 20:29:57 +00:00
|
|
|
class JsAsker {
|
2015-08-12 05:30:19 +00:00
|
|
|
public:
|
2018-10-05 20:29:57 +00:00
|
|
|
JsAsker();
|
|
|
|
~JsAsker();
|
2015-08-12 14:57:25 +00:00
|
|
|
|
|
|
|
// Called by |CustomProtocolHandler| to store handler related information.
|
2018-04-18 01:44:10 +00:00
|
|
|
void SetHandlerInfo(v8::Isolate* isolate,
|
|
|
|
net::URLRequestContextGetter* request_context_getter,
|
2018-10-05 20:29:57 +00:00
|
|
|
const JavaScriptHandler& handler);
|
|
|
|
|
|
|
|
// Ask handler for options in UI thread.
|
|
|
|
static void AskForOptions(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const JavaScriptHandler& handler,
|
|
|
|
std::unique_ptr<base::DictionaryValue> request_details,
|
2019-05-03 19:08:41 +00:00
|
|
|
BeforeStartCallback before_start);
|
2015-08-12 05:30:19 +00:00
|
|
|
|
2018-10-05 20:29:57 +00:00
|
|
|
// Test whether the |options| means an error.
|
|
|
|
static bool IsErrorOptions(base::Value* value, int* error);
|
2015-08-12 05:30:19 +00:00
|
|
|
|
2015-08-12 14:57:25 +00:00
|
|
|
net::URLRequestContextGetter* request_context_getter() const {
|
2015-09-09 11:27:28 +00:00
|
|
|
return request_context_getter_;
|
2015-08-12 14:57:25 +00:00
|
|
|
}
|
2018-10-05 20:29:57 +00:00
|
|
|
v8::Isolate* isolate() { return isolate_; }
|
|
|
|
JavaScriptHandler handler() { return handler_; }
|
2015-08-12 14:57:25 +00:00
|
|
|
|
2015-08-12 05:30:19 +00:00
|
|
|
private:
|
|
|
|
v8::Isolate* isolate_;
|
2015-09-09 11:27:28 +00:00
|
|
|
net::URLRequestContextGetter* request_context_getter_;
|
2015-08-12 05:30:19 +00:00
|
|
|
JavaScriptHandler handler_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(JsAsker);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_NET_JS_ASKER_H_
|