]> khamidou — GitHub mirrors - electron.git/commitdiff
Make the completion callback optional
authorCheng Zhao <zcbenz@gmail.com>
Wed, 12 Aug 2015 13:32:52 +0000 (21:32 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 12 Aug 2015 13:32:52 +0000 (21:32 +0800)
atom/browser/api/atom_api_protocol.cc
atom/browser/api/atom_api_protocol.h
atom/browser/net/asar/url_request_asar_job.cc
atom/browser/net/js_asker.cc
atom/browser/net/url_request_string_job.h
vendor/native_mate

index c0c2e5b512ca2b52903ae13554ab5cf010d0f59e..b7a4971a37dce9e61e340fbaf2a81c05c31bf8c0 100644 (file)
@@ -49,13 +49,13 @@ mate::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder(
   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(
@@ -65,6 +65,10 @@ 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());
 
index 54dac9b13b9aee6076159cbdb996592eb1e51fe4..233ee00a290f6c92bbf90f424f93bdb571ea3ab7 100644 (file)
@@ -12,6 +12,8 @@
 #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"
 
@@ -106,6 +108,25 @@ class Protocol : public mate::Wrappable {
       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);
 
index 33cb04c9ede8acb010c324693d728dc410ac1929..de019f6d9420145d21173825cd7e4d68fd58cc9e 100644 (file)
@@ -5,6 +5,7 @@
 #include "atom/browser/net/asar/url_request_asar_job.h"
 
 #include <string>
+#include <vector>
 
 #include "base/bind.h"
 #include "base/files/file_util.h"
index aa6192b057ac4474143f59df13e4eb0aa27dc0ab..bbaf093eb250761f842f074c1de69b4b87e1027a 100644 (file)
@@ -4,6 +4,8 @@
 
 #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"
index 7a2e23acab051d9208115ef62f4dec22526e117c..87b9181352c472b0ca18b510ae6c595b95caf20f 100644 (file)
@@ -5,11 +5,11 @@
 #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> {
index 67d9eaa215e8727d86dc7b1f7a10be8699848f1f..24d31e204698bafc65c50295167764fbb0f28bc0 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 67d9eaa215e8727d86dc7b1f7a10be8699848f1f
+Subproject commit 24d31e204698bafc65c50295167764fbb0f28bc0