return mate::ObjectTemplateBuilder(isolate)
.SetMethod("registerStandardSchemes", &Protocol::RegisterStandardSchemes)
.SetMethod("registerStringProtocol",
- &Protocol::RegisterProtocol<URLRequestStringJob>)
+ &Protocol::JavaScriptRegisterProtocol<URLRequestStringJob>)
.SetMethod("registerBufferProtocol",
- &Protocol::RegisterProtocol<URLRequestBufferJob>)
+ &Protocol::JavaScriptRegisterProtocol<URLRequestBufferJob>)
.SetMethod("registerFileProtocol",
- &Protocol::RegisterProtocol<UrlRequestAsyncAsarJob>)
+ &Protocol::JavaScriptRegisterProtocol<UrlRequestAsyncAsarJob>)
.SetMethod("registerHttpProtocol",
- &Protocol::RegisterProtocol<URLRequestFetchJob>);
+ &Protocol::JavaScriptRegisterProtocol<URLRequestFetchJob>);
}
void Protocol::RegisterStandardSchemes(
void Protocol::OnIOCompleted(
const CompletionCallback& callback, ProtocolError error) {
+ // The completion callback is optional.
+ if (callback.is_null())
+ return;
+
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
#include "atom/browser/net/atom_url_request_job_factory.h"
#include "base/callback.h"
#include "content/public/browser/browser_thread.h"
+#include "native_mate/arguments.h"
+#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"
return PROTOCOL_FAIL;
}
+ // Parse optional parameters for registerProtocol.
+ template<typename RequestJob>
+ void JavaScriptRegisterProtocol(v8::Isolate* isolate,
+ const std::string& scheme,
+ mate::Arguments* args) {
+ // protocol.registerProtocol(scheme[, options], handler[, callback]);
+ mate::Dictionary options = mate::Dictionary::CreateEmpty(isolate);
+ Handler handler;
+ CompletionCallback callback;
+ args->GetNext(&options);
+ if (!args->GetNext(&handler)) {
+ args->ThrowError();
+ return;
+ }
+ args->GetNext(&callback);
+
+ RegisterProtocol<RequestJob>(isolate, scheme, handler, callback);
+ }
+
// Convert error code to JS exception and call the callback.
void OnIOCompleted(const CompletionCallback& callback, ProtocolError error);
#include "atom/browser/net/asar/url_request_asar_job.h"
#include <string>
+#include <vector>
#include "base/bind.h"
#include "base/files/file_util.h"
#include "atom/browser/net/js_asker.h"
+#include <vector>
+
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/v8_value_converter.h"
#include "native_mate/function_template.h"
#ifndef ATOM_BROWSER_NET_URL_REQUEST_STRING_JOB_H_
#define ATOM_BROWSER_NET_URL_REQUEST_STRING_JOB_H_
+#include <string>
+
#include "atom/browser/net/js_asker.h"
#include "net/url_request/url_request_simple_job.h"
-#include <string>
-
namespace atom {
class URLRequestStringJob : public JsAsker<net::URLRequestSimpleJob> {
-Subproject commit 67d9eaa215e8727d86dc7b1f7a10be8699848f1f
+Subproject commit 24d31e204698bafc65c50295167764fbb0f28bc0